1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_COLOR_SCHEMA_DIALOG_CONTROLLER_H_
23 #define _U2_COLOR_SCHEMA_DIALOG_CONTROLLER_H_
24 
25 #include <ui_ColorSchemaSettingsWidget.h>
26 #include <ui_CreateMSAScheme.h>
27 
28 #include <QDialog>
29 #include <QMap>
30 #include <QMouseEvent>
31 #include <QPixmap>
32 
33 #include <U2Algorithm/MsaColorScheme.h>
34 
35 #include <U2Gui/AppSettingsGUI.h>
36 
37 #include <U2View/ColorSchemaSettingsController.h>
38 
39 #include "ui_ColorSchemaDialog.h"
40 
41 namespace U2 {
42 
43 class ColorSchemaDialogController : public QDialog, public Ui_ColorSchemaDialog {
44     Q_OBJECT
45 public:
46     ColorSchemaDialogController(QMap<char, QColor> &colors);
47     ~ColorSchemaDialogController();
48     int adjustAlphabetColors();
49 
50 protected:
51     void mouseReleaseEvent(QMouseEvent *);
52     void paintEvent(QPaintEvent *);
53 private slots:
54     void sl_onClear();
55     void sl_onRestore();
56 
57 private:
58     QPixmap *alphabetColorsView;
59     QMap<char, QColor> &newColors;
60     QMap<char, QColor> storedColors;
61     QMap<char, QRect> charsPlacement;
62 };
63 
64 class ColorSchemaSettingsPageState : public AppSettingsGUIPageState {
65     Q_OBJECT
66 public:
67     QString colorsDir;
68     QList<ColorSchemeData> customSchemas;
69     QList<ColorSchemeData> removedCustomSchemas;
70 };
71 
72 class ColorSchemaSettingsPageWidget : public AppSettingsGUIPageWidget, public Ui_ColorSchemaSettingsWidget {
73     Q_OBJECT
74 public:
75     ColorSchemaSettingsPageWidget(ColorSchemaSettingsPageController *ctrl);
76 
77     virtual void setState(AppSettingsGUIPageState *state);
78 
79     virtual AppSettingsGUIPageState *getState(QString &err) const;
80 
81 private slots:
82     void sl_onColorsDirButton();
83     void sl_onChangeColorSchema();
84     void sl_onAddColorSchema();
85     void sl_onDeleteColorSchema();
86     void sl_schemaChanged(int);
87 
88 private:
89     QList<ColorSchemeData> customSchemas;
90     QList<ColorSchemeData> removedCustomSchemas;
91 };
92 
93 class CreateColorSchemaDialog : public QDialog, public Ui_CreateMSAScheme {
94     Q_OBJECT
95 public:
96     CreateColorSchemaDialog(ColorSchemeData *, QStringList usedNames);
97     int createNewScheme();
98 
99 private slots:
100     void sl_createSchema();
101     void sl_cancel();
102     void sl_schemaNameEdited(const QString &);
103     void sl_alphabetChanged(int);
104 
105 private:
106     bool isNameExist(const QString &);
107     bool isSchemaNameValid(const QString &, QString &);
108 
109     QStringList usedNames;
110     ColorSchemeData *newSchema;
111 };
112 
113 }  // namespace U2
114 
115 #endif  // _U2_COLOR_SCHEMA_DIALOG_CONTROLLER_H_
116