]> Shamusworld >> Repos - architektonas/blobdiff - src/forms/cadtoolbarellipses.cpp
Refactored CAD tool bars to use predefined actions.
[architektonas] / src / forms / cadtoolbarellipses.cpp
index 6e385327fbe3d1fe09b2416d1a55788e40cefcf4..db170f6fc0c6e1565dc392a0c1b78d1fa90a6bee 100644 (file)
 #include "cadtoolbarellipses.h"
 
 #include "cadtoolbar.h"
-#include "qg_actionhandler.h"
-#include "rs_debug.h"
+#include "createqtactions.h"
 
-CadToolBarEllipses::CadToolBarEllipses(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
-       QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
+CadToolBarEllipses::CadToolBarEllipses(CadToolBar * parent, Qt::WindowFlags flags/*= 0*/):
+       QWidget((QWidget *)parent, flags), cadToolBar(parent)
 {
-       ui.setupUi(this);
-}
+       QGridLayout * gridLayout = new QGridLayout(this);
+       gridLayout->setSpacing(0);
+       gridLayout->setContentsMargins(0, 0, 0, 0);
 
-CadToolBarEllipses::~CadToolBarEllipses()
-{
-}
-
-void CadToolBarEllipses::mousePressEvent(QMouseEvent * e)
-{
-       if (e->button() == Qt::RightButton && cadToolBar != NULL)
-       {
-               cadToolBar->back();
-               e->accept();
-       }
-}
+       QAction * actionBack = new QAction(QIcon(":/res/qg_back"), tr("Back"), this);
+       QToolButton * button = new QToolButton(this);
+       button->setDefaultAction(actionBack);
+       QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+       button->setSizePolicy(policy);
+       gridLayout->addWidget(button, 0, 0, 1, 2);
+       connect(button, SIGNAL(triggered(QAction *)), this, SLOT(back()));
 
-void CadToolBarEllipses::contextMenuEvent(QContextMenuEvent * e)
-{
-       e->accept();
+       gridLayout->addWidget(CreateToolButton(actionDrawEllipseAxis), 1, 0, 1, 1);
+       gridLayout->addWidget(CreateToolButton(actionDrawEllipseArcAxis), 1, 1, 1, 1);
 }
 
-void CadToolBarEllipses::setCadToolBar(CadToolBar * tb)
+CadToolBarEllipses::~CadToolBarEllipses()
 {
-       cadToolBar = tb;
-
-       if (tb != NULL)
-               actionHandler = tb->getActionHandler();
-       else
-               RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarEllipses::setCadToolBar(): No valid toolbar set.");
 }
 
-void CadToolBarEllipses::drawEllipseAxis()
+void CadToolBarEllipses::back()
 {
-       if (cadToolBar != NULL && actionHandler != NULL)
-               actionHandler->slotDrawEllipseAxis();
+       cadToolBar->back();
 }
 
-void CadToolBarEllipses::drawEllipseArcAxis()
+QToolButton * CadToolBarEllipses::CreateToolButton(QAction * action)
 {
-       if (cadToolBar != NULL && actionHandler != NULL)
-               actionHandler->slotDrawEllipseArcAxis();
-}
+       QToolButton * button = new QToolButton(this);
+       button->setDefaultAction(action);
+       button->setIconSize(QSize(18, 18));
 
-void CadToolBarEllipses::back()
-{
-       if (cadToolBar != NULL)
-               cadToolBar->back();
+       return button;
 }