extern WeightDataModel *wdm;
MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent)
+ QMainWindow(parent), ew(new EditWindow(this))
{
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow);
QWidget *central = new QWidget(this);
QHBoxLayout *topLayout = new QHBoxLayout(central);
- // vv LEFT SIDE BEGINS vv
+ topLayout->addWidget(createLeftColumn(central));
+ topLayout->addWidget(createRightColumn(central));
+ createAboutDialog();
+ createMenuBar();
+
+ this->setCentralWidget(central);
+
+ grabZoomKeys(Settings::grabZoomKeys());
+ connect(Settings::self(), SIGNAL(settingChanged()), this, SLOT(update()));
+}
+
+QWidget *MainWindow::createLeftColumn(QWidget *central) {
QWidget *leftContainer = new QWidget(central);
QVBoxLayout *leftLayout = new QVBoxLayout(leftContainer);
leftLayout->setSpacing(1);
leftLayout->setMargin(1);
// vvv LEFT TOP BEGINS vvv
- //QGroupBox * leftTopContainer = new QGroupBox("Today's weight?", leftContainer);
QFrame *leftTopContainer = new QFrame(leftContainer);
leftTopContainer->setFrameShadow(QFrame::Sunken);
leftTopContainer->setFrameStyle(QFrame::StyledPanel);
leftLayout->addWidget(leftTopContainer);
// ^^^ LEFT TOP ENDS ^^^
-// QWidget *vspacer0 = new QWidget(leftContainer);
-// vspacer0->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
-// leftLayout->addWidget(vspacer0);
-
WeightStatsView *stats = new WeightStatsView(wdm, this);
leftLayout->addWidget(stats);
-// QWidget *vspacer = new QWidget(leftContainer);
-// vspacer->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
-// leftLayout->addWidget(vspacer);
-
- ew = new EditWindow(this);
- QPushButton *listButton = new QPushButton("List / edit", leftContainer);
- connect(listButton, SIGNAL(clicked()), ew, SLOT(show()));
- leftLayout->addWidget(listButton);
-
- topLayout->addWidget(leftContainer);
- // ^^ LEFT SIDE ENDS ^^
+ return leftContainer;
+}
+QWidget *MainWindow::createRightColumn(QWidget *central) {
+ createBigGraph();
smallGraph = new WeightGraphView(wdm, "Small", central);
+ connect(smallGraph, SIGNAL(clicked()), bigGraph, SLOT(show()));
+ return smallGraph;
+}
+
+void MainWindow::createBigGraph() {
bigGraph = new WeightGraphView(wdm, "Big", this);
#ifdef Q_WS_MAEMO_5
bigGraph->setAttribute(Qt::WA_Maemo5StackedWindow);
bigGraph->grabZoomKeys(Settings::grabZoomKeys());
#endif
bigGraph->setWindowFlags(bigGraph->windowFlags() | Qt::Window);
- connect(smallGraph, SIGNAL(clicked()), bigGraph, SLOT(show()));
- topLayout->addWidget(smallGraph);
-
- this->setCentralWidget(central);
-
+}
+void MainWindow::createAboutDialog() {
aboutDialog = new QMessageBox(QMessageBox::NoIcon, "About WeightGraph",
- "Copyright (C) 2011 Visa Putkinen. Licence: GPLv2",
+ "Copyright (C) 2011-2012 Visa Putkinen. Licence: GPLv2",
QMessageBox::Close, this);
aboutDialog->setIconPixmap(QPixmap(":/img/icon48"));
- aboutDialog->setInformativeText("Usage: enter your weight every day using "
+ aboutDialog->setInformativeText("Usage: enter your weight daily using "
"the main screen's \"Today's weight?\" box "
"or the List / edit window. You may enter "
"at most one weight per day."
"The weights are stored in human readable (and "
"writeable) form in "
"MyDocs/WeightGraph/weightdata.txt");
+}
-
- //Important: SettingsWindow must be created after all graph
- //views are created or settings won't show all graphs
+void MainWindow::createMenuBar() {
settingsWindow = new SettingsWindow(this);
menuBar()->addAction(tr("Settings"), settingsWindow, SLOT(show()));
- menuBar()->addAction(tr("About"), aboutDialog, SLOT(exec()));
-
- grabZoomKeys(Settings::grabZoomKeys());
-
- connect(Settings::self(), SIGNAL(settingChanged()), this, SLOT(update()));
+ menuBar()->addAction(tr("List / edit"), ew, SLOT(show()));
+ menuBar()->addAction(tr("About / help"), aboutDialog, SLOT(exec()));
}
+
void MainWindow::setTodaysWeight()
{
wdm->setWeightForDate(QDate::currentDate(), weight->value());
void MainWindow::keyPressEvent(QKeyEvent* event)
{
- //qDebug() << "Main window: key pressed: " << event->key();
switch (event->key()) {
case Qt::Key_F7:
smallGraph->decPeriod();
unsigned long val = (grab) ? 1 : 0;
Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
if (!atom) {
- qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM. This example will only work "
- "on a Maemo 5 device!");
+ qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM");
return;
}
-
- XChangeProperty (QX11Info::display(),
- winId(),
- atom,
- XA_INTEGER,
- 32,
- PropModeReplace,
- reinterpret_cast<unsigned char *>(&val),
- 1);
-
- //qDebug() << "Main window grabbed zoom keys: " << winId();
+ XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER, 32,
+ PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
}