| 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 | ++mPressed;
|
|---|
| 97 | update();
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void mouseReleaseEvent(QMouseEvent *aE)
|
|---|
| 101 | {
|
|---|
| 102 | ++mPressed;
|
|---|
| 103 | update();
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 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 |
|
|---|
| 125 | class MyButton : public QPushButton
|
|---|
| 126 | {
|
|---|
| 127 | public:
|
|---|
| 128 |
|
|---|
| 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 | }
|
|---|
| 136 |
|
|---|
| 137 | #if 0
|
|---|
| 138 | void focusInEvent(QFocusEvent *aE)
|
|---|
| 139 | {
|
|---|
| 140 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
|
|---|
| 141 | << "reason" << aE->reason()
|
|---|
| 142 | << "focus" << (qApp->focusWidget() ?
|
|---|
| 143 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
|---|
| 144 |
|
|---|
| 145 | QPushButton::focusInEvent(aE);
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | void focusOutEvent(QFocusEvent *aE)
|
|---|
| 149 | {
|
|---|
| 150 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
|
|---|
| 151 | << "reason" << aE->reason()
|
|---|
| 152 | << "focus" << (qApp->focusWidget() ?
|
|---|
| 153 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
|---|
| 154 | QPushButton::focusOutEvent(aE);
|
|---|
| 155 | }
|
|---|
| 156 | #endif
|
|---|
| 157 | };
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 161 |
|
|---|
| 162 | class MyCombo : public QComboBox
|
|---|
| 163 | {
|
|---|
| 164 | public:
|
|---|
| 165 |
|
|---|
| 166 | MyCombo(QWidget *aParent) : QComboBox(aParent) {}
|
|---|
| 167 |
|
|---|
| 168 | #if 0
|
|---|
| 169 | void focusInEvent(QFocusEvent *aE)
|
|---|
| 170 | {
|
|---|
| 171 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
|
|---|
| 172 | << "reason" << aE->reason()
|
|---|
| 173 | << "focus" << (qApp->focusWidget() ?
|
|---|
| 174 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
|---|
| 175 | QComboBox::focusInEvent(aE);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | void focusOutEvent(QFocusEvent *aE)
|
|---|
| 179 | {
|
|---|
| 180 | qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
|
|---|
| 181 | << "reason" << aE->reason()
|
|---|
| 182 | << "focus" << (qApp->focusWidget() ?
|
|---|
| 183 | qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
|
|---|
| 184 | QComboBox::focusOutEvent(aE);
|
|---|
| 185 | }
|
|---|
| 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 |
|
|---|
| 244 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 245 |
|
|---|
| 246 | class MyWidget : public QWidget
|
|---|
| 247 | {
|
|---|
| 248 | public:
|
|---|
| 249 |
|
|---|
| 250 | MyWidget() : mPressed(0)
|
|---|
| 251 | {
|
|---|
| 252 | // setFocusPolicy(Qt::StrongFocus);
|
|---|
| 253 |
|
|---|
| 254 | #if 1
|
|---|
| 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 1
|
|---|
| 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 | void mousePressEvent(QMouseEvent *aE)
|
|---|
| 424 | {
|
|---|
| 425 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
|---|
| 426 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
|---|
| 427 | (int) aE->buttons(), (int) aE->modifiers()))
|
|---|
| 428 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
|---|
| 429 |
|
|---|
| 430 | ++mPressed;
|
|---|
| 431 | update();
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | void mouseReleaseEvent(QMouseEvent *aE)
|
|---|
| 435 | {
|
|---|
| 436 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
|---|
| 437 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
|---|
| 438 | (int) aE->buttons(), (int) aE->modifiers()))
|
|---|
| 439 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | void mouseMoveEvent(QMouseEvent *aE)
|
|---|
| 443 | {
|
|---|
| 444 | qDebug() << __FUNCTION__ << ": btn" << aE->button()
|
|---|
| 445 | << QDbgStr(QString().sprintf("btns %08X mods %08X",
|
|---|
| 446 | (int) aE->buttons(), (int) aE->modifiers()))
|
|---|
| 447 | << "gpos" << aE->globalPos() << "pos" << aE->pos();
|
|---|
| 448 | }
|
|---|
| 449 | #endif
|
|---|
| 450 |
|
|---|
| 451 | #if 0
|
|---|
| 452 | virtual void enterEvent(QEvent *event)
|
|---|
| 453 | {
|
|---|
| 454 | qDebug() << __FUNCTION__ << ":";
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | virtual void leaveEvent(QEvent *event)
|
|---|
| 458 | {
|
|---|
| 459 | qDebug() << __FUNCTION__ << ":";
|
|---|
| 460 | }
|
|---|
| 461 | #endif
|
|---|
| 462 |
|
|---|
| 463 | #if 0
|
|---|
| 464 | void contextMenuEvent(QContextMenuEvent *aE)
|
|---|
| 465 | {
|
|---|
| 466 | QMenu menu;
|
|---|
| 467 | menu.addAction(QLatin1String("Action &1"));
|
|---|
| 468 | menu.addAction(QLatin1String("Action &2"));
|
|---|
| 469 | menu.exec(aE->globalPos());
|
|---|
| 470 | }
|
|---|
| 471 | #endif
|
|---|
| 472 |
|
|---|
| 473 | #if 0
|
|---|
| 474 | void timerEvent(QTimerEvent *aE)
|
|---|
| 475 | {
|
|---|
| 476 | qDebug() << __FUNCTION__ << ": id" << aE->timerId();
|
|---|
| 477 | }
|
|---|
| 478 | #endif
|
|---|
| 479 |
|
|---|
| 480 | private:
|
|---|
| 481 |
|
|---|
| 482 | int mPressed;
|
|---|
| 483 | };
|
|---|
| 484 |
|
|---|
| 485 | void testCodec(const char *title, const QString &sample, QTextCodec *codec)
|
|---|
| 486 | {
|
|---|
| 487 | // test console output
|
|---|
| 488 |
|
|---|
| 489 | printf("%s : Unicode (source) : ", title);
|
|---|
| 490 | foreach (QChar ch, sample)
|
|---|
| 491 | printf("%hX ", ch.unicode());
|
|---|
| 492 | printf("\n");
|
|---|
| 493 |
|
|---|
| 494 | QByteArray eightbit = codec->fromUnicode(sample);
|
|---|
| 495 | printf("%s : 8-bit (as is) : %s\n", title, eightbit.data());
|
|---|
| 496 |
|
|---|
| 497 | QString sample2 = codec->toUnicode(eightbit);
|
|---|
| 498 | printf("%s : Unicode (result) : ", title);
|
|---|
| 499 | foreach (QChar ch, sample2)
|
|---|
| 500 | printf("%hX ", ch.unicode());
|
|---|
| 501 | printf("\n");
|
|---|
| 502 |
|
|---|
| 503 | if (sample != sample2)
|
|---|
| 504 | qWarning() << "Source and resulting Unicode differ!";
|
|---|
| 505 |
|
|---|
| 506 | qWarning() << "";
|
|---|
| 507 |
|
|---|
| 508 | // test GUI output (both window title and window text)
|
|---|
| 509 |
|
|---|
| 510 | QString combined = QString("%1 : %2").arg(QLatin1String(title), sample);
|
|---|
| 511 | QMessageBox mbox;
|
|---|
| 512 | mbox.setWindowTitle(combined);
|
|---|
| 513 | mbox.setText(combined);
|
|---|
| 514 | mbox.exec();
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | int main(int argc, char **argv)
|
|---|
| 518 | {
|
|---|
| 519 | #if 0
|
|---|
| 520 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 521 | // Text mode
|
|---|
| 522 |
|
|---|
| 523 | QCoreApplication app(argc, argv);
|
|---|
| 524 |
|
|---|
| 525 | #if 0
|
|---|
| 526 | //--------------------------------------------------------------------------
|
|---|
| 527 | // QTextStream test
|
|---|
| 528 |
|
|---|
| 529 | QFile file("widget.cpp");
|
|---|
| 530 | file.open(QIODevice::ReadOnly);
|
|---|
| 531 | QTextStream text(&file);
|
|---|
| 532 | QString str = text.readAll();
|
|---|
| 533 | file.close();
|
|---|
| 534 | qWarning() << "Read" << str.length() << "chars from widget.cpp";
|
|---|
| 535 | #endif
|
|---|
| 536 |
|
|---|
| 537 | #if 0
|
|---|
| 538 | //--------------------------------------------------------------------------
|
|---|
| 539 | // absolute/relative path test
|
|---|
| 540 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("../aaa"));
|
|---|
| 541 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("aaa"));
|
|---|
| 542 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("/aaa"));
|
|---|
| 543 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("\\aaa"));
|
|---|
| 544 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
|---|
| 545 | qWarning() << "1" << QDir(QLatin1String("C:\\OS2")).absoluteFilePath(QLatin1String("D:aaa"));
|
|---|
| 546 |
|
|---|
| 547 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("../aaa"));
|
|---|
| 548 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("aaa"));
|
|---|
| 549 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("/aaa"));
|
|---|
| 550 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("\\aaa"));
|
|---|
| 551 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
|---|
| 552 | qWarning() << "2" << QDir(QLatin1String(".")).absoluteFilePath(QLatin1String("D:aaa"));
|
|---|
| 553 |
|
|---|
| 554 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("../aaa"));
|
|---|
| 555 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("aaa"));
|
|---|
| 556 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("/aaa"));
|
|---|
| 557 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("\\aaa"));
|
|---|
| 558 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:\\aaa"));
|
|---|
| 559 | qWarning() << "3" << QDir(QLatin1String("D:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
|
|---|
| 560 |
|
|---|
| 561 | qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("D:aaa"));
|
|---|
| 562 | qWarning() << "4" << QDir(QLatin1String("E:bbb")).absoluteFilePath(QLatin1String("bbb"));
|
|---|
| 563 | qWarning() << "4" << QDir(QLatin1String("C:bbb")).absoluteFilePath(QLatin1String("bbb"));
|
|---|
| 564 | #endif
|
|---|
| 565 |
|
|---|
| 566 | #if 0
|
|---|
| 567 | //--------------------------------------------------------------------------
|
|---|
| 568 | // QDir::mkdir/mkpath test
|
|---|
| 569 | PRINT_EXPR(QDir().mkdir("some_dir"));
|
|---|
| 570 | PRINT_EXPR(QFile::exists("some_dir"));
|
|---|
| 571 | PRINT_EXPR(QDir().rmdir("some_dir"));
|
|---|
| 572 |
|
|---|
| 573 | PRINT_EXPR(QDir().mkdir("some_dir/subdir"));
|
|---|
| 574 | PRINT_EXPR(QFile::exists("some_dir/subdir"));
|
|---|
| 575 | PRINT_EXPR(QDir().rmdir("some_dir/subdir"));
|
|---|
| 576 |
|
|---|
| 577 | PRINT_EXPR(QDir().mkpath("some_dir/subdir"));
|
|---|
| 578 | PRINT_EXPR(QFile::exists("some_dir/subdir"));
|
|---|
| 579 | PRINT_EXPR(QDir().rmpath("some_dir/subdir"));
|
|---|
| 580 |
|
|---|
| 581 | PRINT_EXPR(QDir("C:/").mkpath("some_dir/subdir"));
|
|---|
| 582 | PRINT_EXPR(QFile::exists("C:/some_dir/subdir"));
|
|---|
| 583 | PRINT_EXPR(QDir("C:/").rmpath("some_dir/subdir"));
|
|---|
| 584 |
|
|---|
| 585 | PRINT_EXPR(QDir("C:/").mkdir("/aaa"));
|
|---|
| 586 | PRINT_EXPR(QFile::exists("C:/aaa"));
|
|---|
| 587 | PRINT_EXPR(QDir("C:/").rmdir("/aaa"));
|
|---|
| 588 | #endif
|
|---|
| 589 |
|
|---|
| 590 | #if 0
|
|---|
| 591 | //--------------------------------------------------------------------------
|
|---|
| 592 | // QLibraryInfo test
|
|---|
| 593 | qWarning() << "QLibraryInfo::buildKey :" << QLibraryInfo::buildKey();
|
|---|
| 594 | qWarning() << "QLibraryInfo::licensedProducts :" << QLibraryInfo::licensedProducts();
|
|---|
| 595 | qWarning() << "QLibraryInfo::licensee :" << QLibraryInfo::licensee();
|
|---|
| 596 | #define PRINT_LOC(L) qWarning() << #L << ":" << QLibraryInfo::location(L)
|
|---|
| 597 | PRINT_LOC(QLibraryInfo::PrefixPath);
|
|---|
| 598 | PRINT_LOC(QLibraryInfo::DocumentationPath);
|
|---|
| 599 | PRINT_LOC(QLibraryInfo::HeadersPath);
|
|---|
| 600 | PRINT_LOC(QLibraryInfo::LibrariesPath);
|
|---|
| 601 | PRINT_LOC(QLibraryInfo::BinariesPath);
|
|---|
| 602 | PRINT_LOC(QLibraryInfo::PluginsPath);
|
|---|
| 603 | PRINT_LOC(QLibraryInfo::DataPath);
|
|---|
| 604 | PRINT_LOC(QLibraryInfo::TranslationsPath);
|
|---|
| 605 | PRINT_LOC(QLibraryInfo::SettingsPath);
|
|---|
| 606 | PRINT_LOC(QLibraryInfo::DemosPath);
|
|---|
| 607 | PRINT_LOC(QLibraryInfo::ExamplesPath);
|
|---|
| 608 | #undef PRINT_LOC
|
|---|
| 609 | #endif
|
|---|
| 610 |
|
|---|
| 611 | #if 0
|
|---|
| 612 | //--------------------------------------------------------------------------
|
|---|
| 613 | // QSettings test
|
|---|
| 614 |
|
|---|
| 615 | QSettings sysOrgSet(QSettings::IniFormat, QSettings::SystemScope,
|
|---|
| 616 | QLatin1String("MySoft"));
|
|---|
| 617 | QSettings sysAppSet(QSettings::IniFormat, QSettings::SystemScope,
|
|---|
| 618 | QLatin1String("MySoft"), QLatin1String("MyApp"));
|
|---|
| 619 | QSettings userOrgSet(QSettings::IniFormat, QSettings::UserScope,
|
|---|
| 620 | QLatin1String("MySoft"));
|
|---|
| 621 | QSettings userAppSet(QSettings::IniFormat, QSettings::UserScope,
|
|---|
| 622 | QLatin1String("MySoft"), QLatin1String("MyApp"));
|
|---|
| 623 |
|
|---|
| 624 | QList<QSettings *> sets;
|
|---|
| 625 | sets << &sysOrgSet << &sysAppSet << &userOrgSet << &userAppSet;
|
|---|
| 626 |
|
|---|
| 627 | foreach (QSettings *set, sets) {
|
|---|
| 628 | set->setValue("Time", QDateTime::currentDateTime());
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 | qWarning() << "Modified Time key in MySoft/MyApp (system & user)";
|
|---|
| 632 | #endif
|
|---|
| 633 |
|
|---|
| 634 | #else
|
|---|
| 635 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 636 | // GUI
|
|---|
| 637 |
|
|---|
| 638 | QApplication app(argc, argv);
|
|---|
| 639 | app.setQuitOnLastWindowClosed(true);
|
|---|
| 640 |
|
|---|
| 641 | #if 0
|
|---|
| 642 | //--------------------------------------------------------------------------
|
|---|
| 643 | // locale test
|
|---|
| 644 |
|
|---|
| 645 | QLocale locale = QLocale::system();
|
|---|
| 646 |
|
|---|
| 647 | qWarning() << "Library paths :" << QApplication::libraryPaths();
|
|---|
| 648 | qWarning() << "";
|
|---|
| 649 | qWarning() << "Available codecs :\n" << QTextCodec::availableCodecs();
|
|---|
| 650 | qWarning() << "";
|
|---|
| 651 | qWarning() << "Codec for locale :" << QTextCodec::codecForLocale()->name();
|
|---|
| 652 | qWarning() << " Aliases :" << QTextCodec::codecForLocale()->aliases();
|
|---|
| 653 | qWarning() << "";
|
|---|
| 654 | qWarning() << "Country for locale :" << QLocale::countryToString(locale.country())
|
|---|
| 655 | << "[" << locale.country() << "]";
|
|---|
| 656 | qWarning() << "Language for locale :" << QLocale::languageToString(locale.language())
|
|---|
| 657 | << "[" << locale.language() << "]";
|
|---|
| 658 | qWarning() << "";
|
|---|
| 659 |
|
|---|
| 660 | testCodec("First 3 months",
|
|---|
| 661 | QString("%1, %2, %3").arg(locale.standaloneMonthName(1),
|
|---|
| 662 | locale.standaloneMonthName(2),
|
|---|
| 663 | locale.standaloneMonthName(3)),
|
|---|
| 664 | QTextCodec::codecForLocale());
|
|---|
| 665 | return 0;
|
|---|
| 666 | #endif
|
|---|
| 667 |
|
|---|
| 668 | #if 1
|
|---|
| 669 | QRect r = QApplication::desktop()->availableGeometry();
|
|---|
| 670 | MyWidget widget;
|
|---|
| 671 | widget.resize(100, 100);
|
|---|
| 672 | widget.move(r.width() - 200, r.height() - 200);
|
|---|
| 673 |
|
|---|
| 674 | widget.show();
|
|---|
| 675 | #endif
|
|---|
| 676 |
|
|---|
| 677 | #if 0
|
|---|
| 678 | //--------------------------------------------------------------------------
|
|---|
| 679 | // QFontDialog test
|
|---|
| 680 | {
|
|---|
| 681 | QFontDialog fntDlg;
|
|---|
| 682 | fntDlg.exec();
|
|---|
| 683 |
|
|---|
| 684 | {
|
|---|
| 685 | QFont font("MyCoolFont");
|
|---|
| 686 | QFontInfo info(font);
|
|---|
| 687 | qDebug() << info.family();
|
|---|
| 688 | }
|
|---|
| 689 | {
|
|---|
| 690 | QFont font("MyCoolFont2");
|
|---|
| 691 | QFontInfo info(font);
|
|---|
| 692 | qDebug() << info.family();
|
|---|
| 693 | }
|
|---|
| 694 | }
|
|---|
| 695 | #endif
|
|---|
| 696 |
|
|---|
| 697 | #if 0
|
|---|
| 698 | //--------------------------------------------------------------------------
|
|---|
| 699 | // QFileDialog test
|
|---|
| 700 | {
|
|---|
| 701 | QFileDialog dlg;
|
|---|
| 702 |
|
|---|
| 703 | dlg.setFileMode(QFileDialog::ExistingFile);
|
|---|
| 704 | //dlg.setFilter(QDir::Dirs | QDir::Files | QDir::Drives);
|
|---|
| 705 | dlg.setNameFilter("*.exe");
|
|---|
| 706 | dlg.selectFile("mplayer.exe");
|
|---|
| 707 | dlg.exec();
|
|---|
| 708 |
|
|---|
| 709 | //PRINT_EXPR(QFileDialog::getOpenFileName());
|
|---|
| 710 | }
|
|---|
| 711 | #endif
|
|---|
| 712 |
|
|---|
| 713 | #if 0
|
|---|
| 714 | QSound snd2("C:/MMOS2/SOUNDS/DESKTOP/dsk_shut.wav");
|
|---|
| 715 | snd2.setLoops(2);
|
|---|
| 716 | snd2.play();
|
|---|
| 717 |
|
|---|
| 718 | QSound snd1("C:/MMOS2/SOUNDS/DESKTOP/dsk_strt.wav");
|
|---|
| 719 | snd1.setLoops(3);
|
|---|
| 720 | snd1.play();
|
|---|
| 721 | #endif
|
|---|
| 722 |
|
|---|
| 723 | #if 0
|
|---|
| 724 | widget.startTimer(1000);
|
|---|
| 725 | widget.startTimer(2000);
|
|---|
| 726 | widget.startTimer(4000);
|
|---|
| 727 | #endif
|
|---|
| 728 |
|
|---|
| 729 | #if 0
|
|---|
| 730 | qDebug() << "------------- before min" << widget.geometry() << widget.frameGeometry();
|
|---|
| 731 | widget.showMinimized();
|
|---|
| 732 | qDebug() << "------------- after min" << widget.geometry() << widget.frameGeometry();
|
|---|
| 733 | widget.move(100, 100);
|
|---|
| 734 | qDebug() << "------------- after move" << widget.geometry() << widget.frameGeometry();
|
|---|
| 735 | widget.showNormal();
|
|---|
| 736 | qDebug() << "------------- after norm" << widget.geometry() << widget.frameGeometry();
|
|---|
| 737 | widget.showFullScreen();
|
|---|
| 738 | qDebug() << "------------- after full" << widget.geometry() << widget.frameGeometry();
|
|---|
| 739 | #endif
|
|---|
| 740 |
|
|---|
| 741 | if (!app.topLevelWidgets().isEmpty())
|
|---|
| 742 | return app.exec();
|
|---|
| 743 |
|
|---|
| 744 | return 0;
|
|---|
| 745 | #endif
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | #include "widget.moc"
|
|---|