]> Shamusworld >> Repos - architektonas/blob - src/forms/arcoptions.cpp
Bugfixes related to removing Snapper class.
[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 "debug.h"
23 #include "settings.h"
24
25 ArcOptions::ArcOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
26         QWidget(parent, flags),
27         rbPos(new QRadioButton(this)),
28         rbNeg(new QRadioButton(this))
29 {
30         QHBoxLayout * layout = new QHBoxLayout(this);
31         layout->setContentsMargins(0, 0, 0, 0);
32
33         rbPos->setIcon(QIcon(":/res/qg_dirpos"));
34         rbNeg->setIcon(QIcon(":/res/qg_dirneg"));
35
36         layout->addWidget(rbPos);
37         layout->addWidget(rbNeg);
38
39         connect(rbPos, SIGNAL(toggled(bool)), this, SLOT(updateDirection(bool)));
40         connect(rbNeg, SIGNAL(toggled(bool)), this, SLOT(updateDirection(bool)));
41
42         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
43         // nothing will show up on the screen. :-)
44         if (parent)
45                 parent->addWidget(this);
46 }
47
48 ArcOptions::~ArcOptions()
49 {
50         settings.beginGroup("Draw");
51         settings.setValue("ArcReversed", rbNeg->isChecked());
52         settings.endGroup();
53 }
54
55 void ArcOptions::setAction(ActionInterface * a, bool update)
56 {
57         if (a != NULL && a->rtti() == RS2::ActionDrawArc)
58         {
59                 action = (ActionDrawArc *)a;
60
61                 bool reversed;
62
63                 if (update)
64                         reversed = action->isReversed();
65                 else
66                 {
67                         settings.beginGroup("Draw");
68                         reversed = settings.value("ArcReversed", false).toBool();
69                         settings.endGroup();
70                         action->setReversed(reversed);
71                 }
72
73                 rbNeg->setChecked(reversed);
74         }
75         else
76         {
77                 DEBUG->print(Debug::D_ERROR, "QG_ArcOptions::setAction: wrong action type");
78                 action = NULL;
79         }
80 }
81
82 void ArcOptions::updateDirection(bool /*pos*/)
83 {
84         if (action != NULL)
85                 action->setReversed(rbNeg->isChecked());
86 }