~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/ui/forms/qg_cadtoolbarselect.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_cadtoolbarselect.h"
 
27
 
 
28
#include "qg_cadtoolbar.h"
 
29
#include "rs_actionselect.h"
 
30
 
 
31
/*
 
32
 *  Constructs a QG_CadToolBarSelect as a child of 'parent', with the
 
33
 *  name 'name' and widget flags set to 'f'.
 
34
 */
 
35
QG_CadToolBarSelect::QG_CadToolBarSelect(QWidget* parent, Qt::WindowFlags fl)
 
36
    : QWidget(parent, fl)
 
37
{
 
38
    setupUi(this);
 
39
    parentTB=static_cast<QG_CadToolBar*>(parent);
 
40
 
 
41
    init();
 
42
}
 
43
 
 
44
/*
 
45
 *  Destroys the object and frees any allocated resources
 
46
 */
 
47
QG_CadToolBarSelect::~QG_CadToolBarSelect()
 
48
{
 
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_CadToolBarSelect::languageChange()
 
57
{
 
58
    retranslateUi(this);
 
59
}
 
60
 
 
61
void QG_CadToolBarSelect::init() {
 
62
    cadToolBar = NULL;
 
63
    actionHandler = NULL;
 
64
    selectAction = NULL;
 
65
    nextAction = -1;
 
66
}
 
67
 
 
68
void QG_CadToolBarSelect::mousePressEvent(QMouseEvent* e) {
 
69
    if (e->button()==Qt::RightButton && cadToolBar!=NULL) {
 
70
        cadToolBar->back();
 
71
        e->accept();
 
72
    }
 
73
}
 
74
 
 
75
void QG_CadToolBarSelect::contextMenuEvent(QContextMenuEvent *e) {
 
76
    e->accept();
 
77
}
 
78
 
 
79
void QG_CadToolBarSelect::setCadToolBar(QG_CadToolBar* tb) {
 
80
    cadToolBar = tb;
 
81
    if (tb!=NULL) {
 
82
        actionHandler = tb->getActionHandler();
 
83
        //actionHandler->setCadToolBarSelect(this);
 
84
    }
 
85
    else {
 
86
        RS_DEBUG->print(RS_Debug::D_ERROR,
 
87
                        "QG_CadToolBarSelect::setCadToolBar(): No valid toolbar set.");
 
88
    }
 
89
}
 
90
 
 
91
void QG_CadToolBarSelect::selectSingle() {
 
92
    if (actionHandler!=NULL) {
 
93
       if(actionHandler->getCurrentAction()->rtti() != RS2::ActionSelect){
 
94
        actionHandler->slotSelectSingle();
 
95
       }
 
96
    }
 
97
}
 
98
 
 
99
void QG_CadToolBarSelect::selectContour() {
 
100
    if (actionHandler!=NULL) {
 
101
        actionHandler->slotSelectContour();
 
102
    }
 
103
}
 
104
 
 
105
void QG_CadToolBarSelect::deselectAll() {
 
106
    if (actionHandler!=NULL) {
 
107
        actionHandler->slotDeselectAll();
 
108
    }
 
109
}
 
110
 
 
111
void QG_CadToolBarSelect::selectAll() {
 
112
    if (actionHandler!=NULL) {
 
113
        actionHandler->slotSelectAll();
 
114
    }
 
115
}
 
116
 
 
117
void QG_CadToolBarSelect::selectWindow() {
 
118
    if (actionHandler!=NULL) {
 
119
        actionHandler->slotSelectWindow();
 
120
    }
 
121
}
 
122
 
 
123
void QG_CadToolBarSelect::deselectWindow() {
 
124
    if (actionHandler!=NULL) {
 
125
        actionHandler->slotDeselectWindow();
 
126
    }
 
127
}
 
128
 
 
129
void QG_CadToolBarSelect::selectIntersected() {
 
130
    if (actionHandler!=NULL) {
 
131
        actionHandler->slotSelectIntersected();
 
132
    }
 
133
}
 
134
 
 
135
void QG_CadToolBarSelect::deselectIntersected() {
 
136
    if (actionHandler!=NULL) {
 
137
        actionHandler->slotDeselectIntersected();
 
138
    }
 
139
}
 
140
 
 
141
void QG_CadToolBarSelect::selectInvert() {
 
142
    if (actionHandler!=NULL) {
 
143
        actionHandler->slotSelectInvert();
 
144
    }
 
145
}
 
146
 
 
147
void QG_CadToolBarSelect::selectLayer() {
 
148
    if (actionHandler!=NULL) {
 
149
        actionHandler->slotSelectLayer();
 
150
    }
 
151
}
 
152
 
 
153
void QG_CadToolBarSelect::setSelectAction(RS_ActionInterface* selectAction) {
 
154
    this->selectAction = selectAction;
 
155
}
 
156
 
 
157
void QG_CadToolBarSelect::setNextAction(int nextAction) {
 
158
    this->nextAction = nextAction;
 
159
    if (nextAction==-1) {
 
160
        bDoit->hide();
 
161
    } else {
 
162
        bDoit->show();
 
163
    }
 
164
}
 
165
 
 
166
void QG_CadToolBarSelect::runNextAction() {
 
167
    if (selectAction!=NULL) {
 
168
        if(selectAction->rtti() == RS2::ActionSelect){
 
169
            //refuse to run next action if no entity is selected, to avoid segfault by action upon empty selection
 
170
            //issue#235
 
171
            if( static_cast<RS_ActionSelect*>(selectAction)->countSelected()==0) return;
 
172
        }
 
173
        selectAction->finish();
 
174
        selectAction = NULL;
 
175
    }
 
176
    if (nextAction!=-1) {
 
177
        actionHandler->killSelectActions();
 
178
        actionHandler->setCurrentAction((RS2::ActionType)nextAction);
 
179
    }
 
180
}
 
181
 
 
182
void QG_CadToolBarSelect::back() {
 
183
    if(parentTB != NULL){
 
184
        parentTB->showPreviousToolBar();
 
185
    }
 
186
}
 
187
 
 
188
void QG_CadToolBarSelect::on_bBack_clicked()
 
189
{
 
190
    if(parentTB != NULL){
 
191
        parentTB->showPreviousToolBar();
 
192
    }
 
193
}