~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/ui/forms/qg_insertoptions.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
9
** This file may be distributed and/or modified under the terms of the
 
10
** GNU General Public License version 2 as published by the Free Software 
 
11
** Foundation and appearing in the file gpl-2.0.txt included in the
 
12
** packaging of this file.
 
13
**
 
14
** This program is distributed in the hope that it will be useful,
 
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
** GNU General Public License for more details.
 
18
** 
 
19
** You should have received a copy of the GNU General Public License
 
20
** along with this program; if not, write to the Free Software
 
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!  
 
24
**
 
25
**********************************************************************/
 
26
#include "qg_insertoptions.h"
 
27
 
 
28
#include "rs_actioninterface.h"
 
29
#include "rs_actionblocksinsert.h"
 
30
#include "rs_settings.h"
 
31
 
 
32
/*
 
33
 *  Constructs a QG_InsertOptions as a child of 'parent', with the
 
34
 *  name 'name' and widget flags set to 'f'.
 
35
 */
 
36
QG_InsertOptions::QG_InsertOptions(QWidget* parent, Qt::WindowFlags fl)
 
37
    : QWidget(parent, fl)
 
38
{
 
39
    setupUi(this);
 
40
 
 
41
}
 
42
 
 
43
/*
 
44
 *  Destroys the object and frees any allocated resources
 
45
 */
 
46
QG_InsertOptions::~QG_InsertOptions()
 
47
{
 
48
    destroy();
 
49
    // no need to delete child widgets, Qt does it all for us
 
50
}
 
51
 
 
52
/*
 
53
 *  Sets the strings of the subwidgets using the current
 
54
 *  language.
 
55
 */
 
56
void QG_InsertOptions::languageChange()
 
57
{
 
58
    retranslateUi(this);
 
59
}
 
60
 
 
61
void QG_InsertOptions::destroy() {
 
62
    RS_SETTINGS->beginGroup("/Insert");
 
63
    RS_SETTINGS->writeEntry("/InsertAngle", leAngle->text());
 
64
    RS_SETTINGS->writeEntry("/InsertFactor", leFactor->text());
 
65
    RS_SETTINGS->writeEntry("/InsertColumns", sbColumns->text());
 
66
    RS_SETTINGS->writeEntry("/InsertRows", sbRows->text());
 
67
    RS_SETTINGS->writeEntry("/InsertColumnSpacing", leColumnSpacing->text());
 
68
    RS_SETTINGS->writeEntry("/InsertRowSpacing", leRowSpacing->text());
 
69
    RS_SETTINGS->endGroup();
 
70
}
 
71
 
 
72
void QG_InsertOptions::setAction(RS_ActionInterface* a, bool update) {
 
73
    if (a!=NULL && a->rtti()==RS2::ActionBlocksInsert) {
 
74
        action = (RS_ActionBlocksInsert*)a;
 
75
 
 
76
        QString sAngle;
 
77
        QString sFactor;
 
78
        QString sColumns;
 
79
        QString sRows;
 
80
        QString sColumnSpacing;
 
81
        QString sRowSpacing;
 
82
        if (update) {
 
83
            sAngle = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
 
84
            sFactor = QString("%1").arg(action->getFactor());
 
85
            sColumns = QString("%1").arg(action->getColumns());
 
86
            sRows = QString("%1").arg(action->getRows());
 
87
            sColumnSpacing = QString("%1").arg(action->getColumnSpacing());
 
88
            sRowSpacing = QString("%1").arg(action->getRowSpacing());
 
89
        } else {
 
90
            RS_SETTINGS->beginGroup("/Insert");
 
91
            sAngle = RS_SETTINGS->readEntry("/InsertAngle", "0.0");
 
92
            sFactor = RS_SETTINGS->readEntry("/InsertFactor", "1.0");
 
93
            sColumns = RS_SETTINGS->readEntry("/InsertColumns", "1");
 
94
            sRows = RS_SETTINGS->readEntry("/InsertRows", "1");
 
95
            sColumnSpacing = RS_SETTINGS->readEntry("/InsertColumnSpacing", "1.0");
 
96
            sRowSpacing = RS_SETTINGS->readEntry("/InsertRowSpacing", "1.0");
 
97
            RS_SETTINGS->endGroup();
 
98
        }
 
99
        leAngle->setText(sAngle);
 
100
        leFactor->setText(sFactor);
 
101
        sbColumns->setValue(sColumns.toInt());
 
102
        sbRows->setValue(sRows.toInt());
 
103
        leColumnSpacing->setText(sColumnSpacing);
 
104
        leRowSpacing->setText(sRowSpacing);
 
105
    } else {
 
106
        RS_DEBUG->print(RS_Debug::D_ERROR, 
 
107
                        "QG_InsertOptions::setAction: wrong action type");
 
108
        action = NULL;
 
109
    }
 
110
}
 
111
 
 
112
void QG_InsertOptions::updateData() {
 
113
    if (action!=NULL) {
 
114
        action->setAngle(RS_Math::deg2rad(RS_Math::eval(leAngle->text())));
 
115
        action->setFactor(RS_Math::eval(leFactor->text()));
 
116
        action->setColumns(sbColumns->value());
 
117
        action->setRows(sbRows->value());
 
118
        action->setColumnSpacing(RS_Math::eval(leColumnSpacing->text()));
 
119
        action->setRowSpacing(RS_Math::eval(leRowSpacing->text()));
 
120
    }
 
121
}