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