]> Shamusworld >> Repos - architektonas/blobdiff - src/forms/cadtoolbarsnap.cpp
Refactored CAD tool bars once more...
[architektonas] / src / forms / cadtoolbarsnap.cpp
index ff7fa81d2bd79cf4e6c6fe5a18d0b7a070bb5b77..833bd42dd26ea3c34ee2360507b610e534991921 100644 (file)
 
 #include "cadtoolbarsnap.h"
 
-#if 0
-#include "cadtoolbar.h"
-#include "qg_actionhandler.h"
-#include "rs_debug.h"
-
-CadToolBarSnap::CadToolBarSnap(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
-       QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
-{
-       ui.setupUi(this);
-}
-
-CadToolBarSnap::~CadToolBarSnap()
-{
-}
-
-//void CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
-//    if (e->button()==RightButton && cadToolBar!=NULL) {
-//cadToolBar->back();
-//        e->accept();
-//    }
-//}
-
-void CadToolBarSnap::contextMenuEvent(QContextMenuEvent * e)
-{
-       e->accept();
-}
-
-void CadToolBarSnap::setCadToolBar(CadToolBar * tb)
-{
-       cadToolBar = tb;
-
-       if (tb!=NULL)
-       {
-               actionHandler = tb->getActionHandler();
-               actionHandler->setCadToolBarSnap(this);
-       }
-       else
-               RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
-}
-
-void CadToolBarSnap::snapFree()
-{
-       if (actionHandler!=NULL)
-       {
-               disableSnaps();
-               ui.bFree->setChecked(true);
-               actionHandler->slotSnapFree();
-       }
-}
-
-void CadToolBarSnap::snapGrid()
-{
-       if (actionHandler!=NULL)
-       {
-               actionHandler->slotSnapGrid();
-               disableSnaps();
-               ui.bGrid->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::snapEndpoint() {
-       if (actionHandler!=NULL) {
-               actionHandler->slotSnapEndpoint();
-               disableSnaps();
-               ui.bEndpoint->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::snapOnEntity() {
-       if (actionHandler!=NULL) {
-               actionHandler->slotSnapOnEntity();
-               disableSnaps();
-               ui.bOnEntity->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::snapCenter() {
-       if (actionHandler!=NULL) {
-               actionHandler->slotSnapCenter();
-               disableSnaps();
-               ui.bCenter->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::snapMiddle() {
-       if (actionHandler!=NULL) {
-               actionHandler->slotSnapMiddle();
-               disableSnaps();
-               ui.bMiddle->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::snapDist() {
-       if (actionHandler!=NULL) {
-               actionHandler->slotSnapDist();
-               disableSnaps();
-               ui.bDist->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::snapIntersection() {
-       if (actionHandler!=NULL) {
-               actionHandler->slotSnapIntersection();
-               disableSnaps();
-               ui.bIntersection->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::snapIntersectionManual()
-{
-       if (actionHandler!=NULL)
-       {
-               actionHandler->slotSnapIntersectionManual();
-               //disableSnaps();
-               //bIntersectionManual->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::restrictNothing()
-{
-       if (actionHandler!=NULL)
-       {
-               actionHandler->slotRestrictNothing();
-               disableRestrictions();
-               ui.bResNothing->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::restrictOrthogonal()
-{
-       if (actionHandler!=NULL)
-       {
-               actionHandler->slotRestrictOrthogonal();
-               disableRestrictions();
-               ui.bResOrthogonal->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::restrictHorizontal()
-{
-       if (actionHandler!=NULL)
-       {
-               actionHandler->slotRestrictHorizontal();
-               disableRestrictions();
-               ui.bResHorizontal->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::restrictVertical()
-{
-       if (actionHandler!=NULL)
-       {
-               actionHandler->slotRestrictVertical();
-               disableRestrictions();
-               ui.bResVertical->setChecked(true);
-       }
-}
-
-void CadToolBarSnap::disableSnaps()
-{
-       if (ui.bFree->isChecked())
-               ui.bFree->setChecked(false);
-
-       if (ui.bGrid->isChecked())
-               ui.bGrid->setChecked(false);
-
-       if (ui.bEndpoint->isChecked())
-               ui.bEndpoint->setChecked(false);
-
-       if (ui.bOnEntity->isChecked())
-               ui.bOnEntity->setChecked(false);
-
-       if (ui.bCenter->isChecked())
-               ui.bCenter->setChecked(false);
-
-       if (ui.bMiddle->isChecked())
-               ui.bMiddle->setChecked(false);
-
-       if (ui.bDist->isChecked())
-               ui.bDist->setChecked(false);
-
-       if (ui.bIntersection->isChecked())
-               ui.bIntersection->setChecked(false);
-
-       if (ui.bIntersectionManual->isChecked())
-               ui.bIntersectionManual->setChecked(false);
-}
-
-void CadToolBarSnap::disableRestrictions()
-{
-       if (ui.bResNothing->isChecked())
-               ui.bResNothing->setChecked(false);
-
-       if (ui.bResOrthogonal->isChecked())
-               ui.bResOrthogonal->setChecked(false);
-
-       if (ui.bResHorizontal->isChecked())
-               ui.bResHorizontal->setChecked(false);
-
-       if (ui.bResVertical->isChecked())
-               ui.bResVertical->setChecked(false);
-}
-
-void CadToolBarSnap::setSnapMode(int sm)
-{
-       switch (sm)
-       {
-       case RS2::SnapFree:
-               ui.bFree->setChecked(true);
-               break;
-       case RS2::SnapEndpoint:
-               ui.bEndpoint->setChecked(true);
-               break;
-       case RS2::SnapGrid:
-               ui.bGrid->setChecked(true);
-               break;
-       case RS2::SnapOnEntity:
-               ui.bOnEntity->setChecked(true);
-               break;
-       case RS2::SnapCenter:
-               ui.bCenter->setChecked(true);
-               break;
-       case RS2::SnapMiddle:
-               ui.bMiddle->setChecked(true);
-               break;
-       case RS2::SnapDist:
-               ui.bDist->setChecked(true);
-               break;
-       case RS2::SnapIntersection:
-               ui.bIntersection->setChecked(true);
-               break;
-       default:
-               break;
-       }
-}
-
-void CadToolBarSnap::setSnapRestriction(int sr)
-{
-       switch (sr)
-       {
-       default:
-       case RS2::RestrictNothing:
-               ui.bResNothing->setChecked(true);
-               break;
-       case RS2::RestrictOrthogonal:
-               ui.bResOrthogonal->setChecked(true);
-               break;
-       case RS2::RestrictHorizontal:
-               ui.bResHorizontal->setChecked(true);
-               break;
-       case RS2::RestrictVertical:
-               ui.bResVertical->setChecked(true);
-               break;
-       }
-}
-
-void CadToolBarSnap::setRelativeZero()
-{
-       if (cadToolBar!=NULL && actionHandler!=NULL)
-               actionHandler->slotSetRelativeZero();
-}
-
-void CadToolBarSnap::lockRelativeZero(bool on)
-{
-       if (cadToolBar!=NULL && actionHandler!=NULL)
-               actionHandler->slotLockRelativeZero(on);
-}
-
-void CadToolBarSnap::setLockRelativeZero(bool on)
-{
-       ui.bLockRelZero->setChecked(on);
-}
-
-void CadToolBarSnap::back()
-{
-       if (cadToolBar != NULL)
-               cadToolBar->back();
-}
-#else
 #include "cadtoolbar.h"
 #include "createqtactions.h"
 
 CadToolBarSnap::CadToolBarSnap(CadToolBar * parent, Qt::WindowFlags flags/*= 0*/):
-       QWidget((QWidget *)parent, flags), cadToolBar(parent)
+       QWidget((QWidget *)parent, flags)
 {
        QGridLayout * gridLayout = new QGridLayout(this);
        gridLayout->setSpacing(0);
        gridLayout->setContentsMargins(0, 0, 0, 0);
 
-       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()));
+       gridLayout->addWidget(parent->CreateBackButton(this), 0, 0, 1, 2);
 
-       gridLayout->addWidget(CreateToolButton(actionSnapFree), 1, 0, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapGrid), 1, 1, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapEndpoint), 2, 0, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapOnEntity), 2, 1, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapCenter), 3, 0, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapMiddle), 3, 1, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapDist), 4, 0, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapIntersection), 4, 1, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionSnapIntersectionManual), 5, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapFree), 1, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapGrid), 1, 1, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapEndpoint), 2, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapOnEntity), 2, 1, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapCenter), 3, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapMiddle), 3, 1, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapDist), 4, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapIntersection), 4, 1, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSnapIntersectionManual), 5, 0, 1, 1);
 
-       gridLayout->addWidget(CreateToolButton(actionRestrictNothing), 7, 0, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionRestrictOrthogonal), 7, 1, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionRestrictHorizontal), 8, 0, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionRestrictVertical), 8, 1, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionRestrictNothing), 7, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionRestrictOrthogonal), 7, 1, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionRestrictHorizontal), 8, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionRestrictVertical), 8, 1, 1, 1);
 
-       gridLayout->addWidget(CreateToolButton(actionSetRelativeZero), 10, 0, 1, 1);
-       gridLayout->addWidget(CreateToolButton(actionLockRelativeZero), 10, 1, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionSetRelativeZero), 10, 0, 1, 1);
+       gridLayout->addWidget(parent->CreateToolButton(actionLockRelativeZero), 10, 1, 1, 1);
 }
 
 CadToolBarSnap::~CadToolBarSnap()
 {
 }
-
-void CadToolBarSnap::back()
-{
-       cadToolBar->back();
-}
-
-QToolButton * CadToolBarSnap::CreateToolButton(QAction * action)
-{
-       QToolButton * button = new QToolButton(this);
-       button->setDefaultAction(action);
-       button->setIconSize(QSize(18, 18));
-
-       return button;
-}
-#endif