5
** Copyright (C) 2001-2004 Richard Moore <rich@kde.org>
7
** All rights reserved.
9
** KasBar is dual-licensed: you can choose the GPL or the BSD license.
10
** Short forms of both licenses are included below.
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.
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.
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.
31
** Redistribution and use in source and binary forms, with or without
32
** modification, are permitted provided that the following conditions
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.
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
54
** Bug reports and questions can be sent to kde-devel@kde.org
67
#include "kasresources.h"
74
typedef QPtrList<KasItem> KasItemList;
78
* The main view for KasBar.
80
class KDE_EXPORT KasBar : public QWidget
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 )
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 );
98
typedef QBoxLayout::Direction Direction;
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_; }
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_; }
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 );
109
/** Factory method that returns the singleton resources object. */
110
virtual KasResources *resources();
112
/** Returns true iff we have a resources object. */
113
bool hasResources() const { return (res ? true : false); }
118
void append( KasItem *i );
119
void insert( int index, KasItem *i );
120
void remove( KasItem *i );
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 ); }
126
KasItemList *itemList() { return &items; }
132
/** The possible item sizes. */
133
enum ItemSize { Enormous, Huge, Large, Medium, Small, Custom };
135
int itemSize() const { return itemSize_; }
136
int itemExtent() const { return itemExtent_; }
138
/** The number of items in the bar. */
139
unsigned int itemCount() const { return items.count(); }
141
int maxBoxes() const { return maxBoxes_; }
142
uint boxesPerLine() const { return boxesPerLine_; }
144
void setOrientation( Orientation o );
145
Orientation orientation() const { return orient; }
147
void setDirection( Direction dir );
148
Direction direction() const { return direction_; }
150
bool isDetached() const { return detached; }
151
QPoint detachedPosition() const { return detachedPos; }
153
bool isDrag() const { return inDrag; }
155
QSize sizeHint( Orientation, QSize max );
158
// Look and feel options
161
bool isMasked() const { return useMask_; }
163
/** Is transparency enabled? */
164
bool isTransparent() const { return transparent_; }
166
/** Is tinting enabled? */
167
bool hasTint() const { return enableTint_; }
169
/** Sets the amount and color of the tint. */
170
void setTint( double amount, QColor color );
172
/** Sets the amount of tinting. */
173
void setTintAmount( double amount ) { setTint( amount, tintColour_ ); }
175
/** Get the amount of tinting. */
176
double tintAmount() const { return tintAmount_; }
178
/** Get the color of the tint. */
179
QColor tintColor() const { return tintColour_; }
181
/** Returns true iff we will paint frames around inactive items. */
182
bool paintInactiveFrames() const { return paintInactiveFrame_; }
188
void updateItem( KasItem *i );
190
/** Redraws the specified item. */
191
void repaintItem(KasItem *i, bool erase = true );
193
/** Returns the item at p or 0. */
194
KasItem* itemAt(const QPoint &p);
196
/** Get the position of the specified item. */
197
QPoint itemPos( KasItem *i );
199
/** The item under the mouse pointer (or 0). */
200
KasItem *itemUnderMouse() const { return itemUnderMouse_; }
206
void setMaxBoxes( int count );
207
void setBoxesPerLine( int count );
209
void setItemSize( int size );
210
void setItemExtent( int size );
211
void setDetachedPosition( const QPoint &pos );
213
virtual void updateLayout();
215
void updateMouseOver();
216
void updateMouseOver( QPoint pos );
218
/** Enable or disable tinting. */
219
void setTint( bool enable );
221
/** Enable or disable transparency. */
222
void setTransparent( bool enable );
224
/** Set the color of the tint. */
225
void setTintColor( const QColor &c );
227
/** Set the strength of the tint (as a percentage). */
228
void setTintAmount( int percent );
230
void setBackground( const QPixmap &pix );
232
void setMasked( bool mask );
234
void setPaintInactiveFrames( bool enable );
236
void toggleOrientation();
237
void toggleDetached();
238
void setDetached( bool detach );
240
/** Rereads the configuration of the master Kasbar. */
241
virtual void rereadMaster();
243
virtual void addTestItems();
247
void detachedChanged( bool );
248
void detachedPositionChanged( const QPoint & );
251
void directionChanged();
253
/** Emitted when kasbar wants to resize. This happens when a new window is added. */
254
void layoutChanged();
256
/** Emitted when the item size is changed. */
257
void itemSizeChanged( int );
259
void configChanged();
262
KRootPixmap *rootPixmap() const { return rootPix; }
264
/** Displays the popup menus, hides/shows windows. */
265
void mousePressEvent(QMouseEvent *ev);
267
/** Displays the popup menus, hides/shows windows. */
268
void mouseReleaseEvent(QMouseEvent *ev);
270
/** Overridden to implement the mouse-over highlight effect. */
271
void mouseMoveEvent(QMouseEvent *ev);
273
/** Overridden to implement the drag-over task switching. */
274
void dragMoveEvent(QDragMoveEvent *ev);
276
/** Paints the background of the item to the painter. */
277
void paintBackground( QPainter *p, const QRect &r );
279
/** Calls the paint methods for the items in the rectangle specified by the event. */
280
void paintEvent(QPaintEvent *ev);
282
/** Forces the widget to re-layout it's contents. */
283
void resizeEvent(QResizeEvent *ev);
291
Direction direction_;
292
KasItem *itemUnderMouse_;
301
bool paintInactiveFrame_;
303
// Implements pseudo-transparency
306
KRootPixmap *rootPix;
312
// Look and feel resources