| 1 | #include <QDebug>
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include <QtGui>
 | 
|---|
| 4 | 
 | 
|---|
| 5 | #ifndef Q_WS_PM
 | 
|---|
| 6 | 
 | 
|---|
| 7 | // For printing non-quoted QString's with QDebug)
 | 
|---|
| 8 | struct QDbgStr: public QString
 | 
|---|
| 9 | {
 | 
|---|
| 10 |     inline QDbgStr(const QString &str) : QString(str) {}
 | 
|---|
| 11 | };
 | 
|---|
| 12 | 
 | 
|---|
| 13 | // Prints a non-quoted QString
 | 
|---|
| 14 | inline QDebug operator<<(QDebug dbg, const QDbgStr &str)
 | 
|---|
| 15 | { dbg << str.toUtf8().constData(); return dbg; }
 | 
|---|
| 16 | 
 | 
|---|
| 17 | QDbgStr qWidgetName(QWidget *w)
 | 
|---|
| 18 | {
 | 
|---|
| 19 |     if (w)
 | 
|---|
| 20 |         return QString()
 | 
|---|
| 21 |             .sprintf("%s.%s", w->metaObject()->className(),
 | 
|---|
| 22 |                      w->objectName().isEmpty() ? "<noname>" :
 | 
|---|
| 23 |                      w->objectName().toUtf8().constData());
 | 
|---|
| 24 |     return QString(QLatin1String("<no-widget>"));
 | 
|---|
| 25 | }
 | 
|---|
| 26 | 
 | 
|---|
| 27 | #endif
 | 
|---|
| 28 | 
 | 
|---|
| 29 | #define myDefFlagEx(var,fl,varstr,flstr) if (var & fl) { \
 | 
|---|
| 30 |     if (!varstr.isEmpty()) varstr += QLatin1String("|"); varstr += QLatin1String(flstr); \
 | 
|---|
| 31 | } else do {} while(0)
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #define myDefFlag(var,fl,varstr) myDefFlagEx(var,fl,varstr,#fl)
 | 
|---|
| 34 | #define myDefFlagCut(var,fl,varstr,pos) myDefFlagEx(var,fl,varstr,#fl + pos)
 | 
|---|
| 35 | 
 | 
|---|
| 36 | #define PRINT_EXPR(e) qWarning() << #e << e
 | 
|---|
| 37 | 
 | 
|---|
| 38 | QDebug operator<<(QDebug dbg, Qt::WindowStates st)
 | 
|---|
| 39 | {
 | 
|---|
| 40 |     QString name;
 | 
|---|
| 41 |     myDefFlagEx(st, Qt::WindowMinimized, name, "Min");
 | 
|---|
| 42 |     myDefFlagEx(st, Qt::WindowMaximized, name, "Max");
 | 
|---|
| 43 |     myDefFlagEx(st, Qt::WindowFullScreen, name, "Full");
 | 
|---|
| 44 |     myDefFlagEx(st, Qt::WindowActive, name, "Act");
 | 
|---|
| 45 |     if (name.isEmpty()) name = QLatin1String("None");
 | 
|---|
| 46 |     dbg.nospace() << "WindowState(" << QDbgStr(name) << ")";
 | 
|---|
| 47 |     return dbg.space();
 | 
|---|
| 48 | }
 | 
|---|
| 49 | 
 | 
|---|
| 50 | QDebug operator<<(QDebug dbg, Qt::FocusReason r)
 | 
|---|
| 51 | {
 | 
|---|
| 52 |     QString name;
 | 
|---|
| 53 |     if (r == Qt::MouseFocusReason) name = "Mouse";
 | 
|---|
| 54 |     if (r == Qt::TabFocusReason) name = "Tab";
 | 
|---|
| 55 |     if (r == Qt::BacktabFocusReason) name = "Backtab";
 | 
|---|
| 56 |     if (r == Qt::ActiveWindowFocusReason) name = "ActWin";
 | 
|---|
| 57 |     if (r == Qt::PopupFocusReason) name = "Popup";
 | 
|---|
| 58 |     if (r == Qt::ShortcutFocusReason) name = "Shortcut";
 | 
|---|
| 59 |     if (r == Qt::MenuBarFocusReason) name = "MenuBar";
 | 
|---|
| 60 |     if (r == Qt::OtherFocusReason) name = "Other";
 | 
|---|
| 61 |     dbg.nospace() << "FocusReason(" << QDbgStr(name) << ")";
 | 
|---|
| 62 |     return dbg.space();
 | 
|---|
| 63 | }
 | 
|---|
| 64 | 
 | 
|---|
| 65 | ////////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 66 | 
 | 
|---|
| 67 | class MyChild : public QWidget
 | 
|---|
| 68 | {
 | 
|---|
| 69 |     Q_OBJECT
 | 
|---|
| 70 | 
 | 
|---|
| 71 | public:
 | 
|---|
| 72 | 
 | 
|---|
| 73 |     MyChild(QWidget *aParent) : QWidget(aParent), mPressed(0)
 | 
|---|
| 74 |     {
 | 
|---|
| 75 |         setFocusPolicy(Qt::StrongFocus);
 | 
|---|
| 76 | 
 | 
|---|
| 77 |         resize(64, 32);
 | 
|---|
| 78 |     }
 | 
|---|
| 79 | 
 | 
|---|
| 80 |     void paintEvent(QPaintEvent *aE)
 | 
|---|
| 81 |     {
 | 
|---|
| 82 |         qDebug() << qWidgetName(this) << __FUNCTION__
 | 
|---|
| 83 |                  << ": " << aE->rect() << "focus" << hasFocus();
 | 
|---|
| 84 | 
 | 
|---|
| 85 |         QPainter p(this);
 | 
|---|
| 86 |         p.setRenderHint(QPainter::Antialiasing);
 | 
|---|
| 87 | 
 | 
|---|
| 88 |         if (hasFocus())
 | 
|---|
| 89 |             p.fillRect(aE->rect(), mPressed % 2 ? Qt::red : Qt::green);
 | 
|---|
| 90 |         else
 | 
|---|
| 91 |             p.fillRect(aE->rect(), Qt::gray);
 | 
|---|
| 92 |     }
 | 
|---|
| 93 | 
 | 
|---|
| 94 |     void mousePressEvent(QMouseEvent *aE)
 | 
|---|
| 95 |     {
 | 
|---|
| 96 |         Q_UNUSED(aE);
 | 
|---|
| 97 |         ++mPressed;
 | 
|---|
| 98 |         update();
 | 
|---|
| 99 |     }
 | 
|---|
| 100 | 
 | 
|---|
| 101 |     void mouseReleaseEvent(QMouseEvent *aE)
 | 
|---|
| 102 |     {
 | 
|---|
| 103 |         Q_UNUSED(aE);
 | 
|---|
| 104 |         ++mPressed;
 | 
|---|
| 105 |         update();
 | 
|---|
| 106 |     }
 | 
|---|
| 107 | 
 | 
|---|
| 108 |     void focusInEvent(QFocusEvent *aE)
 | 
|---|
| 109 |     {
 | 
|---|
| 110 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
 | 
|---|
| 111 |         QWidget::focusInEvent(aE);
 | 
|---|
| 112 |     }
 | 
|---|
| 113 | 
 | 
|---|
| 114 |     void focusOutEvent(QFocusEvent *aE)
 | 
|---|
| 115 |     {
 | 
|---|
| 116 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
 | 
|---|
| 117 |         QWidget::focusOutEvent(aE);
 | 
|---|
| 118 |     }
 | 
|---|
| 119 | 
 | 
|---|
| 120 | private:
 | 
|---|
| 121 | 
 | 
|---|
| 122 |     int mPressed;
 | 
|---|
| 123 | };
 | 
|---|
| 124 | 
 | 
|---|
| 125 | ////////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 126 | 
 | 
|---|
| 127 | class MyButton : public QPushButton
 | 
|---|
| 128 | {
 | 
|---|
| 129 | public:
 | 
|---|
| 130 | 
 | 
|---|
| 131 |     MyButton(QWidget *aParent) : QPushButton(aParent)
 | 
|---|
| 132 |     {
 | 
|---|
| 133 |         QMenu *menu = new QMenu(aParent);
 | 
|---|
| 134 |         menu->addAction(QLatin1String("Action &1"));
 | 
|---|
| 135 |         menu->addAction(QLatin1String("Action &2"));
 | 
|---|
| 136 |         setMenu(menu);
 | 
|---|
| 137 |     }
 | 
|---|
| 138 | 
 | 
|---|
| 139 | #if 0
 | 
|---|
| 140 |     void focusInEvent(QFocusEvent *aE)
 | 
|---|
| 141 |     {
 | 
|---|
| 142 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
 | 
|---|
| 143 |                  << "reason" << aE->reason()
 | 
|---|
| 144 |                  << "focus" << (qApp->focusWidget() ?
 | 
|---|
| 145 |                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
 | 
|---|
| 146 | 
 | 
|---|
| 147 |         QPushButton::focusInEvent(aE);
 | 
|---|
| 148 |     }
 | 
|---|
| 149 | 
 | 
|---|
| 150 |     void focusOutEvent(QFocusEvent *aE)
 | 
|---|
| 151 |     {
 | 
|---|
| 152 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
 | 
|---|
| 153 |                  << "reason" << aE->reason()
 | 
|---|
| 154 |                  << "focus" << (qApp->focusWidget() ?
 | 
|---|
| 155 |                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
 | 
|---|
| 156 |         QPushButton::focusOutEvent(aE);
 | 
|---|
| 157 |     }
 | 
|---|
| 158 | #endif
 | 
|---|
| 159 | };
 | 
|---|
| 160 | 
 | 
|---|
| 161 | 
 | 
|---|
| 162 | ////////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 163 | 
 | 
|---|
| 164 | class MyCombo : public QComboBox
 | 
|---|
| 165 | {
 | 
|---|
| 166 | public:
 | 
|---|
| 167 | 
 | 
|---|
| 168 |     MyCombo(QWidget *aParent) : QComboBox(aParent) {}
 | 
|---|
| 169 | 
 | 
|---|
| 170 | #if 0
 | 
|---|
| 171 |     void focusInEvent(QFocusEvent *aE)
 | 
|---|
| 172 |     {
 | 
|---|
| 173 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
 | 
|---|
| 174 |                  << "reason" << aE->reason()
 | 
|---|
| 175 |                  << "focus" << (qApp->focusWidget() ?
 | 
|---|
| 176 |                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
 | 
|---|
| 177 |         QComboBox::focusInEvent(aE);
 | 
|---|
| 178 |     }
 | 
|---|
| 179 | 
 | 
|---|
| 180 |     void focusOutEvent(QFocusEvent *aE)
 | 
|---|
| 181 |     {
 | 
|---|
| 182 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
 | 
|---|
| 183 |                  << "reason" << aE->reason()
 | 
|---|
| 184 |                  << "focus" << (qApp->focusWidget() ?
 | 
|---|
| 185 |                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
 | 
|---|
| 186 |         QComboBox::focusOutEvent(aE);
 | 
|---|
| 187 |     }
 | 
|---|
| 188 | #endif
 | 
|---|
| 189 | 
 | 
|---|
| 190 | #if 0
 | 
|---|
| 191 |     void resizeEvent(QResizeEvent *aE)
 | 
|---|
| 192 |     {
 | 
|---|
| 193 |         qDebug() << __FUNCTION__ << ":"  << currentText() << "g" << geometry() << "fg" << frameGeometry()
 | 
|---|
| 194 |                  << "sz" << aE->size() << "old" << aE->oldSize();
 | 
|---|
| 195 |     }
 | 
|---|
| 196 | 
 | 
|---|
| 197 |     void moveEvent(QMoveEvent *aE)
 | 
|---|
| 198 |     {
 | 
|---|
| 199 |         qDebug() << __FUNCTION__ << ":" << currentText() << " g" << geometry() << "fg" << frameGeometry()
 | 
|---|
| 200 |                  << "pos" << aE->pos() << "old" << aE->oldPos();
 | 
|---|
| 201 |     }
 | 
|---|
| 202 | #endif
 | 
|---|
| 203 | 
 | 
|---|
| 204 | #if 0
 | 
|---|
| 205 |     virtual void enterEvent(QEvent *event)
 | 
|---|
| 206 |     {
 | 
|---|
| 207 |         qDebug() << __FUNCTION__ << ":" << currentText();
 | 
|---|
| 208 |     }
 | 
|---|
| 209 | 
 | 
|---|
| 210 |     virtual void leaveEvent(QEvent *event)
 | 
|---|
| 211 |     {
 | 
|---|
| 212 |         qDebug() << __FUNCTION__ << ":" << currentText();
 | 
|---|
| 213 |     }
 | 
|---|
| 214 | #endif
 | 
|---|
| 215 | 
 | 
|---|
| 216 | #if 0
 | 
|---|
| 217 |     void mousePressEvent(QMouseEvent *aE)
 | 
|---|
| 218 |     {
 | 
|---|
| 219 |         qDebug() << __FUNCTION__ << ": btn" << aE->button()
 | 
|---|
| 220 |                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
 | 
|---|
| 221 |                                               (int) aE->buttons(), (int) aE->modifiers()))
 | 
|---|
| 222 |                  << "gpos" << aE->globalPos() << "pos" << aE->pos();
 | 
|---|
| 223 |         QComboBox::mousePressEvent(aE);
 | 
|---|
| 224 |     }
 | 
|---|
| 225 | 
 | 
|---|
| 226 |     void mouseReleaseEvent(QMouseEvent *aE)
 | 
|---|
| 227 |     {
 | 
|---|
| 228 |         qDebug() << __FUNCTION__ << ": btn" << aE->button()
 | 
|---|
| 229 |                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
 | 
|---|
| 230 |                                               (int) aE->buttons(), (int) aE->modifiers()))
 | 
|---|
| 231 |                  << "gpos" << aE->globalPos() << "pos" << aE->pos();
 | 
|---|
| 232 |         QComboBox::mouseReleaseEvent(aE);
 | 
|---|
| 233 |     }
 | 
|---|
| 234 | 
 | 
|---|
| 235 |     void contextMenuEvent(QContextMenuEvent *aE)
 | 
|---|
| 236 |     {
 | 
|---|
| 237 |         QMenu menu;
 | 
|---|
| 238 |         menu.addAction(QLatin1String("Action &1"));
 | 
|---|
| 239 |         menu.addAction(QLatin1String("Action &2"));
 | 
|---|
| 240 |         menu.exec(aE->globalPos());
 | 
|---|
| 241 |         winId();
 | 
|---|
| 242 |     }
 | 
|---|
| 243 | #endif
 | 
|---|
| 244 | };
 | 
|---|
| 245 | 
 | 
|---|
| 246 | ////////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 247 | 
 | 
|---|
| 248 | class MyWidget : public QWidget
 | 
|---|
| 249 | {
 | 
|---|
| 250 | public:
 | 
|---|
| 251 | 
 | 
|---|
| 252 |     MyWidget() : mPressed(0)
 | 
|---|
| 253 |     {
 | 
|---|
| 254 | #if 0
 | 
|---|
| 255 |         MyButton *btn1 = new MyButton(this);
 | 
|---|
| 256 |         btn1->setText(QLatin1String("&Hello (also Ctrl+H)"));
 | 
|---|
| 257 |         btn1->setObjectName("Hello");
 | 
|---|
| 258 |         btn1->move(20, 20);
 | 
|---|
| 259 | 
 | 
|---|
| 260 |         connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_H), btn1),
 | 
|---|
| 261 |                 SIGNAL(activated()), btn1, SLOT(animateClick()));
 | 
|---|
| 262 | 
 | 
|---|
| 263 |         MyButton *btn2 = new MyButton(this);
 | 
|---|
| 264 |         btn2->setText(QString::fromUtf16((const ushort *)L"&\u041f\u0440\u0438\u0432\u0435\u0442 (also Ctrl+\u041f)"));
 | 
|---|
| 265 |         btn2->setObjectName(QString::fromUtf16((const ushort *)L"\u041f\u0440\u0438\u0432\u0435\u0442"));
 | 
|---|
| 266 |         btn2->move(20, 60);
 | 
|---|
| 267 | 
 | 
|---|
| 268 |         connect(new QShortcut(QKeySequence(Qt::CTRL + 0x041F), btn2),
 | 
|---|
| 269 |                 SIGNAL(activated()), btn2, SLOT(animateClick()));
 | 
|---|
| 270 | 
 | 
|---|
| 271 | //      QComboBox *cb1 = new MyCombo(this);
 | 
|---|
| 272 | //      cb1->addItem(QLatin1String("Test 1"));
 | 
|---|
| 273 | //      cb1->addItem(QLatin1String("Test 2"));
 | 
|---|
| 274 | 
 | 
|---|
| 275 | //      QComboBox *cb2 = new MyCombo(this);
 | 
|---|
| 276 | //      cb2->addItem(QLatin1String("Test 3"));
 | 
|---|
| 277 | //      cb2->addItem(QLatin1String("Test 4"));
 | 
|---|
| 278 | 
 | 
|---|
| 279 |         QVBoxLayout *mainLayout = new QVBoxLayout();
 | 
|---|
| 280 |         mainLayout->addWidget(btn1);
 | 
|---|
| 281 |         mainLayout->addWidget(btn2);
 | 
|---|
| 282 | //      mainLayout->addWidget(cb1);
 | 
|---|
| 283 | //      mainLayout->addWidget(cb2);
 | 
|---|
| 284 | 
 | 
|---|
| 285 |         setLayout(mainLayout);
 | 
|---|
| 286 | #endif
 | 
|---|
| 287 | 
 | 
|---|
| 288 | #if 0
 | 
|---|
| 289 |         QMenuBar *mb = new QMenuBar(this);
 | 
|---|
| 290 | 
 | 
|---|
| 291 |         QMenu *menu = new QMenu(mb);
 | 
|---|
| 292 |         menu->setTitle ("Menu &1");
 | 
|---|
| 293 |         menu->addAction(QLatin1String("Action &1"));
 | 
|---|
| 294 |         menu->addAction(QLatin1String("Action &2"));
 | 
|---|
| 295 |         mb->addMenu(menu);
 | 
|---|
| 296 | 
 | 
|---|
| 297 |         menu = new QMenu(mb);
 | 
|---|
| 298 |         menu->setTitle ("Menu &2");
 | 
|---|
| 299 |         menu->addAction(QLatin1String("Action &1"));
 | 
|---|
| 300 |         menu->addAction(QLatin1String("Action &2"));
 | 
|---|
| 301 |         mb->addMenu(menu);
 | 
|---|
| 302 | 
 | 
|---|
| 303 |         menu = new QMenu(mb);
 | 
|---|
| 304 |         menu->setTitle ("Menu &3");
 | 
|---|
| 305 |         menu->addAction(QLatin1String("Action &1"));
 | 
|---|
| 306 |         menu->addAction(QLatin1String("Action &2"));
 | 
|---|
| 307 |         mb->addMenu(menu);
 | 
|---|
| 308 | #endif
 | 
|---|
| 309 | 
 | 
|---|
| 310 | #if 0
 | 
|---|
| 311 |         new MyChild(this);
 | 
|---|
| 312 | #endif
 | 
|---|
| 313 | 
 | 
|---|
| 314 |     };
 | 
|---|
| 315 | 
 | 
|---|
| 316 | #if 0
 | 
|---|
| 317 |     void closeEvent(QCloseEvent *aE)
 | 
|---|
| 318 |     {
 | 
|---|
| 319 |         QMessageBox::warning(this, QLatin1String("Close"),
 | 
|---|
| 320 |                              QLatin1String("Somebody asked us to terminate"));
 | 
|---|
| 321 |         aE->accept();
 | 
|---|
| 322 |     }
 | 
|---|
| 323 | #endif
 | 
|---|
| 324 | 
 | 
|---|
| 325 | #if 0
 | 
|---|
| 326 |     void paintEvent(QPaintEvent *aE)
 | 
|---|
| 327 |     {
 | 
|---|
| 328 |         qDebug() << __FUNCTION__ <<": " << aE->rect();
 | 
|---|
| 329 | 
 | 
|---|
| 330 |         QPainter p(this);
 | 
|---|
| 331 | #if 0
 | 
|---|
| 332 |         // simple QPainter test
 | 
|---|
| 333 | 
 | 
|---|
| 334 |         p.setRenderHint(QPainter::Antialiasing);
 | 
|---|
| 335 | 
 | 
|---|
| 336 |         p.fillRect(0, 0, 20, 20, mPressed % 2 ? Qt::red : Qt::green);
 | 
|---|
| 337 | 
 | 
|---|
| 338 |         p.setPen(Qt::black);
 | 
|---|
| 339 |         p.drawEllipse(10, 10, 10, 10);
 | 
|---|
| 340 | 
 | 
|---|
| 341 |         //p.setFont(QFont("Arial", 12));
 | 
|---|
| 342 |         p.drawText(10, 30, QLatin1String("ABC"));
 | 
|---|
| 343 | #endif
 | 
|---|
| 344 | #if 0
 | 
|---|
| 345 |         // simple QClipboard image test
 | 
|---|
| 346 | 
 | 
|---|
| 347 |         const QMimeData *data = QApplication::clipboard()->mimeData();
 | 
|---|
| 348 |         if (data && data->hasImage()){
 | 
|---|
| 349 |             QImage img = qvariant_cast<QImage>(data->imageData());
 | 
|---|
| 350 |             p.drawImage(0, 0, img);
 | 
|---|
| 351 |         }
 | 
|---|
| 352 | #endif
 | 
|---|
| 353 |     }
 | 
|---|
| 354 | #endif
 | 
|---|
| 355 | 
 | 
|---|
| 356 | #if 0
 | 
|---|
| 357 |     void resizeEvent(QResizeEvent *aE)
 | 
|---|
| 358 |     {
 | 
|---|
| 359 |         qDebug() << __FUNCTION__ << ": g" << geometry() << "fg" << frameGeometry()
 | 
|---|
| 360 |                  << "sz" << aE->size() << "old" << aE->oldSize();
 | 
|---|
| 361 |     }
 | 
|---|
| 362 | 
 | 
|---|
| 363 |     void moveEvent(QMoveEvent *aE)
 | 
|---|
| 364 |     {
 | 
|---|
| 365 |         qDebug() << __FUNCTION__ << ": g" << geometry() << "fg" << frameGeometry()
 | 
|---|
| 366 |                  << "pos" << aE->pos() << "old" << aE->oldPos();
 | 
|---|
| 367 |     }
 | 
|---|
| 368 | #endif
 | 
|---|
| 369 | 
 | 
|---|
| 370 | #if 0
 | 
|---|
| 371 |     void focusInEvent(QFocusEvent *aE)
 | 
|---|
| 372 |     {
 | 
|---|
| 373 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
 | 
|---|
| 374 |         QWidget::focusInEvent(aE);
 | 
|---|
| 375 |     }
 | 
|---|
| 376 | 
 | 
|---|
| 377 |     void focusOutEvent(QFocusEvent *aE)
 | 
|---|
| 378 |     {
 | 
|---|
| 379 |         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
 | 
|---|
| 380 |         QWidget::focusOutEvent(aE);
 | 
|---|
| 381 |     }
 | 
|---|
| 382 | #endif
 | 
|---|
| 383 | 
 | 
|---|
| 384 | #if 0
 | 
|---|
| 385 |     void changeEvent(QEvent *aE)
 | 
|---|
| 386 |     {
 | 
|---|
| 387 |         switch (aE->type()) {
 | 
|---|
| 388 |         case QEvent::WindowStateChange: {
 | 
|---|
| 389 |             QWindowStateChangeEvent *e2 = (QWindowStateChangeEvent *)aE;
 | 
|---|
| 390 |             qDebug().nospace() << __FUNCTION__ << ": QWindowStateChangeEvent(" <<
 | 
|---|
| 391 |                 e2->oldState() << "->" << windowState() << ")";
 | 
|---|
| 392 |             break;
 | 
|---|
| 393 |         }
 | 
|---|
| 394 |         default:
 | 
|---|
| 395 |             break;
 | 
|---|
| 396 |         }
 | 
|---|
| 397 |     }
 | 
|---|
| 398 | #endif
 | 
|---|
| 399 | 
 | 
|---|
| 400 | #if 0
 | 
|---|
| 401 |     void keyPressEvent(QKeyEvent *aE)
 | 
|---|
| 402 |     {
 | 
|---|
| 403 |         qDebug() << __FUNCTION__ << "  : cnt" << aE->count()
 | 
|---|
| 404 |                  << "rep" << aE->isAutoRepeat()
 | 
|---|
| 405 |                  << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
 | 
|---|
| 406 |                  << "text" << aE->text()
 | 
|---|
| 407 |                  << QDbgStr(aE->text().isEmpty() ? QString() :
 | 
|---|
| 408 |                             QString().sprintf("(%04X)", aE->text()[0].unicode()));
 | 
|---|
| 409 |     }
 | 
|---|
| 410 | 
 | 
|---|
| 411 |     void keyReleaseEvent(QKeyEvent *aE)
 | 
|---|
| 412 |     {
 | 
|---|
| 413 |         qDebug() << __FUNCTION__ << ": cnt" << aE->count()
 | 
|---|
| 414 |                  << "rep" << aE->isAutoRepeat()
 | 
|---|
| 415 |                  << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
 | 
|---|
| 416 |                  << "text" << aE->text()
 | 
|---|
| 417 |                  << QDbgStr(aE->text().isEmpty() ? QString() :
 | 
|---|
| 418 |                             QString().sprintf("(%04X)", aE->text()[0].unicode()));
 | 
|---|
| 419 |     }
 | 
|---|
| 420 | #endif
 | 
|---|
| 421 | 
 | 
|---|
| 422 | #if 0
 | 
|---|
| 423 |     // QCursor shape test
 | 
|---|
| 424 |     void mousePressEvent(QMouseEvent *aE)
 | 
|---|
| 425 |     {
 | 
|---|
| 426 |         static int shape = 0;
 | 
|---|
| 427 |         if (aE->button() == Qt::LeftButton)
 | 
|---|
| 428 |             ++shape;
 | 
|---|
| 429 |         else
 | 
|---|
| 430 |             --shape;
 | 
|---|
| 431 |         shape = (Qt::LastCursor + 1 + shape) % (Qt::LastCursor + 1);
 | 
|---|
| 432 |         setCursor(QCursor((Qt::CursorShape)shape));
 | 
|---|
| 433 |     }
 | 
|---|
| 434 | #endif
 | 
|---|
| 435 | 
 | 
|---|
| 436 | #if 0
 | 
|---|
| 437 |     void mousePressEvent(QMouseEvent *aE)
 | 
|---|
| 438 |     {
 | 
|---|
| 439 |         qDebug() << __FUNCTION__ << ": btn" << aE->button()
 | 
|---|
| 440 |                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
 | 
|---|
| 441 |                                               (int) aE->buttons(), (int) aE->modifiers()))
 | 
|---|
| 442 |                  << "gpos" << aE->globalPos() << "pos" << aE->pos();
 | 
|---|
| 443 | 
 | 
|---|
| 444 |         ++mPressed;
 | 
|---|
| 445 |         update();
 | 
|---|
| 446 |     }
 | 
|---|
| 447 | 
 | 
|---|
| 448 |     void mouseReleaseEvent(QMouseEvent *aE)
 | 
|---|
| 449 |     {
 | 
|---|
| 450 |         qDebug() << __FUNCTION__ << ": btn" << aE->button()
 | 
|---|
| 451 |                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
 | 
|---|
| 452 |                                               (int) aE->buttons(), (int) aE->modifiers()))
 | 
|---|
| 453 |                  << "gpos" << aE->globalPos() << "pos" << aE->pos();
 | 
|---|
| 454 |     }
 | 
|---|
| 455 | 
 | 
|---|
| 456 |     void mouseMoveEvent(QMouseEvent *aE)
 | 
|---|
| 457 |     {
 | 
|---|
| 458 |         qDebug() << __FUNCTION__ << ": btn" << aE->button()
 | 
|---|
| 459 |                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
 | 
|---|
| 460 |                                               (int) aE->buttons(), (int) aE->modifiers()))
 | 
|---|
| 461 |                  << "gpos" << aE->globalPos() << "pos" << aE->pos();
 | 
|---|
| 462 |     }
 | 
|---|
| 463 | #endif
 | 
|---|
| 464 | 
 | 
|---|
| 465 | #if 0
 | 
|---|
| 466 |     virtual void enterEvent(QEvent *event)
 | 
|---|
| 467 |     {
 | 
|---|
| 468 |         qDebug() << __FUNCTION__ << ":";
 | 
|---|
| 469 |     }
 | 
|---|
| 470 | 
 | 
|---|
| 471 |     virtual void leaveEvent(QEvent *event)
 | 
|---|
| 472 |     {
 | 
|---|
| 473 |         qDebug() << __FUNCTION__ << ":";
 | 
|---|
| 474 |     }
 | 
|---|
| 475 | #endif
 | 
|---|
| 476 | 
 | 
|---|
| 477 | #if 0
 | 
|---|
| 478 |     void contextMenuEvent(QContextMenuEvent *aE)
 | 
|---|
| 479 |     {
 | 
|---|
| 480 |         QMenu menu;
 | 
|---|
| 481 |         menu.addAction(QLatin1String("Action &1"));
 | 
|---|
| 482 |         menu.addAction(QLatin1String("Action &2"));
 | 
|---|
| 483 |         menu.exec(aE->globalPos());
 | 
|---|
| 484 |     }
 | 
|---|
| 485 | #endif
 | 
|---|
| 486 | 
 | 
|---|
| 487 | #if 0
 | 
|---|
| 488 |     void timerEvent(QTimerEvent *aE)
 | 
|---|
| 489 |     {
 | 
|---|
| 490 |         qDebug() << __FUNCTION__ << ": id" << aE->timerId();
 | 
|---|
| 491 |     }
 | 
|---|
| 492 | #endif
 | 
|---|
| 493 | 
 | 
|---|
| 494 |     bool event(QEvent *aE)
 | 
|---|
| 495 |     {
 | 
|---|
| 496 |         switch (aE->type())
 | 
|---|
| 497 |         {
 | 
|---|
| 498 | #if 0
 | 
|---|
| 499 |         case QEvent::Enter:
 | 
|---|
| 500 |             qDebug() << this << "Enter";
 | 
|---|
| 501 |             break;
 | 
|---|
| 502 |         case QEvent::Leave:
 | 
|---|
| 503 |             qDebug() << this << "Leave";
 | 
|---|
| 504 |             break;
 | 
|---|
| 505 |         case QEvent::NonClientAreaMouseMove:
 | 
|---|
| 506 |         case QEvent::NonClientAreaMouseButtonPress:
 | 
|---|
| 507 |         case QEvent::NonClientAreaMouseButtonRelease:
 | 
|---|
| 508 |         case QEvent::NonClientAreaMouseButtonDblClick: {
 | 
|---|
| 509 |             QMouseEvent *me = static_cast<QMouseEvent*>(aE);
 | 
|---|
| 510 |             qDebug() << this << aE->type() << ": btn" << me->button()
 | 
|---|
| 511 |                      << QDbgStr(QString().sprintf("btns %08X mods %08X",
 | 
|---|
| 512 |                                                   (int) me->buttons(), (int) me->modifiers()))
 | 
|---|
| 513 |                      << "gpos" << me->globalPos() << "pos" << me->pos();
 | 
|---|
| 514 |             break;
 | 
|---|
| 515 |         }
 | 
|---|
| 516 | #endif
 | 
|---|
| 517 |         default:
 | 
|---|
| 518 |             break;
 | 
|---|
| 519 |         }
 | 
|---|
| 520 | 
 | 
|---|
| 521 |         return QWidget::event(aE);
 | 
|---|
| 522 |     }
 | 
|---|
| 523 | 
 | 
|---|
| 524 | private:
 | 
|---|
| 525 | 
 | 
|---|
| 526 |     int mPressed;
 | 
|---|
| 527 | };
 | 
|---|
| 528 | 
 | 
|---|
| 529 | void testCodec(const char *title, const QString &sample, QTextCodec *codec)
 | 
|---|
| 530 | {
 | 
|---|
| 531 |     // test console output
 | 
|---|
| 532 | 
 | 
|---|
| 533 |     printf("%s : Unicode (source) : ", title);
 | 
|---|
| 534 |     foreach (QChar ch, sample)
 | 
|---|
| 535 |         printf("%hX ", ch.unicode());
 | 
|---|
| 536 |     printf("\n");
 | 
|---|
| 537 | 
 | 
|---|
| 538 |     QByteArray eightbit = codec->fromUnicode(sample);
 | 
|---|
| 539 |     printf("%s : 8-bit (as is)    : %s\n", title, eightbit.data());
 | 
|---|
| 540 | 
 | 
|---|
| 541 |     QString sample2 = codec->toUnicode(eightbit);
 | 
|---|
| 542 |     printf("%s : Unicode (result) : ", title);
 | 
|---|
| 543 |     foreach (QChar ch, sample2)
 | 
|---|
| 544 |         printf("%hX ", ch.unicode());
 | 
|---|
| 545 |     printf("\n");
 | 
|---|
| 546 | 
 | 
|---|
| 547 |     if (sample != sample2)
 | 
|---|
| 548 |         qWarning() << "Source and resulting Unicode differ!";
 | 
|---|
| 549 | 
 | 
|---|
| 550 |     qWarning() << "";
 | 
|---|
| 551 | 
 | 
|---|
| 552 |     // test GUI output (both window title and window text)
 | 
|---|
| 553 | 
 | 
|---|
| 554 |     QString combined = QString("%1 : %2").arg(QLatin1String(title), sample);
 | 
|---|
| 555 |     QMessageBox mbox;
 | 
|---|
| 556 |     mbox.setWindowTitle(combined);
 | 
|---|
| 557 |     mbox.setText(combined);
 | 
|---|
| 558 |     mbox.exec();
 | 
|---|
| 559 | }
 | 
|---|
| 560 | 
 | 
|---|
| 561 | int main(int argc, char **argv)
 | 
|---|
| 562 | {
 | 
|---|
| 563 | #if 1
 | 
|---|
| 564 |     ////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 565 |     // Text mode
 | 
|---|
| 566 | 
 | 
|---|
| 567 |     QCoreApplication app(argc, argv);
 | 
|---|
| 568 | 
 | 
|---|
| 569 | #if 1
 | 
|---|
| 570 |     //--------------------------------------------------------------------------
 | 
|---|
| 571 |     // QFileInfo test
 | 
|---|
| 572 |     PRINT_EXPR(QFileInfo(QLatin1String("../../qt4/src/corelib/global/qt_windows.h")).isExecutable());
 | 
|---|
| 573 |     PRINT_EXPR(QFileInfo(QLatin1String("../../qt4/src/corelib/global/qt_os2.h")).isExecutable());
 | 
|---|
| 574 |     PRINT_EXPR(QFileInfo(QLatin1String("../../qt4/configure.cmd")).isExecutable());
 | 
|---|
| 575 |     PRINT_EXPR(QFileInfo(QLatin1String("../../qt4/configure.exe")).isExecutable());
 | 
|---|
| 576 |     PRINT_EXPR(QFileInfo(QLatin1String("../../qt4/bin/qmake.exe")).isExecutable());
 | 
|---|
| 577 |     PRINT_EXPR(QFileInfo(QLatin1String("../../qt4/bin/QtCore4.dll")).isExecutable());
 | 
|---|
| 578 |     PRINT_EXPR(QFileInfo(QLatin1String("../../qt4/bin")).isExecutable());
 | 
|---|
| 579 | #endif
 | 
|---|
| 580 | 
 | 
|---|
| 581 | #if 0
 | 
|---|
| 582 |     //--------------------------------------------------------------------------
 | 
|---|
| 583 |     // QTextStream test
 | 
|---|
| 584 | 
 | 
|---|
| 585 |     QFile file("widget.cpp");
 | 
|---|
| 586 |     file.open(QIODevice::ReadOnly);
 | 
|---|
| 587 |     QTextStream text(&file);
 | 
|---|
| 588 |     QString str = text.readAll();
 | 
|---|
| 589 |     file.close();
 | 
|---|
| 590 |     qWarning() << "Read" << str.length() << "chars from widget.cpp";
 | 
|---|
| 591 | #endif
 | 
|---|
| 592 | 
 | 
|---|
| 593 | #if 0
 | 
|---|
| 594 |     //--------------------------------------------------------------------------
 | 
|---|
| 595 |     // absolute/relative path test
 | 
|---|
| 596 |     qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("../aaa"));
 | 
|---|
| 597 |     qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("aaa"));
 | 
|---|
| 598 |     qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("/aaa"));
 | 
|---|
| 599 |     qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("\\aaa"));
 | 
|---|
| 600 |     qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:\\aaa"));
 | 
|---|
| 601 |     qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:aaa"));
 | 
|---|
| 602 | 
 | 
|---|
| 603 |     qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("../aaa"));
 | 
|---|
| 604 |     qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("aaa"));
 | 
|---|
| 605 |     qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("/aaa"));
 | 
|---|
| 606 |     qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("\\aaa"));
 | 
|---|
| 607 |     qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:\\aaa"));
 | 
|---|
| 608 |     qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:aaa"));
 | 
|---|
| 609 | 
 | 
|---|
| 610 |     qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("../aaa"));
 | 
|---|
| 611 |     qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("aaa"));
 | 
|---|
| 612 |     qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("/aaa"));
 | 
|---|
| 613 |     qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("\\aaa"));
 | 
|---|
| 614 |     qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:\\aaa"));
 | 
|---|
| 615 |     qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
 | 
|---|
| 616 | 
 | 
|---|
| 617 |     qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
 | 
|---|
| 618 |     qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("bbb"));
 | 
|---|
| 619 |     qWarning() << "4" << QDir(QLatin1String("C:bbb")).absoluteFilePath(QLatin1String("bbb"));
 | 
|---|
| 620 | #endif
 | 
|---|
| 621 | 
 | 
|---|
| 622 | #if 0
 | 
|---|
| 623 |     //--------------------------------------------------------------------------
 | 
|---|
| 624 |     // QDir::mkdir/mkpath test
 | 
|---|
| 625 |     PRINT_EXPR(QDir().mkdir("some_dir"));
 | 
|---|
| 626 |     PRINT_EXPR(QFile::exists("some_dir"));
 | 
|---|
| 627 |     PRINT_EXPR(QDir().rmdir("some_dir"));
 | 
|---|
| 628 | 
 | 
|---|
| 629 |     PRINT_EXPR(QDir().mkdir("some_dir/subdir"));
 | 
|---|
| 630 |     PRINT_EXPR(QFile::exists("some_dir/subdir"));
 | 
|---|
| 631 |     PRINT_EXPR(QDir().rmdir("some_dir/subdir"));
 | 
|---|
| 632 | 
 | 
|---|
| 633 |     PRINT_EXPR(QDir().mkpath("some_dir/subdir"));
 | 
|---|
| 634 |     PRINT_EXPR(QFile::exists("some_dir/subdir"));
 | 
|---|
| 635 |     PRINT_EXPR(QDir().rmpath("some_dir/subdir"));
 | 
|---|
| 636 | 
 | 
|---|
| 637 |     PRINT_EXPR(QDir("C:/").mkpath("some_dir/subdir"));
 | 
|---|
| 638 |     PRINT_EXPR(QFile::exists("C:/some_dir/subdir"));
 | 
|---|
| 639 |     PRINT_EXPR(QDir("C:/").rmpath("some_dir/subdir"));
 | 
|---|
| 640 | 
 | 
|---|
| 641 |     PRINT_EXPR(QDir("C:/").mkdir("/aaa"));
 | 
|---|
| 642 |     PRINT_EXPR(QFile::exists("C:/aaa"));
 | 
|---|
| 643 |     PRINT_EXPR(QDir("C:/").rmdir("/aaa"));
 | 
|---|
| 644 | #endif
 | 
|---|
| 645 | 
 | 
|---|
| 646 | #if 0
 | 
|---|
| 647 |     //--------------------------------------------------------------------------
 | 
|---|
| 648 |     // QLibraryInfo test
 | 
|---|
| 649 |     qWarning() << "QLibraryInfo::buildKey :" << QLibraryInfo::buildKey();
 | 
|---|
| 650 |     qWarning() << "QLibraryInfo::licensedProducts :" << QLibraryInfo::licensedProducts();
 | 
|---|
| 651 |     qWarning() << "QLibraryInfo::licensee :" << QLibraryInfo::licensee();
 | 
|---|
| 652 |     #define PRINT_LOC(L) qWarning() << #L << ":" << QLibraryInfo::location(L)
 | 
|---|
| 653 |     PRINT_LOC(QLibraryInfo::PrefixPath);
 | 
|---|
| 654 |     PRINT_LOC(QLibraryInfo::DocumentationPath);
 | 
|---|
| 655 |     PRINT_LOC(QLibraryInfo::HeadersPath);
 | 
|---|
| 656 |     PRINT_LOC(QLibraryInfo::LibrariesPath);
 | 
|---|
| 657 |     PRINT_LOC(QLibraryInfo::BinariesPath);
 | 
|---|
| 658 |     PRINT_LOC(QLibraryInfo::PluginsPath);
 | 
|---|
| 659 |     PRINT_LOC(QLibraryInfo::DataPath);
 | 
|---|
| 660 |     PRINT_LOC(QLibraryInfo::TranslationsPath);
 | 
|---|
| 661 |     PRINT_LOC(QLibraryInfo::SettingsPath);
 | 
|---|
| 662 |     PRINT_LOC(QLibraryInfo::DemosPath);
 | 
|---|
| 663 |     PRINT_LOC(QLibraryInfo::ExamplesPath);
 | 
|---|
| 664 |     #undef PRINT_LOC
 | 
|---|
| 665 | #endif
 | 
|---|
| 666 | 
 | 
|---|
| 667 | #if 0
 | 
|---|
| 668 |     //--------------------------------------------------------------------------
 | 
|---|
| 669 |     // QSettings test
 | 
|---|
| 670 | 
 | 
|---|
| 671 |     QSettings sysOrgSet(QSettings::IniFormat, QSettings::SystemScope,
 | 
|---|
| 672 |                         QLatin1String("MySoft"));
 | 
|---|
| 673 |     QSettings sysAppSet(QSettings::IniFormat, QSettings::SystemScope,
 | 
|---|
| 674 |                         QLatin1String("MySoft"), QLatin1String("MyApp"));
 | 
|---|
| 675 |     QSettings userOrgSet(QSettings::IniFormat, QSettings::UserScope,
 | 
|---|
| 676 |                          QLatin1String("MySoft"));
 | 
|---|
| 677 |     QSettings userAppSet(QSettings::IniFormat, QSettings::UserScope,
 | 
|---|
| 678 |                          QLatin1String("MySoft"), QLatin1String("MyApp"));
 | 
|---|
| 679 | 
 | 
|---|
| 680 |     QList<QSettings *> sets;
 | 
|---|
| 681 |     sets << &sysOrgSet << &sysAppSet << &userOrgSet << &userAppSet;
 | 
|---|
| 682 | 
 | 
|---|
| 683 |     foreach (QSettings *set, sets) {
 | 
|---|
| 684 |         set->setValue("Time", QDateTime::currentDateTime());
 | 
|---|
| 685 |     }
 | 
|---|
| 686 | 
 | 
|---|
| 687 |     qWarning() << "Modified Time key in MySoft/MyApp (system & user)";
 | 
|---|
| 688 | #endif
 | 
|---|
| 689 | 
 | 
|---|
| 690 | #else
 | 
|---|
| 691 |     ////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 692 |     // GUI
 | 
|---|
| 693 | 
 | 
|---|
| 694 |     QApplication app(argc, argv);
 | 
|---|
| 695 |     app.setQuitOnLastWindowClosed(true);
 | 
|---|
| 696 | 
 | 
|---|
| 697 | #if 0
 | 
|---|
| 698 |     //--------------------------------------------------------------------------
 | 
|---|
| 699 |     // locale test
 | 
|---|
| 700 | 
 | 
|---|
| 701 |     QLocale locale = QLocale::system();
 | 
|---|
| 702 | 
 | 
|---|
| 703 |     qWarning() << "Library paths    :" << QApplication::libraryPaths();
 | 
|---|
| 704 |     qWarning() << "";
 | 
|---|
| 705 |     qWarning() << "Available codecs :\n" << QTextCodec::availableCodecs();
 | 
|---|
| 706 |     qWarning() << "";
 | 
|---|
| 707 |     qWarning() << "Codec for locale :" << QTextCodec::codecForLocale()->name();
 | 
|---|
| 708 |     qWarning() << "         Aliases :" << QTextCodec::codecForLocale()->aliases();
 | 
|---|
| 709 |     qWarning() << "";
 | 
|---|
| 710 |     qWarning() << "Country for locale  :" << QLocale::countryToString(locale.country())
 | 
|---|
| 711 |                                           << "[" << locale.country() << "]";
 | 
|---|
| 712 |     qWarning() << "Language for locale :" << QLocale::languageToString(locale.language())
 | 
|---|
| 713 |                                           << "[" << locale.language() << "]";
 | 
|---|
| 714 |     qWarning() << "";
 | 
|---|
| 715 | 
 | 
|---|
| 716 |     testCodec("First 3 months",
 | 
|---|
| 717 |               QString("%1, %2, %3").arg(locale.standaloneMonthName(1),
 | 
|---|
| 718 |                                         locale.standaloneMonthName(2),
 | 
|---|
| 719 |                                         locale.standaloneMonthName(3)),
 | 
|---|
| 720 |               QTextCodec::codecForLocale());
 | 
|---|
| 721 |     return 0;
 | 
|---|
| 722 | #endif
 | 
|---|
| 723 | 
 | 
|---|
| 724 | #if 0
 | 
|---|
| 725 |     QRect r = QApplication::desktop()->availableGeometry();
 | 
|---|
| 726 |     MyWidget widget;
 | 
|---|
| 727 |     widget.resize(100, 100);
 | 
|---|
| 728 |     widget.move(r.width() - 200, r.height() - 200);
 | 
|---|
| 729 | 
 | 
|---|
| 730 |     widget.show();
 | 
|---|
| 731 | #endif
 | 
|---|
| 732 | 
 | 
|---|
| 733 | #if 0
 | 
|---|
| 734 |     //--------------------------------------------------------------------------
 | 
|---|
| 735 |     // QDesktopServices test
 | 
|---|
| 736 |     {
 | 
|---|
| 737 |         for (int i = 0; i <= 10; ++i) {
 | 
|---|
| 738 |             qWarning() << "StandardLocation" << i
 | 
|---|
| 739 |                        << QDesktopServices::
 | 
|---|
| 740 |                 storageLocation((QDesktopServices::StandardLocation)i);
 | 
|---|
| 741 |         }
 | 
|---|
| 742 | 
 | 
|---|
| 743 |         PRINT_EXPR(QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::currentPath())));
 | 
|---|
| 744 |         PRINT_EXPR(QDesktopServices::openUrl(QUrl("file:///C:/OS2/BITMAP/OCEAN.BMP")));
 | 
|---|
| 745 |         PRINT_EXPR(QDesktopServices::openUrl(QUrl("mailto:user@example.com")));
 | 
|---|
| 746 |         PRINT_EXPR(QDesktopServices::openUrl(QUrl("http://www.ru")));
 | 
|---|
| 747 |     }
 | 
|---|
| 748 | #endif
 | 
|---|
| 749 | 
 | 
|---|
| 750 | #if 0
 | 
|---|
| 751 |     //--------------------------------------------------------------------------
 | 
|---|
| 752 |     // QFontDialog test
 | 
|---|
| 753 |     {
 | 
|---|
| 754 |         int appFont1, appFont2;
 | 
|---|
| 755 | 
 | 
|---|
| 756 |         PRINT_EXPR((appFont1 = QFontDatabase::addApplicationFont(
 | 
|---|
| 757 |             QLatin1String("fonts/Earthqua.ttf"))));
 | 
|---|
| 758 | 
 | 
|---|
| 759 |         QByteArray fontData;
 | 
|---|
| 760 |         QFile fontFile(QLatin1String("fonts/NATIONFD.TTF"));
 | 
|---|
| 761 |         if (fontFile.open(QIODevice::ReadOnly)) {
 | 
|---|
| 762 |             fontData = fontFile.readAll();
 | 
|---|
| 763 |             fontFile.close();
 | 
|---|
| 764 |         }
 | 
|---|
| 765 |         PRINT_EXPR((appFont2 = QFontDatabase::addApplicationFontFromData(fontData)));
 | 
|---|
| 766 | 
 | 
|---|
| 767 |         PRINT_EXPR(QFontDatabase::applicationFontFamilies(appFont1));
 | 
|---|
| 768 |         PRINT_EXPR(QFontDatabase::applicationFontFamilies(appFont2));
 | 
|---|
| 769 | 
 | 
|---|
| 770 |         QFontDialog fntDlg;
 | 
|---|
| 771 |         fntDlg.exec();
 | 
|---|
| 772 | 
 | 
|---|
| 773 |         PRINT_EXPR(QFontDatabase::removeApplicationFont(appFont1));
 | 
|---|
| 774 |         PRINT_EXPR(QFontDatabase::applicationFontFamilies(appFont1));
 | 
|---|
| 775 | 
 | 
|---|
| 776 |         fntDlg.exec();
 | 
|---|
| 777 | 
 | 
|---|
| 778 |         {
 | 
|---|
| 779 |             QFont font("MyCoolFont");
 | 
|---|
| 780 |             QFontInfo info(font);
 | 
|---|
| 781 |             qDebug() << info.family();
 | 
|---|
| 782 |         }
 | 
|---|
| 783 |     }
 | 
|---|
| 784 | #endif
 | 
|---|
| 785 | 
 | 
|---|
| 786 | #if 0
 | 
|---|
| 787 |     //--------------------------------------------------------------------------
 | 
|---|
| 788 |     // QFileDialog test
 | 
|---|
| 789 |     {
 | 
|---|
| 790 |         QFileDialog dlg;
 | 
|---|
| 791 | 
 | 
|---|
| 792 |         dlg.setFileMode(QFileDialog::ExistingFile);
 | 
|---|
| 793 |         //dlg.setFilter(QDir::Dirs | QDir::Files | QDir::Drives);
 | 
|---|
| 794 |         dlg.setNameFilter("*.exe");
 | 
|---|
| 795 |         dlg.selectFile("mplayer.exe");
 | 
|---|
| 796 |         dlg.exec();
 | 
|---|
| 797 | 
 | 
|---|
| 798 |         //PRINT_EXPR(QFileDialog::getOpenFileName());
 | 
|---|
| 799 |     }
 | 
|---|
| 800 | #endif
 | 
|---|
| 801 | 
 | 
|---|
| 802 | #if 0
 | 
|---|
| 803 |     QSound snd2("C:/MMOS2/SOUNDS/DESKTOP/dsk_shut.wav");
 | 
|---|
| 804 |     snd2.setLoops(2);
 | 
|---|
| 805 |     snd2.play();
 | 
|---|
| 806 | 
 | 
|---|
| 807 |     QSound snd1("C:/MMOS2/SOUNDS/DESKTOP/dsk_strt.wav");
 | 
|---|
| 808 |     snd1.setLoops(3);
 | 
|---|
| 809 |     snd1.play();
 | 
|---|
| 810 | #endif
 | 
|---|
| 811 | 
 | 
|---|
| 812 | #if 0
 | 
|---|
| 813 |     widget.startTimer(1000);
 | 
|---|
| 814 |     widget.startTimer(2000);
 | 
|---|
| 815 |     widget.startTimer(4000);
 | 
|---|
| 816 | #endif
 | 
|---|
| 817 | 
 | 
|---|
| 818 | #if 0
 | 
|---|
| 819 |     qDebug() << "------------- before min" << widget.geometry() << widget.frameGeometry();
 | 
|---|
| 820 |     widget.showMinimized();
 | 
|---|
| 821 |     qDebug() << "------------- after min" << widget.geometry() << widget.frameGeometry();
 | 
|---|
| 822 |     widget.move(100, 100);
 | 
|---|
| 823 |     qDebug() << "------------- after move" << widget.geometry() << widget.frameGeometry();
 | 
|---|
| 824 |     widget.showNormal();
 | 
|---|
| 825 |     qDebug() << "------------- after norm" << widget.geometry() << widget.frameGeometry();
 | 
|---|
| 826 |     widget.showFullScreen();
 | 
|---|
| 827 |     qDebug() << "------------- after full" << widget.geometry() << widget.frameGeometry();
 | 
|---|
| 828 | #endif
 | 
|---|
| 829 | 
 | 
|---|
| 830 |     bool haveVisibleTops = false;
 | 
|---|
| 831 |     foreach(QWidget *top, app.topLevelWidgets()) {
 | 
|---|
| 832 |         if (top->isVisible()) {
 | 
|---|
| 833 |             haveVisibleTops = true;
 | 
|---|
| 834 |             break;
 | 
|---|
| 835 |         }
 | 
|---|
| 836 |     }
 | 
|---|
| 837 | 
 | 
|---|
| 838 |     if (haveVisibleTops)
 | 
|---|
| 839 |         return app.exec();
 | 
|---|
| 840 | 
 | 
|---|
| 841 |     return 0;
 | 
|---|
| 842 | #endif
 | 
|---|
| 843 | }
 | 
|---|
| 844 | 
 | 
|---|
| 845 | #include "widget.moc"
 | 
|---|