1 /***************************************************************************
2     File                 : CustomActionDialog.h
3     Project              : QtiPlot
4     --------------------------------------------------------------------
5     Copyright            : (C) 2007 by Ion Vasilief
6     Email (use @ for *)  : ion_vasilief*yahoo.fr
7     Description          : Custom Action dialog
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *  This program is free software; you can redistribute it and/or modify   *
14  *  it under the terms of the GNU General Public License as published by   *
15  *  the Free Software Foundation; either version 2 of the License, or      *
16  *  (at your option) any later version.                                    *
17  *                                                                         *
18  *  This program is distributed in the hope that it will be useful,        *
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
21  *  GNU General Public License for more details.                           *
22  *                                                                         *
23  *   You should have received a copy of the GNU General Public License     *
24  *   along with this program; if not, write to the Free Software           *
25  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
26  *   Boston, MA  02110-1301  USA                                           *
27  *                                                                         *
28  ***************************************************************************/
29 #ifndef CustomActionDialog_H
30 #define CustomActionDialog_H
31 
32 #include <QDialog>
33 #include <QXmlDefaultHandler>
34 
35 class QGroupBox;
36 class QPushButton;
37 class QRadioButton;
38 class QComboBox;
39 class QListWidget;
40 class QLineEdit;
41 class QMenu;
42 class QToolBar;
43 
44 class CustomActionDialog : public QDialog
45 {
46     Q_OBJECT
47 
48 public:
49 	//! Constructor
50 	/**
51 	 * \param parent parent widget (must be the application window!=
52 	 * \param fl window flags
53 	 */
54     CustomActionDialog( QWidget* parent, Qt::WFlags fl = 0 );
55 
56 private slots:
57 	void chooseIcon();
58 	void chooseFile();
59 	void chooseFolder();
60 	QAction* addAction();
61 	void removeAction();
62 	void setCurrentAction(int);
63 	void saveCurrentAction();
64 	void addMenu();
65 	void removeMenu();
66 	void enableDeleteMenuBtn(const QString &);
67 
68 private:
69 	void init();
70 	void updateDisplayList();
71 	QAction* actionAt(int row);
72 	void saveAction(QAction *action);
73 	void customizeAction(QAction *action);
74 	bool validUserInput();
75 	void saveMenu(QMenu *menu);
76 
77 	QStringList d_app_shortcut_keys;
78 
79 	QList<QMenu *> d_menus;
80 	QList<QToolBar *> d_app_toolbars;
81 
82     QListWidget *itemsList;
83     QPushButton *buttonCancel, *buttonAdd, *buttonRemove, *buttonSave;
84     QPushButton *folderBtn, *fileBtn, *iconBtn;
85     QLineEdit *folderBox, *fileBox, *iconBox, *textBox, *toolTipBox, *shortcutBox;
86     QRadioButton *menuBtn, *toolBarBtn;
87     QComboBox *menuBox, *toolBarBox;
88     QPushButton *newMenuBtn, *removeMenuBtn;
89 };
90 
91 class CustomActionHandler : public QXmlDefaultHandler
92 {
93 public:
94     CustomActionHandler(QAction *action);
95 
96     bool startElement(const QString &namespaceURI, const QString &localName,
97                        const QString &qName, const QXmlAttributes &attributes);
98     bool endElement(const QString &namespaceURI, const QString &localName,
99                      const QString &qName);
100     bool characters(const QString &str){currentText += str; return true;};
101     bool fatalError(const QXmlParseException &){return false;};
102     QString errorString() const {return errorStr;};
103 	QString parentName(){return d_widget_name;};
104 
105 private:
106     bool metFitTag;
107     QString currentText;
108     QString errorStr;
109     QString filePath;
110 	QString d_widget_name;
111     QAction *d_action;
112 };
113 
114 class CustomMenuHandler : public QXmlDefaultHandler
115 {
116 public:
117     CustomMenuHandler();
118 
119     bool startElement(const QString &namespaceURI, const QString &localName,
120                        const QString &qName, const QXmlAttributes &attributes);
121     bool endElement(const QString &namespaceURI, const QString &localName,
122                      const QString &qName);
123     bool characters(const QString &str){currentText += str; return true;};
124     bool fatalError(const QXmlParseException &){return false;};
125     QString errorString() const {return errorStr;};
126 	QString location(){return d_location;};
127 	QString title(){return d_title;};
128 
129 private:
130     bool metFitTag;
131     QString currentText;
132     QString errorStr;
133 	QString d_location, d_title;
134 };
135 #endif
136