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

Last change on this file since 7 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 43.4 KB
Line 
1/****************************************************************************
2** $Id: qmotifplusstyle.cpp 2 2005-11-16 15:49:26Z 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 if ( !mi )
760 break;
761
762 int tab = opt.tabWidth();
763 int maxpmw = opt.maxIconWidth();
764 bool dis = ! (flags & Style_Enabled);
765 bool checkable = popupmenu->isCheckable();
766 bool act = flags & Style_Active;
767 int x, y, w, h;
768
769 r.rect(&x, &y, &w, &h);
770
771 if (checkable)
772 maxpmw = QMAX(maxpmw, 15);
773
774 int checkcol = maxpmw;
775
776 if (mi && mi->isSeparator()) {
777 p->setPen( cg.dark() );
778 p->drawLine( x, y, x+w, y );
779 p->setPen( cg.light() );
780 p->drawLine( x, y+1, x+w, y+1 );
781 return;
782 }
783
784 if ( act && !dis )
785 drawMotifPlusShade(p, QRect(x, y, w, h), cg, FALSE, TRUE);
786 else
787 p->fillRect(x, y, w, h, cg.brush( QColorGroup::Button ));
788
789 if ( !mi )
790 return;
791
792 QRect vrect = visualRect( QRect( x+2, y+2, checkcol, h-2 ), r );
793 if ( mi->isChecked() ) {
794 if ( mi->iconSet() ) {
795 qDrawShadePanel( p, vrect.x(), y+2, checkcol, h-2*2,
796 cg, TRUE, 1, &cg.brush( QColorGroup::Midlight ) );
797 }
798 } else if ( !act ) {
799 p->fillRect(vrect,
800 cg.brush( QColorGroup::Button ));
801 }
802
803 if ( mi->iconSet() ) { // draw iconset
804 QIconSet::Mode mode = (!dis) ? QIconSet::Normal : QIconSet::Disabled;
805
806 if (act && !dis)
807 mode = QIconSet::Active;
808
809 QPixmap pixmap;
810 if ( checkable && mi->isChecked() )
811 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode,
812 QIconSet::On );
813 else
814 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
815
816 int pixw = pixmap.width();
817 int pixh = pixmap.height();
818
819 QRect pmr( 0, 0, pixw, pixh );
820
821 pmr.moveCenter(vrect.center());
822
823 p->setPen( cg.text() );
824 p->drawPixmap( pmr.topLeft(), pixmap );
825
826 } else if (checkable) {
827 if (mi->isChecked()) {
828 SFlags cflags = Style_Default;
829 if (! dis)
830 cflags |= Style_Enabled;
831 if (act)
832 cflags |= Style_On;
833
834 drawPrimitive(PE_CheckMark, p, vrect, cg, cflags);
835 }
836 }
837
838 p->setPen( cg.buttonText() );
839
840 QColor discol;
841 if (dis) {
842 discol = cg.text();
843 p->setPen( discol );
844 }
845
846 vrect = visualRect( QRect(x + checkcol + 4, y + 2,
847 w - checkcol - tab - 3, h - 4), r );
848 if (mi->custom()) {
849 p->save();
850 mi->custom()->paint(p, cg, act, !dis, vrect.x(), y + 2,
851 w - checkcol - tab - 3, h - 4);
852 p->restore();
853 }
854
855 QString s = mi->text();
856 if ( !s.isNull() ) { // draw text
857 int t = s.find( '\t' );
858 int m = 2;
859 int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
860 text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
861 if ( t >= 0 ) { // draw tab text
862 QRect vr = visualRect( QRect(x+w-tab-2-2,
863 y+m, tab, h-2*m), r );
864 p->drawText( vr.x(),
865 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
866 }
867 p->drawText(vrect.x(), y + 2, w - checkcol -tab - 3, h - 4,
868 text_flags, s, t);
869 } else if (mi->pixmap()) {
870 QPixmap *pixmap = mi->pixmap();
871
872 if (pixmap->depth() == 1) p->setBackgroundMode(OpaqueMode);
873 QRect vr = visualRect( QRect( x + checkcol + 2, y + 2, w - checkcol - 1, h - 4 ), r );
874 p->drawPixmap(vr.x(), y + 2, *pixmap);
875 if (pixmap->depth() == 1) p->setBackgroundMode(TransparentMode);
876 }
877
878 if (mi->popup()) {
879 int hh = h / 2;
880 QStyle::PrimitiveElement arrow = (QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight);
881 vrect = visualRect( QRect(x + w - hh - 6, y + (hh / 2), hh, hh), r );
882 drawPrimitive(arrow, p,
883 vrect, cg,
884 ((act && !dis) ?
885 Style_Down : Style_Default) |
886 ((!dis) ? Style_Enabled : Style_Default));
887 }
888 break;
889 }
890#endif // QT_NO_POPUPMENU
891
892 case CE_TabBarTab:
893 {
894#ifndef QT_NO_TABBAR
895 const QTabBar *tabbar = (const QTabBar *) widget;
896 bool selected = flags & Style_Selected;
897
898 QColorGroup g = tabbar->colorGroup();
899 QPen oldpen = p->pen();
900 QRect fr(r);
901
902 if (! selected) {
903 if (tabbar->shape() == QTabBar::RoundedAbove ||
904 tabbar->shape() == QTabBar::TriangularAbove) {
905 fr.setTop(fr.top() + 2);
906 } else {
907 fr.setBottom(fr.bottom() - 2);
908 }
909 }
910
911 fr.setWidth(fr.width() - 3);
912
913 p->fillRect(fr.left() + 1, fr.top() + 1, fr.width() - 2, fr.height() - 2,
914 (selected) ? cg.brush(QColorGroup::Button)
915 : cg.brush(QColorGroup::Mid));
916
917 if (tabbar->shape() == QTabBar::RoundedAbove) {
918 // "rounded" tabs on top
919 fr.setBottom(fr.bottom() - 1);
920
921 p->setPen(g.light());
922 p->drawLine(fr.left(), fr.top() + 1,
923 fr.left(), fr.bottom() - 1);
924 p->drawLine(fr.left() + 1, fr.top(),
925 fr.right() - 1, fr.top());
926 if (! selected)
927 p->drawLine(fr.left(), fr.bottom(),
928 fr.right() + 3, fr.bottom());
929
930 if (fr.left() == 0)
931 p->drawLine(fr.left(), fr.bottom(),
932 fr.left(), fr.bottom() + 1);
933
934 p->setPen(g.dark());
935 p->drawLine(fr.right() - 1, fr.top() + 2,
936 fr.right() - 1, fr.bottom() - 1);
937
938 p->setPen(black);
939 p->drawLine(fr.right(), fr.top() + 1,
940 fr.right(), fr.bottom() - 1);
941 } else if (tabbar->shape() == QTabBar::RoundedBelow) {
942 // "rounded" tabs on bottom
943 fr.setTop(fr.top() + 1);
944
945 p->setPen(g.dark());
946 p->drawLine(fr.right() + 3, fr.top() - 1,
947 fr.right() - 1, fr.top() - 1);
948 p->drawLine(fr.right() - 1, fr.top(),
949 fr.right() - 1, fr.bottom() - 2);
950 p->drawLine(fr.right() - 1, fr.bottom() - 2,
951 fr.left() + 2, fr.bottom() - 2);
952 if (! selected) {
953 p->drawLine(fr.right(), fr.top() - 1,
954 fr.left() + 1, fr.top() - 1);
955
956 if (fr.left() != 0)
957 p->drawPoint(fr.left(), fr.top() - 1);
958 }
959
960 p->setPen(black);
961 p->drawLine(fr.right(), fr.top(),
962 fr.right(), fr.bottom() - 2);
963 p->drawLine(fr.right() - 1, fr.bottom() - 1,
964 fr.left(), fr.bottom() - 1);
965 if (! selected)
966 p->drawLine(fr.right() + 3, fr.top(),
967 fr.left(), fr.top());
968 else
969 p->drawLine(fr.right() + 3, fr.top(),
970 fr.right(), fr.top());
971
972 p->setPen(g.light());
973 p->drawLine(fr.left(), fr.top() + 1,
974 fr.left(), fr.bottom() - 2);
975
976 if (selected) {
977 p->drawPoint(fr.left(), fr.top());
978 if (fr.left() == 0)
979 p->drawPoint(fr.left(), fr.top() - 1);
980
981 p->setPen(g.button());
982 p->drawLine(fr.left() + 2, fr.top() - 1,
983 fr.left() + 1, fr.top() - 1);
984 }
985 } else
986 // triangular drawing code
987 QMotifStyle::drawControl(element, p, widget, r, cg, flags, opt);
988
989 p->setPen(oldpen);
990#endif
991 break;
992 }
993
994 default:
995 QMotifStyle::drawControl(element, p, widget, r, cg, flags, opt);
996 break;
997 }
998}
999
1000
1001/*! \reimp
1002*/
1003QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const
1004{
1005 QRect rect;
1006
1007 switch (r) {
1008 case SR_PushButtonFocusRect:
1009 {
1010#ifndef QT_NO_PUSHBUTTON
1011 const QPushButton *button = (const QPushButton *) widget;
1012 int dfi = pixelMetric(PM_ButtonDefaultIndicator, widget);
1013
1014 rect = button->rect();
1015 if (button->isDefault() || button->autoDefault())
1016 rect.addCoords(dfi, dfi, -dfi, -dfi);
1017#endif
1018 break;
1019 }
1020
1021 case SR_CheckBoxIndicator:
1022 {
1023 int h = pixelMetric( PM_IndicatorHeight );
1024 rect.setRect(( widget->rect().height() - h ) / 2,
1025 ( widget->rect().height() - h ) / 2,
1026 pixelMetric( PM_IndicatorWidth ), h );
1027 break;
1028 }
1029
1030 case SR_RadioButtonIndicator:
1031 {
1032 int h = pixelMetric( PM_ExclusiveIndicatorHeight );
1033 rect.setRect( ( widget->rect().height() - h ) / 2,
1034 ( widget->rect().height() - h ) / 2,
1035 pixelMetric( PM_ExclusiveIndicatorWidth ), h );
1036 break;
1037 }
1038
1039 case SR_CheckBoxFocusRect:
1040 case SR_RadioButtonFocusRect:
1041 rect = widget->rect();
1042 break;
1043
1044 case SR_ComboBoxFocusRect:
1045 {
1046#ifndef QT_NO_COMBOBOX
1047 const QComboBox *combobox = (const QComboBox *) widget;
1048
1049 if (combobox->editable()) {
1050 rect = querySubControlMetrics(CC_ComboBox, widget,
1051 SC_ComboBoxEditField);
1052 rect.addCoords(-3, -3, 3, 3);
1053 } else
1054 rect = combobox->rect();
1055#endif
1056 break;
1057 }
1058
1059 case SR_SliderFocusRect:
1060 {
1061#ifndef QT_NO_SLIDER
1062 const QSlider *slider = (const QSlider *) widget;
1063 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget );
1064 int thickness = pixelMetric( PM_SliderControlThickness, widget );
1065 int x, y, wi, he;
1066
1067 if ( slider->orientation() == Horizontal ) {
1068 x = 0;
1069 y = tickOffset;
1070 wi = slider->width();
1071 he = thickness;
1072 } else {
1073 x = tickOffset;
1074 y = 0;
1075 wi = thickness;
1076 he = slider->height();
1077 }
1078
1079 rect.setRect(x, y, wi, he);
1080#endif
1081 break;
1082 }
1083
1084 default:
1085 rect = QMotifStyle::subRect(r, widget);
1086 break;
1087 }
1088
1089 return rect;
1090}
1091
1092
1093/*! \reimp */
1094void QMotifPlusStyle::drawComplexControl(ComplexControl control,
1095 QPainter *p,
1096 const QWidget *widget,
1097 const QRect &r,
1098 const QColorGroup &cg,
1099 SFlags flags,
1100 SCFlags controls,
1101 SCFlags active,
1102 const QStyleOption& opt ) const
1103{
1104 if (widget == singleton->hoverWidget)
1105 flags |= Style_MouseOver;
1106
1107 switch (control) {
1108 case CC_ScrollBar:
1109 {
1110#ifndef QT_NO_SCROLLBAR
1111 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1112 QRect addline, subline, addpage, subpage, slider, first, last;
1113 bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
1114
1115 subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, opt);
1116 addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, opt);
1117 subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, opt);
1118 addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, opt);
1119 slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, opt);
1120 first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, opt);
1121 last = querySubControlMetrics(control, widget, SC_ScrollBarLast, opt);
1122
1123 bool skipUpdate = FALSE;
1124 if (singleton->hovering) {
1125 if (addline.contains(singleton->mousePos)) {
1126 skipUpdate =
1127 (singleton->scrollbarElement == SC_ScrollBarAddLine);
1128 singleton->scrollbarElement = SC_ScrollBarAddLine;
1129 } else if (subline.contains(singleton->mousePos)) {
1130 skipUpdate =
1131 (singleton->scrollbarElement == SC_ScrollBarSubLine);
1132 singleton->scrollbarElement = SC_ScrollBarSubLine;
1133 } else if (slider.contains(singleton->mousePos)) {
1134 skipUpdate =
1135 (singleton->scrollbarElement == SC_ScrollBarSlider);
1136 singleton->scrollbarElement = SC_ScrollBarSlider;
1137 } else {
1138 skipUpdate =
1139 (singleton->scrollbarElement == 0);
1140 singleton->scrollbarElement = 0;
1141 }
1142 } else
1143 singleton->scrollbarElement = 0;
1144
1145 if (skipUpdate && singleton->scrollbarElement == singleton->lastElement)
1146 break;
1147
1148 singleton->lastElement = singleton->scrollbarElement;
1149
1150 if (controls == (SC_ScrollBarAddLine | SC_ScrollBarSubLine |
1151 SC_ScrollBarAddPage | SC_ScrollBarSubPage |
1152 SC_ScrollBarFirst | SC_ScrollBarLast | SC_ScrollBarSlider))
1153 drawMotifPlusShade(p, widget->rect(), cg, TRUE, FALSE,
1154 &cg.brush(QColorGroup::Mid));
1155
1156 if ((controls & SC_ScrollBarSubLine) && subline.isValid())
1157 drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
1158 ((active == SC_ScrollBarSubLine ||
1159 singleton->scrollbarElement == SC_ScrollBarSubLine) ?
1160 Style_MouseOver: Style_Default) |
1161 ((maxedOut) ? Style_Default : Style_Enabled) |
1162 ((active == SC_ScrollBarSubLine) ?
1163 Style_Down : Style_Default) |
1164 ((scrollbar->orientation() == Qt::Horizontal) ?
1165 Style_Horizontal : Style_Default));
1166 if ((controls & SC_ScrollBarAddLine) && addline.isValid())
1167 drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
1168 ((active == SC_ScrollBarAddLine ||
1169 singleton->scrollbarElement == SC_ScrollBarAddLine) ?
1170 Style_MouseOver: Style_Default) |
1171 ((maxedOut) ? Style_Default : Style_Enabled) |
1172 ((active == SC_ScrollBarAddLine) ?
1173 Style_Down : Style_Default) |
1174 ((scrollbar->orientation() == Qt::Horizontal) ?
1175 Style_Horizontal : Style_Default));
1176 if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
1177 drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
1178 ((maxedOut) ? Style_Default : Style_Enabled) |
1179 ((active == SC_ScrollBarSubPage) ?
1180 Style_Down : Style_Default) |
1181 ((scrollbar->orientation() == Qt::Horizontal) ?
1182 Style_Horizontal : Style_Default));
1183 if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
1184 drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
1185 ((maxedOut) ? Style_Default : Style_Enabled) |
1186 ((active == SC_ScrollBarAddPage) ?
1187 Style_Down : Style_Default) |
1188 ((scrollbar->orientation() == Qt::Horizontal) ?
1189 Style_Horizontal : Style_Default));
1190 if ((controls & SC_ScrollBarFirst) && first.isValid())
1191 drawPrimitive(PE_ScrollBarFirst, p, first, cg,
1192 ((maxedOut) ? Style_Default : Style_Enabled) |
1193 ((active == SC_ScrollBarFirst) ?
1194 Style_Down : Style_Default) |
1195 ((scrollbar->orientation() == Qt::Horizontal) ?
1196 Style_Horizontal : Style_Default));
1197 if ((controls & SC_ScrollBarLast) && last.isValid())
1198 drawPrimitive(PE_ScrollBarLast, p, last, cg,
1199 ((maxedOut) ? Style_Default : Style_Enabled) |
1200 ((active == SC_ScrollBarLast) ?
1201 Style_Down : Style_Default) |
1202 ((scrollbar->orientation() == Qt::Horizontal) ?
1203 Style_Horizontal : Style_Default));
1204 if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
1205 drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
1206 ((active == SC_ScrollBarSlider ||
1207 singleton->scrollbarElement == SC_ScrollBarSlider) ?
1208 Style_MouseOver: Style_Default) |
1209 ((maxedOut) ? Style_Default : Style_Enabled) |
1210 ((scrollbar->orientation() == Qt::Horizontal) ?
1211 Style_Horizontal : Style_Default));
1212
1213 // ### perhaps this should not be able to accept focus if maxedOut?
1214 if (scrollbar->hasFocus()) {
1215 QRect fr(slider.x() + 2, slider.y() + 2,
1216 slider.width() - 5, slider.height() - 5);
1217 drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default);
1218 }
1219 }
1220#endif
1221 break;
1222 }
1223
1224 case CC_ComboBox:
1225 {
1226#ifndef QT_NO_COMBOBOX
1227 const QComboBox *combobox = (const QComboBox *) widget;
1228
1229 QRect editfield, arrow;
1230 editfield =
1231 visualRect(querySubControlMetrics(CC_ComboBox,
1232 combobox,
1233 SC_ComboBoxEditField,
1234 opt), widget);
1235 arrow =
1236 visualRect(querySubControlMetrics(CC_ComboBox,
1237 combobox,
1238 SC_ComboBoxArrow,
1239 opt), widget);
1240
1241 if (combobox->editable()) {
1242 if (controls & SC_ComboBoxEditField && editfield.isValid()) {
1243 editfield.addCoords(-3, -3, 3, 3);
1244 if (combobox->hasFocus())
1245 editfield.addCoords(1, 1, -1, -1);
1246 drawMotifPlusShade(p, editfield, cg, TRUE, FALSE,
1247 (widget->isEnabled() ?
1248 &cg.brush(QColorGroup::Base) :
1249 &cg.brush(QColorGroup::Background)));
1250 }
1251
1252 if (controls & SC_ComboBoxArrow && arrow.isValid()) {
1253 drawMotifPlusShade(p, arrow, cg, (active == SC_ComboBoxArrow),
1254 (flags & Style_MouseOver));
1255
1256 int space = (r.height() - 13) / 2;
1257 arrow.addCoords(space, space, -space, -space);
1258
1259 if (active == SC_ComboBoxArrow)
1260 flags |= Style_Sunken;
1261 drawPrimitive(PE_ArrowDown, p, arrow, cg, flags);
1262 }
1263 } else {
1264 if (controls & SC_ComboBoxEditField && editfield.isValid()) {
1265 editfield.addCoords(-3, -3, 3, 3);
1266 if (combobox->hasFocus())
1267 editfield.addCoords(1, 1, -1, -1);
1268 drawMotifPlusShade(p, editfield, cg, FALSE,
1269 (flags & Style_MouseOver));
1270 }
1271
1272 if (controls & SC_ComboBoxArrow && arrow.isValid())
1273 drawMotifPlusShade(p, arrow, cg, FALSE, (flags & Style_MouseOver));
1274 }
1275
1276 if (combobox->hasFocus() ||
1277 (combobox->editable() && combobox->lineEdit()->hasFocus())) {
1278 QRect fr = visualRect(subRect(SR_ComboBoxFocusRect, widget), widget);
1279 drawPrimitive(PE_FocusRect, p, fr, cg, flags);
1280 }
1281#endif
1282 break;
1283 }
1284
1285 case CC_SpinWidget:
1286 {
1287#ifndef QT_NO_SPINWIDGET
1288 const QSpinWidget * sw = (const QSpinWidget *) widget;
1289 SFlags flags = Style_Default;
1290
1291 if (controls & SC_SpinWidgetFrame)
1292 drawMotifPlusShade(p, r, cg, TRUE, FALSE, &cg.brush(QColorGroup::Base));
1293
1294 if (controls & SC_SpinWidgetUp) {
1295 flags = Style_Enabled;
1296 if (active == SC_SpinWidgetUp )
1297 flags |= Style_Down;
1298
1299 PrimitiveElement pe;
1300 if ( sw->buttonSymbols() == QSpinWidget::PlusMinus )
1301 pe = PE_SpinWidgetPlus;
1302 else
1303 pe = PE_SpinWidgetUp;
1304
1305 QRect re = sw->upRect();
1306 QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled();
1307 drawPrimitive(pe, p, re, ucg, flags);
1308 }
1309
1310 if (controls & SC_SpinWidgetDown) {
1311 flags = Style_Enabled;
1312 if (active == SC_SpinWidgetDown )
1313 flags |= Style_Down;
1314
1315 PrimitiveElement pe;
1316 if ( sw->buttonSymbols() == QSpinWidget::PlusMinus )
1317 pe = PE_SpinWidgetMinus;
1318 else
1319 pe = PE_SpinWidgetDown;
1320
1321 QRect re = sw->downRect();
1322 QColorGroup dcg = sw->isDownEnabled() ? cg : sw->palette().disabled();
1323 drawPrimitive(pe, p, re, dcg, flags);
1324 }
1325#endif
1326 break;
1327 }
1328
1329 case CC_Slider:
1330 {
1331#ifndef QT_NO_SLIDER
1332 const QSlider *slider = (const QSlider *) widget;
1333 bool mouseover = (flags & Style_MouseOver);
1334
1335 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
1336 opt),
1337 handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
1338 opt);
1339
1340 if ((controls & SC_SliderGroove) && groove.isValid()) {
1341 drawMotifPlusShade(p, groove, cg, TRUE, FALSE,
1342 &cg.brush(QColorGroup::Mid));
1343
1344 if ( flags & Style_HasFocus ) {
1345 QRect fr = subRect( SR_SliderFocusRect, widget );
1346 drawPrimitive( PE_FocusRect, p, fr, cg, flags );
1347 }
1348 }
1349
1350 if ((controls & SC_SliderHandle) && handle.isValid()) {
1351 if ((mouseover && handle.contains(singleton->mousePos)) ||
1352 singleton->sliderActive)
1353 flags |= Style_MouseOver;
1354 else
1355 flags &= ~Style_MouseOver;
1356 drawPrimitive(PE_ButtonBevel, p, handle, cg, flags | Style_Raised);
1357
1358 if ( slider->orientation() == Horizontal ) {
1359 QCOORD mid = handle.x() + handle.width() / 2;
1360 qDrawShadeLine( p, mid, handle.y() + 1, mid ,
1361 handle.y() + handle.height() - 3,
1362 cg, TRUE, 1);
1363 } else {
1364 QCOORD mid = handle.y() + handle.height() / 2;
1365 qDrawShadeLine( p, handle.x() + 1, mid,
1366 handle.x() + handle.width() - 3, mid,
1367 cg, TRUE, 1);
1368 }
1369 }
1370
1371 if (controls & SC_SliderTickmarks)
1372 QMotifStyle::drawComplexControl(control, p, widget, r, cg, flags,
1373 SC_SliderTickmarks, active, opt);
1374#endif
1375 break;
1376 }
1377
1378 default:
1379 QMotifStyle::drawComplexControl(control, p, widget, r, cg, flags,
1380 controls, active, opt);
1381 }
1382}
1383
1384
1385/*! \reimp
1386*/
1387QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control,
1388 const QWidget *widget,
1389 SubControl subcontrol,
1390 const QStyleOption& opt) const
1391{
1392 switch (control) {
1393 case CC_SpinWidget: {
1394 int fw = pixelMetric( PM_SpinBoxFrameWidth, 0 );
1395 QSize bs;
1396 bs.setHeight( (widget->height() + 1)/2 );
1397 if ( bs.height() < 10 )
1398 bs.setHeight( 10 );
1399 bs.setWidth( bs.height() ); // 1.6 -approximate golden mean
1400 bs = bs.expandedTo( QApplication::globalStrut() );
1401 int y = 0;
1402 int x, lx, rx, h;
1403 x = widget->width() - y - bs.width();
1404 lx = fw;
1405 rx = x - fw * 2;
1406 h = bs.height() * 2;
1407
1408 switch ( subcontrol ) {
1409 case SC_SpinWidgetUp:
1410 return QRect(x + 1, y, bs.width(), bs.height() - 1);
1411 case SC_SpinWidgetDown:
1412 return QRect(x + 1, y + bs.height() + 1, bs.width(), bs.height());
1413 case SC_SpinWidgetButtonField:
1414 return QRect(x, y, bs.width(), h - 2*fw);
1415 case SC_SpinWidgetEditField:
1416 return QRect(lx, fw, rx, h - 2*fw);
1417 case SC_SpinWidgetFrame:
1418 return QRect( 0, 0, widget->width() - bs.width(), h);
1419 default:
1420 break;
1421 }
1422 break; }
1423
1424#ifndef QT_NO_COMBOBOX
1425 case CC_ComboBox: {
1426 const QComboBox *combobox = (const QComboBox *) widget;
1427 if (combobox->editable()) {
1428 int space = (combobox->height() - 13) / 2;
1429 switch (subcontrol) {
1430 case SC_ComboBoxFrame:
1431 return QRect();
1432 case SC_ComboBoxEditField: {
1433 QRect rect = widget->rect();
1434 rect.setWidth(rect.width() - 13 - space * 2);
1435 rect.addCoords(3, 3, -3, -3);
1436 return rect; }
1437 case SC_ComboBoxArrow:
1438 return QRect(combobox->width() - 13 - space * 2, 0,
1439 13 + space * 2, combobox->height());
1440 default: break; // shouldn't get here
1441 }
1442
1443 } else {
1444 int space = (combobox->height() - 7) / 2;
1445 switch (subcontrol) {
1446 case SC_ComboBoxFrame:
1447 return QRect();
1448 case SC_ComboBoxEditField: {
1449 QRect rect = widget->rect();
1450 rect.addCoords(3, 3, -3, -3);
1451 return rect; }
1452 case SC_ComboBoxArrow: // 12 wide, 7 tall
1453 return QRect(combobox->width() - 12 - space, space, 12, 7);
1454 default: break; // shouldn't get here
1455 }
1456 }
1457 break; }
1458#endif
1459
1460#ifndef QT_NO_SLIDER
1461 case CC_Slider: {
1462
1463 if (subcontrol == SC_SliderHandle) {
1464 const QSlider *slider = (const QSlider *) widget;
1465 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget );
1466 int thickness = pixelMetric( PM_SliderControlThickness, widget );
1467 int len = pixelMetric( PM_SliderLength, widget ) + 2;
1468 int sliderPos = slider->sliderStart();
1469 int motifBorder = 2;
1470
1471 if ( slider->orientation() == Horizontal )
1472 return QRect( sliderPos + motifBorder, tickOffset + motifBorder, len,
1473 thickness - 2*motifBorder );
1474 return QRect( tickOffset + motifBorder, sliderPos + motifBorder,
1475 thickness - 2*motifBorder, len);
1476 }
1477 break; }
1478#endif
1479 default: break;
1480 }
1481 return QMotifStyle::querySubControlMetrics(control, widget, subcontrol, opt);
1482}
1483
1484
1485/*! \reimp */
1486bool QMotifPlusStyle::eventFilter(QObject *object, QEvent *event)
1487{
1488 switch(event->type()) {
1489 case QEvent::MouseButtonPress:
1490 {
1491 singleton->mousePressed = TRUE;
1492
1493 if (!::qt_cast<QSlider*>(object))
1494 break;
1495
1496 singleton->sliderActive = TRUE;
1497 break;
1498 }
1499
1500 case QEvent::MouseButtonRelease:
1501 {
1502 singleton->mousePressed = FALSE;
1503
1504 if (!::qt_cast<QSlider*>(object))
1505 break;
1506
1507 singleton->sliderActive = FALSE;
1508 ((QWidget *) object)->repaint(FALSE);
1509 break;
1510 }
1511
1512 case QEvent::Enter:
1513 {
1514 if (! object->isWidgetType())
1515 break;
1516
1517 singleton->hoverWidget = (QWidget *) object;
1518 if (! singleton->hoverWidget->isEnabled()) {
1519 singleton->hoverWidget = 0;
1520 break;
1521 }
1522 singleton->hoverWidget->repaint(FALSE);
1523 break;
1524 }
1525
1526 case QEvent::Leave:
1527 {
1528 if (object != singleton->hoverWidget)
1529 break;
1530 QWidget *w = singleton->hoverWidget;
1531 singleton->hoverWidget = 0;
1532 w->repaint(FALSE);
1533 break;
1534 }
1535
1536 case QEvent::MouseMove:
1537 {
1538 if (! object->isWidgetType() || object != singleton->hoverWidget)
1539 break;
1540
1541 if (!::qt_cast<QScrollBar*>(object) && ! ::qt_cast<QSlider*>(object))
1542 break;
1543
1544 singleton->mousePos = ((QMouseEvent *) event)->pos();
1545 if (! singleton->mousePressed) {
1546 singleton->hovering = TRUE;
1547 singleton->hoverWidget->repaint(FALSE);
1548 singleton->hovering = FALSE;
1549 }
1550
1551 break;
1552 }
1553
1554 default:
1555 break;
1556 }
1557
1558 return QMotifStyle::eventFilter(object, event);
1559}
1560
1561
1562/*! \reimp */
1563int QMotifPlusStyle::styleHint(StyleHint hint,
1564 const QWidget *widget,
1565 const QStyleOption &opt,
1566 QStyleHintReturn *returnData) const
1567{
1568 int ret;
1569 switch (hint) {
1570 case SH_PopupMenu_MouseTracking:
1571 ret = 1;
1572 break;
1573 default:
1574 ret = QMotifStyle::styleHint(hint, widget, opt, returnData);
1575 break;
1576 }
1577 return ret;
1578}
1579
1580
1581#endif // QT_NO_STYLE_MOTIFPLUS
Note: See TracBrowser for help on using the repository browser.