source: trunk/src/styles/qmotifplusstyle.cpp@ 150

Last change on this file since 150 was 8, checked in by dmik, 20 years ago

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

  • Property svn:keywords set to Id
File size: 43.9 KB
Line 
1/****************************************************************************
2** $Id: qmotifplusstyle.cpp 8 2005-11-16 19:36:46Z dmik $
3**
4** Implementation of QMotifPlusStyle class
5**
6** Created : 000727
7**
8** Copyright (C) 2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the widgets module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qmotifplusstyle.h"
39
40#if !defined(QT_NO_STYLE_MOTIFPLUS) || defined(QT_PLUGIN)
41
42#include "qmenubar.h"
43#include "qapplication.h"
44#include "qpainter.h"
45#include "qpalette.h"
46#include "qframe.h"
47#include "qpushbutton.h"
48#include "qcheckbox.h"
49#include "qradiobutton.h"
50#include "qcombobox.h"
51#include "qlineedit.h"
52#include "qspinbox.h"
53#include "qslider.h"
54#include "qdrawutil.h"
55#include "qscrollbar.h"
56#include "qtabbar.h"
57#include "qtoolbar.h"
58#include "qguardedptr.h"
59#include "qlayout.h"
60
61
62struct QMotifPlusStylePrivate
63{
64 QMotifPlusStylePrivate()
65 : hoverWidget(0), hovering(FALSE), sliderActive(FALSE), mousePressed(FALSE),
66 scrollbarElement(0), lastElement(0), ref(1)
67 { ; }
68
69 QGuardedPtr<QWidget> hoverWidget;
70 bool hovering, sliderActive, mousePressed;
71 int scrollbarElement, lastElement, ref;
72 QPoint mousePos;
73};
74
75static QMotifPlusStylePrivate * singleton = 0;
76
77
78static void drawMotifPlusShade(QPainter *p,
79 const QRect &r,
80 const QColorGroup &g,
81 bool sunken, bool mouseover,
82 const QBrush *fill = 0)
83{
84 QPen oldpen = p->pen();
85 QPointArray a(4);
86 QColor button =
87 mouseover ? g.midlight() : g.button();
88 QBrush brush =
89 mouseover ? g.brush(QColorGroup::Midlight) : g.brush(QColorGroup::Button);
90 int x, y, w, h;
91
92 r.rect(&x, &y, &w, &h);
93
94 if (sunken) p->setPen(g.dark()); else p->setPen(g.light());
95 a.setPoint(0, x, y + h - 1);
96 a.setPoint(1, x, y);
97 a.setPoint(2, x, y);
98 a.setPoint(3, x + w - 1, y);
99 p->drawLineSegments(a);
100
101 if (sunken) p->setPen(Qt::black); else p->setPen(button);
102 a.setPoint(0, x + 1, y + h - 2);
103 a.setPoint(1, x + 1, y + 1);
104 a.setPoint(2, x + 1, y + 1);
105 a.setPoint(3, x + w - 2, y + 1);
106 p->drawLineSegments(a);
107
108 if (sunken) p->setPen(button); else p->setPen(g.dark());
109 a.setPoint(0, x + 2, y + h - 2);
110 a.setPoint(1, x + w - 2, y + h - 2);
111 a.setPoint(2, x + w - 2, y + h - 2);
112 a.setPoint(3, x + w - 2, y + 2);
113 p->drawLineSegments(a);
114
115 if (sunken) p->setPen(g.light()); else p->setPen(Qt::black);
116 a.setPoint(0, x + 1, y + h - 1);
117 a.setPoint(1, x + w - 1, y + h - 1);
118 a.setPoint(2, x + w - 1, y + h - 1);
119 a.setPoint(3, x + w - 1, y);
120 p->drawLineSegments(a);
121
122 if (fill)
123 p->fillRect(x + 2, y + 2, w - 4, h - 4, *fill);
124 else
125 p->fillRect(x + 2, y + 2, w - 4, h - 4, brush);
126
127 p->setPen(oldpen);
128}
129
130
131/*!
132 \class QMotifPlusStyle qmotifplusstyle.h
133 \brief The QMotifPlusStyle class provides a more sophisticated Motif-ish look and feel.
134
135 \ingroup appearance
136
137 This class implements a Motif-ish look and feel with the more
138 sophisticated bevelling as used by the GIMP Toolkit (GTK+) for
139 Unix/X11.
140*/
141
142/*!
143 Constructs a QMotifPlusStyle
144
145 If \a hoveringHighlight is TRUE (the default), then the style will
146 not highlight push buttons, checkboxes, radiobuttons, comboboxes,
147 scrollbars or sliders.
148*/
149QMotifPlusStyle::QMotifPlusStyle(bool hoveringHighlight) : QMotifStyle(TRUE)
150{
151 if ( !singleton )
152 singleton = new QMotifPlusStylePrivate;
153 else
154 singleton->ref++;
155
156 useHoveringHighlight = hoveringHighlight;
157}
158
159/*! \reimp */
160QMotifPlusStyle::~QMotifPlusStyle()
161{
162 if ( singleton && singleton->ref-- <= 0) {
163 delete singleton;
164 singleton = 0;
165 }
166}
167
168
169/*! \reimp */
170void QMotifPlusStyle::polish(QPalette &)
171{
172}
173
174
175/*! \reimp */
176void QMotifPlusStyle::polish(QWidget *widget)
177{
178#ifndef QT_NO_FRAME
179 if (::qt_cast<QFrame*>(widget) && ((QFrame *) widget)->frameStyle() == QFrame::Panel)
180 ((QFrame *) widget)->setFrameStyle(QFrame::WinPanel);
181#endif
182
183#ifndef QT_NO_MENUBAR
184 if (::qt_cast<QMenuBar*>(widget) && ((QMenuBar *) widget)->frameStyle() != QFrame::NoFrame)
185 ((QMenuBar *) widget)->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
186#endif
187
188#ifndef QT_NO_TOOLBAR
189 if (::qt_cast<QToolBar*>(widget))
190 widget->layout()->setMargin(2);
191#endif
192 if (useHoveringHighlight) {
193 if (::qt_cast<QButton*>(widget) || ::qt_cast<QComboBox*>(widget))
194 widget->installEventFilter(this);
195
196 if (::qt_cast<QScrollBar*>(widget) || ::qt_cast<QSlider*>(widget)) {
197 widget->setMouseTracking(TRUE);
198 widget->installEventFilter(this);
199 }
200 }
201
202 QMotifStyle::polish(widget);
203}
204
205
206/*! \reimp */
207void QMotifPlusStyle::unPolish(QWidget *widget)
208{
209 widget->removeEventFilter(this);
210 QMotifStyle::unPolish(widget);
211}
212
213
214/*! \reimp */
215void QMotifPlusStyle::polish(QApplication *)
216{
217}
218
219
220/*! \reimp */
221void QMotifPlusStyle::unPolish(QApplication *)
222{
223}
224
225
226/*! \reimp */
227int QMotifPlusStyle::pixelMetric(PixelMetric metric, const QWidget *widget) const
228{
229 int ret;
230
231 switch (metric) {
232 case PM_ScrollBarExtent:
233 ret = 15;
234 break;
235
236 case PM_ButtonDefaultIndicator:
237 ret = 5;
238 break;
239
240 case PM_ButtonMargin:
241 ret = 4;
242 break;
243
244 case PM_SliderThickness:
245 ret = 15;
246 break;
247
248 case PM_IndicatorWidth:
249 case PM_IndicatorHeight:
250 ret = 10;
251 break;
252
253 case PM_ExclusiveIndicatorWidth:
254 case PM_ExclusiveIndicatorHeight:
255 ret = 11;
256 break;
257
258 default:
259 ret = QMotifStyle::pixelMetric(metric, widget);
260 break;
261 }
262
263 return ret;
264}
265
266
267/*! \reimp */
268void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe,
269 QPainter *p,
270 const QRect &r,
271 const QColorGroup &cg,
272 SFlags flags,
273 const QStyleOption& opt ) const
274{
275 switch (pe) {
276 case PE_HeaderSection:
277
278 case PE_ButtonCommand:
279 case PE_ButtonBevel:
280 case PE_ButtonTool:
281 if (flags & (Style_Down | Style_On | Style_Raised | Style_Sunken))
282 drawMotifPlusShade( p, r, cg, bool(flags & (Style_Down | Style_On)),
283 bool(flags & Style_MouseOver));
284 else if (flags & Style_MouseOver)
285 p->fillRect(r, cg.brush(QColorGroup::Midlight));
286 else
287 p->fillRect(r, cg.brush(QColorGroup::Button));
288 break;
289
290 case PE_Panel:
291 case PE_PanelPopup:
292 case PE_PanelMenuBar:
293 case PE_PanelDockWindow:
294 if ( opt.lineWidth() )
295 drawMotifPlusShade( p, r, cg, (flags & Style_Sunken), (flags & Style_MouseOver));
296 else if ( flags & Style_MouseOver )
297 p->fillRect(r, cg.brush(QColorGroup::Midlight));
298 else
299 p->fillRect(r, cg.brush(QColorGroup::Button));
300 break;
301
302 case PE_SpinWidgetUp:
303 drawPrimitive(PE_ArrowUp, p, r, cg, flags, opt);
304 break;
305
306 case PE_SpinWidgetDown:
307 drawPrimitive(PE_ArrowDown, p, r, cg, flags, opt);
308 break;
309
310 case PE_Indicator:
311 {
312 QBrush fill;
313 if (flags & Style_On)
314 fill = cg.brush(QColorGroup::Mid);
315 else if (flags & Style_MouseOver)
316 fill = cg.brush(QColorGroup::Midlight);
317 else
318 fill = cg.brush(QColorGroup::Button);
319
320 if (flags & Style_NoChange) {
321 qDrawPlainRect(p, r, cg.text(), 1, &fill);
322 p->drawLine(r.topRight(), r.bottomLeft());
323 } else
324 drawMotifPlusShade(p, r, cg, (flags & Style_On),
325 (flags & Style_MouseOver), &fill);
326 break;
327 }
328
329 case PE_ExclusiveIndicator:
330 {
331 QPen oldpen = p->pen();
332 QPointArray thick(8);
333 QPointArray thin(4);
334 QColor button = ((flags & Style_MouseOver) ? cg.midlight() : cg.button());
335 QBrush brush = ((flags & Style_MouseOver) ?
336 cg.brush(QColorGroup::Midlight) :
337 cg.brush(QColorGroup::Button));
338 int x, y, w, h;
339 r.rect(&x, &y, &w, &h);
340
341 p->fillRect(x, y, w, h, brush);
342
343
344 if (flags & Style_On) {
345 thick.setPoint(0, x, y + (h / 2));
346 thick.setPoint(1, x + (w / 2), y);
347 thick.setPoint(2, x + 1, y + (h / 2));
348 thick.setPoint(3, x + (w / 2), y + 1);
349 thick.setPoint(4, x + (w / 2), y);
350 thick.setPoint(5, x + w - 1, y + (h / 2));
351 thick.setPoint(6, x + (w / 2), y + 1);
352 thick.setPoint(7, x + w - 2, y + (h / 2));
353 p->setPen(cg.dark());
354 p->drawLineSegments(thick);
355
356 thick.setPoint(0, x + 1, y + (h / 2) + 1);
357 thick.setPoint(1, x + (w / 2), y + h - 1);
358 thick.setPoint(2, x + 2, y + (h / 2) + 1);
359 thick.setPoint(3, x + (w / 2), y + h - 2);
360 thick.setPoint(4, x + (w / 2), y + h - 1);
361 thick.setPoint(5, x + w - 2, y + (h / 2) + 1);
362 thick.setPoint(6, x + (w / 2), y + h - 2);
363 thick.setPoint(7, x + w - 3, y + (h / 2) + 1);
364 p->setPen(cg.light());
365 p->drawLineSegments(thick);
366
367 thin.setPoint(0, x + 2, y + (h / 2));
368 thin.setPoint(1, x + (w / 2), y + 2);
369 thin.setPoint(2, x + (w / 2), y + 2);
370 thin.setPoint(3, x + w - 3, y + (h / 2));
371 p->setPen(Qt::black);
372 p->drawLineSegments(thin);
373
374 thin.setPoint(0, x + 3, y + (h / 2) + 1);
375 thin.setPoint(1, x + (w / 2), y + h - 3);
376 thin.setPoint(2, x + (w / 2), y + h - 3);
377 thin.setPoint(3, x + w - 4, y + (h / 2) + 1);
378 p->setPen(cg.mid());
379 p->drawLineSegments(thin);
380 } else {
381 thick.setPoint(0, x, y + (h / 2));
382 thick.setPoint(1, x + (w / 2), y);
383 thick.setPoint(2, x + 1, y + (h / 2));
384 thick.setPoint(3, x + (w / 2), y + 1);
385 thick.setPoint(4, x + (w / 2), y);
386 thick.setPoint(5, x + w - 1, y + (h / 2));
387 thick.setPoint(6, x + (w / 2), y + 1);
388 thick.setPoint(7, x + w - 2, y + (h / 2));
389 p->setPen(cg.light());
390 p->drawLineSegments(thick);
391
392 thick.setPoint(0, x + 2, y + (h / 2) + 1);
393 thick.setPoint(1, x + (w / 2), y + h - 2);
394 thick.setPoint(2, x + 3, y + (h / 2) + 1);
395 thick.setPoint(3, x + (w / 2), y + h - 3);
396 thick.setPoint(4, x + (w / 2), y + h - 2);
397 thick.setPoint(5, x + w - 3, y + (h / 2) + 1);
398 thick.setPoint(6, x + (w / 2), y + h - 3);
399 thick.setPoint(7, x + w - 4, y + (h / 2) + 1);
400 p->setPen(cg.dark());
401 p->drawLineSegments(thick);
402
403 thin.setPoint(0, x + 2, y + (h / 2));
404 thin.setPoint(1, x + (w / 2), y + 2);
405 thin.setPoint(2, x + (w / 2), y + 2);
406 thin.setPoint(3, x + w - 3, y + (h / 2));
407 p->setPen(button);
408 p->drawLineSegments(thin);
409
410 thin.setPoint(0, x + 1, y + (h / 2) + 1);
411 thin.setPoint(1, x + (w / 2), y + h - 1);
412 thin.setPoint(2, x + (w / 2), y + h - 1);
413 thin.setPoint(3, x + w - 2, y + (h / 2) + 1);
414 p->setPen(Qt::black);
415 p->drawLineSegments(thin);
416 }
417
418 p->setPen(oldpen);
419 break;
420 }
421
422
423
424 case PE_ArrowDown:
425 case PE_ArrowLeft:
426 case PE_ArrowRight:
427 case PE_ArrowUp:
428 {
429 QPen oldpen = p->pen();
430 QBrush oldbrush = p->brush();
431 QPointArray poly(3);
432 QColor button = (flags & Style_MouseOver) ? cg.midlight() : cg.button();
433 bool down = (flags & Style_Down);
434 int x, y, w, h;
435 r.rect(&x, &y, &w, &h);
436
437 p->save();
438 p->setBrush(button);
439
440 switch (pe) {
441 case PE_ArrowUp:
442 {
443 poly.setPoint(0, x + (w / 2), y );
444 poly.setPoint(1, x, y + h - 1);
445 poly.setPoint(2, x + w - 1, y + h - 1);
446 p->drawPolygon(poly);
447
448 if (down)
449 p->setPen(button);
450 else
451 p->setPen(cg.dark());
452 p->drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
453
454 if (down)
455 p->setPen(cg.light());
456 else
457 p->setPen(black);
458 p->drawLine(x, y + h - 1, x + w - 1, y + h - 1);
459
460 if (down)
461 p->setPen(button);
462 else
463 p->setPen(cg.dark());
464 p->drawLine(x + w - 2, y + h - 1, x + (w / 2), y + 1);
465
466 if (down)
467 p->setPen(cg.light());
468 else
469 p->setPen(black);
470 p->drawLine(x + w - 1, y + h - 1, x + (w / 2), y);
471
472 if (down)
473 p->setPen(black);
474 else
475 p->setPen(button);
476 p->drawLine(x + (w / 2), y + 1, x + 1, y + h - 1);
477
478 if (down)
479 p->setPen(cg.dark());
480 else
481 p->setPen(cg.light());
482 p->drawLine(x + (w / 2), y, x, y + h - 1);
483 break;
484 }
485
486 case PE_ArrowDown:
487 {
488 poly.setPoint(0, x + w - 1, y);
489 poly.setPoint(1, x, y);
490 poly.setPoint(2, x + (w / 2), y + h - 1);
491 p->drawPolygon(poly);
492
493 if (down)
494 p->setPen(black);
495 else
496 p->setPen(button);
497 p->drawLine(x + w - 2, y + 1, x + 1, y + 1);
498
499 if (down)
500 p->setPen(cg.dark());
501 else
502 p->setPen(cg.light());
503 p->drawLine(x + w - 1, y, x, y);
504
505 if (down)
506 p->setPen(black);
507 else
508 p->setPen(button);
509 p->drawLine(x + 1, y, x + (w / 2), y + h - 2);
510
511 if (down)
512 p->setPen(cg.dark());
513 else
514 p->setPen(cg.light());
515 p->drawLine(x, y, x + (w / 2), y + h - 1);
516
517 if (down)
518 p->setPen(button);
519 else
520 p->setPen(cg.dark());
521 p->drawLine(x + (w / 2), y + h - 2, x + w - 2, y);
522
523 if (down)
524 p->setPen(cg.light());
525 else
526 p->setPen(black);
527 p->drawLine(x + (w / 2), y + h - 1, x + w - 1, y);
528 break;
529 }
530
531 case PE_ArrowLeft:
532 {
533 poly.setPoint(0, x, y + (h / 2));
534 poly.setPoint(1, x + w - 1, y + h - 1);
535 poly.setPoint(2, x + w - 1, y);
536 p->drawPolygon(poly);
537
538 if (down)
539 p->setPen(button);
540 else
541 p->setPen(cg.dark());
542 p->drawLine(x + 1, y + (h / 2), x + w - 1, y + h - 1);
543
544 if (down)
545 p->setPen(cg.light());
546 else
547 p->setPen(black);
548 p->drawLine(x, y + (h / 2), x + w - 1, y + h - 1);
549
550 if (down)
551 p->setPen(button);
552 else
553 p->setPen(cg.dark());
554 p->drawLine(x + w - 2, y + h - 1, x + w - 2, y + 1);
555
556 if (down)
557 p->setPen(cg.light());
558 else
559 p->setPen(black);
560 p->drawLine(x + w - 1, y + h - 1, x + w - 1, y);
561
562 if (down)
563 p->setPen(black);
564 else
565 p->setPen(button);
566 p->drawLine(x + w - 1, y + 1, x + 1, y + (h / 2));
567
568 if (down)
569 p->setPen(cg.dark());
570 else
571 p->setPen(cg.light());
572 p->drawLine(x + w - 1, y, x, y + (h / 2));
573 break;
574 }
575
576 case PE_ArrowRight:
577 {
578 poly.setPoint(0, x + w - 1, y + (h / 2));
579 poly.setPoint(1, x, y);
580 poly.setPoint(2, x, y + h - 1);
581 p->drawPolygon(poly);
582
583 if (down)
584 p->setPen(black);
585 else
586 p->setPen(button);
587 p->drawLine( x + w - 1, y + (h / 2), x + 1, y + 1);
588
589 if (down)
590 p->setPen(cg.dark());
591 else
592 p->setPen(cg.light());
593 p->drawLine(x + w - 1, y + (h / 2), x, y);
594
595 if (down)
596 p->setPen(black);
597 else
598 p->setPen(button);
599 p->drawLine(x + 1, y + 1, x + 1, y + h - 2);
600
601 if (down)
602 p->setPen(cg.dark());
603 else
604 p->setPen(cg.light());
605 p->drawLine(x, y, x, y + h - 1);
606
607 if (down)
608 p->setPen(button);
609 else
610 p->setPen(cg.dark());
611 p->drawLine(x + 1, y + h - 2, x + w - 1, y + (h / 2));
612
613 if (down)
614 p->setPen(cg.light());
615 else
616 p->setPen(black);
617 p->drawLine(x, y + h - 1, x + w - 1, y + (h / 2));
618 break;
619 }
620
621 default:
622 break;
623 }
624
625 p->restore();
626 p->setBrush(oldbrush);
627 p->setPen(oldpen);
628 break;
629 }
630
631 default:
632 QMotifStyle::drawPrimitive(pe, p, r, cg, flags, opt);
633 break;
634 }
635}
636
637
638/*! \reimp
639*/
640void QMotifPlusStyle::drawControl( ControlElement element,
641 QPainter *p,
642 const QWidget *widget,
643 const QRect &r,
644 const QColorGroup &cg,
645 SFlags flags,
646 const QStyleOption& opt ) const
647{
648 if (widget == singleton->hoverWidget)
649 flags |= Style_MouseOver;
650
651 switch (element) {
652 case CE_PushButton:
653 {
654#ifndef QT_NO_PUSHBUTTON
655 const QPushButton *button = (const QPushButton *) widget;
656 QRect br = r;
657 int dbi = pixelMetric(PM_ButtonDefaultIndicator, widget);
658
659 if (button->isDefault() || button->autoDefault()) {
660 if (button->isDefault())
661 drawMotifPlusShade(p, br, cg, TRUE, FALSE,
662 &cg.brush(QColorGroup::Background));
663
664 br.setCoords(br.left() + dbi,
665 br.top() + dbi,
666 br.right() - dbi,
667 br.bottom() - dbi);
668 }
669
670 if (flags & Style_HasFocus)
671 br.addCoords(1, 1, -1, -1);
672 p->save();
673 p->setBrushOrigin( -button->backgroundOffset().x(),
674 -button->backgroundOffset().y() );
675 drawPrimitive(PE_ButtonCommand, p, br, cg, flags);
676 p->restore();
677#endif
678 break;
679 }
680
681 case CE_CheckBoxLabel:
682 {
683#ifndef QT_NO_CHECKBOX
684 const QCheckBox *checkbox = (const QCheckBox *) widget;
685
686 if (flags & Style_MouseOver) {
687 QRegion r(checkbox->rect());
688 r -= visualRect(subRect(SR_CheckBoxIndicator, widget), widget);
689 p->setClipRegion(r);
690 p->fillRect(checkbox->rect(), cg.brush(QColorGroup::Midlight));
691 p->setClipping(FALSE);
692 }
693
694 int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft;
695 drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg,
696 flags & Style_Enabled, checkbox->pixmap(), checkbox->text());
697
698 if (checkbox->hasFocus()) {
699 QRect fr = visualRect(subRect(SR_CheckBoxFocusRect, widget), widget);
700 drawPrimitive(PE_FocusRect, p, fr, cg, flags);
701 }
702#endif
703 break;
704 }
705
706 case CE_RadioButtonLabel:
707 {
708#ifndef QT_NO_RADIOBUTTON
709 const QRadioButton *radiobutton = (const QRadioButton *) widget;
710
711 if (flags & Style_MouseOver) {
712 QRegion r(radiobutton->rect());
713 r -= visualRect(subRect(SR_RadioButtonIndicator, widget), widget);
714 p->setClipRegion(r);
715 p->fillRect(radiobutton->rect(), cg.brush(QColorGroup::Midlight));
716 p->setClipping(FALSE);
717 }
718
719 int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft;
720 drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg,
721 flags & Style_Enabled, radiobutton->pixmap(), radiobutton->text());
722
723 if (radiobutton->hasFocus()) {
724 QRect fr = visualRect(subRect(SR_RadioButtonFocusRect, widget), widget);
725 drawPrimitive(PE_FocusRect, p, fr, cg, flags);
726 }
727#endif
728 break;
729 }
730
731 case CE_MenuBarItem:
732 {
733#ifndef QT_NO_MENUDATA
734 if (opt.isDefault())
735 break;
736
737 QMenuItem *mi = opt.menuItem();
738 if ((flags & Style_Enabled) && (flags & Style_Active))
739 drawMotifPlusShade(p, r, cg, FALSE, TRUE);
740 else
741 p->fillRect(r, cg.button());
742
743 drawItem(p, r, AlignCenter | ShowPrefix | DontClip | SingleLine,
744 cg, flags & Style_Enabled, mi->pixmap(), mi->text(), -1,
745 &cg.buttonText());
746#endif
747 break;
748 }
749
750
751#ifndef QT_NO_POPUPMENU
752 case CE_PopupMenuItem:
753 {
754 if (! widget || opt.isDefault())
755 break;
756
757 QPopupMenu *popupmenu = (QPopupMenu *) widget;
758 QMenuItem *mi = opt.menuItem();
759
760 // QPopupMenu has WResizeNoErase and WRepaintNoErase flags, so we
761 // must erase areas not covered by menu items (this is requested by
762 // QPopupMenu using 0 as the menu item argument).
763 // [Win32 version feels ok without this, because it doesn't actually
764 // fully obey WResizeNoErase and WRepaintNoErase: WM_ERASEBKGND always
765 // erases the background before WM_PAINT and after every resize].
766#if !defined (Q_WS_PM)
767 if ( !mi )
768 break;
769#endif
770
771 int tab = opt.tabWidth();
772 int maxpmw = opt.maxIconWidth();
773 bool dis = ! (flags & Style_Enabled);
774 bool checkable = popupmenu->isCheckable();
775 bool act = flags & Style_Active;
776 int x, y, w, h;
777
778 r.rect(&x, &y, &w, &h);
779
780 if (checkable)
781 maxpmw = QMAX(maxpmw, 15);
782
783 int checkcol = maxpmw;
784
785 if (mi && mi->isSeparator()) {
786 p->setPen( cg.dark() );
787 p->drawLine( x, y, x+w, y );
788 p->setPen( cg.light() );
789 p->drawLine( x, y+1, x+w, y+1 );
790 return;
791 }
792
793 if ( act && !dis )
794 drawMotifPlusShade(p, QRect(x, y, w, h), cg, FALSE, TRUE);
795 else
796 p->fillRect(x, y, w, h, cg.brush( QColorGroup::Button ));
797
798 if ( !mi )
799 return;
800
801 QRect vrect = visualRect( QRect( x+2, y+2, checkcol, h-2 ), r );
802 if ( mi->isChecked() ) {
803 if ( mi->iconSet() ) {
804 qDrawShadePanel( p, vrect.x(), y+2, checkcol, h-2*2,
805 cg, TRUE, 1, &cg.brush( QColorGroup::Midlight ) );
806 }
807 } else if ( !act ) {
808 p->fillRect(vrect,
809 cg.brush( QColorGroup::Button ));
810 }
811
812 if ( mi->iconSet() ) { // draw iconset
813 QIconSet::Mode mode = (!dis) ? QIconSet::Normal : QIconSet::Disabled;
814
815 if (act && !dis)
816 mode = QIconSet::Active;
817
818 QPixmap pixmap;
819 if ( checkable && mi->isChecked() )
820 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode,
821 QIconSet::On );
822 else
823 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
824
825 int pixw = pixmap.width();
826 int pixh = pixmap.height();
827
828 QRect pmr( 0, 0, pixw, pixh );
829
830 pmr.moveCenter(vrect.center());
831
832 p->setPen( cg.text() );
833 p->drawPixmap( pmr.topLeft(), pixmap );
834
835 } else if (checkable) {
836 if (mi->isChecked()) {
837 SFlags cflags = Style_Default;
838 if (! dis)
839 cflags |= Style_Enabled;
840 if (act)
841 cflags |= Style_On;
842
843 drawPrimitive(PE_CheckMark, p, vrect, cg, cflags);
844 }
845 }
846
847 p->setPen( cg.buttonText() );
848
849 QColor discol;
850 if (dis) {
851 discol = cg.text();
852 p->setPen( discol );
853 }
854
855 vrect = visualRect( QRect(x + checkcol + 4, y + 2,
856 w - checkcol - tab - 3, h - 4), r );
857 if (mi->custom()) {
858 p->save();
859 mi->custom()->paint(p, cg, act, !dis, vrect.x(), y + 2,
860 w - checkcol - tab - 3, h - 4);
861 p->restore();
862 }
863
864 QString s = mi->text();
865 if ( !s.isNull() ) { // draw text
866 int t = s.find( '\t' );
867 int m = 2;
868 int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
869 text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
870 if ( t >= 0 ) { // draw tab text
871 QRect vr = visualRect( QRect(x+w-tab-2-2,
872 y+m, tab, h-2*m), r );
873 p->drawText( vr.x(),
874 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
875 }
876 p->drawText(vrect.x(), y + 2, w - checkcol -tab - 3, h - 4,
877 text_flags, s, t);
878 } else if (mi->pixmap()) {
879 QPixmap *pixmap = mi->pixmap();
880
881 if (pixmap->depth() == 1) p->setBackgroundMode(OpaqueMode);
882 QRect vr = visualRect( QRect( x + checkcol + 2, y + 2, w - checkcol - 1, h - 4 ), r );
883 p->drawPixmap(vr.x(), y + 2, *pixmap);
884 if (pixmap->depth() == 1) p->setBackgroundMode(TransparentMode);
885 }
886
887 if (mi->popup()) {
888 int hh = h / 2;
889 QStyle::PrimitiveElement arrow = (QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight);
890 vrect = visualRect( QRect(x + w - hh - 6, y + (hh / 2), hh, hh), r );
891 drawPrimitive(arrow, p,
892 vrect, cg,
893 ((act && !dis) ?
894 Style_Down : Style_Default) |
895 ((!dis) ? Style_Enabled : Style_Default));
896 }
897 break;
898 }
899#endif // QT_NO_POPUPMENU
900
901 case CE_TabBarTab:
902 {
903#ifndef QT_NO_TABBAR
904 const QTabBar *tabbar = (const QTabBar *) widget;
905 bool selected = flags & Style_Selected;
906
907 QColorGroup g = tabbar->colorGroup();
908 QPen oldpen = p->pen();
909 QRect fr(r);
910
911 if (! selected) {
912 if (tabbar->shape() == QTabBar::RoundedAbove ||
913 tabbar->shape() == QTabBar::TriangularAbove) {
914 fr.setTop(fr.top() + 2);
915 } else {
916 fr.setBottom(fr.bottom() - 2);
917 }
918 }
919
920 fr.setWidth(fr.width() - 3);
921
922 p->fillRect(fr.left() + 1, fr.top() + 1, fr.width() - 2, fr.height() - 2,
923 (selected) ? cg.brush(QColorGroup::Button)
924 : cg.brush(QColorGroup::Mid));
925
926 if (tabbar->shape() == QTabBar::RoundedAbove) {
927 // "rounded" tabs on top
928 fr.setBottom(fr.bottom() - 1);
929
930 p->setPen(g.light());
931 p->drawLine(fr.left(), fr.top() + 1,
932 fr.left(), fr.bottom() - 1);
933 p->drawLine(fr.left() + 1, fr.top(),
934 fr.right() - 1, fr.top());
935 if (! selected)
936 p->drawLine(fr.left(), fr.bottom(),
937 fr.right() + 3, fr.bottom());
938
939 if (fr.left() == 0)
940 p->drawLine(fr.left(), fr.bottom(),
941 fr.left(), fr.bottom() + 1);
942
943 p->setPen(g.dark());
944 p->drawLine(fr.right() - 1, fr.top() + 2,
945 fr.right() - 1, fr.bottom() - 1);
946
947 p->setPen(black);
948 p->drawLine(fr.right(), fr.top() + 1,
949 fr.right(), fr.bottom() - 1);
950 } else if (tabbar->shape() == QTabBar::RoundedBelow) {
951 // "rounded" tabs on bottom
952 fr.setTop(fr.top() + 1);
953
954 p->setPen(g.dark());
955 p->drawLine(fr.right() + 3, fr.top() - 1,
956 fr.right() - 1, fr.top() - 1);
957 p->drawLine(fr.right() - 1, fr.top(),
958 fr.right() - 1, fr.bottom() - 2);
959 p->drawLine(fr.right() - 1, fr.bottom() - 2,
960 fr.left() + 2, fr.bottom() - 2);
961 if (! selected) {
962 p->drawLine(fr.right(), fr.top() - 1,
963 fr.left() + 1, fr.top() - 1);
964
965 if (fr.left() != 0)
966 p->drawPoint(fr.left(), fr.top() - 1);
967 }
968
969 p->setPen(black);
970 p->drawLine(fr.right(), fr.top(),
971 fr.right(), fr.bottom() - 2);
972 p->drawLine(fr.right() - 1, fr.bottom() - 1,
973 fr.left(), fr.bottom() - 1);
974 if (! selected)
975 p->drawLine(fr.right() + 3, fr.top(),
976 fr.left(), fr.top());
977 else
978 p->drawLine(fr.right() + 3, fr.top(),
979 fr.right(), fr.top());
980
981 p->setPen(g.light());
982 p->drawLine(fr.left(), fr.top() + 1,
983 fr.left(), fr.bottom() - 2);
984
985 if (selected) {
986 p->drawPoint(fr.left(), fr.top());
987 if (fr.left() == 0)
988 p->drawPoint(fr.left(), fr.top() - 1);
989
990 p->setPen(g.button());
991 p->drawLine(fr.left() + 2, fr.top() - 1,
992 fr.left() + 1, fr.top() - 1);
993 }
994 } else
995 // triangular drawing code
996 QMotifStyle::drawControl(element, p, widget, r, cg, flags, opt);
997
998 p->setPen(oldpen);
999#endif
1000 break;
1001 }
1002
1003 default:
1004 QMotifStyle::drawControl(element, p, widget, r, cg, flags, opt);
1005 break;
1006 }
1007}
1008
1009
1010/*! \reimp
1011*/
1012QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const
1013{
1014 QRect rect;
1015
1016 switch (r) {
1017 case SR_PushButtonFocusRect:
1018 {
1019#ifndef QT_NO_PUSHBUTTON
1020 const QPushButton *button = (const QPushButton *) widget;
1021 int dfi = pixelMetric(PM_ButtonDefaultIndicator, widget);
1022
1023 rect = button->rect();
1024 if (button->isDefault() || button->autoDefault())
1025 rect.addCoords(dfi, dfi, -dfi, -dfi);
1026#endif
1027 break;
1028 }
1029
1030 case SR_CheckBoxIndicator:
1031 {
1032 int h = pixelMetric( PM_IndicatorHeight );
1033 rect.setRect(( widget->rect().height() - h ) / 2,
1034 ( widget->rect().height() - h ) / 2,
1035 pixelMetric( PM_IndicatorWidth ), h );
1036 break;
1037 }
1038
1039 case SR_RadioButtonIndicator:
1040 {
1041 int h = pixelMetric( PM_ExclusiveIndicatorHeight );
1042 rect.setRect( ( widget->rect().height() - h ) / 2,
1043 ( widget->rect().height() - h ) / 2,
1044 pixelMetric( PM_ExclusiveIndicatorWidth ), h );
1045 break;
1046 }
1047
1048 case SR_CheckBoxFocusRect:
1049 case SR_RadioButtonFocusRect:
1050 rect = widget->rect();
1051 break;
1052
1053 case SR_ComboBoxFocusRect:
1054 {
1055#ifndef QT_NO_COMBOBOX
1056 const QComboBox *combobox = (const QComboBox *) widget;
1057
1058 if (combobox->editable()) {
1059 rect = querySubControlMetrics(CC_ComboBox, widget,
1060 SC_ComboBoxEditField);
1061 rect.addCoords(-3, -3, 3, 3);
1062 } else
1063 rect = combobox->rect();
1064#endif
1065 break;
1066 }
1067
1068 case SR_SliderFocusRect:
1069 {
1070#ifndef QT_NO_SLIDER
1071 const QSlider *slider = (const QSlider *) widget;
1072 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget );
1073 int thickness = pixelMetric( PM_SliderControlThickness, widget );
1074 int x, y, wi, he;
1075
1076 if ( slider->orientation() == Horizontal ) {
1077 x = 0;
1078 y = tickOffset;
1079 wi = slider->width();
1080 he = thickness;
1081 } else {
1082 x = tickOffset;
1083 y = 0;
1084 wi = thickness;
1085 he = slider->height();
1086 }
1087
1088 rect.setRect(x, y, wi, he);
1089#endif
1090 break;
1091 }
1092
1093 default:
1094 rect = QMotifStyle::subRect(r, widget);
1095 break;
1096 }
1097
1098 return rect;
1099}
1100
1101
1102/*! \reimp */
1103void QMotifPlusStyle::drawComplexControl(ComplexControl control,
1104 QPainter *p,
1105 const QWidget *widget,
1106 const QRect &r,
1107 const QColorGroup &cg,
1108 SFlags flags,
1109 SCFlags controls,
1110 SCFlags active,
1111 const QStyleOption& opt ) const
1112{
1113 if (widget == singleton->hoverWidget)
1114 flags |= Style_MouseOver;
1115
1116 switch (control) {
1117 case CC_ScrollBar:
1118 {
1119#ifndef QT_NO_SCROLLBAR
1120 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1121 QRect addline, subline, addpage, subpage, slider, first, last;
1122 bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
1123
1124 subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, opt);
1125 addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, opt);
1126 subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, opt);
1127 addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, opt);
1128 slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, opt);
1129 first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, opt);
1130 last = querySubControlMetrics(control, widget, SC_ScrollBarLast, opt);
1131
1132 bool skipUpdate = FALSE;
1133 if (singleton->hovering) {
1134 if (addline.contains(singleton->mousePos)) {
1135 skipUpdate =
1136 (singleton->scrollbarElement == SC_ScrollBarAddLine);
1137 singleton->scrollbarElement = SC_ScrollBarAddLine;
1138 } else if (subline.contains(singleton->mousePos)) {
1139 skipUpdate =
1140 (singleton->scrollbarElement == SC_ScrollBarSubLine);
1141 singleton->scrollbarElement = SC_ScrollBarSubLine;
1142 } else if (slider.contains(singleton->mousePos)) {
1143 skipUpdate =
1144 (singleton->scrollbarElement == SC_ScrollBarSlider);
1145 singleton->scrollbarElement = SC_ScrollBarSlider;
1146 } else {
1147 skipUpdate =
1148 (singleton->scrollbarElement == 0);
1149 singleton->scrollbarElement = 0;
1150 }
1151 } else
1152 singleton->scrollbarElement = 0;
1153
1154 if (skipUpdate && singleton->scrollbarElement == singleton->lastElement)
1155 break;
1156
1157 singleton->lastElement = singleton->scrollbarElement;
1158
1159 if (controls == (SC_ScrollBarAddLine | SC_ScrollBarSubLine |
1160 SC_ScrollBarAddPage | SC_ScrollBarSubPage |
1161 SC_ScrollBarFirst | SC_ScrollBarLast | SC_ScrollBarSlider))
1162 drawMotifPlusShade(p, widget->rect(), cg, TRUE, FALSE,
1163 &cg.brush(QColorGroup::Mid));
1164
1165 if ((controls & SC_ScrollBarSubLine) && subline.isValid())
1166 drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
1167 ((active == SC_ScrollBarSubLine ||
1168 singleton->scrollbarElement == SC_ScrollBarSubLine) ?
1169 Style_MouseOver: Style_Default) |
1170 ((maxedOut) ? Style_Default : Style_Enabled) |
1171 ((active == SC_ScrollBarSubLine) ?
1172 Style_Down : Style_Default) |
1173 ((scrollbar->orientation() == Qt::Horizontal) ?
1174 Style_Horizontal : Style_Default));
1175 if ((controls & SC_ScrollBarAddLine) && addline.isValid())
1176 drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
1177 ((active == SC_ScrollBarAddLine ||
1178 singleton->scrollbarElement == SC_ScrollBarAddLine) ?
1179 Style_MouseOver: Style_Default) |
1180 ((maxedOut) ? Style_Default : Style_Enabled) |
1181 ((active == SC_ScrollBarAddLine) ?
1182 Style_Down : Style_Default) |
1183 ((scrollbar->orientation() == Qt::Horizontal) ?
1184 Style_Horizontal : Style_Default));
1185 if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
1186 drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
1187 ((maxedOut) ? Style_Default : Style_Enabled) |
1188 ((active == SC_ScrollBarSubPage) ?
1189 Style_Down : Style_Default) |
1190 ((scrollbar->orientation() == Qt::Horizontal) ?
1191 Style_Horizontal : Style_Default));
1192 if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
1193 drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
1194 ((maxedOut) ? Style_Default : Style_Enabled) |
1195 ((active == SC_ScrollBarAddPage) ?
1196 Style_Down : Style_Default) |
1197 ((scrollbar->orientation() == Qt::Horizontal) ?
1198 Style_Horizontal : Style_Default));
1199 if ((controls & SC_ScrollBarFirst) && first.isValid())
1200 drawPrimitive(PE_ScrollBarFirst, p, first, cg,
1201 ((maxedOut) ? Style_Default : Style_Enabled) |
1202 ((active == SC_ScrollBarFirst) ?
1203 Style_Down : Style_Default) |
1204 ((scrollbar->orientation() == Qt::Horizontal) ?
1205 Style_Horizontal : Style_Default));
1206 if ((controls & SC_ScrollBarLast) && last.isValid())
1207 drawPrimitive(PE_ScrollBarLast, p, last, cg,
1208 ((maxedOut) ? Style_Default : Style_Enabled) |
1209 ((active == SC_ScrollBarLast) ?
1210 Style_Down : Style_Default) |
1211 ((scrollbar->orientation() == Qt::Horizontal) ?
1212 Style_Horizontal : Style_Default));
1213 if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
1214 drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
1215 ((active == SC_ScrollBarSlider ||
1216 singleton->scrollbarElement == SC_ScrollBarSlider) ?
1217 Style_MouseOver: Style_Default) |
1218 ((maxedOut) ? Style_Default : Style_Enabled) |
1219 ((scrollbar->orientation() == Qt::Horizontal) ?
1220 Style_Horizontal : Style_Default));
1221
1222 // ### perhaps this should not be able to accept focus if maxedOut?
1223 if (scrollbar->hasFocus()) {
1224 QRect fr(slider.x() + 2, slider.y() + 2,
1225 slider.width() - 5, slider.height() - 5);
1226 drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default);
1227 }
1228 }
1229#endif
1230 break;
1231 }
1232
1233 case CC_ComboBox:
1234 {
1235#ifndef QT_NO_COMBOBOX
1236 const QComboBox *combobox = (const QComboBox *) widget;
1237
1238 QRect editfield, arrow;
1239 editfield =
1240 visualRect(querySubControlMetrics(CC_ComboBox,
1241 combobox,
1242 SC_ComboBoxEditField,
1243 opt), widget);
1244 arrow =
1245 visualRect(querySubControlMetrics(CC_ComboBox,
1246 combobox,
1247 SC_ComboBoxArrow,
1248 opt), widget);
1249
1250 if (combobox->editable()) {
1251 if (controls & SC_ComboBoxEditField && editfield.isValid()) {
1252 editfield.addCoords(-3, -3, 3, 3);
1253 if (combobox->hasFocus())
1254 editfield.addCoords(1, 1, -1, -1);
1255 drawMotifPlusShade(p, editfield, cg, TRUE, FALSE,
1256 (widget->isEnabled() ?
1257 &cg.brush(QColorGroup::Base) :
1258 &cg.brush(QColorGroup::Background)));
1259 }
1260
1261 if (controls & SC_ComboBoxArrow && arrow.isValid()) {
1262 drawMotifPlusShade(p, arrow, cg, (active == SC_ComboBoxArrow),
1263 (flags & Style_MouseOver));
1264
1265 int space = (r.height() - 13) / 2;
1266 arrow.addCoords(space, space, -space, -space);
1267
1268 if (active == SC_ComboBoxArrow)
1269 flags |= Style_Sunken;
1270 drawPrimitive(PE_ArrowDown, p, arrow, cg, flags);
1271 }
1272 } else {
1273 if (controls & SC_ComboBoxEditField && editfield.isValid()) {
1274 editfield.addCoords(-3, -3, 3, 3);
1275 if (combobox->hasFocus())
1276 editfield.addCoords(1, 1, -1, -1);
1277 drawMotifPlusShade(p, editfield, cg, FALSE,
1278 (flags & Style_MouseOver));
1279 }
1280
1281 if (controls & SC_ComboBoxArrow && arrow.isValid())
1282 drawMotifPlusShade(p, arrow, cg, FALSE, (flags & Style_MouseOver));
1283 }
1284
1285 if (combobox->hasFocus() ||
1286 (combobox->editable() && combobox->lineEdit()->hasFocus())) {
1287 QRect fr = visualRect(subRect(SR_ComboBoxFocusRect, widget), widget);
1288 drawPrimitive(PE_FocusRect, p, fr, cg, flags);
1289 }
1290#endif
1291 break;
1292 }
1293
1294 case CC_SpinWidget:
1295 {
1296#ifndef QT_NO_SPINWIDGET
1297 const QSpinWidget * sw = (const QSpinWidget *) widget;
1298 SFlags flags = Style_Default;
1299
1300 if (controls & SC_SpinWidgetFrame)
1301 drawMotifPlusShade(p, r, cg, TRUE, FALSE, &cg.brush(QColorGroup::Base));
1302
1303 if (controls & SC_SpinWidgetUp) {
1304 flags = Style_Enabled;
1305 if (active == SC_SpinWidgetUp )
1306 flags |= Style_Down;
1307
1308 PrimitiveElement pe;
1309 if ( sw->buttonSymbols() == QSpinWidget::PlusMinus )
1310 pe = PE_SpinWidgetPlus;
1311 else
1312 pe = PE_SpinWidgetUp;
1313
1314 QRect re = sw->upRect();
1315 QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled();
1316 drawPrimitive(pe, p, re, ucg, flags);
1317 }
1318
1319 if (controls & SC_SpinWidgetDown) {
1320 flags = Style_Enabled;
1321 if (active == SC_SpinWidgetDown )
1322 flags |= Style_Down;
1323
1324 PrimitiveElement pe;
1325 if ( sw->buttonSymbols() == QSpinWidget::PlusMinus )
1326 pe = PE_SpinWidgetMinus;
1327 else
1328 pe = PE_SpinWidgetDown;
1329
1330 QRect re = sw->downRect();
1331 QColorGroup dcg = sw->isDownEnabled() ? cg : sw->palette().disabled();
1332 drawPrimitive(pe, p, re, dcg, flags);
1333 }
1334#endif
1335 break;
1336 }
1337
1338 case CC_Slider:
1339 {
1340#ifndef QT_NO_SLIDER
1341 const QSlider *slider = (const QSlider *) widget;
1342 bool mouseover = (flags & Style_MouseOver);
1343
1344 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
1345 opt),
1346 handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
1347 opt);
1348
1349 if ((controls & SC_SliderGroove) && groove.isValid()) {
1350 drawMotifPlusShade(p, groove, cg, TRUE, FALSE,
1351 &cg.brush(QColorGroup::Mid));
1352
1353 if ( flags & Style_HasFocus ) {
1354 QRect fr = subRect( SR_SliderFocusRect, widget );
1355 drawPrimitive( PE_FocusRect, p, fr, cg, flags );
1356 }
1357 }
1358
1359 if ((controls & SC_SliderHandle) && handle.isValid()) {
1360 if ((mouseover && handle.contains(singleton->mousePos)) ||
1361 singleton->sliderActive)
1362 flags |= Style_MouseOver;
1363 else
1364 flags &= ~Style_MouseOver;
1365 drawPrimitive(PE_ButtonBevel, p, handle, cg, flags | Style_Raised);
1366
1367 if ( slider->orientation() == Horizontal ) {
1368 QCOORD mid = handle.x() + handle.width() / 2;
1369 qDrawShadeLine( p, mid, handle.y() + 1, mid ,
1370 handle.y() + handle.height() - 3,
1371 cg, TRUE, 1);
1372 } else {
1373 QCOORD mid = handle.y() + handle.height() / 2;
1374 qDrawShadeLine( p, handle.x() + 1, mid,
1375 handle.x() + handle.width() - 3, mid,
1376 cg, TRUE, 1);
1377 }
1378 }
1379
1380 if (controls & SC_SliderTickmarks)
1381 QMotifStyle::drawComplexControl(control, p, widget, r, cg, flags,
1382 SC_SliderTickmarks, active, opt);
1383#endif
1384 break;
1385 }
1386
1387 default:
1388 QMotifStyle::drawComplexControl(control, p, widget, r, cg, flags,
1389 controls, active, opt);
1390 }
1391}
1392
1393
1394/*! \reimp
1395*/
1396QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control,
1397 const QWidget *widget,
1398 SubControl subcontrol,
1399 const QStyleOption& opt) const
1400{
1401 switch (control) {
1402 case CC_SpinWidget: {
1403 int fw = pixelMetric( PM_SpinBoxFrameWidth, 0 );
1404 QSize bs;
1405 bs.setHeight( (widget->height() + 1)/2 );
1406 if ( bs.height() < 10 )
1407 bs.setHeight( 10 );
1408 bs.setWidth( bs.height() ); // 1.6 -approximate golden mean
1409 bs = bs.expandedTo( QApplication::globalStrut() );
1410 int y = 0;
1411 int x, lx, rx, h;
1412 x = widget->width() - y - bs.width();
1413 lx = fw;
1414 rx = x - fw * 2;
1415 h = bs.height() * 2;
1416
1417 switch ( subcontrol ) {
1418 case SC_SpinWidgetUp:
1419 return QRect(x + 1, y, bs.width(), bs.height() - 1);
1420 case SC_SpinWidgetDown:
1421 return QRect(x + 1, y + bs.height() + 1, bs.width(), bs.height());
1422 case SC_SpinWidgetButtonField:
1423 return QRect(x, y, bs.width(), h - 2*fw);
1424 case SC_SpinWidgetEditField:
1425 return QRect(lx, fw, rx, h - 2*fw);
1426 case SC_SpinWidgetFrame:
1427 return QRect( 0, 0, widget->width() - bs.width(), h);
1428 default:
1429 break;
1430 }
1431 break; }
1432
1433#ifndef QT_NO_COMBOBOX
1434 case CC_ComboBox: {
1435 const QComboBox *combobox = (const QComboBox *) widget;
1436 if (combobox->editable()) {
1437 int space = (combobox->height() - 13) / 2;
1438 switch (subcontrol) {
1439 case SC_ComboBoxFrame:
1440 return QRect();
1441 case SC_ComboBoxEditField: {
1442 QRect rect = widget->rect();
1443 rect.setWidth(rect.width() - 13 - space * 2);
1444 rect.addCoords(3, 3, -3, -3);
1445 return rect; }
1446 case SC_ComboBoxArrow:
1447 return QRect(combobox->width() - 13 - space * 2, 0,
1448 13 + space * 2, combobox->height());
1449 default: break; // shouldn't get here
1450 }
1451
1452 } else {
1453 int space = (combobox->height() - 7) / 2;
1454 switch (subcontrol) {
1455 case SC_ComboBoxFrame:
1456 return QRect();
1457 case SC_ComboBoxEditField: {
1458 QRect rect = widget->rect();
1459 rect.addCoords(3, 3, -3, -3);
1460 return rect; }
1461 case SC_ComboBoxArrow: // 12 wide, 7 tall
1462 return QRect(combobox->width() - 12 - space, space, 12, 7);
1463 default: break; // shouldn't get here
1464 }
1465 }
1466 break; }
1467#endif
1468
1469#ifndef QT_NO_SLIDER
1470 case CC_Slider: {
1471
1472 if (subcontrol == SC_SliderHandle) {
1473 const QSlider *slider = (const QSlider *) widget;
1474 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget );
1475 int thickness = pixelMetric( PM_SliderControlThickness, widget );
1476 int len = pixelMetric( PM_SliderLength, widget ) + 2;
1477 int sliderPos = slider->sliderStart();
1478 int motifBorder = 2;
1479
1480 if ( slider->orientation() == Horizontal )
1481 return QRect( sliderPos + motifBorder, tickOffset + motifBorder, len,
1482 thickness - 2*motifBorder );
1483 return QRect( tickOffset + motifBorder, sliderPos + motifBorder,
1484 thickness - 2*motifBorder, len);
1485 }
1486 break; }
1487#endif
1488 default: break;
1489 }
1490 return QMotifStyle::querySubControlMetrics(control, widget, subcontrol, opt);
1491}
1492
1493
1494/*! \reimp */
1495bool QMotifPlusStyle::eventFilter(QObject *object, QEvent *event)
1496{
1497 switch(event->type()) {
1498 case QEvent::MouseButtonPress:
1499 {
1500 singleton->mousePressed = TRUE;
1501
1502 if (!::qt_cast<QSlider*>(object))
1503 break;
1504
1505 singleton->sliderActive = TRUE;
1506 break;
1507 }
1508
1509 case QEvent::MouseButtonRelease:
1510 {
1511 singleton->mousePressed = FALSE;
1512
1513 if (!::qt_cast<QSlider*>(object))
1514 break;
1515
1516 singleton->sliderActive = FALSE;
1517 ((QWidget *) object)->repaint(FALSE);
1518 break;
1519 }
1520
1521 case QEvent::Enter:
1522 {
1523 if (! object->isWidgetType())
1524 break;
1525
1526 singleton->hoverWidget = (QWidget *) object;
1527 if (! singleton->hoverWidget->isEnabled()) {
1528 singleton->hoverWidget = 0;
1529 break;
1530 }
1531 singleton->hoverWidget->repaint(FALSE);
1532 break;
1533 }
1534
1535 case QEvent::Leave:
1536 {
1537 if (object != singleton->hoverWidget)
1538 break;
1539 QWidget *w = singleton->hoverWidget;
1540 singleton->hoverWidget = 0;
1541 w->repaint(FALSE);
1542 break;
1543 }
1544
1545 case QEvent::MouseMove:
1546 {
1547 if (! object->isWidgetType() || object != singleton->hoverWidget)
1548 break;
1549
1550 if (!::qt_cast<QScrollBar*>(object) && ! ::qt_cast<QSlider*>(object))
1551 break;
1552
1553 singleton->mousePos = ((QMouseEvent *) event)->pos();
1554 if (! singleton->mousePressed) {
1555 singleton->hovering = TRUE;
1556 singleton->hoverWidget->repaint(FALSE);
1557 singleton->hovering = FALSE;
1558 }
1559
1560 break;
1561 }
1562
1563 default:
1564 break;
1565 }
1566
1567 return QMotifStyle::eventFilter(object, event);
1568}
1569
1570
1571/*! \reimp */
1572int QMotifPlusStyle::styleHint(StyleHint hint,
1573 const QWidget *widget,
1574 const QStyleOption &opt,
1575 QStyleHintReturn *returnData) const
1576{
1577 int ret;
1578 switch (hint) {
1579 case SH_PopupMenu_MouseTracking:
1580 ret = 1;
1581 break;
1582 default:
1583 ret = QMotifStyle::styleHint(hint, widget, opt, returnData);
1584 break;
1585 }
1586 return ret;
1587}
1588
1589
1590#endif // QT_NO_STYLE_MOTIFPLUS
Note: See TracBrowser for help on using the repository browser.