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
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.0, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qglobal.h"
#ifndef QT_NO_GRAPHICSVIEW
#include <QtCore/qdebug.h>
#include "qgraphicswidget_p.h"
#include "qgraphicslayout.h"
#include "qgraphicsscene_p.h"
#include <QtGui/qapplication.h>
#include <QtGui/qgraphicsscene.h>
#include <QtGui/qstyleoption.h>
#include <QtGui/QStyleOptionTitleBar>
#include <QtGui/QGraphicsSceneMouseEvent>
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
# include <QMacStyle>
#endif
QT_BEGIN_NAMESPACE
void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags)
{
Q_Q(QGraphicsWidget);
attributes = 0;
isWidget = 1; // QGraphicsItem::isWidget() returns true.
focusNext = focusPrev = q;
focusPolicy = Qt::NoFocus;
q->setParentItem(parentItem);
q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType));
q->setGraphicsItem(q);
resolveLayoutDirection();
if (!parentItem)
adjustWindowFlags(&wFlags);
windowFlags = wFlags;
q->unsetWindowFrameMargins();
}
qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const
{
Q_Q(const QGraphicsWidget);
int height = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options);
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)
if (qobject_cast<QMacStyle*>(q->style())) {
height -=4;
}
#endif
return (qreal)height;
}
void QGraphicsWidgetPrivate::getLayoutItemMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
{
if (left)
*left = leftLayoutItemMargin;
if (top)
*top = topLayoutItemMargin;
if (right)
*right = rightLayoutItemMargin;
if (bottom)
*bottom = bottomLayoutItemMargin;
}
void QGraphicsWidgetPrivate::setLayoutItemMargins(qreal left, qreal top, qreal right, qreal bottom)
{
if (leftLayoutItemMargin == left
&& topLayoutItemMargin == top
&& rightLayoutItemMargin == right
&& bottomLayoutItemMargin == bottom)
return;
Q_Q(QGraphicsWidget);
leftLayoutItemMargin = left;
topLayoutItemMargin = top;
rightLayoutItemMargin = right;
bottomLayoutItemMargin = bottom;
q->updateGeometry();
}
void QGraphicsWidgetPrivate::setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt)
{
Q_Q(QGraphicsWidget);
QStyleOption myOpt;
if (!opt) {
q->initStyleOption(&myOpt);
myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary
opt = &myOpt;
}
QRect liRect = q->style()->subElementRect(element, opt, /* q */ 0);
if (liRect.isValid()) {
leftLayoutItemMargin = (opt->rect.left() - liRect.left());
topLayoutItemMargin = (opt->rect.top() - liRect.top());
rightLayoutItemMargin = (liRect.right() - opt->rect.right());
bottomLayoutItemMargin = (liRect.bottom() - opt->rect.bottom());
} else {
leftLayoutItemMargin = 0;
topLayoutItemMargin = 0;
rightLayoutItemMargin = 0;
bottomLayoutItemMargin = 0;
}
}
void QGraphicsWidgetPrivate::setPalette_helper(const QPalette &palette)
{
if (this->palette == palette && this->palette.resolve() == palette.resolve())
return;
updatePalette(palette);
}
void QGraphicsWidgetPrivate::resolvePalette(uint inheritedMask)
{
inheritedPaletteResolveMask = inheritedMask;
QPalette naturalPalette = naturalWidgetPalette();
QPalette resolvedPalette = palette.resolve(naturalPalette);
updatePalette(resolvedPalette);
}
void QGraphicsWidgetPrivate::updatePalette(const QPalette &palette)
{
Q_Q(QGraphicsWidget);
// Update local palette setting.
this->palette = palette;
// Calculate new mask.
if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
inheritedPaletteResolveMask = 0;
int mask = palette.resolve() | inheritedPaletteResolveMask;
// Propagate to children.
for (int i = 0; i < children.size(); ++i) {
QGraphicsItem *item = children.at(i);
if (item->isWidget()) {
QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
if (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
w->d_func()->resolvePalette(mask);
} else {
item->d_ptr->resolvePalette(mask);
}
}
// Notify change.
QEvent event(QEvent::PaletteChange);
QApplication::sendEvent(q, &event);
}
void QGraphicsWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction)
{
Q_Q(QGraphicsWidget);
if ((direction == Qt::RightToLeft) == (testAttribute(Qt::WA_RightToLeft)))
return;
q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
// Propagate this change to all children.
for (int i = 0; i < children.size(); ++i) {
QGraphicsItem *item = children.at(i);
if (item->isWidget()) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
if (widget->parentWidget() && !widget->testAttribute(Qt::WA_SetLayoutDirection))
widget->d_func()->setLayoutDirection_helper(direction);
}
}
// Send the notification event to this widget item.
QEvent e(QEvent::LayoutDirectionChange);
QApplication::sendEvent(q, &e);
}
void QGraphicsWidgetPrivate::resolveLayoutDirection()
{
Q_Q(QGraphicsWidget);
if (q->testAttribute(Qt::WA_SetLayoutDirection)) {
return;
}
if (QGraphicsWidget *parentWidget = q->parentWidget()) {
setLayoutDirection_helper(parentWidget->layoutDirection());
} else if (scene) {
// ### shouldn't the scene have a layoutdirection really? how does
// ### QGraphicsWidget get changes from QApplication::layoutDirection?
setLayoutDirection_helper(QApplication::layoutDirection());
} else {
setLayoutDirection_helper(QApplication::layoutDirection());
}
}
QPalette QGraphicsWidgetPrivate::naturalWidgetPalette() const
{
Q_Q(const QGraphicsWidget);
QPalette palette;
if (QGraphicsWidget *parent = q->parentWidget()) {
palette = parent->palette();
} else if (scene) {
palette = scene->palette();
}
palette.resolve(0);
return palette;
}
void QGraphicsWidgetPrivate::setFont_helper(const QFont &font)
{
if (this->font == font && this->font.resolve() == font.resolve())
return;
updateFont(font);
}
void QGraphicsWidgetPrivate::resolveFont(uint inheritedMask)
{
inheritedFontResolveMask = inheritedMask;
QFont naturalFont = naturalWidgetFont();
QFont resolvedFont = font.resolve(naturalFont);
updateFont(resolvedFont);
}
void QGraphicsWidgetPrivate::updateFont(const QFont &font)
{
Q_Q(QGraphicsWidget);
// Update the local font setting.
this->font = font;
// Calculate new mask.
if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
inheritedFontResolveMask = 0;
int mask = font.resolve() | inheritedFontResolveMask;
// Propagate to children.
for (int i = 0; i < children.size(); ++i) {
QGraphicsItem *item = children.at(i);
if (item->isWidget()) {
QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
if (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
w->d_func()->resolveFont(mask);
} else {
item->d_ptr->resolveFont(mask);
}
}
if (!polished)
return;
// Notify change.
QEvent event(QEvent::FontChange);
QApplication::sendEvent(q, &event);
}
QFont QGraphicsWidgetPrivate::naturalWidgetFont() const
{
Q_Q(const QGraphicsWidget);
QFont naturalFont; // ### no application font support
if (QGraphicsWidget *parent = q->parentWidget()) {
naturalFont = parent->font();
} else if (scene) {
naturalFont = scene->font();
}
naturalFont.resolve(0);
return naturalFont;
}
void QGraphicsWidgetPrivate::initStyleOptionTitleBar(QStyleOptionTitleBar *option)
{
Q_Q(QGraphicsWidget);
q->initStyleOption(option);
option->rect.setHeight(titleBarHeight(*option));
option->titleBarFlags = windowFlags;
option->subControls = QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarSysMenu;
option->activeSubControls = hoveredSubControl;
bool isActive = q->isActiveWindow();
if (isActive) {
option->state |= QStyle::State_Active;
option->titleBarState = Qt::WindowActive;
option->titleBarState |= QStyle::State_Active;
} else {
option->state &= ~QStyle::State_Active;
option->titleBarState = Qt::WindowNoState;
}
QFont windowTitleFont = QApplication::font("QWorkspaceTitleBar");
QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, 0);
option->text = QFontMetrics(windowTitleFont).elidedText(windowTitle, Qt::ElideRight, textRect.width());
}
void QGraphicsWidgetPrivate::adjustWindowFlags(Qt::WindowFlags *flags)
{
bool customize = (*flags & (Qt::CustomizeWindowHint
| Qt::FramelessWindowHint
| Qt::WindowTitleHint
| Qt::WindowSystemMenuHint
| Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowContextHelpButtonHint));
uint type = (*flags & Qt::WindowType_Mask);
if (customize)
;
else if (type == Qt::Dialog || type == Qt::Sheet)
*flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint;
else if (type == Qt::Tool)
*flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint;
else if (type == Qt::Window || type == Qt::SubWindow)
*flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint
| Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint;
}
void QGraphicsWidgetPrivate::windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_Q(QGraphicsWidget);
if (grabbedSection != Qt::NoSection) {
if (grabbedSection == Qt::TitleBarArea) {
buttonSunken = false;
QStyleOptionTitleBar bar;
initStyleOptionTitleBar(&bar);
// make sure that the coordinates (rect and pos) we send to the style are positive.
bar.rect = q->windowFrameRect().toRect();
bar.rect.moveTo(0,0);
bar.rect.setHeight(q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &bar));
QPointF pos = event->pos();
pos.rx() += leftWindowFrameMargin;
pos.ry() += topWindowFrameMargin;
bar.subControls = QStyle::SC_TitleBarCloseButton;
if (q->style()->subControlRect(QStyle::CC_TitleBar, &bar,
QStyle::SC_TitleBarCloseButton,
event->widget()).contains(pos.toPoint())) {
q->close();
}
}
if (!(static_cast<QGraphicsSceneMouseEvent *>(event)->buttons()))
grabbedSection = Qt::NoSection;
event->accept();
}
}
void QGraphicsWidgetPrivate::windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_Q(QGraphicsWidget);
if (event->button() != Qt::LeftButton)
return;
startGeometry = q->geometry();
grabbedSection = q->windowFrameSectionAt(event->pos());
switch (grabbedSection) {
case Qt::LeftSection:
case Qt::TopLeftSection:
mouseDelta = event->pos() - q->rect().topLeft();
break;
case Qt::TopSection:
case Qt::TopRightSection:
mouseDelta = event->pos() - q->rect().topRight();
break;
case Qt::RightSection:
case Qt::BottomRightSection:
mouseDelta = event->pos() - q->rect().bottomRight();
break;
case Qt::BottomSection:
case Qt::BottomLeftSection:
mouseDelta = event->pos() - q->rect().bottomLeft();
break;
case Qt::TitleBarArea:
if (hoveredSubControl == QStyle::SC_TitleBarCloseButton) {
buttonSunken = true;
q->update();
}
break;
case Qt::NoSection:
break;
}
event->setAccepted(grabbedSection != Qt::NoSection);
}
static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry,
QRectF *rect, Qt::WindowFrameSection section,
const QSizeF &min, const QSizeF &max)
{
int height;
int width;
switch (section) {
case Qt::LeftSection:
width = qRound(qBound(min.width(), rect->width(), max.width()));
rect->setRect(startGeometry.right() - width, startGeometry.top(),
width, startGeometry.height());
break;
case Qt::TopLeftSection:
width = qRound(qBound(min.width(), rect->width(), max.width()));
height = qRound(qBound(min.height(), rect->height(), max.height()));
rect->setRect(startGeometry.right() - width, startGeometry.bottom() - height,
width, height);
break;
case Qt::TopSection:
height = qRound(qBound(min.height(), rect->height(), max.height()));
rect->setRect(startGeometry.left(), startGeometry.bottom() - height,
startGeometry.width(), height);
break;
case Qt::TopRightSection:
height = qRound(qBound(min.height(), rect->height(), max.height()));
rect->setTop(rect->bottom() - height);
rect->setWidth(qBound(min.width(), rect->width(), max.width()));
break;
case Qt::RightSection:
rect->setWidth(qBound(min.width(), rect->width(), max.width()));
break;
case Qt::BottomRightSection:
rect->setWidth(qBound(min.width(), rect->width(), max.width()));
rect->setHeight(qBound(min.height(), rect->height(), max.height()));
break;
case Qt::BottomSection:
rect->setHeight(qBound(min.height(), rect->height(), max.height()));
break;
case Qt::BottomLeftSection:
height = qRound(qBound(min.height(), rect->height(), max.height()));
width = qRound(qBound(min.width(), rect->width(), max.width()));
rect->setRect(startGeometry.right() - width, startGeometry.top(),
width, height);
break;
default:
break;
}
}
void QGraphicsWidgetPrivate::windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_Q(QGraphicsWidget);
if (!(event->buttons() & Qt::LeftButton) || hoveredSubControl != QStyle::SC_TitleBarLabel)
return;
QLineF delta(q->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)), event->pos());
QLineF parentDelta(q->mapToParent(delta.p1()), q->mapToParent(delta.p2()));
QLineF parentXDelta(q->mapToParent(QPointF(delta.p1().x(), 0)), q->mapToParent(QPointF(delta.p2().x(), 0)));
QLineF parentYDelta(q->mapToParent(QPointF(0, delta.p1().y())), q->mapToParent(QPointF(0, delta.p2().y())));
QRectF newGeometry;
switch (grabbedSection) {
case Qt::LeftSection:
newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()),
startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
break;
case Qt::TopLeftSection:
newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()),
startGeometry.size() - QSizeF(delta.dx(), delta.dy()));
break;
case Qt::TopSection:
newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()),
startGeometry.size() - QSizeF(0, delta.dy()));
break;
case Qt::TopRightSection:
newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentYDelta.dx(), parentYDelta.dy()),
startGeometry.size() - QSizeF(-delta.dx(), delta.dy()));
break;
case Qt::RightSection:
newGeometry = QRectF(startGeometry.topLeft(),
startGeometry.size() + QSizeF(delta.dx(), 0));
break;
case Qt::BottomRightSection:
newGeometry = QRectF(startGeometry.topLeft(),
startGeometry.size() + QSizeF(delta.dx(), delta.dy()));
break;
case Qt::BottomSection:
newGeometry = QRectF(startGeometry.topLeft(),
startGeometry.size() + QSizeF(0, delta.dy()));
break;
case Qt::BottomLeftSection:
newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentXDelta.dx(), parentXDelta.dy()),
startGeometry.size() - QSizeF(delta.dx(), -delta.dy()));
break;
case Qt::TitleBarArea:
newGeometry = QRectF(startGeometry.topLeft() + QPointF(parentDelta.dx(), parentDelta.dy()),
startGeometry.size());
break;
case Qt::NoSection:
break;
}
if (grabbedSection != Qt::NoSection) {
_q_boundGeometryToSizeConstraints(startGeometry, &newGeometry, grabbedSection,
q->effectiveSizeHint(Qt::MinimumSize),
q->effectiveSizeHint(Qt::MaximumSize));
q->setGeometry(newGeometry);
}
}
void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_Q(QGraphicsWidget);
if (!hasDecoration())
return;
if (q->rect().contains(event->pos())) {
if (buttonMouseOver || hoveredSubControl != QStyle::SC_None)
windowFrameHoverLeaveEvent(event);
return;
}
bool wasMouseOver = buttonMouseOver;
QRect oldButtonRect = buttonRect;
buttonRect = QRect();
buttonMouseOver = false;
QPointF pos = event->pos();
QStyleOptionTitleBar bar;
// make sure that the coordinates (rect and pos) we send to the style are positive.
pos.rx() += leftWindowFrameMargin;
pos.ry() += topWindowFrameMargin;
initStyleOptionTitleBar(&bar);
bar.rect = q->windowFrameRect().toRect();
bar.rect.moveTo(0,0);
bar.rect.setHeight(int(titleBarHeight(bar)));
Qt::CursorShape cursorShape = Qt::ArrowCursor;
bool needsSetCursorCall = true;
switch (q->windowFrameSectionAt(event->pos())) {
case Qt::TopLeftSection:
case Qt::BottomRightSection:
cursorShape = Qt::SizeFDiagCursor;
break;
case Qt::TopRightSection:
case Qt::BottomLeftSection:
cursorShape = Qt::SizeBDiagCursor;
break;
case Qt::LeftSection:
case Qt::RightSection:
cursorShape = Qt::SizeHorCursor;
break;
case Qt::TopSection:
case Qt::BottomSection:
cursorShape = Qt::SizeVerCursor;
break;
case Qt::TitleBarArea:
buttonRect = q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0);
#ifdef Q_WS_MAC
// On mac we should hover if we are in the 'area' of the buttons
buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0);
buttonRect |= q->style()->subControlRect(QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0);
#endif
if (buttonRect.contains(pos.toPoint()))
buttonMouseOver = true;
event->ignore();
break;
default:
needsSetCursorCall = false;
event->ignore();
}
#ifndef QT_NO_CURSOR
if (needsSetCursorCall)
q->setCursor(cursorShape);
#endif
// update buttons if we hover over them
hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);
if (hoveredSubControl != QStyle::SC_TitleBarCloseButton)
hoveredSubControl = QStyle::SC_TitleBarLabel;
if (buttonMouseOver != wasMouseOver) {
if (!oldButtonRect.isNull())
q->update(QRectF(oldButtonRect).translated(q->windowFrameRect().topLeft()));
if (!buttonRect.isNull())
q->update(QRectF(buttonRect).translated(q->windowFrameRect().topLeft()));
}
}
void QGraphicsWidgetPrivate::windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
Q_Q(QGraphicsWidget);
if (hasDecoration()) {
// ### restore the cursor, don't override it
#ifndef QT_NO_CURSOR
q->unsetCursor();
#endif
bool needsUpdate = false;
if (hoveredSubControl == QStyle::SC_TitleBarCloseButton || buttonMouseOver)
needsUpdate = true;
// update the hover state (of buttons etc...)
hoveredSubControl = QStyle::SC_None;
buttonMouseOver = false;
buttonRect = QRect();
if (needsUpdate)
q->update(buttonRect);
}
}
bool QGraphicsWidgetPrivate::hasDecoration() const
{
return (windowFlags & Qt::Window) && (windowFlags & Qt::WindowTitleHint);
}
/*!
\internal
*/
void QGraphicsWidgetPrivate::setFocusWidget()
{
// Update focus child chain.
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
QGraphicsWidget *parent = widget;
bool hidden = !visible;
do {
parent->d_func()->focusChild = widget;
} while (!parent->isWindow() && (parent = parent->parentWidget()) && (!hidden || !parent->d_func()->visible));
}
/*!
\internal
*/
void QGraphicsWidgetPrivate::clearFocusWidget()
{
// Reset focus child chain.
QGraphicsWidget *parent = static_cast<QGraphicsWidget *>(q_ptr);
do {
if (parent->d_func()->focusChild != q_ptr)
break;
parent->d_func()->focusChild = 0;
} while (!parent->isWindow() && (parent = parent->parentWidget()));
}
/**
* is called after a reparent has taken place to fix up the focus chain(s)
*/
void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *newScene)
{
Q_Q(QGraphicsWidget);
Q_ASSERT(focusNext && focusPrev);
QGraphicsWidget *n = q; //last one in 'new' list
QGraphicsWidget *o = 0; //last one in 'old' list
QGraphicsWidget *w = focusNext;
QGraphicsWidget *firstOld = 0;
bool wasPreviousNew = true;
if (focusChild) {
// Ensure that the current focus child doesn't leave pointers around
// before reparenting.
focusChild->clearFocus();
}
while (w != q) {
bool isCurrentNew = q->isAncestorOf(w);
if (isCurrentNew) {
if (!wasPreviousNew) {
n->d_func()->focusNext = w;
w->d_func()->focusPrev = n;
}
n = w;
} else /*if (!isCurrentNew)*/ {
if (wasPreviousNew) {
if (o) {
o->d_func()->focusNext = w;
w->d_func()->focusPrev = o;
} else {
firstOld = w;
}
}
o = w;
}
w = w->d_func()->focusNext;
wasPreviousNew = isCurrentNew;
}
// repair the 'old' chain
if (firstOld) {
o->d_func()->focusNext = firstOld;
firstOld->d_func()->focusPrev = o;
}
// update tabFocusFirst for oldScene if the item is going to be removed from oldScene
if (newParent)
newScene = newParent->scene();
QGraphicsScene *oldScene = q->scene();
if (oldScene && newScene != oldScene)
oldScene->d_func()->tabFocusFirst = firstOld;
QGraphicsItem *topLevelItem = newParent ? newParent->topLevelItem() : 0;
QGraphicsWidget *topLevel = 0;
if (topLevelItem && topLevelItem->isWidget())
topLevel = static_cast<QGraphicsWidget *>(topLevelItem);
if (topLevel && newParent) {
QGraphicsWidget *last = topLevel->d_func()->focusPrev;
// link last with new chain
last->d_func()->focusNext = q;
focusPrev = last;
// link last in chain with
topLevel->d_func()->focusPrev = n;
n->d_func()->focusNext = topLevel;
} else {
// q is the start of the focus chain
n->d_func()->focusNext = q;
focusPrev = n;
}
}
void QGraphicsWidgetPrivate::setLayout_helper(QGraphicsLayout *l)
{
delete (this->layout);
layout = l;
if (!l) {
Q_Q(QGraphicsWidget);
q->updateGeometry();
}
}
QT_END_NAMESPACE
#endif //QT_NO_GRAPHICSVIEW
|