Engauge Digitizer  2
Signals | Public Member Functions | List of all members
TutorialButton Class Reference

Show a button with text for clicking ion. The button is implemented using layering of two graphics items (text and rectangle) More...

#include <TutorialButton.h>

Inheritance diagram for TutorialButton:
Inheritance graph
Collaboration diagram for TutorialButton:
Collaboration graph

Signals

void signalTriggered ()
 Signal that button was triggered. More...
 

Public Member Functions

 TutorialButton (const QString &text, QGraphicsScene &scene)
 Single constructor. Position is set after creation using setGeometry. More...
 
 ~TutorialButton ()
 
void handleTriggered ()
 Callback to be called when button was triggered by mouse event. More...
 
void setGeometry (const QPoint &pos)
 Set the position. This is called after creation so screen extent is available for positioning calculations. More...
 
QSize size () const
 Size of this button. More...
 

Detailed Description

Show a button with text for clicking ion. The button is implemented using layering of two graphics items (text and rectangle)

Definition at line 20 of file TutorialButton.h.

Constructor & Destructor Documentation

◆ TutorialButton()

TutorialButton::TutorialButton ( const QString &  text,
QGraphicsScene &  scene 
)

Single constructor. Position is set after creation using setGeometry.

Definition at line 21 of file TutorialButton.cpp.

22  :
23  m_rect (nullptr),
24  m_text (nullptr)
25 {
26  createRect (scene);
27  createText (text);
28 }

◆ ~TutorialButton()

TutorialButton::~TutorialButton ( )

Definition at line 30 of file TutorialButton.cpp.

31 {
32  if (m_rect != nullptr) {
33  QGraphicsScene *scene = m_rect->scene();
34  scene->removeItem (m_rect); // This also removes m_text from the scene
35 
36  delete m_rect;
37  }
38  delete m_text;
39 }

Member Function Documentation

◆ handleTriggered()

void TutorialButton::handleTriggered ( )

Callback to be called when button was triggered by mouse event.

Definition at line 69 of file TutorialButton.cpp.

70 {
71  LOG4CPP_INFO_S ((*mainCat)) << "TutorialButton::handleTriggered";
72 
73  // Relay signal from internal widgets to outside world
74  emit signalTriggered ();
75 }
void signalTriggered()
Signal that button was triggered.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ setGeometry()

void TutorialButton::setGeometry ( const QPoint &  pos)

Set the position. This is called after creation so screen extent is available for positioning calculations.

Definition at line 77 of file TutorialButton.cpp.

78 {
79  // Size the rectangle to fit the text, now that the extent of the text is known, with padding on the four sides
80  m_rect->setRect(pos.x(),
81  pos.y(),
82  m_text->boundingRect().width() + 2 * HORIZONTAL_PADDING,
83  m_text->boundingRect().height() + 2 * VERTICAL_PADDING);
84 
85  // Put text at the center of the rectangle
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);
88 }
const int VERTICAL_PADDING
const int HORIZONTAL_PADDING

◆ signalTriggered

void TutorialButton::signalTriggered ( )
signal

Signal that button was triggered.

◆ size()

QSize TutorialButton::size ( ) const

Size of this button.

Definition at line 62 of file TutorialButton.cpp.

63 {
64  // The size of the rectangle is not updated until later so we use the size of the text
65  return QSize (qFloor (m_text->boundingRect().size().width() + 2 * HORIZONTAL_PADDING),
66  qFloor (m_text->boundingRect().size().height() + 2 * VERTICAL_PADDING));
67 }
const int VERTICAL_PADDING
const int HORIZONTAL_PADDING

The documentation for this class was generated from the following files: