]> Shamusworld >> Repos - architektonas/blob - src/forms/arcoptions.cpp
Start of bringing back missing forms/dialogs
[architektonas] / src / forms / arcoptions.cpp
1 // arcoptions.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  06/08/2010  Created this file. :-)
13 // JLH  06/08/2010  Fixed problem with widget not showing up in toolbar.
14 //
15
16 #include "arcoptions.h"
17
18 #include "rs_actiondrawarc.h"
19 #include "rs_actioninterface.h"
20 #include "settings.h"
21
22 ArcOptions::ArcOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags)
24 {
25         QHBoxLayout * layout = new QHBoxLayout(this);
26         layout->setContentsMargins(0, 0, 0, 0);
27
28         rbPos = new QRadioButton(this);
29         rbNeg = new QRadioButton(this);
30
31         rbPos->setIcon(QIcon(":/res/qg_dirpos.xpm"));
32         rbNeg->setIcon(QIcon(":/res/qg_dirneg.xpm"));
33
34         layout->addWidget(rbPos);
35         layout->addWidget(rbNeg);
36
37         connect(rbPos, SIGNAL(toggled(bool)), this, SLOT(updateDirection(bool)));
38         connect(rbNeg, SIGNAL(toggled(bool)), this, SLOT(updateDirection(bool)));
39
40         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
41         // nothing will show up on the screen. :-)
42         if (parent)
43                 parent->addWidget(this);
44 }
45
46 ArcOptions::~ArcOptions()
47 {
48         settings.beginGroup("Draw");
49         settings.setValue("ArcReversed", rbNeg->isChecked());
50         settings.endGroup();
51 }
52
53 void ArcOptions::setAction(RS_ActionInterface * a, bool update)
54 {
55         if (a != NULL && a->rtti() == RS2::ActionDrawArc)
56         {
57                 action = (RS_ActionDrawArc *)a;
58
59                 bool reversed;
60
61                 if (update)
62                         reversed = action->isReversed();
63                 else
64                 {
65                         settings.beginGroup("Draw");
66                         reversed = settings.value("ArcReversed", false).toBool();
67                         settings.endGroup();
68                         action->setReversed(reversed);
69                 }
70
71                 rbNeg->setChecked(reversed);
72         }
73         else
74         {
75                 RS_DEBUG->print(RS_Debug::D_ERROR, "QG_ArcOptions::setAction: wrong action type");
76                 action = NULL;
77         }
78 }
79
80 void ArcOptions::updateDirection(bool /*pos*/)
81 {
82         if (action != NULL)
83                 action->setReversed(rbNeg->isChecked());
84 }