]> Shamusworld >> Repos - architektonas/blob - src/forms/arcoptions.cpp
4811be29eefff6576a1ea449ae33dc5414ffe273
[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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/08/2010  Created this file. :-)
15 // JLH  06/08/2010  Fixed problem with widget not showing up in toolbar.
16 //
17
18 #include "arcoptions.h"
19
20 #include "actiondrawarc.h"
21 #include "actioninterface.h"
22 #include "settings.h"
23
24 ArcOptions::ArcOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
25         QWidget(parent, flags),
26         rbPos(new QRadioButton(this)),
27         rbNeg(new QRadioButton(this))
28 {
29         QHBoxLayout * layout = new QHBoxLayout(this);
30         layout->setContentsMargins(0, 0, 0, 0);
31
32         rbPos->setIcon(QIcon(":/res/qg_dirpos"));
33         rbNeg->setIcon(QIcon(":/res/qg_dirneg"));
34
35         layout->addWidget(rbPos);
36         layout->addWidget(rbNeg);
37
38         connect(rbPos, SIGNAL(toggled(bool)), this, SLOT(updateDirection(bool)));
39         connect(rbNeg, SIGNAL(toggled(bool)), this, SLOT(updateDirection(bool)));
40
41         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
42         // nothing will show up on the screen. :-)
43         if (parent)
44                 parent->addWidget(this);
45 }
46
47 ArcOptions::~ArcOptions()
48 {
49         settings.beginGroup("Draw");
50         settings.setValue("ArcReversed", rbNeg->isChecked());
51         settings.endGroup();
52 }
53
54 void ArcOptions::setAction(ActionInterface * a, bool update)
55 {
56         if (a != NULL && a->rtti() == RS2::ActionDrawArc)
57         {
58                 action = (ActionDrawArc *)a;
59
60                 bool reversed;
61
62                 if (update)
63                         reversed = action->isReversed();
64                 else
65                 {
66                         settings.beginGroup("Draw");
67                         reversed = settings.value("ArcReversed", false).toBool();
68                         settings.endGroup();
69                         action->setReversed(reversed);
70                 }
71
72                 rbNeg->setChecked(reversed);
73         }
74         else
75         {
76                 RS_DEBUG->print(RS_Debug::D_ERROR, "QG_ArcOptions::setAction: wrong action type");
77                 action = NULL;
78         }
79 }
80
81 void ArcOptions::updateDirection(bool /*pos*/)
82 {
83         if (action != NULL)
84                 action->setReversed(rbNeg->isChecked());
85 }