-
Notifications
You must be signed in to change notification settings - Fork 1
/
apertureeditview.cpp
executable file
·103 lines (78 loc) · 2.61 KB
/
apertureeditview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "apertureeditview.h"
#include "gerberstencilgenerator.h"
#include <QDebug>
apertureEditView::apertureEditView( QWidget *parent ) {
std::ignore = parent;
_lastWidth = this->getBoundingBox().width();
_lastHeight = this->getBoundingBox().height();
}
apertureEditView::~apertureEditView() {
}
void apertureEditView::resizeEvent( QResizeEvent *event ) {
event->accept();
if ( this->items().count() == 0 ) {
return;
} else {
this->adjustPreviewSize();
}
}
void apertureEditView::adjustPreviewSize() {
if ( this->items().count() == 0 ) {
return;
}
this->adjustPreviewSize( _lastWidth, _lastHeight );
}
void apertureEditView::adjustPreviewSize( qreal width, qreal height ) {
if ( this->items().count() == 0 ) {
return;
}
if ( _lastWidth != width && width != 0 ) {
_lastWidth = width;
}
if ( _lastHeight != height && height != 0 ) {
_lastHeight = height;
}
double maxHeight = height;
double maxWidth = width;
maxHeight *= 1.75;
maxWidth *= 1.75;
QRectF viewportBoundingBox;
viewportBoundingBox.setWidth( maxWidth );
viewportBoundingBox.setHeight( maxHeight );
viewportBoundingBox.setX( -( maxWidth / 2 ) );
viewportBoundingBox.setY( -( maxHeight / 2 ) );
this->setBoundingBox( viewportBoundingBox );
this->fitInView( viewportBoundingBox, Qt::KeepAspectRatio );
this->centerOn( 0, 0 );
this->repaint();
this->update();
}
void apertureEditView::setBoundingBoxHeight( qreal height ) {
_boundingBox.setY( -( height / 2 ) );
_boundingBox.setHeight( height );
}
void apertureEditView::setBoundingBoxWidth( qreal width ) {
_boundingBox.setX( -( width / 2 ) );
_boundingBox.setWidth( width );
}
void apertureEditView::setBoundingBoxSize( QRectF bbrect ) {
_boundingBox.setWidth( bbrect.width() );
_boundingBox.setHeight( bbrect.height() );
}
void apertureEditView::setBoundingBoxSize( qreal width, qreal height ) {
_boundingBox.setWidth( width );
_boundingBox.setHeight( height );
}
void apertureEditView::setBoundingBox( QRectF bbrect ) {
_boundingBox = bbrect;
}
QPointF apertureEditView::getShapeOffset() {
QRectF shapeBoundingBox = _boundingBox;
QRectF sceneBoundingBox = this->scene()->itemsBoundingRect();
QPointF shapeCenter = shapeBoundingBox.center();
QPointF sceneCenter = sceneBoundingBox.center();
return QPointF( ( sceneCenter.x() - shapeCenter.x() ), ( sceneCenter.y() - shapeCenter.y() ) );
}
const QRectF apertureEditView::getBoundingBox() {
return _boundingBox;
}