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