insilmaril@0
|
1 |
#include "mapeditor.h"
|
insilmaril@0
|
2 |
|
insilmaril@374
|
3 |
#include <q3filedialog.h>
|
insilmaril@0
|
4 |
|
insilmaril@0
|
5 |
#include <iostream>
|
insilmaril@95
|
6 |
#include <cstdlib>
|
insilmaril@0
|
7 |
#include <typeinfo>
|
insilmaril@0
|
8 |
|
insilmaril@432
|
9 |
#include "parser.h"
|
insilmaril@175
|
10 |
#include "editxlinkdialog.h"
|
insilmaril@175
|
11 |
#include "exports.h"
|
insilmaril@517
|
12 |
#include "exportxhtmldialog.h"
|
insilmaril@175
|
13 |
#include "extrainfodialog.h"
|
insilmaril@236
|
14 |
#include "file.h"
|
insilmaril@175
|
15 |
#include "linkablemapobj.h"
|
insilmaril@175
|
16 |
#include "mainwindow.h"
|
insilmaril@175
|
17 |
#include "misc.h"
|
insilmaril@175
|
18 |
#include "texteditor.h"
|
insilmaril@314
|
19 |
#include "warningdialog.h"
|
insilmaril@571
|
20 |
#include "xml-freemind.h"
|
insilmaril@571
|
21 |
#include "xml-vym.h"
|
insilmaril@0
|
22 |
|
insilmaril@0
|
23 |
|
insilmaril@0
|
24 |
extern TextEditor *textEditor;
|
insilmaril@0
|
25 |
extern int statusbarTime;
|
insilmaril@0
|
26 |
extern Main *mainWindow;
|
insilmaril@164
|
27 |
extern QString tmpVymDir;
|
insilmaril@166
|
28 |
extern QString clipboardDir;
|
insilmaril@491
|
29 |
extern QString clipboardFile;
|
insilmaril@166
|
30 |
extern bool clipboardEmpty;
|
insilmaril@473
|
31 |
extern bool debug;
|
insilmaril@0
|
32 |
extern FlagRowObj *standardFlagsDefault;
|
insilmaril@0
|
33 |
|
insilmaril@366
|
34 |
extern QMenu* branchContextMenu;
|
insilmaril@366
|
35 |
extern QMenu* branchAddContextMenu;
|
insilmaril@366
|
36 |
extern QMenu* branchRemoveContextMenu;
|
insilmaril@366
|
37 |
extern QMenu* branchLinksContextMenu;
|
insilmaril@366
|
38 |
extern QMenu* branchXLinksContextMenuEdit;
|
insilmaril@366
|
39 |
extern QMenu* branchXLinksContextMenuFollow;
|
insilmaril@366
|
40 |
extern QMenu* floatimageContextMenu;
|
insilmaril@366
|
41 |
extern QMenu* canvasContextMenu;
|
insilmaril@366
|
42 |
|
insilmaril@0
|
43 |
|
insilmaril@0
|
44 |
extern Settings settings;
|
insilmaril@366
|
45 |
extern ImageIO imageIO;
|
insilmaril@0
|
46 |
|
insilmaril@404
|
47 |
extern QString vymName;
|
insilmaril@404
|
48 |
extern QString vymVersion;
|
insilmaril@404
|
49 |
|
insilmaril@269
|
50 |
extern QString iconPath;
|
insilmaril@301
|
51 |
extern QDir vymBaseDir;
|
insilmaril@366
|
52 |
extern QDir lastImageDir;
|
insilmaril@421
|
53 |
extern QDir lastFileDir;
|
insilmaril@269
|
54 |
|
insilmaril@164
|
55 |
int MapEditor::mapNum=0; // make instance
|
insilmaril@0
|
56 |
|
insilmaril@0
|
57 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@0
|
58 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@408
|
59 |
MapEditor::MapEditor( QWidget* parent) :
|
insilmaril@473
|
60 |
QGraphicsView(parent)
|
insilmaril@0
|
61 |
{
|
insilmaril@0
|
62 |
//cout << "Constructor ME "<<this<<endl;
|
insilmaril@164
|
63 |
mapNum++;
|
insilmaril@0
|
64 |
|
insilmaril@119
|
65 |
|
insilmaril@408
|
66 |
mapScene= new QGraphicsScene(parent);
|
insilmaril@408
|
67 |
//mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
|
insilmaril@408
|
68 |
mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
|
insilmaril@408
|
69 |
|
insilmaril@645
|
70 |
model=new VymModel();
|
insilmaril@645
|
71 |
model->setScene (mapScene);
|
insilmaril@645
|
72 |
model->setMapEditor (this);
|
insilmaril@408
|
73 |
|
insilmaril@408
|
74 |
setScene (mapScene);
|
insilmaril@0
|
75 |
|
insilmaril@0
|
76 |
printer=NULL;
|
insilmaril@0
|
77 |
|
insilmaril@97
|
78 |
defLinkColor=QColor (0,0,255);
|
insilmaril@97
|
79 |
defXLinkColor=QColor (180,180,180);
|
insilmaril@473
|
80 |
linkcolorhint=LinkableMapObj::DefaultColor;
|
insilmaril@473
|
81 |
linkstyle=LinkableMapObj::PolyParabel;
|
insilmaril@0
|
82 |
|
insilmaril@366
|
83 |
// Create bitmap cursors, platform dependant
|
insilmaril@404
|
84 |
HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
|
insilmaril@404
|
85 |
PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
|
insilmaril@404
|
86 |
CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
|
insilmaril@404
|
87 |
XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
|
insilmaril@398
|
88 |
|
insilmaril@398
|
89 |
setFocusPolicy (Qt::StrongFocus);
|
insilmaril@0
|
90 |
|
insilmaril@0
|
91 |
pickingColor=false;
|
insilmaril@91
|
92 |
drawingLink=false;
|
insilmaril@93
|
93 |
copyingObj=false;
|
insilmaril@0
|
94 |
|
insilmaril@0
|
95 |
editingBO=NULL;
|
insilmaril@0
|
96 |
movingObj=NULL;
|
insilmaril@0
|
97 |
|
insilmaril@645
|
98 |
xelection.setModel (model);
|
insilmaril@424
|
99 |
xelection.unselect();
|
insilmaril@366
|
100 |
|
insilmaril@102
|
101 |
defXLinkWidth=1;
|
insilmaril@102
|
102 |
defXLinkColor=QColor (230,230,230);
|
insilmaril@102
|
103 |
|
insilmaril@0
|
104 |
mapChanged=false;
|
insilmaril@0
|
105 |
mapDefault=true;
|
insilmaril@0
|
106 |
mapUnsaved=false;
|
insilmaril@0
|
107 |
|
insilmaril@0
|
108 |
zipped=true;
|
insilmaril@0
|
109 |
filePath="";
|
insilmaril@294
|
110 |
fileName=tr("unnamed");
|
insilmaril@0
|
111 |
mapName="";
|
insilmaril@0
|
112 |
|
insilmaril@398
|
113 |
stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
|
insilmaril@381
|
114 |
undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
|
insilmaril@491
|
115 |
mainWindow->updateHistory (undoSet);
|
insilmaril@163
|
116 |
|
insilmaril@0
|
117 |
// Initialize find routine
|
insilmaril@0
|
118 |
itFind=NULL;
|
insilmaril@0
|
119 |
EOFind=false;
|
insilmaril@0
|
120 |
|
insilmaril@0
|
121 |
printFrame=true;
|
insilmaril@0
|
122 |
printFooter=true;
|
insilmaril@0
|
123 |
|
insilmaril@139
|
124 |
blockReposition=false;
|
insilmaril@139
|
125 |
blockSaveState=false;
|
insilmaril@260
|
126 |
|
insilmaril@628
|
127 |
hidemode=HideNone;
|
insilmaril@260
|
128 |
|
insilmaril@377
|
129 |
// Create temporary files
|
insilmaril@377
|
130 |
makeTmpDirs();
|
insilmaril@0
|
131 |
|
insilmaril@502
|
132 |
curStep=0;
|
insilmaril@502
|
133 |
redosAvail=0;
|
insilmaril@502
|
134 |
undosAvail=0;
|
insilmaril@502
|
135 |
|
insilmaril@417
|
136 |
setAcceptDrops (true);
|
insilmaril@0
|
137 |
|
insilmaril@645
|
138 |
model->reposition();
|
insilmaril@381
|
139 |
|
insilmaril@473
|
140 |
// TODO animations
|
insilmaril@473
|
141 |
animObjList.clear();
|
insilmaril@473
|
142 |
//timerId = startTimer(100);
|
insilmaril@473
|
143 |
|
insilmaril@473
|
144 |
// autosave
|
insilmaril@473
|
145 |
autosaveTimer=new QTimer (this);
|
insilmaril@473
|
146 |
connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
|
insilmaril@531
|
147 |
|
insilmaril@676
|
148 |
fileChangedTimer=new QTimer (this);
|
insilmaril@676
|
149 |
fileChangedTimer->start(3000);
|
insilmaril@676
|
150 |
connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
|
insilmaril@676
|
151 |
|
insilmaril@531
|
152 |
// Network
|
insilmaril@531
|
153 |
netstate=Offline;
|
insilmaril@628
|
154 |
|
insilmaril@638
|
155 |
// Attributes //FIXME testing only...
|
insilmaril@638
|
156 |
QString k;
|
insilmaril@638
|
157 |
AttributeDef *ad;
|
insilmaril@628
|
158 |
attrTable= new AttributeTable();
|
insilmaril@638
|
159 |
k="A - StringList";
|
insilmaril@638
|
160 |
ad=attrTable->addKey (k,StringList);
|
insilmaril@638
|
161 |
if (ad)
|
insilmaril@638
|
162 |
{
|
insilmaril@638
|
163 |
QStringList sl;
|
insilmaril@638
|
164 |
sl <<"val 1"<<"val 2"<< "val 3";
|
insilmaril@638
|
165 |
ad->setValue (QVariant (sl));
|
insilmaril@638
|
166 |
}
|
insilmaril@638
|
167 |
//attrTable->addValue ("Key A","P 1");
|
insilmaril@638
|
168 |
//attrTable->addValue ("Key A","P 2");
|
insilmaril@638
|
169 |
//attrTable->addValue ("Key A","P 3");
|
insilmaril@638
|
170 |
//attrTable->addValue ("Key A","P 4");
|
insilmaril@638
|
171 |
k="B - FreeString";
|
insilmaril@638
|
172 |
ad=attrTable->addKey (k,FreeString);
|
insilmaril@638
|
173 |
if (ad)
|
insilmaril@638
|
174 |
{
|
insilmaril@638
|
175 |
//attrTable->addValue ("Key B","w1");
|
insilmaril@638
|
176 |
//attrTable->addValue ("Key B","w2");
|
insilmaril@638
|
177 |
}
|
insilmaril@638
|
178 |
k="C - UniqueString";
|
insilmaril@638
|
179 |
ad=attrTable->addKey (k,UniqueString);
|
insilmaril@638
|
180 |
if (ad)
|
insilmaril@638
|
181 |
{
|
insilmaril@638
|
182 |
//attrTable->addKey ("Key Prio");
|
insilmaril@638
|
183 |
//attrTable->addValue ("Key Prio","Prio 1");
|
insilmaril@638
|
184 |
//attrTable->addValue ("Key Prio","Prio 2");
|
insilmaril@638
|
185 |
}
|
insilmaril@0
|
186 |
}
|
insilmaril@0
|
187 |
|
insilmaril@0
|
188 |
MapEditor::~MapEditor()
|
insilmaril@0
|
189 |
{
|
insilmaril@0
|
190 |
//cout <<"Destructor MapEditor\n";
|
insilmaril@473
|
191 |
autosaveTimer->stop();
|
insilmaril@676
|
192 |
fileChangedTimer->stop();
|
insilmaril@625
|
193 |
|
insilmaril@625
|
194 |
// tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
|
insilmaril@625
|
195 |
|
insilmaril@625
|
196 |
//removeDir(QDir(tmpMapDir));
|
insilmaril@645
|
197 |
delete (model);
|
insilmaril@0
|
198 |
}
|
insilmaril@0
|
199 |
|
insilmaril@645
|
200 |
VymModel* MapEditor::getModel()
|
insilmaril@0
|
201 |
{
|
insilmaril@645
|
202 |
return model;
|
insilmaril@0
|
203 |
}
|
insilmaril@0
|
204 |
|
insilmaril@408
|
205 |
QGraphicsScene * MapEditor::getScene()
|
insilmaril@0
|
206 |
{
|
insilmaril@408
|
207 |
return mapScene;
|
insilmaril@0
|
208 |
}
|
insilmaril@0
|
209 |
|
insilmaril@491
|
210 |
MapEditor::State MapEditor::getState()
|
insilmaril@491
|
211 |
{
|
insilmaril@491
|
212 |
return state;
|
insilmaril@491
|
213 |
}
|
insilmaril@491
|
214 |
|
insilmaril@491
|
215 |
void MapEditor::setStateEditHeading(bool s)
|
insilmaril@491
|
216 |
{
|
insilmaril@491
|
217 |
if (s)
|
insilmaril@491
|
218 |
{
|
insilmaril@491
|
219 |
if (state==Idle) state=EditHeading;
|
insilmaril@491
|
220 |
}
|
insilmaril@491
|
221 |
else
|
insilmaril@491
|
222 |
state=Idle;
|
insilmaril@491
|
223 |
}
|
insilmaril@491
|
224 |
|
insilmaril@139
|
225 |
bool MapEditor::isRepositionBlocked()
|
insilmaril@0
|
226 |
{
|
insilmaril@139
|
227 |
return blockReposition;
|
insilmaril@0
|
228 |
}
|
insilmaril@0
|
229 |
|
insilmaril@473
|
230 |
void MapEditor::setSaveStateBlocked(bool b)
|
insilmaril@473
|
231 |
{
|
insilmaril@473
|
232 |
blockSaveState=b;
|
insilmaril@473
|
233 |
}
|
insilmaril@473
|
234 |
|
insilmaril@491
|
235 |
bool MapEditor::isSelectBlocked()
|
insilmaril@491
|
236 |
{
|
insilmaril@491
|
237 |
if (state==EditHeading)
|
insilmaril@491
|
238 |
return true;
|
insilmaril@491
|
239 |
else
|
insilmaril@491
|
240 |
return false;
|
insilmaril@491
|
241 |
}
|
insilmaril@491
|
242 |
|
insilmaril@420
|
243 |
QString MapEditor::getName (const LinkableMapObj *lmo)
|
insilmaril@294
|
244 |
{
|
insilmaril@314
|
245 |
QString s;
|
insilmaril@314
|
246 |
if (!lmo) return QString("Error: NULL has no name!");
|
insilmaril@294
|
247 |
|
insilmaril@294
|
248 |
if ((typeid(*lmo) == typeid(BranchObj) ||
|
insilmaril@294
|
249 |
typeid(*lmo) == typeid(MapCenterObj)))
|
insilmaril@314
|
250 |
{
|
insilmaril@314
|
251 |
|
insilmaril@314
|
252 |
s=(((BranchObj*)lmo)->getHeading());
|
insilmaril@314
|
253 |
if (s=="") s="unnamed";
|
insilmaril@377
|
254 |
return QString("branch (%1)").arg(s);
|
insilmaril@314
|
255 |
}
|
insilmaril@294
|
256 |
if ((typeid(*lmo) == typeid(FloatImageObj) ))
|
insilmaril@377
|
257 |
return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
|
insilmaril@294
|
258 |
return QString("Unknown type has no name!");
|
insilmaril@294
|
259 |
}
|
insilmaril@294
|
260 |
|
insilmaril@0
|
261 |
void MapEditor::makeTmpDirs()
|
insilmaril@0
|
262 |
{
|
insilmaril@0
|
263 |
// Create unique temporary directories
|
insilmaril@625
|
264 |
tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
|
insilmaril@625
|
265 |
histPath = tmpMapDir+"/history";
|
insilmaril@164
|
266 |
QDir d;
|
insilmaril@377
|
267 |
d.mkdir (tmpMapDir);
|
insilmaril@0
|
268 |
}
|
insilmaril@0
|
269 |
|
insilmaril@408
|
270 |
QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
|
insilmaril@0
|
271 |
{
|
insilmaril@163
|
272 |
// tmpdir temporary directory to which data will be written
|
insilmaril@0
|
273 |
// prefix mapname, which will be appended to images etc.
|
insilmaril@0
|
274 |
// writeflags Only write flags for "real" save of map, not undo
|
insilmaril@408
|
275 |
// offset offset of bbox of whole map in scene.
|
insilmaril@0
|
276 |
// Needed for XML export
|
insilmaril@0
|
277 |
|
insilmaril@0
|
278 |
// Save Header
|
insilmaril@0
|
279 |
QString ls;
|
insilmaril@0
|
280 |
switch (linkstyle)
|
insilmaril@0
|
281 |
{
|
insilmaril@473
|
282 |
case LinkableMapObj::Line:
|
insilmaril@0
|
283 |
ls="StyleLine";
|
insilmaril@0
|
284 |
break;
|
insilmaril@473
|
285 |
case LinkableMapObj::Parabel:
|
insilmaril@0
|
286 |
ls="StyleParabel";
|
insilmaril@0
|
287 |
break;
|
insilmaril@473
|
288 |
case LinkableMapObj::PolyLine:
|
insilmaril@0
|
289 |
ls="StylePolyLine";
|
insilmaril@0
|
290 |
break;
|
insilmaril@0
|
291 |
default:
|
insilmaril@0
|
292 |
ls="StylePolyParabel";
|
insilmaril@0
|
293 |
break;
|
insilmaril@0
|
294 |
}
|
insilmaril@0
|
295 |
|
insilmaril@0
|
296 |
QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
|
insilmaril@0
|
297 |
QString colhint="";
|
insilmaril@473
|
298 |
if (linkcolorhint==LinkableMapObj::HeadingColor)
|
insilmaril@0
|
299 |
colhint=attribut("linkColorHint","HeadingColor");
|
insilmaril@0
|
300 |
|
insilmaril@404
|
301 |
QString mapAttr=attribut("version",vymVersion);
|
insilmaril@645
|
302 |
if (!saveSel)
|
insilmaril@645
|
303 |
mapAttr+= attribut("author",model->getAuthor()) +
|
insilmaril@645
|
304 |
attribut("comment",model->getComment()) +
|
insilmaril@645
|
305 |
attribut("date",model->getDate()) +
|
insilmaril@408
|
306 |
attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
|
insilmaril@442
|
307 |
attribut("selectionColor", xelection.getColor().name() ) +
|
insilmaril@0
|
308 |
attribut("linkStyle", ls ) +
|
insilmaril@97
|
309 |
attribut("linkColor", defLinkColor.name() ) +
|
insilmaril@102
|
310 |
attribut("defXLinkColor", defXLinkColor.name() ) +
|
insilmaril@102
|
311 |
attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
|
insilmaril@0
|
312 |
colhint;
|
insilmaril@0
|
313 |
s+=beginElement("vymmap",mapAttr);
|
insilmaril@0
|
314 |
incIndent();
|
insilmaril@0
|
315 |
|
insilmaril@0
|
316 |
// Find the used flags while traversing the tree
|
insilmaril@0
|
317 |
standardFlagsDefault->resetUsedCounter();
|
insilmaril@0
|
318 |
|
insilmaril@166
|
319 |
// Reset the counters before saving
|
insilmaril@406
|
320 |
// TODO constr. of FIO creates lots of objects, better do this in some other way...
|
insilmaril@408
|
321 |
FloatImageObj (mapScene).resetSaveCounter();
|
insilmaril@166
|
322 |
|
insilmaril@0
|
323 |
// Build xml recursivly
|
insilmaril@398
|
324 |
if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
|
insilmaril@366
|
325 |
// Save complete map, if saveSel not set
|
insilmaril@645
|
326 |
s+=model->saveToDir(tmpdir,prefix,writeflags,offset);
|
insilmaril@0
|
327 |
else
|
insilmaril@0
|
328 |
{
|
insilmaril@366
|
329 |
if ( typeid(*saveSel) == typeid(BranchObj) )
|
insilmaril@366
|
330 |
// Save Subtree
|
insilmaril@366
|
331 |
s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
|
insilmaril@366
|
332 |
else if ( typeid(*saveSel) == typeid(FloatImageObj) )
|
insilmaril@366
|
333 |
// Save image
|
insilmaril@377
|
334 |
s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
|
insilmaril@0
|
335 |
}
|
insilmaril@0
|
336 |
|
insilmaril@0
|
337 |
// Save local settings
|
insilmaril@616
|
338 |
s+=settings.getDataXML (destPath);
|
insilmaril@0
|
339 |
|
insilmaril@0
|
340 |
// Save selection
|
insilmaril@424
|
341 |
if (!xelection.isEmpty() && !saveSel )
|
insilmaril@424
|
342 |
s+=valueElement("select",xelection.getSelectString());
|
insilmaril@0
|
343 |
|
insilmaril@0
|
344 |
decIndent();
|
insilmaril@0
|
345 |
s+=endElement("vymmap");
|
insilmaril@0
|
346 |
|
insilmaril@0
|
347 |
if (writeflags)
|
insilmaril@0
|
348 |
standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
|
insilmaril@0
|
349 |
return s;
|
insilmaril@0
|
350 |
}
|
insilmaril@0
|
351 |
|
insilmaril@505
|
352 |
QString MapEditor::getHistoryDir()
|
insilmaril@505
|
353 |
{
|
insilmaril@625
|
354 |
QString histName(QString("history-%1").arg(curStep));
|
insilmaril@625
|
355 |
return (tmpMapDir+"/"+histName);
|
insilmaril@505
|
356 |
}
|
insilmaril@505
|
357 |
|
insilmaril@486
|
358 |
void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
|
insilmaril@486
|
359 |
{
|
insilmaril@528
|
360 |
sendData(redoCom); //FIXME testing
|
insilmaril@528
|
361 |
|
insilmaril@486
|
362 |
// Main saveState
|
insilmaril@486
|
363 |
|
insilmaril@528
|
364 |
|
insilmaril@486
|
365 |
if (blockSaveState) return;
|
insilmaril@486
|
366 |
|
insilmaril@658
|
367 |
if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
|
insilmaril@486
|
368 |
|
insilmaril@486
|
369 |
// Find out current undo directory
|
insilmaril@486
|
370 |
if (undosAvail<stepsTotal) undosAvail++;
|
insilmaril@486
|
371 |
curStep++;
|
insilmaril@486
|
372 |
if (curStep>stepsTotal) curStep=1;
|
insilmaril@486
|
373 |
|
insilmaril@486
|
374 |
QString backupXML="";
|
insilmaril@505
|
375 |
QString histDir=getHistoryDir();
|
insilmaril@625
|
376 |
QString bakMapPath=histDir+"/map.xml";
|
insilmaril@505
|
377 |
|
insilmaril@505
|
378 |
// Create histDir if not available
|
insilmaril@505
|
379 |
QDir d(histDir);
|
insilmaril@486
|
380 |
if (!d.exists())
|
insilmaril@505
|
381 |
makeSubDirs (histDir);
|
insilmaril@486
|
382 |
|
insilmaril@486
|
383 |
// Save depending on how much needs to be saved
|
insilmaril@486
|
384 |
if (saveSel)
|
insilmaril@505
|
385 |
backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
|
insilmaril@486
|
386 |
|
insilmaril@486
|
387 |
QString undoCommand="";
|
insilmaril@486
|
388 |
if (savemode==UndoCommand)
|
insilmaril@486
|
389 |
{
|
insilmaril@486
|
390 |
undoCommand=undoCom;
|
insilmaril@486
|
391 |
}
|
insilmaril@486
|
392 |
else if (savemode==PartOfMap )
|
insilmaril@486
|
393 |
{
|
insilmaril@486
|
394 |
undoCommand=undoCom;
|
insilmaril@486
|
395 |
undoCommand.replace ("PATH",bakMapPath);
|
insilmaril@486
|
396 |
}
|
insilmaril@486
|
397 |
|
insilmaril@486
|
398 |
if (!backupXML.isEmpty())
|
insilmaril@486
|
399 |
// Write XML Data to disk
|
insilmaril@625
|
400 |
saveStringToDisk (bakMapPath,backupXML);
|
insilmaril@486
|
401 |
|
insilmaril@486
|
402 |
// We would have to save all actions in a tree, to keep track of
|
insilmaril@486
|
403 |
// possible redos after a action. Possible, but we are too lazy: forget about redos.
|
insilmaril@486
|
404 |
redosAvail=0;
|
insilmaril@486
|
405 |
|
insilmaril@486
|
406 |
// Write the current state to disk
|
insilmaril@486
|
407 |
undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
|
insilmaril@486
|
408 |
undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
|
insilmaril@486
|
409 |
undoSet.setEntry ("/history/curStep",QString::number(curStep));
|
insilmaril@486
|
410 |
undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
|
insilmaril@486
|
411 |
undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
|
insilmaril@486
|
412 |
undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
|
insilmaril@486
|
413 |
undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
|
insilmaril@486
|
414 |
undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
|
insilmaril@486
|
415 |
undoSet.setEntry (QString("/history/version"),vymVersion);
|
insilmaril@486
|
416 |
undoSet.writeSettings(histPath);
|
insilmaril@486
|
417 |
|
insilmaril@486
|
418 |
if (debug)
|
insilmaril@486
|
419 |
{
|
insilmaril@486
|
420 |
// TODO remove after testing
|
insilmaril@486
|
421 |
//cout << " into="<< histPath.toStdString()<<endl;
|
insilmaril@486
|
422 |
cout << " stepsTotal="<<stepsTotal<<
|
insilmaril@486
|
423 |
", undosAvail="<<undosAvail<<
|
insilmaril@486
|
424 |
", redosAvail="<<redosAvail<<
|
insilmaril@486
|
425 |
", curStep="<<curStep<<endl;
|
insilmaril@486
|
426 |
cout << " ---------------------------"<<endl;
|
insilmaril@486
|
427 |
cout << " comment="<<comment.toStdString()<<endl;
|
insilmaril@486
|
428 |
cout << " undoCom="<<undoCommand.toStdString()<<endl;
|
insilmaril@486
|
429 |
cout << " undoSel="<<undoSelection.toStdString()<<endl;
|
insilmaril@486
|
430 |
cout << " redoCom="<<redoCom.toStdString()<<endl;
|
insilmaril@486
|
431 |
cout << " redoSel="<<redoSelection.toStdString()<<endl;
|
insilmaril@684
|
432 |
if (saveSel) cout << " saveSel="<<qPrintable (model->getSelectString(saveSel))<<endl;
|
insilmaril@486
|
433 |
cout << " ---------------------------"<<endl;
|
insilmaril@486
|
434 |
}
|
insilmaril@486
|
435 |
|
insilmaril@486
|
436 |
mainWindow->updateHistory (undoSet);
|
insilmaril@486
|
437 |
setChanged();
|
insilmaril@486
|
438 |
updateActions();
|
insilmaril@486
|
439 |
}
|
insilmaril@486
|
440 |
|
insilmaril@486
|
441 |
|
insilmaril@395
|
442 |
void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
|
insilmaril@0
|
443 |
{
|
insilmaril@366
|
444 |
// save the selected part of the map, Undo will replace part of map
|
insilmaril@366
|
445 |
QString undoSelection="";
|
insilmaril@395
|
446 |
if (undoSel)
|
insilmaril@684
|
447 |
undoSelection=model->getSelectString(undoSel);
|
insilmaril@395
|
448 |
else
|
insilmaril@395
|
449 |
qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
|
insilmaril@395
|
450 |
QString redoSelection="";
|
insilmaril@395
|
451 |
if (redoSel)
|
insilmaril@684
|
452 |
redoSelection=model->getSelectString(undoSel);
|
insilmaril@395
|
453 |
else
|
insilmaril@395
|
454 |
qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
|
insilmaril@395
|
455 |
|
insilmaril@366
|
456 |
|
insilmaril@366
|
457 |
saveState (PartOfMap,
|
insilmaril@398
|
458 |
undoSelection, "addMapReplace (\"PATH\")",
|
insilmaril@395
|
459 |
redoSelection, rc,
|
insilmaril@366
|
460 |
comment,
|
insilmaril@366
|
461 |
undoSel);
|
insilmaril@105
|
462 |
}
|
insilmaril@105
|
463 |
|
insilmaril@393
|
464 |
void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
|
insilmaril@393
|
465 |
{
|
insilmaril@394
|
466 |
if (!redoSel)
|
insilmaril@393
|
467 |
{
|
insilmaril@394
|
468 |
qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
|
insilmaril@393
|
469 |
return;
|
insilmaril@393
|
470 |
}
|
insilmaril@684
|
471 |
QString undoSelection=model->getSelectString (redoSel->getParObj());
|
insilmaril@684
|
472 |
QString redoSelection=model->getSelectString(redoSel);
|
insilmaril@398
|
473 |
if (typeid(*redoSel) == typeid(BranchObj) )
|
insilmaril@394
|
474 |
{
|
insilmaril@394
|
475 |
// save the selected branch of the map, Undo will insert part of map
|
insilmaril@394
|
476 |
saveState (PartOfMap,
|
insilmaril@394
|
477 |
undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
|
insilmaril@394
|
478 |
redoSelection, "delete ()",
|
insilmaril@394
|
479 |
comment,
|
insilmaril@394
|
480 |
redoSel);
|
insilmaril@394
|
481 |
}
|
insilmaril@393
|
482 |
}
|
insilmaril@393
|
483 |
|
insilmaril@106
|
484 |
|
insilmaril@366
|
485 |
void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
|
insilmaril@366
|
486 |
{
|
insilmaril@366
|
487 |
// "Normal" savestate: save commands, selections and comment
|
insilmaril@366
|
488 |
// so just save commands for undo and redo
|
insilmaril@366
|
489 |
// and use current selection
|
insilmaril@366
|
490 |
|
insilmaril@366
|
491 |
QString redoSelection="";
|
insilmaril@684
|
492 |
if (redoSel) redoSelection=model->getSelectString(redoSel);
|
insilmaril@366
|
493 |
QString undoSelection="";
|
insilmaril@684
|
494 |
if (undoSel) undoSelection=model->getSelectString(undoSel);
|
insilmaril@366
|
495 |
|
insilmaril@366
|
496 |
saveState (UndoCommand,
|
insilmaril@366
|
497 |
undoSelection, uc,
|
insilmaril@366
|
498 |
redoSelection, rc,
|
insilmaril@366
|
499 |
comment,
|
insilmaril@366
|
500 |
NULL);
|
insilmaril@366
|
501 |
}
|
insilmaril@366
|
502 |
|
insilmaril@366
|
503 |
void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
|
insilmaril@366
|
504 |
{
|
insilmaril@366
|
505 |
// "Normal" savestate: save commands, selections and comment
|
insilmaril@366
|
506 |
// so just save commands for undo and redo
|
insilmaril@366
|
507 |
// and use current selection
|
insilmaril@366
|
508 |
saveState (UndoCommand,
|
insilmaril@366
|
509 |
undoSel, uc,
|
insilmaril@366
|
510 |
redoSel, rc,
|
insilmaril@366
|
511 |
comment,
|
insilmaril@366
|
512 |
NULL);
|
insilmaril@366
|
513 |
}
|
insilmaril@366
|
514 |
|
insilmaril@645
|
515 |
void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
|
insilmaril@645
|
516 |
{
|
insilmaril@645
|
517 |
// "Normal" savestate applied to model (no selection needed):
|
insilmaril@645
|
518 |
// save commands and comment
|
insilmaril@645
|
519 |
saveState (UndoCommand,
|
insilmaril@645
|
520 |
NULL, uc,
|
insilmaril@645
|
521 |
NULL, rc,
|
insilmaril@645
|
522 |
comment,
|
insilmaril@645
|
523 |
NULL);
|
insilmaril@645
|
524 |
}
|
insilmaril@645
|
525 |
|
insilmaril@366
|
526 |
|
insilmaril@129
|
527 |
void MapEditor::parseAtom(const QString &atom)
|
insilmaril@106
|
528 |
{
|
insilmaril@424
|
529 |
BranchObj *selb=xelection.getBranch();
|
insilmaril@163
|
530 |
QString s,t;
|
insilmaril@537
|
531 |
double x,y;
|
insilmaril@537
|
532 |
int n;
|
insilmaril@395
|
533 |
bool b,ok;
|
insilmaril@129
|
534 |
|
insilmaril@129
|
535 |
// Split string s into command and parameters
|
insilmaril@432
|
536 |
parser.parseAtom (atom);
|
insilmaril@447
|
537 |
QString com=parser.getCommand();
|
insilmaril@129
|
538 |
|
insilmaril@106
|
539 |
// External commands
|
insilmaril@514
|
540 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@393
|
541 |
if (com=="addBranch")
|
insilmaril@366
|
542 |
{
|
insilmaril@424
|
543 |
if (xelection.isEmpty())
|
insilmaril@394
|
544 |
{
|
insilmaril@432
|
545 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
546 |
} else if (! selb )
|
insilmaril@394
|
547 |
{
|
insilmaril@432
|
548 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@394
|
549 |
} else
|
insilmaril@366
|
550 |
{
|
insilmaril@394
|
551 |
QList <int> pl;
|
insilmaril@394
|
552 |
pl << 0 <<1;
|
insilmaril@514
|
553 |
if (parser.checkParCount(pl))
|
insilmaril@394
|
554 |
{
|
insilmaril@514
|
555 |
if (parser.parCount()==0)
|
insilmaril@537
|
556 |
addNewBranch (0);
|
insilmaril@394
|
557 |
else
|
insilmaril@394
|
558 |
{
|
insilmaril@537
|
559 |
n=parser.parInt (ok,0);
|
insilmaril@537
|
560 |
if (ok ) addNewBranch (n);
|
insilmaril@394
|
561 |
}
|
insilmaril@394
|
562 |
}
|
insilmaril@394
|
563 |
}
|
insilmaril@514
|
564 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@394
|
565 |
} else if (com=="addBranchBefore")
|
insilmaril@394
|
566 |
{
|
insilmaril@424
|
567 |
if (xelection.isEmpty())
|
insilmaril@394
|
568 |
{
|
insilmaril@432
|
569 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
570 |
} else if (! selb )
|
insilmaril@394
|
571 |
{
|
insilmaril@432
|
572 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@394
|
573 |
} else
|
insilmaril@394
|
574 |
{
|
insilmaril@514
|
575 |
if (parser.parCount()==0)
|
insilmaril@394
|
576 |
{
|
insilmaril@394
|
577 |
addNewBranchBefore ();
|
insilmaril@394
|
578 |
}
|
insilmaril@394
|
579 |
}
|
insilmaril@514
|
580 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@684
|
581 |
} else if (com==QString("addMapCenter"))
|
insilmaril@684
|
582 |
{
|
insilmaril@684
|
583 |
if (parser.checkParCount(2))
|
insilmaril@684
|
584 |
{
|
insilmaril@684
|
585 |
x=parser.parDouble (ok,0);
|
insilmaril@684
|
586 |
if (ok)
|
insilmaril@684
|
587 |
{
|
insilmaril@684
|
588 |
y=parser.parDouble (ok,1);
|
insilmaril@684
|
589 |
if (ok) model->addMapCenter (QPointF(x,y));
|
insilmaril@684
|
590 |
}
|
insilmaril@684
|
591 |
}
|
insilmaril@684
|
592 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@393
|
593 |
} else if (com==QString("addMapReplace"))
|
insilmaril@393
|
594 |
{
|
insilmaril@424
|
595 |
if (xelection.isEmpty())
|
insilmaril@394
|
596 |
{
|
insilmaril@432
|
597 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
598 |
} else if (! selb )
|
insilmaril@394
|
599 |
{
|
insilmaril@432
|
600 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
601 |
} else if (parser.checkParCount(1))
|
insilmaril@393
|
602 |
{
|
insilmaril@432
|
603 |
//s=parser.parString (ok,0); // selection
|
insilmaril@432
|
604 |
t=parser.parString (ok,0); // path to map
|
insilmaril@625
|
605 |
if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
|
insilmaril@684
|
606 |
addMapReplaceInt(model->getSelectString(selb),t);
|
insilmaril@393
|
607 |
}
|
insilmaril@514
|
608 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@434
|
609 |
} else if (com==QString("addMapInsert"))
|
insilmaril@393
|
610 |
{
|
insilmaril@424
|
611 |
if (xelection.isEmpty())
|
insilmaril@393
|
612 |
{
|
insilmaril@432
|
613 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
614 |
} else if (! selb )
|
insilmaril@394
|
615 |
{
|
insilmaril@432
|
616 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@394
|
617 |
} else
|
insilmaril@394
|
618 |
{
|
insilmaril@514
|
619 |
if (parser.checkParCount(2))
|
insilmaril@394
|
620 |
{
|
insilmaril@432
|
621 |
t=parser.parString (ok,0); // path to map
|
insilmaril@537
|
622 |
n=parser.parInt(ok,1); // position
|
insilmaril@625
|
623 |
if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
|
insilmaril@537
|
624 |
addMapInsertInt(t,n);
|
insilmaril@394
|
625 |
}
|
insilmaril@393
|
626 |
}
|
insilmaril@514
|
627 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@447
|
628 |
} else if (com=="clearFlags")
|
insilmaril@447
|
629 |
{
|
insilmaril@447
|
630 |
if (xelection.isEmpty() )
|
insilmaril@447
|
631 |
{
|
insilmaril@447
|
632 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@447
|
633 |
} else if (! selb )
|
insilmaril@447
|
634 |
{
|
insilmaril@447
|
635 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
636 |
} else if (parser.checkParCount(0))
|
insilmaril@447
|
637 |
{
|
insilmaril@447
|
638 |
selb->clearStandardFlags();
|
insilmaril@447
|
639 |
selb->updateFlagsToolbar();
|
insilmaril@447
|
640 |
}
|
insilmaril@514
|
641 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@395
|
642 |
} else if (com=="colorBranch")
|
insilmaril@395
|
643 |
{
|
insilmaril@424
|
644 |
if (xelection.isEmpty())
|
insilmaril@395
|
645 |
{
|
insilmaril@432
|
646 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
647 |
} else if (! selb )
|
insilmaril@395
|
648 |
{
|
insilmaril@432
|
649 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
650 |
} else if (parser.checkParCount(1))
|
insilmaril@395
|
651 |
{
|
insilmaril@432
|
652 |
QColor c=parser.parColor (ok,0);
|
insilmaril@395
|
653 |
if (ok) colorBranch (c);
|
insilmaril@395
|
654 |
}
|
insilmaril@514
|
655 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@417
|
656 |
} else if (com=="colorSubtree")
|
insilmaril@417
|
657 |
{
|
insilmaril@424
|
658 |
if (xelection.isEmpty())
|
insilmaril@417
|
659 |
{
|
insilmaril@432
|
660 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
661 |
} else if (! selb )
|
insilmaril@417
|
662 |
{
|
insilmaril@432
|
663 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
664 |
} else if (parser.checkParCount(1))
|
insilmaril@417
|
665 |
{
|
insilmaril@432
|
666 |
QColor c=parser.parColor (ok,0);
|
insilmaril@417
|
667 |
if (ok) colorSubtree (c);
|
insilmaril@417
|
668 |
}
|
insilmaril@514
|
669 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@502
|
670 |
} else if (com=="copy")
|
insilmaril@502
|
671 |
{
|
insilmaril@502
|
672 |
if (xelection.isEmpty())
|
insilmaril@502
|
673 |
{
|
insilmaril@502
|
674 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@502
|
675 |
} else if (! selb )
|
insilmaril@502
|
676 |
{
|
insilmaril@502
|
677 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
678 |
} else if (parser.checkParCount(0))
|
insilmaril@502
|
679 |
{
|
insilmaril@502
|
680 |
//FIXME missing action for copy
|
insilmaril@502
|
681 |
}
|
insilmaril@514
|
682 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@395
|
683 |
} else if (com=="cut")
|
insilmaril@395
|
684 |
{
|
insilmaril@424
|
685 |
if (xelection.isEmpty())
|
insilmaril@395
|
686 |
{
|
insilmaril@432
|
687 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@491
|
688 |
} else if ( xelection.type()!=Selection::Branch &&
|
insilmaril@491
|
689 |
xelection.type()!=Selection::MapCenter &&
|
insilmaril@491
|
690 |
xelection.type()!=Selection::FloatImage )
|
insilmaril@395
|
691 |
{
|
insilmaril@432
|
692 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@514
|
693 |
} else if (parser.checkParCount(0))
|
insilmaril@395
|
694 |
{
|
insilmaril@395
|
695 |
cut();
|
insilmaril@395
|
696 |
}
|
insilmaril@514
|
697 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@393
|
698 |
} else if (com=="delete")
|
insilmaril@393
|
699 |
{
|
insilmaril@424
|
700 |
if (xelection.isEmpty())
|
insilmaril@394
|
701 |
{
|
insilmaril@432
|
702 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@684
|
703 |
}
|
insilmaril@684
|
704 |
/*else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
|
insilmaril@424
|
705 |
{
|
insilmaril@434
|
706 |
parser.setError (Aborted,"Type of selection is wrong.");
|
insilmaril@684
|
707 |
}
|
insilmaril@684
|
708 |
*/
|
insilmaril@684
|
709 |
else if (parser.checkParCount(0))
|
insilmaril@393
|
710 |
{
|
insilmaril@393
|
711 |
deleteSelection();
|
insilmaril@393
|
712 |
}
|
insilmaril@514
|
713 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@394
|
714 |
} else if (com=="deleteKeepChilds")
|
insilmaril@394
|
715 |
{
|
insilmaril@424
|
716 |
if (xelection.isEmpty())
|
insilmaril@394
|
717 |
{
|
insilmaril@432
|
718 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
719 |
} else if (! selb )
|
insilmaril@424
|
720 |
{
|
insilmaril@432
|
721 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
722 |
} else if (parser.checkParCount(0))
|
insilmaril@394
|
723 |
{
|
insilmaril@395
|
724 |
deleteKeepChilds();
|
insilmaril@395
|
725 |
}
|
insilmaril@514
|
726 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@395
|
727 |
} else if (com=="deleteChilds")
|
insilmaril@395
|
728 |
{
|
insilmaril@424
|
729 |
if (xelection.isEmpty())
|
insilmaril@395
|
730 |
{
|
insilmaril@432
|
731 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
732 |
} else if (! selb)
|
insilmaril@424
|
733 |
{
|
insilmaril@432
|
734 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
735 |
} else if (parser.checkParCount(0))
|
insilmaril@395
|
736 |
{
|
insilmaril@395
|
737 |
deleteChilds();
|
insilmaril@394
|
738 |
}
|
insilmaril@514
|
739 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@517
|
740 |
} else if (com=="exportASCII")
|
insilmaril@514
|
741 |
{
|
insilmaril@517
|
742 |
QString fname="";
|
insilmaril@517
|
743 |
ok=true;
|
insilmaril@613
|
744 |
if (parser.parCount()>=1)
|
insilmaril@517
|
745 |
// Hey, we even have a filename
|
insilmaril@613
|
746 |
fname=parser.parString(ok,0);
|
insilmaril@517
|
747 |
if (!ok)
|
insilmaril@514
|
748 |
{
|
insilmaril@517
|
749 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@514
|
750 |
} else
|
insilmaril@514
|
751 |
{
|
insilmaril@517
|
752 |
exportASCII (fname,false);
|
insilmaril@517
|
753 |
}
|
insilmaril@517
|
754 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@517
|
755 |
} else if (com=="exportImage")
|
insilmaril@517
|
756 |
{
|
insilmaril@517
|
757 |
QString fname="";
|
insilmaril@517
|
758 |
ok=true;
|
insilmaril@517
|
759 |
if (parser.parCount()>=2)
|
insilmaril@517
|
760 |
// Hey, we even have a filename
|
insilmaril@613
|
761 |
fname=parser.parString(ok,0);
|
insilmaril@517
|
762 |
if (!ok)
|
insilmaril@517
|
763 |
{
|
insilmaril@517
|
764 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@517
|
765 |
} else
|
insilmaril@517
|
766 |
{
|
insilmaril@517
|
767 |
QString format="PNG";
|
insilmaril@613
|
768 |
if (parser.parCount()>=2)
|
insilmaril@514
|
769 |
{
|
insilmaril@613
|
770 |
format=parser.parString(ok,1);
|
insilmaril@514
|
771 |
}
|
insilmaril@517
|
772 |
exportImage (fname,false,format);
|
insilmaril@517
|
773 |
}
|
insilmaril@517
|
774 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@517
|
775 |
} else if (com=="exportXHTML")
|
insilmaril@517
|
776 |
{
|
insilmaril@517
|
777 |
QString fname="";
|
insilmaril@517
|
778 |
ok=true;
|
insilmaril@517
|
779 |
if (parser.parCount()>=2)
|
insilmaril@517
|
780 |
// Hey, we even have a filename
|
insilmaril@517
|
781 |
fname=parser.parString(ok,1);
|
insilmaril@517
|
782 |
if (!ok)
|
insilmaril@517
|
783 |
{
|
insilmaril@517
|
784 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@517
|
785 |
} else
|
insilmaril@517
|
786 |
{
|
insilmaril@520
|
787 |
exportXHTML (fname,false);
|
insilmaril@517
|
788 |
}
|
insilmaril@514
|
789 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@526
|
790 |
} else if (com=="exportXML")
|
insilmaril@526
|
791 |
{
|
insilmaril@526
|
792 |
QString fname="";
|
insilmaril@526
|
793 |
ok=true;
|
insilmaril@526
|
794 |
if (parser.parCount()>=2)
|
insilmaril@526
|
795 |
// Hey, we even have a filename
|
insilmaril@526
|
796 |
fname=parser.parString(ok,1);
|
insilmaril@526
|
797 |
if (!ok)
|
insilmaril@526
|
798 |
{
|
insilmaril@526
|
799 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@526
|
800 |
} else
|
insilmaril@526
|
801 |
{
|
insilmaril@526
|
802 |
exportXML (fname,false);
|
insilmaril@526
|
803 |
}
|
insilmaril@526
|
804 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@491
|
805 |
} else if (com=="importDir")
|
insilmaril@491
|
806 |
{
|
insilmaril@491
|
807 |
if (xelection.isEmpty())
|
insilmaril@491
|
808 |
{
|
insilmaril@491
|
809 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@491
|
810 |
} else if (! selb )
|
insilmaril@491
|
811 |
{
|
insilmaril@491
|
812 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
813 |
} else if (parser.checkParCount(1))
|
insilmaril@491
|
814 |
{
|
insilmaril@491
|
815 |
s=parser.parString(ok,0);
|
insilmaril@491
|
816 |
if (ok) importDirInt(s);
|
insilmaril@491
|
817 |
}
|
insilmaril@514
|
818 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@420
|
819 |
} else if (com=="linkTo")
|
insilmaril@420
|
820 |
{
|
insilmaril@424
|
821 |
if (xelection.isEmpty())
|
insilmaril@420
|
822 |
{
|
insilmaril@432
|
823 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
824 |
} else if ( selb)
|
insilmaril@420
|
825 |
{
|
insilmaril@514
|
826 |
if (parser.checkParCount(4))
|
insilmaril@421
|
827 |
{
|
insilmaril@421
|
828 |
// 0 selectstring of parent
|
insilmaril@421
|
829 |
// 1 num in parent (for branches)
|
insilmaril@421
|
830 |
// 2,3 x,y of mainbranch or mapcenter
|
insilmaril@432
|
831 |
s=parser.parString(ok,0);
|
insilmaril@645
|
832 |
LinkableMapObj *dst=model->findObjBySelect (s);
|
insilmaril@421
|
833 |
if (dst)
|
insilmaril@421
|
834 |
{
|
insilmaril@421
|
835 |
if (typeid(*dst) == typeid(BranchObj) )
|
insilmaril@421
|
836 |
{
|
insilmaril@421
|
837 |
// Get number in parent
|
insilmaril@537
|
838 |
n=parser.parInt (ok,1);
|
insilmaril@421
|
839 |
if (ok)
|
insilmaril@534
|
840 |
{
|
insilmaril@537
|
841 |
selb->linkTo ((BranchObj*)(dst),n);
|
insilmaril@534
|
842 |
xelection.update();
|
insilmaril@534
|
843 |
}
|
insilmaril@421
|
844 |
} else if (typeid(*dst) == typeid(MapCenterObj) )
|
insilmaril@421
|
845 |
{
|
insilmaril@424
|
846 |
selb->linkTo ((BranchObj*)(dst),-1);
|
insilmaril@421
|
847 |
// Get coordinates of mainbranch
|
insilmaril@537
|
848 |
x=parser.parDouble(ok,2);
|
insilmaril@421
|
849 |
if (ok)
|
insilmaril@421
|
850 |
{
|
insilmaril@537
|
851 |
y=parser.parDouble(ok,3);
|
insilmaril@534
|
852 |
if (ok)
|
insilmaril@534
|
853 |
{
|
insilmaril@534
|
854 |
selb->move (x,y);
|
insilmaril@534
|
855 |
xelection.update();
|
insilmaril@534
|
856 |
}
|
insilmaril@421
|
857 |
}
|
insilmaril@421
|
858 |
}
|
insilmaril@421
|
859 |
}
|
insilmaril@421
|
860 |
}
|
insilmaril@491
|
861 |
} else if ( xelection.type() == Selection::FloatImage)
|
insilmaril@421
|
862 |
{
|
insilmaril@514
|
863 |
if (parser.checkParCount(1))
|
insilmaril@421
|
864 |
{
|
insilmaril@421
|
865 |
// 0 selectstring of parent
|
insilmaril@432
|
866 |
s=parser.parString(ok,0);
|
insilmaril@645
|
867 |
LinkableMapObj *dst=model->findObjBySelect (s);
|
insilmaril@421
|
868 |
if (dst)
|
insilmaril@421
|
869 |
{
|
insilmaril@421
|
870 |
if (typeid(*dst) == typeid(BranchObj) ||
|
insilmaril@421
|
871 |
typeid(*dst) == typeid(MapCenterObj))
|
insilmaril@684
|
872 |
linkTo (model->getSelectString(dst));
|
insilmaril@421
|
873 |
} else
|
insilmaril@432
|
874 |
parser.setError (Aborted,"Destination is not a branch");
|
insilmaril@421
|
875 |
}
|
insilmaril@421
|
876 |
} else
|
insilmaril@432
|
877 |
parser.setError (Aborted,"Type of selection is not a floatimage or branch");
|
insilmaril@514
|
878 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@432
|
879 |
} else if (com=="loadImage")
|
insilmaril@432
|
880 |
{
|
insilmaril@432
|
881 |
if (xelection.isEmpty())
|
insilmaril@432
|
882 |
{
|
insilmaril@432
|
883 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@432
|
884 |
} else if (! selb )
|
insilmaril@432
|
885 |
{
|
insilmaril@432
|
886 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
887 |
} else if (parser.checkParCount(1))
|
insilmaril@432
|
888 |
{
|
insilmaril@432
|
889 |
s=parser.parString(ok,0);
|
insilmaril@432
|
890 |
if (ok) loadFloatImageInt (s);
|
insilmaril@432
|
891 |
}
|
insilmaril@514
|
892 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@393
|
893 |
} else if (com=="moveBranchUp")
|
insilmaril@393
|
894 |
{
|
insilmaril@424
|
895 |
if (xelection.isEmpty() )
|
insilmaril@394
|
896 |
{
|
insilmaril@432
|
897 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
898 |
} else if (! selb )
|
insilmaril@394
|
899 |
{
|
insilmaril@432
|
900 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
901 |
} else if (parser.checkParCount(0))
|
insilmaril@394
|
902 |
{
|
insilmaril@394
|
903 |
moveBranchUp();
|
insilmaril@394
|
904 |
}
|
insilmaril@514
|
905 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@394
|
906 |
} else if (com=="moveBranchDown")
|
insilmaril@394
|
907 |
{
|
insilmaril@424
|
908 |
if (xelection.isEmpty() )
|
insilmaril@394
|
909 |
{
|
insilmaril@432
|
910 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
911 |
} else if (! selb )
|
insilmaril@394
|
912 |
{
|
insilmaril@432
|
913 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
914 |
} else if (parser.checkParCount(0))
|
insilmaril@394
|
915 |
{
|
insilmaril@394
|
916 |
moveBranchDown();
|
insilmaril@394
|
917 |
}
|
insilmaril@514
|
918 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@394
|
919 |
} else if (com=="move")
|
insilmaril@394
|
920 |
{
|
insilmaril@424
|
921 |
if (xelection.isEmpty() )
|
insilmaril@394
|
922 |
{
|
insilmaril@432
|
923 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@491
|
924 |
} else if ( xelection.type()!=Selection::Branch &&
|
insilmaril@491
|
925 |
xelection.type()!=Selection::MapCenter &&
|
insilmaril@491
|
926 |
xelection.type()!=Selection::FloatImage )
|
insilmaril@394
|
927 |
{
|
insilmaril@432
|
928 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@514
|
929 |
} else if (parser.checkParCount(2))
|
insilmaril@393
|
930 |
{
|
insilmaril@537
|
931 |
x=parser.parDouble (ok,0);
|
insilmaril@393
|
932 |
if (ok)
|
insilmaril@393
|
933 |
{
|
insilmaril@537
|
934 |
y=parser.parDouble (ok,1);
|
insilmaril@393
|
935 |
if (ok) move (x,y);
|
insilmaril@393
|
936 |
}
|
insilmaril@393
|
937 |
}
|
insilmaril@514
|
938 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@395
|
939 |
} else if (com=="moveRel")
|
insilmaril@393
|
940 |
{
|
insilmaril@424
|
941 |
if (xelection.isEmpty() )
|
insilmaril@394
|
942 |
{
|
insilmaril@432
|
943 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@491
|
944 |
} else if ( xelection.type()!=Selection::Selection::Branch &&
|
insilmaril@491
|
945 |
xelection.type()!=Selection::Selection::MapCenter &&
|
insilmaril@491
|
946 |
xelection.type()!=Selection::Selection::FloatImage )
|
insilmaril@394
|
947 |
{
|
insilmaril@432
|
948 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@514
|
949 |
} else if (parser.checkParCount(2))
|
insilmaril@393
|
950 |
{
|
insilmaril@537
|
951 |
x=parser.parDouble (ok,0);
|
insilmaril@393
|
952 |
if (ok)
|
insilmaril@393
|
953 |
{
|
insilmaril@537
|
954 |
y=parser.parDouble (ok,1);
|
insilmaril@393
|
955 |
if (ok) moveRel (x,y);
|
insilmaril@393
|
956 |
}
|
insilmaril@393
|
957 |
}
|
insilmaril@514
|
958 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@502
|
959 |
} else if (com=="nop")
|
insilmaril@502
|
960 |
{
|
insilmaril@514
|
961 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@395
|
962 |
} else if (com=="paste")
|
insilmaril@395
|
963 |
{
|
insilmaril@424
|
964 |
if (xelection.isEmpty() )
|
insilmaril@395
|
965 |
{
|
insilmaril@432
|
966 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
967 |
} else if (! selb )
|
insilmaril@395
|
968 |
{
|
insilmaril@432
|
969 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
970 |
} else if (parser.checkParCount(1))
|
insilmaril@395
|
971 |
{
|
insilmaril@537
|
972 |
n=parser.parInt (ok,0);
|
insilmaril@537
|
973 |
if (ok) pasteNoSave(n);
|
insilmaril@502
|
974 |
}
|
insilmaril@502
|
975 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@502
|
976 |
} else if (com=="qa")
|
insilmaril@502
|
977 |
{
|
insilmaril@502
|
978 |
if (xelection.isEmpty() )
|
insilmaril@502
|
979 |
{
|
insilmaril@502
|
980 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@502
|
981 |
} else if (! selb )
|
insilmaril@502
|
982 |
{
|
insilmaril@502
|
983 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
984 |
} else if (parser.checkParCount(4))
|
insilmaril@502
|
985 |
{
|
insilmaril@502
|
986 |
QString c,u;
|
insilmaril@502
|
987 |
c=parser.parString (ok,0);
|
insilmaril@502
|
988 |
if (!ok)
|
insilmaril@502
|
989 |
{
|
insilmaril@502
|
990 |
parser.setError (Aborted,"No comment given");
|
insilmaril@502
|
991 |
} else
|
insilmaril@502
|
992 |
{
|
insilmaril@502
|
993 |
s=parser.parString (ok,1);
|
insilmaril@502
|
994 |
if (!ok)
|
insilmaril@502
|
995 |
{
|
insilmaril@502
|
996 |
parser.setError (Aborted,"First parameter is not a string");
|
insilmaril@502
|
997 |
} else
|
insilmaril@502
|
998 |
{
|
insilmaril@502
|
999 |
t=parser.parString (ok,2);
|
insilmaril@502
|
1000 |
if (!ok)
|
insilmaril@502
|
1001 |
{
|
insilmaril@502
|
1002 |
parser.setError (Aborted,"Condition is not a string");
|
insilmaril@502
|
1003 |
} else
|
insilmaril@502
|
1004 |
{
|
insilmaril@502
|
1005 |
u=parser.parString (ok,3);
|
insilmaril@502
|
1006 |
if (!ok)
|
insilmaril@502
|
1007 |
{
|
insilmaril@502
|
1008 |
parser.setError (Aborted,"Third parameter is not a string");
|
insilmaril@502
|
1009 |
} else
|
insilmaril@502
|
1010 |
{
|
insilmaril@502
|
1011 |
if (s!="heading")
|
insilmaril@502
|
1012 |
{
|
insilmaril@502
|
1013 |
parser.setError (Aborted,"Unknown type: "+s);
|
insilmaril@502
|
1014 |
} else
|
insilmaril@502
|
1015 |
{
|
insilmaril@502
|
1016 |
if (! (t=="eq") )
|
insilmaril@502
|
1017 |
{
|
insilmaril@502
|
1018 |
parser.setError (Aborted,"Unknown operator: "+t);
|
insilmaril@502
|
1019 |
} else
|
insilmaril@502
|
1020 |
{
|
insilmaril@502
|
1021 |
if (! selb )
|
insilmaril@502
|
1022 |
{
|
insilmaril@502
|
1023 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@502
|
1024 |
} else
|
insilmaril@502
|
1025 |
{
|
insilmaril@502
|
1026 |
if (selb->getHeading() == u)
|
insilmaril@502
|
1027 |
{
|
insilmaril@658
|
1028 |
cout << "PASSED: " << qPrintable (c) << endl;
|
insilmaril@502
|
1029 |
} else
|
insilmaril@502
|
1030 |
{
|
insilmaril@658
|
1031 |
cout << "FAILED: " << qPrintable (c) << endl;
|
insilmaril@502
|
1032 |
}
|
insilmaril@502
|
1033 |
}
|
insilmaril@502
|
1034 |
}
|
insilmaril@502
|
1035 |
}
|
insilmaril@502
|
1036 |
}
|
insilmaril@502
|
1037 |
}
|
insilmaril@502
|
1038 |
}
|
insilmaril@502
|
1039 |
}
|
insilmaril@395
|
1040 |
}
|
insilmaril@514
|
1041 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@434
|
1042 |
} else if (com=="saveImage")
|
insilmaril@434
|
1043 |
{
|
insilmaril@434
|
1044 |
FloatImageObj *fio=xelection.getFloatImage();
|
insilmaril@434
|
1045 |
if (!fio)
|
insilmaril@434
|
1046 |
{
|
insilmaril@434
|
1047 |
parser.setError (Aborted,"Type of selection is not an image");
|
insilmaril@514
|
1048 |
} else if (parser.checkParCount(2))
|
insilmaril@434
|
1049 |
{
|
insilmaril@434
|
1050 |
s=parser.parString(ok,0);
|
insilmaril@434
|
1051 |
if (ok)
|
insilmaril@434
|
1052 |
{
|
insilmaril@434
|
1053 |
t=parser.parString(ok,1);
|
insilmaril@434
|
1054 |
if (ok) saveFloatImageInt (fio,t,s);
|
insilmaril@434
|
1055 |
}
|
insilmaril@434
|
1056 |
}
|
insilmaril@514
|
1057 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@427
|
1058 |
} else if (com=="scroll")
|
insilmaril@427
|
1059 |
{
|
insilmaril@427
|
1060 |
if (xelection.isEmpty() )
|
insilmaril@427
|
1061 |
{
|
insilmaril@432
|
1062 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@427
|
1063 |
} else if (! selb )
|
insilmaril@427
|
1064 |
{
|
insilmaril@432
|
1065 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1066 |
} else if (parser.checkParCount(0))
|
insilmaril@427
|
1067 |
{
|
insilmaril@473
|
1068 |
if (!scrollBranch (selb))
|
insilmaril@432
|
1069 |
parser.setError (Aborted,"Could not scroll branch");
|
insilmaril@427
|
1070 |
}
|
insilmaril@514
|
1071 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@398
|
1072 |
} else if (com=="select")
|
insilmaril@398
|
1073 |
{
|
insilmaril@514
|
1074 |
if (parser.checkParCount(1))
|
insilmaril@398
|
1075 |
{
|
insilmaril@432
|
1076 |
s=parser.parString(ok,0);
|
insilmaril@398
|
1077 |
if (ok) select (s);
|
insilmaril@398
|
1078 |
}
|
insilmaril@514
|
1079 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@432
|
1080 |
} else if (com=="selectLastBranch")
|
insilmaril@432
|
1081 |
{
|
insilmaril@432
|
1082 |
if (xelection.isEmpty() )
|
insilmaril@432
|
1083 |
{
|
insilmaril@432
|
1084 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@432
|
1085 |
} else if (! selb )
|
insilmaril@432
|
1086 |
{
|
insilmaril@432
|
1087 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1088 |
} else if (parser.checkParCount(0))
|
insilmaril@432
|
1089 |
{
|
insilmaril@432
|
1090 |
BranchObj *bo=selb->getLastBranch();
|
insilmaril@432
|
1091 |
if (!bo)
|
insilmaril@432
|
1092 |
parser.setError (Aborted,"Could not select last branch");
|
insilmaril@432
|
1093 |
selectInt (bo);
|
insilmaril@432
|
1094 |
|
insilmaril@432
|
1095 |
}
|
insilmaril@514
|
1096 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@434
|
1097 |
} else if (com=="selectLastImage")
|
insilmaril@434
|
1098 |
{
|
insilmaril@434
|
1099 |
if (xelection.isEmpty() )
|
insilmaril@434
|
1100 |
{
|
insilmaril@434
|
1101 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@434
|
1102 |
} else if (! selb )
|
insilmaril@434
|
1103 |
{
|
insilmaril@434
|
1104 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1105 |
} else if (parser.checkParCount(0))
|
insilmaril@434
|
1106 |
{
|
insilmaril@434
|
1107 |
FloatImageObj *fio=selb->getLastFloatImage();
|
insilmaril@434
|
1108 |
if (!fio)
|
insilmaril@434
|
1109 |
parser.setError (Aborted,"Could not select last image");
|
insilmaril@434
|
1110 |
selectInt (fio);
|
insilmaril@434
|
1111 |
|
insilmaril@434
|
1112 |
}
|
insilmaril@514
|
1113 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@537
|
1114 |
} else if (com=="selectLatestAdded")
|
insilmaril@537
|
1115 |
{
|
insilmaril@537
|
1116 |
if (latestSelection.isEmpty() )
|
insilmaril@537
|
1117 |
{
|
insilmaril@537
|
1118 |
parser.setError (Aborted,"No latest added object");
|
insilmaril@537
|
1119 |
} else
|
insilmaril@537
|
1120 |
{
|
insilmaril@537
|
1121 |
if (!select (latestSelection))
|
insilmaril@537
|
1122 |
parser.setError (Aborted,"Could not select latest added object "+latestSelection);
|
insilmaril@537
|
1123 |
}
|
insilmaril@537
|
1124 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@473
|
1125 |
} else if (com=="setFrameType")
|
insilmaril@473
|
1126 |
{
|
insilmaril@491
|
1127 |
if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
|
insilmaril@473
|
1128 |
{
|
insilmaril@473
|
1129 |
parser.setError (Aborted,"Type of selection does not allow setting frame type");
|
insilmaril@473
|
1130 |
}
|
insilmaril@514
|
1131 |
else if (parser.checkParCount(1))
|
insilmaril@473
|
1132 |
{
|
insilmaril@473
|
1133 |
s=parser.parString(ok,0);
|
insilmaril@473
|
1134 |
if (ok) setFrameType (s);
|
insilmaril@473
|
1135 |
}
|
insilmaril@514
|
1136 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@486
|
1137 |
} else if (com=="setFramePenColor")
|
insilmaril@486
|
1138 |
{
|
insilmaril@491
|
1139 |
if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
|
insilmaril@486
|
1140 |
{
|
insilmaril@486
|
1141 |
parser.setError (Aborted,"Type of selection does not allow setting of pen color");
|
insilmaril@486
|
1142 |
}
|
insilmaril@514
|
1143 |
else if (parser.checkParCount(1))
|
insilmaril@486
|
1144 |
{
|
insilmaril@486
|
1145 |
QColor c=parser.parColor(ok,0);
|
insilmaril@486
|
1146 |
if (ok) setFramePenColor (c);
|
insilmaril@486
|
1147 |
}
|
insilmaril@514
|
1148 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@486
|
1149 |
} else if (com=="setFrameBrushColor")
|
insilmaril@486
|
1150 |
{
|
insilmaril@491
|
1151 |
if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
|
insilmaril@486
|
1152 |
{
|
insilmaril@486
|
1153 |
parser.setError (Aborted,"Type of selection does not allow setting brush color");
|
insilmaril@486
|
1154 |
}
|
insilmaril@514
|
1155 |
else if (parser.checkParCount(1))
|
insilmaril@486
|
1156 |
{
|
insilmaril@486
|
1157 |
QColor c=parser.parColor(ok,0);
|
insilmaril@486
|
1158 |
if (ok) setFrameBrushColor (c);
|
insilmaril@486
|
1159 |
}
|
insilmaril@514
|
1160 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@486
|
1161 |
} else if (com=="setFramePadding")
|
insilmaril@486
|
1162 |
{
|
insilmaril@491
|
1163 |
if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
|
insilmaril@486
|
1164 |
{
|
insilmaril@486
|
1165 |
parser.setError (Aborted,"Type of selection does not allow setting frame padding");
|
insilmaril@486
|
1166 |
}
|
insilmaril@514
|
1167 |
else if (parser.checkParCount(1))
|
insilmaril@486
|
1168 |
{
|
insilmaril@537
|
1169 |
n=parser.parInt(ok,0);
|
insilmaril@537
|
1170 |
if (ok) setFramePadding(n);
|
insilmaril@486
|
1171 |
}
|
insilmaril@514
|
1172 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@486
|
1173 |
} else if (com=="setFrameBorderWidth")
|
insilmaril@486
|
1174 |
{
|
insilmaril@491
|
1175 |
if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
|
insilmaril@486
|
1176 |
{
|
insilmaril@486
|
1177 |
parser.setError (Aborted,"Type of selection does not allow setting frame border width");
|
insilmaril@486
|
1178 |
}
|
insilmaril@514
|
1179 |
else if (parser.checkParCount(1))
|
insilmaril@486
|
1180 |
{
|
insilmaril@537
|
1181 |
n=parser.parInt(ok,0);
|
insilmaril@537
|
1182 |
if (ok) setFrameBorderWidth (n);
|
insilmaril@486
|
1183 |
}
|
insilmaril@514
|
1184 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@398
|
1185 |
} else if (com=="setMapAuthor")
|
insilmaril@398
|
1186 |
{
|
insilmaril@514
|
1187 |
if (parser.checkParCount(1))
|
insilmaril@398
|
1188 |
{
|
insilmaril@432
|
1189 |
s=parser.parString(ok,0);
|
insilmaril@398
|
1190 |
if (ok) setMapAuthor (s);
|
insilmaril@398
|
1191 |
}
|
insilmaril@514
|
1192 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@398
|
1193 |
} else if (com=="setMapComment")
|
insilmaril@398
|
1194 |
{
|
insilmaril@514
|
1195 |
if (parser.checkParCount(1))
|
insilmaril@398
|
1196 |
{
|
insilmaril@432
|
1197 |
s=parser.parString(ok,0);
|
insilmaril@398
|
1198 |
if (ok) setMapComment(s);
|
insilmaril@398
|
1199 |
}
|
insilmaril@514
|
1200 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@398
|
1201 |
} else if (com=="setMapBackgroundColor")
|
insilmaril@398
|
1202 |
{
|
insilmaril@424
|
1203 |
if (xelection.isEmpty() )
|
insilmaril@398
|
1204 |
{
|
insilmaril@432
|
1205 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
1206 |
} else if (! xelection.getBranch() )
|
insilmaril@398
|
1207 |
{
|
insilmaril@432
|
1208 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1209 |
} else if (parser.checkParCount(1))
|
insilmaril@398
|
1210 |
{
|
insilmaril@432
|
1211 |
QColor c=parser.parColor (ok,0);
|
insilmaril@398
|
1212 |
if (ok) setMapBackgroundColor (c);
|
insilmaril@398
|
1213 |
}
|
insilmaril@514
|
1214 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@398
|
1215 |
} else if (com=="setMapDefLinkColor")
|
insilmaril@398
|
1216 |
{
|
insilmaril@424
|
1217 |
if (xelection.isEmpty() )
|
insilmaril@398
|
1218 |
{
|
insilmaril@432
|
1219 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
1220 |
} else if (! selb )
|
insilmaril@398
|
1221 |
{
|
insilmaril@432
|
1222 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1223 |
} else if (parser.checkParCount(1))
|
insilmaril@398
|
1224 |
{
|
insilmaril@432
|
1225 |
QColor c=parser.parColor (ok,0);
|
insilmaril@398
|
1226 |
if (ok) setMapDefLinkColor (c);
|
insilmaril@398
|
1227 |
}
|
insilmaril@514
|
1228 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@398
|
1229 |
} else if (com=="setMapLinkStyle")
|
insilmaril@398
|
1230 |
{
|
insilmaril@514
|
1231 |
if (parser.checkParCount(1))
|
insilmaril@398
|
1232 |
{
|
insilmaril@432
|
1233 |
s=parser.parString (ok,0);
|
insilmaril@398
|
1234 |
if (ok) setMapLinkStyle(s);
|
insilmaril@398
|
1235 |
}
|
insilmaril@514
|
1236 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@129
|
1237 |
} else if (com=="setHeading")
|
insilmaril@129
|
1238 |
{
|
insilmaril@424
|
1239 |
if (xelection.isEmpty() )
|
insilmaril@394
|
1240 |
{
|
insilmaril@432
|
1241 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
1242 |
} else if (! selb )
|
insilmaril@394
|
1243 |
{
|
insilmaril@432
|
1244 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1245 |
} else if (parser.checkParCount(1))
|
insilmaril@129
|
1246 |
{
|
insilmaril@432
|
1247 |
s=parser.parString (ok,0);
|
insilmaril@366
|
1248 |
if (ok)
|
insilmaril@366
|
1249 |
setHeading (s);
|
insilmaril@129
|
1250 |
}
|
insilmaril@514
|
1251 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@395
|
1252 |
} else if (com=="setHideExport")
|
insilmaril@395
|
1253 |
{
|
insilmaril@424
|
1254 |
if (xelection.isEmpty() )
|
insilmaril@395
|
1255 |
{
|
insilmaril@432
|
1256 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@491
|
1257 |
} else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage)
|
insilmaril@395
|
1258 |
{
|
insilmaril@432
|
1259 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@514
|
1260 |
} else if (parser.checkParCount(1))
|
insilmaril@395
|
1261 |
{
|
insilmaril@432
|
1262 |
b=parser.parBool(ok,0);
|
insilmaril@395
|
1263 |
if (ok) setHideExport (b);
|
insilmaril@395
|
1264 |
}
|
insilmaril@514
|
1265 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@434
|
1266 |
} else if (com=="setIncludeImagesHorizontally")
|
insilmaril@473
|
1267 |
{
|
insilmaril@434
|
1268 |
if (xelection.isEmpty() )
|
insilmaril@434
|
1269 |
{
|
insilmaril@434
|
1270 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@434
|
1271 |
} else if (! selb)
|
insilmaril@434
|
1272 |
{
|
insilmaril@434
|
1273 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1274 |
} else if (parser.checkParCount(1))
|
insilmaril@434
|
1275 |
{
|
insilmaril@434
|
1276 |
b=parser.parBool(ok,0);
|
insilmaril@434
|
1277 |
if (ok) setIncludeImagesHor(b);
|
insilmaril@434
|
1278 |
}
|
insilmaril@514
|
1279 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@434
|
1280 |
} else if (com=="setIncludeImagesVertically")
|
insilmaril@434
|
1281 |
{
|
insilmaril@434
|
1282 |
if (xelection.isEmpty() )
|
insilmaril@434
|
1283 |
{
|
insilmaril@434
|
1284 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@434
|
1285 |
} else if (! selb)
|
insilmaril@434
|
1286 |
{
|
insilmaril@434
|
1287 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1288 |
} else if (parser.checkParCount(1))
|
insilmaril@434
|
1289 |
{
|
insilmaril@434
|
1290 |
b=parser.parBool(ok,0);
|
insilmaril@434
|
1291 |
if (ok) setIncludeImagesVer(b);
|
insilmaril@434
|
1292 |
}
|
insilmaril@514
|
1293 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@491
|
1294 |
} else if (com=="setHideLinkUnselected")
|
insilmaril@491
|
1295 |
{
|
insilmaril@491
|
1296 |
if (xelection.isEmpty() )
|
insilmaril@491
|
1297 |
{
|
insilmaril@491
|
1298 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@491
|
1299 |
} else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage)
|
insilmaril@491
|
1300 |
{
|
insilmaril@491
|
1301 |
parser.setError (Aborted,"Type of selection does not allow hiding the link");
|
insilmaril@514
|
1302 |
} else if (parser.checkParCount(1))
|
insilmaril@491
|
1303 |
{
|
insilmaril@491
|
1304 |
b=parser.parBool(ok,0);
|
insilmaril@491
|
1305 |
if (ok) setHideLinkUnselected(b);
|
insilmaril@491
|
1306 |
}
|
insilmaril@514
|
1307 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@442
|
1308 |
} else if (com=="setSelectionColor")
|
insilmaril@442
|
1309 |
{
|
insilmaril@514
|
1310 |
if (parser.checkParCount(1))
|
insilmaril@442
|
1311 |
{
|
insilmaril@442
|
1312 |
QColor c=parser.parColor (ok,0);
|
insilmaril@442
|
1313 |
if (ok) setSelectionColorInt (c);
|
insilmaril@442
|
1314 |
}
|
insilmaril@514
|
1315 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@143
|
1316 |
} else if (com=="setURL")
|
insilmaril@143
|
1317 |
{
|
insilmaril@424
|
1318 |
if (xelection.isEmpty() )
|
insilmaril@394
|
1319 |
{
|
insilmaril@432
|
1320 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
1321 |
} else if (! selb )
|
insilmaril@394
|
1322 |
{
|
insilmaril@432
|
1323 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1324 |
} else if (parser.checkParCount(1))
|
insilmaril@143
|
1325 |
{
|
insilmaril@432
|
1326 |
s=parser.parString (ok,0);
|
insilmaril@491
|
1327 |
if (ok) setURL(s);
|
insilmaril@143
|
1328 |
}
|
insilmaril@514
|
1329 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@143
|
1330 |
} else if (com=="setVymLink")
|
insilmaril@143
|
1331 |
{
|
insilmaril@424
|
1332 |
if (xelection.isEmpty() )
|
insilmaril@394
|
1333 |
{
|
insilmaril@432
|
1334 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
1335 |
} else if (! selb )
|
insilmaril@394
|
1336 |
{
|
insilmaril@432
|
1337 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1338 |
} else if (parser.checkParCount(1))
|
insilmaril@143
|
1339 |
{
|
insilmaril@432
|
1340 |
s=parser.parString (ok,0);
|
insilmaril@366
|
1341 |
if (ok) setVymLinkInt(s);
|
insilmaril@143
|
1342 |
}
|
insilmaril@143
|
1343 |
}
|
insilmaril@514
|
1344 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@366
|
1345 |
else if (com=="setFlag")
|
insilmaril@366
|
1346 |
{
|
insilmaril@424
|
1347 |
if (xelection.isEmpty() )
|
insilmaril@366
|
1348 |
{
|
insilmaril@432
|
1349 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
1350 |
} else if (! selb )
|
insilmaril@394
|
1351 |
{
|
insilmaril@432
|
1352 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1353 |
} else if (parser.checkParCount(1))
|
insilmaril@394
|
1354 |
{
|
insilmaril@432
|
1355 |
s=parser.parString(ok,0);
|
insilmaril@394
|
1356 |
if (ok)
|
insilmaril@394
|
1357 |
{
|
insilmaril@424
|
1358 |
selb->activateStandardFlag(s);
|
insilmaril@424
|
1359 |
selb->updateFlagsToolbar();
|
insilmaril@366
|
1360 |
}
|
insilmaril@366
|
1361 |
}
|
insilmaril@514
|
1362 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@445
|
1363 |
} else if (com=="setFrameType")
|
insilmaril@445
|
1364 |
{
|
insilmaril@445
|
1365 |
if (xelection.isEmpty() )
|
insilmaril@445
|
1366 |
{
|
insilmaril@445
|
1367 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@445
|
1368 |
} else if (! selb )
|
insilmaril@445
|
1369 |
{
|
insilmaril@445
|
1370 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1371 |
} else if (parser.checkParCount(1))
|
insilmaril@445
|
1372 |
{
|
insilmaril@445
|
1373 |
s=parser.parString(ok,0);
|
insilmaril@445
|
1374 |
if (ok)
|
insilmaril@445
|
1375 |
setFrameType (s);
|
insilmaril@445
|
1376 |
}
|
insilmaril@514
|
1377 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@615
|
1378 |
} else if (com=="sortChildren")
|
insilmaril@615
|
1379 |
{
|
insilmaril@615
|
1380 |
if (xelection.isEmpty() )
|
insilmaril@615
|
1381 |
{
|
insilmaril@615
|
1382 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@615
|
1383 |
} else if (! selb )
|
insilmaril@615
|
1384 |
{
|
insilmaril@615
|
1385 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@615
|
1386 |
} else if (parser.checkParCount(0))
|
insilmaril@615
|
1387 |
{
|
insilmaril@615
|
1388 |
sortChildren();
|
insilmaril@615
|
1389 |
}
|
insilmaril@615
|
1390 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@447
|
1391 |
} else if (com=="toggleFlag")
|
insilmaril@447
|
1392 |
{
|
insilmaril@447
|
1393 |
if (xelection.isEmpty() )
|
insilmaril@447
|
1394 |
{
|
insilmaril@447
|
1395 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@447
|
1396 |
} else if (! selb )
|
insilmaril@447
|
1397 |
{
|
insilmaril@447
|
1398 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1399 |
} else if (parser.checkParCount(1))
|
insilmaril@447
|
1400 |
{
|
insilmaril@447
|
1401 |
s=parser.parString(ok,0);
|
insilmaril@447
|
1402 |
if (ok)
|
insilmaril@447
|
1403 |
{
|
insilmaril@447
|
1404 |
selb->toggleStandardFlag(s);
|
insilmaril@447
|
1405 |
selb->updateFlagsToolbar();
|
insilmaril@447
|
1406 |
}
|
insilmaril@447
|
1407 |
}
|
insilmaril@514
|
1408 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@427
|
1409 |
} else if (com=="unscroll")
|
insilmaril@427
|
1410 |
{
|
insilmaril@427
|
1411 |
if (xelection.isEmpty() )
|
insilmaril@427
|
1412 |
{
|
insilmaril@432
|
1413 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@427
|
1414 |
} else if (! selb )
|
insilmaril@427
|
1415 |
{
|
insilmaril@432
|
1416 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1417 |
} else if (parser.checkParCount(0))
|
insilmaril@427
|
1418 |
{
|
insilmaril@473
|
1419 |
if (!unscrollBranch (selb))
|
insilmaril@432
|
1420 |
parser.setError (Aborted,"Could not unscroll branch");
|
insilmaril@427
|
1421 |
}
|
insilmaril@514
|
1422 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@473
|
1423 |
} else if (com=="unscrollChilds")
|
insilmaril@473
|
1424 |
{
|
insilmaril@473
|
1425 |
if (xelection.isEmpty() )
|
insilmaril@473
|
1426 |
{
|
insilmaril@473
|
1427 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@473
|
1428 |
} else if (! selb )
|
insilmaril@473
|
1429 |
{
|
insilmaril@473
|
1430 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1431 |
} else if (parser.checkParCount(0))
|
insilmaril@473
|
1432 |
{
|
insilmaril@473
|
1433 |
unscrollChilds ();
|
insilmaril@473
|
1434 |
}
|
insilmaril@514
|
1435 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@427
|
1436 |
} else if (com=="unsetFlag")
|
insilmaril@366
|
1437 |
{
|
insilmaril@424
|
1438 |
if (xelection.isEmpty() )
|
insilmaril@366
|
1439 |
{
|
insilmaril@432
|
1440 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@424
|
1441 |
} else if (! selb )
|
insilmaril@394
|
1442 |
{
|
insilmaril@432
|
1443 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@514
|
1444 |
} else if (parser.checkParCount(1))
|
insilmaril@394
|
1445 |
{
|
insilmaril@432
|
1446 |
s=parser.parString(ok,0);
|
insilmaril@394
|
1447 |
if (ok)
|
insilmaril@394
|
1448 |
{
|
insilmaril@424
|
1449 |
selb->deactivateStandardFlag(s);
|
insilmaril@424
|
1450 |
selb->updateFlagsToolbar();
|
insilmaril@366
|
1451 |
}
|
insilmaril@366
|
1452 |
}
|
insilmaril@398
|
1453 |
} else
|
insilmaril@432
|
1454 |
parser.setError (Aborted,"Unknown command");
|
insilmaril@129
|
1455 |
|
insilmaril@129
|
1456 |
// Any errors?
|
insilmaril@432
|
1457 |
if (parser.errorLevel()==NoError)
|
insilmaril@432
|
1458 |
{
|
insilmaril@613
|
1459 |
// setChanged(); FIXME should not be called e.g. for export?!
|
insilmaril@645
|
1460 |
model->reposition();
|
insilmaril@432
|
1461 |
}
|
insilmaril@394
|
1462 |
else
|
insilmaril@106
|
1463 |
{
|
insilmaril@366
|
1464 |
// TODO Error handling
|
insilmaril@366
|
1465 |
qWarning("MapEditor::parseAtom: Error!");
|
insilmaril@432
|
1466 |
qWarning(parser.errorMessage());
|
insilmaril@394
|
1467 |
}
|
insilmaril@0
|
1468 |
}
|
insilmaril@0
|
1469 |
|
insilmaril@432
|
1470 |
void MapEditor::runScript (QString script)
|
insilmaril@432
|
1471 |
{
|
insilmaril@445
|
1472 |
parser.setScript (script);
|
insilmaril@445
|
1473 |
parser.runScript();
|
insilmaril@447
|
1474 |
while (parser.next() )
|
insilmaril@447
|
1475 |
parseAtom(parser.getAtom());
|
insilmaril@432
|
1476 |
}
|
insilmaril@0
|
1477 |
|
insilmaril@0
|
1478 |
bool MapEditor::isDefault()
|
insilmaril@0
|
1479 |
{
|
insilmaril@0
|
1480 |
return mapDefault;
|
insilmaril@0
|
1481 |
}
|
insilmaril@0
|
1482 |
|
insilmaril@0
|
1483 |
bool MapEditor::hasChanged()
|
insilmaril@0
|
1484 |
{
|
insilmaril@0
|
1485 |
return mapChanged;
|
insilmaril@0
|
1486 |
}
|
insilmaril@0
|
1487 |
|
insilmaril@0
|
1488 |
void MapEditor::setChanged()
|
insilmaril@0
|
1489 |
{
|
insilmaril@473
|
1490 |
if (!mapChanged)
|
insilmaril@473
|
1491 |
autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt());
|
insilmaril@0
|
1492 |
mapChanged=true;
|
insilmaril@0
|
1493 |
mapDefault=false;
|
insilmaril@0
|
1494 |
mapUnsaved=true;
|
insilmaril@0
|
1495 |
findReset();
|
insilmaril@473
|
1496 |
|
insilmaril@0
|
1497 |
}
|
insilmaril@0
|
1498 |
|
insilmaril@0
|
1499 |
void MapEditor::closeMap()
|
insilmaril@0
|
1500 |
{
|
insilmaril@0
|
1501 |
// Unselect before disabling the toolbar actions
|
insilmaril@424
|
1502 |
if (!xelection.isEmpty() ) xelection.unselect();
|
insilmaril@424
|
1503 |
xelection.clear();
|
insilmaril@0
|
1504 |
updateActions();
|
insilmaril@0
|
1505 |
|
insilmaril@0
|
1506 |
clear();
|
insilmaril@0
|
1507 |
close();
|
insilmaril@0
|
1508 |
}
|
insilmaril@0
|
1509 |
|
insilmaril@486
|
1510 |
void MapEditor::setFilePath(QString fpath, QString destname)
|
insilmaril@0
|
1511 |
{
|
insilmaril@486
|
1512 |
if (fpath.isEmpty() || fpath=="")
|
insilmaril@106
|
1513 |
{
|
insilmaril@106
|
1514 |
filePath="";
|
insilmaril@106
|
1515 |
fileName="";
|
insilmaril@106
|
1516 |
destPath="";
|
insilmaril@106
|
1517 |
} else
|
insilmaril@106
|
1518 |
{
|
insilmaril@486
|
1519 |
filePath=fpath; // becomes absolute path
|
insilmaril@486
|
1520 |
fileName=fpath; // gets stripped of path
|
insilmaril@676
|
1521 |
destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
|
insilmaril@106
|
1522 |
|
insilmaril@486
|
1523 |
// If fpath is not an absolute path, complete it
|
insilmaril@486
|
1524 |
filePath=QDir(fpath).absPath();
|
insilmaril@106
|
1525 |
fileDir=filePath.left (1+filePath.findRev ("/"));
|
insilmaril@106
|
1526 |
|
insilmaril@106
|
1527 |
// Set short name, too. Search from behind:
|
insilmaril@106
|
1528 |
int i=fileName.findRev("/");
|
insilmaril@106
|
1529 |
if (i>=0) fileName=fileName.remove (0,i+1);
|
insilmaril@106
|
1530 |
|
insilmaril@106
|
1531 |
// Forget the .vym (or .xml) for name of map
|
insilmaril@106
|
1532 |
mapName=fileName.left(fileName.findRev(".",-1,true) );
|
insilmaril@106
|
1533 |
}
|
insilmaril@0
|
1534 |
}
|
insilmaril@0
|
1535 |
|
insilmaril@486
|
1536 |
void MapEditor::setFilePath(QString fpath)
|
insilmaril@486
|
1537 |
{
|
insilmaril@486
|
1538 |
setFilePath (fpath,fpath);
|
insilmaril@486
|
1539 |
}
|
insilmaril@486
|
1540 |
|
insilmaril@0
|
1541 |
QString MapEditor::getFilePath()
|
insilmaril@0
|
1542 |
{
|
insilmaril@0
|
1543 |
return filePath;
|
insilmaril@0
|
1544 |
}
|
insilmaril@0
|
1545 |
|
insilmaril@0
|
1546 |
QString MapEditor::getFileName()
|
insilmaril@0
|
1547 |
{
|
insilmaril@0
|
1548 |
return fileName;
|
insilmaril@0
|
1549 |
}
|
insilmaril@0
|
1550 |
|
insilmaril@0
|
1551 |
QString MapEditor::getMapName()
|
insilmaril@0
|
1552 |
{
|
insilmaril@0
|
1553 |
return mapName;
|
insilmaril@0
|
1554 |
}
|
insilmaril@0
|
1555 |
|
insilmaril@0
|
1556 |
QString MapEditor::getDestPath()
|
insilmaril@0
|
1557 |
{
|
insilmaril@0
|
1558 |
return destPath;
|
insilmaril@0
|
1559 |
}
|
insilmaril@0
|
1560 |
|
insilmaril@571
|
1561 |
ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype)
|
insilmaril@0
|
1562 |
{
|
insilmaril@205
|
1563 |
ErrorCode err=success;
|
insilmaril@0
|
1564 |
|
insilmaril@571
|
1565 |
parseBaseHandler *handler;
|
insilmaril@676
|
1566 |
fileType=ftype;
|
insilmaril@676
|
1567 |
switch (fileType)
|
insilmaril@571
|
1568 |
{
|
insilmaril@571
|
1569 |
case VymMap: handler=new parseVYMHandler; break;
|
insilmaril@571
|
1570 |
case FreemindMap : handler=new parseFreemindHandler; break;
|
insilmaril@571
|
1571 |
default:
|
insilmaril@571
|
1572 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@571
|
1573 |
"Unknown FileType in MapEditor::load()");
|
insilmaril@571
|
1574 |
return aborted;
|
insilmaril@571
|
1575 |
}
|
insilmaril@0
|
1576 |
if (lmode==NewMap)
|
insilmaril@0
|
1577 |
{
|
insilmaril@424
|
1578 |
xelection.clear();
|
insilmaril@645
|
1579 |
model->setMapEditor(this);
|
insilmaril@0
|
1580 |
// (map state is set later at end of load...)
|
insilmaril@0
|
1581 |
} else
|
insilmaril@0
|
1582 |
{
|
insilmaril@424
|
1583 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
1584 |
if (!bo) return aborted;
|
insilmaril@395
|
1585 |
if (lmode==ImportAdd)
|
insilmaril@395
|
1586 |
saveStateChangingPart(
|
insilmaril@424
|
1587 |
bo,
|
insilmaril@424
|
1588 |
bo,
|
insilmaril@395
|
1589 |
QString("addMapInsert (%1)").arg(fname),
|
insilmaril@395
|
1590 |
QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
|
insilmaril@395
|
1591 |
else
|
insilmaril@395
|
1592 |
saveStateChangingPart(
|
insilmaril@424
|
1593 |
bo,
|
insilmaril@424
|
1594 |
bo,
|
insilmaril@395
|
1595 |
QString("addMapReplace(%1)").arg(fname),
|
insilmaril@395
|
1596 |
QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
|
insilmaril@0
|
1597 |
}
|
insilmaril@0
|
1598 |
|
insilmaril@676
|
1599 |
|
insilmaril@676
|
1600 |
// Create temporary directory for packing
|
insilmaril@676
|
1601 |
bool ok;
|
insilmaril@676
|
1602 |
QString tmpZipDir=makeTmpDir (ok,"vym-pack");
|
insilmaril@676
|
1603 |
if (!ok)
|
insilmaril@676
|
1604 |
{
|
insilmaril@676
|
1605 |
QMessageBox::critical( 0, tr( "Critical Load Error" ),
|
insilmaril@676
|
1606 |
tr("Couldn't create temporary directory before load\n"));
|
insilmaril@676
|
1607 |
return aborted;
|
insilmaril@676
|
1608 |
}
|
insilmaril@676
|
1609 |
|
insilmaril@676
|
1610 |
// Try to unzip file
|
insilmaril@676
|
1611 |
err=unzipDir (tmpZipDir,fname);
|
insilmaril@676
|
1612 |
QString xmlfile;
|
insilmaril@676
|
1613 |
if (err==nozip)
|
insilmaril@676
|
1614 |
{
|
insilmaril@676
|
1615 |
xmlfile=fname;
|
insilmaril@676
|
1616 |
zipped=false;
|
insilmaril@676
|
1617 |
} else
|
insilmaril@676
|
1618 |
{
|
insilmaril@676
|
1619 |
zipped=true;
|
insilmaril@676
|
1620 |
|
insilmaril@676
|
1621 |
// Look for mapname.xml
|
insilmaril@676
|
1622 |
xmlfile= fname.left(fname.findRev(".",-1,true));
|
insilmaril@676
|
1623 |
xmlfile=xmlfile.section( '/', -1 );
|
insilmaril@676
|
1624 |
QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
|
insilmaril@676
|
1625 |
if (!mfile.exists() )
|
insilmaril@676
|
1626 |
{
|
insilmaril@676
|
1627 |
// mapname.xml does not exist, well,
|
insilmaril@676
|
1628 |
// maybe someone renamed the mapname.vym file...
|
insilmaril@676
|
1629 |
// Try to find any .xml in the toplevel
|
insilmaril@676
|
1630 |
// directory of the .vym file
|
insilmaril@676
|
1631 |
QStringList flist=QDir (tmpZipDir).entryList("*.xml");
|
insilmaril@676
|
1632 |
if (flist.count()==1)
|
insilmaril@676
|
1633 |
{
|
insilmaril@676
|
1634 |
// Only one entry, take this one
|
insilmaril@676
|
1635 |
xmlfile=tmpZipDir + "/"+flist.first();
|
insilmaril@676
|
1636 |
} else
|
insilmaril@676
|
1637 |
{
|
insilmaril@676
|
1638 |
for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
|
insilmaril@676
|
1639 |
*it=tmpZipDir + "/" + *it;
|
insilmaril@676
|
1640 |
// TODO Multiple entries, load all (but only the first one into this ME)
|
insilmaril@676
|
1641 |
//mainWindow->fileLoadFromTmp (flist);
|
insilmaril@676
|
1642 |
//returnCode=1; // Silently forget this attempt to load
|
insilmaril@676
|
1643 |
qWarning ("MainWindow::load (fn) multimap found...");
|
insilmaril@676
|
1644 |
}
|
insilmaril@676
|
1645 |
|
insilmaril@676
|
1646 |
if (flist.isEmpty() )
|
insilmaril@676
|
1647 |
{
|
insilmaril@676
|
1648 |
QMessageBox::critical( 0, tr( "Critical Load Error" ),
|
insilmaril@676
|
1649 |
tr("Couldn't find a map (*.xml) in .vym archive.\n"));
|
insilmaril@676
|
1650 |
err=aborted;
|
insilmaril@676
|
1651 |
}
|
insilmaril@676
|
1652 |
} //file doesn't exist
|
insilmaril@676
|
1653 |
else
|
insilmaril@676
|
1654 |
xmlfile=mfile.name();
|
insilmaril@676
|
1655 |
}
|
insilmaril@676
|
1656 |
|
insilmaril@676
|
1657 |
QFile file( xmlfile);
|
insilmaril@0
|
1658 |
|
insilmaril@0
|
1659 |
// I am paranoid: file should exist anyway
|
insilmaril@0
|
1660 |
// according to check in mainwindow.
|
insilmaril@0
|
1661 |
if (!file.exists() )
|
insilmaril@0
|
1662 |
{
|
insilmaril@0
|
1663 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@676
|
1664 |
tr(QString("Couldn't open map %1").arg(file.name())));
|
insilmaril@205
|
1665 |
err=aborted;
|
insilmaril@0
|
1666 |
} else
|
insilmaril@0
|
1667 |
{
|
insilmaril@473
|
1668 |
bool blockSaveStateOrg=blockSaveState;
|
insilmaril@139
|
1669 |
blockReposition=true;
|
insilmaril@473
|
1670 |
blockSaveState=true;
|
insilmaril@0
|
1671 |
QXmlInputSource source( file);
|
insilmaril@0
|
1672 |
QXmlSimpleReader reader;
|
insilmaril@571
|
1673 |
reader.setContentHandler( handler );
|
insilmaril@571
|
1674 |
reader.setErrorHandler( handler );
|
insilmaril@645
|
1675 |
handler->setModel ( model);
|
insilmaril@494
|
1676 |
|
insilmaril@494
|
1677 |
|
insilmaril@494
|
1678 |
// We need to set the tmpDir in order to load files with rel. path
|
insilmaril@680
|
1679 |
QString tmpdir;
|
insilmaril@680
|
1680 |
if (zipped)
|
insilmaril@680
|
1681 |
tmpdir=tmpZipDir;
|
insilmaril@680
|
1682 |
else
|
insilmaril@680
|
1683 |
tmpdir=fname.left(fname.findRev("/",-1));
|
insilmaril@571
|
1684 |
handler->setTmpDir (tmpdir);
|
insilmaril@571
|
1685 |
handler->setInputFile (file.name());
|
insilmaril@571
|
1686 |
handler->setLoadMode (lmode);
|
insilmaril@0
|
1687 |
bool ok = reader.parse( source );
|
insilmaril@139
|
1688 |
blockReposition=false;
|
insilmaril@473
|
1689 |
blockSaveState=blockSaveStateOrg;
|
insilmaril@0
|
1690 |
file.close();
|
insilmaril@0
|
1691 |
if ( ok )
|
insilmaril@0
|
1692 |
{
|
insilmaril@676
|
1693 |
model->reposition(); // FIXME reposition the view instead...
|
insilmaril@442
|
1694 |
xelection.update();
|
insilmaril@0
|
1695 |
if (lmode==NewMap)
|
insilmaril@0
|
1696 |
{
|
insilmaril@0
|
1697 |
mapDefault=false;
|
insilmaril@0
|
1698 |
mapChanged=false;
|
insilmaril@0
|
1699 |
mapUnsaved=false;
|
insilmaril@473
|
1700 |
autosaveTimer->stop();
|
insilmaril@0
|
1701 |
}
|
insilmaril@676
|
1702 |
|
insilmaril@676
|
1703 |
// Reset timestamp to check for later updates of file
|
insilmaril@676
|
1704 |
fileChangedTime=QFileInfo (destPath).lastModified();
|
insilmaril@0
|
1705 |
} else
|
insilmaril@0
|
1706 |
{
|
insilmaril@0
|
1707 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@571
|
1708 |
tr( handler->errorProtocol() ) );
|
insilmaril@0
|
1709 |
// returnCode=1;
|
insilmaril@0
|
1710 |
// Still return "success": the map maybe at least
|
insilmaril@0
|
1711 |
// partially read by the parser
|
insilmaril@0
|
1712 |
}
|
insilmaril@0
|
1713 |
}
|
insilmaril@676
|
1714 |
|
insilmaril@680
|
1715 |
// Delete tmpZipDir
|
insilmaril@676
|
1716 |
removeDir (QDir(tmpZipDir));
|
insilmaril@676
|
1717 |
|
insilmaril@0
|
1718 |
updateActions();
|
insilmaril@680
|
1719 |
|
insilmaril@205
|
1720 |
return err;
|
insilmaril@0
|
1721 |
}
|
insilmaril@0
|
1722 |
|
insilmaril@676
|
1723 |
ErrorCode MapEditor::save (const SaveMode &savemode)
|
insilmaril@676
|
1724 |
{
|
insilmaril@676
|
1725 |
QString tmpZipDir;
|
insilmaril@676
|
1726 |
QString mapFileName;
|
insilmaril@676
|
1727 |
QString safeFilePath;
|
insilmaril@676
|
1728 |
|
insilmaril@676
|
1729 |
ErrorCode err=success;
|
insilmaril@676
|
1730 |
|
insilmaril@676
|
1731 |
if (zipped)
|
insilmaril@0
|
1732 |
// save as .xml
|
insilmaril@676
|
1733 |
mapFileName=mapName+".xml";
|
insilmaril@0
|
1734 |
else
|
insilmaril@0
|
1735 |
// use name given by user, even if he chooses .doc
|
insilmaril@676
|
1736 |
mapFileName=fileName;
|
insilmaril@676
|
1737 |
|
insilmaril@676
|
1738 |
// Look, if we should zip the data:
|
insilmaril@676
|
1739 |
if (!zipped)
|
insilmaril@676
|
1740 |
{
|
insilmaril@676
|
1741 |
QMessageBox mb( vymName,
|
insilmaril@676
|
1742 |
tr("The map %1\ndid not use the compressed "
|
insilmaril@676
|
1743 |
"vym file format.\nWriting it uncompressed will also write images \n"
|
insilmaril@676
|
1744 |
"and flags and thus may overwrite files in the "
|
insilmaril@676
|
1745 |
"given directory\n\nDo you want to write the map").arg(filePath),
|
insilmaril@676
|
1746 |
QMessageBox::Warning,
|
insilmaril@676
|
1747 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@676
|
1748 |
QMessageBox::No ,
|
insilmaril@676
|
1749 |
QMessageBox::Cancel | QMessageBox::Escape);
|
insilmaril@676
|
1750 |
mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
|
insilmaril@676
|
1751 |
mb.setButtonText( QMessageBox::No, tr("uncompressed") );
|
insilmaril@676
|
1752 |
mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
|
insilmaril@676
|
1753 |
switch( mb.exec() )
|
insilmaril@676
|
1754 |
{
|
insilmaril@676
|
1755 |
case QMessageBox::Yes:
|
insilmaril@676
|
1756 |
// save compressed (default file format)
|
insilmaril@676
|
1757 |
zipped=true;
|
insilmaril@676
|
1758 |
break;
|
insilmaril@676
|
1759 |
case QMessageBox::No:
|
insilmaril@676
|
1760 |
// save uncompressed
|
insilmaril@676
|
1761 |
zipped=false;
|
insilmaril@676
|
1762 |
break;
|
insilmaril@676
|
1763 |
case QMessageBox::Cancel:
|
insilmaril@676
|
1764 |
// do nothing
|
insilmaril@676
|
1765 |
return aborted;
|
insilmaril@676
|
1766 |
break;
|
insilmaril@676
|
1767 |
}
|
insilmaril@676
|
1768 |
}
|
insilmaril@676
|
1769 |
|
insilmaril@676
|
1770 |
// First backup existing file, we
|
insilmaril@676
|
1771 |
// don't want to add to old zip archives
|
insilmaril@676
|
1772 |
QFile f(destPath);
|
insilmaril@676
|
1773 |
if (f.exists())
|
insilmaril@676
|
1774 |
{
|
insilmaril@676
|
1775 |
if ( settings.value ("/mapeditor/writeBackupFile").toBool())
|
insilmaril@676
|
1776 |
{
|
insilmaril@676
|
1777 |
QString backupFileName(destPath + "~");
|
insilmaril@676
|
1778 |
QFile backupFile(backupFileName);
|
insilmaril@676
|
1779 |
if (backupFile.exists() && !backupFile.remove())
|
insilmaril@676
|
1780 |
{
|
insilmaril@676
|
1781 |
QMessageBox::warning(0, tr("Save Error"),
|
insilmaril@676
|
1782 |
tr("%1\ncould not be removed before saving").arg(backupFileName));
|
insilmaril@676
|
1783 |
}
|
insilmaril@676
|
1784 |
else if (!f.rename(backupFileName))
|
insilmaril@676
|
1785 |
{
|
insilmaril@676
|
1786 |
QMessageBox::warning(0, tr("Save Error"),
|
insilmaril@676
|
1787 |
tr("%1\ncould not be renamed before saving").arg(destPath));
|
insilmaril@676
|
1788 |
}
|
insilmaril@676
|
1789 |
}
|
insilmaril@676
|
1790 |
}
|
insilmaril@676
|
1791 |
|
insilmaril@676
|
1792 |
if (zipped)
|
insilmaril@676
|
1793 |
{
|
insilmaril@676
|
1794 |
// Create temporary directory for packing
|
insilmaril@676
|
1795 |
bool ok;
|
insilmaril@676
|
1796 |
tmpZipDir=makeTmpDir (ok,"vym-zip");
|
insilmaril@676
|
1797 |
if (!ok)
|
insilmaril@676
|
1798 |
{
|
insilmaril@676
|
1799 |
QMessageBox::critical( 0, tr( "Critical Load Error" ),
|
insilmaril@676
|
1800 |
tr("Couldn't create temporary directory before save\n"));
|
insilmaril@676
|
1801 |
return aborted;
|
insilmaril@676
|
1802 |
}
|
insilmaril@676
|
1803 |
|
insilmaril@676
|
1804 |
safeFilePath=filePath;
|
insilmaril@676
|
1805 |
setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
|
insilmaril@676
|
1806 |
} // zipped
|
insilmaril@0
|
1807 |
|
insilmaril@680
|
1808 |
// Create mapName and fileDir
|
insilmaril@680
|
1809 |
makeSubDirs (fileDir);
|
insilmaril@680
|
1810 |
|
insilmaril@0
|
1811 |
QString saveFile;
|
insilmaril@424
|
1812 |
if (savemode==CompleteMap || xelection.isEmpty())
|
insilmaril@629
|
1813 |
{
|
insilmaril@629
|
1814 |
// Save complete map
|
insilmaril@408
|
1815 |
saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
|
insilmaril@629
|
1816 |
mapChanged=false;
|
insilmaril@629
|
1817 |
mapUnsaved=false;
|
insilmaril@629
|
1818 |
autosaveTimer->stop();
|
insilmaril@629
|
1819 |
}
|
insilmaril@106
|
1820 |
else
|
insilmaril@491
|
1821 |
{
|
insilmaril@629
|
1822 |
// Save part of map
|
insilmaril@491
|
1823 |
if (xelection.type()==Selection::FloatImage)
|
insilmaril@491
|
1824 |
saveFloatImage();
|
insilmaril@491
|
1825 |
else
|
insilmaril@491
|
1826 |
saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch());
|
insilmaril@629
|
1827 |
// TODO take care of multiselections
|
insilmaril@491
|
1828 |
}
|
insilmaril@0
|
1829 |
|
insilmaril@676
|
1830 |
if (!saveStringToDisk(fileDir+mapFileName,saveFile))
|
insilmaril@676
|
1831 |
{
|
insilmaril@676
|
1832 |
err=aborted;
|
insilmaril@676
|
1833 |
qWarning ("ME::saveStringToDisk failed!");
|
insilmaril@676
|
1834 |
}
|
insilmaril@676
|
1835 |
|
insilmaril@676
|
1836 |
if (zipped)
|
insilmaril@676
|
1837 |
{
|
insilmaril@676
|
1838 |
// zip
|
insilmaril@676
|
1839 |
if (err==success) err=zipDir (tmpZipDir,destPath);
|
insilmaril@676
|
1840 |
|
insilmaril@676
|
1841 |
// Delete tmpDir
|
insilmaril@676
|
1842 |
removeDir (QDir(tmpZipDir));
|
insilmaril@676
|
1843 |
|
insilmaril@676
|
1844 |
// Restore original filepath outside of tmp zip dir
|
insilmaril@676
|
1845 |
setFilePath (safeFilePath);
|
insilmaril@676
|
1846 |
}
|
insilmaril@0
|
1847 |
|
insilmaril@531
|
1848 |
updateActions();
|
insilmaril@676
|
1849 |
fileChangedTime=QFileInfo (destPath).lastModified();
|
insilmaril@676
|
1850 |
return err;
|
insilmaril@0
|
1851 |
}
|
insilmaril@0
|
1852 |
|
insilmaril@0
|
1853 |
|
insilmaril@0
|
1854 |
void MapEditor::print()
|
insilmaril@0
|
1855 |
{
|
insilmaril@0
|
1856 |
if ( !printer )
|
insilmaril@0
|
1857 |
{
|
insilmaril@0
|
1858 |
printer = new QPrinter;
|
insilmaril@0
|
1859 |
printer->setColorMode (QPrinter::Color);
|
insilmaril@366
|
1860 |
printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
|
insilmaril@412
|
1861 |
printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
|
insilmaril@412
|
1862 |
printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
|
insilmaril@0
|
1863 |
}
|
insilmaril@0
|
1864 |
|
insilmaril@645
|
1865 |
QRectF totalBBox=model->getTotalBBox();
|
insilmaril@0
|
1866 |
|
insilmaril@0
|
1867 |
// Try to set orientation automagically
|
insilmaril@0
|
1868 |
// Note: Interpretation of generated postscript is amibiguous, if
|
insilmaril@0
|
1869 |
// there are problems with landscape mode, see
|
insilmaril@0
|
1870 |
// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
|
insilmaril@0
|
1871 |
|
insilmaril@0
|
1872 |
if (totalBBox.width()>totalBBox.height())
|
insilmaril@0
|
1873 |
// recommend landscape
|
insilmaril@0
|
1874 |
printer->setOrientation (QPrinter::Landscape);
|
insilmaril@0
|
1875 |
else
|
insilmaril@0
|
1876 |
// recommend portrait
|
insilmaril@0
|
1877 |
printer->setOrientation (QPrinter::Portrait);
|
insilmaril@0
|
1878 |
|
insilmaril@0
|
1879 |
if ( printer->setup(this) )
|
insilmaril@0
|
1880 |
// returns false, if printing is canceled
|
insilmaril@0
|
1881 |
{
|
insilmaril@0
|
1882 |
QPainter pp(printer);
|
insilmaril@0
|
1883 |
|
insilmaril@412
|
1884 |
pp.setRenderHint(QPainter::Antialiasing,true);
|
insilmaril@412
|
1885 |
|
insilmaril@0
|
1886 |
// Don't print the visualisation of selection
|
insilmaril@424
|
1887 |
xelection.unselect();
|
insilmaril@0
|
1888 |
|
insilmaril@408
|
1889 |
QRectF mapRect=totalBBox;
|
insilmaril@411
|
1890 |
QGraphicsRectItem *frame=NULL;
|
insilmaril@412
|
1891 |
|
insilmaril@417
|
1892 |
if (printFrame)
|
insilmaril@0
|
1893 |
{
|
insilmaril@417
|
1894 |
// Print frame around map
|
insilmaril@417
|
1895 |
mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
|
insilmaril@417
|
1896 |
totalBBox.width()+20, totalBBox.height()+20);
|
insilmaril@417
|
1897 |
frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
|
insilmaril@417
|
1898 |
frame->setZValue(0);
|
insilmaril@417
|
1899 |
frame->show();
|
insilmaril@417
|
1900 |
}
|
insilmaril@417
|
1901 |
|
insilmaril@417
|
1902 |
|
insilmaril@412
|
1903 |
double paperAspect = (double)printer->width() / (double)printer->height();
|
insilmaril@412
|
1904 |
double mapAspect = (double)mapRect.width() / (double)mapRect.height();
|
insilmaril@417
|
1905 |
int viewBottom;
|
insilmaril@0
|
1906 |
if (mapAspect>=paperAspect)
|
insilmaril@0
|
1907 |
{
|
insilmaril@0
|
1908 |
// Fit horizontally to paper width
|
insilmaril@417
|
1909 |
//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
|
insilmaril@417
|
1910 |
viewBottom=(int)(printer->width()/mapAspect);
|
insilmaril@0
|
1911 |
} else
|
insilmaril@0
|
1912 |
{
|
insilmaril@0
|
1913 |
// Fit vertically to paper height
|
insilmaril@417
|
1914 |
//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
|
insilmaril@417
|
1915 |
viewBottom=printer->height();
|
insilmaril@0
|
1916 |
}
|
insilmaril@417
|
1917 |
|
insilmaril@417
|
1918 |
if (printFooter)
|
insilmaril@417
|
1919 |
{
|
insilmaril@417
|
1920 |
// Print footer below map
|
insilmaril@417
|
1921 |
QFont font;
|
insilmaril@417
|
1922 |
font.setPointSize(10);
|
insilmaril@417
|
1923 |
pp.setFont (font);
|
insilmaril@417
|
1924 |
QRectF footerBox(0,viewBottom,printer->width(),15);
|
insilmaril@417
|
1925 |
pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
|
insilmaril@417
|
1926 |
pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
|
insilmaril@417
|
1927 |
}
|
insilmaril@412
|
1928 |
mapScene->render (
|
insilmaril@412
|
1929 |
&pp,
|
insilmaril@412
|
1930 |
QRectF (0,0,printer->width(),printer->height()-15),
|
insilmaril@412
|
1931 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
|
insilmaril@412
|
1932 |
);
|
insilmaril@412
|
1933 |
|
insilmaril@412
|
1934 |
// Viewport has paper dimension
|
insilmaril@412
|
1935 |
if (frame) delete (frame);
|
insilmaril@0
|
1936 |
|
insilmaril@0
|
1937 |
// Restore selection
|
insilmaril@424
|
1938 |
xelection.reselect();
|
insilmaril@119
|
1939 |
|
insilmaril@119
|
1940 |
// Save settings in vymrc
|
insilmaril@366
|
1941 |
settings.writeEntry("/mainwindow/printerName",printer->printerName());
|
insilmaril@412
|
1942 |
settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
|
insilmaril@412
|
1943 |
settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
|
insilmaril@0
|
1944 |
}
|
insilmaril@0
|
1945 |
}
|
insilmaril@0
|
1946 |
|
insilmaril@408
|
1947 |
void MapEditor::setAntiAlias (bool b)
|
insilmaril@408
|
1948 |
{
|
insilmaril@408
|
1949 |
setRenderHint(QPainter::Antialiasing,b);
|
insilmaril@408
|
1950 |
}
|
insilmaril@408
|
1951 |
|
insilmaril@408
|
1952 |
void MapEditor::setSmoothPixmap(bool b)
|
insilmaril@408
|
1953 |
{
|
insilmaril@408
|
1954 |
setRenderHint(QPainter::SmoothPixmapTransform,b);
|
insilmaril@408
|
1955 |
}
|
insilmaril@408
|
1956 |
|
insilmaril@0
|
1957 |
QPixmap MapEditor::getPixmap()
|
insilmaril@0
|
1958 |
{
|
insilmaril@645
|
1959 |
QRectF mapRect=model->getTotalBBox();
|
insilmaril@564
|
1960 |
QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
|
insilmaril@0
|
1961 |
QPainter pp (&pix);
|
insilmaril@420
|
1962 |
|
insilmaril@420
|
1963 |
pp.setRenderHints(renderHints());
|
insilmaril@0
|
1964 |
|
insilmaril@0
|
1965 |
// Don't print the visualisation of selection
|
insilmaril@424
|
1966 |
xelection.unselect();
|
insilmaril@0
|
1967 |
|
insilmaril@420
|
1968 |
mapScene->render ( &pp,
|
insilmaril@450
|
1969 |
QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
|
insilmaril@420
|
1970 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
|
insilmaril@420
|
1971 |
|
insilmaril@0
|
1972 |
// Restore selection
|
insilmaril@424
|
1973 |
xelection.reselect();
|
insilmaril@0
|
1974 |
|
insilmaril@0
|
1975 |
return pix;
|
insilmaril@0
|
1976 |
}
|
insilmaril@0
|
1977 |
|
insilmaril@628
|
1978 |
void MapEditor::setHideTmpMode (HideTmpMode mode)
|
insilmaril@260
|
1979 |
{
|
insilmaril@260
|
1980 |
hidemode=mode;
|
insilmaril@645
|
1981 |
model->setHideTmp (hidemode);
|
insilmaril@645
|
1982 |
model->reposition();
|
insilmaril@408
|
1983 |
scene()->update();
|
insilmaril@260
|
1984 |
}
|
insilmaril@260
|
1985 |
|
insilmaril@628
|
1986 |
HideTmpMode MapEditor::getHideTmpMode()
|
insilmaril@260
|
1987 |
{
|
insilmaril@260
|
1988 |
return hidemode;
|
insilmaril@260
|
1989 |
}
|
insilmaril@260
|
1990 |
|
insilmaril@260
|
1991 |
void MapEditor::setExportMode (bool b)
|
insilmaril@260
|
1992 |
{
|
insilmaril@260
|
1993 |
// should be called before and after exports
|
insilmaril@260
|
1994 |
// depending on the settings
|
insilmaril@600
|
1995 |
if (b && settings.value("/export/useHideExport","true")=="true")
|
insilmaril@628
|
1996 |
setHideTmpMode (HideExport);
|
insilmaril@260
|
1997 |
else
|
insilmaril@628
|
1998 |
setHideTmpMode (HideNone);
|
insilmaril@0
|
1999 |
}
|
insilmaril@0
|
2000 |
|
insilmaril@514
|
2001 |
void MapEditor::exportASCII(QString fname,bool askName)
|
insilmaril@0
|
2002 |
{
|
insilmaril@514
|
2003 |
ExportASCII ex;
|
insilmaril@645
|
2004 |
ex.setModel (model);
|
insilmaril@514
|
2005 |
if (fname=="")
|
insilmaril@514
|
2006 |
ex.setFile (mapName+".txt");
|
insilmaril@514
|
2007 |
else
|
insilmaril@514
|
2008 |
ex.setFile (fname);
|
insilmaril@514
|
2009 |
|
insilmaril@514
|
2010 |
if (askName)
|
insilmaril@514
|
2011 |
{
|
insilmaril@514
|
2012 |
//ex.addFilter ("TXT (*.txt)");
|
insilmaril@514
|
2013 |
ex.setDir(lastImageDir);
|
insilmaril@514
|
2014 |
//ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
|
insilmaril@514
|
2015 |
ex.execDialog() ;
|
insilmaril@514
|
2016 |
}
|
insilmaril@514
|
2017 |
if (!ex.canceled())
|
insilmaril@514
|
2018 |
{
|
insilmaril@514
|
2019 |
setExportMode(true);
|
insilmaril@514
|
2020 |
ex.doExport();
|
insilmaril@514
|
2021 |
setExportMode(false);
|
insilmaril@514
|
2022 |
}
|
insilmaril@514
|
2023 |
}
|
insilmaril@514
|
2024 |
|
insilmaril@514
|
2025 |
void MapEditor::exportImage(QString fname, bool askName, QString format)
|
insilmaril@514
|
2026 |
{
|
insilmaril@514
|
2027 |
if (fname=="")
|
insilmaril@514
|
2028 |
{
|
insilmaril@514
|
2029 |
fname=mapName+".png";
|
insilmaril@514
|
2030 |
format="PNG";
|
insilmaril@514
|
2031 |
}
|
insilmaril@514
|
2032 |
|
insilmaril@514
|
2033 |
if (askName)
|
insilmaril@514
|
2034 |
{
|
insilmaril@514
|
2035 |
QStringList fl;
|
insilmaril@514
|
2036 |
QFileDialog *fd=new QFileDialog (this);
|
insilmaril@514
|
2037 |
fd->setCaption (tr("Export map as image"));
|
insilmaril@514
|
2038 |
fd->setDirectory (lastImageDir);
|
insilmaril@514
|
2039 |
fd->setFileMode(QFileDialog::AnyFile);
|
insilmaril@514
|
2040 |
fd->setFilters (imageIO.getFilters() );
|
insilmaril@514
|
2041 |
if (fd->exec())
|
insilmaril@514
|
2042 |
{
|
insilmaril@514
|
2043 |
fl=fd->selectedFiles();
|
insilmaril@514
|
2044 |
fname=fl.first();
|
insilmaril@514
|
2045 |
format=imageIO.getType(fd->selectedFilter());
|
insilmaril@514
|
2046 |
}
|
insilmaril@514
|
2047 |
}
|
insilmaril@514
|
2048 |
|
insilmaril@260
|
2049 |
setExportMode (true);
|
insilmaril@0
|
2050 |
QPixmap pix (getPixmap());
|
insilmaril@514
|
2051 |
pix.save(fname, format);
|
insilmaril@260
|
2052 |
setExportMode (false);
|
insilmaril@0
|
2053 |
}
|
insilmaril@0
|
2054 |
|
insilmaril@185
|
2055 |
void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
|
insilmaril@163
|
2056 |
{
|
insilmaril@185
|
2057 |
ExportOO ex;
|
insilmaril@199
|
2058 |
ex.setFile (fn);
|
insilmaril@645
|
2059 |
ex.setModel (model);
|
insilmaril@260
|
2060 |
if (ex.setConfigFile(cf))
|
insilmaril@260
|
2061 |
{
|
insilmaril@260
|
2062 |
setExportMode (true);
|
insilmaril@260
|
2063 |
ex.exportPresentation();
|
insilmaril@260
|
2064 |
setExportMode (false);
|
insilmaril@260
|
2065 |
}
|
insilmaril@163
|
2066 |
}
|
insilmaril@163
|
2067 |
|
insilmaril@520
|
2068 |
void MapEditor::exportXHTML (const QString &dir, bool askForName)
|
insilmaril@517
|
2069 |
{
|
insilmaril@517
|
2070 |
ExportXHTMLDialog dia(this);
|
insilmaril@517
|
2071 |
dia.setFilePath (filePath );
|
insilmaril@517
|
2072 |
dia.setMapName (mapName );
|
insilmaril@517
|
2073 |
dia.readSettings();
|
insilmaril@526
|
2074 |
if (dir!="") dia.setDir (dir);
|
insilmaril@517
|
2075 |
|
insilmaril@517
|
2076 |
bool ok=true;
|
insilmaril@517
|
2077 |
|
insilmaril@520
|
2078 |
if (askForName)
|
insilmaril@517
|
2079 |
{
|
insilmaril@517
|
2080 |
if (dia.exec()!=QDialog::Accepted)
|
insilmaril@517
|
2081 |
ok=false;
|
insilmaril@517
|
2082 |
else
|
insilmaril@517
|
2083 |
{
|
insilmaril@517
|
2084 |
QDir d (dia.getDir());
|
insilmaril@517
|
2085 |
// Check, if warnings should be used before overwriting
|
insilmaril@517
|
2086 |
// the output directory
|
insilmaril@517
|
2087 |
if (d.exists() && d.count()>0)
|
insilmaril@517
|
2088 |
{
|
insilmaril@517
|
2089 |
WarningDialog warn;
|
insilmaril@517
|
2090 |
warn.showCancelButton (true);
|
insilmaril@517
|
2091 |
warn.setText(QString(
|
insilmaril@517
|
2092 |
"The directory %1 is not empty.\n"
|
insilmaril@517
|
2093 |
"Do you risk to overwrite some of its contents?").arg(d.path() ));
|
insilmaril@517
|
2094 |
warn.setCaption("Warning: Directory not empty");
|
insilmaril@517
|
2095 |
warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
|
insilmaril@517
|
2096 |
|
insilmaril@517
|
2097 |
if (warn.exec()!=QDialog::Accepted) ok=false;
|
insilmaril@517
|
2098 |
}
|
insilmaril@517
|
2099 |
}
|
insilmaril@517
|
2100 |
}
|
insilmaril@517
|
2101 |
|
insilmaril@517
|
2102 |
if (ok)
|
insilmaril@517
|
2103 |
{
|
insilmaril@526
|
2104 |
exportXML (dia.getDir(),false );
|
insilmaril@517
|
2105 |
dia.doExport(mapName );
|
insilmaril@517
|
2106 |
//if (dia.hasChanged()) setChanged();
|
insilmaril@517
|
2107 |
}
|
insilmaril@517
|
2108 |
}
|
insilmaril@0
|
2109 |
|
insilmaril@526
|
2110 |
void MapEditor::exportXML(QString dir, bool askForName)
|
insilmaril@0
|
2111 |
{
|
insilmaril@526
|
2112 |
if (askForName)
|
insilmaril@526
|
2113 |
{
|
insilmaril@526
|
2114 |
dir=browseDirectory(this,tr("Export XML to directory"));
|
insilmaril@526
|
2115 |
if (dir =="" && !reallyWriteDirectory(dir) )
|
insilmaril@526
|
2116 |
return;
|
insilmaril@526
|
2117 |
}
|
insilmaril@526
|
2118 |
|
insilmaril@260
|
2119 |
// Hide stuff during export, if settings want this
|
insilmaril@260
|
2120 |
setExportMode (true);
|
insilmaril@260
|
2121 |
|
insilmaril@0
|
2122 |
// Create subdirectories
|
insilmaril@0
|
2123 |
makeSubDirs (dir);
|
insilmaril@0
|
2124 |
|
insilmaril@0
|
2125 |
// write to directory
|
insilmaril@645
|
2126 |
QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL);
|
insilmaril@0
|
2127 |
QFile file;
|
insilmaril@0
|
2128 |
|
insilmaril@0
|
2129 |
file.setName ( dir + "/"+mapName+".xml");
|
insilmaril@366
|
2130 |
if ( !file.open( QIODevice::WriteOnly ) )
|
insilmaril@0
|
2131 |
{
|
insilmaril@0
|
2132 |
// This should neverever happen
|
insilmaril@159
|
2133 |
QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
|
insilmaril@0
|
2134 |
return;
|
insilmaril@0
|
2135 |
}
|
insilmaril@0
|
2136 |
|
insilmaril@0
|
2137 |
// Write it finally, and write in UTF8, no matter what
|
insilmaril@0
|
2138 |
QTextStream ts( &file );
|
insilmaril@0
|
2139 |
ts.setEncoding (QTextStream::UnicodeUTF8);
|
insilmaril@0
|
2140 |
ts << saveFile;
|
insilmaril@0
|
2141 |
file.close();
|
insilmaril@0
|
2142 |
|
insilmaril@0
|
2143 |
// Now write image, too
|
insilmaril@517
|
2144 |
exportImage (dir+"/images/"+mapName+".png",false,"PNG");
|
insilmaril@260
|
2145 |
|
insilmaril@260
|
2146 |
setExportMode (false);
|
insilmaril@0
|
2147 |
}
|
insilmaril@0
|
2148 |
|
insilmaril@0
|
2149 |
void MapEditor::clear()
|
insilmaril@0
|
2150 |
{
|
insilmaril@424
|
2151 |
xelection.unselect();
|
insilmaril@645
|
2152 |
model->clear();
|
insilmaril@0
|
2153 |
}
|
insilmaril@0
|
2154 |
|
insilmaril@0
|
2155 |
void MapEditor::copy()
|
insilmaril@0
|
2156 |
{
|
insilmaril@424
|
2157 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@424
|
2158 |
if (sel)
|
insilmaril@0
|
2159 |
{
|
insilmaril@502
|
2160 |
if (redosAvail == 0)
|
insilmaril@0
|
2161 |
{
|
insilmaril@502
|
2162 |
// Copy to history
|
insilmaril@684
|
2163 |
QString s=model->getSelectString(sel);
|
insilmaril@505
|
2164 |
saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
|
insilmaril@502
|
2165 |
curClipboard=curStep;
|
insilmaril@502
|
2166 |
}
|
insilmaril@502
|
2167 |
|
insilmaril@502
|
2168 |
// Copy also to global clipboard, because we are at last step in history
|
insilmaril@625
|
2169 |
QString bakMapName(QString("history-%1").arg(curStep));
|
insilmaril@625
|
2170 |
QString bakMapDir(tmpMapDir +"/"+bakMapName);
|
insilmaril@502
|
2171 |
copyDir (bakMapDir,clipboardDir );
|
insilmaril@166
|
2172 |
|
insilmaril@166
|
2173 |
clipboardEmpty=false;
|
insilmaril@166
|
2174 |
updateActions();
|
insilmaril@0
|
2175 |
}
|
insilmaril@0
|
2176 |
}
|
insilmaril@0
|
2177 |
|
insilmaril@163
|
2178 |
void MapEditor::redo()
|
insilmaril@163
|
2179 |
{
|
insilmaril@381
|
2180 |
// Can we undo at all?
|
insilmaril@381
|
2181 |
if (redosAvail<1) return;
|
insilmaril@473
|
2182 |
|
insilmaril@473
|
2183 |
bool blockSaveStateOrg=blockSaveState;
|
insilmaril@473
|
2184 |
blockSaveState=true;
|
insilmaril@473
|
2185 |
|
insilmaril@381
|
2186 |
redosAvail--;
|
insilmaril@381
|
2187 |
|
insilmaril@381
|
2188 |
if (undosAvail<stepsTotal) undosAvail++;
|
insilmaril@366
|
2189 |
curStep++;
|
insilmaril@381
|
2190 |
if (curStep>stepsTotal) curStep=1;
|
insilmaril@366
|
2191 |
QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
|
insilmaril@366
|
2192 |
QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
|
insilmaril@366
|
2193 |
QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
|
insilmaril@366
|
2194 |
QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
|
insilmaril@366
|
2195 |
QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
|
insilmaril@395
|
2196 |
QString version=undoSet.readEntry ("/history/version");
|
insilmaril@395
|
2197 |
|
insilmaril@645
|
2198 |
/* TODO Maybe check for version, if we save the history
|
insilmaril@395
|
2199 |
if (!checkVersion(version))
|
insilmaril@395
|
2200 |
QMessageBox::warning(0,tr("Warning"),
|
insilmaril@404
|
2201 |
tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
|
insilmaril@645
|
2202 |
*/
|
insilmaril@366
|
2203 |
|
insilmaril@163
|
2204 |
// Find out current undo directory
|
insilmaril@625
|
2205 |
QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
|
insilmaril@366
|
2206 |
|
insilmaril@473
|
2207 |
if (debug)
|
insilmaril@473
|
2208 |
{
|
insilmaril@473
|
2209 |
cout << "ME::redo() begin\n";
|
insilmaril@473
|
2210 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@473
|
2211 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@473
|
2212 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@473
|
2213 |
cout << " ---------------------------"<<endl;
|
insilmaril@473
|
2214 |
cout << " comment="<<comment.toStdString()<<endl;
|
insilmaril@473
|
2215 |
cout << " undoCom="<<undoCommand.toStdString()<<endl;
|
insilmaril@473
|
2216 |
cout << " undoSel="<<undoSelection.toStdString()<<endl;
|
insilmaril@473
|
2217 |
cout << " redoCom="<<redoCommand.toStdString()<<endl;
|
insilmaril@473
|
2218 |
cout << " redoSel="<<redoSelection.toStdString()<<endl;
|
insilmaril@473
|
2219 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@473
|
2220 |
}
|
insilmaril@163
|
2221 |
|
insilmaril@163
|
2222 |
// select object before redo
|
insilmaril@163
|
2223 |
if (!redoSelection.isEmpty())
|
insilmaril@163
|
2224 |
select (redoSelection);
|
insilmaril@163
|
2225 |
|
insilmaril@366
|
2226 |
|
insilmaril@366
|
2227 |
parseAtom (redoCommand);
|
insilmaril@645
|
2228 |
model->reposition();
|
insilmaril@366
|
2229 |
|
insilmaril@473
|
2230 |
blockSaveState=blockSaveStateOrg;
|
insilmaril@366
|
2231 |
|
insilmaril@366
|
2232 |
undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
|
insilmaril@366
|
2233 |
undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
|
insilmaril@366
|
2234 |
undoSet.setEntry ("/history/curStep",QString::number(curStep));
|
insilmaril@366
|
2235 |
undoSet.writeSettings(histPath);
|
insilmaril@366
|
2236 |
|
insilmaril@408
|
2237 |
mainWindow->updateHistory (undoSet);
|
insilmaril@407
|
2238 |
updateActions();
|
insilmaril@366
|
2239 |
|
insilmaril@366
|
2240 |
/* TODO remove testing
|
insilmaril@163
|
2241 |
cout << "ME::redo() end\n";
|
insilmaril@163
|
2242 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@366
|
2243 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@366
|
2244 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@163
|
2245 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@404
|
2246 |
*/
|
insilmaril@366
|
2247 |
|
insilmaril@366
|
2248 |
|
insilmaril@163
|
2249 |
}
|
insilmaril@163
|
2250 |
|
insilmaril@390
|
2251 |
bool MapEditor::isRedoAvailable()
|
insilmaril@390
|
2252 |
{
|
insilmaril@393
|
2253 |
if (undoSet.readNumEntry("/history/redosAvail",0)>0)
|
insilmaril@390
|
2254 |
return true;
|
insilmaril@390
|
2255 |
else
|
insilmaril@390
|
2256 |
return false;
|
insilmaril@390
|
2257 |
}
|
insilmaril@390
|
2258 |
|
insilmaril@106
|
2259 |
void MapEditor::undo()
|
insilmaril@106
|
2260 |
{
|
insilmaril@381
|
2261 |
// Can we undo at all?
|
insilmaril@381
|
2262 |
if (undosAvail<1) return;
|
insilmaril@381
|
2263 |
|
insilmaril@502
|
2264 |
mainWindow->statusMessage (tr("Autosave disabled during undo."));
|
insilmaril@502
|
2265 |
|
insilmaril@473
|
2266 |
bool blockSaveStateOrg=blockSaveState;
|
insilmaril@473
|
2267 |
blockSaveState=true;
|
insilmaril@473
|
2268 |
|
insilmaril@366
|
2269 |
QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
|
insilmaril@366
|
2270 |
QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
|
insilmaril@366
|
2271 |
QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
|
insilmaril@366
|
2272 |
QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
|
insilmaril@366
|
2273 |
QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
|
insilmaril@395
|
2274 |
QString version=undoSet.readEntry ("/history/version");
|
insilmaril@395
|
2275 |
|
insilmaril@645
|
2276 |
/* TODO Maybe check for version, if we save the history
|
insilmaril@395
|
2277 |
if (!checkVersion(version))
|
insilmaril@395
|
2278 |
QMessageBox::warning(0,tr("Warning"),
|
insilmaril@404
|
2279 |
tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
|
insilmaril@645
|
2280 |
*/
|
insilmaril@366
|
2281 |
|
insilmaril@163
|
2282 |
// Find out current undo directory
|
insilmaril@625
|
2283 |
QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
|
insilmaril@163
|
2284 |
|
insilmaril@136
|
2285 |
// select object before undo
|
insilmaril@136
|
2286 |
if (!undoSelection.isEmpty())
|
insilmaril@136
|
2287 |
select (undoSelection);
|
insilmaril@136
|
2288 |
|
insilmaril@473
|
2289 |
if (debug)
|
insilmaril@473
|
2290 |
{
|
insilmaril@473
|
2291 |
cout << "ME::undo() begin\n";
|
insilmaril@473
|
2292 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@473
|
2293 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@473
|
2294 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@473
|
2295 |
cout << " ---------------------------"<<endl;
|
insilmaril@473
|
2296 |
cout << " comment="<<comment.toStdString()<<endl;
|
insilmaril@473
|
2297 |
cout << " undoCom="<<undoCommand.toStdString()<<endl;
|
insilmaril@473
|
2298 |
cout << " undoSel="<<undoSelection.toStdString()<<endl;
|
insilmaril@473
|
2299 |
cout << " redoCom="<<redoCommand.toStdString()<<endl;
|
insilmaril@473
|
2300 |
cout << " redoSel="<<redoSelection.toStdString()<<endl;
|
insilmaril@473
|
2301 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@473
|
2302 |
}
|
insilmaril@106
|
2303 |
parseAtom (undoCommand);
|
insilmaril@645
|
2304 |
model->reposition();
|
insilmaril@106
|
2305 |
|
insilmaril@163
|
2306 |
undosAvail--;
|
insilmaril@366
|
2307 |
curStep--;
|
insilmaril@381
|
2308 |
if (curStep<1) curStep=stepsTotal;
|
insilmaril@366
|
2309 |
|
insilmaril@366
|
2310 |
redosAvail++;
|
insilmaril@163
|
2311 |
|
insilmaril@473
|
2312 |
blockSaveState=blockSaveStateOrg;
|
insilmaril@163
|
2313 |
/* TODO remove testing
|
insilmaril@163
|
2314 |
cout << "ME::undo() end\n";
|
insilmaril@163
|
2315 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@366
|
2316 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@366
|
2317 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@163
|
2318 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@404
|
2319 |
*/
|
insilmaril@366
|
2320 |
|
insilmaril@366
|
2321 |
undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
|
insilmaril@366
|
2322 |
undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
|
insilmaril@366
|
2323 |
undoSet.setEntry ("/history/curStep",QString::number(curStep));
|
insilmaril@366
|
2324 |
undoSet.writeSettings(histPath);
|
insilmaril@366
|
2325 |
|
insilmaril@404
|
2326 |
mainWindow->updateHistory (undoSet);
|
insilmaril@366
|
2327 |
updateActions();
|
insilmaril@442
|
2328 |
xelection.update();
|
insilmaril@420
|
2329 |
ensureSelectionVisible();
|
insilmaril@106
|
2330 |
}
|
insilmaril@106
|
2331 |
|
insilmaril@390
|
2332 |
bool MapEditor::isUndoAvailable()
|
insilmaril@390
|
2333 |
{
|
insilmaril@390
|
2334 |
if (undoSet.readNumEntry("/history/undosAvail",0)>0)
|
insilmaril@390
|
2335 |
return true;
|
insilmaril@390
|
2336 |
else
|
insilmaril@390
|
2337 |
return false;
|
insilmaril@390
|
2338 |
}
|
insilmaril@390
|
2339 |
|
insilmaril@404
|
2340 |
void MapEditor::gotoHistoryStep (int i)
|
insilmaril@381
|
2341 |
{
|
insilmaril@381
|
2342 |
// Restore variables
|
insilmaril@381
|
2343 |
int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
|
insilmaril@388
|
2344 |
int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
|
insilmaril@388
|
2345 |
|
insilmaril@388
|
2346 |
if (i<0) i=undosAvail+redosAvail;
|
insilmaril@388
|
2347 |
|
insilmaril@388
|
2348 |
// Clicking above current step makes us undo things
|
insilmaril@381
|
2349 |
if (i<undosAvail)
|
insilmaril@381
|
2350 |
{
|
insilmaril@381
|
2351 |
for (int j=0; j<undosAvail-i; j++) undo();
|
insilmaril@381
|
2352 |
return;
|
insilmaril@381
|
2353 |
}
|
insilmaril@388
|
2354 |
// Clicking below current step makes us redo things
|
insilmaril@381
|
2355 |
if (i>undosAvail)
|
insilmaril@491
|
2356 |
for (int j=undosAvail; j<i; j++)
|
insilmaril@491
|
2357 |
{
|
insilmaril@491
|
2358 |
cout << "redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
|
insilmaril@491
|
2359 |
redo();
|
insilmaril@491
|
2360 |
}
|
insilmaril@381
|
2361 |
|
insilmaril@381
|
2362 |
// And ignore clicking the current row ;-)
|
insilmaril@381
|
2363 |
}
|
insilmaril@381
|
2364 |
|
insilmaril@394
|
2365 |
void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
|
insilmaril@106
|
2366 |
{
|
insilmaril@393
|
2367 |
QString pathDir=path.left(path.findRev("/"));
|
insilmaril@393
|
2368 |
QDir d(pathDir);
|
insilmaril@393
|
2369 |
QFile file (path);
|
insilmaril@163
|
2370 |
|
insilmaril@106
|
2371 |
if (d.exists() )
|
insilmaril@106
|
2372 |
{
|
insilmaril@106
|
2373 |
// We need to parse saved XML data
|
insilmaril@564
|
2374 |
parseVYMHandler handler;
|
insilmaril@163
|
2375 |
QXmlInputSource source( file);
|
insilmaril@106
|
2376 |
QXmlSimpleReader reader;
|
insilmaril@106
|
2377 |
reader.setContentHandler( &handler );
|
insilmaril@106
|
2378 |
reader.setErrorHandler( &handler );
|
insilmaril@645
|
2379 |
handler.setModel ( model);
|
insilmaril@393
|
2380 |
handler.setTmpDir ( pathDir ); // needed to load files with rel. path
|
insilmaril@106
|
2381 |
if (undoSel.isEmpty())
|
insilmaril@106
|
2382 |
{
|
insilmaril@139
|
2383 |
unselect();
|
insilmaril@645
|
2384 |
model->clear();
|
insilmaril@106
|
2385 |
handler.setLoadMode (NewMap);
|
insilmaril@106
|
2386 |
} else
|
insilmaril@106
|
2387 |
{
|
insilmaril@106
|
2388 |
select (undoSel);
|
insilmaril@106
|
2389 |
handler.setLoadMode (ImportReplace);
|
insilmaril@106
|
2390 |
}
|
insilmaril@139
|
2391 |
blockReposition=true;
|
insilmaril@106
|
2392 |
bool ok = reader.parse( source );
|
insilmaril@139
|
2393 |
blockReposition=false;
|
insilmaril@106
|
2394 |
if (! ok )
|
insilmaril@106
|
2395 |
{
|
insilmaril@106
|
2396 |
// This should never ever happen
|
insilmaril@393
|
2397 |
QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
|
insilmaril@393
|
2398 |
handler.errorProtocol());
|
insilmaril@106
|
2399 |
}
|
insilmaril@106
|
2400 |
} else
|
insilmaril@393
|
2401 |
QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
|
insilmaril@393
|
2402 |
}
|
insilmaril@393
|
2403 |
|
insilmaril@394
|
2404 |
void MapEditor::addMapInsertInt (const QString &path, int pos)
|
insilmaril@393
|
2405 |
{
|
insilmaril@424
|
2406 |
BranchObj *sel=xelection.getBranch();
|
insilmaril@608
|
2407 |
if (sel)
|
insilmaril@106
|
2408 |
{
|
insilmaril@393
|
2409 |
QString pathDir=path.left(path.findRev("/"));
|
insilmaril@393
|
2410 |
QDir d(pathDir);
|
insilmaril@393
|
2411 |
QFile file (path);
|
insilmaril@393
|
2412 |
|
insilmaril@393
|
2413 |
if (d.exists() )
|
insilmaril@393
|
2414 |
{
|
insilmaril@393
|
2415 |
// We need to parse saved XML data
|
insilmaril@564
|
2416 |
parseVYMHandler handler;
|
insilmaril@393
|
2417 |
QXmlInputSource source( file);
|
insilmaril@393
|
2418 |
QXmlSimpleReader reader;
|
insilmaril@393
|
2419 |
reader.setContentHandler( &handler );
|
insilmaril@393
|
2420 |
reader.setErrorHandler( &handler );
|
insilmaril@645
|
2421 |
handler.setModel (model);
|
insilmaril@393
|
2422 |
handler.setTmpDir ( pathDir ); // needed to load files with rel. path
|
insilmaril@394
|
2423 |
handler.setLoadMode (ImportAdd);
|
insilmaril@393
|
2424 |
blockReposition=true;
|
insilmaril@393
|
2425 |
bool ok = reader.parse( source );
|
insilmaril@393
|
2426 |
blockReposition=false;
|
insilmaril@393
|
2427 |
if (! ok )
|
insilmaril@393
|
2428 |
{
|
insilmaril@393
|
2429 |
// This should never ever happen
|
insilmaril@393
|
2430 |
QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
|
insilmaril@393
|
2431 |
handler.errorProtocol());
|
insilmaril@393
|
2432 |
}
|
insilmaril@645
|
2433 |
if (sel->getDepth()>0)
|
insilmaril@424
|
2434 |
sel->getLastBranch()->linkTo (sel,pos);
|
insilmaril@393
|
2435 |
} else
|
insilmaril@393
|
2436 |
QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
|
insilmaril@393
|
2437 |
}
|
insilmaril@106
|
2438 |
}
|
insilmaril@106
|
2439 |
|
insilmaril@502
|
2440 |
void MapEditor::pasteNoSave(const int &n)
|
insilmaril@0
|
2441 |
{
|
insilmaril@491
|
2442 |
bool old=blockSaveState;
|
insilmaril@491
|
2443 |
blockSaveState=true;
|
insilmaril@680
|
2444 |
bool zippedOrg=zipped;
|
insilmaril@502
|
2445 |
if (redosAvail > 0 || n!=0)
|
insilmaril@502
|
2446 |
{
|
insilmaril@502
|
2447 |
// Use the "historical" buffer
|
insilmaril@625
|
2448 |
QString bakMapName(QString("history-%1").arg(n));
|
insilmaril@625
|
2449 |
QString bakMapDir(tmpMapDir +"/"+bakMapName);
|
insilmaril@571
|
2450 |
load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
|
insilmaril@502
|
2451 |
} else
|
insilmaril@502
|
2452 |
// Use the global buffer
|
insilmaril@571
|
2453 |
load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
|
insilmaril@680
|
2454 |
zipped=zippedOrg;
|
insilmaril@491
|
2455 |
blockSaveState=old;
|
insilmaril@0
|
2456 |
}
|
insilmaril@0
|
2457 |
|
insilmaril@497
|
2458 |
void MapEditor::paste()
|
insilmaril@0
|
2459 |
{
|
insilmaril@424
|
2460 |
BranchObj *sel=xelection.getBranch();
|
insilmaril@424
|
2461 |
if (sel)
|
insilmaril@166
|
2462 |
{
|
insilmaril@395
|
2463 |
saveStateChangingPart(
|
insilmaril@424
|
2464 |
sel,
|
insilmaril@424
|
2465 |
sel,
|
insilmaril@502
|
2466 |
QString ("paste (%1)").arg(curClipboard),
|
insilmaril@424
|
2467 |
QString("Paste to %1").arg( getName(sel))
|
insilmaril@395
|
2468 |
);
|
insilmaril@502
|
2469 |
pasteNoSave(0);
|
insilmaril@645
|
2470 |
model->reposition();
|
insilmaril@166
|
2471 |
}
|
insilmaril@0
|
2472 |
}
|
insilmaril@0
|
2473 |
|
insilmaril@0
|
2474 |
void MapEditor::cut()
|
insilmaril@0
|
2475 |
{
|
insilmaril@424
|
2476 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@491
|
2477 |
if ( sel && (xelection.type() == Selection::Branch ||
|
insilmaril@491
|
2478 |
xelection.type()==Selection::MapCenter ||
|
insilmaril@491
|
2479 |
xelection.type()==Selection::FloatImage))
|
insilmaril@424
|
2480 |
{
|
insilmaril@491
|
2481 |
/* No savestate! savestate is called in cutNoSave
|
insilmaril@424
|
2482 |
saveStateChangingPart(
|
insilmaril@424
|
2483 |
sel->getParObj(),
|
insilmaril@424
|
2484 |
sel,
|
insilmaril@424
|
2485 |
"cut ()",
|
insilmaril@424
|
2486 |
QString("Cut %1").arg(getName(sel ))
|
insilmaril@424
|
2487 |
);
|
insilmaril@491
|
2488 |
*/
|
insilmaril@424
|
2489 |
copy();
|
insilmaril@491
|
2490 |
deleteSelection();
|
insilmaril@645
|
2491 |
model->reposition();
|
insilmaril@424
|
2492 |
}
|
insilmaril@0
|
2493 |
}
|
insilmaril@0
|
2494 |
|
insilmaril@537
|
2495 |
void MapEditor::move(const double &x, const double &y)
|
insilmaril@130
|
2496 |
{
|
insilmaril@424
|
2497 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@424
|
2498 |
if (sel)
|
insilmaril@366
|
2499 |
{
|
insilmaril@625
|
2500 |
QPointF ap(sel->getAbsPos());
|
insilmaril@625
|
2501 |
QPointF to(x, y);
|
insilmaril@625
|
2502 |
if (ap != to)
|
insilmaril@625
|
2503 |
{
|
insilmaril@625
|
2504 |
QString ps=qpointfToString(ap);
|
insilmaril@684
|
2505 |
QString s=xelection.getSelectString();
|
insilmaril@625
|
2506 |
saveState(
|
insilmaril@625
|
2507 |
s, "move "+ps,
|
insilmaril@625
|
2508 |
s, "move "+qpointfToString(to),
|
insilmaril@625
|
2509 |
QString("Move %1 to %2").arg(getName(sel)).arg(ps));
|
insilmaril@625
|
2510 |
sel->move(x,y);
|
insilmaril@645
|
2511 |
model->reposition();
|
insilmaril@625
|
2512 |
xelection.update();
|
insilmaril@625
|
2513 |
}
|
insilmaril@366
|
2514 |
}
|
insilmaril@366
|
2515 |
}
|
insilmaril@366
|
2516 |
|
insilmaril@537
|
2517 |
void MapEditor::moveRel (const double &x, const double &y)
|
insilmaril@366
|
2518 |
{
|
insilmaril@424
|
2519 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@424
|
2520 |
if (sel)
|
insilmaril@366
|
2521 |
{
|
insilmaril@625
|
2522 |
QPointF rp(sel->getRelPos());
|
insilmaril@625
|
2523 |
QPointF to(x, y);
|
insilmaril@625
|
2524 |
if (rp != to)
|
insilmaril@625
|
2525 |
{
|
insilmaril@625
|
2526 |
QString ps=qpointfToString (sel->getRelPos());
|
insilmaril@684
|
2527 |
QString s=model->getSelectString(sel);
|
insilmaril@625
|
2528 |
saveState(
|
insilmaril@625
|
2529 |
s, "moveRel "+ps,
|
insilmaril@625
|
2530 |
s, "moveRel "+qpointfToString(to),
|
insilmaril@625
|
2531 |
QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
|
insilmaril@625
|
2532 |
((OrnamentedObj*)sel)->move2RelPos (x,y);
|
insilmaril@645
|
2533 |
model->reposition();
|
insilmaril@625
|
2534 |
sel->updateLink();
|
insilmaril@625
|
2535 |
xelection.update();
|
insilmaril@625
|
2536 |
}
|
insilmaril@366
|
2537 |
}
|
insilmaril@130
|
2538 |
}
|
insilmaril@130
|
2539 |
|
insilmaril@0
|
2540 |
void MapEditor::moveBranchUp()
|
insilmaril@0
|
2541 |
{
|
insilmaril@424
|
2542 |
BranchObj* bo=xelection.getBranch();
|
insilmaril@0
|
2543 |
BranchObj* par;
|
insilmaril@424
|
2544 |
if (bo)
|
insilmaril@0
|
2545 |
{
|
insilmaril@314
|
2546 |
if (!bo->canMoveBranchUp()) return;
|
insilmaril@0
|
2547 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@473
|
2548 |
BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
|
insilmaril@684
|
2549 |
saveState (model->getSelectString(bo),"moveBranchDown ()",model->getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
|
insilmaril@645
|
2550 |
model->reposition();
|
insilmaril@420
|
2551 |
scene()->update();
|
insilmaril@442
|
2552 |
xelection.update();
|
insilmaril@0
|
2553 |
ensureSelectionVisible();
|
insilmaril@0
|
2554 |
}
|
insilmaril@0
|
2555 |
}
|
insilmaril@0
|
2556 |
|
insilmaril@0
|
2557 |
void MapEditor::moveBranchDown()
|
insilmaril@0
|
2558 |
{
|
insilmaril@424
|
2559 |
BranchObj* bo=xelection.getBranch();
|
insilmaril@0
|
2560 |
BranchObj* par;
|
insilmaril@424
|
2561 |
if (bo)
|
insilmaril@0
|
2562 |
{
|
insilmaril@314
|
2563 |
if (!bo->canMoveBranchDown()) return;
|
insilmaril@0
|
2564 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@473
|
2565 |
BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
|
insilmaril@684
|
2566 |
saveState(model->getSelectString(bo),"moveBranchUp ()",model->getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
|
insilmaril@645
|
2567 |
model->reposition();
|
insilmaril@420
|
2568 |
scene()->update();
|
insilmaril@442
|
2569 |
xelection.update();
|
insilmaril@0
|
2570 |
ensureSelectionVisible();
|
insilmaril@0
|
2571 |
}
|
insilmaril@0
|
2572 |
}
|
insilmaril@0
|
2573 |
|
insilmaril@608
|
2574 |
void MapEditor::sortChildren()
|
insilmaril@608
|
2575 |
{
|
insilmaril@608
|
2576 |
BranchObj* bo=xelection.getBranch();
|
insilmaril@608
|
2577 |
if (bo)
|
insilmaril@608
|
2578 |
{
|
insilmaril@608
|
2579 |
if(bo->countBranches()>1)
|
insilmaril@608
|
2580 |
{
|
insilmaril@615
|
2581 |
saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo)));
|
insilmaril@608
|
2582 |
bo->sortChildren();
|
insilmaril@645
|
2583 |
model->reposition();
|
insilmaril@608
|
2584 |
ensureSelectionVisible();
|
insilmaril@608
|
2585 |
}
|
insilmaril@608
|
2586 |
}
|
insilmaril@608
|
2587 |
}
|
insilmaril@608
|
2588 |
|
insilmaril@491
|
2589 |
void MapEditor::linkTo(const QString &dstString)
|
insilmaril@420
|
2590 |
{
|
insilmaril@424
|
2591 |
FloatImageObj *fio=xelection.getFloatImage();
|
insilmaril@424
|
2592 |
if (fio)
|
insilmaril@424
|
2593 |
{
|
insilmaril@645
|
2594 |
BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString));
|
insilmaril@424
|
2595 |
if (dst && (typeid(*dst)==typeid (BranchObj) ||
|
insilmaril@424
|
2596 |
typeid(*dst)==typeid (MapCenterObj)))
|
insilmaril@424
|
2597 |
{
|
insilmaril@424
|
2598 |
LinkableMapObj *dstPar=dst->getParObj();
|
insilmaril@684
|
2599 |
QString parString=model->getSelectString(dstPar);
|
insilmaril@684
|
2600 |
QString fioPreSelectString=model->getSelectString(fio);
|
insilmaril@684
|
2601 |
QString fioPreParentSelectString=model->getSelectString (fio->getParObj());
|
insilmaril@420
|
2602 |
((BranchObj*)(dst))->addFloatImage (fio);
|
insilmaril@424
|
2603 |
xelection.unselect();
|
insilmaril@420
|
2604 |
((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
|
insilmaril@420
|
2605 |
fio=((BranchObj*)(dst))->getLastFloatImage();
|
insilmaril@420
|
2606 |
fio->setRelPos();
|
insilmaril@420
|
2607 |
fio->reposition();
|
insilmaril@424
|
2608 |
xelection.select(fio);
|
insilmaril@420
|
2609 |
saveState(
|
insilmaril@684
|
2610 |
model->getSelectString(fio),
|
insilmaril@420
|
2611 |
QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
|
insilmaril@420
|
2612 |
fioPreSelectString,
|
insilmaril@420
|
2613 |
QString ("linkTo (\"%1\")").arg(dstString),
|
insilmaril@420
|
2614 |
QString ("Link floatimage to %1").arg(getName(dst)));
|
insilmaril@424
|
2615 |
}
|
insilmaril@420
|
2616 |
}
|
insilmaril@420
|
2617 |
}
|
insilmaril@420
|
2618 |
|
insilmaril@366
|
2619 |
QString MapEditor::getHeading(bool &ok, QPoint &p)
|
insilmaril@0
|
2620 |
{
|
insilmaril@424
|
2621 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
2622 |
if (bo)
|
insilmaril@366
|
2623 |
{
|
insilmaril@366
|
2624 |
ok=true;
|
insilmaril@424
|
2625 |
p=mapFromScene(bo->getAbsPos());
|
insilmaril@424
|
2626 |
return bo->getHeading();
|
insilmaril@366
|
2627 |
}
|
insilmaril@366
|
2628 |
ok=false;
|
insilmaril@366
|
2629 |
return QString();
|
insilmaril@366
|
2630 |
}
|
insilmaril@366
|
2631 |
|
insilmaril@366
|
2632 |
void MapEditor::setHeading(const QString &s)
|
insilmaril@366
|
2633 |
{
|
insilmaril@424
|
2634 |
BranchObj *sel=xelection.getBranch();
|
insilmaril@424
|
2635 |
if (sel)
|
insilmaril@0
|
2636 |
{
|
insilmaril@395
|
2637 |
saveState(
|
insilmaril@424
|
2638 |
sel,
|
insilmaril@424
|
2639 |
"setHeading (\""+sel->getHeading()+"\")",
|
insilmaril@424
|
2640 |
sel,
|
insilmaril@366
|
2641 |
"setHeading (\""+s+"\")",
|
insilmaril@424
|
2642 |
QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) );
|
insilmaril@424
|
2643 |
sel->setHeading(s );
|
insilmaril@645
|
2644 |
model->reposition();
|
insilmaril@442
|
2645 |
xelection.update();
|
insilmaril@106
|
2646 |
ensureSelectionVisible();
|
insilmaril@106
|
2647 |
}
|
insilmaril@106
|
2648 |
}
|
insilmaril@106
|
2649 |
|
insilmaril@366
|
2650 |
void MapEditor::setHeadingInt(const QString &s)
|
insilmaril@366
|
2651 |
{
|
insilmaril@424
|
2652 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
2653 |
if (bo)
|
insilmaril@366
|
2654 |
{
|
insilmaril@424
|
2655 |
bo->setHeading(s);
|
insilmaril@645
|
2656 |
model->reposition();
|
insilmaril@442
|
2657 |
xelection.update();
|
insilmaril@366
|
2658 |
ensureSelectionVisible();
|
insilmaril@366
|
2659 |
}
|
insilmaril@366
|
2660 |
}
|
insilmaril@366
|
2661 |
|
insilmaril@366
|
2662 |
void MapEditor::setVymLinkInt (const QString &s)
|
insilmaril@143
|
2663 |
{
|
insilmaril@143
|
2664 |
// Internal function, no saveState needed
|
insilmaril@424
|
2665 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
2666 |
if (bo)
|
insilmaril@143
|
2667 |
{
|
insilmaril@424
|
2668 |
bo->setVymLink(s);
|
insilmaril@645
|
2669 |
model->reposition();
|
insilmaril@491
|
2670 |
updateActions();
|
insilmaril@442
|
2671 |
xelection.update();
|
insilmaril@143
|
2672 |
ensureSelectionVisible();
|
insilmaril@143
|
2673 |
}
|
insilmaril@143
|
2674 |
}
|
insilmaril@143
|
2675 |
|
insilmaril@684
|
2676 |
BranchObj* MapEditor::addMapCenter ()
|
insilmaril@684
|
2677 |
{
|
insilmaril@684
|
2678 |
MapCenterObj *mco= model->addMapCenter(contextMenuPos);
|
insilmaril@684
|
2679 |
xelection.select (mco);
|
insilmaril@684
|
2680 |
updateActions();
|
insilmaril@684
|
2681 |
ensureSelectionVisible();
|
insilmaril@684
|
2682 |
saveState (
|
insilmaril@684
|
2683 |
mco,
|
insilmaril@684
|
2684 |
"delete()",
|
insilmaril@684
|
2685 |
NULL,
|
insilmaril@684
|
2686 |
QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()),
|
insilmaril@684
|
2687 |
QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y())
|
insilmaril@684
|
2688 |
);
|
insilmaril@684
|
2689 |
return mco;
|
insilmaril@684
|
2690 |
}
|
insilmaril@684
|
2691 |
|
insilmaril@366
|
2692 |
BranchObj* MapEditor::addNewBranchInt(int num)
|
insilmaril@0
|
2693 |
{
|
insilmaril@366
|
2694 |
// Depending on pos:
|
insilmaril@366
|
2695 |
// -3 insert in childs of parent above selection
|
insilmaril@366
|
2696 |
// -2 add branch to selection
|
insilmaril@366
|
2697 |
// -1 insert in childs of parent below selection
|
insilmaril@366
|
2698 |
// 0..n insert in childs of parent at pos
|
insilmaril@366
|
2699 |
BranchObj *newbo=NULL;
|
insilmaril@424
|
2700 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
2701 |
if (bo)
|
insilmaril@0
|
2702 |
{
|
insilmaril@366
|
2703 |
if (num==-2)
|
insilmaril@0
|
2704 |
{
|
insilmaril@0
|
2705 |
// save scroll state. If scrolled, automatically select
|
insilmaril@0
|
2706 |
// new branch in order to tmp unscroll parent...
|
insilmaril@537
|
2707 |
newbo=bo->addBranch();
|
insilmaril@366
|
2708 |
|
insilmaril@366
|
2709 |
}else if (num==-1)
|
insilmaril@0
|
2710 |
{
|
insilmaril@366
|
2711 |
num=bo->getNum()+1;
|
insilmaril@366
|
2712 |
bo=(BranchObj*)bo->getParObj();
|
insilmaril@537
|
2713 |
if (bo) newbo=bo->insertBranch(num);
|
insilmaril@366
|
2714 |
}else if (num==-3)
|
insilmaril@366
|
2715 |
{
|
insilmaril@366
|
2716 |
num=bo->getNum();
|
insilmaril@366
|
2717 |
bo=(BranchObj*)bo->getParObj();
|
insilmaril@537
|
2718 |
if (bo) newbo=bo->insertBranch(num);
|
insilmaril@366
|
2719 |
}
|
insilmaril@537
|
2720 |
if (!newbo) return NULL;
|
insilmaril@366
|
2721 |
}
|
insilmaril@366
|
2722 |
return newbo;
|
insilmaril@366
|
2723 |
}
|
insilmaril@366
|
2724 |
|
insilmaril@394
|
2725 |
BranchObj* MapEditor::addNewBranch(int pos)
|
insilmaril@366
|
2726 |
{
|
insilmaril@366
|
2727 |
// Different meaning than num in addNewBranchInt!
|
insilmaril@366
|
2728 |
// -1 add above
|
insilmaril@366
|
2729 |
// 0 add as child
|
insilmaril@366
|
2730 |
// +1 add below
|
insilmaril@424
|
2731 |
BranchObj *bo = xelection.getBranch();
|
insilmaril@394
|
2732 |
BranchObj *newbo=NULL;
|
insilmaril@394
|
2733 |
|
insilmaril@424
|
2734 |
if (bo)
|
insilmaril@366
|
2735 |
{
|
insilmaril@421
|
2736 |
setCursor (Qt::ArrowCursor);
|
insilmaril@421
|
2737 |
|
insilmaril@366
|
2738 |
newbo=addNewBranchInt (pos-2);
|
insilmaril@366
|
2739 |
|
insilmaril@366
|
2740 |
if (newbo)
|
insilmaril@366
|
2741 |
{
|
insilmaril@395
|
2742 |
saveState(
|
insilmaril@417
|
2743 |
newbo,
|
insilmaril@393
|
2744 |
"delete ()",
|
insilmaril@424
|
2745 |
bo,
|
insilmaril@537
|
2746 |
QString ("addBranch (%1)").arg(pos),
|
insilmaril@395
|
2747 |
QString ("Add new branch to %1").arg(getName(bo)));
|
insilmaril@366
|
2748 |
|
insilmaril@645
|
2749 |
model->reposition();
|
insilmaril@537
|
2750 |
xelection.update();
|
insilmaril@684
|
2751 |
latestSelection=model->getSelectString(newbo);
|
insilmaril@531
|
2752 |
// In Network mode, the client needs to know where the new branch is,
|
insilmaril@531
|
2753 |
// so we have to pass on this information via saveState.
|
insilmaril@531
|
2754 |
// TODO: Get rid of this positioning workaround
|
insilmaril@531
|
2755 |
QString ps=qpointfToString (newbo->getAbsPos());
|
insilmaril@537
|
2756 |
sendData ("selectLatestAdded ()");
|
insilmaril@534
|
2757 |
sendData (QString("move %1").arg(ps));
|
insilmaril@534
|
2758 |
sendSelection();
|
insilmaril@366
|
2759 |
}
|
insilmaril@366
|
2760 |
}
|
insilmaril@394
|
2761 |
return newbo;
|
insilmaril@366
|
2762 |
}
|
insilmaril@366
|
2763 |
|
insilmaril@366
|
2764 |
|
insilmaril@394
|
2765 |
BranchObj* MapEditor::addNewBranchBefore()
|
insilmaril@366
|
2766 |
{
|
insilmaril@394
|
2767 |
BranchObj *newbo=NULL;
|
insilmaril@424
|
2768 |
BranchObj *bo = xelection.getBranch();
|
insilmaril@491
|
2769 |
if (bo && xelection.type()==Selection::Branch)
|
insilmaril@394
|
2770 |
// We accept no MapCenterObj here, so we _have_ a parent
|
insilmaril@366
|
2771 |
{
|
insilmaril@408
|
2772 |
QPointF p=bo->getRelPos();
|
insilmaril@394
|
2773 |
|
insilmaril@394
|
2774 |
|
insilmaril@424
|
2775 |
BranchObj *parbo=(BranchObj*)(bo->getParObj());
|
insilmaril@394
|
2776 |
|
insilmaril@394
|
2777 |
// add below selection
|
insilmaril@394
|
2778 |
newbo=parbo->insertBranch(bo->getNum()+1);
|
insilmaril@394
|
2779 |
if (newbo)
|
insilmaril@366
|
2780 |
{
|
insilmaril@394
|
2781 |
newbo->move2RelPos (p);
|
insilmaril@394
|
2782 |
|
insilmaril@394
|
2783 |
// Move selection to new branch
|
insilmaril@424
|
2784 |
bo->linkTo (newbo,-1);
|
insilmaril@394
|
2785 |
|
insilmaril@394
|
2786 |
saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
|
insilmaril@394
|
2787 |
QString ("Add branch before %1").arg(getName(bo)));
|
insilmaril@394
|
2788 |
|
insilmaril@645
|
2789 |
model->reposition();
|
insilmaril@442
|
2790 |
xelection.update();
|
insilmaril@394
|
2791 |
}
|
insilmaril@0
|
2792 |
}
|
insilmaril@537
|
2793 |
latestSelection=xelection.getSelectString();
|
insilmaril@394
|
2794 |
return newbo;
|
insilmaril@0
|
2795 |
}
|
insilmaril@0
|
2796 |
|
insilmaril@0
|
2797 |
void MapEditor::deleteSelection()
|
insilmaril@0
|
2798 |
{
|
insilmaril@424
|
2799 |
BranchObj *bo = xelection.getBranch();
|
insilmaril@645
|
2800 |
if (bo && xelection.type()==Selection::MapCenter)
|
insilmaril@645
|
2801 |
{
|
insilmaril@645
|
2802 |
// BranchObj* par=(BranchObj*)(bo->getParObj());
|
insilmaril@645
|
2803 |
xelection.unselect();
|
insilmaril@645
|
2804 |
/* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
|
insilmaril@645
|
2805 |
saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
|
insilmaril@645
|
2806 |
*/
|
insilmaril@645
|
2807 |
bo=model->removeMapCenter ((MapCenterObj*)bo);
|
insilmaril@645
|
2808 |
if (bo)
|
insilmaril@645
|
2809 |
{
|
insilmaril@645
|
2810 |
xelection.select (bo);
|
insilmaril@645
|
2811 |
ensureSelectionVisible();
|
insilmaril@645
|
2812 |
xelection.update();
|
insilmaril@645
|
2813 |
}
|
insilmaril@645
|
2814 |
model->reposition();
|
insilmaril@645
|
2815 |
return;
|
insilmaril@645
|
2816 |
}
|
insilmaril@491
|
2817 |
if (bo && xelection.type()==Selection::Branch)
|
insilmaril@0
|
2818 |
{
|
insilmaril@294
|
2819 |
BranchObj* par=(BranchObj*)(bo->getParObj());
|
insilmaril@424
|
2820 |
xelection.unselect();
|
insilmaril@394
|
2821 |
saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
|
insilmaril@0
|
2822 |
par->removeBranch(bo);
|
insilmaril@424
|
2823 |
xelection.select (par);
|
insilmaril@0
|
2824 |
ensureSelectionVisible();
|
insilmaril@645
|
2825 |
model->reposition();
|
insilmaril@442
|
2826 |
xelection.update();
|
insilmaril@442
|
2827 |
xelection.update();
|
insilmaril@424
|
2828 |
return;
|
insilmaril@0
|
2829 |
}
|
insilmaril@424
|
2830 |
FloatImageObj *fio=xelection.getFloatImage();
|
insilmaril@424
|
2831 |
if (fio)
|
insilmaril@0
|
2832 |
{
|
insilmaril@0
|
2833 |
BranchObj* par=(BranchObj*)(fio->getParObj());
|
insilmaril@395
|
2834 |
saveStateChangingPart(
|
insilmaril@395
|
2835 |
par,
|
insilmaril@395
|
2836 |
fio,
|
insilmaril@395
|
2837 |
"delete ()",
|
insilmaril@395
|
2838 |
QString("Delete %1").arg(getName(fio))
|
insilmaril@395
|
2839 |
);
|
insilmaril@424
|
2840 |
xelection.unselect();
|
insilmaril@0
|
2841 |
par->removeFloatImage(fio);
|
insilmaril@424
|
2842 |
xelection.select (par);
|
insilmaril@645
|
2843 |
model->reposition();
|
insilmaril@442
|
2844 |
xelection.update();
|
insilmaril@0
|
2845 |
ensureSelectionVisible();
|
insilmaril@424
|
2846 |
return;
|
insilmaril@0
|
2847 |
}
|
insilmaril@0
|
2848 |
}
|
insilmaril@0
|
2849 |
|
insilmaril@0
|
2850 |
LinkableMapObj* MapEditor::getSelection()
|
insilmaril@0
|
2851 |
{
|
insilmaril@424
|
2852 |
return xelection.single();
|
insilmaril@0
|
2853 |
}
|
insilmaril@0
|
2854 |
|
insilmaril@442
|
2855 |
BranchObj* MapEditor::getSelectedBranch()
|
insilmaril@442
|
2856 |
{
|
insilmaril@442
|
2857 |
return xelection.getBranch();
|
insilmaril@442
|
2858 |
}
|
insilmaril@442
|
2859 |
|
insilmaril@442
|
2860 |
FloatImageObj* MapEditor::getSelectedFloatImage()
|
insilmaril@442
|
2861 |
{
|
insilmaril@442
|
2862 |
return xelection.getFloatImage();
|
insilmaril@442
|
2863 |
}
|
insilmaril@442
|
2864 |
|
insilmaril@267
|
2865 |
void MapEditor::unselect()
|
insilmaril@267
|
2866 |
{
|
insilmaril@424
|
2867 |
xelection.unselect();
|
insilmaril@267
|
2868 |
}
|
insilmaril@267
|
2869 |
|
insilmaril@267
|
2870 |
void MapEditor::reselect()
|
insilmaril@267
|
2871 |
{
|
insilmaril@424
|
2872 |
xelection.reselect();
|
insilmaril@267
|
2873 |
}
|
insilmaril@267
|
2874 |
|
insilmaril@83
|
2875 |
bool MapEditor::select (const QString &s)
|
insilmaril@83
|
2876 |
{
|
insilmaril@652
|
2877 |
if (xelection.select(s))
|
insilmaril@0
|
2878 |
{
|
insilmaril@442
|
2879 |
xelection.update();
|
insilmaril@0
|
2880 |
ensureSelectionVisible();
|
insilmaril@528
|
2881 |
sendSelection ();
|
insilmaril@0
|
2882 |
return true;
|
insilmaril@652
|
2883 |
}
|
insilmaril@139
|
2884 |
return false;
|
insilmaril@0
|
2885 |
}
|
insilmaril@0
|
2886 |
|
insilmaril@684
|
2887 |
bool MapEditor::select (LinkableMapObj *lmo)
|
insilmaril@684
|
2888 |
{
|
insilmaril@684
|
2889 |
if (xelection.select(lmo))
|
insilmaril@684
|
2890 |
{
|
insilmaril@684
|
2891 |
xelection.update();
|
insilmaril@684
|
2892 |
ensureSelectionVisible();
|
insilmaril@684
|
2893 |
sendSelection ();
|
insilmaril@684
|
2894 |
return true;
|
insilmaril@684
|
2895 |
}
|
insilmaril@684
|
2896 |
return false;
|
insilmaril@684
|
2897 |
}
|
insilmaril@684
|
2898 |
|
insilmaril@366
|
2899 |
QString MapEditor::getSelectString()
|
insilmaril@366
|
2900 |
{
|
insilmaril@424
|
2901 |
return xelection.getSelectString();
|
insilmaril@366
|
2902 |
}
|
insilmaril@366
|
2903 |
|
insilmaril@366
|
2904 |
void MapEditor::selectInt (LinkableMapObj *lmo)
|
insilmaril@0
|
2905 |
{
|
insilmaril@491
|
2906 |
if (lmo && xelection.single()!= lmo && isSelectBlocked()==false )
|
insilmaril@442
|
2907 |
{
|
insilmaril@424
|
2908 |
xelection.select(lmo);
|
insilmaril@442
|
2909 |
xelection.update();
|
insilmaril@528
|
2910 |
sendSelection ();
|
insilmaril@442
|
2911 |
}
|
insilmaril@267
|
2912 |
}
|
insilmaril@0
|
2913 |
|
insilmaril@366
|
2914 |
void MapEditor::selectNextBranchInt()
|
insilmaril@0
|
2915 |
{
|
insilmaril@0
|
2916 |
// Increase number of branch
|
insilmaril@424
|
2917 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@424
|
2918 |
if (sel)
|
insilmaril@0
|
2919 |
{
|
insilmaril@684
|
2920 |
QString s=xelection.getSelectString();
|
insilmaril@0
|
2921 |
QString part;
|
insilmaril@0
|
2922 |
QString typ;
|
insilmaril@0
|
2923 |
QString num;
|
insilmaril@0
|
2924 |
|
insilmaril@0
|
2925 |
// Where am I?
|
insilmaril@0
|
2926 |
part=s.section(",",-1);
|
insilmaril@0
|
2927 |
typ=part.left (3);
|
insilmaril@0
|
2928 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
2929 |
|
insilmaril@0
|
2930 |
s=s.left (s.length() -num.length());
|
insilmaril@0
|
2931 |
|
insilmaril@0
|
2932 |
// Go to next lmo
|
insilmaril@0
|
2933 |
num=QString ("%1").arg(num.toUInt()+1);
|
insilmaril@0
|
2934 |
|
insilmaril@0
|
2935 |
s=s+num;
|
insilmaril@0
|
2936 |
|
insilmaril@0
|
2937 |
// Try to select this one
|
insilmaril@0
|
2938 |
if (select (s)) return;
|
insilmaril@0
|
2939 |
|
insilmaril@0
|
2940 |
// We have no direct successor,
|
insilmaril@0
|
2941 |
// try to increase the parental number in order to
|
insilmaril@0
|
2942 |
// find a successor with same depth
|
insilmaril@0
|
2943 |
|
insilmaril@424
|
2944 |
int d=xelection.single()->getDepth();
|
insilmaril@0
|
2945 |
int oldDepth=d;
|
insilmaril@0
|
2946 |
int i;
|
insilmaril@0
|
2947 |
bool found=false;
|
insilmaril@0
|
2948 |
bool b;
|
insilmaril@0
|
2949 |
while (!found && d>0)
|
insilmaril@0
|
2950 |
{
|
insilmaril@0
|
2951 |
s=s.section (",",0,d-1);
|
insilmaril@0
|
2952 |
// replace substring of current depth in s with "1"
|
insilmaril@0
|
2953 |
part=s.section(",",-1);
|
insilmaril@0
|
2954 |
typ=part.left (3);
|
insilmaril@0
|
2955 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
2956 |
|
insilmaril@0
|
2957 |
if (d>1)
|
insilmaril@0
|
2958 |
{
|
insilmaril@0
|
2959 |
// increase number of parent
|
insilmaril@0
|
2960 |
num=QString ("%1").arg(num.toUInt()+1);
|
insilmaril@0
|
2961 |
s=s.section (",",0,d-2) + ","+ typ+num;
|
insilmaril@0
|
2962 |
} else
|
insilmaril@0
|
2963 |
{
|
insilmaril@0
|
2964 |
// Special case, look at orientation
|
insilmaril@473
|
2965 |
if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@0
|
2966 |
num=QString ("%1").arg(num.toUInt()+1);
|
insilmaril@0
|
2967 |
else
|
insilmaril@0
|
2968 |
num=QString ("%1").arg(num.toUInt()-1);
|
insilmaril@0
|
2969 |
s=typ+num;
|
insilmaril@0
|
2970 |
}
|
insilmaril@0
|
2971 |
|
insilmaril@0
|
2972 |
if (select (s))
|
insilmaril@0
|
2973 |
// pad to oldDepth, select the first branch for each depth
|
insilmaril@0
|
2974 |
for (i=d;i<oldDepth;i++)
|
insilmaril@0
|
2975 |
{
|
insilmaril@0
|
2976 |
b=select (s);
|
insilmaril@0
|
2977 |
if (b)
|
insilmaril@0
|
2978 |
{
|
insilmaril@424
|
2979 |
if ( xelection.getBranch()->countBranches()>0)
|
insilmaril@0
|
2980 |
s+=",bo:0";
|
insilmaril@0
|
2981 |
else
|
insilmaril@0
|
2982 |
break;
|
insilmaril@0
|
2983 |
} else
|
insilmaril@0
|
2984 |
break;
|
insilmaril@0
|
2985 |
}
|
insilmaril@0
|
2986 |
|
insilmaril@0
|
2987 |
// try to select the freshly built string
|
insilmaril@0
|
2988 |
found=select(s);
|
insilmaril@0
|
2989 |
d--;
|
insilmaril@0
|
2990 |
}
|
insilmaril@0
|
2991 |
return;
|
insilmaril@0
|
2992 |
}
|
insilmaril@0
|
2993 |
}
|
insilmaril@0
|
2994 |
|
insilmaril@366
|
2995 |
void MapEditor::selectPrevBranchInt()
|
insilmaril@0
|
2996 |
{
|
insilmaril@0
|
2997 |
// Decrease number of branch
|
insilmaril@424
|
2998 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
2999 |
if (bo)
|
insilmaril@0
|
3000 |
{
|
insilmaril@684
|
3001 |
QString s=xelection.getSelectString();
|
insilmaril@0
|
3002 |
QString part;
|
insilmaril@0
|
3003 |
QString typ;
|
insilmaril@0
|
3004 |
QString num;
|
insilmaril@0
|
3005 |
|
insilmaril@0
|
3006 |
// Where am I?
|
insilmaril@0
|
3007 |
part=s.section(",",-1);
|
insilmaril@0
|
3008 |
typ=part.left (3);
|
insilmaril@0
|
3009 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
3010 |
|
insilmaril@0
|
3011 |
s=s.left (s.length() -num.length());
|
insilmaril@0
|
3012 |
|
insilmaril@411
|
3013 |
int n=num.toInt()-1;
|
insilmaril@411
|
3014 |
|
insilmaril@0
|
3015 |
// Go to next lmo
|
insilmaril@411
|
3016 |
num=QString ("%1").arg(n);
|
insilmaril@0
|
3017 |
s=s+num;
|
insilmaril@0
|
3018 |
|
insilmaril@0
|
3019 |
// Try to select this one
|
insilmaril@411
|
3020 |
if (n>=0 && select (s)) return;
|
insilmaril@0
|
3021 |
|
insilmaril@0
|
3022 |
// We have no direct precessor,
|
insilmaril@0
|
3023 |
// try to decrease the parental number in order to
|
insilmaril@0
|
3024 |
// find a precessor with same depth
|
insilmaril@0
|
3025 |
|
insilmaril@424
|
3026 |
int d=xelection.single()->getDepth();
|
insilmaril@0
|
3027 |
int oldDepth=d;
|
insilmaril@0
|
3028 |
int i;
|
insilmaril@0
|
3029 |
bool found=false;
|
insilmaril@0
|
3030 |
bool b;
|
insilmaril@0
|
3031 |
while (!found && d>0)
|
insilmaril@0
|
3032 |
{
|
insilmaril@0
|
3033 |
s=s.section (",",0,d-1);
|
insilmaril@0
|
3034 |
// replace substring of current depth in s with "1"
|
insilmaril@0
|
3035 |
part=s.section(",",-1);
|
insilmaril@0
|
3036 |
typ=part.left (3);
|
insilmaril@0
|
3037 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
3038 |
|
insilmaril@0
|
3039 |
if (d>1)
|
insilmaril@0
|
3040 |
{
|
insilmaril@0
|
3041 |
// decrease number of parent
|
insilmaril@411
|
3042 |
num=QString ("%1").arg(num.toInt()-1);
|
insilmaril@0
|
3043 |
s=s.section (",",0,d-2) + ","+ typ+num;
|
insilmaril@0
|
3044 |
} else
|
insilmaril@0
|
3045 |
{
|
insilmaril@0
|
3046 |
// Special case, look at orientation
|
insilmaril@473
|
3047 |
if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@411
|
3048 |
num=QString ("%1").arg(num.toInt()-1);
|
insilmaril@0
|
3049 |
else
|
insilmaril@411
|
3050 |
num=QString ("%1").arg(num.toInt()+1);
|
insilmaril@0
|
3051 |
s=typ+num;
|
insilmaril@0
|
3052 |
}
|
insilmaril@0
|
3053 |
|
insilmaril@0
|
3054 |
if (select(s))
|
insilmaril@0
|
3055 |
// pad to oldDepth, select the last branch for each depth
|
insilmaril@0
|
3056 |
for (i=d;i<oldDepth;i++)
|
insilmaril@0
|
3057 |
{
|
insilmaril@0
|
3058 |
b=select (s);
|
insilmaril@0
|
3059 |
if (b)
|
insilmaril@424
|
3060 |
if ( xelection.getBranch()->countBranches()>0)
|
insilmaril@424
|
3061 |
s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 );
|
insilmaril@0
|
3062 |
else
|
insilmaril@0
|
3063 |
break;
|
insilmaril@0
|
3064 |
else
|
insilmaril@0
|
3065 |
break;
|
insilmaril@0
|
3066 |
}
|
insilmaril@0
|
3067 |
|
insilmaril@0
|
3068 |
// try to select the freshly built string
|
insilmaril@0
|
3069 |
found=select(s);
|
insilmaril@0
|
3070 |
d--;
|
insilmaril@0
|
3071 |
}
|
insilmaril@0
|
3072 |
return;
|
insilmaril@0
|
3073 |
}
|
insilmaril@0
|
3074 |
}
|
insilmaril@0
|
3075 |
|
insilmaril@0
|
3076 |
void MapEditor::selectUpperBranch()
|
insilmaril@0
|
3077 |
{
|
insilmaril@491
|
3078 |
if (isSelectBlocked() ) return;
|
insilmaril@491
|
3079 |
|
insilmaril@424
|
3080 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@491
|
3081 |
if (bo && xelection.type()==Selection::Branch)
|
insilmaril@0
|
3082 |
{
|
insilmaril@473
|
3083 |
if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@424
|
3084 |
selectPrevBranchInt();
|
insilmaril@424
|
3085 |
else
|
insilmaril@424
|
3086 |
if (bo->getDepth()==1)
|
insilmaril@424
|
3087 |
selectNextBranchInt();
|
insilmaril@424
|
3088 |
else
|
insilmaril@424
|
3089 |
selectPrevBranchInt();
|
insilmaril@424
|
3090 |
}
|
insilmaril@424
|
3091 |
}
|
insilmaril@424
|
3092 |
|
insilmaril@424
|
3093 |
void MapEditor::selectLowerBranch()
|
insilmaril@424
|
3094 |
{
|
insilmaril@491
|
3095 |
if (isSelectBlocked() ) return;
|
insilmaril@491
|
3096 |
|
insilmaril@424
|
3097 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@491
|
3098 |
if (bo && xelection.type()==Selection::Branch)
|
insilmaril@473
|
3099 |
if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@424
|
3100 |
selectNextBranchInt();
|
insilmaril@424
|
3101 |
else
|
insilmaril@424
|
3102 |
if (bo->getDepth()==1)
|
insilmaril@366
|
3103 |
selectPrevBranchInt();
|
insilmaril@0
|
3104 |
else
|
insilmaril@366
|
3105 |
selectNextBranchInt();
|
insilmaril@0
|
3106 |
}
|
insilmaril@0
|
3107 |
|
insilmaril@0
|
3108 |
|
insilmaril@0
|
3109 |
void MapEditor::selectLeftBranch()
|
insilmaril@0
|
3110 |
{
|
insilmaril@491
|
3111 |
if (isSelectBlocked() ) return;
|
insilmaril@491
|
3112 |
|
insilmaril@0
|
3113 |
BranchObj* bo;
|
insilmaril@0
|
3114 |
BranchObj* par;
|
insilmaril@424
|
3115 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@424
|
3116 |
if (sel)
|
insilmaril@0
|
3117 |
{
|
insilmaril@491
|
3118 |
if (xelection.type()== Selection::MapCenter)
|
insilmaril@0
|
3119 |
{
|
insilmaril@424
|
3120 |
par=xelection.getBranch();
|
insilmaril@0
|
3121 |
bo=par->getLastSelectedBranch();
|
insilmaril@0
|
3122 |
if (bo)
|
insilmaril@0
|
3123 |
{
|
insilmaril@0
|
3124 |
// Workaround for reselecting on left and right side
|
insilmaril@473
|
3125 |
if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@424
|
3126 |
bo=par->getLastBranch();
|
insilmaril@424
|
3127 |
if (bo)
|
insilmaril@0
|
3128 |
{
|
insilmaril@0
|
3129 |
bo=par->getLastBranch();
|
insilmaril@424
|
3130 |
xelection.select(bo);
|
insilmaril@442
|
3131 |
xelection.update();
|
insilmaril@0
|
3132 |
ensureSelectionVisible();
|
insilmaril@528
|
3133 |
sendSelection();
|
insilmaril@0
|
3134 |
}
|
insilmaril@0
|
3135 |
}
|
insilmaril@0
|
3136 |
} else
|
insilmaril@0
|
3137 |
{
|
insilmaril@424
|
3138 |
par=(BranchObj*)(sel->getParObj());
|
insilmaril@473
|
3139 |
if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@0
|
3140 |
{
|
insilmaril@491
|
3141 |
if (xelection.type() == Selection::Branch ||
|
insilmaril@491
|
3142 |
xelection.type() == Selection::FloatImage)
|
insilmaril@0
|
3143 |
{
|
insilmaril@424
|
3144 |
xelection.select(par);
|
insilmaril@442
|
3145 |
xelection.update();
|
insilmaril@0
|
3146 |
ensureSelectionVisible();
|
insilmaril@528
|
3147 |
sendSelection();
|
insilmaril@0
|
3148 |
}
|
insilmaril@0
|
3149 |
} else
|
insilmaril@0
|
3150 |
{
|
insilmaril@491
|
3151 |
if (xelection.type() == Selection::Branch )
|
insilmaril@0
|
3152 |
{
|
insilmaril@424
|
3153 |
bo=xelection.getBranch()->getLastSelectedBranch();
|
insilmaril@0
|
3154 |
if (bo)
|
insilmaril@0
|
3155 |
{
|
insilmaril@424
|
3156 |
xelection.select(bo);
|
insilmaril@442
|
3157 |
xelection.update();
|
insilmaril@0
|
3158 |
ensureSelectionVisible();
|
insilmaril@528
|
3159 |
sendSelection();
|
insilmaril@0
|
3160 |
}
|
insilmaril@0
|
3161 |
}
|
insilmaril@0
|
3162 |
}
|
insilmaril@0
|
3163 |
}
|
insilmaril@0
|
3164 |
}
|
insilmaril@0
|
3165 |
}
|
insilmaril@0
|
3166 |
|
insilmaril@0
|
3167 |
void MapEditor::selectRightBranch()
|
insilmaril@0
|
3168 |
{
|
insilmaril@491
|
3169 |
if (isSelectBlocked() ) return;
|
insilmaril@491
|
3170 |
|
insilmaril@0
|
3171 |
BranchObj* bo;
|
insilmaril@0
|
3172 |
BranchObj* par;
|
insilmaril@424
|
3173 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@424
|
3174 |
if (sel)
|
insilmaril@0
|
3175 |
{
|
insilmaril@491
|
3176 |
if (xelection.type()==Selection::MapCenter)
|
insilmaril@0
|
3177 |
{
|
insilmaril@424
|
3178 |
par=xelection.getBranch();
|
insilmaril@0
|
3179 |
bo=par->getLastSelectedBranch();
|
insilmaril@0
|
3180 |
if (bo)
|
insilmaril@0
|
3181 |
{
|
insilmaril@366
|
3182 |
// Workaround for reselecting on left and right side
|
insilmaril@473
|
3183 |
if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
|
insilmaril@0
|
3184 |
bo=par->getFirstBranch();
|
insilmaril@0
|
3185 |
if (bo)
|
insilmaril@0
|
3186 |
{
|
insilmaril@424
|
3187 |
xelection.select(bo);
|
insilmaril@442
|
3188 |
xelection.update();
|
insilmaril@0
|
3189 |
ensureSelectionVisible();
|
insilmaril@528
|
3190 |
sendSelection();
|
insilmaril@0
|
3191 |
}
|
insilmaril@0
|
3192 |
}
|
insilmaril@0
|
3193 |
} else
|
insilmaril@0
|
3194 |
{
|
insilmaril@424
|
3195 |
par=(BranchObj*)(xelection.single()->getParObj());
|
insilmaril@473
|
3196 |
if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
|
insilmaril@0
|
3197 |
{
|
insilmaril@491
|
3198 |
if (xelection.type() == Selection::Branch ||
|
insilmaril@491
|
3199 |
xelection.type() == Selection::FloatImage)
|
insilmaril@0
|
3200 |
{
|
insilmaril@424
|
3201 |
xelection.select(par);
|
insilmaril@442
|
3202 |
xelection.update();
|
insilmaril@0
|
3203 |
ensureSelectionVisible();
|
insilmaril@528
|
3204 |
sendSelection();
|
insilmaril@0
|
3205 |
}
|
insilmaril@0
|
3206 |
} else
|
insilmaril@0
|
3207 |
{
|
insilmaril@491
|
3208 |
if (xelection.type() == Selection::Branch)
|
insilmaril@0
|
3209 |
{
|
insilmaril@424
|
3210 |
bo=xelection.getBranch()->getLastSelectedBranch();
|
insilmaril@0
|
3211 |
if (bo)
|
insilmaril@0
|
3212 |
{
|
insilmaril@424
|
3213 |
xelection.select(bo);
|
insilmaril@442
|
3214 |
xelection.update();
|
insilmaril@0
|
3215 |
ensureSelectionVisible();
|
insilmaril@528
|
3216 |
sendSelection();
|
insilmaril@0
|
3217 |
}
|
insilmaril@0
|
3218 |
}
|
insilmaril@0
|
3219 |
}
|
insilmaril@0
|
3220 |
}
|
insilmaril@0
|
3221 |
}
|
insilmaril@0
|
3222 |
}
|
insilmaril@0
|
3223 |
|
insilmaril@0
|
3224 |
void MapEditor::selectFirstBranch()
|
insilmaril@0
|
3225 |
{
|
insilmaril@424
|
3226 |
BranchObj *bo1=xelection.getBranch();
|
insilmaril@0
|
3227 |
BranchObj *bo2;
|
insilmaril@0
|
3228 |
BranchObj* par;
|
insilmaril@424
|
3229 |
if (bo1)
|
insilmaril@424
|
3230 |
{
|
insilmaril@424
|
3231 |
par=(BranchObj*)(bo1->getParObj());
|
insilmaril@680
|
3232 |
if (!par) return;
|
insilmaril@424
|
3233 |
bo2=par->getFirstBranch();
|
insilmaril@424
|
3234 |
if (bo2) {
|
insilmaril@424
|
3235 |
xelection.select(bo2);
|
insilmaril@442
|
3236 |
xelection.update();
|
insilmaril@424
|
3237 |
ensureSelectionVisible();
|
insilmaril@528
|
3238 |
sendSelection();
|
insilmaril@424
|
3239 |
}
|
insilmaril@424
|
3240 |
}
|
insilmaril@0
|
3241 |
}
|
insilmaril@0
|
3242 |
|
insilmaril@0
|
3243 |
void MapEditor::selectLastBranch()
|
insilmaril@0
|
3244 |
{
|
insilmaril@424
|
3245 |
BranchObj *bo1=xelection.getBranch();
|
insilmaril@0
|
3246 |
BranchObj *bo2;
|
insilmaril@0
|
3247 |
BranchObj* par;
|
insilmaril@424
|
3248 |
if (bo1)
|
insilmaril@424
|
3249 |
{
|
insilmaril@424
|
3250 |
par=(BranchObj*)(bo1->getParObj());
|
insilmaril@680
|
3251 |
if (!par) return;
|
insilmaril@424
|
3252 |
bo2=par->getLastBranch();
|
insilmaril@424
|
3253 |
if (bo2)
|
insilmaril@0
|
3254 |
{
|
insilmaril@424
|
3255 |
xelection.select(bo2);
|
insilmaril@442
|
3256 |
xelection.update();
|
insilmaril@424
|
3257 |
ensureSelectionVisible();
|
insilmaril@528
|
3258 |
sendSelection();
|
insilmaril@424
|
3259 |
}
|
insilmaril@424
|
3260 |
}
|
insilmaril@0
|
3261 |
}
|
insilmaril@0
|
3262 |
|
insilmaril@408
|
3263 |
void MapEditor::selectMapBackgroundImage ()
|
insilmaril@408
|
3264 |
{
|
insilmaril@408
|
3265 |
Q3FileDialog *fd=new Q3FileDialog( this);
|
insilmaril@408
|
3266 |
fd->setMode (Q3FileDialog::ExistingFile);
|
insilmaril@408
|
3267 |
fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
|
insilmaril@408
|
3268 |
ImagePreview *p =new ImagePreview (fd);
|
insilmaril@408
|
3269 |
fd->setContentsPreviewEnabled( TRUE );
|
insilmaril@408
|
3270 |
fd->setContentsPreview( p, p );
|
insilmaril@408
|
3271 |
fd->setPreviewMode( Q3FileDialog::Contents );
|
insilmaril@408
|
3272 |
fd->setCaption(vymName+" - " +tr("Load background image"));
|
insilmaril@408
|
3273 |
fd->setDir (lastImageDir);
|
insilmaril@408
|
3274 |
fd->show();
|
insilmaril@408
|
3275 |
|
insilmaril@408
|
3276 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@408
|
3277 |
{
|
insilmaril@412
|
3278 |
// TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
|
insilmaril@408
|
3279 |
lastImageDir=QDir (fd->dirPath());
|
insilmaril@408
|
3280 |
setMapBackgroundImage (fd->selectedFile());
|
insilmaril@408
|
3281 |
}
|
insilmaril@408
|
3282 |
}
|
insilmaril@408
|
3283 |
|
insilmaril@442
|
3284 |
void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
|
insilmaril@408
|
3285 |
{
|
insilmaril@408
|
3286 |
QColor oldcol=mapScene->backgroundBrush().color();
|
insilmaril@408
|
3287 |
/*
|
insilmaril@408
|
3288 |
saveState(
|
insilmaril@408
|
3289 |
selection,
|
insilmaril@408
|
3290 |
QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
|
insilmaril@408
|
3291 |
selection,
|
insilmaril@408
|
3292 |
QString ("setMapBackgroundImage (%1)").arg(col.name()),
|
insilmaril@408
|
3293 |
QString("Set background color of map to %1").arg(col.name()));
|
insilmaril@408
|
3294 |
*/
|
insilmaril@408
|
3295 |
QBrush brush;
|
insilmaril@408
|
3296 |
brush.setTextureImage (QPixmap (fn));
|
insilmaril@408
|
3297 |
mapScene->setBackgroundBrush(brush);
|
insilmaril@408
|
3298 |
}
|
insilmaril@408
|
3299 |
|
insilmaril@398
|
3300 |
void MapEditor::selectMapBackgroundColor()
|
insilmaril@0
|
3301 |
{
|
insilmaril@408
|
3302 |
QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
|
insilmaril@0
|
3303 |
if ( !col.isValid() ) return;
|
insilmaril@408
|
3304 |
setMapBackgroundColor( col );
|
insilmaril@0
|
3305 |
}
|
insilmaril@0
|
3306 |
|
insilmaril@398
|
3307 |
|
insilmaril@398
|
3308 |
void MapEditor::setMapBackgroundColor(QColor col)
|
insilmaril@0
|
3309 |
{
|
insilmaril@408
|
3310 |
QColor oldcol=mapScene->backgroundBrush().color();
|
insilmaril@398
|
3311 |
saveState(
|
insilmaril@445
|
3312 |
QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
|
insilmaril@445
|
3313 |
QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
|
insilmaril@398
|
3314 |
QString("Set background color of map to %1").arg(col.name()));
|
insilmaril@408
|
3315 |
mapScene->setBackgroundBrush(col);
|
insilmaril@398
|
3316 |
}
|
insilmaril@398
|
3317 |
|
insilmaril@398
|
3318 |
QColor MapEditor::getMapBackgroundColor()
|
insilmaril@398
|
3319 |
{
|
insilmaril@408
|
3320 |
return mapScene->backgroundBrush().color();
|
insilmaril@0
|
3321 |
}
|
insilmaril@0
|
3322 |
|
insilmaril@395
|
3323 |
QColor MapEditor::getCurrentHeadingColor()
|
insilmaril@0
|
3324 |
{
|
insilmaril@424
|
3325 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3326 |
if (bo) return bo->getColor();
|
insilmaril@395
|
3327 |
|
insilmaril@395
|
3328 |
QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
|
insilmaril@395
|
3329 |
return Qt::black;
|
insilmaril@0
|
3330 |
}
|
insilmaril@0
|
3331 |
|
insilmaril@417
|
3332 |
void MapEditor::colorBranch (QColor c)
|
insilmaril@0
|
3333 |
{
|
insilmaril@424
|
3334 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3335 |
if (bo)
|
insilmaril@0
|
3336 |
{
|
insilmaril@424
|
3337 |
saveState(
|
insilmaril@424
|
3338 |
bo,
|
insilmaril@445
|
3339 |
QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
|
insilmaril@424
|
3340 |
bo,
|
insilmaril@445
|
3341 |
QString ("colorBranch (\"%1\")").arg(c.name()),
|
insilmaril@424
|
3342 |
QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
|
insilmaril@424
|
3343 |
);
|
insilmaril@424
|
3344 |
bo->setColor(c); // color branch
|
insilmaril@0
|
3345 |
}
|
insilmaril@0
|
3346 |
}
|
insilmaril@0
|
3347 |
|
insilmaril@417
|
3348 |
void MapEditor::colorSubtree (QColor c)
|
insilmaril@0
|
3349 |
{
|
insilmaril@424
|
3350 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3351 |
if (bo)
|
insilmaril@0
|
3352 |
{
|
insilmaril@424
|
3353 |
saveStateChangingPart(
|
insilmaril@424
|
3354 |
bo,
|
insilmaril@424
|
3355 |
bo,
|
insilmaril@445
|
3356 |
QString ("colorSubtree (\"%1\")").arg(c.name()),
|
insilmaril@424
|
3357 |
QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
|
insilmaril@424
|
3358 |
);
|
insilmaril@424
|
3359 |
bo->setColorSubtree (c); // color links, color childs
|
insilmaril@0
|
3360 |
}
|
insilmaril@0
|
3361 |
}
|
insilmaril@0
|
3362 |
|
insilmaril@0
|
3363 |
|
insilmaril@0
|
3364 |
void MapEditor::toggleStandardFlag(QString f)
|
insilmaril@0
|
3365 |
{
|
insilmaril@424
|
3366 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3367 |
if (bo)
|
insilmaril@0
|
3368 |
{
|
insilmaril@424
|
3369 |
QString u,r;
|
insilmaril@424
|
3370 |
if (bo->isSetStandardFlag(f))
|
insilmaril@366
|
3371 |
{
|
insilmaril@424
|
3372 |
r="unsetFlag";
|
insilmaril@424
|
3373 |
u="setFlag";
|
insilmaril@424
|
3374 |
}
|
insilmaril@424
|
3375 |
else
|
insilmaril@424
|
3376 |
{
|
insilmaril@424
|
3377 |
u="unsetFlag";
|
insilmaril@424
|
3378 |
r="setFlag";
|
insilmaril@424
|
3379 |
}
|
insilmaril@424
|
3380 |
saveState(
|
insilmaril@424
|
3381 |
bo,
|
insilmaril@424
|
3382 |
QString("%1 (\"%2\")").arg(u).arg(f),
|
insilmaril@424
|
3383 |
bo,
|
insilmaril@424
|
3384 |
QString("%1 (\"%2\")").arg(r).arg(f),
|
insilmaril@424
|
3385 |
QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
|
insilmaril@424
|
3386 |
bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
|
insilmaril@442
|
3387 |
xelection.update();
|
insilmaril@424
|
3388 |
}
|
insilmaril@0
|
3389 |
}
|
insilmaril@0
|
3390 |
|
insilmaril@0
|
3391 |
|
insilmaril@0
|
3392 |
BranchObj* MapEditor::findText (QString s, bool cs)
|
insilmaril@0
|
3393 |
{
|
insilmaril@366
|
3394 |
QTextDocument::FindFlags flags=0;
|
insilmaril@366
|
3395 |
if (cs) flags=QTextDocument::FindCaseSensitively;
|
insilmaril@366
|
3396 |
|
insilmaril@0
|
3397 |
if (!itFind)
|
insilmaril@0
|
3398 |
{ // Nothing found or new find process
|
insilmaril@0
|
3399 |
if (EOFind)
|
insilmaril@0
|
3400 |
// nothing found, start again
|
insilmaril@0
|
3401 |
EOFind=false;
|
insilmaril@645
|
3402 |
itFind=model->first();
|
insilmaril@0
|
3403 |
}
|
insilmaril@0
|
3404 |
bool searching=true;
|
insilmaril@0
|
3405 |
bool foundNote=false;
|
insilmaril@0
|
3406 |
while (searching && !EOFind)
|
insilmaril@0
|
3407 |
{
|
insilmaril@0
|
3408 |
if (itFind)
|
insilmaril@0
|
3409 |
{
|
insilmaril@0
|
3410 |
// Searching in Note
|
insilmaril@0
|
3411 |
if (itFind->getNote().contains(s,cs))
|
insilmaril@0
|
3412 |
{
|
insilmaril@424
|
3413 |
if (xelection.single()!=itFind)
|
insilmaril@0
|
3414 |
{
|
insilmaril@424
|
3415 |
xelection.select(itFind);
|
insilmaril@0
|
3416 |
ensureSelectionVisible();
|
insilmaril@0
|
3417 |
}
|
insilmaril@366
|
3418 |
if (textEditor->findText(s,flags))
|
insilmaril@0
|
3419 |
{
|
insilmaril@0
|
3420 |
searching=false;
|
insilmaril@0
|
3421 |
foundNote=true;
|
insilmaril@0
|
3422 |
}
|
insilmaril@0
|
3423 |
}
|
insilmaril@0
|
3424 |
// Searching in Heading
|
insilmaril@0
|
3425 |
if (searching && itFind->getHeading().contains (s,cs) )
|
insilmaril@0
|
3426 |
{
|
insilmaril@424
|
3427 |
xelection.select(itFind);
|
insilmaril@0
|
3428 |
ensureSelectionVisible();
|
insilmaril@0
|
3429 |
searching=false;
|
insilmaril@0
|
3430 |
}
|
insilmaril@0
|
3431 |
}
|
insilmaril@0
|
3432 |
if (!foundNote)
|
insilmaril@0
|
3433 |
{
|
insilmaril@645
|
3434 |
itFind=model->next(itFind);
|
insilmaril@0
|
3435 |
if (!itFind) EOFind=true;
|
insilmaril@0
|
3436 |
}
|
insilmaril@684
|
3437 |
//cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
|
insilmaril@0
|
3438 |
}
|
insilmaril@0
|
3439 |
if (!searching)
|
insilmaril@424
|
3440 |
return xelection.getBranch();
|
insilmaril@424
|
3441 |
else
|
insilmaril@0
|
3442 |
return NULL;
|
insilmaril@0
|
3443 |
}
|
insilmaril@0
|
3444 |
|
insilmaril@0
|
3445 |
void MapEditor::findReset()
|
insilmaril@0
|
3446 |
{ // Necessary if text to find changes during a find process
|
insilmaril@0
|
3447 |
itFind=NULL;
|
insilmaril@0
|
3448 |
EOFind=false;
|
insilmaril@0
|
3449 |
}
|
insilmaril@395
|
3450 |
void MapEditor::setURL(const QString &url)
|
insilmaril@395
|
3451 |
{
|
insilmaril@424
|
3452 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3453 |
if (bo)
|
insilmaril@424
|
3454 |
{
|
insilmaril@395
|
3455 |
QString oldurl=bo->getURL();
|
insilmaril@395
|
3456 |
bo->setURL (url);
|
insilmaril@395
|
3457 |
saveState (
|
insilmaril@424
|
3458 |
bo,
|
insilmaril@395
|
3459 |
QString ("setURL (\"%1\")").arg(oldurl),
|
insilmaril@424
|
3460 |
bo,
|
insilmaril@395
|
3461 |
QString ("setURL (\"%1\")").arg(url),
|
insilmaril@395
|
3462 |
QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
|
insilmaril@395
|
3463 |
);
|
insilmaril@395
|
3464 |
updateActions();
|
insilmaril@645
|
3465 |
model->reposition();
|
insilmaril@491
|
3466 |
xelection.update();
|
insilmaril@491
|
3467 |
ensureSelectionVisible();
|
insilmaril@395
|
3468 |
}
|
insilmaril@395
|
3469 |
}
|
insilmaril@0
|
3470 |
|
insilmaril@0
|
3471 |
void MapEditor::editURL()
|
insilmaril@0
|
3472 |
{
|
insilmaril@424
|
3473 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3474 |
if (bo)
|
insilmaril@0
|
3475 |
{
|
insilmaril@0
|
3476 |
bool ok;
|
insilmaril@0
|
3477 |
QString text = QInputDialog::getText(
|
insilmaril@0
|
3478 |
"VYM", tr("Enter URL:"), QLineEdit::Normal,
|
insilmaril@143
|
3479 |
bo->getURL(), &ok, this );
|
insilmaril@0
|
3480 |
if ( ok)
|
insilmaril@0
|
3481 |
// user entered something and pressed OK
|
insilmaril@395
|
3482 |
setURL (text);
|
insilmaril@0
|
3483 |
}
|
insilmaril@0
|
3484 |
}
|
insilmaril@0
|
3485 |
|
insilmaril@528
|
3486 |
void MapEditor::editLocalURL()
|
insilmaril@528
|
3487 |
{
|
insilmaril@528
|
3488 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@528
|
3489 |
if (bo)
|
insilmaril@528
|
3490 |
{
|
insilmaril@528
|
3491 |
QStringList filters;
|
insilmaril@528
|
3492 |
filters <<"All files (*)";
|
insilmaril@528
|
3493 |
filters << tr("Text","Filedialog") + " (*.txt)";
|
insilmaril@528
|
3494 |
filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
|
insilmaril@528
|
3495 |
filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
|
insilmaril@528
|
3496 |
filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
|
insilmaril@528
|
3497 |
QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file"));
|
insilmaril@528
|
3498 |
fd->setFilters (filters);
|
insilmaril@528
|
3499 |
fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
|
insilmaril@528
|
3500 |
fd->setDirectory (lastFileDir);
|
insilmaril@528
|
3501 |
if (! bo->getVymLink().isEmpty() )
|
insilmaril@528
|
3502 |
fd->selectFile( bo->getURL() );
|
insilmaril@528
|
3503 |
fd->show();
|
insilmaril@528
|
3504 |
|
insilmaril@528
|
3505 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@528
|
3506 |
{
|
insilmaril@528
|
3507 |
lastFileDir=QDir (fd->directory().path());
|
insilmaril@528
|
3508 |
setURL (fd->selectedFile() );
|
insilmaril@528
|
3509 |
}
|
insilmaril@528
|
3510 |
}
|
insilmaril@528
|
3511 |
}
|
insilmaril@528
|
3512 |
|
insilmaril@266
|
3513 |
QString MapEditor::getURL()
|
insilmaril@266
|
3514 |
{
|
insilmaril@424
|
3515 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3516 |
if (bo)
|
insilmaril@424
|
3517 |
return bo->getURL();
|
insilmaril@266
|
3518 |
else
|
insilmaril@266
|
3519 |
return "";
|
insilmaril@266
|
3520 |
}
|
insilmaril@266
|
3521 |
|
insilmaril@366
|
3522 |
QStringList MapEditor::getURLs()
|
insilmaril@366
|
3523 |
{
|
insilmaril@366
|
3524 |
QStringList urls;
|
insilmaril@424
|
3525 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3526 |
if (bo)
|
insilmaril@366
|
3527 |
{
|
insilmaril@366
|
3528 |
bo=bo->first();
|
insilmaril@366
|
3529 |
while (bo)
|
insilmaril@366
|
3530 |
{
|
insilmaril@366
|
3531 |
if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
|
insilmaril@366
|
3532 |
bo=bo->next();
|
insilmaril@366
|
3533 |
}
|
insilmaril@366
|
3534 |
}
|
insilmaril@366
|
3535 |
return urls;
|
insilmaril@366
|
3536 |
}
|
insilmaril@366
|
3537 |
|
insilmaril@366
|
3538 |
|
insilmaril@0
|
3539 |
void MapEditor::editHeading2URL()
|
insilmaril@0
|
3540 |
{
|
insilmaril@424
|
3541 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3542 |
if (bo)
|
insilmaril@424
|
3543 |
setURL (bo->getHeading());
|
insilmaril@0
|
3544 |
}
|
insilmaril@0
|
3545 |
|
insilmaril@0
|
3546 |
void MapEditor::editBugzilla2URL()
|
insilmaril@0
|
3547 |
{
|
insilmaril@424
|
3548 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3549 |
if (bo)
|
insilmaril@0
|
3550 |
{
|
insilmaril@143
|
3551 |
QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
|
insilmaril@395
|
3552 |
setURL (url);
|
insilmaril@0
|
3553 |
}
|
insilmaril@0
|
3554 |
}
|
insilmaril@0
|
3555 |
|
insilmaril@175
|
3556 |
void MapEditor::editFATE2URL()
|
insilmaril@175
|
3557 |
{
|
insilmaril@424
|
3558 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3559 |
if (bo)
|
insilmaril@175
|
3560 |
{
|
insilmaril@175
|
3561 |
QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
|
insilmaril@395
|
3562 |
saveState(
|
insilmaril@424
|
3563 |
bo,
|
insilmaril@395
|
3564 |
"setURL (\""+bo->getURL()+"\")",
|
insilmaril@424
|
3565 |
bo,
|
insilmaril@395
|
3566 |
"setURL (\""+url+"\")",
|
insilmaril@395
|
3567 |
QString("Use heading of %1 as link to FATE").arg(getName(bo))
|
insilmaril@395
|
3568 |
);
|
insilmaril@175
|
3569 |
bo->setURL (url);
|
insilmaril@175
|
3570 |
updateActions();
|
insilmaril@175
|
3571 |
}
|
insilmaril@175
|
3572 |
}
|
insilmaril@175
|
3573 |
|
insilmaril@0
|
3574 |
void MapEditor::editVymLink()
|
insilmaril@0
|
3575 |
{
|
insilmaril@424
|
3576 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3577 |
if (bo)
|
insilmaril@0
|
3578 |
{
|
insilmaril@404
|
3579 |
QStringList filters;
|
insilmaril@404
|
3580 |
filters <<"VYM map (*.vym)";
|
insilmaril@404
|
3581 |
QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
|
insilmaril@404
|
3582 |
fd->setFilters (filters);
|
insilmaril@404
|
3583 |
fd->setCaption(vymName+" - " +tr("Link to another map"));
|
insilmaril@442
|
3584 |
fd->setDirectory (lastFileDir);
|
insilmaril@143
|
3585 |
if (! bo->getVymLink().isEmpty() )
|
insilmaril@404
|
3586 |
fd->selectFile( bo->getVymLink() );
|
insilmaril@0
|
3587 |
fd->show();
|
insilmaril@0
|
3588 |
|
insilmaril@0
|
3589 |
QString fn;
|
insilmaril@0
|
3590 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@143
|
3591 |
{
|
insilmaril@442
|
3592 |
lastFileDir=QDir (fd->directory().path());
|
insilmaril@395
|
3593 |
saveState(
|
insilmaril@424
|
3594 |
bo,
|
insilmaril@395
|
3595 |
"setVymLink (\""+bo->getVymLink()+"\")",
|
insilmaril@424
|
3596 |
bo,
|
insilmaril@395
|
3597 |
"setVymLink (\""+fd->selectedFile()+"\")",
|
insilmaril@395
|
3598 |
QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
|
insilmaril@395
|
3599 |
);
|
insilmaril@491
|
3600 |
setVymLinkInt (fd->selectedFile() );
|
insilmaril@143
|
3601 |
}
|
insilmaril@0
|
3602 |
}
|
insilmaril@0
|
3603 |
}
|
insilmaril@0
|
3604 |
|
insilmaril@0
|
3605 |
void MapEditor::deleteVymLink()
|
insilmaril@0
|
3606 |
{
|
insilmaril@424
|
3607 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3608 |
if (bo)
|
insilmaril@0
|
3609 |
{
|
insilmaril@395
|
3610 |
saveState(
|
insilmaril@424
|
3611 |
bo,
|
insilmaril@395
|
3612 |
"setVymLink (\""+bo->getVymLink()+"\")",
|
insilmaril@424
|
3613 |
bo,
|
insilmaril@395
|
3614 |
"setVymLink (\"\")",
|
insilmaril@395
|
3615 |
QString("Unset vymlink of %1").arg(getName(bo))
|
insilmaril@395
|
3616 |
);
|
insilmaril@143
|
3617 |
bo->setVymLink ("" );
|
insilmaril@0
|
3618 |
updateActions();
|
insilmaril@645
|
3619 |
model->reposition();
|
insilmaril@408
|
3620 |
scene()->update();
|
insilmaril@0
|
3621 |
}
|
insilmaril@0
|
3622 |
}
|
insilmaril@0
|
3623 |
|
insilmaril@395
|
3624 |
void MapEditor::setHideExport(bool b)
|
insilmaril@243
|
3625 |
{
|
insilmaril@424
|
3626 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3627 |
if (bo)
|
insilmaril@395
|
3628 |
{
|
insilmaril@424
|
3629 |
bo->setHideInExport (b);
|
insilmaril@395
|
3630 |
QString u= b ? "false" : "true";
|
insilmaril@395
|
3631 |
QString r=!b ? "false" : "true";
|
insilmaril@395
|
3632 |
|
insilmaril@395
|
3633 |
saveState(
|
insilmaril@424
|
3634 |
bo,
|
insilmaril@395
|
3635 |
QString ("setHideExport (%1)").arg(u),
|
insilmaril@424
|
3636 |
bo,
|
insilmaril@395
|
3637 |
QString ("setHideExport (%1)").arg(r),
|
insilmaril@424
|
3638 |
QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r)
|
insilmaril@395
|
3639 |
);
|
insilmaril@243
|
3640 |
updateActions();
|
insilmaril@645
|
3641 |
model->reposition();
|
insilmaril@491
|
3642 |
xelection.update();
|
insilmaril@408
|
3643 |
scene()->update();
|
insilmaril@243
|
3644 |
}
|
insilmaril@243
|
3645 |
}
|
insilmaril@243
|
3646 |
|
insilmaril@395
|
3647 |
void MapEditor::toggleHideExport()
|
insilmaril@395
|
3648 |
{
|
insilmaril@424
|
3649 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3650 |
if (bo)
|
insilmaril@424
|
3651 |
setHideExport ( !bo->hideInExport() );
|
insilmaril@395
|
3652 |
}
|
insilmaril@395
|
3653 |
|
insilmaril@0
|
3654 |
QString MapEditor::getVymLink()
|
insilmaril@0
|
3655 |
{
|
insilmaril@424
|
3656 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3657 |
if (bo)
|
insilmaril@424
|
3658 |
return bo->getVymLink();
|
insilmaril@424
|
3659 |
else
|
insilmaril@424
|
3660 |
return "";
|
insilmaril@0
|
3661 |
|
insilmaril@0
|
3662 |
}
|
insilmaril@0
|
3663 |
|
insilmaril@366
|
3664 |
QStringList MapEditor::getVymLinks()
|
insilmaril@366
|
3665 |
{
|
insilmaril@366
|
3666 |
QStringList links;
|
insilmaril@424
|
3667 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3668 |
if (bo)
|
insilmaril@366
|
3669 |
{
|
insilmaril@366
|
3670 |
bo=bo->first();
|
insilmaril@366
|
3671 |
while (bo)
|
insilmaril@366
|
3672 |
{
|
insilmaril@366
|
3673 |
if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
|
insilmaril@366
|
3674 |
bo=bo->next();
|
insilmaril@366
|
3675 |
}
|
insilmaril@366
|
3676 |
}
|
insilmaril@366
|
3677 |
return links;
|
insilmaril@366
|
3678 |
}
|
insilmaril@366
|
3679 |
|
insilmaril@366
|
3680 |
|
insilmaril@395
|
3681 |
void MapEditor::deleteKeepChilds()
|
insilmaril@98
|
3682 |
{
|
insilmaril@424
|
3683 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3684 |
BranchObj *par;
|
insilmaril@424
|
3685 |
if (bo)
|
insilmaril@424
|
3686 |
{
|
insilmaril@424
|
3687 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@408
|
3688 |
QPointF p=bo->getRelPos();
|
insilmaril@395
|
3689 |
saveStateChangingPart(
|
insilmaril@424
|
3690 |
bo->getParObj(),
|
insilmaril@424
|
3691 |
bo,
|
insilmaril@395
|
3692 |
"deleteKeepChilds ()",
|
insilmaril@395
|
3693 |
QString("Remove %1 and keep its childs").arg(getName(bo))
|
insilmaril@395
|
3694 |
);
|
insilmaril@394
|
3695 |
|
insilmaril@684
|
3696 |
QString sel=model->getSelectString(bo);
|
insilmaril@98
|
3697 |
unselect();
|
insilmaril@98
|
3698 |
par->removeBranchHere(bo);
|
insilmaril@645
|
3699 |
model->reposition();
|
insilmaril@98
|
3700 |
select (sel);
|
insilmaril@424
|
3701 |
xelection.getBranch()->move2RelPos (p);
|
insilmaril@645
|
3702 |
model->reposition();
|
insilmaril@98
|
3703 |
}
|
insilmaril@98
|
3704 |
}
|
insilmaril@98
|
3705 |
|
insilmaril@395
|
3706 |
void MapEditor::deleteChilds()
|
insilmaril@98
|
3707 |
{
|
insilmaril@424
|
3708 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
3709 |
if (bo)
|
insilmaril@98
|
3710 |
{
|
insilmaril@395
|
3711 |
saveStateChangingPart(
|
insilmaril@491
|
3712 |
bo,
|
insilmaril@424
|
3713 |
bo,
|
insilmaril@395
|
3714 |
"deleteChilds ()",
|
insilmaril@424
|
3715 |
QString( "Remove childs of branch %1").arg(getName(bo))
|
insilmaril@395
|
3716 |
);
|
insilmaril@424
|
3717 |
bo->removeChilds();
|
insilmaril@645
|
3718 |
model->reposition();
|
insilmaril@98
|
3719 |
}
|
insilmaril@98
|
3720 |
}
|
insilmaril@98
|
3721 |
|
insilmaril@0
|
3722 |
void MapEditor::editMapInfo()
|
insilmaril@0
|
3723 |
{
|
insilmaril@0
|
3724 |
ExtraInfoDialog dia;
|
insilmaril@0
|
3725 |
dia.setMapName (getFileName() );
|
insilmaril@645
|
3726 |
dia.setAuthor (model->getAuthor() );
|
insilmaril@645
|
3727 |
dia.setComment(model->getComment() );
|
insilmaril@0
|
3728 |
|
insilmaril@0
|
3729 |
// Calc some stats
|
insilmaril@0
|
3730 |
QString stats;
|
insilmaril@408
|
3731 |
stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
|
insilmaril@0
|
3732 |
|
insilmaril@0
|
3733 |
uint b=0;
|
insilmaril@0
|
3734 |
uint f=0;
|
insilmaril@0
|
3735 |
uint n=0;
|
insilmaril@103
|
3736 |
uint xl=0;
|
insilmaril@0
|
3737 |
BranchObj *bo;
|
insilmaril@645
|
3738 |
bo=model->first();
|
insilmaril@0
|
3739 |
while (bo)
|
insilmaril@0
|
3740 |
{
|
insilmaril@0
|
3741 |
if (!bo->getNote().isEmpty() ) n++;
|
insilmaril@0
|
3742 |
f+= bo->countFloatImages();
|
insilmaril@0
|
3743 |
b++;
|
insilmaril@103
|
3744 |
xl+=bo->countXLinks();
|
insilmaril@645
|
3745 |
bo=model->next(bo);
|
insilmaril@0
|
3746 |
}
|
insilmaril@0
|
3747 |
stats+=QString ("%1 branches\n").arg (b-1,6);
|
insilmaril@104
|
3748 |
stats+=QString ("%1 xLinks \n").arg (xl,6);
|
insilmaril@0
|
3749 |
stats+=QString ("%1 notes\n").arg (n,6);
|
insilmaril@0
|
3750 |
stats+=QString ("%1 images\n").arg (f,6);
|
insilmaril@0
|
3751 |
dia.setStats (stats);
|
insilmaril@0
|
3752 |
|
insilmaril@0
|
3753 |
// Finally show dialog
|
insilmaril@0
|
3754 |
if (dia.exec() == QDialog::Accepted)
|
insilmaril@0
|
3755 |
{
|
insilmaril@398
|
3756 |
setMapAuthor (dia.getAuthor() );
|
insilmaril@398
|
3757 |
setMapComment (dia.getComment() );
|
insilmaril@0
|
3758 |
}
|
insilmaril@0
|
3759 |
}
|
insilmaril@0
|
3760 |
|
insilmaril@442
|
3761 |
void MapEditor::ensureSelectionVisible()
|
insilmaril@442
|
3762 |
{
|
insilmaril@442
|
3763 |
LinkableMapObj *lmo=xelection.single();
|
insilmaril@442
|
3764 |
if (lmo) ensureVisible (lmo->getBBox() );
|
insilmaril@442
|
3765 |
|
insilmaril@442
|
3766 |
}
|
insilmaril@442
|
3767 |
|
insilmaril@442
|
3768 |
void MapEditor::updateSelection()
|
insilmaril@442
|
3769 |
{
|
insilmaril@442
|
3770 |
// Tell selection to update geometries
|
insilmaril@442
|
3771 |
xelection.update();
|
insilmaril@442
|
3772 |
}
|
insilmaril@442
|
3773 |
|
insilmaril@0
|
3774 |
void MapEditor::updateActions()
|
insilmaril@0
|
3775 |
{
|
insilmaril@442
|
3776 |
// Tell mainwindow to update states of actions
|
insilmaril@390
|
3777 |
mainWindow->updateActions();
|
insilmaril@412
|
3778 |
// TODO maybe don't update if blockReposition is set
|
insilmaril@0
|
3779 |
}
|
insilmaril@0
|
3780 |
|
insilmaril@160
|
3781 |
void MapEditor::updateNoteFlag()
|
insilmaril@160
|
3782 |
{
|
insilmaril@427
|
3783 |
setChanged();
|
insilmaril@424
|
3784 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@427
|
3785 |
if (bo)
|
insilmaril@427
|
3786 |
{
|
insilmaril@427
|
3787 |
bo->updateNoteFlag();
|
insilmaril@427
|
3788 |
mainWindow->updateActions();
|
insilmaril@427
|
3789 |
}
|
insilmaril@160
|
3790 |
}
|
insilmaril@160
|
3791 |
|
insilmaril@398
|
3792 |
void MapEditor::setMapAuthor (const QString &s)
|
insilmaril@0
|
3793 |
{
|
insilmaril@398
|
3794 |
saveState (
|
insilmaril@645
|
3795 |
QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()),
|
insilmaril@398
|
3796 |
QString ("setMapAuthor (\"%1\")").arg(s),
|
insilmaril@398
|
3797 |
QString ("Set author of map to \"%1\"").arg(s)
|
insilmaril@398
|
3798 |
);
|
insilmaril@645
|
3799 |
model->setAuthor (s);
|
insilmaril@398
|
3800 |
}
|
insilmaril@398
|
3801 |
|
insilmaril@398
|
3802 |
void MapEditor::setMapComment (const QString &s)
|
insilmaril@398
|
3803 |
{
|
insilmaril@398
|
3804 |
saveState (
|
insilmaril@645
|
3805 |
QString ("setMapComment (\"%1\")").arg(model->getComment()),
|
insilmaril@398
|
3806 |
QString ("setMapComment (\"%1\")").arg(s),
|
insilmaril@398
|
3807 |
QString ("Set comment of map")
|
insilmaril@398
|
3808 |
);
|
insilmaril@645
|
3809 |
model->setComment (s);
|
insilmaril@398
|
3810 |
}
|
insilmaril@398
|
3811 |
|
insilmaril@398
|
3812 |
void MapEditor::setMapLinkStyle (const QString & s)
|
insilmaril@398
|
3813 |
{
|
insilmaril@645
|
3814 |
QString snow;
|
insilmaril@645
|
3815 |
if (linkstyle==LinkableMapObj::Line)
|
insilmaril@645
|
3816 |
snow="StyleLine";
|
insilmaril@645
|
3817 |
else if (linkstyle==LinkableMapObj::Parabel)
|
insilmaril@645
|
3818 |
snow="StyleParabel";
|
insilmaril@645
|
3819 |
else if (linkstyle==LinkableMapObj::PolyLine)
|
insilmaril@645
|
3820 |
snow="StylePolyLine";
|
insilmaril@645
|
3821 |
else if (linkstyle==LinkableMapObj::PolyParabel)
|
insilmaril@645
|
3822 |
snow="StyleParabel";
|
insilmaril@645
|
3823 |
|
insilmaril@645
|
3824 |
saveState (
|
insilmaril@398
|
3825 |
QString("setMapLinkStyle (\"%1\")").arg(s),
|
insilmaril@645
|
3826 |
QString("setMapLinkStyle (\"%1\")").arg(snow),
|
insilmaril@398
|
3827 |
QString("Set map link style (\"%1\")").arg(s)
|
insilmaril@398
|
3828 |
);
|
insilmaril@398
|
3829 |
|
insilmaril@398
|
3830 |
if (s=="StyleLine")
|
insilmaril@473
|
3831 |
linkstyle=LinkableMapObj::Line;
|
insilmaril@398
|
3832 |
else if (s=="StyleParabel")
|
insilmaril@473
|
3833 |
linkstyle=LinkableMapObj::Parabel;
|
insilmaril@398
|
3834 |
else if (s=="StylePolyLine")
|
insilmaril@473
|
3835 |
linkstyle=LinkableMapObj::PolyLine;
|
insilmaril@398
|
3836 |
else
|
insilmaril@473
|
3837 |
linkstyle=LinkableMapObj::PolyParabel;
|
insilmaril@398
|
3838 |
|
insilmaril@0
|
3839 |
BranchObj *bo;
|
insilmaril@645
|
3840 |
bo=model->first();
|
insilmaril@645
|
3841 |
bo=model->next(bo);
|
insilmaril@0
|
3842 |
while (bo)
|
insilmaril@0
|
3843 |
{
|
insilmaril@0
|
3844 |
bo->setLinkStyle(bo->getDefLinkStyle());
|
insilmaril@645
|
3845 |
bo=model->next(bo);
|
insilmaril@0
|
3846 |
}
|
insilmaril@645
|
3847 |
model->reposition();
|
insilmaril@0
|
3848 |
}
|
insilmaril@0
|
3849 |
|
insilmaril@473
|
3850 |
LinkableMapObj::Style MapEditor::getMapLinkStyle ()
|
insilmaril@0
|
3851 |
{
|
insilmaril@0
|
3852 |
return linkstyle;
|
insilmaril@0
|
3853 |
}
|
insilmaril@0
|
3854 |
|
insilmaril@398
|
3855 |
void MapEditor::setMapDefLinkColor(QColor c)
|
insilmaril@0
|
3856 |
{
|
insilmaril@97
|
3857 |
defLinkColor=c;
|
insilmaril@497
|
3858 |
BranchObj *bo;
|
insilmaril@645
|
3859 |
bo=model->first();
|
insilmaril@497
|
3860 |
while (bo)
|
insilmaril@497
|
3861 |
{
|
insilmaril@497
|
3862 |
bo->setLinkColor();
|
insilmaril@645
|
3863 |
bo=model->next(bo);
|
insilmaril@497
|
3864 |
}
|
insilmaril@0
|
3865 |
updateActions();
|
insilmaril@0
|
3866 |
}
|
insilmaril@0
|
3867 |
|
insilmaril@398
|
3868 |
void MapEditor::setMapLinkColorHintInt()
|
insilmaril@0
|
3869 |
{
|
insilmaril@398
|
3870 |
// called from setMapLinkColorHint(lch) or at end of parse
|
insilmaril@0
|
3871 |
BranchObj *bo;
|
insilmaril@645
|
3872 |
bo=model->first();
|
insilmaril@0
|
3873 |
while (bo)
|
insilmaril@0
|
3874 |
{
|
insilmaril@0
|
3875 |
bo->setLinkColor();
|
insilmaril@645
|
3876 |
bo=model->next(bo);
|
insilmaril@0
|
3877 |
}
|
insilmaril@0
|
3878 |
}
|
insilmaril@0
|
3879 |
|
insilmaril@473
|
3880 |
void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
|
insilmaril@0
|
3881 |
{
|
insilmaril@0
|
3882 |
linkcolorhint=lch;
|
insilmaril@398
|
3883 |
setMapLinkColorHintInt();
|
insilmaril@0
|
3884 |
}
|
insilmaril@0
|
3885 |
|
insilmaril@398
|
3886 |
void MapEditor::toggleMapLinkColorHint()
|
insilmaril@0
|
3887 |
{
|
insilmaril@473
|
3888 |
if (linkcolorhint==LinkableMapObj::HeadingColor)
|
insilmaril@473
|
3889 |
linkcolorhint=LinkableMapObj::DefaultColor;
|
insilmaril@0
|
3890 |
else
|
insilmaril@473
|
3891 |
linkcolorhint=LinkableMapObj::HeadingColor;
|
insilmaril@0
|
3892 |
BranchObj *bo;
|
insilmaril@645
|
3893 |
bo=model->first();
|
insilmaril@0
|
3894 |
while (bo)
|
insilmaril@0
|
3895 |
{
|
insilmaril@0
|
3896 |
bo->setLinkColor();
|
insilmaril@645
|
3897 |
bo=model->next(bo);
|
insilmaril@0
|
3898 |
}
|
insilmaril@0
|
3899 |
}
|
insilmaril@0
|
3900 |
|
insilmaril@473
|
3901 |
LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint()
|
insilmaril@0
|
3902 |
{
|
insilmaril@0
|
3903 |
return linkcolorhint;
|
insilmaril@0
|
3904 |
}
|
insilmaril@0
|
3905 |
|
insilmaril@398
|
3906 |
QColor MapEditor::getMapDefLinkColor()
|
insilmaril@0
|
3907 |
{
|
insilmaril@97
|
3908 |
return defLinkColor;
|
insilmaril@97
|
3909 |
}
|
insilmaril@97
|
3910 |
|
insilmaril@398
|
3911 |
void MapEditor::setMapDefXLinkColor(QColor col)
|
insilmaril@97
|
3912 |
{
|
insilmaril@97
|
3913 |
defXLinkColor=col;
|
insilmaril@97
|
3914 |
}
|
insilmaril@97
|
3915 |
|
insilmaril@398
|
3916 |
QColor MapEditor::getMapDefXLinkColor()
|
insilmaril@97
|
3917 |
{
|
insilmaril@97
|
3918 |
return defXLinkColor;
|
insilmaril@97
|
3919 |
}
|
insilmaril@97
|
3920 |
|
insilmaril@398
|
3921 |
void MapEditor::setMapDefXLinkWidth (int w)
|
insilmaril@97
|
3922 |
{
|
insilmaril@97
|
3923 |
defXLinkWidth=w;
|
insilmaril@97
|
3924 |
}
|
insilmaril@97
|
3925 |
|
insilmaril@398
|
3926 |
int MapEditor::getMapDefXLinkWidth()
|
insilmaril@97
|
3927 |
{
|
insilmaril@97
|
3928 |
return defXLinkWidth;
|
insilmaril@0
|
3929 |
}
|
insilmaril@0
|
3930 |
|
insilmaril@398
|
3931 |
void MapEditor::selectMapLinkColor()
|
insilmaril@0
|
3932 |
{
|
insilmaril@97
|
3933 |
QColor col = QColorDialog::getColor( defLinkColor, this );
|
insilmaril@0
|
3934 |
if ( !col.isValid() ) return;
|
insilmaril@398
|
3935 |
saveState (
|
insilmaril@398
|
3936 |
QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
|
insilmaril@398
|
3937 |
QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
|
insilmaril@497
|
3938 |
QString("Set map link color to %1").arg(col.name())
|
insilmaril@398
|
3939 |
);
|
insilmaril@398
|
3940 |
setMapDefLinkColor( col );
|
insilmaril@442
|
3941 |
}
|
insilmaril@442
|
3942 |
|
insilmaril@442
|
3943 |
void MapEditor::selectMapSelectionColor()
|
insilmaril@442
|
3944 |
{
|
insilmaril@442
|
3945 |
QColor col = QColorDialog::getColor( defLinkColor, this );
|
insilmaril@442
|
3946 |
setSelectionColor (col);
|
insilmaril@442
|
3947 |
}
|
insilmaril@442
|
3948 |
|
insilmaril@442
|
3949 |
void MapEditor::setSelectionColorInt (QColor col)
|
insilmaril@442
|
3950 |
{
|
insilmaril@442
|
3951 |
if ( !col.isValid() ) return;
|
insilmaril@442
|
3952 |
xelection.setColor (col);
|
insilmaril@442
|
3953 |
}
|
insilmaril@442
|
3954 |
|
insilmaril@442
|
3955 |
void MapEditor::setSelectionColor(QColor col)
|
insilmaril@442
|
3956 |
{
|
insilmaril@442
|
3957 |
if ( !col.isValid() ) return;
|
insilmaril@442
|
3958 |
saveState (
|
insilmaril@442
|
3959 |
QString("setSelectionColor (%1)").arg(xelection.getColor().name()),
|
insilmaril@442
|
3960 |
QString("setSelectionColor (%1)").arg(col.name()),
|
insilmaril@442
|
3961 |
QString("Set color of selection box to %1").arg(col.name())
|
insilmaril@442
|
3962 |
);
|
insilmaril@442
|
3963 |
setSelectionColorInt (col);
|
insilmaril@442
|
3964 |
}
|
insilmaril@442
|
3965 |
|
insilmaril@442
|
3966 |
QColor MapEditor::getSelectionColor()
|
insilmaril@442
|
3967 |
{
|
insilmaril@442
|
3968 |
return xelection.getColor();
|
insilmaril@0
|
3969 |
}
|
insilmaril@0
|
3970 |
|
insilmaril@473
|
3971 |
bool MapEditor::scrollBranch(BranchObj *bo)
|
insilmaril@0
|
3972 |
{
|
insilmaril@427
|
3973 |
if (bo)
|
insilmaril@0
|
3974 |
{
|
insilmaril@427
|
3975 |
if (bo->isScrolled()) return false;
|
insilmaril@427
|
3976 |
if (bo->countBranches()==0) return false;
|
insilmaril@427
|
3977 |
if (bo->getDepth()==0) return false;
|
insilmaril@395
|
3978 |
QString u,r;
|
insilmaril@427
|
3979 |
r="scroll";
|
insilmaril@427
|
3980 |
u="unscroll";
|
insilmaril@395
|
3981 |
saveState(
|
insilmaril@424
|
3982 |
bo,
|
insilmaril@395
|
3983 |
QString ("%1 ()").arg(u),
|
insilmaril@424
|
3984 |
bo,
|
insilmaril@395
|
3985 |
QString ("%1 ()").arg(r),
|
insilmaril@395
|
3986 |
QString ("%1 %2").arg(r).arg(getName(bo))
|
insilmaril@395
|
3987 |
);
|
insilmaril@0
|
3988 |
bo->toggleScroll();
|
insilmaril@491
|
3989 |
xelection.update();
|
insilmaril@408
|
3990 |
scene()->update();
|
insilmaril@427
|
3991 |
return true;
|
insilmaril@427
|
3992 |
}
|
insilmaril@427
|
3993 |
return false;
|
insilmaril@427
|
3994 |
}
|
insilmaril@427
|
3995 |
|
insilmaril@473
|
3996 |
bool MapEditor::unscrollBranch(BranchObj *bo)
|
insilmaril@427
|
3997 |
{
|
insilmaril@427
|
3998 |
if (bo)
|
insilmaril@427
|
3999 |
{
|
insilmaril@427
|
4000 |
if (!bo->isScrolled()) return false;
|
insilmaril@427
|
4001 |
if (bo->countBranches()==0) return false;
|
insilmaril@427
|
4002 |
if (bo->getDepth()==0) return false;
|
insilmaril@427
|
4003 |
QString u,r;
|
insilmaril@427
|
4004 |
u="scroll";
|
insilmaril@427
|
4005 |
r="unscroll";
|
insilmaril@427
|
4006 |
saveState(
|
insilmaril@427
|
4007 |
bo,
|
insilmaril@427
|
4008 |
QString ("%1 ()").arg(u),
|
insilmaril@427
|
4009 |
bo,
|
insilmaril@427
|
4010 |
QString ("%1 ()").arg(r),
|
insilmaril@427
|
4011 |
QString ("%1 %2").arg(r).arg(getName(bo))
|
insilmaril@427
|
4012 |
);
|
insilmaril@427
|
4013 |
bo->toggleScroll();
|
insilmaril@491
|
4014 |
xelection.update();
|
insilmaril@427
|
4015 |
scene()->update();
|
insilmaril@427
|
4016 |
return true;
|
insilmaril@427
|
4017 |
}
|
insilmaril@427
|
4018 |
return false;
|
insilmaril@427
|
4019 |
}
|
insilmaril@427
|
4020 |
|
insilmaril@427
|
4021 |
void MapEditor::toggleScroll()
|
insilmaril@427
|
4022 |
{
|
insilmaril@427
|
4023 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@491
|
4024 |
if (xelection.type()==Selection::Branch )
|
insilmaril@427
|
4025 |
{
|
insilmaril@427
|
4026 |
if (bo->isScrolled())
|
insilmaril@473
|
4027 |
unscrollBranch (bo);
|
insilmaril@427
|
4028 |
else
|
insilmaril@473
|
4029 |
scrollBranch (bo);
|
insilmaril@0
|
4030 |
}
|
insilmaril@0
|
4031 |
}
|
insilmaril@0
|
4032 |
|
insilmaril@473
|
4033 |
void MapEditor::unscrollChilds()
|
insilmaril@0
|
4034 |
{
|
insilmaril@428
|
4035 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@428
|
4036 |
if (bo)
|
insilmaril@0
|
4037 |
{
|
insilmaril@428
|
4038 |
bo->first();
|
insilmaril@428
|
4039 |
while (bo)
|
insilmaril@428
|
4040 |
{
|
insilmaril@473
|
4041 |
if (bo->isScrolled()) unscrollBranch (bo);
|
insilmaril@428
|
4042 |
bo=bo->next();
|
insilmaril@428
|
4043 |
}
|
insilmaril@428
|
4044 |
}
|
insilmaril@0
|
4045 |
}
|
insilmaril@0
|
4046 |
|
insilmaril@432
|
4047 |
FloatImageObj* MapEditor::loadFloatImageInt (QString fn)
|
insilmaril@432
|
4048 |
{
|
insilmaril@432
|
4049 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@432
|
4050 |
if (bo)
|
insilmaril@432
|
4051 |
{
|
insilmaril@432
|
4052 |
FloatImageObj *fio;
|
insilmaril@432
|
4053 |
bo->addFloatImage();
|
insilmaril@432
|
4054 |
fio=bo->getLastFloatImage();
|
insilmaril@432
|
4055 |
fio->load(fn);
|
insilmaril@645
|
4056 |
model->reposition();
|
insilmaril@432
|
4057 |
scene()->update();
|
insilmaril@432
|
4058 |
return fio;
|
insilmaril@432
|
4059 |
}
|
insilmaril@432
|
4060 |
return NULL;
|
insilmaril@432
|
4061 |
}
|
insilmaril@428
|
4062 |
|
insilmaril@0
|
4063 |
void MapEditor::loadFloatImage ()
|
insilmaril@0
|
4064 |
{
|
insilmaril@424
|
4065 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4066 |
if (bo)
|
insilmaril@0
|
4067 |
{
|
insilmaril@0
|
4068 |
|
insilmaril@366
|
4069 |
Q3FileDialog *fd=new Q3FileDialog( this);
|
insilmaril@366
|
4070 |
fd->setMode (Q3FileDialog::ExistingFiles);
|
insilmaril@0
|
4071 |
fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
|
insilmaril@0
|
4072 |
ImagePreview *p =new ImagePreview (fd);
|
insilmaril@0
|
4073 |
fd->setContentsPreviewEnabled( TRUE );
|
insilmaril@0
|
4074 |
fd->setContentsPreview( p, p );
|
insilmaril@366
|
4075 |
fd->setPreviewMode( Q3FileDialog::Contents );
|
insilmaril@404
|
4076 |
fd->setCaption(vymName+" - " +tr("Load image"));
|
insilmaril@0
|
4077 |
fd->setDir (lastImageDir);
|
insilmaril@0
|
4078 |
fd->show();
|
insilmaril@0
|
4079 |
|
insilmaril@0
|
4080 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
4081 |
{
|
insilmaril@491
|
4082 |
// TODO loadFIO in QT4 use: lastImageDir=fd->directory();
|
insilmaril@366
|
4083 |
lastImageDir=QDir (fd->dirPath());
|
insilmaril@432
|
4084 |
QString s;
|
insilmaril@395
|
4085 |
FloatImageObj *fio;
|
insilmaril@432
|
4086 |
for (int j=0; j<fd->selectedFiles().count(); j++)
|
insilmaril@185
|
4087 |
{
|
insilmaril@432
|
4088 |
s=fd->selectedFiles().at(j);
|
insilmaril@432
|
4089 |
fio=loadFloatImageInt (s);
|
insilmaril@432
|
4090 |
if (fio)
|
insilmaril@432
|
4091 |
saveState(
|
insilmaril@432
|
4092 |
(LinkableMapObj*)fio,
|
insilmaril@432
|
4093 |
"delete ()",
|
insilmaril@432
|
4094 |
bo,
|
insilmaril@432
|
4095 |
QString ("loadImage (%1)").arg(s ),
|
insilmaril@432
|
4096 |
QString("Add image %1 to %2").arg(s).arg(getName(bo))
|
insilmaril@432
|
4097 |
);
|
insilmaril@432
|
4098 |
else
|
insilmaril@491
|
4099 |
// TODO loadFIO error handling
|
insilmaril@432
|
4100 |
qWarning ("Failed to load "+s);
|
insilmaril@185
|
4101 |
}
|
insilmaril@0
|
4102 |
}
|
insilmaril@236
|
4103 |
delete (p);
|
insilmaril@236
|
4104 |
delete (fd);
|
insilmaril@0
|
4105 |
}
|
insilmaril@0
|
4106 |
}
|
insilmaril@0
|
4107 |
|
insilmaril@434
|
4108 |
void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
|
insilmaril@434
|
4109 |
{
|
insilmaril@434
|
4110 |
fio->save (fn,type);
|
insilmaril@434
|
4111 |
}
|
insilmaril@434
|
4112 |
|
insilmaril@366
|
4113 |
void MapEditor::saveFloatImage ()
|
insilmaril@0
|
4114 |
{
|
insilmaril@424
|
4115 |
FloatImageObj *fio=xelection.getFloatImage();
|
insilmaril@424
|
4116 |
if (fio)
|
insilmaril@0
|
4117 |
{
|
insilmaril@366
|
4118 |
QFileDialog *fd=new QFileDialog( this);
|
insilmaril@366
|
4119 |
fd->setFilters (imageIO.getFilters());
|
insilmaril@404
|
4120 |
fd->setCaption(vymName+" - " +tr("Save image"));
|
insilmaril@366
|
4121 |
fd->setFileMode( QFileDialog::AnyFile );
|
insilmaril@366
|
4122 |
fd->setDirectory (lastImageDir);
|
insilmaril@366
|
4123 |
// fd->setSelection (fio->getOriginalFilename());
|
insilmaril@0
|
4124 |
fd->show();
|
insilmaril@0
|
4125 |
|
insilmaril@0
|
4126 |
QString fn;
|
insilmaril@434
|
4127 |
if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
|
insilmaril@0
|
4128 |
{
|
insilmaril@434
|
4129 |
fn=fd->selectedFiles().at(0);
|
insilmaril@434
|
4130 |
if (QFile (fn).exists() )
|
insilmaril@0
|
4131 |
{
|
insilmaril@404
|
4132 |
QMessageBox mb( vymName,
|
insilmaril@159
|
4133 |
tr("The file %1 exists already.\n"
|
insilmaril@434
|
4134 |
"Do you want to overwrite it?").arg(fn),
|
insilmaril@0
|
4135 |
QMessageBox::Warning,
|
insilmaril@0
|
4136 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@0
|
4137 |
QMessageBox::Cancel | QMessageBox::Escape,
|
insilmaril@0
|
4138 |
QMessageBox::QMessageBox::NoButton );
|
insilmaril@0
|
4139 |
|
insilmaril@0
|
4140 |
mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
|
insilmaril@0
|
4141 |
mb.setButtonText( QMessageBox::No, tr("Cancel"));
|
insilmaril@0
|
4142 |
switch( mb.exec() )
|
insilmaril@0
|
4143 |
{
|
insilmaril@0
|
4144 |
case QMessageBox::Yes:
|
insilmaril@0
|
4145 |
// save
|
insilmaril@676
|
4146 |
break;
|
insilmaril@0
|
4147 |
case QMessageBox::Cancel:
|
insilmaril@0
|
4148 |
// do nothing
|
insilmaril@377
|
4149 |
delete (fd);
|
insilmaril@0
|
4150 |
return;
|
insilmaril@0
|
4151 |
break;
|
insilmaril@0
|
4152 |
}
|
insilmaril@0
|
4153 |
}
|
insilmaril@434
|
4154 |
saveFloatImageInt (fio,fd->selectedFilter(),fn );
|
insilmaril@0
|
4155 |
}
|
insilmaril@377
|
4156 |
delete (fd);
|
insilmaril@0
|
4157 |
}
|
insilmaril@0
|
4158 |
}
|
insilmaril@0
|
4159 |
|
insilmaril@473
|
4160 |
void MapEditor::setFrameType(const FrameObj::FrameType &t)
|
insilmaril@0
|
4161 |
{
|
insilmaril@424
|
4162 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4163 |
if (bo)
|
insilmaril@0
|
4164 |
{
|
insilmaril@473
|
4165 |
QString s=bo->getFrameTypeName();
|
insilmaril@424
|
4166 |
bo->setFrameType (t);
|
insilmaril@473
|
4167 |
saveState (bo, QString("setFrameType (\"%1\")").arg(s),
|
insilmaril@473
|
4168 |
bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
|
insilmaril@645
|
4169 |
model->reposition();
|
insilmaril@424
|
4170 |
bo->updateLink();
|
insilmaril@0
|
4171 |
}
|
insilmaril@0
|
4172 |
}
|
insilmaril@0
|
4173 |
|
insilmaril@473
|
4174 |
void MapEditor::setFrameType(const QString &s)
|
insilmaril@445
|
4175 |
{
|
insilmaril@445
|
4176 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@445
|
4177 |
if (bo)
|
insilmaril@445
|
4178 |
{
|
insilmaril@473
|
4179 |
saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
|
insilmaril@473
|
4180 |
bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
|
insilmaril@445
|
4181 |
bo->setFrameType (s);
|
insilmaril@645
|
4182 |
model->reposition();
|
insilmaril@445
|
4183 |
bo->updateLink();
|
insilmaril@445
|
4184 |
}
|
insilmaril@445
|
4185 |
}
|
insilmaril@445
|
4186 |
|
insilmaril@473
|
4187 |
void MapEditor::setFramePenColor(const QColor &c)
|
insilmaril@442
|
4188 |
{
|
insilmaril@442
|
4189 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@442
|
4190 |
if (bo)
|
insilmaril@473
|
4191 |
{
|
insilmaril@473
|
4192 |
saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
|
insilmaril@473
|
4193 |
bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
|
insilmaril@442
|
4194 |
bo->setFramePenColor (c);
|
insilmaril@473
|
4195 |
}
|
insilmaril@442
|
4196 |
}
|
insilmaril@442
|
4197 |
|
insilmaril@473
|
4198 |
void MapEditor::setFrameBrushColor(const QColor &c)
|
insilmaril@442
|
4199 |
{
|
insilmaril@442
|
4200 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@442
|
4201 |
if (bo)
|
insilmaril@473
|
4202 |
{
|
insilmaril@473
|
4203 |
saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
|
insilmaril@473
|
4204 |
bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
|
insilmaril@442
|
4205 |
bo->setFrameBrushColor (c);
|
insilmaril@473
|
4206 |
}
|
insilmaril@473
|
4207 |
}
|
insilmaril@473
|
4208 |
|
insilmaril@486
|
4209 |
void MapEditor::setFramePadding (const int &i)
|
insilmaril@473
|
4210 |
{
|
insilmaril@473
|
4211 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@473
|
4212 |
if (bo)
|
insilmaril@473
|
4213 |
{
|
insilmaril@486
|
4214 |
saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
|
insilmaril@486
|
4215 |
bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
|
insilmaril@486
|
4216 |
bo->setFramePadding (i);
|
insilmaril@645
|
4217 |
model->reposition();
|
insilmaril@486
|
4218 |
bo->updateLink();
|
insilmaril@473
|
4219 |
}
|
insilmaril@473
|
4220 |
}
|
insilmaril@473
|
4221 |
|
insilmaril@486
|
4222 |
void MapEditor::setFrameBorderWidth(const int &i)
|
insilmaril@473
|
4223 |
{
|
insilmaril@473
|
4224 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@473
|
4225 |
if (bo)
|
insilmaril@473
|
4226 |
{
|
insilmaril@486
|
4227 |
saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
|
insilmaril@486
|
4228 |
bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
|
insilmaril@486
|
4229 |
bo->setFrameBorderWidth (i);
|
insilmaril@645
|
4230 |
model->reposition();
|
insilmaril@486
|
4231 |
bo->updateLink();
|
insilmaril@473
|
4232 |
}
|
insilmaril@442
|
4233 |
}
|
insilmaril@442
|
4234 |
|
insilmaril@437
|
4235 |
void MapEditor::setIncludeImagesVer(bool b)
|
insilmaril@175
|
4236 |
{
|
insilmaril@424
|
4237 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4238 |
if (bo)
|
insilmaril@424
|
4239 |
{
|
insilmaril@434
|
4240 |
QString u= b ? "false" : "true";
|
insilmaril@434
|
4241 |
QString r=!b ? "false" : "true";
|
insilmaril@434
|
4242 |
|
insilmaril@434
|
4243 |
saveState(
|
insilmaril@434
|
4244 |
bo,
|
insilmaril@434
|
4245 |
QString("setIncludeImagesVertically (%1)").arg(u),
|
insilmaril@434
|
4246 |
bo,
|
insilmaril@434
|
4247 |
QString("setIncludeImagesVertically (%1)").arg(r),
|
insilmaril@434
|
4248 |
QString("Include images vertically in %1").arg(getName(bo))
|
insilmaril@434
|
4249 |
);
|
insilmaril@424
|
4250 |
bo->setIncludeImagesVer(b);
|
insilmaril@645
|
4251 |
model->reposition();
|
insilmaril@424
|
4252 |
}
|
insilmaril@175
|
4253 |
}
|
insilmaril@175
|
4254 |
|
insilmaril@437
|
4255 |
void MapEditor::setIncludeImagesHor(bool b)
|
insilmaril@175
|
4256 |
{
|
insilmaril@424
|
4257 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4258 |
if (bo)
|
insilmaril@424
|
4259 |
{
|
insilmaril@434
|
4260 |
QString u= b ? "false" : "true";
|
insilmaril@434
|
4261 |
QString r=!b ? "false" : "true";
|
insilmaril@434
|
4262 |
|
insilmaril@434
|
4263 |
saveState(
|
insilmaril@434
|
4264 |
bo,
|
insilmaril@434
|
4265 |
QString("setIncludeImagesHorizontally (%1)").arg(u),
|
insilmaril@434
|
4266 |
bo,
|
insilmaril@434
|
4267 |
QString("setIncludeImagesHorizontally (%1)").arg(r),
|
insilmaril@434
|
4268 |
QString("Include images horizontally in %1").arg(getName(bo))
|
insilmaril@434
|
4269 |
);
|
insilmaril@424
|
4270 |
bo->setIncludeImagesHor(b);
|
insilmaril@645
|
4271 |
model->reposition();
|
insilmaril@424
|
4272 |
}
|
insilmaril@175
|
4273 |
}
|
insilmaril@175
|
4274 |
|
insilmaril@491
|
4275 |
void MapEditor::setHideLinkUnselected (bool b)
|
insilmaril@160
|
4276 |
{
|
insilmaril@424
|
4277 |
LinkableMapObj *sel=xelection.single();
|
insilmaril@424
|
4278 |
if (sel &&
|
insilmaril@491
|
4279 |
(xelection.type() == Selection::Branch ||
|
insilmaril@491
|
4280 |
xelection.type() == Selection::MapCenter ||
|
insilmaril@491
|
4281 |
xelection.type() == Selection::FloatImage ))
|
insilmaril@491
|
4282 |
{
|
insilmaril@491
|
4283 |
QString u= b ? "false" : "true";
|
insilmaril@491
|
4284 |
QString r=!b ? "false" : "true";
|
insilmaril@491
|
4285 |
|
insilmaril@491
|
4286 |
saveState(
|
insilmaril@491
|
4287 |
sel,
|
insilmaril@491
|
4288 |
QString("setHideLinkUnselected (%1)").arg(u),
|
insilmaril@491
|
4289 |
sel,
|
insilmaril@491
|
4290 |
QString("setHideLinkUnselected (%1)").arg(r),
|
insilmaril@491
|
4291 |
QString("Hide link of %1 if unselected").arg(getName(sel))
|
insilmaril@491
|
4292 |
);
|
insilmaril@424
|
4293 |
sel->setHideLinkUnselected(b);
|
insilmaril@491
|
4294 |
}
|
insilmaril@160
|
4295 |
}
|
insilmaril@160
|
4296 |
|
insilmaril@491
|
4297 |
void MapEditor::importDirInt(BranchObj *dst, QDir d)
|
insilmaril@0
|
4298 |
{
|
insilmaril@424
|
4299 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4300 |
if (bo)
|
insilmaril@0
|
4301 |
{
|
insilmaril@0
|
4302 |
// Traverse directories
|
insilmaril@0
|
4303 |
d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
|
insilmaril@366
|
4304 |
QFileInfoList list = d.entryInfoList();
|
insilmaril@366
|
4305 |
QFileInfo fi;
|
insilmaril@366
|
4306 |
|
insilmaril@366
|
4307 |
for (int i = 0; i < list.size(); ++i)
|
insilmaril@0
|
4308 |
{
|
insilmaril@366
|
4309 |
fi=list.at(i);
|
insilmaril@366
|
4310 |
if (fi.fileName() != "." && fi.fileName() != ".." )
|
insilmaril@0
|
4311 |
{
|
insilmaril@0
|
4312 |
dst->addBranch();
|
insilmaril@0
|
4313 |
bo=dst->getLastBranch();
|
insilmaril@366
|
4314 |
bo->setHeading (fi.fileName() );
|
insilmaril@243
|
4315 |
bo->setColor (QColor("blue"));
|
insilmaril@0
|
4316 |
bo->toggleScroll();
|
insilmaril@366
|
4317 |
if ( !d.cd(fi.fileName()) )
|
insilmaril@366
|
4318 |
QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
|
insilmaril@0
|
4319 |
else
|
insilmaril@0
|
4320 |
{
|
insilmaril@103
|
4321 |
// Recursively add subdirs
|
insilmaril@366
|
4322 |
importDirInt (bo,d);
|
insilmaril@0
|
4323 |
d.cdUp();
|
insilmaril@0
|
4324 |
}
|
insilmaril@0
|
4325 |
}
|
insilmaril@0
|
4326 |
}
|
insilmaril@0
|
4327 |
// Traverse files
|
insilmaril@0
|
4328 |
d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
|
insilmaril@366
|
4329 |
list = d.entryInfoList();
|
insilmaril@366
|
4330 |
|
insilmaril@366
|
4331 |
for (int i = 0; i < list.size(); ++i)
|
insilmaril@0
|
4332 |
{
|
insilmaril@366
|
4333 |
fi=list.at(i);
|
insilmaril@0
|
4334 |
dst->addBranch();
|
insilmaril@0
|
4335 |
bo=dst->getLastBranch();
|
insilmaril@366
|
4336 |
bo->setHeading (fi.fileName() );
|
insilmaril@243
|
4337 |
bo->setColor (QColor("black"));
|
insilmaril@366
|
4338 |
if (fi.fileName().right(4) == ".vym" )
|
insilmaril@366
|
4339 |
bo->setVymLink (fi.filePath());
|
insilmaril@0
|
4340 |
}
|
insilmaril@0
|
4341 |
}
|
insilmaril@0
|
4342 |
}
|
insilmaril@0
|
4343 |
|
insilmaril@491
|
4344 |
void MapEditor::importDirInt (const QString &s)
|
insilmaril@491
|
4345 |
{
|
insilmaril@491
|
4346 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@491
|
4347 |
if (bo)
|
insilmaril@491
|
4348 |
{
|
insilmaril@491
|
4349 |
saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
|
insilmaril@491
|
4350 |
|
insilmaril@491
|
4351 |
QDir d(s);
|
insilmaril@491
|
4352 |
importDirInt (bo,d);
|
insilmaril@491
|
4353 |
}
|
insilmaril@491
|
4354 |
}
|
insilmaril@491
|
4355 |
|
insilmaril@0
|
4356 |
void MapEditor::importDir()
|
insilmaril@0
|
4357 |
{
|
insilmaril@424
|
4358 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4359 |
if (bo)
|
insilmaril@0
|
4360 |
{
|
insilmaril@404
|
4361 |
QStringList filters;
|
insilmaril@404
|
4362 |
filters <<"VYM map (*.vym)";
|
insilmaril@404
|
4363 |
QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
|
insilmaril@404
|
4364 |
fd->setMode (QFileDialog::DirectoryOnly);
|
insilmaril@404
|
4365 |
fd->setFilters (filters);
|
insilmaril@404
|
4366 |
fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
|
insilmaril@0
|
4367 |
fd->show();
|
insilmaril@0
|
4368 |
|
insilmaril@0
|
4369 |
QString fn;
|
insilmaril@0
|
4370 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
4371 |
{
|
insilmaril@491
|
4372 |
importDirInt (fd->selectedFile() );
|
insilmaril@645
|
4373 |
model->reposition();
|
insilmaril@408
|
4374 |
scene()->update();
|
insilmaril@0
|
4375 |
}
|
insilmaril@0
|
4376 |
}
|
insilmaril@0
|
4377 |
}
|
insilmaril@0
|
4378 |
|
insilmaril@95
|
4379 |
void MapEditor::followXLink(int i)
|
insilmaril@89
|
4380 |
{
|
insilmaril@424
|
4381 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4382 |
if (bo)
|
insilmaril@89
|
4383 |
{
|
insilmaril@424
|
4384 |
bo=bo->XLinkTargetAt(i);
|
insilmaril@97
|
4385 |
if (bo)
|
insilmaril@97
|
4386 |
{
|
insilmaril@424
|
4387 |
xelection.select(bo);
|
insilmaril@97
|
4388 |
ensureSelectionVisible();
|
insilmaril@97
|
4389 |
}
|
insilmaril@89
|
4390 |
}
|
insilmaril@89
|
4391 |
}
|
insilmaril@89
|
4392 |
|
insilmaril@421
|
4393 |
void MapEditor::editXLink(int i) // FIXME missing saveState
|
insilmaril@94
|
4394 |
{
|
insilmaril@424
|
4395 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
4396 |
if (bo)
|
insilmaril@94
|
4397 |
{
|
insilmaril@424
|
4398 |
XLinkObj *xlo=bo->XLinkAt(i);
|
insilmaril@97
|
4399 |
if (xlo)
|
insilmaril@94
|
4400 |
{
|
insilmaril@97
|
4401 |
EditXLinkDialog dia;
|
insilmaril@97
|
4402 |
dia.setXLink (xlo);
|
insilmaril@424
|
4403 |
dia.setSelection(bo);
|
insilmaril@97
|
4404 |
if (dia.exec() == QDialog::Accepted)
|
insilmaril@97
|
4405 |
{
|
insilmaril@97
|
4406 |
if (dia.useSettingsGlobal() )
|
insilmaril@97
|
4407 |
{
|
insilmaril@398
|
4408 |
setMapDefXLinkColor (xlo->getColor() );
|
insilmaril@398
|
4409 |
setMapDefXLinkWidth (xlo->getWidth() );
|
insilmaril@97
|
4410 |
}
|
insilmaril@97
|
4411 |
if (dia.deleteXLink())
|
insilmaril@424
|
4412 |
bo->deleteXLinkAt(i);
|
insilmaril@97
|
4413 |
}
|
insilmaril@97
|
4414 |
}
|
insilmaril@97
|
4415 |
}
|
insilmaril@94
|
4416 |
}
|
insilmaril@94
|
4417 |
|
insilmaril@628
|
4418 |
AttributeTable* MapEditor::attributeTable()
|
insilmaril@628
|
4419 |
{
|
insilmaril@628
|
4420 |
return attrTable;
|
insilmaril@628
|
4421 |
}
|
insilmaril@628
|
4422 |
|
insilmaril@527
|
4423 |
void MapEditor::testFunction1()
|
insilmaril@0
|
4424 |
{
|
insilmaril@663
|
4425 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@663
|
4426 |
if (bo) model->moveAway (bo);
|
insilmaril@663
|
4427 |
|
insilmaril@663
|
4428 |
|
insilmaril@527
|
4429 |
/*
|
insilmaril@473
|
4430 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@473
|
4431 |
if (bo) animObjList.append( bo );
|
insilmaril@527
|
4432 |
*/
|
insilmaril@432
|
4433 |
|
insilmaril@420
|
4434 |
/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
|
insilmaril@260
|
4435 |
if (hidemode==HideNone)
|
insilmaril@185
|
4436 |
{
|
insilmaril@260
|
4437 |
setHideTmpMode (HideExport);
|
insilmaril@260
|
4438 |
mapCenter->calcBBoxSizeWithChilds();
|
insilmaril@408
|
4439 |
QRectF totalBBox=mapCenter->getTotalBBox();
|
insilmaril@408
|
4440 |
QRectF mapRect=totalBBox;
|
insilmaril@260
|
4441 |
QCanvasRectangle *frame=NULL;
|
insilmaril@260
|
4442 |
|
insilmaril@260
|
4443 |
cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
|
insilmaril@260
|
4444 |
|
insilmaril@260
|
4445 |
mapRect.setRect (totalBBox.x(), totalBBox.y(),
|
insilmaril@260
|
4446 |
totalBBox.width(), totalBBox.height());
|
insilmaril@408
|
4447 |
frame=new QCanvasRectangle (mapRect,mapScene);
|
insilmaril@260
|
4448 |
frame->setBrush (QColor(white));
|
insilmaril@260
|
4449 |
frame->setPen (QColor(black));
|
insilmaril@408
|
4450 |
frame->setZValue(0);
|
insilmaril@260
|
4451 |
frame->show();
|
insilmaril@260
|
4452 |
}
|
insilmaril@260
|
4453 |
else
|
insilmaril@260
|
4454 |
{
|
insilmaril@260
|
4455 |
setHideTmpMode (HideNone);
|
insilmaril@260
|
4456 |
}
|
insilmaril@260
|
4457 |
cout <<" hidemode="<<hidemode<<endl;
|
insilmaril@301
|
4458 |
*/
|
insilmaril@527
|
4459 |
}
|
insilmaril@527
|
4460 |
|
insilmaril@527
|
4461 |
void MapEditor::testFunction2()
|
insilmaril@527
|
4462 |
{
|
insilmaril@645
|
4463 |
|
insilmaril@628
|
4464 |
// Toggle hidemode
|
insilmaril@628
|
4465 |
if (hidemode==HideExport)
|
insilmaril@628
|
4466 |
setHideTmpMode (HideNone);
|
insilmaril@628
|
4467 |
else
|
insilmaril@628
|
4468 |
setHideTmpMode (HideExport);
|
insilmaril@105
|
4469 |
}
|
insilmaril@105
|
4470 |
|
insilmaril@408
|
4471 |
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
|
insilmaril@0
|
4472 |
{
|
insilmaril@0
|
4473 |
// Lineedits are already closed by preceding
|
insilmaril@0
|
4474 |
// mouseEvent, we don't need to close here.
|
insilmaril@0
|
4475 |
|
insilmaril@408
|
4476 |
QPointF p = mapToScene(e->pos());
|
insilmaril@645
|
4477 |
LinkableMapObj* lmo=model->findMapObj(p, NULL);
|
insilmaril@0
|
4478 |
|
insilmaril@0
|
4479 |
if (lmo)
|
insilmaril@0
|
4480 |
{ // MapObj was found
|
insilmaril@424
|
4481 |
if (xelection.single() != lmo)
|
insilmaril@0
|
4482 |
{
|
insilmaril@0
|
4483 |
// select the MapObj
|
insilmaril@424
|
4484 |
xelection.select(lmo);
|
insilmaril@0
|
4485 |
}
|
insilmaril@0
|
4486 |
// Context Menu
|
insilmaril@424
|
4487 |
if (xelection.getBranch() )
|
insilmaril@0
|
4488 |
{
|
insilmaril@424
|
4489 |
// Context Menu on branch or mapcenter
|
insilmaril@424
|
4490 |
updateActions();
|
insilmaril@424
|
4491 |
branchContextMenu->popup(e->globalPos() );
|
insilmaril@424
|
4492 |
} else
|
insilmaril@424
|
4493 |
{
|
insilmaril@424
|
4494 |
if (xelection.getFloatImage() )
|
insilmaril@0
|
4495 |
{
|
insilmaril@0
|
4496 |
// Context Menu on floatimage
|
insilmaril@0
|
4497 |
updateActions();
|
insilmaril@0
|
4498 |
floatimageContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
4499 |
}
|
insilmaril@0
|
4500 |
}
|
insilmaril@0
|
4501 |
} else
|
insilmaril@0
|
4502 |
{ // No MapObj found, we are on the Canvas itself
|
insilmaril@408
|
4503 |
// Context Menu on scene
|
insilmaril@0
|
4504 |
updateActions();
|
insilmaril@684
|
4505 |
contextMenuPos=p;
|
insilmaril@0
|
4506 |
canvasContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
4507 |
}
|
insilmaril@329
|
4508 |
e->accept();
|
insilmaril@0
|
4509 |
}
|
insilmaril@0
|
4510 |
|
insilmaril@398
|
4511 |
void MapEditor::keyPressEvent(QKeyEvent* e)
|
insilmaril@398
|
4512 |
{
|
insilmaril@411
|
4513 |
if (e->modifiers() & Qt::ControlModifier)
|
insilmaril@398
|
4514 |
{
|
insilmaril@398
|
4515 |
switch (mainWindow->getModMode())
|
insilmaril@398
|
4516 |
{
|
insilmaril@473
|
4517 |
case Main::ModModeColor:
|
insilmaril@398
|
4518 |
setCursor (PickColorCursor);
|
insilmaril@398
|
4519 |
break;
|
insilmaril@473
|
4520 |
case Main::ModModeCopy:
|
insilmaril@398
|
4521 |
setCursor (CopyCursor);
|
insilmaril@398
|
4522 |
break;
|
insilmaril@473
|
4523 |
case Main::ModModeXLink:
|
insilmaril@398
|
4524 |
setCursor (XLinkCursor);
|
insilmaril@398
|
4525 |
break;
|
insilmaril@398
|
4526 |
default :
|
insilmaril@398
|
4527 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
4528 |
break;
|
insilmaril@398
|
4529 |
}
|
insilmaril@398
|
4530 |
}
|
insilmaril@398
|
4531 |
}
|
insilmaril@398
|
4532 |
|
insilmaril@398
|
4533 |
void MapEditor::keyReleaseEvent(QKeyEvent* e)
|
insilmaril@398
|
4534 |
{
|
insilmaril@411
|
4535 |
if (!(e->modifiers() & Qt::ControlModifier))
|
insilmaril@398
|
4536 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
4537 |
}
|
insilmaril@398
|
4538 |
|
insilmaril@408
|
4539 |
void MapEditor::mousePressEvent(QMouseEvent* e)
|
insilmaril@0
|
4540 |
{
|
insilmaril@329
|
4541 |
// Ignore right clicks, these will go to context menus
|
insilmaril@366
|
4542 |
if (e->button() == Qt::RightButton )
|
insilmaril@329
|
4543 |
{
|
insilmaril@329
|
4544 |
e->ignore();
|
insilmaril@329
|
4545 |
return;
|
insilmaril@329
|
4546 |
}
|
insilmaril@329
|
4547 |
|
insilmaril@491
|
4548 |
//Ignore clicks while editing heading
|
insilmaril@491
|
4549 |
if (isSelectBlocked() )
|
insilmaril@491
|
4550 |
{
|
insilmaril@491
|
4551 |
e->ignore();
|
insilmaril@491
|
4552 |
return;
|
insilmaril@491
|
4553 |
}
|
insilmaril@491
|
4554 |
|
insilmaril@408
|
4555 |
QPointF p = mapToScene(e->pos());
|
insilmaril@645
|
4556 |
LinkableMapObj* lmo=model->findMapObj(p, NULL);
|
insilmaril@0
|
4557 |
|
insilmaril@329
|
4558 |
e->accept();
|
insilmaril@329
|
4559 |
|
insilmaril@442
|
4560 |
//Take care of system flags _or_ modifier modes
|
insilmaril@267
|
4561 |
//
|
insilmaril@267
|
4562 |
if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
|
insilmaril@267
|
4563 |
typeid(*lmo)==typeid(MapCenterObj) ))
|
insilmaril@267
|
4564 |
{
|
insilmaril@267
|
4565 |
QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
|
insilmaril@267
|
4566 |
if (!foname.isEmpty())
|
insilmaril@267
|
4567 |
{
|
insilmaril@267
|
4568 |
// systemFlag clicked
|
insilmaril@366
|
4569 |
selectInt (lmo);
|
insilmaril@267
|
4570 |
if (foname=="url")
|
insilmaril@267
|
4571 |
{
|
insilmaril@366
|
4572 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@267
|
4573 |
mainWindow->editOpenURLTab();
|
insilmaril@267
|
4574 |
else
|
insilmaril@267
|
4575 |
mainWindow->editOpenURL();
|
insilmaril@267
|
4576 |
}
|
insilmaril@267
|
4577 |
else if (foname=="vymLink")
|
insilmaril@267
|
4578 |
{
|
insilmaril@267
|
4579 |
mainWindow->editOpenVymLink();
|
insilmaril@267
|
4580 |
// tabWidget may change, better return now
|
insilmaril@267
|
4581 |
// before segfaulting...
|
insilmaril@267
|
4582 |
} else if (foname=="note")
|
insilmaril@267
|
4583 |
mainWindow->windowToggleNoteEditor();
|
insilmaril@267
|
4584 |
else if (foname=="hideInExport")
|
insilmaril@267
|
4585 |
toggleHideExport();
|
insilmaril@442
|
4586 |
xelection.update();
|
insilmaril@267
|
4587 |
return;
|
insilmaril@267
|
4588 |
}
|
insilmaril@267
|
4589 |
}
|
insilmaril@442
|
4590 |
|
insilmaril@442
|
4591 |
// No system flag clicked, take care of modmodes (CTRL-Click)
|
insilmaril@366
|
4592 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@0
|
4593 |
{
|
insilmaril@473
|
4594 |
if (mainWindow->getModMode()==Main::ModModeColor)
|
insilmaril@83
|
4595 |
{
|
insilmaril@83
|
4596 |
pickingColor=true;
|
insilmaril@398
|
4597 |
setCursor (PickColorCursor);
|
insilmaril@83
|
4598 |
return;
|
insilmaril@83
|
4599 |
}
|
insilmaril@473
|
4600 |
if (mainWindow->getModMode()==Main::ModModeXLink)
|
insilmaril@83
|
4601 |
{
|
insilmaril@90
|
4602 |
BranchObj *bo_begin=NULL;
|
insilmaril@90
|
4603 |
if (lmo)
|
insilmaril@90
|
4604 |
bo_begin=(BranchObj*)(lmo);
|
insilmaril@90
|
4605 |
else
|
insilmaril@424
|
4606 |
if (xelection.getBranch() )
|
insilmaril@424
|
4607 |
bo_begin=xelection.getBranch();
|
insilmaril@90
|
4608 |
if (bo_begin)
|
insilmaril@83
|
4609 |
{
|
insilmaril@83
|
4610 |
drawingLink=true;
|
insilmaril@90
|
4611 |
linkingObj_src=bo_begin;
|
insilmaril@408
|
4612 |
tmpXLink=new XLinkObj (mapScene);
|
insilmaril@95
|
4613 |
tmpXLink->setBegin (bo_begin);
|
insilmaril@95
|
4614 |
tmpXLink->setEnd (p);
|
insilmaril@97
|
4615 |
tmpXLink->setColor(defXLinkColor);
|
insilmaril@97
|
4616 |
tmpXLink->setWidth(defXLinkWidth);
|
insilmaril@95
|
4617 |
tmpXLink->updateXLink();
|
insilmaril@95
|
4618 |
tmpXLink->setVisibility (true);
|
insilmaril@83
|
4619 |
return;
|
insilmaril@89
|
4620 |
}
|
insilmaril@267
|
4621 |
}
|
insilmaril@442
|
4622 |
} // End of modmodes
|
insilmaril@442
|
4623 |
|
insilmaril@0
|
4624 |
if (lmo)
|
insilmaril@267
|
4625 |
{
|
insilmaril@442
|
4626 |
// Select the clicked object
|
insilmaril@366
|
4627 |
selectInt (lmo);
|
insilmaril@442
|
4628 |
|
insilmaril@0
|
4629 |
// Left Button Move Branches
|
insilmaril@366
|
4630 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
4631 |
{
|
insilmaril@424
|
4632 |
//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
|
insilmaril@424
|
4633 |
//movingObj_start.setY( p.y() - selection->y() );
|
insilmaril@424
|
4634 |
movingObj_start.setX( p.x() - lmo->x() );
|
insilmaril@424
|
4635 |
movingObj_start.setY( p.y() - lmo->y() );
|
insilmaril@129
|
4636 |
movingObj_orgPos.setX (lmo->x() );
|
insilmaril@129
|
4637 |
movingObj_orgPos.setY (lmo->y() );
|
insilmaril@366
|
4638 |
movingObj_orgRelPos=lmo->getRelPos();
|
insilmaril@129
|
4639 |
|
insilmaril@93
|
4640 |
// If modMode==copy, then we want to "move" the _new_ object around
|
insilmaril@93
|
4641 |
// then we need the offset from p to the _old_ selection, because of tmp
|
insilmaril@473
|
4642 |
if (mainWindow->getModMode()==Main::ModModeCopy &&
|
insilmaril@366
|
4643 |
e->state() & Qt::ControlModifier)
|
insilmaril@93
|
4644 |
{
|
insilmaril@645
|
4645 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@645
|
4646 |
if (bo)
|
insilmaril@93
|
4647 |
{
|
insilmaril@93
|
4648 |
copyingObj=true;
|
insilmaril@645
|
4649 |
bo->addBranch ((BranchObj*)xelection.single());
|
insilmaril@93
|
4650 |
unselect();
|
insilmaril@645
|
4651 |
xelection.select(bo->getLastBranch());
|
insilmaril@645
|
4652 |
model->reposition();
|
insilmaril@93
|
4653 |
}
|
insilmaril@421
|
4654 |
}
|
insilmaril@421
|
4655 |
|
insilmaril@424
|
4656 |
movingObj=xelection.single();
|
insilmaril@0
|
4657 |
} else
|
insilmaril@0
|
4658 |
// Middle Button Toggle Scroll
|
insilmaril@0
|
4659 |
// (On Mac OS X this won't work, but we still have
|
insilmaril@0
|
4660 |
// a button in the toolbar)
|
insilmaril@366
|
4661 |
if (e->button() == Qt::MidButton )
|
insilmaril@0
|
4662 |
toggleScroll();
|
insilmaril@0
|
4663 |
updateActions();
|
insilmaril@442
|
4664 |
xelection.update();
|
insilmaril@0
|
4665 |
} else
|
insilmaril@408
|
4666 |
{ // No MapObj found, we are on the scene itself
|
insilmaril@408
|
4667 |
// Left Button move Pos of sceneView
|
insilmaril@366
|
4668 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
4669 |
{
|
insilmaril@0
|
4670 |
movingObj=NULL; // move Content not Obj
|
insilmaril@0
|
4671 |
movingObj_start=e->globalPos();
|
insilmaril@408
|
4672 |
movingCont_start=QPointF (
|
insilmaril@408
|
4673 |
horizontalScrollBar()->value(),
|
insilmaril@408
|
4674 |
verticalScrollBar()->value());
|
insilmaril@408
|
4675 |
movingVec=QPointF(0,0);
|
insilmaril@398
|
4676 |
setCursor(HandOpenCursor);
|
insilmaril@0
|
4677 |
}
|
insilmaril@0
|
4678 |
}
|
insilmaril@0
|
4679 |
}
|
insilmaril@0
|
4680 |
|
insilmaril@408
|
4681 |
void MapEditor::mouseMoveEvent(QMouseEvent* e)
|
insilmaril@0
|
4682 |
{
|
insilmaril@408
|
4683 |
QPointF p = mapToScene(e->pos());
|
insilmaril@424
|
4684 |
LinkableMapObj *lmosel=xelection.single();
|
insilmaril@83
|
4685 |
|
insilmaril@0
|
4686 |
// Move the selected MapObj
|
insilmaril@424
|
4687 |
if ( lmosel && movingObj)
|
insilmaril@0
|
4688 |
{
|
insilmaril@421
|
4689 |
// reset cursor if we are moving and don't copy
|
insilmaril@473
|
4690 |
if (mainWindow->getModMode()!=Main::ModModeCopy)
|
insilmaril@421
|
4691 |
setCursor (Qt::ArrowCursor);
|
insilmaril@421
|
4692 |
|
insilmaril@408
|
4693 |
// To avoid jumping of the sceneView, only
|
insilmaril@164
|
4694 |
// ensureSelectionVisible, if not tmp linked
|
insilmaril@424
|
4695 |
if (!lmosel->hasParObjTmp())
|
insilmaril@164
|
4696 |
ensureSelectionVisible ();
|
insilmaril@0
|
4697 |
|
insilmaril@83
|
4698 |
// Now move the selection, but add relative position
|
insilmaril@83
|
4699 |
// (movingObj_start) where selection was chosen with
|
insilmaril@83
|
4700 |
// mousepointer. (This avoids flickering resp. jumping
|
insilmaril@0
|
4701 |
// of selection back to absPos)
|
insilmaril@0
|
4702 |
|
insilmaril@0
|
4703 |
// Check if we could link
|
insilmaril@645
|
4704 |
LinkableMapObj* lmo=model->findMapObj(p, lmosel);
|
insilmaril@0
|
4705 |
|
insilmaril@0
|
4706 |
|
insilmaril@424
|
4707 |
FloatObj *fio=xelection.getFloatImage();
|
insilmaril@424
|
4708 |
if (fio)
|
insilmaril@0
|
4709 |
{
|
insilmaril@424
|
4710 |
fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@424
|
4711 |
fio->setRelPos();
|
insilmaril@424
|
4712 |
fio->updateLink(); //no need for reposition, if we update link here
|
insilmaril@442
|
4713 |
xelection.update();
|
insilmaril@0
|
4714 |
|
insilmaril@0
|
4715 |
// Relink float to new mapcenter or branch, if shift is pressed
|
insilmaril@0
|
4716 |
// Only relink, if selection really has a new parent
|
insilmaril@388
|
4717 |
if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
|
insilmaril@0
|
4718 |
( (typeid(*lmo)==typeid(BranchObj)) ||
|
insilmaril@0
|
4719 |
(typeid(*lmo)==typeid(MapCenterObj)) ) &&
|
insilmaril@424
|
4720 |
( lmo != fio->getParObj())
|
insilmaril@0
|
4721 |
)
|
insilmaril@0
|
4722 |
{
|
insilmaril@424
|
4723 |
if (typeid(*fio) == typeid(FloatImageObj) &&
|
insilmaril@420
|
4724 |
( (typeid(*lmo)==typeid(BranchObj) ||
|
insilmaril@420
|
4725 |
typeid(*lmo)==typeid(MapCenterObj)) ))
|
insilmaril@0
|
4726 |
{
|
insilmaril@420
|
4727 |
|
insilmaril@420
|
4728 |
// Also save the move which was done so far
|
insilmaril@420
|
4729 |
QString pold=qpointfToString(movingObj_orgRelPos);
|
insilmaril@420
|
4730 |
QString pnow=qpointfToString(fio->getRelPos());
|
insilmaril@420
|
4731 |
saveState(
|
insilmaril@424
|
4732 |
fio,
|
insilmaril@420
|
4733 |
"moveRel "+pold,
|
insilmaril@424
|
4734 |
fio,
|
insilmaril@420
|
4735 |
"moveRel "+pnow,
|
insilmaril@625
|
4736 |
QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
|
insilmaril@420
|
4737 |
fio->getParObj()->requestReposition();
|
insilmaril@645
|
4738 |
model->reposition();
|
insilmaril@420
|
4739 |
|
insilmaril@684
|
4740 |
linkTo (model->getSelectString(lmo));
|
insilmaril@442
|
4741 |
//movingObj=lmosel;
|
insilmaril@442
|
4742 |
//movingObj_orgRelPos=lmosel->getRelPos();
|
insilmaril@420
|
4743 |
|
insilmaril@645
|
4744 |
model->reposition();
|
insilmaril@0
|
4745 |
}
|
insilmaril@0
|
4746 |
}
|
insilmaril@388
|
4747 |
} else
|
insilmaril@388
|
4748 |
{ // selection != a FloatObj
|
insilmaril@0
|
4749 |
if (lmosel->getDepth()==0)
|
insilmaril@0
|
4750 |
{
|
insilmaril@388
|
4751 |
// Move MapCenter
|
insilmaril@388
|
4752 |
if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
|
insilmaril@645
|
4753 |
((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@0
|
4754 |
else
|
insilmaril@645
|
4755 |
lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@645
|
4756 |
model->updateRelPositions();
|
insilmaril@0
|
4757 |
} else
|
insilmaril@0
|
4758 |
{
|
insilmaril@0
|
4759 |
if (lmosel->getDepth()==1)
|
insilmaril@0
|
4760 |
{
|
insilmaril@388
|
4761 |
// Move mainbranch
|
insilmaril@0
|
4762 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@388
|
4763 |
lmosel->setRelPos();
|
insilmaril@0
|
4764 |
} else
|
insilmaril@0
|
4765 |
{
|
insilmaril@388
|
4766 |
// Move ordinary branch
|
insilmaril@473
|
4767 |
if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
|
insilmaril@0
|
4768 |
// Add width of bbox here, otherwise alignRelTo will cause jumping around
|
insilmaril@0
|
4769 |
lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
|
insilmaril@175
|
4770 |
p.y()-movingObj_start.y() +lmosel->getTopPad() );
|
insilmaril@0
|
4771 |
else
|
insilmaril@175
|
4772 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
|
insilmaril@0
|
4773 |
}
|
insilmaril@0
|
4774 |
|
insilmaril@431
|
4775 |
// Maybe we can relink temporary?
|
insilmaril@431
|
4776 |
if (lmo && (lmo!=lmosel) && xelection.getBranch() &&
|
insilmaril@431
|
4777 |
(typeid(*lmo)==typeid(BranchObj) ||
|
insilmaril@431
|
4778 |
typeid(*lmo)==typeid(MapCenterObj)) )
|
insilmaril@431
|
4779 |
|
insilmaril@0
|
4780 |
{
|
insilmaril@388
|
4781 |
if (e->modifiers()==Qt::ControlModifier)
|
insilmaril@0
|
4782 |
{
|
insilmaril@0
|
4783 |
// Special case: CTRL to link below lmo
|
insilmaril@0
|
4784 |
lmosel->setParObjTmp (lmo,p,+1);
|
insilmaril@0
|
4785 |
}
|
insilmaril@388
|
4786 |
else if (e->modifiers()==Qt::ShiftModifier)
|
insilmaril@0
|
4787 |
lmosel->setParObjTmp (lmo,p,-1);
|
insilmaril@0
|
4788 |
else
|
insilmaril@0
|
4789 |
lmosel->setParObjTmp (lmo,p,0);
|
insilmaril@0
|
4790 |
} else
|
insilmaril@0
|
4791 |
{
|
insilmaril@93
|
4792 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
4793 |
}
|
insilmaril@428
|
4794 |
// reposition subbranch
|
insilmaril@428
|
4795 |
lmosel->reposition();
|
insilmaril@0
|
4796 |
} // depth>0
|
insilmaril@0
|
4797 |
|
insilmaril@442
|
4798 |
xelection.update();
|
insilmaril@0
|
4799 |
} // no FloatImageObj
|
insilmaril@0
|
4800 |
|
insilmaril@408
|
4801 |
scene()->update();
|
insilmaril@0
|
4802 |
return;
|
insilmaril@0
|
4803 |
} // selection && moving_obj
|
insilmaril@0
|
4804 |
|
insilmaril@83
|
4805 |
// Draw a link from one branch to another
|
insilmaril@83
|
4806 |
if (drawingLink)
|
insilmaril@83
|
4807 |
{
|
insilmaril@95
|
4808 |
tmpXLink->setEnd (p);
|
insilmaril@95
|
4809 |
tmpXLink->updateXLink();
|
insilmaril@83
|
4810 |
}
|
insilmaril@83
|
4811 |
|
insilmaril@408
|
4812 |
// Move sceneView
|
insilmaril@411
|
4813 |
if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
|
insilmaril@0
|
4814 |
{
|
insilmaril@408
|
4815 |
QPointF p=e->globalPos();
|
insilmaril@0
|
4816 |
movingVec.setX(-p.x() + movingObj_start.x() );
|
insilmaril@0
|
4817 |
movingVec.setY(-p.y() + movingObj_start.y() );
|
insilmaril@408
|
4818 |
horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
|
insilmaril@408
|
4819 |
verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
|
insilmaril@0
|
4820 |
}
|
insilmaril@0
|
4821 |
}
|
insilmaril@0
|
4822 |
|
insilmaril@0
|
4823 |
|
insilmaril@408
|
4824 |
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
|
insilmaril@0
|
4825 |
{
|
insilmaril@408
|
4826 |
QPointF p = mapToScene(e->pos());
|
insilmaril@0
|
4827 |
LinkableMapObj *dst;
|
insilmaril@424
|
4828 |
LinkableMapObj *lmosel=xelection.single();
|
insilmaril@0
|
4829 |
// Have we been picking color?
|
insilmaril@0
|
4830 |
if (pickingColor)
|
insilmaril@0
|
4831 |
{
|
insilmaril@0
|
4832 |
pickingColor=false;
|
insilmaril@366
|
4833 |
setCursor (Qt::ArrowCursor);
|
insilmaril@0
|
4834 |
// Check if we are over another branch
|
insilmaril@645
|
4835 |
dst=model->findMapObj(p, NULL);
|
insilmaril@424
|
4836 |
if (dst && lmosel)
|
insilmaril@0
|
4837 |
{
|
insilmaril@366
|
4838 |
if (e->state() & Qt::ShiftModifier)
|
insilmaril@638
|
4839 |
colorBranch (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
4840 |
else
|
insilmaril@638
|
4841 |
colorSubtree (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
4842 |
}
|
insilmaril@0
|
4843 |
return;
|
insilmaril@0
|
4844 |
}
|
insilmaril@83
|
4845 |
|
insilmaril@83
|
4846 |
// Have we been drawing a link?
|
insilmaril@491
|
4847 |
if (drawingLink)
|
insilmaril@83
|
4848 |
{
|
insilmaril@83
|
4849 |
drawingLink=false;
|
insilmaril@83
|
4850 |
// Check if we are over another branch
|
insilmaril@645
|
4851 |
dst=model->findMapObj(p, NULL);
|
insilmaril@424
|
4852 |
if (dst && lmosel)
|
insilmaril@83
|
4853 |
{
|
insilmaril@95
|
4854 |
tmpXLink->setEnd ( ((BranchObj*)(dst)) );
|
insilmaril@95
|
4855 |
tmpXLink->updateXLink();
|
insilmaril@491
|
4856 |
tmpXLink->activate(); //FIXME savestate missing
|
insilmaril@473
|
4857 |
//saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
|
insilmaril@83
|
4858 |
} else
|
insilmaril@83
|
4859 |
{
|
insilmaril@95
|
4860 |
delete(tmpXLink);
|
insilmaril@95
|
4861 |
tmpXLink=NULL;
|
insilmaril@83
|
4862 |
}
|
insilmaril@83
|
4863 |
return;
|
insilmaril@83
|
4864 |
}
|
insilmaril@83
|
4865 |
|
insilmaril@0
|
4866 |
// Have we been moving something?
|
insilmaril@424
|
4867 |
if ( lmosel && movingObj )
|
insilmaril@0
|
4868 |
{
|
insilmaril@424
|
4869 |
FloatImageObj *fo=xelection.getFloatImage();
|
insilmaril@424
|
4870 |
if(fo)
|
insilmaril@175
|
4871 |
{
|
insilmaril@388
|
4872 |
// Moved FloatObj. Maybe we need to reposition
|
insilmaril@408
|
4873 |
QString pold=qpointfToString(movingObj_orgRelPos);
|
insilmaril@408
|
4874 |
QString pnow=qpointfToString(fo->getRelPos());
|
insilmaril@395
|
4875 |
saveState(
|
insilmaril@424
|
4876 |
fo,
|
insilmaril@366
|
4877 |
"moveRel "+pold,
|
insilmaril@424
|
4878 |
fo,
|
insilmaril@366
|
4879 |
"moveRel "+pnow,
|
insilmaril@625
|
4880 |
QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
|
insilmaril@424
|
4881 |
|
insilmaril@424
|
4882 |
fo->getParObj()->requestReposition();
|
insilmaril@645
|
4883 |
model->reposition();
|
insilmaril@175
|
4884 |
}
|
insilmaril@175
|
4885 |
|
insilmaril@0
|
4886 |
// Check if we are over another branch, but ignore
|
insilmaril@0
|
4887 |
// any found LMOs, which are FloatObjs
|
insilmaril@645
|
4888 |
dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
|
insilmaril@0
|
4889 |
|
insilmaril@336
|
4890 |
if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
|
insilmaril@0
|
4891 |
dst=NULL;
|
insilmaril@0
|
4892 |
|
insilmaril@645
|
4893 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@645
|
4894 |
if (bo && bo->getDepth()==0)
|
insilmaril@497
|
4895 |
{
|
insilmaril@645
|
4896 |
if (movingObj_orgPos != bo->getAbsPos())
|
insilmaril@625
|
4897 |
{
|
insilmaril@625
|
4898 |
QString pold=qpointfToString(movingObj_orgPos);
|
insilmaril@645
|
4899 |
QString pnow=qpointfToString(bo->getAbsPos());
|
insilmaril@625
|
4900 |
saveState(
|
insilmaril@625
|
4901 |
fo,
|
insilmaril@625
|
4902 |
"move "+pold,
|
insilmaril@625
|
4903 |
fo,
|
insilmaril@625
|
4904 |
"move "+pnow,
|
insilmaril@645
|
4905 |
QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
|
insilmaril@625
|
4906 |
}
|
insilmaril@388
|
4907 |
}
|
insilmaril@645
|
4908 |
|
insilmaril@491
|
4909 |
if (xelection.type() == Selection::Branch )
|
insilmaril@388
|
4910 |
{ // A branch was moved
|
insilmaril@388
|
4911 |
|
insilmaril@0
|
4912 |
// save the position in case we link to mapcenter
|
insilmaril@424
|
4913 |
QPointF savePos=QPointF (lmosel->getAbsPos() );
|
insilmaril@0
|
4914 |
|
insilmaril@0
|
4915 |
// Reset the temporary drawn link to the original one
|
insilmaril@424
|
4916 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
4917 |
|
insilmaril@366
|
4918 |
// For Redo we may need to save original selection
|
insilmaril@684
|
4919 |
QString preSelStr=model->getSelectString(lmosel);
|
insilmaril@93
|
4920 |
|
insilmaril@94
|
4921 |
copyingObj=false;
|
insilmaril@129
|
4922 |
if (dst )
|
insilmaril@93
|
4923 |
{
|
insilmaril@424
|
4924 |
BranchObj* bsel=xelection.getBranch();
|
insilmaril@366
|
4925 |
BranchObj* bdst=(BranchObj*)dst;
|
insilmaril@366
|
4926 |
|
insilmaril@684
|
4927 |
QString preParStr=model->getSelectString (bsel->getParObj());
|
insilmaril@366
|
4928 |
QString preNum=QString::number (bsel->getNum(),10);
|
insilmaril@366
|
4929 |
QString preDstParStr;
|
insilmaril@366
|
4930 |
|
insilmaril@366
|
4931 |
if (e->state() & Qt::ShiftModifier && dst->getParObj())
|
insilmaril@366
|
4932 |
{ // Link above dst
|
insilmaril@684
|
4933 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@421
|
4934 |
bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
|
insilmaril@366
|
4935 |
} else
|
insilmaril@366
|
4936 |
if (e->state() & Qt::ControlModifier && dst->getParObj())
|
insilmaril@366
|
4937 |
{
|
insilmaril@366
|
4938 |
// Link below dst
|
insilmaril@684
|
4939 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@421
|
4940 |
bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
|
insilmaril@366
|
4941 |
} else
|
insilmaril@366
|
4942 |
{ // Append to dst
|
insilmaril@684
|
4943 |
preDstParStr=model->getSelectString(dst);
|
insilmaril@421
|
4944 |
bsel->linkTo (bdst,-1);
|
insilmaril@366
|
4945 |
if (dst->getDepth()==0) bsel->move (savePos);
|
insilmaril@366
|
4946 |
}
|
insilmaril@684
|
4947 |
QString postSelStr=model->getSelectString(lmosel);
|
insilmaril@366
|
4948 |
QString postNum=QString::number (bsel->getNum(),10);
|
insilmaril@366
|
4949 |
|
insilmaril@421
|
4950 |
QString undoCom="linkTo (\""+
|
insilmaril@366
|
4951 |
preParStr+ "\"," + preNum +"," +
|
insilmaril@366
|
4952 |
QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
|
insilmaril@366
|
4953 |
|
insilmaril@421
|
4954 |
QString redoCom="linkTo (\""+
|
insilmaril@366
|
4955 |
preDstParStr + "\"," + postNum + "," +
|
insilmaril@366
|
4956 |
QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
|
insilmaril@366
|
4957 |
|
insilmaril@366
|
4958 |
saveState (
|
insilmaril@366
|
4959 |
postSelStr,undoCom,
|
insilmaril@366
|
4960 |
preSelStr, redoCom,
|
insilmaril@366
|
4961 |
QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
|
insilmaril@163
|
4962 |
} else
|
insilmaril@424
|
4963 |
if (lmosel->getDepth()==1)
|
insilmaril@366
|
4964 |
{
|
insilmaril@366
|
4965 |
// The select string might be different _after_ moving around.
|
insilmaril@366
|
4966 |
// Therefor reposition and then use string of old selection, too
|
insilmaril@645
|
4967 |
model->reposition();
|
insilmaril@366
|
4968 |
|
insilmaril@625
|
4969 |
QPointF rp(lmosel->getRelPos());
|
insilmaril@625
|
4970 |
if (rp != movingObj_orgRelPos)
|
insilmaril@625
|
4971 |
{
|
insilmaril@625
|
4972 |
QString ps=qpointfToString(rp);
|
insilmaril@625
|
4973 |
saveState(
|
insilmaril@684
|
4974 |
model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
|
insilmaril@625
|
4975 |
preSelStr, "moveRel "+ps,
|
insilmaril@625
|
4976 |
QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
|
insilmaril@625
|
4977 |
}
|
insilmaril@366
|
4978 |
}
|
insilmaril@0
|
4979 |
// Draw the original link, before selection was moved around
|
insilmaril@645
|
4980 |
model->reposition();
|
insilmaril@0
|
4981 |
}
|
insilmaril@442
|
4982 |
xelection.update();
|
insilmaril@408
|
4983 |
// Finally resize scene, if needed
|
insilmaril@408
|
4984 |
scene()->update();
|
insilmaril@0
|
4985 |
movingObj=NULL;
|
insilmaril@366
|
4986 |
|
insilmaril@366
|
4987 |
// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
|
insilmaril@366
|
4988 |
updateActions();
|
insilmaril@0
|
4989 |
} else
|
insilmaril@83
|
4990 |
// maybe we moved View: set old cursor
|
insilmaril@366
|
4991 |
setCursor (Qt::ArrowCursor);
|
insilmaril@83
|
4992 |
|
insilmaril@0
|
4993 |
}
|
insilmaril@0
|
4994 |
|
insilmaril@408
|
4995 |
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
|
insilmaril@0
|
4996 |
{
|
insilmaril@491
|
4997 |
if (isSelectBlocked() )
|
insilmaril@491
|
4998 |
{
|
insilmaril@491
|
4999 |
e->ignore();
|
insilmaril@491
|
5000 |
return;
|
insilmaril@491
|
5001 |
}
|
insilmaril@491
|
5002 |
|
insilmaril@366
|
5003 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
5004 |
{
|
insilmaril@408
|
5005 |
QPointF p = mapToScene(e->pos());
|
insilmaril@645
|
5006 |
LinkableMapObj *lmo=model->findMapObj(p, NULL);
|
insilmaril@0
|
5007 |
if (lmo) { // MapObj was found
|
insilmaril@0
|
5008 |
// First select the MapObj than edit heading
|
insilmaril@424
|
5009 |
xelection.select(lmo);
|
insilmaril@366
|
5010 |
mainWindow->editHeading();
|
insilmaril@0
|
5011 |
}
|
insilmaril@0
|
5012 |
}
|
insilmaril@0
|
5013 |
}
|
insilmaril@0
|
5014 |
|
insilmaril@0
|
5015 |
void MapEditor::resizeEvent (QResizeEvent* e)
|
insilmaril@0
|
5016 |
{
|
insilmaril@408
|
5017 |
QGraphicsView::resizeEvent( e );
|
insilmaril@0
|
5018 |
}
|
insilmaril@0
|
5019 |
|
insilmaril@412
|
5020 |
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
|
insilmaril@119
|
5021 |
{
|
insilmaril@417
|
5022 |
//for (unsigned int i=0;event->format(i);i++) // Debug mime type
|
insilmaril@417
|
5023 |
// cerr << event->format(i) << endl;
|
insilmaril@417
|
5024 |
|
insilmaril@417
|
5025 |
if (event->mimeData()->hasImage())
|
insilmaril@417
|
5026 |
event->acceptProposedAction();
|
insilmaril@417
|
5027 |
else
|
insilmaril@417
|
5028 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
5029 |
event->acceptProposedAction();
|
insilmaril@417
|
5030 |
}
|
insilmaril@417
|
5031 |
|
insilmaril@531
|
5032 |
void MapEditor::dragMoveEvent(QDragMoveEvent *)
|
insilmaril@417
|
5033 |
{
|
insilmaril@417
|
5034 |
}
|
insilmaril@417
|
5035 |
|
insilmaril@417
|
5036 |
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
|
insilmaril@417
|
5037 |
{
|
insilmaril@417
|
5038 |
event->accept();
|
insilmaril@119
|
5039 |
}
|
insilmaril@129
|
5040 |
|
insilmaril@412
|
5041 |
void MapEditor::dropEvent(QDropEvent *event)
|
insilmaril@129
|
5042 |
{
|
insilmaril@424
|
5043 |
BranchObj *sel=xelection.getBranch();
|
insilmaril@424
|
5044 |
if (sel)
|
insilmaril@128
|
5045 |
{
|
insilmaril@505
|
5046 |
if (debug)
|
insilmaril@505
|
5047 |
foreach (QString format,event->mimeData()->formats())
|
insilmaril@658
|
5048 |
cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
|
insilmaril@497
|
5049 |
|
insilmaril@497
|
5050 |
|
insilmaril@417
|
5051 |
QList <QUrl> uris;
|
insilmaril@417
|
5052 |
if (event->mimeData()->hasImage())
|
insilmaril@128
|
5053 |
{
|
insilmaril@417
|
5054 |
QVariant imageData = event->mimeData()->imageData();
|
insilmaril@417
|
5055 |
addFloatImageInt (qvariant_cast<QPixmap>(imageData));
|
insilmaril@417
|
5056 |
} else
|
insilmaril@417
|
5057 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
5058 |
uris=event->mimeData()->urls();
|
insilmaril@417
|
5059 |
|
insilmaril@417
|
5060 |
if (uris.count()>0)
|
insilmaril@128
|
5061 |
{
|
insilmaril@417
|
5062 |
QStringList files;
|
insilmaril@417
|
5063 |
QString s;
|
insilmaril@417
|
5064 |
QString heading;
|
insilmaril@417
|
5065 |
BranchObj *bo;
|
insilmaril@428
|
5066 |
for (int i=0; i<uris.count();i++)
|
insilmaril@408
|
5067 |
{
|
insilmaril@428
|
5068 |
// Workaround to avoid adding empty branches
|
insilmaril@428
|
5069 |
if (!uris.at(i).toString().isEmpty())
|
insilmaril@417
|
5070 |
{
|
insilmaril@428
|
5071 |
bo=sel->addBranch();
|
insilmaril@428
|
5072 |
if (bo)
|
insilmaril@417
|
5073 |
{
|
insilmaril@428
|
5074 |
s=uris.at(i).toLocalFile();
|
insilmaril@428
|
5075 |
if (!s.isEmpty())
|
insilmaril@428
|
5076 |
{
|
insilmaril@625
|
5077 |
QString file = QDir::fromNativeSeparators(s);
|
insilmaril@428
|
5078 |
heading = QFileInfo(file).baseName();
|
insilmaril@428
|
5079 |
files.append(file);
|
insilmaril@428
|
5080 |
if (file.endsWith(".vym", false))
|
insilmaril@428
|
5081 |
bo->setVymLink(file);
|
insilmaril@428
|
5082 |
else
|
insilmaril@428
|
5083 |
bo->setURL(uris.at(i).toString());
|
insilmaril@428
|
5084 |
} else
|
insilmaril@428
|
5085 |
{
|
insilmaril@428
|
5086 |
bo->setURL(uris.at(i).toString());
|
insilmaril@428
|
5087 |
}
|
insilmaril@428
|
5088 |
|
insilmaril@428
|
5089 |
if (!heading.isEmpty())
|
insilmaril@428
|
5090 |
bo->setHeading(heading);
|
insilmaril@428
|
5091 |
else
|
insilmaril@428
|
5092 |
bo->setHeading(uris.at(i).toString());
|
insilmaril@428
|
5093 |
}
|
insilmaril@417
|
5094 |
}
|
insilmaril@417
|
5095 |
}
|
insilmaril@645
|
5096 |
model->reposition();
|
insilmaril@417
|
5097 |
}
|
insilmaril@417
|
5098 |
}
|
insilmaril@417
|
5099 |
event->acceptProposedAction();
|
insilmaril@417
|
5100 |
}
|
insilmaril@417
|
5101 |
|
insilmaril@491
|
5102 |
void MapEditor::timerEvent(QTimerEvent *event) //TODO animation
|
insilmaril@473
|
5103 |
{
|
insilmaril@473
|
5104 |
Q_UNUSED(event);
|
insilmaril@473
|
5105 |
|
insilmaril@473
|
5106 |
cout << "ME::timerEvent\n";
|
insilmaril@473
|
5107 |
|
insilmaril@473
|
5108 |
for (int i=0; i<animObjList.size(); ++i)
|
insilmaril@473
|
5109 |
{
|
insilmaril@473
|
5110 |
animObjList.at(i)->animate();
|
insilmaril@473
|
5111 |
((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() );
|
insilmaril@473
|
5112 |
}
|
insilmaril@645
|
5113 |
model->reposition();
|
insilmaril@473
|
5114 |
}
|
insilmaril@473
|
5115 |
|
insilmaril@528
|
5116 |
|
insilmaril@528
|
5117 |
void MapEditor::sendSelection()
|
insilmaril@473
|
5118 |
{
|
insilmaril@531
|
5119 |
if (netstate!=Server) return;
|
insilmaril@531
|
5120 |
sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) );
|
insilmaril@528
|
5121 |
}
|
insilmaril@528
|
5122 |
|
insilmaril@528
|
5123 |
void MapEditor::newServer()
|
insilmaril@528
|
5124 |
{
|
insilmaril@531
|
5125 |
port=54321;
|
insilmaril@531
|
5126 |
sendCounter=0;
|
insilmaril@528
|
5127 |
tcpServer = new QTcpServer(this);
|
insilmaril@531
|
5128 |
if (!tcpServer->listen(QHostAddress::Any,port)) {
|
insilmaril@528
|
5129 |
QMessageBox::critical(this, "vym server",
|
insilmaril@528
|
5130 |
QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
|
insilmaril@528
|
5131 |
close();
|
insilmaril@528
|
5132 |
return;
|
insilmaril@528
|
5133 |
}
|
insilmaril@528
|
5134 |
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
|
insilmaril@531
|
5135 |
netstate=Server;
|
insilmaril@534
|
5136 |
cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
|
insilmaril@473
|
5137 |
}
|
insilmaril@473
|
5138 |
|
insilmaril@531
|
5139 |
void MapEditor::connectToServer()
|
insilmaril@531
|
5140 |
{
|
insilmaril@531
|
5141 |
port=54321;
|
insilmaril@531
|
5142 |
server="salam.suse.de";
|
insilmaril@531
|
5143 |
server="localhost";
|
insilmaril@531
|
5144 |
clientSocket = new QTcpSocket (this);
|
insilmaril@531
|
5145 |
clientSocket->abort();
|
insilmaril@531
|
5146 |
clientSocket->connectToHost(server ,port);
|
insilmaril@531
|
5147 |
connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
|
insilmaril@531
|
5148 |
connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
insilmaril@531
|
5149 |
this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
|
insilmaril@531
|
5150 |
netstate=Client;
|
insilmaril@658
|
5151 |
cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
|
insilmaril@531
|
5152 |
|
insilmaril@531
|
5153 |
|
insilmaril@531
|
5154 |
}
|
insilmaril@531
|
5155 |
|
insilmaril@527
|
5156 |
void MapEditor::newClient()
|
insilmaril@527
|
5157 |
{
|
insilmaril@527
|
5158 |
QTcpSocket *newClient = tcpServer->nextPendingConnection();
|
insilmaril@527
|
5159 |
connect(newClient, SIGNAL(disconnected()),
|
insilmaril@527
|
5160 |
newClient, SLOT(deleteLater()));
|
insilmaril@527
|
5161 |
|
insilmaril@658
|
5162 |
cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
|
insilmaril@527
|
5163 |
|
insilmaril@527
|
5164 |
clientList.append (newClient);
|
insilmaril@527
|
5165 |
}
|
insilmaril@473
|
5166 |
|
insilmaril@528
|
5167 |
|
insilmaril@528
|
5168 |
void MapEditor::sendData(const QString &s)
|
insilmaril@528
|
5169 |
{
|
insilmaril@537
|
5170 |
if (clientList.size()==0) return;
|
insilmaril@537
|
5171 |
|
insilmaril@528
|
5172 |
// Create bytearray to send
|
insilmaril@528
|
5173 |
QByteArray block;
|
insilmaril@528
|
5174 |
QDataStream out(&block, QIODevice::WriteOnly);
|
insilmaril@528
|
5175 |
out.setVersion(QDataStream::Qt_4_0);
|
insilmaril@528
|
5176 |
|
insilmaril@528
|
5177 |
// Reserve some space for blocksize
|
insilmaril@528
|
5178 |
out << (quint16)0;
|
insilmaril@528
|
5179 |
|
insilmaril@531
|
5180 |
// Write sendCounter
|
insilmaril@531
|
5181 |
out << sendCounter++;
|
insilmaril@531
|
5182 |
|
insilmaril@528
|
5183 |
// Write data
|
insilmaril@528
|
5184 |
out << s;
|
insilmaril@528
|
5185 |
|
insilmaril@528
|
5186 |
// Go back and write blocksize so far
|
insilmaril@528
|
5187 |
out.device()->seek(0);
|
insilmaril@531
|
5188 |
quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
|
insilmaril@531
|
5189 |
out << bs;
|
insilmaril@531
|
5190 |
|
insilmaril@537
|
5191 |
if (debug)
|
insilmaril@658
|
5192 |
cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
|
insilmaril@528
|
5193 |
|
insilmaril@528
|
5194 |
for (int i=0; i<clientList.size(); ++i)
|
insilmaril@528
|
5195 |
{
|
insilmaril@658
|
5196 |
//cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
|
insilmaril@528
|
5197 |
clientList.at(i)->write (block);
|
insilmaril@528
|
5198 |
}
|
insilmaril@528
|
5199 |
}
|
insilmaril@531
|
5200 |
|
insilmaril@531
|
5201 |
void MapEditor::readData ()
|
insilmaril@531
|
5202 |
{
|
insilmaril@531
|
5203 |
while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
|
insilmaril@531
|
5204 |
{
|
insilmaril@537
|
5205 |
if (debug)
|
insilmaril@537
|
5206 |
cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
|
insilmaril@534
|
5207 |
quint16 recCounter;
|
insilmaril@534
|
5208 |
quint16 blockSize;
|
insilmaril@534
|
5209 |
|
insilmaril@534
|
5210 |
QDataStream in(clientSocket);
|
insilmaril@534
|
5211 |
in.setVersion(QDataStream::Qt_4_0);
|
insilmaril@534
|
5212 |
|
insilmaril@534
|
5213 |
in >> blockSize;
|
insilmaril@534
|
5214 |
in >> recCounter;
|
insilmaril@534
|
5215 |
|
insilmaril@534
|
5216 |
QString t;
|
insilmaril@534
|
5217 |
in >>t;
|
insilmaril@537
|
5218 |
if (debug)
|
insilmaril@658
|
5219 |
cout << " t="<<qPrintable (t)<<endl;
|
insilmaril@534
|
5220 |
parseAtom (t);
|
insilmaril@531
|
5221 |
}
|
insilmaril@534
|
5222 |
return;
|
insilmaril@531
|
5223 |
}
|
insilmaril@531
|
5224 |
|
insilmaril@531
|
5225 |
void MapEditor::displayNetworkError(QAbstractSocket::SocketError socketError)
|
insilmaril@531
|
5226 |
{
|
insilmaril@531
|
5227 |
switch (socketError) {
|
insilmaril@531
|
5228 |
case QAbstractSocket::RemoteHostClosedError:
|
insilmaril@531
|
5229 |
break;
|
insilmaril@531
|
5230 |
case QAbstractSocket::HostNotFoundError:
|
insilmaril@645
|
5231 |
QMessageBox::information(this, vymName +" Network client",
|
insilmaril@531
|
5232 |
"The host was not found. Please check the "
|
insilmaril@531
|
5233 |
"host name and port settings.");
|
insilmaril@531
|
5234 |
break;
|
insilmaril@531
|
5235 |
case QAbstractSocket::ConnectionRefusedError:
|
insilmaril@645
|
5236 |
QMessageBox::information(this, vymName + " Network client",
|
insilmaril@531
|
5237 |
"The connection was refused by the peer. "
|
insilmaril@531
|
5238 |
"Make sure the fortune server is running, "
|
insilmaril@531
|
5239 |
"and check that the host name and port "
|
insilmaril@531
|
5240 |
"settings are correct.");
|
insilmaril@531
|
5241 |
break;
|
insilmaril@531
|
5242 |
default:
|
insilmaril@645
|
5243 |
QMessageBox::information(this, vymName + " Network client",
|
insilmaril@531
|
5244 |
QString("The following error occurred: %1.")
|
insilmaril@531
|
5245 |
.arg(clientSocket->errorString()));
|
insilmaril@531
|
5246 |
}
|
insilmaril@531
|
5247 |
}
|
insilmaril@531
|
5248 |
|
insilmaril@528
|
5249 |
void MapEditor::autosave()
|
insilmaril@528
|
5250 |
{
|
insilmaril@676
|
5251 |
QDateTime now=QDateTime().currentDateTime();
|
insilmaril@676
|
5252 |
/* FIXME debug
|
insilmaril@676
|
5253 |
cout << "ME::autosave checking "<<qPrintable(filePath)<<"...\n";
|
insilmaril@676
|
5254 |
cout << "fsaved: "<<qPrintable (fileChangedTime.toString())<<endl;
|
insilmaril@676
|
5255 |
cout << " fnow: "<<qPrintable (QFileInfo(filePath).lastModified().toString())<<endl;
|
insilmaril@676
|
5256 |
cout << " time: "<<qPrintable (now.toString())<<endl;
|
insilmaril@680
|
5257 |
cout << " zipped="<<zipped<<endl;
|
insilmaril@679
|
5258 |
*/
|
insilmaril@528
|
5259 |
// Disable autosave, while we have gone back in history
|
insilmaril@528
|
5260 |
int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
|
insilmaril@528
|
5261 |
if (redosAvail>0) return;
|
insilmaril@528
|
5262 |
|
insilmaril@528
|
5263 |
|
insilmaril@528
|
5264 |
if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() )
|
insilmaril@676
|
5265 |
{
|
insilmaril@676
|
5266 |
if (QFileInfo(filePath).lastModified()<=fileChangedTime)
|
insilmaril@676
|
5267 |
mainWindow->fileSave (this);
|
insilmaril@676
|
5268 |
else
|
insilmaril@676
|
5269 |
if (debug)
|
insilmaril@676
|
5270 |
cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
|
insilmaril@676
|
5271 |
|
insilmaril@676
|
5272 |
}
|
insilmaril@676
|
5273 |
}
|
insilmaril@676
|
5274 |
|
insilmaril@676
|
5275 |
void MapEditor::fileChanged()
|
insilmaril@676
|
5276 |
{
|
insilmaril@676
|
5277 |
// Check if file on disk has changed meanwhile
|
insilmaril@676
|
5278 |
if (!filePath.isEmpty())
|
insilmaril@676
|
5279 |
{
|
insilmaril@676
|
5280 |
QDateTime tmod=QFileInfo (filePath).lastModified();
|
insilmaril@676
|
5281 |
if (tmod>fileChangedTime)
|
insilmaril@676
|
5282 |
{
|
insilmaril@676
|
5283 |
|
insilmaril@676
|
5284 |
/* FIXME debug message, sometimes there's a glitch in the metrics...
|
insilmaril@676
|
5285 |
cout << "ME::fileChanged()\n"
|
insilmaril@676
|
5286 |
<< " last saved: "<<qPrintable (fileChangedTime.toString())<<endl
|
insilmaril@676
|
5287 |
<< " last modififed: "<<qPrintable (tmod.toString())<<endl;
|
insilmaril@676
|
5288 |
*/
|
insilmaril@676
|
5289 |
// FIXME switch to current mapeditor and finish lineedits...
|
insilmaril@676
|
5290 |
QMessageBox mb( vymName,
|
insilmaril@676
|
5291 |
tr("The file of the map on disk has changed:\n\n"
|
insilmaril@676
|
5292 |
" %1\n\nDo you want to reload this map with the new file?").arg(filePath),
|
insilmaril@676
|
5293 |
QMessageBox::Question,
|
insilmaril@676
|
5294 |
QMessageBox::Yes ,
|
insilmaril@676
|
5295 |
QMessageBox::Cancel | QMessageBox::Default,
|
insilmaril@676
|
5296 |
QMessageBox::NoButton );
|
insilmaril@676
|
5297 |
|
insilmaril@676
|
5298 |
mb.setButtonText( QMessageBox::Yes, tr("Reload"));
|
insilmaril@676
|
5299 |
mb.setButtonText( QMessageBox::No, tr("Ignore"));
|
insilmaril@676
|
5300 |
switch( mb.exec() )
|
insilmaril@676
|
5301 |
{
|
insilmaril@676
|
5302 |
case QMessageBox::Yes:
|
insilmaril@676
|
5303 |
// Reload map
|
insilmaril@676
|
5304 |
load (filePath,NewMap,fileType);
|
insilmaril@676
|
5305 |
case QMessageBox::Cancel:
|
insilmaril@676
|
5306 |
fileChangedTime=tmod; // allow autosave to overwrite newer file!
|
insilmaril@676
|
5307 |
}
|
insilmaril@676
|
5308 |
}
|
insilmaril@676
|
5309 |
}
|
insilmaril@676
|
5310 |
|
insilmaril@528
|
5311 |
}
|
insilmaril@528
|
5312 |
|
insilmaril@528
|
5313 |
|
insilmaril@491
|
5314 |
/*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event)
|
insilmaril@417
|
5315 |
{
|
insilmaril@408
|
5316 |
|
insilmaril@408
|
5317 |
} else if (event->provides("application/x-moz-file-promise-url") &&
|
insilmaril@408
|
5318 |
event->provides("application/x-moz-nativeimage"))
|
insilmaril@408
|
5319 |
{
|
insilmaril@129
|
5320 |
// Contains url to the img src in unicode16
|
insilmaril@128
|
5321 |
QByteArray d = event->encodedData("application/x-moz-file-promise-url");
|
insilmaril@128
|
5322 |
QString url = QString((const QChar*)d.data(),d.size()/2);
|
insilmaril@408
|
5323 |
fetchImage(url);
|
insilmaril@408
|
5324 |
event->accept();
|
insilmaril@128
|
5325 |
update=true;
|
insilmaril@408
|
5326 |
} else if (event->provides ("text/uri-list"))
|
insilmaril@408
|
5327 |
{ // Uris provided e.g. by konqueror
|
insilmaril@408
|
5328 |
Q3UriDrag::decode (event,uris);
|
insilmaril@408
|
5329 |
} else if (event->provides ("_NETSCAPE_URL"))
|
insilmaril@128
|
5330 |
{ // Uris provided by Mozilla
|
insilmaril@129
|
5331 |
QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
|
insilmaril@129
|
5332 |
uris.append(l[0]);
|
insilmaril@129
|
5333 |
heading = l[1];
|
insilmaril@129
|
5334 |
} else if (event->provides("text/html")) {
|
insilmaril@129
|
5335 |
|
insilmaril@129
|
5336 |
// Handels text mime types
|
insilmaril@129
|
5337 |
// Look like firefox allways handle text as unicode16 (2 bytes per char.)
|
insilmaril@129
|
5338 |
QByteArray d = event->encodedData("text/html");
|
insilmaril@129
|
5339 |
QString text;
|
insilmaril@129
|
5340 |
if (isUnicode16(d))
|
insilmaril@129
|
5341 |
text = QString((const QChar*)d.data(),d.size()/2);
|
insilmaril@129
|
5342 |
else
|
insilmaril@129
|
5343 |
text = QString(d);
|
insilmaril@129
|
5344 |
|
insilmaril@129
|
5345 |
textEditor->setText(text);
|
insilmaril@129
|
5346 |
|
insilmaril@129
|
5347 |
event->accept();
|
insilmaril@129
|
5348 |
update=true;
|
insilmaril@129
|
5349 |
} else if (event->provides("text/plain")) {
|
insilmaril@129
|
5350 |
QByteArray d = event->encodedData("text/plain");
|
insilmaril@129
|
5351 |
QString text;
|
insilmaril@129
|
5352 |
if (isUnicode16(d))
|
insilmaril@129
|
5353 |
text = QString((const QChar*)d.data(),d.size()/2);
|
insilmaril@129
|
5354 |
else
|
insilmaril@129
|
5355 |
text = QString(d);
|
insilmaril@129
|
5356 |
|
insilmaril@129
|
5357 |
textEditor->setText(text);
|
insilmaril@129
|
5358 |
|
insilmaril@129
|
5359 |
event->accept();
|
insilmaril@129
|
5360 |
update= true;
|
insilmaril@128
|
5361 |
}
|
insilmaril@417
|
5362 |
|
insilmaril@406
|
5363 |
*/
|
insilmaril@406
|
5364 |
|
insilmaril@417
|
5365 |
|
insilmaril@412
|
5366 |
|
insilmaril@412
|
5367 |
bool isUnicode16(const QByteArray &d)
|
insilmaril@412
|
5368 |
{
|
insilmaril@412
|
5369 |
// TODO: make more precise check for unicode 16.
|
insilmaril@412
|
5370 |
// Guess unicode16 if any of second bytes are zero
|
insilmaril@412
|
5371 |
unsigned int length = max(0,d.size()-2)/2;
|
insilmaril@412
|
5372 |
for (unsigned int i = 0; i<length ; i++)
|
insilmaril@412
|
5373 |
if (d.at(i*2+1)==0) return true;
|
insilmaril@412
|
5374 |
return false;
|
insilmaril@412
|
5375 |
}
|
insilmaril@412
|
5376 |
|
insilmaril@395
|
5377 |
void MapEditor::addFloatImageInt (const QPixmap &img)
|
insilmaril@119
|
5378 |
{
|
insilmaril@424
|
5379 |
BranchObj *bo=xelection.getBranch();
|
insilmaril@424
|
5380 |
if (bo)
|
insilmaril@119
|
5381 |
{
|
insilmaril@395
|
5382 |
FloatImageObj *fio=bo->addFloatImage();
|
insilmaril@395
|
5383 |
fio->load(img);
|
insilmaril@505
|
5384 |
fio->setOriginalFilename("No original filename (image added by dropevent)");
|
insilmaril@684
|
5385 |
QString s=model->getSelectString(bo);
|
insilmaril@505
|
5386 |
saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
|
insilmaril@505
|
5387 |
saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
|
insilmaril@645
|
5388 |
model->reposition();
|
insilmaril@408
|
5389 |
scene()->update();
|
insilmaril@119
|
5390 |
}
|
insilmaril@119
|
5391 |
}
|
insilmaril@119
|
5392 |
|
insilmaril@412
|
5393 |
/*
|
insilmaril@412
|
5394 |
|
insilmaril@412
|
5395 |
void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /)
|
insilmaril@119
|
5396 |
{
|
insilmaril@119
|
5397 |
if (!imageBuffer) imageBuffer = new QBuffer();
|
insilmaril@119
|
5398 |
if (!imageBuffer->isOpen()) {
|
insilmaril@366
|
5399 |
imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
|
insilmaril@119
|
5400 |
}
|
insilmaril@119
|
5401 |
imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
|
insilmaril@119
|
5402 |
}
|
insilmaril@119
|
5403 |
|
insilmaril@119
|
5404 |
|
insilmaril@366
|
5405 |
void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
|
insilmaril@119
|
5406 |
{
|
insilmaril@366
|
5407 |
if (nop->state()==Q3NetworkProtocol::StDone) {
|
insilmaril@129
|
5408 |
QPixmap img(imageBuffer->buffer());
|
insilmaril@395
|
5409 |
addFloatImageInt (img);
|
insilmaril@129
|
5410 |
}
|
insilmaril@129
|
5411 |
|
insilmaril@129
|
5412 |
if (imageBuffer) {
|
insilmaril@129
|
5413 |
imageBuffer->close();
|
insilmaril@129
|
5414 |
if (imageBuffer) {
|
insilmaril@129
|
5415 |
imageBuffer->close();
|
insilmaril@129
|
5416 |
delete imageBuffer;
|
insilmaril@129
|
5417 |
imageBuffer = 0;
|
insilmaril@129
|
5418 |
}
|
insilmaril@129
|
5419 |
}
|
insilmaril@119
|
5420 |
}
|
insilmaril@119
|
5421 |
|
insilmaril@129
|
5422 |
void MapEditor::fetchImage(const QString &url)
|
insilmaril@119
|
5423 |
{
|
insilmaril@119
|
5424 |
if (urlOperator) {
|
insilmaril@119
|
5425 |
urlOperator->stop();
|
insilmaril@119
|
5426 |
disconnect(urlOperator);
|
insilmaril@119
|
5427 |
delete urlOperator;
|
insilmaril@119
|
5428 |
}
|
insilmaril@119
|
5429 |
|
insilmaril@366
|
5430 |
urlOperator = new Q3UrlOperator(url);
|
insilmaril@366
|
5431 |
connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
|
insilmaril@366
|
5432 |
this, SLOT(imageDataFinished(Q3NetworkOperation*)));
|
insilmaril@366
|
5433 |
|
insilmaril@366
|
5434 |
connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
|
insilmaril@366
|
5435 |
this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
|
insilmaril@119
|
5436 |
urlOperator->get();
|
insilmaril@119
|
5437 |
}
|
insilmaril@412
|
5438 |
*/
|
insilmaril@412
|
5439 |
|