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@175
|
9 |
#include "mainwindow.h"
|
insilmaril@175
|
10 |
#include "misc.h"
|
insilmaril@314
|
11 |
#include "warningdialog.h"
|
insilmaril@0
|
12 |
|
insilmaril@0
|
13 |
|
insilmaril@0
|
14 |
extern int statusbarTime;
|
insilmaril@0
|
15 |
extern Main *mainWindow;
|
insilmaril@164
|
16 |
extern QString tmpVymDir;
|
insilmaril@166
|
17 |
extern QString clipboardDir;
|
insilmaril@491
|
18 |
extern QString clipboardFile;
|
insilmaril@166
|
19 |
extern bool clipboardEmpty;
|
insilmaril@473
|
20 |
extern bool debug;
|
insilmaril@0
|
21 |
extern FlagRowObj *standardFlagsDefault;
|
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@720
|
43 |
model=vm;
|
insilmaril@645
|
44 |
model->setScene (mapScene);
|
insilmaril@645
|
45 |
model->setMapEditor (this);
|
insilmaril@720
|
46 |
model->registerEditor(this);
|
insilmaril@720
|
47 |
model->addMapCenter(); // FIXME create this in MapEditor until BO and MCO are independent of scene
|
insilmaril@720
|
48 |
model->makeDefault();
|
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@398
|
60 |
setFocusPolicy (Qt::StrongFocus);
|
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@720
|
74 |
model->reposition(); //FIXME really still needed?
|
insilmaril@381
|
75 |
|
insilmaril@531
|
76 |
|
insilmaril@720
|
77 |
// Action to embed LineEdit for heading in Scene
|
insilmaril@720
|
78 |
editingHeading=false;
|
insilmaril@720
|
79 |
lineEdit=new QLineEdit;
|
insilmaril@720
|
80 |
lineEdit->hide();
|
insilmaril@720
|
81 |
QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
|
insilmaril@720
|
82 |
pw->setZValue (100);
|
insilmaril@676
|
83 |
|
insilmaril@720
|
84 |
QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
|
insilmaril@720
|
85 |
a->setShortcut ( Qt::Key_Return ); //Edit heading
|
insilmaril@720
|
86 |
//a->setShortcutContext (Qt::WindowShortcut);
|
insilmaril@720
|
87 |
addAction (a);
|
insilmaril@720
|
88 |
connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
|
insilmaril@720
|
89 |
a = new QAction( tr( "Edit heading","MapEditor" ), this);
|
insilmaril@720
|
90 |
a->setShortcut ( Qt::Key_Enter); //Edit heading
|
insilmaril@720
|
91 |
//a->setShortcutContext (Qt::WindowShortcut);
|
insilmaril@720
|
92 |
addAction (a);
|
insilmaril@720
|
93 |
connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
|
insilmaril@628
|
94 |
|
insilmaril@638
|
95 |
// Attributes //FIXME testing only...
|
insilmaril@638
|
96 |
QString k;
|
insilmaril@638
|
97 |
AttributeDef *ad;
|
insilmaril@628
|
98 |
attrTable= new AttributeTable();
|
insilmaril@638
|
99 |
k="A - StringList";
|
insilmaril@638
|
100 |
ad=attrTable->addKey (k,StringList);
|
insilmaril@638
|
101 |
if (ad)
|
insilmaril@638
|
102 |
{
|
insilmaril@638
|
103 |
QStringList sl;
|
insilmaril@638
|
104 |
sl <<"val 1"<<"val 2"<< "val 3";
|
insilmaril@638
|
105 |
ad->setValue (QVariant (sl));
|
insilmaril@638
|
106 |
}
|
insilmaril@638
|
107 |
//attrTable->addValue ("Key A","P 1");
|
insilmaril@638
|
108 |
//attrTable->addValue ("Key A","P 2");
|
insilmaril@638
|
109 |
//attrTable->addValue ("Key A","P 3");
|
insilmaril@638
|
110 |
//attrTable->addValue ("Key A","P 4");
|
insilmaril@638
|
111 |
k="B - FreeString";
|
insilmaril@638
|
112 |
ad=attrTable->addKey (k,FreeString);
|
insilmaril@638
|
113 |
if (ad)
|
insilmaril@638
|
114 |
{
|
insilmaril@638
|
115 |
//attrTable->addValue ("Key B","w1");
|
insilmaril@638
|
116 |
//attrTable->addValue ("Key B","w2");
|
insilmaril@638
|
117 |
}
|
insilmaril@638
|
118 |
k="C - UniqueString";
|
insilmaril@638
|
119 |
ad=attrTable->addKey (k,UniqueString);
|
insilmaril@638
|
120 |
if (ad)
|
insilmaril@638
|
121 |
{
|
insilmaril@638
|
122 |
//attrTable->addKey ("Key Prio");
|
insilmaril@638
|
123 |
//attrTable->addValue ("Key Prio","Prio 1");
|
insilmaril@638
|
124 |
//attrTable->addValue ("Key Prio","Prio 2");
|
insilmaril@638
|
125 |
}
|
insilmaril@0
|
126 |
}
|
insilmaril@0
|
127 |
|
insilmaril@0
|
128 |
MapEditor::~MapEditor()
|
insilmaril@0
|
129 |
{
|
insilmaril@0
|
130 |
//cout <<"Destructor MapEditor\n";
|
insilmaril@625
|
131 |
// tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
|
insilmaril@625
|
132 |
|
insilmaril@720
|
133 |
//removeDir(QDir(tmpMapDir)); // FIXME check?!?
|
insilmaril@720
|
134 |
model->unregisterEditor(this);
|
insilmaril@0
|
135 |
}
|
insilmaril@0
|
136 |
|
insilmaril@645
|
137 |
VymModel* MapEditor::getModel()
|
insilmaril@0
|
138 |
{
|
insilmaril@645
|
139 |
return model;
|
insilmaril@0
|
140 |
}
|
insilmaril@0
|
141 |
|
insilmaril@408
|
142 |
QGraphicsScene * MapEditor::getScene()
|
insilmaril@0
|
143 |
{
|
insilmaril@408
|
144 |
return mapScene;
|
insilmaril@0
|
145 |
}
|
insilmaril@0
|
146 |
|
insilmaril@0
|
147 |
void MapEditor::print()
|
insilmaril@0
|
148 |
{
|
insilmaril@0
|
149 |
if ( !printer )
|
insilmaril@0
|
150 |
{
|
insilmaril@0
|
151 |
printer = new QPrinter;
|
insilmaril@0
|
152 |
printer->setColorMode (QPrinter::Color);
|
insilmaril@366
|
153 |
printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
|
insilmaril@412
|
154 |
printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
|
insilmaril@412
|
155 |
printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
|
insilmaril@0
|
156 |
}
|
insilmaril@0
|
157 |
|
insilmaril@645
|
158 |
QRectF totalBBox=model->getTotalBBox();
|
insilmaril@0
|
159 |
|
insilmaril@0
|
160 |
// Try to set orientation automagically
|
insilmaril@0
|
161 |
// Note: Interpretation of generated postscript is amibiguous, if
|
insilmaril@0
|
162 |
// there are problems with landscape mode, see
|
insilmaril@0
|
163 |
// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
|
insilmaril@0
|
164 |
|
insilmaril@0
|
165 |
if (totalBBox.width()>totalBBox.height())
|
insilmaril@0
|
166 |
// recommend landscape
|
insilmaril@0
|
167 |
printer->setOrientation (QPrinter::Landscape);
|
insilmaril@0
|
168 |
else
|
insilmaril@0
|
169 |
// recommend portrait
|
insilmaril@0
|
170 |
printer->setOrientation (QPrinter::Portrait);
|
insilmaril@0
|
171 |
|
insilmaril@0
|
172 |
if ( printer->setup(this) )
|
insilmaril@0
|
173 |
// returns false, if printing is canceled
|
insilmaril@0
|
174 |
{
|
insilmaril@0
|
175 |
QPainter pp(printer);
|
insilmaril@0
|
176 |
|
insilmaril@412
|
177 |
pp.setRenderHint(QPainter::Antialiasing,true);
|
insilmaril@412
|
178 |
|
insilmaril@0
|
179 |
// Don't print the visualisation of selection
|
insilmaril@720
|
180 |
model->unselect();
|
insilmaril@0
|
181 |
|
insilmaril@408
|
182 |
QRectF mapRect=totalBBox;
|
insilmaril@411
|
183 |
QGraphicsRectItem *frame=NULL;
|
insilmaril@412
|
184 |
|
insilmaril@417
|
185 |
if (printFrame)
|
insilmaril@0
|
186 |
{
|
insilmaril@417
|
187 |
// Print frame around map
|
insilmaril@417
|
188 |
mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
|
insilmaril@417
|
189 |
totalBBox.width()+20, totalBBox.height()+20);
|
insilmaril@417
|
190 |
frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
|
insilmaril@417
|
191 |
frame->setZValue(0);
|
insilmaril@417
|
192 |
frame->show();
|
insilmaril@417
|
193 |
}
|
insilmaril@417
|
194 |
|
insilmaril@417
|
195 |
|
insilmaril@412
|
196 |
double paperAspect = (double)printer->width() / (double)printer->height();
|
insilmaril@412
|
197 |
double mapAspect = (double)mapRect.width() / (double)mapRect.height();
|
insilmaril@417
|
198 |
int viewBottom;
|
insilmaril@0
|
199 |
if (mapAspect>=paperAspect)
|
insilmaril@0
|
200 |
{
|
insilmaril@0
|
201 |
// Fit horizontally to paper width
|
insilmaril@417
|
202 |
//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
|
insilmaril@417
|
203 |
viewBottom=(int)(printer->width()/mapAspect);
|
insilmaril@0
|
204 |
} else
|
insilmaril@0
|
205 |
{
|
insilmaril@0
|
206 |
// Fit vertically to paper height
|
insilmaril@417
|
207 |
//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
|
insilmaril@417
|
208 |
viewBottom=printer->height();
|
insilmaril@0
|
209 |
}
|
insilmaril@417
|
210 |
|
insilmaril@417
|
211 |
if (printFooter)
|
insilmaril@417
|
212 |
{
|
insilmaril@417
|
213 |
// Print footer below map
|
insilmaril@417
|
214 |
QFont font;
|
insilmaril@417
|
215 |
font.setPointSize(10);
|
insilmaril@417
|
216 |
pp.setFont (font);
|
insilmaril@417
|
217 |
QRectF footerBox(0,viewBottom,printer->width(),15);
|
insilmaril@720
|
218 |
// FIXME fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
|
insilmaril@417
|
219 |
pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
|
insilmaril@417
|
220 |
}
|
insilmaril@412
|
221 |
mapScene->render (
|
insilmaril@412
|
222 |
&pp,
|
insilmaril@412
|
223 |
QRectF (0,0,printer->width(),printer->height()-15),
|
insilmaril@412
|
224 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
|
insilmaril@412
|
225 |
);
|
insilmaril@412
|
226 |
|
insilmaril@412
|
227 |
// Viewport has paper dimension
|
insilmaril@412
|
228 |
if (frame) delete (frame);
|
insilmaril@0
|
229 |
|
insilmaril@0
|
230 |
// Restore selection
|
insilmaril@720
|
231 |
model->reselect();
|
insilmaril@119
|
232 |
|
insilmaril@119
|
233 |
// Save settings in vymrc
|
insilmaril@366
|
234 |
settings.writeEntry("/mainwindow/printerName",printer->printerName());
|
insilmaril@412
|
235 |
settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
|
insilmaril@412
|
236 |
settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
|
insilmaril@0
|
237 |
}
|
insilmaril@0
|
238 |
}
|
insilmaril@0
|
239 |
|
insilmaril@408
|
240 |
void MapEditor::setAntiAlias (bool b)
|
insilmaril@408
|
241 |
{
|
insilmaril@408
|
242 |
setRenderHint(QPainter::Antialiasing,b);
|
insilmaril@408
|
243 |
}
|
insilmaril@408
|
244 |
|
insilmaril@408
|
245 |
void MapEditor::setSmoothPixmap(bool b)
|
insilmaril@408
|
246 |
{
|
insilmaril@408
|
247 |
setRenderHint(QPainter::SmoothPixmapTransform,b);
|
insilmaril@408
|
248 |
}
|
insilmaril@408
|
249 |
|
insilmaril@0
|
250 |
void MapEditor::toggleStandardFlag(QString f)
|
insilmaril@0
|
251 |
{
|
insilmaril@720
|
252 |
BranchObj *bo=model->getSelectedBranch();
|
insilmaril@424
|
253 |
if (bo)
|
insilmaril@0
|
254 |
{
|
insilmaril@424
|
255 |
QString u,r;
|
insilmaril@424
|
256 |
if (bo->isSetStandardFlag(f))
|
insilmaril@366
|
257 |
{
|
insilmaril@424
|
258 |
r="unsetFlag";
|
insilmaril@424
|
259 |
u="setFlag";
|
insilmaril@424
|
260 |
}
|
insilmaril@424
|
261 |
else
|
insilmaril@424
|
262 |
{
|
insilmaril@424
|
263 |
u="unsetFlag";
|
insilmaril@424
|
264 |
r="setFlag";
|
insilmaril@424
|
265 |
}
|
insilmaril@720
|
266 |
model->saveState(
|
insilmaril@424
|
267 |
bo,
|
insilmaril@424
|
268 |
QString("%1 (\"%2\")").arg(u).arg(f),
|
insilmaril@424
|
269 |
bo,
|
insilmaril@424
|
270 |
QString("%1 (\"%2\")").arg(r).arg(f),
|
insilmaril@424
|
271 |
QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
|
insilmaril@424
|
272 |
bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
|
insilmaril@720
|
273 |
model->updateSelection();
|
insilmaril@424
|
274 |
}
|
insilmaril@0
|
275 |
}
|
insilmaril@0
|
276 |
|
insilmaril@442
|
277 |
void MapEditor::updateSelection()
|
insilmaril@442
|
278 |
{
|
insilmaril@442
|
279 |
// Tell selection to update geometries
|
insilmaril@720
|
280 |
model->updateSelection();
|
insilmaril@94
|
281 |
}
|
insilmaril@94
|
282 |
|
insilmaril@628
|
283 |
AttributeTable* MapEditor::attributeTable()
|
insilmaril@628
|
284 |
{
|
insilmaril@628
|
285 |
return attrTable;
|
insilmaril@628
|
286 |
}
|
insilmaril@628
|
287 |
|
insilmaril@527
|
288 |
void MapEditor::testFunction1()
|
insilmaril@0
|
289 |
{
|
insilmaril@720
|
290 |
BranchObj *bo=model->getSelectedBranch();
|
insilmaril@720
|
291 |
//if (bo) model->moveAway (bo);
|
insilmaril@720
|
292 |
if (bo) bo->setLinkStyle (LinkableMapObj::Line);
|
insilmaril@432
|
293 |
|
insilmaril@420
|
294 |
/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
|
insilmaril@260
|
295 |
if (hidemode==HideNone)
|
insilmaril@185
|
296 |
{
|
insilmaril@260
|
297 |
setHideTmpMode (HideExport);
|
insilmaril@260
|
298 |
mapCenter->calcBBoxSizeWithChilds();
|
insilmaril@408
|
299 |
QRectF totalBBox=mapCenter->getTotalBBox();
|
insilmaril@408
|
300 |
QRectF mapRect=totalBBox;
|
insilmaril@260
|
301 |
QCanvasRectangle *frame=NULL;
|
insilmaril@260
|
302 |
|
insilmaril@260
|
303 |
cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
|
insilmaril@260
|
304 |
|
insilmaril@260
|
305 |
mapRect.setRect (totalBBox.x(), totalBBox.y(),
|
insilmaril@260
|
306 |
totalBBox.width(), totalBBox.height());
|
insilmaril@408
|
307 |
frame=new QCanvasRectangle (mapRect,mapScene);
|
insilmaril@260
|
308 |
frame->setBrush (QColor(white));
|
insilmaril@260
|
309 |
frame->setPen (QColor(black));
|
insilmaril@408
|
310 |
frame->setZValue(0);
|
insilmaril@260
|
311 |
frame->show();
|
insilmaril@260
|
312 |
}
|
insilmaril@260
|
313 |
else
|
insilmaril@260
|
314 |
{
|
insilmaril@260
|
315 |
setHideTmpMode (HideNone);
|
insilmaril@260
|
316 |
}
|
insilmaril@260
|
317 |
cout <<" hidemode="<<hidemode<<endl;
|
insilmaril@301
|
318 |
*/
|
insilmaril@527
|
319 |
}
|
insilmaril@527
|
320 |
|
insilmaril@527
|
321 |
void MapEditor::testFunction2()
|
insilmaril@527
|
322 |
{
|
insilmaril@645
|
323 |
|
insilmaril@691
|
324 |
/*
|
insilmaril@628
|
325 |
// Toggle hidemode
|
insilmaril@628
|
326 |
if (hidemode==HideExport)
|
insilmaril@628
|
327 |
setHideTmpMode (HideNone);
|
insilmaril@628
|
328 |
else
|
insilmaril@628
|
329 |
setHideTmpMode (HideExport);
|
insilmaril@691
|
330 |
*/
|
insilmaril@105
|
331 |
}
|
insilmaril@105
|
332 |
|
insilmaril@720
|
333 |
void MapEditor::editHeading()
|
insilmaril@720
|
334 |
{
|
insilmaril@720
|
335 |
if (editingHeading)
|
insilmaril@720
|
336 |
{
|
insilmaril@720
|
337 |
editHeadingFinished();
|
insilmaril@720
|
338 |
return;
|
insilmaril@720
|
339 |
}
|
insilmaril@720
|
340 |
BranchObj *bo=model->getSelectedBranch();
|
insilmaril@720
|
341 |
if (bo)
|
insilmaril@720
|
342 |
{
|
insilmaril@720
|
343 |
model->setSelectionBlocked(true);
|
insilmaril@720
|
344 |
|
insilmaril@720
|
345 |
lineEdit->setText (bo->getHeading());
|
insilmaril@720
|
346 |
QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
|
insilmaril@720
|
347 |
lineEdit->setGeometry(p.x(),p.y(),230,25);
|
insilmaril@720
|
348 |
lineEdit->selectAll();
|
insilmaril@720
|
349 |
lineEdit->show();
|
insilmaril@720
|
350 |
lineEdit->setFocus();
|
insilmaril@720
|
351 |
lineEdit->grabKeyboard();
|
insilmaril@720
|
352 |
editingHeading=true;
|
insilmaril@720
|
353 |
}
|
insilmaril@720
|
354 |
|
insilmaril@720
|
355 |
}
|
insilmaril@720
|
356 |
void MapEditor::editHeadingFinished()
|
insilmaril@720
|
357 |
{
|
insilmaril@720
|
358 |
editingHeading=false;
|
insilmaril@720
|
359 |
lineEdit->releaseKeyboard();
|
insilmaril@720
|
360 |
model->setHeading (lineEdit->text() );
|
insilmaril@720
|
361 |
model->setSelectionBlocked(false);
|
insilmaril@720
|
362 |
lineEdit->hide();
|
insilmaril@720
|
363 |
|
insilmaril@720
|
364 |
// Maybe reselect previous branch
|
insilmaril@720
|
365 |
mainWindow->editHeadingFinished (model);
|
insilmaril@720
|
366 |
}
|
insilmaril@720
|
367 |
|
insilmaril@720
|
368 |
|
insilmaril@408
|
369 |
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
|
insilmaril@0
|
370 |
{
|
insilmaril@0
|
371 |
// Lineedits are already closed by preceding
|
insilmaril@0
|
372 |
// mouseEvent, we don't need to close here.
|
insilmaril@0
|
373 |
|
insilmaril@408
|
374 |
QPointF p = mapToScene(e->pos());
|
insilmaril@645
|
375 |
LinkableMapObj* lmo=model->findMapObj(p, NULL);
|
insilmaril@0
|
376 |
|
insilmaril@0
|
377 |
if (lmo)
|
insilmaril@0
|
378 |
{ // MapObj was found
|
insilmaril@720
|
379 |
if (model->getSelection() != lmo)
|
insilmaril@0
|
380 |
{
|
insilmaril@0
|
381 |
// select the MapObj
|
insilmaril@720
|
382 |
model->select(lmo);
|
insilmaril@0
|
383 |
}
|
insilmaril@0
|
384 |
// Context Menu
|
insilmaril@720
|
385 |
if (model->getSelectedBranch() )
|
insilmaril@0
|
386 |
{
|
insilmaril@424
|
387 |
// Context Menu on branch or mapcenter
|
insilmaril@720
|
388 |
model->updateActions();
|
insilmaril@424
|
389 |
branchContextMenu->popup(e->globalPos() );
|
insilmaril@424
|
390 |
} else
|
insilmaril@424
|
391 |
{
|
insilmaril@720
|
392 |
if (model->getSelectedFloatImage() )
|
insilmaril@0
|
393 |
{
|
insilmaril@0
|
394 |
// Context Menu on floatimage
|
insilmaril@720
|
395 |
model->updateActions();
|
insilmaril@0
|
396 |
floatimageContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
397 |
}
|
insilmaril@0
|
398 |
}
|
insilmaril@0
|
399 |
} else
|
insilmaril@0
|
400 |
{ // No MapObj found, we are on the Canvas itself
|
insilmaril@408
|
401 |
// Context Menu on scene
|
insilmaril@720
|
402 |
model->updateActions();
|
insilmaril@684
|
403 |
contextMenuPos=p;
|
insilmaril@0
|
404 |
canvasContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
405 |
}
|
insilmaril@329
|
406 |
e->accept();
|
insilmaril@0
|
407 |
}
|
insilmaril@0
|
408 |
|
insilmaril@398
|
409 |
void MapEditor::keyPressEvent(QKeyEvent* e)
|
insilmaril@398
|
410 |
{
|
insilmaril@411
|
411 |
if (e->modifiers() & Qt::ControlModifier)
|
insilmaril@398
|
412 |
{
|
insilmaril@398
|
413 |
switch (mainWindow->getModMode())
|
insilmaril@398
|
414 |
{
|
insilmaril@473
|
415 |
case Main::ModModeColor:
|
insilmaril@398
|
416 |
setCursor (PickColorCursor);
|
insilmaril@398
|
417 |
break;
|
insilmaril@473
|
418 |
case Main::ModModeCopy:
|
insilmaril@398
|
419 |
setCursor (CopyCursor);
|
insilmaril@398
|
420 |
break;
|
insilmaril@473
|
421 |
case Main::ModModeXLink:
|
insilmaril@398
|
422 |
setCursor (XLinkCursor);
|
insilmaril@398
|
423 |
break;
|
insilmaril@398
|
424 |
default :
|
insilmaril@398
|
425 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
426 |
break;
|
insilmaril@398
|
427 |
}
|
insilmaril@398
|
428 |
}
|
insilmaril@398
|
429 |
}
|
insilmaril@398
|
430 |
|
insilmaril@398
|
431 |
void MapEditor::keyReleaseEvent(QKeyEvent* e)
|
insilmaril@398
|
432 |
{
|
insilmaril@411
|
433 |
if (!(e->modifiers() & Qt::ControlModifier))
|
insilmaril@398
|
434 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
435 |
}
|
insilmaril@398
|
436 |
|
insilmaril@408
|
437 |
void MapEditor::mousePressEvent(QMouseEvent* e)
|
insilmaril@0
|
438 |
{
|
insilmaril@329
|
439 |
// Ignore right clicks, these will go to context menus
|
insilmaril@366
|
440 |
if (e->button() == Qt::RightButton )
|
insilmaril@329
|
441 |
{
|
insilmaril@329
|
442 |
e->ignore();
|
insilmaril@329
|
443 |
return;
|
insilmaril@329
|
444 |
}
|
insilmaril@329
|
445 |
|
insilmaril@491
|
446 |
//Ignore clicks while editing heading
|
insilmaril@720
|
447 |
if (model->isSelectionBlocked() )
|
insilmaril@491
|
448 |
{
|
insilmaril@491
|
449 |
e->ignore();
|
insilmaril@491
|
450 |
return;
|
insilmaril@491
|
451 |
}
|
insilmaril@491
|
452 |
|
insilmaril@408
|
453 |
QPointF p = mapToScene(e->pos());
|
insilmaril@645
|
454 |
LinkableMapObj* lmo=model->findMapObj(p, NULL);
|
insilmaril@0
|
455 |
|
insilmaril@329
|
456 |
e->accept();
|
insilmaril@329
|
457 |
|
insilmaril@442
|
458 |
//Take care of system flags _or_ modifier modes
|
insilmaril@267
|
459 |
//
|
insilmaril@267
|
460 |
if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
|
insilmaril@267
|
461 |
typeid(*lmo)==typeid(MapCenterObj) ))
|
insilmaril@267
|
462 |
{
|
insilmaril@267
|
463 |
QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
|
insilmaril@267
|
464 |
if (!foname.isEmpty())
|
insilmaril@267
|
465 |
{
|
insilmaril@267
|
466 |
// systemFlag clicked
|
insilmaril@720
|
467 |
model->selectInt (lmo);
|
insilmaril@267
|
468 |
if (foname=="url")
|
insilmaril@267
|
469 |
{
|
insilmaril@366
|
470 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@267
|
471 |
mainWindow->editOpenURLTab();
|
insilmaril@267
|
472 |
else
|
insilmaril@267
|
473 |
mainWindow->editOpenURL();
|
insilmaril@267
|
474 |
}
|
insilmaril@267
|
475 |
else if (foname=="vymLink")
|
insilmaril@267
|
476 |
{
|
insilmaril@267
|
477 |
mainWindow->editOpenVymLink();
|
insilmaril@267
|
478 |
// tabWidget may change, better return now
|
insilmaril@267
|
479 |
// before segfaulting...
|
insilmaril@267
|
480 |
} else if (foname=="note")
|
insilmaril@267
|
481 |
mainWindow->windowToggleNoteEditor();
|
insilmaril@267
|
482 |
else if (foname=="hideInExport")
|
insilmaril@720
|
483 |
model->toggleHideExport();
|
insilmaril@720
|
484 |
// FIXME needed? xelection.update();
|
insilmaril@267
|
485 |
return;
|
insilmaril@267
|
486 |
}
|
insilmaril@720
|
487 |
}
|
insilmaril@442
|
488 |
// No system flag clicked, take care of modmodes (CTRL-Click)
|
insilmaril@366
|
489 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@0
|
490 |
{
|
insilmaril@473
|
491 |
if (mainWindow->getModMode()==Main::ModModeColor)
|
insilmaril@83
|
492 |
{
|
insilmaril@83
|
493 |
pickingColor=true;
|
insilmaril@398
|
494 |
setCursor (PickColorCursor);
|
insilmaril@83
|
495 |
return;
|
insilmaril@83
|
496 |
}
|
insilmaril@473
|
497 |
if (mainWindow->getModMode()==Main::ModModeXLink)
|
insilmaril@83
|
498 |
{
|
insilmaril@90
|
499 |
BranchObj *bo_begin=NULL;
|
insilmaril@90
|
500 |
if (lmo)
|
insilmaril@90
|
501 |
bo_begin=(BranchObj*)(lmo);
|
insilmaril@90
|
502 |
else
|
insilmaril@720
|
503 |
bo_begin=model->getSelectedBranch();
|
insilmaril@90
|
504 |
if (bo_begin)
|
insilmaril@83
|
505 |
{
|
insilmaril@83
|
506 |
drawingLink=true;
|
insilmaril@90
|
507 |
linkingObj_src=bo_begin;
|
insilmaril@408
|
508 |
tmpXLink=new XLinkObj (mapScene);
|
insilmaril@95
|
509 |
tmpXLink->setBegin (bo_begin);
|
insilmaril@95
|
510 |
tmpXLink->setEnd (p);
|
insilmaril@720
|
511 |
tmpXLink->setColor(model->getMapDefXLinkColor());
|
insilmaril@720
|
512 |
tmpXLink->setWidth(model->getMapDefXLinkWidth());
|
insilmaril@95
|
513 |
tmpXLink->updateXLink();
|
insilmaril@95
|
514 |
tmpXLink->setVisibility (true);
|
insilmaril@83
|
515 |
return;
|
insilmaril@89
|
516 |
}
|
insilmaril@267
|
517 |
}
|
insilmaril@442
|
518 |
} // End of modmodes
|
insilmaril@442
|
519 |
|
insilmaril@0
|
520 |
if (lmo)
|
insilmaril@267
|
521 |
{
|
insilmaril@442
|
522 |
// Select the clicked object
|
insilmaril@720
|
523 |
model->selectInt (lmo);
|
insilmaril@442
|
524 |
|
insilmaril@0
|
525 |
// Left Button Move Branches
|
insilmaril@366
|
526 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
527 |
{
|
insilmaril@424
|
528 |
//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
|
insilmaril@424
|
529 |
//movingObj_start.setY( p.y() - selection->y() );
|
insilmaril@424
|
530 |
movingObj_start.setX( p.x() - lmo->x() );
|
insilmaril@424
|
531 |
movingObj_start.setY( p.y() - lmo->y() );
|
insilmaril@129
|
532 |
movingObj_orgPos.setX (lmo->x() );
|
insilmaril@129
|
533 |
movingObj_orgPos.setY (lmo->y() );
|
insilmaril@720
|
534 |
lmo->setRelPos();
|
insilmaril@366
|
535 |
movingObj_orgRelPos=lmo->getRelPos();
|
insilmaril@129
|
536 |
|
insilmaril@93
|
537 |
// If modMode==copy, then we want to "move" the _new_ object around
|
insilmaril@93
|
538 |
// then we need the offset from p to the _old_ selection, because of tmp
|
insilmaril@473
|
539 |
if (mainWindow->getModMode()==Main::ModModeCopy &&
|
insilmaril@366
|
540 |
e->state() & Qt::ControlModifier)
|
insilmaril@93
|
541 |
{
|
insilmaril@720
|
542 |
BranchObj *bo=model->getSelectedBranch();
|
insilmaril@645
|
543 |
if (bo)
|
insilmaril@93
|
544 |
{
|
insilmaril@93
|
545 |
copyingObj=true;
|
insilmaril@720
|
546 |
bo->addBranch ((BranchObj*)model->getSelection());
|
insilmaril@720
|
547 |
model->unselect();
|
insilmaril@720
|
548 |
model->select(bo->getLastBranch());
|
insilmaril@645
|
549 |
model->reposition();
|
insilmaril@93
|
550 |
}
|
insilmaril@421
|
551 |
}
|
insilmaril@421
|
552 |
|
insilmaril@720
|
553 |
movingObj=model->getSelection();
|
insilmaril@0
|
554 |
} else
|
insilmaril@0
|
555 |
// Middle Button Toggle Scroll
|
insilmaril@0
|
556 |
// (On Mac OS X this won't work, but we still have
|
insilmaril@0
|
557 |
// a button in the toolbar)
|
insilmaril@366
|
558 |
if (e->button() == Qt::MidButton )
|
insilmaril@720
|
559 |
model->toggleScroll();
|
insilmaril@720
|
560 |
model->updateActions();
|
insilmaril@720
|
561 |
// FIXME needed? xelection.update();
|
insilmaril@0
|
562 |
} else
|
insilmaril@408
|
563 |
{ // No MapObj found, we are on the scene itself
|
insilmaril@408
|
564 |
// Left Button move Pos of sceneView
|
insilmaril@366
|
565 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
566 |
{
|
insilmaril@0
|
567 |
movingObj=NULL; // move Content not Obj
|
insilmaril@0
|
568 |
movingObj_start=e->globalPos();
|
insilmaril@408
|
569 |
movingCont_start=QPointF (
|
insilmaril@408
|
570 |
horizontalScrollBar()->value(),
|
insilmaril@408
|
571 |
verticalScrollBar()->value());
|
insilmaril@408
|
572 |
movingVec=QPointF(0,0);
|
insilmaril@398
|
573 |
setCursor(HandOpenCursor);
|
insilmaril@0
|
574 |
}
|
insilmaril@0
|
575 |
}
|
insilmaril@0
|
576 |
}
|
insilmaril@0
|
577 |
|
insilmaril@408
|
578 |
void MapEditor::mouseMoveEvent(QMouseEvent* e)
|
insilmaril@0
|
579 |
{
|
insilmaril@408
|
580 |
QPointF p = mapToScene(e->pos());
|
insilmaril@720
|
581 |
LinkableMapObj *lmosel=model->getSelection();
|
insilmaril@83
|
582 |
|
insilmaril@0
|
583 |
// Move the selected MapObj
|
insilmaril@424
|
584 |
if ( lmosel && movingObj)
|
insilmaril@0
|
585 |
{
|
insilmaril@421
|
586 |
// reset cursor if we are moving and don't copy
|
insilmaril@473
|
587 |
if (mainWindow->getModMode()!=Main::ModModeCopy)
|
insilmaril@421
|
588 |
setCursor (Qt::ArrowCursor);
|
insilmaril@421
|
589 |
|
insilmaril@408
|
590 |
// To avoid jumping of the sceneView, only
|
insilmaril@164
|
591 |
// ensureSelectionVisible, if not tmp linked
|
insilmaril@424
|
592 |
if (!lmosel->hasParObjTmp())
|
insilmaril@720
|
593 |
model->ensureSelectionVisible ();
|
insilmaril@0
|
594 |
|
insilmaril@83
|
595 |
// Now move the selection, but add relative position
|
insilmaril@83
|
596 |
// (movingObj_start) where selection was chosen with
|
insilmaril@83
|
597 |
// mousepointer. (This avoids flickering resp. jumping
|
insilmaril@0
|
598 |
// of selection back to absPos)
|
insilmaril@0
|
599 |
|
insilmaril@0
|
600 |
// Check if we could link
|
insilmaril@645
|
601 |
LinkableMapObj* lmo=model->findMapObj(p, lmosel);
|
insilmaril@0
|
602 |
|
insilmaril@0
|
603 |
|
insilmaril@720
|
604 |
FloatObj *fio=model->getSelectedFloatImage();
|
insilmaril@424
|
605 |
if (fio)
|
insilmaril@0
|
606 |
{
|
insilmaril@424
|
607 |
fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@424
|
608 |
fio->setRelPos();
|
insilmaril@424
|
609 |
fio->updateLink(); //no need for reposition, if we update link here
|
insilmaril@720
|
610 |
model->updateSelection();
|
insilmaril@0
|
611 |
|
insilmaril@0
|
612 |
// Relink float to new mapcenter or branch, if shift is pressed
|
insilmaril@0
|
613 |
// Only relink, if selection really has a new parent
|
insilmaril@388
|
614 |
if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
|
insilmaril@0
|
615 |
( (typeid(*lmo)==typeid(BranchObj)) ||
|
insilmaril@0
|
616 |
(typeid(*lmo)==typeid(MapCenterObj)) ) &&
|
insilmaril@424
|
617 |
( lmo != fio->getParObj())
|
insilmaril@0
|
618 |
)
|
insilmaril@0
|
619 |
{
|
insilmaril@424
|
620 |
if (typeid(*fio) == typeid(FloatImageObj) &&
|
insilmaril@420
|
621 |
( (typeid(*lmo)==typeid(BranchObj) ||
|
insilmaril@420
|
622 |
typeid(*lmo)==typeid(MapCenterObj)) ))
|
insilmaril@0
|
623 |
{
|
insilmaril@420
|
624 |
|
insilmaril@420
|
625 |
// Also save the move which was done so far
|
insilmaril@420
|
626 |
QString pold=qpointfToString(movingObj_orgRelPos);
|
insilmaril@420
|
627 |
QString pnow=qpointfToString(fio->getRelPos());
|
insilmaril@720
|
628 |
model->saveState(
|
insilmaril@424
|
629 |
fio,
|
insilmaril@420
|
630 |
"moveRel "+pold,
|
insilmaril@424
|
631 |
fio,
|
insilmaril@420
|
632 |
"moveRel "+pnow,
|
insilmaril@625
|
633 |
QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
|
insilmaril@420
|
634 |
fio->getParObj()->requestReposition();
|
insilmaril@645
|
635 |
model->reposition();
|
insilmaril@420
|
636 |
|
insilmaril@720
|
637 |
model->linkFloatImageTo (model->getSelectString(lmo));
|
insilmaril@442
|
638 |
//movingObj=lmosel;
|
insilmaril@442
|
639 |
//movingObj_orgRelPos=lmosel->getRelPos();
|
insilmaril@420
|
640 |
|
insilmaril@645
|
641 |
model->reposition();
|
insilmaril@0
|
642 |
}
|
insilmaril@0
|
643 |
}
|
insilmaril@388
|
644 |
} else
|
insilmaril@388
|
645 |
{ // selection != a FloatObj
|
insilmaril@0
|
646 |
if (lmosel->getDepth()==0)
|
insilmaril@0
|
647 |
{
|
insilmaril@388
|
648 |
// Move MapCenter
|
insilmaril@388
|
649 |
if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
|
insilmaril@645
|
650 |
((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@0
|
651 |
else
|
insilmaril@645
|
652 |
lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@645
|
653 |
model->updateRelPositions();
|
insilmaril@0
|
654 |
} else
|
insilmaril@0
|
655 |
{
|
insilmaril@0
|
656 |
if (lmosel->getDepth()==1)
|
insilmaril@0
|
657 |
{
|
insilmaril@388
|
658 |
// Move mainbranch
|
insilmaril@0
|
659 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@388
|
660 |
lmosel->setRelPos();
|
insilmaril@0
|
661 |
} else
|
insilmaril@0
|
662 |
{
|
insilmaril@388
|
663 |
// Move ordinary branch
|
insilmaril@473
|
664 |
if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
|
insilmaril@0
|
665 |
// Add width of bbox here, otherwise alignRelTo will cause jumping around
|
insilmaril@720
|
666 |
lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
|
insilmaril@175
|
667 |
p.y()-movingObj_start.y() +lmosel->getTopPad() );
|
insilmaril@0
|
668 |
else
|
insilmaril@175
|
669 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
|
insilmaril@720
|
670 |
lmosel->setRelPos();
|
insilmaril@0
|
671 |
}
|
insilmaril@0
|
672 |
|
insilmaril@431
|
673 |
// Maybe we can relink temporary?
|
insilmaril@720
|
674 |
if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
|
insilmaril@431
|
675 |
(typeid(*lmo)==typeid(BranchObj) ||
|
insilmaril@431
|
676 |
typeid(*lmo)==typeid(MapCenterObj)) )
|
insilmaril@431
|
677 |
|
insilmaril@0
|
678 |
{
|
insilmaril@388
|
679 |
if (e->modifiers()==Qt::ControlModifier)
|
insilmaril@0
|
680 |
{
|
insilmaril@0
|
681 |
// Special case: CTRL to link below lmo
|
insilmaril@0
|
682 |
lmosel->setParObjTmp (lmo,p,+1);
|
insilmaril@0
|
683 |
}
|
insilmaril@388
|
684 |
else if (e->modifiers()==Qt::ShiftModifier)
|
insilmaril@0
|
685 |
lmosel->setParObjTmp (lmo,p,-1);
|
insilmaril@0
|
686 |
else
|
insilmaril@0
|
687 |
lmosel->setParObjTmp (lmo,p,0);
|
insilmaril@0
|
688 |
} else
|
insilmaril@0
|
689 |
{
|
insilmaril@93
|
690 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
691 |
}
|
insilmaril@428
|
692 |
// reposition subbranch
|
insilmaril@428
|
693 |
lmosel->reposition();
|
insilmaril@0
|
694 |
} // depth>0
|
insilmaril@0
|
695 |
|
insilmaril@720
|
696 |
model->updateSelection();// FIXME needed?
|
insilmaril@0
|
697 |
} // no FloatImageObj
|
insilmaril@0
|
698 |
|
insilmaril@408
|
699 |
scene()->update();
|
insilmaril@0
|
700 |
return;
|
insilmaril@0
|
701 |
} // selection && moving_obj
|
insilmaril@0
|
702 |
|
insilmaril@83
|
703 |
// Draw a link from one branch to another
|
insilmaril@83
|
704 |
if (drawingLink)
|
insilmaril@83
|
705 |
{
|
insilmaril@95
|
706 |
tmpXLink->setEnd (p);
|
insilmaril@95
|
707 |
tmpXLink->updateXLink();
|
insilmaril@83
|
708 |
}
|
insilmaril@83
|
709 |
|
insilmaril@408
|
710 |
// Move sceneView
|
insilmaril@411
|
711 |
if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
|
insilmaril@0
|
712 |
{
|
insilmaril@408
|
713 |
QPointF p=e->globalPos();
|
insilmaril@0
|
714 |
movingVec.setX(-p.x() + movingObj_start.x() );
|
insilmaril@0
|
715 |
movingVec.setY(-p.y() + movingObj_start.y() );
|
insilmaril@408
|
716 |
horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
|
insilmaril@408
|
717 |
verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
|
insilmaril@0
|
718 |
}
|
insilmaril@0
|
719 |
}
|
insilmaril@0
|
720 |
|
insilmaril@0
|
721 |
|
insilmaril@408
|
722 |
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
|
insilmaril@0
|
723 |
{
|
insilmaril@408
|
724 |
QPointF p = mapToScene(e->pos());
|
insilmaril@0
|
725 |
LinkableMapObj *dst;
|
insilmaril@720
|
726 |
LinkableMapObj *lmosel=model->getSelection();
|
insilmaril@0
|
727 |
// Have we been picking color?
|
insilmaril@0
|
728 |
if (pickingColor)
|
insilmaril@0
|
729 |
{
|
insilmaril@0
|
730 |
pickingColor=false;
|
insilmaril@366
|
731 |
setCursor (Qt::ArrowCursor);
|
insilmaril@0
|
732 |
// Check if we are over another branch
|
insilmaril@645
|
733 |
dst=model->findMapObj(p, NULL);
|
insilmaril@424
|
734 |
if (dst && lmosel)
|
insilmaril@0
|
735 |
{
|
insilmaril@366
|
736 |
if (e->state() & Qt::ShiftModifier)
|
insilmaril@720
|
737 |
model->colorBranch (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
738 |
else
|
insilmaril@720
|
739 |
model->colorSubtree (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
740 |
}
|
insilmaril@0
|
741 |
return;
|
insilmaril@0
|
742 |
}
|
insilmaril@83
|
743 |
|
insilmaril@83
|
744 |
// Have we been drawing a link?
|
insilmaril@491
|
745 |
if (drawingLink)
|
insilmaril@83
|
746 |
{
|
insilmaril@83
|
747 |
drawingLink=false;
|
insilmaril@83
|
748 |
// Check if we are over another branch
|
insilmaril@645
|
749 |
dst=model->findMapObj(p, NULL);
|
insilmaril@424
|
750 |
if (dst && lmosel)
|
insilmaril@83
|
751 |
{
|
insilmaril@95
|
752 |
tmpXLink->setEnd ( ((BranchObj*)(dst)) );
|
insilmaril@95
|
753 |
tmpXLink->updateXLink();
|
insilmaril@491
|
754 |
tmpXLink->activate(); //FIXME savestate missing
|
insilmaril@720
|
755 |
//model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
|
insilmaril@83
|
756 |
} else
|
insilmaril@83
|
757 |
{
|
insilmaril@95
|
758 |
delete(tmpXLink);
|
insilmaril@95
|
759 |
tmpXLink=NULL;
|
insilmaril@83
|
760 |
}
|
insilmaril@83
|
761 |
return;
|
insilmaril@83
|
762 |
}
|
insilmaril@83
|
763 |
|
insilmaril@0
|
764 |
// Have we been moving something?
|
insilmaril@424
|
765 |
if ( lmosel && movingObj )
|
insilmaril@0
|
766 |
{
|
insilmaril@720
|
767 |
FloatImageObj *fo=model->getSelectedFloatImage();
|
insilmaril@424
|
768 |
if(fo)
|
insilmaril@175
|
769 |
{
|
insilmaril@388
|
770 |
// Moved FloatObj. Maybe we need to reposition
|
insilmaril@408
|
771 |
QString pold=qpointfToString(movingObj_orgRelPos);
|
insilmaril@408
|
772 |
QString pnow=qpointfToString(fo->getRelPos());
|
insilmaril@720
|
773 |
model->saveState(
|
insilmaril@424
|
774 |
fo,
|
insilmaril@366
|
775 |
"moveRel "+pold,
|
insilmaril@424
|
776 |
fo,
|
insilmaril@366
|
777 |
"moveRel "+pnow,
|
insilmaril@625
|
778 |
QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
|
insilmaril@424
|
779 |
|
insilmaril@424
|
780 |
fo->getParObj()->requestReposition();
|
insilmaril@645
|
781 |
model->reposition();
|
insilmaril@175
|
782 |
}
|
insilmaril@175
|
783 |
|
insilmaril@0
|
784 |
// Check if we are over another branch, but ignore
|
insilmaril@0
|
785 |
// any found LMOs, which are FloatObjs
|
insilmaril@645
|
786 |
dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
|
insilmaril@0
|
787 |
|
insilmaril@336
|
788 |
if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
|
insilmaril@0
|
789 |
dst=NULL;
|
insilmaril@0
|
790 |
|
insilmaril@720
|
791 |
BranchObj *bo=model->getSelectedBranch();
|
insilmaril@645
|
792 |
if (bo && bo->getDepth()==0)
|
insilmaril@497
|
793 |
{
|
insilmaril@645
|
794 |
if (movingObj_orgPos != bo->getAbsPos())
|
insilmaril@625
|
795 |
{
|
insilmaril@625
|
796 |
QString pold=qpointfToString(movingObj_orgPos);
|
insilmaril@645
|
797 |
QString pnow=qpointfToString(bo->getAbsPos());
|
insilmaril@720
|
798 |
model->saveState(
|
insilmaril@625
|
799 |
fo,
|
insilmaril@625
|
800 |
"move "+pold,
|
insilmaril@625
|
801 |
fo,
|
insilmaril@625
|
802 |
"move "+pnow,
|
insilmaril@645
|
803 |
QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
|
insilmaril@625
|
804 |
}
|
insilmaril@388
|
805 |
}
|
insilmaril@645
|
806 |
|
insilmaril@720
|
807 |
if (model->selectionType() == Selection::Branch )
|
insilmaril@388
|
808 |
{ // A branch was moved
|
insilmaril@388
|
809 |
|
insilmaril@0
|
810 |
// save the position in case we link to mapcenter
|
insilmaril@424
|
811 |
QPointF savePos=QPointF (lmosel->getAbsPos() );
|
insilmaril@0
|
812 |
|
insilmaril@0
|
813 |
// Reset the temporary drawn link to the original one
|
insilmaril@424
|
814 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
815 |
|
insilmaril@366
|
816 |
// For Redo we may need to save original selection
|
insilmaril@684
|
817 |
QString preSelStr=model->getSelectString(lmosel);
|
insilmaril@93
|
818 |
|
insilmaril@94
|
819 |
copyingObj=false;
|
insilmaril@129
|
820 |
if (dst )
|
insilmaril@93
|
821 |
{
|
insilmaril@691
|
822 |
// We have a destination, relink to that
|
insilmaril@691
|
823 |
|
insilmaril@720
|
824 |
BranchObj* bsel=model->getSelectedBranch();
|
insilmaril@366
|
825 |
BranchObj* bdst=(BranchObj*)dst;
|
insilmaril@366
|
826 |
|
insilmaril@684
|
827 |
QString preParStr=model->getSelectString (bsel->getParObj());
|
insilmaril@366
|
828 |
QString preNum=QString::number (bsel->getNum(),10);
|
insilmaril@366
|
829 |
QString preDstParStr;
|
insilmaril@366
|
830 |
|
insilmaril@366
|
831 |
if (e->state() & Qt::ShiftModifier && dst->getParObj())
|
insilmaril@366
|
832 |
{ // Link above dst
|
insilmaril@684
|
833 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@421
|
834 |
bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
|
insilmaril@366
|
835 |
} else
|
insilmaril@366
|
836 |
if (e->state() & Qt::ControlModifier && dst->getParObj())
|
insilmaril@366
|
837 |
{
|
insilmaril@366
|
838 |
// Link below dst
|
insilmaril@684
|
839 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@421
|
840 |
bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
|
insilmaril@366
|
841 |
} else
|
insilmaril@366
|
842 |
{ // Append to dst
|
insilmaril@684
|
843 |
preDstParStr=model->getSelectString(dst);
|
insilmaril@421
|
844 |
bsel->linkTo (bdst,-1);
|
insilmaril@366
|
845 |
if (dst->getDepth()==0) bsel->move (savePos);
|
insilmaril@366
|
846 |
}
|
insilmaril@684
|
847 |
QString postSelStr=model->getSelectString(lmosel);
|
insilmaril@366
|
848 |
QString postNum=QString::number (bsel->getNum(),10);
|
insilmaril@366
|
849 |
|
insilmaril@421
|
850 |
QString undoCom="linkTo (\""+
|
insilmaril@366
|
851 |
preParStr+ "\"," + preNum +"," +
|
insilmaril@366
|
852 |
QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
|
insilmaril@366
|
853 |
|
insilmaril@421
|
854 |
QString redoCom="linkTo (\""+
|
insilmaril@366
|
855 |
preDstParStr + "\"," + postNum + "," +
|
insilmaril@366
|
856 |
QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
|
insilmaril@366
|
857 |
|
insilmaril@720
|
858 |
model->saveState (
|
insilmaril@366
|
859 |
postSelStr,undoCom,
|
insilmaril@366
|
860 |
preSelStr, redoCom,
|
insilmaril@366
|
861 |
QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
|
insilmaril@691
|
862 |
|
insilmaril@691
|
863 |
model->reposition(); // not necessary if we undo temporary move below
|
insilmaril@163
|
864 |
} else
|
insilmaril@691
|
865 |
{
|
insilmaril@691
|
866 |
// No destination, undo temporary move
|
insilmaril@691
|
867 |
|
insilmaril@424
|
868 |
if (lmosel->getDepth()==1)
|
insilmaril@366
|
869 |
{
|
insilmaril@366
|
870 |
// The select string might be different _after_ moving around.
|
insilmaril@366
|
871 |
// Therefor reposition and then use string of old selection, too
|
insilmaril@645
|
872 |
model->reposition();
|
insilmaril@366
|
873 |
|
insilmaril@625
|
874 |
QPointF rp(lmosel->getRelPos());
|
insilmaril@625
|
875 |
if (rp != movingObj_orgRelPos)
|
insilmaril@625
|
876 |
{
|
insilmaril@625
|
877 |
QString ps=qpointfToString(rp);
|
insilmaril@720
|
878 |
model->saveState(
|
insilmaril@684
|
879 |
model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
|
insilmaril@625
|
880 |
preSelStr, "moveRel "+ps,
|
insilmaril@625
|
881 |
QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
|
insilmaril@625
|
882 |
}
|
insilmaril@366
|
883 |
}
|
insilmaril@691
|
884 |
|
insilmaril@691
|
885 |
// Draw the original link, before selection was moved around
|
insilmaril@691
|
886 |
if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
|
insilmaril@691
|
887 |
{
|
insilmaril@720
|
888 |
lmosel->setRelPos(); // calc relPos first for starting point
|
insilmaril@720
|
889 |
QPointF dst=bo->getParObj()->getChildPos();
|
insilmaril@720
|
890 |
// if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
|
insilmaril@720
|
891 |
|
insilmaril@691
|
892 |
model->startAnimation(
|
insilmaril@691
|
893 |
lmosel->getRelPos(),
|
insilmaril@720
|
894 |
movingObj_orgRelPos
|
insilmaril@720
|
895 |
// QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
|
insilmaril@691
|
896 |
);
|
insilmaril@691
|
897 |
} else
|
insilmaril@691
|
898 |
model->reposition();
|
insilmaril@691
|
899 |
}
|
insilmaril@0
|
900 |
}
|
insilmaril@720
|
901 |
model->updateSelection();
|
insilmaril@408
|
902 |
// Finally resize scene, if needed
|
insilmaril@408
|
903 |
scene()->update();
|
insilmaril@0
|
904 |
movingObj=NULL;
|
insilmaril@366
|
905 |
|
insilmaril@366
|
906 |
// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
|
insilmaril@720
|
907 |
model->updateActions();
|
insilmaril@0
|
908 |
} else
|
insilmaril@83
|
909 |
// maybe we moved View: set old cursor
|
insilmaril@366
|
910 |
setCursor (Qt::ArrowCursor);
|
insilmaril@83
|
911 |
|
insilmaril@0
|
912 |
}
|
insilmaril@0
|
913 |
|
insilmaril@408
|
914 |
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
|
insilmaril@0
|
915 |
{
|
insilmaril@720
|
916 |
if (model->isSelectionBlocked() )
|
insilmaril@491
|
917 |
{
|
insilmaril@491
|
918 |
e->ignore();
|
insilmaril@491
|
919 |
return;
|
insilmaril@491
|
920 |
}
|
insilmaril@491
|
921 |
|
insilmaril@366
|
922 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
923 |
{
|
insilmaril@408
|
924 |
QPointF p = mapToScene(e->pos());
|
insilmaril@645
|
925 |
LinkableMapObj *lmo=model->findMapObj(p, NULL);
|
insilmaril@0
|
926 |
if (lmo) { // MapObj was found
|
insilmaril@0
|
927 |
// First select the MapObj than edit heading
|
insilmaril@720
|
928 |
model->select (lmo);
|
insilmaril@720
|
929 |
editHeading();
|
insilmaril@0
|
930 |
}
|
insilmaril@0
|
931 |
}
|
insilmaril@0
|
932 |
}
|
insilmaril@0
|
933 |
|
insilmaril@0
|
934 |
void MapEditor::resizeEvent (QResizeEvent* e)
|
insilmaril@0
|
935 |
{
|
insilmaril@408
|
936 |
QGraphicsView::resizeEvent( e );
|
insilmaril@0
|
937 |
}
|
insilmaril@0
|
938 |
|
insilmaril@412
|
939 |
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
|
insilmaril@119
|
940 |
{
|
insilmaril@417
|
941 |
//for (unsigned int i=0;event->format(i);i++) // Debug mime type
|
insilmaril@417
|
942 |
// cerr << event->format(i) << endl;
|
insilmaril@417
|
943 |
|
insilmaril@417
|
944 |
if (event->mimeData()->hasImage())
|
insilmaril@417
|
945 |
event->acceptProposedAction();
|
insilmaril@417
|
946 |
else
|
insilmaril@417
|
947 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
948 |
event->acceptProposedAction();
|
insilmaril@417
|
949 |
}
|
insilmaril@417
|
950 |
|
insilmaril@531
|
951 |
void MapEditor::dragMoveEvent(QDragMoveEvent *)
|
insilmaril@417
|
952 |
{
|
insilmaril@417
|
953 |
}
|
insilmaril@417
|
954 |
|
insilmaril@417
|
955 |
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
|
insilmaril@417
|
956 |
{
|
insilmaril@417
|
957 |
event->accept();
|
insilmaril@119
|
958 |
}
|
insilmaril@129
|
959 |
|
insilmaril@412
|
960 |
void MapEditor::dropEvent(QDropEvent *event)
|
insilmaril@129
|
961 |
{
|
insilmaril@720
|
962 |
BranchObj *sel=model->getSelectedBranch();
|
insilmaril@424
|
963 |
if (sel)
|
insilmaril@128
|
964 |
{
|
insilmaril@505
|
965 |
if (debug)
|
insilmaril@505
|
966 |
foreach (QString format,event->mimeData()->formats())
|
insilmaril@658
|
967 |
cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
|
insilmaril@497
|
968 |
|
insilmaril@497
|
969 |
|
insilmaril@417
|
970 |
QList <QUrl> uris;
|
insilmaril@417
|
971 |
if (event->mimeData()->hasImage())
|
insilmaril@128
|
972 |
{
|
insilmaril@417
|
973 |
QVariant imageData = event->mimeData()->imageData();
|
insilmaril@720
|
974 |
model->addFloatImage (qvariant_cast<QPixmap>(imageData));
|
insilmaril@417
|
975 |
} else
|
insilmaril@417
|
976 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
977 |
uris=event->mimeData()->urls();
|
insilmaril@417
|
978 |
|
insilmaril@417
|
979 |
if (uris.count()>0)
|
insilmaril@128
|
980 |
{
|
insilmaril@417
|
981 |
QStringList files;
|
insilmaril@417
|
982 |
QString s;
|
insilmaril@417
|
983 |
QString heading;
|
insilmaril@417
|
984 |
BranchObj *bo;
|
insilmaril@428
|
985 |
for (int i=0; i<uris.count();i++)
|
insilmaril@408
|
986 |
{
|
insilmaril@428
|
987 |
// Workaround to avoid adding empty branches
|
insilmaril@428
|
988 |
if (!uris.at(i).toString().isEmpty())
|
insilmaril@417
|
989 |
{
|
insilmaril@428
|
990 |
bo=sel->addBranch();
|
insilmaril@428
|
991 |
if (bo)
|
insilmaril@417
|
992 |
{
|
insilmaril@428
|
993 |
s=uris.at(i).toLocalFile();
|
insilmaril@428
|
994 |
if (!s.isEmpty())
|
insilmaril@428
|
995 |
{
|
insilmaril@625
|
996 |
QString file = QDir::fromNativeSeparators(s);
|
insilmaril@428
|
997 |
heading = QFileInfo(file).baseName();
|
insilmaril@428
|
998 |
files.append(file);
|
insilmaril@428
|
999 |
if (file.endsWith(".vym", false))
|
insilmaril@428
|
1000 |
bo->setVymLink(file);
|
insilmaril@428
|
1001 |
else
|
insilmaril@428
|
1002 |
bo->setURL(uris.at(i).toString());
|
insilmaril@428
|
1003 |
} else
|
insilmaril@428
|
1004 |
{
|
insilmaril@428
|
1005 |
bo->setURL(uris.at(i).toString());
|
insilmaril@428
|
1006 |
}
|
insilmaril@428
|
1007 |
|
insilmaril@428
|
1008 |
if (!heading.isEmpty())
|
insilmaril@428
|
1009 |
bo->setHeading(heading);
|
insilmaril@428
|
1010 |
else
|
insilmaril@428
|
1011 |
bo->setHeading(uris.at(i).toString());
|
insilmaril@428
|
1012 |
}
|
insilmaril@417
|
1013 |
}
|
insilmaril@417
|
1014 |
}
|
insilmaril@645
|
1015 |
model->reposition();
|
insilmaril@417
|
1016 |
}
|
insilmaril@417
|
1017 |
}
|
insilmaril@417
|
1018 |
event->acceptProposedAction();
|
insilmaril@417
|
1019 |
}
|
insilmaril@417
|
1020 |
|
insilmaril@528
|
1021 |
|
insilmaril@412
|
1022 |
|
insilmaril@412
|
1023 |
bool isUnicode16(const QByteArray &d)
|
insilmaril@412
|
1024 |
{
|
insilmaril@412
|
1025 |
// TODO: make more precise check for unicode 16.
|
insilmaril@412
|
1026 |
// Guess unicode16 if any of second bytes are zero
|
insilmaril@412
|
1027 |
unsigned int length = max(0,d.size()-2)/2;
|
insilmaril@412
|
1028 |
for (unsigned int i = 0; i<length ; i++)
|
insilmaril@412
|
1029 |
if (d.at(i*2+1)==0) return true;
|
insilmaril@412
|
1030 |
return false;
|
insilmaril@412
|
1031 |
}
|
insilmaril@412
|
1032 |
|
insilmaril@119
|
1033 |
|
insilmaril@720
|
1034 |
// FIXME the following are not needed...
|
insilmaril@720
|
1035 |
QString MapEditor::getName(const LinkableMapObj*) {return QString();}
|
insilmaril@412
|
1036 |
|