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 | | - |
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 | #include "qmdisubwindow_p.h" | - |
149 | | - |
150 | #ifndef QT_NO_MDIAREA | - |
151 | | - |
152 | #include <QApplication> | - |
153 | #include <QStylePainter> | - |
154 | #include <QVBoxLayout> | - |
155 | #include <QMouseEvent> | - |
156 | #include <QWhatsThis> | - |
157 | #include <QToolTip> | - |
158 | #include <QMainWindow> | - |
159 | #include <QScrollBar> | - |
160 | #include <QDebug> | - |
161 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
162 | #include <private/qmacstyle_mac_p.h> | - |
163 | #endif | - |
164 | #include <QMdiArea> | - |
165 | #include <QScopedValueRollback> | - |
166 | | - |
167 | QT_BEGIN_NAMESPACE | - |
168 | | - |
169 | using namespace QMdi; | - |
170 | | - |
171 | static const QStyle::SubControl SubControls[] = | - |
172 | { | - |
173 | QStyle::SC_TitleBarLabel, | - |
174 | QStyle::SC_TitleBarSysMenu, | - |
175 | QStyle::SC_TitleBarMinButton, | - |
176 | QStyle::SC_TitleBarMaxButton, | - |
177 | QStyle::SC_TitleBarShadeButton, | - |
178 | QStyle::SC_TitleBarCloseButton, | - |
179 | QStyle::SC_TitleBarNormalButton, | - |
180 | QStyle::SC_TitleBarUnshadeButton, | - |
181 | QStyle::SC_TitleBarContextHelpButton | - |
182 | }; | - |
183 | static const int NumSubControls = sizeof(SubControls) / sizeof(SubControls[0]); | - |
184 | | - |
185 | static const Qt::WindowFlags CustomizeWindowFlags = | - |
186 | Qt::FramelessWindowHint | - |
187 | | Qt::CustomizeWindowHint | - |
188 | | Qt::WindowTitleHint | - |
189 | | Qt::WindowSystemMenuHint | - |
190 | | Qt::WindowMinimizeButtonHint | - |
191 | | Qt::WindowMaximizeButtonHint | - |
192 | | Qt::WindowMinMaxButtonsHint; | - |
193 | | - |
194 | | - |
195 | static const int BoundaryMargin = 5; | - |
196 | | - |
197 | static inline int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag, | - |
198 | int delta, int maxDelta, int minDelta) | - |
199 | { | - |
200 | if (cflags & moveFlag) { | - |
201 | if (delta > 0) | - |
202 | return (cflags & resizeFlag) ? qMin(delta, maxDelta) : delta; | - |
203 | return (cflags & resizeFlag) ? qMax(delta, minDelta) : delta; | - |
204 | } | - |
205 | return 0; | - |
206 | } | - |
207 | | - |
208 | static inline int getResizeDeltaComponent(uint cflags, uint resizeFlag, | - |
209 | uint resizeReverseFlag, int delta) | - |
210 | { | - |
211 | if (cflags & resizeFlag) { | - |
212 | if (cflags & resizeReverseFlag) | - |
213 | return -delta; | - |
214 | return delta; | - |
215 | } | - |
216 | return 0; | - |
217 | } | - |
218 | | - |
219 | static inline bool isChildOfQMdiSubWindow(const QWidget *child) | - |
220 | { | - |
221 | Q_ASSERT(child); | - |
222 | QWidget *parent = child->parentWidget(); | - |
223 | while (parent) { | - |
224 | if (qobject_cast<QMdiSubWindow *>(parent)) | - |
225 | return true; | - |
226 | parent = parent->parentWidget(); | - |
227 | } | - |
228 | return false; | - |
229 | } | - |
230 | | - |
231 | static inline bool isChildOfTabbedQMdiArea(const QMdiSubWindow *child) | - |
232 | { | - |
233 | Q_ASSERT(child); | - |
234 | if (QMdiArea *mdiArea = child->mdiArea()) { | - |
235 | if (mdiArea->viewMode() == QMdiArea::TabbedView) | - |
236 | return true; | - |
237 | } | - |
238 | return false; | - |
239 | } | - |
240 | | - |
241 | template<typename T> | - |
242 | static inline ControlElement<T> *ptr(QWidget *widget) | - |
243 | { | - |
244 | if (widget && widget->qt_metacast("ControlElement") | - |
245 | && strcmp(widget->metaObject()->className(), T::staticMetaObject.className()) == 0) { | - |
246 | return static_cast<ControlElement<T> *>(widget); | - |
247 | } | - |
248 | return 0; | - |
249 | } | - |
250 | | - |
251 | QString QMdiSubWindowPrivate::originalWindowTitle() | - |
252 | { | - |
253 | Q_Q(QMdiSubWindow); | - |
254 | if (originalTitle.isNull()) { | - |
255 | originalTitle = q->window()->windowTitle(); | - |
256 | if (originalTitle.isNull()) | - |
257 | originalTitle = QLatin1String(""); | - |
258 | } | - |
259 | return originalTitle; | - |
260 | } | - |
261 | | - |
262 | void QMdiSubWindowPrivate::setNewWindowTitle() | - |
263 | { | - |
264 | Q_Q(QMdiSubWindow); | - |
265 | QString childTitle = q->windowTitle(); | - |
266 | if (childTitle.isEmpty()) | - |
267 | return; | - |
268 | QString original = originalWindowTitle(); | - |
269 | if (!original.isEmpty()) { | - |
270 | if (!original.contains(QMdiSubWindow::tr("- [%1]").arg(childTitle))) | - |
271 | q->window()->setWindowTitle(QMdiSubWindow::tr("%1 - [%2]").arg(original, childTitle)); | - |
272 | | - |
273 | } else { | - |
274 | q->window()->setWindowTitle(childTitle); | - |
275 | } | - |
276 | } | - |
277 | | - |
278 | static inline bool isHoverControl(QStyle::SubControl control) | - |
279 | { | - |
280 | return control != QStyle::SC_None && control != QStyle::SC_TitleBarLabel; | - |
281 | } | - |
282 | | - |
283 | #if defined(Q_DEAD_CODE_FROM_QT4_WIN) | - |
284 | static inline QRgb colorref2qrgb(COLORREF col) | - |
285 | { | - |
286 | return qRgb(GetRValue(col),GetGValue(col),GetBValue(col)); | - |
287 | } | - |
288 | #endif | - |
289 | | - |
290 | #ifndef QT_NO_TOOLTIP | - |
291 | static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOptionComplex &opt, | - |
292 | QStyle::ComplexControl complexControl, QStyle::SubControl subControl) | - |
293 | { | - |
294 | Q_ASSERT(helpEvent); | - |
295 | Q_ASSERT(helpEvent->type() == QEvent::ToolTip); | - |
296 | Q_ASSERT(widget); | - |
297 | | - |
298 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
299 | | - |
300 | if (qobject_cast<QMacStyle *>(widget->style())) | - |
301 | return; | - |
302 | #endif | - |
303 | | - |
304 | | - |
305 | | - |
306 | if (complexControl == QStyle::CC_MdiControls) { | - |
307 | if (subControl == QStyle::SC_MdiMinButton) | - |
308 | subControl = QStyle::SC_TitleBarMinButton; | - |
309 | else if (subControl == QStyle::SC_MdiCloseButton) | - |
310 | subControl = QStyle::SC_TitleBarCloseButton; | - |
311 | else if (subControl == QStyle::SC_MdiNormalButton) | - |
312 | subControl = QStyle::SC_TitleBarNormalButton; | - |
313 | else | - |
314 | subControl = QStyle::SC_None; | - |
315 | } | - |
316 | | - |
317 | | - |
318 | if (subControl == QStyle::SC_None) | - |
319 | return; | - |
320 | | - |
321 | QString toolTip; | - |
322 | | - |
323 | switch (subControl) { | - |
324 | case QStyle::SC_TitleBarMinButton: | - |
325 | toolTip = QMdiSubWindow::tr("Minimize"); | - |
326 | break; | - |
327 | case QStyle::SC_TitleBarMaxButton: | - |
328 | toolTip = QMdiSubWindow::tr("Maximize"); | - |
329 | break; | - |
330 | case QStyle::SC_TitleBarUnshadeButton: | - |
331 | toolTip = QMdiSubWindow::tr("Unshade"); | - |
332 | break; | - |
333 | case QStyle::SC_TitleBarShadeButton: | - |
334 | toolTip = QMdiSubWindow::tr("Shade"); | - |
335 | break; | - |
336 | case QStyle::SC_TitleBarNormalButton: | - |
337 | if (widget->isMaximized() || !qobject_cast<QMdiSubWindow *>(widget)) | - |
338 | toolTip = QMdiSubWindow::tr("Restore Down"); | - |
339 | else | - |
340 | toolTip = QMdiSubWindow::tr("Restore"); | - |
341 | break; | - |
342 | case QStyle::SC_TitleBarCloseButton: | - |
343 | toolTip = QMdiSubWindow::tr("Close"); | - |
344 | break; | - |
345 | case QStyle::SC_TitleBarContextHelpButton: | - |
346 | toolTip = QMdiSubWindow::tr("Help"); | - |
347 | break; | - |
348 | case QStyle::SC_TitleBarSysMenu: | - |
349 | toolTip = QMdiSubWindow::tr("Menu"); | - |
350 | break; | - |
351 | default: | - |
352 | break; | - |
353 | } | - |
354 | | - |
355 | const QRect rect = widget->style()->subControlRect(complexControl, &opt, subControl, widget); | - |
356 | QToolTip::showText(helpEvent->globalPos(), toolTip, widget, rect); | - |
357 | } | - |
358 | #endif // QT_NO_TOOLTIP | - |
359 | | - |
360 | namespace QMdi { | - |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | class ControlLabel : public QWidget | - |
366 | { | - |
367 | Q_OBJECT | - |
368 | public: | - |
369 | ControlLabel(QMdiSubWindow *subWindow, QWidget *parent = 0); | - |
370 | | - |
371 | QSize sizeHint() const Q_DECL_OVERRIDE; | - |
372 | | - |
373 | signals: | - |
374 | void _q_clicked(); | - |
375 | void _q_doubleClicked(); | - |
376 | | - |
377 | protected: | - |
378 | bool event(QEvent *event) Q_DECL_OVERRIDE; | - |
379 | void paintEvent(QPaintEvent *paintEvent) Q_DECL_OVERRIDE; | - |
380 | void mousePressEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; | - |
381 | void mouseDoubleClickEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; | - |
382 | void mouseReleaseEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; | - |
383 | | - |
384 | private: | - |
385 | QPixmap label; | - |
386 | bool isPressed; | - |
387 | void updateWindowIcon(); | - |
388 | }; | - |
389 | } | - |
390 | | - |
391 | ControlLabel::ControlLabel(QMdiSubWindow *subWindow, QWidget *parent) | - |
392 | : QWidget(parent), isPressed(false) | - |
393 | { | - |
394 | Q_UNUSED(subWindow); | - |
395 | setFocusPolicy(Qt::NoFocus); | - |
396 | updateWindowIcon(); | - |
397 | setFixedSize(label.size()); | - |
398 | } | - |
399 | | - |
400 | | - |
401 | | - |
402 | | - |
403 | QSize ControlLabel::sizeHint() const | - |
404 | { | - |
405 | return label.size(); | - |
406 | } | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | bool ControlLabel::event(QEvent *event) | - |
412 | { | - |
413 | if (event->type() == QEvent::WindowIconChange) | - |
414 | updateWindowIcon(); | - |
415 | #ifndef QT_NO_TOOLTIP | - |
416 | else if (event->type() == QEvent::ToolTip) { | - |
417 | QStyleOptionTitleBar options; | - |
418 | options.initFrom(this); | - |
419 | showToolTip(static_cast<QHelpEvent *>(event), this, options, | - |
420 | QStyle::CC_TitleBar, QStyle::SC_TitleBarSysMenu); | - |
421 | } | - |
422 | #endif | - |
423 | return QWidget::event(event); | - |
424 | } | - |
425 | | - |
426 | | - |
427 | | - |
428 | | - |
429 | void ControlLabel::paintEvent(QPaintEvent * ) | - |
430 | { | - |
431 | QPainter painter(this); | - |
432 | painter.drawPixmap(0, 0, label); | - |
433 | } | - |
434 | | - |
435 | | - |
436 | | - |
437 | | - |
438 | void ControlLabel::mousePressEvent(QMouseEvent *mouseEvent) | - |
439 | { | - |
440 | if (mouseEvent->button() != Qt::LeftButton) { | - |
441 | mouseEvent->ignore(); | - |
442 | return; | - |
443 | } | - |
444 | isPressed = true; | - |
445 | } | - |
446 | | - |
447 | | - |
448 | | - |
449 | | - |
450 | void ControlLabel::mouseDoubleClickEvent(QMouseEvent *mouseEvent) | - |
451 | { | - |
452 | if (mouseEvent->button() != Qt::LeftButton) { | - |
453 | mouseEvent->ignore(); | - |
454 | return; | - |
455 | } | - |
456 | isPressed = false; | - |
457 | emit _q_doubleClicked(); | - |
458 | } | - |
459 | | - |
460 | | - |
461 | | - |
462 | | - |
463 | void ControlLabel::mouseReleaseEvent(QMouseEvent *mouseEvent) | - |
464 | { | - |
465 | if (mouseEvent->button() != Qt::LeftButton) { | - |
466 | mouseEvent->ignore(); | - |
467 | return; | - |
468 | } | - |
469 | if (isPressed) { | - |
470 | isPressed = false; | - |
471 | emit _q_clicked(); | - |
472 | } | - |
473 | } | - |
474 | | - |
475 | | - |
476 | | - |
477 | | - |
478 | void ControlLabel::updateWindowIcon() | - |
479 | { | - |
480 | QIcon menuIcon = windowIcon(); | - |
481 | if (menuIcon.isNull()) | - |
482 | menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, parentWidget()); | - |
483 | label = menuIcon.pixmap(16, 16); | - |
484 | update(); | - |
485 | } | - |
486 | | - |
487 | namespace QMdi { | - |
488 | | - |
489 | | - |
490 | | - |
491 | | - |
492 | class ControllerWidget : public QWidget | - |
493 | { | - |
494 | Q_OBJECT | - |
495 | public: | - |
496 | ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent = 0); | - |
497 | QSize sizeHint() const Q_DECL_OVERRIDE; | - |
498 | void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible); | - |
499 | inline bool hasVisibleControls() const | - |
500 | { | - |
501 | return (visibleControls & QStyle::SC_MdiMinButton) | - |
502 | || (visibleControls & QStyle::SC_MdiNormalButton) | - |
503 | || (visibleControls & QStyle::SC_MdiCloseButton); | - |
504 | } | - |
505 | | - |
506 | signals: | - |
507 | void _q_minimize(); | - |
508 | void _q_restore(); | - |
509 | void _q_close(); | - |
510 | | - |
511 | protected: | - |
512 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; | - |
513 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; | - |
514 | void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; | - |
515 | void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; | - |
516 | void leaveEvent(QEvent *event) Q_DECL_OVERRIDE; | - |
517 | bool event(QEvent *event) Q_DECL_OVERRIDE; | - |
518 | | - |
519 | private: | - |
520 | QStyle::SubControl activeControl; | - |
521 | QStyle::SubControl hoverControl; | - |
522 | QStyle::SubControls visibleControls; | - |
523 | void initStyleOption(QStyleOptionComplex *option) const; | - |
524 | QMdiArea *mdiArea; | - |
525 | inline QStyle::SubControl getSubControl(const QPoint &pos) const | - |
526 | { | - |
527 | QStyleOptionComplex opt; | - |
528 | initStyleOption(&opt); | - |
529 | return style()->hitTestComplexControl(QStyle::CC_MdiControls, &opt, pos, mdiArea); | - |
530 | } | - |
531 | }; | - |
532 | } | - |
533 | | - |
534 | | - |
535 | | - |
536 | | - |
537 | ControllerWidget::ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent) | - |
538 | : QWidget(parent), | - |
539 | activeControl(QStyle::SC_None), | - |
540 | hoverControl(QStyle::SC_None), | - |
541 | visibleControls(QStyle::SC_None), | - |
542 | mdiArea(0) | - |
543 | { | - |
544 | if (subWindow->parentWidget()) | - |
545 | mdiArea = qobject_cast<QMdiArea *>(subWindow->parentWidget()->parentWidget()); | - |
546 | setFocusPolicy(Qt::NoFocus); | - |
547 | setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); | - |
548 | setMouseTracking(true); | - |
549 | } | - |
550 | | - |
551 | | - |
552 | | - |
553 | | - |
554 | QSize ControllerWidget::sizeHint() const | - |
555 | { | - |
556 | ensurePolished(); | - |
557 | QStyleOptionComplex opt; | - |
558 | initStyleOption(&opt); | - |
559 | QSize size(48, 16); | - |
560 | return style()->sizeFromContents(QStyle::CT_MdiControls, &opt, size, mdiArea); | - |
561 | } | - |
562 | | - |
563 | void ControllerWidget::setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible) | - |
564 | { | - |
565 | QStyle::SubControl subControl = QStyle::SC_None; | - |
566 | | - |
567 | | - |
568 | if (action == QMdiSubWindowPrivate::MaximizeAction)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
569 | subControl = QStyle::SC_MdiNormalButton; never executed: subControl = QStyle::SC_MdiNormalButton; | 0 |
570 | else if (action == QMdiSubWindowPrivate::CloseAction)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
571 | subControl = QStyle::SC_MdiCloseButton; never executed: subControl = QStyle::SC_MdiCloseButton; | 0 |
572 | else if (action == QMdiSubWindowPrivate::MinimizeAction)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
573 | subControl = QStyle::SC_MdiMinButton; never executed: subControl = QStyle::SC_MdiMinButton; | 0 |
574 | | - |
575 | if (subControl == QStyle::SC_None)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
576 | return; never executed: return; | 0 |
577 | | - |
578 | if (visible && !(visibleControls & subControl))visibleControls|=.setFlag(subControl; | - |
| else if (!, visible && (visibleControls & subControl))!(visibleControls & = ~subControl;)); | |
579 | } never executed: end of block | 0 |
580 | | - |
581 | | - |
582 | | - |
583 | | - |
584 | void ControllerWidget::paintEvent(QPaintEvent * ) | - |
585 | { | - |
586 | QStyleOptionComplex opt; | - |
587 | initStyleOption(&opt); | - |
588 | if (activeControl == hoverControl) { | - |
589 | opt.activeSubControls = activeControl; | - |
590 | opt.state |= QStyle::State_Sunken; | - |
591 | } else if (hoverControl != QStyle::SC_None && (activeControl == QStyle::SC_None)) { | - |
592 | opt.activeSubControls = hoverControl; | - |
593 | opt.state |= QStyle::State_MouseOver; | - |
594 | } | - |
595 | QPainter painter(this); | - |
596 | style()->drawComplexControl(QStyle::CC_MdiControls, &opt, &painter, mdiArea); | - |
597 | } | - |
598 | | - |
599 | | - |
600 | | - |
601 | | - |
602 | void ControllerWidget::mousePressEvent(QMouseEvent *event) | - |
603 | { | - |
604 | if (event->button() != Qt::LeftButton) { | - |
605 | event->ignore(); | - |
606 | return; | - |
607 | } | - |
608 | activeControl = getSubControl(event->pos()); | - |
609 | update(); | - |
610 | } | - |
611 | | - |
612 | | - |
613 | | - |
614 | | - |
615 | void ControllerWidget::mouseReleaseEvent(QMouseEvent *event) | - |
616 | { | - |
617 | if (event->button() != Qt::LeftButton) { | - |
618 | event->ignore(); | - |
619 | return; | - |
620 | } | - |
621 | | - |
622 | QStyle::SubControl under_mouse = getSubControl(event->pos()); | - |
623 | if (under_mouse == activeControl) { | - |
624 | switch (activeControl) { | - |
625 | case QStyle::SC_MdiCloseButton: | - |
626 | emit _q_close(); | - |
627 | break; | - |
628 | case QStyle::SC_MdiNormalButton: | - |
629 | emit _q_restore(); | - |
630 | break; | - |
631 | case QStyle::SC_MdiMinButton: | - |
632 | emit _q_minimize(); | - |
633 | break; | - |
634 | default: | - |
635 | break; | - |
636 | } | - |
637 | } | - |
638 | | - |
639 | activeControl = QStyle::SC_None; | - |
640 | update(); | - |
641 | } | - |
642 | | - |
643 | | - |
644 | | - |
645 | | - |
646 | void ControllerWidget::mouseMoveEvent(QMouseEvent *event) | - |
647 | { | - |
648 | QStyle::SubControl under_mouse = getSubControl(event->pos()); | - |
649 | | - |
650 | if (hoverControl != under_mouse) { | - |
651 | hoverControl = under_mouse; | - |
652 | update(); | - |
653 | } | - |
654 | } | - |
655 | | - |
656 | | - |
657 | | - |
658 | | - |
659 | void ControllerWidget::leaveEvent(QEvent * ) | - |
660 | { | - |
661 | hoverControl = QStyle::SC_None; | - |
662 | update(); | - |
663 | } | - |
664 | | - |
665 | | - |
666 | | - |
667 | | - |
668 | bool ControllerWidget::event(QEvent *event) | - |
669 | { | - |
670 | #ifndef QT_NO_TOOLTIP | - |
671 | if (event->type() == QEvent::ToolTip) { | - |
672 | QStyleOptionComplex opt; | - |
673 | initStyleOption(&opt); | - |
674 | QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); | - |
675 | showToolTip(helpEvent, this, opt, QStyle::CC_MdiControls, getSubControl(helpEvent->pos())); | - |
676 | } | - |
677 | #endif // QT_NO_TOOLTIP | - |
678 | return QWidget::event(event); | - |
679 | } | - |
680 | | - |
681 | | - |
682 | | - |
683 | | - |
684 | void ControllerWidget::initStyleOption(QStyleOptionComplex *option) const | - |
685 | { | - |
686 | option->initFrom(this); | - |
687 | option->subControls = visibleControls; | - |
688 | option->activeSubControls = QStyle::SC_None; | - |
689 | } | - |
690 | | - |
691 | | - |
692 | | - |
693 | | - |
694 | ControlContainer::ControlContainer(QMdiSubWindow *mdiChild) | - |
695 | : QObject(mdiChild), | - |
696 | previousLeft(0), | - |
697 | previousRight(0), | - |
698 | #ifndef QT_NO_MENUBAR | - |
699 | m_menuBar(0), | - |
700 | #endif | - |
701 | mdiChild(mdiChild) | - |
702 | { | - |
703 | Q_ASSERT(mdiChild); | - |
704 | | - |
705 | m_controllerWidget = new ControlElement<ControllerWidget>(mdiChild); | - |
706 | connect(m_controllerWidget, SIGNAL(_q_close()), mdiChild, SLOT(close())); | - |
707 | connect(m_controllerWidget, SIGNAL(_q_restore()), mdiChild, SLOT(showNormal())); | - |
708 | connect(m_controllerWidget, SIGNAL(_q_minimize()), mdiChild, SLOT(showMinimized())); | - |
709 | | - |
710 | m_menuLabel = new ControlElement<ControlLabel>(mdiChild); | - |
711 | m_menuLabel->setWindowIcon(mdiChild->windowIcon()); | - |
712 | #ifndef QT_NO_MENU | - |
713 | connect(m_menuLabel, SIGNAL(_q_clicked()), mdiChild, SLOT(showSystemMenu())); | - |
714 | #endif | - |
715 | connect(m_menuLabel, SIGNAL(_q_doubleClicked()), mdiChild, SLOT(close())); | - |
716 | } | - |
717 | | - |
718 | ControlContainer::~ControlContainer() | - |
719 | { | - |
720 | #ifndef QT_NO_MENUBAR | - |
721 | removeButtonsFromMenuBar(); | - |
722 | #endif | - |
723 | delete m_menuLabel; | - |
724 | m_menuLabel = 0; | - |
725 | delete m_controllerWidget; | - |
726 | m_controllerWidget = 0; | - |
727 | } | - |
728 | | - |
729 | #ifndef QT_NO_MENUBAR | - |
730 | | - |
731 | | - |
732 | | - |
733 | QMenuBar *QMdiSubWindowPrivate::menuBar() const | - |
734 | { | - |
735 | #if defined(QT_NO_MAINWINDOW) | - |
736 | return 0; | - |
737 | #else | - |
738 | Q_Q(const QMdiSubWindow); | - |
739 | if (!q->isMaximized() || drawTitleBarWhenMaximized() || isChildOfTabbedQMdiArea(q)) | - |
740 | return 0; | - |
741 | | - |
742 | if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window())) | - |
743 | return mainWindow->menuBar(); | - |
744 | | - |
745 | return 0; | - |
746 | #endif | - |
747 | } | - |
748 | | - |
749 | | - |
750 | | - |
751 | | - |
752 | void ControlContainer::showButtonsInMenuBar(QMenuBar *menuBar) | - |
753 | { | - |
754 | if (!menuBar || !mdiChild || mdiChild->windowFlags() & Qt::FramelessWindowHint) | - |
755 | return; | - |
756 | m_menuBar = menuBar; | - |
757 | | - |
758 | if (m_menuLabel && mdiChild->windowFlags() & Qt::WindowSystemMenuHint) { | - |
759 | QWidget *currentLeft = menuBar->cornerWidget(Qt::TopLeftCorner); | - |
760 | if (currentLeft) | - |
761 | currentLeft->hide(); | - |
762 | if (currentLeft != m_menuLabel) { | - |
763 | menuBar->setCornerWidget(m_menuLabel, Qt::TopLeftCorner); | - |
764 | previousLeft = currentLeft; | - |
765 | } | - |
766 | m_menuLabel->show(); | - |
767 | } | - |
768 | ControllerWidget *controllerWidget = qobject_cast<ControllerWidget *>(m_controllerWidget); | - |
769 | if (controllerWidget && controllerWidget->hasVisibleControls()) { | - |
770 | QWidget *currentRight = menuBar->cornerWidget(Qt::TopRightCorner); | - |
771 | if (currentRight) | - |
772 | currentRight->hide(); | - |
773 | if (currentRight != m_controllerWidget) { | - |
774 | menuBar->setCornerWidget(m_controllerWidget, Qt::TopRightCorner); | - |
775 | previousRight = currentRight; | - |
776 | } | - |
777 | m_controllerWidget->show(); | - |
778 | } | - |
779 | mdiChild->d_func()->setNewWindowTitle(); | - |
780 | } | - |
781 | | - |
782 | | - |
783 | | - |
784 | | - |
785 | void ControlContainer::removeButtonsFromMenuBar(QMenuBar *menuBar) | - |
786 | { | - |
787 | if (menuBar && menuBar != m_menuBar) { | - |
788 | | - |
789 | previousRight = 0; | - |
790 | previousLeft = 0; | - |
791 | m_menuBar = menuBar; | - |
792 | } | - |
793 | | - |
794 | if (!m_menuBar || !mdiChild || qt_widget_private(mdiChild->window())->data.in_destructor) | - |
795 | return; | - |
796 | | - |
797 | QMdiSubWindow *child = 0; | - |
798 | if (m_controllerWidget) { | - |
799 | QWidget *currentRight = m_menuBar->cornerWidget(Qt::TopRightCorner); | - |
800 | if (currentRight == m_controllerWidget) { | - |
801 | if (ControlElement<ControllerWidget> *ce = ptr<ControllerWidget>(previousRight)) { | - |
802 | if (!ce->mdiChild || !ce->mdiChild->isMaximized()) | - |
803 | previousRight = 0; | - |
804 | else | - |
805 | child = ce->mdiChild; | - |
806 | } | - |
807 | m_menuBar->setCornerWidget(previousRight, Qt::TopRightCorner); | - |
808 | if (previousRight) { | - |
809 | previousRight->show(); | - |
810 | previousRight = 0; | - |
811 | } | - |
812 | } | - |
813 | m_controllerWidget->hide(); | - |
814 | m_controllerWidget->setParent(0); | - |
815 | } | - |
816 | if (m_menuLabel) { | - |
817 | QWidget *currentLeft = m_menuBar->cornerWidget(Qt::TopLeftCorner); | - |
818 | if (currentLeft == m_menuLabel) { | - |
819 | if (ControlElement<ControlLabel> *ce = ptr<ControlLabel>(previousLeft)) { | - |
820 | if (!ce->mdiChild || !ce->mdiChild->isMaximized()) | - |
821 | previousLeft = 0; | - |
822 | else if (!child) | - |
823 | child = mdiChild; | - |
824 | } | - |
825 | m_menuBar->setCornerWidget(previousLeft, Qt::TopLeftCorner); | - |
826 | if (previousLeft) { | - |
827 | previousLeft->show(); | - |
828 | previousLeft = 0; | - |
829 | } | - |
830 | } | - |
831 | m_menuLabel->hide(); | - |
832 | m_menuLabel->setParent(0); | - |
833 | } | - |
834 | m_menuBar->update(); | - |
835 | if (child) | - |
836 | child->d_func()->setNewWindowTitle(); | - |
837 | else if (mdiChild) | - |
838 | mdiChild->window()->setWindowTitle(mdiChild->d_func()->originalWindowTitle()); | - |
839 | } | - |
840 | | - |
841 | #endif // QT_NO_MENUBAR | - |
842 | | - |
843 | void ControlContainer::updateWindowIcon(const QIcon &windowIcon) | - |
844 | { | - |
845 | if (m_menuLabel) | - |
846 | m_menuLabel->setWindowIcon(windowIcon); | - |
847 | } | - |
848 | | - |
849 | | - |
850 | | - |
851 | | - |
852 | QMdiSubWindowPrivate::QMdiSubWindowPrivate() | - |
853 | : baseWidget(0), | - |
854 | restoreFocusWidget(0), | - |
855 | controlContainer(0), | - |
856 | #ifndef QT_NO_SIZEGRIP | - |
857 | sizeGrip(0), | - |
858 | #endif | - |
859 | #ifndef QT_NO_RUBBERBAND | - |
860 | rubberBand(0), | - |
861 | #endif | - |
862 | userMinimumSize(0,0), | - |
863 | resizeEnabled(true), | - |
864 | moveEnabled(true), | - |
865 | isInInteractiveMode(false), | - |
866 | #ifndef QT_NO_RUBBERBAND | - |
867 | isInRubberBandMode(false), | - |
868 | #endif | - |
869 | isShadeMode(false), | - |
870 | ignoreWindowTitleChange(false), | - |
871 | ignoreNextActivationEvent(false), | - |
872 | activationEnabled(true), | - |
873 | isShadeRequestFromMinimizeMode(false), | - |
874 | isMaximizeMode(false), | - |
875 | isWidgetHiddenByUs(false), | - |
876 | isActive(false), | - |
877 | isExplicitlyDeactivated(false), | - |
878 | keyboardSingleStep(5), | - |
879 | keyboardPageStep(20), | - |
880 | resizeTimerId(-1), | - |
881 | currentOperation(None), | - |
882 | hoveredSubControl(QStyle::SC_None), | - |
883 | activeSubControl(QStyle::SC_None), | - |
884 | focusInReason(Qt::ActiveWindowFocusReason) | - |
885 | { | - |
886 | initOperationMap(); | - |
887 | } | - |
888 | | - |
889 | | - |
890 | | - |
891 | | - |
892 | void QMdiSubWindowPrivate::_q_updateStaysOnTopHint() | - |
893 | { | - |
894 | #ifndef QT_NO_ACTION | - |
895 | Q_Q(QMdiSubWindow); | - |
896 | if (QAction *senderAction = qobject_cast<QAction *>(q->sender())) { | - |
897 | if (senderAction->isChecked()) { | - |
898 | q->setWindowFlags(q->windowFlags() | Qt::WindowStaysOnTopHint); | - |
899 | q->raise(); | - |
900 | } else { | - |
901 | q->setWindowFlags(q->windowFlags() & ~Qt::WindowStaysOnTopHint); | - |
902 | q->lower(); | - |
903 | } | - |
904 | } | - |
905 | #endif // QT_NO_ACTION | - |
906 | } | - |
907 | | - |
908 | | - |
909 | | - |
910 | | - |
911 | void QMdiSubWindowPrivate::_q_enterInteractiveMode() | - |
912 | { | - |
913 | #ifndef QT_NO_ACTION | - |
914 | Q_Q(QMdiSubWindow); | - |
915 | QAction *action = qobject_cast<QAction *>(q->sender()); | - |
916 | if (!action) | - |
917 | return; | - |
918 | | - |
919 | QPoint pressPos; | - |
920 | if (actions[MoveAction] && actions[MoveAction] == action) { | - |
921 | currentOperation = Move; | - |
922 | pressPos = QPoint(q->width() / 2, titleBarHeight() - 1); | - |
923 | } else if (actions[ResizeAction] && actions[ResizeAction] == action) { | - |
924 | currentOperation = q->isLeftToRight() ? BottomRightResize : BottomLeftResize; | - |
925 | int offset = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q) / 2; | - |
926 | int x = q->isLeftToRight() ? q->width() - offset : offset; | - |
927 | pressPos = QPoint(x, q->height() - offset); | - |
928 | } else { | - |
929 | return; | - |
930 | } | - |
931 | | - |
932 | updateCursor(); | - |
933 | #ifndef QT_NO_CURSOR | - |
934 | q->cursor().setPos(q->mapToGlobal(pressPos)); | - |
935 | #endif | - |
936 | mousePressPosition = q->mapToParent(pressPos); | - |
937 | oldGeometry = q->geometry(); | - |
938 | isInInteractiveMode = true; | - |
939 | q->setFocus(); | - |
940 | #ifndef QT_NO_RUBBERBAND | - |
941 | if ((q->testOption(QMdiSubWindow::RubberBandResize) | - |
942 | && (currentOperation == BottomRightResize || currentOperation == BottomLeftResize)) | - |
943 | || (q->testOption(QMdiSubWindow::RubberBandMove) && currentOperation == Move)) { | - |
944 | enterRubberBandMode(); | - |
945 | } else | - |
946 | #endif // QT_NO_RUBBERBAND | - |
947 | { | - |
948 | q->grabMouse(); | - |
949 | } | - |
950 | #endif // QT_NO_ACTION | - |
951 | } | - |
952 | | - |
953 | | - |
954 | | - |
955 | | - |
956 | void QMdiSubWindowPrivate::_q_processFocusChanged(QWidget *old, QWidget *now) | - |
957 | { | - |
958 | Q_UNUSED(old); | - |
959 | Q_Q(QMdiSubWindow); | - |
960 | if (now && (now == q || q->isAncestorOf(now))) { | - |
961 | if (now == q && !isInInteractiveMode) | - |
962 | setFocusWidget(); | - |
963 | setActive(true); | - |
964 | } | - |
965 | } | - |
966 | | - |
967 | | - |
968 | | - |
969 | | - |
970 | void QMdiSubWindowPrivate::leaveInteractiveMode() | - |
971 | { | - |
972 | Q_Q(QMdiSubWindow); | - |
973 | #ifndef QT_NO_RUBBERBAND | - |
974 | if (isInRubberBandMode) | - |
975 | leaveRubberBandMode(); | - |
976 | else | - |
977 | #endif | - |
978 | q->releaseMouse(); | - |
979 | isInInteractiveMode = false; | - |
980 | currentOperation = None; | - |
981 | updateDirtyRegions(); | - |
982 | updateCursor(); | - |
983 | if (baseWidget && baseWidget->focusWidget()) | - |
984 | baseWidget->focusWidget()->setFocus(); | - |
985 | } | - |
986 | | - |
987 | | - |
988 | | - |
989 | | - |
990 | void QMdiSubWindowPrivate::removeBaseWidget() | - |
991 | { | - |
992 | if (!baseWidget)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
993 | return; never executed: return; | 0 |
994 | | - |
995 | Q_Q(QMdiSubWindow); | - |
996 | baseWidget->removeEventFilter(q); | - |
997 | if (layout)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
998 | layout->removeWidget(baseWidget); never executed: layout->removeWidget(baseWidget); | 0 |
999 | if (baseWidget->windowTitle() == q->windowTitle()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1000 | ignoreWindowTitleChange = true; | - |
1001 | q->setWindowTitle(QString()); | - |
1002 | ignoreWindowTitleChange = false; | - |
1003 | q->setWindowModified(false); | - |
1004 | } never executed: end of block | 0 |
1005 | lastChildWindowTitle.clear(); | - |
1006 | | - |
1007 | if (baseWidget->parentWidget() == q)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1008 | baseWidget->setParent(0); never executed: baseWidget->setParent(0); | 0 |
1009 | baseWidget = 0; | - |
1010 | isWidgetHiddenByUs = false; | - |
1011 | } never executed: end of block | 0 |
1012 | | - |
1013 | | - |
1014 | | - |
1015 | | - |
1016 | void QMdiSubWindowPrivate::initOperationMap() | - |
1017 | { | - |
1018 | operationMap.insert(Move, OperationInfo(HMove | VMove, Qt::ArrowCursor, false)); | - |
1019 | operationMap.insert(TopResize, OperationInfo(VMove | VResize | VResizeReverse, Qt::SizeVerCursor)); | - |
1020 | operationMap.insert(BottomResize, OperationInfo(VResize, Qt::SizeVerCursor)); | - |
1021 | operationMap.insert(LeftResize, OperationInfo(HMove | HResize | HResizeReverse, Qt::SizeHorCursor)); | - |
1022 | operationMap.insert(RightResize, OperationInfo(HResize, Qt::SizeHorCursor)); | - |
1023 | operationMap.insert(TopLeftResize, OperationInfo(HMove | VMove | HResize | VResize | VResizeReverse | - |
1024 | | HResizeReverse, Qt::SizeFDiagCursor)); | - |
1025 | operationMap.insert(TopRightResize, OperationInfo(VMove | HResize | VResize | - |
1026 | | VResizeReverse, Qt::SizeBDiagCursor)); | - |
1027 | operationMap.insert(BottomLeftResize, OperationInfo(HMove | HResize | VResize | HResizeReverse, | - |
1028 | Qt::SizeBDiagCursor)); | - |
1029 | operationMap.insert(BottomRightResize, OperationInfo(HResize | VResize, Qt::SizeFDiagCursor)); | - |
1030 | } | - |
1031 | | - |
1032 | #ifndef QT_NO_MENU | - |
1033 | | - |
1034 | | - |
1035 | | - |
1036 | | - |
1037 | void QMdiSubWindowPrivate::createSystemMenu() | - |
1038 | { | - |
1039 | Q_Q(QMdiSubWindow); | - |
1040 | Q_ASSERT_X(q, "QMdiSubWindowPrivate::createSystemMenu", | - |
1041 | "You can NOT call this function before QMdiSubWindow's ctor"); | - |
1042 | systemMenu = new QMenu(q); | - |
1043 | systemMenu->installEventFilter(q); | - |
1044 | const QStyle *style = q->style(); | - |
1045 | addToSystemMenu(RestoreAction, QMdiSubWindow::tr("&Restore"), SLOT(showNormal())); | - |
1046 | actions[RestoreAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarNormalButton, 0, q)); | - |
1047 | actions[RestoreAction]->setEnabled(false); | - |
1048 | addToSystemMenu(MoveAction, QMdiSubWindow::tr("&Move"), SLOT(_q_enterInteractiveMode())); | - |
1049 | addToSystemMenu(ResizeAction, QMdiSubWindow::tr("&Size"), SLOT(_q_enterInteractiveMode())); | - |
1050 | addToSystemMenu(MinimizeAction, QMdiSubWindow::tr("Mi&nimize"), SLOT(showMinimized())); | - |
1051 | actions[MinimizeAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarMinButton, 0, q)); | - |
1052 | addToSystemMenu(MaximizeAction, QMdiSubWindow::tr("Ma&ximize"), SLOT(showMaximized())); | - |
1053 | actions[MaximizeAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarMaxButton, 0, q)); | - |
1054 | addToSystemMenu(StayOnTopAction, QMdiSubWindow::tr("Stay on &Top"), SLOT(_q_updateStaysOnTopHint())); | - |
1055 | actions[StayOnTopAction]->setCheckable(true); | - |
1056 | systemMenu->addSeparator(); | - |
1057 | addToSystemMenu(CloseAction, QMdiSubWindow::tr("&Close"), SLOT(close())); | - |
1058 | actions[CloseAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarCloseButton, 0, q)); | - |
1059 | #if !defined(QT_NO_SHORTCUT) | - |
1060 | actions[CloseAction]->setShortcuts(QKeySequence::Close); | - |
1061 | #endif | - |
1062 | updateActions(); | - |
1063 | } | - |
1064 | #endif | - |
1065 | | - |
1066 | | - |
1067 | | - |
1068 | | - |
1069 | void QMdiSubWindowPrivate::updateCursor() | - |
1070 | { | - |
1071 | #ifndef QT_NO_CURSOR | - |
1072 | Q_Q(QMdiSubWindow); | - |
1073 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
1074 | if (qobject_cast<QMacStyle *>(q->style())) | - |
1075 | return; | - |
1076 | #endif | - |
1077 | | - |
1078 | if (currentOperation == None) { | - |
1079 | q->unsetCursor(); | - |
1080 | return; | - |
1081 | } | - |
1082 | | - |
1083 | if (currentOperation == Move || operationMap.find(currentOperation).value().hover) { | - |
1084 | q->setCursor(operationMap.find(currentOperation).value().cursorShape); | - |
1085 | return; | - |
1086 | } | - |
1087 | #endif | - |
1088 | } | - |
1089 | | - |
1090 | | - |
1091 | | - |
1092 | | - |
1093 | void QMdiSubWindowPrivate::updateDirtyRegions() | - |
1094 | { | - |
1095 | | - |
1096 | if (!parent) | - |
1097 | return; | - |
1098 | | - |
1099 | for (OperationInfoMap::iterator it = operationMap.begin(), end = operationMap.end(); it != end; ++it) | - |
1100 | it.value().region = getRegion(it.key()); | - |
1101 | } | - |
1102 | | - |
1103 | | - |
1104 | | - |
1105 | | - |
1106 | void QMdiSubWindowPrivate::updateGeometryConstraints() | - |
1107 | { | - |
1108 | Q_Q(QMdiSubWindow); | - |
1109 | if (!parent) | - |
1110 | return; | - |
1111 | | - |
1112 | internalMinimumSize = (!q->isMinimized() && !q->minimumSize().isNull()) | - |
1113 | ? q->minimumSize() : q->minimumSizeHint(); | - |
1114 | int margin, minWidth; | - |
1115 | sizeParameters(&margin, &minWidth); | - |
1116 | q->setContentsMargins(margin, titleBarHeight(), margin, margin); | - |
1117 | if (q->isMaximized() || (q->isMinimized() && !q->isShaded())) { | - |
1118 | moveEnabled = false; | - |
1119 | resizeEnabled = false; | - |
1120 | } else { | - |
1121 | moveEnabled = true; | - |
1122 | if ((q->windowFlags() & Qt::MSWindowsFixedSizeDialogHint) || q->isShaded()) | - |
1123 | resizeEnabled = false; | - |
1124 | else | - |
1125 | resizeEnabled = true; | - |
1126 | } | - |
1127 | updateDirtyRegions(); | - |
1128 | } | - |
1129 | | - |
1130 | | - |
1131 | | - |
1132 | | - |
1133 | void QMdiSubWindowPrivate::updateMask() | - |
1134 | { | - |
1135 | Q_Q(QMdiSubWindow); | - |
1136 | if (!q->mask().isEmpty()) | - |
1137 | q->clearMask(); | - |
1138 | | - |
1139 | if (!parent) | - |
1140 | return; | - |
1141 | | - |
1142 | if ((q->isMaximized() && !drawTitleBarWhenMaximized()) | - |
1143 | || q->windowFlags() & Qt::FramelessWindowHint) | - |
1144 | return; | - |
1145 | | - |
1146 | if (resizeTimerId == -1) | - |
1147 | cachedStyleOptions = titleBarOptions(); | - |
1148 | cachedStyleOptions.rect = q->rect(); | - |
1149 | QStyleHintReturnMask frameMask; | - |
1150 | q->style()->styleHint(QStyle::SH_WindowFrame_Mask, &cachedStyleOptions, q, &frameMask); | - |
1151 | if (!frameMask.region.isEmpty()) | - |
1152 | q->setMask(frameMask.region); | - |
1153 | } | - |
1154 | | - |
1155 | | - |
1156 | | - |
1157 | | - |
1158 | void QMdiSubWindowPrivate::setNewGeometry(const QPoint &pos) | - |
1159 | { | - |
1160 | Q_Q(QMdiSubWindow); | - |
1161 | Q_ASSERT(currentOperation != None); | - |
1162 | Q_ASSERT(parent); | - |
1163 | | - |
1164 | uint cflags = operationMap.find(currentOperation).value().changeFlags; | - |
1165 | int posX = pos.x(); | - |
1166 | int posY = pos.y(); | - |
1167 | | - |
1168 | const bool restrictHorizontal = !q->testOption(QMdiSubWindow::AllowOutsideAreaHorizontally); | - |
1169 | const bool restrictVertical = !q->testOption(QMdiSubWindow::AllowOutsideAreaVertically); | - |
1170 | | - |
1171 | if (restrictHorizontal || restrictVertical) { | - |
1172 | QRect parentRect = q->parentWidget()->rect(); | - |
1173 | if (restrictVertical && (cflags & VResizeReverse || currentOperation == Move)) { | - |
1174 | posY = qMin(qMax(mousePressPosition.y() - oldGeometry.y(), posY), | - |
1175 | parentRect.height() - BoundaryMargin); | - |
1176 | } | - |
1177 | if (currentOperation == Move) { | - |
1178 | if (restrictHorizontal) | - |
1179 | posX = qMin(qMax(BoundaryMargin, posX), parentRect.width() - BoundaryMargin); | - |
1180 | if (restrictVertical) | - |
1181 | posY = qMin(posY, parentRect.height() - BoundaryMargin); | - |
1182 | } else { | - |
1183 | if (restrictHorizontal) { | - |
1184 | if (cflags & HResizeReverse) | - |
1185 | posX = qMax(mousePressPosition.x() - oldGeometry.x(), posX); | - |
1186 | else | - |
1187 | posX = qMin(parentRect.width() - (oldGeometry.x() + oldGeometry.width() | - |
1188 | - mousePressPosition.x()), posX); | - |
1189 | } | - |
1190 | if (restrictVertical && !(cflags & VResizeReverse)) { | - |
1191 | posY = qMin(parentRect.height() - (oldGeometry.y() + oldGeometry.height() | - |
1192 | - mousePressPosition.y()), posY); | - |
1193 | } | - |
1194 | } | - |
1195 | } | - |
1196 | | - |
1197 | QRect geometry; | - |
1198 | if (cflags & (HMove | VMove)) { | - |
1199 | int dx = getMoveDeltaComponent(cflags, HMove, HResize, posX - mousePressPosition.x(), | - |
1200 | oldGeometry.width() - internalMinimumSize.width(), | - |
1201 | oldGeometry.width() - q->maximumWidth()); | - |
1202 | int dy = getMoveDeltaComponent(cflags, VMove, VResize, posY - mousePressPosition.y(), | - |
1203 | oldGeometry.height() - internalMinimumSize.height(), | - |
1204 | oldGeometry.height() - q->maximumHeight()); | - |
1205 | geometry.setTopLeft(oldGeometry.topLeft() + QPoint(dx, dy)); | - |
1206 | } else { | - |
1207 | geometry.setTopLeft(q->geometry().topLeft()); | - |
1208 | } | - |
1209 | | - |
1210 | if (cflags & (HResize | VResize)) { | - |
1211 | int dx = getResizeDeltaComponent(cflags, HResize, HResizeReverse, | - |
1212 | posX - mousePressPosition.x()); | - |
1213 | int dy = getResizeDeltaComponent(cflags, VResize, VResizeReverse, | - |
1214 | posY - mousePressPosition.y()); | - |
1215 | geometry.setSize(oldGeometry.size() + QSize(dx, dy)); | - |
1216 | } else { | - |
1217 | geometry.setSize(q->geometry().size()); | - |
1218 | } | - |
1219 | | - |
1220 | setNewGeometry(&geometry); | - |
1221 | } | - |
1222 | | - |
1223 | | - |
1224 | | - |
1225 | | - |
1226 | void QMdiSubWindowPrivate::setMinimizeMode() | - |
1227 | { | - |
1228 | Q_Q(QMdiSubWindow); | - |
1229 | Q_ASSERT(parent); | - |
1230 | | - |
1231 | ensureWindowState(Qt::WindowMinimized); | - |
1232 | isShadeRequestFromMinimizeMode = true; | - |
1233 | q->showShaded(); | - |
1234 | isShadeRequestFromMinimizeMode = false; | - |
1235 | | - |
1236 | moveEnabled = false; | - |
1237 | #ifndef QT_NO_ACTION | - |
1238 | setEnabled(MoveAction, moveEnabled); | - |
1239 | #endif | - |
1240 | | - |
1241 | Q_ASSERT(q->windowState() & Qt::WindowMinimized); | - |
1242 | Q_ASSERT(!(q->windowState() & Qt::WindowMaximized)); | - |
1243 | | - |
1244 | | - |
1245 | | - |
1246 | | - |
1247 | | - |
1248 | setActive(true); | - |
1249 | } | - |
1250 | | - |
1251 | | - |
1252 | | - |
1253 | | - |
1254 | void QMdiSubWindowPrivate::setNormalMode() | - |
1255 | { | - |
1256 | Q_Q(QMdiSubWindow); | - |
1257 | Q_ASSERT(parent); | - |
1258 | | - |
1259 | isShadeMode = false; | - |
1260 | isMaximizeMode = false; | - |
1261 | | - |
1262 | ensureWindowState(Qt::WindowNoState); | - |
1263 | #ifndef QT_NO_MENUBAR | - |
1264 | removeButtonsFromMenuBar(); | - |
1265 | #endif | - |
1266 | | - |
1267 | | - |
1268 | | - |
1269 | const bool wasVisible = q->isVisible(); | - |
1270 | if (wasVisible) | - |
1271 | q->setVisible(false); | - |
1272 | | - |
1273 | | - |
1274 | if (!userMinimumSize.isNull()) { | - |
1275 | q->setMinimumSize(userMinimumSize); | - |
1276 | userMinimumSize = QSize(0, 0); | - |
1277 | } | - |
1278 | | - |
1279 | | - |
1280 | if (baseWidget && isWidgetHiddenByUs) { | - |
1281 | baseWidget->show(); | - |
1282 | isWidgetHiddenByUs = false; | - |
1283 | } | - |
1284 | | - |
1285 | updateGeometryConstraints(); | - |
1286 | QRect newGeometry = oldGeometry; | - |
1287 | newGeometry.setSize(restoreSize.expandedTo(internalMinimumSize)); | - |
1288 | q->setGeometry(newGeometry); | - |
1289 | | - |
1290 | if (wasVisible) | - |
1291 | q->setVisible(true); | - |
1292 | | - |
1293 | | - |
1294 | restoreSize.setWidth(-1); | - |
1295 | restoreSize.setHeight(-1); | - |
1296 | | - |
1297 | #ifndef QT_NO_SIZEGRIP | - |
1298 | setSizeGripVisible(true); | - |
1299 | #endif | - |
1300 | | - |
1301 | #ifndef QT_NO_ACTION | - |
1302 | setEnabled(MoveAction, true); | - |
1303 | setEnabled(MaximizeAction, true); | - |
1304 | setEnabled(MinimizeAction, true); | - |
1305 | setEnabled(RestoreAction, false); | - |
1306 | setEnabled(ResizeAction, resizeEnabled); | - |
1307 | #endif // QT_NO_ACTION | - |
1308 | | - |
1309 | Q_ASSERT(!(q_func()->windowState() & Qt::WindowMinimized)); | - |
1310 | | - |
1311 | | - |
1312 | | - |
1313 | Q_ASSERT((isMaximizeMode && q_func()->windowState() & Qt::WindowMaximized) | - |
1314 | || (!isMaximizeMode && !(q_func()->windowState() & Qt::WindowMaximized))); | - |
1315 | Q_ASSERT(!isShadeMode); | - |
1316 | | - |
1317 | setActive(true); | - |
1318 | restoreFocus(); | - |
1319 | updateMask(); | - |
1320 | } | - |
1321 | | - |
1322 | inline void QMdiSubWindowPrivate::storeFocusWidget() | - |
1323 | { | - |
1324 | if (QWidget *focus = QApplication::focusWidget()) { | - |
1325 | if (!restoreFocusWidget && q_func()->isAncestorOf(focus)) | - |
1326 | restoreFocusWidget = focus; | - |
1327 | } | - |
1328 | } | - |
1329 | | - |
1330 | | - |
1331 | | - |
1332 | | - |
1333 | void QMdiSubWindowPrivate::setMaximizeMode() | - |
1334 | { | - |
1335 | Q_Q(QMdiSubWindow); | - |
1336 | Q_ASSERT(parent); | - |
1337 | | - |
1338 | ensureWindowState(Qt::WindowMaximized); | - |
1339 | isShadeMode = false; | - |
1340 | isMaximizeMode = true; | - |
1341 | | - |
1342 | storeFocusWidget(); | - |
1343 | | - |
1344 | #ifndef QT_NO_SIZEGRIP | - |
1345 | setSizeGripVisible(false); | - |
1346 | #endif | - |
1347 | | - |
1348 | | - |
1349 | if (!restoreSize.isValid()) { | - |
1350 | oldGeometry = q->geometry(); | - |
1351 | restoreSize.setWidth(oldGeometry.width()); | - |
1352 | restoreSize.setHeight(oldGeometry.height()); | - |
1353 | } | - |
1354 | | - |
1355 | | - |
1356 | | - |
1357 | const bool wasVisible = q->isVisible(); | - |
1358 | if (wasVisible) | - |
1359 | q->setVisible(false); | - |
1360 | | - |
1361 | | - |
1362 | if (baseWidget && isWidgetHiddenByUs) { | - |
1363 | baseWidget->show(); | - |
1364 | isWidgetHiddenByUs = false; | - |
1365 | } | - |
1366 | | - |
1367 | updateGeometryConstraints(); | - |
1368 | | - |
1369 | if (wasVisible) { | - |
1370 | #ifndef QT_NO_MENUBAR | - |
1371 | if (QMenuBar *mBar = menuBar()) | - |
1372 | showButtonsInMenuBar(mBar); | - |
1373 | else | - |
1374 | #endif | - |
1375 | if (!controlContainer) | - |
1376 | controlContainer = new ControlContainer(q); | - |
1377 | } | - |
1378 | | - |
1379 | QWidget *parent = q->parentWidget(); | - |
1380 | QRect availableRect = parent->contentsRect(); | - |
1381 | | - |
1382 | | - |
1383 | QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent->parentWidget()); | - |
1384 | if (scrollArea && scrollArea->viewport() == parent) { | - |
1385 | QScrollBar *hbar = scrollArea->horizontalScrollBar(); | - |
1386 | QScrollBar *vbar = scrollArea->verticalScrollBar(); | - |
1387 | const int xOffset = hbar ? hbar->value() : 0; | - |
1388 | const int yOffset = vbar ? vbar->value() : 0; | - |
1389 | availableRect.adjust(-xOffset, -yOffset, -xOffset, -yOffset); | - |
1390 | oldGeometry.adjust(xOffset, yOffset, xOffset, yOffset); | - |
1391 | } | - |
1392 | | - |
1393 | setNewGeometry(&availableRect); | - |
1394 | | - |
1395 | ensureWindowState(Qt::WindowMaximized); | - |
1396 | | - |
1397 | if (wasVisible) | - |
1398 | q->setVisible(true); | - |
1399 | | - |
1400 | resizeEnabled = false; | - |
1401 | moveEnabled = false; | - |
1402 | | - |
1403 | #ifndef QT_NO_ACTION | - |
1404 | setEnabled(MoveAction, moveEnabled); | - |
1405 | setEnabled(MaximizeAction, false); | - |
1406 | setEnabled(MinimizeAction, true); | - |
1407 | setEnabled(RestoreAction, true); | - |
1408 | setEnabled(ResizeAction, resizeEnabled); | - |
1409 | #endif // QT_NO_ACTION | - |
1410 | | - |
1411 | Q_ASSERT(q->windowState() & Qt::WindowMaximized); | - |
1412 | Q_ASSERT(!(q->windowState() & Qt::WindowMinimized)); | - |
1413 | | - |
1414 | restoreFocus(); | - |
1415 | updateMask(); | - |
1416 | } | - |
1417 | | - |
1418 | | - |
1419 | | - |
1420 | | - |
1421 | void QMdiSubWindowPrivate::setActive(bool activate, bool changeFocus) | - |
1422 | { | - |
1423 | Q_Q(QMdiSubWindow); | - |
1424 | if (!parent || !activationEnabled) | - |
1425 | return; | - |
1426 | | - |
1427 | if (activate && !isActive && q->isEnabled()) { | - |
1428 | isActive = true; | - |
1429 | isExplicitlyDeactivated = false; | - |
1430 | Qt::WindowStates oldWindowState = q->windowState(); | - |
1431 | ensureWindowState(Qt::WindowActive); | - |
1432 | emit q->aboutToActivate(); | - |
1433 | #ifndef QT_NO_MENUBAR | - |
1434 | if (QMenuBar *mBar = menuBar()) | - |
1435 | showButtonsInMenuBar(mBar); | - |
1436 | #endif | - |
1437 | Q_ASSERT(isActive); | - |
1438 | emit q->windowStateChanged(oldWindowState, q->windowState()); | - |
1439 | } else if (!activate && isActive) { | - |
1440 | isActive = false; | - |
1441 | Qt::WindowStates oldWindowState = q->windowState(); | - |
1442 | q->overrideWindowState(q->windowState() & ~Qt::WindowActive); | - |
1443 | if (changeFocus) { | - |
1444 | storeFocusWidget(); | - |
1445 | QWidget *focusWidget = QApplication::focusWidget(); | - |
1446 | if (focusWidget && (focusWidget == q || q->isAncestorOf(focusWidget))) | - |
1447 | focusWidget->clearFocus(); | - |
1448 | } | - |
1449 | if (baseWidget) | - |
1450 | baseWidget->overrideWindowState(baseWidget->windowState() & ~Qt::WindowActive); | - |
1451 | Q_ASSERT(!isActive); | - |
1452 | emit q->windowStateChanged(oldWindowState, q->windowState()); | - |
1453 | } | - |
1454 | | - |
1455 | if (activate && isActive && q->isEnabled() && !q->hasFocus() | - |
1456 | && !q->isAncestorOf(QApplication::focusWidget())) { | - |
1457 | if (changeFocus) | - |
1458 | setFocusWidget(); | - |
1459 | ensureWindowState(Qt::WindowActive); | - |
1460 | } | - |
1461 | | - |
1462 | int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q); | - |
1463 | int titleBarHeight = this->titleBarHeight(); | - |
1464 | QRegion windowDecoration = QRegion(0, 0, q->width(), q->height()); | - |
1465 | windowDecoration -= QRegion(frameWidth, titleBarHeight, q->width() - 2 * frameWidth, | - |
1466 | q->height() - titleBarHeight - frameWidth); | - |
1467 | | - |
1468 | | - |
1469 | | - |
1470 | if (resizeTimerId != -1) { | - |
1471 | q->killTimer(resizeTimerId); | - |
1472 | resizeTimerId = -1; | - |
1473 | updateDirtyRegions(); | - |
1474 | } | - |
1475 | | - |
1476 | q->update(windowDecoration); | - |
1477 | } | - |
1478 | | - |
1479 | | - |
1480 | | - |
1481 | | - |
1482 | void QMdiSubWindowPrivate::processClickedSubControl() | - |
1483 | { | - |
1484 | Q_Q(QMdiSubWindow); | - |
1485 | switch (activeSubControl) { | - |
1486 | case QStyle::SC_TitleBarContextHelpButton: | - |
1487 | #ifndef QT_NO_WHATSTHIS | - |
1488 | QWhatsThis::enterWhatsThisMode(); | - |
1489 | #endif | - |
1490 | break; | - |
1491 | case QStyle::SC_TitleBarShadeButton: | - |
1492 | q->showShaded(); | - |
1493 | hoveredSubControl = QStyle::SC_TitleBarUnshadeButton; | - |
1494 | break; | - |
1495 | case QStyle::SC_TitleBarUnshadeButton: | - |
1496 | if (q->isShaded()) | - |
1497 | hoveredSubControl = QStyle::SC_TitleBarShadeButton; | - |
1498 | q->showNormal(); | - |
1499 | break; | - |
1500 | case QStyle::SC_TitleBarMinButton: | - |
1501 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
1502 | if (qobject_cast<QMacStyle *>(q->style())) { | - |
1503 | if (q->isMinimized()) | - |
1504 | q->showNormal(); | - |
1505 | else | - |
1506 | q->showMinimized(); | - |
1507 | break; | - |
1508 | } | - |
1509 | #endif | - |
1510 | q->showMinimized(); | - |
1511 | break; | - |
1512 | case QStyle::SC_TitleBarNormalButton: | - |
1513 | if (q->isShaded()) | - |
1514 | hoveredSubControl = QStyle::SC_TitleBarMinButton; | - |
1515 | q->showNormal(); | - |
1516 | break; | - |
1517 | case QStyle::SC_TitleBarMaxButton: | - |
1518 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
1519 | if (qobject_cast<QMacStyle *>(q->style())) { | - |
1520 | if (q->isMaximized()) | - |
1521 | q->showNormal(); | - |
1522 | else | - |
1523 | q->showMaximized(); | - |
1524 | break; | - |
1525 | } | - |
1526 | #endif | - |
1527 | q->showMaximized(); | - |
1528 | break; | - |
1529 | case QStyle::SC_TitleBarCloseButton: | - |
1530 | q->close(); | - |
1531 | break; | - |
1532 | default: | - |
1533 | break; | - |
1534 | } | - |
1535 | } | - |
1536 | | - |
1537 | | - |
1538 | | - |
1539 | | - |
1540 | QRegion QMdiSubWindowPrivate::getRegion(Operation operation) const | - |
1541 | { | - |
1542 | Q_Q(const QMdiSubWindow); | - |
1543 | int width = q->width(); | - |
1544 | int height = q->height(); | - |
1545 | int titleBarHeight = this->titleBarHeight(); | - |
1546 | int frameWidth = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q); | - |
1547 | int cornerConst = titleBarHeight - frameWidth; | - |
1548 | int titleBarConst = 2 * titleBarHeight; | - |
1549 | | - |
1550 | if (operation == Move) { | - |
1551 | QStyleOptionTitleBar titleBarOptions = this->titleBarOptions(); | - |
1552 | QRegion move(frameWidth, frameWidth, width - 2 * frameWidth, cornerConst); | - |
1553 | | - |
1554 | | - |
1555 | for (int i = 0; i < NumSubControls; ++i) { | - |
1556 | if (SubControls[i] == QStyle::SC_TitleBarLabel) | - |
1557 | continue; | - |
1558 | move -= QRegion(q->style()->subControlRect(QStyle::CC_TitleBar, &titleBarOptions, | - |
1559 | SubControls[i])); | - |
1560 | } | - |
1561 | return move; | - |
1562 | } | - |
1563 | | - |
1564 | QRegion region; | - |
1565 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
1566 | if (qobject_cast<QMacStyle *>(q->style())) | - |
1567 | return region; | - |
1568 | #endif | - |
1569 | | - |
1570 | switch (operation) { | - |
1571 | case TopResize: | - |
1572 | region = QRegion(titleBarHeight, 0, width - titleBarConst, frameWidth); | - |
1573 | break; | - |
1574 | case BottomResize: | - |
1575 | region = QRegion(titleBarHeight, height - frameWidth, width - titleBarConst, frameWidth); | - |
1576 | break; | - |
1577 | case LeftResize: | - |
1578 | region = QRegion(0, titleBarHeight, frameWidth, height - titleBarConst); | - |
1579 | break; | - |
1580 | case RightResize: | - |
1581 | region = QRegion(width - frameWidth, titleBarHeight, frameWidth, height - titleBarConst); | - |
1582 | break; | - |
1583 | case TopLeftResize: | - |
1584 | region = QRegion(0, 0, titleBarHeight, titleBarHeight) | - |
1585 | - QRegion(frameWidth, frameWidth, cornerConst, cornerConst); | - |
1586 | break; | - |
1587 | case TopRightResize: | - |
1588 | region = QRegion(width - titleBarHeight, 0, titleBarHeight, titleBarHeight) | - |
1589 | - QRegion(width - titleBarHeight, frameWidth, cornerConst, cornerConst); | - |
1590 | break; | - |
1591 | case BottomLeftResize: | - |
1592 | region = QRegion(0, height - titleBarHeight, titleBarHeight, titleBarHeight) | - |
1593 | - QRegion(frameWidth, height - titleBarHeight, cornerConst, cornerConst); | - |
1594 | break; | - |
1595 | case BottomRightResize: | - |
1596 | region = QRegion(width - titleBarHeight, height - titleBarHeight, titleBarHeight, titleBarHeight) | - |
1597 | - QRegion(width - titleBarHeight, height - titleBarHeight, cornerConst, cornerConst); | - |
1598 | break; | - |
1599 | default: | - |
1600 | break; | - |
1601 | } | - |
1602 | | - |
1603 | return region; | - |
1604 | } | - |
1605 | | - |
1606 | | - |
1607 | | - |
1608 | | - |
1609 | QMdiSubWindowPrivate::Operation QMdiSubWindowPrivate::getOperation(const QPoint &pos) const | - |
1610 | { | - |
1611 | OperationInfoMap::const_iterator it; | - |
1612 | for (it = operationMap.constBegin(); it != operationMap.constEnd(); ++it) | - |
1613 | if (it.value().region.contains(pos)) | - |
1614 | return it.key(); | - |
1615 | return None; | - |
1616 | } | - |
1617 | | - |
1618 | extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); | - |
1619 | | - |
1620 | | - |
1621 | | - |
1622 | | - |
1623 | QStyleOptionTitleBar QMdiSubWindowPrivate::titleBarOptions() const | - |
1624 | { | - |
1625 | Q_Q(const QMdiSubWindow); | - |
1626 | QStyleOptionTitleBar titleBarOptions; | - |
1627 | titleBarOptions.initFrom(q); | - |
1628 | if (activeSubControl != QStyle::SC_None) { | - |
1629 | if (hoveredSubControl == activeSubControl) { | - |
1630 | titleBarOptions.state |= QStyle::State_Sunken; | - |
1631 | titleBarOptions.activeSubControls = activeSubControl; | - |
1632 | } | - |
1633 | } else if (autoRaise() && hoveredSubControl != QStyle::SC_None | - |
1634 | && hoveredSubControl != QStyle::SC_TitleBarLabel) { | - |
1635 | titleBarOptions.state |= QStyle::State_MouseOver; | - |
1636 | titleBarOptions.activeSubControls = hoveredSubControl; | - |
1637 | } else { | - |
1638 | titleBarOptions.state &= ~QStyle::State_MouseOver; | - |
1639 | titleBarOptions.activeSubControls = QStyle::SC_None; | - |
1640 | } | - |
1641 | | - |
1642 | titleBarOptions.subControls = QStyle::SC_All; | - |
1643 | titleBarOptions.titleBarFlags = q->windowFlags(); | - |
1644 | titleBarOptions.titleBarState = q->windowState(); | - |
1645 | titleBarOptions.palette = titleBarPalette; | - |
1646 | titleBarOptions.icon = menuIcon; | - |
1647 | | - |
1648 | if (isActive) { | - |
1649 | titleBarOptions.state |= QStyle::State_Active; | - |
1650 | titleBarOptions.titleBarState |= QStyle::State_Active; | - |
1651 | titleBarOptions.palette.setCurrentColorGroup(QPalette::Active); | - |
1652 | } else { | - |
1653 | titleBarOptions.state &= ~QStyle::State_Active; | - |
1654 | titleBarOptions.palette.setCurrentColorGroup(QPalette::Inactive); | - |
1655 | } | - |
1656 | | - |
1657 | int border = hasBorder(titleBarOptions) ? 4 : 0; | - |
1658 | int paintHeight = titleBarHeight(titleBarOptions); | - |
1659 | paintHeight -= q->isMinimized() ? 2 * border : border; | - |
1660 | titleBarOptions.rect = QRect(border, border, q->width() - 2 * border, paintHeight); | - |
1661 | | - |
1662 | if (!windowTitle.isEmpty()) { | - |
1663 | | - |
1664 | | - |
1665 | titleBarOptions.text = windowTitle; | - |
1666 | titleBarOptions.fontMetrics = QFontMetrics(font); | - |
1667 | int width = q->style()->subControlRect(QStyle::CC_TitleBar, &titleBarOptions, | - |
1668 | QStyle::SC_TitleBarLabel, q).width(); | - |
1669 | | - |
1670 | titleBarOptions.text = titleBarOptions.fontMetrics.elidedText(windowTitle, Qt::ElideRight, width); | - |
1671 | } | - |
1672 | return titleBarOptions; | - |
1673 | } | - |
1674 | | - |
1675 | | - |
1676 | | - |
1677 | | - |
1678 | void QMdiSubWindowPrivate::ensureWindowState(Qt::WindowState state) | - |
1679 | { | - |
1680 | Q_Q(QMdiSubWindow); | - |
1681 | Qt::WindowStates windowStates = q->windowState() | state; | - |
1682 | switch (state) { | - |
1683 | case Qt::WindowMinimized: | - |
1684 | windowStates &= ~Qt::WindowMaximized; | - |
1685 | windowStates &= ~Qt::WindowFullScreen; | - |
1686 | windowStates &= ~Qt::WindowNoState; | - |
1687 | break; | - |
1688 | case Qt::WindowMaximized: | - |
1689 | windowStates &= ~Qt::WindowMinimized; | - |
1690 | windowStates &= ~Qt::WindowFullScreen; | - |
1691 | windowStates &= ~Qt::WindowNoState; | - |
1692 | break; | - |
1693 | case Qt::WindowNoState: | - |
1694 | windowStates &= ~Qt::WindowMinimized; | - |
1695 | windowStates &= ~Qt::WindowMaximized; | - |
1696 | windowStates &= ~Qt::WindowFullScreen; | - |
1697 | break; | - |
1698 | default: | - |
1699 | break; | - |
1700 | } | - |
1701 | if (baseWidget) { | - |
1702 | if (!(baseWidget->windowState() & Qt::WindowActive) && windowStates & Qt::WindowActive) | - |
1703 | baseWidget->overrideWindowState(windowStates & ~Qt::WindowActive); | - |
1704 | else | - |
1705 | baseWidget->overrideWindowState(windowStates); | - |
1706 | } | - |
1707 | q->overrideWindowState(windowStates); | - |
1708 | } | - |
1709 | | - |
1710 | | - |
1711 | | - |
1712 | | - |
1713 | int QMdiSubWindowPrivate::titleBarHeight(const QStyleOptionTitleBar &options) const | - |
1714 | { | - |
1715 | Q_Q(const QMdiSubWindow); | - |
1716 | if (!parent || q->windowFlags() & Qt::FramelessWindowHint | - |
1717 | || (q->isMaximized() && !drawTitleBarWhenMaximized())) { | - |
1718 | return 0; | - |
1719 | } | - |
1720 | | - |
1721 | int height = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options, q); | - |
1722 | if (hasBorder(options)) | - |
1723 | height += q->isMinimized() ? 8 : 4; | - |
1724 | return height; | - |
1725 | } | - |
1726 | | - |
1727 | | - |
1728 | | - |
1729 | | - |
1730 | void QMdiSubWindowPrivate::sizeParameters(int *margin, int *minWidth) const | - |
1731 | { | - |
1732 | Q_Q(const QMdiSubWindow); | - |
1733 | Qt::WindowFlags flags = q->windowFlags(); | - |
1734 | if (!parent || flags & Qt::FramelessWindowHint) { | - |
1735 | *margin = 0; | - |
1736 | *minWidth = 0; | - |
1737 | return; | - |
1738 | } | - |
1739 | | - |
1740 | if (q->isMaximized() && !drawTitleBarWhenMaximized()) | - |
1741 | *margin = 0; | - |
1742 | else | - |
1743 | *margin = q->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, q); | - |
1744 | | - |
1745 | QStyleOptionTitleBar opt = this->titleBarOptions(); | - |
1746 | int tempWidth = 0; | - |
1747 | for (int i = 0; i < NumSubControls; ++i) { | - |
1748 | if (SubControls[i] == QStyle::SC_TitleBarLabel) { | - |
1749 | tempWidth += 30; | - |
1750 | continue; | - |
1751 | } | - |
1752 | QRect rect = q->style()->subControlRect(QStyle::CC_TitleBar, &opt, SubControls[i], q); | - |
1753 | if (!rect.isValid()) | - |
1754 | continue; | - |
1755 | tempWidth += rect.width(); | - |
1756 | } | - |
1757 | *minWidth = tempWidth; | - |
1758 | } | - |
1759 | | - |
1760 | | - |
1761 | | - |
1762 | | - |
1763 | bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const | - |
1764 | { | - |
1765 | Q_Q(const QMdiSubWindow); | - |
1766 | if (q->window()->testAttribute(Qt::WA_CanHostQMdiSubWindowTitleBar)) | - |
1767 | return false; | - |
1768 | | - |
1769 | if (isChildOfTabbedQMdiArea(q)) | - |
1770 | return false; | - |
1771 | | - |
1772 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_OS_WINCE_WM) | - |
1773 | Q_UNUSED(isChildOfQMdiSubWindow); | - |
1774 | return true; | - |
1775 | #else | - |
1776 | if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) | - |
1777 | return true; | - |
1778 | #if defined(QT_NO_MENUBAR) || defined(QT_NO_MAINWINDOW) | - |
1779 | Q_UNUSED(isChildOfQMdiSubWindow); | - |
1780 | return true; | - |
1781 | #else | - |
1782 | QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window()); | - |
1783 | if (!mainWindow || !qobject_cast<QMenuBar *>(mainWindow->menuWidget()) | - |
1784 | || mainWindow->menuWidget()->isHidden()) | - |
1785 | return true; | - |
1786 | | - |
1787 | return isChildOfQMdiSubWindow(q); | - |
1788 | #endif | - |
1789 | #endif | - |
1790 | } | - |
1791 | | - |
1792 | #ifndef QT_NO_MENUBAR | - |
1793 | | - |
1794 | | - |
1795 | | - |
1796 | | - |
1797 | void QMdiSubWindowPrivate::showButtonsInMenuBar(QMenuBar *menuBar) | - |
1798 | { | - |
1799 | Q_Q(QMdiSubWindow); | - |
1800 | Q_ASSERT(q->isMaximized() && !drawTitleBarWhenMaximized()); | - |
1801 | | - |
1802 | if (isChildOfTabbedQMdiArea(q)) | - |
1803 | return; | - |
1804 | | - |
1805 | removeButtonsFromMenuBar(); | - |
1806 | if (!controlContainer) | - |
1807 | controlContainer = new ControlContainer(q); | - |
1808 | | - |
1809 | ignoreWindowTitleChange = true; | - |
1810 | controlContainer->showButtonsInMenuBar(menuBar); | - |
1811 | ignoreWindowTitleChange = false; | - |
1812 | | - |
1813 | QWidget *topLevelWindow = q->window(); | - |
1814 | topLevelWindow->setWindowModified(q->isWindowModified()); | - |
1815 | topLevelWindow->installEventFilter(q); | - |
1816 | | - |
1817 | int buttonHeight = 0; | - |
1818 | if (controlContainer->controllerWidget()) | - |
1819 | buttonHeight = controlContainer->controllerWidget()->height(); | - |
1820 | else if (controlContainer->systemMenuLabel()) | - |
1821 | buttonHeight = controlContainer->systemMenuLabel()->height(); | - |
1822 | | - |
1823 | | - |
1824 | if (menuBar && menuBar->height() < buttonHeight | - |
1825 | && topLevelWindow->layout()) { | - |
1826 | | - |
1827 | | - |
1828 | QEvent event(QEvent::LayoutRequest); | - |
1829 | QApplication::sendEvent(topLevelWindow, &event); | - |
1830 | } | - |
1831 | } | - |
1832 | | - |
1833 | | - |
1834 | | - |
1835 | | - |
1836 | void QMdiSubWindowPrivate::removeButtonsFromMenuBar() | - |
1837 | { | - |
1838 | Q_Q(QMdiSubWindow); | - |
1839 | | - |
1840 | if (!controlContainer || isChildOfTabbedQMdiArea(q)) | - |
1841 | return; | - |
1842 | | - |
1843 | QMenuBar *currentMenuBar = 0; | - |
1844 | #ifndef QT_NO_MAINWINDOW | - |
1845 | if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->window())) { | - |
1846 | | - |
1847 | | - |
1848 | currentMenuBar = qobject_cast<QMenuBar *>(mainWindow->menuWidget()); | - |
1849 | } | - |
1850 | #endif | - |
1851 | | - |
1852 | ignoreWindowTitleChange = true; | - |
1853 | controlContainer->removeButtonsFromMenuBar(currentMenuBar); | - |
1854 | ignoreWindowTitleChange = false; | - |
1855 | | - |
1856 | QWidget *topLevelWindow = q->window(); | - |
1857 | topLevelWindow->removeEventFilter(q); | - |
1858 | if (baseWidget && !drawTitleBarWhenMaximized()) | - |
1859 | topLevelWindow->setWindowModified(false); | - |
1860 | originalTitle = QString::null; | - |
1861 | } | - |
1862 | | - |
1863 | #endif // QT_NO_MENUBAR | - |
1864 | | - |
1865 | void QMdiSubWindowPrivate::updateWindowTitle(bool isRequestFromChild) | - |
1866 | { | - |
1867 | Q_Q(QMdiSubWindow); | - |
1868 | if (isRequestFromChild && !q->windowTitle().isEmpty() && !lastChildWindowTitle.isEmpty() | - |
1869 | && lastChildWindowTitle != q->windowTitle()) { | - |
1870 | return; | - |
1871 | } | - |
1872 | | - |
1873 | QWidget *titleWidget = 0; | - |
1874 | if (isRequestFromChild) | - |
1875 | titleWidget = baseWidget; | - |
1876 | else | - |
1877 | titleWidget = q; | - |
1878 | if (!titleWidget || titleWidget->windowTitle().isEmpty()) | - |
1879 | return; | - |
1880 | | - |
1881 | ignoreWindowTitleChange = true; | - |
1882 | q->setWindowTitle(titleWidget->windowTitle()); | - |
1883 | if (q->maximizedButtonsWidget()) | - |
1884 | setNewWindowTitle(); | - |
1885 | ignoreWindowTitleChange = false; | - |
1886 | } | - |
1887 | | - |
1888 | #ifndef QT_NO_RUBBERBAND | - |
1889 | void QMdiSubWindowPrivate::enterRubberBandMode() | - |
1890 | { | - |
1891 | Q_Q(QMdiSubWindow); | - |
1892 | if (q->isMaximized()) | - |
1893 | return; | - |
1894 | Q_ASSERT(oldGeometry.isValid()); | - |
1895 | Q_ASSERT(parent); | - |
1896 | if (!rubberBand) { | - |
1897 | rubberBand = new QRubberBand(QRubberBand::Rectangle, q->parentWidget()); | - |
1898 | | - |
1899 | rubberBand->setObjectName(QLatin1String("qt_rubberband")); | - |
1900 | } | - |
1901 | QPoint rubberBandPos = q->mapToParent(QPoint(0, 0)); | - |
1902 | rubberBand->setGeometry(rubberBandPos.x(), rubberBandPos.y(), | - |
1903 | oldGeometry.width(), oldGeometry.height()); | - |
1904 | rubberBand->show(); | - |
1905 | isInRubberBandMode = true; | - |
1906 | q->grabMouse(); | - |
1907 | } | - |
1908 | | - |
1909 | void QMdiSubWindowPrivate::leaveRubberBandMode() | - |
1910 | { | - |
1911 | Q_Q(QMdiSubWindow); | - |
1912 | Q_ASSERT(rubberBand); | - |
1913 | Q_ASSERT(isInRubberBandMode); | - |
1914 | q->releaseMouse(); | - |
1915 | isInRubberBandMode = false; | - |
1916 | q->setGeometry(rubberBand->geometry()); | - |
1917 | rubberBand->hide(); | - |
1918 | currentOperation = None; | - |
1919 | } | - |
1920 | #endif // QT_NO_RUBBERBAND | - |
1921 | | - |
1922 | | - |
1923 | QPalette QMdiSubWindowPrivate::desktopPalette() const | - |
1924 | { | - |
1925 | Q_Q(const QMdiSubWindow); | - |
1926 | QPalette newPalette = q->palette(); | - |
1927 | | - |
1928 | bool colorsInitialized = false; | - |
1929 | #ifdef Q_DEAD_CODE_FROM_QT4_WIN // ask system properties on windows | - |
1930 | #ifndef SPI_GETGRADIENTCAPTIONS | - |
1931 | #define SPI_GETGRADIENTCAPTIONS 0x1008 | - |
1932 | #endif | - |
1933 | #ifndef COLOR_GRADIENTACTIVECAPTION | - |
1934 | #define COLOR_GRADIENTACTIVECAPTION 27 | - |
1935 | #endif | - |
1936 | #ifndef COLOR_GRADIENTINACTIVECAPTION | - |
1937 | #define COLOR_GRADIENTINACTIVECAPTION 28 | - |
1938 | #endif | - |
1939 | if (QApplication::desktopSettingsAware()) { | - |
1940 | newPalette.setColor(QPalette::Active, QPalette::Highlight, | - |
1941 | colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION))); | - |
1942 | newPalette.setColor(QPalette::Inactive, QPalette::Highlight, | - |
1943 | colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION))); | - |
1944 | newPalette.setColor(QPalette::Active, QPalette::HighlightedText, | - |
1945 | colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT))); | - |
1946 | newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, | - |
1947 | colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT))); | - |
1948 | | - |
1949 | colorsInitialized = true; | - |
1950 | BOOL hasGradient = false; | - |
1951 | SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &hasGradient, 0); | - |
1952 | | - |
1953 | if (hasGradient) { | - |
1954 | newPalette.setColor(QPalette::Active, QPalette::Base, | - |
1955 | colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION))); | - |
1956 | newPalette.setColor(QPalette::Inactive, QPalette::Base, | - |
1957 | colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))); | - |
1958 | } else { | - |
1959 | newPalette.setColor(QPalette::Active, QPalette::Base, | - |
1960 | newPalette.color(QPalette::Active, QPalette::Highlight)); | - |
1961 | newPalette.setColor(QPalette::Inactive, QPalette::Base, | - |
1962 | newPalette.color(QPalette::Inactive, QPalette::Highlight)); | - |
1963 | } | - |
1964 | } | - |
1965 | #endif // Q_DEAD_CODE_FROM_QT4_WIN | - |
1966 | if (!colorsInitialized) { | - |
1967 | newPalette.setColor(QPalette::Active, QPalette::Highlight, | - |
1968 | newPalette.color(QPalette::Active, QPalette::Highlight)); | - |
1969 | newPalette.setColor(QPalette::Active, QPalette::Base, | - |
1970 | newPalette.color(QPalette::Active, QPalette::Highlight)); | - |
1971 | newPalette.setColor(QPalette::Inactive, QPalette::Highlight, | - |
1972 | newPalette.color(QPalette::Inactive, QPalette::Dark)); | - |
1973 | newPalette.setColor(QPalette::Inactive, QPalette::Base, | - |
1974 | newPalette.color(QPalette::Inactive, QPalette::Dark)); | - |
1975 | newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, | - |
1976 | newPalette.color(QPalette::Inactive, QPalette::Window)); | - |
1977 | } | - |
1978 | | - |
1979 | return newPalette; | - |
1980 | } | - |
1981 | | - |
1982 | void QMdiSubWindowPrivate::updateActions() | - |
1983 | { | - |
1984 | Qt::WindowFlags windowFlags = q_func()->windowFlags(); | - |
1985 | | - |
1986 | for (int i = 0; i < NumWindowStateActions; ++i) | - |
1987 | setVisible(WindowStateAction(i), false); | - |
1988 | | - |
1989 | if (windowFlags & Qt::FramelessWindowHint) | - |
1990 | return; | - |
1991 | | - |
1992 | setVisible(StayOnTopAction, true); | - |
1993 | setVisible(MoveAction, moveEnabled); | - |
1994 | setVisible(ResizeAction, resizeEnabled); | - |
1995 | | - |
1996 | | - |
1997 | if (windowFlags & Qt::WindowSystemMenuHint) | - |
1998 | setVisible(CloseAction, true); | - |
1999 | | - |
2000 | | - |
2001 | if (windowFlags & (Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint)) | - |
2002 | setVisible(RestoreAction, true); | - |
2003 | | - |
2004 | | - |
2005 | if (windowFlags & Qt::WindowMinimizeButtonHint) | - |
2006 | setVisible(MinimizeAction, true); | - |
2007 | | - |
2008 | | - |
2009 | if (windowFlags & Qt::WindowMaximizeButtonHint) | - |
2010 | setVisible(MaximizeAction, true); | - |
2011 | } | - |
2012 | | - |
2013 | void QMdiSubWindowPrivate::setFocusWidget() | - |
2014 | { | - |
2015 | Q_Q(QMdiSubWindow); | - |
2016 | if (!baseWidget) { | - |
2017 | q->setFocus(); | - |
2018 | return; | - |
2019 | } | - |
2020 | | - |
2021 | | - |
2022 | | - |
2023 | | - |
2024 | if (focusInReason == Qt::TabFocusReason) { | - |
2025 | q->focusNextChild(); | - |
2026 | return; | - |
2027 | } | - |
2028 | | - |
2029 | | - |
2030 | if (focusInReason == Qt::BacktabFocusReason) { | - |
2031 | q->focusPreviousChild(); | - |
2032 | return; | - |
2033 | } | - |
2034 | | - |
2035 | if (!(q->windowState() & Qt::WindowMinimized) && restoreFocus()) | - |
2036 | return; | - |
2037 | | - |
2038 | if (QWidget *focusWidget = baseWidget->focusWidget()) { | - |
2039 | if (!focusWidget->hasFocus() && q->isAncestorOf(focusWidget) | - |
2040 | && focusWidget->isVisible() && !q->isMinimized() | - |
2041 | && focusWidget->focusPolicy() != Qt::NoFocus) { | - |
2042 | focusWidget->setFocus(); | - |
2043 | } else { | - |
2044 | q->setFocus(); | - |
2045 | } | - |
2046 | return; | - |
2047 | } | - |
2048 | | - |
2049 | QWidget *focusWidget = q->nextInFocusChain(); | - |
2050 | while (focusWidget && focusWidget != q && focusWidget->focusPolicy() == Qt::NoFocus) | - |
2051 | focusWidget = focusWidget->nextInFocusChain(); | - |
2052 | if (focusWidget && q->isAncestorOf(focusWidget)) | - |
2053 | focusWidget->setFocus(); | - |
2054 | else if (baseWidget->focusPolicy() != Qt::NoFocus) | - |
2055 | baseWidget->setFocus(); | - |
2056 | else if (!q->hasFocus()) | - |
2057 | q->setFocus(); | - |
2058 | } | - |
2059 | | - |
2060 | bool QMdiSubWindowPrivate::restoreFocus() | - |
2061 | { | - |
2062 | if (restoreFocusWidget.isNull()) | - |
2063 | return false; | - |
2064 | QWidget *candidate = restoreFocusWidget; | - |
2065 | restoreFocusWidget.clear(); | - |
2066 | if (!candidate->hasFocus() && q_func()->isAncestorOf(candidate) | - |
2067 | && candidate->isVisible() | - |
2068 | && candidate->focusPolicy() != Qt::NoFocus) { | - |
2069 | candidate->setFocus(); | - |
2070 | return true; | - |
2071 | } | - |
2072 | return candidate->hasFocus(); | - |
2073 | } | - |
2074 | | - |
2075 | | - |
2076 | | - |
2077 | | - |
2078 | void QMdiSubWindowPrivate::setWindowFlags(Qt::WindowFlags windowFlags) | - |
2079 | { | - |
2080 | Q_Q(QMdiSubWindow); | - |
2081 | | - |
2082 | if (!parent) { | - |
2083 | QWidgetPrivate::setWindowFlags(windowFlags); | - |
2084 | return; | - |
2085 | } | - |
2086 | | - |
2087 | Qt::WindowFlags windowType = windowFlags & Qt::WindowType_Mask; | - |
2088 | if (windowType == Qt::Dialog || windowFlags & Qt::MSWindowsFixedSizeDialogHint) | - |
2089 | windowFlags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint; | - |
2090 | | - |
2091 | | - |
2092 | if (!(windowFlags & CustomizeWindowFlags)) | - |
2093 | windowFlags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint; | - |
2094 | else if (windowFlags & Qt::FramelessWindowHint && windowFlags & Qt::WindowStaysOnTopHint) | - |
2095 | windowFlags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint; | - |
2096 | else if (windowFlags & Qt::FramelessWindowHint) | - |
2097 | windowFlags = Qt::FramelessWindowHint; | - |
2098 | | - |
2099 | windowFlags &= ~windowType; | - |
2100 | windowFlags &= ~Qt::WindowFullscreenButtonHint; | - |
2101 | windowFlags |= Qt::SubWindow; | - |
2102 | | - |
2103 | #ifndef QT_NO_ACTION | - |
2104 | if (QAction *stayOnTopAction = actions[QMdiSubWindowPrivate::StayOnTopAction]) { | - |
2105 | if (windowFlags & Qt::WindowStaysOnTopHint) | - |
2106 | stayOnTopAction->setChecked(true); | - |
2107 | else | - |
2108 | stayOnTopAction->setChecked(false); | - |
2109 | } | - |
2110 | #endif | - |
2111 | | - |
2112 | #ifndef QT_NO_SIZEGRIP | - |
2113 | if ((windowFlags & Qt::FramelessWindowHint) && sizeGrip) | - |
2114 | delete sizeGrip; | - |
2115 | #endif | - |
2116 | | - |
2117 | QWidgetPrivate::setWindowFlags(windowFlags); | - |
2118 | updateGeometryConstraints(); | - |
2119 | updateActions(); | - |
2120 | QSize currentSize = q->size(); | - |
2121 | if (q->isVisible() && (currentSize.width() < internalMinimumSize.width() | - |
2122 | || currentSize.height() < internalMinimumSize.height())) { | - |
2123 | q->resize(currentSize.expandedTo(internalMinimumSize)); | - |
2124 | } | - |
2125 | } | - |
2126 | | - |
2127 | void QMdiSubWindowPrivate::setVisible(WindowStateAction action, bool visible) | - |
2128 | { | - |
2129 | #ifndef QT_NO_ACTION | - |
2130 | if (actions[action]) | - |
2131 | actions[action]->setVisible(visible); | - |
2132 | #endif | - |
2133 | | - |
2134 | Q_Q(QMdiSubWindow); | - |
2135 | if (!controlContainer) | - |
2136 | controlContainer = new ControlContainer(q); | - |
2137 | | - |
2138 | if (ControllerWidget *ctrlWidget = qobject_cast<ControllerWidget *> | - |
2139 | (controlContainer->controllerWidget())) { | - |
2140 | ctrlWidget->setControlVisible(action, visible); | - |
2141 | } | - |
2142 | } | - |
2143 | | - |
2144 | #ifndef QT_NO_ACTION | - |
2145 | void QMdiSubWindowPrivate::setEnabled(WindowStateAction action, bool enable) | - |
2146 | { | - |
2147 | if (actions[action]) | - |
2148 | actions[action]->setEnabled(enable); | - |
2149 | } | - |
2150 | | - |
2151 | #ifndef QT_NO_MENU | - |
2152 | void QMdiSubWindowPrivate::addToSystemMenu(WindowStateAction action, const QString &text, | - |
2153 | const char *slot) | - |
2154 | { | - |
2155 | if (!systemMenu) | - |
2156 | return; | - |
2157 | actions[action] = systemMenu->addAction(text, q_func(), slot); | - |
2158 | } | - |
2159 | #endif | - |
2160 | #endif // QT_NO_ACTION | - |
2161 | | - |
2162 | | - |
2163 | | - |
2164 | | - |
2165 | QSize QMdiSubWindowPrivate::iconSize() const | - |
2166 | { | - |
2167 | Q_Q(const QMdiSubWindow); | - |
2168 | if (!parent || q->windowFlags() & Qt::FramelessWindowHint) | - |
2169 | return QSize(-1, -1); | - |
2170 | return QSize(q->style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth, 0, q), titleBarHeight()); | - |
2171 | } | - |
2172 | | - |
2173 | #ifndef QT_NO_SIZEGRIP | - |
2174 | | - |
2175 | | - |
2176 | | - |
2177 | | - |
2178 | void QMdiSubWindowPrivate::setSizeGrip(QSizeGrip *newSizeGrip) | - |
2179 | { | - |
2180 | Q_Q(QMdiSubWindow); | - |
2181 | if (!newSizeGrip || sizeGrip || q->windowFlags() & Qt::FramelessWindowHint) | - |
2182 | return; | - |
2183 | | - |
2184 | if (layout && layout->indexOf(newSizeGrip) != -1) | - |
2185 | return; | - |
2186 | newSizeGrip->setFixedSize(newSizeGrip->sizeHint()); | - |
2187 | bool putSizeGripInLayout = layout ? true : false; | - |
2188 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
2189 | if (qobject_cast<QMacStyle *>(q->style())) | - |
2190 | putSizeGripInLayout = false; | - |
2191 | #endif | - |
2192 | if (putSizeGripInLayout) { | - |
2193 | layout->addWidget(newSizeGrip); | - |
2194 | layout->setAlignment(newSizeGrip, Qt::AlignBottom | Qt::AlignRight); | - |
2195 | } else { | - |
2196 | newSizeGrip->setParent(q); | - |
2197 | newSizeGrip->move(q->isLeftToRight() ? q->width() - newSizeGrip->width() : 0, | - |
2198 | q->height() - newSizeGrip->height()); | - |
2199 | sizeGrip = newSizeGrip; | - |
2200 | } | - |
2201 | newSizeGrip->raise(); | - |
2202 | updateGeometryConstraints(); | - |
2203 | newSizeGrip->installEventFilter(q); | - |
2204 | } | - |
2205 | | - |
2206 | | - |
2207 | | - |
2208 | | - |
2209 | void QMdiSubWindowPrivate::setSizeGripVisible(bool visible) const | - |
2210 | { | - |
2211 | | - |
2212 | const QList<QSizeGrip *> sizeGrips = q_func()->findChildren<QSizeGrip *>(); | - |
2213 | foreachfor (QSizeGrip *grip ,: sizeGrips) | - |
2214 | grip->setVisible(visible); never executed: grip->setVisible(visible); | 0 |
2215 | } never executed: end of block | 0 |
2216 | | - |
2217 | #endif // QT_NO_SIZEGRIP | - |
2218 | | - |
2219 | | - |
2220 | | - |
2221 | | - |
2222 | void QMdiSubWindowPrivate::updateInternalWindowTitle() | - |
2223 | { | - |
2224 | Q_Q(QMdiSubWindow); | - |
2225 | if (q->isWindowModified()) { | - |
2226 | windowTitle = q->windowTitle(); | - |
2227 | windowTitle.replace(QLatin1String("[*]"), QLatin1String("*")); | - |
2228 | } else { | - |
2229 | windowTitle = qt_setWindowTitle_helperHelper(q->windowTitle(), q); | - |
2230 | } | - |
2231 | q->update(0, 0, q->width(), titleBarHeight()); | - |
2232 | } | - |
2233 | | - |
2234 | | - |
2235 | | - |
2236 | | - |
2237 | | - |
2238 | | - |
2239 | | - |
2240 | | - |
2241 | | - |
2242 | | - |
2243 | | - |
2244 | | - |
2245 | | - |
2246 | | - |
2247 | | - |
2248 | | - |
2249 | | - |
2250 | | - |
2251 | | - |
2252 | QMdiSubWindow::QMdiSubWindow(QWidget *parent, Qt::WindowFlags flags) | - |
2253 | : QWidget(*new QMdiSubWindowPrivate, parent, 0) | - |
2254 | { | - |
2255 | Q_D(QMdiSubWindow); | - |
2256 | #ifndef QT_NO_MENU | - |
2257 | d->createSystemMenu(); | - |
2258 | addActions(d->systemMenu->actions()); | - |
2259 | #endif | - |
2260 | d->setWindowFlags(flags); | - |
2261 | setBackgroundRole(QPalette::Window); | - |
2262 | setAutoFillBackground(true); | - |
2263 | setMouseTracking(true); | - |
2264 | setLayout(new QVBoxLayout); | - |
2265 | setFocusPolicy(Qt::StrongFocus); | - |
2266 | layout()->setMargin(0); | - |
2267 | d->updateGeometryConstraints(); | - |
2268 | setAttribute(Qt::WA_Resized, false); | - |
2269 | d->titleBarPalette = d->desktopPalette(); | - |
2270 | d->font = QApplication::font("QMdiSubWindowTitleBar"); | - |
2271 | | - |
2272 | #ifndef Q_OS_MAC | - |
2273 | if (windowIcon().isNull()) | - |
2274 | d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, this); | - |
2275 | else | - |
2276 | d->menuIcon = windowIcon(); | - |
2277 | #endif | - |
2278 | connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), | - |
2279 | this, SLOT(_q_processFocusChanged(QWidget*,QWidget*))); | - |
2280 | } | - |
2281 | | - |
2282 | | - |
2283 | | - |
2284 | | - |
2285 | | - |
2286 | | - |
2287 | QMdiSubWindow::~QMdiSubWindow() | - |
2288 | { | - |
2289 | Q_D(QMdiSubWindow); | - |
2290 | #ifndef QT_NO_MENUBAR | - |
2291 | d->removeButtonsFromMenuBar(); | - |
2292 | #endif | - |
2293 | d->setActive(false); | - |
2294 | } | - |
2295 | | - |
2296 | | - |
2297 | | - |
2298 | | - |
2299 | | - |
2300 | | - |
2301 | | - |
2302 | | - |
2303 | | - |
2304 | | - |
2305 | | - |
2306 | | - |
2307 | void QMdiSubWindow::setWidget(QWidget *widget) | - |
2308 | { | - |
2309 | Q_D(QMdiSubWindow); | - |
2310 | if (!widget) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2311 | d->removeBaseWidget(); | - |
2312 | return; never executed: return; | 0 |
2313 | } | - |
2314 | | - |
2315 | if (Q_UNLIKELY(widget == d->baseWidget))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2316 | qWarning("QMdiSubWindow::setWidget: widget is already set"); | - |
2317 | return; never executed: return; | 0 |
2318 | } | - |
2319 | | - |
2320 | bool wasResized = testAttribute(Qt::WA_Resized); | - |
2321 | d->removeBaseWidget(); | - |
2322 | | - |
2323 | if (QLayout *layout = this->layout())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2324 | layout->addWidget(widget); never executed: layout->addWidget(widget); | 0 |
2325 | else | - |
2326 | widget->setParent(this); never executed: widget->setParent(this); | 0 |
2327 | | - |
2328 | #ifndef QT_NO_SIZEGRIP | - |
2329 | QSizeGrip *sizeGrip = widget->findChild<QSizeGrip *>(); | - |
2330 | if (sizeGrip)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2331 | sizeGrip->installEventFilter(this); never executed: sizeGrip->installEventFilter(this); | 0 |
2332 | if (d->sizeGrip)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2333 | d->sizeGrip->raise(); never executed: d->sizeGrip->raise(); | 0 |
2334 | #endif | - |
2335 | | - |
2336 | d->baseWidget = widget; | - |
2337 | d->baseWidget->installEventFilter(this); | - |
2338 | | - |
2339 | d->ignoreWindowTitleChange = true; | - |
2340 | bool isWindowModified = this->isWindowModified(); | - |
2341 | if (windowTitle().isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2342 | d->updateWindowTitle(true); | - |
2343 | isWindowModified = d->baseWidget->isWindowModified(); | - |
2344 | } never executed: end of block | 0 |
2345 | if (!this->isWindowModified() && isWindowModifiedTRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2346 | && windowTitle().contains(QLatin1String("[*]"))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2347 | setWindowModified(isWindowModified); | - |
2348 | } never executed: end of block | 0 |
2349 | d->lastChildWindowTitle = d->baseWidget->windowTitle(); | - |
2350 | d->ignoreWindowTitleChange = false; | - |
2351 | | - |
2352 | if (windowIcon().isNull() && !d->baseWidget->windowIcon().isNull())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2353 | setWindowIcon(d->baseWidget->windowIcon()); never executed: setWindowIcon(d->baseWidget->windowIcon()); | 0 |
2354 | | - |
2355 | d->updateGeometryConstraints(); | - |
2356 | if (!wasResized && testAttribute(Qt::WA_Resized))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2357 | setAttribute(Qt::WA_Resized, false); never executed: setAttribute(Qt::WA_Resized, false); | 0 |
2358 | } never executed: end of block | 0 |
2359 | | - |
2360 | | - |
2361 | | - |
2362 | | - |
2363 | | - |
2364 | | - |
2365 | QWidget *QMdiSubWindow::widget() const | - |
2366 | { | - |
2367 | return d_func()->baseWidget; | - |
2368 | } | - |
2369 | | - |
2370 | | - |
2371 | | - |
2372 | | - |
2373 | | - |
2374 | QWidget *QMdiSubWindow::maximizedButtonsWidget() const | - |
2375 | { | - |
2376 | Q_D(const QMdiSubWindow); | - |
2377 | if (isVisible() && d->controlContainer && isMaximized() && !d->drawTitleBarWhenMaximized() | - |
2378 | && !isChildOfTabbedQMdiArea(this)) { | - |
2379 | return d->controlContainer->controllerWidget(); | - |
2380 | } | - |
2381 | return 0; | - |
2382 | } | - |
2383 | | - |
2384 | | - |
2385 | | - |
2386 | | - |
2387 | QWidget *QMdiSubWindow::maximizedSystemMenuIconWidget() const | - |
2388 | { | - |
2389 | Q_D(const QMdiSubWindow); | - |
2390 | if (isVisible() && d->controlContainer && isMaximized() && !d->drawTitleBarWhenMaximized() | - |
2391 | && !isChildOfTabbedQMdiArea(this)) { | - |
2392 | return d->controlContainer->systemMenuLabel(); | - |
2393 | } | - |
2394 | return 0; | - |
2395 | } | - |
2396 | | - |
2397 | | - |
2398 | | - |
2399 | | - |
2400 | | - |
2401 | | - |
2402 | | - |
2403 | bool QMdiSubWindow::isShaded() const | - |
2404 | { | - |
2405 | return d_func()->isShadeMode; | - |
2406 | } | - |
2407 | | - |
2408 | | - |
2409 | | - |
2410 | | - |
2411 | | - |
2412 | | - |
2413 | | - |
2414 | void QMdiSubWindow::setOption(SubWindowOption option, bool on) | - |
2415 | { | - |
2416 | Q_D(QMdiSubWindow); | - |
2417 | if (on && !(d->options & option))d->options|= option; | - |
| else if (!on &&.setFlag(d->options & option)) | |
| d->options &= ~option;, on); | |
2418 | | - |
2419 | #ifndef QT_NO_RUBBERBAND | - |
2420 | if ((option & (RubberBandResize | RubberBandMove)) && !on && d->isInRubberBandMode)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2421 | d->leaveRubberBandMode(); never executed: d->leaveRubberBandMode(); | 0 |
2422 | #endif | - |
2423 | } never executed: end of block | 0 |
2424 | | - |
2425 | | - |
2426 | | - |
2427 | | - |
2428 | | - |
2429 | | - |
2430 | bool QMdiSubWindow::testOption(SubWindowOption option) const | - |
2431 | { | - |
2432 | return d_func()->options & option; | - |
2433 | } | - |
2434 | | - |
2435 | | - |
2436 | | - |
2437 | | - |
2438 | | - |
2439 | | - |
2440 | | - |
2441 | | - |
2442 | | - |
2443 | | - |
2444 | | - |
2445 | | - |
2446 | | - |
2447 | | - |
2448 | | - |
2449 | int QMdiSubWindow::keyboardSingleStep() const | - |
2450 | { | - |
2451 | return d_func()->keyboardSingleStep; | - |
2452 | } | - |
2453 | | - |
2454 | void QMdiSubWindow::setKeyboardSingleStep(int step) | - |
2455 | { | - |
2456 | | - |
2457 | | - |
2458 | | - |
2459 | d_func()->keyboardSingleStep = step; | - |
2460 | } | - |
2461 | | - |
2462 | | - |
2463 | | - |
2464 | | - |
2465 | | - |
2466 | | - |
2467 | | - |
2468 | | - |
2469 | | - |
2470 | | - |
2471 | | - |
2472 | | - |
2473 | | - |
2474 | | - |
2475 | | - |
2476 | int QMdiSubWindow::keyboardPageStep() const | - |
2477 | { | - |
2478 | return d_func()->keyboardPageStep; | - |
2479 | } | - |
2480 | | - |
2481 | void QMdiSubWindow::setKeyboardPageStep(int step) | - |
2482 | { | - |
2483 | | - |
2484 | | - |
2485 | | - |
2486 | d_func()->keyboardPageStep = step; | - |
2487 | } | - |
2488 | | - |
2489 | #ifndef QT_NO_MENU | - |
2490 | | - |
2491 | | - |
2492 | | - |
2493 | | - |
2494 | | - |
2495 | | - |
2496 | | - |
2497 | | - |
2498 | | - |
2499 | | - |
2500 | | - |
2501 | | - |
2502 | | - |
2503 | | - |
2504 | | - |
2505 | | - |
2506 | | - |
2507 | void QMdiSubWindow::setSystemMenu(QMenu *systemMenu) | - |
2508 | { | - |
2509 | Q_D(QMdiSubWindow); | - |
2510 | if (Q_UNLIKELY(systemMenu && systemMenu == d->systemMenu))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2511 | qWarning("QMdiSubWindow::setSystemMenu: system menu is already set"); | - |
2512 | return; never executed: return; | 0 |
2513 | } | - |
2514 | | - |
2515 | if (d->systemMenu) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2516 | delete d->systemMenu; | - |
2517 | d->systemMenu = 0; | - |
2518 | } never executed: end of block | 0 |
2519 | | - |
2520 | if (!systemMenu)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2521 | return; never executed: return; | 0 |
2522 | | - |
2523 | if (systemMenu->parent() != this)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2524 | systemMenu->setParent(this); never executed: systemMenu->setParent(this); | 0 |
2525 | d->systemMenu = systemMenu; | - |
2526 | } never executed: end of block | 0 |
2527 | | - |
2528 | | - |
2529 | | - |
2530 | | - |
2531 | | - |
2532 | | - |
2533 | | - |
2534 | | - |
2535 | QMenu *QMdiSubWindow::systemMenu() const | - |
2536 | { | - |
2537 | return d_func()->systemMenu; | - |
2538 | } | - |
2539 | | - |
2540 | | - |
2541 | | - |
2542 | | - |
2543 | | - |
2544 | | - |
2545 | void QMdiSubWindow::showSystemMenu() | - |
2546 | { | - |
2547 | Q_D(QMdiSubWindow); | - |
2548 | if (!d->systemMenu) | - |
2549 | return; | - |
2550 | | - |
2551 | QPoint globalPopupPos; | - |
2552 | if (QWidget *icon = maximizedSystemMenuIconWidget()) { | - |
2553 | if (isLeftToRight()) | - |
2554 | globalPopupPos = icon->mapToGlobal(QPoint(0, icon->y() + icon->height())); | - |
2555 | else | - |
2556 | globalPopupPos = icon->mapToGlobal(QPoint(icon->width(), icon->y() + icon->height())); | - |
2557 | } else { | - |
2558 | if (isLeftToRight()) | - |
2559 | globalPopupPos = mapToGlobal(contentsRect().topLeft()); | - |
2560 | else | - |
2561 | globalPopupPos = mapToGlobal(contentsRect().topRight()) + QPoint(1, 0); | - |
2562 | } | - |
2563 | | - |
2564 | | - |
2565 | if (isRightToLeft()) | - |
2566 | globalPopupPos -= QPoint(d->systemMenu->sizeHint().width(), 0); | - |
2567 | d->systemMenu->popup(globalPopupPos); | - |
2568 | } | - |
2569 | #endif // QT_NO_MENU | - |
2570 | | - |
2571 | | - |
2572 | | - |
2573 | | - |
2574 | | - |
2575 | | - |
2576 | | - |
2577 | | - |
2578 | QMdiArea *QMdiSubWindow::mdiArea() const | - |
2579 | { | - |
2580 | QWidget *parent = parentWidget(); | - |
2581 | while (parent) { | - |
2582 | if (QMdiArea *area = qobject_cast<QMdiArea *>(parent)) { | - |
2583 | if (area->viewport() == parentWidget()) | - |
2584 | return area; | - |
2585 | } | - |
2586 | parent = parent->parentWidget(); | - |
2587 | } | - |
2588 | return 0; | - |
2589 | } | - |
2590 | | - |
2591 | | - |
2592 | | - |
2593 | | - |
2594 | | - |
2595 | | - |
2596 | | - |
2597 | | - |
2598 | | - |
2599 | | - |
2600 | | - |
2601 | | - |
2602 | | - |
2603 | | - |
2604 | void QMdiSubWindow::showShaded() | - |
2605 | { | - |
2606 | if (!parent())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2607 | return; never executed: return; | 0 |
2608 | | - |
2609 | Q_D(QMdiSubWindow); | - |
2610 | | - |
2611 | if (!d->isShadeRequestFromMinimizeMode && isShaded())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2612 | return; never executed: return; | 0 |
2613 | | - |
2614 | d->isMaximizeMode = false; | - |
2615 | | - |
2616 | d->storeFocusWidget(); | - |
2617 | | - |
2618 | if (!d->isShadeRequestFromMinimizeMode) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2619 | d->isShadeMode = true; | - |
2620 | d->ensureWindowState(Qt::WindowMinimized); | - |
2621 | } never executed: end of block | 0 |
2622 | | - |
2623 | #ifndef QT_NO_MENUBAR | - |
2624 | d->removeButtonsFromMenuBar(); | - |
2625 | #endif | - |
2626 | | - |
2627 | | - |
2628 | | - |
2629 | | - |
2630 | if (hasFocus() || isAncestorOf(QApplication::focusWidget()))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2631 | d->ensureWindowState(Qt::WindowActive); never executed: d->ensureWindowState(Qt::WindowActive); | 0 |
2632 | | - |
2633 | #ifndef QT_NO_SIZEGRIP | - |
2634 | d->setSizeGripVisible(false); | - |
2635 | #endif | - |
2636 | | - |
2637 | if (!d->restoreSize.isValid() || d->isShadeMode) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2638 | d->oldGeometry = geometry(); | - |
2639 | d->restoreSize.setWidth(d->oldGeometry.width()); | - |
2640 | d->restoreSize.setHeight(d->oldGeometry.height()); | - |
2641 | } never executed: end of block | 0 |
2642 | | - |
2643 | | - |
2644 | | - |
2645 | const bool wasVisible = isVisible(); | - |
2646 | if (wasVisible)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2647 | setVisible(false); never executed: setVisible(false); | 0 |
2648 | | - |
2649 | d->updateGeometryConstraints(); | - |
2650 | | - |
2651 | if (!minimumSize().isNull()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2652 | d->userMinimumSize = minimumSize(); | - |
2653 | setMinimumSize(d->internalMinimumSize); | - |
2654 | } never executed: end of block | 0 |
2655 | resize(d->internalMinimumSize); | - |
2656 | | - |
2657 | | - |
2658 | if (d->baseWidget && !d->baseWidget->isHidden())() && !(windowFlags() & Qt::FramelessWindowHint)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2659 | d->baseWidget->hide(); | - |
2660 | d->isWidgetHiddenByUs = true; | - |
2661 | } never executed: end of block | 0 |
2662 | | - |
2663 | if (wasVisible)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2664 | setVisible(true); never executed: setVisible(true); | 0 |
2665 | | - |
2666 | d->setFocusWidget(); | - |
2667 | d->resizeEnabled = false; | - |
2668 | d->moveEnabled = true; | - |
2669 | d->updateDirtyRegions(); | - |
2670 | d->updateMask(); | - |
2671 | | - |
2672 | #ifndef QT_NO_ACTION | - |
2673 | d->setEnabled(QMdiSubWindowPrivate::MinimizeAction, false); | - |
2674 | d->setEnabled(QMdiSubWindowPrivate::ResizeAction, d->resizeEnabled); | - |
2675 | d->setEnabled(QMdiSubWindowPrivate::MaximizeAction, true); | - |
2676 | d->setEnabled(QMdiSubWindowPrivate::RestoreAction, true); | - |
2677 | d->setEnabled(QMdiSubWindowPrivate::MoveAction, d->moveEnabled); | - |
2678 | #endif | - |
2679 | } never executed: end of block | 0 |
2680 | | - |
2681 | | - |
2682 | | - |
2683 | | - |
2684 | bool QMdiSubWindow::eventFilter(QObject *object, QEvent *event) | - |
2685 | { | - |
2686 | Q_D(QMdiSubWindow); | - |
2687 | if (!object) | - |
2688 | return QWidget::eventFilter(object, event); | - |
2689 | | - |
2690 | #ifndef QT_NO_MENU | - |
2691 | | - |
2692 | if (d->systemMenu && d->systemMenu == object) { | - |
2693 | if (event->type() == QEvent::MouseButtonDblClick) { | - |
2694 | const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event); | - |
2695 | const QAction *action = d->systemMenu->actionAt(mouseEvent->pos()); | - |
2696 | if (!action || action->isEnabled()) | - |
2697 | close(); | - |
2698 | } else if (event->type() == QEvent::MouseMove) { | - |
2699 | QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); | - |
2700 | d->hoveredSubControl = d->getSubControl(mapFromGlobal(mouseEvent->globalPos())); | - |
2701 | } else if (event->type() == QEvent::Hide) { | - |
2702 | d->activeSubControl = QStyle::SC_None; | - |
2703 | update(QRegion(0, 0, width(), d->titleBarHeight())); | - |
2704 | } | - |
2705 | return QWidget::eventFilter(object, event); | - |
2706 | } | - |
2707 | #endif | - |
2708 | | - |
2709 | #ifndef QT_NO_SIZEGRIP | - |
2710 | if (object != d->baseWidget && parent() && qobject_cast<QSizeGrip *>(object)) { | - |
2711 | if (event->type() != QEvent::MouseButtonPress || !testOption(QMdiSubWindow::RubberBandResize)) | - |
2712 | return QWidget::eventFilter(object, event); | - |
2713 | const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); | - |
2714 | d->mousePressPosition = parentWidget()->mapFromGlobal(mouseEvent->globalPos()); | - |
2715 | d->oldGeometry = geometry(); | - |
2716 | d->currentOperation = isLeftToRight() ? QMdiSubWindowPrivate::BottomRightResize | - |
2717 | : QMdiSubWindowPrivate::BottomLeftResize; | - |
2718 | #ifndef QT_NO_RUBBERBAND | - |
2719 | d->enterRubberBandMode(); | - |
2720 | #endif | - |
2721 | return true; | - |
2722 | } | - |
2723 | #endif | - |
2724 | | - |
2725 | if (object != d->baseWidget && event->type() != QEvent::WindowTitleChange) | - |
2726 | return QWidget::eventFilter(object, event); | - |
2727 | | - |
2728 | switch (event->type()) { | - |
2729 | case QEvent::Show: | - |
2730 | d->setActive(true); | - |
2731 | break; | - |
2732 | case QEvent::ShowToParent: | - |
2733 | if (!d->isWidgetHiddenByUs) | - |
2734 | show(); | - |
2735 | break; | - |
2736 | case QEvent::WindowStateChange: { | - |
2737 | QWindowStateChangeEvent *changeEvent = static_cast<QWindowStateChangeEvent*>(event); | - |
2738 | if (changeEvent->isOverride()) | - |
2739 | break; | - |
2740 | Qt::WindowStates oldState = changeEvent->oldState(); | - |
2741 | Qt::WindowStates newState = d->baseWidget->windowState(); | - |
2742 | if (!(oldState & Qt::WindowMinimized) && (newState & Qt::WindowMinimized)) | - |
2743 | showMinimized(); | - |
2744 | else if (!(oldState & Qt::WindowMaximized) && (newState & Qt::WindowMaximized)) | - |
2745 | showMaximized(); | - |
2746 | else if (!(newState & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen))) | - |
2747 | showNormal(); | - |
2748 | break; | - |
2749 | } | - |
2750 | case QEvent::Enter: | - |
2751 | d->currentOperation = QMdiSubWindowPrivate::None; | - |
2752 | d->updateCursor(); | - |
2753 | break; | - |
2754 | case QEvent::LayoutRequest: | - |
2755 | d->updateGeometryConstraints(); | - |
2756 | break; | - |
2757 | case QEvent::WindowTitleChange: | - |
2758 | if (d->ignoreWindowTitleChange) | - |
2759 | break; | - |
2760 | if (object == d->baseWidget) { | - |
2761 | d->updateWindowTitle(true); | - |
2762 | d->lastChildWindowTitle = d->baseWidget->windowTitle(); | - |
2763 | #ifndef QT_NO_MENUBAR | - |
2764 | } else if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar() | - |
2765 | ->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) { | - |
2766 | d->originalTitle = QString::null; | - |
2767 | if (d->baseWidget && d->baseWidget->windowTitle() == windowTitle()) | - |
2768 | d->updateWindowTitle(true); | - |
2769 | else | - |
2770 | d->updateWindowTitle(false); | - |
2771 | #endif | - |
2772 | } | - |
2773 | break; | - |
2774 | case QEvent::ModifiedChange: { | - |
2775 | if (object != d->baseWidget) | - |
2776 | break; | - |
2777 | bool windowModified = d->baseWidget->isWindowModified(); | - |
2778 | if (!windowModified && d->baseWidget->windowTitle() != windowTitle()) | - |
2779 | break; | - |
2780 | if (windowTitle().contains(QLatin1String("[*]"))) | - |
2781 | setWindowModified(windowModified); | - |
2782 | break; | - |
2783 | } | - |
2784 | default: | - |
2785 | break; | - |
2786 | } | - |
2787 | return QWidget::eventFilter(object, event); | - |
2788 | } | - |
2789 | | - |
2790 | | - |
2791 | | - |
2792 | | - |
2793 | bool QMdiSubWindow::event(QEvent *event) | - |
2794 | { | - |
2795 | Q_D(QMdiSubWindow); | - |
2796 | switch (event->type()) { | - |
2797 | case QEvent::StyleChange: { | - |
2798 | bool wasShaded = isShaded(); | - |
2799 | bool wasMinimized = isMinimized(); | - |
2800 | bool wasMaximized = isMaximized(); | - |
2801 | | - |
2802 | const QScopedValueRollback<bool> activationEnabledSaver(d->activationEnabled); | - |
2803 | d->activationEnabled = false; | - |
2804 | | - |
2805 | ensurePolished(); | - |
2806 | setContentsMargins(0, 0, 0, 0); | - |
2807 | if (wasMinimized || wasMaximized || wasShaded) | - |
2808 | showNormal(); | - |
2809 | d->updateGeometryConstraints(); | - |
2810 | resize(d->internalMinimumSize.expandedTo(size())); | - |
2811 | d->updateMask(); | - |
2812 | d->updateDirtyRegions(); | - |
2813 | if (wasShaded) | - |
2814 | showShaded(); | - |
2815 | else if (wasMinimized) | - |
2816 | showMinimized(); | - |
2817 | else if (wasMaximized) | - |
2818 | showMaximized(); | - |
2819 | break; | - |
2820 | } | - |
2821 | case QEvent::ParentAboutToChange: | - |
2822 | d->setActive(false); | - |
2823 | break; | - |
2824 | case QEvent::ParentChange: { | - |
2825 | bool wasResized = testAttribute(Qt::WA_Resized); | - |
2826 | #ifndef QT_NO_MENUBAR | - |
2827 | d->removeButtonsFromMenuBar(); | - |
2828 | #endif | - |
2829 | d->currentOperation = QMdiSubWindowPrivate::None; | - |
2830 | d->activeSubControl = QStyle::SC_None; | - |
2831 | d->hoveredSubControl = QStyle::SC_None; | - |
2832 | #ifndef QT_NO_RUBBERBAND | - |
2833 | if (d->isInRubberBandMode) | - |
2834 | d->leaveRubberBandMode(); | - |
2835 | #endif | - |
2836 | d->isShadeMode = false; | - |
2837 | d->isMaximizeMode = false; | - |
2838 | d->isWidgetHiddenByUs = false; | - |
2839 | if (!parent()) { | - |
2840 | #if !defined(QT_NO_SIZEGRIP) && defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
2841 | if (qobject_cast<QMacStyle *>(style())) | - |
2842 | delete d->sizeGrip; | - |
2843 | #endif | - |
2844 | setOption(RubberBandResize, false); | - |
2845 | setOption(RubberBandMove, false); | - |
2846 | } else { | - |
2847 | d->setWindowFlags(windowFlags()); | - |
2848 | } | - |
2849 | setContentsMargins(0, 0, 0, 0); | - |
2850 | d->updateGeometryConstraints(); | - |
2851 | d->updateCursor(); | - |
2852 | d->updateMask(); | - |
2853 | d->updateDirtyRegions(); | - |
2854 | d->updateActions(); | - |
2855 | if (!wasResized && testAttribute(Qt::WA_Resized)) | - |
2856 | setAttribute(Qt::WA_Resized, false); | - |
2857 | break; | - |
2858 | } | - |
2859 | case QEvent::WindowActivate: | - |
2860 | if (d->ignoreNextActivationEvent) { | - |
2861 | d->ignoreNextActivationEvent = false; | - |
2862 | break; | - |
2863 | } | - |
2864 | d->isExplicitlyDeactivated = false; | - |
2865 | d->setActive(true); | - |
2866 | break; | - |
2867 | case QEvent::WindowDeactivate: | - |
2868 | if (d->ignoreNextActivationEvent) { | - |
2869 | d->ignoreNextActivationEvent = false; | - |
2870 | break; | - |
2871 | } | - |
2872 | d->isExplicitlyDeactivated = true; | - |
2873 | d->setActive(false); | - |
2874 | break; | - |
2875 | case QEvent::WindowTitleChange: | - |
2876 | if (!d->ignoreWindowTitleChange) | - |
2877 | d->updateWindowTitle(false); | - |
2878 | d->updateInternalWindowTitle(); | - |
2879 | break; | - |
2880 | case QEvent::ModifiedChange: | - |
2881 | if (!windowTitle().contains(QLatin1String("[*]"))) | - |
2882 | break; | - |
2883 | #ifndef QT_NO_MENUBAR | - |
2884 | if (maximizedButtonsWidget() && d->controlContainer->menuBar() && d->controlContainer->menuBar() | - |
2885 | ->cornerWidget(Qt::TopRightCorner) == maximizedButtonsWidget()) { | - |
2886 | window()->setWindowModified(isWindowModified()); | - |
2887 | } | - |
2888 | #endif // QT_NO_MENUBAR | - |
2889 | d->updateInternalWindowTitle(); | - |
2890 | break; | - |
2891 | case QEvent::LayoutDirectionChange: | - |
2892 | d->updateDirtyRegions(); | - |
2893 | break; | - |
2894 | case QEvent::LayoutRequest: | - |
2895 | d->updateGeometryConstraints(); | - |
2896 | break; | - |
2897 | case QEvent::WindowIconChange: | - |
2898 | d->menuIcon = windowIcon(); | - |
2899 | if (d->menuIcon.isNull()) | - |
2900 | d->menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, 0, this); | - |
2901 | if (d->controlContainer) | - |
2902 | d->controlContainer->updateWindowIcon(d->menuIcon); | - |
2903 | if (!maximizedSystemMenuIconWidget()) | - |
2904 | update(0, 0, width(), d->titleBarHeight()); | - |
2905 | break; | - |
2906 | case QEvent::PaletteChange: | - |
2907 | d->titleBarPalette = d->desktopPalette(); | - |
2908 | break; | - |
2909 | case QEvent::FontChange: | - |
2910 | d->font = font(); | - |
2911 | break; | - |
2912 | #ifndef QT_NO_TOOLTIP | - |
2913 | case QEvent::ToolTip: | - |
2914 | showToolTip(static_cast<QHelpEvent *>(event), this, d->titleBarOptions(), | - |
2915 | QStyle::CC_TitleBar, d->hoveredSubControl); | - |
2916 | break; | - |
2917 | #endif | - |
2918 | default: | - |
2919 | break; | - |
2920 | } | - |
2921 | return QWidget::event(event); | - |
2922 | } | - |
2923 | | - |
2924 | | - |
2925 | | - |
2926 | | - |
2927 | void QMdiSubWindow::showEvent(QShowEvent *showEvent) | - |
2928 | { | - |
2929 | Q_D(QMdiSubWindow); | - |
2930 | if (!parent()) { | - |
2931 | QWidget::showEvent(showEvent); | - |
2932 | return; | - |
2933 | } | - |
2934 | | - |
2935 | #if !defined(QT_NO_SIZEGRIP) && defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
2936 | if (qobject_cast<QMacStyle *>(style()) && !d->sizeGrip | - |
2937 | && !(windowFlags() & Qt::FramelessWindowHint)) { | - |
2938 | d->setSizeGrip(new QSizeGrip(this)); | - |
2939 | Q_ASSERT(d->sizeGrip); | - |
2940 | if (isMinimized()) | - |
2941 | d->setSizeGripVisible(false); | - |
2942 | else | - |
2943 | d->setSizeGripVisible(true); | - |
2944 | resize(size().expandedTo(d->internalMinimumSize)); | - |
2945 | } | - |
2946 | #endif | - |
2947 | | - |
2948 | d->updateDirtyRegions(); | - |
2949 | | - |
2950 | | - |
2951 | #ifndef QT_NO_MENUBAR | - |
2952 | if (d->controlContainer) { | - |
2953 | if (QMenuBar *menuBar = d->menuBar()) { | - |
2954 | if (menuBar->cornerWidget(Qt::TopRightCorner) != maximizedButtonsWidget()) | - |
2955 | d->showButtonsInMenuBar(menuBar); | - |
2956 | } | - |
2957 | } | - |
2958 | #endif | - |
2959 | d->setActive(true); | - |
2960 | } | - |
2961 | | - |
2962 | | - |
2963 | | - |
2964 | | - |
2965 | void QMdiSubWindow::hideEvent(QHideEvent * ) | - |
2966 | { | - |
2967 | #ifndef QT_NO_MENUBAR | - |
2968 | d_func()->removeButtonsFromMenuBar(); | - |
2969 | #endif | - |
2970 | } | - |
2971 | | - |
2972 | | - |
2973 | | - |
2974 | | - |
2975 | void QMdiSubWindow::changeEvent(QEvent *changeEvent) | - |
2976 | { | - |
2977 | if (!parent()) { | - |
2978 | QWidget::changeEvent(changeEvent); | - |
2979 | return; | - |
2980 | } | - |
2981 | | - |
2982 | if (changeEvent->type() != QEvent::WindowStateChange) { | - |
2983 | QWidget::changeEvent(changeEvent); | - |
2984 | return; | - |
2985 | } | - |
2986 | | - |
2987 | QWindowStateChangeEvent *event = static_cast<QWindowStateChangeEvent *>(changeEvent); | - |
2988 | if (event->isOverride()) { | - |
2989 | event->ignore(); | - |
2990 | return; | - |
2991 | } | - |
2992 | | - |
2993 | Qt::WindowStates oldState = event->oldState(); | - |
2994 | Qt::WindowStates newState = windowState(); | - |
2995 | if (oldState == newState) { | - |
2996 | changeEvent->ignore(); | - |
2997 | return; | - |
2998 | } | - |
2999 | | - |
3000 | | - |
3001 | | - |
3002 | | - |
3003 | Q_D(QMdiSubWindow); | - |
3004 | if (!isVisible()) { | - |
3005 | d->ensureWindowState(Qt::WindowNoState); | - |
3006 | setVisible(true); | - |
3007 | } | - |
3008 | | - |
3009 | if (!d->oldGeometry.isValid()) | - |
3010 | d->oldGeometry = geometry(); | - |
3011 | | - |
3012 | if ((oldState & Qt::WindowActive) && (newState & Qt::WindowActive)) | - |
3013 | d->currentOperation = QMdiSubWindowPrivate::None; | - |
3014 | | - |
3015 | if (!(oldState & Qt::WindowMinimized) && (newState & Qt::WindowMinimized)) | - |
3016 | d->setMinimizeMode(); | - |
3017 | else if (!(oldState & Qt::WindowMaximized) && (newState & Qt::WindowMaximized)) | - |
3018 | d->setMaximizeMode(); | - |
3019 | else if (!(newState & (Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen))) | - |
3020 | d->setNormalMode(); | - |
3021 | | - |
3022 | if (d->isActive) | - |
3023 | d->ensureWindowState(Qt::WindowActive); | - |
3024 | if (d->activationEnabled) | - |
3025 | emit windowStateChanged(oldState, windowState()); | - |
3026 | } | - |
3027 | | - |
3028 | | - |
3029 | | - |
3030 | | - |
3031 | void QMdiSubWindow::closeEvent(QCloseEvent *closeEvent) | - |
3032 | { | - |
3033 | Q_D(QMdiSubWindow); | - |
3034 | bool acceptClose = true; | - |
3035 | if (d->baseWidget) | - |
3036 | acceptClose = d->baseWidget->close(); | - |
3037 | if (!acceptClose) { | - |
3038 | closeEvent->ignore(); | - |
3039 | return; | - |
3040 | } | - |
3041 | #ifndef QT_NO_MENUBAR | - |
3042 | d->removeButtonsFromMenuBar(); | - |
3043 | #endif | - |
3044 | d->setActive(false); | - |
3045 | if (parentWidget() && testAttribute(Qt::WA_DeleteOnClose)) { | - |
3046 | QChildEvent childRemoved(QEvent::ChildRemoved, this); | - |
3047 | QApplication::sendEvent(parentWidget(), &childRemoved); | - |
3048 | } | - |
3049 | closeEvent->accept(); | - |
3050 | } | - |
3051 | | - |
3052 | | - |
3053 | | - |
3054 | | - |
3055 | void QMdiSubWindow::leaveEvent(QEvent * ) | - |
3056 | { | - |
3057 | Q_D(QMdiSubWindow); | - |
3058 | if (d->hoveredSubControl != QStyle::SC_None) { | - |
3059 | d->hoveredSubControl = QStyle::SC_None; | - |
3060 | update(QRegion(0, 0, width(), d->titleBarHeight())); | - |
3061 | } | - |
3062 | } | - |
3063 | | - |
3064 | | - |
3065 | | - |
3066 | | - |
3067 | | - |
3068 | | - |
3069 | | - |
3070 | void QMdiSubWindow::resizeEvent(QResizeEvent *resizeEvent) | - |
3071 | { | - |
3072 | Q_D(QMdiSubWindow); | - |
3073 | #ifndef QT_NO_SIZEGRIP | - |
3074 | if (d->sizeGrip) { | - |
3075 | d->sizeGrip->move(isLeftToRight() ? width() - d->sizeGrip->width() : 0, | - |
3076 | height() - d->sizeGrip->height()); | - |
3077 | } | - |
3078 | #endif | - |
3079 | | - |
3080 | if (!parent()) { | - |
3081 | QWidget::resizeEvent(resizeEvent); | - |
3082 | return; | - |
3083 | } | - |
3084 | | - |
3085 | if (d->isMaximizeMode) | - |
3086 | d->ensureWindowState(Qt::WindowMaximized); | - |
3087 | | - |
3088 | d->updateMask(); | - |
3089 | if (!isVisible()) | - |
3090 | return; | - |
3091 | | - |
3092 | if (d->resizeTimerId <= 0) | - |
3093 | d->cachedStyleOptions = d->titleBarOptions(); | - |
3094 | else | - |
3095 | killTimer(d->resizeTimerId); | - |
3096 | d->resizeTimerId = startTimer(200); | - |
3097 | } | - |
3098 | | - |
3099 | | - |
3100 | | - |
3101 | | - |
3102 | void QMdiSubWindow::timerEvent(QTimerEvent *timerEvent) | - |
3103 | { | - |
3104 | Q_D(QMdiSubWindow); | - |
3105 | if (timerEvent->timerId() == d->resizeTimerId) { | - |
3106 | killTimer(d->resizeTimerId); | - |
3107 | d->resizeTimerId = -1; | - |
3108 | d->updateDirtyRegions(); | - |
3109 | } | - |
3110 | } | - |
3111 | | - |
3112 | | - |
3113 | | - |
3114 | | - |
3115 | void QMdiSubWindow::moveEvent(QMoveEvent *moveEvent) | - |
3116 | { | - |
3117 | if (!parent()) { | - |
3118 | QWidget::moveEvent(moveEvent); | - |
3119 | return; | - |
3120 | } | - |
3121 | | - |
3122 | Q_D(QMdiSubWindow); | - |
3123 | if (d->isMaximizeMode) | - |
3124 | d->ensureWindowState(Qt::WindowMaximized); | - |
3125 | } | - |
3126 | | - |
3127 | | - |
3128 | | - |
3129 | | - |
3130 | void QMdiSubWindow::paintEvent(QPaintEvent *paintEvent) | - |
3131 | { | - |
3132 | if (!parent() || (windowFlags() & Qt::FramelessWindowHint)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3133 | QWidget::paintEvent(paintEvent); | - |
3134 | return; never executed: return; | 0 |
3135 | } | - |
3136 | | - |
3137 | Q_D(QMdiSubWindow); | - |
3138 | if (isMaximized() && !d->drawTitleBarWhenMaximized())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3139 | return; never executed: return; | 0 |
3140 | | - |
3141 | if (d->resizeTimerId != -1) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3142 | | - |
3143 | int border = d->hasBorder(d->cachedStyleOptions) ? 4 : 0;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3144 | int titleBarHeight = d->titleBarHeight(d->cachedStyleOptions); | - |
3145 | titleBarHeight -= isMinimized() ? 2 * border : border;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3146 | d->cachedStyleOptions.rect = QRect(border, border, width() - 2 * border, titleBarHeight); | - |
3147 | if (!d->windowTitle.isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3148 | int width = style()->subControlRect(QStyle::CC_TitleBar, &d->cachedStyleOptions, | - |
3149 | QStyle::SC_TitleBarLabel, this).width(); | - |
3150 | d->cachedStyleOptions.text = d->cachedStyleOptions.fontMetrics | - |
3151 | .elidedText(d->windowTitle, Qt::ElideRight, width); | - |
3152 | } never executed: end of block | 0 |
3153 | } else { never executed: end of block | 0 |
3154 | | - |
3155 | d->cachedStyleOptions = d->titleBarOptions(); | - |
3156 | } never executed: end of block | 0 |
3157 | | - |
3158 | QStylePainter painter(this); | - |
3159 | if (!d->windowTitle.isEmpty())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3160 | painter.setFont(d->font); never executed: painter.setFont(d->font); | 0 |
3161 | painter.drawComplexControl(QStyle::CC_TitleBar, d->cachedStyleOptions); | - |
3162 | | - |
3163 | if (isMinimized() && !d->hasBorder(d->cachedStyleOptions))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3164 | return; never executed: return; | 0 |
3165 | | - |
3166 | QStyleOptionFrame frameOptions; | - |
3167 | frameOptions.initFrom(this); | - |
3168 | frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, this); | - |
3169 | if (d->isActive)frameOptions.state|= QStyle::State_Active; | - |
| else | |
| frameOptions.state &= ~setFlag(QStyle::State_Active;, d->isActive); | |
3170 | | - |
3171 | | - |
3172 | if (!isMinimized() && !d->hasBorder(d->cachedStyleOptions))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3173 | painter.setClipRect(rect().adjusted(0, d->titleBarHeight(d->cachedStyleOptions), 0, 0)); never executed: painter.setClipRect(rect().adjusted(0, d->titleBarHeight(d->cachedStyleOptions), 0, 0)); | 0 |
3174 | if (!isMinimized() || d->hasBorder(d->cachedStyleOptions))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
3175 | painter.drawPrimitive(QStyle::PE_FrameWindow, frameOptions); never executed: painter.drawPrimitive(QStyle::PE_FrameWindow, frameOptions); | 0 |
3176 | } never executed: end of block | 0 |
3177 | | - |
3178 | | - |
3179 | | - |
3180 | | - |
3181 | void QMdiSubWindow::mousePressEvent(QMouseEvent *mouseEvent) | - |
3182 | { | - |
3183 | if (!parent()) { | - |
3184 | QWidget::mousePressEvent(mouseEvent); | - |
3185 | return; | - |
3186 | } | - |
3187 | | - |
3188 | Q_D(QMdiSubWindow); | - |
3189 | if (d->isInInteractiveMode) | - |
3190 | d->leaveInteractiveMode(); | - |
3191 | #ifndef QT_NO_RUBBERBAND | - |
3192 | if (d->isInRubberBandMode) | - |
3193 | d->leaveRubberBandMode(); | - |
3194 | #endif | - |
3195 | | - |
3196 | if (mouseEvent->button() != Qt::LeftButton) { | - |
3197 | mouseEvent->ignore(); | - |
3198 | return; | - |
3199 | } | - |
3200 | | - |
3201 | if (d->currentOperation != QMdiSubWindowPrivate::None) { | - |
3202 | d->updateCursor(); | - |
3203 | d->mousePressPosition = mapToParent(mouseEvent->pos()); | - |
3204 | if (d->resizeEnabled || d->moveEnabled) | - |
3205 | d->oldGeometry = geometry(); | - |
3206 | #ifndef QT_NO_RUBBERBAND | - |
3207 | if ((testOption(QMdiSubWindow::RubberBandResize) && d->isResizeOperation()) | - |
3208 | || (testOption(QMdiSubWindow::RubberBandMove) && d->isMoveOperation())) { | - |
3209 | d->enterRubberBandMode(); | - |
3210 | } | - |
3211 | #endif | - |
3212 | return; | - |
3213 | } | - |
3214 | | - |
3215 | d->activeSubControl = d->hoveredSubControl; | - |
3216 | #ifndef QT_NO_MENU | - |
3217 | if (d->activeSubControl == QStyle::SC_TitleBarSysMenu) | - |
3218 | showSystemMenu(); | - |
3219 | else | - |
3220 | #endif | - |
3221 | update(QRegion(0, 0, width(), d->titleBarHeight())); | - |
3222 | } | - |
3223 | | - |
3224 | | - |
3225 | | - |
3226 | | - |
3227 | void QMdiSubWindow::mouseDoubleClickEvent(QMouseEvent *mouseEvent) | - |
3228 | { | - |
3229 | if (!parent()) { | - |
3230 | QWidget::mouseDoubleClickEvent(mouseEvent); | - |
3231 | return; | - |
3232 | } | - |
3233 | | - |
3234 | if (mouseEvent->button() != Qt::LeftButton) { | - |
3235 | mouseEvent->ignore(); | - |
3236 | return; | - |
3237 | } | - |
3238 | | - |
3239 | Q_D(QMdiSubWindow); | - |
3240 | if (!d->isMoveOperation()) { | - |
3241 | #ifndef QT_NO_MENU | - |
3242 | if (d->hoveredSubControl == QStyle::SC_TitleBarSysMenu) | - |
3243 | close(); | - |
3244 | #endif | - |
3245 | return; | - |
3246 | } | - |
3247 | | - |
3248 | Qt::WindowFlags flags = windowFlags(); | - |
3249 | if (isMinimized()) { | - |
3250 | if ((isShaded() && (flags & Qt::WindowShadeButtonHint)) | - |
3251 | || (flags & Qt::WindowMinimizeButtonHint)) { | - |
3252 | showNormal(); | - |
3253 | } | - |
3254 | return; | - |
3255 | } | - |
3256 | | - |
3257 | if (isMaximized()) { | - |
3258 | if (flags & Qt::WindowMaximizeButtonHint) | - |
3259 | showNormal(); | - |
3260 | return; | - |
3261 | } | - |
3262 | | - |
3263 | if (flags & Qt::WindowShadeButtonHint) | - |
3264 | showShaded(); | - |
3265 | else if (flags & Qt::WindowMaximizeButtonHint) | - |
3266 | showMaximized(); | - |
3267 | } | - |
3268 | | - |
3269 | | - |
3270 | | - |
3271 | | - |
3272 | void QMdiSubWindow::mouseReleaseEvent(QMouseEvent *mouseEvent) | - |
3273 | { | - |
3274 | if (!parent()) { | - |
3275 | QWidget::mouseReleaseEvent(mouseEvent); | - |
3276 | return; | - |
3277 | } | - |
3278 | | - |
3279 | if (mouseEvent->button() != Qt::LeftButton) { | - |
3280 | mouseEvent->ignore(); | - |
3281 | return; | - |
3282 | } | - |
3283 | | - |
3284 | Q_D(QMdiSubWindow); | - |
3285 | if (d->currentOperation != QMdiSubWindowPrivate::None) { | - |
3286 | #ifndef QT_NO_RUBBERBAND | - |
3287 | if (d->isInRubberBandMode && !d->isInInteractiveMode) | - |
3288 | d->leaveRubberBandMode(); | - |
3289 | #endif | - |
3290 | if (d->resizeEnabled || d->moveEnabled) | - |
3291 | d->oldGeometry = geometry(); | - |
3292 | } | - |
3293 | | - |
3294 | d->currentOperation = d->getOperation(mouseEvent->pos()); | - |
3295 | d->updateCursor(); | - |
3296 | | - |
3297 | d->hoveredSubControl = d->getSubControl(mouseEvent->pos()); | - |
3298 | if (d->activeSubControl != QStyle::SC_None | - |
3299 | && d->activeSubControl == d->hoveredSubControl) { | - |
3300 | d->processClickedSubControl(); | - |
3301 | } | - |
3302 | d->activeSubControl = QStyle::SC_None; | - |
3303 | update(QRegion(0, 0, width(), d->titleBarHeight())); | - |
3304 | } | - |
3305 | | - |
3306 | | - |
3307 | | - |
3308 | | - |
3309 | void QMdiSubWindow::mouseMoveEvent(QMouseEvent *mouseEvent) | - |
3310 | { | - |
3311 | if (!parent()) { | - |
3312 | QWidget::mouseMoveEvent(mouseEvent); | - |
3313 | return; | - |
3314 | } | - |
3315 | | - |
3316 | Q_D(QMdiSubWindow); | - |
3317 | | - |
3318 | if (!d->isMoveOperation() && !d->isResizeOperation()) { | - |
3319 | | - |
3320 | const QStyleOptionTitleBar options = d->titleBarOptions(); | - |
3321 | QStyle::SubControl oldHover = d->hoveredSubControl; | - |
3322 | d->hoveredSubControl = d->getSubControl(mouseEvent->pos()); | - |
3323 | QRegion hoverRegion; | - |
3324 | if (isHoverControl(oldHover) && oldHover != d->hoveredSubControl) | - |
3325 | hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options, oldHover, this); | - |
3326 | if (isHoverControl(d->hoveredSubControl) && d->hoveredSubControl != oldHover) { | - |
3327 | hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options, | - |
3328 | d->hoveredSubControl, this); | - |
3329 | } | - |
3330 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
3331 | if (qobject_cast<QMacStyle *>(style()) && !hoverRegion.isEmpty()) | - |
3332 | hoverRegion += QRegion(0, 0, width(), d->titleBarHeight(options)); | - |
3333 | #endif | - |
3334 | if (!hoverRegion.isEmpty()) | - |
3335 | update(hoverRegion); | - |
3336 | } | - |
3337 | | - |
3338 | if ((mouseEvent->buttons() & Qt::LeftButton) || d->isInInteractiveMode) { | - |
3339 | if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled)) | - |
3340 | d->setNewGeometry(mapToParent(mouseEvent->pos())); | - |
3341 | return; | - |
3342 | } | - |
3343 | | - |
3344 | | - |
3345 | d->currentOperation = d->getOperation(mouseEvent->pos()); | - |
3346 | if ((d->isResizeOperation() && !d->resizeEnabled) || (d->isMoveOperation() && !d->moveEnabled)) | - |
3347 | d->currentOperation = QMdiSubWindowPrivate::None; | - |
3348 | d->updateCursor(); | - |
3349 | } | - |
3350 | | - |
3351 | | - |
3352 | | - |
3353 | | - |
3354 | void QMdiSubWindow::keyPressEvent(QKeyEvent *keyEvent) | - |
3355 | { | - |
3356 | Q_D(QMdiSubWindow); | - |
3357 | if (!d->isInInteractiveMode || !parent()) { | - |
3358 | keyEvent->ignore(); | - |
3359 | return; | - |
3360 | } | - |
3361 | | - |
3362 | QPoint delta; | - |
3363 | switch (keyEvent->key()) { | - |
3364 | case Qt::Key_Right: | - |
3365 | if (keyEvent->modifiers() & Qt::ShiftModifier) | - |
3366 | delta = QPoint(d->keyboardPageStep, 0); | - |
3367 | else | - |
3368 | delta = QPoint(d->keyboardSingleStep, 0); | - |
3369 | break; | - |
3370 | case Qt::Key_Up: | - |
3371 | if (keyEvent->modifiers() & Qt::ShiftModifier) | - |
3372 | delta = QPoint(0, -d->keyboardPageStep); | - |
3373 | else | - |
3374 | delta = QPoint(0, -d->keyboardSingleStep); | - |
3375 | break; | - |
3376 | case Qt::Key_Left: | - |
3377 | if (keyEvent->modifiers() & Qt::ShiftModifier) | - |
3378 | delta = QPoint(-d->keyboardPageStep, 0); | - |
3379 | else | - |
3380 | delta = QPoint(-d->keyboardSingleStep, 0); | - |
3381 | break; | - |
3382 | case Qt::Key_Down: | - |
3383 | if (keyEvent->modifiers() & Qt::ShiftModifier) | - |
3384 | delta = QPoint(0, d->keyboardPageStep); | - |
3385 | else | - |
3386 | delta = QPoint(0, d->keyboardSingleStep); | - |
3387 | break; | - |
3388 | case Qt::Key_Escape: | - |
3389 | case Qt::Key_Return: | - |
3390 | case Qt::Key_Enter: | - |
3391 | d->leaveInteractiveMode(); | - |
3392 | return; | - |
3393 | default: | - |
3394 | keyEvent->ignore(); | - |
3395 | return; | - |
3396 | } | - |
3397 | | - |
3398 | #ifndef QT_NO_CURSOR | - |
3399 | QPoint newPosition = parentWidget()->mapFromGlobal(cursor().pos() + delta); | - |
3400 | QRect oldGeometry = | - |
3401 | #ifndef QT_NO_RUBBERBAND | - |
3402 | d->isInRubberBandMode ? d->rubberBand->geometry() : | - |
3403 | #endif | - |
3404 | geometry(); | - |
3405 | d->setNewGeometry(newPosition); | - |
3406 | QRect currentGeometry = | - |
3407 | #ifndef QT_NO_RUBBERBAND | - |
3408 | d->isInRubberBandMode ? d->rubberBand->geometry() : | - |
3409 | #endif | - |
3410 | geometry(); | - |
3411 | if (currentGeometry == oldGeometry) | - |
3412 | return; | - |
3413 | | - |
3414 | | - |
3415 | | - |
3416 | QPoint actualDelta; | - |
3417 | if (d->isMoveOperation()) { | - |
3418 | actualDelta = QPoint(currentGeometry.x() - oldGeometry.x(), | - |
3419 | currentGeometry.y() - oldGeometry.y()); | - |
3420 | } else { | - |
3421 | int dx = isLeftToRight() ? currentGeometry.width() - oldGeometry.width() | - |
3422 | : currentGeometry.x() - oldGeometry.x(); | - |
3423 | actualDelta = QPoint(dx, currentGeometry.height() - oldGeometry.height()); | - |
3424 | } | - |
3425 | | - |
3426 | | - |
3427 | if (actualDelta != delta) | - |
3428 | newPosition += (actualDelta - delta); | - |
3429 | cursor().setPos(parentWidget()->mapToGlobal(newPosition)); | - |
3430 | #endif | - |
3431 | } | - |
3432 | | - |
3433 | #ifndef QT_NO_CONTEXTMENU | - |
3434 | | - |
3435 | | - |
3436 | | - |
3437 | void QMdiSubWindow::contextMenuEvent(QContextMenuEvent *contextMenuEvent) | - |
3438 | { | - |
3439 | Q_D(QMdiSubWindow); | - |
3440 | if (!d->systemMenu) { | - |
3441 | contextMenuEvent->ignore(); | - |
3442 | return; | - |
3443 | } | - |
3444 | | - |
3445 | if (d->hoveredSubControl == QStyle::SC_TitleBarSysMenu | - |
3446 | || d->getRegion(QMdiSubWindowPrivate::Move).contains(contextMenuEvent->pos())) { | - |
3447 | d->systemMenu->exec(contextMenuEvent->globalPos()); | - |
3448 | } else { | - |
3449 | contextMenuEvent->ignore(); | - |
3450 | } | - |
3451 | } | - |
3452 | #endif // QT_NO_CONTEXTMENU | - |
3453 | | - |
3454 | | - |
3455 | | - |
3456 | | - |
3457 | void QMdiSubWindow::focusInEvent(QFocusEvent *focusInEvent) | - |
3458 | { | - |
3459 | d_func()->focusInReason = focusInEvent->reason(); | - |
3460 | } | - |
3461 | | - |
3462 | | - |
3463 | | - |
3464 | | - |
3465 | void QMdiSubWindow::focusOutEvent(QFocusEvent * ) | - |
3466 | { | - |
3467 | | - |
3468 | } | - |
3469 | | - |
3470 | | - |
3471 | | - |
3472 | | - |
3473 | void QMdiSubWindow::childEvent(QChildEvent *childEvent) | - |
3474 | { | - |
3475 | if (childEvent->type() != QEvent::ChildPolished) | - |
3476 | return; | - |
3477 | #ifndef QT_NO_SIZEGRIP | - |
3478 | if (QSizeGrip *sizeGrip = qobject_cast<QSizeGrip *>(childEvent->child())) | - |
3479 | d_func()->setSizeGrip(sizeGrip); | - |
3480 | #endif | - |
3481 | } | - |
3482 | | - |
3483 | | - |
3484 | | - |
3485 | | - |
3486 | QSize QMdiSubWindow::sizeHint() const | - |
3487 | { | - |
3488 | Q_D(const QMdiSubWindow); | - |
3489 | int margin, minWidth; | - |
3490 | d->sizeParameters(&margin, &minWidth); | - |
3491 | QSize size(2 * margin, d->titleBarHeight() + margin); | - |
3492 | if (d->baseWidget && d->baseWidget->sizeHint().isValid()) | - |
3493 | size += d->baseWidget->sizeHint(); | - |
3494 | return size.expandedTo(minimumSizeHint()); | - |
3495 | } | - |
3496 | | - |
3497 | | - |
3498 | | - |
3499 | | - |
3500 | QSize QMdiSubWindow::minimumSizeHint() const | - |
3501 | { | - |
3502 | Q_D(const QMdiSubWindow); | - |
3503 | if (isVisible()) | - |
3504 | ensurePolished(); | - |
3505 | | - |
3506 | | - |
3507 | if (parent() && isMinimized() && !isShaded()) | - |
3508 | return d->iconSize(); | - |
3509 | | - |
3510 | | - |
3511 | int margin, minWidth; | - |
3512 | d->sizeParameters(&margin, &minWidth); | - |
3513 | int decorationHeight = margin + d->titleBarHeight(); | - |
3514 | int minHeight = decorationHeight; | - |
3515 | | - |
3516 | | - |
3517 | if (parent() && isShaded()) | - |
3518 | return QSize(qMax(minWidth, width()), d->titleBarHeight()); | - |
3519 | | - |
3520 | | - |
3521 | if (layout()) { | - |
3522 | QSize minLayoutSize = layout()->minimumSize(); | - |
3523 | if (minLayoutSize.isValid()) { | - |
3524 | minWidth = qMax(minWidth, minLayoutSize.width() + 2 * margin); | - |
3525 | minHeight += minLayoutSize.height(); | - |
3526 | } | - |
3527 | } else if (d->baseWidget && d->baseWidget->isVisible()) { | - |
3528 | QSize minBaseWidgetSize = d->baseWidget->minimumSizeHint(); | - |
3529 | if (minBaseWidgetSize.isValid()) { | - |
3530 | minWidth = qMax(minWidth, minBaseWidgetSize.width() + 2 * margin); | - |
3531 | minHeight += minBaseWidgetSize.height(); | - |
3532 | } | - |
3533 | } | - |
3534 | | - |
3535 | #ifndef QT_NO_SIZEGRIP | - |
3536 | | - |
3537 | int sizeGripHeight = 0; | - |
3538 | if (d->sizeGrip && d->sizeGrip->isVisibleTo(const_cast<QMdiSubWindow *>(this))) | - |
3539 | sizeGripHeight = d->sizeGrip->height(); | - |
3540 | #if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) | - |
3541 | else if (parent() && qobject_cast<QMacStyle *>(style()) && !d->sizeGrip) | - |
3542 | sizeGripHeight = style()->pixelMetric(QStyle::PM_SizeGripSize, 0, this); | - |
3543 | #endif | - |
3544 | minHeight = qMax(minHeight, decorationHeight + sizeGripHeight); | - |
3545 | #endif | - |
3546 | | - |
3547 | return QSize(minWidth, minHeight).expandedTo(QApplication::globalStrut()); | - |
3548 | } | - |
3549 | | - |
3550 | QT_END_NAMESPACE | - |
3551 | | - |
3552 | #include "moc_qmdisubwindow.cpp" | - |
3553 | #include "qmdisubwindow.moc" | - |
3554 | | - |
3555 | #endif //QT_NO_MDIAREA | - |
| | |