1 //#include "ui_mainwindow.h"
2 #include "mainwindow.h"
3 #include "weightdata.h"
4 #include "weightstatsview.h"
5 #include "weightgraphview.h"
6 #include <QtGui/QX11Info>
10 extern WeightDataModel *wdm;
12 MainWindow::MainWindow(QWidget *parent) :
13 QMainWindow(parent), ew(new EditWindow(this))
16 setAttribute(Qt::WA_Maemo5StackedWindow);
19 setWindowTitle("WeightGraph");
21 QWidget *central = new QWidget(this);
22 QHBoxLayout *topLayout = new QHBoxLayout(central);
24 topLayout->addWidget(createLeftColumn(central));
25 topLayout->addWidget(createRightColumn(central));
29 this->setCentralWidget(central);
31 grabZoomKeys(Settings::grabZoomKeys());
32 connect(Settings::self(), SIGNAL(settingChanged()), this, SLOT(update()));
35 QWidget *MainWindow::createLeftColumn(QWidget *central) {
36 QWidget *leftContainer = new QWidget(central);
37 QVBoxLayout *leftLayout = new QVBoxLayout(leftContainer);
38 leftLayout->setSpacing(1);
39 leftLayout->setMargin(1);
41 // vvv LEFT TOP BEGINS vvv
42 QFrame *leftTopContainer = new QFrame(leftContainer);
43 leftTopContainer->setFrameShadow(QFrame::Sunken);
44 leftTopContainer->setFrameStyle(QFrame::StyledPanel);
45 leftTopContainer->setLineWidth(2);
46 leftTopContainer->setMidLineWidth(2);
47 QGridLayout *leftTopLayout = new QGridLayout(leftTopContainer);
49 QLabel *todayLabel = new QLabel("Today's weight?", leftContainer);
50 leftTopLayout->addWidget(todayLabel, 0, 0);
52 weight = new WeightSpinBox(leftTopContainer);
54 weight->setValue(wdm->getWeights().last().weight);
55 leftTopLayout->addWidget(weight, 1, 0);
57 QPushButton *setButton = new QPushButton("Set", leftTopContainer);
58 connect(setButton, SIGNAL(clicked()), this, SLOT(setTodaysWeight()));
59 leftTopLayout->addWidget(setButton, 2, 0);
61 leftLayout->addWidget(leftTopContainer);
62 // ^^^ LEFT TOP ENDS ^^^
64 WeightStatsView *stats = new WeightStatsView(wdm, this);
65 leftLayout->addWidget(stats);
70 QWidget *MainWindow::createRightColumn(QWidget *central) {
72 smallGraph = new WeightGraphView(wdm, "Small", central);
73 connect(smallGraph, SIGNAL(clicked()), bigGraph, SLOT(show()));
77 void MainWindow::createBigGraph() {
78 bigGraph = new WeightGraphView(wdm, "Big", this);
80 bigGraph->setAttribute(Qt::WA_Maemo5StackedWindow);
81 bigGraph->grabZoomKeys(Settings::grabZoomKeys());
83 bigGraph->setWindowFlags(bigGraph->windowFlags() | Qt::Window);
86 void MainWindow::createAboutDialog() {
87 aboutDialog = new QMessageBox(QMessageBox::NoIcon, "About WeightGraph",
88 "Copyright (C) 2011-2012 Visa Putkinen. Licence: GPLv2",
89 QMessageBox::Close, this);
90 aboutDialog->setIconPixmap(QPixmap(":/img/icon48"));
91 aboutDialog->setInformativeText("Usage: enter your weight daily using "
92 "the main screen's \"Today's weight?\" box "
93 "or the List / edit window. You may enter "
94 "at most one weight per day."
96 "A graph of the weights will be drawn when "
97 "two or more weights are entered. Tap the "
98 "graph to open a larger graph view. Use the "
99 "external zoom buttons to adjust the shown "
102 "The weights are stored in human readable (and "
103 "writeable) form in "
104 "MyDocs/WeightGraph/weightdata.txt");
107 void MainWindow::createMenuBar() {
108 settingsWindow = new SettingsWindow(this);
109 menuBar()->addAction(tr("Settings"), settingsWindow, SLOT(show()));
110 menuBar()->addAction(tr("List / edit"), ew, SLOT(show()));
111 menuBar()->addAction(tr("About / help"), aboutDialog, SLOT(exec()));
115 void MainWindow::setTodaysWeight()
117 wdm->setWeightForDate(QDate::currentDate(), weight->value());
120 void MainWindow::keyPressEvent(QKeyEvent* event)
122 switch (event->key()) {
124 smallGraph->decPeriod();
129 smallGraph->incPeriod();
133 QWidget::keyPressEvent(event);
135 void MainWindow::grabZoomKeys(bool grab)
137 WeightGraphView::grabZoomKeysForWindow(winId(), grab);