1 #ifndef _KVI_WINDOWLIST_H_
2 #define _KVI_WINDOWLIST_H_
3 //=============================================================================
4 //
5 //   File : KviWindowListBase.h
6 //   Creation date : Thu Jan 7 1999 03:56:50 by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 1999-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 "KviPointerList.h"
29 #include "KviTalToolTip.h"
30 
31 #include <QPushButton>
32 #include <QToolButton>
33 #include <QBoxLayout>
34 #include <QFrame>
35 #include <QDockWidget>
36 
37 class QPixmap;
38 class KviWindow;
39 class KviMainWindow;
40 class KviDynamicToolTip;
41 class KviConsoleWindow;
42 
43 //
44 // KviWindowListItem
45 // The base class for the WindowList items
46 // this is the only interface to an item visible to external classes
47 //
48 
49 class KVIRC_API KviWindowListItem
50 {
51 public:
52 	KviWindowListItem(KviWindow * wnd);
53 	virtual ~KviWindowListItem();
54 
55 protected:
56 	KviWindow * m_pWindow;
57 	int m_iHighlightLevel;
58 	int m_iProgress;
59 
60 public:
kviWindow()61 	KviWindow * kviWindow() { return m_pWindow; };
captionChanged()62 	virtual void captionChanged(){};
highlight(int)63 	virtual void highlight(int){};
setProgress(int)64 	virtual void setProgress(int){};
active()65 	virtual bool active() { return false; };
unhighlight()66 	virtual void unhighlight(){};
progress()67 	int progress() { return m_iProgress; };
highlightLevel()68 	int highlightLevel() { return m_iHighlightLevel; };
69 };
70 
71 //
72 // KviWindowListBase
73 // The base class for the WindowList implementations
74 // This is the basic interface that all the external classes should see
75 //
76 
77 class KVIRC_API KviWindowListBase : public QDockWidget
78 {
79 	Q_OBJECT
80 public:
81 	KviWindowListBase();
82 	~KviWindowListBase();
83 
84 protected:
85 	KviMainWindow * m_pFrm;
86 	QTimer * m_pActivityMeterTimer;
87 	QWidget * m_pTitleWidget;
88 	Qt::DockWidgetArea currentArea;
89 
90 public:
addItem(KviWindow *)91 	virtual KviWindowListItem * addItem(KviWindow *) { return nullptr; }
removeItem(KviWindowListItem *)92 	virtual bool removeItem(KviWindowListItem *) { return false; };
setActiveItem(KviWindowListItem *)93 	virtual void setActiveItem(KviWindowListItem *){};
firstItem()94 	virtual KviWindowListItem * firstItem() { return nullptr; }
lastItem(void)95 	virtual KviWindowListItem * lastItem(void) { return nullptr; }
nextItem()96 	virtual KviWindowListItem * nextItem() { return nullptr; }
prevItem(void)97 	virtual KviWindowListItem * prevItem(void) { return nullptr; }
98 	virtual KviWindowListItem * item(int number);
setIterationPointer(KviWindowListItem *)99 	virtual bool setIterationPointer(KviWindowListItem *) { return false; };
100 	virtual void switchWindow(bool bNext, bool bInContextOnly, bool bHighlightedOnly = false);
updatePseudoTransparency()101 	virtual void updatePseudoTransparency(){};
102 	virtual void applyOptions();
103 	void wheelEvent(QWheelEvent * e) override;
104 	static void getTextForConsole(QString & szText, KviConsoleWindow * pConsole);
currentDockArea()105 	Qt::DockWidgetArea currentDockArea() { return currentArea; };
106 protected slots:
107 	virtual void updateActivityMeter();
108 	void updateDockLocation(Qt::DockWidgetArea newArea);
109 };
110 
111 //
112 // Implementation details: the following classes should be
113 // never used directly (with just the exception of KviMainWindow
114 // that creates the WindowList)
115 //
116 
117 class KviClassicWindowList;
118 
119 //
120 // KviWindowListButton
121 // Button to show/hide the window and containing the button to close it
122 //
123 
124 class KVIRC_API KviWindowListButton : public QPushButton, KviWindowListItem
125 {
126 	friend class KviClassicWindowList;
127 	friend class KviClassicWindowListToolButton;
128 	Q_OBJECT
129 public:
130 	KviWindowListButton(QWidget * par, KviWindow * wnd, const char * name);
131 	~KviWindowListButton();
132 
133 protected:
134 	bool m_bActive;
135 	QBoxLayout * m_pLayout;
136 	QToolButton * m_pTool;
137 	KviDynamicToolTip * m_pTip;
138 
139 protected:
140 	void mousePressEvent(QMouseEvent * e) override;
141 	void contextMenuEvent(QContextMenuEvent * e) override;
142 	virtual void drawButtonLabel(QPainter * p);
143 	void paintEvent(QPaintEvent * e) override;
144 
145 public:
active()146 	bool active() override { return m_bActive; }
147 	void highlight(int iLevel = 1) override;
148 	void unhighlight() override;
149 	void setProgress(int progress) override;
150 	void captionChanged() override;
151 
152 protected:
153 	void setActive(bool bActive);
154 protected slots:
155 	void tipRequest(KviDynamicToolTip * tip, const QPoint & pnt);
156 };
157 
158 //
159 // KviClassicWindowListToolButton
160 // Button to close the window
161 //
162 
163 class KVIRC_API KviClassicWindowListToolButton : public QToolButton
164 {
165 	Q_OBJECT
166 protected:
167 	KviWindowListButton * m_pPar;
168 
169 public:
170 	KviClassicWindowListToolButton(KviWindowListButton * par);
~KviClassicWindowListToolButton()171 	~KviClassicWindowListToolButton() {};
172 
173 protected:
174 	void mousePressEvent(QMouseEvent *e) override;
175 
176 public:
177 	QSize sizeHint() const override;
178 };
179 
180 class KVIRC_API KviClassicWindowList : public KviWindowListBase
181 {
182 	Q_OBJECT
183 public:
184 	KviClassicWindowList();
185 	~KviClassicWindowList();
186 
187 protected:
188 	KviPointerList<KviWindowListButton> * m_pButtonList;
189 	int m_iButtonHeight;
190 	QWidget * m_pBase;
191 
192 protected:
193 	void calcButtonHeight();
194 	void insertButton(KviWindowListButton * b);
195 
196 public:
197 	void resizeEvent(QResizeEvent * e) override;
198 
199 public:
200 	KviWindowListItem * addItem(KviWindow *) override;
201 	bool removeItem(KviWindowListItem *) override;
202 	void setActiveItem(KviWindowListItem *) override;
203 	KviWindowListItem * firstItem() override;
204 	KviWindowListItem * lastItem(void) override;
205 	KviWindowListItem * nextItem() override;
206 	KviWindowListItem * prevItem(void) override;
207 	bool setIterationPointer(KviWindowListItem * it) override;
208 	void updateActivityMeter() override;
209 	void applyOptions() override;
210 protected slots:
211 	void orientationChangedSlot(Qt::Orientation o);
212 	void doLayout();
213 };
214 
215 class KVIRC_API KviWindowListTitleWidget : public QWidget
216 {
217 	Q_OBJECT
218 public:
KviWindowListTitleWidget(KviWindowListBase * parent)219 	KviWindowListTitleWidget(KviWindowListBase * parent) { m_pParent = parent; };
~KviWindowListTitleWidget()220 	~KviWindowListTitleWidget(){};
221 
222 private:
223 	KviWindowListBase * m_pParent;
224 
225 public:
226 	QSize sizeHint() const override;
227 	void paintEvent(QPaintEvent *) override;
228 };
229 
230 #endif //_KVI_WINDOWLIST_H_
231