~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kicker/extensions/kasbar/kasbar.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c++ -*-
 
2
 
 
3
/* kasbar.h
 
4
**
 
5
** Copyright (C) 2001-2004 Richard Moore <rich@kde.org>
 
6
** Contributor: Mosfet
 
7
**     All rights reserved.
 
8
**
 
9
** KasBar is dual-licensed: you can choose the GPL or the BSD license.
 
10
** Short forms of both licenses are included below.
 
11
*/
 
12
 
 
13
/*
 
14
** This program is free software; you can redistribute it and/or modify
 
15
** it under the terms of the GNU General Public License as published by
 
16
** the Free Software Foundation; either version 2 of the License, or
 
17
** (at your option) any later version.
 
18
**
 
19
** This program is distributed in the hope that it will be useful,
 
20
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
22
** GNU General Public License for more details.
 
23
**
 
24
** You should have received a copy of the GNU General Public License
 
25
** along with this program in a file called COPYING; if not, write to
 
26
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
27
** MA 02110-1301, USA.
 
28
*/
 
29
 
 
30
/*
 
31
** Redistribution and use in source and binary forms, with or without
 
32
** modification, are permitted provided that the following conditions
 
33
** are met:
 
34
** 1. Redistributions of source code must retain the above copyright
 
35
**    notice, this list of conditions and the following disclaimer.
 
36
** 2. Redistributions in binary form must reproduce the above copyright
 
37
**    notice, this list of conditions and the following disclaimer in the
 
38
**    documentation and/or other materials provided with the distribution.
 
39
**
 
40
** THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 
41
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
42
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
43
** ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
44
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
45
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
46
** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
47
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
48
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
49
** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
50
** SUCH DAMAGE.
 
51
*/
 
52
 
 
53
/*
 
54
** Bug reports and questions can be sent to kde-devel@kde.org
 
55
*/
 
56
// -*- c++ -*-
 
57
 
 
58
 
 
59
#ifndef __KASBAR_H
 
60
#define __KASBAR_H
 
61
 
 
62
#include <QWidget>
 
63
#include <QPoint>
 
64
#include <Qt3Support/Q3PtrList>
 
65
#include <QLayout>
 
66
#include <QtCore/QCOORD>
 
67
//Added by qt3to4:
 
68
#include <QPixmap>
 
69
#include <QPaintEvent>
 
70
#include <QDragMoveEvent>
 
71
#include <QBoxLayout>
 
72
#include <QResizeEvent>
 
73
#include <QMouseEvent>
 
74
 
 
75
#include "kasresources.h"
 
76
 
 
77
class KasItem;
 
78
class KasResources;
 
79
 
 
80
typedef Q3PtrList<KasItem> KasItemList;
 
81
 
 
82
 
 
83
/**
 
84
 * The main view for KasBar.
 
85
 */
 
86
class KDE_EXPORT KasBar : public QWidget
 
87
{
 
88
   Q_OBJECT
 
89
   Q_PROPERTY( int maxBoxes READ maxBoxes )
 
90
   Q_PROPERTY( uint boxesPerLine READ boxesPerLine )
 
91
   Q_PROPERTY( Direction direction READ direction )
 
92
   Q_PROPERTY( Qt::Orientation orientation READ orientation )
 
93
   Q_PROPERTY( bool masked READ isMasked )
 
94
   Q_ENUMS( Direction )
 
95
 
 
96
   friend class KasItem;
 
97
public:
 
98
   KasBar( Qt::Orientation o, QWidget *parent=0, const char *name=0, Qt::WFlags f=0 );
 
99
   KasBar( Qt::Orientation o, KasBar *master, 
 
100
           QWidget* parent=0, const char* name=0, Qt::WFlags f=0 );
 
101
 
 
102
   virtual ~KasBar();
 
103
 
 
104
   typedef QBoxLayout::Direction Direction;
 
105
 
 
106
   /** Returns true iff this is a top-level bar. This is unrelated to it being a top-level widget. */
 
107
   bool isTopLevel() const { return !master_; }
 
108
 
 
109
   /** Returns the bar from which this bar inherits its settings (or 0 if this is the top-level bar). */
 
110
   KasBar *master() const { return master_; }
 
111
 
 
112
   /** Creates a child bar of the kasbar. The child will inherit the appearance options. */
 
113
   virtual KasBar *createChildBar( Qt::Orientation o, QWidget *parent, const char *name=0 );
 
114
 
 
115
   /** Factory method that returns the singleton resources object. */
 
116
   virtual KasResources *resources();
 
117
 
 
118
   /** Returns true iff we have a resources object. */
 
119
   bool hasResources() const { return (res ? true : false); }
 
120
 
 
121
   //
 
122
   // Item management
 
123
   //
 
124
   void append( KasItem *i );
 
125
   void insert( int index, KasItem *i );
 
126
   void remove( KasItem *i );
 
127
   void clear();
 
128
   KasItem *take( KasItem *i ) { return items.take( indexOf(i) ); }
 
129
   KasItem *itemAt( uint i ) { return items.at( i ); }
 
130
   int indexOf( KasItem *i ) { return items.find( i ); }
 
131
 
 
132
   KasItemList *itemList() { return &items; }
 
133
 
 
134
   //
 
135
   // Layout options.
 
136
   //
 
137
 
 
138
   /** The possible item sizes. */
 
139
   enum ItemSize { Enormous, Huge, Large, Medium, Small, Custom };
 
140
 
 
141
   int itemSize() const { return itemSize_; }
 
142
   int itemExtent() const { return itemExtent_; }
 
143
 
 
144
   /** The number of items in the bar. */
 
145
   unsigned int itemCount() const { return items.count(); }
 
146
 
 
147
   int maxBoxes() const { return maxBoxes_; }
 
148
   uint boxesPerLine() const { return boxesPerLine_; }
 
149
 
 
150
   void setOrientation( Qt::Orientation o );
 
151
   Qt::Orientation orientation() const { return orient; }
 
152
 
 
153
   void setDirection( Direction dir );
 
154
   Direction direction() const { return direction_; }
 
155
 
 
156
   bool isDetached() const { return detached; }
 
157
   QPoint detachedPosition() const { return detachedPos; }
 
158
 
 
159
   bool isDrag() const { return inDrag; }
 
160
 
 
161
   QSize sizeHint( Qt::Orientation,  QSize max );
 
162
 
 
163
   //
 
164
   // Look and feel options
 
165
   //
 
166
 
 
167
   bool isMasked() const { return useMask_; }
 
168
 
 
169
   /** Is transparency enabled? */
 
170
   bool isTransparent() const { return transparent_; }
 
171
 
 
172
   /** Is tinting enabled? */
 
173
   bool hasTint() const { return enableTint_; }
 
174
 
 
175
   /** Sets the amount and color of the tint. */
 
176
   void setTint( double amount, QColor color );
 
177
 
 
178
   /** Sets the amount of tinting. */
 
179
   void setTintAmount( double amount ) { setTint( amount, tintColour_ ); }
 
180
 
 
181
   /** Get the amount of tinting. */
 
182
   double tintAmount() const { return tintAmount_; }
 
183
 
 
184
   /** Get the color of the tint. */
 
185
   QColor tintColor() const { return tintColour_; }
 
186
 
 
187
   /** Returns true iff we will paint frames around inactive items. */
 
188
   bool paintInactiveFrames() const { return paintInactiveFrame_; }
 
189
 
 
190
   //
 
191
   // Utilities
 
192
   //
 
193
 
 
194
   void updateItem( KasItem *i );
 
195
 
 
196
   /** Redraws the specified item. */
 
197
   void repaintItem(KasItem *i, bool erase = true );
 
198
 
 
199
   /** Returns the item at p or 0. */
 
200
   KasItem* itemAt(const QPoint &p);
 
201
 
 
202
   /** Get the position of the specified item. */
 
203
    QPoint itemPos( KasItem *i );
 
204
 
 
205
   /** The item under the mouse pointer (or 0). */
 
206
   KasItem *itemUnderMouse() const { return itemUnderMouse_; }
 
207
 
 
208
public Q_SLOTS:
 
209
   //
 
210
   // Layout slots
 
211
   //
 
212
   void setMaxBoxes( int count );
 
213
   void setBoxesPerLine( int count );
 
214
 
 
215
   void setItemSize( int size );
 
216
   void setItemExtent( int size );
 
217
   void setDetachedPosition( const QPoint &pos );
 
218
 
 
219
   virtual void updateLayout();
 
220
 
 
221
   void updateMouseOver();
 
222
   void updateMouseOver( QPoint pos );
 
223
 
 
224
   /** Enable or disable tinting. */
 
225
   void setTint( bool enable );
 
226
 
 
227
   /** Enable or disable transparency. */
 
228
   void setTransparent( bool enable );
 
229
 
 
230
   /** Set the color of the tint. */
 
231
   void setTintColor( const QColor &c );
 
232
 
 
233
   /** Set the strength of the tint (as a percentage). */
 
234
   void setTintAmount( int percent );
 
235
 
 
236
   void setBackground( const QPixmap &pix );
 
237
 
 
238
   void setMasked( bool mask );
 
239
 
 
240
   void setPaintInactiveFrames( bool enable );
 
241
 
 
242
   void toggleOrientation();
 
243
   void toggleDetached();
 
244
   void setDetached( bool detach );
 
245
 
 
246
    /** Rereads the configuration of the master Kasbar. */
 
247
    virtual void rereadMaster();
 
248
 
 
249
    virtual void addTestItems();
 
250
 
 
251
Q_SIGNALS:
 
252
 
 
253
   void detachedChanged( bool );
 
254
   void detachedPositionChanged( const QPoint & );
 
255
   void dragStarted();
 
256
 
 
257
   void directionChanged();
 
258
 
 
259
   /** Emitted when kasbar wants to resize. This happens when a new window is added. */
 
260
   void layoutChanged();
 
261
 
 
262
   /** Emitted when the item size is changed. */
 
263
   void itemSizeChanged( int );
 
264
 
 
265
   void configChanged();
 
266
 
 
267
protected:
 
268
   /** Displays the popup menus, hides/shows windows. */
 
269
   void mousePressEvent(QMouseEvent *ev);
 
270
 
 
271
   /** Displays the popup menus, hides/shows windows. */
 
272
   void mouseReleaseEvent(QMouseEvent *ev);
 
273
 
 
274
   /** Overridden to implement the mouse-over highlight effect. */
 
275
   void mouseMoveEvent(QMouseEvent *ev);
 
276
 
 
277
   /** Overridden to implement the drag-over task switching. */
 
278
   void dragMoveEvent(QDragMoveEvent *ev);
 
279
 
 
280
   /** Paints the background of the item to the painter. */
 
281
   void paintBackground( QPainter *p, const QRect &r );
 
282
 
 
283
   /** Calls the paint methods for the items in the rectangle specified by the event. */
 
284
   void paintEvent(QPaintEvent *ev);
 
285
 
 
286
   /** Forces the widget to re-layout it's contents. */
 
287
   void resizeEvent(QResizeEvent *ev);
 
288
 
 
289
private:
 
290
   // Core data
 
291
   QPixmap offscreen;
 
292
   KasBar *master_;
 
293
   KasItemList items;
 
294
   Qt::Orientation orient;
 
295
   Direction direction_;
 
296
   KasItem *itemUnderMouse_;
 
297
   uint boxesPerLine_;
 
298
   QPoint pressPos;
 
299
   bool inDrag;
 
300
   bool detached;
 
301
   int maxBoxes_;
 
302
   int itemSize_;
 
303
   int itemExtent_;
 
304
   QPoint detachedPos;
 
305
   bool paintInactiveFrame_;
 
306
 
 
307
   // Implements pseudo-transparency
 
308
   bool transparent_;
 
309
   KPixmap bg;
 
310
   bool enableTint_;
 
311
   double tintAmount_;
 
312
   QColor tintColour_;
 
313
   bool useMask_;
 
314
 
 
315
   // Look and feel resources
 
316
   KasResources *res;
 
317
};
 
318
 
 
319
 
 
320
 
 
321
#endif