[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 | {
|
---|
[481] | 252 | #if 0
|
---|
[304] | 253 | MyButton *btn1 = new MyButton(this);
|
---|
[435] | 254 | btn1->setText(QLatin1String("&Hello (also Ctrl+H)"));
|
---|
| 255 | btn1->setObjectName("Hello");
|
---|
[304] | 256 | btn1->move(20, 20);
|
---|
[435] | 257 |
|
---|
| 258 | connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_H), btn1),
|
---|
| 259 | SIGNAL(activated()), btn1, SLOT(animateClick()));
|
---|
| 260 |
|
---|
[304] | 261 | MyButton *btn2 = new MyButton(this);
|
---|
[435] | 262 | btn2->setText(QString::fromUtf16((const ushort *)L"&\u041f\u0440\u0438\u0432\u0435\u0442 (also Ctrl+\u041f)"));
|
---|
| 263 | btn2->setObjectName(QString::fromUtf16((const ushort *)L"\u041f\u0440\u0438\u0432\u0435\u0442"));
|
---|
[304] | 264 | btn2->move(20, 60);
|
---|
[231] | 265 |
|
---|
[435] | 266 | connect(new QShortcut(QKeySequence(Qt::CTRL + 0x041F), btn2),
|
---|
| 267 | SIGNAL(activated()), btn2, SLOT(animateClick()));
|
---|
| 268 |
|
---|
[304] | 269 | // QComboBox *cb1 = new MyCombo(this);
|
---|
| 270 | // cb1->addItem(QLatin1String("Test 1"));
|
---|
| 271 | // cb1->addItem(QLatin1String("Test 2"));
|
---|
[231] | 272 |
|
---|
| 273 | // QComboBox *cb2 = new MyCombo(this);
|
---|
| 274 | // cb2->addItem(QLatin1String("Test 3"));
|
---|
| 275 | // cb2->addItem(QLatin1String("Test 4"));
|
---|
| 276 |
|
---|
[435] | 277 | QVBoxLayout *mainLayout = new QVBoxLayout();
|
---|
| 278 | mainLayout->addWidget(btn1);
|
---|
| 279 | mainLayout->addWidget(btn2);
|
---|
[304] | 280 | // mainLayout->addWidget(cb1);
|
---|
[231] | 281 | // mainLayout->addWidget(cb2);
|
---|
| 282 |
|
---|
[435] | 283 | setLayout(mainLayout);
|
---|
[311] | 284 | #endif
|
---|
[304] | 285 |
|
---|
[341] | 286 | #if 0
|
---|
[311] | 287 | QMenuBar *mb = new QMenuBar(this);
|
---|
| 288 |
|
---|
| 289 | QMenu *menu = new QMenu(mb);
|
---|
| 290 | menu->setTitle ("Menu &1");
|
---|
| 291 | menu->addAction(QLatin1String("Action &1"));
|
---|
| 292 | menu->addAction(QLatin1String("Action &2"));
|
---|
| 293 | mb->addMenu(menu);
|
---|
| 294 |
|
---|
| 295 | menu = new QMenu(mb);
|
---|
| 296 | menu->setTitle ("Menu &2");
|
---|
| 297 | menu->addAction(QLatin1String("Action &1"));
|
---|
| 298 | menu->addAction(QLatin1String("Action &2"));
|
---|
| 299 | mb->addMenu(menu);
|
---|
| 300 |
|
---|
| 301 | menu = new QMenu(mb);
|
---|
| 302 | menu->setTitle ("Menu &3");
|
---|
| 303 | menu->addAction(QLatin1String("Action &1"));
|
---|
| 304 | menu->addAction(QLatin1String("Action &2"));
|
---|
| 305 | mb->addMenu(menu);
|
---|
| 306 | #endif
|
---|
| 307 |
|
---|
[304] | 308 | #if 0
|
---|
| 309 | new MyChild(this);
|
---|
| 310 | #endif
|
---|
| 311 |
|
---|
[231] | 312 | };
|
---|
| 313 |
|
---|
[368] | 314 | #if 0
|
---|
[435] | 315 | void closeEvent(QCloseEvent *aE)
|
---|
| 316 | {
|
---|
| 317 | QMessageBox::warning(this, QLatin1String("Close"),
|
---|
| 318 | QLatin1String("Somebody asked us to terminate"));
|
---|
| 319 | aE->accept();
|
---|
| 320 | }
|
---|
| 321 | #endif
|
---|
| 322 |
|
---|
| 323 | #if 0
|
---|
[231] | 324 | void paintEvent(QPaintEvent *aE)
|
---|
| 325 | {
|
---|
| 326 | qDebug() << __FUNCTION__ <<": " << aE->rect();
|
---|
| 327 |
|
---|
| 328 | QPainter p(this);
|
---|
[346] | 329 | #if 0
|
---|
| 330 | // simple QPainter test
|
---|
| 331 |
|
---|
[231] | 332 | p.setRenderHint(QPainter::Antialiasing);
|
---|
| 333 |
|
---|
[304] | 334 | p.fillRect(0, 0, 20, 20, mPressed % 2 ? Qt::red : Qt::green);
|
---|
[231] | 335 |
|
---|
| 336 | p.setPen(Qt::black);
|
---|
| 337 | p.drawEllipse(10, 10, 10, 10);
|
---|
| 338 |
|
---|
| 339 | //p.setFont(QFont("Arial", 12));
|
---|
| 340 | p.drawText(10, 30, QLatin1String("ABC"));
|
---|
[346] | 341 | #endif
|
---|
[368] | 342 | #if 0
|
---|
[346] | 343 | // simple QClipboard image test
|
---|
| 344 |
|
---|
| 345 | const QMimeData *data = QApplication::clipboard()->mimeData();
|
---|
| 346 | if (data && data->hasImage()){
|
---|
| 347 | QImage img = qvariant_cast<QImage>(data->imageData());
|
---|
| 348 | p.drawImage(0, 0, img);
|
---|
| 349 | }
|
---|
| 350 | #endif
|
---|
[231] | 351 | }
|
---|
| 352 | #endif
|
---|
| 353 |
|
---|
| 354 | #if 0
|
---|
| 355 | void resizeEvent(QResizeEvent *aE)
|
---|
| 356 | {
|
---|
| 357 | qDebug() << __FUNCTION__ << ": g" << geometry() << "fg" << frameGeometry()
|
---|
| 358 | << "sz" << aE->size() << "old" << aE->oldSize();
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | void moveEvent(QMoveEvent *aE)
|
---|
| 362 | {
|
---|
| 363 | qDebug() << __FUNCTION__ << ": g" << geometry() << "fg" << frameGeometry()
|
---|
| 364 | << "pos" << aE->pos() << "old" << aE->oldPos();
|
---|
| 365 | }
|
---|
| 366 | #endif
|
---|
| 367 |
|
---|
| 368 | #if 0
|
---|
| 369 | void focusInEvent(QFocusEvent *aE)
|
---|
| 370 | {
|
---|
[304] | 371 | qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
|
---|
| 372 | QWidget::focusInEvent(aE);
|
---|
[231] | 373 | }
|
---|
| 374 |
|
---|
| 375 | void focusOutEvent(QFocusEvent *aE)
|
---|
| 376 | {
|
---|
[304] | 377 | qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
|
---|
| 378 | QWidget::focusOutEvent(aE);
|
---|
[231] | 379 | }
|
---|
| 380 | #endif
|
---|
| 381 |
|
---|
| 382 | #if 0
|
---|
| 383 | void changeEvent(QEvent *aE)
|
---|
| 384 | {
|
---|
| 385 | switch (aE->type()) {
|
---|
| 386 | case QEvent::WindowStateChange: {
|
---|
| 387 | QWindowStateChangeEvent *e2 = (QWindowStateChangeEvent *)aE;
|
---|
| 388 | qDebug().nospace() << __FUNCTION__ << ": QWindowStateChangeEvent(" <<
|
---|
| 389 | e2->oldState() << "->" << windowState() << ")";
|
---|
| 390 | break;
|
---|
| 391 | }
|
---|
| 392 | default:
|
---|
| 393 | break;
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
| 396 | #endif
|
---|
| 397 |
|
---|
[481] | 398 | #if 0
|
---|
[231] | 399 | void keyPressEvent(QKeyEvent *aE)
|
---|
| 400 | {
|
---|
| 401 | qDebug() << __FUNCTION__ << " : cnt" << aE->count()
|
---|
| 402 | << "rep" << aE->isAutoRepeat()
|
---|
| 403 | << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
|
---|
| 404 | << "text" << aE->text()
|
---|
| 405 | << QDbgStr(aE->text().isEmpty() ? QString() :
|
---|
| 406 | QString().sprintf("(%04X)", aE->text()[0].unicode()));
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | void keyReleaseEvent(QKeyEvent *aE)
|
---|
| 410 | {
|
---|
| 411 | qDebug() << __FUNCTION__ << ": cnt" << aE->count()
|
---|
| 412 | << "rep" << aE->isAutoRepeat()
|
---|
| 413 | << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
|
---|
| 414 | << "text" << aE->text()
|
---|
| 415 | << QDbgStr(aE->text().isEmpty() ? QString() :
|
---|
| 416 | QString().sprintf("(%04X)", aE->text()[0].unicode()));
|
---|
| 417 | }
|
---|
| 418 | #endif
|
---|
| 419 |
|
---|
[481] | 420 | #if 1
|
---|
| 421 | // QCursor shape test
|
---|
| 422 | void mousePressEvent(QMouseEvent *aE)
|
---|
| 423 | {
|
---|
| 424 | static int shape = 0;
|
---|
| 425 | if (aE->button() == Qt::LeftButton)
|
---|
| 426 | ++shape;
|
---|
| 427 | else
|
---|
| 428 | --shape;
|
---|
| 429 | shape = (Qt::LastCursor + 1 + shape) % (Qt::LastCursor + 1);
|
---|
| 430 | setCursor(QCursor((Qt::CursorShape)shape));
|
---|
| 431 | }
|
---|
| 432 | #endif
|
---|
| 433 |
|
---|
[231] | 434 | #if 0
|
---|
[304] | 435 | void mousePressEvent(QMouseEvent *aE)
|
---|
[231] | 436 | {
|
---|
| 437 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 438 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 439 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 440 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
[304] | 441 |
|
---|
| 442 | ++mPressed;
|
---|
| 443 | update();
|
---|
[231] | 444 | }
|
---|
| 445 |
|
---|
[304] | 446 | void mouseReleaseEvent(QMouseEvent *aE)
|
---|
[231] | 447 | {
|
---|
| 448 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 449 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 450 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 451 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
| 452 | }
|
---|
| 453 |
|
---|
[304] | 454 | void mouseMoveEvent(QMouseEvent *aE)
|
---|
[231] | 455 | {
|
---|
| 456 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
---|
| 457 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
---|
| 458 | (int) aE->buttons(), (int) aE->modifiers()))
|
---|
| 459 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
---|
| 460 | }
|
---|
| 461 | #endif
|
---|
| 462 |
|
---|
| 463 | #if 0
|
---|
| 464 | virtual void enterEvent(QEvent *event)
|
---|
| 465 | {
|
---|
| 466 | qDebug() << __FUNCTION__ << ":";
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | virtual void leaveEvent(QEvent *event)
|
---|
| 470 | {
|
---|
| 471 | qDebug() << __FUNCTION__ << ":";
|
---|
| 472 | }
|
---|
| 473 | #endif
|
---|
| 474 |
|
---|
| 475 | #if 0
|
---|
| 476 | void contextMenuEvent(QContextMenuEvent *aE)
|
---|
| 477 | {
|
---|
| 478 | QMenu menu;
|
---|
| 479 | menu.addAction(QLatin1String("Action &1"));
|
---|
| 480 | menu.addAction(QLatin1String("Action &2"));
|
---|
| 481 | menu.exec(aE->globalPos());
|
---|
| 482 | }
|
---|
| 483 | #endif
|
---|
| 484 |
|
---|
| 485 | #if 0
|
---|
| 486 | void timerEvent(QTimerEvent *aE)
|
---|
| 487 | {
|
---|
| 488 | qDebug() << __FUNCTION__ << ": id" << aE->timerId();
|
---|
| 489 | }
|
---|
| 490 | #endif
|
---|
[304] | 491 |
|
---|
| 492 | private:
|
---|
| 493 |
|
---|
| 494 | int mPressed;
|
---|
[231] | 495 | };
|
---|
| 496 |
|
---|
[351] | 497 | void testCodec(const char *title, const QString &sample, QTextCodec *codec)
|
---|
| 498 | {
|
---|
| 499 | // test console output
|
---|
| 500 |
|
---|
| 501 | printf("%s : Unicode (source) : ", title);
|
---|
| 502 | foreach (QChar ch, sample)
|
---|
| 503 | printf("%hX ", ch.unicode());
|
---|
| 504 | printf("\n");
|
---|
| 505 |
|
---|
| 506 | QByteArray eightbit = codec->fromUnicode(sample);
|
---|
| 507 | printf("%s : 8-bit (as is) : %s\n", title, eightbit.data());
|
---|
| 508 |
|
---|
| 509 | QString sample2 = codec->toUnicode(eightbit);
|
---|
| 510 | printf("%s : Unicode (result) : ", title);
|
---|
| 511 | foreach (QChar ch, sample2)
|
---|
| 512 | printf("%hX ", ch.unicode());
|
---|
| 513 | printf("\n");
|
---|
| 514 |
|
---|
| 515 | if (sample != sample2)
|
---|
| 516 | qWarning() << "Source and resulting Unicode differ!";
|
---|
| 517 |
|
---|
| 518 | qWarning() << "";
|
---|
| 519 |
|
---|
| 520 | // test GUI output (both window title and window text)
|
---|
| 521 |
|
---|
| 522 | QString combined = QString("%1 : %2").arg(QLatin1String(title), sample);
|
---|
| 523 | QMessageBox mbox;
|
---|
| 524 | mbox.setWindowTitle(combined);
|
---|
| 525 | mbox.setText(combined);
|
---|
| 526 | mbox.exec();
|
---|
| 527 | }
|
---|
| 528 |
|
---|
[231] | 529 | int main(int argc, char **argv)
|
---|
| 530 | {
|
---|
[380] | 531 | #if 0
|
---|
[341] | 532 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 533 | // Text mode
|
---|
| 534 |
|
---|
| 535 | QCoreApplication app(argc, argv);
|
---|
| 536 |
|
---|
[368] | 537 | #if 0
|
---|
| 538 | //--------------------------------------------------------------------------
|
---|
| 539 | // QTextStream test
|
---|
| 540 |
|
---|
| 541 | QFile file("widget.cpp");
|
---|
| 542 | file.open(QIODevice::ReadOnly);
|
---|
| 543 | QTextStream text(&file);
|
---|
| 544 | QString str = text.readAll();
|
---|
| 545 | file.close();
|
---|
| 546 | qWarning() << "Read" << str.length() << "chars from widget.cpp";
|
---|
| 547 | #endif
|
---|
| 548 |
|
---|
| 549 | #if 0
|
---|
| 550 | //--------------------------------------------------------------------------
|
---|
| 551 | // absolute/relative path test
|
---|
| 552 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("../aaa"));
|
---|
| 553 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("aaa"));
|
---|
| 554 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("/aaa"));
|
---|
| 555 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("\\aaa"));
|
---|
| 556 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
---|
| 557 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 558 |
|
---|
| 559 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("../aaa"));
|
---|
| 560 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("aaa"));
|
---|
| 561 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("/aaa"));
|
---|
| 562 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("\\aaa"));
|
---|
| 563 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
---|
| 564 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 565 |
|
---|
| 566 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("../aaa"));
|
---|
| 567 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("aaa"));
|
---|
| 568 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("/aaa"));
|
---|
| 569 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("\\aaa"));
|
---|
| 570 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
---|
| 571 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 572 |
|
---|
| 573 | qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
|
---|
| 574 | qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("bbb"));
|
---|
| 575 | qWarning() << "4" << QDir(QLatin1String("C:bbb")).absoluteFilePath(QLatin1String("bbb"));
|
---|
| 576 | #endif
|
---|
| 577 |
|
---|
[380] | 578 | #if 0
|
---|
[368] | 579 | //--------------------------------------------------------------------------
|
---|
| 580 | // QDir::mkdir/mkpath test
|
---|
| 581 | PRINT_EXPR(QDir().mkdir("some_dir"));
|
---|
| 582 | PRINT_EXPR(QFile::exists("some_dir"));
|
---|
| 583 | PRINT_EXPR(QDir().rmdir("some_dir"));
|
---|
| 584 |
|
---|
| 585 | PRINT_EXPR(QDir().mkdir("some_dir/subdir"));
|
---|
| 586 | PRINT_EXPR(QFile::exists("some_dir/subdir"));
|
---|
| 587 | PRINT_EXPR(QDir().rmdir("some_dir/subdir"));
|
---|
| 588 |
|
---|
| 589 | PRINT_EXPR(QDir().mkpath("some_dir/subdir"));
|
---|
| 590 | PRINT_EXPR(QFile::exists("some_dir/subdir"));
|
---|
| 591 | PRINT_EXPR(QDir().rmpath("some_dir/subdir"));
|
---|
| 592 |
|
---|
| 593 | PRINT_EXPR(QDir("C:/").mkpath("some_dir/subdir"));
|
---|
| 594 | PRINT_EXPR(QFile::exists("C:/some_dir/subdir"));
|
---|
| 595 | PRINT_EXPR(QDir("C:/").rmpath("some_dir/subdir"));
|
---|
| 596 |
|
---|
| 597 | PRINT_EXPR(QDir("C:/").mkdir("/aaa"));
|
---|
| 598 | PRINT_EXPR(QFile::exists("C:/aaa"));
|
---|
| 599 | PRINT_EXPR(QDir("C:/").rmdir("/aaa"));
|
---|
| 600 | #endif
|
---|
| 601 |
|
---|
| 602 | #if 0
|
---|
| 603 | //--------------------------------------------------------------------------
|
---|
| 604 | // QLibraryInfo test
|
---|
| 605 | qWarning() << "QLibraryInfo::buildKey :" << QLibraryInfo::buildKey();
|
---|
| 606 | qWarning() << "QLibraryInfo::licensedProducts :" << QLibraryInfo::licensedProducts();
|
---|
| 607 | qWarning() << "QLibraryInfo::licensee :" << QLibraryInfo::licensee();
|
---|
| 608 | #define PRINT_LOC(L) qWarning() << #L << ":" << QLibraryInfo::location(L)
|
---|
| 609 | PRINT_LOC(QLibraryInfo::PrefixPath);
|
---|
| 610 | PRINT_LOC(QLibraryInfo::DocumentationPath);
|
---|
| 611 | PRINT_LOC(QLibraryInfo::HeadersPath);
|
---|
| 612 | PRINT_LOC(QLibraryInfo::LibrariesPath);
|
---|
| 613 | PRINT_LOC(QLibraryInfo::BinariesPath);
|
---|
| 614 | PRINT_LOC(QLibraryInfo::PluginsPath);
|
---|
| 615 | PRINT_LOC(QLibraryInfo::DataPath);
|
---|
| 616 | PRINT_LOC(QLibraryInfo::TranslationsPath);
|
---|
| 617 | PRINT_LOC(QLibraryInfo::SettingsPath);
|
---|
| 618 | PRINT_LOC(QLibraryInfo::DemosPath);
|
---|
| 619 | PRINT_LOC(QLibraryInfo::ExamplesPath);
|
---|
| 620 | #undef PRINT_LOC
|
---|
| 621 | #endif
|
---|
| 622 |
|
---|
[435] | 623 | #if 0
|
---|
[426] | 624 | //--------------------------------------------------------------------------
|
---|
| 625 | // QSettings test
|
---|
| 626 |
|
---|
| 627 | QSettings sysOrgSet(QSettings::IniFormat, QSettings::SystemScope,
|
---|
| 628 | QLatin1String("MySoft"));
|
---|
| 629 | QSettings sysAppSet(QSettings::IniFormat, QSettings::SystemScope,
|
---|
| 630 | QLatin1String("MySoft"), QLatin1String("MyApp"));
|
---|
| 631 | QSettings userOrgSet(QSettings::IniFormat, QSettings::UserScope,
|
---|
| 632 | QLatin1String("MySoft"));
|
---|
| 633 | QSettings userAppSet(QSettings::IniFormat, QSettings::UserScope,
|
---|
| 634 | QLatin1String("MySoft"), QLatin1String("MyApp"));
|
---|
| 635 |
|
---|
| 636 | QList<QSettings *> sets;
|
---|
| 637 | sets << &sysOrgSet << &sysAppSet << &userOrgSet << &userAppSet;
|
---|
| 638 |
|
---|
| 639 | foreach (QSettings *set, sets) {
|
---|
| 640 | set->setValue("Time", QDateTime::currentDateTime());
|
---|
| 641 | }
|
---|
| 642 |
|
---|
[435] | 643 | qWarning() << "Modified Time key in MySoft/MyApp (system & user)";
|
---|
[426] | 644 | #endif
|
---|
| 645 |
|
---|
[351] | 646 | #else
|
---|
| 647 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 648 | // GUI
|
---|
| 649 |
|
---|
| 650 | QApplication app(argc, argv);
|
---|
[380] | 651 | app.setQuitOnLastWindowClosed(true);
|
---|
[351] | 652 |
|
---|
[368] | 653 | #if 0
|
---|
[351] | 654 | //--------------------------------------------------------------------------
|
---|
| 655 | // locale test
|
---|
| 656 |
|
---|
| 657 | QLocale locale = QLocale::system();
|
---|
| 658 |
|
---|
| 659 | qWarning() << "Library paths :" << QApplication::libraryPaths();
|
---|
| 660 | qWarning() << "";
|
---|
[341] | 661 | qWarning() << "Available codecs :\n" << QTextCodec::availableCodecs();
|
---|
| 662 | qWarning() << "";
|
---|
| 663 | qWarning() << "Codec for locale :" << QTextCodec::codecForLocale()->name();
|
---|
| 664 | qWarning() << " Aliases :" << QTextCodec::codecForLocale()->aliases();
|
---|
| 665 | qWarning() << "";
|
---|
[351] | 666 | qWarning() << "Country for locale :" << QLocale::countryToString(locale.country())
|
---|
| 667 | << "[" << locale.country() << "]";
|
---|
| 668 | qWarning() << "Language for locale :" << QLocale::languageToString(locale.language())
|
---|
| 669 | << "[" << locale.language() << "]";
|
---|
| 670 | qWarning() << "";
|
---|
[341] | 671 |
|
---|
[351] | 672 | testCodec("First 3 months",
|
---|
| 673 | QString("%1, %2, %3").arg(locale.standaloneMonthName(1),
|
---|
| 674 | locale.standaloneMonthName(2),
|
---|
| 675 | locale.standaloneMonthName(3)),
|
---|
| 676 | QTextCodec::codecForLocale());
|
---|
| 677 | return 0;
|
---|
| 678 | #endif
|
---|
[341] | 679 |
|
---|
[435] | 680 | #if 1
|
---|
[341] | 681 | QRect r = QApplication::desktop()->availableGeometry();
|
---|
[231] | 682 | MyWidget widget;
|
---|
| 683 | widget.resize(100, 100);
|
---|
[341] | 684 | widget.move(r.width() - 200, r.height() - 200);
|
---|
[231] | 685 |
|
---|
| 686 | widget.show();
|
---|
[351] | 687 | #endif
|
---|
[304] | 688 |
|
---|
| 689 | #if 0
|
---|
[380] | 690 | //--------------------------------------------------------------------------
|
---|
| 691 | // QFontDialog test
|
---|
[231] | 692 | {
|
---|
| 693 | QFontDialog fntDlg;
|
---|
| 694 | fntDlg.exec();
|
---|
[304] | 695 |
|
---|
[231] | 696 | {
|
---|
| 697 | QFont font("MyCoolFont");
|
---|
| 698 | QFontInfo info(font);
|
---|
| 699 | qDebug() << info.family();
|
---|
| 700 | }
|
---|
| 701 | {
|
---|
| 702 | QFont font("MyCoolFont2");
|
---|
| 703 | QFontInfo info(font);
|
---|
| 704 | qDebug() << info.family();
|
---|
| 705 | }
|
---|
| 706 | }
|
---|
| 707 | #endif
|
---|
| 708 |
|
---|
[435] | 709 | #if 0
|
---|
[380] | 710 | //--------------------------------------------------------------------------
|
---|
| 711 | // QFileDialog test
|
---|
| 712 | {
|
---|
| 713 | QFileDialog dlg;
|
---|
| 714 |
|
---|
| 715 | dlg.setFileMode(QFileDialog::ExistingFile);
|
---|
| 716 | //dlg.setFilter(QDir::Dirs | QDir::Files | QDir::Drives);
|
---|
| 717 | dlg.setNameFilter("*.exe");
|
---|
| 718 | dlg.selectFile("mplayer.exe");
|
---|
| 719 | dlg.exec();
|
---|
| 720 |
|
---|
| 721 | //PRINT_EXPR(QFileDialog::getOpenFileName());
|
---|
| 722 | }
|
---|
| 723 | #endif
|
---|
| 724 |
|
---|
[231] | 725 | #if 0
|
---|
[300] | 726 | QSound snd2("C:/MMOS2/SOUNDS/DESKTOP/dsk_shut.wav");
|
---|
| 727 | snd2.setLoops(2);
|
---|
| 728 | snd2.play();
|
---|
| 729 |
|
---|
| 730 | QSound snd1("C:/MMOS2/SOUNDS/DESKTOP/dsk_strt.wav");
|
---|
| 731 | snd1.setLoops(3);
|
---|
| 732 | snd1.play();
|
---|
| 733 | #endif
|
---|
| 734 |
|
---|
| 735 | #if 0
|
---|
[231] | 736 | widget.startTimer(1000);
|
---|
| 737 | widget.startTimer(2000);
|
---|
| 738 | widget.startTimer(4000);
|
---|
| 739 | #endif
|
---|
| 740 |
|
---|
| 741 | #if 0
|
---|
| 742 | qDebug() << "------------- before min" << widget.geometry() << widget.frameGeometry();
|
---|
| 743 | widget.showMinimized();
|
---|
| 744 | qDebug() << "------------- after min" << widget.geometry() << widget.frameGeometry();
|
---|
| 745 | widget.move(100, 100);
|
---|
| 746 | qDebug() << "------------- after move" << widget.geometry() << widget.frameGeometry();
|
---|
| 747 | widget.showNormal();
|
---|
| 748 | qDebug() << "------------- after norm" << widget.geometry() << widget.frameGeometry();
|
---|
| 749 | widget.showFullScreen();
|
---|
| 750 | qDebug() << "------------- after full" << widget.geometry() << widget.frameGeometry();
|
---|
| 751 | #endif
|
---|
| 752 |
|
---|
[380] | 753 | if (!app.topLevelWidgets().isEmpty())
|
---|
| 754 | return app.exec();
|
---|
| 755 |
|
---|
| 756 | return 0;
|
---|
[341] | 757 | #endif
|
---|
[231] | 758 | }
|
---|
[304] | 759 |
|
---|
| 760 | #include "widget.moc"
|
---|