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