1 /*
2 # PostgreSQL Database Modeler (pgModeler)
3 #
4 # Copyright 2006-2020 - Raphael Araújo e Silva <raphael@pgmodeler.io>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation version 3.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # The complete text of GPLv3 is at LICENSE file on source code root directory.
16 # Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
17 */
18 
19 /**
20 \ingroup libpgmodeler_ui
21 \class AppearanceConfigWidget
22 \brief Implements the operations to manage graphical objects appearance configuration.
23 */
24 
25 #ifndef APPEARANCE_CONFIG_WIDGET_H
26 #define APPEARANCE_CONFIG_WIDGET_H
27 
28 #include "ui_appearanceconfigwidget.h"
29 #include "baseconfigwidget.h"
30 #include "colorpickerwidget.h"
31 #include "objectsscene.h"
32 #include "databasemodel.h"
33 #include <algorithm>
34 
35 class AppearanceConfigWidget: public BaseConfigWidget, public Ui::AppearanceConfigWidget  {
36 	private:
37 		Q_OBJECT
38 
39 		static map<QString, attribs_map> config_params;
40 
41 		//! \brief Auxiliary class that stores the formating data of each element
42 		class AppearanceConfigItem {
43 			public:
44 				QString conf_id;
45 				QTextCharFormat font_fmt;
46 				QColor colors[3];
47 				bool obj_conf;
48 		};
49 
50 		RoundedRectItem *placeholder;
51 
52 		ColorPickerWidget *color_picker;
53 
54 		//! \brief Color picker dialog
55 		QColorDialog color_dlg;
56 
57 		//! \brief Viewport used to show the example model
58 		QGraphicsView *viewp;
59 
60 		//! \brief Object scene used to store the graphical objects
61 		ObjectsScene *scene;
62 
63 		//! \brief Database model used to store the example base objects
64 		DatabaseModel *model;
65 
66 		//! \brief Stores the element configuration items
67 		vector<AppearanceConfigItem> conf_items;
68 
69 		//! \brief Loads the example model from file (conf/exampledb.dbm)
70 		void loadExampleModel();
71 
72 		//! \brief Updates the color configuration for the placeholder item
73 		void updatePlaceholderItem();
74 
75 	public:
76 		AppearanceConfigWidget(QWidget * parent = nullptr);
77 		virtual ~AppearanceConfigWidget();
78 
79 		void saveConfiguration();
80 		void loadConfiguration();
81 		static map<QString, attribs_map> getConfigurationParams();
82 
83 	private slots:
84 		void enableConfigElement();
85 		void applyFontStyle();
86 		void applyElementColor(unsigned color_idx, QColor color);
87 
88 		/*! \brief Disabled method */
applyConfiguration(void)89 		void applyConfiguration(void){}
90 
91 	public slots:
92 		void restoreDefaults();
93 };
94 
95 #endif
96