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