Skip to content

Commit

Permalink
Got the hover text centered
Browse files Browse the repository at this point in the history
  • Loading branch information
macumber committed Jan 30, 2015
1 parent 1666408 commit acfe8f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
65 changes: 37 additions & 28 deletions openstudiocore/src/openstudio_lib/ScheduleDayView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,28 +1502,54 @@ DaySchedulePlotArea::DaySchedulePlotArea(ScheduleDayEditor * scheduleDayEditor)
m_scheduleDayEditor(scheduleDayEditor),
m_currentItem(nullptr),
m_currentHoverItem(nullptr),
m_keyboardInputText()
m_keyboardInputTextItem(nullptr)
{
connect(this, &DaySchedulePlotArea::dayScheduleSceneChanged, m_scheduleDayEditor->scheduleDayView()->schedulesView(), &SchedulesView::dayScheduleSceneChanged);
setFocusPolicy(Qt::StrongFocus);

m_keyboardInputText = new QGraphicsTextItem();
m_keyboardInputTextItem = new QGraphicsTextItem();
QTimer::singleShot(0, this, SLOT(initialize()));
}

void DaySchedulePlotArea::initialize()
{
scene()->addItem(m_keyboardInputText);
scene()->addItem(m_keyboardInputTextItem);

// DLM: I am almost certain this is not the best way to do this
QFont font;
font.setPointSize(1000);
font.setStretch(50);
m_keyboardInputText->setFont(font);
m_keyboardInputTextItem->setFont(font);

///m_keyboardInputText->adjustSize();
}

void DaySchedulePlotArea::updateKeyboardInputTextItem()
{
if (m_currentHoverItem){

if (m_keyboardInputValue.isEmpty()){
m_keyboardInputTextItem->setHtml("<center>Enter Value</center>");
} else {
QString tmp = "<center>" + m_keyboardInputValue + "</center>";
m_keyboardInputTextItem->setHtml(tmp);
}

double x = m_currentHoverItem->hCenterPos();
double y = m_currentHoverItem->vCenterPos();
double width = m_currentHoverItem->boundingRect().width();

double textX = x - width / 2.0;
double textY = y - 1.5 * LINEWIDTH;
m_keyboardInputTextItem->setPos(textX, textY);
m_keyboardInputTextItem->setTextWidth(width);

} else{
m_keyboardInputTextItem->setPlainText("");
}
}


QGraphicsItem * DaySchedulePlotArea::segmentAt(QPoint point) const
{
double zoom = m_scheduleDayEditor->scheduleDayView()->zoom();
Expand Down Expand Up @@ -1612,7 +1638,7 @@ void DaySchedulePlotArea::mouseMoveEvent(QMouseEvent * event)
m_currentHoverItem = nullptr;

m_keyboardInputValue.clear();
m_keyboardInputText->setPlainText("");
m_keyboardInputTextItem->setPlainText("");

if( m_currentItem )
{
Expand All @@ -1622,10 +1648,7 @@ void DaySchedulePlotArea::mouseMoveEvent(QMouseEvent * event)

m_currentHoverItem = calendarItem;

m_keyboardInputText->setPlainText("Enter Value");
double textX = m_currentHoverItem->hCenterPos() - 2 * LINEWIDTH;
double textY = m_currentHoverItem->vCenterPos() - 1.5 * LINEWIDTH;
m_keyboardInputText->setPos(textX, textY);
updateKeyboardInputTextItem();

setFocus();

Expand Down Expand Up @@ -1747,10 +1770,7 @@ void DaySchedulePlotArea::mouseMoveEvent(QMouseEvent * event)

m_currentHoverItem = calendarItem;

m_keyboardInputText->setPlainText("Enter Value");
double textX = m_currentHoverItem->hCenterPos() - 2 * LINEWIDTH;
double textY = m_currentHoverItem->vCenterPos() - 1.5 * LINEWIDTH;
m_keyboardInputText->setPos(textX, textY);
updateKeyboardInputTextItem();

setFocus();

Expand Down Expand Up @@ -1841,7 +1861,7 @@ void DaySchedulePlotArea::keyPressEvent(QKeyEvent * event)
m_currentHoverItem->setValue(scaledValue);

m_keyboardInputValue.clear();
m_keyboardInputText->setPlainText("");
m_keyboardInputTextItem->setPlainText("");

m_currentHoverItem->setHovering(false);

Expand All @@ -1852,21 +1872,13 @@ void DaySchedulePlotArea::keyPressEvent(QKeyEvent * event)
else if( event->key() == Qt::Key_Minus )
{
m_keyboardInputValue.clear();

m_keyboardInputValue.append(event->text());
m_keyboardInputText->setPlainText("-");
double textX = m_currentHoverItem->hCenterPos() - 2 * LINEWIDTH;
double textY = m_currentHoverItem->vCenterPos() - 1.5 * LINEWIDTH;
m_keyboardInputText->setPos(textX, textY);
updateKeyboardInputTextItem();
}
else if (event->key() == Qt::Key_Backspace)
{
m_keyboardInputValue.chop(1);

m_keyboardInputText->setPlainText(m_keyboardInputValue);
double textX = m_currentHoverItem->hCenterPos() - 2 * LINEWIDTH;
double textY = m_currentHoverItem->vCenterPos() - 1.5* LINEWIDTH;
m_keyboardInputText->setPos(textX, textY);
updateKeyboardInputTextItem();
}
else if( event->key() == Qt::Key_0 ||
event->key() == Qt::Key_1 ||
Expand All @@ -1882,10 +1894,7 @@ void DaySchedulePlotArea::keyPressEvent(QKeyEvent * event)
)
{
m_keyboardInputValue.append(event->text());
m_keyboardInputText->setPlainText(m_keyboardInputValue);
double textX = m_currentHoverItem->hCenterPos() - 2 * LINEWIDTH;
double textY = m_currentHoverItem->vCenterPos() - 1.5 * LINEWIDTH;
m_keyboardInputText->setPos(textX, textY);
updateKeyboardInputTextItem();
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion openstudiocore/src/openstudio_lib/ScheduleDayView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,15 @@ class DaySchedulePlotArea : public QGraphicsView

private:

void updateKeyboardInputTextItem();

ScheduleDayEditor * m_scheduleDayEditor;

QGraphicsItem * m_currentItem;

CalendarSegmentItem * m_currentHoverItem;

QGraphicsTextItem * m_keyboardInputText;
QGraphicsTextItem * m_keyboardInputTextItem;

QString m_keyboardInputValue;

Expand Down

4 comments on commit acfe8f5

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

86121908_copy_schedule (macumber) - x86_64-Linux-Ubuntu-14.04-clang-3.5: OK (2160 of 2190 tests passed)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

86121908_copy_schedule (macumber) - x86_64-Linux-Ubuntu-14.04-cppcheck-1.61: Build Failed

Build Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

86121908_copy_schedule (macumber) - Win64-Windows-7-VisualStudio-12: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

86121908_copy_schedule (macumber) - i386-Windows-7-VisualStudio-12: OK (2176 of 2190 tests passed)

Build Badge Test Badge

Please sign in to comment.