QElectroTech  0.70
customelementpart.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "customelementpart.h"
19 #include "qetelementeditor.h"
20 
23  return(element_editor);
24 }
25 
31  if (element_editor) {
33  }
34 }
35 
38  return(element_editor -> elementScene());
39 }
40 
42 QUndoStack &CustomElementPart::undoStack() const {
43  return(elementScene() -> undoStack());
44 }
45 
47 QGraphicsItem *CustomElementPart::toItem() {
48  return(dynamic_cast<QGraphicsItem *>(this));
49 }
50 
60 }
61 
69 QList<QPointF> CustomElementPart::mapPoints(const QRectF &initial_selection_rect, const QRectF &new_selection_rect, const QList<QPointF> &points) {
70  QList<QPointF> new_points;
71  if (!points.count()) return(new_points);
72 
73  // compare the new selection rectangle with the stored one to get the scaling ratio
74  qreal sx = new_selection_rect.width() / initial_selection_rect.width();
75  qreal sy = new_selection_rect.height() / initial_selection_rect.height();
76 
77  QPointF initial_top_left = initial_selection_rect.topLeft();
78  qreal new_top_left_x = new_selection_rect.x();
79  qreal new_top_left_y = new_selection_rect.y();
80 
81  foreach (QPointF point, points) {
82  QPointF point_offset = point - initial_top_left;
83  new_points << QPointF(
84  new_top_left_x + (point_offset.rx() * sx),
85  new_top_left_y + (point_offset.y() * sy)
86  );
87  }
88 
89  return(new_points);
90 }
virtual QUndoStack & undoStack() const
snap the point used to define the new bounding rectangle to the grid
Definition: qet.h:81
virtual QETElementEditor * elementEditor() const
virtual QET::ScalingMethod preferredScalingMethod() const
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
virtual QGraphicsItem * toItem()
QETElementEditor * element_editor
ScalingMethod
Supported types of interactive scaling, typically for a single element primitive. ...
Definition: qet.h:79
virtual void updateCurrentPartEditor() const
virtual ElementScene * elementScene() const