]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/thermostat-demo.git/commitdiff
schedulepoint: no longer controlled by arrows, controlled by dragging
authordgerlach <d-gerlach@ti.com>
Wed, 19 Sep 2012 21:45:56 +0000 (16:45 -0500)
committerdgerlach <d-gerlach@ti.com>
Wed, 19 Sep 2012 21:45:56 +0000 (16:45 -0500)
* up and down for temp left and right for time

ThermostatDemoSource/schedulepoint.cpp
ThermostatDemoSource/schedulepoint.h
ThermostatDemoSource/schedulescreen.cpp

index 8ae33be8ecef168e1bf90346708c69c8673bd359..1e32a5f55c55052b4c0dc4d742cb41935a9cb3ee 100644 (file)
@@ -6,16 +6,21 @@
 \r
 #include <QtGui>\r
 \r
+\r
+#define MAXTEMP 100\r
+#define MINTEMP 50\r
+\r
 SchedulePoint::SchedulePoint(int seqNumber)\r
 {\r
     m_globalSettings = GlobalSettings::getInstance();\r
 \r
     // create schedule point with necessary information\r
     ID = seqNumber;\r
-    myBackgroundColor = Qt::blue;\r
     temp = 72;\r
+    pen.setColor((Qt::white));\r
     setFlags(ItemIsSelectable);\r
     location=0;\r
+    m_pressed = false;\r
     updateUnit();\r
 }\r
 \r
@@ -24,6 +29,15 @@ SchedulePoint::~SchedulePoint()
     // destructor\r
 }\r
 \r
+//calculation to make color vary linearly from defined MINTEMP to MAXTEMP\r
+//based on passed temp\r
+\r
+QColor SchedulePoint::tempToColor(int temp)\r
+{\r
+     float pct = ((float)temp-MINTEMP)/100.0 *((float)MAXTEMP/MINTEMP);\r
+     return QColor(255*pct, 0, 255*(1-pct));\r
+}\r
+\r
 void SchedulePoint::setText(const QString &text)\r
 {\r
     // add new text\r
@@ -50,13 +64,11 @@ void SchedulePoint::setPointArea(QRectF pointArea)
 QRectF SchedulePoint::outlineRect() const\r
 {\r
     // define outline rectangle\r
-    const int padding = 5;\r
-    QFontMetricsF metrics = qApp->font();\r
-    QRectF rect = metrics.boundingRect(myText);\r
+    QRectF rect;\r
     //choose either to go smallest size to fit the text or 90% of the row Height\r
     rect.setHeight(qMax(rect.height(), (qreal)(m_weekHeight*.90)));\r
     //adjust to make wider and look normal\r
-    rect.adjust(-padding, 0, padding, 0);\r
+    rect.adjust(-m_timeBlockWidth*2.5, 0, m_timeBlockWidth*2.5, 0);\r
     //make it so the coords represent the center\r
     rect.translate(-rect.center());\r
     return rect;\r
@@ -82,10 +94,12 @@ void SchedulePoint::paint(QPainter *painter,
                           const QStyleOptionGraphicsItem *option, QWidget * /*widget*/)\r
 {\r
     // draw point itself\r
-    QPen pen(Qt::white); // outline color\r
+\r
     if(option->state & QStyle::State_Selected) {\r
 \r
     }\r
+\r
+    myBackgroundColor = tempToColor(temp);\r
     painter->setPen(pen);\r
     painter->setBrush(myBackgroundColor);\r
 \r
@@ -95,11 +109,54 @@ void SchedulePoint::paint(QPainter *painter,
     painter->drawText(rect, Qt::AlignCenter, myText);\r
 }\r
 \r
-void SchedulePoint::mousePressEvent(QGraphicsSceneMouseEvent * /* event */)\r
+void SchedulePoint::mousePressEvent(QGraphicsSceneMouseEvent *e)\r
 {\r
     // provide event handler for mouse click\r
     emit clicked(this);\r
+    m_pressed = true;\r
+    pen.setColor(Qt::black);\r
+    setZValue(10);\r
+    m_xClickPos = e->pos().x();\r
+    m_yClickPos = e->pos().y();\r
+}\r
+\r
+void SchedulePoint::mouseMoveEvent(QGraphicsSceneMouseEvent *e)\r
+{\r
+    // provide event handler for mouse move\r
+    emit clicked(this);\r
+    if(m_pressed == true)\r
+    {\r
+        if(m_yClickPos - m_weekHeight/4 > e->pos().y())\r
+        {\r
+            m_yClickPos = e->pos().y();\r
+            increaseTemp();\r
+        }\r
+        else if(m_yClickPos + m_weekHeight/4 < e->pos().y())\r
+        {\r
+            m_yClickPos = e->pos().y();\r
+            decreaseTemp();\r
+        }\r
+\r
+        if(m_xClickPos - m_timeBlockWidth > e->pos().x())\r
+        {\r
+            //m_xClickPos = e->pos().x();\r
+            shiftLeft();\r
+        }\r
+        else if(m_xClickPos + m_timeBlockWidth < e->pos().x())\r
+        {\r
+            //m_xClickPos = e->pos().x();\r
+            shiftRight();\r
+        }\r
+    }\r
+\r
+    e->accept();\r
+}\r
 \r
+void SchedulePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)\r
+{\r
+    setZValue(0);\r
+    pen.setColor(Qt::white);\r
+    e->accept();\r
 }\r
 \r
 int SchedulePoint::roundness(double size) const\r
@@ -112,6 +169,8 @@ int SchedulePoint::roundness(double size) const
 \r
 void SchedulePoint::shiftLeft()\r
 {\r
+    if(pos().x() - m_timeBlockWidth - boundingRect().width()/2.0 <m_pointArea.left())\r
+        return;\r
     // provide a slot to allow point shifting to the left\r
     location--;\r
     this->moveBy(-m_timeBlockWidth, 0.0);\r
@@ -120,6 +179,9 @@ void SchedulePoint::shiftLeft()
 \r
 void SchedulePoint::shiftRight()\r
 {\r
+    qDebug() <<boundingRect().width()/2.0;\r
+    if(pos().x() + m_timeBlockWidth + boundingRect().width()*1.5 > m_pointArea.right())\r
+        return;\r
     // provide a slot to allow point shifting to the right\r
     location++;\r
     this->moveBy(+m_timeBlockWidth, 0.0);\r
@@ -130,6 +192,7 @@ void SchedulePoint::increaseTemp()
 {\r
     // provide a slot to increase point temperature\r
     temp++;\r
+    if(temp>MAXTEMP)temp=MAXTEMP;\r
     updateUnit();\r
 }\r
 \r
@@ -137,6 +200,7 @@ void SchedulePoint::decreaseTemp()
 {\r
     // provide a slot to decrease temperature\r
     temp--;\r
+    if(temp<MINTEMP)temp=MINTEMP;\r
     updateUnit();\r
 }\r
 \r
@@ -169,9 +233,9 @@ QString SchedulePoint::time()
     // output the current time represnted by this point's location\r
     int timeBlockCount = qRound((pos().x() -m_pointArea.left())/m_timeBlockWidth);\r
     int hours = (timeBlockCount/4.0f + 2.0f);\r
-    qDebug() << "TIME: " << hours << pos().x() << timeBlockCount<< m_pointArea.left() << m_timeBlockWidth;\r
+    //qDebug() << "TIME: " << hours << pos().x() << timeBlockCount<< m_pointArea.left() << m_timeBlockWidth;\r
     int minutes = (timeBlockCount%4) *15;\r
-    qDebug() << "TIME MINUTES: " << minutes << pos().x() << timeBlockCount<< m_pointArea.left() << m_timeBlockWidth;\r
+    //qDebug() << "TIME MINUTES: " << minutes << pos().x() << timeBlockCount<< m_pointArea.left() << m_timeBlockWidth;\r
     QTime time(hours, minutes);\r
     return formatTimeString(time, m_globalSettings->timeFormat());\r
 }\r
index 6746c0d3b3ec0cda732956ee95c52eecd0110a19..ee9d000ab17e0f548a4fced4c67846d28715a2ac 100644 (file)
@@ -31,12 +31,15 @@ public:
     void setTimeBlockWidth(float timeBlockWidth);\r
     void setPointArea(QRectF pointArea);\r
     void setWeekHeight(int weekHeight);\r
+    QColor tempToColor(int temp);\r
 \r
 public slots:\r
     void updateUnit();\r
 \r
 protected:\r
     void mousePressEvent(QGraphicsSceneMouseEvent */* event */);\r
+    void mouseMoveEvent(QGraphicsSceneMouseEvent * /* event */);\r
+    void mouseReleaseEvent(QGraphicsSceneMouseEvent * /* event */);\r
     void paintEvent(QPaintEvent */* event */);\r
 \r
 private:\r
@@ -52,6 +55,10 @@ private:
     QRectF m_pointArea;\r
 \r
     GlobalSettings* m_globalSettings;\r
+    bool m_pressed;\r
+    int m_xClickPos;\r
+    int m_yClickPos;\r
+    QPen pen; // outline color\r
     \r
 signals:\r
     void clicked(SchedulePoint *);\r
index fe52bc3f08843f778213f1809aa6065716849301..1a4e4789b576cfe656392fceeac72db85e79e5e2 100644 (file)
@@ -66,7 +66,7 @@ ScheduleScreen::ScheduleScreen(QWidget *parent) :
 
     QWidget *sizeLimiterWidget = new QWidget;
     sizeLimiterWidget->setMaximumSize(800, 450);
-    //sizeLimiterWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    sizeLimiterWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     sizeLimiterWidget->setLayout(mainLayout);
     QHBoxLayout* contentsBox = new QHBoxLayout;
     contentsBox->addWidget(sizeLimiterWidget);
@@ -196,8 +196,6 @@ void ScheduleScreen::showPoint(SchedulePoint *point)
 {
     qreal timeWidth = ((scene->width()- pointArea.left())/5.0);
 
-    qDebug() << "SHOW POINT  "<< QPoint(pointArea.left() + timeWidth + (timeWidth * (point->getID() % 4)), weekHeight/2 + (weekHeight * ((point->getID() / 4) % 7)));
-
     // show point based on unique ID
     point->setPos(QPoint(pointArea.left() + timeWidth + (timeWidth * (point->getID() % 4)), pointArea.top() + weekHeight/2 + (weekHeight * ((point->getID() / 4) % 7))));
     scene->addItem(point);
@@ -312,7 +310,7 @@ void ScheduleScreen::showButtons(SchedulePoint *point)
     currentTime->setText(currentPoint->time());
 
     // first hide all 4 buttons, then we will make them reappear in the correct position
-    hideButtons();
+    /*hideButtons();
 
     // create left arrow
     QPushButton *leftArrowButton = new QPushButton();
@@ -384,6 +382,7 @@ void ScheduleScreen::showButtons(SchedulePoint *point)
 
     // blur all columns except the currently selected column
     blur();
+    */
 
 }