1 /*
2  * Copyright (c) 2005-2019 Libor Pecháček.
3  *
4  * This file is part of CoVe
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (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 Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef COVE_MAINFORM_H
21 #define COVE_MAINFORM_H
22 
23 #include <memory>
24 #include <vector>
25 
26 #include <QDialog>
27 #include <QImage>
28 #include <QObject>
29 #include <QRgb>
30 #include <QString>
31 #include <Qt>
32 #include <QUndoCommand>
33 
34 #include "libvectorizer/Vectorizer.h"
35 
36 #include "Settings.h"
37 #include "ui_mainform.h"
38 
39 class QPushButton;
40 class QWidget;
41 class QUndoStack;
42 
43 namespace OpenOrienteering {
44 class Map;
45 class Template;
46 class TemplateImage;
47 } // namespace OpenOrienteering
48 
49 namespace cove {
50 
51 class mainForm : public QDialog
52 {
53 	Q_OBJECT
54 
55 	struct BwBitmapUndoStep : public QUndoCommand
56 	{
57 		BwBitmapUndoStep(mainForm& form, QImage image, bool vectorizable);
58 		void redo() override;
59 		void undo() override;
60 
61 		mainForm& form;
62 		QImage image;
63 		bool suitableForVectorization;
64 	};
65 
66 public:
67 	Ui::mainForm ui;
68 
69 protected:
70 	std::unique_ptr<Vectorizer> vectorizerApp;
71 	OpenOrienteering::Map* ooMap;
72 	OpenOrienteering::Template* ooTempl;
73 	QString imageFileName;
74 	QImage imageBitmap;
75 	QImage classifiedBitmap;
76 	QImage bwBitmap;
77 	bool bwBitmapVectorizable {};
78 	QUndoStack* bwBitmapUndo {};
79 	std::vector<QPushButton*> colorButtons;
80 	Settings settings;
81 	static const int MESSAGESHOWDELAY;
82 
83 	bool performMorphologicalOperation(Vectorizer::MorphologicalOperation mo);
84 	void clearColorsTab();
85 	void clearBWImageTab();
86 	void setTabEnabled(QWidget* tab, bool state);
87 	void afterLoadImage();
88 	QRgb getColorFromImage(const QImage& image);
89 
90 public:
91 	mainForm(QWidget* parent, OpenOrienteering::Map* map,
92 	         OpenOrienteering::TemplateImage* templ, Qt::WindowFlags flags = {});
93 	~mainForm() override;
94 	void loadImage(const QImage& imageToLoad, const QString& imageName);
95 	void clearColorButtonsGroup();
96 	void setColorButtonsGroup(std::vector<QRgb> colors);
97 	std::vector<bool> getSelectedColors();
98 
99 public slots:
100 	void aboutDialog();
101 	void setInitialColors(bool on);
102 	void colorButtonToggled(bool on);
103 
104 	void on_bwImageSaveButton_clicked();        // clazy:exclude=connect-by-name
105 	void on_classificationOptionsButton_clicked();  // clazy:exclude=connect-by-name
106 	void on_initialColorsButton_clicked();      // clazy:exclude=connect-by-name
107 	void on_howManyColorsSpinBox_valueChanged(int n);  // clazy:exclude=connect-by-name
108 	void on_mainTabWidget_currentChanged(int w);  // clazy:exclude=connect-by-name
109 	void on_setVectorizationOptionsButton_clicked();  // clazy:exclude=connect-by-name
110 	void on_createVectorsButton_clicked();      // clazy:exclude=connect-by-name
111 	void on_saveVectorsButton_clicked();        // clazy:exclude=connect-by-name
112 	void on_runClassificationButton_clicked();  // clazy:exclude=connect-by-name
113 	void on_runErosionButton_clicked();         // clazy:exclude=connect-by-name
114 	void on_runDilationButton_clicked();        // clazy:exclude=connect-by-name
115 	void on_runThinningButton_clicked();        // clazy:exclude=connect-by-name
116 	void on_runPruningButton_clicked();         // clazy:exclude=connect-by-name
117 	void on_bwImageHistoryBack_clicked();       // clazy:exclude=connect-by-name
118 	void on_bwImageHistoryForward_clicked();    // clazy:exclude=connect-by-name
119 	void on_applyFIRFilterPushButton_clicked(); // clazy:exclude=connect-by-name
120 };
121 } // cove
122 
123 #endif
124