summaryrefslogtreecommitdiff
path: root/noncore/styles/theme/othemestyle.h
blob: 406b35bd0dfe5aeef21d2a3cc02fbae7084f31b7 (plain)
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/* This file is part of the KDE libraries
  Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public
  License version 2 as published by the Free Software Foundation.

  This library 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
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to
  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.
*/
#ifndef __KTHEMESTYLE_H
#define __KTHEMESTYLE_H

#include "othemebase.h"
#include <qwindowdefs.h>
#include <qobject.h>
#include <qbutton.h>
#include <qpushbutton.h>
#include <qscrollbar.h>
#include <qstring.h>

class QProgressBar;


/**
 * KDE themed styles.
 *
 * It provides methods for
 * drawing most widgets with user-specified borders, highlights, pixmaps,
 * etc. It also handles various other settings such as scrollbar types,
 * rounded buttons, and shading types. For a full list of parameters this
 * class handles refer to the KDE theme configuration documentation.
 *
 */

class OThemeStyle: public OThemeBase
{
	Q_OBJECT
public:
	/**
	 * Construct a new @ref OThemeStyle object.
	 *
	 * @param configFile A KConfig file to use as the theme configuration.
	 * Defaults to ~/.kderc.
	 */
	OThemeStyle( const QString &configFile = QString::null );
	~OThemeStyle();
	virtual void polish( QWidget* );
	virtual void unPolish( QWidget* );
	/**
	 * By default this just sets the background brushes to the pixmapped
	 * background.
	 */
	virtual void polish( QApplication *app );
	virtual void unPolish( QApplication* );

	/// @internal
	// to make it possible for derived classes to overload this function
	virtual void polish( QPalette& pal );

	virtual bool eventFilter ( QObject *obj, QEvent *ev );

	/**
	 * This is a convenience method for drawing widgets with
	 * borders, highlights, pixmaps, colors, etc...
	 * You specify the widget type and it will draw it according to the
	 * config file settings.
	 *
	 * @param p The QPainter to draw on.
	 * @param g The color group to use.
	 * @param rounded @p true if the widget is rounded, @p false if rectangular.
	 * @param type The widget type to paint.
	 * @param fill An optional fill brush. Currently ignored (the config file
	 * is used instead).
	 */
	virtual void drawBaseButton( QPainter *p, int x, int y, int w, int h,
	                             const QColorGroup &g, bool sunken = FALSE,
	                             bool rounded = FALSE, WidgetType type = Bevel,
	                             const QBrush *fill = 0 );
	/**
	 * Draw a mask with for widgets that may be rounded. 
	 *
	 *Currently used
	 * by pushbuttons and comboboxes.
	 *
	 * @param p The QPainter to draw on.
	 * @param rounded @p true if the widget is rounded, @p false if rectangular.
	 */
	virtual void drawBaseMask( QPainter *p, int x, int y, int w, int h,
	                           bool rounded );
	/**
	 * Draw a pushbutton.
	 *
	 * This calls @ref drawBaseButton() with @p PushButton as the
	 * widget type.
	 */
	virtual void drawButton( QPainter *p, int x, int y, int w, int h,
	                         const QColorGroup &g, bool sunken = FALSE,
	                         const QBrush *fill = 0 );
	/**
	 * Draw a bevel button.
	 *
	 * This calls @ref drawBaseButton() with Bevel as the
	 * widget type.
	 */
	virtual void drawBevelButton( QPainter *p, int x, int y, int w, int h,
	                              const QColorGroup &g, bool sunken = FALSE,
	                              const QBrush *fill = 0 );
	/**
	 * Draw a toolbar button.
	 */
	virtual void drawToolButton ( QPainter *p, int x, int y, int w, int h,
	                              const QColorGroup &g, bool sunken = FALSE,
	                              const QBrush *fill = 0 );
#if 0
	/**
	 * Draw a toolbar button.
	 */
	virtual void drawKToolBarButton( QPainter *p, int x, int y, int w, int h,
	                                 const QColorGroup &g, bool sunken = false,
	                                 bool raised = true, bool enabled = true,
	                                 bool popup = false, KToolButtonType type = Icon,
	                                 const QString &btext = QString::null,
	                                 const QPixmap *icon = NULL,
	                                 QFont *font = NULL, QWidget *btn = NULL );
	/**
	 * Draw the handle used in toolbars.
	 */
	void drawKBarHandle( QPainter *p, int x, int y, int w, int h,
	                     const QColorGroup &g,
	                     KToolBarPos type, QBrush *fill = NULL );

	/**
	 * Draw a toolbar.
	 */
	void drawKToolBar( QPainter *p, int x, int y, int w, int h,
	                   const QColorGroup &g, KToolBarPos type,
	                   QBrush *fill = NULL );
#endif
	/**
	 * Return the space available in a pushbutton, taking configurable
	 * borders and highlights into account.
	 */
	virtual QRect buttonRect( int x, int y, int w, int h );
	/**
	 * Draw an arrow in the style specified by the config file.
	 */
	virtual void drawArrow( QPainter *p, Qt::ArrowType type, bool down,
	                        int x, int y, int w, int h, const QColorGroup &g,
	                        bool enabled = true, const QBrush *fill = 0 );
	/**
	 * Return the size of the exclusive indicator pixmap if one is specified
	 * in the config file, otherwise it uses the base style's size.
	 */
	virtual QSize exclusiveIndicatorSize() const;
	/**
	 * Draw an exclusive indicator widget.
	 *
	 * If a pixmap is specified in the
	 * config file that is used, otherwise the base style's widget is drawn.
	 */
	virtual void drawExclusiveIndicator( QPainter* p, int x, int y, int w,
	                                     int h, const QColorGroup &g, bool on,
	                                     bool down = FALSE,
	                                     bool enabled = TRUE );
	/**
	 * Set the mask of an exclusive indicator widget.
	 *
	 * If a pixmap is specified
	 * it is masked according to it's transparent pixels, otherwise the
	 * base style's mask is used.
	 */
	virtual void drawExclusiveIndicatorMask( QPainter *p, int x, int y, int w,
	        int h, bool on );
	/**
	 * Set the mask of an indicator widget.
	 *
	 * If a pixmap is specified
	 * it is masked according to it's transparent pixels, otherwise the
	 * base style's mask is used.
	 */
	virtual void drawIndicatorMask( QPainter *p, int x, int y, int w, int h,
	                                int state );
	/**
	 * Set the mask for pushbuttons.
	 */
	virtual void drawButtonMask( QPainter *p, int x, int y, int w, int h );
	/**
	 * Set the mask for combo boxes.
	 */
	virtual void drawComboButtonMask( QPainter *p, int x, int y, int w, int h );
	/**
	 * Return the size of the indicator pixmap if one is specified
	 * in the config file, otherwise it uses the base style's size.
	 */
	virtual QSize indicatorSize() const;
	/**
	 * Draw an indicator widget.
	 *
	 * If a pixmap is specified in the
	 * config file that is used, otherwise the base style's widget is drawn.
	 */
	virtual void drawIndicator( QPainter* p, int x, int y, int w, int h,
	                            const QColorGroup &g, int state,
	                            bool down = FALSE, bool enabled = TRUE );
	/**
	 * Draw a combobox.
	 */
	virtual void drawComboButton( QPainter *p, int x, int y, int w, int h,
	                              const QColorGroup &g, bool sunken = FALSE,
	                              bool editable = FALSE, bool enabled = TRUE,
	                              const QBrush *fill = 0 );
	/**
	 * Draw a pushbutton.
	 */
	virtual void drawPushButton( QPushButton* btn, QPainter *p );
	/**
	 * Return the amount of button content displacement specified by the
	 * config file.
	 */
	virtual void getButtonShift( int &x, int &y );
	/**
	 * Return the frame width.
	 */
	virtual int defaultFrameWidth() const;
	/**
	 * Calculate the metrics of the scrollbar controls according to the
	 * layout specified by the config file.
	 */
	virtual void scrollBarMetrics( const QScrollBar*, int&, int&, int&, int& );
	/**
	 * Draw a themed scrollbar.
	 */
	virtual void drawScrollBarControls( QPainter*, const QScrollBar*,
	                                    int sliderStart, uint controls,
	                                    uint activeControl );
	/**
	 * Return the control that the given point is over according to the
	 * layout in the config file.
	 */
	virtual ScrollControl scrollBarPointOver( const QScrollBar*,
	        int sliderStart, const QPoint& );
	/**
	 * Return the configurable default slider length.
	 */
	virtual int sliderLength() const;
	/**
	 * Draw a slider control.
	 */
	virtual void drawSlider( QPainter *p, int x, int y, int w, int h,
	                         const QColorGroup &g, Orientation, bool tickAbove,
	                         bool tickBelow );
	/**
	 * Draw a slider groove.
	 */
	void drawSliderGroove( QPainter *p, int x, int y, int w, int h,
	                       const QColorGroup& g, QCOORD c,
	                       Orientation );
	/**
	 * Draw the mask for a slider (both the control and groove.
	 */
	virtual void drawSliderMask( QPainter *p, int x, int y, int w, int h,
	                             Orientation, bool tickAbove, bool tickBelow );
	//    void drawSliderGrooveMask(QPainter *p,int x, int y, int w, int h,
	//                              QCOORD c, Orientation );
	/**
	 * Convience method for drawing themed scrollbar grooves.
	 *
	 * Since the
	 * grooves may be a scaled pixmap you cannot just bitblt the pixmap at
	 * any offset. This generates a cached pixmap at full size if needed and
	 * then copies the requested area.
	 *
	 * @param p The painter to draw on.
	 * @param sb The scrollbar (usually given by drawScrollBarControls).
	 * @param horizontal Is the scrollBar horizontal?
	 * @param r The rectangle to fill.
	 * @param g The color group to use.
	 */
	virtual void drawScrollBarGroove( QPainter *p, const QScrollBar *sb,
	                                  bool horizontal, QRect r, QColorGroup g );
	/**
	 * Draw a shaded rectangle using the given style.
	 *
	 * @param p The painter to draw on.
	 * @param g The color group to use.
	 * @param rounded Draws a rounded shape if true. Requires bWidth to be
	 * at least 1.
	 * @param hWidth The highlight width.
	 * @param bWidth The border width.
	 * @param style The shading style to use.
	 */
	virtual void drawShade( QPainter *p, int x, int y, int w, int h,
	                        const QColorGroup &g, bool sunken, bool rounded,
	                        int hWidth, int bWidth, ShadeStyle style );
	/**
	 * Draw the text for a pushbutton.
	 */
	virtual void drawPushButtonLabel( QPushButton *btn, QPainter *p );
	/**
	 * Draw a menubar.
	 */
#if 0

	void drawKMenuBar( QPainter *p, int x, int y, int w, int h,
	                   const QColorGroup &g, bool macMode,
	                   QBrush *fill = NULL );
#endif
	/**
	 * Draw a menubar item.
	 */
	virtual void drawMenuBarItem( QPainter *p, int x, int y, int w, int h,
	                              QMenuItem *item, const QColorGroup &g, 
	                              bool enabled, bool active );
	/**
	 * Return the width of the splitter as specified in the config file.
	 */
	virtual int splitterWidth() const;
	/**
	 * Draw a splitter widget.
	 */
	virtual void drawSplitter( QPainter *p, int x, int y, int w, int h,
	                           const QColorGroup &g, Orientation );
	/**
	 * Draw a checkmark.
	 */
	virtual void drawCheckMark( QPainter *p, int x, int y, int w, int h,
	                            const QColorGroup &g, bool act, bool dis );
	/**
	 * Draw a menu item.
	 *
	 * Note: This method manually handles applying
	 * inactive menu backgrounds to the entire widget.
	 */
	virtual void drawPopupMenuItem( QPainter *p, bool checkable, int maxpmw,
	                                int tab, QMenuItem *mi, const QPalette &pal,
	                                bool act, bool enabled, int x, int y, int w,
	                                int h );
	int popupMenuItemHeight( bool checkable, QMenuItem *mi,
	                         const QFontMetrics &fm );
	/**
	 * Draw the focus rectangle.
	 */
	void drawFocusRect( QPainter *p, const QRect &r, const QColorGroup &g,
	                    const QColor *c = 0, bool atBorder = false );
	/**
	 * Draw a @ref KProgess bar.
	 */ 
	virtual void drawProgressBar (QPainter *, int , int , int , int , const QColorGroup &, int );
	/**
	 * Return the background for @ref KProgress.
	 */ 
	//    virtual void getKProgressBackground(const QColorGroup &g, QBrush &bg);
	virtual void tabbarMetrics( const QTabBar*, int&, int&, int& );
	virtual void drawTab( QPainter*, const QTabBar*, QTab*, bool selected );
	virtual void drawTabMask( QPainter*, const QTabBar*, QTab*, bool selected );
protected:
	QPalette oldPalette, popupPalette, indiPalette, exIndiPalette;

	class OThemeStylePrivate;
	OThemeStylePrivate *d;
};

#endif