]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/thermostat-demo.git/blob - awayscreen.cpp
Merge branch 'master' of git://gitorious.org/thermostat-demo/thermostat-demo
[apps/thermostat-demo.git] / awayscreen.cpp
1 #include "awayscreen.h"
2 #include "thermostatwidget.h"
3 #include "globalsettings.h"
4 #include "utilities.h"
5 #include "mainwindow.h"
7 AwayScreen::AwayScreen(QWidget *parent) :
8     QWidget(parent)
9 {
10     // the away screen provides the user an AWAY MODE with the tap of a button
11     // it is meant to be used for long periods of away time (i.e. vacation)
12     // it is called from the mainwindow
14     m_currentTemp = NULL;
16     m_globalSettings = GlobalSettings::getInstance();
18     m_upperBound = 84;
19     m_lowerBound = 60;
21     // title
22     awayLabel = new QLabel("System is using energy saving AWAY MODE");
23     awayLabel->setAlignment(Qt::AlignHCenter);
24     awayLabel->setObjectName("awayLabel");
26     // button to return to main screen
27     QPushButton *backButton = new QPushButton();
28     backButton->setIcon(QIcon(":/Images/glossy-blue-orb-icon-arrowback.png"));
29     backButton->setIconSize(QSize(40,40));
30     backButton->setFocusPolicy(Qt::NoFocus);
31     backButton->setObjectName("backButton");
32     connect(backButton,SIGNAL(clicked()),this,SLOT(close()));
34     // green leaf
35     ecoLabel = new QLabel();
36     ecoLabel->setAlignment(Qt::AlignHCenter);
37     QPixmap *ecoLeaf = new QPixmap(":/Images/eco-leaf.png");
38     *ecoLeaf = ecoLeaf->scaled(60,60,Qt::KeepAspectRatio);
39     ecoLabel->setPixmap(*ecoLeaf);
40     ecoLabel->setObjectName("ecoLabel");
41     ecoLabel->setAlignment(Qt::AlignTop);
43     // provides current temp - same value as listed in MainWindow adjust dynamically
44     currentTempLabel = new QLabel;
45     currentTempLabel->setText("");
46     currentTempLabel->setAlignment(Qt::AlignHCenter);
47     currentTempLabel->setObjectName("currentTemp");
48     currentTempLabel->setMargin(0);
50     // inside label
51     QLabel *insideLabel = new QLabel("Inside");
52     insideLabel->setAlignment(Qt::AlignHCenter);
53     insideLabel->setMargin(0);
55     // layout for current temp
56     QVBoxLayout *currentLayout = new QVBoxLayout;
57     currentLayout->addStretch();
58     currentLayout->addWidget(insideLabel);
59     currentLayout->addWidget(currentTempLabel);
60     currentLayout->addStretch();
62     // upper bound control widget
63     upperBound = new QSpinBox;
64     upperBound->setValue(m_upperBound);
65     upperBound->setSuffix("°");
66     upperBound->findChild<QLineEdit*>()->setReadOnly(true);
68     // lower bound control widget
69     lowerBound = new QSpinBox;
70     lowerBound->setValue(m_lowerBound);
71     lowerBound->setSuffix("°");
72     lowerBound->findChild<QLineEdit*>()->setReadOnly(true);
74     // upper and lower bound labels
75     QLabel *heatTo = new QLabel("Heat to");
76     heatTo->setAlignment(Qt::AlignHCenter);
77     QLabel *coolTo = new QLabel("Cool to");
78     coolTo->setAlignment(Qt::AlignHCenter);
80     // combines upper and lower bounds into one layout
81     QVBoxLayout *boundsLayout = new QVBoxLayout;
82     boundsLayout->addStretch();
83     boundsLayout->addWidget(coolTo);
84     boundsLayout->addWidget(upperBound);
85     boundsLayout->addWidget(heatTo);
86     boundsLayout->addWidget(lowerBound);
87     boundsLayout->addStretch();
89     // combines current temp layout and bounds layout
90     QHBoxLayout *centerLayout = new QHBoxLayout;
91     centerLayout->addStretch();
92     centerLayout->addLayout(currentLayout);
93     centerLayout->addSpacing(20);
94     centerLayout->addLayout(boundsLayout);
95     centerLayout->addStretch();
97     // combines center layout with title
98     QVBoxLayout *rightLayout = new QVBoxLayout;
99     rightLayout->addWidget(awayLabel);
100     rightLayout->insertSpacing(1,10);
103     // combines existing layout with green leaf
104     QHBoxLayout *topLayout = new QHBoxLayout;
105     topLayout->addWidget(ecoLabel);
106     topLayout->addStretch();
107     topLayout->addLayout(rightLayout);
108     topLayout->addStretch();
109     topLayout->addWidget(backButton);
111     QVBoxLayout *mainLayout = new QVBoxLayout;
112     mainLayout->addLayout(topLayout);
113     mainLayout->addLayout(centerLayout);
114     mainLayout->setAlignment(centerLayout,Qt::AlignHCenter);
116     // show final layout
117     setLayout(mainLayout);
120 void AwayScreen::updateCurrentTemp()
122     // updates current temp in away screen based on current temp in main window
123     // connects to 10 second update timer within thermostat widget
124     currentTempLabel->setText(formatTemperatureString(*m_currentTemp, m_globalSettings->temperatureFormat()));
127 void AwayScreen::updateUnit()
129     upperBound->setValue(formatTemperature(m_upperBound, m_globalSettings->temperatureFormat()));
130     lowerBound->setValue(formatTemperature(m_lowerBound, m_globalSettings->temperatureFormat()));
132     updateCurrentTemp();
135 void AwayScreen::setCurrentTempPtr(int *currentTempPointer)
137     m_currentTemp = currentTempPointer;