KVIrc  4.9.2
DeveloperAPIs
KviKvsPopupMenu.h
Go to the documentation of this file.
1 #ifndef _KVI_KVS_POPUPMENU_H_
2 #define _KVI_KVS_POPUPMENU_H_
3 //=============================================================================
4 //
5 // File : KviKvsPopupMenu.h
6 // Creation date : Wed 07 Jan 2004 05:02:57 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2004-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 "kvi_settings.h"
28 #include "KviQString.h"
29 #include "KviWindow.h"
30 #include "KviKvsHash.h"
31 #include "KviKvsVariantList.h"
32 #include "KviKvsScript.h"
33 #include "KviKvsRunTimeContext.h"
34 
35 #include <QLabel>
36 #include <QPixmap>
37 #include <QMenu>
38 
39 class KviKvsPopupMenu;
40 
42 {
43  friend class KviKvsPopupMenu;
44 
45 public:
49  {
52  HardLocked
53  };
54 
55 protected:
61 
62 public:
63  KviKvsExtendedRunTimeData * extendedRunTimeData() { return m_pExtendedRunTimeData; };
64  //KviKvsHash * extScopeVariables(){ return m_pExtScopeVariables; };
65  KviKvsVariantList * parameters() { return m_pParameters; };
66  bool isSoftLocked() { return m_eLocked != Unlocked; };
67  bool isHardLocked() { return m_eLocked == HardLocked; };
68  void setLocked(LockStatus eLocked) { m_eLocked = eLocked; };
69  KviWindow * window() { return m_pWindow; };
70  void setWindow(KviWindow * pWindow) { m_pWindow = pWindow; };
71  bool testMode() { return m_bTestMode; };
72  void setTestMode(bool bTestMode) { m_bTestMode = bTestMode; };
73 };
74 
76 {
77  friend class KviKvsPopupMenu;
78 
79 public:
80  enum Type
81  {
86  ExtMenu
87  };
88 
89 protected:
90  KviKvsPopupMenuItem(Type t, const QString & szItemName, const QString & szCondition);
91  KviKvsPopupMenuItem(Type t, const QString & szItemName, const KviKvsScript * pCondition);
92 
93 public:
94  virtual ~KviKvsPopupMenuItem();
95 
96 protected:
97  QString m_szItemName;
100 
101 public:
102  // this doesn't trigger errors, only warnings
103  bool evaluateCondition(KviKvsPopupMenuTopLevelData * pData);
104 
105  KviKvsPopupMenuItem::Type type() { return m_eType; };
106 
107  const QString & name() { return m_szItemName; };
108 
109  bool isItem() { return m_eType == Item; };
110  bool isSeparator() { return m_eType == Separator; };
111  bool isLabel() { return m_eType == Label; };
112  bool isExtMenu() { return m_eType == ExtMenu; };
113  bool isMenu() { return m_eType == Menu; };
114 
115  KviKvsScript * kvsCondition() { return m_pKvsCondition; };
116  virtual KviKvsScript * kvsIcon();
117  virtual KviKvsScript * kvsText();
118  virtual KviKvsScript * kvsCode();
119 
120  virtual void fill(KviKvsPopupMenu * pMenu, KviKvsPopupMenuTopLevelData * pData, int iIdx) = 0;
121  virtual void clear();
122  virtual KviKvsPopupMenuItem * clone() const = 0;
123 };
124 
126 {
127  friend class KviKvsPopupMenu;
128 
129 protected:
130  KviKvsPopupMenuItemSeparator(const QString & szItemName, const QString & szCondition);
131  KviKvsPopupMenuItemSeparator(const QString & szItemName, const KviKvsScript * pCondition);
132 
133 public:
134  virtual ~KviKvsPopupMenuItemSeparator();
135 
136 public:
137  virtual void fill(KviKvsPopupMenu * pMenu, KviKvsPopupMenuTopLevelData * pData, int iIdx);
138  virtual KviKvsPopupMenuItem * clone() const;
139 };
140 
142 {
143 protected:
144  KviKvsPopupMenuItemWithTextAndIcon(KviKvsPopupMenuItem::Type t, const QString & szItemName, const QString & szText, const QString & szIcon, const QString & szCondition);
145  KviKvsPopupMenuItemWithTextAndIcon(KviKvsPopupMenuItem::Type t, const QString & szItemName, const KviKvsScript * pText, const KviKvsScript * pIcon, const KviKvsScript * pCondition);
146 
147 public:
149 
150 protected:
153 
154 public:
155  virtual KviKvsScript * kvsIcon();
156  virtual KviKvsScript * kvsText();
157  // this just returns a string, eventually empty
158  QString evaluateText(KviKvsPopupMenuTopLevelData * pData);
159  // this just returns the icon, eventually
160  QPixmap * evaluateIcon(KviKvsPopupMenuTopLevelData * pData);
161 };
162 
164 
165 // this acts as signal relay
167 {
168  Q_OBJECT
170 
171 protected:
174 
175 protected:
177 protected slots:
178  void labelDestroyed();
179 };
180 
182 {
184  friend class KviKvsPopupMenu;
185 
186 protected:
187  KviKvsPopupMenuItemLabel(const QString & szItemName, const QString & szText, const QString & szIcon, const QString & szCondition);
188  KviKvsPopupMenuItemLabel(const QString & szItemName, const KviKvsScript * pText, const KviKvsScript * pIcon, const KviKvsScript * pCondition);
189 
190 public:
191  virtual ~KviKvsPopupMenuItemLabel();
192 
193 protected:
194  QLabel * m_pLabel;
196 
197 public:
198  virtual void fill(KviKvsPopupMenu * pMenu, KviKvsPopupMenuTopLevelData * pData, int iIdx);
199  virtual KviKvsPopupMenuItem * clone() const;
200  virtual void clear();
201 
202 protected:
203  void labelDestroyed();
204 };
205 
207 {
208  friend class KviKvsPopupMenu;
209 
210 protected:
211  KviKvsPopupMenuItemItem(const QString & szItemName, const QString & szCode, const QString & szText, const QString & szIcon, const QString & szCondition);
212  KviKvsPopupMenuItemItem(const QString & szItemName, const KviKvsScript * pCode, const KviKvsScript * pText, const KviKvsScript * pIcon, const KviKvsScript * pCondition);
213 
214 public:
215  virtual ~KviKvsPopupMenuItemItem();
216 
217 protected:
219 
220 protected:
221  virtual KviKvsScript * kvsCode();
222 
223 public:
224  virtual void fill(KviKvsPopupMenu * pMenu, KviKvsPopupMenuTopLevelData * pData, int iIdx);
225  virtual KviKvsPopupMenuItem * clone() const;
226 };
227 
229 {
230  friend class KviKvsPopupMenu;
231 
232 protected:
233  KviKvsPopupMenuItemMenu(const QString & szItemName, KviKvsPopupMenu * pMenu, const QString & szText, const QString & szIcon, const QString & szCondition);
234  KviKvsPopupMenuItemMenu(const QString & szItemName, KviKvsPopupMenu * pMenu, const KviKvsScript * pText, const KviKvsScript * pIcon, const KviKvsScript * pCondition);
235 
236 public:
237  virtual ~KviKvsPopupMenuItemMenu();
238 
239 protected:
241 
242 public:
243  KviKvsPopupMenu * menu() { return m_pMenu; };
244  virtual void fill(KviKvsPopupMenu * pMenu, KviKvsPopupMenuTopLevelData * pData, int iIdx);
245  virtual void clear();
246  virtual KviKvsPopupMenuItem * clone() const;
247 };
248 
250 {
251  friend class KviKvsPopupMenu;
252 
253 protected:
254  KviKvsPopupMenuItemExtMenu(const QString & szItemName, const QString & szMenuName, const QString & szText, const QString & szIcon, const QString & szCondition);
255  KviKvsPopupMenuItemExtMenu(const QString & szItemName, const QString & szMenuName, const KviKvsScript * pText, const KviKvsScript * pIcon, const KviKvsScript * pCondition);
256 
257 public:
258  virtual ~KviKvsPopupMenuItemExtMenu();
259 
260 protected:
261  QString m_szMenuName;
263 public:
264  const QString & extName() { return m_szMenuName; };
265  virtual void fill(KviKvsPopupMenu * pMenu, KviKvsPopupMenuTopLevelData * pData, int iIdx);
266  virtual void clear();
267  virtual KviKvsPopupMenuItem * clone() const;
268 };
269 
270 class KVIRC_API KviKvsPopupMenu : public QMenu
271 {
273  friend class KviKvsPopupManager;
274  friend class KviSinglePopupEditor;
275  Q_OBJECT
276 public:
277  KviKvsPopupMenu(const QString & szName);
278  ~KviKvsPopupMenu();
279 
280 protected:
282 
283 private:
284  QString m_szName;
289  // this is a temporary used to hack-in the activation from KviMenuBar
292 
293 public:
294  const QString & popupName() { return m_szName; };
295  void setPopupName(const QString & szName) { m_szName = szName; };
296  void copyFrom(const KviKvsPopupMenu * src);
297  KviKvsPopupMenuTopLevelData * topLevelData();
298  KviKvsPopupMenu * topLevelPopup();
299  KviPointerList<KviKvsPopupMenuItem> * itemList() { return m_pItemList; };
300  bool isSoftLocked();
301  bool isHardLocked();
303  KviKvsPopupMenu * addPopup(const QString & szItemName, const QString & szText, const QString & szIcon, const QString & szCondition);
304  void addSeparator(const QString & szItemName, const QString & szCondition);
305  void addLabel(const QString & szItemName, const QString & szText, const QString & szIcon, const QString & szCondition);
306  void addItem(const QString & szItemName, const QString & szCode, const QString & szText, const QString & szIcon, const QString & szCondition);
307  void addExtPopup(const QString & szItemName, const QString & szPopupName, const QString & szText, const QString & szIcon, const QString & szCondition);
308  void doPopup(const QPoint & pnt, KviWindow * wnd, KviKvsVariantList * pParams, bool bTestMode = false);
309  bool isEmpty() { return m_pItemList->isEmpty() && m_pPrologues->isEmpty() && m_pEpilogues->isEmpty(); };
310  void doClear();
311  void addPrologue(const QString & szItemName, const QString & szCode);
312  void addEpilogue(const QString & szItemName, const QString & szCode);
313  bool removeItemByName(const QString & szItemName, bool bRecursive);
314  KviKvsPopupMenu * findChildPopupByName(const QString & szItemName);
315  KviPointerList<KviKvsScript> * epilogues() { return m_pEpilogues; };
316  KviPointerList<KviKvsScript> * prologues() { return m_pPrologues; };
317  KviKvsPopupMenu * parentPopup() { return m_pParentPopup; };
318  void generateDefPopup(QString & buffer);
319  void setParentPopup(KviKvsPopupMenu * par) { m_pParentPopup = par; };
320  void generateDefPopupCore(QString & buffer);
321 
322 protected:
323  void addItemInternal(KviKvsPopupMenuItem * it);
324  void executePrologues(KviKvsPopupMenuTopLevelData * pData);
325  void executeEpilogues(KviKvsPopupMenuTopLevelData * pData);
326  void load(const QString & prefix, KviConfigurationFile * cfg);
327  void save(const QString & prefix, KviConfigurationFile * cfg);
328 private slots:
329  void setupMenuContents();
330 
331 protected:
332  void clearMenuContents();
333 protected slots:
334  void itemClicked(QAction * pAction);
335 signals:
336  void testModeItemClicked(KviKvsPopupMenuItem * it);
337 };
338 
339 #endif
KviPointerList< KviKvsScript > * m_pEpilogues
Definition: KviKvsPopupMenu.h:287
Definition: KviKvsPopupMenu.h:41
virtual KviKvsScript * kvsText()
Definition: KviKvsPopupMenu.cpp:93
Definition: KviKvsPopupMenu.h:141
KviPointerList< KviKvsScript > * m_pPrologues
Definition: KviKvsPopupMenu.h:286
KviKvsPopupMenuTopLevelData * m_pTopLevelData
Definition: KviKvsPopupMenu.h:288
Definition: KviKvsPopupMenu.h:50
KviKvsPopupMenuItem::Type type()
Definition: KviKvsPopupMenu.h:105
#define KVIRC_API
Definition: kvi_settings.h:128
Definition: KviKvsPopupMenu.h:51
KviPointerList< KviKvsScript > * prologues()
Definition: KviKvsPopupMenu.h:316
KviKvsExtendedRunTimeData * m_pExtendedRunTimeData
Definition: KviKvsPopupMenu.h:56
KviKvsExtendedRunTimeData * extendedRunTimeData()
Definition: KviKvsPopupMenu.h:63
KviKvsPopupMenuItemLabel * m_pItem
Definition: KviKvsPopupMenu.h:176
virtual KviKvsPopupMenuItem * clone() const =0
Class to handle variant variables lists.
Definition: KviKvsVariantList.h:41
KviKvsPopupMenu * m_pParentPopup
Definition: KviKvsPopupMenu.h:285
The KVIrc Script class.
Definition: KviKvsScript.h:59
friend class KviKvsPopupMenuItemMenu
Definition: KviKvsPopupMenu.h:272
bool isSeparator()
Definition: KviKvsPopupMenu.h:110
Definition: KviConfigurationFile.h:48
KviKvsPopupMenu * m_pMenu
Definition: KviKvsPopupMenu.h:262
QLabel * m_pLabel
Definition: KviKvsPopupMenu.h:194
Definition: KviKvsPopupMenu.h:75
KviKvsVariantList * m_pParameters
Definition: KviKvsPopupMenu.h:57
KviKvsScript * m_pKvsCondition
Definition: KviKvsPopupMenu.h:99
KviKvsScript * kvsCondition()
Definition: KviKvsPopupMenu.h:115
virtual void fill(KviKvsPopupMenu *pMenu, KviKvsPopupMenuTopLevelData *pData, int iIdx)=0
Type
Definition: KviKvsPopupMenu.h:80
KviKvsPopupMenu * menu()
Definition: KviKvsPopupMenu.h:243
Definition: KviKvsPopupMenu.h:206
QString m_szName
Definition: KviKvsPopupMenu.h:284
const QString & extName()
Definition: KviKvsPopupMenu.h:264
void setParentPopup(KviKvsPopupMenu *par)
Definition: KviKvsPopupMenu.h:319
KVIrc Script manager.
KviKvsScript * m_pKvsIcon
Definition: KviKvsPopupMenu.h:152
Definition: KviKvsRunTimeContext.h:43
btnDict clear()
Definition: KviKvsPopupMenu.h:85
bool isItem()
Definition: KviKvsPopupMenu.h:109
const QString & popupName()
Definition: KviKvsPopupMenu.h:294
const QString & name()
Definition: KviKvsPopupMenu.h:107
Definition: KviKvsPopupMenu.h:249
virtual KviKvsScript * kvsIcon()
Definition: KviKvsPopupMenu.cpp:88
Definition: KviKvsPopupMenu.h:84
KviPointerList< KviKvsPopupMenuItem > * m_pItemList
Definition: KviKvsPopupMenu.h:281
void setTestMode(bool bTestMode)
Definition: KviKvsPopupMenu.h:72
LockStatus
Definition: KviKvsPopupMenu.h:48
bool save(KviThemeInfo &options, bool bSaveIcons)
Definition: KviOptions.cpp:986
bool isHardLocked()
Definition: KviKvsPopupMenu.h:67
void setLocked(LockStatus eLocked)
Definition: KviKvsPopupMenu.h:68
virtual void clear()
Definition: KviKvsPopupMenu.cpp:84
Definition: KviKvsPopupMenu.h:83
bool isExtMenu()
Definition: KviKvsPopupMenu.h:112
Definition: KviKvsPopupMenu.h:270
bool testMode()
Definition: KviKvsPopupMenu.h:71
KviPointerList< KviKvsScript > * epilogues()
Definition: KviKvsPopupMenu.h:315
friend class KviKvsPopupMenuItemLabelHelper
Definition: KviKvsPopupMenu.h:183
void labelDestroyed()
Definition: KviKvsPopupMenu.cpp:294
QHashIterator< int, QFile * > t(getDict)
KviKvsPopupMenu * m_pMenu
Definition: KviKvsPopupMenu.h:240
Definition: KviKvsPopupMenu.h:125
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
KviKvsScript * m_pKvsCode
Definition: KviKvsPopupMenu.h:218
QString m_szItemName
Definition: KviKvsPopupMenu.h:97
Definition: KviKvsPopupManager.h:30
void setPopupName(const QString &szName)
Definition: KviKvsPopupMenu.h:295
KviKvsPopupMenu * parentPopup()
Definition: KviKvsPopupMenu.h:317
KviKvsPopupMenuItemLabelHelper * m_pSignalRelay
Definition: KviKvsPopupMenu.h:195
KviPointerList< KviKvsPopupMenuItem > * itemList()
Definition: KviKvsPopupMenu.h:299
bool isLabel()
Definition: KviKvsPopupMenu.h:111
KviKvsScript * m_pKvsText
Definition: KviKvsPopupMenu.h:151
Definition: KviKvsPopupMenu.h:181
KviWindow * m_pWindow
Definition: KviKvsPopupMenu.h:58
void setWindow(KviWindow *pWindow)
Definition: KviKvsPopupMenu.h:70
Parser class to handle variant variables lists.
bool isSoftLocked()
Definition: KviKvsPopupMenu.h:66
KviKvsPopupMenuTopLevelData * m_pTempTopLevelData
Definition: KviKvsPopupMenu.h:290
Contains the KviWindow class.
Definition: KviKvsPopupMenu.h:82
bool m_bTestMode
Definition: KviKvsPopupMenu.h:60
Type m_eType
Definition: KviKvsPopupMenu.h:98
Definition: KviKvsPopupMenu.h:166
bool isEmpty()
Definition: KviKvsPopupMenu.h:309
KviKvsVariantList * parameters()
Definition: KviKvsPopupMenu.h:65
QString m_szMenuName
Definition: KviKvsPopupMenu.h:261
Handling of hash data type in KVS.
KviWindow * window()
Definition: KviKvsPopupMenu.h:69
This file contains compile time settings.
bool isMenu()
Definition: KviKvsPopupMenu.h:113
bool m_bSetupDone
Definition: KviKvsPopupMenu.h:291
Helper functions for the QString class.
virtual KviKvsScript * kvsCode()
Definition: KviKvsPopupMenu.cpp:98
Definition: KviKvsPopupMenu.h:228
LockStatus m_eLocked
Definition: KviKvsPopupMenu.h:59