1 #ifndef _POPUPEDITOR_H_
2 #define _POPUPEDITOR_H_
3 //=============================================================================
4 //
5 //   File : PopupEditorWindow.h
6 //   Creation date : Mon Dec 23 2002 20:24:55 CEST by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 //   This program is FREE software. You can redistribute it and/or
12 //   modify it under the terms of the GNU General Public License
13 //   as published by the Free Software Foundation; either version 2
14 //   of the License, or (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.
19 //   See the 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 Free Software Foundation,
23 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "KviWindow.h"
28 #include "KviCString.h"
29 
30 #include <QTreeWidget>
31 #include <QWidget>
32 #include <QLineEdit>
33 #include <QPushButton>
34 #include <QMenu>
35 
36 class KviKvsPopupMenu;
37 class KviKvsPopupMenuItem;
38 class KviScriptEditor;
39 class MenuTreeWidgetItem;
40 
41 // PopupTreeWidgetItem
42 class PopupTreeWidgetItem : public QTreeWidgetItem
43 {
44 public:
45 	enum Type
46 	{
47 		Item,
48 		Menu,
49 		Separator,
50 		Label,
51 		Epilogue,
52 		Prologue,
53 		ExtMenu
54 	};
55 
56 public:
57 	PopupTreeWidgetItem(QTreeWidget * pTreeWidget, PopupTreeWidgetItem * after, Type t);
58 	PopupTreeWidgetItem(PopupTreeWidgetItem * parent, PopupTreeWidgetItem * after, Type t);
59 
60 public:
61 	Type m_type;
62 	QString m_szText;
63 	QString m_szCondition;
64 	QString m_szIcon;
65 	QString m_szCode;
66 	QString m_szId;
67 
68 private:
69 	void init();
70 
71 public:
72 	void setItemText(const QString & szText);
73 	void setCondition(const QString & szCondition);
74 	void setIcon(const QString & szIcon);
75 	void setCode(const QString & szCode);
76 	void setId(const QString & szId);
77 };
78 
79 class SinglePopupEditor final : public QWidget
80 {
81 	Q_OBJECT
82 public:
83 	SinglePopupEditor(QWidget * par);
84 	~SinglePopupEditor();
85 
86 protected:
87 	QPushButton * m_pMenuButton;
88 	KviKvsPopupMenu * m_pClipboard;
89 	KviKvsPopupMenu * m_pTestPopup;
90 	PopupTreeWidgetItem * m_pLastSelectedItem;
91 	QTreeWidget * m_pTreeWidget;
92 	QLineEdit * m_pNameEditor;
93 	KviScriptEditor * m_pEditor;
94 	QLineEdit * m_pTextEditor;
95 	QLineEdit * m_pIdEditor;
96 	QLineEdit * m_pIconEditor;
97 	QLineEdit * m_pConditionEditor;
98 	QLineEdit * m_pExtNameEditor;
99 	QMenu * m_pContextPopup;
100 
101 public:
102 	void edit(MenuTreeWidgetItem * it);
103 	KviKvsPopupMenu * getMenu();
104 
105 protected:
106 	// theItem is the item above the first item that has to be inserted
107 	void populateMenu(KviKvsPopupMenu * pop, PopupTreeWidgetItem * par, PopupTreeWidgetItem * theItem = nullptr);
108 	void saveLastSelectedItem();
109 	void addItemToMenu(KviKvsPopupMenu * pop, PopupTreeWidgetItem * par);
110 	PopupTreeWidgetItem * newItem(PopupTreeWidgetItem * par, PopupTreeWidgetItem * after, PopupTreeWidgetItem::Type t);
111 	PopupTreeWidgetItem * newItemBelow(PopupTreeWidgetItem * it, PopupTreeWidgetItem::Type t);
112 	PopupTreeWidgetItem * newItemAbove(PopupTreeWidgetItem * it, PopupTreeWidgetItem::Type t);
113 	PopupTreeWidgetItem * newItemInside(PopupTreeWidgetItem * it, PopupTreeWidgetItem::Type t);
114 	void createNewItemAboveLastSelected(PopupTreeWidgetItem::Type t);
115 	void createNewItemBelowLastSelected(PopupTreeWidgetItem::Type t);
116 	void createNewItemInsideLastSelected(PopupTreeWidgetItem::Type t);
117 	PopupTreeWidgetItem * findMatchingItem(KviKvsPopupMenuItem * it, PopupTreeWidgetItem * item);
118 protected slots:
119 	void contextCut();
120 	void contextCopy();
121 	void contextRemove();
122 	void contextPasteBelow();
123 	void contextPasteAbove();
124 	void contextPasteInside();
125 	void contextNewSeparatorBelow();
126 	void contextNewSeparatorAbove();
127 	void contextNewSeparatorInside();
128 	void contextNewItemBelow();
129 	void contextNewItemAbove();
130 	void contextNewItemInside();
131 	void contextNewMenuBelow();
132 	void contextNewMenuAbove();
133 	void contextNewMenuInside();
134 	void contextNewExtMenuBelow();
135 	void contextNewExtMenuAbove();
136 	void contextNewExtMenuInside();
137 	void contextNewLabelBelow();
138 	void contextNewLabelAbove();
139 	void contextNewLabelInside();
140 	void contextNewPrologue();
141 	void contextNewEpilogue();
142 	void selectionChanged();
143 	void customContextMenuRequested(const QPoint & pnt);
144 	void testPopup();
145 	void testModeMenuItemClicked(KviKvsPopupMenuItem * it);
146 };
147 
148 class MenuTreeWidgetItem final : public QTreeWidgetItem
149 {
150 public:
151 	MenuTreeWidgetItem(QTreeWidget * par, KviKvsPopupMenu * popup);
152 	~MenuTreeWidgetItem();
153 
154 public:
155 	KviKvsPopupMenu * m_pPopup;
156 
157 public:
popup()158 	KviKvsPopupMenu * popup() { return m_pPopup; };
159 public:
160 	void replacePopup(KviKvsPopupMenu * popup);
161 };
162 
163 class PopupEditorWidget final : public QWidget
164 {
165 	Q_OBJECT
166 public:
167 	PopupEditorWidget(QWidget * par);
168 
169 public:
170 	SinglePopupEditor * m_pEditor;
171 	QTreeWidget * m_pTreeWidget;
172 	MenuTreeWidgetItem * m_pLastEditedItem;
173 	bool m_bOneTimeSetupDone;
174 	QMenu * m_pContextPopup;
175 	QMenu * m_pEmptyContextPopup;
176 	bool m_bSaving;
177 
178 public:
179 	void commit();
180 	void exportPopups(bool);
181 protected slots:
182 	void currentItemChanged(QTreeWidgetItem * it, QTreeWidgetItem * prev);
183 	void customContextMenuRequested(const QPoint & pnt);
184 	void newPopup();
185 	void exportAll();
186 	void exportSelected();
187 	void exportCurrentPopup();
188 	void removeCurrentPopup();
189 	void popupRefresh(const QString & szName);
190 
191 protected:
192 	void showEvent(QShowEvent * e) override;
193 	void getExportPopupBuffer(QString & buffer, MenuTreeWidgetItem * it);
194 
195 private:
196 	void oneTimeSetup();
197 	void saveLastEditedItem();
198 	void getUniquePopupName(MenuTreeWidgetItem * it, QString & buffer);
199 };
200 
201 class PopupEditorWindow final : public KviWindow
202 {
203 	Q_OBJECT
204 public:
205 	PopupEditorWindow();
206 	~PopupEditorWindow();
207 
208 private:
209 	PopupEditorWidget * m_pEditor;
210 	QPixmap * myIconPtr() override;
211 	void fillCaptionBuffers() override;
getConfigGroupName(QString & szName)212 	void getConfigGroupName(QString & szName) override { szName = "popupeditor"; };
saveProperties(KviConfigurationFile *)213 	void saveProperties(KviConfigurationFile *) override {};
loadProperties(KviConfigurationFile *)214 	void loadProperties(KviConfigurationFile *) override {};
215 private slots:
cancelClicked()216 	void cancelClicked() { close(); };
217 	void okClicked();
applyClicked()218 	void applyClicked() { m_pEditor->commit(); };
219 };
220 
221 #endif //_POPUPEDITOR_H_
222