insilmaril@0
|
1 |
#include "mapeditor.h"
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
#include <iostream>
|
insilmaril@95
|
4 |
#include <cstdlib>
|
insilmaril@0
|
5 |
#include <typeinfo>
|
insilmaril@0
|
6 |
|
insilmaril@720
|
7 |
#include <QObject>
|
insilmaril@720
|
8 |
|
insilmaril@750
|
9 |
#include "branchitem.h"
|
insilmaril@175
|
10 |
#include "mainwindow.h"
|
insilmaril@175
|
11 |
#include "misc.h"
|
insilmaril@314
|
12 |
#include "warningdialog.h"
|
insilmaril@0
|
13 |
|
insilmaril@0
|
14 |
|
insilmaril@0
|
15 |
extern int statusbarTime;
|
insilmaril@0
|
16 |
extern Main *mainWindow;
|
insilmaril@164
|
17 |
extern QString tmpVymDir;
|
insilmaril@166
|
18 |
extern QString clipboardDir;
|
insilmaril@491
|
19 |
extern QString clipboardFile;
|
insilmaril@166
|
20 |
extern bool clipboardEmpty;
|
insilmaril@473
|
21 |
extern bool debug;
|
insilmaril@0
|
22 |
|
insilmaril@366
|
23 |
extern QMenu* branchContextMenu;
|
insilmaril@366
|
24 |
extern QMenu* branchAddContextMenu;
|
insilmaril@366
|
25 |
extern QMenu* branchRemoveContextMenu;
|
insilmaril@366
|
26 |
extern QMenu* branchLinksContextMenu;
|
insilmaril@366
|
27 |
extern QMenu* branchXLinksContextMenuEdit;
|
insilmaril@366
|
28 |
extern QMenu* branchXLinksContextMenuFollow;
|
insilmaril@366
|
29 |
extern QMenu* floatimageContextMenu;
|
insilmaril@366
|
30 |
extern QMenu* canvasContextMenu;
|
insilmaril@366
|
31 |
|
insilmaril@0
|
32 |
extern Settings settings;
|
insilmaril@269
|
33 |
extern QString iconPath;
|
insilmaril@0
|
34 |
|
insilmaril@0
|
35 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@0
|
36 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@720
|
37 |
MapEditor::MapEditor( VymModel *vm)
|
insilmaril@0
|
38 |
{
|
insilmaril@0
|
39 |
//cout << "Constructor ME "<<this<<endl;
|
insilmaril@720
|
40 |
mapScene= new QGraphicsScene(NULL);
|
insilmaril@408
|
41 |
mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
|
insilmaril@408
|
42 |
|
insilmaril@767
|
43 |
zoomFactor=zoomFactorTarget=1;
|
insilmaril@767
|
44 |
|
insilmaril@720
|
45 |
model=vm;
|
insilmaril@645
|
46 |
model->setScene (mapScene);
|
insilmaril@720
|
47 |
model->registerEditor(this);
|
insilmaril@727
|
48 |
model->makeDefault(); // No changes in model so far
|
insilmaril@408
|
49 |
|
insilmaril@408
|
50 |
setScene (mapScene);
|
insilmaril@0
|
51 |
|
insilmaril@0
|
52 |
printer=NULL;
|
insilmaril@0
|
53 |
|
insilmaril@366
|
54 |
// Create bitmap cursors, platform dependant
|
insilmaril@404
|
55 |
HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
|
insilmaril@404
|
56 |
PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
|
insilmaril@404
|
57 |
CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
|
insilmaril@404
|
58 |
XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
|
insilmaril@398
|
59 |
|
insilmaril@769
|
60 |
//setFocusPolicy (Qt::StrongFocus); //FIXME-3
|
insilmaril@0
|
61 |
|
insilmaril@0
|
62 |
pickingColor=false;
|
insilmaril@91
|
63 |
drawingLink=false;
|
insilmaril@93
|
64 |
copyingObj=false;
|
insilmaril@0
|
65 |
|
insilmaril@0
|
66 |
editingBO=NULL;
|
insilmaril@0
|
67 |
movingObj=NULL;
|
insilmaril@0
|
68 |
|
insilmaril@0
|
69 |
printFrame=true;
|
insilmaril@0
|
70 |
printFooter=true;
|
insilmaril@0
|
71 |
|
insilmaril@417
|
72 |
setAcceptDrops (true);
|
insilmaril@0
|
73 |
|
insilmaril@746
|
74 |
//model->reposition(); //FIXME-3 really still needed?
|
insilmaril@381
|
75 |
|
insilmaril@531
|
76 |
|
insilmaril@769
|
77 |
// Shortcuts and actions
|
insilmaril@769
|
78 |
QAction *a;
|
insilmaril@769
|
79 |
a = new QAction("Select upper branch", this);
|
insilmaril@769
|
80 |
a->setShortcut (Qt::Key_Up );
|
insilmaril@769
|
81 |
a->setShortcutContext (Qt::WidgetShortcut);
|
insilmaril@769
|
82 |
addAction (a);
|
insilmaril@769
|
83 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
|
insilmaril@769
|
84 |
|
insilmaril@769
|
85 |
a = new QAction( "Select lower branch",this);
|
insilmaril@769
|
86 |
a->setShortcut ( Qt::Key_Down );
|
insilmaril@769
|
87 |
a->setShortcutContext (Qt::WidgetShortcut);
|
insilmaril@769
|
88 |
addAction (a);
|
insilmaril@769
|
89 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
|
insilmaril@769
|
90 |
|
insilmaril@769
|
91 |
a = new QAction( "Select left branch", this);
|
insilmaril@769
|
92 |
a->setShortcut (Qt::Key_Left );
|
insilmaril@769
|
93 |
// a->setShortcutContext (Qt::WindowShortcut);
|
insilmaril@769
|
94 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
95 |
addAction (a);
|
insilmaril@769
|
96 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorLeft() ) );
|
insilmaril@769
|
97 |
|
insilmaril@769
|
98 |
a = new QAction( "Select child branch", this);
|
insilmaril@769
|
99 |
a->setShortcut (Qt::Key_Right);
|
insilmaril@769
|
100 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
101 |
addAction (a);
|
insilmaril@769
|
102 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorRight() ) );
|
insilmaril@769
|
103 |
|
insilmaril@769
|
104 |
a = new QAction( "Select first branch", this);
|
insilmaril@769
|
105 |
a->setShortcut (Qt::Key_Home );
|
insilmaril@769
|
106 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
107 |
addAction (a);
|
insilmaril@769
|
108 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorFirst() ) );
|
insilmaril@769
|
109 |
|
insilmaril@769
|
110 |
a = new QAction( "Select last branch",this);
|
insilmaril@769
|
111 |
a->setShortcut ( Qt::Key_End );
|
insilmaril@769
|
112 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
113 |
addAction (a);
|
insilmaril@769
|
114 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorLast() ) );
|
insilmaril@769
|
115 |
|
insilmaril@720
|
116 |
// Action to embed LineEdit for heading in Scene
|
insilmaril@720
|
117 |
editingHeading=false;
|
insilmaril@720
|
118 |
lineEdit=new QLineEdit;
|
insilmaril@720
|
119 |
lineEdit->hide();
|
insilmaril@720
|
120 |
QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
|
insilmaril@772
|
121 |
pw->setZValue (Z_LINEEDIT);
|
insilmaril@676
|
122 |
|
insilmaril@769
|
123 |
a = new QAction( tr( "Edit heading","MapEditor" ), this);
|
insilmaril@720
|
124 |
a->setShortcut ( Qt::Key_Return ); //Edit heading
|
insilmaril@720
|
125 |
addAction (a);
|
insilmaril@720
|
126 |
connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
|
insilmaril@720
|
127 |
a = new QAction( tr( "Edit heading","MapEditor" ), this);
|
insilmaril@720
|
128 |
a->setShortcut ( Qt::Key_Enter); //Edit heading
|
insilmaril@720
|
129 |
addAction (a);
|
insilmaril@720
|
130 |
connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
|
insilmaril@628
|
131 |
|
insilmaril@728
|
132 |
// Selections
|
insilmaril@728
|
133 |
selectionColor =QColor (255,255,0);
|
insilmaril@728
|
134 |
|
insilmaril@728
|
135 |
|
insilmaril@746
|
136 |
// Attributes //FIXME-2 testing only...
|
insilmaril@638
|
137 |
QString k;
|
insilmaril@638
|
138 |
AttributeDef *ad;
|
insilmaril@628
|
139 |
attrTable= new AttributeTable();
|
insilmaril@638
|
140 |
k="A - StringList";
|
insilmaril@638
|
141 |
ad=attrTable->addKey (k,StringList);
|
insilmaril@638
|
142 |
if (ad)
|
insilmaril@638
|
143 |
{
|
insilmaril@638
|
144 |
QStringList sl;
|
insilmaril@638
|
145 |
sl <<"val 1"<<"val 2"<< "val 3";
|
insilmaril@638
|
146 |
ad->setValue (QVariant (sl));
|
insilmaril@638
|
147 |
}
|
insilmaril@638
|
148 |
//attrTable->addValue ("Key A","P 1");
|
insilmaril@638
|
149 |
//attrTable->addValue ("Key A","P 2");
|
insilmaril@638
|
150 |
//attrTable->addValue ("Key A","P 3");
|
insilmaril@638
|
151 |
//attrTable->addValue ("Key A","P 4");
|
insilmaril@638
|
152 |
k="B - FreeString";
|
insilmaril@638
|
153 |
ad=attrTable->addKey (k,FreeString);
|
insilmaril@638
|
154 |
if (ad)
|
insilmaril@638
|
155 |
{
|
insilmaril@638
|
156 |
//attrTable->addValue ("Key B","w1");
|
insilmaril@638
|
157 |
//attrTable->addValue ("Key B","w2");
|
insilmaril@638
|
158 |
}
|
insilmaril@638
|
159 |
k="C - UniqueString";
|
insilmaril@638
|
160 |
ad=attrTable->addKey (k,UniqueString);
|
insilmaril@638
|
161 |
if (ad)
|
insilmaril@638
|
162 |
{
|
insilmaril@638
|
163 |
//attrTable->addKey ("Key Prio");
|
insilmaril@638
|
164 |
//attrTable->addValue ("Key Prio","Prio 1");
|
insilmaril@638
|
165 |
//attrTable->addValue ("Key Prio","Prio 2");
|
insilmaril@638
|
166 |
}
|
insilmaril@0
|
167 |
}
|
insilmaril@0
|
168 |
|
insilmaril@0
|
169 |
MapEditor::~MapEditor()
|
insilmaril@0
|
170 |
{
|
insilmaril@746
|
171 |
//cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
|
insilmaril@720
|
172 |
model->unregisterEditor(this);
|
insilmaril@0
|
173 |
}
|
insilmaril@0
|
174 |
|
insilmaril@645
|
175 |
VymModel* MapEditor::getModel()
|
insilmaril@0
|
176 |
{
|
insilmaril@645
|
177 |
return model;
|
insilmaril@0
|
178 |
}
|
insilmaril@0
|
179 |
|
insilmaril@408
|
180 |
QGraphicsScene * MapEditor::getScene()
|
insilmaril@0
|
181 |
{
|
insilmaril@408
|
182 |
return mapScene;
|
insilmaril@0
|
183 |
}
|
insilmaril@0
|
184 |
|
insilmaril@772
|
185 |
void MapEditor::scrollTo (const QModelIndex &index)
|
insilmaril@772
|
186 |
{
|
insilmaril@772
|
187 |
if (index.isValid())
|
insilmaril@772
|
188 |
{
|
insilmaril@776
|
189 |
LinkableMapObj* lmo=NULL;
|
insilmaril@776
|
190 |
TreeItem *ti= static_cast<TreeItem*>(index.internalPointer());
|
insilmaril@776
|
191 |
if (ti->getType()==TreeItem::Image ||ti->isBranchLikeType() )
|
insilmaril@779
|
192 |
lmo=((MapItem*)ti)->getLMO();
|
insilmaril@772
|
193 |
if (lmo) setScrollBarPosTarget (lmo->getBBox() );
|
insilmaril@772
|
194 |
}
|
insilmaril@772
|
195 |
}
|
insilmaril@772
|
196 |
|
insilmaril@767
|
197 |
void MapEditor::setScrollBarPosTarget (const QRectF &rect)
|
insilmaril@767
|
198 |
{
|
insilmaril@767
|
199 |
// Code copied from Qt sources
|
insilmaril@767
|
200 |
int xmargin=50;
|
insilmaril@767
|
201 |
int ymargin=50;
|
insilmaril@767
|
202 |
|
insilmaril@767
|
203 |
qreal width = viewport()->width();
|
insilmaril@767
|
204 |
qreal height = viewport()->height();
|
insilmaril@767
|
205 |
QRectF viewRect = matrix().mapRect(rect);
|
insilmaril@767
|
206 |
|
insilmaril@767
|
207 |
qreal left = horizontalScrollBar()->value();
|
insilmaril@767
|
208 |
qreal right = left + width;
|
insilmaril@767
|
209 |
qreal top = verticalScrollBar()->value();
|
insilmaril@767
|
210 |
qreal bottom = top + height;
|
insilmaril@767
|
211 |
|
insilmaril@767
|
212 |
if (viewRect.left() <= left + xmargin) {
|
insilmaril@767
|
213 |
// need to scroll from the left
|
insilmaril@767
|
214 |
// if (!d->leftIndent)
|
insilmaril@767
|
215 |
scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
|
insilmaril@767
|
216 |
}
|
insilmaril@767
|
217 |
if (viewRect.right() >= right - xmargin) {
|
insilmaril@767
|
218 |
// need to scroll from the right
|
insilmaril@767
|
219 |
// if (!d->leftIndent)
|
insilmaril@767
|
220 |
scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
|
insilmaril@767
|
221 |
}
|
insilmaril@767
|
222 |
if (viewRect.top() <= top + ymargin) {
|
insilmaril@767
|
223 |
// need to scroll from the top
|
insilmaril@767
|
224 |
// if (!d->topIndent)
|
insilmaril@767
|
225 |
scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
|
insilmaril@767
|
226 |
}
|
insilmaril@767
|
227 |
if (viewRect.bottom() >= bottom - ymargin) {
|
insilmaril@767
|
228 |
// need to scroll from the bottom
|
insilmaril@767
|
229 |
// if (!d->topIndent)
|
insilmaril@767
|
230 |
scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
|
insilmaril@767
|
231 |
}
|
insilmaril@767
|
232 |
|
insilmaril@767
|
233 |
if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
|
insilmaril@767
|
234 |
scrollBarPosAnimation.stop();
|
insilmaril@767
|
235 |
scrollBarPosAnimation.setTargetObject (this);
|
insilmaril@767
|
236 |
scrollBarPosAnimation.setPropertyName ("scrollBarPos");
|
insilmaril@767
|
237 |
scrollBarPosAnimation.setDuration(1000);
|
insilmaril@767
|
238 |
scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@767
|
239 |
scrollBarPosAnimation.setStartValue(
|
insilmaril@767
|
240 |
QPointF (horizontalScrollBar()->value() ,
|
insilmaril@767
|
241 |
verticalScrollBar()->value() ) );
|
insilmaril@767
|
242 |
scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
|
insilmaril@767
|
243 |
scrollBarPosAnimation.start();
|
insilmaril@767
|
244 |
}
|
insilmaril@767
|
245 |
|
insilmaril@767
|
246 |
QPointF MapEditor::getScrollBarPosTarget()
|
insilmaril@767
|
247 |
{
|
insilmaril@767
|
248 |
return scrollBarPosTarget;
|
insilmaril@767
|
249 |
}
|
insilmaril@767
|
250 |
|
insilmaril@767
|
251 |
|
insilmaril@767
|
252 |
void MapEditor::setScrollBarPos(const QPointF &p)
|
insilmaril@767
|
253 |
{
|
insilmaril@767
|
254 |
scrollBarPos=p;
|
insilmaril@767
|
255 |
horizontalScrollBar()->setValue(int(p.x()));
|
insilmaril@767
|
256 |
verticalScrollBar()->setValue(int(p.y()));
|
insilmaril@767
|
257 |
}
|
insilmaril@767
|
258 |
|
insilmaril@767
|
259 |
QPointF MapEditor::getScrollBarPos()
|
insilmaril@767
|
260 |
{
|
insilmaril@767
|
261 |
return scrollBarPos;
|
insilmaril@767
|
262 |
}
|
insilmaril@767
|
263 |
|
insilmaril@767
|
264 |
void MapEditor::setZoomFactorTarget (const qreal &zft)
|
insilmaril@767
|
265 |
{
|
insilmaril@767
|
266 |
zoomFactorTarget=zft;
|
insilmaril@767
|
267 |
if (zoomAnimation.state()==QtAbstractAnimation::Running)
|
insilmaril@767
|
268 |
zoomAnimation.stop();
|
insilmaril@767
|
269 |
//zoomAnimation=QtPropertyAnimation(this, "zoomFactor");
|
insilmaril@767
|
270 |
zoomAnimation.setTargetObject (this);
|
insilmaril@767
|
271 |
zoomAnimation.setPropertyName ("zoomFactor");
|
insilmaril@767
|
272 |
zoomAnimation.setDuration(1000);
|
insilmaril@767
|
273 |
zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@767
|
274 |
zoomAnimation.setStartValue(zoomFactor);
|
insilmaril@767
|
275 |
zoomAnimation.setEndValue(zft);
|
insilmaril@767
|
276 |
zoomAnimation.start();
|
insilmaril@767
|
277 |
}
|
insilmaril@767
|
278 |
|
insilmaril@767
|
279 |
qreal MapEditor::getZoomFactorTarget()
|
insilmaril@767
|
280 |
{
|
insilmaril@767
|
281 |
return zoomFactorTarget;
|
insilmaril@767
|
282 |
}
|
insilmaril@767
|
283 |
|
insilmaril@767
|
284 |
|
insilmaril@767
|
285 |
void MapEditor::setZoomFactor(const qreal &zf)
|
insilmaril@767
|
286 |
{
|
insilmaril@767
|
287 |
zoomFactor=zf;
|
insilmaril@767
|
288 |
setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
|
insilmaril@767
|
289 |
}
|
insilmaril@767
|
290 |
|
insilmaril@767
|
291 |
qreal MapEditor::getZoomFactor()
|
insilmaril@767
|
292 |
{
|
insilmaril@767
|
293 |
return zoomFactor;
|
insilmaril@767
|
294 |
}
|
insilmaril@767
|
295 |
|
insilmaril@0
|
296 |
void MapEditor::print()
|
insilmaril@0
|
297 |
{
|
insilmaril@0
|
298 |
if ( !printer )
|
insilmaril@0
|
299 |
{
|
insilmaril@0
|
300 |
printer = new QPrinter;
|
insilmaril@0
|
301 |
printer->setColorMode (QPrinter::Color);
|
insilmaril@366
|
302 |
printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
|
insilmaril@412
|
303 |
printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
|
insilmaril@412
|
304 |
printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
|
insilmaril@0
|
305 |
}
|
insilmaril@0
|
306 |
|
insilmaril@782
|
307 |
QRectF totalBBox=getTotalBBox();
|
insilmaril@0
|
308 |
|
insilmaril@0
|
309 |
// Try to set orientation automagically
|
insilmaril@0
|
310 |
// Note: Interpretation of generated postscript is amibiguous, if
|
insilmaril@0
|
311 |
// there are problems with landscape mode, see
|
insilmaril@0
|
312 |
// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
|
insilmaril@0
|
313 |
|
insilmaril@0
|
314 |
if (totalBBox.width()>totalBBox.height())
|
insilmaril@0
|
315 |
// recommend landscape
|
insilmaril@0
|
316 |
printer->setOrientation (QPrinter::Landscape);
|
insilmaril@0
|
317 |
else
|
insilmaril@0
|
318 |
// recommend portrait
|
insilmaril@0
|
319 |
printer->setOrientation (QPrinter::Portrait);
|
insilmaril@0
|
320 |
|
insilmaril@0
|
321 |
if ( printer->setup(this) )
|
insilmaril@0
|
322 |
// returns false, if printing is canceled
|
insilmaril@0
|
323 |
{
|
insilmaril@0
|
324 |
QPainter pp(printer);
|
insilmaril@0
|
325 |
|
insilmaril@412
|
326 |
pp.setRenderHint(QPainter::Antialiasing,true);
|
insilmaril@412
|
327 |
|
insilmaril@0
|
328 |
// Don't print the visualisation of selection
|
insilmaril@720
|
329 |
model->unselect();
|
insilmaril@0
|
330 |
|
insilmaril@408
|
331 |
QRectF mapRect=totalBBox;
|
insilmaril@411
|
332 |
QGraphicsRectItem *frame=NULL;
|
insilmaril@412
|
333 |
|
insilmaril@417
|
334 |
if (printFrame)
|
insilmaril@0
|
335 |
{
|
insilmaril@417
|
336 |
// Print frame around map
|
insilmaril@417
|
337 |
mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
|
insilmaril@417
|
338 |
totalBBox.width()+20, totalBBox.height()+20);
|
insilmaril@417
|
339 |
frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
|
insilmaril@417
|
340 |
frame->setZValue(0);
|
insilmaril@417
|
341 |
frame->show();
|
insilmaril@417
|
342 |
}
|
insilmaril@417
|
343 |
|
insilmaril@417
|
344 |
|
insilmaril@412
|
345 |
double paperAspect = (double)printer->width() / (double)printer->height();
|
insilmaril@412
|
346 |
double mapAspect = (double)mapRect.width() / (double)mapRect.height();
|
insilmaril@417
|
347 |
int viewBottom;
|
insilmaril@0
|
348 |
if (mapAspect>=paperAspect)
|
insilmaril@0
|
349 |
{
|
insilmaril@0
|
350 |
// Fit horizontally to paper width
|
insilmaril@417
|
351 |
//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
|
insilmaril@417
|
352 |
viewBottom=(int)(printer->width()/mapAspect);
|
insilmaril@0
|
353 |
} else
|
insilmaril@0
|
354 |
{
|
insilmaril@0
|
355 |
// Fit vertically to paper height
|
insilmaril@417
|
356 |
//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
|
insilmaril@417
|
357 |
viewBottom=printer->height();
|
insilmaril@0
|
358 |
}
|
insilmaril@417
|
359 |
|
insilmaril@417
|
360 |
if (printFooter)
|
insilmaril@417
|
361 |
{
|
insilmaril@417
|
362 |
// Print footer below map
|
insilmaril@417
|
363 |
QFont font;
|
insilmaril@417
|
364 |
font.setPointSize(10);
|
insilmaril@417
|
365 |
pp.setFont (font);
|
insilmaril@417
|
366 |
QRectF footerBox(0,viewBottom,printer->width(),15);
|
insilmaril@746
|
367 |
// FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
|
insilmaril@417
|
368 |
pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
|
insilmaril@417
|
369 |
}
|
insilmaril@412
|
370 |
mapScene->render (
|
insilmaril@412
|
371 |
&pp,
|
insilmaril@412
|
372 |
QRectF (0,0,printer->width(),printer->height()-15),
|
insilmaril@412
|
373 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
|
insilmaril@412
|
374 |
);
|
insilmaril@412
|
375 |
|
insilmaril@412
|
376 |
// Viewport has paper dimension
|
insilmaril@412
|
377 |
if (frame) delete (frame);
|
insilmaril@0
|
378 |
|
insilmaril@0
|
379 |
// Restore selection
|
insilmaril@720
|
380 |
model->reselect();
|
insilmaril@119
|
381 |
|
insilmaril@119
|
382 |
// Save settings in vymrc
|
insilmaril@366
|
383 |
settings.writeEntry("/mainwindow/printerName",printer->printerName());
|
insilmaril@412
|
384 |
settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
|
insilmaril@412
|
385 |
settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
|
insilmaril@0
|
386 |
}
|
insilmaril@0
|
387 |
}
|
insilmaril@0
|
388 |
|
insilmaril@782
|
389 |
QRectF MapEditor::getTotalBBox() //FIXME-2 needed e.g. for image export
|
insilmaril@782
|
390 |
{
|
insilmaril@782
|
391 |
QRectF r;
|
insilmaril@782
|
392 |
/*
|
insilmaril@782
|
393 |
for (int i=0;i<rootItem->branchCount(); i++)
|
insilmaril@782
|
394 |
r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
|
insilmaril@782
|
395 |
*/
|
insilmaril@782
|
396 |
return r;
|
insilmaril@782
|
397 |
}
|
insilmaril@782
|
398 |
|
insilmaril@782
|
399 |
|
insilmaril@782
|
400 |
QPixmap MapEditor::getPixmap()
|
insilmaril@782
|
401 |
{
|
insilmaril@782
|
402 |
QRectF mapRect=getTotalBBox();
|
insilmaril@782
|
403 |
QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
|
insilmaril@782
|
404 |
QPainter pp (&pix);
|
insilmaril@782
|
405 |
|
insilmaril@782
|
406 |
pp.setRenderHints(renderHints());
|
insilmaril@782
|
407 |
|
insilmaril@782
|
408 |
// Don't print the visualisation of selection
|
insilmaril@782
|
409 |
model->unselect();
|
insilmaril@782
|
410 |
|
insilmaril@782
|
411 |
mapScene->render ( &pp,
|
insilmaril@782
|
412 |
QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
|
insilmaril@782
|
413 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
|
insilmaril@782
|
414 |
|
insilmaril@782
|
415 |
// Restore selection
|
insilmaril@782
|
416 |
model->reselect();
|
insilmaril@782
|
417 |
|
insilmaril@782
|
418 |
return pix;
|
insilmaril@782
|
419 |
}
|
insilmaril@782
|
420 |
|
insilmaril@782
|
421 |
|
insilmaril@408
|
422 |
void MapEditor::setAntiAlias (bool b)
|
insilmaril@408
|
423 |
{
|
insilmaril@408
|
424 |
setRenderHint(QPainter::Antialiasing,b);
|
insilmaril@408
|
425 |
}
|
insilmaril@408
|
426 |
|
insilmaril@408
|
427 |
void MapEditor::setSmoothPixmap(bool b)
|
insilmaril@408
|
428 |
{
|
insilmaril@408
|
429 |
setRenderHint(QPainter::SmoothPixmapTransform,b);
|
insilmaril@408
|
430 |
}
|
insilmaril@408
|
431 |
|
insilmaril@754
|
432 |
TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
|
insilmaril@754
|
433 |
{
|
insilmaril@754
|
434 |
// Start with mapcenter, no images allowed at rootItem
|
insilmaril@754
|
435 |
int i=0;
|
insilmaril@754
|
436 |
BranchItem *bi=model->getRootItem()->getFirstBranch();
|
insilmaril@754
|
437 |
TreeItem *found=NULL;
|
insilmaril@754
|
438 |
while (bi)
|
insilmaril@754
|
439 |
{
|
insilmaril@754
|
440 |
found=bi->findMapItem (p, exclude);
|
insilmaril@754
|
441 |
if (found) return found;
|
insilmaril@754
|
442 |
i++;
|
insilmaril@754
|
443 |
bi=model->getRootItem()->getBranchNum(i);
|
insilmaril@754
|
444 |
}
|
insilmaril@754
|
445 |
return NULL;
|
insilmaril@754
|
446 |
}
|
insilmaril@754
|
447 |
|
insilmaril@628
|
448 |
AttributeTable* MapEditor::attributeTable()
|
insilmaril@628
|
449 |
{
|
insilmaril@628
|
450 |
return attrTable;
|
insilmaril@628
|
451 |
}
|
insilmaril@628
|
452 |
|
insilmaril@527
|
453 |
void MapEditor::testFunction1()
|
insilmaril@0
|
454 |
{
|
insilmaril@767
|
455 |
|
insilmaril@767
|
456 |
// Code copied from Qt sources
|
insilmaril@767
|
457 |
QRectF rect=model->getSelectedBranchObj()->getBBox();
|
insilmaril@767
|
458 |
int xmargin=50;
|
insilmaril@767
|
459 |
int ymargin=50;
|
insilmaril@741
|
460 |
|
insilmaril@767
|
461 |
qreal width = viewport()->width();
|
insilmaril@767
|
462 |
qreal height = viewport()->height();
|
insilmaril@767
|
463 |
QRectF viewRect = matrix().mapRect(rect);
|
insilmaril@741
|
464 |
|
insilmaril@767
|
465 |
qreal left = horizontalScrollBar()->value();
|
insilmaril@767
|
466 |
qreal right = left + width;
|
insilmaril@767
|
467 |
qreal top = verticalScrollBar()->value();
|
insilmaril@767
|
468 |
qreal bottom = top + height;
|
insilmaril@723
|
469 |
|
insilmaril@767
|
470 |
if (viewRect.left() <= left + xmargin) {
|
insilmaril@767
|
471 |
// need to scroll from the left
|
insilmaril@767
|
472 |
// if (!d->leftIndent)
|
insilmaril@767
|
473 |
horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
|
insilmaril@767
|
474 |
}
|
insilmaril@767
|
475 |
if (viewRect.right() >= right - xmargin) {
|
insilmaril@767
|
476 |
// need to scroll from the right
|
insilmaril@767
|
477 |
// if (!d->leftIndent)
|
insilmaril@767
|
478 |
horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
|
insilmaril@767
|
479 |
}
|
insilmaril@767
|
480 |
if (viewRect.top() <= top + ymargin) {
|
insilmaril@767
|
481 |
// need to scroll from the top
|
insilmaril@767
|
482 |
// if (!d->topIndent)
|
insilmaril@767
|
483 |
verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
|
insilmaril@767
|
484 |
}
|
insilmaril@767
|
485 |
if (viewRect.bottom() >= bottom - ymargin) {
|
insilmaril@767
|
486 |
// need to scroll from the bottom
|
insilmaril@767
|
487 |
// if (!d->topIndent)
|
insilmaril@767
|
488 |
verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
|
insilmaril@767
|
489 |
}
|
insilmaril@767
|
490 |
cout << "test1: hor="<<horizontalScrollBar()->value()<<endl;
|
insilmaril@767
|
491 |
cout << "test1: ver="<<verticalScrollBar()->value()<<endl;
|
insilmaril@767
|
492 |
}
|
insilmaril@741
|
493 |
/*
|
insilmaril@767
|
494 |
QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
|
insilmaril@767
|
495 |
animation->setDuration(5000);
|
insilmaril@767
|
496 |
//animation->setEasingCurve ( QtEasingCurve::OutElastic);
|
insilmaril@767
|
497 |
animation->setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@767
|
498 |
animation->setStartValue(sceneRect() );
|
insilmaril@767
|
499 |
animation->setEndValue(QRectF(50, 50, 1000, 1000));
|
insilmaril@740
|
500 |
|
insilmaril@767
|
501 |
animation->start();
|
insilmaril@767
|
502 |
*/
|
insilmaril@767
|
503 |
/*
|
insilmaril@767
|
504 |
QDialog *dia= new QDialog (this);
|
insilmaril@767
|
505 |
dia->setGeometry (50,50,10,10);
|
insilmaril@723
|
506 |
|
insilmaril@767
|
507 |
dia->show();
|
insilmaril@767
|
508 |
dia ->raise();
|
insilmaril@767
|
509 |
|
insilmaril@767
|
510 |
QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
|
insilmaril@767
|
511 |
animation->setDuration(1000);
|
insilmaril@767
|
512 |
//animation->setEasingCurve ( QtEasingCurve::OutElastic);
|
insilmaril@767
|
513 |
animation->setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@767
|
514 |
animation->setStartValue(QRect(50, 50, 10, 10));
|
insilmaril@767
|
515 |
animation->setEndValue(QRect(250, 250, 100, 100));
|
insilmaril@767
|
516 |
|
insilmaril@767
|
517 |
animation->start();
|
insilmaril@767
|
518 |
*/
|
insilmaril@723
|
519 |
|
insilmaril@420
|
520 |
/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
|
insilmaril@260
|
521 |
if (hidemode==HideNone)
|
insilmaril@185
|
522 |
{
|
insilmaril@260
|
523 |
setHideTmpMode (HideExport);
|
insilmaril@260
|
524 |
mapCenter->calcBBoxSizeWithChilds();
|
insilmaril@408
|
525 |
QRectF totalBBox=mapCenter->getTotalBBox();
|
insilmaril@408
|
526 |
QRectF mapRect=totalBBox;
|
insilmaril@260
|
527 |
QCanvasRectangle *frame=NULL;
|
insilmaril@260
|
528 |
|
insilmaril@260
|
529 |
cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
|
insilmaril@260
|
530 |
|
insilmaril@260
|
531 |
mapRect.setRect (totalBBox.x(), totalBBox.y(),
|
insilmaril@260
|
532 |
totalBBox.width(), totalBBox.height());
|
insilmaril@408
|
533 |
frame=new QCanvasRectangle (mapRect,mapScene);
|
insilmaril@260
|
534 |
frame->setBrush (QColor(white));
|
insilmaril@260
|
535 |
frame->setPen (QColor(black));
|
insilmaril@408
|
536 |
frame->setZValue(0);
|
insilmaril@260
|
537 |
frame->show();
|
insilmaril@260
|
538 |
}
|
insilmaril@260
|
539 |
else
|
insilmaril@260
|
540 |
{
|
insilmaril@260
|
541 |
setHideTmpMode (HideNone);
|
insilmaril@260
|
542 |
}
|
insilmaril@260
|
543 |
cout <<" hidemode="<<hidemode<<endl;
|
insilmaril@301
|
544 |
*/
|
insilmaril@527
|
545 |
|
insilmaril@527
|
546 |
void MapEditor::testFunction2()
|
insilmaril@527
|
547 |
{
|
insilmaril@645
|
548 |
|
insilmaril@691
|
549 |
/*
|
insilmaril@628
|
550 |
// Toggle hidemode
|
insilmaril@628
|
551 |
if (hidemode==HideExport)
|
insilmaril@628
|
552 |
setHideTmpMode (HideNone);
|
insilmaril@628
|
553 |
else
|
insilmaril@628
|
554 |
setHideTmpMode (HideExport);
|
insilmaril@691
|
555 |
*/
|
insilmaril@105
|
556 |
}
|
insilmaril@105
|
557 |
|
insilmaril@769
|
558 |
void MapEditor::cursorUp()
|
insilmaril@769
|
559 |
{
|
insilmaril@769
|
560 |
model->selectUpperBranch();
|
insilmaril@769
|
561 |
}
|
insilmaril@769
|
562 |
|
insilmaril@769
|
563 |
void MapEditor::cursorDown()
|
insilmaril@769
|
564 |
|
insilmaril@769
|
565 |
{
|
insilmaril@769
|
566 |
model->selectLowerBranch();
|
insilmaril@769
|
567 |
}
|
insilmaril@769
|
568 |
|
insilmaril@769
|
569 |
void MapEditor::cursorLeft()
|
insilmaril@769
|
570 |
{
|
insilmaril@769
|
571 |
model->selectLeftBranch();
|
insilmaril@769
|
572 |
}
|
insilmaril@769
|
573 |
|
insilmaril@769
|
574 |
void MapEditor::cursorRight()
|
insilmaril@769
|
575 |
{
|
insilmaril@769
|
576 |
model->selectRightBranch();
|
insilmaril@769
|
577 |
}
|
insilmaril@769
|
578 |
|
insilmaril@769
|
579 |
void MapEditor::cursorFirst()
|
insilmaril@769
|
580 |
{
|
insilmaril@769
|
581 |
model->selectFirstBranch();
|
insilmaril@769
|
582 |
}
|
insilmaril@769
|
583 |
|
insilmaril@769
|
584 |
void MapEditor::cursorLast()
|
insilmaril@769
|
585 |
{
|
insilmaril@769
|
586 |
model->selectLastBranch();
|
insilmaril@769
|
587 |
}
|
insilmaril@769
|
588 |
|
insilmaril@769
|
589 |
|
insilmaril@720
|
590 |
void MapEditor::editHeading()
|
insilmaril@720
|
591 |
{
|
insilmaril@720
|
592 |
if (editingHeading)
|
insilmaril@720
|
593 |
{
|
insilmaril@720
|
594 |
editHeadingFinished();
|
insilmaril@720
|
595 |
return;
|
insilmaril@720
|
596 |
}
|
insilmaril@753
|
597 |
BranchObj *bo=model->getSelectedBranchObj();
|
insilmaril@753
|
598 |
BranchItem *bi=model->getSelectedBranchItem();
|
insilmaril@773
|
599 |
if (bo)
|
insilmaril@720
|
600 |
{
|
insilmaril@720
|
601 |
model->setSelectionBlocked(true);
|
insilmaril@720
|
602 |
|
insilmaril@753
|
603 |
lineEdit->setText (bi->getHeading());
|
insilmaril@720
|
604 |
QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
|
insilmaril@720
|
605 |
lineEdit->setGeometry(p.x(),p.y(),230,25);
|
insilmaril@720
|
606 |
lineEdit->selectAll();
|
insilmaril@720
|
607 |
lineEdit->show();
|
insilmaril@720
|
608 |
lineEdit->setFocus();
|
insilmaril@720
|
609 |
lineEdit->grabKeyboard();
|
insilmaril@720
|
610 |
editingHeading=true;
|
insilmaril@720
|
611 |
}
|
insilmaril@720
|
612 |
|
insilmaril@720
|
613 |
}
|
insilmaril@720
|
614 |
void MapEditor::editHeadingFinished()
|
insilmaril@720
|
615 |
{
|
insilmaril@720
|
616 |
editingHeading=false;
|
insilmaril@720
|
617 |
lineEdit->releaseKeyboard();
|
insilmaril@720
|
618 |
model->setHeading (lineEdit->text() );
|
insilmaril@720
|
619 |
model->setSelectionBlocked(false);
|
insilmaril@720
|
620 |
lineEdit->hide();
|
insilmaril@720
|
621 |
|
insilmaril@720
|
622 |
// Maybe reselect previous branch
|
insilmaril@720
|
623 |
mainWindow->editHeadingFinished (model);
|
insilmaril@720
|
624 |
}
|
insilmaril@720
|
625 |
|
insilmaril@720
|
626 |
|
insilmaril@408
|
627 |
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
|
insilmaril@0
|
628 |
{
|
insilmaril@0
|
629 |
// Lineedits are already closed by preceding
|
insilmaril@0
|
630 |
// mouseEvent, we don't need to close here.
|
insilmaril@0
|
631 |
|
insilmaril@408
|
632 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
633 |
TreeItem *ti=findMapItem (p, NULL);
|
insilmaril@754
|
634 |
LinkableMapObj* lmo=NULL;
|
insilmaril@779
|
635 |
if (ti) lmo=((MapItem*)ti)->getLMO();
|
insilmaril@0
|
636 |
|
insilmaril@0
|
637 |
if (lmo)
|
insilmaril@0
|
638 |
{ // MapObj was found
|
insilmaril@735
|
639 |
if (model->getSelectedLMO() != lmo)
|
insilmaril@0
|
640 |
{
|
insilmaril@0
|
641 |
// select the MapObj
|
insilmaril@720
|
642 |
model->select(lmo);
|
insilmaril@0
|
643 |
}
|
insilmaril@0
|
644 |
// Context Menu
|
insilmaril@753
|
645 |
if (model->getSelectedBranchObj() )
|
insilmaril@0
|
646 |
{
|
insilmaril@424
|
647 |
// Context Menu on branch or mapcenter
|
insilmaril@746
|
648 |
//FIXME-3 model->updateActions(); needed?
|
insilmaril@424
|
649 |
branchContextMenu->popup(e->globalPos() );
|
insilmaril@424
|
650 |
} else
|
insilmaril@424
|
651 |
{
|
insilmaril@776
|
652 |
if (model->getSelectedImageItem() )
|
insilmaril@0
|
653 |
{
|
insilmaril@0
|
654 |
// Context Menu on floatimage
|
insilmaril@746
|
655 |
// model->updateActions(); FIXME-3 needed?
|
insilmaril@0
|
656 |
floatimageContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
657 |
}
|
insilmaril@0
|
658 |
}
|
insilmaril@0
|
659 |
} else
|
insilmaril@0
|
660 |
{ // No MapObj found, we are on the Canvas itself
|
insilmaril@408
|
661 |
// Context Menu on scene
|
insilmaril@746
|
662 |
// model->updateActions(); FIXME-3 needed?
|
insilmaril@723
|
663 |
|
insilmaril@723
|
664 |
// Open context menu synchronously to position new mapcenter
|
insilmaril@723
|
665 |
model->setContextPos (p);
|
insilmaril@723
|
666 |
canvasContextMenu->exec(e->globalPos() );
|
insilmaril@723
|
667 |
model->unsetContextPos ();
|
insilmaril@0
|
668 |
}
|
insilmaril@329
|
669 |
e->accept();
|
insilmaril@0
|
670 |
}
|
insilmaril@0
|
671 |
|
insilmaril@398
|
672 |
void MapEditor::keyPressEvent(QKeyEvent* e)
|
insilmaril@398
|
673 |
{
|
insilmaril@411
|
674 |
if (e->modifiers() & Qt::ControlModifier)
|
insilmaril@398
|
675 |
{
|
insilmaril@398
|
676 |
switch (mainWindow->getModMode())
|
insilmaril@398
|
677 |
{
|
insilmaril@473
|
678 |
case Main::ModModeColor:
|
insilmaril@398
|
679 |
setCursor (PickColorCursor);
|
insilmaril@398
|
680 |
break;
|
insilmaril@473
|
681 |
case Main::ModModeCopy:
|
insilmaril@398
|
682 |
setCursor (CopyCursor);
|
insilmaril@398
|
683 |
break;
|
insilmaril@473
|
684 |
case Main::ModModeXLink:
|
insilmaril@398
|
685 |
setCursor (XLinkCursor);
|
insilmaril@398
|
686 |
break;
|
insilmaril@398
|
687 |
default :
|
insilmaril@398
|
688 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
689 |
break;
|
insilmaril@398
|
690 |
}
|
insilmaril@398
|
691 |
}
|
insilmaril@398
|
692 |
}
|
insilmaril@398
|
693 |
|
insilmaril@398
|
694 |
void MapEditor::keyReleaseEvent(QKeyEvent* e)
|
insilmaril@398
|
695 |
{
|
insilmaril@411
|
696 |
if (!(e->modifiers() & Qt::ControlModifier))
|
insilmaril@398
|
697 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
698 |
}
|
insilmaril@398
|
699 |
|
insilmaril@408
|
700 |
void MapEditor::mousePressEvent(QMouseEvent* e)
|
insilmaril@0
|
701 |
{
|
insilmaril@329
|
702 |
// Ignore right clicks, these will go to context menus
|
insilmaril@366
|
703 |
if (e->button() == Qt::RightButton )
|
insilmaril@329
|
704 |
{
|
insilmaril@329
|
705 |
e->ignore();
|
insilmaril@329
|
706 |
return;
|
insilmaril@329
|
707 |
}
|
insilmaril@329
|
708 |
|
insilmaril@491
|
709 |
//Ignore clicks while editing heading
|
insilmaril@720
|
710 |
if (model->isSelectionBlocked() )
|
insilmaril@491
|
711 |
{
|
insilmaril@491
|
712 |
e->ignore();
|
insilmaril@491
|
713 |
return;
|
insilmaril@491
|
714 |
}
|
insilmaril@491
|
715 |
|
insilmaril@408
|
716 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
717 |
TreeItem *ti=findMapItem (p, NULL);
|
insilmaril@754
|
718 |
LinkableMapObj* lmo=NULL;
|
insilmaril@779
|
719 |
if (ti) lmo=((MapItem*)ti)->getLMO();
|
insilmaril@0
|
720 |
|
insilmaril@329
|
721 |
e->accept();
|
insilmaril@329
|
722 |
|
insilmaril@442
|
723 |
//Take care of system flags _or_ modifier modes
|
insilmaril@267
|
724 |
//
|
insilmaril@773
|
725 |
if (lmo && ti->isBranchLikeType() )
|
insilmaril@267
|
726 |
{
|
insilmaril@267
|
727 |
QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
|
insilmaril@267
|
728 |
if (!foname.isEmpty())
|
insilmaril@267
|
729 |
{
|
insilmaril@267
|
730 |
// systemFlag clicked
|
insilmaril@750
|
731 |
model->select (lmo); // FIXME-3 was selectInt
|
insilmaril@267
|
732 |
if (foname=="url")
|
insilmaril@267
|
733 |
{
|
insilmaril@366
|
734 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@267
|
735 |
mainWindow->editOpenURLTab();
|
insilmaril@267
|
736 |
else
|
insilmaril@267
|
737 |
mainWindow->editOpenURL();
|
insilmaril@267
|
738 |
}
|
insilmaril@780
|
739 |
else if (foname=="system-vymLink")
|
insilmaril@267
|
740 |
{
|
insilmaril@267
|
741 |
mainWindow->editOpenVymLink();
|
insilmaril@267
|
742 |
// tabWidget may change, better return now
|
insilmaril@267
|
743 |
// before segfaulting...
|
insilmaril@267
|
744 |
} else if (foname=="note")
|
insilmaril@267
|
745 |
mainWindow->windowToggleNoteEditor();
|
insilmaril@267
|
746 |
else if (foname=="hideInExport")
|
insilmaril@720
|
747 |
model->toggleHideExport();
|
insilmaril@746
|
748 |
// FIXME-3 needed? xelection.update();
|
insilmaril@267
|
749 |
return;
|
insilmaril@267
|
750 |
}
|
insilmaril@720
|
751 |
}
|
insilmaril@442
|
752 |
// No system flag clicked, take care of modmodes (CTRL-Click)
|
insilmaril@366
|
753 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@0
|
754 |
{
|
insilmaril@473
|
755 |
if (mainWindow->getModMode()==Main::ModModeColor)
|
insilmaril@83
|
756 |
{
|
insilmaril@83
|
757 |
pickingColor=true;
|
insilmaril@398
|
758 |
setCursor (PickColorCursor);
|
insilmaril@83
|
759 |
return;
|
insilmaril@83
|
760 |
}
|
insilmaril@473
|
761 |
if (mainWindow->getModMode()==Main::ModModeXLink)
|
insilmaril@83
|
762 |
{
|
insilmaril@90
|
763 |
BranchObj *bo_begin=NULL;
|
insilmaril@90
|
764 |
if (lmo)
|
insilmaril@90
|
765 |
bo_begin=(BranchObj*)(lmo);
|
insilmaril@90
|
766 |
else
|
insilmaril@753
|
767 |
bo_begin=model->getSelectedBranchObj();
|
insilmaril@90
|
768 |
if (bo_begin)
|
insilmaril@83
|
769 |
{
|
insilmaril@83
|
770 |
drawingLink=true;
|
insilmaril@90
|
771 |
linkingObj_src=bo_begin;
|
insilmaril@408
|
772 |
tmpXLink=new XLinkObj (mapScene);
|
insilmaril@95
|
773 |
tmpXLink->setBegin (bo_begin);
|
insilmaril@95
|
774 |
tmpXLink->setEnd (p);
|
insilmaril@720
|
775 |
tmpXLink->setColor(model->getMapDefXLinkColor());
|
insilmaril@720
|
776 |
tmpXLink->setWidth(model->getMapDefXLinkWidth());
|
insilmaril@95
|
777 |
tmpXLink->updateXLink();
|
insilmaril@95
|
778 |
tmpXLink->setVisibility (true);
|
insilmaril@83
|
779 |
return;
|
insilmaril@89
|
780 |
}
|
insilmaril@267
|
781 |
}
|
insilmaril@442
|
782 |
} // End of modmodes
|
insilmaril@442
|
783 |
|
insilmaril@0
|
784 |
if (lmo)
|
insilmaril@267
|
785 |
{
|
insilmaril@738
|
786 |
/*
|
insilmaril@729
|
787 |
cout << "ME::mouse pressed\n";
|
insilmaril@729
|
788 |
cout << " lmo="<<lmo<<endl;
|
insilmaril@776
|
789 |
cout << " ti="<<ti->getHeadingStd()<<endl;
|
insilmaril@738
|
790 |
*/
|
insilmaril@442
|
791 |
// Select the clicked object
|
insilmaril@729
|
792 |
|
insilmaril@776
|
793 |
// Get clicked LMO
|
insilmaril@738
|
794 |
model->select (ti);
|
insilmaril@442
|
795 |
|
insilmaril@0
|
796 |
// Left Button Move Branches
|
insilmaril@366
|
797 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
798 |
{
|
insilmaril@424
|
799 |
movingObj_start.setX( p.x() - lmo->x() );
|
insilmaril@424
|
800 |
movingObj_start.setY( p.y() - lmo->y() );
|
insilmaril@129
|
801 |
movingObj_orgPos.setX (lmo->x() );
|
insilmaril@129
|
802 |
movingObj_orgPos.setY (lmo->y() );
|
insilmaril@720
|
803 |
lmo->setRelPos();
|
insilmaril@366
|
804 |
movingObj_orgRelPos=lmo->getRelPos();
|
insilmaril@129
|
805 |
|
insilmaril@93
|
806 |
// If modMode==copy, then we want to "move" the _new_ object around
|
insilmaril@93
|
807 |
// then we need the offset from p to the _old_ selection, because of tmp
|
insilmaril@473
|
808 |
if (mainWindow->getModMode()==Main::ModModeCopy &&
|
insilmaril@366
|
809 |
e->state() & Qt::ControlModifier)
|
insilmaril@93
|
810 |
{
|
insilmaril@750
|
811 |
BranchItem *bi=model->getSelectedBranchItem();
|
insilmaril@750
|
812 |
if (bi)
|
insilmaril@93
|
813 |
{
|
insilmaril@93
|
814 |
copyingObj=true;
|
insilmaril@750
|
815 |
//FIXME-2 TreeItem::addBranch (BranchItem still missing)
|
insilmaril@750
|
816 |
//bi->addBranch (model->getSelectedBranchItem());
|
insilmaril@720
|
817 |
model->unselect();
|
insilmaril@750
|
818 |
model->select(bi->getLastBranch());
|
insilmaril@645
|
819 |
model->reposition();
|
insilmaril@93
|
820 |
}
|
insilmaril@421
|
821 |
}
|
insilmaril@421
|
822 |
|
insilmaril@735
|
823 |
movingObj=model->getSelectedLMO();
|
insilmaril@0
|
824 |
} else
|
insilmaril@0
|
825 |
// Middle Button Toggle Scroll
|
insilmaril@0
|
826 |
// (On Mac OS X this won't work, but we still have
|
insilmaril@0
|
827 |
// a button in the toolbar)
|
insilmaril@366
|
828 |
if (e->button() == Qt::MidButton )
|
insilmaril@720
|
829 |
model->toggleScroll();
|
insilmaril@746
|
830 |
// model->updateActions(); FIXME-3 needed?
|
insilmaril@746
|
831 |
// FIXME-3 needed? xelection.update();
|
insilmaril@0
|
832 |
} else
|
insilmaril@408
|
833 |
{ // No MapObj found, we are on the scene itself
|
insilmaril@408
|
834 |
// Left Button move Pos of sceneView
|
insilmaril@366
|
835 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
836 |
{
|
insilmaril@0
|
837 |
movingObj=NULL; // move Content not Obj
|
insilmaril@0
|
838 |
movingObj_start=e->globalPos();
|
insilmaril@408
|
839 |
movingCont_start=QPointF (
|
insilmaril@408
|
840 |
horizontalScrollBar()->value(),
|
insilmaril@408
|
841 |
verticalScrollBar()->value());
|
insilmaril@408
|
842 |
movingVec=QPointF(0,0);
|
insilmaril@398
|
843 |
setCursor(HandOpenCursor);
|
insilmaril@0
|
844 |
}
|
insilmaril@0
|
845 |
}
|
insilmaril@0
|
846 |
}
|
insilmaril@0
|
847 |
|
insilmaril@408
|
848 |
void MapEditor::mouseMoveEvent(QMouseEvent* e)
|
insilmaril@0
|
849 |
{
|
insilmaril@408
|
850 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
851 |
TreeItem *seli=model->getSelectedItem();
|
insilmaril@777
|
852 |
LinkableMapObj* lmosel=NULL;
|
insilmaril@776
|
853 |
if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image))
|
insilmaril@779
|
854 |
lmosel=((MapItem*)seli)->getLMO();
|
insilmaril@83
|
855 |
|
insilmaril@0
|
856 |
// Move the selected MapObj
|
insilmaril@424
|
857 |
if ( lmosel && movingObj)
|
insilmaril@0
|
858 |
{
|
insilmaril@421
|
859 |
// reset cursor if we are moving and don't copy
|
insilmaril@473
|
860 |
if (mainWindow->getModMode()!=Main::ModModeCopy)
|
insilmaril@421
|
861 |
setCursor (Qt::ArrowCursor);
|
insilmaril@421
|
862 |
|
insilmaril@408
|
863 |
// To avoid jumping of the sceneView, only
|
insilmaril@763
|
864 |
// show selection, if not tmp linked
|
insilmaril@424
|
865 |
if (!lmosel->hasParObjTmp())
|
insilmaril@763
|
866 |
model->emitShowSelection();
|
insilmaril@0
|
867 |
|
insilmaril@83
|
868 |
// Now move the selection, but add relative position
|
insilmaril@83
|
869 |
// (movingObj_start) where selection was chosen with
|
insilmaril@83
|
870 |
// mousepointer. (This avoids flickering resp. jumping
|
insilmaril@0
|
871 |
// of selection back to absPos)
|
insilmaril@0
|
872 |
|
insilmaril@0
|
873 |
// Check if we could link
|
insilmaril@777
|
874 |
TreeItem *ti=findMapItem (p, seli);
|
insilmaril@777
|
875 |
BranchItem *dsti=NULL;
|
insilmaril@754
|
876 |
LinkableMapObj* dst=NULL;
|
insilmaril@777
|
877 |
if (ti && ti!=seli && ti->isBranchLikeType())
|
insilmaril@777
|
878 |
{
|
insilmaril@777
|
879 |
dsti=(BranchItem*)ti;
|
insilmaril@777
|
880 |
dst=dsti->getLMO();
|
insilmaril@777
|
881 |
} else
|
insilmaril@772
|
882 |
dsti=NULL;
|
insilmaril@0
|
883 |
|
insilmaril@0
|
884 |
|
insilmaril@777
|
885 |
if (lmosel && seli->getType()==TreeItem::Image)
|
insilmaril@0
|
886 |
{
|
insilmaril@776
|
887 |
FloatObj *fio=(FloatImageObj*)lmosel;
|
insilmaril@424
|
888 |
fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@424
|
889 |
fio->setRelPos();
|
insilmaril@779
|
890 |
fio->updateLinkGeometry(); //no need for reposition, if we update link here
|
insilmaril@775
|
891 |
model->emitSelectionChanged(); // position has changed
|
insilmaril@0
|
892 |
|
insilmaril@0
|
893 |
// Relink float to new mapcenter or branch, if shift is pressed
|
insilmaril@0
|
894 |
// Only relink, if selection really has a new parent
|
insilmaril@777
|
895 |
if ( e->modifiers()==Qt::ShiftModifier && dsti && dsti != seli->parent() )
|
insilmaril@0
|
896 |
{
|
insilmaril@773
|
897 |
// Also save the move which was done so far
|
insilmaril@773
|
898 |
QString pold=qpointfToString(movingObj_orgRelPos);
|
insilmaril@773
|
899 |
QString pnow=qpointfToString(fio->getRelPos());
|
insilmaril@773
|
900 |
model->saveState(
|
insilmaril@777
|
901 |
seli,
|
insilmaril@773
|
902 |
"moveRel "+pold,
|
insilmaril@777
|
903 |
seli,
|
insilmaril@773
|
904 |
"moveRel "+pnow,
|
insilmaril@773
|
905 |
QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
|
insilmaril@773
|
906 |
fio->getParObj()->requestReposition();
|
insilmaril@773
|
907 |
model->reposition();
|
insilmaril@420
|
908 |
|
insilmaril@777
|
909 |
model->relinkImage ((ImageItem*) seli,dsti);
|
insilmaril@777
|
910 |
model->select (seli);
|
insilmaril@777
|
911 |
//movingObj=lmosel; //FIXME-3
|
insilmaril@773
|
912 |
//movingObj_orgRelPos=lmosel->getRelPos();
|
insilmaril@420
|
913 |
|
insilmaril@773
|
914 |
model->reposition();
|
insilmaril@0
|
915 |
}
|
insilmaril@388
|
916 |
} else
|
insilmaril@388
|
917 |
{ // selection != a FloatObj
|
insilmaril@755
|
918 |
if (seli->depth()==0) //FIXME-1 also moved mapcenters could be linked, but not working here...
|
insilmaril@0
|
919 |
{
|
insilmaril@388
|
920 |
// Move MapCenter
|
insilmaril@388
|
921 |
if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
|
insilmaril@773
|
922 |
((BranchObj*)lmosel)->moveBy(
|
insilmaril@773
|
923 |
QPointF(p.x() -movingObj_start.x(),
|
insilmaril@773
|
924 |
p.y()-movingObj_start.y()) );
|
insilmaril@0
|
925 |
else
|
insilmaril@645
|
926 |
lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@645
|
927 |
model->updateRelPositions();
|
insilmaril@0
|
928 |
} else
|
insilmaril@0
|
929 |
{
|
insilmaril@755
|
930 |
if (seli->depth()==1)
|
insilmaril@0
|
931 |
{
|
insilmaril@388
|
932 |
// Move mainbranch
|
insilmaril@0
|
933 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@388
|
934 |
lmosel->setRelPos();
|
insilmaril@0
|
935 |
} else
|
insilmaril@0
|
936 |
{
|
insilmaril@388
|
937 |
// Move ordinary branch
|
insilmaril@473
|
938 |
if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
|
insilmaril@0
|
939 |
// Add width of bbox here, otherwise alignRelTo will cause jumping around
|
insilmaril@720
|
940 |
lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
|
insilmaril@175
|
941 |
p.y()-movingObj_start.y() +lmosel->getTopPad() );
|
insilmaril@0
|
942 |
else
|
insilmaril@175
|
943 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
|
insilmaril@720
|
944 |
lmosel->setRelPos();
|
insilmaril@0
|
945 |
}
|
insilmaril@0
|
946 |
|
insilmaril@431
|
947 |
// Maybe we can relink temporary?
|
insilmaril@772
|
948 |
if (dsti)
|
insilmaril@0
|
949 |
{
|
insilmaril@388
|
950 |
if (e->modifiers()==Qt::ControlModifier)
|
insilmaril@0
|
951 |
{
|
insilmaril@754
|
952 |
// Special case: CTRL to link below dst
|
insilmaril@754
|
953 |
lmosel->setParObjTmp (dst,p,+1);
|
insilmaril@0
|
954 |
}
|
insilmaril@388
|
955 |
else if (e->modifiers()==Qt::ShiftModifier)
|
insilmaril@754
|
956 |
lmosel->setParObjTmp (dst,p,-1);
|
insilmaril@0
|
957 |
else
|
insilmaril@754
|
958 |
lmosel->setParObjTmp (dst,p,0);
|
insilmaril@0
|
959 |
} else
|
insilmaril@0
|
960 |
{
|
insilmaril@93
|
961 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
962 |
}
|
insilmaril@428
|
963 |
// reposition subbranch
|
insilmaril@428
|
964 |
lmosel->reposition();
|
insilmaril@0
|
965 |
} // depth>0
|
insilmaril@0
|
966 |
|
insilmaril@732
|
967 |
QItemSelection sel=model->getSelectionModel()->selection();
|
insilmaril@735
|
968 |
updateSelection(sel,sel); // position has changed
|
insilmaril@732
|
969 |
|
insilmaril@0
|
970 |
} // no FloatImageObj
|
insilmaril@0
|
971 |
|
insilmaril@408
|
972 |
scene()->update();
|
insilmaril@0
|
973 |
return;
|
insilmaril@0
|
974 |
} // selection && moving_obj
|
insilmaril@0
|
975 |
|
insilmaril@83
|
976 |
// Draw a link from one branch to another
|
insilmaril@83
|
977 |
if (drawingLink)
|
insilmaril@83
|
978 |
{
|
insilmaril@95
|
979 |
tmpXLink->setEnd (p);
|
insilmaril@95
|
980 |
tmpXLink->updateXLink();
|
insilmaril@83
|
981 |
}
|
insilmaril@83
|
982 |
|
insilmaril@408
|
983 |
// Move sceneView
|
insilmaril@411
|
984 |
if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
|
insilmaril@0
|
985 |
{
|
insilmaril@408
|
986 |
QPointF p=e->globalPos();
|
insilmaril@0
|
987 |
movingVec.setX(-p.x() + movingObj_start.x() );
|
insilmaril@0
|
988 |
movingVec.setY(-p.y() + movingObj_start.y() );
|
insilmaril@408
|
989 |
horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
|
insilmaril@408
|
990 |
verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
|
insilmaril@0
|
991 |
}
|
insilmaril@0
|
992 |
}
|
insilmaril@0
|
993 |
|
insilmaril@0
|
994 |
|
insilmaril@408
|
995 |
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
|
insilmaril@0
|
996 |
{
|
insilmaril@408
|
997 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
998 |
TreeItem *seli=model->getSelectedItem();
|
insilmaril@754
|
999 |
|
insilmaril@772
|
1000 |
TreeItem *dsti=NULL;
|
insilmaril@772
|
1001 |
if (seli) dsti=findMapItem(p, seli);
|
insilmaril@755
|
1002 |
LinkableMapObj* dst=NULL;
|
insilmaril@772
|
1003 |
if (dsti && dsti->isBranchLikeType ())
|
insilmaril@779
|
1004 |
dst=((MapItem*)dsti)->getLMO();
|
insilmaril@772
|
1005 |
else
|
insilmaril@772
|
1006 |
dsti=NULL;
|
insilmaril@754
|
1007 |
|
insilmaril@754
|
1008 |
|
insilmaril@0
|
1009 |
// Have we been picking color?
|
insilmaril@0
|
1010 |
if (pickingColor)
|
insilmaril@0
|
1011 |
{
|
insilmaril@0
|
1012 |
pickingColor=false;
|
insilmaril@366
|
1013 |
setCursor (Qt::ArrowCursor);
|
insilmaril@0
|
1014 |
// Check if we are over another branch
|
insilmaril@772
|
1015 |
if (dst)
|
insilmaril@0
|
1016 |
{
|
insilmaril@366
|
1017 |
if (e->state() & Qt::ShiftModifier)
|
insilmaril@720
|
1018 |
model->colorBranch (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
1019 |
else
|
insilmaril@720
|
1020 |
model->colorSubtree (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
1021 |
}
|
insilmaril@0
|
1022 |
return;
|
insilmaril@0
|
1023 |
}
|
insilmaril@83
|
1024 |
|
insilmaril@83
|
1025 |
// Have we been drawing a link?
|
insilmaril@491
|
1026 |
if (drawingLink)
|
insilmaril@83
|
1027 |
{
|
insilmaril@83
|
1028 |
drawingLink=false;
|
insilmaril@83
|
1029 |
// Check if we are over another branch
|
insilmaril@772
|
1030 |
if (dsti)
|
insilmaril@83
|
1031 |
{
|
insilmaril@95
|
1032 |
tmpXLink->setEnd ( ((BranchObj*)(dst)) );
|
insilmaril@95
|
1033 |
tmpXLink->updateXLink();
|
insilmaril@746
|
1034 |
tmpXLink->activate(); //FIXME-2 savestate missing
|
insilmaril@726
|
1035 |
//model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
|
insilmaril@83
|
1036 |
} else
|
insilmaril@83
|
1037 |
{
|
insilmaril@95
|
1038 |
delete(tmpXLink);
|
insilmaril@95
|
1039 |
tmpXLink=NULL;
|
insilmaril@83
|
1040 |
}
|
insilmaril@83
|
1041 |
return;
|
insilmaril@83
|
1042 |
}
|
insilmaril@83
|
1043 |
|
insilmaril@0
|
1044 |
// Have we been moving something?
|
insilmaril@754
|
1045 |
if ( seli && movingObj )
|
insilmaril@0
|
1046 |
{
|
insilmaril@776
|
1047 |
if (seli->getType()==TreeItem::Image)
|
insilmaril@175
|
1048 |
{
|
insilmaril@779
|
1049 |
FloatImageObj *fio=(FloatImageObj*)( ((MapItem*)seli)->getLMO());
|
insilmaril@776
|
1050 |
if(fio)
|
insilmaril@776
|
1051 |
{
|
insilmaril@776
|
1052 |
// Moved FloatObj. Maybe we need to reposition
|
insilmaril@776
|
1053 |
QString pold=qpointfToString(movingObj_orgRelPos);
|
insilmaril@776
|
1054 |
QString pnow=qpointfToString(fio->getRelPos());
|
insilmaril@776
|
1055 |
model->saveState(
|
insilmaril@776
|
1056 |
seli,
|
insilmaril@776
|
1057 |
"moveRel "+pold,
|
insilmaril@776
|
1058 |
seli,
|
insilmaril@776
|
1059 |
"moveRel "+pnow,
|
insilmaril@776
|
1060 |
QString("Move %1 to relative position %2").arg(model->getObjectName(seli)).arg(pnow));
|
insilmaril@424
|
1061 |
|
insilmaril@776
|
1062 |
fio->getParObj()->requestReposition();
|
insilmaril@776
|
1063 |
model->reposition();
|
insilmaril@776
|
1064 |
}
|
insilmaril@776
|
1065 |
}
|
insilmaril@175
|
1066 |
|
insilmaril@753
|
1067 |
BranchItem *bi=model->getSelectedBranchItem();
|
insilmaril@753
|
1068 |
if (bi && bi->depth()==0)
|
insilmaril@497
|
1069 |
{
|
insilmaril@753
|
1070 |
if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
|
insilmaril@625
|
1071 |
{
|
insilmaril@625
|
1072 |
QString pold=qpointfToString(movingObj_orgPos);
|
insilmaril@753
|
1073 |
QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
|
insilmaril@753
|
1074 |
|
insilmaril@720
|
1075 |
model->saveState(
|
insilmaril@753
|
1076 |
bi,
|
insilmaril@625
|
1077 |
"move "+pold,
|
insilmaril@753
|
1078 |
bi,
|
insilmaril@625
|
1079 |
"move "+pnow,
|
insilmaril@753
|
1080 |
QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
|
insilmaril@625
|
1081 |
}
|
insilmaril@388
|
1082 |
}
|
insilmaril@645
|
1083 |
|
insilmaril@773
|
1084 |
if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
|
insilmaril@388
|
1085 |
{ // A branch was moved
|
insilmaril@777
|
1086 |
LinkableMapObj* lmosel=NULL;
|
insilmaril@779
|
1087 |
lmosel=((MapItem*)seli)->getLMO();
|
insilmaril@760
|
1088 |
|
insilmaril@0
|
1089 |
// save the position in case we link to mapcenter
|
insilmaril@424
|
1090 |
QPointF savePos=QPointF (lmosel->getAbsPos() );
|
insilmaril@0
|
1091 |
|
insilmaril@0
|
1092 |
// Reset the temporary drawn link to the original one
|
insilmaril@424
|
1093 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
1094 |
|
insilmaril@366
|
1095 |
// For Redo we may need to save original selection
|
insilmaril@773
|
1096 |
QString preSelStr=model->getSelectString(seli);
|
insilmaril@93
|
1097 |
|
insilmaril@94
|
1098 |
copyingObj=false;
|
insilmaril@772
|
1099 |
if (dsti)
|
insilmaril@93
|
1100 |
{
|
insilmaril@691
|
1101 |
// We have a destination, relink to that
|
insilmaril@691
|
1102 |
|
insilmaril@753
|
1103 |
BranchObj* bsel=model->getSelectedBranchObj();
|
insilmaril@366
|
1104 |
|
insilmaril@684
|
1105 |
QString preParStr=model->getSelectString (bsel->getParObj());
|
insilmaril@755
|
1106 |
QString preNum=QString::number (seli->num(),10);
|
insilmaril@366
|
1107 |
QString preDstParStr;
|
insilmaril@767
|
1108 |
bool relinked;
|
insilmaril@366
|
1109 |
|
insilmaril@366
|
1110 |
if (e->state() & Qt::ShiftModifier && dst->getParObj())
|
insilmaril@366
|
1111 |
{ // Link above dst
|
insilmaril@684
|
1112 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@767
|
1113 |
relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
|
insilmaril@366
|
1114 |
} else
|
insilmaril@366
|
1115 |
if (e->state() & Qt::ControlModifier && dst->getParObj())
|
insilmaril@366
|
1116 |
{
|
insilmaril@366
|
1117 |
// Link below dst
|
insilmaril@684
|
1118 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@767
|
1119 |
relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
|
insilmaril@366
|
1120 |
} else
|
insilmaril@366
|
1121 |
{ // Append to dst
|
insilmaril@684
|
1122 |
preDstParStr=model->getSelectString(dst);
|
insilmaril@767
|
1123 |
relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
|
insilmaril@755
|
1124 |
if (dsti->depth()==0) bsel->move (savePos);
|
insilmaril@366
|
1125 |
}
|
insilmaril@767
|
1126 |
if (relinked)
|
insilmaril@767
|
1127 |
{
|
insilmaril@767
|
1128 |
QString postSelStr=model->getSelectString(lmosel);
|
insilmaril@767
|
1129 |
QString postNum=QString::number (seli->num(),10);
|
insilmaril@366
|
1130 |
|
insilmaril@776
|
1131 |
QString undoCom="relinkTo (\""+
|
insilmaril@767
|
1132 |
preParStr+ "\"," + preNum +"," +
|
insilmaril@767
|
1133 |
QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
|
insilmaril@366
|
1134 |
|
insilmaril@776
|
1135 |
QString redoCom="relinkTo (\""+
|
insilmaril@767
|
1136 |
preDstParStr + "\"," + postNum + "," +
|
insilmaril@767
|
1137 |
QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
|
insilmaril@366
|
1138 |
|
insilmaril@767
|
1139 |
model->saveState (
|
insilmaril@767
|
1140 |
postSelStr,undoCom,
|
insilmaril@767
|
1141 |
preSelStr, redoCom,
|
insilmaril@767
|
1142 |
QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
|
insilmaril@691
|
1143 |
|
insilmaril@767
|
1144 |
}
|
insilmaril@163
|
1145 |
} else
|
insilmaril@691
|
1146 |
{
|
insilmaril@691
|
1147 |
// No destination, undo temporary move
|
insilmaril@691
|
1148 |
|
insilmaril@755
|
1149 |
if (seli->depth()==1)
|
insilmaril@366
|
1150 |
{
|
insilmaril@366
|
1151 |
// The select string might be different _after_ moving around.
|
insilmaril@366
|
1152 |
// Therefor reposition and then use string of old selection, too
|
insilmaril@645
|
1153 |
model->reposition();
|
insilmaril@366
|
1154 |
|
insilmaril@625
|
1155 |
QPointF rp(lmosel->getRelPos());
|
insilmaril@625
|
1156 |
if (rp != movingObj_orgRelPos)
|
insilmaril@625
|
1157 |
{
|
insilmaril@625
|
1158 |
QString ps=qpointfToString(rp);
|
insilmaril@720
|
1159 |
model->saveState(
|
insilmaril@684
|
1160 |
model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
|
insilmaril@625
|
1161 |
preSelStr, "moveRel "+ps,
|
insilmaril@726
|
1162 |
QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
|
insilmaril@625
|
1163 |
}
|
insilmaril@366
|
1164 |
}
|
insilmaril@691
|
1165 |
|
insilmaril@691
|
1166 |
// Draw the original link, before selection was moved around
|
insilmaril@755
|
1167 |
if (settings.value("/animation/use",false).toBool() && seli->depth()>1)
|
insilmaril@691
|
1168 |
{
|
insilmaril@720
|
1169 |
lmosel->setRelPos(); // calc relPos first for starting point
|
insilmaril@753
|
1170 |
QPointF dst=bi->getBranchObj()->getParObj()->getChildPos(); // FIXME-3 check getBO here...
|
insilmaril@720
|
1171 |
// if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
|
insilmaril@720
|
1172 |
|
insilmaril@691
|
1173 |
model->startAnimation(
|
insilmaril@723
|
1174 |
(BranchObj*)lmosel,
|
insilmaril@691
|
1175 |
lmosel->getRelPos(),
|
insilmaril@720
|
1176 |
movingObj_orgRelPos
|
insilmaril@720
|
1177 |
// QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
|
insilmaril@691
|
1178 |
);
|
insilmaril@691
|
1179 |
} else
|
insilmaril@691
|
1180 |
model->reposition();
|
insilmaril@691
|
1181 |
}
|
insilmaril@0
|
1182 |
}
|
insilmaril@775
|
1183 |
model->emitSelectionChanged(); //FIXME-3 needed? at least not after pos of selection has changed...
|
insilmaril@408
|
1184 |
// Finally resize scene, if needed
|
insilmaril@408
|
1185 |
scene()->update();
|
insilmaril@0
|
1186 |
movingObj=NULL;
|
insilmaril@366
|
1187 |
|
insilmaril@366
|
1188 |
// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
|
insilmaril@746
|
1189 |
// model->updateActions(); FIXME-3 neeeded?
|
insilmaril@0
|
1190 |
} else
|
insilmaril@83
|
1191 |
// maybe we moved View: set old cursor
|
insilmaril@366
|
1192 |
setCursor (Qt::ArrowCursor);
|
insilmaril@83
|
1193 |
|
insilmaril@0
|
1194 |
}
|
insilmaril@0
|
1195 |
|
insilmaril@408
|
1196 |
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
|
insilmaril@0
|
1197 |
{
|
insilmaril@720
|
1198 |
if (model->isSelectionBlocked() )
|
insilmaril@491
|
1199 |
{
|
insilmaril@491
|
1200 |
e->ignore();
|
insilmaril@491
|
1201 |
return;
|
insilmaril@491
|
1202 |
}
|
insilmaril@491
|
1203 |
|
insilmaril@366
|
1204 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
1205 |
{
|
insilmaril@408
|
1206 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
1207 |
TreeItem *ti=findMapItem (p, NULL);
|
insilmaril@754
|
1208 |
if (ti) { // MapObj was found
|
insilmaril@0
|
1209 |
// First select the MapObj than edit heading
|
insilmaril@754
|
1210 |
model->select (ti);
|
insilmaril@720
|
1211 |
editHeading();
|
insilmaril@0
|
1212 |
}
|
insilmaril@0
|
1213 |
}
|
insilmaril@0
|
1214 |
}
|
insilmaril@0
|
1215 |
|
insilmaril@0
|
1216 |
void MapEditor::resizeEvent (QResizeEvent* e)
|
insilmaril@0
|
1217 |
{
|
insilmaril@408
|
1218 |
QGraphicsView::resizeEvent( e );
|
insilmaril@0
|
1219 |
}
|
insilmaril@0
|
1220 |
|
insilmaril@412
|
1221 |
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
|
insilmaril@119
|
1222 |
{
|
insilmaril@417
|
1223 |
//for (unsigned int i=0;event->format(i);i++) // Debug mime type
|
insilmaril@417
|
1224 |
// cerr << event->format(i) << endl;
|
insilmaril@417
|
1225 |
|
insilmaril@417
|
1226 |
if (event->mimeData()->hasImage())
|
insilmaril@417
|
1227 |
event->acceptProposedAction();
|
insilmaril@417
|
1228 |
else
|
insilmaril@417
|
1229 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
1230 |
event->acceptProposedAction();
|
insilmaril@417
|
1231 |
}
|
insilmaril@417
|
1232 |
|
insilmaril@531
|
1233 |
void MapEditor::dragMoveEvent(QDragMoveEvent *)
|
insilmaril@417
|
1234 |
{
|
insilmaril@417
|
1235 |
}
|
insilmaril@417
|
1236 |
|
insilmaril@417
|
1237 |
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
|
insilmaril@417
|
1238 |
{
|
insilmaril@417
|
1239 |
event->accept();
|
insilmaril@119
|
1240 |
}
|
insilmaril@129
|
1241 |
|
insilmaril@412
|
1242 |
void MapEditor::dropEvent(QDropEvent *event)
|
insilmaril@129
|
1243 |
{
|
insilmaril@753
|
1244 |
BranchItem *selbi=model->getSelectedBranchItem();
|
insilmaril@753
|
1245 |
if (selbi)
|
insilmaril@128
|
1246 |
{
|
insilmaril@505
|
1247 |
if (debug)
|
insilmaril@505
|
1248 |
foreach (QString format,event->mimeData()->formats())
|
insilmaril@658
|
1249 |
cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
|
insilmaril@497
|
1250 |
|
insilmaril@497
|
1251 |
|
insilmaril@417
|
1252 |
QList <QUrl> uris;
|
insilmaril@417
|
1253 |
if (event->mimeData()->hasImage())
|
insilmaril@128
|
1254 |
{
|
insilmaril@417
|
1255 |
QVariant imageData = event->mimeData()->imageData();
|
insilmaril@720
|
1256 |
model->addFloatImage (qvariant_cast<QPixmap>(imageData));
|
insilmaril@417
|
1257 |
} else
|
insilmaril@417
|
1258 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
1259 |
uris=event->mimeData()->urls();
|
insilmaril@417
|
1260 |
|
insilmaril@417
|
1261 |
if (uris.count()>0)
|
insilmaril@128
|
1262 |
{
|
insilmaril@417
|
1263 |
QStringList files;
|
insilmaril@417
|
1264 |
QString s;
|
insilmaril@417
|
1265 |
QString heading;
|
insilmaril@753
|
1266 |
BranchItem *bi;
|
insilmaril@428
|
1267 |
for (int i=0; i<uris.count();i++)
|
insilmaril@408
|
1268 |
{
|
insilmaril@428
|
1269 |
// Workaround to avoid adding empty branches
|
insilmaril@428
|
1270 |
if (!uris.at(i).toString().isEmpty())
|
insilmaril@417
|
1271 |
{
|
insilmaril@775
|
1272 |
bi=model->addNewBranch();
|
insilmaril@753
|
1273 |
if (bi)
|
insilmaril@417
|
1274 |
{
|
insilmaril@753
|
1275 |
/* FIXME-2
|
insilmaril@428
|
1276 |
s=uris.at(i).toLocalFile();
|
insilmaril@428
|
1277 |
if (!s.isEmpty())
|
insilmaril@428
|
1278 |
{
|
insilmaril@625
|
1279 |
QString file = QDir::fromNativeSeparators(s);
|
insilmaril@428
|
1280 |
heading = QFileInfo(file).baseName();
|
insilmaril@428
|
1281 |
files.append(file);
|
insilmaril@428
|
1282 |
if (file.endsWith(".vym", false))
|
insilmaril@753
|
1283 |
bi->setVymLink(file);
|
insilmaril@428
|
1284 |
else
|
insilmaril@753
|
1285 |
bi->setURL(uris.at(i).toString());
|
insilmaril@428
|
1286 |
} else
|
insilmaril@428
|
1287 |
{
|
insilmaril@428
|
1288 |
bo->setURL(uris.at(i).toString());
|
insilmaril@428
|
1289 |
}
|
insilmaril@753
|
1290 |
*/
|
insilmaril@428
|
1291 |
|
insilmaril@428
|
1292 |
if (!heading.isEmpty())
|
insilmaril@753
|
1293 |
bi->setHeading(heading);
|
insilmaril@428
|
1294 |
else
|
insilmaril@753
|
1295 |
bi->setHeading(uris.at(i).toString());
|
insilmaril@753
|
1296 |
|
insilmaril@428
|
1297 |
}
|
insilmaril@417
|
1298 |
}
|
insilmaril@417
|
1299 |
}
|
insilmaril@645
|
1300 |
model->reposition();
|
insilmaril@417
|
1301 |
}
|
insilmaril@417
|
1302 |
}
|
insilmaril@417
|
1303 |
event->acceptProposedAction();
|
insilmaril@417
|
1304 |
}
|
insilmaril@417
|
1305 |
|
insilmaril@776
|
1306 |
void MapEditor::updateSelection(QItemSelection newsel,QItemSelection oldsel)
|
insilmaril@728
|
1307 |
{
|
insilmaril@779
|
1308 |
// Note: Here we are prepared for multiple selections, though this
|
insilmaril@779
|
1309 |
// is not yet implemented elsewhere
|
insilmaril@779
|
1310 |
|
insilmaril@776
|
1311 |
// Here in MapEditor we can only select Branches and Images
|
insilmaril@776
|
1312 |
QModelIndex ix;
|
insilmaril@776
|
1313 |
foreach (ix,newsel.indexes() )
|
insilmaril@776
|
1314 |
{
|
insilmaril@776
|
1315 |
TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
|
insilmaril@776
|
1316 |
if (ti->getType()!=TreeItem::Branch && ti->getType()!=TreeItem::Image )
|
insilmaril@776
|
1317 |
newsel.indexes().removeOne (ix);
|
insilmaril@776
|
1318 |
}
|
insilmaril@776
|
1319 |
|
insilmaril@779
|
1320 |
// Trim list of selection rectangles
|
insilmaril@776
|
1321 |
while (newsel.indexes().count() < selboxList.count() )
|
insilmaril@776
|
1322 |
delete selboxList.takeFirst();
|
insilmaril@776
|
1323 |
|
insilmaril@775
|
1324 |
// Take care to tmp scroll/unscroll
|
insilmaril@775
|
1325 |
if (!oldsel.isEmpty())
|
insilmaril@775
|
1326 |
{
|
insilmaril@775
|
1327 |
QModelIndex ix=oldsel.indexes().first();
|
insilmaril@775
|
1328 |
if (ix.isValid() )
|
insilmaril@775
|
1329 |
{
|
insilmaril@775
|
1330 |
TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
|
insilmaril@779
|
1331 |
if (ti)
|
insilmaril@775
|
1332 |
{
|
insilmaril@779
|
1333 |
if (ti->isBranchLikeType() )
|
insilmaril@779
|
1334 |
{
|
insilmaril@779
|
1335 |
// reset tmp scrolled branches
|
insilmaril@779
|
1336 |
BranchItem *bi=(BranchItem*)ti;
|
insilmaril@779
|
1337 |
bi->resetTmpUnscroll();
|
insilmaril@779
|
1338 |
}
|
insilmaril@779
|
1339 |
if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
|
insilmaril@779
|
1340 |
// Hide link if not needed
|
insilmaril@779
|
1341 |
((MapItem*)ti)->getLMO()->updateVisibility();
|
insilmaril@775
|
1342 |
}
|
insilmaril@775
|
1343 |
}
|
insilmaril@775
|
1344 |
}
|
insilmaril@775
|
1345 |
|
insilmaril@775
|
1346 |
if (!newsel.isEmpty())
|
insilmaril@775
|
1347 |
{
|
insilmaril@775
|
1348 |
QModelIndex ix=newsel.indexes().first();
|
insilmaril@775
|
1349 |
if (ix.isValid() )
|
insilmaril@775
|
1350 |
{
|
insilmaril@775
|
1351 |
// Temporary unscroll if necessary
|
insilmaril@775
|
1352 |
TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
|
insilmaril@775
|
1353 |
if (ti->isBranchLikeType() )
|
insilmaril@775
|
1354 |
{
|
insilmaril@775
|
1355 |
BranchItem *bi=(BranchItem*)ti;
|
insilmaril@775
|
1356 |
if (bi->hasScrolledParent(bi) )
|
insilmaril@775
|
1357 |
bi->tmpUnscroll();
|
insilmaril@775
|
1358 |
}
|
insilmaril@775
|
1359 |
scrollTo (ix);
|
insilmaril@779
|
1360 |
if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
|
insilmaril@779
|
1361 |
// Show link if needed
|
insilmaril@779
|
1362 |
((MapItem*)ti)->getLMO()->updateVisibility();
|
insilmaril@775
|
1363 |
}
|
insilmaril@775
|
1364 |
}
|
insilmaril@775
|
1365 |
|
insilmaril@731
|
1366 |
// Reduce rectangles
|
insilmaril@731
|
1367 |
while (newsel.indexes().count() < selboxList.count() )
|
insilmaril@731
|
1368 |
delete selboxList.takeFirst();
|
insilmaril@731
|
1369 |
|
insilmaril@731
|
1370 |
// Add additonal rectangles
|
insilmaril@731
|
1371 |
QGraphicsRectItem *sb;
|
insilmaril@731
|
1372 |
while (newsel.indexes().count() > selboxList.count() )
|
insilmaril@728
|
1373 |
{
|
insilmaril@731
|
1374 |
sb = mapScene->addRect(
|
insilmaril@731
|
1375 |
QRectF(0,0,0,0),
|
insilmaril@731
|
1376 |
QPen(selectionColor),
|
insilmaril@731
|
1377 |
selectionColor);
|
insilmaril@731
|
1378 |
sb->setZValue(Z_SELBOX);
|
insilmaril@731
|
1379 |
sb->show();
|
insilmaril@731
|
1380 |
selboxList.append (sb);
|
insilmaril@728
|
1381 |
}
|
insilmaril@731
|
1382 |
|
insilmaril@731
|
1383 |
// Reposition rectangles
|
insilmaril@731
|
1384 |
int i=0;
|
insilmaril@731
|
1385 |
QRectF bbox;
|
insilmaril@732
|
1386 |
QModelIndex index;
|
insilmaril@732
|
1387 |
|
insilmaril@732
|
1388 |
TreeItem *ti;
|
insilmaril@732
|
1389 |
LinkableMapObj *lmo;
|
insilmaril@731
|
1390 |
foreach (sb,selboxList)
|
insilmaril@731
|
1391 |
{
|
insilmaril@731
|
1392 |
index=newsel.indexes().at(i);
|
insilmaril@731
|
1393 |
ti= static_cast<TreeItem*>(index.internalPointer());
|
insilmaril@779
|
1394 |
lmo=((MapItem*)ti)->getLMO();
|
insilmaril@731
|
1395 |
bbox=lmo->getBBox();
|
insilmaril@731
|
1396 |
sb->setRect (
|
insilmaril@731
|
1397 |
bbox.x(),bbox.y(),
|
insilmaril@731
|
1398 |
bbox.width(), bbox.height());
|
insilmaril@731
|
1399 |
sb->setPen (selectionColor);
|
insilmaril@731
|
1400 |
sb->setBrush (selectionColor);
|
insilmaril@731
|
1401 |
i++;
|
insilmaril@731
|
1402 |
}
|
insilmaril@775
|
1403 |
|
insilmaril@775
|
1404 |
scene()->update();
|
insilmaril@729
|
1405 |
}
|
insilmaril@728
|
1406 |
|
insilmaril@753
|
1407 |
void MapEditor::updateData (const QModelIndex &sel)
|
insilmaril@729
|
1408 |
{
|
insilmaril@753
|
1409 |
TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
|
insilmaril@732
|
1410 |
|
insilmaril@746
|
1411 |
/* testing
|
insilmaril@753
|
1412 |
cout << "ME::updateData\n";
|
insilmaril@732
|
1413 |
|
insilmaril@753
|
1414 |
cout << " ti="<<ti<<endl;
|
insilmaril@753
|
1415 |
cout << " h="<<ti->getHeading().toStdString()<<endl;
|
insilmaril@729
|
1416 |
*/
|
insilmaril@753
|
1417 |
|
insilmaril@753
|
1418 |
if (ti->isBranchLikeType())
|
insilmaril@753
|
1419 |
{
|
insilmaril@779
|
1420 |
BranchObj *bo=(BranchObj*) ( ((MapItem*)ti)->getLMO());
|
insilmaril@767
|
1421 |
bo->updateData();
|
insilmaril@753
|
1422 |
}
|
insilmaril@728
|
1423 |
|
insilmaril@726
|
1424 |
}
|
insilmaril@412
|
1425 |
|
insilmaril@728
|
1426 |
void MapEditor::setSelectionColor (QColor col)
|
insilmaril@728
|
1427 |
{
|
insilmaril@728
|
1428 |
selectionColor=col;
|
insilmaril@732
|
1429 |
QItemSelection sel=model->getSelectionModel()->selection();
|
insilmaril@732
|
1430 |
updateSelection(sel,sel);
|
insilmaril@728
|
1431 |
}
|
insilmaril@728
|
1432 |
|
insilmaril@753
|
1433 |
|
insilmaril@728
|
1434 |
QColor MapEditor::getSelectionColor ()
|
insilmaril@728
|
1435 |
{
|
insilmaril@728
|
1436 |
return selectionColor;
|
insilmaril@728
|
1437 |
}
|
insilmaril@728
|
1438 |
|
insilmaril@728
|
1439 |
|