Tulip  5.2.0
Large graphs analysis and drawing
ColorScaleConfigDialog.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef COLORSCALECONFIGDIALOG_H_
22 #define COLORSCALECONFIGDIALOG_H_
23 
24 #include <tulip/ColorScale.h>
25 
26 #include <QDialog>
27 
28 namespace Ui {
29 class ColorScaleDialog;
30 }
31 
32 class QTableWidgetItem;
33 class QListWidgetItem;
34 class QLabel;
35 
36 namespace tlp {
37 
38 class TLP_QT_SCOPE ColorScaleConfigDialog : public QDialog {
39 
40  Q_OBJECT
41 
42 public:
43  ColorScaleConfigDialog(const ColorScale &colorScale = ColorScale(), QWidget *parent = nullptr);
44  ~ColorScaleConfigDialog() override;
45  void setColorScale(const ColorScale &colorScale);
46  const ColorScale &getColorScale() const;
47  static ColorScale getColorScaleFromImageFile(const std::string &imageFilePath,
48  bool gradient = true);
49 
50 protected:
51  void resizeEvent(QResizeEvent *event) override;
52  void showEvent(QShowEvent *event) override;
53 
54 private slots:
55 
56  void accept() override;
57  void pressButtonBrowse();
58  void nbColorsValueChanged(int value);
59  void colorTableItemDoubleClicked(QTableWidgetItem *item);
60  void displaySavedGradientPreview();
61  void displayUserGradientPreview();
62  void saveCurrentColorScale();
63  void deleteSavedColorScale();
64  void reeditSaveColorScale(QListWidgetItem *savedColorScaleItem);
65  void importColorScaleFromImageFile();
66  void importColorScaleFromColorScaleFile();
67  void invertEditedColorScale();
68  void applyGlobalAlphaToColorScale();
69 
70 private:
71  Ui::ColorScaleDialog *_ui;
72 
73  void setColorScaleFromImage(const QString &imageFilePath);
74 
75  void loadUserSavedColorScales();
76  void displayGradientPreview(const QList<QColor> &colorsVector, bool gradient,
77  QLabel *displayLabel);
78  void importColorScaleFromFile(const QString &currentDir);
79 
80  ColorScale colorScale;
81  ColorScale latestColorScale;
82  std::string gradientsImageDirectory;
83 
84  static std::map<QString, std::vector<Color>> tulipImageColorScales;
85  static void loadTulipImageColorScales();
86  static void loadImageColorScalesFromDir(const QString &colorScalesDir);
87  static std::vector<Color> getColorScaleFromImageFile(const QString &imageFilePath);
88 };
89 }
90 
91 #endif /* COLORSCALECONFIGDIALOG_H_ */
92 ///@endcond