]> Shamusworld >> Repos - architektonas/blob - src/forms/lineoptions.cpp
Refactored CAD tool bars to use predefined actions.
[architektonas] / src / forms / lineoptions.cpp
1 // lineoptions.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Created this file. :-)
13 //
14
15 #include "lineoptions.h"
16
17 #include "rs.h"
18 #include "rs_actiondrawline.h"
19 #include "rs_actioninterface.h"
20
21 LineOptions::LineOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
22         QWidget(parent, flags), action(NULL),
23         bClose(new QToolButton(this)),
24         bUndo(new QToolButton(this))
25 {
26         QHBoxLayout * layout = new QHBoxLayout(this);
27         layout->setContentsMargins(0, 0, 0, 0);
28
29         bClose->setText(tr("Close"));
30         bUndo->setText(tr("Undo"));
31
32         layout->addWidget(bClose);
33         layout->addWidget(bUndo);
34
35         connect(bClose, SIGNAL(clicked()), this, SLOT(close()));
36         connect(bUndo, SIGNAL(clicked()), this, SLOT(undo()));
37
38         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
39         // nothing will show up on the screen. :-)
40         if (parent)
41                 parent->addWidget(this);
42 }
43
44 LineOptions::~LineOptions()
45 {
46 }
47
48 void LineOptions::setAction(RS_ActionInterface * a)
49 {
50         if (a != NULL && a->rtti() == RS2::ActionDrawLine)
51         {
52                 action = (RS_ActionDrawLine *)a;
53         }
54         else
55         {
56                 RS_DEBUG->print(RS_Debug::D_ERROR, "QG_LineOptions::setAction: wrong action type");
57                 action = NULL;
58         }
59 }
60
61 void LineOptions::close()
62 {
63         if (action)
64                 action->close();
65 }
66
67 void LineOptions::undo()
68 {
69         if (action)
70                 action->undo();
71 }