Add new widget ToolButtonBox. Add setting to prevent display blanking.
[dorian] / devtools.cpp
1 #include <QtGui>
2 #include <QDebug>
3
4 #include "devtools.h"
5 #include "trace.h"
6 #include "settings.h"
7 #include "toolbuttonbox.h"
8
9 DevTools::DevTools(QWidget *parent):
10         QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
11                 Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint)
12 {
13     setWindowTitle(tr("Developer"));
14     QScrollArea *scroller = new QScrollArea(this);
15     scroller->setFrameStyle(QFrame::NoFrame);
16 #ifdef Q_WS_MAEMO_5
17     scroller->setProperty("FingerScrollable", true);
18     scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
19 #else
20     scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
21     setSizeGripEnabled(true);
22 #endif // Q_WS_MAEMO_5
23     scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
24
25     QWidget *contents = new QWidget(scroller);
26     QVBoxLayout *layout = new QVBoxLayout(contents);
27
28     QPushButton *clearSettings = new QPushButton("Clear persistent data", this);
29     connect(clearSettings, SIGNAL(clicked()), this, SLOT(onClear()));
30     layout->addWidget(clearSettings);
31
32     QLabel *level = new QLabel(tr("Trace level:"), contents);
33     layout->addWidget(level);
34
35     ToolButtonBox *box = new ToolButtonBox(this);
36     layout->addWidget(box);
37     box->addButton(QtDebugMsg, tr("Debug"));
38     box->addButton(QtWarningMsg, tr("Warning"));
39     box->addButton(QtCriticalMsg, tr("Critical"));
40     box->addButton(QtFatalMsg, tr("Fatal"));
41     box->toggle(Trace::level);
42     connect(box, SIGNAL(buttonClicked(int)),
43             this, SLOT(onLevelButtonClicked(int)));
44
45     contents->setLayout(layout);
46     scroller->setWidget(contents);
47
48     QHBoxLayout *dialogLayout = new QHBoxLayout();
49     dialogLayout->addWidget(scroller);
50     setLayout(dialogLayout);
51 }
52
53 void DevTools::onClear()
54 {
55     if (QMessageBox::Yes ==
56         QMessageBox::question(this, "Clear persistent data?",
57                               "Library and settings data will be cleared, "
58                               "application will be restarted. Continue?",
59                               QMessageBox::Yes
60 #ifndef Q_WS_MAEMO_5
61                               , QMessageBox::No
62 #endif
63                               )) {
64         QSettings().clear();
65         QApplication::exit(1000);
66     }
67 }
68
69 void DevTools::onLevelButtonClicked(int level) {
70     Trace::level = (QtMsgType)level;
71     Settings::instance()->setValue("tracelevel", level);
72 }