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