1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qstatusbar.h"
#ifndef QT_NO_STATUSBAR
#include "qlist.h"
#include "qdebug.h"
#include "qevent.h"
#include "qlayout.h"
#include "qpainter.h"
#include "qtimer.h"
#include "qstyle.h"
#include "qstyleoption.h"
#include "qsizegrip.h"
#include "qmainwindow.h"
#include <private/qlayoutengine_p.h>
#include <private/qwidget_p.h>
QT_BEGIN_NAMESPACE
class QStatusBarPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QStatusBar)
public:
QStatusBarPrivate() {}
struct SBItem {
SBItem(QWidget* widget, int stretch, bool permanent)
: s(stretch), w(widget), p(permanent) {}
int s;
QWidget * w;
bool p;
};
QList<SBItem *> items;
QString tempItem;
QBoxLayout * box;
QTimer * timer;
#ifndef QT_NO_SIZEGRIP
QSizeGrip * resizer;
bool showSizeGrip;
#endif
int savedStrut;
#ifdef Q_WS_MAC
QPoint dragStart;
#endif
int indexToLastNonPermanentWidget() const
{
int i = items.size() - 1;
for (; i >= 0; --i) {
SBItem *item = items.at(i);
if (!(item && item->p))
break;
}
return i;
}
#ifndef QT_NO_SIZEGRIP
void tryToShowSizeGrip()
{
if (!showSizeGrip)
return;
showSizeGrip = false;
if (!resizer || resizer->isVisible())
return;
resizer->setAttribute(Qt::WA_WState_ExplicitShowHide, false);
QMetaObject::invokeMethod(resizer, "_q_showIfNotHidden", Qt::DirectConnection);
resizer->setAttribute(Qt::WA_WState_ExplicitShowHide, false);
}
#endif
QRect messageRect() const;
};
QRect QStatusBarPrivate::messageRect() const
{
Q_Q(const QStatusBar);
bool rtl = q->layoutDirection() == Qt::RightToLeft;
int left = 6;
int right = q->width() - 12;
#ifndef QT_NO_SIZEGRIP
if (resizer && resizer->isVisible()) {
if (rtl)
left = resizer->x() + resizer->width();
else
right = resizer->x();
}
#endif
for (int i=0; i<items.size(); ++i) {
QStatusBarPrivate::SBItem* item = items.at(i);
if (!item)
break;
if (item->p && item->w->isVisible()) {
if (item->p) {
if (rtl)
left = qMax(left, item->w->x() + item->w->width() + 2);
else
right = qMin(right, item->w->x() - 2);
}
break;
}
}
return QRect(left, 0, right-left, q->height());
}
/*!
\class QStatusBar
\brief The QStatusBar class provides a horizontal bar suitable for
presenting status information.
\ingroup mainwindow-classes
\ingroup helpsystem
Each status indicator falls into one of three categories:
\list
\o \e Temporary - briefly occupies most of the status bar. Used
to explain tool tip texts or menu entries, for example.
\o \e Normal - occupies part of the status bar and may be hidden
by temporary messages. Used to display the page and line
number in a word processor, for example.
\o \e Permanent - is never hidden. Used for important mode
indications, for example, some applications put a Caps Lock
indicator in the status bar.
\endlist
QStatusBar lets you display all three types of indicators.
Typically, a request for the status bar functionality occurs in
relation to a QMainWindow object. QMainWindow provides a main
application window, with a menu bar, tool bars, dock widgets \e
and a status bar around a large central widget. The status bar can
be retrieved using the QMainWindow::statusBar() function, and
replaced using the QMainWindow::setStatusBar() function.
Use the showMessage() slot to display a \e temporary message:
\snippet examples/mainwindows/dockwidgets/mainwindow.cpp 8
To remove a temporary message, use the clearMessage() slot, or set
a time limit when calling showMessage(). For example:
\snippet examples/mainwindows/dockwidgets/mainwindow.cpp 3
Use the currentMessage() function to retrieve the temporary
message currently shown. The QStatusBar class also provide the
messageChanged() signal which is emitted whenever the temporary
status message changes.
\target permanent message
\e Normal and \e Permanent messages are displayed by creating a
small widget (QLabel, QProgressBar or even QToolButton) and then
adding it to the status bar using the addWidget() or the
addPermanentWidget() function. Use the removeWidget() function to
remove such messages from the status bar.
\snippet doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp 0
By default QStatusBar provides a QSizeGrip in the lower-right
corner. You can disable it using the setSizeGripEnabled()
function. Use the isSizeGripEnabled() function to determine the
current status of the size grip.
\image plastique-statusbar.png A status bar shown in the Plastique widget style
\sa QMainWindow, QStatusTipEvent, {fowler}{GUI Design Handbook:
Status Bar}, {Application Example}
*/
#ifdef QT3_SUPPORT
/*!
Constructs a status bar with a size grip and the given \a parent
and object \a name.
Use the QStatusBar() constructor and the QObject::setObjectName()
function instead.
\oldcode
QStatusBar *myStatusBar = new QStatusBar(parent, name);
\newcode
QStatusBar *myStatusBar = new QStatusBar(parent);
myStatusBar->setObjectName(name);
\endcode
*/
QStatusBar::QStatusBar(QWidget * parent, const char *name)
: QWidget(*new QStatusBarPrivate, parent, 0)
{
Q_D(QStatusBar);
setObjectName(QString::fromAscii(name));
d->box = 0;
d->timer = 0;
#ifndef QT_NO_SIZEGRIP
d->resizer = 0;
d->showSizeGrip = false;
setSizeGripEnabled(true); // causes reformat()
#else
reformat();
#endif
}
/*!
\fn void QStatusBar::addWidget(QWidget * widget, int stretch, bool permanent)
Use addWidget() or addPermanentWidget() instead, depending on the
value of the \a permanent parameter.
\oldcode
QStatusBar *myStatusBar;
myStatusBar->addWidget(widget, stretch, permanent); // permanent == true
\newcode
QStatusBar *myStatusBar;
myStatusBar->addPermanentWidget(widget, stretch);
\endcode
*/
#endif
/*!
Constructs a status bar with a size grip and the given \a parent.
\sa setSizeGripEnabled()
*/
QStatusBar::QStatusBar(QWidget * parent)
: QWidget(*new QStatusBarPrivate, parent, 0)
{
Q_D(QStatusBar);
d->box = 0;
d->timer = 0;
#ifndef QT_NO_SIZEGRIP
d->resizer = 0;
setSizeGripEnabled(true); // causes reformat()
#else
reformat();
#endif
}
/*!
Destroys this status bar and frees any allocated resources and
child widgets.
*/
QStatusBar::~QStatusBar()
{
Q_D(QStatusBar);
while (!d->items.isEmpty())
delete d->items.takeFirst();
}
/*!
Adds the given \a widget to this status bar, reparenting the
widget if it isn't already a child of this QStatusBar object. The
\a stretch parameter is used to compute a suitable size for the
given \a widget as the status bar grows and shrinks. The default
stretch factor is 0, i.e giving the widget a minimum of space.
The widget is located to the far left of the first permanent
widget (see addPermanentWidget()) and may be obscured by temporary
messages.
\sa insertWidget(), removeWidget(), addPermanentWidget()
*/
void QStatusBar::addWidget(QWidget * widget, int stretch)
{
if (!widget)
return;
insertWidget(d_func()->indexToLastNonPermanentWidget() + 1, widget, stretch);
}
/*!
\since 4.2
Inserts the given \a widget at the given \a index to this status bar,
reparenting the widget if it isn't already a child of this
QStatusBar object. If \a index is out of range, the widget is appended
(in which case it is the actual index of the widget that is returned).
The \a stretch parameter is used to compute a suitable size for
the given \a widget as the status bar grows and shrinks. The
default stretch factor is 0, i.e giving the widget a minimum of
space.
The widget is located to the far left of the first permanent
widget (see addPermanentWidget()) and may be obscured by temporary
messages.
\sa addWidget(), removeWidget(), addPermanentWidget()
*/
int QStatusBar::insertWidget(int index, QWidget *widget, int stretch)
{
if (!widget)
return -1;
Q_D(QStatusBar);
QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, false);
int idx = d->indexToLastNonPermanentWidget();
if (index < 0 || index > d->items.size() || (idx >= 0 && index > idx + 1)) {
qWarning("QStatusBar::insertWidget: Index out of range (%d), appending widget", index);
index = idx + 1;
}
d->items.insert(index, item);
if (!d->tempItem.isEmpty())
widget->hide();
reformat();
if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
widget->show();
return index;
}
/*!
Adds the given \a widget permanently to this status bar,
reparenting the widget if it isn't already a child of this
QStatusBar object. The \a stretch parameter is used to compute a
suitable size for the given \a widget as the status bar grows and
shrinks. The default stretch factor is 0, i.e giving the widget a
minimum of space.
Permanently means that the widget may not be obscured by temporary
messages. It is is located at the far right of the status bar.
\sa insertPermanentWidget(), removeWidget(), addWidget()
*/
void QStatusBar::addPermanentWidget(QWidget * widget, int stretch)
{
if (!widget)
return;
insertPermanentWidget(d_func()->items.size(), widget, stretch);
}
/*!
\since 4.2
Inserts the given \a widget at the given \a index permanently to this status bar,
reparenting the widget if it isn't already a child of this
QStatusBar object. If \a index is out of range, the widget is appended
(in which case it is the actual index of the widget that is returned).
The \a stretch parameter is used to compute a
suitable size for the given \a widget as the status bar grows and
shrinks. The default stretch factor is 0, i.e giving the widget a
minimum of space.
Permanently means that the widget may not be obscured by temporary
messages. It is is located at the far right of the status bar.
\sa addPermanentWidget(), removeWidget(), addWidget()
*/
int QStatusBar::insertPermanentWidget(int index, QWidget *widget, int stretch)
{
if (!widget)
return -1;
Q_D(QStatusBar);
QStatusBarPrivate::SBItem* item = new QStatusBarPrivate::SBItem(widget, stretch, true);
int idx = d->indexToLastNonPermanentWidget();
if (index < 0 || index > d->items.size() || (idx >= 0 && index <= idx)) {
qWarning("QStatusBar::insertPermanentWidget: Index out of range (%d), appending widget", index);
index = d->items.size();
}
d->items.insert(index, item);
reformat();
if (!widget->isHidden() || !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
widget->show();
return index;
}
/*!
Removes the specified \a widget from the status bar.
\note This function does not delete the widget but \e hides it.
To add the widget again, you must call both the addWidget() and
show() functions.
\sa addWidget(), addPermanentWidget(), clearMessage()
*/
void QStatusBar::removeWidget(QWidget *widget)
{
if (!widget)
return;
Q_D(QStatusBar);
bool found = false;
QStatusBarPrivate::SBItem* item;
for (int i=0; i<d->items.size(); ++i) {
item = d->items.at(i);
if (!item)
break;
if (item->w == widget) {
d->items.removeAt(i);
item->w->hide();
delete item;
found = true;
break;
}
}
if (found)
reformat();
#if defined(QT_DEBUG)
else
qDebug("QStatusBar::removeWidget(): Widget not found.");
#endif
}
/*!
\property QStatusBar::sizeGripEnabled
\brief whether the QSizeGrip in the bottom-right corner of the
status bar is enabled
The size grip is enabled by default.
*/
bool QStatusBar::isSizeGripEnabled() const
{
#ifdef QT_NO_SIZEGRIP
return false;
#else
Q_D(const QStatusBar);
return !!d->resizer;
#endif
}
void QStatusBar::setSizeGripEnabled(bool enabled)
{
#ifdef QT_NO_SIZEGRIP
Q_UNUSED(enabled);
#else
Q_D(QStatusBar);
if (!enabled != !d->resizer) {
if (enabled) {
d->resizer = new QSizeGrip(this);
d->resizer->hide();
d->resizer->installEventFilter(this);
d->showSizeGrip = true;
} else {
delete d->resizer;
d->resizer = 0;
d->showSizeGrip = false;
}
reformat();
if (d->resizer && isVisible())
d->tryToShowSizeGrip();
}
#endif
}
/*!
Changes the status bar's appearance to account for item changes.
Special subclasses may need this function, but geometry management
will usually take care of any necessary rearrangements.
*/
void QStatusBar::reformat()
{
Q_D(QStatusBar);
if (d->box)
delete d->box;
QBoxLayout *vbox;
#ifndef QT_NO_SIZEGRIP
if (d->resizer) {
d->box = new QHBoxLayout(this);
d->box->setMargin(0);
vbox = new QVBoxLayout;
d->box->addLayout(vbox);
} else
#endif
{
vbox = d->box = new QVBoxLayout(this);
d->box->setMargin(0);
}
vbox->addSpacing(3);
QBoxLayout* l = new QHBoxLayout;
vbox->addLayout(l);
l->addSpacing(2);
l->setSpacing(6);
int maxH = fontMetrics().height();
int i;
QStatusBarPrivate::SBItem* item;
for (i=0,item=0; i<d->items.size(); ++i) {
item = d->items.at(i);
if (!item || item->p)
break;
l->addWidget(item->w, item->s);
int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight());
maxH = qMax(maxH, itemH);
}
l->addStretch(0);
for (item=0; i<d->items.size(); ++i) {
item = d->items.at(i);
if (!item)
break;
l->addWidget(item->w, item->s);
int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight());
maxH = qMax(maxH, itemH);
}
#ifndef QT_NO_SIZEGRIP
if (d->resizer) {
maxH = qMax(maxH, d->resizer->sizeHint().height());
d->box->addSpacing(1);
d->box->addWidget(d->resizer, 0, Qt::AlignBottom);
}
#endif
l->addStrut(maxH);
d->savedStrut = maxH;
vbox->addSpacing(2);
d->box->activate();
update();
}
/*!
Hides the normal status indications and displays the given \a
message for the specified number of milli-seconds (\a{timeout}). If
\a{timeout} is 0 (default), the \a {message} remains displayed until
the clearMessage() slot is called or until the showMessage() slot is
called again to change the message.
Note that showMessage() is called to show temporary explanations of
tool tip texts, so passing a \a{timeout} of 0 is not sufficient to
display a \l{permanent message}{permanent message}.
\sa messageChanged(), currentMessage(), clearMessage()
*/
void QStatusBar::showMessage(const QString &message, int timeout)
{
Q_D(QStatusBar);
d->tempItem = message;
if (timeout > 0) {
if (!d->timer) {
d->timer = new QTimer(this);
connect(d->timer, SIGNAL(timeout()), this, SLOT(clearMessage()));
}
d->timer->start(timeout);
} else if (d->timer) {
delete d->timer;
d->timer = 0;
}
hideOrShow();
}
/*!
Removes any temporary message being shown.
\sa currentMessage(), showMessage(), removeWidget()
*/
void QStatusBar::clearMessage()
{
Q_D(QStatusBar);
if (d->tempItem.isEmpty())
return;
if (d->timer) {
qDeleteInEventHandler(d->timer);
d->timer = 0;
}
d->tempItem.clear();
hideOrShow();
}
/*!
Returns the temporary message currently shown,
or an empty string if there is no such message.
\sa showMessage()
*/
QString QStatusBar::currentMessage() const
{
Q_D(const QStatusBar);
return d->tempItem;
}
/*!
\fn void QStatusBar::message(const QString &message, int timeout)
Use the showMessage() function instead.
*/
/*!
\fn void QStatusBar::clear()
Use the clearMessage() function instead.
*/
/*!
\fn QStatusBar::messageChanged(const QString &message)
This signal is emitted whenever the temporary status message
changes. The new temporary message is passed in the \a message
parameter which is a null-string when the message has been
removed.
\sa showMessage(), clearMessage()
*/
/*!
Ensures that the right widgets are visible.
Used by the showMessage() and clearMessage() functions.
*/
void QStatusBar::hideOrShow()
{
Q_D(QStatusBar);
bool haveMessage = !d->tempItem.isEmpty();
QStatusBarPrivate::SBItem* item = 0;
for (int i=0; i<d->items.size(); ++i) {
item = d->items.at(i);
if (!item || item->p)
break;
if (haveMessage && item->w->isVisible()) {
item->w->hide();
item->w->setAttribute(Qt::WA_WState_ExplicitShowHide, false);
} else if (!haveMessage && !item->w->testAttribute(Qt::WA_WState_ExplicitShowHide)) {
item->w->show();
}
}
emit messageChanged(d->tempItem);
repaint(d->messageRect());
}
/*!
\reimp
*/
void QStatusBar::showEvent(QShowEvent *)
{
#ifndef QT_NO_SIZEGRIP
Q_D(QStatusBar);
if (d->resizer && d->showSizeGrip)
d->tryToShowSizeGrip();
#endif
}
/*!
\reimp
\fn void QStatusBar::paintEvent(QPaintEvent *event)
Shows the temporary message, if appropriate, in response to the
paint \a event.
*/
void QStatusBar::paintEvent(QPaintEvent *event)
{
Q_D(QStatusBar);
bool haveMessage = !d->tempItem.isEmpty();
QPainter p(this);
QStyleOption opt;
opt.initFrom(this);
style()->drawPrimitive(QStyle::PE_PanelStatusBar, &opt, &p, this);
for (int i=0; i<d->items.size(); ++i) {
QStatusBarPrivate::SBItem* item = d->items.at(i);
if (item && item->w->isVisible() && (!haveMessage || item->p)) {
QRect ir = item->w->geometry().adjusted(-2, -1, 2, 1);
if (event->rect().intersects(ir)) {
QStyleOption opt(0);
opt.rect = ir;
opt.palette = palette();
opt.state = QStyle::State_None;
style()->drawPrimitive(QStyle::PE_FrameStatusBarItem, &opt, &p, item->w);
}
}
}
if (haveMessage) {
p.setPen(palette().foreground().color());
p.drawText(d->messageRect(), Qt::AlignLeading | Qt::AlignVCenter | Qt::TextSingleLine, d->tempItem);
}
}
/*!
\reimp
*/
void QStatusBar::resizeEvent(QResizeEvent * e)
{
QWidget::resizeEvent(e);
}
/*!
\reimp
*/
bool QStatusBar::event(QEvent *e)
{
Q_D(QStatusBar);
if (e->type() == QEvent::LayoutRequest
#ifdef QT3_SUPPORT
|| e->type() == QEvent::LayoutHint
#endif
) {
// Calculate new strut height and call reformat() if it has changed
int maxH = fontMetrics().height();
QStatusBarPrivate::SBItem* item = 0;
for (int i=0; i<d->items.size(); ++i) {
item = d->items.at(i);
if (!item)
break;
int itemH = qMin(qSmartMinSize(item->w).height(), item->w->maximumHeight());
maxH = qMax(maxH, itemH);
}
#ifndef QT_NO_SIZEGRIP
if (d->resizer)
maxH = qMax(maxH, d->resizer->sizeHint().height());
#endif
if (maxH != d->savedStrut)
reformat();
else
update();
}
if (e->type() == QEvent::ChildRemoved) {
QStatusBarPrivate::SBItem* item = 0;
for (int i=0; i<d->items.size(); ++i) {
item = d->items.at(i);
if (!item)
break;
if (item->w == ((QChildEvent*)e)->child()) {
d->items.removeAt(i);
delete item;
}
}
}
// On Mac OS X Leopard it is possible to drag the window by clicking
// on the tool bar on most applications.
#ifndef Q_WS_MAC
return QWidget::event(e);
#else
if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_4)
return QWidget::event(e);
// Enable drag-click only if the status bar is the status bar for a
// QMainWindow with a unifed toolbar.
if (parent() == 0 || qobject_cast<QMainWindow *>(parent()) == 0 ||
qobject_cast<QMainWindow *>(parent())->unifiedTitleAndToolBarOnMac() == false )
return QWidget::event(e);
// Check for mouse events.
QMouseEvent *mouseEvent;
if (e->type() == QEvent::MouseButtonPress ||
e->type() == QEvent::MouseMove ||
e->type() == QEvent::MouseButtonRelease) {
mouseEvent = static_cast <QMouseEvent*>(e);
} else {
return QWidget::event(e);
}
// The following is a standard mouse drag handler.
if (e->type() == QEvent::MouseButtonPress && (mouseEvent->button() == Qt::LeftButton)) {
d->dragStart = mouseEvent->pos();
} else if (e->type() == QEvent::MouseMove){
if (d->dragStart == QPoint())
return QWidget::event(e);
QPoint pos = mouseEvent->pos();
QPoint delta = (pos - d->dragStart);
window()->move(window()->pos() + delta);
} else if (e->type() == QEvent::MouseButtonRelease && (mouseEvent->button() == Qt::LeftButton)){
d->dragStart = QPoint();
} else {
return QWidget::event(e);
}
return true;
#endif
}
QT_END_NAMESPACE
#endif
|