1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
/* kasitem.h
**
** Copyright (C) 2001-2004 Richard Moore <rich@kde.org>
** Contributor: Mosfet
** All rights reserved.
**
** KasBar is dual-licensed: you can choose the GPL or the BSD license.
** Short forms of both licenses are included below.
*/
/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/
/*
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
*/
/*
** Bug reports and questions can be sent to kde-devel@kde.org
*/
#ifndef KASITEM_H
#define KASITEM_H
class TQPainter;
class TQMouseEvent;
class KasPopup;
#include <tqobject.h>
#include <tqguardedptr.h>
#include <tqpoint.h>
#include <tqvaluevector.h>
#include <tqapplication.h>
#include <kdemacros.h>
#include "kasbar.h"
/**
* Abstract base class for items that can be in a KasBar.
*
* @author Richard Moore, rich@kde.org
*/
class TDE_EXPORT KasItem : public TQObject
{
TQ_OBJECT
public:
friend class KasBar;
typedef TQValueVector<TQPixmap> PixmapList;
/** The states that a window can be in. */
enum WindowState {
StateIcon, StateShaded, StateNormal
};
KasItem( KasBar *parent );
virtual ~KasItem();
/** Returns the parent KasBar of this item. */
KasBar *kasbar() const { return kas; }
/** Returns the size of the item in pixels. */
int extent() const { return kas->itemExtent(); }
/** Returns the text that will be displayed in the title. */
TQString text() const { return title; }
/** Returns the position of this item. */
TQPoint pos() const { return pos_; }
void setPos( const TQPoint &p ) { pos_ = p; }
void setPos( int x, int y ) { pos_ = TQPoint( x, y ); }
/** Returns the progress so far. This will -1 if the item is not displaying progress info. */
int progress() const { return prog; }
/** Returns true iff this item is displaying progress info. */
bool isProgressItem() const { return prog != -1; }
/** Returns true iff this item will display the modified indicator. */
bool isModified() const { return modified; }
/**
* Returns true if this is a group item. Group items display an arrow
* showing where the popup containing their children will appear.
*/
void setGroupItem( bool enable = true ) { groupItem = enable; }
//
// Popup
//
/** Returns true iff this item is showing a popup. */
bool isShowingPopup() const;
/** Returns the active popup or 0. */
KasPopup *popup() const { return pop; }
/** Sets the popup to be used by this item. */
void setPopup( KasPopup *popup );
/**
* Returns true iff this item uses a custom popup policy. If this flag is
* set, the default popup behaviour is disabled. This means you must call
* show/hide/toggle yourself if you want the popup to be shown.
*/
bool hasCustomPopup() const { return customPopup; }
/** Enables or disables custom popup handling. */
void setCustomPopup( bool enable = true ) { customPopup = enable; }
//
// Drawing Methods
//
/** Translates the TQPainter then calls paintItem(). */
void paint( TQPainter *p, int x, int y );
/**
* Subclasses should reimplement this method to paint themselves. The painter is setup so
* that the item is always at 0, 0.
*/
virtual void paint( TQPainter *p );
/** Draw a standard frame for the item. */
void paintFrame( TQPainter *p );
/** Paint the background. */
void paintBackground( TQPainter *p );
/** Draw the label for the item. */
void paintLabel( TQPainter *p );
void paintIcon( TQPainter *p );
void paintModified( TQPainter *p );
public slots:
void repaint();
void repaint( bool erase );
void update();
void setActive( bool yes );
void setText( const TQString &title );
void setIcon( const TQPixmap &icon );
void setProgress( int percent );
void setShowFrame( bool yes );
void setModified( bool yes );
void setAttention( bool yes );
void setAnimation( const PixmapList &frames );
void setShowAnimation( bool yes );
void advanceAnimation();
void setLockPopup( bool yes ) { lockPopup = yes; }
/** Shows the items popup. */
void showPopup();
/** Hides the items popup. */
void hidePopup();
/** Check if the popup should be visible. */
void checkPopup();
/** Hides or shows the popup. */
void togglePopup();
/**
* Called when something being dragged is held over the item for a while.
*/
virtual void dragOverAction() {}
signals:
void leftButtonClicked( TQMouseEvent *ev );
void middleButtonClicked( TQMouseEvent *ev );
void rightButtonClicked( TQMouseEvent *ev );
protected:
KasResources *resources() { return kas->resources(); }
/** Gets the font metrics from the parent. */
TQFontMetrics fontMetrics() const { return kas->fontMetrics(); }
/** Gets the color group from the parent. */
const TQColorGroup &colorGroup() const { return kas->colorGroup(); }
/** Factory method that creates a popup widget for the item. */
virtual KasPopup *createPopup();
/** Draw a label with an arrow, the parameters specify the position and size of the arrow. */
void paintArrowLabel( TQPainter *p, int arrowSize, bool arrowOnLeft );
/** Paints a progress graph. */
void paintProgress( TQPainter *p, int percent );
void paintStateIcon( TQPainter *p, uint state );
void paintAttention( TQPainter *p );
void paintAnimation( TQPainter *p );
//
// Event Handlers
//
/** Called when the item receives a mouse event. */
virtual void mousePressEvent( TQMouseEvent * ) {}
/** Called when the item receives a mouse event. */
virtual void mouseReleaseEvent( TQMouseEvent * );
/** Called when the mouse enters the item. */
virtual void mouseEnter();
/** Called when the mouse leaves the item. */
virtual void mouseLeave();
/** Called when a drag enters the item. */
virtual void dragEnter();
/** Called when a drag leaves the item. */
virtual void dragLeave();
private:
KasBar *kas;
TQGuardedPtr<KasPopup> pop;
TQTimer *popupTimer;
TQTimer *dragTimer;
TQPoint pos_;
TQString title;
TQPixmap pix;
bool mouseOver;
bool activated;
bool customPopup;
bool lockPopup;
bool groupItem;
bool frame;
bool modified;
bool attention_;
int prog;
PixmapList anim;
uint aniFrame;
bool drawAnim;
};
#endif // KASITEM_H
|