blob: 14660a3d16a0226dea0885c5febb4ebeecac6823 (
plain)
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
|
#include "qtoplevelwindow.h"
#include <QDesktopWidget>
QTopLevelWindow::QTopLevelWindow()
: QMainWindow(), _view(new QDeclarativeView), _positionIsDefined(false) {
setVisible(false);
setCentralWidget(_view);
setAttribute(Qt::WA_DeleteOnClose);
}
QTopLevelWindow::~QTopLevelWindow()
{
//we need this to break the parental loop of QWindowItem and QTopLevelWindow
_view->scene()->setParent(0);
}
void QTopLevelWindow::registerChildWindow(QTopLevelWindow* child)
{
_childWindows.insert(child);
child->setParent(this);
}
void QTopLevelWindow::hideChildWindows()
{
foreach(QTopLevelWindow* child, _childWindows) {
child->hide();
}
}
void QTopLevelWindow::initPosition()
{
if (!_positionIsDefined)
center();
foreach(QTopLevelWindow* child, _childWindows) {
child->initPosition();
}
}
void QTopLevelWindow::center()
{
QPoint parentCenter;
if (parentWidget())
parentCenter = parentWidget()->geometry().center();
else
parentCenter = QDesktopWidget().screenGeometry().center();
QRect thisGeometry = geometry();
thisGeometry.moveCenter(parentCenter);
setGeometry(thisGeometry);
}
void QTopLevelWindow::move(int x, int y)
{
move(QPoint(x,y));
}
void QTopLevelWindow::move(const QPoint &point)
{
_positionIsDefined = true;
QMainWindow::move(point);
}
void QTopLevelWindow::setWindowFlags(Qt::WindowFlags type)
{
QWidget::setWindowFlags(type | Qt::Window);
}
bool QTopLevelWindow::event(QEvent *event) {
switch (event->type()) {
case QEvent::WindowStateChange:
emit windowStateChanged();
break;
case QEvent::Show:
emit visibilityChanged();
break;
case QEvent::Hide:
hideChildWindows();
emit visibilityChanged();
break;
case QEvent::ParentChange:
setAttribute(Qt::WA_DeleteOnClose, !parent());
break;
case QEvent::Resize: {
const QResizeEvent *resize = static_cast<const QResizeEvent *>(event);
emit sizeChanged(resize->size());
break;
}
default: break;
}
return QMainWindow::event(event);
}
|