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