~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/widgets/q3titlebar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qplatformdefs.h"
 
30
 
 
31
#ifndef QT_NO_TITLEBAR
 
32
 
 
33
#include "qapplication.h"
 
34
#include "qcursor.h"
 
35
#include "qdatetime.h"
 
36
#include "qevent.h"
 
37
#include "qimage.h"
 
38
#include "qpainter.h"
 
39
#include "qiodevice.h"
 
40
#include "qpixmap.h"
 
41
#include "qstyle.h"
 
42
#include "qstyleoption.h"
 
43
#include "qtimer.h"
 
44
#include "qtooltip.h"
 
45
#include "qdebug.h"
 
46
#if defined(Q_WS_WIN)
 
47
#include "qt_windows.h"
 
48
#endif
 
49
 
 
50
#include "private/qapplication_p.h"
 
51
#include "private/qinternal_p.h"
 
52
#include "private/q3titlebar_p.h"
 
53
#include "private/qwidget_p.h"
 
54
 
 
55
class Q3TitleBarPrivate : public QWidgetPrivate
 
56
{
 
57
    Q_DECLARE_PUBLIC(Q3TitleBar)
 
58
public:
 
59
    Q3TitleBarPrivate()
 
60
        : toolTip(0), act(0), window(0), movable(1), pressed(0), autoraise(0), inevent(0)
 
61
    {
 
62
    }
 
63
 
 
64
    Qt::WFlags flags;
 
65
    QStyle::SubControl buttonDown;
 
66
    QPoint moveOffset;
 
67
    QToolTip *toolTip;
 
68
    bool act                    :1;
 
69
    QWidget* window;
 
70
    bool movable            :1;
 
71
    bool pressed            :1;
 
72
    bool autoraise          :1;
 
73
    bool inevent : 1;
 
74
 
 
75
    int titleBarState() const;
 
76
    QStyleOptionTitleBar getStyleOption() const;
 
77
    void readColors();
 
78
};
 
79
 
 
80
inline int Q3TitleBarPrivate::titleBarState() const
 
81
{
 
82
    uint state = window ? window->windowState() : static_cast<Qt::WindowStates>(Qt::WindowNoState);
 
83
    state |= uint(act ? QStyle::State_Active : QStyle::State_None);
 
84
    return (int)state;
 
85
}
 
86
 
 
87
QStyleOptionTitleBar Q3TitleBarPrivate::getStyleOption() const
 
88
{
 
89
    Q_Q(const Q3TitleBar);
 
90
    QStyleOptionTitleBar opt;
 
91
    opt.init(q);
 
92
    opt.text = q->windowTitle();
 
93
    //################
 
94
    QIcon icon = q->windowIcon();
 
95
    QSize s = icon.actualSize(QSize(64, 64));
 
96
    opt.icon = icon.pixmap(s);
 
97
    opt.subControls = QStyle::SC_All;
 
98
    opt.activeSubControls = QStyle::SC_None;
 
99
    opt.titleBarState = titleBarState();
 
100
    opt.titleBarFlags = flags;
 
101
    return opt;
 
102
}
 
103
 
 
104
Q3TitleBar::Q3TitleBar(QWidget *w, QWidget *parent, Qt::WFlags f)
 
105
    : QWidget(*new Q3TitleBarPrivate, parent, Qt::WStyle_Customize | Qt::WStyle_NoBorder)
 
106
{
 
107
    Q_D(Q3TitleBar);
 
108
    if (f == 0 && w)
 
109
        f = w->windowFlags();
 
110
    d->flags = f;
 
111
    d->window = w;
 
112
    d->buttonDown = QStyle::SC_None;
 
113
    d->act = 0;
 
114
    if (w) {
 
115
        if (w->minimumSize() == w->maximumSize())
 
116
            d->flags &= ~Qt::WindowMaximizeButtonHint;
 
117
        setWindowTitle(w->windowTitle());
 
118
    }
 
119
 
 
120
    d->readColors();
 
121
    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
 
122
    setMouseTracking(true);
 
123
    setAutoRaise(style()->styleHint(QStyle::SH_TitleBar_AutoRaise, 0, this));
 
124
}
 
125
 
 
126
Q3TitleBar::~Q3TitleBar()
 
127
{
 
128
}
 
129
 
 
130
QStyleOptionTitleBar Q3TitleBar::getStyleOption() const
 
131
{
 
132
    return d_func()->getStyleOption();
 
133
}
 
134
 
 
135
#ifdef Q_WS_WIN
 
136
static inline QRgb colorref2qrgb(COLORREF col)
 
137
{
 
138
    return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));
 
139
}
 
140
#endif
 
141
 
 
142
void Q3TitleBarPrivate::readColors()
 
143
{
 
144
    Q_Q(Q3TitleBar);
 
145
    QPalette pal = q->palette();
 
146
 
 
147
    bool colorsInitialized = false;
 
148
 
 
149
#ifdef Q_WS_WIN // ask system properties on windows
 
150
#ifndef SPI_GETGRADIENTCAPTIONS
 
151
#define SPI_GETGRADIENTCAPTIONS 0x1008
 
152
#endif
 
153
#ifndef COLOR_GRADIENTACTIVECAPTION
 
154
#define COLOR_GRADIENTACTIVECAPTION 27
 
155
#endif
 
156
#ifndef COLOR_GRADIENTINACTIVECAPTION
 
157
#define COLOR_GRADIENTINACTIVECAPTION 28
 
158
#endif
 
159
    if (QApplication::desktopSettingsAware()) {
 
160
        pal.setColor(QPalette::Active, QPalette::Highlight, colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION)));
 
161
        pal.setColor(QPalette::Inactive, QPalette::Highlight, colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION)));
 
162
        pal.setColor(QPalette::Active, QPalette::HighlightedText, colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT)));
 
163
        pal.setColor(QPalette::Inactive, QPalette::HighlightedText, colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT)));
 
164
        if (QSysInfo::WindowsVersion != QSysInfo::WV_95 && QSysInfo::WindowsVersion != QSysInfo::WV_NT) {
 
165
            colorsInitialized = true;
 
166
            BOOL gradient;
 
167
            QT_WA({
 
168
                SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &gradient, 0);
 
169
            } , {
 
170
                SystemParametersInfoA(SPI_GETGRADIENTCAPTIONS, 0, &gradient, 0);
 
171
            });
 
172
            if (gradient) {
 
173
                pal.setColor(QPalette::Active, QPalette::Base, colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION)));
 
174
                pal.setColor(QPalette::Inactive, QPalette::Base, colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION)));
 
175
            } else {
 
176
                pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Active, QPalette::Highlight));
 
177
                pal.setColor(QPalette::Inactive, QPalette::Base, pal.color(QPalette::Inactive, QPalette::Highlight));
 
178
            }
 
179
        }
 
180
    }
 
181
#endif // Q_WS_WIN
 
182
    if (!colorsInitialized) {
 
183
        pal.setColor(QPalette::Active, QPalette::Highlight,
 
184
                      pal.color(QPalette::Active, QPalette::Highlight));
 
185
        pal.setColor(QPalette::Active, QPalette::Base,
 
186
                      pal.color(QPalette::Active, QPalette::Highlight));
 
187
        pal.setColor(QPalette::Inactive, QPalette::Highlight,
 
188
                      pal.color(QPalette::Inactive, QPalette::Dark));
 
189
        pal.setColor(QPalette::Inactive, QPalette::Base,
 
190
                      pal.color(QPalette::Inactive, QPalette::Dark));
 
191
        pal.setColor(QPalette::Inactive, QPalette::HighlightedText,
 
192
                      pal.color(QPalette::Inactive, QPalette::Background));
 
193
    }
 
194
 
 
195
    q->setPalette(pal);
 
196
    q->setActive(act);
 
197
}
 
198
 
 
199
void Q3TitleBar::changeEvent(QEvent *ev)
 
200
{
 
201
    if(ev->type() == QEvent::ModifiedChange)
 
202
        update();
 
203
    QWidget::changeEvent(ev);
 
204
}
 
205
 
 
206
void Q3TitleBar::mousePressEvent(QMouseEvent *e)
 
207
{
 
208
    Q_D(Q3TitleBar);
 
209
    if (!d->act)
 
210
        emit doActivate();
 
211
    if (e->button() == Qt::LeftButton) {
 
212
        d->pressed = true;
 
213
        QStyleOptionTitleBar opt = d->getStyleOption();
 
214
        QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,
 
215
                                                                 e->pos(), this);
 
216
        switch (ctrl) {
 
217
        case QStyle::SC_TitleBarSysMenu:
 
218
            if (d->flags & Qt::WindowSystemMenuHint) {
 
219
                d->buttonDown = QStyle::SC_None;
 
220
                static QTime *t = 0;
 
221
                static Q3TitleBar *tc = 0;
 
222
                if (!t)
 
223
                    t = new QTime;
 
224
                if (tc != this || t->elapsed() > QApplication::doubleClickInterval()) {
 
225
                    emit showOperationMenu();
 
226
                    t->start();
 
227
                    tc = this;
 
228
                } else {
 
229
                    tc = 0;
 
230
                    emit doClose();
 
231
                    return;
 
232
                }
 
233
            }
 
234
            break;
 
235
 
 
236
        case QStyle::SC_TitleBarShadeButton:
 
237
        case QStyle::SC_TitleBarUnshadeButton:
 
238
            if (d->flags & Qt::WindowShadeButtonHint)
 
239
                d->buttonDown = ctrl;
 
240
            break;
 
241
 
 
242
        case QStyle::SC_TitleBarNormalButton:
 
243
            if (d->flags & Qt::WindowMinMaxButtonsHint)
 
244
                d->buttonDown = ctrl;
 
245
            break;
 
246
 
 
247
        case QStyle::SC_TitleBarMinButton:
 
248
            if (d->flags & Qt::WindowMinimizeButtonHint)
 
249
                d->buttonDown = ctrl;
 
250
            break;
 
251
 
 
252
        case QStyle::SC_TitleBarMaxButton:
 
253
            if (d->flags & Qt::WindowMaximizeButtonHint)
 
254
                d->buttonDown = ctrl;
 
255
            break;
 
256
 
 
257
        case QStyle::SC_TitleBarCloseButton:
 
258
            if (d->flags & Qt::WindowSystemMenuHint)
 
259
                d->buttonDown = ctrl;
 
260
            break;
 
261
 
 
262
        case QStyle::SC_TitleBarLabel:
 
263
            d->buttonDown = ctrl;
 
264
            d->moveOffset = mapToParent(e->pos());
 
265
            break;
 
266
 
 
267
        default:
 
268
            break;
 
269
        }
 
270
        repaint();
 
271
    } else {
 
272
        d->pressed = false;
 
273
    }
 
274
}
 
275
 
 
276
void Q3TitleBar::contextMenuEvent(QContextMenuEvent *e)
 
277
{
 
278
    Q_D(Q3TitleBar);
 
279
    QStyleOptionTitleBar opt = d->getStyleOption();
 
280
    QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(),
 
281
                                                             this);
 
282
    if(ctrl == QStyle::SC_TitleBarLabel || ctrl == QStyle::SC_TitleBarSysMenu) {
 
283
        e->accept();
 
284
        emit popupOperationMenu(e->globalPos());
 
285
    } else {
 
286
        e->ignore();
 
287
    }
 
288
}
 
289
 
 
290
void Q3TitleBar::mouseReleaseEvent(QMouseEvent *e)
 
291
{
 
292
    Q_D(Q3TitleBar);
 
293
    if (e->button() == Qt::LeftButton && d->pressed) {
 
294
        e->accept();
 
295
        QStyleOptionTitleBar opt = d->getStyleOption();
 
296
        QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,
 
297
                                                                 e->pos(), this);
 
298
        d->pressed = false;
 
299
        if (ctrl == d->buttonDown) {
 
300
            d->buttonDown = QStyle::SC_None;
 
301
            repaint();
 
302
            switch(ctrl) {
 
303
            case QStyle::SC_TitleBarShadeButton:
 
304
            case QStyle::SC_TitleBarUnshadeButton:
 
305
                if(d->flags & Qt::WindowShadeButtonHint)
 
306
                    emit doShade();
 
307
                break;
 
308
 
 
309
            case QStyle::SC_TitleBarNormalButton:
 
310
                if(d->flags & Qt::WindowMaximizeButtonHint)
 
311
                    emit doNormal();
 
312
                break;
 
313
 
 
314
            case QStyle::SC_TitleBarMinButton:
 
315
                if(d->flags & Qt::WindowMinimizeButtonHint) {
 
316
                    if (d->window && d->window->isMinimized())
 
317
                        emit doNormal();
 
318
                    else
 
319
                        emit doMinimize();
 
320
                }
 
321
                break;
 
322
 
 
323
            case QStyle::SC_TitleBarMaxButton:
 
324
                if(d->flags & Qt::WindowMaximizeButtonHint) {
 
325
                    if(d->window && d->window->isMaximized())
 
326
                        emit doNormal();
 
327
                    else
 
328
                        emit doMaximize();
 
329
                }
 
330
                break;
 
331
 
 
332
            case QStyle::SC_TitleBarCloseButton:
 
333
                if(d->flags & Qt::WindowSystemMenuHint) {
 
334
                    d->buttonDown = QStyle::SC_None;
 
335
                    repaint();
 
336
                    emit doClose();
 
337
                    return;
 
338
                }
 
339
                break;
 
340
 
 
341
            default:
 
342
                break;
 
343
            }
 
344
        }
 
345
    } else {
 
346
        e->ignore();
 
347
    }
 
348
}
 
349
 
 
350
void Q3TitleBar::mouseMoveEvent(QMouseEvent *e)
 
351
{
 
352
    Q_D(Q3TitleBar);
 
353
    e->accept();
 
354
    switch (d->buttonDown) {
 
355
    case QStyle::SC_None:
 
356
        if(autoRaise())
 
357
            repaint();
 
358
        break;
 
359
    case QStyle::SC_TitleBarSysMenu:
 
360
        break;
 
361
    case QStyle::SC_TitleBarShadeButton:
 
362
    case QStyle::SC_TitleBarUnshadeButton:
 
363
    case QStyle::SC_TitleBarNormalButton:
 
364
    case QStyle::SC_TitleBarMinButton:
 
365
    case QStyle::SC_TitleBarMaxButton:
 
366
    case QStyle::SC_TitleBarCloseButton:
 
367
        {
 
368
            QStyle::SubControl last_ctrl = d->buttonDown;
 
369
            QStyleOptionTitleBar opt = d->getStyleOption();
 
370
            d->buttonDown = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(), this);
 
371
            if (d->buttonDown != last_ctrl)
 
372
                d->buttonDown = QStyle::SC_None;
 
373
            repaint();
 
374
            d->buttonDown = last_ctrl;
 
375
        }
 
376
        break;
 
377
 
 
378
    case QStyle::SC_TitleBarLabel:
 
379
        if (d->buttonDown == QStyle::SC_TitleBarLabel && d->movable && d->pressed) {
 
380
            if ((d->moveOffset - mapToParent(e->pos())).manhattanLength() >= 4) {
 
381
                QPoint p = mapFromGlobal(e->globalPos());
 
382
 
 
383
                QWidget *parent = d->window ? d->window->parentWidget() : 0;
 
384
                if(parent && parent->inherits("Q3WorkspaceChild")) {
 
385
                    QWidget *workspace = parent->parentWidget();
 
386
                    p = workspace->mapFromGlobal(e->globalPos());
 
387
                    if (!workspace->rect().contains(p)) {
 
388
                        if (p.x() < 0)
 
389
                            p.rx() = 0;
 
390
                        if (p.y() < 0)
 
391
                            p.ry() = 0;
 
392
                        if (p.x() > workspace->width())
 
393
                            p.rx() = workspace->width();
 
394
                        if (p.y() > workspace->height())
 
395
                            p.ry() = workspace->height();
 
396
                    }
 
397
                }
 
398
 
 
399
                QPoint pp = p - d->moveOffset;
 
400
                if (!parentWidget()->isMaximized())
 
401
                    parentWidget()->move(pp);
 
402
            }
 
403
        } else {
 
404
            QStyle::SubControl last_ctrl = d->buttonDown;
 
405
            d->buttonDown = QStyle::SC_None;
 
406
            if(d->buttonDown != last_ctrl)
 
407
                repaint();
 
408
        }
 
409
        break;
 
410
    default:
 
411
        break;
 
412
    }
 
413
}
 
414
 
 
415
void Q3TitleBar::resizeEvent(QResizeEvent *r)
 
416
{
 
417
    QWidget::resizeEvent(r);
 
418
    cutText();
 
419
}
 
420
 
 
421
bool Q3TitleBar::isTool() const
 
422
{
 
423
    return (d_func()->flags & Qt::WindowType_Mask) == Qt::Tool;
 
424
}
 
425
 
 
426
void Q3TitleBar::paintEvent(QPaintEvent *)
 
427
{
 
428
    Q_D(Q3TitleBar);
 
429
    QStyleOptionTitleBar opt = d->getStyleOption();
 
430
    opt.subControls = QStyle::SC_TitleBarLabel;
 
431
    opt.activeSubControls = d->buttonDown;
 
432
    if (d->flags & Qt::WindowSystemMenuHint) {
 
433
        opt.subControls |= QStyle::SC_TitleBarSysMenu | QStyle::SC_TitleBarCloseButton;
 
434
        if (d->window && (d->flags & Qt::WindowShadeButtonHint)) {
 
435
            if (d->window->isMinimized())
 
436
                opt.subControls |= QStyle::SC_TitleBarUnshadeButton;
 
437
            else
 
438
                opt.subControls |= QStyle::SC_TitleBarShadeButton;
 
439
        }
 
440
        if (d->window && (d->flags & Qt::WindowMinMaxButtonsHint)) {
 
441
            if(d->window && d->window->isMinimized())
 
442
                opt.subControls |= QStyle::SC_TitleBarNormalButton;
 
443
            else
 
444
                opt.subControls |= QStyle::SC_TitleBarMinButton;
 
445
        }
 
446
        if (d->window && (d->flags & Qt::WindowMaximizeButtonHint) && !d->window->isMaximized())
 
447
            opt.subControls |= QStyle::SC_TitleBarMaxButton;
 
448
    }
 
449
 
 
450
    QStyle::SubControl under_mouse = QStyle::SC_None;
 
451
    if(autoRaise() && underMouse()) {
 
452
        under_mouse = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt,
 
453
                                                     mapFromGlobal(QCursor::pos()), this);
 
454
        opt.activeSubControls |= under_mouse;
 
455
        opt.state |= QStyle::State_MouseOver;
 
456
    }
 
457
    opt.palette.setCurrentColorGroup(usesActiveColor() ? QPalette::Active : QPalette::Inactive);
 
458
 
 
459
    QPainter p(this);
 
460
    style()->drawComplexControl(QStyle::CC_TitleBar, &opt, &p, this);
 
461
}
 
462
 
 
463
void Q3TitleBar::mouseDoubleClickEvent(QMouseEvent *e)
 
464
{
 
465
    Q_D(Q3TitleBar);
 
466
    if (e->button() != Qt::LeftButton) {
 
467
        e->ignore();
 
468
        return;
 
469
    }
 
470
    e->accept();
 
471
    QStyleOptionTitleBar opt = d->getStyleOption();
 
472
    switch (style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(), this)) {
 
473
    case QStyle::SC_TitleBarLabel:
 
474
        emit doubleClicked();
 
475
        break;
 
476
 
 
477
    case QStyle::SC_TitleBarSysMenu:
 
478
        if (d->flags & Qt::WStyle_SysMenu)
 
479
            emit doClose();
 
480
        break;
 
481
 
 
482
    default:
 
483
        break;
 
484
    }
 
485
}
 
486
 
 
487
void Q3TitleBar::cutText()
 
488
{
 
489
    Q_D(Q3TitleBar);
 
490
    QFontMetrics fm(font());
 
491
    QStyleOptionTitleBar opt = d->getStyleOption();
 
492
    int maxw = style()->subControlRect(QStyle::CC_TitleBar, &opt, QStyle::SC_TitleBarLabel,
 
493
                                       this).width();
 
494
    if (!d->window)
 
495
        return;
 
496
 
 
497
    QString txt = d->window->windowTitle();
 
498
    if (style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, this) && d->window
 
499
        && d->window->isWindowModified())
 
500
        txt += " *";
 
501
 
 
502
    QString cuttext = txt;
 
503
    if (fm.width(txt + "m") > maxw) {
 
504
        int i = txt.length();
 
505
        int dotlength = fm.width("...");
 
506
        while (i>0 && fm.width(txt.left(i)) + dotlength > maxw)
 
507
            i--;
 
508
        if(i != (int)txt.length())
 
509
            cuttext = txt.left(i) + "...";
 
510
    }
 
511
 
 
512
    setWindowTitle(cuttext);
 
513
}
 
514
 
 
515
 
 
516
void Q3TitleBar::leaveEvent(QEvent *)
 
517
{
 
518
    if(autoRaise() && !d_func()->pressed)
 
519
        repaint();
 
520
}
 
521
 
 
522
void Q3TitleBar::enterEvent(QEvent *)
 
523
{
 
524
    if(autoRaise() && !d_func()->pressed)
 
525
        repaint();
 
526
    QEvent e(QEvent::Leave);
 
527
    QApplication::sendEvent(parentWidget(), &e);
 
528
}
 
529
 
 
530
void Q3TitleBar::setActive(bool active)
 
531
{
 
532
    Q_D(Q3TitleBar);
 
533
    if (d->act == active)
 
534
        return ;
 
535
 
 
536
    d->act = active;
 
537
    update();
 
538
}
 
539
 
 
540
bool Q3TitleBar::isActive() const
 
541
{
 
542
    return d_func()->act;
 
543
}
 
544
 
 
545
bool Q3TitleBar::usesActiveColor() const
 
546
{
 
547
    return (isActive() && isActiveWindow()) ||
 
548
        (!window() && QWidget::window()->isActiveWindow());
 
549
}
 
550
 
 
551
QWidget *Q3TitleBar::window() const
 
552
{
 
553
    return d_func()->window;
 
554
}
 
555
 
 
556
bool Q3TitleBar::event(QEvent *e)
 
557
{
 
558
    Q_D(Q3TitleBar);
 
559
    if (d->inevent)
 
560
        return QWidget::event(e);
 
561
    d->inevent = true;
 
562
    if (e->type() == QEvent::ApplicationPaletteChange) {
 
563
        d->readColors();
 
564
        return true;
 
565
    } else if (e->type() == QEvent::WindowActivate) {
 
566
        setActive(d->act);
 
567
    } else if (e->type() == QEvent::WindowDeactivate) {
 
568
        bool wasActive = d->act;
 
569
        setActive(false);
 
570
        d->act = wasActive;
 
571
    } else if (e->type() == QEvent::WindowIconChange) {
 
572
        update();
 
573
    } else if (e->type() == QEvent::WindowTitleChange) {
 
574
        cutText();
 
575
        update();
 
576
    }
 
577
 
 
578
    d->inevent = false;
 
579
    return QWidget::event(e);
 
580
}
 
581
 
 
582
void Q3TitleBar::setMovable(bool b)
 
583
{
 
584
    d_func()->movable = b;
 
585
}
 
586
 
 
587
bool Q3TitleBar::isMovable() const
 
588
{
 
589
    return d_func()->movable;
 
590
}
 
591
 
 
592
void Q3TitleBar::setAutoRaise(bool b)
 
593
{
 
594
    d_func()->autoraise = b;
 
595
}
 
596
 
 
597
bool Q3TitleBar::autoRaise() const
 
598
{
 
599
    return d_func()->autoraise;
 
600
}
 
601
 
 
602
QSize Q3TitleBar::sizeHint() const
 
603
{
 
604
    ensurePolished();
 
605
    QStyleOptionTitleBar opt = d_func()->getStyleOption();
 
606
    QRect menur = style()->subControlRect(QStyle::CC_TitleBar, &opt,
 
607
                                          QStyle::SC_TitleBarSysMenu, this);
 
608
    return QSize(menur.width(), style()->pixelMetric(QStyle::PM_TitleBarHeight, &opt, this));
 
609
}
 
610
 
 
611
#endif //QT_NO_TITLEBAR