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
64
#include <Qt3Support/Q3PtrList>
66
#include <QtCore/QCOORD>
69
#include <QPaintEvent>
70
#include <QDragMoveEvent>
72
#include <QResizeEvent>
73
#include <QMouseEvent>
75
#include "kasresources.h"
80
typedef Q3PtrList<KasItem> KasItemList;
84
* The main view for KasBar.
86
class KDE_EXPORT KasBar : public QWidget
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 )
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 );
104
typedef QBoxLayout::Direction Direction;
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_; }
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_; }
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 );
115
/** Factory method that returns the singleton resources object. */
116
virtual KasResources *resources();
118
/** Returns true iff we have a resources object. */
119
bool hasResources() const { return (res ? true : false); }
124
void append( KasItem *i );
125
void insert( int index, KasItem *i );
126
void remove( KasItem *i );
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 ); }
132
KasItemList *itemList() { return &items; }
138
/** The possible item sizes. */
139
enum ItemSize { Enormous, Huge, Large, Medium, Small, Custom };
141
int itemSize() const { return itemSize_; }
142
int itemExtent() const { return itemExtent_; }
144
/** The number of items in the bar. */
145
unsigned int itemCount() const { return items.count(); }
147
int maxBoxes() const { return maxBoxes_; }
148
uint boxesPerLine() const { return boxesPerLine_; }
150
void setOrientation( Qt::Orientation o );
151
Qt::Orientation orientation() const { return orient; }
153
void setDirection( Direction dir );
154
Direction direction() const { return direction_; }
156
bool isDetached() const { return detached; }
157
QPoint detachedPosition() const { return detachedPos; }
159
bool isDrag() const { return inDrag; }
161
QSize sizeHint( Qt::Orientation, QSize max );
164
// Look and feel options
167
bool isMasked() const { return useMask_; }
169
/** Is transparency enabled? */
170
bool isTransparent() const { return transparent_; }
172
/** Is tinting enabled? */
173
bool hasTint() const { return enableTint_; }
175
/** Sets the amount and color of the tint. */
176
void setTint( double amount, QColor color );
178
/** Sets the amount of tinting. */
179
void setTintAmount( double amount ) { setTint( amount, tintColour_ ); }
181
/** Get the amount of tinting. */
182
double tintAmount() const { return tintAmount_; }
184
/** Get the color of the tint. */
185
QColor tintColor() const { return tintColour_; }
187
/** Returns true iff we will paint frames around inactive items. */
188
bool paintInactiveFrames() const { return paintInactiveFrame_; }
194
void updateItem( KasItem *i );
196
/** Redraws the specified item. */
197
void repaintItem(KasItem *i, bool erase = true );
199
/** Returns the item at p or 0. */
200
KasItem* itemAt(const QPoint &p);
202
/** Get the position of the specified item. */
203
QPoint itemPos( KasItem *i );
205
/** The item under the mouse pointer (or 0). */
206
KasItem *itemUnderMouse() const { return itemUnderMouse_; }
212
void setMaxBoxes( int count );
213
void setBoxesPerLine( int count );
215
void setItemSize( int size );
216
void setItemExtent( int size );
217
void setDetachedPosition( const QPoint &pos );
219
virtual void updateLayout();
221
void updateMouseOver();
222
void updateMouseOver( QPoint pos );
224
/** Enable or disable tinting. */
225
void setTint( bool enable );
227
/** Enable or disable transparency. */
228
void setTransparent( bool enable );
230
/** Set the color of the tint. */
231
void setTintColor( const QColor &c );
233
/** Set the strength of the tint (as a percentage). */
234
void setTintAmount( int percent );
236
void setBackground( const QPixmap &pix );
238
void setMasked( bool mask );
240
void setPaintInactiveFrames( bool enable );
242
void toggleOrientation();
243
void toggleDetached();
244
void setDetached( bool detach );
246
/** Rereads the configuration of the master Kasbar. */
247
virtual void rereadMaster();
249
virtual void addTestItems();
253
void detachedChanged( bool );
254
void detachedPositionChanged( const QPoint & );
257
void directionChanged();
259
/** Emitted when kasbar wants to resize. This happens when a new window is added. */
260
void layoutChanged();
262
/** Emitted when the item size is changed. */
263
void itemSizeChanged( int );
265
void configChanged();
268
/** Displays the popup menus, hides/shows windows. */
269
void mousePressEvent(QMouseEvent *ev);
271
/** Displays the popup menus, hides/shows windows. */
272
void mouseReleaseEvent(QMouseEvent *ev);
274
/** Overridden to implement the mouse-over highlight effect. */
275
void mouseMoveEvent(QMouseEvent *ev);
277
/** Overridden to implement the drag-over task switching. */
278
void dragMoveEvent(QDragMoveEvent *ev);
280
/** Paints the background of the item to the painter. */
281
void paintBackground( QPainter *p, const QRect &r );
283
/** Calls the paint methods for the items in the rectangle specified by the event. */
284
void paintEvent(QPaintEvent *ev);
286
/** Forces the widget to re-layout it's contents. */
287
void resizeEvent(QResizeEvent *ev);
294
Qt::Orientation orient;
295
Direction direction_;
296
KasItem *itemUnderMouse_;
305
bool paintInactiveFrame_;
307
// Implements pseudo-transparency
315
// Look and feel resources