summaryrefslogtreecommitdiffstats
path: root/src/styles/qcdestyle.cpp
blob: 3a5baf375ede39e37aaafc7592eb97661ce85d64 (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
/****************************************************************************
**
** Implementation of CDE-like style class
**
** Created : 981231
**
** Copyright (C) 1998-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of the widgets module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing retquirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#include "qcdestyle.h"

#if !defined(QT_NO_STYLE_CDE) || defined(QT_PLUGIN)

#include "qpainter.h"
#include "qdrawutil.h"
#include "qbutton.h"
#include <limits.h>

/*!
    \class TQCDEStyle qcdestyle.h
    \brief The TQCDEStyle class provides a CDE look and feel.

    \ingroup appearance

    This style provides a slightly improved Motif look similar to some
    versions of the Common Desktop Environment (CDE). The main
    differences are thinner frames and more modern radio buttons and
    checkboxes. Together with a dark background and a bright
    text/foreground color, the style looks tquite attractive (at least
    for Motif fans).

    Note that the functions provided by TQCDEStyle are
    reimplementations of TQStyle functions; see TQStyle for their
    documentation.
*/

/*!
    Constructs a TQCDEStyle.

    If \a useHighlightCols is FALSE (the default), then the style will
    polish the application's color palette to emulate the Motif way of
    highlighting, which is a simple inversion between the base and the
    text color.
*/
TQCDEStyle::TQCDEStyle( bool useHighlightCols ) : TQMotifStyle( useHighlightCols )
{
}

/*!
    Destroys the style.
*/
TQCDEStyle::~TQCDEStyle()
{
}


/*!\reimp
*/
int TQCDEStyle::pixelMetric( PixelMetric metric, const TQWidget *widget ) const
{
    int ret;

    switch( metric ) {
    case PM_DefaultFrameWidth:
	ret = 1;
	break	;
    case PM_MenuBarFrameWidth:
	ret = 1;
	break;
    case PM_ScrollBarExtent:
	ret = 13;
	break;
    default:
	ret = TQMotifStyle::pixelMetric( metric, widget );
	break;
    }
    return ret;
}

/*! \reimp
*/
void TQCDEStyle::drawControl( ControlElement element,
			     TQPainter *p,
			     const TQWidget *widget,
			     const TQRect &r,
			     const TQColorGroup &cg,
			     SFlags how,
			     const TQStyleOption& opt ) const
{

    switch( element ) {
    case CE_MenuBarItem:
	{
	    if ( how & Style_Active )  // active item
		qDrawShadePanel( p, r, cg, TRUE, 1,
				 &cg.brush( TQColorGroup::Button ) );
	    else  // other item
		p->fillRect( r, cg.brush( TQColorGroup::Button ) );
	    TQCommonStyle::drawControl( element, p, widget, r, cg, how, opt );
	    break;
	}
    default:
	TQMotifStyle::drawControl( element, p, widget, r, cg, how, opt );
    break;
    }


}

/*! \reimp
*/
void TQCDEStyle::drawPrimitive( PrimitiveElement pe,
			       TQPainter *p,
			       const TQRect &r,
			       const TQColorGroup &cg,
			       SFlags flags,
			       const TQStyleOption& opt ) const
{
    switch( pe ) {
    case PE_Indicator: {
#ifndef QT_NO_BUTTON
	bool down = flags & Style_Down;
	bool on = flags & Style_On;
	bool showUp = !( down ^ on );
	TQBrush fill = showUp || flags & Style_NoChange ? cg.brush( TQColorGroup::Button ) : cg.brush( TQColorGroup::Mid );
	qDrawShadePanel( p, r, cg, !showUp, pixelMetric( PM_DefaultFrameWidth ), &cg.brush( TQColorGroup::Button ) );

	if ( !( flags & Style_Off ) ) {
	    TQPointArray a( 7 * 2 );
	    int i, xx, yy;
	    xx = r.x() + 3;
	    yy = r.y() + 5;
	    for ( i = 0; i < 3; i++ ) {
		a.setPoint( 2 * i,   xx, yy );
		a.setPoint( 2 * i + 1, xx, yy + 2 );
		xx++; yy++;
	    }
	    yy -= 2;
	    for ( i = 3; i < 7; i++ ) {
		a.setPoint( 2 * i, xx, yy );
		a.setPoint( 2 * i + 1, xx, yy + 2 );
		xx++; yy--;
	    }
	    if ( flags & Style_NoChange )
		p->setPen( cg.dark() );
	    else
		p->setPen( cg.foreground() );
	    p->drawLineSegments( a );
	}
#endif
    }
	break;
    case PE_ExclusiveIndicator:
	{
#define TQCOORDARRLEN(x) sizeof(x)/(sizeof(TQCOORD)*2)
	    static const TQCOORD pts1[] = {              // up left  lines
		1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
	    static const TQCOORD pts4[] = {              // bottom right  lines
		2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
		11,4, 10,3, 10,2 };
	    static const TQCOORD pts5[] = {              // inner fill
		4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
	    bool down = flags & Style_Down;
	    bool on = flags & Style_On;
	    p->eraseRect( r );
	    TQPointArray a( TQCOORDARRLEN(pts1), pts1 );
	    a.translate( r.x(), r.y() );
	    p->setPen( ( down || on ) ? cg.dark() : cg.light() );
	    p->drawPolyline( a );
	    a.setPoints( TQCOORDARRLEN(pts4), pts4 );
	    a.translate( r.x(), r.y() );
	    p->setPen( ( down || on ) ? cg.light() : cg.dark() );
	    p->drawPolyline( a );
	    a.setPoints( TQCOORDARRLEN(pts5), pts5 );
	    a.translate( r.x(), r.y() );
	    TQColor fillColor = on ? cg.dark() : cg.background();
	    p->setPen( fillColor );
	    p->setBrush( on ? cg.brush( TQColorGroup::Dark ) :
			 cg.brush( TQColorGroup::Background ) );
	    p->drawPolygon( a );
	    break;
	}

    case PE_ExclusiveIndicatorMask:
	{
	    static const TQCOORD pts1[] = {
		// up left  lines
		1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1,
		// bottom right  lines
		10,2, 10,3, 11,4, 11,7, 10,8, 10,9, 9,10, 8,10, 7,11, 4,11, 3,10, 2,10
	    };
	    TQPointArray a(TQCOORDARRLEN(pts1), pts1);
	    a.translate(r.x(), r.y());
	    p->setPen(color1);
	    p->setBrush(color1);
	    p->drawPolygon(a);
	    break;
	}
    case PE_ArrowUp:
    case PE_ArrowDown:
    case PE_ArrowRight:
    case PE_ArrowLeft: {
	TQRect rect = r;
	TQPointArray bFill;                          // fill polygon
	TQPointArray bTop;                           // top shadow.
	TQPointArray bBot;                           // bottom shadow.
	TQPointArray bLeft;                          // left shadow.
	TQWMatrix    matrix;                         // xform matrix
	bool vertical = pe == PE_ArrowUp || pe == PE_ArrowDown;
	bool horizontal = !vertical;
	int  dim = rect.width() < rect.height() ? rect.width() : rect.height();
	int  colspec = 0x0000;                      // color specification array

	if ( dim < 2 )                              // too small arrow
	    return;

	// adjust size and center (to fix rotation below)
	if ( rect.width() >  dim ) {
	    rect.setX( rect.x() + ( ( rect.width() - dim ) / 2 ) );
	    rect.setWidth( dim );
	}
	if ( rect.height() > dim ) {
	    rect.setY( rect.y() + ( ( rect.height() - dim ) / 2 ) );
	    rect.setHeight( dim );
	}

	if ( dim > 3 ) {
	    bFill.resize( dim & 1 ? 3 : 4 );
	    bTop.resize( 2 );
	    bBot.resize( 2 );
	    bLeft.resize( 2 );
	    bLeft.putPoints( 0, 2, 0, 0, 0, dim-1 );
	    bTop.putPoints( 0, 2, 1, 0, dim-1, dim/2 );
	    bBot.putPoints( 0, 2, 1, dim-1, dim-1, dim/2 );

	    if ( dim > 6 ) {                        // dim>6: must fill interior
		bFill.putPoints( 0, 2, 1, dim-1, 1, 1 );
		if ( dim & 1 )                      // if size is an odd number
		    bFill.setPoint( 2, dim - 2, dim / 2 );
		else
		    bFill.putPoints( 2, 2, dim-2, dim/2-1, dim-2, dim/2 );
	    }
	} else {
	    if ( dim == 3 ) {                       // 3x3 arrow pattern
		bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 );
		bTop .setPoints( 2, 1,0, 1,0 );
		bBot .setPoints( 2, 1,2, 2,1 );
	    } else {                                  // 2x2 arrow pattern
		bLeft.setPoints( 2, 0,0, 0,1 );
		bTop .setPoints( 2, 1,0, 1,0 );
		bBot .setPoints( 2, 1,1, 1,1 );
	    }
	}

	if ( pe == PE_ArrowUp || pe == PE_ArrowLeft ) {
	    matrix.translate( rect.x(), rect.y() );
	    if ( vertical ) {
		matrix.translate( 0, rect.height() - 1 );
		matrix.rotate( -90 );
	    } else {
		matrix.translate( rect.width() - 1, rect.height() - 1 );
		matrix.rotate( 180 );
	    }
	    if ( flags & Style_Down )
		colspec = horizontal ? 0x2334 : 0x2343;
	    else
		colspec = horizontal ? 0x1443 : 0x1434;
	} else if ( pe == PE_ArrowDown || pe == PE_ArrowRight ) {
	    matrix.translate( rect.x(), rect.y() );
	    if ( vertical ) {
		matrix.translate( rect.width()-1, 0 );
		matrix.rotate( 90 );
	    }
	    if ( flags & Style_Down )
		colspec = horizontal ? 0x2443 : 0x2434;
	    else
		colspec = horizontal ? 0x1334 : 0x1343;
	}

	TQColor *cols[5];
	if ( flags & Style_Enabled ) {
	    cols[0] = 0;
	    cols[1] = (TQColor *)&cg.button();
	    cols[2] = (TQColor *)&cg.mid();
	    cols[3] = (TQColor *)&cg.light();
	    cols[4] = (TQColor *)&cg.dark();
	} else {
	    cols[0] = 0;
	    cols[1] = (TQColor *)&cg.button();
	    cols[2] = (TQColor *)&cg.button();
	    cols[3] = (TQColor *)&cg.button();
	    cols[4] = (TQColor *)&cg.button();
	}

#define CMID    *cols[ (colspec>>12) & 0xf ]
#define CLEFT   *cols[ (colspec>>8) & 0xf ]
#define CTOP    *cols[ (colspec>>4) & 0xf ]
#define CBOT    *cols[ colspec & 0xf ]

	TQPen     savePen   = p->pen();              // save current pen
	TQBrush   saveBrush = p->brush();            // save current brush
	TQWMatrix wxm = p->worldMatrix();
	TQPen     pen( NoPen );
	TQBrush brush = cg.brush( flags & Style_Enabled ? TQColorGroup::Button :
				 TQColorGroup::Mid );

	p->setPen( pen );
	p->setBrush( brush );
	p->setWorldMatrix( matrix, TRUE );          // set transformation matrix
	p->drawPolygon( bFill );                    // fill arrow
	p->setBrush( NoBrush );                     // don't fill

	p->setPen( CLEFT );
	p->drawLineSegments( bLeft );
	p->setPen( CBOT );
	p->drawLineSegments( bBot );
	p->setPen( CTOP );
	p->drawLineSegments( bTop );

	p->setWorldMatrix( wxm );
	p->setBrush( saveBrush );                   // restore brush
	p->setPen( savePen );                       // restore pen

#undef CMID
#undef CLEFT
#undef CTOP
#undef CBOT

    }
	break;
    default:
	TQMotifStyle::drawPrimitive( pe, p, r, cg, flags, opt );
    }
}

#endif