-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathranges_item.cpp
More file actions
executable file
·299 lines (256 loc) · 9.05 KB
/
ranges_item.cpp
File metadata and controls
executable file
·299 lines (256 loc) · 9.05 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/****************************************************************************
**
** Copyright (C) 2007-2009 Kevin Clague. All rights reserved.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include <QGraphicsItem>
#include "ranges.h"
#include "ranges_item.h"
#include "range.h"
#include "step.h"
#include "color.h"
#include "commonmenus.h"
/****************************************************************************
*
* This is the graphical representation of step groups.
*
* Please see lpub.h for an overall description of how the files in LPub
* make up the LPub program.
*
***************************************************************************/
MultiStepRangesBackgroundItem::MultiStepRangesBackgroundItem(
Steps *_steps,
QRectF rect,
QGraphicsItem *parent,
Meta *_meta)
{
meta = _meta;
//page = dynamic_cast<Page *>(_steps);
page = _steps;
setRect(rect);
setPen(Qt::NoPen);
setBrush(Qt::NoBrush);
setParentItem(parent);
setToolTip("Step Group - popup menu");
setFlag(QGraphicsItem::ItemIsSelectable,true);
setFlag(QGraphicsItem::ItemIsMovable,true);
setZValue(-2);
}
void MultiStepRangesBackgroundItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
positionChanged = false;
position = pos();
}
void MultiStepRangesBackgroundItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsRectItem::mouseMoveEvent(event);
positionChanged = true;
}
void MultiStepRangesBackgroundItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
if (isSelected() && (flags() & QGraphicsItem::ItemIsMovable) && positionChanged) {
QPointF newPosition;
// back annotate the movement of the PLI into the LDraw file.
newPosition = pos() - position;
PlacementData placementData = meta->LPub.multiStep.placement.value();
placementData.offsets[0] += newPosition.x()/page->relativeToSize[0];
placementData.offsets[1] += newPosition.y()/page->relativeToSize[1];
meta->LPub.multiStep.placement.setValue(placementData);
changePlacementOffset(page->topOfSteps(),&meta->LPub.multiStep.placement,StepGroupType,true,false);
}
}
MultiStepRangeBackgroundItem::MultiStepRangeBackgroundItem(
Steps *_steps,
Range *_range,
Meta *_meta,
int _offset_x,
int _offset_y,
QGraphicsItem *parent)
{
meta = _meta;
page = _steps;
MultiStepMeta *multiStep = &_meta->LPub.multiStep;
background = NULL;
border = NULL;
margin = &multiStep->margin;
placement = &multiStep->placement;
freeform = &multiStep->freeform;
alloc = &multiStep->alloc;
subModelFont = &multiStep->subModelFont;
subModelFontColor = &multiStep->subModelFontColor;
perStep = &multiStep->pli.perStep;
relativeType = _steps->relativeType;
int tx = _offset_x+_range->loc[XX];
int ty = _offset_y+_range->loc[YY];
setRect(tx,ty, _steps->size[XX], _steps->size[YY]);
setPen(QPen(Qt::NoPen));
setBrush(QBrush(Qt::NoBrush));
setToolTip("Step Group - popup menu");
setParentItem(parent);
setZValue(-2);
}
void MultiStepRangeBackgroundItem::contextMenuEvent(
QGraphicsSceneContextMenuEvent *event)
{
QMenu menu;
PlacementData placementData = meta->LPub.multiStep.placement.value();
QString name = "Move These Steps";
QAction *placementAction = menu.addAction(name);
placementAction->setWhatsThis(commonMenus.naturalLanguagePlacementWhatsThis(
StepGroupType,placementData,name));
QAction *perStepAction = menu.addAction(
meta->LPub.multiStep.pli.perStep.value() ?
"No Parts List per Step" :
"Parts List per Step");
QAction *allocAction;
if (page->allocType() == Vertical) {
allocAction = menu.addAction("Display as Rows");
allocAction->setWhatsThis(
"Display as Rows:\n"
" Change this whole set of steps from columns of steps\n"
" to rows of steps");
} else {
allocAction = menu.addAction("Display as Columns");
allocAction->setWhatsThis(
"Display as Columns:\n"
" Change this whole set of steps from rows of steps\n"
" to columns of steps");
}
QAction *marginAction = menu.addAction("Change Step Group Margins");
marginAction->setWhatsThis("Change Step Group Margins:\n"
" Margins are the empty space around this group of steps.\n"
" You can change the margins if things are too close together,\n"
" or too far apart. You can change the things in this group of\n"
" steps by putting your mouse cursor over them, and clicking\n"
" the menu button\n");
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == placementAction) {
changePlacement(PageType,
relativeType,
"Step Group Placement",
page->topOfSteps(),
page->bottomOfSteps(),
&meta->LPub.multiStep.placement,
true,1,false);
} else if (selectedAction == perStepAction) {
changeBool(page->topOfSteps(),
page->bottomOfSteps(),
&meta->LPub.multiStep.pli.perStep,true,1,false,false);
} else if (selectedAction == marginAction) {
changeMargins("Step Group Margins",
page->topOfSteps(),
page->bottomOfSteps(),
margin);
} else if (selectedAction == allocAction) {
changeAlloc(page->topOfSteps(),
page->bottomOfSteps(),
page->allocMeta());
}
}
DividerItem::DividerItem(
Step *_step,
Meta *_meta,
int offsetX,
int offsetY)
{
step = _step;
AllocEnc allocEnc;
Steps *steps = step->grandparent();
Range *range = step->range();
parentRelativeType = steps->relativeType;
if (parentRelativeType == CalloutType) {
allocEnc = steps->meta.LPub.callout.alloc.value();
} else {
allocEnc = steps->meta.LPub.multiStep.alloc.value();
}
SepData sepData = range->sepMeta.valuePixels();
/* Size the rectangle around the divider */
if (allocEnc == Vertical) {
setRect(offsetX,
offsetY,
2*sepData.margin[XX]
+sepData.thickness,
range->size[YY]);
} else {
setRect(offsetX,
offsetY,
range->size[XX],
2*sepData.margin[YY]
+sepData.thickness);
}
setPen(QPen(Qt::NoPen));
setBrush(QBrush(Qt::NoBrush));
setToolTip("Divider - popup menu");
lineItem = new DividerLine(this);
BorderData borderData;
if (steps->relativeType == CalloutType) {
borderData = _meta->LPub.callout.border.valuePixels();
} else {
borderData.margin[0] = 0;
borderData.margin[1] = 0;
borderData.thickness = 0;
}
if (sepData.thickness > 0.5) {
if (allocEnc == Vertical) {
int left = offsetX+sepData.margin[XX]+sepData.thickness/2;
lineItem->setLine(left,
offsetY,
left,
offsetY
+range->size[YY]);
} else {
int top = offsetY+sepData.margin[YY]+sepData.thickness/2;
lineItem->setLine(offsetX,
top,
offsetX
+range->size[XX],
top);
}
QPen pen(LDrawColor::color(sepData.color));
pen.setWidth(sepData.thickness);
pen.setCapStyle(Qt::RoundCap);
lineItem->setPen(pen);
lineItem->setZValue(100);
setZValue(99);
}
}
void DividerItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu menu;
QAction *editAction = menu.addAction("Change Divider");
QAction *deleteAction = menu.addAction("Delete Divider");
editAction->setWhatsThis("Put the steps in this row together with the steps after this");
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == NULL) {
return;
}
Step *nextStep = step->nextStep();
if ( ! nextStep) {
return;
}
Where topOfStep = nextStep->topOfStep();
Where bottomOfStep = nextStep->bottomOfStep();
Range *range = step->range();
if (selectedAction == editAction) {
changeDivider("Divider",topOfStep,bottomOfStep,&range->sepMeta,1,false);
} else if (selectedAction == deleteAction) {
deleteDivider(parentRelativeType,topOfStep);
}
}
void DividerLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
DividerItem *dividerItem = dynamic_cast<DividerItem *>(parentItem());
dividerItem->contextMenuEvent(event);
}