[231] | 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 |
|
---|
[368] | 36 | #define PRINT_EXPR(e) qWarning() << #e << e
|
---|
[231] | 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 |
|
---|
[304] | 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 | ++mPressed;
|
---|
| 97 | update();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[311] | 100 | void mouseReleaseEvent(QMouseEvent *aE)
|
---|
| 101 | {
|
---|
| 102 | ++mPressed;
|
---|
| 103 | update();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[304] | 106 | void focusInEvent(QFocusEvent *aE)
|
---|
| 107 | {
|
---|
| 108 | qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
|
---|
| 109 | QWidget::focusInEvent(aE);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | void focusOutEvent(QFocusEvent *aE)
|
---|
| 113 | {
|
---|
| 114 | qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
|
---|
| 115 | QWidget::focusOutEvent(aE);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | private:
|
---|
| 119 |
|
---|
| 120 | int mPressed;
|
---|
| 121 | };
|
---|
| 122 |
|
---|
| 123 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 124 |
|
---|
[231] | 125 | class MyButton : public QPushButton
|
---|
| 126 | {
|
---|
| 127 | public:
|
---|
| 128 |
|
---|
[311] | 129 | MyButton(QWidget *aParent) : QPushButton(aParent)
|
---|
| 130 | {
|
---|
| 131 | QMenu *menu = new QMenu(aParent);
|
---|
| 132 | menu->addAction(QLatin1String("Action &1"));
|
---|
| 133 | menu->addAction(QLatin1String("Action &2"));
|
---|
| 134 | setMenu(menu);
|
---|
| 135 | }
|
---|
[231] | 136 |
|
---|
[304] | 137 | #if 0
|
---|
[231] | 138 | void focusInEvent(QFocusEvent *aE)
|
---|
| 139 | {
|
---|
[304] | 140 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
|
---|
| 141 | << "reason" << aE->reason()
|
---|
[231] | 142 | << "focus" << (qApp->focusWidget() ?
|
---|
| 143 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
---|
[304] | 144 |
|
---|
| 145 | QPushButton::focusInEvent(aE);
|
---|
[231] | 146 | }
|
---|
| 147 |
|
---|
| 148 | void focusOutEvent(QFocusEvent *aE)
|
---|
| 149 | {
|
---|
[304] | 150 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
|
---|
| 151 | << "reason" << aE->reason()
|
---|
[231] | 152 | << "focus" << (qApp->focusWidget() ?
|
---|
| 153 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
---|
[304] | 154 | QPushButton::focusOutEvent(aE);
|
---|
| 155 | }
|
---|
[231] | 156 | #endif
|
---|
| 157 | };
|
---|
| 158 |
|
---|
[304] | 159 |
|
---|
| 160 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 161 |
|
---|
[231] | 162 | class MyCombo : public QComboBox
|
---|
| 163 | {
|
---|
| 164 | public:
|
---|
| 165 |
|
---|
| 166 | MyCombo(QWidget *aParent) : QComboBox(aParent) {}
|
---|
| 167 |
|
---|
[304] | 168 | #if 0
|
---|
[231] | 169 | void focusInEvent(QFocusEvent *aE)
|
---|
| 170 | {
|
---|
[304] | 171 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
|
---|
| 172 | << "reason" << aE->reason()
|
---|
[231] | 173 | << "focus" << (qApp->focusWidget() ?
|
---|
| 174 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
---|
[304] | 175 | QComboBox::focusInEvent(aE);
|
---|
[231] | 176 | }
|
---|
| 177 |
|
---|
| 178 | void focusOutEvent(QFocusEvent *aE)
|
---|
| 179 | {
|
---|
[304] | 180 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
|
---|
| 181 | << "reason" << aE->reason()
|
---|
[231] | 182 | << "focus" << (qApp->focusWidget() ?
|
---|
| 183 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
---|
[304] | 184 | QComboBox::focusOutEvent(aE);
|
---|
| 185 | }
|
---|
[231] | 186 | #endif
|
---|
| 187 |
|
---|
| 188 | #if 0
|
---|
| 189 | void resizeEvent(QResizeEvent *aE)
|
---|
| 190 | {
|
---|
| 191 | qDebug() << __FUNCTION__ << ":" << currentText() << "g" << geometry() << "fg" << frameGeometry()
|
---|
| 192 | << "sz" << aE->size() << "old" << aE->oldSize();
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | void moveEvent(QMoveEvent *aE)
|
---|
| 196 | {
|
---|
| 197 | qDebug() << __FUNCTION__ << ":" << currentText() << " g" << geometry() << "fg" << frameGeometry()
|
---|
| 198 | << "pos" << aE->pos() << "old" << aE->oldPos();
|
---|
| 199 | }
|
---|
| 200 | #endif
|
---|
| 201 |
|
---|
| 202 | #if 0
|
---|
| 203 | virtual void enterEvent(QEvent *event)
|
---|
| 204 | {
|
---|
| 205 | qDebug() << __FUNCTION__ << ":" << currentText();
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | virtual void leaveEvent(QEvent *event)
|
---|
| 209 | {
|
---|
| 210 | qDebug() << __FUNCTION__ << ":" << currentText();
|
---|
| 211 | }
|
---|
| 212 | #endif
|
---|
| 213 |
|
---|
| 214 | #if 0
|
---|
| 215 | void mousePressEvent(QMouseEvent *aE)
|
---|
| 216 | {
|
---|
| 217 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 218 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 219 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 220 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
| 221 | QComboBox::mousePressEvent(aE);
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | void mouseReleaseEvent(QMouseEvent *aE)
|
---|
| 225 | {
|
---|
| 226 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 227 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 228 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 229 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
| 230 | QComboBox::mouseReleaseEvent(aE);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | void contextMenuEvent(QContextMenuEvent *aE)
|
---|
| 234 | {
|
---|
| 235 | QMenu menu;
|
---|
| 236 | menu.addAction(QLatin1String("Action &1"));
|
---|
| 237 | menu.addAction(QLatin1String("Action &2"));
|
---|
| 238 | menu.exec(aE->globalPos());
|
---|
| 239 | winId();
|
---|
| 240 | }
|
---|
| 241 | #endif
|
---|
| 242 | };
|
---|
| 243 |
|
---|
[304] | 244 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 245 |
|
---|
[231] | 246 | class MyWidget : public QWidget
|
---|
| 247 | {
|
---|
| 248 | public:
|
---|
| 249 |
|
---|
[304] | 250 | MyWidget() : mPressed(0)
|
---|
[231] | 251 | {
|
---|
[304] | 252 | // setFocusPolicy(Qt::StrongFocus);
|
---|
[231] | 253 |
|
---|
[311] | 254 | #if 0
|
---|
[304] | 255 | MyButton *btn1 = new MyButton(this);
|
---|
| 256 | btn1->setText(QLatin1String("Hello 1"));
|
---|
| 257 | btn1->setObjectName("Hello 1");
|
---|
| 258 | btn1->move(20, 20);
|
---|
| 259 | MyButton *btn2 = new MyButton(this);
|
---|
| 260 | btn2->setText(QLatin1String("Hello 2"));
|
---|
| 261 | btn2->setObjectName("Hello 2");
|
---|
| 262 | btn2->move(20, 60);
|
---|
[231] | 263 |
|
---|
[304] | 264 | // QComboBox *cb1 = new MyCombo(this);
|
---|
| 265 | // cb1->addItem(QLatin1String("Test 1"));
|
---|
| 266 | // cb1->addItem(QLatin1String("Test 2"));
|
---|
[231] | 267 |
|
---|
| 268 | // QComboBox *cb2 = new MyCombo(this);
|
---|
| 269 | // cb2->addItem(QLatin1String("Test 3"));
|
---|
| 270 | // cb2->addItem(QLatin1String("Test 4"));
|
---|
| 271 |
|
---|
[304] | 272 | // QVBoxLayout *mainLayout = new QVBoxLayout();
|
---|
[231] | 273 | // mainLayout->addWidget(btn1);
|
---|
| 274 | // mainLayout->addWidget(btn2);
|
---|
[304] | 275 | // mainLayout->addWidget(cb1);
|
---|
[231] | 276 | // mainLayout->addWidget(cb2);
|
---|
| 277 |
|
---|
[304] | 278 | // setLayout(mainLayout);
|
---|
[311] | 279 | #endif
|
---|
[304] | 280 |
|
---|
[341] | 281 | #if 0
|
---|
[311] | 282 | QMenuBar *mb = new QMenuBar(this);
|
---|
| 283 |
|
---|
| 284 | QMenu *menu = new QMenu(mb);
|
---|
| 285 | menu->setTitle ("Menu &1");
|
---|
| 286 | menu->addAction(QLatin1String("Action &1"));
|
---|
| 287 | menu->addAction(QLatin1String("Action &2"));
|
---|
| 288 | mb->addMenu(menu);
|
---|
| 289 |
|
---|
| 290 | menu = new QMenu(mb);
|
---|
| 291 | menu->setTitle ("Menu &2");
|
---|
| 292 | menu->addAction(QLatin1String("Action &1"));
|
---|
| 293 | menu->addAction(QLatin1String("Action &2"));
|
---|
| 294 | mb->addMenu(menu);
|
---|
| 295 |
|
---|
| 296 | menu = new QMenu(mb);
|
---|
| 297 | menu->setTitle ("Menu &3");
|
---|
| 298 | menu->addAction(QLatin1String("Action &1"));
|
---|
| 299 | menu->addAction(QLatin1String("Action &2"));
|
---|
| 300 | mb->addMenu(menu);
|
---|
| 301 | #endif
|
---|
| 302 |
|
---|
[304] | 303 | #if 0
|
---|
| 304 | new MyChild(this);
|
---|
| 305 | #endif
|
---|
| 306 |
|
---|
[231] | 307 | };
|
---|
| 308 |
|
---|
[368] | 309 | #if 0
|
---|
[231] | 310 | void paintEvent(QPaintEvent *aE)
|
---|
| 311 | {
|
---|
| 312 | qDebug() << __FUNCTION__ <<": " << aE->rect();
|
---|
| 313 |
|
---|
| 314 | QPainter p(this);
|
---|
[346] | 315 | #if 0
|
---|
| 316 | // simple QPainter test
|
---|
| 317 |
|
---|
[231] | 318 | p.setRenderHint(QPainter::Antialiasing);
|
---|
| 319 |
|
---|
[304] | 320 | p.fillRect(0, 0, 20, 20, mPressed % 2 ? Qt::red : Qt::green);
|
---|
[231] | 321 |
|
---|
| 322 | p.setPen(Qt::black);
|
---|
| 323 | p.drawEllipse(10, 10, 10, 10);
|
---|
| 324 |
|
---|
| 325 | //p.setFont(QFont("Arial", 12));
|
---|
| 326 | p.drawText(10, 30, QLatin1String("ABC"));
|
---|
[346] | 327 | #endif
|
---|
[368] | 328 | #if 0
|
---|
[346] | 329 | // simple QClipboard image test
|
---|
| 330 |
|
---|
| 331 | const QMimeData *data = QApplication::clipboard()->mimeData();
|
---|
| 332 | if (data && data->hasImage()){
|
---|
| 333 | QImage img = qvariant_cast<QImage>(data->imageData());
|
---|
| 334 | p.drawImage(0, 0, img);
|
---|
| 335 | }
|
---|
| 336 | #endif
|
---|
[231] | 337 | }
|
---|
| 338 | #endif
|
---|
| 339 |
|
---|
| 340 | #if 0
|
---|
| 341 | void resizeEvent(QResizeEvent *aE)
|
---|
| 342 | {
|
---|
| 343 | qDebug() << __FUNCTION__ << ": g" << geometry() << "fg" << frameGeometry()
|
---|
| 344 | << "sz" << aE->size() << "old" << aE->oldSize();
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | void moveEvent(QMoveEvent *aE)
|
---|
| 348 | {
|
---|
| 349 | qDebug() << __FUNCTION__ << ": g" << geometry() << "fg" << frameGeometry()
|
---|
| 350 | << "pos" << aE->pos() << "old" << aE->oldPos();
|
---|
| 351 | }
|
---|
| 352 | #endif
|
---|
| 353 |
|
---|
| 354 | #if 0
|
---|
| 355 | void focusInEvent(QFocusEvent *aE)
|
---|
| 356 | {
|
---|
[304] | 357 | qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
|
---|
| 358 | QWidget::focusInEvent(aE);
|
---|
[231] | 359 | }
|
---|
| 360 |
|
---|
| 361 | void focusOutEvent(QFocusEvent *aE)
|
---|
| 362 | {
|
---|
[304] | 363 | qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
|
---|
| 364 | QWidget::focusOutEvent(aE);
|
---|
[231] | 365 | }
|
---|
| 366 | #endif
|
---|
| 367 |
|
---|
| 368 | #if 0
|
---|
| 369 | void changeEvent(QEvent *aE)
|
---|
| 370 | {
|
---|
| 371 | switch (aE->type()) {
|
---|
| 372 | case QEvent::WindowStateChange: {
|
---|
| 373 | QWindowStateChangeEvent *e2 = (QWindowStateChangeEvent *)aE;
|
---|
| 374 | qDebug().nospace() << __FUNCTION__ << ": QWindowStateChangeEvent(" <<
|
---|
| 375 | e2->oldState() << "->" << windowState() << ")";
|
---|
| 376 | break;
|
---|
| 377 | }
|
---|
| 378 | default:
|
---|
| 379 | break;
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 | #endif
|
---|
| 383 |
|
---|
| 384 | #if 0
|
---|
| 385 | void keyPressEvent(QKeyEvent *aE)
|
---|
| 386 | {
|
---|
| 387 | qDebug() << __FUNCTION__ << " : cnt" << aE->count()
|
---|
| 388 | << "rep" << aE->isAutoRepeat()
|
---|
| 389 | << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
|
---|
| 390 | << "text" << aE->text()
|
---|
| 391 | << QDbgStr(aE->text().isEmpty() ? QString() :
|
---|
| 392 | QString().sprintf("(%04X)", aE->text()[0].unicode()));
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | void keyReleaseEvent(QKeyEvent *aE)
|
---|
| 396 | {
|
---|
| 397 | qDebug() << __FUNCTION__ << ": cnt" << aE->count()
|
---|
| 398 | << "rep" << aE->isAutoRepeat()
|
---|
| 399 | << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
|
---|
| 400 | << "text" << aE->text()
|
---|
| 401 | << QDbgStr(aE->text().isEmpty() ? QString() :
|
---|
| 402 | QString().sprintf("(%04X)", aE->text()[0].unicode()));
|
---|
| 403 | }
|
---|
| 404 | #endif
|
---|
| 405 |
|
---|
| 406 | #if 0
|
---|
[304] | 407 | void mousePressEvent(QMouseEvent *aE)
|
---|
[231] | 408 | {
|
---|
| 409 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 410 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 411 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 412 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
[304] | 413 |
|
---|
| 414 | ++mPressed;
|
---|
| 415 | update();
|
---|
[231] | 416 | }
|
---|
| 417 |
|
---|
[304] | 418 | void mouseReleaseEvent(QMouseEvent *aE)
|
---|
[231] | 419 | {
|
---|
| 420 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 421 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 422 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 423 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
| 424 | }
|
---|
| 425 |
|
---|
[304] | 426 | void mouseMoveEvent(QMouseEvent *aE)
|
---|
[231] | 427 | {
|
---|
| 428 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 429 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 430 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 431 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
| 432 | }
|
---|
| 433 | #endif
|
---|
| 434 |
|
---|
| 435 | #if 0
|
---|
| 436 | virtual void enterEvent(QEvent *event)
|
---|
| 437 | {
|
---|
| 438 | qDebug() << __FUNCTION__ << ":";
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | virtual void leaveEvent(QEvent *event)
|
---|
| 442 | {
|
---|
| 443 | qDebug() << __FUNCTION__ << ":";
|
---|
| 444 | }
|
---|
| 445 | #endif
|
---|
| 446 |
|
---|
| 447 | #if 0
|
---|
| 448 | void contextMenuEvent(QContextMenuEvent *aE)
|
---|
| 449 | {
|
---|
| 450 | QMenu menu;
|
---|
| 451 | menu.addAction(QLatin1String("Action &1"));
|
---|
| 452 | menu.addAction(QLatin1String("Action &2"));
|
---|
| 453 | menu.exec(aE->globalPos());
|
---|
| 454 | }
|
---|
| 455 | #endif
|
---|
| 456 |
|
---|
| 457 | #if 0
|
---|
| 458 | void timerEvent(QTimerEvent *aE)
|
---|
| 459 | {
|
---|
| 460 | qDebug() << __FUNCTION__ << ": id" << aE->timerId();
|
---|
| 461 | }
|
---|
| 462 | #endif
|
---|
[304] | 463 |
|
---|
| 464 | private:
|
---|
| 465 |
|
---|
| 466 | int mPressed;
|
---|
[231] | 467 | };
|
---|
| 468 |
|
---|
[351] | 469 | void testCodec(const char *title, const QString &sample, QTextCodec *codec)
|
---|
| 470 | {
|
---|
| 471 | // test console output
|
---|
| 472 |
|
---|
| 473 | printf("%s : Unicode (source) : ", title);
|
---|
| 474 | foreach (QChar ch, sample)
|
---|
| 475 | printf("%hX ", ch.unicode());
|
---|
| 476 | printf("\n");
|
---|
| 477 |
|
---|
| 478 | QByteArray eightbit = codec->fromUnicode(sample);
|
---|
| 479 | printf("%s : 8-bit (as is) : %s\n", title, eightbit.data());
|
---|
| 480 |
|
---|
| 481 | QString sample2 = codec->toUnicode(eightbit);
|
---|
| 482 | printf("%s : Unicode (result) : ", title);
|
---|
| 483 | foreach (QChar ch, sample2)
|
---|
| 484 | printf("%hX ", ch.unicode());
|
---|
| 485 | printf("\n");
|
---|
| 486 |
|
---|
| 487 | if (sample != sample2)
|
---|
| 488 | qWarning() << "Source and resulting Unicode differ!";
|
---|
| 489 |
|
---|
| 490 | qWarning() << "";
|
---|
| 491 |
|
---|
| 492 | // test GUI output (both window title and window text)
|
---|
| 493 |
|
---|
| 494 | QString combined = QString("%1 : %2").arg(QLatin1String(title), sample);
|
---|
| 495 | QMessageBox mbox;
|
---|
| 496 | mbox.setWindowTitle(combined);
|
---|
| 497 | mbox.setText(combined);
|
---|
| 498 | mbox.exec();
|
---|
| 499 | }
|
---|
| 500 |
|
---|
[231] | 501 | int main(int argc, char **argv)
|
---|
| 502 | {
|
---|
[368] | 503 | #if 1
|
---|
[341] | 504 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 505 | // Text mode
|
---|
| 506 |
|
---|
| 507 | QCoreApplication app(argc, argv);
|
---|
| 508 |
|
---|
[368] | 509 | #if 0
|
---|
| 510 | //--------------------------------------------------------------------------
|
---|
| 511 | // QTextStream test
|
---|
| 512 |
|
---|
| 513 | QFile file("widget.cpp");
|
---|
| 514 | file.open(QIODevice::ReadOnly);
|
---|
| 515 | QTextStream text(&file);
|
---|
| 516 | QString str = text.readAll();
|
---|
| 517 | file.close();
|
---|
| 518 | qWarning() << "Read" << str.length() << "chars from widget.cpp";
|
---|
| 519 | #endif
|
---|
| 520 |
|
---|
| 521 | #if 0
|
---|
| 522 | //--------------------------------------------------------------------------
|
---|
| 523 | // absolute/relative path test
|
---|
| 524 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("../aaa"));
|
---|
| 525 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("aaa"));
|
---|
| 526 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("/aaa"));
|
---|
| 527 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("\\aaa"));
|
---|
| 528 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
---|
| 529 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 530 |
|
---|
| 531 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("../aaa"));
|
---|
| 532 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("aaa"));
|
---|
| 533 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("/aaa"));
|
---|
| 534 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("\\aaa"));
|
---|
| 535 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
---|
| 536 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 537 |
|
---|
| 538 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("../aaa"));
|
---|
| 539 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("aaa"));
|
---|
| 540 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("/aaa"));
|
---|
| 541 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("\\aaa"));
|
---|
| 542 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
---|
| 543 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 544 |
|
---|
| 545 | qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 546 | qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("bbb"));
|
---|
| 547 | qWarning() << "4" << QDir(QLatin1String("C:bbb")).absoluteFilePath(QLatin1String("bbb"));
|
---|
| 548 | #endif
|
---|
| 549 |
|
---|
| 550 | #if 1
|
---|
| 551 | //--------------------------------------------------------------------------
|
---|
| 552 | // QDir::mkdir/mkpath test
|
---|
| 553 | PRINT_EXPR(QDir().mkdir("some_dir"));
|
---|
| 554 | PRINT_EXPR(QFile::exists("some_dir"));
|
---|
| 555 | PRINT_EXPR(QDir().rmdir("some_dir"));
|
---|
| 556 |
|
---|
| 557 | PRINT_EXPR(QDir().mkdir("some_dir/subdir"));
|
---|
| 558 | PRINT_EXPR(QFile::exists("some_dir/subdir"));
|
---|
| 559 | PRINT_EXPR(QDir().rmdir("some_dir/subdir"));
|
---|
| 560 |
|
---|
| 561 | PRINT_EXPR(QDir().mkpath("some_dir/subdir"));
|
---|
| 562 | PRINT_EXPR(QFile::exists("some_dir/subdir"));
|
---|
| 563 | PRINT_EXPR(QDir().rmpath("some_dir/subdir"));
|
---|
| 564 |
|
---|
| 565 | PRINT_EXPR(QDir("C:/").mkpath("some_dir/subdir"));
|
---|
| 566 | PRINT_EXPR(QFile::exists("C:/some_dir/subdir"));
|
---|
| 567 | PRINT_EXPR(QDir("C:/").rmpath("some_dir/subdir"));
|
---|
| 568 |
|
---|
| 569 | PRINT_EXPR(QDir("C:/").mkdir("/aaa"));
|
---|
| 570 | PRINT_EXPR(QFile::exists("C:/aaa"));
|
---|
| 571 | PRINT_EXPR(QDir("C:/").rmdir("/aaa"));
|
---|
| 572 | #endif
|
---|
| 573 |
|
---|
| 574 | #if 0
|
---|
| 575 | //--------------------------------------------------------------------------
|
---|
| 576 | // QLibraryInfo test
|
---|
| 577 | qWarning() << "QLibraryInfo::buildKey :" << QLibraryInfo::buildKey();
|
---|
| 578 | qWarning() << "QLibraryInfo::licensedProducts :" << QLibraryInfo::licensedProducts();
|
---|
| 579 | qWarning() << "QLibraryInfo::licensee :" << QLibraryInfo::licensee();
|
---|
| 580 | #define PRINT_LOC(L) qWarning() << #L << ":" << QLibraryInfo::location(L)
|
---|
| 581 | PRINT_LOC(QLibraryInfo::PrefixPath);
|
---|
| 582 | PRINT_LOC(QLibraryInfo::DocumentationPath);
|
---|
| 583 | PRINT_LOC(QLibraryInfo::HeadersPath);
|
---|
| 584 | PRINT_LOC(QLibraryInfo::LibrariesPath);
|
---|
| 585 | PRINT_LOC(QLibraryInfo::BinariesPath);
|
---|
| 586 | PRINT_LOC(QLibraryInfo::PluginsPath);
|
---|
| 587 | PRINT_LOC(QLibraryInfo::DataPath);
|
---|
| 588 | PRINT_LOC(QLibraryInfo::TranslationsPath);
|
---|
| 589 | PRINT_LOC(QLibraryInfo::SettingsPath);
|
---|
| 590 | PRINT_LOC(QLibraryInfo::DemosPath);
|
---|
| 591 | PRINT_LOC(QLibraryInfo::ExamplesPath);
|
---|
| 592 | #undef PRINT_LOC
|
---|
| 593 | #endif
|
---|
| 594 |
|
---|
[351] | 595 | #else
|
---|
| 596 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 597 | // GUI
|
---|
| 598 |
|
---|
| 599 | QApplication app(argc, argv);
|
---|
| 600 |
|
---|
[368] | 601 | #if 0
|
---|
[351] | 602 | //--------------------------------------------------------------------------
|
---|
| 603 | // locale test
|
---|
| 604 |
|
---|
| 605 | QLocale locale = QLocale::system();
|
---|
| 606 |
|
---|
| 607 | qWarning() << "Library paths :" << QApplication::libraryPaths();
|
---|
| 608 | qWarning() << "";
|
---|
[341] | 609 | qWarning() << "Available codecs :\n" << QTextCodec::availableCodecs();
|
---|
| 610 | qWarning() << "";
|
---|
| 611 | qWarning() << "Codec for locale :" << QTextCodec::codecForLocale()->name();
|
---|
| 612 | qWarning() << " Aliases :" << QTextCodec::codecForLocale()->aliases();
|
---|
| 613 | qWarning() << "";
|
---|
[351] | 614 | qWarning() << "Country for locale :" << QLocale::countryToString(locale.country())
|
---|
| 615 | << "[" << locale.country() << "]";
|
---|
| 616 | qWarning() << "Language for locale :" << QLocale::languageToString(locale.language())
|
---|
| 617 | << "[" << locale.language() << "]";
|
---|
| 618 | qWarning() << "";
|
---|
[341] | 619 |
|
---|
[351] | 620 | testCodec("First 3 months",
|
---|
| 621 | QString("%1, %2, %3").arg(locale.standaloneMonthName(1),
|
---|
| 622 | locale.standaloneMonthName(2),
|
---|
| 623 | locale.standaloneMonthName(3)),
|
---|
| 624 | QTextCodec::codecForLocale());
|
---|
| 625 | return 0;
|
---|
| 626 | #endif
|
---|
[341] | 627 |
|
---|
[351] | 628 | #if 0
|
---|
[341] | 629 | QRect r = QApplication::desktop()->availableGeometry();
|
---|
[231] | 630 | MyWidget widget;
|
---|
| 631 | widget.resize(100, 100);
|
---|
[341] | 632 | widget.move(r.width() - 200, r.height() - 200);
|
---|
[231] | 633 |
|
---|
| 634 | widget.show();
|
---|
[351] | 635 | #endif
|
---|
[304] | 636 |
|
---|
| 637 | #if 0
|
---|
[231] | 638 | {
|
---|
| 639 | QFontDialog fntDlg;
|
---|
| 640 | fntDlg.exec();
|
---|
[304] | 641 |
|
---|
[231] | 642 | {
|
---|
| 643 | QFont font("MyCoolFont");
|
---|
| 644 | QFontInfo info(font);
|
---|
| 645 | qDebug() << info.family();
|
---|
| 646 | }
|
---|
| 647 | {
|
---|
| 648 | QFont font("MyCoolFont2");
|
---|
| 649 | QFontInfo info(font);
|
---|
| 650 | qDebug() << info.family();
|
---|
| 651 | }
|
---|
| 652 | }
|
---|
| 653 | #endif
|
---|
| 654 |
|
---|
| 655 | #if 0
|
---|
[300] | 656 | QSound snd2("C:/MMOS2/SOUNDS/DESKTOP/dsk_shut.wav");
|
---|
| 657 | snd2.setLoops(2);
|
---|
| 658 | snd2.play();
|
---|
| 659 |
|
---|
| 660 | QSound snd1("C:/MMOS2/SOUNDS/DESKTOP/dsk_strt.wav");
|
---|
| 661 | snd1.setLoops(3);
|
---|
| 662 | snd1.play();
|
---|
| 663 | #endif
|
---|
| 664 |
|
---|
| 665 | #if 0
|
---|
[231] | 666 | widget.startTimer(1000);
|
---|
| 667 | widget.startTimer(2000);
|
---|
| 668 | widget.startTimer(4000);
|
---|
| 669 | #endif
|
---|
| 670 |
|
---|
| 671 | #if 0
|
---|
| 672 | qDebug() << "------------- before min" << widget.geometry() << widget.frameGeometry();
|
---|
| 673 | widget.showMinimized();
|
---|
| 674 | qDebug() << "------------- after min" << widget.geometry() << widget.frameGeometry();
|
---|
| 675 | widget.move(100, 100);
|
---|
| 676 | qDebug() << "------------- after move" << widget.geometry() << widget.frameGeometry();
|
---|
| 677 | widget.showNormal();
|
---|
| 678 | qDebug() << "------------- after norm" << widget.geometry() << widget.frameGeometry();
|
---|
| 679 | widget.showFullScreen();
|
---|
| 680 | qDebug() << "------------- after full" << widget.geometry() << widget.frameGeometry();
|
---|
| 681 | #endif
|
---|
| 682 |
|
---|
| 683 | return app.exec();
|
---|
[341] | 684 | #endif
|
---|
[231] | 685 | }
|
---|
[304] | 686 |
|
---|
| 687 | #include "widget.moc"
|
---|