summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9f6430c)
raw | patch | inline | side by side (parent: 9f6430c)
author | dgerlach <d-gerlach@ti.com> | |
Wed, 19 Sep 2012 21:45:56 +0000 (16:45 -0500) | ||
committer | dgerlach <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 | patch | blob | history | |
ThermostatDemoSource/schedulepoint.h | patch | blob | history | |
ThermostatDemoSource/schedulescreen.cpp | patch | blob | history |
index 8ae33be8ecef168e1bf90346708c69c8673bd359..1e32a5f55c55052b4c0dc4d742cb41935a9cb3ee 100644 (file)
\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
// 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
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
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
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
\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
\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
{\r
// provide a slot to increase point temperature\r
temp++;\r
+ if(temp>MAXTEMP)temp=MAXTEMP;\r
updateUnit();\r
}\r
\r
{\r
// provide a slot to decrease temperature\r
temp--;\r
+ if(temp<MINTEMP)temp=MINTEMP;\r
updateUnit();\r
}\r
\r
// 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)
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
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)
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);
{
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);
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();
// blur all columns except the currently selected column
blur();
+ */
}