| [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 |  | 
|---|
| [939] | 10 | MyMainWidget (QWidget *aParent = 0, Qt::WindowFlags aFlags = 0) | 
|---|
|  | 11 | : QWidget (aParent, aFlags) | 
|---|
| [937] | 12 | { | 
|---|
| [939] | 13 | setWindowTitle (QString ("MyMainWidget (0x%1)") | 
|---|
|  | 14 | .arg ((intptr_t) this, 8, 16, QChar('0'))); | 
|---|
| [937] | 15 |  | 
|---|
| [939] | 16 | QHBoxLayout *pbLayout = new QHBoxLayout(); | 
|---|
| [937] | 17 |  | 
|---|
| [939] | 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 | } | 
|---|
| [937] | 24 |  | 
|---|
| [939] | 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 |  | 
|---|
| [937] | 34 | QVBoxLayout *layout = new QVBoxLayout(); | 
|---|
| [939] | 35 | layout->addLayout (pbLayout); | 
|---|
|  | 36 | layout->addWidget (mPBClone); | 
|---|
|  | 37 | layout->addWidget (mPBCloneModal); | 
|---|
|  | 38 | layout->addWidget (mPBCloneAppModal); | 
|---|
| [937] | 39 | setLayout (layout); | 
|---|
|  | 40 | } | 
|---|
|  | 41 |  | 
|---|
|  | 42 | virtual ~MyMainWidget() | 
|---|
|  | 43 | { | 
|---|
|  | 44 | } | 
|---|
|  | 45 |  | 
|---|
| [939] | 46 | void test (int aNum, QWidget *aWgt, const QString &aText) | 
|---|
| [937] | 47 | { | 
|---|
| [939] | 48 | aWgt->setAttribute (Qt::WA_DeleteOnClose); | 
|---|
| [937] | 49 |  | 
|---|
| [939] | 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 |  | 
|---|
| [937] | 55 | QString newText = QString ( | 
|---|
| [939] | 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()); | 
|---|
| [937] | 71 |  | 
|---|
| [939] | 72 | if (aWgt->inherits ("QMessageBox")) | 
|---|
| [937] | 73 | { | 
|---|
| [939] | 74 | static_cast <QMessageBox *> (aWgt)->setText (newText); | 
|---|
| [937] | 75 | } | 
|---|
|  | 76 | else | 
|---|
|  | 77 | { | 
|---|
| [939] | 78 | QLabel *label = new QLabel (aWgt); | 
|---|
| [937] | 79 | label->setText (newText); | 
|---|
|  | 80 |  | 
|---|
|  | 81 | QVBoxLayout *layout = new QVBoxLayout(); | 
|---|
|  | 82 | layout->addWidget (label); | 
|---|
| [939] | 83 | aWgt->setLayout (layout); | 
|---|
| [937] | 84 | } | 
|---|
|  | 85 |  | 
|---|
| [939] | 86 | aWgt->show(); | 
|---|
| [937] | 87 | } | 
|---|
|  | 88 |  | 
|---|
|  | 89 | public slots: | 
|---|
|  | 90 |  | 
|---|
|  | 91 | void nextTest() | 
|---|
|  | 92 | { | 
|---|
| [939] | 93 | int num = static_cast <QPushButton *> (sender())->text().toInt(); | 
|---|
|  | 94 | switch (num) | 
|---|
| [937] | 95 | { | 
|---|
| [939] | 96 | case 1: | 
|---|
| [937] | 97 | { | 
|---|
|  | 98 | QWidget *w = new QWidget(); | 
|---|
| [939] | 99 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 106 | case 2: | 
|---|
| [937] | 107 | { | 
|---|
|  | 108 | QWidget *w = new QWidget (this, Qt::Window); | 
|---|
| [939] | 109 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 116 | case 3: | 
|---|
| [937] | 117 | { | 
|---|
|  | 118 | QWidget *w = new QDialog(); | 
|---|
| [939] | 119 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 126 | case 4: | 
|---|
| [937] | 127 | { | 
|---|
|  | 128 | QWidget *w = new QDialog (this); | 
|---|
| [939] | 129 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 136 | case 5: | 
|---|
| [937] | 137 | { | 
|---|
|  | 138 | QWidget *w = new QMessageBox(); | 
|---|
| [939] | 139 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 146 | case 6: | 
|---|
| [937] | 147 | { | 
|---|
|  | 148 | QWidget *w = new QMessageBox (this); | 
|---|
| [939] | 149 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 156 | case 7: | 
|---|
| [937] | 157 | { | 
|---|
|  | 158 | QWidget *w = new QWidget(); | 
|---|
|  | 159 | w->setWindowModality (Qt::WindowModal); | 
|---|
| [939] | 160 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 167 | case 8: | 
|---|
| [937] | 168 | { | 
|---|
|  | 169 | QWidget *w = new QWidget (this, Qt::Window); | 
|---|
|  | 170 | w->setWindowModality (Qt::WindowModal); | 
|---|
| [939] | 171 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 178 | case 9: | 
|---|
| [937] | 179 | { | 
|---|
|  | 180 | QWidget *w = new QWidget(0, Qt::Dialog); | 
|---|
|  | 181 | w->setWindowModality (Qt::ApplicationModal); | 
|---|
| [939] | 182 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 189 | case 10: | 
|---|
| [937] | 190 | { | 
|---|
|  | 191 | QWidget *w = new QWidget (this, Qt::Window); | 
|---|
|  | 192 | w->setWindowModality (Qt::ApplicationModal); | 
|---|
| [939] | 193 | test (num, w, | 
|---|
| [937] | 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 | } | 
|---|
| [939] | 203 | } | 
|---|
| [937] | 204 |  | 
|---|
| [939] | 205 | void clone() | 
|---|
|  | 206 | { | 
|---|
|  | 207 | QWidget *w = new MyMainWidget (); | 
|---|
|  | 208 | w->setAttribute (Qt::WA_DeleteOnClose); | 
|---|
|  | 209 | w->show(); | 
|---|
| [937] | 210 | } | 
|---|
|  | 211 |  | 
|---|
| [939] | 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 |  | 
|---|
| [937] | 230 | private: | 
|---|
|  | 231 |  | 
|---|
| [939] | 232 | QPushButton *mPBClone; | 
|---|
|  | 233 | QPushButton *mPBCloneModal; | 
|---|
|  | 234 | QPushButton *mPBCloneAppModal; | 
|---|
| [935] | 235 | }; | 
|---|
|  | 236 |  | 
|---|
|  | 237 | int main (int argc, char **argv) | 
|---|
|  | 238 | { | 
|---|
|  | 239 | QApplication app (argc, argv); | 
|---|
|  | 240 | app.setQuitOnLastWindowClosed (true); | 
|---|
|  | 241 |  | 
|---|
| [939] | 242 | MyMainWidget *mainWidget = new MyMainWidget(); | 
|---|
|  | 243 | mainWidget->show(); | 
|---|
| [935] | 244 |  | 
|---|
|  | 245 | return app.exec(); | 
|---|
|  | 246 | } | 
|---|
| [937] | 247 |  | 
|---|
|  | 248 | #include "modal.moc" | 
|---|