00001
00002
00003
00004
00005
00006
00007 #include "Logger.h"
00008 #include <qdebug.h>
00009 #include <QGraphicsRectItem>
00010 #include <QGraphicsScene>
00011 #include <QGraphicsTextItem>
00012 #include "TutorialButton.h"
00013 #include "TutorialButtonRect.h"
00014 #include "TutorialButtonText.h"
00015
00016 const int HORIZONTAL_PADDING = 10;
00017 const int VERTICAL_PADDING = 5;
00018 const double Z_IN_FRONT = 1;
00019
00020 TutorialButton::TutorialButton (const QString &text,
00021 QGraphicsScene &scene)
00022 {
00023 createRect (scene);
00024 createText (text);
00025 }
00026
00027 TutorialButton::~TutorialButton ()
00028 {
00029 QGraphicsScene *scene = m_rect->scene();
00030 scene->removeItem (m_rect);
00031 }
00032
00033 void TutorialButton::createRect (QGraphicsScene &scene)
00034 {
00035
00036 m_rect = new TutorialButtonRect (*this);
00037 m_rect->show ();
00038 m_rect->setPen (QPen (Qt::gray));
00039 m_rect->setBrush (QBrush (Qt::white));
00040 m_rect->setZValue (Z_IN_FRONT);
00041 scene.addItem (m_rect);
00042 }
00043
00044 void TutorialButton::createText (const QString &text)
00045 {
00046
00047
00048 m_text = new TutorialButtonText (*this,
00049 text,
00050 m_rect);
00051 m_text->show ();
00052 }
00053
00054 QSize TutorialButton::size () const
00055 {
00056
00057 return QSize (m_text->boundingRect().size().width() + 2 * HORIZONTAL_PADDING,
00058 m_text->boundingRect().size().height() + 2 * VERTICAL_PADDING);
00059 }
00060
00061 void TutorialButton::handleTriggered()
00062 {
00063 LOG4CPP_INFO_S ((*mainCat)) << "TutorialButton::handleTriggered";
00064
00065
00066 emit signalTriggered ();
00067 }
00068
00069 void TutorialButton::setGeometry (const QPoint &pos)
00070 {
00071
00072 m_rect->setRect(pos.x(),
00073 pos.y(),
00074 m_text->boundingRect().width() + 2 * HORIZONTAL_PADDING,
00075 m_text->boundingRect().height() + 2 * VERTICAL_PADDING);
00076
00077
00078 m_text->setPos (pos.x() + m_rect->boundingRect().width() / 2.0 - m_text->boundingRect().width() / 2.0,
00079 pos.y() + m_rect->boundingRect().height() / 2.0 - m_text->boundingRect().height() / 2.0);
00080 }