source: tests/widget/widget.cpp@ 501

Last change on this file since 501 was 501, checked in by Dmitry A. Kuminov, 15 years ago

tests/widgets: Testcase for adding and removing application-defined fonts.

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