9 #include <QGraphicsRectItem> 10 #include <QGraphicsScene> 11 #include <QGraphicsTextItem> 13 #include "TutorialButton.h" 14 #include "TutorialButtonRect.h" 15 #include "TutorialButtonText.h" 17 const int HORIZONTAL_PADDING = 10;
18 const int VERTICAL_PADDING = 5;
19 const double Z_IN_FRONT = 1;
22 QGraphicsScene &scene) :
30 TutorialButton::~TutorialButton ()
32 if (m_rect !=
nullptr) {
33 QGraphicsScene *scene = m_rect->scene();
34 scene->removeItem (m_rect);
41 void TutorialButton::createRect (QGraphicsScene &scene)
46 m_rect->setPen (QPen (Qt::gray));
47 m_rect->setBrush (QBrush (Qt::white));
48 m_rect->setZValue (Z_IN_FRONT);
49 scene.addItem (m_rect);
52 void TutorialButton::createText (
const QString &text)
65 return QSize (qFloor (m_text->boundingRect().size().width() + 2 * HORIZONTAL_PADDING),
66 qFloor (m_text->boundingRect().size().height() + 2 * VERTICAL_PADDING));
71 LOG4CPP_INFO_S ((*mainCat)) <<
"TutorialButton::handleTriggered";
80 m_rect->setRect(pos.x(),
82 m_text->boundingRect().width() + 2 * HORIZONTAL_PADDING,
83 m_text->boundingRect().height() + 2 * VERTICAL_PADDING);
86 m_text->setPos (pos.x() + m_rect->boundingRect().width() / 2.0 - m_text->boundingRect().width() / 2.0,
87 pos.y() + m_rect->boundingRect().height() / 2.0 - m_text->boundingRect().height() / 2.0);
This class customizes QGraphicsTextItem so it performs a callback after a mouse event.