[935] | 1 | #include <QDebug>
|
---|
| 2 | #include <QtGui>
|
---|
| 3 |
|
---|
[937] | 4 | class MyMainWidget : public QWidget
|
---|
[935] | 5 | {
|
---|
[937] | 6 | Q_OBJECT
|
---|
| 7 |
|
---|
[935] | 8 | public:
|
---|
| 9 |
|
---|
[937] | 10 | MyMainWidget() : mTestNo (0), mCurWidget (0)
|
---|
| 11 | {
|
---|
| 12 | mTestNo = 4;
|
---|
| 13 |
|
---|
| 14 | setWindowTitle ("Primary");
|
---|
| 15 |
|
---|
| 16 | mPB = new QPushButton ("Next Test", this);
|
---|
| 17 | connect (mPB, SIGNAL (clicked()), this, SLOT (nextTest()));
|
---|
| 18 |
|
---|
| 19 | QVBoxLayout *layout = new QVBoxLayout();
|
---|
| 20 | layout->addWidget (mPB);
|
---|
| 21 | setLayout (layout);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | virtual ~MyMainWidget()
|
---|
| 25 | {
|
---|
| 26 | delete mCurWidget;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | void test (QWidget *w, const QString &text)
|
---|
| 30 | {
|
---|
| 31 | w->setWindowTitle ("Secondary");
|
---|
| 32 |
|
---|
| 33 | QString newText = QString (
|
---|
| 34 | "%1\n\n"
|
---|
| 35 | "parentWidget() is %2\n"
|
---|
| 36 | "className() is %3\n"
|
---|
| 37 | "isWindow() is %4\n"
|
---|
| 38 | "windowFlags() is 0x%5\n"
|
---|
| 39 | "windowModality() is %6")
|
---|
| 40 | .arg (text)
|
---|
| 41 | .arg (w->parentWidget() ? w->parentWidget()->metaObject()
|
---|
| 42 | ->className()
|
---|
| 43 | : "<none>")
|
---|
| 44 | .arg (w->metaObject()->className())
|
---|
| 45 | .arg (w->isWindow())
|
---|
| 46 | .arg (w->windowFlags(), 8, 16, QLatin1Char ('0'))
|
---|
| 47 | .arg (w->windowModality());
|
---|
| 48 |
|
---|
| 49 | if (w->inherits ("QMessageBox"))
|
---|
| 50 | {
|
---|
| 51 | static_cast <QMessageBox *> (w)->setText (newText);
|
---|
| 52 | }
|
---|
| 53 | else
|
---|
| 54 | {
|
---|
| 55 | QLabel *label = new QLabel (w);
|
---|
| 56 | label->setText (newText);
|
---|
| 57 |
|
---|
| 58 | QVBoxLayout *layout = new QVBoxLayout();
|
---|
| 59 | layout->addWidget (label);
|
---|
| 60 | w->setLayout (layout);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | w->show();
|
---|
| 64 |
|
---|
| 65 | if (mCurWidget)
|
---|
| 66 | {
|
---|
| 67 | mCurWidget->close();
|
---|
| 68 | delete mCurWidget;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | mCurWidget = w;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public slots:
|
---|
| 75 |
|
---|
| 76 | void nextTest()
|
---|
| 77 | {
|
---|
| 78 | switch (mTestNo)
|
---|
| 79 | {
|
---|
| 80 | case 0:
|
---|
| 81 | {
|
---|
| 82 | QWidget *w = new QWidget();
|
---|
| 83 | test (w,
|
---|
| 84 | "QWidget().\n"
|
---|
| 85 | "Should have a taskbar entry.\n"
|
---|
| 86 | "Should not be always on top of parent.\n"
|
---|
| 87 | "Should not block parent.");
|
---|
| 88 | break;
|
---|
| 89 | }
|
---|
| 90 | case 1:
|
---|
| 91 | {
|
---|
| 92 | QWidget *w = new QWidget (this, Qt::Window);
|
---|
| 93 | test (w,
|
---|
| 94 | "QWidget (this, Qt::Window).\n"
|
---|
| 95 | "Should not have a taskbar entry.\n"
|
---|
| 96 | "Should be always on top of parent.\n"
|
---|
| 97 | "Should not block parent.");
|
---|
| 98 | break;
|
---|
| 99 | }
|
---|
| 100 | case 2:
|
---|
| 101 | {
|
---|
| 102 | QWidget *w = new QDialog();
|
---|
| 103 | test (w,
|
---|
| 104 | "QDialog().\n"
|
---|
| 105 | "Should have a taskbar entry.\n"
|
---|
| 106 | "Should not be always on top of parent.\n"
|
---|
| 107 | "Should not block parent.");
|
---|
| 108 | break;
|
---|
| 109 | }
|
---|
| 110 | case 3:
|
---|
| 111 | {
|
---|
| 112 | QWidget *w = new QDialog (this);
|
---|
| 113 | test (w,
|
---|
| 114 | "QDialog(this).\n"
|
---|
| 115 | "Should not have a taskbar entry.\n"
|
---|
| 116 | "Should be always on top of parent.\n"
|
---|
| 117 | "Should not block parent.");
|
---|
| 118 | break;
|
---|
| 119 | }
|
---|
| 120 | case 4:
|
---|
| 121 | {
|
---|
| 122 | QWidget *w = new QMessageBox();
|
---|
| 123 | test (w,
|
---|
| 124 | "QMessageBox().\n"
|
---|
| 125 | "Should have a taskbar entry.\n"
|
---|
| 126 | "Should be always on top of parent.\n"
|
---|
| 127 | "Should block parent.");
|
---|
| 128 | break;
|
---|
| 129 | }
|
---|
| 130 | case 5:
|
---|
| 131 | {
|
---|
| 132 | QWidget *w = new QMessageBox (this);
|
---|
| 133 | test (w,
|
---|
| 134 | "QMessageBox (this).\n"
|
---|
| 135 | "Should not have a taskbar entry.\n"
|
---|
| 136 | "Should be always on top of parent.\n"
|
---|
| 137 | "Should block parent.");
|
---|
| 138 | break;
|
---|
| 139 | }
|
---|
| 140 | case 6:
|
---|
| 141 | {
|
---|
| 142 | QWidget *w = new QWidget();
|
---|
| 143 | w->setWindowModality (Qt::WindowModal);
|
---|
| 144 | test (w,
|
---|
| 145 | "QWidget() - WindowModal.\n"
|
---|
| 146 | "Should have a taskbar entry.\n"
|
---|
| 147 | "Should not be always on top of parent.\n"
|
---|
| 148 | "Should not block parent.");
|
---|
| 149 | break;
|
---|
| 150 | }
|
---|
| 151 | case 7:
|
---|
| 152 | {
|
---|
| 153 | QWidget *w = new QWidget (this, Qt::Window);
|
---|
| 154 | w->setWindowModality (Qt::WindowModal);
|
---|
| 155 | test (w,
|
---|
| 156 | "QWidget (this, Qt::Window) - WindowModal.\n"
|
---|
| 157 | "Should not have a taskbar entry.\n"
|
---|
| 158 | "Should be always on top of parent.\n"
|
---|
| 159 | "Should block parent.");
|
---|
| 160 | break;
|
---|
| 161 | }
|
---|
| 162 | case 8:
|
---|
| 163 | {
|
---|
| 164 | QWidget *w = new QWidget(0, Qt::Dialog);
|
---|
| 165 | w->setWindowModality (Qt::ApplicationModal);
|
---|
| 166 | test (w,
|
---|
| 167 | "QWidget() - ApplicationModal.\n"
|
---|
| 168 | "Should have a taskbar entry.\n"
|
---|
| 169 | "Should be always on top of parent.\n"
|
---|
| 170 | "Should block parent.");
|
---|
| 171 | break;
|
---|
| 172 | }
|
---|
| 173 | case 9:
|
---|
| 174 | {
|
---|
| 175 | QWidget *w = new QWidget (this, Qt::Window);
|
---|
| 176 | w->setWindowModality (Qt::ApplicationModal);
|
---|
| 177 | test (w,
|
---|
| 178 | "QWidget (this, Qt::Window) - ApplicationModal.\n"
|
---|
| 179 | "Should not have a taskbar entry.\n"
|
---|
| 180 | "Should be always on top of parent.\n"
|
---|
| 181 | "Should block parent.");
|
---|
| 182 | break;
|
---|
| 183 | }
|
---|
| 184 | default:
|
---|
| 185 | mPB->setText ("No More Tests");
|
---|
| 186 | mPB->setEnabled (false);
|
---|
| 187 | return;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | ++ mTestNo;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | private:
|
---|
| 194 |
|
---|
| 195 | int mTestNo;
|
---|
| 196 | QPushButton *mPB;
|
---|
| 197 | QWidget *mCurWidget;
|
---|
[935] | 198 | };
|
---|
| 199 |
|
---|
| 200 | int main (int argc, char **argv)
|
---|
| 201 | {
|
---|
| 202 | QApplication app (argc, argv);
|
---|
| 203 | app.setQuitOnLastWindowClosed (true);
|
---|
| 204 |
|
---|
[937] | 205 | MyMainWidget mainWidget;
|
---|
| 206 | mainWidget.resize (100, 100);
|
---|
| 207 | mainWidget.show();
|
---|
[935] | 208 |
|
---|
| 209 | return app.exec();
|
---|
| 210 | }
|
---|
[937] | 211 |
|
---|
| 212 | #include "modal.moc"
|
---|