~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/actions/rs_actionmodifyoffset.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
 
 
27
#include<QAction>
 
28
#include "rs_actionmodifyoffset.h"
 
29
 
 
30
#include "rs_dialogfactory.h"
 
31
#include "rs_graphicview.h"
 
32
//#include "rs_commands.h"
 
33
//#include "rs_commandevent.h"
 
34
#include "rs_modification.h"
 
35
 
 
36
 
 
37
RS_ActionModifyOffset::RS_ActionModifyOffset(RS_EntityContainer& container,
 
38
                                             RS_GraphicView& graphicView)
 
39
    :RS_PreviewActionInterface("Modify Offset",
 
40
                               container, graphicView) {
 
41
 
 
42
    data.distance=0.;
 
43
    data.number=1;
 
44
    data.useCurrentAttributes = true;
 
45
    data.useCurrentLayer = true;
 
46
}
 
47
 
 
48
 
 
49
 
 
50
RS_ActionModifyOffset::~RS_ActionModifyOffset() {}
 
51
 
 
52
QAction* RS_ActionModifyOffset::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
 
53
    QAction* action = new QAction(tr("&Offset"),NULL);
 
54
    action->setIcon(QIcon(":/extui/arcspara.png"));//we need a new icon here
 
55
    return action;
 
56
}
 
57
 
 
58
 
 
59
 
 
60
 
 
61
void RS_ActionModifyOffset::init(int status) {
 
62
    RS_ActionInterface::init(status);
 
63
    //finish, if nothing selected
 
64
    if(container->countSelected()==0) finish();
 
65
 
 
66
}
 
67
 
 
68
void RS_ActionModifyOffset::trigger() {
 
69
    RS_Modification m(*container, graphicView);
 
70
    m.offset(data);
 
71
    if (RS_DIALOGFACTORY!=NULL) {
 
72
        RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
 
73
        RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
 
74
    }
 
75
    finish(false);
 
76
}
 
77
 
 
78
 
 
79
 
 
80
void RS_ActionModifyOffset::mouseMoveEvent(QMouseEvent* e) {
 
81
//    RS_DEBUG->print("RS_ActionModifyOffset::mouseMoveEvent begin");
 
82
    data.coord=snapPoint(e);
 
83
 
 
84
 
 
85
    RS_EntityContainer ec(NULL,true);
 
86
    for(RS_Entity* en=container->firstEntity();en!=NULL;en=container->nextEntity()){
 
87
        if(en->isSelected()) ec.addEntity(en->clone());
 
88
    }
 
89
    if(ec.isEmpty()) return;
 
90
    RS_Modification m(ec, NULL, false);
 
91
    m.offset(data);
 
92
 
 
93
    deletePreview();
 
94
    preview->addSelectionFrom(ec);
 
95
    drawPreview();
 
96
 
 
97
}
 
98
 
 
99
 
 
100
 
 
101
void RS_ActionModifyOffset::mouseReleaseEvent(QMouseEvent* e) {
 
102
    if (e->button()==Qt::LeftButton) {
 
103
            trigger();
 
104
    } else if (e->button()==Qt::RightButton) {
 
105
        deletePreview();
 
106
        init(getStatus()-1);
 
107
    }
 
108
}
 
109
 
 
110
 
 
111
void RS_ActionModifyOffset::updateMouseButtonHints() {
 
112
    if (RS_DIALOGFACTORY!=NULL) {
 
113
        switch (getStatus()) {
 
114
        case SetPosition:
 
115
            RS_DIALOGFACTORY->updateMouseWidget(tr("Specify direction of offset"), tr("Back"));
 
116
            break;
 
117
 
 
118
        default:
 
119
            RS_DIALOGFACTORY->updateMouseWidget("", "");
 
120
            break;
 
121
        }
 
122
    }
 
123
}
 
124
 
 
125
 
 
126
 
 
127
void RS_ActionModifyOffset::showOptions() {
 
128
    RS_ActionInterface::showOptions();
 
129
    if (RS_DIALOGFACTORY!=NULL) {
 
130
        RS_DIALOGFACTORY->requestModifyOffsetOptions(data.distance, true);
 
131
    }
 
132
}
 
133
 
 
134
 
 
135
 
 
136
void RS_ActionModifyOffset::hideOptions() {
 
137
    RS_ActionInterface::hideOptions();
 
138
 
 
139
    if (RS_DIALOGFACTORY!=NULL) {
 
140
        RS_DIALOGFACTORY->requestModifyOffsetOptions(data.distance, false);
 
141
    }
 
142
}
 
143
 
 
144
 
 
145
 
 
146
void RS_ActionModifyOffset::updateMouseCursor() {
 
147
    graphicView->setMouseCursor(RS2::CadCursor);
 
148
}
 
149
 
 
150
 
 
151
 
 
152
//void RS_ActionModifyOffset::updateToolBar() {
 
153
//    if (RS_DIALOGFACTORY!=NULL) {
 
154
//        if (isFinished()) {
 
155
//            RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
 
156
//        }
 
157
//    }
 
158
//}
 
159
 
 
160
 
 
161
// EOF
 
162