~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-04-05 05:22:13 UTC
  • mfrom: (0.4.2 experimental) (0.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20090405052213-39thr4l6p2ss07uj
Tags: 4:4.2.2-1
* New upstream release:
  - khtml fixes. (Closes: #290285, #359680)
  - Default konsole sessions can be deleted. (Closes: #286342)
  - Tag widget uses standard application palette. (Closes: #444800)
  - ... and surely many more but we have lost track...

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.h>
63
 
#include <qpoint.h>
64
 
#include <qptrlist.h>
65
 
#include <qlayout.h>
66
 
 
67
 
#include "kasresources.h"
68
 
 
69
 
class KRootPixmap;
70
 
 
71
 
class KasItem;
72
 
class KasResources;
73
 
 
74
 
typedef QPtrList<KasItem> KasItemList;
75
 
 
76
 
 
77
 
/**
78
 
 * The main view for KasBar.
79
 
 */
80
 
class KDE_EXPORT KasBar : public QWidget
81
 
{
82
 
   Q_OBJECT
83
 
   Q_PROPERTY( int maxBoxes READ maxBoxes )
84
 
   Q_PROPERTY( uint boxesPerLine READ boxesPerLine )
85
 
   Q_PROPERTY( Direction direction READ direction )
86
 
   Q_PROPERTY( Orientation orientation READ orientation )
87
 
   Q_PROPERTY( bool masked READ isMasked )
88
 
   Q_ENUMS( Direction )
89
 
 
90
 
   friend class KasItem;
91
 
public:
92
 
   KasBar( Orientation o, QWidget *parent=0, const char *name=0, WFlags f=0 );
93
 
   KasBar( Orientation o, KasBar *master, 
94
 
           QWidget* parent=0, const char* name=0, WFlags f=0 );
95
 
 
96
 
   virtual ~KasBar();
97
 
 
98
 
   typedef QBoxLayout::Direction Direction;
99
 
 
100
 
   /** Returns true iff this is a top-level bar. This is unrelated to it being a top-level widget. */
101
 
   bool isTopLevel() const { return !master_; }
102
 
 
103
 
   /** Returns the bar from which this bar inherits its settings (or 0 if this is the top-level bar). */
104
 
   KasBar *master() const { return master_; }
105
 
 
106
 
   /** Creates a child bar of the kasbar. The child will inherit the appearance options. */
107
 
   virtual KasBar *createChildBar( Orientation o, QWidget *parent, const char *name=0 );
108
 
 
109
 
   /** Factory method that returns the singleton resources object. */
110
 
   virtual KasResources *resources();
111
 
 
112
 
   /** Returns true iff we have a resources object. */
113
 
   bool hasResources() const { return (res ? true : false); }
114
 
 
115
 
   //
116
 
   // Item management
117
 
   //
118
 
   void append( KasItem *i );
119
 
   void insert( int index, KasItem *i );
120
 
   void remove( KasItem *i );
121
 
   void clear();
122
 
   KasItem *take( KasItem *i ) { return items.take( indexOf(i) ); }
123
 
   KasItem *itemAt( uint i ) { return items.at( i ); }
124
 
   int indexOf( KasItem *i ) { return items.find( i ); }
125
 
 
126
 
   KasItemList *itemList() { return &items; }
127
 
 
128
 
   //
129
 
   // Layout options.
130
 
   //
131
 
 
132
 
   /** The possible item sizes. */
133
 
   enum ItemSize { Enormous, Huge, Large, Medium, Small, Custom };
134
 
 
135
 
   int itemSize() const { return itemSize_; }
136
 
   int itemExtent() const { return itemExtent_; }
137
 
 
138
 
   /** The number of items in the bar. */
139
 
   unsigned int itemCount() const { return items.count(); }
140
 
 
141
 
   int maxBoxes() const { return maxBoxes_; }
142
 
   uint boxesPerLine() const { return boxesPerLine_; }
143
 
 
144
 
   void setOrientation( Orientation o );
145
 
   Orientation orientation() const { return orient; }
146
 
 
147
 
   void setDirection( Direction dir );
148
 
   Direction direction() const { return direction_; }
149
 
 
150
 
   bool isDetached() const { return detached; }
151
 
   QPoint detachedPosition() const { return detachedPos; }
152
 
 
153
 
   bool isDrag() const { return inDrag; }
154
 
 
155
 
   QSize sizeHint( Orientation,  QSize max );
156
 
 
157
 
   //
158
 
   // Look and feel options
159
 
   //
160
 
 
161
 
   bool isMasked() const { return useMask_; }
162
 
 
163
 
   /** Is transparency enabled? */
164
 
   bool isTransparent() const { return transparent_; }
165
 
 
166
 
   /** Is tinting enabled? */
167
 
   bool hasTint() const { return enableTint_; }
168
 
 
169
 
   /** Sets the amount and color of the tint. */
170
 
   void setTint( double amount, QColor color );
171
 
 
172
 
   /** Sets the amount of tinting. */
173
 
   void setTintAmount( double amount ) { setTint( amount, tintColour_ ); }
174
 
 
175
 
   /** Get the amount of tinting. */
176
 
   double tintAmount() const { return tintAmount_; }
177
 
 
178
 
   /** Get the color of the tint. */
179
 
   QColor tintColor() const { return tintColour_; }
180
 
 
181
 
   /** Returns true iff we will paint frames around inactive items. */
182
 
   bool paintInactiveFrames() const { return paintInactiveFrame_; }
183
 
 
184
 
   //
185
 
   // Utilities
186
 
   //
187
 
 
188
 
   void updateItem( KasItem *i );
189
 
 
190
 
   /** Redraws the specified item. */
191
 
   void repaintItem(KasItem *i, bool erase = true );
192
 
 
193
 
   /** Returns the item at p or 0. */
194
 
   KasItem* itemAt(const QPoint &p);
195
 
 
196
 
   /** Get the position of the specified item. */
197
 
    QPoint itemPos( KasItem *i );
198
 
 
199
 
   /** The item under the mouse pointer (or 0). */
200
 
   KasItem *itemUnderMouse() const { return itemUnderMouse_; }
201
 
 
202
 
public slots:
203
 
   //
204
 
   // Layout slots
205
 
   //
206
 
   void setMaxBoxes( int count );
207
 
   void setBoxesPerLine( int count );
208
 
 
209
 
   void setItemSize( int size );
210
 
   void setItemExtent( int size );
211
 
   void setDetachedPosition( const QPoint &pos );
212
 
 
213
 
   virtual void updateLayout();
214
 
 
215
 
   void updateMouseOver();
216
 
   void updateMouseOver( QPoint pos );
217
 
 
218
 
   /** Enable or disable tinting. */
219
 
   void setTint( bool enable );
220
 
 
221
 
   /** Enable or disable transparency. */
222
 
   void setTransparent( bool enable );
223
 
 
224
 
   /** Set the color of the tint. */
225
 
   void setTintColor( const QColor &c );
226
 
 
227
 
   /** Set the strength of the tint (as a percentage). */
228
 
   void setTintAmount( int percent );
229
 
 
230
 
   void setBackground( const QPixmap &pix );
231
 
 
232
 
   void setMasked( bool mask );
233
 
 
234
 
   void setPaintInactiveFrames( bool enable );
235
 
 
236
 
   void toggleOrientation();
237
 
   void toggleDetached();
238
 
   void setDetached( bool detach );
239
 
 
240
 
    /** Rereads the configuration of the master Kasbar. */
241
 
    virtual void rereadMaster();
242
 
 
243
 
    virtual void addTestItems();
244
 
 
245
 
signals:
246
 
 
247
 
   void detachedChanged( bool );
248
 
   void detachedPositionChanged( const QPoint & );
249
 
   void dragStarted();
250
 
 
251
 
   void directionChanged();
252
 
 
253
 
   /** Emitted when kasbar wants to resize. This happens when a new window is added. */
254
 
   void layoutChanged();
255
 
 
256
 
   /** Emitted when the item size is changed. */
257
 
   void itemSizeChanged( int );
258
 
 
259
 
   void configChanged();
260
 
 
261
 
protected:
262
 
    KRootPixmap *rootPixmap() const { return rootPix; }
263
 
 
264
 
   /** Displays the popup menus, hides/shows windows. */
265
 
   void mousePressEvent(QMouseEvent *ev);
266
 
 
267
 
   /** Displays the popup menus, hides/shows windows. */
268
 
   void mouseReleaseEvent(QMouseEvent *ev);
269
 
 
270
 
   /** Overridden to implement the mouse-over highlight effect. */
271
 
   void mouseMoveEvent(QMouseEvent *ev);
272
 
 
273
 
   /** Overridden to implement the drag-over task switching. */
274
 
   void dragMoveEvent(QDragMoveEvent *ev);
275
 
 
276
 
   /** Paints the background of the item to the painter. */
277
 
   void paintBackground( QPainter *p, const QRect &r );
278
 
 
279
 
   /** Calls the paint methods for the items in the rectangle specified by the event. */
280
 
   void paintEvent(QPaintEvent *ev);
281
 
 
282
 
   /** Forces the widget to re-layout it's contents. */
283
 
   void resizeEvent(QResizeEvent *ev);
284
 
 
285
 
private:
286
 
   // Core data
287
 
   QPixmap offscreen;
288
 
   KasBar *master_;
289
 
   KasItemList items;
290
 
   Orientation orient;
291
 
   Direction direction_;
292
 
   KasItem *itemUnderMouse_;
293
 
   uint boxesPerLine_;
294
 
   QPoint pressPos;
295
 
   bool inDrag;
296
 
   bool detached;
297
 
   int maxBoxes_;
298
 
   int itemSize_;
299
 
   int itemExtent_;
300
 
   QPoint detachedPos;
301
 
   bool paintInactiveFrame_;
302
 
 
303
 
   // Implements pseudo-transparency
304
 
   bool transparent_;
305
 
   KPixmap bg;
306
 
   KRootPixmap *rootPix;
307
 
   bool enableTint_;
308
 
   double tintAmount_;
309
 
   QColor tintColour_;
310
 
   bool useMask_;
311
 
 
312
 
   // Look and feel resources
313
 
   KasResources *res;
314
 
};
315
 
 
316
 
 
317
 
 
318
 
#endif