1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /**************************************************************************
8 *   Copyright (C) 2010 by Franz Schmid                                    *
9 *   franz.schmid@altmuehlnet.de                                           *
10 *                                                                         *
11 *   This program is free software; you can redistribute it and/or modify  *
12 *   it under the terms of the GNU General Public License as published by  *
13 *   the Free Software Foundation; either version 2 of the License, or     *
14 *   (at your option) any later version.                                   *
15 *                                                                         *
16 *   This program is distributed in the hope that it will be useful,       *
17 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19 *   GNU General Public License for more details.                          *
20 *                                                                         *
21 *   You should have received a copy of the GNU General Public License     *
22 *   along with this program; if not, write to the                         *
23 *   Free Software Foundation, Inc.,                                       *
24 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
25 ***************************************************************************/
26 #ifndef COLORSANDFILLS_H
27 #define COLORSANDFILLS_H
28 
29 #include "ui_colorsandfillsbase.h"
30 #include "colorsetmanager.h"
31 #include "sccolor.h"
32 #include "scribusapi.h"
33 #include "scribusdoc.h"
34 
35 #include "vgradient.h"
36 #include "scpattern.h"
37 
38 class SCRIBUS_API ColorsAndFillsDialog : public QDialog, Ui::ColorsAndFillsBase
39 {
40 	Q_OBJECT
41 
42 	public:
43 		ColorsAndFillsDialog(QWidget* parent, QHash<QString, VGradient> *docGradients, const ColorList& doco, const QString& docColSet, QHash<QString, ScPattern> *docPatterns, ScribusDoc *doc, ScribusMainWindow* scMW);
~ColorsAndFillsDialog()44 		~ColorsAndFillsDialog() {}
45 		/*! \brief Returns the name of the current/selected color set.
46 		\retval QString selected name. */
47 		QString getColorSetName();
48 		/*! \brief Returns currently selected ScColor.
49 		It's used e.g. in BarcodeGenerator plugin.
50 		*/
51 		ScColor selectedColor();
52 		/*! \brief Returns name of the currently selected color.
53 		It's used e.g. in BarcodeGenerator plugin.
54 		*/
55 		QString selectedColorName();
56 
57 		void keyPressEvent(QKeyEvent *k);
58 
59 
60 		ScribusDoc *m_doc {nullptr};
61 		ScribusMainWindow *mainWin {nullptr};
62 		QHash<QString, VGradient> dialogGradients;
63 		QMap<QString,QString> replaceMap;
64 		QMap<QString,QString> origNames;
65 		QStringList origGradients;
66 		ColorList m_colorList;
67 		QMap<QString,QString> replaceColorMap;
68 		//! \brief Custom user's color set
69 		QStringList customColSet;
70 		bool hasImportedColors {false};
71 		QHash<QString, ScPattern> dialogPatterns;
72 		QMap<QString,QString> replaceMapPatterns;
73 		QMap<QString,QString> origNamesPatterns;
74 		QStringList origPatterns;
75 
76 	private slots:
77 		void leaveDialog();
78 		void slotRightClick(QPoint p);
79 		void selEditColor(QTreeWidgetItem *it);
80 		void itemSelectionChanged();
81 		void itemSelected(QTreeWidgetItem* it);
82 		void createNew();
83 		void editColorItem();
84 		void duplicateColorItem();
85 		void removeColorItem();
86 		void removeUnusedColorItem();
87 		void importColorItems();
88 		void loadDefaults(QTreeWidgetItem* item);
89 		void saveDefaults();
90 
91 	protected:
92 		QTreeWidgetItem* updatePatternList(const QString& addedName = "");
93 		QTreeWidgetItem* updateGradientList(const QString& addedName = "");
94 		QTreeWidgetItem* updateColorList(const QString& addedName = "");
95 		ColorList getGradientColors();
96 		QString getColorTooltip(const ScColor& color);
97 		bool isMandatoryColor(const QString& colorName);
98 		void loadPatternDir();
99 		void loadVectors(const QString& data);
100 		void updateGradientColors(const QString& newName, const QString& oldName);
101 		void loadGimpFormat(const QString& fileName);
102 		void addGimpColor(QString &colorName, double r, double g, double b);
103 		void loadScribusFormat(const QString& fileName);
104 		QStringList getUsedPatternsHelper(const QString& pattern, QStringList &results);
105 		void doSaveDefaults(const QString& name, bool changed = false);
106 		ColorSetManager csm;
107 		bool paletteLocked;
108 		bool modified;
109 		int sortRule;
110 		QTreeWidgetItem *colorItems;
111 		QTreeWidgetItem *gradientItems;
112 		QTreeWidgetItem *patternItems;
113 		QTreeWidgetItem *systemSwatches;
114 		QTreeWidgetItem *userSwatches;
115 		ColorList inDocUsedColors;
116 };
117 
118 #endif
119