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