1 | #include <QDebug>
|
---|
2 | #include <QtGui>
|
---|
3 |
|
---|
4 | class MyMainWidget : public QWidget
|
---|
5 | {
|
---|
6 | Q_OBJECT
|
---|
7 |
|
---|
8 | public:
|
---|
9 |
|
---|
10 | MyMainWidget (QWidget *aParent = 0, Qt::WindowFlags aFlags = 0)
|
---|
11 | : QWidget (aParent, aFlags)
|
---|
12 | {
|
---|
13 | setWindowTitle (QString ("MyMainWidget (0x%1)")
|
---|
14 | .arg ((intptr_t) this, 8, 16, QChar('0')));
|
---|
15 |
|
---|
16 | QHBoxLayout *pbLayout = new QHBoxLayout();
|
---|
17 |
|
---|
18 | for (int i = 1; i <= 10; ++ i)
|
---|
19 | {
|
---|
20 | QPushButton *pb = new QPushButton (QString::number (i), this);
|
---|
21 | connect (pb, SIGNAL (clicked()), this, SLOT (nextTest()));
|
---|
22 | pbLayout->addWidget (pb);
|
---|
23 | }
|
---|
24 |
|
---|
25 | mPBClone = new QPushButton ("Clone", this);
|
---|
26 | connect (mPBClone, SIGNAL (clicked()), this, SLOT (clone()));
|
---|
27 |
|
---|
28 | mPBCloneModal = new QPushButton ("Modal Clone", this);
|
---|
29 | connect (mPBCloneModal, SIGNAL (clicked()), this, SLOT (cloneModal()));
|
---|
30 |
|
---|
31 | mPBCloneAppModal = new QPushButton ("App Modal Clone", this);
|
---|
32 | connect (mPBCloneAppModal, SIGNAL (clicked()), this, SLOT (cloneAppModal()));
|
---|
33 |
|
---|
34 | QVBoxLayout *layout = new QVBoxLayout();
|
---|
35 | layout->addLayout (pbLayout);
|
---|
36 | layout->addWidget (mPBClone);
|
---|
37 | layout->addWidget (mPBCloneModal);
|
---|
38 | layout->addWidget (mPBCloneAppModal);
|
---|
39 | setLayout (layout);
|
---|
40 | }
|
---|
41 |
|
---|
42 | virtual ~MyMainWidget()
|
---|
43 | {
|
---|
44 | }
|
---|
45 |
|
---|
46 | void test (int aNum, QWidget *aWgt, const QString &aText)
|
---|
47 | {
|
---|
48 | aWgt->setAttribute (Qt::WA_DeleteOnClose);
|
---|
49 |
|
---|
50 | aWgt->setWindowTitle (QString ("[%1] %2 (0x%3)")
|
---|
51 | .arg (aNum)
|
---|
52 | .arg (aWgt->metaObject()->className())
|
---|
53 | .arg ((intptr_t) aWgt, 8, 16, QChar('0')));
|
---|
54 |
|
---|
55 | QString newText = QString (
|
---|
56 | "[%1] %2\n\n"
|
---|
57 | "parentWidget() is %3\n"
|
---|
58 | "className() is %4\n"
|
---|
59 | "isWindow() is %5\n"
|
---|
60 | "windowFlags() is 0x%6\n"
|
---|
61 | "windowModality() is %7")
|
---|
62 | .arg (aNum)
|
---|
63 | .arg (aText)
|
---|
64 | .arg (aWgt->parentWidget() ? aWgt->parentWidget()->metaObject()
|
---|
65 | ->className()
|
---|
66 | : "<none>")
|
---|
67 | .arg (aWgt->metaObject()->className())
|
---|
68 | .arg (aWgt->isWindow())
|
---|
69 | .arg (aWgt->windowFlags(), 8, 16, QLatin1Char ('0'))
|
---|
70 | .arg (aWgt->windowModality());
|
---|
71 |
|
---|
72 | if (aWgt->inherits ("QMessageBox"))
|
---|
73 | {
|
---|
74 | static_cast <QMessageBox *> (aWgt)->setText (newText);
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | QLabel *label = new QLabel (aWgt);
|
---|
79 | label->setText (newText);
|
---|
80 |
|
---|
81 | QVBoxLayout *layout = new QVBoxLayout();
|
---|
82 | layout->addWidget (label);
|
---|
83 | aWgt->setLayout (layout);
|
---|
84 | }
|
---|
85 |
|
---|
86 | aWgt->show();
|
---|
87 | }
|
---|
88 |
|
---|
89 | public slots:
|
---|
90 |
|
---|
91 | void nextTest()
|
---|
92 | {
|
---|
93 | int num = static_cast <QPushButton *> (sender())->text().toInt();
|
---|
94 | switch (num)
|
---|
95 | {
|
---|
96 | case 1:
|
---|
97 | {
|
---|
98 | QWidget *w = new QWidget();
|
---|
99 | test (num, w,
|
---|
100 | "QWidget().\n"
|
---|
101 | "Should have a taskbar entry.\n"
|
---|
102 | "Should not be always on top of parent.\n"
|
---|
103 | "Should not block parent.");
|
---|
104 | break;
|
---|
105 | }
|
---|
106 | case 2:
|
---|
107 | {
|
---|
108 | QWidget *w = new QWidget (this, Qt::Window);
|
---|
109 | test (num, w,
|
---|
110 | "QWidget (this, Qt::Window).\n"
|
---|
111 | "Should not have a taskbar entry.\n"
|
---|
112 | "Should be always on top of parent.\n"
|
---|
113 | "Should not block parent.");
|
---|
114 | break;
|
---|
115 | }
|
---|
116 | case 3:
|
---|
117 | {
|
---|
118 | QWidget *w = new QDialog();
|
---|
119 | test (num, w,
|
---|
120 | "QDialog().\n"
|
---|
121 | "Should have a taskbar entry.\n"
|
---|
122 | "Should not be always on top of parent.\n"
|
---|
123 | "Should not block parent.");
|
---|
124 | break;
|
---|
125 | }
|
---|
126 | case 4:
|
---|
127 | {
|
---|
128 | QWidget *w = new QDialog (this);
|
---|
129 | test (num, w,
|
---|
130 | "QDialog(this).\n"
|
---|
131 | "Should not have a taskbar entry.\n"
|
---|
132 | "Should be always on top of parent.\n"
|
---|
133 | "Should not block parent.");
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | case 5:
|
---|
137 | {
|
---|
138 | QWidget *w = new QMessageBox();
|
---|
139 | test (num, w,
|
---|
140 | "QMessageBox().\n"
|
---|
141 | "Should have a taskbar entry.\n"
|
---|
142 | "Should be always on top of parent.\n"
|
---|
143 | "Should block parent.");
|
---|
144 | break;
|
---|
145 | }
|
---|
146 | case 6:
|
---|
147 | {
|
---|
148 | QWidget *w = new QMessageBox (this);
|
---|
149 | test (num, w,
|
---|
150 | "QMessageBox (this).\n"
|
---|
151 | "Should not have a taskbar entry.\n"
|
---|
152 | "Should be always on top of parent.\n"
|
---|
153 | "Should block parent.");
|
---|
154 | break;
|
---|
155 | }
|
---|
156 | case 7:
|
---|
157 | {
|
---|
158 | QWidget *w = new QWidget();
|
---|
159 | w->setWindowModality (Qt::WindowModal);
|
---|
160 | test (num, w,
|
---|
161 | "QWidget() - WindowModal.\n"
|
---|
162 | "Should have a taskbar entry.\n"
|
---|
163 | "Should not be always on top of parent.\n"
|
---|
164 | "Should not block parent.");
|
---|
165 | break;
|
---|
166 | }
|
---|
167 | case 8:
|
---|
168 | {
|
---|
169 | QWidget *w = new QWidget (this, Qt::Window);
|
---|
170 | w->setWindowModality (Qt::WindowModal);
|
---|
171 | test (num, w,
|
---|
172 | "QWidget (this, Qt::Window) - WindowModal.\n"
|
---|
173 | "Should not have a taskbar entry.\n"
|
---|
174 | "Should be always on top of parent.\n"
|
---|
175 | "Should block parent.");
|
---|
176 | break;
|
---|
177 | }
|
---|
178 | case 9:
|
---|
179 | {
|
---|
180 | QWidget *w = new QWidget(0, Qt::Dialog);
|
---|
181 | w->setWindowModality (Qt::ApplicationModal);
|
---|
182 | test (num, w,
|
---|
183 | "QWidget() - ApplicationModal.\n"
|
---|
184 | "Should have a taskbar entry.\n"
|
---|
185 | "Should be always on top of parent.\n"
|
---|
186 | "Should block parent.");
|
---|
187 | break;
|
---|
188 | }
|
---|
189 | case 10:
|
---|
190 | {
|
---|
191 | QWidget *w = new QWidget (this, Qt::Window);
|
---|
192 | w->setWindowModality (Qt::ApplicationModal);
|
---|
193 | test (num, w,
|
---|
194 | "QWidget (this, Qt::Window) - ApplicationModal.\n"
|
---|
195 | "Should not have a taskbar entry.\n"
|
---|
196 | "Should be always on top of parent.\n"
|
---|
197 | "Should block parent.");
|
---|
198 | break;
|
---|
199 | }
|
---|
200 | default:
|
---|
201 | return;
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | void clone()
|
---|
206 | {
|
---|
207 | QWidget *w = new MyMainWidget ();
|
---|
208 | w->setAttribute (Qt::WA_DeleteOnClose);
|
---|
209 | w->show();
|
---|
210 | }
|
---|
211 |
|
---|
212 | void cloneModal()
|
---|
213 | {
|
---|
214 | QWidget *w = new MyMainWidget (this, Qt::Window);
|
---|
215 | w->setAttribute (Qt::WA_DeleteOnClose);
|
---|
216 | w->setWindowModality (Qt::WindowModal);
|
---|
217 | w->setWindowTitle (QString("[M] ") + w->windowTitle());
|
---|
218 | w->show();
|
---|
219 | }
|
---|
220 |
|
---|
221 | void cloneAppModal()
|
---|
222 | {
|
---|
223 | QWidget *w = new MyMainWidget();
|
---|
224 | w->setAttribute (Qt::WA_DeleteOnClose);
|
---|
225 | w->setWindowModality (Qt::ApplicationModal);
|
---|
226 | w->setWindowTitle (QString("[AM] ") + w->windowTitle());
|
---|
227 | w->show();
|
---|
228 | }
|
---|
229 |
|
---|
230 | private:
|
---|
231 |
|
---|
232 | QPushButton *mPBClone;
|
---|
233 | QPushButton *mPBCloneModal;
|
---|
234 | QPushButton *mPBCloneAppModal;
|
---|
235 | };
|
---|
236 |
|
---|
237 | int main (int argc, char **argv)
|
---|
238 | {
|
---|
239 | QApplication app (argc, argv);
|
---|
240 | app.setQuitOnLastWindowClosed (true);
|
---|
241 |
|
---|
242 | MyMainWidget *mainWidget = new MyMainWidget();
|
---|
243 | mainWidget->show();
|
---|
244 |
|
---|
245 | return app.exec();
|
---|
246 | }
|
---|
247 |
|
---|
248 | #include "modal.moc"
|
---|