Line | Source | Count |
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 | #include "qglobal.h" | - |
41 | | - |
42 | #ifndef QT_NO_GRAPHICSVIEW | - |
43 | | - |
44 | #include <QtCore/qdebug.h> | - |
45 | #include <QtCore/qnumeric.h> | - |
46 | #include "qgraphicswidget_p.h" | - |
47 | #include "qgraphicslayoutitem_p.h" | - |
48 | #include "qgraphicslayout.h" | - |
49 | #include "qgraphicsscene_p.h" | - |
50 | #include <QtWidgets/qapplication.h> | - |
51 | #include <QtWidgets/qgraphicsscene.h> | - |
52 | #include <QtWidgets/qstyleoption.h> | - |
53 | #include <QtWidgets/QStyleOptionTitleBar> | - |
54 | #include <QtWidgets/QGraphicsSceneMouseEvent> | - |
55 | #if defined(Q_DEAD_CODE_FROM_QT4_MAC) && !defined(QT_NO_STYLE_MAC) | - |
56 | # include <private/qmacstyle_mac_p.h> | - |
57 | #endif | - |
58 | | - |
59 | QT_BEGIN_NAMESPACE | - |
60 | | - |
61 | void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags) | - |
62 | { | - |
63 | Q_Q(QGraphicsWidget); | - |
64 | | - |
65 | attributes = 0; | - |
66 | isWidget = 1; | - |
67 | focusNext = focusPrev = q; | - |
68 | focusPolicy = Qt::NoFocus; | - |
69 | | - |
70 | adjustWindowFlags(&wFlags); | - |
71 | windowFlags = wFlags; | - |
72 | | - |
73 | q->setParentItem(parentItem); | - |
74 | q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType)); | - |
75 | q->setGraphicsItem(q); | - |
76 | | - |
77 | resolveLayoutDirection(); | - |
78 | q->unsetWindowFrameMargins(); | - |
79 | flags |= QGraphicsItem::ItemUsesExtendedStyleOption; | - |
80 | flags |= QGraphicsItem::ItemSendsGeometryChanges; | - |
81 | if (windowFlags & Qt::Window) | - |
82 | flags |= QGraphicsItem::ItemIsPanel; | - |
83 | } | - |
84 | | - |
85 | qreal QGraphicsWidgetPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const | - |
86 | { | - |
87 | Q_Q(const QGraphicsWidget); | - |
88 | int height = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options); | - |
89 | return (qreal)height; | - |
90 | } | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | QGraphicsWidgetPrivate::QGraphicsWidgetPrivate() | - |
96 | : margins(nullptr), | - |
97 | layout(nullptr), | - |
98 | inheritedPaletteResolveMask(0), | - |
99 | inheritedFontResolveMask(0), | - |
100 | inSetGeometry(false), | - |
101 | polished(false), | - |
102 | inSetPos(false), | - |
103 | autoFillBackground(false), | - |
104 | focusPolicy(Qt::NoFocus), | - |
105 | focusNext(nullptr), | - |
106 | focusPrev(nullptr), | - |
107 | windowFlags(), | - |
108 | windowData(nullptr), | - |
109 | setWindowFrameMargins(false), | - |
110 | windowFrameMargins(nullptr) | - |
111 | { | - |
112 | } never executed: end of block | 0 |
113 | | - |
114 | QGraphicsWidgetPrivate::~QGraphicsWidgetPrivate() | - |
115 | { | - |
116 | | - |
117 | delete[] margins; | - |
118 | delete[] windowFrameMargins; | - |
119 | delete windowData; | - |
120 | } | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
125 | | - |
126 | | - |
127 | | - |
128 | void QGraphicsWidgetPrivate::ensureMargins() const | - |
129 | { | - |
130 | if (!margins) { | - |
131 | margins = new qreal[4]; | - |
132 | for (int i = 0; i < 4; ++i) | - |
133 | margins[i] = 0; | - |
134 | } | - |
135 | } | - |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | | - |
142 | | - |
143 | void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const | - |
144 | { | - |
145 | if (!windowFrameMargins) { | - |
146 | windowFrameMargins = new qreal[4]; | - |
147 | for (int i = 0; i < 4; ++i) | - |
148 | windowFrameMargins[i] = 0; | - |
149 | } | - |
150 | } | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | void QGraphicsWidgetPrivate::ensureWindowData() | - |
159 | { | - |
160 | if (!windowData) | - |
161 | windowData = new WindowData; | - |
162 | } | - |
163 | | - |
164 | void QGraphicsWidgetPrivate::setPalette_helper(const QPalette &palette) | - |
165 | { | - |
166 | if (this->palette == palette && this->palette.resolve() == palette.resolve()) | - |
167 | return; | - |
168 | updatePalette(palette); | - |
169 | } | - |
170 | | - |
171 | void QGraphicsWidgetPrivate::resolvePalette(uint inheritedMask) | - |
172 | { | - |
173 | inheritedPaletteResolveMask = inheritedMask; | - |
174 | QPalette naturalPalette = naturalWidgetPalette(); | - |
175 | QPalette resolvedPalette = palette.resolve(naturalPalette); | - |
176 | updatePalette(resolvedPalette); | - |
177 | } | - |
178 | | - |
179 | void QGraphicsWidgetPrivate::updatePalette(const QPalette &palette) | - |
180 | { | - |
181 | Q_Q(QGraphicsWidget); | - |
182 | | - |
183 | this->palette = palette; | - |
184 | | - |
185 | | - |
186 | if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) | - |
187 | inheritedPaletteResolveMask = 0; | - |
188 | int mask = palette.resolve() | inheritedPaletteResolveMask; | - |
189 | | - |
190 | | - |
191 | for (int i = 0; i < children.size(); ++i) { | - |
192 | QGraphicsItem *item = children.at(i); | - |
193 | if (item->isWidget()) { | - |
194 | QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item); | - |
195 | if (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation)) | - |
196 | w->d_func()->resolvePalette(mask); | - |
197 | } else { | - |
198 | item->d_ptr->resolvePalette(mask); | - |
199 | } | - |
200 | } | - |
201 | | - |
202 | | - |
203 | QEvent event(QEvent::PaletteChange); | - |
204 | QApplication::sendEvent(q, &event); | - |
205 | } | - |
206 | | - |
207 | void QGraphicsWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction) | - |
208 | { | - |
209 | Q_Q(QGraphicsWidget); | - |
210 | if ((direction == Qt::RightToLeft) == (testAttribute(Qt::WA_RightToLeft))) | - |
211 | return; | - |
212 | q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft)); | - |
213 | | - |
214 | | - |
215 | for (int i = 0; i < children.size(); ++i) { | - |
216 | QGraphicsItem *item = children.at(i); | - |
217 | if (item->isWidget()) { | - |
218 | QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); | - |
219 | if (widget->parentWidget() && !widget->testAttribute(Qt::WA_SetLayoutDirection)) | - |
220 | widget->d_func()->setLayoutDirection_helper(direction); | - |
221 | } | - |
222 | } | - |
223 | | - |
224 | | - |
225 | QEvent e(QEvent::LayoutDirectionChange); | - |
226 | QApplication::sendEvent(q, &e); | - |
227 | } | - |
228 | | - |
229 | void QGraphicsWidgetPrivate::resolveLayoutDirection() | - |
230 | { | - |
231 | Q_Q(QGraphicsWidget); | - |
232 | if (q->testAttribute(Qt::WA_SetLayoutDirection)) { | - |
233 | return; | - |
234 | } | - |
235 | if (QGraphicsWidget *parentWidget = q->parentWidget()) { | - |
236 | setLayoutDirection_helper(parentWidget->layoutDirection()); | - |
237 | } else if (scene) { | - |
238 | | - |
239 | | - |
240 | setLayoutDirection_helper(QApplication::layoutDirection()); | - |
241 | } else { | - |
242 | setLayoutDirection_helper(QApplication::layoutDirection()); | - |
243 | } | - |
244 | } | - |
245 | | - |
246 | QPalette QGraphicsWidgetPrivate::naturalWidgetPalette() const | - |
247 | { | - |
248 | Q_Q(const QGraphicsWidget); | - |
249 | QPalette palette; | - |
250 | if (QGraphicsWidget *parent = q->parentWidget()) { | - |
251 | palette = parent->palette(); | - |
252 | } else if (scene) { | - |
253 | palette = scene->palette(); | - |
254 | } | - |
255 | palette.resolve(0); | - |
256 | return palette; | - |
257 | } | - |
258 | | - |
259 | void QGraphicsWidgetPrivate::setFont_helper(const QFont &font) | - |
260 | { | - |
261 | if (this->font == font && this->font.resolve() == font.resolve()) | - |
262 | return; | - |
263 | updateFont(font); | - |
264 | } | - |
265 | | - |
266 | void QGraphicsWidgetPrivate::resolveFont(uint inheritedMask) | - |
267 | { | - |
268 | Q_Q(QGraphicsWidget); | - |
269 | inheritedFontResolveMask = inheritedMask; | - |
270 | if (QGraphicsWidget *p = q->parentWidget()) | - |
271 | inheritedFontResolveMask |= p->d_func()->inheritedFontResolveMask; | - |
272 | QFont naturalFont = naturalWidgetFont(); | - |
273 | QFont resolvedFont = font.resolve(naturalFont); | - |
274 | updateFont(resolvedFont); | - |
275 | } | - |
276 | | - |
277 | void QGraphicsWidgetPrivate::updateFont(const QFont &font) | - |
278 | { | - |
279 | Q_Q(QGraphicsWidget); | - |
280 | | - |
281 | this->font = font; | - |
282 | | - |
283 | | - |
284 | if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) | - |
285 | inheritedFontResolveMask = 0; | - |
286 | int mask = font.resolve() | inheritedFontResolveMask; | - |
287 | | - |
288 | | - |
289 | for (int i = 0; i < children.size(); ++i) { | - |
290 | QGraphicsItem *item = children.at(i); | - |
291 | if (item->isWidget()) { | - |
292 | QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item); | - |
293 | if (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation)) | - |
294 | w->d_func()->resolveFont(mask); | - |
295 | } else { | - |
296 | item->d_ptr->resolveFont(mask); | - |
297 | } | - |
298 | } | - |
299 | | - |
300 | if (!polished) | - |
301 | return; | - |
302 | | - |
303 | QEvent event(QEvent::FontChange); | - |
304 | QApplication::sendEvent(q, &event); | - |
305 | } | - |
306 | | - |
307 | QFont QGraphicsWidgetPrivate::naturalWidgetFont() const | - |
308 | { | - |
309 | Q_Q(const QGraphicsWidget); | - |
310 | QFont naturalFont; | - |
311 | if (QGraphicsWidget *parent = q->parentWidget()) { | - |
312 | naturalFont = parent->font(); | - |
313 | } else if (scene) { | - |
314 | naturalFont = scene->font(); | - |
315 | } | - |
316 | naturalFont.resolve(0); | - |
317 | return naturalFont; | - |
318 | } | - |
319 | | - |
320 | void QGraphicsWidgetPrivate::initStyleOptionTitleBar(QStyleOptionTitleBar *option) | - |
321 | { | - |
322 | Q_Q(QGraphicsWidget); | - |
323 | ensureWindowData(); | - |
324 | q->initStyleOption(option); | - |
325 | option->rect.setHeight(titleBarHeight(*option)); | - |
326 | option->titleBarFlags = windowFlags; | - |
327 | option->subControls = QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarSysMenu; | - |
328 | option->activeSubControls = windowData->hoveredSubControl; | - |
329 | bool isActive = q->isActiveWindow(); | - |
330 | if (isActive) {option->state|=.setFlag(QStyle::State_Active;, isActive); | - |
331 | if (isActive) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
332 | option->titleBarState = Qt::WindowActive; | - |
333 | option->titleBarState |= QStyle::State_Active; | - |
334 | } else {option->state &= ~QStyle::State_Active; never executed: end of block | 0 |
335 | option->titleBarState = Qt::WindowNoState; | - |
336 | } never executed: end of block | 0 |
337 | QFont windowTitleFont = QApplication::font("QMdiSubWindowTitleBar"); | - |
338 | QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, 0); | - |
339 | option->text = QFontMetrics(windowTitleFont).elidedText( | - |
340 | windowData->windowTitle, Qt::ElideRight, textRect.width()); | - |
341 | } never executed: end of block | 0 |
342 | | - |
343 | void QGraphicsWidgetPrivate::adjustWindowFlags(Qt::WindowFlags *flags) | - |
344 | { | - |
345 | bool customize = (*flags & (Qt::CustomizeWindowHint | - |
346 | | Qt::FramelessWindowHint | - |
347 | | Qt::WindowTitleHint | - |
348 | | Qt::WindowSystemMenuHint | - |
349 | | Qt::WindowMinimizeButtonHint | - |
350 | | Qt::WindowMaximizeButtonHint | - |
351 | | Qt::WindowContextHelpButtonHint)); | - |
352 | | - |
353 | uint type = (*flags & Qt::WindowType_Mask); | - |
354 | if (customize) | - |
355 | ; | - |
356 | else if (type == Qt::Dialog || type == Qt::Sheet) | - |
357 | *flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint; | - |
358 | else if (type == Qt::Tool) | - |
359 | *flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint; | - |
360 | else if (type == Qt::Window || type == Qt::SubWindow) | - |
361 | *flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | - |
362 | | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint; | - |
363 | } | - |
364 | | - |
365 | void QGraphicsWidgetPrivate::windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event) | - |
366 | { | - |
367 | Q_Q(QGraphicsWidget); | - |
368 | ensureWindowData(); | - |
369 | if (windowData->grabbedSection != Qt::NoSection) { | - |
370 | if (windowData->grabbedSection == Qt::TitleBarArea) { | - |
371 | windowData->buttonSunken = false; | - |
372 | QStyleOptionTitleBar bar; | - |
373 | initStyleOptionTitleBar(&bar); | - |
374 | | - |
375 | bar.rect = q->windowFrameRect().toRect(); | - |
376 | bar.rect.moveTo(0,0); | - |
377 | bar.rect.setHeight(q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &bar)); | - |
378 | QPointF pos = event->pos(); | - |
379 | if (windowFrameMargins) { | - |
380 | pos.rx() += windowFrameMargins[Left]; | - |
381 | pos.ry() += windowFrameMargins[Top]; | - |
382 | } | - |
383 | bar.subControls = QStyle::SC_TitleBarCloseButton; | - |
384 | if (q->style()->subControlRect(QStyle::CC_TitleBar, &bar, | - |
385 | QStyle::SC_TitleBarCloseButton, | - |
386 | event->widget()).contains(pos.toPoint())) { | - |
387 | q->close(); | - |
388 | } | - |
389 | } | - |
390 | if (!(static_cast<QGraphicsSceneMouseEvent *>(event)->buttons())) | - |
391 | windowData->grabbedSection = Qt::NoSection; | - |
392 | event->accept(); | - |
393 | } | - |
394 | } | - |
395 | | - |
396 | void QGraphicsWidgetPrivate::windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event) | - |
397 | { | - |
398 | Q_Q(QGraphicsWidget); | - |
399 | if (event->button() != Qt::LeftButton) | - |
400 | return; | - |
401 | | - |
402 | ensureWindowData(); | - |
403 | windowData->startGeometry = q->geometry(); | - |
404 | windowData->grabbedSection = q->windowFrameSectionAt(event->pos()); | - |
405 | ensureWindowData(); | - |
406 | if (windowData->grabbedSection == Qt::TitleBarArea | - |
407 | && windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton) { | - |
408 | windowData->buttonSunken = true; | - |
409 | q->update(); | - |
410 | } | - |
411 | event->setAccepted(windowData->grabbedSection != Qt::NoSection); | - |
412 | } | - |
413 | | - |
414 | | - |
415 | | - |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | | - |
421 | | - |
422 | | - |
423 | static qreal minimumHeightForWidth(qreal width, qreal minh, qreal maxh, | - |
424 | const QGraphicsWidget *widget, | - |
425 | bool heightForWidth = true) | - |
426 | { | - |
427 | qreal minimumHeightForWidth = -1; | - |
428 | const bool hasHFW = QGraphicsLayoutItemPrivate::get(widget)->hasHeightForWidth(); | - |
429 | if (hasHFW == heightForWidth) { | - |
430 | minimumHeightForWidth = hasHFW | - |
431 | ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(width, -1)).height() | - |
432 | : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, width)).width(); | - |
433 | } else { | - |
434 | | - |
435 | const qreal constraint = width; | - |
436 | while (maxh - minh > 0.1) { | - |
437 | qreal middle = minh + (maxh - minh)/2; | - |
438 | | - |
439 | | - |
440 | | - |
441 | qreal hfw = hasHFW | - |
442 | ? widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(middle, -1)).height() | - |
443 | : widget->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, middle)).width(); | - |
444 | if (hfw > constraint) { | - |
445 | minh = middle; | - |
446 | } else if (hfw <= constraint) { | - |
447 | maxh = middle; | - |
448 | } | - |
449 | } | - |
450 | minimumHeightForWidth = maxh; | - |
451 | } | - |
452 | return minimumHeightForWidth; | - |
453 | } | - |
454 | | - |
455 | static qreal minimumWidthForHeight(qreal height, qreal minw, qreal maxw, | - |
456 | const QGraphicsWidget *widget) | - |
457 | { | - |
458 | return minimumHeightForWidth(height, minw, maxw, widget, false); | - |
459 | } | - |
460 | | - |
461 | static QSizeF closestAcceptableSize(const QSizeF &proposed, | - |
462 | const QGraphicsWidget *widget) | - |
463 | { | - |
464 | const QSizeF current = widget->size(); | - |
465 | | - |
466 | qreal minw = proposed.width(); | - |
467 | qreal maxw = current.width(); | - |
468 | qreal minh = proposed.height(); | - |
469 | qreal maxh = current.height(); | - |
470 | | - |
471 | qreal middlew = maxw; | - |
472 | qreal middleh = maxh; | - |
473 | qreal min_hfw; | - |
474 | min_hfw = minimumHeightForWidth(maxw, minh, maxh, widget); | - |
475 | | - |
476 | do { | - |
477 | if (maxw - minw < 0.1) { | - |
478 | | - |
479 | minw = maxw; | - |
480 | minh = maxh; | - |
481 | } | - |
482 | middlew = minw + (maxw - minw)/2.0; | - |
483 | middleh = minh + (maxh - minh)/2.0; | - |
484 | | - |
485 | min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget); | - |
486 | | - |
487 | if (min_hfw > middleh) { | - |
488 | minw = middlew; | - |
489 | minh = middleh; | - |
490 | } else if (min_hfw <= middleh) { | - |
491 | maxw = middlew; | - |
492 | maxh = middleh; | - |
493 | } | - |
494 | } while (maxw != minw); | - |
495 | | - |
496 | min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget); | - |
497 | | - |
498 | QSizeF result; | - |
499 | if (min_hfw < maxh) { | - |
500 | result = QSizeF(middlew, min_hfw); | - |
501 | } else { | - |
502 | | - |
503 | result = QSizeF(minimumWidthForHeight(maxh, proposed.width(), current.width(), widget), maxh); | - |
504 | } | - |
505 | return result; | - |
506 | } | - |
507 | | - |
508 | static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry, | - |
509 | QRectF *rect, Qt::WindowFrameSection section, | - |
510 | const QSizeF &min, const QSizeF &max, | - |
511 | const QGraphicsWidget *widget) | - |
512 | { | - |
513 | const QRectF proposedRect = *rect; | - |
514 | qreal width = qBound(min.width(), proposedRect.width(), max.width()); | - |
515 | qreal height = qBound(min.height(), proposedRect.height(), max.height()); | - |
516 | | - |
517 | const bool hasHFW = QGraphicsLayoutItemPrivate::get(widget)->hasHeightForWidth(); | - |
518 | const bool hasWFH = QGraphicsLayoutItemPrivate::get(widget)->hasWidthForHeight(); | - |
519 | | - |
520 | const bool widthChanged = proposedRect.width() != widget->size().width(); | - |
521 | const bool heightChanged = proposedRect.height() != widget->size().height(); | - |
522 | | - |
523 | if (hasHFW || hasWFH) { | - |
524 | if (widthChanged || heightChanged) { | - |
525 | qreal minExtent; | - |
526 | qreal maxExtent; | - |
527 | qreal constraint; | - |
528 | qreal proposed; | - |
529 | if (hasHFW) { | - |
530 | minExtent = min.height(); | - |
531 | maxExtent = max.height(); | - |
532 | constraint = width; | - |
533 | proposed = proposedRect.height(); | - |
534 | } else { | - |
535 | | - |
536 | minExtent = min.width(); | - |
537 | maxExtent = max.width(); | - |
538 | constraint = height; | - |
539 | proposed = proposedRect.width(); | - |
540 | } | - |
541 | if (minimumHeightForWidth(constraint, minExtent, maxExtent, widget, hasHFW) > proposed) { | - |
542 | QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget); | - |
543 | width = effectiveSize.width(); | - |
544 | height = effectiveSize.height(); | - |
545 | } | - |
546 | } | - |
547 | } | - |
548 | | - |
549 | switch (section) { | - |
550 | case Qt::LeftSection: | - |
551 | rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), | - |
552 | qRound(width), startGeometry.height()); | - |
553 | break; | - |
554 | case Qt::TopLeftSection: | - |
555 | rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height), | - |
556 | qRound(width), qRound(height)); | - |
557 | break; | - |
558 | case Qt::TopSection: | - |
559 | rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height), | - |
560 | startGeometry.width(), qRound(height)); | - |
561 | break; | - |
562 | case Qt::TopRightSection: | - |
563 | rect->setTop(rect->bottom() - qRound(height)); | - |
564 | rect->setWidth(qRound(width)); | - |
565 | break; | - |
566 | case Qt::RightSection: | - |
567 | rect->setWidth(qRound(width)); | - |
568 | break; | - |
569 | case Qt::BottomRightSection: | - |
570 | rect->setWidth(qRound(width)); | - |
571 | rect->setHeight(qRound(height)); | - |
572 | break; | - |
573 | case Qt::BottomSection: | - |
574 | rect->setHeight(qRound(height)); | - |
575 | break; | - |
576 | case Qt::BottomLeftSection: | - |
577 | rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(), | - |
578 | qRound(width), qRound(height)); | - |
579 | break; | - |
580 | default: | - |
581 | break; | - |
582 | } | - |
583 | } | - |
584 | | - |
585 | void QGraphicsWidgetPrivate::windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event) | - |
586 | { | - |
587 | Q_Q(QGraphicsWidget); | - |
588 | ensureWindowData(); | - |
589 | if (!(event->buttons() & Qt::LeftButton) || windowData->hoveredSubControl != QStyle::SC_TitleBarLabel) | - |
590 | return; | - |
591 | | - |
592 | QLineF delta(q->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)), event->pos()); | - |
593 | QLineF parentDelta(q->mapToParent(delta.p1()), q->mapToParent(delta.p2())); | - |
594 | QLineF parentXDelta(q->mapToParent(QPointF(delta.p1().x(), 0)), q->mapToParent(QPointF(delta.p2().x(), 0))); | - |
595 | QLineF parentYDelta(q->mapToParent(QPointF(0, delta.p1().y())), q->mapToParent(QPointF(0, delta.p2().y()))); | - |
596 | | - |
597 | QRectF newGeometry; | - |
598 | switch (windowData->grabbedSection) { | - |
599 | case Qt::LeftSection: | - |
600 | newGeometry = QRectF(windowData->startGeometry.topLeft() | - |
601 | + QPointF(parentXDelta.dx(), parentXDelta.dy()), | - |
602 | windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy())); | - |
603 | break; | - |
604 | case Qt::TopLeftSection: | - |
605 | newGeometry = QRectF(windowData->startGeometry.topLeft() | - |
606 | + QPointF(parentDelta.dx(), parentDelta.dy()), | - |
607 | windowData->startGeometry.size() - QSizeF(delta.dx(), delta.dy())); | - |
608 | break; | - |
609 | case Qt::TopSection: | - |
610 | newGeometry = QRectF(windowData->startGeometry.topLeft() | - |
611 | + QPointF(parentYDelta.dx(), parentYDelta.dy()), | - |
612 | windowData->startGeometry.size() - QSizeF(0, delta.dy())); | - |
613 | break; | - |
614 | case Qt::TopRightSection: | - |
615 | newGeometry = QRectF(windowData->startGeometry.topLeft() | - |
616 | + QPointF(parentYDelta.dx(), parentYDelta.dy()), | - |
617 | windowData->startGeometry.size() - QSizeF(-delta.dx(), delta.dy())); | - |
618 | break; | - |
619 | case Qt::RightSection: | - |
620 | newGeometry = QRectF(windowData->startGeometry.topLeft(), | - |
621 | windowData->startGeometry.size() + QSizeF(delta.dx(), 0)); | - |
622 | break; | - |
623 | case Qt::BottomRightSection: | - |
624 | newGeometry = QRectF(windowData->startGeometry.topLeft(), | - |
625 | windowData->startGeometry.size() + QSizeF(delta.dx(), delta.dy())); | - |
626 | break; | - |
627 | case Qt::BottomSection: | - |
628 | newGeometry = QRectF(windowData->startGeometry.topLeft(), | - |
629 | windowData->startGeometry.size() + QSizeF(0, delta.dy())); | - |
630 | break; | - |
631 | case Qt::BottomLeftSection: | - |
632 | newGeometry = QRectF(windowData->startGeometry.topLeft() | - |
633 | + QPointF(parentXDelta.dx(), parentXDelta.dy()), | - |
634 | windowData->startGeometry.size() - QSizeF(delta.dx(), -delta.dy())); | - |
635 | break; | - |
636 | case Qt::TitleBarArea: | - |
637 | newGeometry = QRectF(windowData->startGeometry.topLeft() | - |
638 | + QPointF(parentDelta.dx(), parentDelta.dy()), | - |
639 | windowData->startGeometry.size()); | - |
640 | break; | - |
641 | case Qt::NoSection: | - |
642 | break; | - |
643 | } | - |
644 | | - |
645 | if (windowData->grabbedSection != Qt::NoSection) { | - |
646 | _q_boundGeometryToSizeConstraints(windowData->startGeometry, &newGeometry, | - |
647 | windowData->grabbedSection, | - |
648 | q->effectiveSizeHint(Qt::MinimumSize), | - |
649 | q->effectiveSizeHint(Qt::MaximumSize), | - |
650 | q); | - |
651 | q->setGeometry(newGeometry); | - |
652 | } | - |
653 | } | - |
654 | | - |
655 | void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event) | - |
656 | { | - |
657 | Q_Q(QGraphicsWidget); | - |
658 | if (!hasDecoration()) | - |
659 | return; | - |
660 | | - |
661 | ensureWindowData(); | - |
662 | | - |
663 | if (q->rect().contains(event->pos())) { | - |
664 | if (windowData->buttonMouseOver || windowData->hoveredSubControl != QStyle::SC_None) | - |
665 | windowFrameHoverLeaveEvent(event); | - |
666 | return; | - |
667 | } | - |
668 | | - |
669 | bool wasMouseOver = windowData->buttonMouseOver; | - |
670 | QRect oldButtonRect = windowData->buttonRect; | - |
671 | windowData->buttonRect = QRect(); | - |
672 | windowData->buttonMouseOver = false; | - |
673 | QPointF pos = event->pos(); | - |
674 | QStyleOptionTitleBar bar; | - |
675 | | - |
676 | if (windowFrameMargins) { | - |
677 | pos.rx() += windowFrameMargins[Left]; | - |
678 | pos.ry() += windowFrameMargins[Top]; | - |
679 | } | - |
680 | initStyleOptionTitleBar(&bar); | - |
681 | bar.rect = q->windowFrameRect().toRect(); | - |
682 | bar.rect.moveTo(0,0); | - |
683 | bar.rect.setHeight(int(titleBarHeight(bar))); | - |
684 | | - |
685 | Qt::CursorShape cursorShape = Qt::ArrowCursor; | - |
686 | bool needsSetCursorCall = true; | - |
687 | switch (q->windowFrameSectionAt(event->pos())) { | - |
688 | case Qt::TopLeftSection: | - |
689 | case Qt::BottomRightSection: | - |
690 | cursorShape = Qt::SizeFDiagCursor; | - |
691 | break; | - |
692 | case Qt::TopRightSection: | - |
693 | case Qt::BottomLeftSection: | - |
694 | cursorShape = Qt::SizeBDiagCursor; | - |
695 | break; | - |
696 | case Qt::LeftSection: | - |
697 | case Qt::RightSection: | - |
698 | cursorShape = Qt::SizeHorCursor; | - |
699 | break; | - |
700 | case Qt::TopSection: | - |
701 | case Qt::BottomSection: | - |
702 | cursorShape = Qt::SizeVerCursor; | - |
703 | break; | - |
704 | case Qt::TitleBarArea: | - |
705 | windowData->buttonRect = q->style()->subControlRect( | - |
706 | QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0); | - |
707 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - |
708 | | - |
709 | windowData->buttonRect |= q->style()->subControlRect( | - |
710 | QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0); | - |
711 | windowData->buttonRect |= q->style()->subControlRect( | - |
712 | QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0); | - |
713 | #endif | - |
714 | if (windowData->buttonRect.contains(pos.toPoint())) | - |
715 | windowData->buttonMouseOver = true; | - |
716 | event->ignore(); | - |
717 | break; | - |
718 | default: | - |
719 | needsSetCursorCall = false; | - |
720 | event->ignore(); | - |
721 | } | - |
722 | #ifndef QT_NO_CURSOR | - |
723 | if (needsSetCursorCall) | - |
724 | q->setCursor(cursorShape); | - |
725 | #endif | - |
726 | | - |
727 | windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0); | - |
728 | if (windowData->hoveredSubControl != QStyle::SC_TitleBarCloseButton) | - |
729 | windowData->hoveredSubControl = QStyle::SC_TitleBarLabel; | - |
730 | | - |
731 | if (windowData->buttonMouseOver != wasMouseOver) { | - |
732 | if (!oldButtonRect.isNull()) | - |
733 | q->update(QRectF(oldButtonRect).translated(q->windowFrameRect().topLeft())); | - |
734 | if (!windowData->buttonRect.isNull()) | - |
735 | q->update(QRectF(windowData->buttonRect).translated(q->windowFrameRect().topLeft())); | - |
736 | } | - |
737 | } | - |
738 | | - |
739 | void QGraphicsWidgetPrivate::windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event) | - |
740 | { | - |
741 | Q_UNUSED(event); | - |
742 | Q_Q(QGraphicsWidget); | - |
743 | if (hasDecoration()) { | - |
744 | | - |
745 | #ifndef QT_NO_CURSOR | - |
746 | q->unsetCursor(); | - |
747 | #endif | - |
748 | | - |
749 | ensureWindowData(); | - |
750 | | - |
751 | bool needsUpdate = false; | - |
752 | if (windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton | - |
753 | || windowData->buttonMouseOver) | - |
754 | needsUpdate = true; | - |
755 | | - |
756 | | - |
757 | windowData->hoveredSubControl = QStyle::SC_None; | - |
758 | windowData->buttonMouseOver = false; | - |
759 | windowData->buttonRect = QRect(); | - |
760 | if (needsUpdate) | - |
761 | q->update(windowData->buttonRect); | - |
762 | } | - |
763 | } | - |
764 | | - |
765 | bool QGraphicsWidgetPrivate::hasDecoration() const | - |
766 | { | - |
767 | return (windowFlags & Qt::Window) && (windowFlags & Qt::WindowTitleHint); | - |
768 | } | - |
769 | | - |
770 | | - |
771 | | - |
772 | | - |
773 | void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene) | - |
774 | { | - |
775 | Q_Q(QGraphicsWidget); | - |
776 | Q_ASSERT(focusNext && focusPrev); | - |
777 | | - |
778 | if (q_ptr->isPanel()) { | - |
779 | | - |
780 | | - |
781 | | - |
782 | return; | - |
783 | } | - |
784 | | - |
785 | | - |
786 | | - |
787 | | - |
788 | | - |
789 | QGraphicsWidget *focusFirst = q; | - |
790 | QGraphicsWidget *focusBefore = focusPrev; | - |
791 | QGraphicsWidget *focusLast = focusFirst; | - |
792 | QGraphicsWidget *focusAfter = focusNext; | - |
793 | do { | - |
794 | if (!q->isAncestorOf(focusAfter)) | - |
795 | break; | - |
796 | focusLast = focusAfter; | - |
797 | } while ((focusAfter = focusAfter->d_func()->focusNext)); | - |
798 | | - |
799 | if (!parent && oldScene && oldScene != newScene && oldScene->d_func()->tabFocusFirst == q) { | - |
800 | | - |
801 | oldScene->d_func()->tabFocusFirst = (focusAfter != q) ? focusAfter : 0; | - |
802 | } | - |
803 | | - |
804 | | - |
805 | focusBefore->d_func()->focusNext = focusAfter; | - |
806 | focusAfter->d_func()->focusPrev = focusBefore; | - |
807 | | - |
808 | if (newParent) { | - |
809 | | - |
810 | | - |
811 | QGraphicsWidget *newFocusFirst = newParent; | - |
812 | QGraphicsWidget *newFocusLast = newFocusFirst; | - |
813 | QGraphicsWidget *newFocusAfter = newFocusFirst->d_func()->focusNext; | - |
814 | do { | - |
815 | if (!newParent->isAncestorOf(newFocusAfter)) | - |
816 | break; | - |
817 | newFocusLast = newFocusAfter; | - |
818 | } while ((newFocusAfter = newFocusAfter->d_func()->focusNext)); | - |
819 | | - |
820 | newFocusLast->d_func()->focusNext = q; | - |
821 | focusLast->d_func()->focusNext = newFocusAfter; | - |
822 | newFocusAfter->d_func()->focusPrev = focusLast; | - |
823 | focusPrev = newFocusLast; | - |
824 | } else { | - |
825 | | - |
826 | focusPrev = focusLast; | - |
827 | focusLast->d_func()->focusNext = q; | - |
828 | } | - |
829 | } | - |
830 | | - |
831 | void QGraphicsWidgetPrivate::setLayout_helper(QGraphicsLayout *l) | - |
832 | { | - |
833 | delete (this->layout); | - |
834 | layout = l; | - |
835 | if (!l) { | - |
836 | Q_Q(QGraphicsWidget); | - |
837 | q->updateGeometry(); | - |
838 | } | - |
839 | } | - |
840 | | - |
841 | qreal QGraphicsWidgetPrivate::width() const | - |
842 | { | - |
843 | Q_Q(const QGraphicsWidget); | - |
844 | return q->geometry().width(); | - |
845 | } | - |
846 | | - |
847 | void QGraphicsWidgetPrivate::setWidth(qreal w) | - |
848 | { | - |
849 | if (qIsNaN(w)) | - |
850 | return; | - |
851 | Q_Q(QGraphicsWidget); | - |
852 | if (q->geometry().width() == w) | - |
853 | return; | - |
854 | | - |
855 | q->setGeometry(QRectF(q->x(), q->y(), w, height())); | - |
856 | } | - |
857 | | - |
858 | void QGraphicsWidgetPrivate::resetWidth() | - |
859 | { | - |
860 | Q_Q(QGraphicsWidget); | - |
861 | q->setGeometry(QRectF(q->x(), q->y(), 0, height())); | - |
862 | } | - |
863 | | - |
864 | qreal QGraphicsWidgetPrivate::height() const | - |
865 | { | - |
866 | Q_Q(const QGraphicsWidget); | - |
867 | return q->geometry().height(); | - |
868 | } | - |
869 | | - |
870 | void QGraphicsWidgetPrivate::setHeight(qreal h) | - |
871 | { | - |
872 | if (qIsNaN(h)) | - |
873 | return; | - |
874 | Q_Q(QGraphicsWidget); | - |
875 | if (q->geometry().height() == h) | - |
876 | return; | - |
877 | | - |
878 | q->setGeometry(QRectF(q->x(), q->y(), width(), h)); | - |
879 | } | - |
880 | | - |
881 | void QGraphicsWidgetPrivate::resetHeight() | - |
882 | { | - |
883 | Q_Q(QGraphicsWidget); | - |
884 | q->setGeometry(QRectF(q->x(), q->y(), width(), 0)); | - |
885 | } | - |
886 | | - |
887 | void QGraphicsWidgetPrivate::setGeometryFromSetPos() | - |
888 | { | - |
889 | if (inSetGeometry) | - |
890 | return; | - |
891 | Q_Q(QGraphicsWidget); | - |
892 | inSetPos = 1; | - |
893 | | - |
894 | | - |
895 | q->setGeometry(QRectF(pos, q->size())); | - |
896 | inSetPos = 0 ; | - |
897 | } | - |
898 | | - |
899 | QT_END_NAMESPACE | - |
900 | | - |
901 | #endif //QT_NO_GRAPHICSVIEW | - |
| | |