insilmaril@0
|
1 |
#include "mapeditor.h"
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
#include <qstatusbar.h>
|
insilmaril@0
|
4 |
#include <qmessagebox.h>
|
insilmaril@0
|
5 |
#include <qapplication.h>
|
insilmaril@0
|
6 |
#include <qpainter.h>
|
insilmaril@0
|
7 |
#include <qpopupmenu.h>
|
insilmaril@0
|
8 |
#include <qprinter.h>
|
insilmaril@0
|
9 |
#include <qpaintdevicemetrics.h>
|
insilmaril@0
|
10 |
#include <qfile.h>
|
insilmaril@0
|
11 |
#include <qfiledialog.h>
|
insilmaril@0
|
12 |
#include <qdir.h>
|
insilmaril@0
|
13 |
#include <qcolor.h>
|
insilmaril@0
|
14 |
#include <qcolordialog.h>
|
insilmaril@0
|
15 |
#include <qbitmap.h>
|
insilmaril@0
|
16 |
#include <qprocess.h>
|
insilmaril@0
|
17 |
#include <qinputdialog.h>
|
insilmaril@119
|
18 |
#include <qdragobject.h>
|
insilmaril@119
|
19 |
#include <qurloperator.h>
|
insilmaril@119
|
20 |
#include <qnetworkprotocol.h>
|
insilmaril@129
|
21 |
#include <qregexp.h>
|
insilmaril@0
|
22 |
|
insilmaril@0
|
23 |
#include <iostream>
|
insilmaril@95
|
24 |
#include <cstdlib>
|
insilmaril@0
|
25 |
#include <typeinfo>
|
insilmaril@0
|
26 |
|
insilmaril@0
|
27 |
#include "version.h"
|
insilmaril@0
|
28 |
|
insilmaril@105
|
29 |
#include "api.h"
|
insilmaril@0
|
30 |
#include "xml.h"
|
insilmaril@0
|
31 |
#include "texteditor.h"
|
insilmaril@0
|
32 |
#include "linkablemapobj.h"
|
insilmaril@0
|
33 |
#include "exports.h"
|
insilmaril@0
|
34 |
#include "misc.h"
|
insilmaril@0
|
35 |
#include "mainwindow.h"
|
insilmaril@0
|
36 |
#include "extrainfodialog.h"
|
insilmaril@95
|
37 |
#include "editxlinkdialog.h"
|
insilmaril@0
|
38 |
#include "settings.h"
|
insilmaril@0
|
39 |
|
insilmaril@0
|
40 |
#include "icons/flag-note.xpm"
|
insilmaril@0
|
41 |
#include "icons/flag-url.xpm"
|
insilmaril@0
|
42 |
#include "icons/flag-vymlink.xpm"
|
insilmaril@0
|
43 |
#include "icons/flag-scrolled-right.xpm"
|
insilmaril@0
|
44 |
#include "icons/flag-tmpUnscrolled-right.xpm"
|
insilmaril@0
|
45 |
#include "icons/flag-questionmark.xpm"
|
insilmaril@0
|
46 |
#include "icons/flag-exclamationmark.xpm"
|
insilmaril@0
|
47 |
#include "icons/flag-hook-green.xpm"
|
insilmaril@0
|
48 |
#include "icons/flag-cross-red.xpm"
|
insilmaril@0
|
49 |
#include "icons/flag-stopsign.xpm"
|
insilmaril@0
|
50 |
#include "icons/flag-smiley-good.xpm"
|
insilmaril@0
|
51 |
#include "icons/flag-smiley-sad.xpm"
|
insilmaril@0
|
52 |
#include "icons/flag-clock.xpm"
|
insilmaril@0
|
53 |
#include "icons/flag-lamp.xpm"
|
insilmaril@0
|
54 |
#include "icons/flag-arrow-up.xpm"
|
insilmaril@0
|
55 |
#include "icons/flag-arrow-down.xpm"
|
insilmaril@0
|
56 |
#include "icons/flag-thumb-up.xpm"
|
insilmaril@0
|
57 |
#include "icons/flag-thumb-down.xpm"
|
insilmaril@0
|
58 |
#include "icons/flag-heart.xpm"
|
insilmaril@0
|
59 |
#include "icons/flag-flash.xpm"
|
insilmaril@0
|
60 |
#include "icons/flag-lifebelt.xpm"
|
insilmaril@0
|
61 |
|
insilmaril@0
|
62 |
extern TextEditor *textEditor;
|
insilmaril@0
|
63 |
extern int statusbarTime;
|
insilmaril@0
|
64 |
extern Main *mainWindow;
|
insilmaril@0
|
65 |
extern FlagRowObj *systemFlagsDefault;
|
insilmaril@0
|
66 |
extern FlagRowObj *standardFlagsDefault;
|
insilmaril@0
|
67 |
extern MapEditor *clipboardME;
|
insilmaril@0
|
68 |
|
insilmaril@98
|
69 |
extern QPtrList <QAction> actionListBranches;
|
insilmaril@98
|
70 |
|
insilmaril@0
|
71 |
extern QAction *actionFileSave;
|
insilmaril@0
|
72 |
extern QAction *actionEditUndo;
|
insilmaril@0
|
73 |
extern QAction *actionEditCopy;
|
insilmaril@0
|
74 |
extern QAction *actionEditCut;
|
insilmaril@0
|
75 |
extern QAction *actionEditPaste;
|
insilmaril@0
|
76 |
extern QAction *actionEditMoveUp;
|
insilmaril@0
|
77 |
extern QAction *actionEditMoveDown;
|
insilmaril@0
|
78 |
extern QAction *actionEditToggleScroll;
|
insilmaril@0
|
79 |
extern QAction *actionEditOpenURL;
|
insilmaril@0
|
80 |
extern QAction *actionEditURL;
|
insilmaril@0
|
81 |
extern QAction *actionEditHeading2URL;
|
insilmaril@0
|
82 |
extern QAction *actionEditBugzilla2URL;
|
insilmaril@0
|
83 |
extern QAction *actionEditOpenVymLink;
|
insilmaril@0
|
84 |
extern QAction *actionEditVymLink;
|
insilmaril@0
|
85 |
extern QAction *actionEditDeleteVymLink;
|
insilmaril@0
|
86 |
extern QAction *actionEditHeading;
|
insilmaril@0
|
87 |
extern QAction *actionEditDelete;
|
insilmaril@0
|
88 |
extern QAction *actionEditAddBranch;
|
insilmaril@0
|
89 |
extern QAction *actionEditAddBranchAbove;
|
insilmaril@0
|
90 |
extern QAction *actionEditAddBranchBelow;
|
insilmaril@98
|
91 |
extern QAction *actionEditRemoveBranchHere;
|
insilmaril@98
|
92 |
extern QAction *actionEditRemoveChilds;
|
insilmaril@0
|
93 |
extern QAction *actionEditImportAdd;
|
insilmaril@0
|
94 |
extern QAction *actionEditImportReplace;
|
insilmaril@0
|
95 |
extern QAction *actionEditSaveBranch;
|
insilmaril@0
|
96 |
extern QAction *actionEditSelectFirst;
|
insilmaril@0
|
97 |
extern QAction *actionEditSelectLast;
|
insilmaril@0
|
98 |
extern QAction *actionEditLoadImage;
|
insilmaril@0
|
99 |
extern QAction *actionEditToggleFloatExport;
|
insilmaril@0
|
100 |
|
insilmaril@0
|
101 |
extern QAction* actionFormatPickColor;
|
insilmaril@0
|
102 |
extern QAction* actionFormatColorBranch;
|
insilmaril@0
|
103 |
extern QAction* actionFormatColorSubtree;
|
insilmaril@0
|
104 |
extern QAction *actionFormatLinkColorHint;
|
insilmaril@0
|
105 |
extern QAction *actionFormatBackColor;
|
insilmaril@0
|
106 |
extern QAction *actionFormatLinkColor;
|
insilmaril@0
|
107 |
|
insilmaril@89
|
108 |
extern QActionGroup* actionGroupModModes;
|
insilmaril@89
|
109 |
extern QAction* actionModModeColor;
|
insilmaril@89
|
110 |
extern QAction* actionModModeLink;
|
insilmaril@93
|
111 |
extern QAction* actionModModeCopy;
|
insilmaril@89
|
112 |
|
insilmaril@0
|
113 |
extern QActionGroup *actionGroupFormatFrameTypes;
|
insilmaril@0
|
114 |
extern QAction *actionFormatFrameNone;
|
insilmaril@0
|
115 |
extern QAction *actionFormatFrameRectangle;
|
insilmaril@0
|
116 |
|
insilmaril@0
|
117 |
extern QActionGroup *actionGroupFormatLinkStyles;
|
insilmaril@0
|
118 |
extern QAction *actionFormatLinkStyleLine;
|
insilmaril@0
|
119 |
extern QAction *actionFormatLinkStyleParabel;
|
insilmaril@0
|
120 |
extern QAction *actionFormatLinkStylePolyLine;
|
insilmaril@0
|
121 |
extern QAction *actionFormatLinkStylePolyParabel;
|
insilmaril@0
|
122 |
|
insilmaril@0
|
123 |
extern QAction *actionViewToggleNoteEditor;
|
insilmaril@0
|
124 |
|
insilmaril@0
|
125 |
extern QAction *actionSettingsAutoedit;
|
insilmaril@0
|
126 |
extern QAction *actionSettingsAutoselectHeading;
|
insilmaril@0
|
127 |
extern QAction *actionSettingsAutoselectText;
|
insilmaril@0
|
128 |
extern QAction *actionSettingsPasteNewHeading;
|
insilmaril@103
|
129 |
extern QAction *actionSettingsUseFlagGroups;
|
insilmaril@0
|
130 |
|
insilmaril@0
|
131 |
extern QPopupMenu *branchContextMenu;
|
insilmaril@89
|
132 |
extern QPopupMenu *branchLinksContextMenu;
|
insilmaril@94
|
133 |
extern QPopupMenu *branchLinksContextMenuDup;
|
insilmaril@0
|
134 |
extern QPopupMenu *floatimageContextMenu;
|
insilmaril@0
|
135 |
extern QPopupMenu *saveImageFormatMenu;
|
insilmaril@0
|
136 |
extern QPopupMenu *exportImageFormatMenu;
|
insilmaril@0
|
137 |
extern QPopupMenu *canvasContextMenu;
|
insilmaril@0
|
138 |
|
insilmaril@0
|
139 |
extern Settings settings;
|
insilmaril@0
|
140 |
|
insilmaril@0
|
141 |
|
insilmaril@0
|
142 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@0
|
143 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@0
|
144 |
MapEditor::MapEditor(
|
insilmaril@0
|
145 |
QWidget* parent, bool interactive, const char* name, WFlags f) :
|
insilmaril@119
|
146 |
QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
|
insilmaril@0
|
147 |
{
|
insilmaril@0
|
148 |
//cout << "Constructor ME "<<this<<endl;
|
insilmaril@0
|
149 |
|
insilmaril@119
|
150 |
viewport()->setAcceptDrops(true);
|
insilmaril@119
|
151 |
|
insilmaril@0
|
152 |
mapCanvas = new QCanvas(1000,800);
|
insilmaril@0
|
153 |
mapCanvas->setAdvancePeriod(30);
|
insilmaril@0
|
154 |
|
insilmaril@0
|
155 |
setCanvas (mapCanvas);
|
insilmaril@0
|
156 |
|
insilmaril@0
|
157 |
setVScrollBarMode ( QScrollView::AlwaysOn );
|
insilmaril@0
|
158 |
setHScrollBarMode ( QScrollView::AlwaysOn );
|
insilmaril@0
|
159 |
|
insilmaril@0
|
160 |
// Now create the _global_ system flags _once_:
|
insilmaril@0
|
161 |
// (Later all OrnamentedObj copy from this
|
insilmaril@0
|
162 |
// and set their own canvas)
|
insilmaril@0
|
163 |
if (!systemFlagsDefault)
|
insilmaril@0
|
164 |
{
|
insilmaril@0
|
165 |
systemFlagsDefault = new FlagRowObj (mapCanvas);
|
insilmaril@0
|
166 |
systemFlagsDefault->setVisibility (false);
|
insilmaril@0
|
167 |
systemFlagsDefault->setName ("systemFlagsDef");
|
insilmaril@0
|
168 |
|
insilmaril@0
|
169 |
FlagObj *fo = new FlagObj (mapCanvas);
|
insilmaril@0
|
170 |
fo->load(QPixmap(flag_note_xpm));
|
insilmaril@0
|
171 |
fo->setName("note");
|
insilmaril@93
|
172 |
fo->setToolTip(tr("Note","Systemflag"));
|
insilmaril@0
|
173 |
systemFlagsDefault->addFlag (fo); // makes deep copy
|
insilmaril@0
|
174 |
|
insilmaril@0
|
175 |
fo->load(QPixmap(flag_url_xpm));
|
insilmaril@0
|
176 |
fo->setName("url");
|
insilmaril@93
|
177 |
fo->setToolTip(tr("WWW Document (external)","Systemflag"));
|
insilmaril@0
|
178 |
systemFlagsDefault->addFlag (fo);
|
insilmaril@0
|
179 |
|
insilmaril@0
|
180 |
fo->load(QPixmap(flag_vymlink_xpm));
|
insilmaril@0
|
181 |
fo->setName("vymLink");
|
insilmaril@93
|
182 |
fo->setToolTip(tr("Link to another vym map","Systemflag"));
|
insilmaril@0
|
183 |
systemFlagsDefault->addFlag (fo);
|
insilmaril@0
|
184 |
|
insilmaril@0
|
185 |
fo->load(QPixmap(flag_scrolled_right_xpm));
|
insilmaril@0
|
186 |
fo->setName("scrolledright");
|
insilmaril@93
|
187 |
fo->setToolTip(tr("subtree is scrolled","Systemflag"));
|
insilmaril@0
|
188 |
systemFlagsDefault->addFlag (fo);
|
insilmaril@0
|
189 |
|
insilmaril@0
|
190 |
fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
|
insilmaril@0
|
191 |
fo->setName("tmpUnscrolledright");
|
insilmaril@93
|
192 |
fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
|
insilmaril@0
|
193 |
systemFlagsDefault->addFlag (fo);
|
insilmaril@0
|
194 |
delete (fo);
|
insilmaril@0
|
195 |
}
|
insilmaril@0
|
196 |
if (!standardFlagsDefault)
|
insilmaril@0
|
197 |
{
|
insilmaril@0
|
198 |
standardFlagsDefault = new FlagRowObj (mapCanvas);
|
insilmaril@0
|
199 |
standardFlagsDefault->setVisibility (false);
|
insilmaril@0
|
200 |
standardFlagsDefault->setName ("standardFlagsDef");
|
insilmaril@0
|
201 |
|
insilmaril@0
|
202 |
FlagObj *fo = new FlagObj (mapCanvas);
|
insilmaril@0
|
203 |
fo->load(QPixmap(flag_exclamationmark_xpm));
|
insilmaril@103
|
204 |
fo->setName ("exclamationmark");
|
insilmaril@103
|
205 |
fo->setGroup("standard-mark");
|
insilmaril@93
|
206 |
fo->setToolTip(tr("Take care!","Standardflag"));
|
insilmaril@0
|
207 |
standardFlagsDefault->addFlag (fo); // makes deep copy
|
insilmaril@0
|
208 |
|
insilmaril@0
|
209 |
fo->load(QPixmap(flag_questionmark_xpm));
|
insilmaril@0
|
210 |
fo->setName("questionmark");
|
insilmaril@103
|
211 |
fo->setGroup("standard-mark");
|
insilmaril@93
|
212 |
fo->setToolTip(tr("Really?","Standardflag"));
|
insilmaril@0
|
213 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
214 |
|
insilmaril@0
|
215 |
fo->load(QPixmap(flag_hook_green_xpm));
|
insilmaril@0
|
216 |
fo->setName("hook-green");
|
insilmaril@103
|
217 |
fo->setGroup("standard-hook");
|
insilmaril@93
|
218 |
fo->setToolTip(tr("ok!","Standardflag"));
|
insilmaril@0
|
219 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
220 |
|
insilmaril@0
|
221 |
fo->load(QPixmap(flag_cross_red_xpm));
|
insilmaril@0
|
222 |
fo->setName("cross-red");
|
insilmaril@103
|
223 |
fo->setGroup("standard-hook");
|
insilmaril@93
|
224 |
fo->setToolTip(tr("Not ok!","Standardflag"));
|
insilmaril@0
|
225 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
226 |
|
insilmaril@0
|
227 |
fo->load(QPixmap(flag_stopsign_xpm));
|
insilmaril@0
|
228 |
fo->setName("stopsign");
|
insilmaril@93
|
229 |
fo->setToolTip(tr("This won't work!","Standardflag"));
|
insilmaril@0
|
230 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
231 |
|
insilmaril@0
|
232 |
fo->load(QPixmap(flag_smiley_good_xpm));
|
insilmaril@0
|
233 |
fo->setName("smiley-good");
|
insilmaril@103
|
234 |
fo->setGroup("standard-smiley");
|
insilmaril@93
|
235 |
fo->setToolTip(tr("Good","Standardflag"));
|
insilmaril@0
|
236 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
237 |
|
insilmaril@0
|
238 |
fo->load(QPixmap(flag_smiley_sad_xpm));
|
insilmaril@0
|
239 |
fo->setName("smiley-sad");
|
insilmaril@103
|
240 |
fo->setGroup("standard-smiley");
|
insilmaril@93
|
241 |
fo->setToolTip(tr("Bad","Standardflag"));
|
insilmaril@0
|
242 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
243 |
|
insilmaril@0
|
244 |
fo->load(QPixmap(flag_clock_xpm));
|
insilmaril@0
|
245 |
fo->setName("clock");
|
insilmaril@93
|
246 |
fo->setToolTip(tr("Time critical","Standardflag"));
|
insilmaril@0
|
247 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
248 |
|
insilmaril@0
|
249 |
fo->load(QPixmap(flag_lamp_xpm));
|
insilmaril@0
|
250 |
fo->setName("lamp");
|
insilmaril@93
|
251 |
fo->setToolTip(tr("Idea!","Standardflag"));
|
insilmaril@0
|
252 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
253 |
|
insilmaril@0
|
254 |
fo->load(QPixmap(flag_arrow_up_xpm));
|
insilmaril@0
|
255 |
fo->setName("arrow-up");
|
insilmaril@103
|
256 |
fo->setGroup("standard-arrow");
|
insilmaril@93
|
257 |
fo->setToolTip(tr("Important","Standardflag"));
|
insilmaril@0
|
258 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
259 |
|
insilmaril@0
|
260 |
fo->load(QPixmap(flag_arrow_down_xpm));
|
insilmaril@0
|
261 |
fo->setName("arrow-down");
|
insilmaril@103
|
262 |
fo->setGroup("standard-arrow");
|
insilmaril@93
|
263 |
fo->setToolTip(tr("Unimportant","Standardflag"));
|
insilmaril@0
|
264 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
265 |
|
insilmaril@0
|
266 |
fo->load(QPixmap(flag_thumb_up_xpm));
|
insilmaril@0
|
267 |
fo->setName("thumb-up");
|
insilmaril@103
|
268 |
fo->setGroup("standard-thumb");
|
insilmaril@93
|
269 |
fo->setToolTip(tr("I like this","Standardflag"));
|
insilmaril@0
|
270 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
271 |
|
insilmaril@0
|
272 |
fo->load(QPixmap(flag_thumb_down_xpm));
|
insilmaril@0
|
273 |
fo->setName("thumb-down");
|
insilmaril@103
|
274 |
fo->setGroup("standard-thumb");
|
insilmaril@103
|
275 |
fo->setToolTip(tr("I like this","Standardflag"));
|
insilmaril@93
|
276 |
fo->setToolTip(tr("I do not like this","Standardflag"));
|
insilmaril@0
|
277 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
278 |
|
insilmaril@0
|
279 |
fo->load(QPixmap(flag_heart_xpm));
|
insilmaril@0
|
280 |
fo->setName("heart");
|
insilmaril@93
|
281 |
fo->setToolTip(tr("I just love... ","Standardflag"));
|
insilmaril@0
|
282 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
283 |
|
insilmaril@0
|
284 |
fo->load(QPixmap(flag_flash_xpm));
|
insilmaril@0
|
285 |
fo->setName("flash");
|
insilmaril@93
|
286 |
fo->setToolTip(tr("Dangerous","Standardflag"));
|
insilmaril@0
|
287 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
288 |
|
insilmaril@0
|
289 |
fo->load(QPixmap(flag_lifebelt_xpm));
|
insilmaril@0
|
290 |
fo->setName("lifebelt");
|
insilmaril@93
|
291 |
fo->setToolTip(tr("This will help","Standardflag"));
|
insilmaril@0
|
292 |
standardFlagsDefault->addFlag (fo);
|
insilmaril@0
|
293 |
delete (fo);
|
insilmaril@0
|
294 |
|
insilmaril@0
|
295 |
}
|
insilmaril@0
|
296 |
|
insilmaril@0
|
297 |
mapCenter = new MapCenterObj(mapCanvas);
|
insilmaril@0
|
298 |
mapCenter->setVisibility (true);
|
insilmaril@0
|
299 |
mapCenter->setMapEditor (this);
|
insilmaril@93
|
300 |
mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
|
insilmaril@0
|
301 |
|
insilmaril@0
|
302 |
printer=NULL;
|
insilmaril@0
|
303 |
|
insilmaril@0
|
304 |
lineedit = new QLineEdit(this, "lineedit" );
|
insilmaril@0
|
305 |
connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
|
insilmaril@0
|
306 |
lineedit->hide();
|
insilmaril@0
|
307 |
|
insilmaril@0
|
308 |
actColor=black; setColor (actColor);
|
insilmaril@97
|
309 |
defLinkColor=QColor (0,0,255);
|
insilmaril@97
|
310 |
defXLinkColor=QColor (180,180,180);
|
insilmaril@0
|
311 |
linkcolorhint=DefaultColor;
|
insilmaril@0
|
312 |
linkstyle=StylePolyParabel;
|
insilmaril@0
|
313 |
mapCanvas->setBackgroundColor (white);
|
insilmaril@0
|
314 |
|
insilmaril@0
|
315 |
// Create bitmap cursors, patform dependant
|
insilmaril@0
|
316 |
#if defined(Q_OS_MACX)
|
insilmaril@0
|
317 |
#include "icons/cursorhandopen16.xpm"
|
insilmaril@0
|
318 |
#include "icons/cursorcolorpicker16.xpm"
|
insilmaril@0
|
319 |
QBitmap cb( 16, 16, chandopen, TRUE );
|
insilmaril@0
|
320 |
QBitmap cm( 16, 16, chandopenmask, TRUE );
|
insilmaril@0
|
321 |
handOpenCursor=QCursor ( cb, cm );
|
insilmaril@0
|
322 |
// set hot spot to tip of picker
|
insilmaril@0
|
323 |
pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
|
insilmaril@0
|
324 |
#else
|
insilmaril@0
|
325 |
#include "icons/cursorhandopen.xpm"
|
insilmaril@0
|
326 |
#include "icons/cursorcolorpicker.xpm"
|
insilmaril@0
|
327 |
|
insilmaril@0
|
328 |
QBitmap cb( 32, 32, chandopen, TRUE );
|
insilmaril@0
|
329 |
QBitmap cm( 32, 32, chandopenmask, TRUE );
|
insilmaril@0
|
330 |
handOpenCursor=QCursor ( cb, cm );
|
insilmaril@0
|
331 |
// set hot spot to tip of picker
|
insilmaril@0
|
332 |
pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
|
insilmaril@0
|
333 |
#endif
|
insilmaril@0
|
334 |
|
insilmaril@0
|
335 |
pickingColor=false;
|
insilmaril@91
|
336 |
drawingLink=false;
|
insilmaril@93
|
337 |
copyingObj=false;
|
insilmaril@0
|
338 |
|
insilmaril@0
|
339 |
editingBO=NULL;
|
insilmaril@0
|
340 |
selection=NULL;
|
insilmaril@0
|
341 |
selectionLast=NULL;
|
insilmaril@0
|
342 |
movingObj=NULL;
|
insilmaril@0
|
343 |
|
insilmaril@102
|
344 |
defXLinkWidth=1;
|
insilmaril@102
|
345 |
defXLinkColor=QColor (230,230,230);
|
insilmaril@102
|
346 |
|
insilmaril@0
|
347 |
mapChanged=false;
|
insilmaril@0
|
348 |
mapDefault=true;
|
insilmaril@0
|
349 |
mapUnsaved=false;
|
insilmaril@0
|
350 |
|
insilmaril@0
|
351 |
zipped=true;
|
insilmaril@0
|
352 |
filePath="";
|
insilmaril@0
|
353 |
fileName="unnamed";
|
insilmaril@0
|
354 |
mapName="";
|
insilmaril@0
|
355 |
|
insilmaril@0
|
356 |
// Initialize find routine
|
insilmaril@0
|
357 |
itFind=NULL;
|
insilmaril@0
|
358 |
EOFind=false;
|
insilmaril@0
|
359 |
|
insilmaril@0
|
360 |
printFrame=true;
|
insilmaril@0
|
361 |
printFooter=true;
|
insilmaril@0
|
362 |
|
insilmaril@139
|
363 |
blockReposition=false;
|
insilmaril@139
|
364 |
blockSaveState=false;
|
insilmaril@0
|
365 |
isInteractive=interactive;
|
insilmaril@0
|
366 |
if (isInteractive)
|
insilmaril@0
|
367 |
// Create temporary files
|
insilmaril@0
|
368 |
makeTmpDirs();
|
insilmaril@0
|
369 |
|
insilmaril@0
|
370 |
// Initially set movingCentre
|
insilmaril@0
|
371 |
updateViewCenter();
|
insilmaril@0
|
372 |
|
insilmaril@0
|
373 |
mapCenter->reposition(); // for positioning heading
|
insilmaril@0
|
374 |
}
|
insilmaril@0
|
375 |
|
insilmaril@0
|
376 |
MapEditor::~MapEditor()
|
insilmaril@0
|
377 |
{
|
insilmaril@119
|
378 |
if (imageBuffer) delete imageBuffer;
|
insilmaril@119
|
379 |
if (urlOperator) {
|
insilmaril@119
|
380 |
urlOperator->stop();
|
insilmaril@119
|
381 |
delete urlOperator;
|
insilmaril@119
|
382 |
}
|
insilmaril@119
|
383 |
|
insilmaril@0
|
384 |
//cout <<"Destructor MapEditor\n";
|
insilmaril@0
|
385 |
if (isInteractive) delTmpDirs();
|
insilmaril@0
|
386 |
|
insilmaril@0
|
387 |
// Save Settings
|
insilmaril@0
|
388 |
//settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
|
insilmaril@0
|
389 |
|
insilmaril@0
|
390 |
}
|
insilmaril@0
|
391 |
|
insilmaril@0
|
392 |
QColor MapEditor::color()
|
insilmaril@0
|
393 |
{
|
insilmaril@0
|
394 |
return actColor;
|
insilmaril@0
|
395 |
}
|
insilmaril@0
|
396 |
|
insilmaril@0
|
397 |
QColor MapEditor::backgroundColor()
|
insilmaril@0
|
398 |
{
|
insilmaril@0
|
399 |
return mapCanvas->backgroundColor();
|
insilmaril@0
|
400 |
}
|
insilmaril@0
|
401 |
|
insilmaril@0
|
402 |
MapCenterObj* MapEditor::getMapCenter()
|
insilmaril@0
|
403 |
{
|
insilmaril@0
|
404 |
return mapCenter;
|
insilmaril@0
|
405 |
}
|
insilmaril@0
|
406 |
|
insilmaril@0
|
407 |
QCanvas* MapEditor::getCanvas()
|
insilmaril@0
|
408 |
{
|
insilmaril@0
|
409 |
return mapCanvas;
|
insilmaril@0
|
410 |
}
|
insilmaril@0
|
411 |
|
insilmaril@0
|
412 |
void MapEditor::adjustCanvasSize()
|
insilmaril@0
|
413 |
{
|
insilmaril@0
|
414 |
// To adjust the canvas to map, viewport size and position, we have to
|
insilmaril@0
|
415 |
// do some coordinate magic...
|
insilmaril@0
|
416 |
//
|
insilmaril@0
|
417 |
// Get rectangle of (scroll-)view.
|
insilmaril@0
|
418 |
// We want to be in canvas coords, so
|
insilmaril@0
|
419 |
// we map. Important if view is zoomed...
|
insilmaril@0
|
420 |
QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
|
insilmaril@0
|
421 |
visibleWidth(), visibleHeight()) );
|
insilmaril@0
|
422 |
|
insilmaril@0
|
423 |
// Now we need the bounding box of view AND map to calc the correct canvas size.
|
insilmaril@0
|
424 |
// Why? Because if the map itself is moved out of view, the view has to be enlarged
|
insilmaril@0
|
425 |
// to avoid jumping aroung...
|
insilmaril@0
|
426 |
QRect map=mapCenter->getTotalBBox();
|
insilmaril@0
|
427 |
|
insilmaril@0
|
428 |
// right edge - left edge
|
insilmaril@0
|
429 |
int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
|
insilmaril@0
|
430 |
int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
|
insilmaril@0
|
431 |
|
insilmaril@0
|
432 |
|
insilmaril@0
|
433 |
if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
|
insilmaril@0
|
434 |
!mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
|
insilmaril@0
|
435 |
)
|
insilmaril@0
|
436 |
{
|
insilmaril@0
|
437 |
// move the map on canvas (in order to not move it on screen) this is neccessary
|
insilmaril@0
|
438 |
// a) if topleft corner of canvas is left or above topleft corner of view and also left of
|
insilmaril@0
|
439 |
// above topleft corner of map. E.g. if map is completly inside view, but it would be possible
|
insilmaril@0
|
440 |
// to scroll to an empty area of canvas to the left.
|
insilmaril@0
|
441 |
// b) if topleft corner of map left of or above topleft of canvas
|
insilmaril@0
|
442 |
int dx=0;
|
insilmaril@0
|
443 |
int dy=0;
|
insilmaril@0
|
444 |
|
insilmaril@0
|
445 |
if (cw > mapCanvas->width() )
|
insilmaril@0
|
446 |
{
|
insilmaril@0
|
447 |
if (map.x()<0) dx=-map.x();
|
insilmaril@0
|
448 |
}
|
insilmaril@0
|
449 |
if (cw < mapCanvas->width() )
|
insilmaril@0
|
450 |
dx=-min (view.x(),map.x());
|
insilmaril@0
|
451 |
if (ch > mapCanvas->height() )
|
insilmaril@0
|
452 |
{
|
insilmaril@0
|
453 |
if (map.y()<0) dy=-map.y();
|
insilmaril@0
|
454 |
}
|
insilmaril@0
|
455 |
if (ch < mapCanvas->height() )
|
insilmaril@0
|
456 |
{
|
insilmaril@0
|
457 |
dy=-min (view.y(),map.y());
|
insilmaril@0
|
458 |
}
|
insilmaril@0
|
459 |
// We really have to resize now. Let's go...
|
insilmaril@0
|
460 |
mapCanvas->resize (cw,ch);
|
insilmaril@0
|
461 |
if ( (dx!=0) || (dy!=0) )
|
insilmaril@0
|
462 |
{
|
insilmaril@0
|
463 |
mapCenter->moveAllBy(dx,dy);
|
insilmaril@0
|
464 |
mapCenter->reposition();
|
insilmaril@0
|
465 |
|
insilmaril@0
|
466 |
// scroll the view (in order to not move map on screen)
|
insilmaril@0
|
467 |
scrollBy (dx,dy);
|
insilmaril@0
|
468 |
}
|
insilmaril@0
|
469 |
}
|
insilmaril@0
|
470 |
}
|
insilmaril@0
|
471 |
|
insilmaril@139
|
472 |
bool MapEditor::isRepositionBlocked()
|
insilmaril@0
|
473 |
{
|
insilmaril@139
|
474 |
return blockReposition;
|
insilmaril@0
|
475 |
}
|
insilmaril@0
|
476 |
|
insilmaril@0
|
477 |
void MapEditor::makeTmpDirs()
|
insilmaril@0
|
478 |
{
|
insilmaril@0
|
479 |
// Create unique temporary directories
|
insilmaril@0
|
480 |
char tmpdir[]="/tmp/vym-XXXXXX";
|
insilmaril@0
|
481 |
bakMapDir=mkdtemp(tmpdir);
|
insilmaril@0
|
482 |
makeSubDirs(bakMapDir);
|
insilmaril@106
|
483 |
// FIXME set permissions and maybe use QT method for portability
|
insilmaril@0
|
484 |
}
|
insilmaril@0
|
485 |
|
insilmaril@0
|
486 |
void MapEditor::delTmpDirs()
|
insilmaril@0
|
487 |
{
|
insilmaril@0
|
488 |
//FIXME delete tmp directory, better use QT methods here:
|
insilmaril@0
|
489 |
system ( "rm -rf "+ bakMapDir );
|
insilmaril@0
|
490 |
}
|
insilmaril@0
|
491 |
|
insilmaril@0
|
492 |
|
insilmaril@0
|
493 |
void MapEditor::makeSubDirs(const QString &s)
|
insilmaril@0
|
494 |
{
|
insilmaril@0
|
495 |
QDir d(s);
|
insilmaril@0
|
496 |
d.mkdir ("images");
|
insilmaril@0
|
497 |
d.mkdir ("flags");
|
insilmaril@0
|
498 |
}
|
insilmaril@0
|
499 |
|
insilmaril@0
|
500 |
|
insilmaril@106
|
501 |
QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
|
insilmaril@0
|
502 |
{
|
insilmaril@0
|
503 |
// tmpdir temporary directory to which data will be writte
|
insilmaril@0
|
504 |
// prefix mapname, which will be appended to images etc.
|
insilmaril@0
|
505 |
// writeflags Only write flags for "real" save of map, not undo
|
insilmaril@0
|
506 |
// offset offset of bbox of whole map in canvas.
|
insilmaril@0
|
507 |
// Needed for XML export
|
insilmaril@0
|
508 |
// completeMap if false, only vympart will be written, without
|
insilmaril@0
|
509 |
// mapcenter
|
insilmaril@0
|
510 |
|
insilmaril@0
|
511 |
// Save Header
|
insilmaril@0
|
512 |
QString ls;
|
insilmaril@0
|
513 |
switch (linkstyle)
|
insilmaril@0
|
514 |
{
|
insilmaril@0
|
515 |
case StyleLine:
|
insilmaril@0
|
516 |
ls="StyleLine";
|
insilmaril@0
|
517 |
break;
|
insilmaril@0
|
518 |
case StyleParabel:
|
insilmaril@0
|
519 |
ls="StyleParabel";
|
insilmaril@0
|
520 |
break;
|
insilmaril@0
|
521 |
case StylePolyLine:
|
insilmaril@0
|
522 |
ls="StylePolyLine";
|
insilmaril@0
|
523 |
break;
|
insilmaril@0
|
524 |
default:
|
insilmaril@0
|
525 |
ls="StylePolyParabel";
|
insilmaril@0
|
526 |
break;
|
insilmaril@0
|
527 |
}
|
insilmaril@0
|
528 |
|
insilmaril@0
|
529 |
QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
|
insilmaril@0
|
530 |
QString colhint="";
|
insilmaril@0
|
531 |
if (linkcolorhint==HeadingColor)
|
insilmaril@0
|
532 |
colhint=attribut("linkColorHint","HeadingColor");
|
insilmaril@0
|
533 |
|
insilmaril@0
|
534 |
QString mapAttr=attribut("version",__VYM_VERSION__);
|
insilmaril@106
|
535 |
if (!saveSelection)
|
insilmaril@0
|
536 |
mapAttr+= attribut("author",mapCenter->getAuthor()) +
|
insilmaril@0
|
537 |
attribut("comment",mapCenter->getComment()) +
|
insilmaril@0
|
538 |
attribut("date",mapCenter->getDate()) +
|
insilmaril@0
|
539 |
attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
|
insilmaril@0
|
540 |
attribut("linkStyle", ls ) +
|
insilmaril@97
|
541 |
attribut("linkColor", defLinkColor.name() ) +
|
insilmaril@102
|
542 |
attribut("defXLinkColor", defXLinkColor.name() ) +
|
insilmaril@102
|
543 |
attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
|
insilmaril@0
|
544 |
colhint;
|
insilmaril@0
|
545 |
s+=beginElement("vymmap",mapAttr);
|
insilmaril@0
|
546 |
incIndent();
|
insilmaril@0
|
547 |
|
insilmaril@0
|
548 |
// Find the used flags while traversing the tree
|
insilmaril@0
|
549 |
standardFlagsDefault->resetUsedCounter();
|
insilmaril@0
|
550 |
|
insilmaril@0
|
551 |
// Build xml recursivly
|
insilmaril@106
|
552 |
if (!saveSelection)
|
insilmaril@0
|
553 |
s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
|
insilmaril@0
|
554 |
else
|
insilmaril@0
|
555 |
{
|
insilmaril@106
|
556 |
if ( typeid(*saveSelection) == typeid(BranchObj) )
|
insilmaril@106
|
557 |
s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
|
insilmaril@94
|
558 |
else
|
insilmaril@94
|
559 |
if (selection && typeid(*selection)==typeid(BranchObj))
|
insilmaril@106
|
560 |
// This is used if selected branch is saved from mainwindow
|
insilmaril@94
|
561 |
s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
|
insilmaril@0
|
562 |
}
|
insilmaril@0
|
563 |
|
insilmaril@0
|
564 |
// Save local settings
|
insilmaril@0
|
565 |
s+=settings.getXMLData (destPath);
|
insilmaril@0
|
566 |
|
insilmaril@0
|
567 |
// Save selection
|
insilmaril@139
|
568 |
if (selection && !saveSelection )
|
insilmaril@0
|
569 |
s+=valueElement("select",selection->getSelectString());
|
insilmaril@0
|
570 |
|
insilmaril@0
|
571 |
decIndent();
|
insilmaril@0
|
572 |
s+=endElement("vymmap");
|
insilmaril@0
|
573 |
|
insilmaril@0
|
574 |
if (writeflags)
|
insilmaril@0
|
575 |
standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
|
insilmaril@0
|
576 |
return s;
|
insilmaril@0
|
577 |
}
|
insilmaril@0
|
578 |
|
insilmaril@0
|
579 |
void MapEditor::saveState()
|
insilmaril@0
|
580 |
{
|
insilmaril@139
|
581 |
saveState (CompleteMap,NULL,"","");
|
insilmaril@0
|
582 |
}
|
insilmaril@0
|
583 |
|
insilmaril@106
|
584 |
void MapEditor::saveState(LinkableMapObj *undoSel)
|
insilmaril@0
|
585 |
{
|
insilmaril@139
|
586 |
saveState (PartOfMap,undoSel,"","");
|
insilmaril@105
|
587 |
}
|
insilmaril@105
|
588 |
|
insilmaril@139
|
589 |
void MapEditor::saveState(const QString & uc, const QString &rc)
|
insilmaril@105
|
590 |
{
|
insilmaril@136
|
591 |
LinkableMapObj *undoSel;
|
insilmaril@136
|
592 |
if (selection)
|
insilmaril@136
|
593 |
undoSel=selection;
|
insilmaril@136
|
594 |
else
|
insilmaril@136
|
595 |
undoSel=NULL;
|
insilmaril@139
|
596 |
saveState (UndoCommand,undoSel,uc,rc);
|
insilmaril@106
|
597 |
}
|
insilmaril@106
|
598 |
|
insilmaril@139
|
599 |
void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, const QString &redoCom)
|
insilmaril@106
|
600 |
{
|
insilmaril@139
|
601 |
if (blockSaveState) return;
|
insilmaril@139
|
602 |
|
insilmaril@131
|
603 |
setChanged();
|
insilmaril@136
|
604 |
|
insilmaril@139
|
605 |
// Save current selection
|
insilmaril@139
|
606 |
redoCommand=redoCom;
|
insilmaril@139
|
607 |
if (selection)
|
insilmaril@139
|
608 |
redoSelection=selection->getSelectString();
|
insilmaril@139
|
609 |
else
|
insilmaril@139
|
610 |
redoSelection="";
|
insilmaril@139
|
611 |
|
insilmaril@139
|
612 |
// Save the object, which should be undone
|
insilmaril@136
|
613 |
if (undoSel)
|
insilmaril@136
|
614 |
undoSelection=undoSel->getSelectString();
|
insilmaril@136
|
615 |
else
|
insilmaril@136
|
616 |
undoSelection="";
|
insilmaril@136
|
617 |
|
insilmaril@136
|
618 |
// Save depending on how much needs to be saved
|
insilmaril@106
|
619 |
if (savemode==UndoCommand)
|
insilmaril@0
|
620 |
{
|
insilmaril@105
|
621 |
undoCommand=undoCom;
|
insilmaril@106
|
622 |
backupXML="";
|
insilmaril@106
|
623 |
}
|
insilmaril@106
|
624 |
else if (savemode==PartOfMap && undoSel)
|
insilmaril@0
|
625 |
{
|
insilmaril@136
|
626 |
undoCommand="undoPart (\""+undoSelection+"\")";
|
insilmaril@106
|
627 |
backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
|
insilmaril@106
|
628 |
} else
|
insilmaril@106
|
629 |
{
|
insilmaril@106
|
630 |
undoCommand="undoMap ()";
|
insilmaril@106
|
631 |
backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
|
insilmaril@139
|
632 |
undoSelection="";
|
insilmaril@106
|
633 |
}
|
insilmaril@106
|
634 |
/* FIXME testing
|
insilmaril@106
|
635 |
cout << "ME::saveState()\n";
|
insilmaril@106
|
636 |
cout << " undoCom="<<undoCommand<<endl;
|
insilmaril@139
|
637 |
cout << " undoSel="<<undoSelection<<endl;
|
insilmaril@139
|
638 |
cout << " ---------------------------"<<endl;
|
insilmaril@139
|
639 |
cout << " redoCom="<<redoCommand<<endl;
|
insilmaril@139
|
640 |
cout << " redoSel="<<redoSelection<<endl<<endl;
|
insilmaril@106
|
641 |
*/
|
insilmaril@106
|
642 |
}
|
insilmaril@106
|
643 |
|
insilmaril@129
|
644 |
void MapEditor::parseAtom(const QString &atom)
|
insilmaril@106
|
645 |
{
|
insilmaril@106
|
646 |
API api;
|
insilmaril@129
|
647 |
QString s;
|
insilmaril@129
|
648 |
int x,y;
|
insilmaril@129
|
649 |
bool ok;
|
insilmaril@129
|
650 |
|
insilmaril@129
|
651 |
// Split string s into command and parameters
|
insilmaril@129
|
652 |
api.parseCommand (atom);
|
insilmaril@129
|
653 |
QString com=api.command();
|
insilmaril@129
|
654 |
|
insilmaril@106
|
655 |
// External commands
|
insilmaril@129
|
656 |
if (com==QString("moveBranchUp"))
|
insilmaril@106
|
657 |
moveBranchUp();
|
insilmaril@129
|
658 |
else if (com=="moveBranchDown")
|
insilmaril@106
|
659 |
moveBranchDown();
|
insilmaril@129
|
660 |
else if (com=="move")
|
insilmaril@129
|
661 |
{
|
insilmaril@139
|
662 |
if (api.checkParamCount(2) && selection )
|
insilmaril@129
|
663 |
{
|
insilmaril@129
|
664 |
x=api.parInt (ok,0);
|
insilmaril@129
|
665 |
if (ok)
|
insilmaril@129
|
666 |
{
|
insilmaril@129
|
667 |
y=api.parInt (ok,1);
|
insilmaril@130
|
668 |
if (ok) move (x,y);
|
insilmaril@129
|
669 |
}
|
insilmaril@129
|
670 |
}
|
insilmaril@129
|
671 |
}
|
insilmaril@129
|
672 |
else if (com=="linkBranchToPos")
|
insilmaril@129
|
673 |
{
|
insilmaril@129
|
674 |
if (selection && typeid(*selection) == typeid(BranchObj) )
|
insilmaril@129
|
675 |
{
|
insilmaril@129
|
676 |
if (api.checkParamCount(4))
|
insilmaril@129
|
677 |
{
|
insilmaril@129
|
678 |
s=api.parString(ok,0);
|
insilmaril@129
|
679 |
LinkableMapObj *dst=mapCenter->findObjBySelect (s);
|
insilmaril@129
|
680 |
if (dst)
|
insilmaril@129
|
681 |
{
|
insilmaril@129
|
682 |
if (typeid(*dst) == typeid(BranchObj) )
|
insilmaril@139
|
683 |
{
|
insilmaril@139
|
684 |
// Get number in parent
|
insilmaril@139
|
685 |
x=api.parInt (ok,1);
|
insilmaril@139
|
686 |
if (ok)
|
insilmaril@139
|
687 |
((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),x);
|
insilmaril@139
|
688 |
} else if (typeid(*dst) == typeid(MapCenterObj) )
|
insilmaril@129
|
689 |
{
|
insilmaril@129
|
690 |
((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
|
insilmaril@139
|
691 |
// Get coordinates of mainbranch
|
insilmaril@129
|
692 |
x=api.parInt (ok,2);
|
insilmaril@129
|
693 |
if (ok)
|
insilmaril@129
|
694 |
{
|
insilmaril@129
|
695 |
y=api.parInt (ok,3);
|
insilmaril@129
|
696 |
if (ok) ((BranchObj*)(selection))->move (x,y);
|
insilmaril@129
|
697 |
}
|
insilmaril@129
|
698 |
}
|
insilmaril@129
|
699 |
}
|
insilmaril@129
|
700 |
}
|
insilmaril@129
|
701 |
}
|
insilmaril@129
|
702 |
} else if (com=="setHeading")
|
insilmaril@129
|
703 |
{
|
insilmaril@129
|
704 |
if (api.checkParamCount(1))
|
insilmaril@129
|
705 |
{
|
insilmaril@129
|
706 |
s=api.parString (ok,0);
|
insilmaril@129
|
707 |
if (ok) setHeading (s);
|
insilmaril@129
|
708 |
}
|
insilmaril@129
|
709 |
}
|
insilmaril@106
|
710 |
// Internal commands, used for undo etc.
|
insilmaril@129
|
711 |
else if (com==QString("undoMap"))
|
insilmaril@139
|
712 |
{
|
insilmaril@139
|
713 |
if (api.checkParamCount(0))
|
insilmaril@139
|
714 |
undoXML("");
|
insilmaril@139
|
715 |
} else if (com==QString("undoPart"))
|
insilmaril@129
|
716 |
{
|
insilmaril@129
|
717 |
if (api.checkParamCount(1))
|
insilmaril@129
|
718 |
{
|
insilmaril@129
|
719 |
s=api.parString (ok,0);
|
insilmaril@129
|
720 |
undoXML(s);
|
insilmaril@129
|
721 |
}
|
insilmaril@129
|
722 |
} else if (com=="select")
|
insilmaril@129
|
723 |
if (api.checkParamCount(1))
|
insilmaril@129
|
724 |
{
|
insilmaril@129
|
725 |
s=api.parString(ok,0);
|
insilmaril@129
|
726 |
if (ok) select (s);
|
insilmaril@129
|
727 |
}
|
insilmaril@106
|
728 |
else
|
insilmaril@129
|
729 |
api.setError ("Unknown command in: "+atom);
|
insilmaril@129
|
730 |
|
insilmaril@129
|
731 |
// Any errors?
|
insilmaril@129
|
732 |
if (api.error())
|
insilmaril@106
|
733 |
{
|
insilmaril@106
|
734 |
cout << "MapEditor::parseAtom: Error!\n";
|
insilmaril@129
|
735 |
cout << " "<<api.errorDesc()<<endl;
|
insilmaril@0
|
736 |
}
|
insilmaril@0
|
737 |
}
|
insilmaril@0
|
738 |
|
insilmaril@106
|
739 |
|
insilmaril@0
|
740 |
void MapEditor::finishedLineEditNoSave()
|
insilmaril@0
|
741 |
{
|
insilmaril@0
|
742 |
// This is called by finishedLineEdit or any MapEditor method,
|
insilmaril@0
|
743 |
// which wants to assure, that lineedits finish, before e.g. a branch is
|
insilmaril@0
|
744 |
// deleted
|
insilmaril@0
|
745 |
|
insilmaril@0
|
746 |
// After calling LineEdit and using the clipboard, the
|
insilmaril@0
|
747 |
// focus is not any longer on the main widget, we
|
insilmaril@0
|
748 |
// have to restore it using parentWidget()->setFocus()
|
insilmaril@0
|
749 |
|
insilmaril@0
|
750 |
if (editingBO!=NULL)
|
insilmaril@0
|
751 |
{
|
insilmaril@0
|
752 |
editingBO->setHeading(lineedit->text() );
|
insilmaril@0
|
753 |
editingBO=NULL;
|
insilmaril@0
|
754 |
lineedit->releaseKeyboard();
|
insilmaril@0
|
755 |
lineedit->hide();
|
insilmaril@0
|
756 |
parentWidget()->setFocus();
|
insilmaril@0
|
757 |
mapCenter->reposition();
|
insilmaril@0
|
758 |
adjustCanvasSize();
|
insilmaril@0
|
759 |
ensureSelectionVisible();
|
insilmaril@0
|
760 |
}
|
insilmaril@0
|
761 |
}
|
insilmaril@0
|
762 |
|
insilmaril@0
|
763 |
|
insilmaril@0
|
764 |
bool MapEditor::isDefault()
|
insilmaril@0
|
765 |
{
|
insilmaril@0
|
766 |
return mapDefault;
|
insilmaril@0
|
767 |
}
|
insilmaril@0
|
768 |
|
insilmaril@0
|
769 |
bool MapEditor::isUnsaved()
|
insilmaril@0
|
770 |
{
|
insilmaril@0
|
771 |
return mapUnsaved;
|
insilmaril@0
|
772 |
}
|
insilmaril@0
|
773 |
|
insilmaril@0
|
774 |
bool MapEditor::hasChanged()
|
insilmaril@0
|
775 |
{
|
insilmaril@0
|
776 |
return mapChanged;
|
insilmaril@0
|
777 |
}
|
insilmaril@0
|
778 |
|
insilmaril@0
|
779 |
void MapEditor::setChanged()
|
insilmaril@0
|
780 |
{
|
insilmaril@0
|
781 |
mapChanged=true;
|
insilmaril@0
|
782 |
mapDefault=false;
|
insilmaril@0
|
783 |
mapUnsaved=true;
|
insilmaril@0
|
784 |
actionEditUndo->setEnabled (true);
|
insilmaril@0
|
785 |
actionFileSave->setEnabled (true);
|
insilmaril@0
|
786 |
findReset();
|
insilmaril@0
|
787 |
}
|
insilmaril@0
|
788 |
|
insilmaril@0
|
789 |
void MapEditor::closeMap()
|
insilmaril@0
|
790 |
{
|
insilmaril@0
|
791 |
// Finish open lineEdits
|
insilmaril@0
|
792 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
793 |
|
insilmaril@0
|
794 |
// Unselect before disabling the toolbar actions
|
insilmaril@0
|
795 |
if (selection) selection->unselect();
|
insilmaril@0
|
796 |
selection=NULL;
|
insilmaril@0
|
797 |
updateActions();
|
insilmaril@0
|
798 |
|
insilmaril@0
|
799 |
clear();
|
insilmaril@0
|
800 |
close();
|
insilmaril@0
|
801 |
}
|
insilmaril@0
|
802 |
|
insilmaril@0
|
803 |
void MapEditor::setFilePath(QString fname)
|
insilmaril@0
|
804 |
{
|
insilmaril@0
|
805 |
setFilePath (fname,fname);
|
insilmaril@0
|
806 |
}
|
insilmaril@0
|
807 |
|
insilmaril@0
|
808 |
void MapEditor::setFilePath(QString fname, QString destname)
|
insilmaril@0
|
809 |
{
|
insilmaril@106
|
810 |
if (fname.isEmpty())
|
insilmaril@106
|
811 |
{
|
insilmaril@106
|
812 |
filePath="";
|
insilmaril@106
|
813 |
fileName="";
|
insilmaril@106
|
814 |
destPath="";
|
insilmaril@106
|
815 |
} else
|
insilmaril@106
|
816 |
{
|
insilmaril@106
|
817 |
filePath=fname; // becomes absolute path
|
insilmaril@106
|
818 |
fileName=fname; // gets stripped of path
|
insilmaril@106
|
819 |
destPath=destname; // needed for vymlinks
|
insilmaril@106
|
820 |
|
insilmaril@106
|
821 |
// If fname is not an absolute path, complete it
|
insilmaril@106
|
822 |
filePath=QDir(fname).absPath();
|
insilmaril@106
|
823 |
fileDir=filePath.left (1+filePath.findRev ("/"));
|
insilmaril@106
|
824 |
|
insilmaril@106
|
825 |
// Set short name, too. Search from behind:
|
insilmaril@106
|
826 |
int i=fileName.findRev("/");
|
insilmaril@106
|
827 |
if (i>=0) fileName=fileName.remove (0,i+1);
|
insilmaril@106
|
828 |
|
insilmaril@106
|
829 |
// Forget the .vym (or .xml) for name of map
|
insilmaril@106
|
830 |
mapName=fileName.left(fileName.findRev(".",-1,true) );
|
insilmaril@106
|
831 |
}
|
insilmaril@0
|
832 |
}
|
insilmaril@0
|
833 |
|
insilmaril@0
|
834 |
QString MapEditor::getFilePath()
|
insilmaril@0
|
835 |
{
|
insilmaril@0
|
836 |
return filePath;
|
insilmaril@0
|
837 |
}
|
insilmaril@0
|
838 |
|
insilmaril@0
|
839 |
QString MapEditor::getFileName()
|
insilmaril@0
|
840 |
{
|
insilmaril@0
|
841 |
return fileName;
|
insilmaril@0
|
842 |
}
|
insilmaril@0
|
843 |
|
insilmaril@0
|
844 |
QString MapEditor::getMapName()
|
insilmaril@0
|
845 |
{
|
insilmaril@0
|
846 |
return mapName;
|
insilmaril@0
|
847 |
}
|
insilmaril@0
|
848 |
|
insilmaril@0
|
849 |
QString MapEditor::getDestPath()
|
insilmaril@0
|
850 |
{
|
insilmaril@0
|
851 |
return destPath;
|
insilmaril@0
|
852 |
}
|
insilmaril@0
|
853 |
|
insilmaril@0
|
854 |
int MapEditor::load (QString &fname, const LoadMode &lmode)
|
insilmaril@0
|
855 |
{
|
insilmaril@0
|
856 |
// Finish open lineEdits
|
insilmaril@0
|
857 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
858 |
|
insilmaril@0
|
859 |
int returnCode=0;
|
insilmaril@0
|
860 |
|
insilmaril@0
|
861 |
if (lmode==NewMap)
|
insilmaril@0
|
862 |
{
|
insilmaril@0
|
863 |
if (selection) selection->unselect();
|
insilmaril@0
|
864 |
selection=NULL;
|
insilmaril@0
|
865 |
mapCenter->clear();
|
insilmaril@0
|
866 |
mapCenter->setMapEditor(this);
|
insilmaril@0
|
867 |
// (map state is set later at end of load...)
|
insilmaril@0
|
868 |
} else
|
insilmaril@0
|
869 |
{
|
insilmaril@106
|
870 |
saveState(selection);
|
insilmaril@0
|
871 |
}
|
insilmaril@0
|
872 |
|
insilmaril@0
|
873 |
|
insilmaril@0
|
874 |
mapBuilderHandler handler;
|
insilmaril@0
|
875 |
QFile file( fname );
|
insilmaril@0
|
876 |
|
insilmaril@0
|
877 |
// I am paranoid: file should exist anyway
|
insilmaril@0
|
878 |
// according to check in mainwindow.
|
insilmaril@0
|
879 |
if (!file.exists() )
|
insilmaril@0
|
880 |
{
|
insilmaril@0
|
881 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@0
|
882 |
tr("Couldn't open map " +fname)+".");
|
insilmaril@0
|
883 |
returnCode=1;
|
insilmaril@0
|
884 |
} else
|
insilmaril@0
|
885 |
{
|
insilmaril@139
|
886 |
blockReposition=true;
|
insilmaril@0
|
887 |
QXmlInputSource source( file);
|
insilmaril@0
|
888 |
QXmlSimpleReader reader;
|
insilmaril@0
|
889 |
reader.setContentHandler( &handler );
|
insilmaril@0
|
890 |
reader.setErrorHandler( &handler );
|
insilmaril@0
|
891 |
handler.setMapEditor( this );
|
insilmaril@0
|
892 |
handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
|
insilmaril@0
|
893 |
handler.setLoadMode (lmode);
|
insilmaril@0
|
894 |
bool ok = reader.parse( source );
|
insilmaril@139
|
895 |
blockReposition=false;
|
insilmaril@0
|
896 |
file.close();
|
insilmaril@0
|
897 |
if ( ok )
|
insilmaril@0
|
898 |
{
|
insilmaril@0
|
899 |
mapCenter->reposition();
|
insilmaril@0
|
900 |
adjustCanvasSize();
|
insilmaril@0
|
901 |
if (lmode==NewMap)
|
insilmaril@0
|
902 |
{
|
insilmaril@0
|
903 |
mapDefault=false;
|
insilmaril@0
|
904 |
mapChanged=false;
|
insilmaril@0
|
905 |
mapUnsaved=false;
|
insilmaril@0
|
906 |
}
|
insilmaril@0
|
907 |
} else
|
insilmaril@0
|
908 |
{
|
insilmaril@0
|
909 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@0
|
910 |
tr( handler.errorProtocol() ) );
|
insilmaril@0
|
911 |
// returnCode=1;
|
insilmaril@0
|
912 |
// Still return "success": the map maybe at least
|
insilmaril@0
|
913 |
// partially read by the parser
|
insilmaril@0
|
914 |
}
|
insilmaril@0
|
915 |
}
|
insilmaril@0
|
916 |
updateActions();
|
insilmaril@0
|
917 |
return returnCode;
|
insilmaril@0
|
918 |
}
|
insilmaril@0
|
919 |
|
insilmaril@0
|
920 |
int MapEditor::save (const SaveMode &savemode)
|
insilmaril@0
|
921 |
{
|
insilmaril@0
|
922 |
// Finish open lineEdits
|
insilmaril@0
|
923 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
924 |
|
insilmaril@0
|
925 |
int returnCode=0;
|
insilmaril@0
|
926 |
|
insilmaril@106
|
927 |
// The SaveMode UndoCommand is not supported here
|
insilmaril@106
|
928 |
if (savemode==UndoCommand) return 1;
|
insilmaril@106
|
929 |
|
insilmaril@0
|
930 |
// Create mapName and fileDir
|
insilmaril@0
|
931 |
makeSubDirs (fileDir);
|
insilmaril@0
|
932 |
QString fname;
|
insilmaril@0
|
933 |
if (saveZipped())
|
insilmaril@0
|
934 |
// save as .xml
|
insilmaril@0
|
935 |
fname=mapName+".xml";
|
insilmaril@0
|
936 |
else
|
insilmaril@0
|
937 |
// use name given by user, even if he chooses .doc
|
insilmaril@0
|
938 |
fname=fileName;
|
insilmaril@0
|
939 |
|
insilmaril@0
|
940 |
|
insilmaril@0
|
941 |
// Check if fname is writeable
|
insilmaril@0
|
942 |
QFile file( fileDir+fname);
|
insilmaril@0
|
943 |
if (!file.open( IO_WriteOnly ) )
|
insilmaril@0
|
944 |
{
|
insilmaril@0
|
945 |
QMessageBox::critical( 0, tr( "Critical Save Error" ),
|
insilmaril@0
|
946 |
tr("Couldn't write to ") +fileDir+fname);
|
insilmaril@0
|
947 |
return 1;
|
insilmaril@0
|
948 |
}
|
insilmaril@0
|
949 |
file.close();
|
insilmaril@0
|
950 |
|
insilmaril@0
|
951 |
QString saveFile;
|
insilmaril@106
|
952 |
if (savemode==CompleteMap || selection==NULL)
|
insilmaril@106
|
953 |
saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
|
insilmaril@106
|
954 |
else
|
insilmaril@106
|
955 |
saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
|
insilmaril@0
|
956 |
|
insilmaril@0
|
957 |
file.setName ( fileDir + fname);
|
insilmaril@0
|
958 |
if ( !file.open( IO_WriteOnly ) )
|
insilmaril@0
|
959 |
{
|
insilmaril@0
|
960 |
// This should neverever happen
|
insilmaril@94
|
961 |
QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
|
insilmaril@0
|
962 |
return 1;
|
insilmaril@0
|
963 |
}
|
insilmaril@0
|
964 |
|
insilmaril@0
|
965 |
// Write it finally, and write in UTF8, no matter what
|
insilmaril@0
|
966 |
QTextStream ts( &file );
|
insilmaril@0
|
967 |
ts.setEncoding (QTextStream::UnicodeUTF8);
|
insilmaril@0
|
968 |
ts << saveFile;
|
insilmaril@0
|
969 |
file.close();
|
insilmaril@0
|
970 |
|
insilmaril@0
|
971 |
if (returnCode==0)
|
insilmaril@0
|
972 |
{
|
insilmaril@0
|
973 |
mapChanged=false;
|
insilmaril@0
|
974 |
mapUnsaved=false;
|
insilmaril@0
|
975 |
actionFileSave->setEnabled(false);
|
insilmaril@0
|
976 |
}
|
insilmaril@0
|
977 |
|
insilmaril@0
|
978 |
return returnCode;
|
insilmaril@0
|
979 |
}
|
insilmaril@0
|
980 |
|
insilmaril@0
|
981 |
void MapEditor::setZipped (bool z)
|
insilmaril@0
|
982 |
{
|
insilmaril@0
|
983 |
zipped=z;
|
insilmaril@0
|
984 |
}
|
insilmaril@0
|
985 |
|
insilmaril@0
|
986 |
bool MapEditor::saveZipped ()
|
insilmaril@0
|
987 |
{
|
insilmaril@0
|
988 |
return zipped;
|
insilmaril@0
|
989 |
}
|
insilmaril@0
|
990 |
|
insilmaril@0
|
991 |
void MapEditor::print()
|
insilmaril@0
|
992 |
{
|
insilmaril@0
|
993 |
// Finish open lineEdits
|
insilmaril@0
|
994 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
995 |
|
insilmaril@0
|
996 |
if ( !printer )
|
insilmaril@0
|
997 |
{
|
insilmaril@0
|
998 |
printer = new QPrinter;
|
insilmaril@0
|
999 |
printer->setColorMode (QPrinter::Color);
|
insilmaril@119
|
1000 |
printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
|
insilmaril@0
|
1001 |
}
|
insilmaril@0
|
1002 |
|
insilmaril@0
|
1003 |
QRect totalBBox=mapCenter->getTotalBBox();
|
insilmaril@0
|
1004 |
|
insilmaril@0
|
1005 |
// Try to set orientation automagically
|
insilmaril@0
|
1006 |
// Note: Interpretation of generated postscript is amibiguous, if
|
insilmaril@0
|
1007 |
// there are problems with landscape mode, see
|
insilmaril@0
|
1008 |
// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
|
insilmaril@0
|
1009 |
|
insilmaril@0
|
1010 |
if (totalBBox.width()>totalBBox.height())
|
insilmaril@0
|
1011 |
// recommend landscape
|
insilmaril@0
|
1012 |
printer->setOrientation (QPrinter::Landscape);
|
insilmaril@0
|
1013 |
else
|
insilmaril@0
|
1014 |
// recommend portrait
|
insilmaril@0
|
1015 |
printer->setOrientation (QPrinter::Portrait);
|
insilmaril@0
|
1016 |
|
insilmaril@0
|
1017 |
if ( printer->setup(this) )
|
insilmaril@0
|
1018 |
// returns false, if printing is canceled
|
insilmaril@0
|
1019 |
{
|
insilmaril@0
|
1020 |
QPainter pp(printer);
|
insilmaril@0
|
1021 |
|
insilmaril@0
|
1022 |
// Don't print the visualisation of selection
|
insilmaril@0
|
1023 |
LinkableMapObj *oldselection=NULL;
|
insilmaril@0
|
1024 |
if (selection)
|
insilmaril@0
|
1025 |
{
|
insilmaril@0
|
1026 |
oldselection=selection;
|
insilmaril@0
|
1027 |
selection->unselect();
|
insilmaril@0
|
1028 |
}
|
insilmaril@0
|
1029 |
|
insilmaril@0
|
1030 |
// Handle sizes of map and paper:
|
insilmaril@0
|
1031 |
//
|
insilmaril@0
|
1032 |
// setWindow defines which part of the canvas will be transformed
|
insilmaril@0
|
1033 |
// setViewport defines area on paper in device coordinates (dpi)
|
insilmaril@0
|
1034 |
// e.g. (0,50,700,700) is upper part on A4
|
insilmaril@0
|
1035 |
// see also /usr/lib/qt3/doc/html/coordsys.html
|
insilmaril@0
|
1036 |
|
insilmaril@0
|
1037 |
QPaintDeviceMetrics metrics (printer);
|
insilmaril@0
|
1038 |
|
insilmaril@0
|
1039 |
double paperAspect = (double)metrics.width() / (double)metrics.height();
|
insilmaril@0
|
1040 |
double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
|
insilmaril@0
|
1041 |
|
insilmaril@102
|
1042 |
QRect mapRect=totalBBox;
|
insilmaril@0
|
1043 |
QCanvasRectangle *frame=NULL;
|
insilmaril@0
|
1044 |
QCanvasText *footerFN=NULL;
|
insilmaril@0
|
1045 |
QCanvasText *footerDate=NULL;
|
insilmaril@0
|
1046 |
if (printFrame || printFooter)
|
insilmaril@0
|
1047 |
{
|
insilmaril@0
|
1048 |
|
insilmaril@0
|
1049 |
if (printFrame)
|
insilmaril@0
|
1050 |
{
|
insilmaril@0
|
1051 |
// Print frame around map
|
insilmaril@102
|
1052 |
mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
|
insilmaril@102
|
1053 |
totalBBox.width()+20, totalBBox.height()+20);
|
insilmaril@0
|
1054 |
frame=new QCanvasRectangle (mapRect,mapCanvas);
|
insilmaril@0
|
1055 |
frame->setBrush (QColor(white));
|
insilmaril@0
|
1056 |
frame->setPen (QColor(black));
|
insilmaril@0
|
1057 |
frame->setZ(0);
|
insilmaril@0
|
1058 |
frame->show();
|
insilmaril@0
|
1059 |
}
|
insilmaril@102
|
1060 |
/* FIXME testing
|
insilmaril@102
|
1061 |
QCanvasLine *l=new QCanvasLine (mapCanvas);
|
insilmaril@102
|
1062 |
l->setPoints (0,0,mapRect.width(),mapRect.height());
|
insilmaril@102
|
1063 |
l->setPen (QPen(QColor(black), 1));
|
insilmaril@102
|
1064 |
l->setZ (200);
|
insilmaril@102
|
1065 |
l->show();
|
insilmaril@131
|
1066 |
*/
|
insilmaril@102
|
1067 |
|
insilmaril@0
|
1068 |
if (printFooter)
|
insilmaril@0
|
1069 |
{
|
insilmaril@0
|
1070 |
// Print footer below map
|
insilmaril@0
|
1071 |
QFont font;
|
insilmaril@0
|
1072 |
font.setPointSize(10);
|
insilmaril@0
|
1073 |
footerFN=new QCanvasText (mapCanvas);
|
insilmaril@0
|
1074 |
footerFN->setText ("VYM - " + fileName);
|
insilmaril@0
|
1075 |
footerFN->setFont(font);
|
insilmaril@0
|
1076 |
footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
|
insilmaril@0
|
1077 |
footerFN->setZ(Z_TEXT);
|
insilmaril@0
|
1078 |
footerFN->show();
|
insilmaril@0
|
1079 |
footerDate=new QCanvasText (mapCanvas);
|
insilmaril@0
|
1080 |
footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
|
insilmaril@0
|
1081 |
footerDate->setFont(font);
|
insilmaril@0
|
1082 |
footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
|
insilmaril@0
|
1083 |
footerDate->setZ(Z_TEXT);
|
insilmaril@0
|
1084 |
footerDate->show();
|
insilmaril@0
|
1085 |
}
|
insilmaril@102
|
1086 |
pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
|
insilmaril@0
|
1087 |
} else
|
insilmaril@0
|
1088 |
{
|
insilmaril@0
|
1089 |
pp.setWindow (mapRect);
|
insilmaril@0
|
1090 |
}
|
insilmaril@0
|
1091 |
|
insilmaril@0
|
1092 |
if (mapAspect>=paperAspect)
|
insilmaril@0
|
1093 |
{
|
insilmaril@0
|
1094 |
// Fit horizontally to paper width
|
insilmaril@0
|
1095 |
pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
|
insilmaril@0
|
1096 |
} else
|
insilmaril@0
|
1097 |
{
|
insilmaril@0
|
1098 |
// Fit vertically to paper height
|
insilmaril@0
|
1099 |
pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
|
insilmaril@0
|
1100 |
}
|
insilmaril@0
|
1101 |
|
insilmaril@0
|
1102 |
mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
|
insilmaril@0
|
1103 |
|
insilmaril@0
|
1104 |
// Delete Frame and footer
|
insilmaril@0
|
1105 |
if (footerFN)
|
insilmaril@0
|
1106 |
{
|
insilmaril@0
|
1107 |
delete (footerFN);
|
insilmaril@0
|
1108 |
delete (footerDate);
|
insilmaril@0
|
1109 |
}
|
insilmaril@0
|
1110 |
if (frame) delete (frame);
|
insilmaril@0
|
1111 |
|
insilmaril@0
|
1112 |
// Restore selection
|
insilmaril@0
|
1113 |
if (oldselection)
|
insilmaril@0
|
1114 |
{
|
insilmaril@0
|
1115 |
selection=oldselection;
|
insilmaril@0
|
1116 |
selection->select();
|
insilmaril@0
|
1117 |
}
|
insilmaril@119
|
1118 |
|
insilmaril@119
|
1119 |
// Save settings in vymrc
|
insilmaril@119
|
1120 |
settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
|
insilmaril@0
|
1121 |
}
|
insilmaril@0
|
1122 |
}
|
insilmaril@0
|
1123 |
|
insilmaril@0
|
1124 |
QPixmap MapEditor::getPixmap()
|
insilmaril@0
|
1125 |
{
|
insilmaril@0
|
1126 |
QRect mapRect=mapCenter->getTotalBBox();
|
insilmaril@0
|
1127 |
QPixmap pix (mapRect.size());
|
insilmaril@0
|
1128 |
QPainter pp (&pix);
|
insilmaril@0
|
1129 |
|
insilmaril@0
|
1130 |
// Don't print the visualisation of selection
|
insilmaril@0
|
1131 |
LinkableMapObj *oldselection=NULL;
|
insilmaril@0
|
1132 |
if (selection)
|
insilmaril@0
|
1133 |
{
|
insilmaril@0
|
1134 |
oldselection=selection;
|
insilmaril@0
|
1135 |
selection->unselect();
|
insilmaril@0
|
1136 |
}
|
insilmaril@0
|
1137 |
|
insilmaril@0
|
1138 |
pp.setWindow (mapRect);
|
insilmaril@0
|
1139 |
|
insilmaril@0
|
1140 |
mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
|
insilmaril@0
|
1141 |
|
insilmaril@0
|
1142 |
|
insilmaril@0
|
1143 |
// Restore selection
|
insilmaril@0
|
1144 |
if (oldselection)
|
insilmaril@0
|
1145 |
{
|
insilmaril@0
|
1146 |
selection=oldselection;
|
insilmaril@0
|
1147 |
selection->select();
|
insilmaril@0
|
1148 |
}
|
insilmaril@0
|
1149 |
|
insilmaril@0
|
1150 |
return pix;
|
insilmaril@0
|
1151 |
}
|
insilmaril@0
|
1152 |
|
insilmaril@0
|
1153 |
void MapEditor::exportImage(QString fn)
|
insilmaril@0
|
1154 |
{
|
insilmaril@0
|
1155 |
// Finish open lineEdits
|
insilmaril@0
|
1156 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1157 |
|
insilmaril@0
|
1158 |
QPixmap pix (getPixmap());
|
insilmaril@0
|
1159 |
pix.save(fn, "PNG");
|
insilmaril@0
|
1160 |
}
|
insilmaril@0
|
1161 |
|
insilmaril@0
|
1162 |
void MapEditor::exportImage(QString fn, int item)
|
insilmaril@0
|
1163 |
{
|
insilmaril@0
|
1164 |
// Finish open lineEdits
|
insilmaril@0
|
1165 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1166 |
|
insilmaril@0
|
1167 |
QPixmap pix (getPixmap());
|
insilmaril@0
|
1168 |
pix.save(fn, exportImageFormatMenu->text(item) );
|
insilmaril@0
|
1169 |
}
|
insilmaril@0
|
1170 |
|
insilmaril@0
|
1171 |
void MapEditor::exportASCII()
|
insilmaril@0
|
1172 |
{
|
insilmaril@0
|
1173 |
// FIXME still experimental
|
insilmaril@131
|
1174 |
Export ex;
|
insilmaril@131
|
1175 |
ex.setMapCenter(mapCenter);
|
insilmaril@131
|
1176 |
|
insilmaril@0
|
1177 |
QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
|
insilmaril@0
|
1178 |
fd->addFilter ("TXT (*.txt)");
|
insilmaril@0
|
1179 |
fd->setCaption("VYM - Export (ASCII) (still experimental)");
|
insilmaril@0
|
1180 |
fd->setMode( QFileDialog::AnyFile );
|
insilmaril@0
|
1181 |
fd->show();
|
insilmaril@0
|
1182 |
|
insilmaril@0
|
1183 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
1184 |
{
|
insilmaril@0
|
1185 |
if (QFile (fd->selectedFile()).exists() )
|
insilmaril@0
|
1186 |
{
|
insilmaril@0
|
1187 |
QMessageBox mb( "VYM",
|
insilmaril@0
|
1188 |
tr("The file ") + fd->selectedFile() +
|
insilmaril@0
|
1189 |
tr(" exists already. Do you want to overwrite it?"),
|
insilmaril@0
|
1190 |
QMessageBox::Warning,
|
insilmaril@0
|
1191 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@0
|
1192 |
QMessageBox::Cancel | QMessageBox::Escape,
|
insilmaril@0
|
1193 |
QMessageBox::NoButton );
|
insilmaril@0
|
1194 |
|
insilmaril@0
|
1195 |
mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
|
insilmaril@0
|
1196 |
mb.setButtonText( QMessageBox::No, tr("Cancel"));
|
insilmaril@0
|
1197 |
Export ex;
|
insilmaril@0
|
1198 |
switch( mb.exec() )
|
insilmaril@0
|
1199 |
{
|
insilmaril@0
|
1200 |
case QMessageBox::Yes:
|
insilmaril@0
|
1201 |
// save
|
insilmaril@0
|
1202 |
break;;
|
insilmaril@0
|
1203 |
case QMessageBox::Cancel:
|
insilmaril@131
|
1204 |
// return, do nothing
|
insilmaril@0
|
1205 |
return;
|
insilmaril@0
|
1206 |
break;
|
insilmaril@0
|
1207 |
}
|
insilmaril@0
|
1208 |
}
|
insilmaril@0
|
1209 |
ex.setPath (fd->selectedFile() );
|
insilmaril@0
|
1210 |
ex.exportMap();
|
insilmaril@0
|
1211 |
}
|
insilmaril@0
|
1212 |
}
|
insilmaril@0
|
1213 |
|
insilmaril@0
|
1214 |
|
insilmaril@0
|
1215 |
void MapEditor::exportXML(const QString &dir)
|
insilmaril@0
|
1216 |
{
|
insilmaril@0
|
1217 |
// Create subdirectories
|
insilmaril@0
|
1218 |
makeSubDirs (dir);
|
insilmaril@0
|
1219 |
|
insilmaril@0
|
1220 |
// write to directory
|
insilmaril@106
|
1221 |
QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
|
insilmaril@0
|
1222 |
QFile file;
|
insilmaril@0
|
1223 |
|
insilmaril@0
|
1224 |
file.setName ( dir + "/"+mapName+".xml");
|
insilmaril@0
|
1225 |
if ( !file.open( IO_WriteOnly ) )
|
insilmaril@0
|
1226 |
{
|
insilmaril@0
|
1227 |
// This should neverever happen
|
insilmaril@0
|
1228 |
QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
|
insilmaril@0
|
1229 |
return;
|
insilmaril@0
|
1230 |
}
|
insilmaril@0
|
1231 |
|
insilmaril@0
|
1232 |
// Write it finally, and write in UTF8, no matter what
|
insilmaril@0
|
1233 |
QTextStream ts( &file );
|
insilmaril@0
|
1234 |
ts.setEncoding (QTextStream::UnicodeUTF8);
|
insilmaril@0
|
1235 |
ts << saveFile;
|
insilmaril@0
|
1236 |
file.close();
|
insilmaril@0
|
1237 |
|
insilmaril@0
|
1238 |
// Now write image, too
|
insilmaril@0
|
1239 |
exportImage (dir+"/images/"+mapName+".png");
|
insilmaril@0
|
1240 |
}
|
insilmaril@0
|
1241 |
|
insilmaril@0
|
1242 |
void MapEditor::clear()
|
insilmaril@0
|
1243 |
{
|
insilmaril@0
|
1244 |
if (selection)
|
insilmaril@0
|
1245 |
{
|
insilmaril@0
|
1246 |
selection->unselect();
|
insilmaril@0
|
1247 |
selection=NULL;
|
insilmaril@0
|
1248 |
}
|
insilmaril@0
|
1249 |
|
insilmaril@0
|
1250 |
mapCenter->clear();
|
insilmaril@0
|
1251 |
}
|
insilmaril@0
|
1252 |
|
insilmaril@0
|
1253 |
void MapEditor::copy()
|
insilmaril@0
|
1254 |
{
|
insilmaril@0
|
1255 |
// Finish open lineEdits
|
insilmaril@0
|
1256 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1257 |
|
insilmaril@0
|
1258 |
if (selection)
|
insilmaril@0
|
1259 |
{
|
insilmaril@0
|
1260 |
if (typeid(*selection) == typeid(BranchObj) )
|
insilmaril@0
|
1261 |
{
|
insilmaril@0
|
1262 |
BranchObj* to;
|
insilmaril@0
|
1263 |
BranchObj* from;
|
insilmaril@0
|
1264 |
clipboardME->clear();
|
insilmaril@0
|
1265 |
clipboardME->getMapCenter()->addBranch();
|
insilmaril@0
|
1266 |
to=clipboardME->getMapCenter()->getLastBranch();
|
insilmaril@0
|
1267 |
if (to)
|
insilmaril@0
|
1268 |
{
|
insilmaril@0
|
1269 |
from=(BranchObj*)(selection);
|
insilmaril@0
|
1270 |
to->copy(from);
|
insilmaril@0
|
1271 |
|
insilmaril@0
|
1272 |
// keep position relative to parent
|
insilmaril@0
|
1273 |
to->move2RelPos ( from->getRelPos());
|
insilmaril@0
|
1274 |
|
insilmaril@0
|
1275 |
// select data in clipboard
|
insilmaril@0
|
1276 |
clipboardME->select ("bo:0");
|
insilmaril@0
|
1277 |
|
insilmaril@0
|
1278 |
// repositioning makes testing nicer,
|
insilmaril@0
|
1279 |
// but is not needed usually:
|
insilmaril@0
|
1280 |
if (clipboardME->isVisible())
|
insilmaril@0
|
1281 |
{
|
insilmaril@0
|
1282 |
clipboardME->getMapCenter()->reposition();
|
insilmaril@0
|
1283 |
}
|
insilmaril@0
|
1284 |
else
|
insilmaril@0
|
1285 |
clipboardME->hide();
|
insilmaril@0
|
1286 |
}
|
insilmaril@0
|
1287 |
}
|
insilmaril@0
|
1288 |
if (typeid(*selection) == typeid(FloatImageObj) )
|
insilmaril@0
|
1289 |
{
|
insilmaril@0
|
1290 |
FloatImageObj* to;
|
insilmaril@0
|
1291 |
FloatImageObj* from;
|
insilmaril@0
|
1292 |
clipboardME->clear();
|
insilmaril@0
|
1293 |
clipboardME->getMapCenter()->addFloatImage();
|
insilmaril@0
|
1294 |
to=clipboardME->getMapCenter()->getLastFloatImage();
|
insilmaril@0
|
1295 |
if (to)
|
insilmaril@0
|
1296 |
{
|
insilmaril@0
|
1297 |
from=(FloatImageObj*)(selection);
|
insilmaril@0
|
1298 |
to->copy(from);
|
insilmaril@0
|
1299 |
|
insilmaril@0
|
1300 |
// select data in clipboard
|
insilmaril@0
|
1301 |
clipboardME->select ("fi:0");
|
insilmaril@0
|
1302 |
|
insilmaril@0
|
1303 |
// repositioning makes testing nicer,
|
insilmaril@0
|
1304 |
// but is not needed usually:
|
insilmaril@0
|
1305 |
if (clipboardME->isVisible())
|
insilmaril@0
|
1306 |
{
|
insilmaril@0
|
1307 |
clipboardME->getMapCenter()->reposition();
|
insilmaril@0
|
1308 |
}
|
insilmaril@0
|
1309 |
else
|
insilmaril@0
|
1310 |
clipboardME->hide();
|
insilmaril@0
|
1311 |
}
|
insilmaril@0
|
1312 |
}
|
insilmaril@0
|
1313 |
}
|
insilmaril@0
|
1314 |
}
|
insilmaril@0
|
1315 |
|
insilmaril@106
|
1316 |
void MapEditor::undo()
|
insilmaril@106
|
1317 |
{
|
insilmaril@106
|
1318 |
// Finish open lineEdits
|
insilmaril@106
|
1319 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@106
|
1320 |
|
insilmaril@136
|
1321 |
// select object before undo
|
insilmaril@136
|
1322 |
if (!undoSelection.isEmpty())
|
insilmaril@136
|
1323 |
select (undoSelection);
|
insilmaril@136
|
1324 |
|
insilmaril@106
|
1325 |
parseAtom (undoCommand);
|
insilmaril@106
|
1326 |
mapCenter->reposition();
|
insilmaril@106
|
1327 |
|
insilmaril@106
|
1328 |
// Undo not longer available now
|
insilmaril@106
|
1329 |
actionEditUndo->setEnabled (false);
|
insilmaril@106
|
1330 |
mapChanged=false;
|
insilmaril@106
|
1331 |
|
insilmaril@139
|
1332 |
if (!redoSelection.isEmpty())
|
insilmaril@139
|
1333 |
select (redoSelection);
|
insilmaril@106
|
1334 |
}
|
insilmaril@106
|
1335 |
|
insilmaril@106
|
1336 |
void MapEditor::undoXML(const QString &undoSel)
|
insilmaril@106
|
1337 |
{
|
insilmaril@106
|
1338 |
QDir d;
|
insilmaril@106
|
1339 |
d.setPath(bakMapDir);
|
insilmaril@106
|
1340 |
if (d.exists() )
|
insilmaril@106
|
1341 |
{
|
insilmaril@106
|
1342 |
// We need to parse saved XML data
|
insilmaril@106
|
1343 |
mapBuilderHandler handler;
|
insilmaril@106
|
1344 |
QXmlInputSource source;
|
insilmaril@106
|
1345 |
source.setData(backupXML);
|
insilmaril@106
|
1346 |
QXmlSimpleReader reader;
|
insilmaril@106
|
1347 |
reader.setContentHandler( &handler );
|
insilmaril@106
|
1348 |
reader.setErrorHandler( &handler );
|
insilmaril@106
|
1349 |
handler.setMapEditor( this );
|
insilmaril@106
|
1350 |
handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
|
insilmaril@106
|
1351 |
if (undoSel.isEmpty())
|
insilmaril@106
|
1352 |
{
|
insilmaril@139
|
1353 |
unselect();
|
insilmaril@106
|
1354 |
mapCenter->clear();
|
insilmaril@106
|
1355 |
handler.setLoadMode (NewMap);
|
insilmaril@106
|
1356 |
} else
|
insilmaril@106
|
1357 |
{
|
insilmaril@106
|
1358 |
select (undoSel);
|
insilmaril@106
|
1359 |
handler.setLoadMode (ImportReplace);
|
insilmaril@106
|
1360 |
}
|
insilmaril@139
|
1361 |
blockReposition=true;
|
insilmaril@139
|
1362 |
blockSaveState=true;
|
insilmaril@106
|
1363 |
bool ok = reader.parse( source );
|
insilmaril@139
|
1364 |
blockReposition=false;
|
insilmaril@139
|
1365 |
blockSaveState=false;
|
insilmaril@106
|
1366 |
if (! ok )
|
insilmaril@106
|
1367 |
{
|
insilmaril@106
|
1368 |
// This should never ever happen
|
insilmaril@106
|
1369 |
QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
|
insilmaril@106
|
1370 |
tr( handler.errorProtocol() )+" in "+backupXML );
|
insilmaril@106
|
1371 |
}
|
insilmaril@106
|
1372 |
} else
|
insilmaril@106
|
1373 |
{
|
insilmaril@106
|
1374 |
QMessageBox::critical( 0, tr( "Critical Error" ),
|
insilmaril@106
|
1375 |
"Temporary directory " +bakMapDir +
|
insilmaril@106
|
1376 |
tr (" used for undo is gone. \n"
|
insilmaril@106
|
1377 |
"I will create a new one, but at the moment no undo is available.\n"
|
insilmaril@106
|
1378 |
"Maybe you want to reload your original data.\n\n"
|
insilmaril@106
|
1379 |
"Sorry for any inconveniences.") );
|
insilmaril@106
|
1380 |
makeTmpDirs();
|
insilmaril@106
|
1381 |
}
|
insilmaril@106
|
1382 |
}
|
insilmaril@106
|
1383 |
|
insilmaril@0
|
1384 |
LinkableMapObj* MapEditor::pasteNoSave()
|
insilmaril@0
|
1385 |
{
|
insilmaril@0
|
1386 |
// Finish open lineEdits
|
insilmaril@0
|
1387 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1388 |
|
insilmaril@0
|
1389 |
LinkableMapObj *fromLMO=clipboardME->getSelection();
|
insilmaril@0
|
1390 |
LinkableMapObj *returnLMO=NULL;
|
insilmaril@0
|
1391 |
|
insilmaril@0
|
1392 |
if (selection && fromLMO)
|
insilmaril@0
|
1393 |
{
|
insilmaril@0
|
1394 |
if (typeid(*fromLMO) == typeid(BranchObj) )
|
insilmaril@0
|
1395 |
{
|
insilmaril@0
|
1396 |
if (typeid(*selection) == typeid(MapCenterObj))
|
insilmaril@0
|
1397 |
{
|
insilmaril@0
|
1398 |
returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
|
insilmaril@0
|
1399 |
((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
|
insilmaril@0
|
1400 |
}
|
insilmaril@0
|
1401 |
if (typeid(*selection) == typeid(BranchObj))
|
insilmaril@0
|
1402 |
returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
|
insilmaril@0
|
1403 |
}
|
insilmaril@0
|
1404 |
|
insilmaril@0
|
1405 |
if (typeid(*fromLMO) == typeid(FloatImageObj) &&
|
insilmaril@0
|
1406 |
(typeid(*selection) == typeid (BranchObj) ||
|
insilmaril@0
|
1407 |
typeid(*selection)==typeid(MapCenterObj)) )
|
insilmaril@0
|
1408 |
returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
|
insilmaril@0
|
1409 |
|
insilmaril@0
|
1410 |
}
|
insilmaril@0
|
1411 |
return returnLMO;
|
insilmaril@0
|
1412 |
}
|
insilmaril@0
|
1413 |
|
insilmaril@0
|
1414 |
void MapEditor::cutNoSave()
|
insilmaril@0
|
1415 |
{
|
insilmaril@0
|
1416 |
// Finish open lineEdits
|
insilmaril@0
|
1417 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1418 |
|
insilmaril@0
|
1419 |
BranchObj* bo;
|
insilmaril@0
|
1420 |
BranchObj* par;
|
insilmaril@0
|
1421 |
if (selection != NULL) {
|
insilmaril@0
|
1422 |
if (typeid(*selection) == typeid(BranchObj) )
|
insilmaril@0
|
1423 |
{
|
insilmaril@0
|
1424 |
bo=(BranchObj*)(selection);
|
insilmaril@0
|
1425 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@0
|
1426 |
bo->unselect();
|
insilmaril@0
|
1427 |
selection=NULL;
|
insilmaril@0
|
1428 |
par->removeBranch(bo);
|
insilmaril@0
|
1429 |
selection=par;
|
insilmaril@0
|
1430 |
selection->select();
|
insilmaril@0
|
1431 |
}
|
insilmaril@0
|
1432 |
if (typeid(*selection) == typeid(FloatImageObj) )
|
insilmaril@0
|
1433 |
{
|
insilmaril@0
|
1434 |
FloatImageObj* fio=(FloatImageObj*)(selection);
|
insilmaril@0
|
1435 |
par=(BranchObj*)(fio->getParObj());
|
insilmaril@0
|
1436 |
fio->unselect();
|
insilmaril@0
|
1437 |
selection=NULL;
|
insilmaril@0
|
1438 |
par->removeFloatImage(fio);
|
insilmaril@0
|
1439 |
selection=par;
|
insilmaril@0
|
1440 |
selection->select();
|
insilmaril@0
|
1441 |
}
|
insilmaril@0
|
1442 |
}
|
insilmaril@0
|
1443 |
}
|
insilmaril@0
|
1444 |
|
insilmaril@0
|
1445 |
void MapEditor::paste()
|
insilmaril@0
|
1446 |
{
|
insilmaril@106
|
1447 |
saveState(selection);
|
insilmaril@0
|
1448 |
pasteNoSave();
|
insilmaril@0
|
1449 |
mapCenter->reposition();
|
insilmaril@0
|
1450 |
adjustCanvasSize();
|
insilmaril@0
|
1451 |
}
|
insilmaril@0
|
1452 |
|
insilmaril@0
|
1453 |
void MapEditor::cut()
|
insilmaril@0
|
1454 |
{
|
insilmaril@106
|
1455 |
saveState(selection->getParObj());
|
insilmaril@0
|
1456 |
copy();
|
insilmaril@0
|
1457 |
cutNoSave();
|
insilmaril@0
|
1458 |
mapCenter->reposition();
|
insilmaril@0
|
1459 |
adjustCanvasSize();
|
insilmaril@0
|
1460 |
}
|
insilmaril@0
|
1461 |
|
insilmaril@130
|
1462 |
void MapEditor::move(const int &x, const int &y)
|
insilmaril@130
|
1463 |
{
|
insilmaril@130
|
1464 |
// FIXME no saveState, because this is only internal at undo so far
|
insilmaril@130
|
1465 |
if (selection) selection->move(x,y);
|
insilmaril@130
|
1466 |
if (typeid(*selection) == typeid(FloatImageObj))
|
insilmaril@130
|
1467 |
((FloatImageObj*)(selection))->setRelPos();
|
insilmaril@130
|
1468 |
}
|
insilmaril@130
|
1469 |
|
insilmaril@0
|
1470 |
void MapEditor::moveBranchUp()
|
insilmaril@0
|
1471 |
{
|
insilmaril@0
|
1472 |
// Finish open lineEdits
|
insilmaril@0
|
1473 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1474 |
|
insilmaril@0
|
1475 |
BranchObj* bo;
|
insilmaril@0
|
1476 |
BranchObj* par;
|
insilmaril@0
|
1477 |
if (typeid(*selection) == typeid(BranchObj) )
|
insilmaril@0
|
1478 |
{
|
insilmaril@0
|
1479 |
bo=(BranchObj*)(selection);
|
insilmaril@0
|
1480 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@0
|
1481 |
selection->unselect();
|
insilmaril@0
|
1482 |
selection=par->moveBranchUp (bo);
|
insilmaril@0
|
1483 |
selection->select();
|
insilmaril@139
|
1484 |
saveState("moveBranchDown ()",bo->getSelectString());
|
insilmaril@0
|
1485 |
mapCenter->reposition();
|
insilmaril@0
|
1486 |
ensureSelectionVisible();
|
insilmaril@0
|
1487 |
}
|
insilmaril@0
|
1488 |
}
|
insilmaril@0
|
1489 |
|
insilmaril@0
|
1490 |
void MapEditor::moveBranchDown()
|
insilmaril@0
|
1491 |
{
|
insilmaril@0
|
1492 |
// Finish open lineEdits
|
insilmaril@0
|
1493 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1494 |
|
insilmaril@0
|
1495 |
BranchObj* bo;
|
insilmaril@0
|
1496 |
BranchObj* par;
|
insilmaril@0
|
1497 |
if (typeid(*selection) == typeid(BranchObj) )
|
insilmaril@0
|
1498 |
{
|
insilmaril@0
|
1499 |
bo=(BranchObj*)(selection);
|
insilmaril@0
|
1500 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@0
|
1501 |
selection->unselect();
|
insilmaril@0
|
1502 |
selection=par->moveBranchDown(bo);
|
insilmaril@0
|
1503 |
selection->select();
|
insilmaril@139
|
1504 |
saveState("moveBranchUp ()",bo->getSelectString());
|
insilmaril@0
|
1505 |
mapCenter->reposition();
|
insilmaril@0
|
1506 |
ensureSelectionVisible();
|
insilmaril@0
|
1507 |
}
|
insilmaril@0
|
1508 |
}
|
insilmaril@0
|
1509 |
|
insilmaril@0
|
1510 |
void MapEditor::editHeading()
|
insilmaril@0
|
1511 |
{
|
insilmaril@0
|
1512 |
// Finish open lineEdits
|
insilmaril@0
|
1513 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1514 |
|
insilmaril@0
|
1515 |
if (selection &&
|
insilmaril@0
|
1516 |
(typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
1517 |
typeid(*selection) == typeid(MapCenterObj) ) )
|
insilmaril@0
|
1518 |
{
|
insilmaril@139
|
1519 |
editingBO=(BranchObj*)(selection);
|
insilmaril@139
|
1520 |
saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")",editingBO->getSelectString() );
|
insilmaril@0
|
1521 |
|
insilmaril@0
|
1522 |
ensureSelectionVisible();
|
insilmaril@93
|
1523 |
QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
|
insilmaril@0
|
1524 |
lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
|
insilmaril@93
|
1525 |
QString s=editingBO->getHeading();
|
insilmaril@0
|
1526 |
lineedit->setText(s);
|
insilmaril@0
|
1527 |
lineedit->setCursorPosition(1);
|
insilmaril@0
|
1528 |
if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
|
insilmaril@0
|
1529 |
lineedit->selectAll();
|
insilmaril@0
|
1530 |
lineedit->show();
|
insilmaril@0
|
1531 |
|
insilmaril@0
|
1532 |
lineedit->grabKeyboard();
|
insilmaril@0
|
1533 |
lineedit->setFocus();
|
insilmaril@0
|
1534 |
}
|
insilmaril@0
|
1535 |
}
|
insilmaril@0
|
1536 |
|
insilmaril@106
|
1537 |
void MapEditor::setHeading(const QString &s)
|
insilmaril@106
|
1538 |
{
|
insilmaril@106
|
1539 |
// Internal function, no saveState needed
|
insilmaril@106
|
1540 |
if (selection &&
|
insilmaril@106
|
1541 |
(typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@106
|
1542 |
typeid(*selection) == typeid(MapCenterObj) ) )
|
insilmaril@106
|
1543 |
{
|
insilmaril@106
|
1544 |
((BranchObj*)(selection))->setHeading(s);
|
insilmaril@106
|
1545 |
mapCenter->reposition();
|
insilmaril@106
|
1546 |
adjustCanvasSize();
|
insilmaril@106
|
1547 |
ensureSelectionVisible();
|
insilmaril@106
|
1548 |
}
|
insilmaril@106
|
1549 |
}
|
insilmaril@106
|
1550 |
|
insilmaril@0
|
1551 |
void MapEditor::addNewBranch(int pos)
|
insilmaril@0
|
1552 |
{
|
insilmaril@0
|
1553 |
// Finish open lineEdits
|
insilmaril@0
|
1554 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1555 |
|
insilmaril@0
|
1556 |
if (selection &&
|
insilmaril@0
|
1557 |
(typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
1558 |
typeid(*selection) == typeid(MapCenterObj) ) )
|
insilmaril@0
|
1559 |
{
|
insilmaril@106
|
1560 |
saveState(selection);
|
insilmaril@0
|
1561 |
|
insilmaril@0
|
1562 |
BranchObj* bo1 = (BranchObj*) (selection);
|
insilmaril@0
|
1563 |
bool wasScrolled=false;
|
insilmaril@0
|
1564 |
BranchObj *newbo=NULL;
|
insilmaril@0
|
1565 |
if (pos==0)
|
insilmaril@0
|
1566 |
{
|
insilmaril@0
|
1567 |
// save scroll state. If scrolled, automatically select
|
insilmaril@0
|
1568 |
// new branch in order to tmp unscroll parent...
|
insilmaril@0
|
1569 |
wasScrolled=bo1->isScrolled();
|
insilmaril@0
|
1570 |
newbo=bo1->addBranch();
|
insilmaril@0
|
1571 |
} else
|
insilmaril@0
|
1572 |
{
|
insilmaril@0
|
1573 |
BranchObj *parbo=(BranchObj*)(selection->getParObj());
|
insilmaril@0
|
1574 |
if (parbo)
|
insilmaril@0
|
1575 |
{
|
insilmaril@0
|
1576 |
if (pos<0)
|
insilmaril@0
|
1577 |
// add above selection
|
insilmaril@0
|
1578 |
newbo=parbo->insertBranch(bo1->getNum());
|
insilmaril@0
|
1579 |
else
|
insilmaril@0
|
1580 |
// add below selection
|
insilmaril@0
|
1581 |
newbo=parbo->insertBranch(bo1->getNum()+1);
|
insilmaril@0
|
1582 |
} else
|
insilmaril@0
|
1583 |
// This should not happen...
|
insilmaril@0
|
1584 |
return;
|
insilmaril@0
|
1585 |
|
insilmaril@0
|
1586 |
}
|
insilmaril@0
|
1587 |
|
insilmaril@0
|
1588 |
LinkableMapObj *oldselection=selection;
|
insilmaril@0
|
1589 |
|
insilmaril@0
|
1590 |
mapCenter->reposition();
|
insilmaril@0
|
1591 |
adjustCanvasSize();
|
insilmaril@0
|
1592 |
if (actionSettingsAutoedit->isOn() ||
|
insilmaril@0
|
1593 |
actionSettingsAutoselectHeading->isOn() )
|
insilmaril@0
|
1594 |
{
|
insilmaril@0
|
1595 |
selection->unselect();
|
insilmaril@0
|
1596 |
selection=newbo;
|
insilmaril@0
|
1597 |
selection->select();
|
insilmaril@0
|
1598 |
if (actionSettingsPasteNewHeading->isOn() )
|
insilmaril@0
|
1599 |
{
|
insilmaril@0
|
1600 |
BranchObj *bo2= (BranchObj*)(selection);
|
insilmaril@0
|
1601 |
bo2->setHeading("");
|
insilmaril@0
|
1602 |
}
|
insilmaril@0
|
1603 |
if (actionSettingsAutoedit->isOn() )
|
insilmaril@0
|
1604 |
editHeading();
|
insilmaril@0
|
1605 |
if (!actionSettingsAutoselectHeading->isOn()
|
insilmaril@0
|
1606 |
&& !wasScrolled)
|
insilmaril@0
|
1607 |
{
|
insilmaril@0
|
1608 |
selection->unselect();
|
insilmaril@0
|
1609 |
selection=oldselection;
|
insilmaril@0
|
1610 |
selection->select();
|
insilmaril@0
|
1611 |
}
|
insilmaril@0
|
1612 |
}
|
insilmaril@0
|
1613 |
}
|
insilmaril@0
|
1614 |
}
|
insilmaril@0
|
1615 |
|
insilmaril@98
|
1616 |
|
insilmaril@98
|
1617 |
void MapEditor::addNewBranchHere()
|
insilmaril@98
|
1618 |
{
|
insilmaril@98
|
1619 |
// Finish open lineEdits
|
insilmaril@98
|
1620 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@98
|
1621 |
|
insilmaril@98
|
1622 |
if (selection &&
|
insilmaril@98
|
1623 |
(typeid(*selection) == typeid(BranchObj) ) )
|
insilmaril@98
|
1624 |
{
|
insilmaril@106
|
1625 |
saveState(selection);
|
insilmaril@98
|
1626 |
|
insilmaril@98
|
1627 |
BranchObj* bo1 = (BranchObj*) (selection);
|
insilmaril@98
|
1628 |
bool wasScrolled=false;
|
insilmaril@98
|
1629 |
BranchObj *newbo=NULL;
|
insilmaril@98
|
1630 |
BranchObj *parbo=(BranchObj*)(selection->getParObj());
|
insilmaril@98
|
1631 |
if (parbo)
|
insilmaril@98
|
1632 |
{
|
insilmaril@98
|
1633 |
// add below selection
|
insilmaril@98
|
1634 |
newbo=parbo->insertBranch(bo1->getNum()+1);
|
insilmaril@98
|
1635 |
}
|
insilmaril@98
|
1636 |
|
insilmaril@98
|
1637 |
LinkableMapObj *oldselection=selection;
|
insilmaril@98
|
1638 |
((BranchObj*)(selection))->moveBranchTo (newbo,-1);
|
insilmaril@98
|
1639 |
|
insilmaril@98
|
1640 |
mapCenter->reposition();
|
insilmaril@98
|
1641 |
adjustCanvasSize();
|
insilmaril@98
|
1642 |
if (actionSettingsAutoedit->isOn() ||
|
insilmaril@98
|
1643 |
actionSettingsAutoselectHeading->isOn() )
|
insilmaril@98
|
1644 |
{
|
insilmaril@98
|
1645 |
selection->unselect();
|
insilmaril@98
|
1646 |
selection=newbo;
|
insilmaril@98
|
1647 |
selection->select();
|
insilmaril@98
|
1648 |
if (actionSettingsPasteNewHeading->isOn() )
|
insilmaril@98
|
1649 |
{
|
insilmaril@98
|
1650 |
BranchObj *bo2= (BranchObj*)(selection);
|
insilmaril@98
|
1651 |
bo2->setHeading("");
|
insilmaril@98
|
1652 |
}
|
insilmaril@98
|
1653 |
if (actionSettingsAutoedit->isOn() )
|
insilmaril@98
|
1654 |
editHeading();
|
insilmaril@98
|
1655 |
if (!actionSettingsAutoselectHeading->isOn()
|
insilmaril@98
|
1656 |
&& !wasScrolled)
|
insilmaril@98
|
1657 |
{
|
insilmaril@98
|
1658 |
selection->unselect();
|
insilmaril@98
|
1659 |
selection=oldselection;
|
insilmaril@98
|
1660 |
selection->select();
|
insilmaril@98
|
1661 |
}
|
insilmaril@98
|
1662 |
}
|
insilmaril@98
|
1663 |
}
|
insilmaril@98
|
1664 |
}
|
insilmaril@98
|
1665 |
|
insilmaril@0
|
1666 |
void MapEditor::deleteSelection()
|
insilmaril@0
|
1667 |
{
|
insilmaril@0
|
1668 |
// Finish open lineEdits
|
insilmaril@0
|
1669 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1670 |
|
insilmaril@0
|
1671 |
if (selection && typeid(*selection) ==typeid(BranchObj) )
|
insilmaril@0
|
1672 |
{
|
insilmaril@139
|
1673 |
if (selection->getDepth()>1)
|
insilmaril@139
|
1674 |
// Normal branch, save parent with childs
|
insilmaril@139
|
1675 |
saveState(selection->getParObj());
|
insilmaril@139
|
1676 |
else
|
insilmaril@139
|
1677 |
// Mainbranch, save whole map
|
insilmaril@139
|
1678 |
// FIXME Better would be to insert mainbranch again at pos
|
insilmaril@139
|
1679 |
// But undoCommand is missing right now
|
insilmaril@139
|
1680 |
saveState();
|
insilmaril@0
|
1681 |
BranchObj* bo=dynamic_cast <BranchObj*> (selection);
|
insilmaril@0
|
1682 |
BranchObj* par=(BranchObj*)(bo->getParObj());
|
insilmaril@0
|
1683 |
bo->unselect();
|
insilmaril@0
|
1684 |
selection=NULL;
|
insilmaril@0
|
1685 |
par->removeBranch(bo);
|
insilmaril@0
|
1686 |
selection=par;
|
insilmaril@0
|
1687 |
selection->select();
|
insilmaril@0
|
1688 |
ensureSelectionVisible();
|
insilmaril@0
|
1689 |
mapCenter->reposition();
|
insilmaril@0
|
1690 |
adjustCanvasSize();
|
insilmaril@0
|
1691 |
}
|
insilmaril@0
|
1692 |
if (selection && typeid(*selection) ==typeid(FloatImageObj) )
|
insilmaril@0
|
1693 |
{
|
insilmaril@106
|
1694 |
saveState(selection->getParObj());
|
insilmaril@0
|
1695 |
FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
|
insilmaril@0
|
1696 |
BranchObj* par=(BranchObj*)(fio->getParObj());
|
insilmaril@0
|
1697 |
fio->unselect();
|
insilmaril@0
|
1698 |
selection=NULL;
|
insilmaril@0
|
1699 |
par->removeFloatImage(fio);
|
insilmaril@0
|
1700 |
selection=par;
|
insilmaril@0
|
1701 |
selection->select();
|
insilmaril@0
|
1702 |
ensureSelectionVisible();
|
insilmaril@0
|
1703 |
mapCenter->reposition();
|
insilmaril@0
|
1704 |
adjustCanvasSize();
|
insilmaril@0
|
1705 |
}
|
insilmaril@0
|
1706 |
}
|
insilmaril@0
|
1707 |
|
insilmaril@0
|
1708 |
LinkableMapObj* MapEditor::getSelection()
|
insilmaril@0
|
1709 |
{
|
insilmaril@0
|
1710 |
return selection;
|
insilmaril@0
|
1711 |
}
|
insilmaril@0
|
1712 |
|
insilmaril@83
|
1713 |
bool MapEditor::select (const QString &s)
|
insilmaril@83
|
1714 |
{
|
insilmaril@106
|
1715 |
LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
|
insilmaril@0
|
1716 |
|
insilmaril@0
|
1717 |
// Finally select the found object
|
insilmaril@0
|
1718 |
if (lmo)
|
insilmaril@0
|
1719 |
{
|
insilmaril@98
|
1720 |
if (selection) unselect();
|
insilmaril@0
|
1721 |
selection=lmo;
|
insilmaril@0
|
1722 |
selection->select();
|
insilmaril@0
|
1723 |
adjustCanvasSize();
|
insilmaril@0
|
1724 |
ensureSelectionVisible();
|
insilmaril@0
|
1725 |
return true;
|
insilmaril@139
|
1726 |
}
|
insilmaril@139
|
1727 |
return false;
|
insilmaril@0
|
1728 |
}
|
insilmaril@0
|
1729 |
|
insilmaril@0
|
1730 |
void MapEditor::unselect()
|
insilmaril@0
|
1731 |
{
|
insilmaril@0
|
1732 |
if (selection)
|
insilmaril@0
|
1733 |
{
|
insilmaril@0
|
1734 |
selectionLast=selection;
|
insilmaril@0
|
1735 |
selection->unselect();
|
insilmaril@0
|
1736 |
selection=NULL;
|
insilmaril@0
|
1737 |
}
|
insilmaril@0
|
1738 |
}
|
insilmaril@0
|
1739 |
|
insilmaril@0
|
1740 |
void MapEditor::reselect()
|
insilmaril@0
|
1741 |
{
|
insilmaril@0
|
1742 |
if (selectionLast)
|
insilmaril@0
|
1743 |
{
|
insilmaril@0
|
1744 |
selection=selectionLast;
|
insilmaril@0
|
1745 |
selection->select();
|
insilmaril@0
|
1746 |
selectionLast=NULL;
|
insilmaril@0
|
1747 |
}
|
insilmaril@0
|
1748 |
}
|
insilmaril@0
|
1749 |
|
insilmaril@0
|
1750 |
void MapEditor::selectNextBranch()
|
insilmaril@0
|
1751 |
{
|
insilmaril@0
|
1752 |
// Increase number of branch
|
insilmaril@0
|
1753 |
if (selection)
|
insilmaril@0
|
1754 |
{
|
insilmaril@0
|
1755 |
QString s=selection->getSelectString();
|
insilmaril@0
|
1756 |
QString part;
|
insilmaril@0
|
1757 |
QString typ;
|
insilmaril@0
|
1758 |
QString num;
|
insilmaril@0
|
1759 |
|
insilmaril@0
|
1760 |
// Where am I?
|
insilmaril@0
|
1761 |
part=s.section(",",-1);
|
insilmaril@0
|
1762 |
typ=part.left (3);
|
insilmaril@0
|
1763 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
1764 |
|
insilmaril@0
|
1765 |
s=s.left (s.length() -num.length());
|
insilmaril@0
|
1766 |
|
insilmaril@0
|
1767 |
// Go to next lmo
|
insilmaril@0
|
1768 |
num=QString ("%1").arg(num.toUInt()+1);
|
insilmaril@0
|
1769 |
|
insilmaril@0
|
1770 |
s=s+num;
|
insilmaril@0
|
1771 |
|
insilmaril@0
|
1772 |
// Try to select this one
|
insilmaril@0
|
1773 |
if (select (s)) return;
|
insilmaril@0
|
1774 |
|
insilmaril@0
|
1775 |
// We have no direct successor,
|
insilmaril@0
|
1776 |
// try to increase the parental number in order to
|
insilmaril@0
|
1777 |
// find a successor with same depth
|
insilmaril@0
|
1778 |
|
insilmaril@0
|
1779 |
int d=selection->getDepth();
|
insilmaril@0
|
1780 |
int oldDepth=d;
|
insilmaril@0
|
1781 |
int i;
|
insilmaril@0
|
1782 |
bool found=false;
|
insilmaril@0
|
1783 |
bool b;
|
insilmaril@0
|
1784 |
while (!found && d>0)
|
insilmaril@0
|
1785 |
{
|
insilmaril@0
|
1786 |
s=s.section (",",0,d-1);
|
insilmaril@0
|
1787 |
// replace substring of current depth in s with "1"
|
insilmaril@0
|
1788 |
part=s.section(",",-1);
|
insilmaril@0
|
1789 |
typ=part.left (3);
|
insilmaril@0
|
1790 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
1791 |
|
insilmaril@0
|
1792 |
if (d>1)
|
insilmaril@0
|
1793 |
{
|
insilmaril@0
|
1794 |
// increase number of parent
|
insilmaril@0
|
1795 |
num=QString ("%1").arg(num.toUInt()+1);
|
insilmaril@0
|
1796 |
s=s.section (",",0,d-2) + ","+ typ+num;
|
insilmaril@0
|
1797 |
} else
|
insilmaril@0
|
1798 |
{
|
insilmaril@0
|
1799 |
// Special case, look at orientation
|
insilmaril@0
|
1800 |
if (selection->getOrientation()==OrientRightOfCenter)
|
insilmaril@0
|
1801 |
num=QString ("%1").arg(num.toUInt()+1);
|
insilmaril@0
|
1802 |
else
|
insilmaril@0
|
1803 |
num=QString ("%1").arg(num.toUInt()-1);
|
insilmaril@0
|
1804 |
s=typ+num;
|
insilmaril@0
|
1805 |
}
|
insilmaril@0
|
1806 |
|
insilmaril@0
|
1807 |
if (select (s))
|
insilmaril@0
|
1808 |
// pad to oldDepth, select the first branch for each depth
|
insilmaril@0
|
1809 |
for (i=d;i<oldDepth;i++)
|
insilmaril@0
|
1810 |
{
|
insilmaril@0
|
1811 |
b=select (s);
|
insilmaril@0
|
1812 |
if (b)
|
insilmaril@0
|
1813 |
{
|
insilmaril@0
|
1814 |
if ( ((BranchObj*)(selection))->countBranches()>0)
|
insilmaril@0
|
1815 |
s+=",bo:0";
|
insilmaril@0
|
1816 |
else
|
insilmaril@0
|
1817 |
break;
|
insilmaril@0
|
1818 |
} else
|
insilmaril@0
|
1819 |
break;
|
insilmaril@0
|
1820 |
}
|
insilmaril@0
|
1821 |
|
insilmaril@0
|
1822 |
// try to select the freshly built string
|
insilmaril@0
|
1823 |
found=select(s);
|
insilmaril@0
|
1824 |
d--;
|
insilmaril@0
|
1825 |
}
|
insilmaril@0
|
1826 |
return;
|
insilmaril@0
|
1827 |
}
|
insilmaril@0
|
1828 |
}
|
insilmaril@0
|
1829 |
|
insilmaril@0
|
1830 |
void MapEditor::selectPrevBranch()
|
insilmaril@0
|
1831 |
{
|
insilmaril@0
|
1832 |
// Decrease number of branch
|
insilmaril@0
|
1833 |
if (selection)
|
insilmaril@0
|
1834 |
{
|
insilmaril@0
|
1835 |
QString s=selection->getSelectString();
|
insilmaril@0
|
1836 |
QString part;
|
insilmaril@0
|
1837 |
QString typ;
|
insilmaril@0
|
1838 |
QString num;
|
insilmaril@0
|
1839 |
|
insilmaril@0
|
1840 |
// Where am I?
|
insilmaril@0
|
1841 |
part=s.section(",",-1);
|
insilmaril@0
|
1842 |
typ=part.left (3);
|
insilmaril@0
|
1843 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
1844 |
|
insilmaril@0
|
1845 |
s=s.left (s.length() -num.length());
|
insilmaril@0
|
1846 |
|
insilmaril@0
|
1847 |
// Go to next lmo
|
insilmaril@0
|
1848 |
num=QString ("%1").arg(num.toUInt()-1);
|
insilmaril@0
|
1849 |
|
insilmaril@0
|
1850 |
s=s+num;
|
insilmaril@0
|
1851 |
|
insilmaril@0
|
1852 |
// Try to select this one
|
insilmaril@0
|
1853 |
if (select (s)) return;
|
insilmaril@0
|
1854 |
|
insilmaril@0
|
1855 |
// We have no direct precessor,
|
insilmaril@0
|
1856 |
// try to decrease the parental number in order to
|
insilmaril@0
|
1857 |
// find a precessor with same depth
|
insilmaril@0
|
1858 |
|
insilmaril@0
|
1859 |
int d=selection->getDepth();
|
insilmaril@0
|
1860 |
int oldDepth=d;
|
insilmaril@0
|
1861 |
int i;
|
insilmaril@0
|
1862 |
bool found=false;
|
insilmaril@0
|
1863 |
bool b;
|
insilmaril@0
|
1864 |
while (!found && d>0)
|
insilmaril@0
|
1865 |
{
|
insilmaril@0
|
1866 |
s=s.section (",",0,d-1);
|
insilmaril@0
|
1867 |
// replace substring of current depth in s with "1"
|
insilmaril@0
|
1868 |
part=s.section(",",-1);
|
insilmaril@0
|
1869 |
typ=part.left (3);
|
insilmaril@0
|
1870 |
num=part.right(part.length() - 3);
|
insilmaril@0
|
1871 |
|
insilmaril@0
|
1872 |
if (d>1)
|
insilmaril@0
|
1873 |
{
|
insilmaril@0
|
1874 |
// decrease number of parent
|
insilmaril@0
|
1875 |
num=QString ("%1").arg(num.toUInt()-1);
|
insilmaril@0
|
1876 |
s=s.section (",",0,d-2) + ","+ typ+num;
|
insilmaril@0
|
1877 |
} else
|
insilmaril@0
|
1878 |
{
|
insilmaril@0
|
1879 |
// Special case, look at orientation
|
insilmaril@0
|
1880 |
if (selection->getOrientation()==OrientRightOfCenter)
|
insilmaril@0
|
1881 |
num=QString ("%1").arg(num.toUInt()-1);
|
insilmaril@0
|
1882 |
else
|
insilmaril@0
|
1883 |
num=QString ("%1").arg(num.toUInt()+1);
|
insilmaril@0
|
1884 |
s=typ+num;
|
insilmaril@0
|
1885 |
}
|
insilmaril@0
|
1886 |
|
insilmaril@0
|
1887 |
if (select(s))
|
insilmaril@0
|
1888 |
// pad to oldDepth, select the last branch for each depth
|
insilmaril@0
|
1889 |
for (i=d;i<oldDepth;i++)
|
insilmaril@0
|
1890 |
{
|
insilmaril@0
|
1891 |
b=select (s);
|
insilmaril@0
|
1892 |
if (b)
|
insilmaril@0
|
1893 |
if ( ((BranchObj*)(selection))->countBranches()>0)
|
insilmaril@0
|
1894 |
s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
|
insilmaril@0
|
1895 |
else
|
insilmaril@0
|
1896 |
break;
|
insilmaril@0
|
1897 |
else
|
insilmaril@0
|
1898 |
break;
|
insilmaril@0
|
1899 |
}
|
insilmaril@0
|
1900 |
|
insilmaril@0
|
1901 |
// try to select the freshly built string
|
insilmaril@0
|
1902 |
found=select(s);
|
insilmaril@0
|
1903 |
d--;
|
insilmaril@0
|
1904 |
}
|
insilmaril@0
|
1905 |
return;
|
insilmaril@0
|
1906 |
}
|
insilmaril@0
|
1907 |
}
|
insilmaril@0
|
1908 |
|
insilmaril@0
|
1909 |
void MapEditor::selectUpperBranch()
|
insilmaril@0
|
1910 |
{
|
insilmaril@0
|
1911 |
// Finish open lineEdits
|
insilmaril@0
|
1912 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1913 |
|
insilmaril@0
|
1914 |
if (selection)
|
insilmaril@0
|
1915 |
{
|
insilmaril@0
|
1916 |
if (typeid(*selection) == typeid(BranchObj))
|
insilmaril@0
|
1917 |
{
|
insilmaril@0
|
1918 |
if (selection->getOrientation()==OrientRightOfCenter)
|
insilmaril@0
|
1919 |
selectPrevBranch();
|
insilmaril@0
|
1920 |
else
|
insilmaril@0
|
1921 |
if (selection->getDepth()==1)
|
insilmaril@0
|
1922 |
selectNextBranch();
|
insilmaril@0
|
1923 |
else
|
insilmaril@0
|
1924 |
selectPrevBranch();
|
insilmaril@0
|
1925 |
}
|
insilmaril@0
|
1926 |
}
|
insilmaril@0
|
1927 |
}
|
insilmaril@0
|
1928 |
|
insilmaril@0
|
1929 |
void MapEditor::selectLowerBranch()
|
insilmaril@0
|
1930 |
{
|
insilmaril@0
|
1931 |
// Finish open lineEdits
|
insilmaril@0
|
1932 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1933 |
|
insilmaril@0
|
1934 |
if (selection)
|
insilmaril@0
|
1935 |
{
|
insilmaril@0
|
1936 |
if (typeid(*selection) == typeid(BranchObj))
|
insilmaril@0
|
1937 |
{
|
insilmaril@0
|
1938 |
if (selection->getOrientation()==OrientRightOfCenter)
|
insilmaril@0
|
1939 |
selectNextBranch();
|
insilmaril@0
|
1940 |
else
|
insilmaril@0
|
1941 |
if (selection->getDepth()==1)
|
insilmaril@0
|
1942 |
selectPrevBranch();
|
insilmaril@0
|
1943 |
else
|
insilmaril@0
|
1944 |
selectNextBranch();
|
insilmaril@0
|
1945 |
}
|
insilmaril@0
|
1946 |
}
|
insilmaril@0
|
1947 |
}
|
insilmaril@0
|
1948 |
|
insilmaril@0
|
1949 |
|
insilmaril@0
|
1950 |
void MapEditor::selectLeftBranch()
|
insilmaril@0
|
1951 |
{
|
insilmaril@0
|
1952 |
// Finish open lineEdits
|
insilmaril@0
|
1953 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
1954 |
|
insilmaril@0
|
1955 |
BranchObj* bo;
|
insilmaril@0
|
1956 |
BranchObj* par;
|
insilmaril@0
|
1957 |
if (selection)
|
insilmaril@0
|
1958 |
{
|
insilmaril@0
|
1959 |
if (typeid(*selection) == typeid(MapCenterObj))
|
insilmaril@0
|
1960 |
{
|
insilmaril@0
|
1961 |
par= (BranchObj*) (selection);
|
insilmaril@0
|
1962 |
bo=par->getLastSelectedBranch();
|
insilmaril@0
|
1963 |
if (bo)
|
insilmaril@0
|
1964 |
{
|
insilmaril@0
|
1965 |
// Workaround for reselecting on left and right side
|
insilmaril@0
|
1966 |
if (bo->getOrientation()==OrientRightOfCenter)
|
insilmaril@0
|
1967 |
{
|
insilmaril@0
|
1968 |
bo=par->getLastBranch();
|
insilmaril@0
|
1969 |
}
|
insilmaril@0
|
1970 |
if (bo)
|
insilmaril@0
|
1971 |
{
|
insilmaril@0
|
1972 |
par->unselect();
|
insilmaril@0
|
1973 |
selection=bo;
|
insilmaril@0
|
1974 |
selection->select();
|
insilmaril@0
|
1975 |
adjustCanvasSize();
|
insilmaril@0
|
1976 |
ensureSelectionVisible();
|
insilmaril@0
|
1977 |
}
|
insilmaril@0
|
1978 |
}
|
insilmaril@0
|
1979 |
} else
|
insilmaril@0
|
1980 |
{
|
insilmaril@0
|
1981 |
par=(BranchObj*)(selection->getParObj());
|
insilmaril@0
|
1982 |
if (selection->getOrientation()==OrientRightOfCenter)
|
insilmaril@0
|
1983 |
{
|
insilmaril@0
|
1984 |
if (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
1985 |
typeid(*selection) == typeid(FloatImageObj))
|
insilmaril@0
|
1986 |
{
|
insilmaril@0
|
1987 |
selection->unselect();
|
insilmaril@0
|
1988 |
selection=par;
|
insilmaril@0
|
1989 |
selection->select();
|
insilmaril@0
|
1990 |
adjustCanvasSize();
|
insilmaril@0
|
1991 |
ensureSelectionVisible();
|
insilmaril@0
|
1992 |
}
|
insilmaril@0
|
1993 |
} else
|
insilmaril@0
|
1994 |
{
|
insilmaril@0
|
1995 |
if (typeid(*selection) == typeid(BranchObj) )
|
insilmaril@0
|
1996 |
{
|
insilmaril@0
|
1997 |
bo=((BranchObj*)(selection))->getLastSelectedBranch();
|
insilmaril@0
|
1998 |
if (bo)
|
insilmaril@0
|
1999 |
{
|
insilmaril@0
|
2000 |
selection->unselect();
|
insilmaril@0
|
2001 |
selection=bo;
|
insilmaril@0
|
2002 |
selection->select();
|
insilmaril@0
|
2003 |
adjustCanvasSize();
|
insilmaril@0
|
2004 |
ensureSelectionVisible();
|
insilmaril@0
|
2005 |
}
|
insilmaril@0
|
2006 |
}
|
insilmaril@0
|
2007 |
}
|
insilmaril@0
|
2008 |
}
|
insilmaril@0
|
2009 |
}
|
insilmaril@0
|
2010 |
}
|
insilmaril@0
|
2011 |
|
insilmaril@0
|
2012 |
void MapEditor::selectRightBranch()
|
insilmaril@0
|
2013 |
{
|
insilmaril@0
|
2014 |
// Finish open lineEdits
|
insilmaril@0
|
2015 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
2016 |
|
insilmaril@0
|
2017 |
BranchObj* bo;
|
insilmaril@0
|
2018 |
BranchObj* par;
|
insilmaril@0
|
2019 |
|
insilmaril@0
|
2020 |
if (selection)
|
insilmaril@0
|
2021 |
{
|
insilmaril@0
|
2022 |
if (typeid(*selection) == typeid(MapCenterObj))
|
insilmaril@0
|
2023 |
{
|
insilmaril@0
|
2024 |
par= (BranchObj*) (selection);
|
insilmaril@0
|
2025 |
bo=par->getLastSelectedBranch();
|
insilmaril@0
|
2026 |
if (bo)
|
insilmaril@0
|
2027 |
{
|
insilmaril@0
|
2028 |
// Workaround for relecting on left and right side
|
insilmaril@0
|
2029 |
if (bo->getOrientation()==OrientLeftOfCenter)
|
insilmaril@0
|
2030 |
bo=par->getFirstBranch();
|
insilmaril@0
|
2031 |
if (bo)
|
insilmaril@0
|
2032 |
{
|
insilmaril@0
|
2033 |
par->unselect();
|
insilmaril@0
|
2034 |
selection=bo;
|
insilmaril@0
|
2035 |
selection->select();
|
insilmaril@0
|
2036 |
ensureSelectionVisible();
|
insilmaril@0
|
2037 |
}
|
insilmaril@0
|
2038 |
}
|
insilmaril@0
|
2039 |
} else
|
insilmaril@0
|
2040 |
{
|
insilmaril@0
|
2041 |
par=(BranchObj*)(selection->getParObj());
|
insilmaril@0
|
2042 |
if (selection->getOrientation()==OrientLeftOfCenter)
|
insilmaril@0
|
2043 |
{
|
insilmaril@0
|
2044 |
if (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2045 |
typeid(*selection) == typeid(FloatImageObj))
|
insilmaril@0
|
2046 |
{
|
insilmaril@0
|
2047 |
selection->unselect();
|
insilmaril@0
|
2048 |
selection=par;
|
insilmaril@0
|
2049 |
selection->select();
|
insilmaril@0
|
2050 |
adjustCanvasSize();
|
insilmaril@0
|
2051 |
ensureSelectionVisible();
|
insilmaril@0
|
2052 |
}
|
insilmaril@0
|
2053 |
} else
|
insilmaril@0
|
2054 |
{
|
insilmaril@0
|
2055 |
if (typeid(*selection) == typeid(BranchObj) )
|
insilmaril@0
|
2056 |
{
|
insilmaril@0
|
2057 |
bo=((BranchObj*)(selection))->getLastSelectedBranch();
|
insilmaril@0
|
2058 |
if (bo)
|
insilmaril@0
|
2059 |
{
|
insilmaril@0
|
2060 |
selection->unselect();
|
insilmaril@0
|
2061 |
selection=bo;
|
insilmaril@0
|
2062 |
selection->select();
|
insilmaril@0
|
2063 |
adjustCanvasSize();
|
insilmaril@0
|
2064 |
ensureSelectionVisible();
|
insilmaril@0
|
2065 |
}
|
insilmaril@0
|
2066 |
}
|
insilmaril@0
|
2067 |
}
|
insilmaril@0
|
2068 |
}
|
insilmaril@0
|
2069 |
}
|
insilmaril@0
|
2070 |
}
|
insilmaril@0
|
2071 |
|
insilmaril@0
|
2072 |
void MapEditor::selectFirstBranch()
|
insilmaril@0
|
2073 |
{
|
insilmaril@0
|
2074 |
// Finish open lineEdits
|
insilmaril@0
|
2075 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
2076 |
|
insilmaril@0
|
2077 |
BranchObj *bo1;
|
insilmaril@0
|
2078 |
BranchObj *bo2;
|
insilmaril@0
|
2079 |
BranchObj* par;
|
insilmaril@0
|
2080 |
if (selection) {
|
insilmaril@0
|
2081 |
if (typeid(*selection) == typeid(BranchObj))
|
insilmaril@0
|
2082 |
{
|
insilmaril@0
|
2083 |
bo1= (BranchObj*) (selection);
|
insilmaril@0
|
2084 |
par=(BranchObj*)(bo1->getParObj());
|
insilmaril@0
|
2085 |
bo2=par->getFirstBranch();
|
insilmaril@0
|
2086 |
if (bo2) {
|
insilmaril@0
|
2087 |
bo1->unselect();
|
insilmaril@0
|
2088 |
selection=bo2;
|
insilmaril@0
|
2089 |
selection->select();
|
insilmaril@0
|
2090 |
ensureSelectionVisible();
|
insilmaril@0
|
2091 |
}
|
insilmaril@0
|
2092 |
}
|
insilmaril@0
|
2093 |
adjustCanvasSize();
|
insilmaril@0
|
2094 |
}
|
insilmaril@0
|
2095 |
}
|
insilmaril@0
|
2096 |
|
insilmaril@0
|
2097 |
void MapEditor::selectLastBranch()
|
insilmaril@0
|
2098 |
{
|
insilmaril@0
|
2099 |
// Finish open lineEdits
|
insilmaril@0
|
2100 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
2101 |
|
insilmaril@0
|
2102 |
BranchObj *bo1;
|
insilmaril@0
|
2103 |
BranchObj *bo2;
|
insilmaril@0
|
2104 |
BranchObj* par;
|
insilmaril@0
|
2105 |
if (selection) {
|
insilmaril@0
|
2106 |
if (typeid(*selection) == typeid(BranchObj))
|
insilmaril@0
|
2107 |
{
|
insilmaril@0
|
2108 |
bo1= (BranchObj*) (selection);
|
insilmaril@0
|
2109 |
par=(BranchObj*)(bo1->getParObj());
|
insilmaril@0
|
2110 |
bo2=par->getLastBranch();
|
insilmaril@0
|
2111 |
if (bo2) {
|
insilmaril@0
|
2112 |
bo1->unselect();
|
insilmaril@0
|
2113 |
selection=bo2;
|
insilmaril@0
|
2114 |
selection->select();
|
insilmaril@0
|
2115 |
ensureSelectionVisible();
|
insilmaril@0
|
2116 |
}
|
insilmaril@0
|
2117 |
}
|
insilmaril@0
|
2118 |
adjustCanvasSize();
|
insilmaril@0
|
2119 |
}
|
insilmaril@0
|
2120 |
}
|
insilmaril@0
|
2121 |
|
insilmaril@0
|
2122 |
void MapEditor::setColor(QColor c)
|
insilmaril@0
|
2123 |
{
|
insilmaril@0
|
2124 |
actColor=c;
|
insilmaril@0
|
2125 |
}
|
insilmaril@0
|
2126 |
|
insilmaril@0
|
2127 |
void MapEditor::selectBackgroundColor()
|
insilmaril@0
|
2128 |
{
|
insilmaril@0
|
2129 |
// Finish open lineEdits
|
insilmaril@0
|
2130 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
2131 |
|
insilmaril@0
|
2132 |
QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
|
insilmaril@0
|
2133 |
if ( !col.isValid() ) return;
|
insilmaril@0
|
2134 |
setBackgroundColor( col );
|
insilmaril@131
|
2135 |
saveState();
|
insilmaril@0
|
2136 |
}
|
insilmaril@0
|
2137 |
|
insilmaril@0
|
2138 |
void MapEditor::setBackgroundColor(QColor c)
|
insilmaril@0
|
2139 |
{
|
insilmaril@0
|
2140 |
mapCanvas->setBackgroundColor (c);
|
insilmaril@0
|
2141 |
}
|
insilmaril@0
|
2142 |
|
insilmaril@0
|
2143 |
QColor MapEditor::pickColor()
|
insilmaril@0
|
2144 |
{
|
insilmaril@0
|
2145 |
if (selection)
|
insilmaril@0
|
2146 |
{
|
insilmaril@0
|
2147 |
if (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2148 |
typeid(*selection) == typeid(MapCenterObj))
|
insilmaril@0
|
2149 |
{
|
insilmaril@0
|
2150 |
BranchObj *bo=(BranchObj*)(selection);
|
insilmaril@0
|
2151 |
actColor=bo->getColor();
|
insilmaril@0
|
2152 |
}
|
insilmaril@0
|
2153 |
}
|
insilmaril@0
|
2154 |
return actColor;
|
insilmaril@0
|
2155 |
}
|
insilmaril@0
|
2156 |
|
insilmaril@0
|
2157 |
void MapEditor::colorItem()
|
insilmaril@0
|
2158 |
{
|
insilmaril@0
|
2159 |
if (selection)
|
insilmaril@0
|
2160 |
{
|
insilmaril@0
|
2161 |
if (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2162 |
typeid(*selection) == typeid(MapCenterObj))
|
insilmaril@0
|
2163 |
{
|
insilmaril@106
|
2164 |
saveState(selection);
|
insilmaril@0
|
2165 |
BranchObj *bo=(BranchObj*)(selection);
|
insilmaril@0
|
2166 |
bo->setColor(actColor, false); // color links, color childs
|
insilmaril@0
|
2167 |
}
|
insilmaril@0
|
2168 |
}
|
insilmaril@0
|
2169 |
}
|
insilmaril@0
|
2170 |
|
insilmaril@0
|
2171 |
void MapEditor::colorBranch()
|
insilmaril@0
|
2172 |
{
|
insilmaril@0
|
2173 |
if (selection)
|
insilmaril@0
|
2174 |
{
|
insilmaril@0
|
2175 |
if (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2176 |
typeid(*selection) == typeid(MapCenterObj))
|
insilmaril@0
|
2177 |
{
|
insilmaril@106
|
2178 |
saveState(selection);
|
insilmaril@0
|
2179 |
BranchObj *bo=(BranchObj*)(selection);
|
insilmaril@0
|
2180 |
bo->setColor(actColor, true); // color links, color childs
|
insilmaril@0
|
2181 |
}
|
insilmaril@0
|
2182 |
}
|
insilmaril@0
|
2183 |
}
|
insilmaril@0
|
2184 |
|
insilmaril@0
|
2185 |
|
insilmaril@0
|
2186 |
void MapEditor::toggleStandardFlag(QString f)
|
insilmaril@0
|
2187 |
{
|
insilmaril@0
|
2188 |
if (selection)
|
insilmaril@0
|
2189 |
{
|
insilmaril@106
|
2190 |
saveState(selection);
|
insilmaril@103
|
2191 |
((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
|
insilmaril@0
|
2192 |
}
|
insilmaril@0
|
2193 |
}
|
insilmaril@0
|
2194 |
|
insilmaril@0
|
2195 |
void MapEditor::setViewCenter()
|
insilmaril@0
|
2196 |
{
|
insilmaril@0
|
2197 |
// transform to CanvasView Coord:
|
insilmaril@0
|
2198 |
QPoint p=worldMatrix().map(movingCenter);
|
insilmaril@0
|
2199 |
center ( p.x(), p.y());
|
insilmaril@0
|
2200 |
}
|
insilmaril@0
|
2201 |
|
insilmaril@0
|
2202 |
|
insilmaril@0
|
2203 |
BranchObj* MapEditor::findText (QString s, bool cs)
|
insilmaril@0
|
2204 |
{
|
insilmaril@0
|
2205 |
if (!itFind)
|
insilmaril@0
|
2206 |
{ // Nothing found or new find process
|
insilmaril@0
|
2207 |
if (EOFind)
|
insilmaril@0
|
2208 |
// nothing found, start again
|
insilmaril@0
|
2209 |
EOFind=false;
|
insilmaril@0
|
2210 |
itFind=mapCenter->first();
|
insilmaril@0
|
2211 |
}
|
insilmaril@0
|
2212 |
bool searching=true;
|
insilmaril@0
|
2213 |
bool foundNote=false;
|
insilmaril@0
|
2214 |
while (searching && !EOFind)
|
insilmaril@0
|
2215 |
{
|
insilmaril@0
|
2216 |
if (itFind)
|
insilmaril@0
|
2217 |
{
|
insilmaril@0
|
2218 |
// Searching in Note
|
insilmaril@0
|
2219 |
if (itFind->getNote().contains(s,cs))
|
insilmaril@0
|
2220 |
{
|
insilmaril@0
|
2221 |
if (selection!=itFind)
|
insilmaril@0
|
2222 |
{
|
insilmaril@0
|
2223 |
if (selection) ((BranchObj*)(selection))->unselect();
|
insilmaril@0
|
2224 |
selection=itFind;
|
insilmaril@0
|
2225 |
selection->select();
|
insilmaril@0
|
2226 |
adjustCanvasSize();
|
insilmaril@0
|
2227 |
ensureSelectionVisible();
|
insilmaril@0
|
2228 |
}
|
insilmaril@0
|
2229 |
if (textEditor->findText(s,cs))
|
insilmaril@0
|
2230 |
{
|
insilmaril@0
|
2231 |
searching=false;
|
insilmaril@0
|
2232 |
foundNote=true;
|
insilmaril@0
|
2233 |
}
|
insilmaril@0
|
2234 |
}
|
insilmaril@0
|
2235 |
// Searching in Heading
|
insilmaril@0
|
2236 |
if (searching && itFind->getHeading().contains (s,cs) )
|
insilmaril@0
|
2237 |
{
|
insilmaril@0
|
2238 |
if (selection) ((BranchObj*)(selection))->unselect();
|
insilmaril@0
|
2239 |
selection=itFind;
|
insilmaril@0
|
2240 |
selection->select();
|
insilmaril@0
|
2241 |
adjustCanvasSize();
|
insilmaril@0
|
2242 |
ensureSelectionVisible();
|
insilmaril@0
|
2243 |
searching=false;
|
insilmaril@0
|
2244 |
}
|
insilmaril@0
|
2245 |
}
|
insilmaril@0
|
2246 |
if (!foundNote)
|
insilmaril@0
|
2247 |
{
|
insilmaril@0
|
2248 |
itFind=itFind->next();
|
insilmaril@0
|
2249 |
if (!itFind) EOFind=true;
|
insilmaril@0
|
2250 |
}
|
insilmaril@0
|
2251 |
}
|
insilmaril@0
|
2252 |
if (!searching)
|
insilmaril@0
|
2253 |
{
|
insilmaril@0
|
2254 |
adjustCanvasSize();
|
insilmaril@0
|
2255 |
return (BranchObj*)(selection);
|
insilmaril@0
|
2256 |
} else
|
insilmaril@0
|
2257 |
return NULL;
|
insilmaril@0
|
2258 |
}
|
insilmaril@0
|
2259 |
|
insilmaril@0
|
2260 |
void MapEditor::findReset()
|
insilmaril@0
|
2261 |
{ // Necessary if text to find changes during a find process
|
insilmaril@0
|
2262 |
itFind=NULL;
|
insilmaril@0
|
2263 |
EOFind=false;
|
insilmaril@0
|
2264 |
}
|
insilmaril@0
|
2265 |
|
insilmaril@0
|
2266 |
void MapEditor::openURL()
|
insilmaril@0
|
2267 |
{
|
insilmaril@0
|
2268 |
if (selection )
|
insilmaril@0
|
2269 |
{
|
insilmaril@0
|
2270 |
if (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2271 |
typeid(*selection) == typeid(MapCenterObj))
|
insilmaril@0
|
2272 |
{
|
insilmaril@0
|
2273 |
QString url=((BranchObj*)(selection))->getURL();
|
insilmaril@0
|
2274 |
|
insilmaril@0
|
2275 |
QProcess *proc = new QProcess( this );
|
insilmaril@0
|
2276 |
|
insilmaril@0
|
2277 |
#if !defined(Q_OS_MACX)
|
insilmaril@0
|
2278 |
proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
|
insilmaril@0
|
2279 |
#else
|
insilmaril@0
|
2280 |
proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
|
insilmaril@0
|
2281 |
"/Applications/Safari.app/Contents/MacOS/Safari" ));
|
insilmaril@0
|
2282 |
#endif
|
insilmaril@0
|
2283 |
|
insilmaril@0
|
2284 |
proc->addArgument( url);
|
insilmaril@0
|
2285 |
|
insilmaril@0
|
2286 |
if ( !proc->start() )
|
insilmaril@0
|
2287 |
// error handling
|
insilmaril@0
|
2288 |
if (mainWindow->settingsURL() )
|
insilmaril@0
|
2289 |
openURL();
|
insilmaril@0
|
2290 |
}
|
insilmaril@0
|
2291 |
}
|
insilmaril@0
|
2292 |
}
|
insilmaril@0
|
2293 |
|
insilmaril@0
|
2294 |
void MapEditor::editURL()
|
insilmaril@0
|
2295 |
{
|
insilmaril@0
|
2296 |
if (selection && (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2297 |
typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2298 |
{
|
insilmaril@0
|
2299 |
bool ok;
|
insilmaril@0
|
2300 |
QString text = QInputDialog::getText(
|
insilmaril@0
|
2301 |
"VYM", tr("Enter URL:"), QLineEdit::Normal,
|
insilmaril@0
|
2302 |
((BranchObj*)(selection))->getURL(), &ok, this );
|
insilmaril@0
|
2303 |
if ( ok)
|
insilmaril@0
|
2304 |
{
|
insilmaril@0
|
2305 |
// user entered something and pressed OK
|
insilmaril@0
|
2306 |
((BranchObj*)(selection))->setURL (text);
|
insilmaril@0
|
2307 |
updateActions();
|
insilmaril@131
|
2308 |
saveState(); //FIXME undoCommand
|
insilmaril@0
|
2309 |
}
|
insilmaril@0
|
2310 |
}
|
insilmaril@0
|
2311 |
}
|
insilmaril@0
|
2312 |
|
insilmaril@0
|
2313 |
void MapEditor::editHeading2URL()
|
insilmaril@0
|
2314 |
{
|
insilmaril@0
|
2315 |
if (selection && (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2316 |
typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2317 |
{
|
insilmaril@0
|
2318 |
BranchObj *b=(BranchObj*)(selection);
|
insilmaril@0
|
2319 |
b->setURL (b->getHeading());
|
insilmaril@0
|
2320 |
updateActions();
|
insilmaril@131
|
2321 |
saveState(); //FIXME undoCommand
|
insilmaril@0
|
2322 |
}
|
insilmaril@0
|
2323 |
}
|
insilmaril@0
|
2324 |
|
insilmaril@0
|
2325 |
void MapEditor::editBugzilla2URL()
|
insilmaril@0
|
2326 |
{
|
insilmaril@0
|
2327 |
if (selection && (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2328 |
typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2329 |
{
|
insilmaril@0
|
2330 |
BranchObj *b=(BranchObj*)(selection);
|
insilmaril@95
|
2331 |
b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
|
insilmaril@0
|
2332 |
updateActions();
|
insilmaril@131
|
2333 |
saveState(); //FIXME undoCommand
|
insilmaril@0
|
2334 |
}
|
insilmaril@0
|
2335 |
}
|
insilmaril@0
|
2336 |
|
insilmaril@0
|
2337 |
void MapEditor::editVymLink()
|
insilmaril@0
|
2338 |
{
|
insilmaril@0
|
2339 |
if (selection && (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2340 |
typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2341 |
{
|
insilmaril@0
|
2342 |
QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
|
insilmaril@0
|
2343 |
fd->addFilter (QString (tr("vym map") + " (*.vym)"));
|
insilmaril@0
|
2344 |
fd->setCaption(tr("VYM - Link to another map"));
|
insilmaril@0
|
2345 |
if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
|
insilmaril@0
|
2346 |
fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
|
insilmaril@0
|
2347 |
fd->show();
|
insilmaril@0
|
2348 |
|
insilmaril@0
|
2349 |
QString fn;
|
insilmaril@0
|
2350 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
2351 |
((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
|
insilmaril@0
|
2352 |
updateActions();
|
insilmaril@0
|
2353 |
mapCenter->reposition();
|
insilmaril@0
|
2354 |
adjustCanvasSize();
|
insilmaril@0
|
2355 |
canvas()->update();
|
insilmaril@131
|
2356 |
saveState(); //FIXME undoCommand
|
insilmaril@0
|
2357 |
}
|
insilmaril@0
|
2358 |
}
|
insilmaril@0
|
2359 |
|
insilmaril@0
|
2360 |
void MapEditor::deleteVymLink()
|
insilmaril@0
|
2361 |
{
|
insilmaril@0
|
2362 |
if (selection && (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2363 |
typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2364 |
{
|
insilmaril@0
|
2365 |
((BranchObj*)(selection))->setVymLink ("" );
|
insilmaril@0
|
2366 |
updateActions();
|
insilmaril@0
|
2367 |
mapCenter->reposition();
|
insilmaril@0
|
2368 |
adjustCanvasSize();
|
insilmaril@0
|
2369 |
canvas()->update();
|
insilmaril@131
|
2370 |
saveState(); //FIXME undoCommand
|
insilmaril@0
|
2371 |
}
|
insilmaril@0
|
2372 |
}
|
insilmaril@0
|
2373 |
|
insilmaril@0
|
2374 |
QString MapEditor::getVymLink()
|
insilmaril@0
|
2375 |
{
|
insilmaril@0
|
2376 |
if (selection && (typeid(*selection) == typeid(BranchObj) ||
|
insilmaril@0
|
2377 |
typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2378 |
{
|
insilmaril@0
|
2379 |
return ((BranchObj*)(selection))->getVymLink();
|
insilmaril@0
|
2380 |
}
|
insilmaril@0
|
2381 |
return "";
|
insilmaril@0
|
2382 |
|
insilmaril@0
|
2383 |
}
|
insilmaril@0
|
2384 |
|
insilmaril@98
|
2385 |
void MapEditor::removeBranchHere()
|
insilmaril@98
|
2386 |
{
|
insilmaril@98
|
2387 |
if (selection && (typeid(*selection) == typeid(BranchObj) ))
|
insilmaril@98
|
2388 |
{
|
insilmaril@98
|
2389 |
BranchObj* bo=(BranchObj*)(selection);
|
insilmaril@98
|
2390 |
BranchObj* par=(BranchObj*)(bo->getParObj());
|
insilmaril@139
|
2391 |
if (bo->getDepth()==1)
|
insilmaril@139
|
2392 |
saveState();
|
insilmaril@139
|
2393 |
else
|
insilmaril@139
|
2394 |
saveState(selection->getParObj()); // FIXME undoCommand
|
insilmaril@139
|
2395 |
QString sel=selection->getSelectString();
|
insilmaril@98
|
2396 |
unselect();
|
insilmaril@98
|
2397 |
par->removeBranchHere(bo);
|
insilmaril@98
|
2398 |
mapCenter->reposition();
|
insilmaril@98
|
2399 |
select (sel);
|
insilmaril@98
|
2400 |
}
|
insilmaril@98
|
2401 |
}
|
insilmaril@98
|
2402 |
|
insilmaril@98
|
2403 |
void MapEditor::removeChilds()
|
insilmaril@98
|
2404 |
{
|
insilmaril@98
|
2405 |
if (selection && (typeid(*selection) == typeid(BranchObj) ))
|
insilmaril@98
|
2406 |
{
|
insilmaril@106
|
2407 |
saveState(selection->getParObj());
|
insilmaril@98
|
2408 |
((BranchObj*)(selection))->removeChilds();
|
insilmaril@98
|
2409 |
mapCenter->reposition();
|
insilmaril@98
|
2410 |
}
|
insilmaril@98
|
2411 |
}
|
insilmaril@98
|
2412 |
|
insilmaril@0
|
2413 |
void MapEditor::editMapInfo()
|
insilmaril@0
|
2414 |
{
|
insilmaril@0
|
2415 |
ExtraInfoDialog dia;
|
insilmaril@0
|
2416 |
dia.setMapName (getFileName() );
|
insilmaril@0
|
2417 |
dia.setAuthor (mapCenter->getAuthor() );
|
insilmaril@0
|
2418 |
dia.setComment(mapCenter->getComment() );
|
insilmaril@0
|
2419 |
|
insilmaril@0
|
2420 |
// Calc some stats
|
insilmaril@0
|
2421 |
QString stats;
|
insilmaril@0
|
2422 |
int i=0;
|
insilmaril@0
|
2423 |
QCanvasItemList l=canvas()->allItems();
|
insilmaril@0
|
2424 |
for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
|
insilmaril@0
|
2425 |
i++;
|
insilmaril@0
|
2426 |
stats+=QString ("%1 items on canvas\n").arg (i,6);
|
insilmaril@0
|
2427 |
|
insilmaril@0
|
2428 |
uint b=0;
|
insilmaril@0
|
2429 |
uint f=0;
|
insilmaril@0
|
2430 |
uint n=0;
|
insilmaril@103
|
2431 |
uint xl=0;
|
insilmaril@0
|
2432 |
BranchObj *bo;
|
insilmaril@0
|
2433 |
bo=mapCenter->first();
|
insilmaril@0
|
2434 |
while (bo)
|
insilmaril@0
|
2435 |
{
|
insilmaril@0
|
2436 |
if (!bo->getNote().isEmpty() ) n++;
|
insilmaril@0
|
2437 |
f+= bo->countFloatImages();
|
insilmaril@0
|
2438 |
b++;
|
insilmaril@103
|
2439 |
xl+=bo->countXLinks();
|
insilmaril@0
|
2440 |
bo=bo->next();
|
insilmaril@0
|
2441 |
}
|
insilmaril@0
|
2442 |
stats+=QString ("%1 branches\n").arg (b-1,6);
|
insilmaril@104
|
2443 |
stats+=QString ("%1 xLinks \n").arg (xl,6);
|
insilmaril@0
|
2444 |
stats+=QString ("%1 notes\n").arg (n,6);
|
insilmaril@0
|
2445 |
stats+=QString ("%1 images\n").arg (f,6);
|
insilmaril@0
|
2446 |
dia.setStats (stats);
|
insilmaril@0
|
2447 |
|
insilmaril@0
|
2448 |
// Finally show dialog
|
insilmaril@0
|
2449 |
if (dia.exec() == QDialog::Accepted)
|
insilmaril@0
|
2450 |
{
|
insilmaril@139
|
2451 |
saveState(); //FIXME undoCommand
|
insilmaril@0
|
2452 |
mapCenter->setAuthor (dia.getAuthor() );
|
insilmaril@0
|
2453 |
mapCenter->setComment (dia.getComment() );
|
insilmaril@0
|
2454 |
}
|
insilmaril@0
|
2455 |
}
|
insilmaril@0
|
2456 |
|
insilmaril@0
|
2457 |
void MapEditor::updateActions()
|
insilmaril@0
|
2458 |
{
|
insilmaril@98
|
2459 |
QAction *a;
|
insilmaril@0
|
2460 |
if (getLinkColorHint()==HeadingColor)
|
insilmaril@0
|
2461 |
actionFormatLinkColorHint->setOn(true);
|
insilmaril@0
|
2462 |
else
|
insilmaril@0
|
2463 |
actionFormatLinkColorHint->setOn(false);
|
insilmaril@0
|
2464 |
|
insilmaril@0
|
2465 |
switch (linkstyle)
|
insilmaril@0
|
2466 |
{
|
insilmaril@0
|
2467 |
case StyleLine:
|
insilmaril@0
|
2468 |
actionFormatLinkStyleLine->setOn(true);
|
insilmaril@0
|
2469 |
break;
|
insilmaril@0
|
2470 |
case StyleParabel:
|
insilmaril@0
|
2471 |
actionFormatLinkStyleParabel->setOn(true);
|
insilmaril@0
|
2472 |
break;
|
insilmaril@0
|
2473 |
case StylePolyLine:
|
insilmaril@0
|
2474 |
actionFormatLinkStylePolyLine->setOn(true);
|
insilmaril@0
|
2475 |
break;
|
insilmaril@0
|
2476 |
case StylePolyParabel:
|
insilmaril@0
|
2477 |
actionFormatLinkStylePolyParabel->setOn(true);
|
insilmaril@0
|
2478 |
break;
|
insilmaril@0
|
2479 |
default:
|
insilmaril@0
|
2480 |
break;
|
insilmaril@0
|
2481 |
}
|
insilmaril@0
|
2482 |
|
insilmaril@0
|
2483 |
QPixmap pix( 16, 16 );
|
insilmaril@0
|
2484 |
pix.fill( mapCanvas->backgroundColor() );
|
insilmaril@0
|
2485 |
actionFormatBackColor->setIconSet( pix );
|
insilmaril@97
|
2486 |
pix.fill( defLinkColor );
|
insilmaril@0
|
2487 |
actionFormatLinkColor->setIconSet( pix );
|
insilmaril@0
|
2488 |
|
insilmaril@0
|
2489 |
actionEditUndo->setEnabled( mapChanged );
|
insilmaril@0
|
2490 |
actionFileSave->setEnabled( mapUnsaved );
|
insilmaril@0
|
2491 |
|
insilmaril@0
|
2492 |
if (selection)
|
insilmaril@0
|
2493 |
{
|
insilmaril@0
|
2494 |
if ( (typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@0
|
2495 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2496 |
{
|
insilmaril@89
|
2497 |
BranchObj *bo=(BranchObj*)(selection);
|
insilmaril@89
|
2498 |
// Take care of links
|
insilmaril@95
|
2499 |
if (bo->countXLinks()==0)
|
insilmaril@89
|
2500 |
{
|
insilmaril@89
|
2501 |
branchLinksContextMenu->clear();
|
insilmaril@125
|
2502 |
branchLinksContextMenu->insertItem ("No xLink available");
|
insilmaril@94
|
2503 |
branchLinksContextMenuDup->clear();
|
insilmaril@125
|
2504 |
branchLinksContextMenuDup->insertItem ("No xLink available");
|
insilmaril@89
|
2505 |
|
insilmaril@89
|
2506 |
} else
|
insilmaril@89
|
2507 |
{
|
insilmaril@89
|
2508 |
BranchObj *bot;
|
insilmaril@89
|
2509 |
QString s;
|
insilmaril@89
|
2510 |
branchLinksContextMenu->clear();
|
insilmaril@94
|
2511 |
branchLinksContextMenuDup->clear();
|
insilmaril@95
|
2512 |
for (int i=0; i<=bo->countXLinks();i++)
|
insilmaril@89
|
2513 |
{
|
insilmaril@95
|
2514 |
bot=bo->XLinkTargetAt(i);
|
insilmaril@89
|
2515 |
if (bot)
|
insilmaril@89
|
2516 |
{
|
insilmaril@89
|
2517 |
s=bot->getHeading();
|
insilmaril@89
|
2518 |
if (s.length()>25)
|
insilmaril@89
|
2519 |
s=s.left(25)+"...";
|
insilmaril@89
|
2520 |
branchLinksContextMenu->insertItem (s);
|
insilmaril@94
|
2521 |
branchLinksContextMenuDup->insertItem (s);
|
insilmaril@89
|
2522 |
}
|
insilmaril@89
|
2523 |
}
|
insilmaril@89
|
2524 |
}
|
insilmaril@89
|
2525 |
|
insilmaril@0
|
2526 |
standardFlagsDefault->setEnabled (true);
|
insilmaril@0
|
2527 |
|
insilmaril@89
|
2528 |
if ( bo->getURL().isEmpty() )
|
insilmaril@0
|
2529 |
actionEditOpenURL->setEnabled (false);
|
insilmaril@0
|
2530 |
else
|
insilmaril@0
|
2531 |
actionEditOpenURL->setEnabled (true);
|
insilmaril@0
|
2532 |
|
insilmaril@89
|
2533 |
if ( bo->getVymLink().isEmpty() )
|
insilmaril@0
|
2534 |
{
|
insilmaril@0
|
2535 |
actionEditOpenVymLink->setEnabled (false);
|
insilmaril@0
|
2536 |
actionEditDeleteVymLink->setEnabled (false);
|
insilmaril@0
|
2537 |
} else
|
insilmaril@0
|
2538 |
{
|
insilmaril@0
|
2539 |
actionEditOpenVymLink->setEnabled (true);
|
insilmaril@0
|
2540 |
actionEditDeleteVymLink->setEnabled (true);
|
insilmaril@0
|
2541 |
}
|
insilmaril@0
|
2542 |
|
insilmaril@0
|
2543 |
actionEditCopy->setEnabled (true);
|
insilmaril@0
|
2544 |
actionEditCut->setEnabled (true);
|
insilmaril@119
|
2545 |
if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
|
insilmaril@119
|
2546 |
actionEditPaste->setEnabled (true);
|
insilmaril@119
|
2547 |
else
|
insilmaril@119
|
2548 |
actionEditPaste->setEnabled (false);
|
insilmaril@119
|
2549 |
for (a=actionListBranches.first();a;a=actionListBranches.next())
|
insilmaril@119
|
2550 |
a->setEnabled(true);
|
insilmaril@0
|
2551 |
actionEditDelete->setEnabled (true);
|
insilmaril@0
|
2552 |
actionEditToggleFloatExport->setEnabled (false);
|
insilmaril@0
|
2553 |
switch (selection->getFrameType())
|
insilmaril@0
|
2554 |
{
|
insilmaril@0
|
2555 |
case NoFrame:
|
insilmaril@0
|
2556 |
actionFormatFrameNone->setOn(true);
|
insilmaril@0
|
2557 |
break;
|
insilmaril@0
|
2558 |
case Rectangle:
|
insilmaril@0
|
2559 |
actionFormatFrameRectangle->setOn(true);
|
insilmaril@0
|
2560 |
break;
|
insilmaril@0
|
2561 |
default:
|
insilmaril@0
|
2562 |
break;
|
insilmaril@0
|
2563 |
}
|
insilmaril@0
|
2564 |
}
|
insilmaril@0
|
2565 |
if ( (typeid(*selection) == typeid(FloatImageObj)) )
|
insilmaril@0
|
2566 |
{
|
insilmaril@0
|
2567 |
standardFlagsDefault->setEnabled (false);
|
insilmaril@0
|
2568 |
|
insilmaril@0
|
2569 |
actionEditOpenURL->setEnabled (false);
|
insilmaril@0
|
2570 |
actionEditOpenVymLink->setEnabled (false);
|
insilmaril@0
|
2571 |
actionEditDeleteVymLink->setEnabled (false);
|
insilmaril@0
|
2572 |
|
insilmaril@0
|
2573 |
actionEditCopy->setEnabled (true);
|
insilmaril@0
|
2574 |
actionEditCut->setEnabled (true);
|
insilmaril@0
|
2575 |
actionEditPaste->setEnabled (false); //FIXME
|
insilmaril@98
|
2576 |
for (a=actionListBranches.first();a;a=actionListBranches.next())
|
insilmaril@98
|
2577 |
a->setEnabled(false);
|
insilmaril@0
|
2578 |
actionEditDelete->setEnabled (true);
|
insilmaril@0
|
2579 |
actionEditToggleFloatExport->setOn
|
insilmaril@0
|
2580 |
( ((FloatImageObj*)(selection))->getFloatExport() );
|
insilmaril@0
|
2581 |
}
|
insilmaril@0
|
2582 |
|
insilmaril@0
|
2583 |
} else
|
insilmaril@0
|
2584 |
{
|
insilmaril@0
|
2585 |
standardFlagsDefault->setEnabled (false);
|
insilmaril@0
|
2586 |
|
insilmaril@0
|
2587 |
actionEditCopy->setEnabled (false);
|
insilmaril@0
|
2588 |
actionEditCut->setEnabled (false);
|
insilmaril@0
|
2589 |
actionEditPaste->setEnabled (false);
|
insilmaril@98
|
2590 |
for (a=actionListBranches.first();a;a=actionListBranches.next())
|
insilmaril@98
|
2591 |
a->setEnabled(false);
|
insilmaril@98
|
2592 |
|
insilmaril@0
|
2593 |
actionEditOpenURL->setEnabled (false);
|
insilmaril@0
|
2594 |
actionEditOpenVymLink->setEnabled (false);
|
insilmaril@0
|
2595 |
actionEditDeleteVymLink->setEnabled (false);
|
insilmaril@0
|
2596 |
actionEditHeading2URL->setEnabled (false);
|
insilmaril@0
|
2597 |
actionEditDelete->setEnabled (false);
|
insilmaril@0
|
2598 |
actionEditToggleFloatExport->setEnabled (false);
|
insilmaril@0
|
2599 |
}
|
insilmaril@0
|
2600 |
}
|
insilmaril@0
|
2601 |
|
insilmaril@0
|
2602 |
void MapEditor::setLinkStyle (LinkStyle ls)
|
insilmaril@0
|
2603 |
{
|
insilmaril@0
|
2604 |
linkstyle=ls;
|
insilmaril@0
|
2605 |
|
insilmaril@139
|
2606 |
saveState(); // FIXME undoCommand
|
insilmaril@0
|
2607 |
BranchObj *bo;
|
insilmaril@0
|
2608 |
bo=mapCenter->first();
|
insilmaril@0
|
2609 |
bo=bo->next();
|
insilmaril@0
|
2610 |
while (bo)
|
insilmaril@0
|
2611 |
{
|
insilmaril@0
|
2612 |
bo->setLinkStyle(bo->getDefLinkStyle());
|
insilmaril@0
|
2613 |
bo=bo->next();
|
insilmaril@0
|
2614 |
}
|
insilmaril@102
|
2615 |
mapCenter->reposition();
|
insilmaril@0
|
2616 |
}
|
insilmaril@0
|
2617 |
|
insilmaril@0
|
2618 |
LinkStyle MapEditor::getLinkStyle ()
|
insilmaril@0
|
2619 |
{
|
insilmaril@0
|
2620 |
return linkstyle;
|
insilmaril@0
|
2621 |
}
|
insilmaril@0
|
2622 |
|
insilmaril@0
|
2623 |
void MapEditor::setLinkColor(QColor c)
|
insilmaril@0
|
2624 |
{
|
insilmaril@97
|
2625 |
defLinkColor=c;
|
insilmaril@0
|
2626 |
updateActions();
|
insilmaril@0
|
2627 |
}
|
insilmaril@0
|
2628 |
|
insilmaril@0
|
2629 |
void MapEditor::setLinkColorHint()
|
insilmaril@0
|
2630 |
{
|
insilmaril@0
|
2631 |
// called from setLinkColorHint(lch) or at end of parse
|
insilmaril@0
|
2632 |
BranchObj *bo;
|
insilmaril@0
|
2633 |
bo=mapCenter->first();
|
insilmaril@0
|
2634 |
while (bo)
|
insilmaril@0
|
2635 |
{
|
insilmaril@0
|
2636 |
bo->setLinkColor();
|
insilmaril@0
|
2637 |
bo=bo->next();
|
insilmaril@0
|
2638 |
}
|
insilmaril@0
|
2639 |
}
|
insilmaril@0
|
2640 |
|
insilmaril@0
|
2641 |
void MapEditor::setLinkColorHint(LinkColorHint lch)
|
insilmaril@0
|
2642 |
{
|
insilmaril@0
|
2643 |
linkcolorhint=lch;
|
insilmaril@0
|
2644 |
setLinkColorHint();
|
insilmaril@0
|
2645 |
}
|
insilmaril@0
|
2646 |
|
insilmaril@0
|
2647 |
void MapEditor::toggleLinkColorHint()
|
insilmaril@0
|
2648 |
{
|
insilmaril@0
|
2649 |
if (linkcolorhint==HeadingColor)
|
insilmaril@0
|
2650 |
linkcolorhint=DefaultColor;
|
insilmaril@0
|
2651 |
else
|
insilmaril@0
|
2652 |
linkcolorhint=HeadingColor;
|
insilmaril@0
|
2653 |
BranchObj *bo;
|
insilmaril@0
|
2654 |
bo=mapCenter->first();
|
insilmaril@0
|
2655 |
while (bo)
|
insilmaril@0
|
2656 |
{
|
insilmaril@0
|
2657 |
bo->setLinkColor();
|
insilmaril@0
|
2658 |
bo=bo->next();
|
insilmaril@0
|
2659 |
}
|
insilmaril@0
|
2660 |
}
|
insilmaril@0
|
2661 |
|
insilmaril@0
|
2662 |
LinkColorHint MapEditor::getLinkColorHint()
|
insilmaril@0
|
2663 |
{
|
insilmaril@0
|
2664 |
return linkcolorhint;
|
insilmaril@0
|
2665 |
}
|
insilmaril@0
|
2666 |
|
insilmaril@0
|
2667 |
QColor MapEditor::getDefLinkColor()
|
insilmaril@0
|
2668 |
{
|
insilmaril@97
|
2669 |
return defLinkColor;
|
insilmaril@97
|
2670 |
}
|
insilmaril@97
|
2671 |
|
insilmaril@97
|
2672 |
void MapEditor::setDefXLinkColor(QColor col)
|
insilmaril@97
|
2673 |
{
|
insilmaril@97
|
2674 |
defXLinkColor=col;
|
insilmaril@97
|
2675 |
}
|
insilmaril@97
|
2676 |
|
insilmaril@97
|
2677 |
QColor MapEditor::getDefXLinkColor()
|
insilmaril@97
|
2678 |
{
|
insilmaril@97
|
2679 |
return defXLinkColor;
|
insilmaril@97
|
2680 |
}
|
insilmaril@97
|
2681 |
|
insilmaril@97
|
2682 |
void MapEditor::setDefXLinkWidth (int w)
|
insilmaril@97
|
2683 |
{
|
insilmaril@97
|
2684 |
defXLinkWidth=w;
|
insilmaril@97
|
2685 |
}
|
insilmaril@97
|
2686 |
|
insilmaril@97
|
2687 |
int MapEditor::getDefXLinkWidth()
|
insilmaril@97
|
2688 |
{
|
insilmaril@97
|
2689 |
return defXLinkWidth;
|
insilmaril@0
|
2690 |
}
|
insilmaril@0
|
2691 |
|
insilmaril@0
|
2692 |
void MapEditor::selectLinkColor()
|
insilmaril@0
|
2693 |
{
|
insilmaril@0
|
2694 |
// Finish open lineEdits
|
insilmaril@0
|
2695 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
2696 |
|
insilmaril@97
|
2697 |
QColor col = QColorDialog::getColor( defLinkColor, this );
|
insilmaril@0
|
2698 |
if ( !col.isValid() ) return;
|
insilmaril@0
|
2699 |
setLinkColor( col );
|
insilmaril@131
|
2700 |
saveState(); //FIXME undoCommand
|
insilmaril@131
|
2701 |
|
insilmaril@0
|
2702 |
}
|
insilmaril@0
|
2703 |
|
insilmaril@0
|
2704 |
void MapEditor::toggleScroll()
|
insilmaril@0
|
2705 |
{
|
insilmaril@0
|
2706 |
if (selection && (typeid(*selection) == typeid(BranchObj)) )
|
insilmaril@0
|
2707 |
{
|
insilmaril@0
|
2708 |
BranchObj *bo=((BranchObj*)(selection));
|
insilmaril@0
|
2709 |
if (bo->countBranches()==0) return;
|
insilmaril@0
|
2710 |
if (bo->getDepth()==0) return;
|
insilmaril@106
|
2711 |
saveState(selection);
|
insilmaril@0
|
2712 |
bo->toggleScroll();
|
insilmaril@0
|
2713 |
adjustCanvasSize();
|
insilmaril@0
|
2714 |
canvas()->update();
|
insilmaril@0
|
2715 |
}
|
insilmaril@0
|
2716 |
}
|
insilmaril@0
|
2717 |
|
insilmaril@0
|
2718 |
void MapEditor::unScrollAll()
|
insilmaril@0
|
2719 |
{
|
insilmaril@0
|
2720 |
BranchObj *bo;
|
insilmaril@0
|
2721 |
bo=mapCenter->first();
|
insilmaril@0
|
2722 |
while (bo)
|
insilmaril@0
|
2723 |
{
|
insilmaril@0
|
2724 |
if (bo->isScrolled()) bo->toggleScroll();
|
insilmaril@0
|
2725 |
bo=bo->next();
|
insilmaril@0
|
2726 |
}
|
insilmaril@0
|
2727 |
}
|
insilmaril@0
|
2728 |
|
insilmaril@0
|
2729 |
void MapEditor::loadFloatImage ()
|
insilmaril@0
|
2730 |
{
|
insilmaril@0
|
2731 |
if (selection &&
|
insilmaril@0
|
2732 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@0
|
2733 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2734 |
{
|
insilmaril@0
|
2735 |
BranchObj *bo=((BranchObj*)(selection));
|
insilmaril@0
|
2736 |
|
insilmaril@0
|
2737 |
QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
|
insilmaril@0
|
2738 |
fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
|
insilmaril@0
|
2739 |
ImagePreview *p =new ImagePreview (fd);
|
insilmaril@0
|
2740 |
fd->setContentsPreviewEnabled( TRUE );
|
insilmaril@0
|
2741 |
fd->setContentsPreview( p, p );
|
insilmaril@0
|
2742 |
fd->setPreviewMode( QFileDialog::Contents );
|
insilmaril@0
|
2743 |
fd->setCaption(tr("vym - Load image"));
|
insilmaril@0
|
2744 |
fd->setDir (lastImageDir);
|
insilmaril@0
|
2745 |
fd->show();
|
insilmaril@0
|
2746 |
|
insilmaril@0
|
2747 |
QString fn;
|
insilmaril@0
|
2748 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
2749 |
{
|
insilmaril@106
|
2750 |
saveState(selection);
|
insilmaril@0
|
2751 |
QString fn=fd->selectedFile();
|
insilmaril@0
|
2752 |
lastImageDir=fn.left(fn.findRev ("/"));
|
insilmaril@0
|
2753 |
bo->addFloatImage();
|
insilmaril@0
|
2754 |
// FIXME check if load was successful
|
insilmaril@0
|
2755 |
bo->getLastFloatImage()->load(fn);
|
insilmaril@0
|
2756 |
bo->getLastFloatImage()->setOriginalFilename(fn);
|
insilmaril@0
|
2757 |
mapCenter->reposition();
|
insilmaril@0
|
2758 |
adjustCanvasSize();
|
insilmaril@0
|
2759 |
canvas()->update();
|
insilmaril@0
|
2760 |
}
|
insilmaril@0
|
2761 |
}
|
insilmaril@0
|
2762 |
}
|
insilmaril@0
|
2763 |
|
insilmaril@0
|
2764 |
void MapEditor::saveFloatImage (int item)
|
insilmaril@0
|
2765 |
{
|
insilmaril@0
|
2766 |
if (selection &&
|
insilmaril@0
|
2767 |
(typeid(*selection) == typeid(FloatImageObj)) )
|
insilmaril@0
|
2768 |
{
|
insilmaril@0
|
2769 |
FloatImageObj *fio=((FloatImageObj*)(selection));
|
insilmaril@0
|
2770 |
const char* fmt = saveImageFormatMenu->text(item);
|
insilmaril@0
|
2771 |
|
insilmaril@0
|
2772 |
QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
|
insilmaril@0
|
2773 |
fd->addFilter ("PNG (*.png)");
|
insilmaril@0
|
2774 |
fd->addFilter ("BMP (*.bmp)");
|
insilmaril@0
|
2775 |
fd->addFilter ("XBM (*.xbm)");
|
insilmaril@0
|
2776 |
fd->addFilter ("JPG (*.jpg)");
|
insilmaril@0
|
2777 |
fd->addFilter ("XPM (*.xpm)");
|
insilmaril@0
|
2778 |
fd->addFilter ("GIF (*.gif)");
|
insilmaril@0
|
2779 |
fd->addFilter ("PNM (*.pnm)");
|
insilmaril@0
|
2780 |
fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
|
insilmaril@0
|
2781 |
fd->setCaption(tr("vym - Save image as ") + fmt);
|
insilmaril@0
|
2782 |
fd->setMode( QFileDialog::AnyFile );
|
insilmaril@0
|
2783 |
fd->setSelection (fio->getOriginalFilename());
|
insilmaril@0
|
2784 |
fd->show();
|
insilmaril@0
|
2785 |
|
insilmaril@0
|
2786 |
QString fn;
|
insilmaril@0
|
2787 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
2788 |
{
|
insilmaril@0
|
2789 |
if (QFile (fd->selectedFile()).exists() )
|
insilmaril@0
|
2790 |
{
|
insilmaril@0
|
2791 |
QMessageBox mb( "VYM",
|
insilmaril@0
|
2792 |
tr("The file ") + fd->selectedFile() +
|
insilmaril@0
|
2793 |
tr(" exists already. "
|
insilmaril@0
|
2794 |
"Do you want to overwrite it?"),
|
insilmaril@0
|
2795 |
QMessageBox::Warning,
|
insilmaril@0
|
2796 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@0
|
2797 |
QMessageBox::Cancel | QMessageBox::Escape,
|
insilmaril@0
|
2798 |
QMessageBox::QMessageBox::NoButton );
|
insilmaril@0
|
2799 |
|
insilmaril@0
|
2800 |
mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
|
insilmaril@0
|
2801 |
mb.setButtonText( QMessageBox::No, tr("Cancel"));
|
insilmaril@0
|
2802 |
switch( mb.exec() )
|
insilmaril@0
|
2803 |
{
|
insilmaril@0
|
2804 |
case QMessageBox::Yes:
|
insilmaril@0
|
2805 |
// save
|
insilmaril@0
|
2806 |
break;;
|
insilmaril@0
|
2807 |
case QMessageBox::Cancel:
|
insilmaril@0
|
2808 |
// do nothing
|
insilmaril@0
|
2809 |
return;
|
insilmaril@0
|
2810 |
break;
|
insilmaril@0
|
2811 |
}
|
insilmaril@0
|
2812 |
}
|
insilmaril@0
|
2813 |
fio->save (fd->selectedFile(),fmt);
|
insilmaril@0
|
2814 |
}
|
insilmaril@0
|
2815 |
}
|
insilmaril@0
|
2816 |
}
|
insilmaril@0
|
2817 |
|
insilmaril@0
|
2818 |
void MapEditor::toggleFloatExport()
|
insilmaril@0
|
2819 |
{
|
insilmaril@0
|
2820 |
if (selection &&
|
insilmaril@0
|
2821 |
(typeid(*selection) == typeid(FloatImageObj))||
|
insilmaril@0
|
2822 |
(typeid(*selection) == typeid(FloatObj)) )
|
insilmaril@0
|
2823 |
{
|
insilmaril@0
|
2824 |
FloatImageObj *fio=((FloatImageObj*)(selection));
|
insilmaril@0
|
2825 |
fio->setFloatExport (actionEditToggleFloatExport->isOn() );
|
insilmaril@0
|
2826 |
}
|
insilmaril@0
|
2827 |
}
|
insilmaril@0
|
2828 |
|
insilmaril@0
|
2829 |
void MapEditor::setFrame(const FrameType &t)
|
insilmaril@0
|
2830 |
{
|
insilmaril@0
|
2831 |
if (selection &&
|
insilmaril@0
|
2832 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@0
|
2833 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2834 |
{
|
insilmaril@0
|
2835 |
selection->setFrameType (t);
|
insilmaril@0
|
2836 |
mapCenter->reposition();
|
insilmaril@0
|
2837 |
selection->updateLink();
|
insilmaril@0
|
2838 |
}
|
insilmaril@0
|
2839 |
}
|
insilmaril@0
|
2840 |
|
insilmaril@0
|
2841 |
void MapEditor::importDir(BranchObj *dst, QDir d)
|
insilmaril@0
|
2842 |
{
|
insilmaril@0
|
2843 |
if (selection &&
|
insilmaril@0
|
2844 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@0
|
2845 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2846 |
{
|
insilmaril@0
|
2847 |
BranchObj *bo;
|
insilmaril@0
|
2848 |
|
insilmaril@0
|
2849 |
// Traverse directories
|
insilmaril@0
|
2850 |
d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
|
insilmaril@0
|
2851 |
const QFileInfoList *dirlist = d.entryInfoList();
|
insilmaril@0
|
2852 |
QFileInfoListIterator itdir( *dirlist );
|
insilmaril@0
|
2853 |
QFileInfo *fi;
|
insilmaril@0
|
2854 |
|
insilmaril@0
|
2855 |
while ( (fi = itdir.current()) != 0 )
|
insilmaril@0
|
2856 |
{
|
insilmaril@0
|
2857 |
if (fi->fileName() != "." && fi->fileName() != ".." )
|
insilmaril@0
|
2858 |
{
|
insilmaril@0
|
2859 |
dst->addBranch();
|
insilmaril@0
|
2860 |
bo=dst->getLastBranch();
|
insilmaril@0
|
2861 |
bo->setHeading (fi->fileName() );
|
insilmaril@0
|
2862 |
bo->setColor (QColor("blue"),false);
|
insilmaril@0
|
2863 |
bo->toggleScroll();
|
insilmaril@0
|
2864 |
if ( !d.cd(fi->fileName()) )
|
insilmaril@0
|
2865 |
QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
|
insilmaril@0
|
2866 |
else
|
insilmaril@0
|
2867 |
{
|
insilmaril@103
|
2868 |
// Recursively add subdirs
|
insilmaril@0
|
2869 |
importDir (bo,d);
|
insilmaril@0
|
2870 |
d.cdUp();
|
insilmaril@0
|
2871 |
}
|
insilmaril@0
|
2872 |
}
|
insilmaril@0
|
2873 |
++itdir;
|
insilmaril@0
|
2874 |
}
|
insilmaril@0
|
2875 |
// Traverse files
|
insilmaril@0
|
2876 |
d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
|
insilmaril@0
|
2877 |
const QFileInfoList *filelist = d.entryInfoList();
|
insilmaril@0
|
2878 |
QFileInfoListIterator itfile( *filelist );
|
insilmaril@0
|
2879 |
|
insilmaril@0
|
2880 |
while ( (fi = itfile.current()) != 0 )
|
insilmaril@0
|
2881 |
{
|
insilmaril@0
|
2882 |
dst->addBranch();
|
insilmaril@0
|
2883 |
bo=dst->getLastBranch();
|
insilmaril@0
|
2884 |
bo->setHeading (fi->fileName() );
|
insilmaril@0
|
2885 |
bo->setColor (QColor("black"),false);
|
insilmaril@103
|
2886 |
if (fi->fileName().right(4) == ".vym" )
|
insilmaril@103
|
2887 |
bo->setVymLink (fi->filePath());
|
insilmaril@103
|
2888 |
|
insilmaril@0
|
2889 |
++itfile;
|
insilmaril@0
|
2890 |
}
|
insilmaril@0
|
2891 |
}
|
insilmaril@0
|
2892 |
}
|
insilmaril@0
|
2893 |
|
insilmaril@0
|
2894 |
void MapEditor::importDir()
|
insilmaril@0
|
2895 |
{
|
insilmaril@0
|
2896 |
if (selection &&
|
insilmaril@0
|
2897 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@0
|
2898 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@0
|
2899 |
{
|
insilmaril@0
|
2900 |
QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
|
insilmaril@0
|
2901 |
fd->setMode (QFileDialog::DirectoryOnly);
|
insilmaril@0
|
2902 |
fd->addFilter (QString (tr("vym map") + " (*.vym)"));
|
insilmaril@0
|
2903 |
fd->setCaption(tr("VYM - Choose directory structur to import"));
|
insilmaril@0
|
2904 |
fd->show();
|
insilmaril@0
|
2905 |
|
insilmaril@0
|
2906 |
QString fn;
|
insilmaril@0
|
2907 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
2908 |
{
|
insilmaril@0
|
2909 |
BranchObj *bo=((BranchObj*)(selection));
|
insilmaril@0
|
2910 |
importDir (bo,QDir(fd->selectedFile()) );
|
insilmaril@0
|
2911 |
mapCenter->reposition();
|
insilmaril@0
|
2912 |
adjustCanvasSize();
|
insilmaril@0
|
2913 |
canvas()->update();
|
insilmaril@0
|
2914 |
}
|
insilmaril@0
|
2915 |
}
|
insilmaril@0
|
2916 |
}
|
insilmaril@0
|
2917 |
|
insilmaril@95
|
2918 |
void MapEditor::followXLink(int i)
|
insilmaril@89
|
2919 |
{
|
insilmaril@97
|
2920 |
if (selection &&
|
insilmaril@97
|
2921 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@97
|
2922 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@89
|
2923 |
{
|
insilmaril@97
|
2924 |
BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
|
insilmaril@97
|
2925 |
if (bo)
|
insilmaril@97
|
2926 |
{
|
insilmaril@97
|
2927 |
selection->unselect();
|
insilmaril@97
|
2928 |
selection=bo;
|
insilmaril@97
|
2929 |
selection->select();
|
insilmaril@97
|
2930 |
ensureSelectionVisible();
|
insilmaril@97
|
2931 |
}
|
insilmaril@89
|
2932 |
}
|
insilmaril@89
|
2933 |
}
|
insilmaril@89
|
2934 |
|
insilmaril@95
|
2935 |
void MapEditor::editXLink(int i)
|
insilmaril@94
|
2936 |
{
|
insilmaril@97
|
2937 |
if (selection &&
|
insilmaril@97
|
2938 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@97
|
2939 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@94
|
2940 |
{
|
insilmaril@97
|
2941 |
XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
|
insilmaril@97
|
2942 |
if (xlo)
|
insilmaril@94
|
2943 |
{
|
insilmaril@97
|
2944 |
EditXLinkDialog dia;
|
insilmaril@97
|
2945 |
dia.setXLink (xlo);
|
insilmaril@102
|
2946 |
dia.setSelection(selection);
|
insilmaril@97
|
2947 |
if (dia.exec() == QDialog::Accepted)
|
insilmaril@97
|
2948 |
{
|
insilmaril@97
|
2949 |
if (dia.useSettingsGlobal() )
|
insilmaril@97
|
2950 |
{
|
insilmaril@97
|
2951 |
setDefXLinkColor (xlo->getColor() );
|
insilmaril@97
|
2952 |
setDefXLinkWidth (xlo->getWidth() );
|
insilmaril@97
|
2953 |
}
|
insilmaril@97
|
2954 |
if (dia.deleteXLink())
|
insilmaril@97
|
2955 |
((BranchObj*)(selection))->deleteXLinkAt(i);
|
insilmaril@131
|
2956 |
saveState(); //FIXME undoCommand
|
insilmaril@97
|
2957 |
}
|
insilmaril@97
|
2958 |
}
|
insilmaril@97
|
2959 |
}
|
insilmaril@94
|
2960 |
}
|
insilmaril@94
|
2961 |
|
insilmaril@0
|
2962 |
void MapEditor::testFunction()
|
insilmaril@0
|
2963 |
{
|
insilmaril@0
|
2964 |
cout << "MapEditor::testFunction() called\n";
|
insilmaril@105
|
2965 |
if (selection &&
|
insilmaril@105
|
2966 |
(typeid(*selection) == typeid(BranchObj)) )
|
insilmaril@105
|
2967 |
{
|
insilmaril@105
|
2968 |
QString s=((BranchObj*)(selection))->getHeading();
|
insilmaril@106
|
2969 |
parseAtom(s);
|
insilmaril@105
|
2970 |
}
|
insilmaril@105
|
2971 |
}
|
insilmaril@105
|
2972 |
|
insilmaril@0
|
2973 |
void MapEditor::ensureSelectionVisible()
|
insilmaril@0
|
2974 |
{
|
insilmaril@98
|
2975 |
if (selection)
|
insilmaril@98
|
2976 |
{
|
insilmaril@98
|
2977 |
LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
|
insilmaril@98
|
2978 |
QPoint p;
|
insilmaril@98
|
2979 |
if (selection->getOrientation() == OrientLeftOfCenter)
|
insilmaril@98
|
2980 |
p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
|
insilmaril@98
|
2981 |
else
|
insilmaril@98
|
2982 |
p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
|
insilmaril@98
|
2983 |
ensureVisible (p.x(), p.y() );
|
insilmaril@98
|
2984 |
}
|
insilmaril@0
|
2985 |
|
insilmaril@0
|
2986 |
}
|
insilmaril@0
|
2987 |
|
insilmaril@0
|
2988 |
void MapEditor::updateViewCenter()
|
insilmaril@0
|
2989 |
{
|
insilmaril@0
|
2990 |
// Update movingCenter, so that we can zoom comfortably later
|
insilmaril@0
|
2991 |
QRect rc = QRect( contentsX(), contentsY(),
|
insilmaril@0
|
2992 |
visibleWidth(), visibleHeight() );
|
insilmaril@0
|
2993 |
QRect canvasRect = inverseWorldMatrix().mapRect(rc);
|
insilmaril@0
|
2994 |
movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
|
insilmaril@0
|
2995 |
movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
|
insilmaril@0
|
2996 |
}
|
insilmaril@0
|
2997 |
|
insilmaril@0
|
2998 |
void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
|
insilmaril@0
|
2999 |
{
|
insilmaril@0
|
3000 |
// Lineedits are already closed by preceding
|
insilmaril@0
|
3001 |
// mouseEvent, we don't need to close here.
|
insilmaril@0
|
3002 |
|
insilmaril@0
|
3003 |
QPoint p = inverseWorldMatrix().map(e->pos());
|
insilmaril@0
|
3004 |
LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
|
insilmaril@0
|
3005 |
|
insilmaril@0
|
3006 |
if (lmo)
|
insilmaril@0
|
3007 |
{ // MapObj was found
|
insilmaril@0
|
3008 |
if (selection != lmo)
|
insilmaril@0
|
3009 |
{
|
insilmaril@0
|
3010 |
// select the MapObj
|
insilmaril@0
|
3011 |
if (selection) selection->unselect();
|
insilmaril@0
|
3012 |
selection=lmo;
|
insilmaril@0
|
3013 |
selection->select();
|
insilmaril@0
|
3014 |
adjustCanvasSize();
|
insilmaril@0
|
3015 |
}
|
insilmaril@0
|
3016 |
// Context Menu
|
insilmaril@0
|
3017 |
if (selection)
|
insilmaril@0
|
3018 |
{
|
insilmaril@0
|
3019 |
if (typeid(*selection)==typeid(BranchObj) ||
|
insilmaril@0
|
3020 |
typeid(*selection)==typeid(MapCenterObj) )
|
insilmaril@0
|
3021 |
{
|
insilmaril@0
|
3022 |
// Context Menu on branch or mapcenter
|
insilmaril@0
|
3023 |
updateActions();
|
insilmaril@0
|
3024 |
branchContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
3025 |
}
|
insilmaril@0
|
3026 |
if (typeid(*selection)==typeid(FloatImageObj))
|
insilmaril@0
|
3027 |
{
|
insilmaril@0
|
3028 |
// Context Menu on floatimage
|
insilmaril@0
|
3029 |
updateActions();
|
insilmaril@0
|
3030 |
floatimageContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
3031 |
}
|
insilmaril@0
|
3032 |
}
|
insilmaril@0
|
3033 |
} else
|
insilmaril@0
|
3034 |
{ // No MapObj found, we are on the Canvas itself
|
insilmaril@0
|
3035 |
// Context Menu on Canvas
|
insilmaril@0
|
3036 |
updateActions();
|
insilmaril@0
|
3037 |
canvasContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
3038 |
}
|
insilmaril@0
|
3039 |
}
|
insilmaril@0
|
3040 |
|
insilmaril@0
|
3041 |
void MapEditor::contentsMousePressEvent(QMouseEvent* e)
|
insilmaril@0
|
3042 |
{
|
insilmaril@0
|
3043 |
// Finish open lineEdits
|
insilmaril@0
|
3044 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
3045 |
|
insilmaril@0
|
3046 |
QPoint p = inverseWorldMatrix().map(e->pos());
|
insilmaril@0
|
3047 |
LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
|
insilmaril@0
|
3048 |
|
insilmaril@83
|
3049 |
// Special case: CTRL is pressed
|
insilmaril@0
|
3050 |
if (e->state() & QMouseEvent::ControlButton)
|
insilmaril@0
|
3051 |
{
|
insilmaril@89
|
3052 |
if (actionModModeColor->isOn())
|
insilmaril@83
|
3053 |
{
|
insilmaril@83
|
3054 |
if (e->state() & QMouseEvent::ControlButton)
|
insilmaril@83
|
3055 |
{
|
insilmaril@83
|
3056 |
pickingColor=true;
|
insilmaril@83
|
3057 |
setCursor (pickColorCursor);
|
insilmaril@83
|
3058 |
return;
|
insilmaril@83
|
3059 |
}
|
insilmaril@83
|
3060 |
}
|
insilmaril@89
|
3061 |
if (actionModModeLink->isOn())
|
insilmaril@83
|
3062 |
{
|
insilmaril@90
|
3063 |
BranchObj *bo_begin=NULL;
|
insilmaril@90
|
3064 |
if (lmo)
|
insilmaril@90
|
3065 |
bo_begin=(BranchObj*)(lmo);
|
insilmaril@90
|
3066 |
else
|
insilmaril@90
|
3067 |
if (selection &&
|
insilmaril@90
|
3068 |
((typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@90
|
3069 |
(typeid(*selection) == typeid(MapCenterObj))) )
|
insilmaril@90
|
3070 |
bo_begin=(BranchObj*)(selection);
|
insilmaril@90
|
3071 |
if (bo_begin)
|
insilmaril@83
|
3072 |
{
|
insilmaril@83
|
3073 |
drawingLink=true;
|
insilmaril@90
|
3074 |
linkingObj_src=bo_begin;
|
insilmaril@95
|
3075 |
tmpXLink=new XLinkObj (mapCanvas);
|
insilmaril@95
|
3076 |
tmpXLink->setBegin (bo_begin);
|
insilmaril@95
|
3077 |
tmpXLink->setEnd (p);
|
insilmaril@97
|
3078 |
tmpXLink->setColor(defXLinkColor);
|
insilmaril@97
|
3079 |
tmpXLink->setWidth(defXLinkWidth);
|
insilmaril@95
|
3080 |
tmpXLink->updateXLink();
|
insilmaril@95
|
3081 |
tmpXLink->setVisibility (true);
|
insilmaril@83
|
3082 |
return;
|
insilmaril@89
|
3083 |
}
|
insilmaril@83
|
3084 |
}
|
insilmaril@0
|
3085 |
}
|
insilmaril@0
|
3086 |
|
insilmaril@0
|
3087 |
if (lmo)
|
insilmaril@0
|
3088 |
{ // MapObj was found
|
insilmaril@0
|
3089 |
if (selection != lmo)
|
insilmaril@0
|
3090 |
{
|
insilmaril@0
|
3091 |
// select the MapObj
|
insilmaril@0
|
3092 |
if (selection) selection->unselect();
|
insilmaril@0
|
3093 |
selection=lmo;
|
insilmaril@0
|
3094 |
selection->select();
|
insilmaril@0
|
3095 |
|
insilmaril@0
|
3096 |
adjustCanvasSize();
|
insilmaril@0
|
3097 |
}
|
insilmaril@0
|
3098 |
|
insilmaril@0
|
3099 |
// Check, if systemFlag clicked
|
insilmaril@0
|
3100 |
if (typeid(*selection)==typeid(BranchObj) ||
|
insilmaril@0
|
3101 |
typeid(*selection)==typeid(MapCenterObj) )
|
insilmaril@0
|
3102 |
{
|
insilmaril@0
|
3103 |
QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
|
insilmaril@0
|
3104 |
if (!foname.isEmpty())
|
insilmaril@0
|
3105 |
{
|
insilmaril@0
|
3106 |
// Do not move, if systemFlag clicked
|
insilmaril@0
|
3107 |
if (foname=="url")
|
insilmaril@0
|
3108 |
openURL();
|
insilmaril@0
|
3109 |
else
|
insilmaril@0
|
3110 |
if (foname=="vymLink")
|
insilmaril@0
|
3111 |
{
|
insilmaril@0
|
3112 |
mainWindow->editOpenVymLink();
|
insilmaril@0
|
3113 |
// tabWidget may change, better return now
|
insilmaril@0
|
3114 |
// before segfaulting...
|
insilmaril@0
|
3115 |
return;
|
insilmaril@0
|
3116 |
} else
|
insilmaril@0
|
3117 |
if (foname=="note")
|
insilmaril@0
|
3118 |
mainWindow->windowToggleNoteEditor();
|
insilmaril@0
|
3119 |
}
|
insilmaril@0
|
3120 |
}
|
insilmaril@0
|
3121 |
|
insilmaril@0
|
3122 |
// Left Button Move Branches
|
insilmaril@0
|
3123 |
if (e->button() == QMouseEvent::LeftButton )
|
insilmaril@0
|
3124 |
{
|
insilmaril@129
|
3125 |
movingObj_start.setX( p.x() - selection->x() );
|
insilmaril@129
|
3126 |
movingObj_start.setY( p.y() - selection->y() );
|
insilmaril@129
|
3127 |
movingObj_orgPos.setX (lmo->x() );
|
insilmaril@129
|
3128 |
movingObj_orgPos.setY (lmo->y() );
|
insilmaril@129
|
3129 |
|
insilmaril@93
|
3130 |
// If modMode==copy, then we want to "move" the _new_ object around
|
insilmaril@93
|
3131 |
// then we need the offset from p to the _old_ selection, because of tmp
|
insilmaril@93
|
3132 |
if (actionModModeCopy->isOn() &&
|
insilmaril@93
|
3133 |
e->state() & QMouseEvent::ControlButton)
|
insilmaril@93
|
3134 |
{
|
insilmaril@93
|
3135 |
if (typeid(*selection)==typeid(BranchObj) )
|
insilmaril@93
|
3136 |
{
|
insilmaril@93
|
3137 |
copyingObj=true;
|
insilmaril@93
|
3138 |
mapCenter->addBranch ((BranchObj*)(selection));
|
insilmaril@93
|
3139 |
unselect();
|
insilmaril@93
|
3140 |
selection=mapCenter->getLastBranch();
|
insilmaril@93
|
3141 |
selection->select();
|
insilmaril@104
|
3142 |
mapCenter->reposition();
|
insilmaril@93
|
3143 |
}
|
insilmaril@129
|
3144 |
}
|
insilmaril@0
|
3145 |
movingObj=selection;
|
insilmaril@0
|
3146 |
} else
|
insilmaril@0
|
3147 |
// Middle Button Toggle Scroll
|
insilmaril@0
|
3148 |
// (On Mac OS X this won't work, but we still have
|
insilmaril@0
|
3149 |
// a button in the toolbar)
|
insilmaril@0
|
3150 |
if (e->button() == QMouseEvent::MidButton )
|
insilmaril@0
|
3151 |
toggleScroll();
|
insilmaril@0
|
3152 |
updateActions();
|
insilmaril@0
|
3153 |
} else
|
insilmaril@0
|
3154 |
{ // No MapObj found, we are on the Canvas itself
|
insilmaril@0
|
3155 |
// Left Button move Pos of CanvasView
|
insilmaril@0
|
3156 |
if (e->button() == QMouseEvent::LeftButton )
|
insilmaril@0
|
3157 |
{
|
insilmaril@0
|
3158 |
movingObj=NULL; // move Content not Obj
|
insilmaril@0
|
3159 |
movingObj_start=e->globalPos();
|
insilmaril@0
|
3160 |
movingCont_start=QPoint (contentsX(), contentsY() );
|
insilmaril@0
|
3161 |
movingVec=QPoint(0,0);
|
insilmaril@0
|
3162 |
setCursor(handOpenCursor);
|
insilmaril@0
|
3163 |
}
|
insilmaril@0
|
3164 |
}
|
insilmaril@0
|
3165 |
}
|
insilmaril@0
|
3166 |
|
insilmaril@0
|
3167 |
void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
|
insilmaril@0
|
3168 |
{
|
insilmaril@83
|
3169 |
QPoint p = inverseWorldMatrix().map(e->pos());
|
insilmaril@83
|
3170 |
|
insilmaril@0
|
3171 |
// Move the selected MapObj
|
insilmaril@0
|
3172 |
if ( selection && movingObj)
|
insilmaril@0
|
3173 |
{
|
insilmaril@89
|
3174 |
ensureVisible (p.x(),p.y());
|
insilmaril@0
|
3175 |
|
insilmaril@83
|
3176 |
// Now move the selection, but add relative position
|
insilmaril@83
|
3177 |
// (movingObj_start) where selection was chosen with
|
insilmaril@83
|
3178 |
// mousepointer. (This avoids flickering resp. jumping
|
insilmaril@0
|
3179 |
// of selection back to absPos)
|
insilmaril@0
|
3180 |
|
insilmaril@0
|
3181 |
LinkableMapObj *lmosel;
|
insilmaril@0
|
3182 |
lmosel = dynamic_cast <LinkableMapObj*> (selection);
|
insilmaril@0
|
3183 |
|
insilmaril@0
|
3184 |
// Check if we could link
|
insilmaril@0
|
3185 |
LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
|
insilmaril@0
|
3186 |
|
insilmaril@0
|
3187 |
|
insilmaril@0
|
3188 |
if (typeid(*selection) == typeid(FloatImageObj))
|
insilmaril@0
|
3189 |
{
|
insilmaril@0
|
3190 |
FloatObj *fo=(FloatObj*)(selection);
|
insilmaril@139
|
3191 |
saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
|
insilmaril@0
|
3192 |
if (fo->getLinkStyle()==StyleUndef)
|
insilmaril@0
|
3193 |
{
|
insilmaril@0
|
3194 |
fo->setLinkStyle(fo->getDefLinkStyle());
|
insilmaril@0
|
3195 |
fo->setLinkColor(fo->getParObj()->getLinkColor());
|
insilmaril@0
|
3196 |
}
|
insilmaril@0
|
3197 |
fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@0
|
3198 |
fo->setRelPos();
|
insilmaril@0
|
3199 |
fo->reposition();
|
insilmaril@0
|
3200 |
|
insilmaril@0
|
3201 |
// Relink float to new mapcenter or branch, if shift is pressed
|
insilmaril@0
|
3202 |
// Only relink, if selection really has a new parent
|
insilmaril@0
|
3203 |
if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
|
insilmaril@0
|
3204 |
( (typeid(*lmo)==typeid(BranchObj)) ||
|
insilmaril@0
|
3205 |
(typeid(*lmo)==typeid(MapCenterObj)) ) &&
|
insilmaril@0
|
3206 |
( lmo != fo->getParObj())
|
insilmaril@0
|
3207 |
)
|
insilmaril@0
|
3208 |
{
|
insilmaril@0
|
3209 |
if (typeid(*fo) == typeid(FloatImageObj))
|
insilmaril@0
|
3210 |
{
|
insilmaril@131
|
3211 |
saveState();
|
insilmaril@0
|
3212 |
FloatImageObj *fio=(FloatImageObj*)(fo);
|
insilmaril@0
|
3213 |
((BranchObj*)(lmo))->addFloatImage (fio);
|
insilmaril@0
|
3214 |
fio->unselect();
|
insilmaril@0
|
3215 |
((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
|
insilmaril@0
|
3216 |
fio=((BranchObj*)(lmo))->getLastFloatImage();
|
insilmaril@0
|
3217 |
fio->setRelPos();
|
insilmaril@0
|
3218 |
fio->reposition();
|
insilmaril@0
|
3219 |
selection=(LinkableMapObj*)(fio);
|
insilmaril@0
|
3220 |
selection->select();
|
insilmaril@0
|
3221 |
movingObj=(MapObj*)(fio);
|
insilmaril@0
|
3222 |
// setLinkStyle calls updateLink, only set it once
|
insilmaril@0
|
3223 |
if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
|
insilmaril@0
|
3224 |
fio->setLinkStyle (fio->getDefLinkStyle());
|
insilmaril@0
|
3225 |
}
|
insilmaril@0
|
3226 |
// TODO if (typeid(*selection) == typeid(FloatTextObj))
|
insilmaril@0
|
3227 |
}
|
insilmaril@0
|
3228 |
} else // selection != a FloatObj
|
insilmaril@0
|
3229 |
{
|
insilmaril@0
|
3230 |
if (lmosel->getDepth()==0)
|
insilmaril@0
|
3231 |
{
|
insilmaril@0
|
3232 |
if (e->state() == (LeftButton | !ShiftButton))
|
insilmaril@0
|
3233 |
// If mapCenter is moved, move all the rest by default, too.
|
insilmaril@0
|
3234 |
mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@0
|
3235 |
else
|
insilmaril@0
|
3236 |
mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@0
|
3237 |
} else
|
insilmaril@0
|
3238 |
{
|
insilmaril@0
|
3239 |
if (lmosel->getDepth()==1)
|
insilmaril@0
|
3240 |
{
|
insilmaril@0
|
3241 |
// depth==1, mainbranch
|
insilmaril@139
|
3242 |
saveState("move "+qpointToString(movingObj_orgPos), lmosel->getSelectString() );
|
insilmaril@0
|
3243 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@0
|
3244 |
} else
|
insilmaril@0
|
3245 |
{
|
insilmaril@0
|
3246 |
// depth>1
|
insilmaril@0
|
3247 |
if (lmosel->getOrientation() == OrientLeftOfCenter)
|
insilmaril@0
|
3248 |
// Add width of bbox here, otherwise alignRelTo will cause jumping around
|
insilmaril@0
|
3249 |
lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
|
insilmaril@0
|
3250 |
p.y()-movingObj_start.y() );
|
insilmaril@0
|
3251 |
else
|
insilmaril@0
|
3252 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@0
|
3253 |
}
|
insilmaril@0
|
3254 |
// reposition subbranch
|
insilmaril@0
|
3255 |
lmosel->reposition();
|
insilmaril@89
|
3256 |
//ensureSelectionVisible();
|
insilmaril@0
|
3257 |
|
insilmaril@0
|
3258 |
if (lmo && (lmo!=selection) &&
|
insilmaril@0
|
3259 |
(typeid(*lmo) == typeid(BranchObj) ||
|
insilmaril@0
|
3260 |
(typeid(*lmo) == typeid(MapCenterObj) )
|
insilmaril@0
|
3261 |
) )
|
insilmaril@0
|
3262 |
{
|
insilmaril@0
|
3263 |
if (e->state() & QMouseEvent::ControlButton)
|
insilmaril@0
|
3264 |
{
|
insilmaril@0
|
3265 |
// Special case: CTRL to link below lmo
|
insilmaril@0
|
3266 |
lmosel->setParObjTmp (lmo,p,+1);
|
insilmaril@0
|
3267 |
}
|
insilmaril@0
|
3268 |
else if (e->state() & QMouseEvent::ShiftButton)
|
insilmaril@0
|
3269 |
lmosel->setParObjTmp (lmo,p,-1);
|
insilmaril@0
|
3270 |
else
|
insilmaril@0
|
3271 |
lmosel->setParObjTmp (lmo,p,0);
|
insilmaril@0
|
3272 |
} else
|
insilmaril@0
|
3273 |
{
|
insilmaril@93
|
3274 |
lmosel->unsetParObjTmp();
|
insilmaril@93
|
3275 |
/*
|
insilmaril@0
|
3276 |
if (lmo &&(lmo==selection))
|
insilmaril@0
|
3277 |
// Could link to myself (happens sometimes...)
|
insilmaril@0
|
3278 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
3279 |
if (!lmo)
|
insilmaril@0
|
3280 |
// no Obj under selection, go back to original Parent
|
insilmaril@0
|
3281 |
lmosel->unsetParObjTmp();
|
insilmaril@93
|
3282 |
*/
|
insilmaril@0
|
3283 |
}
|
insilmaril@0
|
3284 |
} // depth>0
|
insilmaril@0
|
3285 |
|
insilmaril@0
|
3286 |
} // no FloatImageObj
|
insilmaril@0
|
3287 |
|
insilmaril@0
|
3288 |
canvas()->update();
|
insilmaril@0
|
3289 |
return;
|
insilmaril@0
|
3290 |
} // selection && moving_obj
|
insilmaril@0
|
3291 |
|
insilmaril@83
|
3292 |
// Draw a link from one branch to another
|
insilmaril@83
|
3293 |
if (drawingLink)
|
insilmaril@83
|
3294 |
{
|
insilmaril@95
|
3295 |
tmpXLink->setEnd (p);
|
insilmaril@95
|
3296 |
tmpXLink->updateXLink();
|
insilmaril@83
|
3297 |
}
|
insilmaril@83
|
3298 |
|
insilmaril@0
|
3299 |
// Move CanvasView
|
insilmaril@83
|
3300 |
if (!movingObj && !pickingColor &&!drawingLink)
|
insilmaril@0
|
3301 |
{
|
insilmaril@0
|
3302 |
QPoint p=e->globalPos();
|
insilmaril@0
|
3303 |
movingVec.setX(-p.x() + movingObj_start.x() );
|
insilmaril@0
|
3304 |
movingVec.setY(-p.y() + movingObj_start.y() );
|
insilmaril@0
|
3305 |
setContentsPos( movingCont_start.x() + movingVec.x(),
|
insilmaril@0
|
3306 |
movingCont_start.y() + movingVec.y());
|
insilmaril@0
|
3307 |
|
insilmaril@0
|
3308 |
updateViewCenter();
|
insilmaril@0
|
3309 |
}
|
insilmaril@0
|
3310 |
}
|
insilmaril@0
|
3311 |
|
insilmaril@0
|
3312 |
|
insilmaril@0
|
3313 |
void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
|
insilmaril@0
|
3314 |
{
|
insilmaril@0
|
3315 |
LinkableMapObj *dst;
|
insilmaril@0
|
3316 |
// Have we been picking color?
|
insilmaril@0
|
3317 |
if (pickingColor)
|
insilmaril@0
|
3318 |
{
|
insilmaril@0
|
3319 |
pickingColor=false;
|
insilmaril@0
|
3320 |
setCursor (ArrowCursor);
|
insilmaril@0
|
3321 |
// Check if we are over another branch
|
insilmaril@0
|
3322 |
dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
|
insilmaril@0
|
3323 |
if (dst && selection)
|
insilmaril@0
|
3324 |
{
|
insilmaril@0
|
3325 |
if (e->state() & QMouseEvent::ShiftButton)
|
insilmaril@0
|
3326 |
{
|
insilmaril@0
|
3327 |
((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
|
insilmaril@0
|
3328 |
((BranchObj*)(selection))->setLinkColor ();
|
insilmaril@0
|
3329 |
}
|
insilmaril@0
|
3330 |
else
|
insilmaril@0
|
3331 |
{
|
insilmaril@0
|
3332 |
((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
|
insilmaril@0
|
3333 |
((BranchObj*)(selection))->setLinkColor ();
|
insilmaril@0
|
3334 |
}
|
insilmaril@0
|
3335 |
}
|
insilmaril@0
|
3336 |
return;
|
insilmaril@0
|
3337 |
}
|
insilmaril@83
|
3338 |
|
insilmaril@83
|
3339 |
// Have we been drawing a link?
|
insilmaril@83
|
3340 |
if (drawingLink)
|
insilmaril@83
|
3341 |
{
|
insilmaril@83
|
3342 |
drawingLink=false;
|
insilmaril@83
|
3343 |
// Check if we are over another branch
|
insilmaril@83
|
3344 |
dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
|
insilmaril@83
|
3345 |
if (dst && selection)
|
insilmaril@83
|
3346 |
{
|
insilmaril@95
|
3347 |
tmpXLink->setEnd ( ((BranchObj*)(dst)) );
|
insilmaril@95
|
3348 |
tmpXLink->updateXLink();
|
insilmaril@95
|
3349 |
tmpXLink->activate();
|
insilmaril@131
|
3350 |
saveState(); //FIXME undoCommand
|
insilmaril@83
|
3351 |
} else
|
insilmaril@83
|
3352 |
{
|
insilmaril@95
|
3353 |
delete(tmpXLink);
|
insilmaril@95
|
3354 |
tmpXLink=NULL;
|
insilmaril@83
|
3355 |
}
|
insilmaril@83
|
3356 |
return;
|
insilmaril@83
|
3357 |
}
|
insilmaril@83
|
3358 |
|
insilmaril@0
|
3359 |
// Have we been moving something?
|
insilmaril@0
|
3360 |
if ( selection && movingObj )
|
insilmaril@0
|
3361 |
{
|
insilmaril@0
|
3362 |
// Check if we are over another branch, but ignore
|
insilmaril@0
|
3363 |
// any found LMOs, which are FloatObjs
|
insilmaril@0
|
3364 |
dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
|
insilmaril@0
|
3365 |
((LinkableMapObj*)(selection)) );
|
insilmaril@0
|
3366 |
|
insilmaril@0
|
3367 |
if (dst &&
|
insilmaril@0
|
3368 |
(typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
|
insilmaril@0
|
3369 |
{
|
insilmaril@0
|
3370 |
dst=NULL;
|
insilmaril@0
|
3371 |
}
|
insilmaril@0
|
3372 |
|
insilmaril@0
|
3373 |
// Now check, if we have been moving a branch
|
insilmaril@0
|
3374 |
if (typeid(*selection) == typeid(BranchObj) )
|
insilmaril@0
|
3375 |
{
|
insilmaril@0
|
3376 |
// save the position in case we link to mapcenter
|
insilmaril@0
|
3377 |
QPoint savePos=QPoint (selection->x(),selection->y() );
|
insilmaril@0
|
3378 |
|
insilmaril@0
|
3379 |
// Reset the temporary drawn link to the original one
|
insilmaril@0
|
3380 |
((LinkableMapObj*)(selection))->unsetParObjTmp();
|
insilmaril@0
|
3381 |
|
insilmaril@93
|
3382 |
|
insilmaril@94
|
3383 |
copyingObj=false;
|
insilmaril@129
|
3384 |
if (dst )
|
insilmaril@93
|
3385 |
{
|
insilmaril@129
|
3386 |
BranchObj* bs=((BranchObj*)(selection));
|
insilmaril@139
|
3387 |
QString undoCom="linkBranchToPos (\""+
|
insilmaril@129
|
3388 |
(bs->getParObj())->getSelectString()+
|
insilmaril@129
|
3389 |
"\","+
|
insilmaril@129
|
3390 |
QString("%1").arg(bs->getNum())+
|
insilmaril@129
|
3391 |
","+
|
insilmaril@129
|
3392 |
QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
|
insilmaril@139
|
3393 |
")";
|
insilmaril@0
|
3394 |
// TODO we also could check, if dest and src are on same branch,
|
insilmaril@0
|
3395 |
// then it would be sufficient to saveState of this branch
|
insilmaril@0
|
3396 |
|
insilmaril@0
|
3397 |
// Modifiers allow to insert above/below dst
|
insilmaril@0
|
3398 |
if (e->state() & QMouseEvent::ShiftButton)
|
insilmaril@0
|
3399 |
{
|
insilmaril@139
|
3400 |
bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
|
insilmaril@83
|
3401 |
} else
|
insilmaril@93
|
3402 |
if (e->state() & QMouseEvent::ControlButton)
|
insilmaril@93
|
3403 |
{
|
insilmaril@139
|
3404 |
bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
|
insilmaril@93
|
3405 |
} else
|
insilmaril@93
|
3406 |
{
|
insilmaril@129
|
3407 |
bs->moveBranchTo ((BranchObj*)(dst),-1);
|
insilmaril@93
|
3408 |
if (dst->getDepth()==0)
|
insilmaril@129
|
3409 |
bs->move (savePos);
|
insilmaril@93
|
3410 |
}
|
insilmaril@139
|
3411 |
saveState (undoCom,bs->getSelectString() );
|
insilmaril@93
|
3412 |
}
|
insilmaril@0
|
3413 |
// Draw the original link, before selection was moved around
|
insilmaril@0
|
3414 |
mapCenter->reposition();
|
insilmaril@0
|
3415 |
}
|
insilmaril@0
|
3416 |
// Finally resize canvas, if needed
|
insilmaril@0
|
3417 |
adjustCanvasSize();
|
insilmaril@0
|
3418 |
canvas()->update();
|
insilmaril@0
|
3419 |
movingObj=NULL;
|
insilmaril@0
|
3420 |
} else
|
insilmaril@83
|
3421 |
// maybe we moved View: set old cursor
|
insilmaril@0
|
3422 |
setCursor (ArrowCursor);
|
insilmaril@83
|
3423 |
|
insilmaril@0
|
3424 |
}
|
insilmaril@0
|
3425 |
|
insilmaril@0
|
3426 |
void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
|
insilmaril@0
|
3427 |
{
|
insilmaril@0
|
3428 |
// Finish open lineEdits
|
insilmaril@0
|
3429 |
if (lineedit) finishedLineEditNoSave();
|
insilmaril@0
|
3430 |
|
insilmaril@0
|
3431 |
if (e->button() == QMouseEvent::LeftButton )
|
insilmaril@0
|
3432 |
{
|
insilmaril@0
|
3433 |
QPoint p = inverseWorldMatrix().map(e->pos());
|
insilmaril@0
|
3434 |
LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
|
insilmaril@0
|
3435 |
if (lmo) { // MapObj was found
|
insilmaril@0
|
3436 |
// First select the MapObj than edit heading
|
insilmaril@0
|
3437 |
if (selection) selection->unselect();
|
insilmaril@0
|
3438 |
selection=lmo;
|
insilmaril@0
|
3439 |
selection->select();
|
insilmaril@106
|
3440 |
saveState(selection);
|
insilmaril@0
|
3441 |
editHeading();
|
insilmaril@0
|
3442 |
}
|
insilmaril@0
|
3443 |
}
|
insilmaril@0
|
3444 |
}
|
insilmaril@0
|
3445 |
|
insilmaril@0
|
3446 |
void MapEditor::resizeEvent (QResizeEvent* e)
|
insilmaril@0
|
3447 |
{
|
insilmaril@0
|
3448 |
QCanvasView::resizeEvent( e );
|
insilmaril@0
|
3449 |
|
insilmaril@0
|
3450 |
QString s="";
|
insilmaril@0
|
3451 |
if (!fileName.isEmpty()) s=fileName;
|
insilmaril@0
|
3452 |
adjustCanvasSize();
|
insilmaril@0
|
3453 |
}
|
insilmaril@0
|
3454 |
|
insilmaril@128
|
3455 |
void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
|
insilmaril@119
|
3456 |
{
|
insilmaril@129
|
3457 |
|
insilmaril@129
|
3458 |
// for (unsigned int i=0;event->format(i);i++) // Debug mime type
|
insilmaril@129
|
3459 |
// cerr << event->format(i) << endl;
|
insilmaril@129
|
3460 |
|
insilmaril@119
|
3461 |
if (selection &&
|
insilmaril@119
|
3462 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@119
|
3463 |
(typeid(*selection) == typeid(MapCenterObj))) {
|
insilmaril@119
|
3464 |
|
insilmaril@119
|
3465 |
// If QImageDrag can decode mime type
|
insilmaril@119
|
3466 |
if (QImageDrag::canDecode(event)) {
|
insilmaril@119
|
3467 |
event->accept();
|
insilmaril@119
|
3468 |
return;
|
insilmaril@119
|
3469 |
}
|
insilmaril@119
|
3470 |
|
insilmaril@128
|
3471 |
// If image are dragged from firefox
|
insilmaril@119
|
3472 |
if (event->provides("application/x-moz-file-promise-url") &&
|
insilmaril@119
|
3473 |
event->provides("application/x-moz-nativeimage")) {
|
insilmaril@119
|
3474 |
event->accept(true);
|
insilmaril@119
|
3475 |
return;
|
insilmaril@119
|
3476 |
}
|
insilmaril@125
|
3477 |
|
insilmaril@128
|
3478 |
// If QUriDrag can decode mime type
|
insilmaril@128
|
3479 |
if (QUriDrag::canDecode(event)) {
|
insilmaril@128
|
3480 |
event->accept();
|
insilmaril@128
|
3481 |
return;
|
insilmaril@128
|
3482 |
}
|
insilmaril@128
|
3483 |
|
insilmaril@128
|
3484 |
// If Uri are dragged from firefox
|
insilmaril@129
|
3485 |
if (event->provides("_NETSCAPE_URL")){
|
insilmaril@128
|
3486 |
event->accept();
|
insilmaril@128
|
3487 |
return;
|
insilmaril@128
|
3488 |
}
|
insilmaril@129
|
3489 |
|
insilmaril@129
|
3490 |
// If QTextDrag can decode mime type
|
insilmaril@129
|
3491 |
if (QTextDrag::canDecode(event)) {
|
insilmaril@129
|
3492 |
event->accept();
|
insilmaril@129
|
3493 |
return;
|
insilmaril@129
|
3494 |
}
|
insilmaril@129
|
3495 |
|
insilmaril@119
|
3496 |
}
|
insilmaril@119
|
3497 |
event->ignore();
|
insilmaril@119
|
3498 |
}
|
insilmaril@129
|
3499 |
|
insilmaril@129
|
3500 |
bool isUnicode16(const QByteArray &d)
|
insilmaril@129
|
3501 |
{
|
insilmaril@129
|
3502 |
// FIXME: make more precise check for unicode 16.
|
insilmaril@129
|
3503 |
// Guess unicode16 if any of second bytes are zero
|
insilmaril@129
|
3504 |
unsigned int length = max(0,d.size()-2)/2;
|
insilmaril@129
|
3505 |
for (unsigned int i = 0; i<length ; i++)
|
insilmaril@129
|
3506 |
if (d.at(i*2+1)==0) return true;
|
insilmaril@129
|
3507 |
return false;
|
insilmaril@129
|
3508 |
}
|
insilmaril@119
|
3509 |
|
insilmaril@128
|
3510 |
void MapEditor::contentsDropEvent(QDropEvent *event)
|
insilmaril@119
|
3511 |
{
|
insilmaril@128
|
3512 |
if (selection &&
|
insilmaril@128
|
3513 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@128
|
3514 |
(typeid(*selection) == typeid(MapCenterObj)))
|
insilmaril@128
|
3515 |
{
|
insilmaril@128
|
3516 |
bool update=false;
|
insilmaril@128
|
3517 |
QStrList uris;
|
insilmaril@129
|
3518 |
QString heading;
|
insilmaril@128
|
3519 |
if (event->provides("image/png"))
|
insilmaril@128
|
3520 |
{
|
insilmaril@128
|
3521 |
QPixmap pix;
|
insilmaril@128
|
3522 |
if (QImageDrag::decode(event, pix))
|
insilmaril@128
|
3523 |
{
|
insilmaril@128
|
3524 |
addFloatImage(pix);
|
insilmaril@128
|
3525 |
event->accept();
|
insilmaril@128
|
3526 |
update=true;
|
insilmaril@128
|
3527 |
} else
|
insilmaril@128
|
3528 |
event->ignore();
|
insilmaril@128
|
3529 |
|
insilmaril@128
|
3530 |
} else if (event->provides("application/x-moz-file-promise-url") &&
|
insilmaril@128
|
3531 |
event->provides("application/x-moz-nativeimage"))
|
insilmaril@128
|
3532 |
{
|
insilmaril@129
|
3533 |
// Contains url to the img src in unicode16
|
insilmaril@128
|
3534 |
QByteArray d = event->encodedData("application/x-moz-file-promise-url");
|
insilmaril@128
|
3535 |
QString url = QString((const QChar*)d.data(),d.size()/2);
|
insilmaril@128
|
3536 |
fetchImage(url);
|
insilmaril@128
|
3537 |
event->accept();
|
insilmaril@128
|
3538 |
update=true;
|
insilmaril@128
|
3539 |
} else if (event->provides ("text/uri-list"))
|
insilmaril@128
|
3540 |
{ // Uris provided e.g. by konqueror
|
insilmaril@128
|
3541 |
QUriDrag::decode (event,uris);
|
insilmaril@129
|
3542 |
} else if (event->provides ("_NETSCAPE_URL"))
|
insilmaril@128
|
3543 |
{ // Uris provided by Mozilla
|
insilmaril@129
|
3544 |
QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
|
insilmaril@129
|
3545 |
uris.append(l[0]);
|
insilmaril@129
|
3546 |
heading = l[1];
|
insilmaril@129
|
3547 |
} else if (event->provides("text/html")) {
|
insilmaril@129
|
3548 |
|
insilmaril@129
|
3549 |
// Handels text mime types
|
insilmaril@129
|
3550 |
// Look like firefox allways handle text as unicode16 (2 bytes per char.)
|
insilmaril@129
|
3551 |
QByteArray d = event->encodedData("text/html");
|
insilmaril@129
|
3552 |
QString text;
|
insilmaril@129
|
3553 |
if (isUnicode16(d))
|
insilmaril@129
|
3554 |
text = QString((const QChar*)d.data(),d.size()/2);
|
insilmaril@129
|
3555 |
else
|
insilmaril@129
|
3556 |
text = QString(d);
|
insilmaril@129
|
3557 |
|
insilmaril@129
|
3558 |
textEditor->setText(text);
|
insilmaril@129
|
3559 |
|
insilmaril@129
|
3560 |
event->accept();
|
insilmaril@129
|
3561 |
update=true;
|
insilmaril@129
|
3562 |
} else if (event->provides("text/plain")) {
|
insilmaril@129
|
3563 |
QByteArray d = event->encodedData("text/plain");
|
insilmaril@129
|
3564 |
QString text;
|
insilmaril@129
|
3565 |
if (isUnicode16(d))
|
insilmaril@129
|
3566 |
text = QString((const QChar*)d.data(),d.size()/2);
|
insilmaril@129
|
3567 |
else
|
insilmaril@129
|
3568 |
text = QString(d);
|
insilmaril@129
|
3569 |
|
insilmaril@129
|
3570 |
textEditor->setText(text);
|
insilmaril@129
|
3571 |
|
insilmaril@129
|
3572 |
event->accept();
|
insilmaril@129
|
3573 |
update= true;
|
insilmaril@128
|
3574 |
}
|
insilmaril@128
|
3575 |
|
insilmaril@128
|
3576 |
if (uris.count()>0)
|
insilmaril@128
|
3577 |
{
|
insilmaril@128
|
3578 |
QStringList files;
|
insilmaril@128
|
3579 |
QStringList urls;
|
insilmaril@128
|
3580 |
QString s;
|
insilmaril@128
|
3581 |
BranchObj *bo;
|
insilmaril@128
|
3582 |
for (const char* u=uris.first(); u; u=uris.next())
|
insilmaril@128
|
3583 |
{
|
insilmaril@128
|
3584 |
bo=((BranchObj*)(selection))->addBranch();
|
insilmaril@128
|
3585 |
if (bo)
|
insilmaril@128
|
3586 |
{
|
insilmaril@128
|
3587 |
s=QUriDrag::uriToLocalFile(u);
|
insilmaril@129
|
3588 |
if (s) {
|
insilmaril@129
|
3589 |
QString file = QDir::convertSeparators(s);
|
insilmaril@129
|
3590 |
heading = QFileInfo(file).baseName();
|
insilmaril@129
|
3591 |
files.append(file);
|
insilmaril@129
|
3592 |
if (file.endsWith(".vym", false))
|
insilmaril@129
|
3593 |
bo->setVymLink(file);
|
insilmaril@129
|
3594 |
else
|
insilmaril@129
|
3595 |
bo->setURL(u);
|
insilmaril@129
|
3596 |
} else {
|
insilmaril@129
|
3597 |
urls.append (u);
|
insilmaril@129
|
3598 |
bo->setURL(u);
|
insilmaril@129
|
3599 |
}
|
insilmaril@129
|
3600 |
|
insilmaril@129
|
3601 |
if (heading)
|
insilmaril@129
|
3602 |
bo->setHeading(heading);
|
insilmaril@129
|
3603 |
else
|
insilmaril@129
|
3604 |
bo->setHeading(u);
|
insilmaril@128
|
3605 |
}
|
insilmaril@128
|
3606 |
}
|
insilmaril@128
|
3607 |
update=true;
|
insilmaril@128
|
3608 |
}
|
insilmaril@128
|
3609 |
|
insilmaril@128
|
3610 |
if (update)
|
insilmaril@128
|
3611 |
{
|
insilmaril@131
|
3612 |
saveState(); //FIXME undo Command
|
insilmaril@128
|
3613 |
mapCenter->reposition();
|
insilmaril@128
|
3614 |
adjustCanvasSize();
|
insilmaril@128
|
3615 |
canvas()->update();
|
insilmaril@128
|
3616 |
}
|
insilmaril@128
|
3617 |
}
|
insilmaril@119
|
3618 |
}
|
insilmaril@119
|
3619 |
|
insilmaril@125
|
3620 |
void MapEditor::addFloatImage(const QPixmap &img)
|
insilmaril@119
|
3621 |
{
|
insilmaril@119
|
3622 |
if (selection &&
|
insilmaril@119
|
3623 |
(typeid(*selection) == typeid(BranchObj)) ||
|
insilmaril@119
|
3624 |
(typeid(*selection) == typeid(MapCenterObj)) )
|
insilmaril@119
|
3625 |
{
|
insilmaril@119
|
3626 |
BranchObj *bo=((BranchObj*)(selection));
|
insilmaril@119
|
3627 |
saveState(selection);
|
insilmaril@119
|
3628 |
//QString fn=fd->selectedFile();
|
insilmaril@119
|
3629 |
//lastImageDir=fn.left(fn.findRev ("/"));
|
insilmaril@119
|
3630 |
bo->addFloatImage();
|
insilmaril@119
|
3631 |
// FIXME check if load was successful
|
insilmaril@119
|
3632 |
bo->getLastFloatImage()->load(img);
|
insilmaril@119
|
3633 |
//bo->getLastFloatImage()->setOriginalFilename(fn);
|
insilmaril@119
|
3634 |
mapCenter->reposition();
|
insilmaril@119
|
3635 |
adjustCanvasSize();
|
insilmaril@119
|
3636 |
canvas()->update();
|
insilmaril@119
|
3637 |
}
|
insilmaril@119
|
3638 |
}
|
insilmaril@119
|
3639 |
|
insilmaril@119
|
3640 |
|
insilmaril@129
|
3641 |
void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
|
insilmaril@119
|
3642 |
{
|
insilmaril@119
|
3643 |
if (!imageBuffer) imageBuffer = new QBuffer();
|
insilmaril@119
|
3644 |
if (!imageBuffer->isOpen()) {
|
insilmaril@119
|
3645 |
imageBuffer->open(IO_WriteOnly | IO_Append);
|
insilmaril@119
|
3646 |
}
|
insilmaril@119
|
3647 |
imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
|
insilmaril@119
|
3648 |
}
|
insilmaril@119
|
3649 |
|
insilmaril@119
|
3650 |
|
insilmaril@129
|
3651 |
void MapEditor::imageDataFinished(QNetworkOperation *nop)
|
insilmaril@119
|
3652 |
{
|
insilmaril@129
|
3653 |
if (nop->state()==QNetworkProtocol::StDone) {
|
insilmaril@129
|
3654 |
QPixmap img(imageBuffer->buffer());
|
insilmaril@129
|
3655 |
addFloatImage(img);
|
insilmaril@129
|
3656 |
}
|
insilmaril@129
|
3657 |
|
insilmaril@129
|
3658 |
if (imageBuffer) {
|
insilmaril@129
|
3659 |
imageBuffer->close();
|
insilmaril@129
|
3660 |
if (imageBuffer) {
|
insilmaril@129
|
3661 |
imageBuffer->close();
|
insilmaril@129
|
3662 |
delete imageBuffer;
|
insilmaril@129
|
3663 |
imageBuffer = 0;
|
insilmaril@129
|
3664 |
}
|
insilmaril@129
|
3665 |
}
|
insilmaril@119
|
3666 |
}
|
insilmaril@119
|
3667 |
|
insilmaril@129
|
3668 |
void MapEditor::fetchImage(const QString &url)
|
insilmaril@119
|
3669 |
{
|
insilmaril@119
|
3670 |
if (urlOperator) {
|
insilmaril@119
|
3671 |
urlOperator->stop();
|
insilmaril@119
|
3672 |
disconnect(urlOperator);
|
insilmaril@119
|
3673 |
delete urlOperator;
|
insilmaril@119
|
3674 |
}
|
insilmaril@119
|
3675 |
|
insilmaril@119
|
3676 |
urlOperator = new QUrlOperator(url);
|
insilmaril@119
|
3677 |
connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
|
insilmaril@119
|
3678 |
this, SLOT(imageDataFinished(QNetworkOperation*)));
|
insilmaril@119
|
3679 |
|
insilmaril@119
|
3680 |
connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
|
insilmaril@119
|
3681 |
this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));
|
insilmaril@119
|
3682 |
urlOperator->get();
|
insilmaril@119
|
3683 |
}
|