insilmaril@815
|
1 |
#include "mapeditor.h"
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
#include <iostream>
|
insilmaril@95
|
4 |
#include <cstdlib>
|
insilmaril@0
|
5 |
#include <typeinfo>
|
insilmaril@0
|
6 |
|
insilmaril@720
|
7 |
#include <QObject>
|
insilmaril@720
|
8 |
|
insilmaril@750
|
9 |
#include "branchitem.h"
|
insilmaril@792
|
10 |
#include "geometry.h"
|
insilmaril@175
|
11 |
#include "mainwindow.h"
|
insilmaril@175
|
12 |
#include "misc.h"
|
insilmaril@314
|
13 |
#include "warningdialog.h"
|
insilmaril@790
|
14 |
#include "xlinkitem.h"
|
insilmaril@0
|
15 |
|
insilmaril@0
|
16 |
|
insilmaril@0
|
17 |
extern int statusbarTime;
|
insilmaril@0
|
18 |
extern Main *mainWindow;
|
insilmaril@164
|
19 |
extern QString tmpVymDir;
|
insilmaril@166
|
20 |
extern QString clipboardDir;
|
insilmaril@491
|
21 |
extern QString clipboardFile;
|
insilmaril@166
|
22 |
extern bool clipboardEmpty;
|
insilmaril@473
|
23 |
extern bool debug;
|
insilmaril@0
|
24 |
|
insilmaril@366
|
25 |
extern QMenu* branchContextMenu;
|
insilmaril@366
|
26 |
extern QMenu* floatimageContextMenu;
|
insilmaril@366
|
27 |
extern QMenu* canvasContextMenu;
|
insilmaril@366
|
28 |
|
insilmaril@0
|
29 |
extern Settings settings;
|
insilmaril@269
|
30 |
extern QString iconPath;
|
insilmaril@0
|
31 |
|
insilmaril@0
|
32 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@0
|
33 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@720
|
34 |
MapEditor::MapEditor( VymModel *vm)
|
insilmaril@0
|
35 |
{
|
insilmaril@0
|
36 |
//cout << "Constructor ME "<<this<<endl;
|
insilmaril@720
|
37 |
mapScene= new QGraphicsScene(NULL);
|
insilmaril@408
|
38 |
mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
|
insilmaril@408
|
39 |
|
insilmaril@767
|
40 |
zoomFactor=zoomFactorTarget=1;
|
insilmaril@767
|
41 |
|
insilmaril@720
|
42 |
model=vm;
|
insilmaril@645
|
43 |
model->setScene (mapScene);
|
insilmaril@720
|
44 |
model->registerEditor(this);
|
insilmaril@727
|
45 |
model->makeDefault(); // No changes in model so far
|
insilmaril@408
|
46 |
|
insilmaril@408
|
47 |
setScene (mapScene);
|
insilmaril@0
|
48 |
|
insilmaril@0
|
49 |
printer=NULL;
|
insilmaril@0
|
50 |
|
insilmaril@366
|
51 |
// Create bitmap cursors, platform dependant
|
insilmaril@404
|
52 |
HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
|
insilmaril@404
|
53 |
PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
|
insilmaril@404
|
54 |
CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
|
insilmaril@404
|
55 |
XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
|
insilmaril@398
|
56 |
|
insilmaril@769
|
57 |
//setFocusPolicy (Qt::StrongFocus); //FIXME-3
|
insilmaril@0
|
58 |
|
insilmaril@0
|
59 |
pickingColor=false;
|
insilmaril@91
|
60 |
drawingLink=false;
|
insilmaril@93
|
61 |
copyingObj=false;
|
insilmaril@798
|
62 |
objectMoved=false;
|
insilmaril@0
|
63 |
|
insilmaril@0
|
64 |
editingBO=NULL;
|
insilmaril@0
|
65 |
movingObj=NULL;
|
insilmaril@0
|
66 |
|
insilmaril@0
|
67 |
printFrame=true;
|
insilmaril@0
|
68 |
printFooter=true;
|
insilmaril@0
|
69 |
|
insilmaril@417
|
70 |
setAcceptDrops (true);
|
insilmaril@0
|
71 |
|
insilmaril@746
|
72 |
//model->reposition(); //FIXME-3 really still needed?
|
insilmaril@381
|
73 |
|
insilmaril@531
|
74 |
|
insilmaril@769
|
75 |
// Shortcuts and actions
|
insilmaril@769
|
76 |
QAction *a;
|
insilmaril@769
|
77 |
a = new QAction("Select upper branch", this);
|
insilmaril@769
|
78 |
a->setShortcut (Qt::Key_Up );
|
insilmaril@769
|
79 |
a->setShortcutContext (Qt::WidgetShortcut);
|
insilmaril@769
|
80 |
addAction (a);
|
insilmaril@769
|
81 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
|
insilmaril@769
|
82 |
|
insilmaril@769
|
83 |
a = new QAction( "Select lower branch",this);
|
insilmaril@769
|
84 |
a->setShortcut ( Qt::Key_Down );
|
insilmaril@769
|
85 |
a->setShortcutContext (Qt::WidgetShortcut);
|
insilmaril@769
|
86 |
addAction (a);
|
insilmaril@769
|
87 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
|
insilmaril@769
|
88 |
|
insilmaril@769
|
89 |
a = new QAction( "Select left branch", this);
|
insilmaril@769
|
90 |
a->setShortcut (Qt::Key_Left );
|
insilmaril@769
|
91 |
// a->setShortcutContext (Qt::WindowShortcut);
|
insilmaril@769
|
92 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
93 |
addAction (a);
|
insilmaril@769
|
94 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorLeft() ) );
|
insilmaril@769
|
95 |
|
insilmaril@769
|
96 |
a = new QAction( "Select child branch", this);
|
insilmaril@769
|
97 |
a->setShortcut (Qt::Key_Right);
|
insilmaril@769
|
98 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
99 |
addAction (a);
|
insilmaril@769
|
100 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorRight() ) );
|
insilmaril@769
|
101 |
|
insilmaril@769
|
102 |
a = new QAction( "Select first branch", this);
|
insilmaril@769
|
103 |
a->setShortcut (Qt::Key_Home );
|
insilmaril@769
|
104 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
105 |
addAction (a);
|
insilmaril@769
|
106 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorFirst() ) );
|
insilmaril@769
|
107 |
|
insilmaril@769
|
108 |
a = new QAction( "Select last branch",this);
|
insilmaril@769
|
109 |
a->setShortcut ( Qt::Key_End );
|
insilmaril@769
|
110 |
a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
|
insilmaril@769
|
111 |
addAction (a);
|
insilmaril@769
|
112 |
connect( a, SIGNAL( triggered() ), this, SLOT( cursorLast() ) );
|
insilmaril@769
|
113 |
|
insilmaril@720
|
114 |
// Action to embed LineEdit for heading in Scene
|
insilmaril@720
|
115 |
editingHeading=false;
|
insilmaril@720
|
116 |
lineEdit=new QLineEdit;
|
insilmaril@720
|
117 |
lineEdit->hide();
|
insilmaril@720
|
118 |
QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
|
insilmaril@772
|
119 |
pw->setZValue (Z_LINEEDIT);
|
insilmaril@676
|
120 |
|
insilmaril@769
|
121 |
a = new QAction( tr( "Edit heading","MapEditor" ), this);
|
insilmaril@720
|
122 |
a->setShortcut ( Qt::Key_Return ); //Edit heading
|
insilmaril@810
|
123 |
a->setShortcutContext (Qt::WidgetShortcut);
|
insilmaril@720
|
124 |
addAction (a);
|
insilmaril@720
|
125 |
connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
|
insilmaril@720
|
126 |
a = new QAction( tr( "Edit heading","MapEditor" ), this);
|
insilmaril@720
|
127 |
a->setShortcut ( Qt::Key_Enter); //Edit heading
|
insilmaril@720
|
128 |
addAction (a);
|
insilmaril@720
|
129 |
connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
|
insilmaril@628
|
130 |
|
insilmaril@728
|
131 |
// Selections
|
insilmaril@728
|
132 |
selectionColor =QColor (255,255,0);
|
insilmaril@728
|
133 |
|
insilmaril@728
|
134 |
|
insilmaril@746
|
135 |
// Attributes //FIXME-2 testing only...
|
insilmaril@638
|
136 |
QString k;
|
insilmaril@638
|
137 |
AttributeDef *ad;
|
insilmaril@628
|
138 |
attrTable= new AttributeTable();
|
insilmaril@638
|
139 |
k="A - StringList";
|
insilmaril@638
|
140 |
ad=attrTable->addKey (k,StringList);
|
insilmaril@638
|
141 |
if (ad)
|
insilmaril@638
|
142 |
{
|
insilmaril@638
|
143 |
QStringList sl;
|
insilmaril@638
|
144 |
sl <<"val 1"<<"val 2"<< "val 3";
|
insilmaril@638
|
145 |
ad->setValue (QVariant (sl));
|
insilmaril@638
|
146 |
}
|
insilmaril@638
|
147 |
//attrTable->addValue ("Key A","P 1");
|
insilmaril@638
|
148 |
//attrTable->addValue ("Key A","P 2");
|
insilmaril@638
|
149 |
//attrTable->addValue ("Key A","P 3");
|
insilmaril@638
|
150 |
//attrTable->addValue ("Key A","P 4");
|
insilmaril@638
|
151 |
k="B - FreeString";
|
insilmaril@638
|
152 |
ad=attrTable->addKey (k,FreeString);
|
insilmaril@638
|
153 |
if (ad)
|
insilmaril@638
|
154 |
{
|
insilmaril@638
|
155 |
//attrTable->addValue ("Key B","w1");
|
insilmaril@638
|
156 |
//attrTable->addValue ("Key B","w2");
|
insilmaril@638
|
157 |
}
|
insilmaril@638
|
158 |
k="C - UniqueString";
|
insilmaril@638
|
159 |
ad=attrTable->addKey (k,UniqueString);
|
insilmaril@638
|
160 |
if (ad)
|
insilmaril@638
|
161 |
{
|
insilmaril@638
|
162 |
//attrTable->addKey ("Key Prio");
|
insilmaril@638
|
163 |
//attrTable->addValue ("Key Prio","Prio 1");
|
insilmaril@638
|
164 |
//attrTable->addValue ("Key Prio","Prio 2");
|
insilmaril@638
|
165 |
}
|
insilmaril@0
|
166 |
}
|
insilmaril@0
|
167 |
|
insilmaril@0
|
168 |
MapEditor::~MapEditor()
|
insilmaril@0
|
169 |
{
|
insilmaril@746
|
170 |
//cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
|
insilmaril@720
|
171 |
model->unregisterEditor(this);
|
insilmaril@0
|
172 |
}
|
insilmaril@0
|
173 |
|
insilmaril@645
|
174 |
VymModel* MapEditor::getModel()
|
insilmaril@0
|
175 |
{
|
insilmaril@645
|
176 |
return model;
|
insilmaril@0
|
177 |
}
|
insilmaril@0
|
178 |
|
insilmaril@408
|
179 |
QGraphicsScene * MapEditor::getScene()
|
insilmaril@0
|
180 |
{
|
insilmaril@408
|
181 |
return mapScene;
|
insilmaril@0
|
182 |
}
|
insilmaril@0
|
183 |
|
insilmaril@802
|
184 |
void MapEditor::scrollTo (const QModelIndex &index)
|
insilmaril@772
|
185 |
{
|
insilmaril@772
|
186 |
if (index.isValid())
|
insilmaril@772
|
187 |
{
|
insilmaril@776
|
188 |
LinkableMapObj* lmo=NULL;
|
insilmaril@776
|
189 |
TreeItem *ti= static_cast<TreeItem*>(index.internalPointer());
|
insilmaril@776
|
190 |
if (ti->getType()==TreeItem::Image ||ti->isBranchLikeType() )
|
insilmaril@779
|
191 |
lmo=((MapItem*)ti)->getLMO();
|
insilmaril@798
|
192 |
if (lmo)
|
insilmaril@798
|
193 |
{
|
insilmaril@798
|
194 |
QRectF r=lmo->getBBox();
|
insilmaril@802
|
195 |
setScrollBarPosTarget (r);
|
insilmaril@798
|
196 |
}
|
insilmaril@772
|
197 |
}
|
insilmaril@772
|
198 |
}
|
insilmaril@772
|
199 |
|
insilmaril@767
|
200 |
void MapEditor::setScrollBarPosTarget (const QRectF &rect)
|
insilmaril@767
|
201 |
{
|
insilmaril@767
|
202 |
// Code copied from Qt sources
|
insilmaril@767
|
203 |
int xmargin=50;
|
insilmaril@767
|
204 |
int ymargin=50;
|
insilmaril@767
|
205 |
|
insilmaril@767
|
206 |
qreal width = viewport()->width();
|
insilmaril@767
|
207 |
qreal height = viewport()->height();
|
insilmaril@767
|
208 |
QRectF viewRect = matrix().mapRect(rect);
|
insilmaril@767
|
209 |
|
insilmaril@767
|
210 |
qreal left = horizontalScrollBar()->value();
|
insilmaril@767
|
211 |
qreal right = left + width;
|
insilmaril@767
|
212 |
qreal top = verticalScrollBar()->value();
|
insilmaril@767
|
213 |
qreal bottom = top + height;
|
insilmaril@767
|
214 |
|
insilmaril@802
|
215 |
scrollBarPosTarget=getScrollBarPos();
|
insilmaril@802
|
216 |
|
insilmaril@767
|
217 |
if (viewRect.left() <= left + xmargin) {
|
insilmaril@767
|
218 |
// need to scroll from the left
|
insilmaril@767
|
219 |
// if (!d->leftIndent)
|
insilmaril@767
|
220 |
scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
|
insilmaril@767
|
221 |
}
|
insilmaril@767
|
222 |
if (viewRect.right() >= right - xmargin) {
|
insilmaril@767
|
223 |
// need to scroll from the right
|
insilmaril@767
|
224 |
// if (!d->leftIndent)
|
insilmaril@767
|
225 |
scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
|
insilmaril@767
|
226 |
}
|
insilmaril@767
|
227 |
if (viewRect.top() <= top + ymargin) {
|
insilmaril@767
|
228 |
// need to scroll from the top
|
insilmaril@767
|
229 |
// if (!d->topIndent)
|
insilmaril@767
|
230 |
scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
|
insilmaril@767
|
231 |
}
|
insilmaril@767
|
232 |
if (viewRect.bottom() >= bottom - ymargin) {
|
insilmaril@767
|
233 |
// need to scroll from the bottom
|
insilmaril@767
|
234 |
// if (!d->topIndent)
|
insilmaril@767
|
235 |
scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
|
insilmaril@767
|
236 |
}
|
insilmaril@767
|
237 |
|
insilmaril@802
|
238 |
if (scrollBarPosTarget==getScrollBarPos()) return;
|
insilmaril@802
|
239 |
|
insilmaril@767
|
240 |
if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
|
insilmaril@767
|
241 |
scrollBarPosAnimation.stop();
|
insilmaril@802
|
242 |
|
insilmaril@802
|
243 |
if (settings.value ("/animation/use/",true).toBool() )
|
insilmaril@802
|
244 |
{
|
insilmaril@802
|
245 |
scrollBarPosAnimation.setTargetObject (this);
|
insilmaril@802
|
246 |
scrollBarPosAnimation.setPropertyName ("scrollBarPos");
|
insilmaril@802
|
247 |
scrollBarPosAnimation.setDuration(1000);
|
insilmaril@802
|
248 |
scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@802
|
249 |
scrollBarPosAnimation.setStartValue(
|
insilmaril@802
|
250 |
QPointF (horizontalScrollBar()->value() ,
|
insilmaril@802
|
251 |
verticalScrollBar()->value() ) );
|
insilmaril@802
|
252 |
scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
|
insilmaril@802
|
253 |
scrollBarPosAnimation.start();
|
insilmaril@802
|
254 |
} else
|
insilmaril@802
|
255 |
setScrollBarPos (scrollBarPosTarget);
|
insilmaril@767
|
256 |
}
|
insilmaril@767
|
257 |
|
insilmaril@767
|
258 |
QPointF MapEditor::getScrollBarPosTarget()
|
insilmaril@767
|
259 |
{
|
insilmaril@767
|
260 |
return scrollBarPosTarget;
|
insilmaril@767
|
261 |
}
|
insilmaril@767
|
262 |
|
insilmaril@767
|
263 |
|
insilmaril@767
|
264 |
void MapEditor::setScrollBarPos(const QPointF &p)
|
insilmaril@767
|
265 |
{
|
insilmaril@767
|
266 |
scrollBarPos=p;
|
insilmaril@767
|
267 |
horizontalScrollBar()->setValue(int(p.x()));
|
insilmaril@767
|
268 |
verticalScrollBar()->setValue(int(p.y()));
|
insilmaril@767
|
269 |
}
|
insilmaril@767
|
270 |
|
insilmaril@767
|
271 |
QPointF MapEditor::getScrollBarPos()
|
insilmaril@767
|
272 |
{
|
insilmaril@802
|
273 |
return QPointF (horizontalScrollBar()->value(),verticalScrollBar()->value());
|
insilmaril@802
|
274 |
//return scrollBarPos;
|
insilmaril@767
|
275 |
}
|
insilmaril@767
|
276 |
|
insilmaril@767
|
277 |
void MapEditor::setZoomFactorTarget (const qreal &zft)
|
insilmaril@767
|
278 |
{
|
insilmaril@767
|
279 |
zoomFactorTarget=zft;
|
insilmaril@767
|
280 |
if (zoomAnimation.state()==QtAbstractAnimation::Running)
|
insilmaril@767
|
281 |
zoomAnimation.stop();
|
insilmaril@802
|
282 |
if (settings.value ("/animation/use/",true).toBool() )
|
insilmaril@802
|
283 |
{
|
insilmaril@815
|
284 |
//zoomAnimation=QPropertyAnimation(this, "zoomFactor");
|
insilmaril@802
|
285 |
zoomAnimation.setTargetObject (this);
|
insilmaril@802
|
286 |
zoomAnimation.setPropertyName ("zoomFactor");
|
insilmaril@802
|
287 |
zoomAnimation.setDuration(1000);
|
insilmaril@802
|
288 |
zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@802
|
289 |
zoomAnimation.setStartValue(zoomFactor);
|
insilmaril@802
|
290 |
zoomAnimation.setEndValue(zft);
|
insilmaril@802
|
291 |
zoomAnimation.start();
|
insilmaril@802
|
292 |
} else
|
insilmaril@802
|
293 |
setZoomFactor (zft);
|
insilmaril@767
|
294 |
}
|
insilmaril@767
|
295 |
|
insilmaril@767
|
296 |
qreal MapEditor::getZoomFactorTarget()
|
insilmaril@767
|
297 |
{
|
insilmaril@767
|
298 |
return zoomFactorTarget;
|
insilmaril@767
|
299 |
}
|
insilmaril@767
|
300 |
|
insilmaril@767
|
301 |
|
insilmaril@767
|
302 |
void MapEditor::setZoomFactor(const qreal &zf)
|
insilmaril@767
|
303 |
{
|
insilmaril@767
|
304 |
zoomFactor=zf;
|
insilmaril@767
|
305 |
setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
|
insilmaril@767
|
306 |
}
|
insilmaril@767
|
307 |
|
insilmaril@767
|
308 |
qreal MapEditor::getZoomFactor()
|
insilmaril@767
|
309 |
{
|
insilmaril@767
|
310 |
return zoomFactor;
|
insilmaril@767
|
311 |
}
|
insilmaril@767
|
312 |
|
insilmaril@0
|
313 |
void MapEditor::print()
|
insilmaril@0
|
314 |
{
|
insilmaril@0
|
315 |
if ( !printer )
|
insilmaril@0
|
316 |
{
|
insilmaril@0
|
317 |
printer = new QPrinter;
|
insilmaril@0
|
318 |
printer->setColorMode (QPrinter::Color);
|
insilmaril@366
|
319 |
printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
|
insilmaril@412
|
320 |
printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
|
insilmaril@412
|
321 |
printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
|
insilmaril@0
|
322 |
}
|
insilmaril@0
|
323 |
|
insilmaril@782
|
324 |
QRectF totalBBox=getTotalBBox();
|
insilmaril@0
|
325 |
|
insilmaril@0
|
326 |
// Try to set orientation automagically
|
insilmaril@0
|
327 |
// Note: Interpretation of generated postscript is amibiguous, if
|
insilmaril@0
|
328 |
// there are problems with landscape mode, see
|
insilmaril@0
|
329 |
// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
|
insilmaril@0
|
330 |
|
insilmaril@0
|
331 |
if (totalBBox.width()>totalBBox.height())
|
insilmaril@0
|
332 |
// recommend landscape
|
insilmaril@0
|
333 |
printer->setOrientation (QPrinter::Landscape);
|
insilmaril@0
|
334 |
else
|
insilmaril@0
|
335 |
// recommend portrait
|
insilmaril@0
|
336 |
printer->setOrientation (QPrinter::Portrait);
|
insilmaril@0
|
337 |
|
insilmaril@0
|
338 |
if ( printer->setup(this) )
|
insilmaril@0
|
339 |
// returns false, if printing is canceled
|
insilmaril@0
|
340 |
{
|
insilmaril@0
|
341 |
QPainter pp(printer);
|
insilmaril@0
|
342 |
|
insilmaril@412
|
343 |
pp.setRenderHint(QPainter::Antialiasing,true);
|
insilmaril@412
|
344 |
|
insilmaril@0
|
345 |
// Don't print the visualisation of selection
|
insilmaril@720
|
346 |
model->unselect();
|
insilmaril@0
|
347 |
|
insilmaril@408
|
348 |
QRectF mapRect=totalBBox;
|
insilmaril@411
|
349 |
QGraphicsRectItem *frame=NULL;
|
insilmaril@412
|
350 |
|
insilmaril@417
|
351 |
if (printFrame)
|
insilmaril@0
|
352 |
{
|
insilmaril@417
|
353 |
// Print frame around map
|
insilmaril@417
|
354 |
mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
|
insilmaril@417
|
355 |
totalBBox.width()+20, totalBBox.height()+20);
|
insilmaril@417
|
356 |
frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
|
insilmaril@417
|
357 |
frame->setZValue(0);
|
insilmaril@417
|
358 |
frame->show();
|
insilmaril@417
|
359 |
}
|
insilmaril@417
|
360 |
|
insilmaril@417
|
361 |
|
insilmaril@412
|
362 |
double paperAspect = (double)printer->width() / (double)printer->height();
|
insilmaril@412
|
363 |
double mapAspect = (double)mapRect.width() / (double)mapRect.height();
|
insilmaril@417
|
364 |
int viewBottom;
|
insilmaril@0
|
365 |
if (mapAspect>=paperAspect)
|
insilmaril@0
|
366 |
{
|
insilmaril@0
|
367 |
// Fit horizontally to paper width
|
insilmaril@417
|
368 |
//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
|
insilmaril@417
|
369 |
viewBottom=(int)(printer->width()/mapAspect);
|
insilmaril@0
|
370 |
} else
|
insilmaril@0
|
371 |
{
|
insilmaril@0
|
372 |
// Fit vertically to paper height
|
insilmaril@417
|
373 |
//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
|
insilmaril@417
|
374 |
viewBottom=printer->height();
|
insilmaril@0
|
375 |
}
|
insilmaril@417
|
376 |
|
insilmaril@417
|
377 |
if (printFooter)
|
insilmaril@417
|
378 |
{
|
insilmaril@417
|
379 |
// Print footer below map
|
insilmaril@417
|
380 |
QFont font;
|
insilmaril@417
|
381 |
font.setPointSize(10);
|
insilmaril@417
|
382 |
pp.setFont (font);
|
insilmaril@417
|
383 |
QRectF footerBox(0,viewBottom,printer->width(),15);
|
insilmaril@746
|
384 |
// FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
|
insilmaril@417
|
385 |
pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
|
insilmaril@417
|
386 |
}
|
insilmaril@412
|
387 |
mapScene->render (
|
insilmaril@412
|
388 |
&pp,
|
insilmaril@412
|
389 |
QRectF (0,0,printer->width(),printer->height()-15),
|
insilmaril@412
|
390 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
|
insilmaril@412
|
391 |
);
|
insilmaril@412
|
392 |
|
insilmaril@412
|
393 |
// Viewport has paper dimension
|
insilmaril@412
|
394 |
if (frame) delete (frame);
|
insilmaril@0
|
395 |
|
insilmaril@0
|
396 |
// Restore selection
|
insilmaril@720
|
397 |
model->reselect();
|
insilmaril@119
|
398 |
|
insilmaril@119
|
399 |
// Save settings in vymrc
|
insilmaril@366
|
400 |
settings.writeEntry("/mainwindow/printerName",printer->printerName());
|
insilmaril@412
|
401 |
settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
|
insilmaril@412
|
402 |
settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
|
insilmaril@0
|
403 |
}
|
insilmaril@0
|
404 |
}
|
insilmaril@0
|
405 |
|
insilmaril@782
|
406 |
QRectF MapEditor::getTotalBBox() //FIXME-2 needed e.g. for image export
|
insilmaril@782
|
407 |
{
|
insilmaril@782
|
408 |
QRectF r;
|
insilmaril@782
|
409 |
/*
|
insilmaril@782
|
410 |
for (int i=0;i<rootItem->branchCount(); i++)
|
insilmaril@782
|
411 |
r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
|
insilmaril@782
|
412 |
*/
|
insilmaril@782
|
413 |
return r;
|
insilmaril@782
|
414 |
}
|
insilmaril@782
|
415 |
|
insilmaril@782
|
416 |
|
insilmaril@782
|
417 |
QPixmap MapEditor::getPixmap()
|
insilmaril@782
|
418 |
{
|
insilmaril@782
|
419 |
QRectF mapRect=getTotalBBox();
|
insilmaril@782
|
420 |
QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
|
insilmaril@782
|
421 |
QPainter pp (&pix);
|
insilmaril@782
|
422 |
|
insilmaril@782
|
423 |
pp.setRenderHints(renderHints());
|
insilmaril@782
|
424 |
|
insilmaril@782
|
425 |
// Don't print the visualisation of selection
|
insilmaril@782
|
426 |
model->unselect();
|
insilmaril@782
|
427 |
|
insilmaril@782
|
428 |
mapScene->render ( &pp,
|
insilmaril@782
|
429 |
QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
|
insilmaril@782
|
430 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
|
insilmaril@782
|
431 |
|
insilmaril@782
|
432 |
// Restore selection
|
insilmaril@782
|
433 |
model->reselect();
|
insilmaril@782
|
434 |
|
insilmaril@782
|
435 |
return pix;
|
insilmaril@782
|
436 |
}
|
insilmaril@782
|
437 |
|
insilmaril@782
|
438 |
|
insilmaril@408
|
439 |
void MapEditor::setAntiAlias (bool b)
|
insilmaril@408
|
440 |
{
|
insilmaril@408
|
441 |
setRenderHint(QPainter::Antialiasing,b);
|
insilmaril@408
|
442 |
}
|
insilmaril@408
|
443 |
|
insilmaril@408
|
444 |
void MapEditor::setSmoothPixmap(bool b)
|
insilmaril@408
|
445 |
{
|
insilmaril@408
|
446 |
setRenderHint(QPainter::SmoothPixmapTransform,b);
|
insilmaril@408
|
447 |
}
|
insilmaril@408
|
448 |
|
insilmaril@754
|
449 |
TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
|
insilmaril@754
|
450 |
{
|
insilmaril@754
|
451 |
// Start with mapcenter, no images allowed at rootItem
|
insilmaril@754
|
452 |
int i=0;
|
insilmaril@754
|
453 |
BranchItem *bi=model->getRootItem()->getFirstBranch();
|
insilmaril@754
|
454 |
TreeItem *found=NULL;
|
insilmaril@754
|
455 |
while (bi)
|
insilmaril@754
|
456 |
{
|
insilmaril@754
|
457 |
found=bi->findMapItem (p, exclude);
|
insilmaril@754
|
458 |
if (found) return found;
|
insilmaril@754
|
459 |
i++;
|
insilmaril@754
|
460 |
bi=model->getRootItem()->getBranchNum(i);
|
insilmaril@754
|
461 |
}
|
insilmaril@754
|
462 |
return NULL;
|
insilmaril@754
|
463 |
}
|
insilmaril@754
|
464 |
|
insilmaril@628
|
465 |
AttributeTable* MapEditor::attributeTable()
|
insilmaril@628
|
466 |
{
|
insilmaril@628
|
467 |
return attrTable;
|
insilmaril@628
|
468 |
}
|
insilmaril@628
|
469 |
|
insilmaril@527
|
470 |
void MapEditor::testFunction1()
|
insilmaril@0
|
471 |
{
|
insilmaril@795
|
472 |
cout << "ME::test1 selected TI="<<model->getSelectedItem()<<endl;
|
insilmaril@798
|
473 |
|
insilmaril@805
|
474 |
for (int i=0; i<200;i++)
|
insilmaril@805
|
475 |
model->addNewBranch();
|
insilmaril@798
|
476 |
|
insilmaril@788
|
477 |
/*
|
insilmaril@767
|
478 |
// Code copied from Qt sources
|
insilmaril@767
|
479 |
QRectF rect=model->getSelectedBranchObj()->getBBox();
|
insilmaril@767
|
480 |
int xmargin=50;
|
insilmaril@767
|
481 |
int ymargin=50;
|
insilmaril@741
|
482 |
|
insilmaril@767
|
483 |
qreal width = viewport()->width();
|
insilmaril@767
|
484 |
qreal height = viewport()->height();
|
insilmaril@767
|
485 |
QRectF viewRect = matrix().mapRect(rect);
|
insilmaril@741
|
486 |
|
insilmaril@767
|
487 |
qreal left = horizontalScrollBar()->value();
|
insilmaril@767
|
488 |
qreal right = left + width;
|
insilmaril@767
|
489 |
qreal top = verticalScrollBar()->value();
|
insilmaril@767
|
490 |
qreal bottom = top + height;
|
insilmaril@723
|
491 |
|
insilmaril@767
|
492 |
if (viewRect.left() <= left + xmargin) {
|
insilmaril@767
|
493 |
// need to scroll from the left
|
insilmaril@767
|
494 |
// if (!d->leftIndent)
|
insilmaril@767
|
495 |
horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
|
insilmaril@767
|
496 |
}
|
insilmaril@767
|
497 |
if (viewRect.right() >= right - xmargin) {
|
insilmaril@767
|
498 |
// need to scroll from the right
|
insilmaril@767
|
499 |
// if (!d->leftIndent)
|
insilmaril@767
|
500 |
horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
|
insilmaril@767
|
501 |
}
|
insilmaril@767
|
502 |
if (viewRect.top() <= top + ymargin) {
|
insilmaril@767
|
503 |
// need to scroll from the top
|
insilmaril@767
|
504 |
// if (!d->topIndent)
|
insilmaril@767
|
505 |
verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
|
insilmaril@767
|
506 |
}
|
insilmaril@767
|
507 |
if (viewRect.bottom() >= bottom - ymargin) {
|
insilmaril@767
|
508 |
// need to scroll from the bottom
|
insilmaril@767
|
509 |
// if (!d->topIndent)
|
insilmaril@767
|
510 |
verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
|
insilmaril@767
|
511 |
}
|
insilmaril@767
|
512 |
cout << "test1: hor="<<horizontalScrollBar()->value()<<endl;
|
insilmaril@767
|
513 |
cout << "test1: ver="<<verticalScrollBar()->value()<<endl;
|
insilmaril@767
|
514 |
}
|
insilmaril@788
|
515 |
|
insilmaril@788
|
516 |
*/
|
insilmaril@741
|
517 |
/*
|
insilmaril@767
|
518 |
QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
|
insilmaril@767
|
519 |
animation->setDuration(5000);
|
insilmaril@767
|
520 |
//animation->setEasingCurve ( QtEasingCurve::OutElastic);
|
insilmaril@767
|
521 |
animation->setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@767
|
522 |
animation->setStartValue(sceneRect() );
|
insilmaril@767
|
523 |
animation->setEndValue(QRectF(50, 50, 1000, 1000));
|
insilmaril@740
|
524 |
|
insilmaril@767
|
525 |
animation->start();
|
insilmaril@767
|
526 |
*/
|
insilmaril@767
|
527 |
/*
|
insilmaril@767
|
528 |
QDialog *dia= new QDialog (this);
|
insilmaril@767
|
529 |
dia->setGeometry (50,50,10,10);
|
insilmaril@723
|
530 |
|
insilmaril@767
|
531 |
dia->show();
|
insilmaril@767
|
532 |
dia ->raise();
|
insilmaril@767
|
533 |
|
insilmaril@767
|
534 |
QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
|
insilmaril@767
|
535 |
animation->setDuration(1000);
|
insilmaril@767
|
536 |
//animation->setEasingCurve ( QtEasingCurve::OutElastic);
|
insilmaril@767
|
537 |
animation->setEasingCurve ( QtEasingCurve::OutQuint);
|
insilmaril@767
|
538 |
animation->setStartValue(QRect(50, 50, 10, 10));
|
insilmaril@767
|
539 |
animation->setEndValue(QRect(250, 250, 100, 100));
|
insilmaril@767
|
540 |
|
insilmaril@767
|
541 |
animation->start();
|
insilmaril@767
|
542 |
*/
|
insilmaril@723
|
543 |
|
insilmaril@791
|
544 |
/* FIXME-4 Hide hidden stuff temporary, maybe add this as regular function somewhere
|
insilmaril@260
|
545 |
if (hidemode==HideNone)
|
insilmaril@185
|
546 |
{
|
insilmaril@260
|
547 |
setHideTmpMode (HideExport);
|
insilmaril@260
|
548 |
mapCenter->calcBBoxSizeWithChilds();
|
insilmaril@408
|
549 |
QRectF totalBBox=mapCenter->getTotalBBox();
|
insilmaril@408
|
550 |
QRectF mapRect=totalBBox;
|
insilmaril@260
|
551 |
QCanvasRectangle *frame=NULL;
|
insilmaril@260
|
552 |
|
insilmaril@260
|
553 |
cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
|
insilmaril@260
|
554 |
|
insilmaril@260
|
555 |
mapRect.setRect (totalBBox.x(), totalBBox.y(),
|
insilmaril@260
|
556 |
totalBBox.width(), totalBBox.height());
|
insilmaril@408
|
557 |
frame=new QCanvasRectangle (mapRect,mapScene);
|
insilmaril@260
|
558 |
frame->setBrush (QColor(white));
|
insilmaril@260
|
559 |
frame->setPen (QColor(black));
|
insilmaril@408
|
560 |
frame->setZValue(0);
|
insilmaril@260
|
561 |
frame->show();
|
insilmaril@260
|
562 |
}
|
insilmaril@260
|
563 |
else
|
insilmaril@260
|
564 |
{
|
insilmaril@260
|
565 |
setHideTmpMode (HideNone);
|
insilmaril@260
|
566 |
}
|
insilmaril@260
|
567 |
cout <<" hidemode="<<hidemode<<endl;
|
insilmaril@301
|
568 |
*/
|
insilmaril@645
|
569 |
|
insilmaril@691
|
570 |
/*
|
insilmaril@628
|
571 |
// Toggle hidemode
|
insilmaril@628
|
572 |
if (hidemode==HideExport)
|
insilmaril@628
|
573 |
setHideTmpMode (HideNone);
|
insilmaril@628
|
574 |
else
|
insilmaril@628
|
575 |
setHideTmpMode (HideExport);
|
insilmaril@691
|
576 |
*/
|
insilmaril@792
|
577 |
|
insilmaril@792
|
578 |
}
|
insilmaril@792
|
579 |
|
insilmaril@792
|
580 |
void MapEditor::testFunction2()
|
insilmaril@792
|
581 |
{
|
insilmaril@792
|
582 |
// Create list with all bounding polygons
|
insilmaril@794
|
583 |
QList <LinkableMapObj*> mapobjects;
|
insilmaril@792
|
584 |
QList <ConvexPolygon> polys;
|
insilmaril@793
|
585 |
ConvexPolygon p;
|
insilmaril@792
|
586 |
QList <Vector> vectors;
|
insilmaril@792
|
587 |
QList <Vector> orgpos;
|
insilmaril@793
|
588 |
QStringList headings; //FIXME-3 testing only
|
insilmaril@793
|
589 |
Vector v;
|
insilmaril@792
|
590 |
BranchItem *bi;
|
insilmaril@793
|
591 |
BranchItem *bi2;
|
insilmaril@792
|
592 |
BranchObj *bo;
|
insilmaril@794
|
593 |
|
insilmaril@794
|
594 |
// Outer loop: Iterate until we no more changes in orientation
|
insilmaril@794
|
595 |
bool orientationChanged=true;
|
insilmaril@794
|
596 |
while (orientationChanged)
|
insilmaril@792
|
597 |
{
|
insilmaril@794
|
598 |
BranchItem *ri=model->getRootItem();
|
insilmaril@794
|
599 |
for (int i=0;i<ri->branchCount();++i)
|
insilmaril@792
|
600 |
{
|
insilmaril@794
|
601 |
bi=ri->getBranchNum (i);
|
insilmaril@794
|
602 |
bo=(BranchObj*)bi->getLMO();
|
insilmaril@793
|
603 |
if (bo)
|
insilmaril@793
|
604 |
{
|
insilmaril@793
|
605 |
mapobjects.append (bo);
|
insilmaril@793
|
606 |
p=bo->getBoundingPolygon();
|
insilmaril@793
|
607 |
p.calcCentroid();
|
insilmaril@793
|
608 |
polys.append(p);
|
insilmaril@793
|
609 |
vectors.append (QPointF(0,0));
|
insilmaril@793
|
610 |
orgpos.append (p.at(0));
|
insilmaril@794
|
611 |
headings.append (bi->getHeading());
|
insilmaril@794
|
612 |
}
|
insilmaril@794
|
613 |
for (int j=0;j<bi->branchCount();++j)
|
insilmaril@792
|
614 |
{
|
insilmaril@794
|
615 |
bi2=bi->getBranchNum (j);
|
insilmaril@794
|
616 |
bo=(BranchObj*)bi2->getLMO();
|
insilmaril@794
|
617 |
if (bo)
|
insilmaril@792
|
618 |
{
|
insilmaril@794
|
619 |
mapobjects.append (bo);
|
insilmaril@794
|
620 |
p=bo->getBoundingPolygon();
|
insilmaril@794
|
621 |
p.calcCentroid();
|
insilmaril@794
|
622 |
polys.append(p);
|
insilmaril@794
|
623 |
vectors.append (QPointF(0,0));
|
insilmaril@794
|
624 |
orgpos.append (p.at(0));
|
insilmaril@794
|
625 |
headings.append (bi2->getHeading());
|
insilmaril@794
|
626 |
}
|
insilmaril@792
|
627 |
}
|
insilmaril@792
|
628 |
}
|
insilmaril@794
|
629 |
|
insilmaril@794
|
630 |
// Iterate moving bounding polygons until we have no more collisions
|
insilmaril@794
|
631 |
int collisions=1;
|
insilmaril@794
|
632 |
while (collisions>0)
|
insilmaril@793
|
633 |
{
|
insilmaril@794
|
634 |
collisions=0;
|
insilmaril@794
|
635 |
for (int i=0; i<polys.size()-1; ++i)
|
insilmaril@794
|
636 |
{
|
insilmaril@794
|
637 |
for (int j=i+1; j<polys.size();++j)
|
insilmaril@794
|
638 |
{
|
insilmaril@794
|
639 |
if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
|
insilmaril@794
|
640 |
{
|
insilmaril@794
|
641 |
collisions++;
|
insilmaril@794
|
642 |
//cout << "Collision: "<<headings[i].toStdString()<<" - "<<headings[j].toStdString()<<endl;
|
insilmaril@794
|
643 |
v=polys.at(j).centroid()-polys.at(i).centroid();
|
insilmaril@794
|
644 |
// Move also away if centroids are identical
|
insilmaril@794
|
645 |
if (v.isNull())
|
insilmaril@794
|
646 |
{
|
insilmaril@794
|
647 |
//cout << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v<<endl;
|
insilmaril@794
|
648 |
v.setX (rand()%200 -100);
|
insilmaril@794
|
649 |
v.setY (rand()%200 -100);
|
insilmaril@794
|
650 |
//cout << v;
|
insilmaril@794
|
651 |
}
|
insilmaril@794
|
652 |
v.normalize();
|
insilmaril@794
|
653 |
v.scale (2);
|
insilmaril@794
|
654 |
//cout << " v="<<v<<endl;
|
insilmaril@794
|
655 |
vectors[j]=v;
|
insilmaril@794
|
656 |
vectors[i]=v;
|
insilmaril@794
|
657 |
vectors[i].invert();
|
insilmaril@794
|
658 |
}
|
insilmaril@794
|
659 |
}
|
insilmaril@794
|
660 |
}
|
insilmaril@794
|
661 |
for (int i=0;i<vectors.size();i++)
|
insilmaril@794
|
662 |
{
|
insilmaril@794
|
663 |
//cout << " v="<<vectors[i]<<" "<<headings[i].toStdString()<<endl;
|
insilmaril@794
|
664 |
polys[i].translate (vectors[i]);
|
insilmaril@794
|
665 |
}
|
insilmaril@794
|
666 |
cout << "Collisions: "<<collisions<<endl;
|
insilmaril@794
|
667 |
//collisions=0;
|
insilmaril@794
|
668 |
}
|
insilmaril@792
|
669 |
|
insilmaril@794
|
670 |
// Finally move the real objects and update
|
insilmaril@794
|
671 |
QList <LinkableMapObj::Orientation> orients;
|
insilmaril@794
|
672 |
for (int i=0;i<polys.size();i++)
|
insilmaril@794
|
673 |
{
|
insilmaril@794
|
674 |
Vector v=polys[i].at(0)-orgpos[i];
|
insilmaril@794
|
675 |
orients.append (mapobjects[i]->getOrientation());
|
insilmaril@794
|
676 |
mapobjects[i]->moveBy(v.x(),v.y() );
|
insilmaril@798
|
677 |
mapobjects[i]->setRelPos();
|
insilmaril@794
|
678 |
}
|
insilmaril@794
|
679 |
model->reposition();
|
insilmaril@794
|
680 |
orientationChanged=false;
|
insilmaril@794
|
681 |
for (int i=0;i<polys.size();i++)
|
insilmaril@794
|
682 |
if (orients[i]!=mapobjects[i]->getOrientation())
|
insilmaril@794
|
683 |
{
|
insilmaril@794
|
684 |
orientationChanged=true;
|
insilmaril@794
|
685 |
break;
|
insilmaril@794
|
686 |
}
|
insilmaril@794
|
687 |
cout << "Final: orientChanged="<<orientationChanged<<endl;
|
insilmaril@794
|
688 |
break;
|
insilmaril@794
|
689 |
//orientationChanged=false;
|
insilmaril@794
|
690 |
} // loop if orientation has changed
|
insilmaril@798
|
691 |
|
insilmaril@798
|
692 |
model->emitSelectionChanged();
|
insilmaril@105
|
693 |
}
|
insilmaril@105
|
694 |
|
insilmaril@787
|
695 |
BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
|
insilmaril@787
|
696 |
{
|
insilmaril@787
|
697 |
if (bi)
|
insilmaril@787
|
698 |
{
|
insilmaril@787
|
699 |
int i=bi->num();
|
insilmaril@787
|
700 |
if (i>0) return bi->parent()->getBranchNum(i-1);
|
insilmaril@787
|
701 |
}
|
insilmaril@787
|
702 |
return NULL;
|
insilmaril@787
|
703 |
}
|
insilmaril@787
|
704 |
|
insilmaril@787
|
705 |
BranchItem* MapEditor::getBranchAbove (BranchItem *selbi)
|
insilmaril@787
|
706 |
{
|
insilmaril@787
|
707 |
if (selbi)
|
insilmaril@787
|
708 |
{
|
insilmaril@787
|
709 |
int dz=selbi->depth(); // original depth
|
insilmaril@787
|
710 |
bool invert=false;
|
insilmaril@787
|
711 |
if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
|
insilmaril@787
|
712 |
invert=true;
|
insilmaril@787
|
713 |
|
insilmaril@787
|
714 |
BranchItem *bi;
|
insilmaril@787
|
715 |
|
insilmaril@787
|
716 |
// Look for branch with same parent but directly above
|
insilmaril@787
|
717 |
if (dz==1 && invert)
|
insilmaril@787
|
718 |
bi=getBranchDirectBelow(selbi);
|
insilmaril@787
|
719 |
else
|
insilmaril@787
|
720 |
bi=getBranchDirectAbove (selbi);
|
insilmaril@787
|
721 |
|
insilmaril@787
|
722 |
if (bi)
|
insilmaril@787
|
723 |
// direct predecessor
|
insilmaril@787
|
724 |
return bi;
|
insilmaril@787
|
725 |
|
insilmaril@787
|
726 |
// Go towards center and look for predecessor
|
insilmaril@787
|
727 |
while (selbi->depth()>0)
|
insilmaril@787
|
728 |
{
|
insilmaril@787
|
729 |
selbi=(BranchItem*)(selbi->parent());
|
insilmaril@787
|
730 |
if (selbi->depth()==1 && invert)
|
insilmaril@787
|
731 |
bi=getBranchDirectBelow (selbi);
|
insilmaril@787
|
732 |
else
|
insilmaril@787
|
733 |
bi=getBranchDirectAbove (selbi);
|
insilmaril@787
|
734 |
if (bi)
|
insilmaril@787
|
735 |
{
|
insilmaril@787
|
736 |
// turn
|
insilmaril@787
|
737 |
selbi=bi;
|
insilmaril@787
|
738 |
while (selbi->depth()<dz)
|
insilmaril@787
|
739 |
{
|
insilmaril@787
|
740 |
// try to get back to original depth dz
|
insilmaril@787
|
741 |
bi=selbi->getLastBranch();
|
insilmaril@787
|
742 |
if (!bi)
|
insilmaril@787
|
743 |
{
|
insilmaril@787
|
744 |
return selbi;
|
insilmaril@787
|
745 |
}
|
insilmaril@787
|
746 |
selbi=bi;
|
insilmaril@787
|
747 |
}
|
insilmaril@787
|
748 |
return selbi;
|
insilmaril@787
|
749 |
}
|
insilmaril@787
|
750 |
}
|
insilmaril@787
|
751 |
}
|
insilmaril@787
|
752 |
return NULL;
|
insilmaril@787
|
753 |
}
|
insilmaril@787
|
754 |
|
insilmaril@787
|
755 |
BranchItem* MapEditor::getBranchDirectBelow(BranchItem *bi)
|
insilmaril@787
|
756 |
{
|
insilmaril@787
|
757 |
if (bi)
|
insilmaril@787
|
758 |
{
|
insilmaril@787
|
759 |
int i=bi->num();
|
insilmaril@787
|
760 |
if (i+1<bi->parent()->branchCount()) return bi->parent()->getBranchNum(i+1);
|
insilmaril@787
|
761 |
}
|
insilmaril@787
|
762 |
return NULL;
|
insilmaril@787
|
763 |
}
|
insilmaril@787
|
764 |
|
insilmaril@787
|
765 |
BranchItem* MapEditor::getBranchBelow (BranchItem *selbi)
|
insilmaril@787
|
766 |
{
|
insilmaril@787
|
767 |
if (selbi)
|
insilmaril@787
|
768 |
{
|
insilmaril@787
|
769 |
BranchItem *bi;
|
insilmaril@787
|
770 |
int dz=selbi->depth(); // original depth
|
insilmaril@787
|
771 |
bool invert=false;
|
insilmaril@787
|
772 |
if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
|
insilmaril@787
|
773 |
invert=true;
|
insilmaril@787
|
774 |
|
insilmaril@787
|
775 |
|
insilmaril@787
|
776 |
// Look for branch with same parent but directly below
|
insilmaril@787
|
777 |
if (dz==1 && invert)
|
insilmaril@787
|
778 |
bi=getBranchDirectAbove (selbi);
|
insilmaril@787
|
779 |
else
|
insilmaril@787
|
780 |
bi=getBranchDirectBelow (selbi);
|
insilmaril@787
|
781 |
if (bi)
|
insilmaril@787
|
782 |
// direct successor
|
insilmaril@787
|
783 |
return bi;
|
insilmaril@787
|
784 |
|
insilmaril@787
|
785 |
|
insilmaril@787
|
786 |
// Go towards center and look for neighbour
|
insilmaril@787
|
787 |
while (selbi->depth()>0)
|
insilmaril@787
|
788 |
{
|
insilmaril@787
|
789 |
selbi=(BranchItem*)(selbi->parent());
|
insilmaril@787
|
790 |
if (selbi->depth()==1 && invert)
|
insilmaril@787
|
791 |
bi=getBranchDirectAbove (selbi);
|
insilmaril@787
|
792 |
else
|
insilmaril@787
|
793 |
bi=getBranchDirectBelow (selbi);
|
insilmaril@787
|
794 |
if (bi)
|
insilmaril@787
|
795 |
{
|
insilmaril@787
|
796 |
// turn
|
insilmaril@787
|
797 |
selbi=bi;
|
insilmaril@787
|
798 |
while (selbi->depth()<dz)
|
insilmaril@787
|
799 |
{
|
insilmaril@787
|
800 |
// try to get back to original depth dz
|
insilmaril@787
|
801 |
bi=selbi->getFirstBranch();
|
insilmaril@787
|
802 |
if (!bi)
|
insilmaril@787
|
803 |
{
|
insilmaril@787
|
804 |
return selbi;
|
insilmaril@787
|
805 |
}
|
insilmaril@787
|
806 |
selbi=bi;
|
insilmaril@787
|
807 |
}
|
insilmaril@787
|
808 |
return selbi;
|
insilmaril@787
|
809 |
}
|
insilmaril@787
|
810 |
}
|
insilmaril@787
|
811 |
}
|
insilmaril@787
|
812 |
return NULL;
|
insilmaril@787
|
813 |
}
|
insilmaril@787
|
814 |
|
insilmaril@787
|
815 |
BranchItem* MapEditor::getLeftBranch (BranchItem *bi)
|
insilmaril@787
|
816 |
{
|
insilmaril@787
|
817 |
if (bi)
|
insilmaril@787
|
818 |
{
|
insilmaril@787
|
819 |
if (bi->depth()==0)
|
insilmaril@787
|
820 |
// Special case: use alternative selection index
|
insilmaril@787
|
821 |
return bi->getLastSelectedBranchAlt();
|
insilmaril@787
|
822 |
if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)
|
insilmaril@787
|
823 |
// right of center
|
insilmaril@787
|
824 |
return (BranchItem*)(bi->parent());
|
insilmaril@787
|
825 |
else
|
insilmaril@787
|
826 |
// left of center
|
insilmaril@787
|
827 |
if (bi->getType()== TreeItem::Branch )
|
insilmaril@787
|
828 |
return bi->getLastSelectedBranch();
|
insilmaril@787
|
829 |
}
|
insilmaril@787
|
830 |
return NULL;
|
insilmaril@787
|
831 |
}
|
insilmaril@787
|
832 |
|
insilmaril@787
|
833 |
BranchItem* MapEditor::getRightBranch(BranchItem *bi)
|
insilmaril@787
|
834 |
{
|
insilmaril@787
|
835 |
if (bi)
|
insilmaril@787
|
836 |
{
|
insilmaril@787
|
837 |
if (bi->depth()==0) return bi->getLastSelectedBranch();
|
insilmaril@787
|
838 |
if (bi->getBranchObj()->getOrientation()==LinkableMapObj::LeftOfCenter)
|
insilmaril@787
|
839 |
// left of center
|
insilmaril@787
|
840 |
return (BranchItem*)(bi->parent());
|
insilmaril@787
|
841 |
else
|
insilmaril@787
|
842 |
// right of center
|
insilmaril@787
|
843 |
if (bi->getType()== TreeItem::Branch )
|
insilmaril@787
|
844 |
return (BranchItem*)bi->getLastSelectedBranch();
|
insilmaril@787
|
845 |
}
|
insilmaril@787
|
846 |
return NULL;
|
insilmaril@787
|
847 |
}
|
insilmaril@787
|
848 |
|
insilmaril@787
|
849 |
|
insilmaril@787
|
850 |
|
insilmaril@769
|
851 |
void MapEditor::cursorUp()
|
insilmaril@769
|
852 |
{
|
insilmaril@787
|
853 |
BranchItem *bi=model->getSelectedBranch();
|
insilmaril@787
|
854 |
if (bi) model->select (getBranchAbove(bi));
|
insilmaril@769
|
855 |
}
|
insilmaril@769
|
856 |
|
insilmaril@769
|
857 |
void MapEditor::cursorDown()
|
insilmaril@769
|
858 |
|
insilmaril@769
|
859 |
{
|
insilmaril@787
|
860 |
BranchItem *bi=model->getSelectedBranch();
|
insilmaril@787
|
861 |
if (bi) model->select (getBranchBelow(bi));
|
insilmaril@769
|
862 |
}
|
insilmaril@769
|
863 |
|
insilmaril@769
|
864 |
void MapEditor::cursorLeft()
|
insilmaril@769
|
865 |
{
|
insilmaril@787
|
866 |
BranchItem *bi=getLeftBranch (model->getSelectedBranch());
|
insilmaril@787
|
867 |
if (bi) model->select (bi);
|
insilmaril@769
|
868 |
}
|
insilmaril@769
|
869 |
|
insilmaril@769
|
870 |
void MapEditor::cursorRight()
|
insilmaril@769
|
871 |
{
|
insilmaril@787
|
872 |
BranchItem *bi=getRightBranch (model->getSelectedBranch());
|
insilmaril@787
|
873 |
if (bi) model->select (bi);
|
insilmaril@769
|
874 |
}
|
insilmaril@769
|
875 |
|
insilmaril@769
|
876 |
void MapEditor::cursorFirst()
|
insilmaril@769
|
877 |
{
|
insilmaril@769
|
878 |
model->selectFirstBranch();
|
insilmaril@769
|
879 |
}
|
insilmaril@769
|
880 |
|
insilmaril@769
|
881 |
void MapEditor::cursorLast()
|
insilmaril@769
|
882 |
{
|
insilmaril@769
|
883 |
model->selectLastBranch();
|
insilmaril@769
|
884 |
}
|
insilmaril@769
|
885 |
|
insilmaril@769
|
886 |
|
insilmaril@720
|
887 |
void MapEditor::editHeading()
|
insilmaril@720
|
888 |
{
|
insilmaril@720
|
889 |
if (editingHeading)
|
insilmaril@720
|
890 |
{
|
insilmaril@720
|
891 |
editHeadingFinished();
|
insilmaril@720
|
892 |
return;
|
insilmaril@720
|
893 |
}
|
insilmaril@753
|
894 |
BranchObj *bo=model->getSelectedBranchObj();
|
insilmaril@787
|
895 |
BranchItem *bi=model->getSelectedBranch();
|
insilmaril@773
|
896 |
if (bo)
|
insilmaril@720
|
897 |
{
|
insilmaril@720
|
898 |
model->setSelectionBlocked(true);
|
insilmaril@720
|
899 |
|
insilmaril@753
|
900 |
lineEdit->setText (bi->getHeading());
|
insilmaril@720
|
901 |
QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
|
insilmaril@720
|
902 |
lineEdit->setGeometry(p.x(),p.y(),230,25);
|
insilmaril@804
|
903 |
//lineEdit->selectAll();
|
insilmaril@804
|
904 |
//lineEdit->setCursorPosition (1);
|
insilmaril@720
|
905 |
lineEdit->show();
|
insilmaril@720
|
906 |
lineEdit->setFocus();
|
insilmaril@720
|
907 |
lineEdit->grabKeyboard();
|
insilmaril@720
|
908 |
editingHeading=true;
|
insilmaril@720
|
909 |
}
|
insilmaril@720
|
910 |
|
insilmaril@720
|
911 |
}
|
insilmaril@720
|
912 |
void MapEditor::editHeadingFinished()
|
insilmaril@720
|
913 |
{
|
insilmaril@720
|
914 |
editingHeading=false;
|
insilmaril@720
|
915 |
lineEdit->releaseKeyboard();
|
insilmaril@720
|
916 |
model->setHeading (lineEdit->text() );
|
insilmaril@720
|
917 |
model->setSelectionBlocked(false);
|
insilmaril@720
|
918 |
lineEdit->hide();
|
insilmaril@720
|
919 |
|
insilmaril@720
|
920 |
// Maybe reselect previous branch
|
insilmaril@720
|
921 |
mainWindow->editHeadingFinished (model);
|
insilmaril@720
|
922 |
}
|
insilmaril@720
|
923 |
|
insilmaril@720
|
924 |
|
insilmaril@408
|
925 |
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
|
insilmaril@0
|
926 |
{
|
insilmaril@0
|
927 |
// Lineedits are already closed by preceding
|
insilmaril@0
|
928 |
// mouseEvent, we don't need to close here.
|
insilmaril@0
|
929 |
|
insilmaril@408
|
930 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
931 |
TreeItem *ti=findMapItem (p, NULL);
|
insilmaril@754
|
932 |
LinkableMapObj* lmo=NULL;
|
insilmaril@779
|
933 |
if (ti) lmo=((MapItem*)ti)->getLMO();
|
insilmaril@0
|
934 |
|
insilmaril@0
|
935 |
if (lmo)
|
insilmaril@0
|
936 |
{ // MapObj was found
|
insilmaril@735
|
937 |
if (model->getSelectedLMO() != lmo)
|
insilmaril@0
|
938 |
{
|
insilmaril@0
|
939 |
// select the MapObj
|
insilmaril@720
|
940 |
model->select(lmo);
|
insilmaril@0
|
941 |
}
|
insilmaril@0
|
942 |
// Context Menu
|
insilmaril@753
|
943 |
if (model->getSelectedBranchObj() )
|
insilmaril@0
|
944 |
{
|
insilmaril@424
|
945 |
// Context Menu on branch or mapcenter
|
insilmaril@424
|
946 |
branchContextMenu->popup(e->globalPos() );
|
insilmaril@424
|
947 |
} else
|
insilmaril@424
|
948 |
{
|
insilmaril@787
|
949 |
if (model->getSelectedImage() )
|
insilmaril@0
|
950 |
{
|
insilmaril@0
|
951 |
// Context Menu on floatimage
|
insilmaril@0
|
952 |
floatimageContextMenu->popup(e->globalPos() );
|
insilmaril@0
|
953 |
}
|
insilmaril@0
|
954 |
}
|
insilmaril@0
|
955 |
} else
|
insilmaril@0
|
956 |
{ // No MapObj found, we are on the Canvas itself
|
insilmaril@408
|
957 |
// Context Menu on scene
|
insilmaril@723
|
958 |
|
insilmaril@723
|
959 |
// Open context menu synchronously to position new mapcenter
|
insilmaril@723
|
960 |
model->setContextPos (p);
|
insilmaril@723
|
961 |
canvasContextMenu->exec(e->globalPos() );
|
insilmaril@723
|
962 |
model->unsetContextPos ();
|
insilmaril@0
|
963 |
}
|
insilmaril@329
|
964 |
e->accept();
|
insilmaril@0
|
965 |
}
|
insilmaril@0
|
966 |
|
insilmaril@398
|
967 |
void MapEditor::keyPressEvent(QKeyEvent* e)
|
insilmaril@398
|
968 |
{
|
insilmaril@411
|
969 |
if (e->modifiers() & Qt::ControlModifier)
|
insilmaril@398
|
970 |
{
|
insilmaril@398
|
971 |
switch (mainWindow->getModMode())
|
insilmaril@398
|
972 |
{
|
insilmaril@473
|
973 |
case Main::ModModeColor:
|
insilmaril@398
|
974 |
setCursor (PickColorCursor);
|
insilmaril@398
|
975 |
break;
|
insilmaril@473
|
976 |
case Main::ModModeCopy:
|
insilmaril@398
|
977 |
setCursor (CopyCursor);
|
insilmaril@398
|
978 |
break;
|
insilmaril@473
|
979 |
case Main::ModModeXLink:
|
insilmaril@398
|
980 |
setCursor (XLinkCursor);
|
insilmaril@398
|
981 |
break;
|
insilmaril@398
|
982 |
default :
|
insilmaril@398
|
983 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
984 |
break;
|
insilmaril@398
|
985 |
}
|
insilmaril@398
|
986 |
}
|
insilmaril@398
|
987 |
}
|
insilmaril@398
|
988 |
|
insilmaril@398
|
989 |
void MapEditor::keyReleaseEvent(QKeyEvent* e)
|
insilmaril@398
|
990 |
{
|
insilmaril@411
|
991 |
if (!(e->modifiers() & Qt::ControlModifier))
|
insilmaril@398
|
992 |
setCursor (Qt::ArrowCursor);
|
insilmaril@398
|
993 |
}
|
insilmaril@398
|
994 |
|
insilmaril@408
|
995 |
void MapEditor::mousePressEvent(QMouseEvent* e)
|
insilmaril@0
|
996 |
{
|
insilmaril@807
|
997 |
//cout << "ME::mousePressed\n"; //FIXME-3
|
insilmaril@329
|
998 |
// Ignore right clicks, these will go to context menus
|
insilmaril@366
|
999 |
if (e->button() == Qt::RightButton )
|
insilmaril@329
|
1000 |
{
|
insilmaril@807
|
1001 |
//cout << " ME::ignoring right mouse event...\n";
|
insilmaril@329
|
1002 |
e->ignore();
|
insilmaril@329
|
1003 |
return;
|
insilmaril@329
|
1004 |
}
|
insilmaril@329
|
1005 |
|
insilmaril@491
|
1006 |
//Ignore clicks while editing heading
|
insilmaril@720
|
1007 |
if (model->isSelectionBlocked() )
|
insilmaril@491
|
1008 |
{
|
insilmaril@807
|
1009 |
//cout << " ME::ignoring other mouse event...\n";
|
insilmaril@491
|
1010 |
e->ignore();
|
insilmaril@491
|
1011 |
return;
|
insilmaril@491
|
1012 |
}
|
insilmaril@491
|
1013 |
|
insilmaril@408
|
1014 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
1015 |
TreeItem *ti=findMapItem (p, NULL);
|
insilmaril@754
|
1016 |
LinkableMapObj* lmo=NULL;
|
insilmaril@779
|
1017 |
if (ti) lmo=((MapItem*)ti)->getLMO();
|
insilmaril@0
|
1018 |
|
insilmaril@790
|
1019 |
|
insilmaril@329
|
1020 |
e->accept();
|
insilmaril@329
|
1021 |
|
insilmaril@442
|
1022 |
//Take care of system flags _or_ modifier modes
|
insilmaril@267
|
1023 |
//
|
insilmaril@773
|
1024 |
if (lmo && ti->isBranchLikeType() )
|
insilmaril@267
|
1025 |
{
|
insilmaril@267
|
1026 |
QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
|
insilmaril@267
|
1027 |
if (!foname.isEmpty())
|
insilmaril@267
|
1028 |
{
|
insilmaril@267
|
1029 |
// systemFlag clicked
|
insilmaril@798
|
1030 |
model->select (lmo);
|
insilmaril@798
|
1031 |
if (foname=="system-url")
|
insilmaril@267
|
1032 |
{
|
insilmaril@366
|
1033 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@267
|
1034 |
mainWindow->editOpenURLTab();
|
insilmaril@267
|
1035 |
else
|
insilmaril@267
|
1036 |
mainWindow->editOpenURL();
|
insilmaril@267
|
1037 |
}
|
insilmaril@780
|
1038 |
else if (foname=="system-vymLink")
|
insilmaril@267
|
1039 |
{
|
insilmaril@267
|
1040 |
mainWindow->editOpenVymLink();
|
insilmaril@267
|
1041 |
// tabWidget may change, better return now
|
insilmaril@267
|
1042 |
// before segfaulting...
|
insilmaril@814
|
1043 |
} else if (foname=="system-note")
|
insilmaril@267
|
1044 |
mainWindow->windowToggleNoteEditor();
|
insilmaril@267
|
1045 |
else if (foname=="hideInExport")
|
insilmaril@720
|
1046 |
model->toggleHideExport();
|
insilmaril@746
|
1047 |
// FIXME-3 needed? xelection.update();
|
insilmaril@267
|
1048 |
return;
|
insilmaril@814
|
1049 |
} else
|
insilmaril@814
|
1050 |
{
|
insilmaril@814
|
1051 |
// Take care of xLink
|
insilmaril@814
|
1052 |
if (ti->xlinkCount()>0 && lmo->getBBox().width()>30)
|
insilmaril@814
|
1053 |
{
|
insilmaril@817
|
1054 |
if ((lmo->getOrientation()!=LinkableMapObj::RightOfCenter && p.x() < lmo->getBBox().left()+20) ||
|
insilmaril@817
|
1055 |
(lmo->getOrientation()!=LinkableMapObj::LeftOfCenter && p.x() > lmo->getBBox().right()-20) )
|
insilmaril@814
|
1056 |
{
|
insilmaril@817
|
1057 |
// FIXME-4 if (ti->xlinkCount()>1)
|
insilmaril@817
|
1058 |
if (true)
|
insilmaril@814
|
1059 |
{
|
insilmaril@814
|
1060 |
QMenu menu;
|
insilmaril@814
|
1061 |
QList <QAction*> alist;
|
insilmaril@814
|
1062 |
for (int i=0;i<ti->xlinkCount();i++)
|
insilmaril@814
|
1063 |
alist.append (new QAction(ti->getXLinkNum(i)->getOtherBranch(ti)->getHeading(),&menu));
|
insilmaril@814
|
1064 |
menu.addActions (alist);
|
insilmaril@814
|
1065 |
QAction *ra=menu.exec (e->globalPos() );
|
insilmaril@814
|
1066 |
if (ra)
|
insilmaril@814
|
1067 |
model->select (ti->getXLinkNum(alist.indexOf(ra))->getOtherBranch (ti));
|
insilmaril@814
|
1068 |
while (!alist.isEmpty())
|
insilmaril@814
|
1069 |
{
|
insilmaril@814
|
1070 |
QAction *a=alist.takeFirst();
|
insilmaril@814
|
1071 |
delete a;
|
insilmaril@814
|
1072 |
}
|
insilmaril@814
|
1073 |
return;
|
insilmaril@814
|
1074 |
} else
|
insilmaril@814
|
1075 |
{
|
insilmaril@814
|
1076 |
model->select (ti->getXLinkNum(0)->getOtherBranch (ti));
|
insilmaril@814
|
1077 |
return;
|
insilmaril@814
|
1078 |
}
|
insilmaril@814
|
1079 |
}
|
insilmaril@814
|
1080 |
}
|
insilmaril@814
|
1081 |
}
|
insilmaril@720
|
1082 |
}
|
insilmaril@814
|
1083 |
|
insilmaril@442
|
1084 |
// No system flag clicked, take care of modmodes (CTRL-Click)
|
insilmaril@366
|
1085 |
if (e->state() & Qt::ControlModifier)
|
insilmaril@0
|
1086 |
{
|
insilmaril@473
|
1087 |
if (mainWindow->getModMode()==Main::ModModeColor)
|
insilmaril@83
|
1088 |
{
|
insilmaril@83
|
1089 |
pickingColor=true;
|
insilmaril@398
|
1090 |
setCursor (PickColorCursor);
|
insilmaril@83
|
1091 |
return;
|
insilmaril@83
|
1092 |
}
|
insilmaril@473
|
1093 |
if (mainWindow->getModMode()==Main::ModModeXLink)
|
insilmaril@83
|
1094 |
{
|
insilmaril@790
|
1095 |
BranchItem *bi_begin=model->getSelectedBranch();
|
insilmaril@790
|
1096 |
if (bi_begin)
|
insilmaril@83
|
1097 |
{
|
insilmaril@83
|
1098 |
drawingLink=true;
|
insilmaril@790
|
1099 |
tmpXLink=model->createXLink(bi_begin,true);
|
insilmaril@720
|
1100 |
tmpXLink->setColor(model->getMapDefXLinkColor());
|
insilmaril@720
|
1101 |
tmpXLink->setWidth(model->getMapDefXLinkWidth());
|
insilmaril@790
|
1102 |
tmpXLink->setEnd (p);
|
insilmaril@95
|
1103 |
tmpXLink->updateXLink();
|
insilmaril@83
|
1104 |
return;
|
insilmaril@89
|
1105 |
}
|
insilmaril@267
|
1106 |
}
|
insilmaril@442
|
1107 |
} // End of modmodes
|
insilmaril@442
|
1108 |
|
insilmaril@0
|
1109 |
if (lmo)
|
insilmaril@267
|
1110 |
{
|
insilmaril@738
|
1111 |
/*
|
insilmaril@729
|
1112 |
cout << "ME::mouse pressed\n";
|
insilmaril@729
|
1113 |
cout << " lmo="<<lmo<<endl;
|
insilmaril@776
|
1114 |
cout << " ti="<<ti->getHeadingStd()<<endl;
|
insilmaril@738
|
1115 |
*/
|
insilmaril@442
|
1116 |
// Select the clicked object
|
insilmaril@729
|
1117 |
|
insilmaril@776
|
1118 |
// Get clicked LMO
|
insilmaril@738
|
1119 |
model->select (ti);
|
insilmaril@442
|
1120 |
|
insilmaril@0
|
1121 |
// Left Button Move Branches
|
insilmaril@366
|
1122 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
1123 |
{
|
insilmaril@424
|
1124 |
movingObj_start.setX( p.x() - lmo->x() );
|
insilmaril@424
|
1125 |
movingObj_start.setY( p.y() - lmo->y() );
|
insilmaril@129
|
1126 |
movingObj_orgPos.setX (lmo->x() );
|
insilmaril@129
|
1127 |
movingObj_orgPos.setY (lmo->y() );
|
insilmaril@720
|
1128 |
lmo->setRelPos();
|
insilmaril@366
|
1129 |
movingObj_orgRelPos=lmo->getRelPos();
|
insilmaril@129
|
1130 |
|
insilmaril@93
|
1131 |
// If modMode==copy, then we want to "move" the _new_ object around
|
insilmaril@93
|
1132 |
// then we need the offset from p to the _old_ selection, because of tmp
|
insilmaril@473
|
1133 |
if (mainWindow->getModMode()==Main::ModModeCopy &&
|
insilmaril@366
|
1134 |
e->state() & Qt::ControlModifier)
|
insilmaril@93
|
1135 |
{
|
insilmaril@787
|
1136 |
BranchItem *bi=model->getSelectedBranch();
|
insilmaril@750
|
1137 |
if (bi)
|
insilmaril@93
|
1138 |
{
|
insilmaril@93
|
1139 |
copyingObj=true;
|
insilmaril@750
|
1140 |
//FIXME-2 TreeItem::addBranch (BranchItem still missing)
|
insilmaril@787
|
1141 |
//bi->addBranch (model->getSelectedBranch());
|
insilmaril@720
|
1142 |
model->unselect();
|
insilmaril@750
|
1143 |
model->select(bi->getLastBranch());
|
insilmaril@645
|
1144 |
model->reposition();
|
insilmaril@93
|
1145 |
}
|
insilmaril@421
|
1146 |
}
|
insilmaril@421
|
1147 |
|
insilmaril@735
|
1148 |
movingObj=model->getSelectedLMO();
|
insilmaril@0
|
1149 |
} else
|
insilmaril@0
|
1150 |
// Middle Button Toggle Scroll
|
insilmaril@0
|
1151 |
// (On Mac OS X this won't work, but we still have
|
insilmaril@0
|
1152 |
// a button in the toolbar)
|
insilmaril@366
|
1153 |
if (e->button() == Qt::MidButton )
|
insilmaril@720
|
1154 |
model->toggleScroll();
|
insilmaril@746
|
1155 |
// model->updateActions(); FIXME-3 needed?
|
insilmaril@746
|
1156 |
// FIXME-3 needed? xelection.update();
|
insilmaril@0
|
1157 |
} else
|
insilmaril@408
|
1158 |
{ // No MapObj found, we are on the scene itself
|
insilmaril@408
|
1159 |
// Left Button move Pos of sceneView
|
insilmaril@366
|
1160 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
1161 |
{
|
insilmaril@0
|
1162 |
movingObj=NULL; // move Content not Obj
|
insilmaril@0
|
1163 |
movingObj_start=e->globalPos();
|
insilmaril@408
|
1164 |
movingCont_start=QPointF (
|
insilmaril@408
|
1165 |
horizontalScrollBar()->value(),
|
insilmaril@408
|
1166 |
verticalScrollBar()->value());
|
insilmaril@408
|
1167 |
movingVec=QPointF(0,0);
|
insilmaril@398
|
1168 |
setCursor(HandOpenCursor);
|
insilmaril@0
|
1169 |
}
|
insilmaril@0
|
1170 |
}
|
insilmaril@0
|
1171 |
}
|
insilmaril@0
|
1172 |
|
insilmaril@408
|
1173 |
void MapEditor::mouseMoveEvent(QMouseEvent* e)
|
insilmaril@0
|
1174 |
{
|
insilmaril@408
|
1175 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
1176 |
TreeItem *seli=model->getSelectedItem();
|
insilmaril@777
|
1177 |
LinkableMapObj* lmosel=NULL;
|
insilmaril@776
|
1178 |
if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image))
|
insilmaril@779
|
1179 |
lmosel=((MapItem*)seli)->getLMO();
|
insilmaril@83
|
1180 |
|
insilmaril@0
|
1181 |
// Move the selected MapObj
|
insilmaril@424
|
1182 |
if ( lmosel && movingObj)
|
insilmaril@0
|
1183 |
{
|
insilmaril@798
|
1184 |
objectMoved=true;
|
insilmaril@421
|
1185 |
// reset cursor if we are moving and don't copy
|
insilmaril@473
|
1186 |
if (mainWindow->getModMode()!=Main::ModModeCopy)
|
insilmaril@421
|
1187 |
setCursor (Qt::ArrowCursor);
|
insilmaril@421
|
1188 |
|
insilmaril@408
|
1189 |
// To avoid jumping of the sceneView, only
|
insilmaril@763
|
1190 |
// show selection, if not tmp linked
|
insilmaril@798
|
1191 |
/* FIXME-2 if (!lmosel->hasParObjTmp())
|
insilmaril@763
|
1192 |
model->emitShowSelection();
|
insilmaril@798
|
1193 |
*/
|
insilmaril@0
|
1194 |
|
insilmaril@83
|
1195 |
// Now move the selection, but add relative position
|
insilmaril@83
|
1196 |
// (movingObj_start) where selection was chosen with
|
insilmaril@83
|
1197 |
// mousepointer. (This avoids flickering resp. jumping
|
insilmaril@0
|
1198 |
// of selection back to absPos)
|
insilmaril@0
|
1199 |
|
insilmaril@0
|
1200 |
// Check if we could link
|
insilmaril@777
|
1201 |
TreeItem *ti=findMapItem (p, seli);
|
insilmaril@777
|
1202 |
BranchItem *dsti=NULL;
|
insilmaril@754
|
1203 |
LinkableMapObj* dst=NULL;
|
insilmaril@777
|
1204 |
if (ti && ti!=seli && ti->isBranchLikeType())
|
insilmaril@777
|
1205 |
{
|
insilmaril@777
|
1206 |
dsti=(BranchItem*)ti;
|
insilmaril@777
|
1207 |
dst=dsti->getLMO();
|
insilmaril@777
|
1208 |
} else
|
insilmaril@772
|
1209 |
dsti=NULL;
|
insilmaril@0
|
1210 |
|
insilmaril@0
|
1211 |
|
insilmaril@777
|
1212 |
if (lmosel && seli->getType()==TreeItem::Image)
|
insilmaril@0
|
1213 |
{
|
insilmaril@776
|
1214 |
FloatObj *fio=(FloatImageObj*)lmosel;
|
insilmaril@424
|
1215 |
fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
|
insilmaril@424
|
1216 |
fio->setRelPos();
|
insilmaril@779
|
1217 |
fio->updateLinkGeometry(); //no need for reposition, if we update link here
|
insilmaril@775
|
1218 |
model->emitSelectionChanged(); // position has changed
|
insilmaril@0
|
1219 |
|
insilmaril@0
|
1220 |
// Relink float to new mapcenter or branch, if shift is pressed
|
insilmaril@0
|
1221 |
// Only relink, if selection really has a new parent
|
insilmaril@777
|
1222 |
if ( e->modifiers()==Qt::ShiftModifier && dsti && dsti != seli->parent() )
|
insilmaril@0
|
1223 |
{
|
insilmaril@773
|
1224 |
// Also save the move which was done so far
|
insilmaril@792
|
1225 |
QString pold=qpointFToString(movingObj_orgRelPos);
|
insilmaril@792
|
1226 |
QString pnow=qpointFToString(fio->getRelPos());
|
insilmaril@773
|
1227 |
model->saveState(
|
insilmaril@777
|
1228 |
seli,
|
insilmaril@773
|
1229 |
"moveRel "+pold,
|
insilmaril@777
|
1230 |
seli,
|
insilmaril@773
|
1231 |
"moveRel "+pnow,
|
insilmaril@773
|
1232 |
QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
|
insilmaril@773
|
1233 |
fio->getParObj()->requestReposition();
|
insilmaril@773
|
1234 |
model->reposition();
|
insilmaril@420
|
1235 |
|
insilmaril@777
|
1236 |
model->relinkImage ((ImageItem*) seli,dsti);
|
insilmaril@777
|
1237 |
model->select (seli);
|
insilmaril@777
|
1238 |
//movingObj=lmosel; //FIXME-3
|
insilmaril@773
|
1239 |
//movingObj_orgRelPos=lmosel->getRelPos();
|
insilmaril@420
|
1240 |
|
insilmaril@773
|
1241 |
model->reposition();
|
insilmaril@0
|
1242 |
}
|
insilmaril@388
|
1243 |
} else
|
insilmaril@388
|
1244 |
{ // selection != a FloatObj
|
insilmaril@798
|
1245 |
if (seli->depth()==0)
|
insilmaril@0
|
1246 |
{
|
insilmaril@814
|
1247 |
// Move mapcenter
|
insilmaril@796
|
1248 |
lmosel->move (p-movingObj_start);
|
insilmaril@388
|
1249 |
if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
|
insilmaril@796
|
1250 |
{
|
insilmaril@814
|
1251 |
// Move only mapcenter, leave its children where they are
|
insilmaril@796
|
1252 |
QPointF v;
|
insilmaril@796
|
1253 |
v=lmosel->getAbsPos();
|
insilmaril@796
|
1254 |
for (int i=0; i<seli->branchCount(); ++i)
|
insilmaril@796
|
1255 |
{
|
insilmaril@796
|
1256 |
seli->getBranchObjNum(i)->setRelPos();
|
insilmaril@796
|
1257 |
seli->getBranchObjNum(i)->setOrientation();
|
insilmaril@796
|
1258 |
}
|
insilmaril@796
|
1259 |
}
|
insilmaril@0
|
1260 |
} else
|
insilmaril@0
|
1261 |
{
|
insilmaril@755
|
1262 |
if (seli->depth()==1)
|
insilmaril@0
|
1263 |
{
|
insilmaril@388
|
1264 |
// Move mainbranch
|
insilmaril@814
|
1265 |
if (!lmosel->hasParObjTmp())
|
insilmaril@814
|
1266 |
lmosel->move(p-movingObj_start);
|
insilmaril@388
|
1267 |
lmosel->setRelPos();
|
insilmaril@0
|
1268 |
} else
|
insilmaril@0
|
1269 |
{
|
insilmaril@388
|
1270 |
// Move ordinary branch
|
insilmaril@473
|
1271 |
if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
|
insilmaril@0
|
1272 |
// Add width of bbox here, otherwise alignRelTo will cause jumping around
|
insilmaril@720
|
1273 |
lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
|
insilmaril@175
|
1274 |
p.y()-movingObj_start.y() +lmosel->getTopPad() );
|
insilmaril@0
|
1275 |
else
|
insilmaril@175
|
1276 |
lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
|
insilmaril@720
|
1277 |
lmosel->setRelPos();
|
insilmaril@0
|
1278 |
}
|
insilmaril@0
|
1279 |
|
insilmaril@794
|
1280 |
} // depth>0
|
insilmaril@431
|
1281 |
// Maybe we can relink temporary?
|
insilmaril@796
|
1282 |
if (dsti) // FIXME-1 check if dsti is ancestor of myself!
|
insilmaril@0
|
1283 |
{
|
insilmaril@388
|
1284 |
if (e->modifiers()==Qt::ControlModifier)
|
insilmaril@0
|
1285 |
{
|
insilmaril@754
|
1286 |
// Special case: CTRL to link below dst
|
insilmaril@754
|
1287 |
lmosel->setParObjTmp (dst,p,+1);
|
insilmaril@814
|
1288 |
} else if (e->modifiers()==Qt::ShiftModifier)
|
insilmaril@754
|
1289 |
lmosel->setParObjTmp (dst,p,-1);
|
insilmaril@0
|
1290 |
else
|
insilmaril@754
|
1291 |
lmosel->setParObjTmp (dst,p,0);
|
insilmaril@0
|
1292 |
} else
|
insilmaril@0
|
1293 |
{
|
insilmaril@93
|
1294 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
1295 |
}
|
insilmaril@428
|
1296 |
// reposition subbranch
|
insilmaril@428
|
1297 |
lmosel->reposition();
|
insilmaril@0
|
1298 |
|
insilmaril@732
|
1299 |
QItemSelection sel=model->getSelectionModel()->selection();
|
insilmaril@735
|
1300 |
updateSelection(sel,sel); // position has changed
|
insilmaril@732
|
1301 |
|
insilmaril@0
|
1302 |
} // no FloatImageObj
|
insilmaril@0
|
1303 |
|
insilmaril@408
|
1304 |
scene()->update();
|
insilmaril@0
|
1305 |
return;
|
insilmaril@0
|
1306 |
} // selection && moving_obj
|
insilmaril@0
|
1307 |
|
insilmaril@83
|
1308 |
// Draw a link from one branch to another
|
insilmaril@83
|
1309 |
if (drawingLink)
|
insilmaril@83
|
1310 |
{
|
insilmaril@95
|
1311 |
tmpXLink->setEnd (p);
|
insilmaril@95
|
1312 |
tmpXLink->updateXLink();
|
insilmaril@83
|
1313 |
}
|
insilmaril@83
|
1314 |
|
insilmaril@408
|
1315 |
// Move sceneView
|
insilmaril@411
|
1316 |
if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
|
insilmaril@0
|
1317 |
{
|
insilmaril@408
|
1318 |
QPointF p=e->globalPos();
|
insilmaril@0
|
1319 |
movingVec.setX(-p.x() + movingObj_start.x() );
|
insilmaril@0
|
1320 |
movingVec.setY(-p.y() + movingObj_start.y() );
|
insilmaril@408
|
1321 |
horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
|
insilmaril@408
|
1322 |
verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
|
insilmaril@0
|
1323 |
}
|
insilmaril@0
|
1324 |
}
|
insilmaril@0
|
1325 |
|
insilmaril@0
|
1326 |
|
insilmaril@408
|
1327 |
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
|
insilmaril@0
|
1328 |
{
|
insilmaril@408
|
1329 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
1330 |
TreeItem *seli=model->getSelectedItem();
|
insilmaril@754
|
1331 |
|
insilmaril@772
|
1332 |
TreeItem *dsti=NULL;
|
insilmaril@772
|
1333 |
if (seli) dsti=findMapItem(p, seli);
|
insilmaril@755
|
1334 |
LinkableMapObj* dst=NULL;
|
insilmaril@772
|
1335 |
if (dsti && dsti->isBranchLikeType ())
|
insilmaril@779
|
1336 |
dst=((MapItem*)dsti)->getLMO();
|
insilmaril@772
|
1337 |
else
|
insilmaril@772
|
1338 |
dsti=NULL;
|
insilmaril@754
|
1339 |
|
insilmaril@754
|
1340 |
|
insilmaril@0
|
1341 |
// Have we been picking color?
|
insilmaril@0
|
1342 |
if (pickingColor)
|
insilmaril@0
|
1343 |
{
|
insilmaril@0
|
1344 |
pickingColor=false;
|
insilmaril@366
|
1345 |
setCursor (Qt::ArrowCursor);
|
insilmaril@0
|
1346 |
// Check if we are over another branch
|
insilmaril@772
|
1347 |
if (dst)
|
insilmaril@0
|
1348 |
{
|
insilmaril@366
|
1349 |
if (e->state() & Qt::ShiftModifier)
|
insilmaril@720
|
1350 |
model->colorBranch (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
1351 |
else
|
insilmaril@720
|
1352 |
model->colorSubtree (((BranchObj*)dst)->getColor());
|
insilmaril@0
|
1353 |
}
|
insilmaril@0
|
1354 |
return;
|
insilmaril@0
|
1355 |
}
|
insilmaril@83
|
1356 |
|
insilmaril@83
|
1357 |
// Have we been drawing a link?
|
insilmaril@491
|
1358 |
if (drawingLink)
|
insilmaril@83
|
1359 |
{
|
insilmaril@83
|
1360 |
drawingLink=false;
|
insilmaril@83
|
1361 |
// Check if we are over another branch
|
insilmaril@772
|
1362 |
if (dsti)
|
insilmaril@83
|
1363 |
{
|
insilmaril@790
|
1364 |
tmpXLink->setEnd ( ((BranchItem*)dsti) );
|
insilmaril@95
|
1365 |
tmpXLink->updateXLink();
|
insilmaril@790
|
1366 |
tmpXLink->activate();
|
insilmaril@794
|
1367 |
model->saveState(
|
insilmaril@794
|
1368 |
tmpXLink,QString("delete ()"),
|
insilmaril@794
|
1369 |
dsti,QString("addXLink (\"%1\",\"%2\")").arg(model->getSelectString(tmpXLink->getBegin())).arg(model->getSelectString(dsti)),
|
insilmaril@794
|
1370 |
QString("Add xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(dsti))
|
insilmaril@794
|
1371 |
);
|
insilmaril@83
|
1372 |
} else
|
insilmaril@83
|
1373 |
{
|
insilmaril@790
|
1374 |
model->deleteItem(tmpXLink);
|
insilmaril@95
|
1375 |
tmpXLink=NULL;
|
insilmaril@83
|
1376 |
}
|
insilmaril@83
|
1377 |
return;
|
insilmaril@83
|
1378 |
}
|
insilmaril@83
|
1379 |
|
insilmaril@0
|
1380 |
// Have we been moving something?
|
insilmaril@754
|
1381 |
if ( seli && movingObj )
|
insilmaril@0
|
1382 |
{
|
insilmaril@776
|
1383 |
if (seli->getType()==TreeItem::Image)
|
insilmaril@175
|
1384 |
{
|
insilmaril@779
|
1385 |
FloatImageObj *fio=(FloatImageObj*)( ((MapItem*)seli)->getLMO());
|
insilmaril@776
|
1386 |
if(fio)
|
insilmaril@776
|
1387 |
{
|
insilmaril@776
|
1388 |
// Moved FloatObj. Maybe we need to reposition
|
insilmaril@792
|
1389 |
QString pold=qpointFToString(movingObj_orgRelPos);
|
insilmaril@792
|
1390 |
QString pnow=qpointFToString(fio->getRelPos());
|
insilmaril@776
|
1391 |
model->saveState(
|
insilmaril@776
|
1392 |
seli,
|
insilmaril@776
|
1393 |
"moveRel "+pold,
|
insilmaril@776
|
1394 |
seli,
|
insilmaril@776
|
1395 |
"moveRel "+pnow,
|
insilmaril@776
|
1396 |
QString("Move %1 to relative position %2").arg(model->getObjectName(seli)).arg(pnow));
|
insilmaril@424
|
1397 |
|
insilmaril@785
|
1398 |
cout << "ME::release mouse\n";
|
insilmaril@776
|
1399 |
fio->getParObj()->requestReposition();
|
insilmaril@776
|
1400 |
model->reposition();
|
insilmaril@776
|
1401 |
}
|
insilmaril@776
|
1402 |
}
|
insilmaril@175
|
1403 |
|
insilmaril@787
|
1404 |
BranchItem *bi=model->getSelectedBranch();
|
insilmaril@753
|
1405 |
if (bi && bi->depth()==0)
|
insilmaril@497
|
1406 |
{
|
insilmaril@753
|
1407 |
if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
|
insilmaril@625
|
1408 |
{
|
insilmaril@792
|
1409 |
QString pold=qpointFToString(movingObj_orgPos);
|
insilmaril@792
|
1410 |
QString pnow=qpointFToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
|
insilmaril@753
|
1411 |
|
insilmaril@720
|
1412 |
model->saveState(
|
insilmaril@753
|
1413 |
bi,
|
insilmaril@625
|
1414 |
"move "+pold,
|
insilmaril@753
|
1415 |
bi,
|
insilmaril@625
|
1416 |
"move "+pnow,
|
insilmaril@753
|
1417 |
QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
|
insilmaril@625
|
1418 |
}
|
insilmaril@388
|
1419 |
}
|
insilmaril@645
|
1420 |
|
insilmaril@773
|
1421 |
if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
|
insilmaril@388
|
1422 |
{ // A branch was moved
|
insilmaril@777
|
1423 |
LinkableMapObj* lmosel=NULL;
|
insilmaril@779
|
1424 |
lmosel=((MapItem*)seli)->getLMO();
|
insilmaril@760
|
1425 |
|
insilmaril@0
|
1426 |
// save the position in case we link to mapcenter
|
insilmaril@424
|
1427 |
QPointF savePos=QPointF (lmosel->getAbsPos() );
|
insilmaril@0
|
1428 |
|
insilmaril@0
|
1429 |
// Reset the temporary drawn link to the original one
|
insilmaril@424
|
1430 |
lmosel->unsetParObjTmp();
|
insilmaril@0
|
1431 |
|
insilmaril@366
|
1432 |
// For Redo we may need to save original selection
|
insilmaril@773
|
1433 |
QString preSelStr=model->getSelectString(seli);
|
insilmaril@93
|
1434 |
|
insilmaril@94
|
1435 |
copyingObj=false;
|
insilmaril@798
|
1436 |
if (dsti && objectMoved)
|
insilmaril@93
|
1437 |
{
|
insilmaril@691
|
1438 |
// We have a destination, relink to that
|
insilmaril@691
|
1439 |
|
insilmaril@753
|
1440 |
BranchObj* bsel=model->getSelectedBranchObj();
|
insilmaril@366
|
1441 |
|
insilmaril@684
|
1442 |
QString preParStr=model->getSelectString (bsel->getParObj());
|
insilmaril@755
|
1443 |
QString preNum=QString::number (seli->num(),10);
|
insilmaril@366
|
1444 |
QString preDstParStr;
|
insilmaril@767
|
1445 |
bool relinked;
|
insilmaril@366
|
1446 |
|
insilmaril@366
|
1447 |
if (e->state() & Qt::ShiftModifier && dst->getParObj())
|
insilmaril@366
|
1448 |
{ // Link above dst
|
insilmaril@684
|
1449 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@767
|
1450 |
relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
|
insilmaril@366
|
1451 |
} else
|
insilmaril@366
|
1452 |
if (e->state() & Qt::ControlModifier && dst->getParObj())
|
insilmaril@366
|
1453 |
{
|
insilmaril@366
|
1454 |
// Link below dst
|
insilmaril@684
|
1455 |
preDstParStr=model->getSelectString (dst->getParObj());
|
insilmaril@767
|
1456 |
relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
|
insilmaril@366
|
1457 |
} else
|
insilmaril@366
|
1458 |
{ // Append to dst
|
insilmaril@684
|
1459 |
preDstParStr=model->getSelectString(dst);
|
insilmaril@767
|
1460 |
relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
|
insilmaril@755
|
1461 |
if (dsti->depth()==0) bsel->move (savePos);
|
insilmaril@366
|
1462 |
}
|
insilmaril@767
|
1463 |
if (relinked)
|
insilmaril@767
|
1464 |
{
|
insilmaril@767
|
1465 |
QString postSelStr=model->getSelectString(lmosel);
|
insilmaril@767
|
1466 |
QString postNum=QString::number (seli->num(),10);
|
insilmaril@366
|
1467 |
|
insilmaril@776
|
1468 |
QString undoCom="relinkTo (\""+
|
insilmaril@767
|
1469 |
preParStr+ "\"," + preNum +"," +
|
insilmaril@767
|
1470 |
QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
|
insilmaril@366
|
1471 |
|
insilmaril@776
|
1472 |
QString redoCom="relinkTo (\""+
|
insilmaril@767
|
1473 |
preDstParStr + "\"," + postNum + "," +
|
insilmaril@767
|
1474 |
QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
|
insilmaril@366
|
1475 |
|
insilmaril@767
|
1476 |
model->saveState (
|
insilmaril@767
|
1477 |
postSelStr,undoCom,
|
insilmaril@767
|
1478 |
preSelStr, redoCom,
|
insilmaril@767
|
1479 |
QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
|
insilmaril@691
|
1480 |
|
insilmaril@767
|
1481 |
}
|
insilmaril@163
|
1482 |
} else
|
insilmaril@691
|
1483 |
{
|
insilmaril@815
|
1484 |
// No destination, undo temporary move
|
insilmaril@691
|
1485 |
|
insilmaril@755
|
1486 |
if (seli->depth()==1)
|
insilmaril@366
|
1487 |
{
|
insilmaril@366
|
1488 |
// The select string might be different _after_ moving around.
|
insilmaril@366
|
1489 |
// Therefor reposition and then use string of old selection, too
|
insilmaril@645
|
1490 |
model->reposition();
|
insilmaril@366
|
1491 |
|
insilmaril@625
|
1492 |
QPointF rp(lmosel->getRelPos());
|
insilmaril@625
|
1493 |
if (rp != movingObj_orgRelPos)
|
insilmaril@625
|
1494 |
{
|
insilmaril@792
|
1495 |
QString ps=qpointFToString(rp);
|
insilmaril@720
|
1496 |
model->saveState(
|
insilmaril@792
|
1497 |
model->getSelectString(lmosel), "moveRel "+qpointFToString(movingObj_orgRelPos),
|
insilmaril@625
|
1498 |
preSelStr, "moveRel "+ps,
|
insilmaril@726
|
1499 |
QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
|
insilmaril@625
|
1500 |
}
|
insilmaril@366
|
1501 |
}
|
insilmaril@691
|
1502 |
|
insilmaril@691
|
1503 |
// Draw the original link, before selection was moved around
|
insilmaril@815
|
1504 |
if (settings.value("/animation/use",true).toBool() && seli->depth()>1)
|
insilmaril@691
|
1505 |
{
|
insilmaril@720
|
1506 |
lmosel->setRelPos(); // calc relPos first for starting point
|
insilmaril@720
|
1507 |
|
insilmaril@691
|
1508 |
model->startAnimation(
|
insilmaril@723
|
1509 |
(BranchObj*)lmosel,
|
insilmaril@691
|
1510 |
lmosel->getRelPos(),
|
insilmaril@720
|
1511 |
movingObj_orgRelPos
|
insilmaril@691
|
1512 |
);
|
insilmaril@691
|
1513 |
} else
|
insilmaril@691
|
1514 |
model->reposition();
|
insilmaril@691
|
1515 |
}
|
insilmaril@0
|
1516 |
}
|
insilmaril@775
|
1517 |
model->emitSelectionChanged(); //FIXME-3 needed? at least not after pos of selection has changed...
|
insilmaril@408
|
1518 |
// Finally resize scene, if needed
|
insilmaril@408
|
1519 |
scene()->update();
|
insilmaril@0
|
1520 |
movingObj=NULL;
|
insilmaril@798
|
1521 |
objectMoved=false;
|
insilmaril@366
|
1522 |
|
insilmaril@0
|
1523 |
} else
|
insilmaril@83
|
1524 |
// maybe we moved View: set old cursor
|
insilmaril@366
|
1525 |
setCursor (Qt::ArrowCursor);
|
insilmaril@83
|
1526 |
|
insilmaril@0
|
1527 |
}
|
insilmaril@0
|
1528 |
|
insilmaril@408
|
1529 |
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
|
insilmaril@0
|
1530 |
{
|
insilmaril@802
|
1531 |
if (debug)
|
insilmaril@802
|
1532 |
{
|
insilmaril@802
|
1533 |
cout << "ME p="<<mapToScene (e->pos())<<" scrollBarPos="<<getScrollBarPos();
|
insilmaril@802
|
1534 |
cout << " min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
|
insilmaril@802
|
1535 |
cout << endl;
|
insilmaril@802
|
1536 |
}
|
insilmaril@798
|
1537 |
|
insilmaril@798
|
1538 |
|
insilmaril@720
|
1539 |
if (model->isSelectionBlocked() )
|
insilmaril@491
|
1540 |
{
|
insilmaril@491
|
1541 |
e->ignore();
|
insilmaril@491
|
1542 |
return;
|
insilmaril@491
|
1543 |
}
|
insilmaril@491
|
1544 |
|
insilmaril@366
|
1545 |
if (e->button() == Qt::LeftButton )
|
insilmaril@0
|
1546 |
{
|
insilmaril@408
|
1547 |
QPointF p = mapToScene(e->pos());
|
insilmaril@754
|
1548 |
TreeItem *ti=findMapItem (p, NULL);
|
insilmaril@754
|
1549 |
if (ti) { // MapObj was found
|
insilmaril@0
|
1550 |
// First select the MapObj than edit heading
|
insilmaril@754
|
1551 |
model->select (ti);
|
insilmaril@720
|
1552 |
editHeading();
|
insilmaril@0
|
1553 |
}
|
insilmaril@0
|
1554 |
}
|
insilmaril@0
|
1555 |
}
|
insilmaril@0
|
1556 |
|
insilmaril@0
|
1557 |
void MapEditor::resizeEvent (QResizeEvent* e)
|
insilmaril@0
|
1558 |
{
|
insilmaril@408
|
1559 |
QGraphicsView::resizeEvent( e );
|
insilmaril@0
|
1560 |
}
|
insilmaril@0
|
1561 |
|
insilmaril@412
|
1562 |
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
|
insilmaril@119
|
1563 |
{
|
insilmaril@417
|
1564 |
//for (unsigned int i=0;event->format(i);i++) // Debug mime type
|
insilmaril@417
|
1565 |
// cerr << event->format(i) << endl;
|
insilmaril@417
|
1566 |
|
insilmaril@417
|
1567 |
if (event->mimeData()->hasImage())
|
insilmaril@417
|
1568 |
event->acceptProposedAction();
|
insilmaril@417
|
1569 |
else
|
insilmaril@417
|
1570 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
1571 |
event->acceptProposedAction();
|
insilmaril@417
|
1572 |
}
|
insilmaril@417
|
1573 |
|
insilmaril@531
|
1574 |
void MapEditor::dragMoveEvent(QDragMoveEvent *)
|
insilmaril@417
|
1575 |
{
|
insilmaril@417
|
1576 |
}
|
insilmaril@417
|
1577 |
|
insilmaril@417
|
1578 |
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
|
insilmaril@417
|
1579 |
{
|
insilmaril@417
|
1580 |
event->accept();
|
insilmaril@119
|
1581 |
}
|
insilmaril@129
|
1582 |
|
insilmaril@412
|
1583 |
void MapEditor::dropEvent(QDropEvent *event)
|
insilmaril@129
|
1584 |
{
|
insilmaril@787
|
1585 |
BranchItem *selbi=model->getSelectedBranch();
|
insilmaril@753
|
1586 |
if (selbi)
|
insilmaril@128
|
1587 |
{
|
insilmaril@505
|
1588 |
if (debug)
|
insilmaril@505
|
1589 |
foreach (QString format,event->mimeData()->formats())
|
insilmaril@658
|
1590 |
cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
|
insilmaril@497
|
1591 |
|
insilmaril@497
|
1592 |
|
insilmaril@417
|
1593 |
QList <QUrl> uris;
|
insilmaril@417
|
1594 |
if (event->mimeData()->hasImage())
|
insilmaril@128
|
1595 |
{
|
insilmaril@417
|
1596 |
QVariant imageData = event->mimeData()->imageData();
|
insilmaril@720
|
1597 |
model->addFloatImage (qvariant_cast<QPixmap>(imageData));
|
insilmaril@417
|
1598 |
} else
|
insilmaril@417
|
1599 |
if (event->mimeData()->hasUrls())
|
insilmaril@417
|
1600 |
uris=event->mimeData()->urls();
|
insilmaril@417
|
1601 |
|
insilmaril@417
|
1602 |
if (uris.count()>0)
|
insilmaril@128
|
1603 |
{
|
insilmaril@417
|
1604 |
QStringList files;
|
insilmaril@417
|
1605 |
QString s;
|
insilmaril@417
|
1606 |
QString heading;
|
insilmaril@753
|
1607 |
BranchItem *bi;
|
insilmaril@428
|
1608 |
for (int i=0; i<uris.count();i++)
|
insilmaril@408
|
1609 |
{
|
insilmaril@428
|
1610 |
// Workaround to avoid adding empty branches
|
insilmaril@428
|
1611 |
if (!uris.at(i).toString().isEmpty())
|
insilmaril@417
|
1612 |
{
|
insilmaril@775
|
1613 |
bi=model->addNewBranch();
|
insilmaril@753
|
1614 |
if (bi)
|
insilmaril@417
|
1615 |
{
|
insilmaril@753
|
1616 |
/* FIXME-2
|
insilmaril@428
|
1617 |
s=uris.at(i).toLocalFile();
|
insilmaril@428
|
1618 |
if (!s.isEmpty())
|
insilmaril@428
|
1619 |
{
|
insilmaril@625
|
1620 |
QString file = QDir::fromNativeSeparators(s);
|
insilmaril@428
|
1621 |
heading = QFileInfo(file).baseName();
|
insilmaril@428
|
1622 |
files.append(file);
|
insilmaril@428
|
1623 |
if (file.endsWith(".vym", false))
|
insilmaril@753
|
1624 |
bi->setVymLink(file);
|
insilmaril@428
|
1625 |
else
|
insilmaril@753
|
1626 |
bi->setURL(uris.at(i).toString());
|
insilmaril@428
|
1627 |
} else
|
insilmaril@428
|
1628 |
{
|
insilmaril@428
|
1629 |
bo->setURL(uris.at(i).toString());
|
insilmaril@428
|
1630 |
}
|
insilmaril@753
|
1631 |
*/
|
insilmaril@428
|
1632 |
|
insilmaril@428
|
1633 |
if (!heading.isEmpty())
|
insilmaril@753
|
1634 |
bi->setHeading(heading);
|
insilmaril@428
|
1635 |
else
|
insilmaril@753
|
1636 |
bi->setHeading(uris.at(i).toString());
|
insilmaril@753
|
1637 |
|
insilmaril@428
|
1638 |
}
|
insilmaril@417
|
1639 |
}
|
insilmaril@417
|
1640 |
}
|
insilmaril@645
|
1641 |
model->reposition();
|
insilmaril@417
|
1642 |
}
|
insilmaril@417
|
1643 |
}
|
insilmaril@417
|
1644 |
event->acceptProposedAction();
|
insilmaril@417
|
1645 |
}
|
insilmaril@417
|
1646 |
|
insilmaril@776
|
1647 |
void MapEditor::updateSelection(QItemSelection newsel,QItemSelection oldsel)
|
insilmaril@728
|
1648 |
{
|
insilmaril@779
|
1649 |
// Note: Here we are prepared for multiple selections, though this
|
insilmaril@779
|
1650 |
// is not yet implemented elsewhere
|
insilmaril@779
|
1651 |
|
insilmaril@776
|
1652 |
// Here in MapEditor we can only select Branches and Images
|
insilmaril@786
|
1653 |
QList <TreeItem*> treeItemsNew;
|
insilmaril@786
|
1654 |
QList <TreeItem*> treeItemsOld;
|
insilmaril@786
|
1655 |
|
insilmaril@807
|
1656 |
QModelIndex newIndex;
|
insilmaril@807
|
1657 |
|
insilmaril@796
|
1658 |
bool do_reposition=false;
|
insilmaril@796
|
1659 |
|
insilmaril@776
|
1660 |
QModelIndex ix;
|
insilmaril@776
|
1661 |
foreach (ix,newsel.indexes() )
|
insilmaril@776
|
1662 |
{
|
insilmaril@776
|
1663 |
TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
|
insilmaril@787
|
1664 |
if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
|
insilmaril@786
|
1665 |
if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti);
|
insilmaril@786
|
1666 |
}
|
insilmaril@786
|
1667 |
foreach (ix,oldsel.indexes() )
|
insilmaril@786
|
1668 |
{
|
insilmaril@786
|
1669 |
TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
|
insilmaril@787
|
1670 |
if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
|
insilmaril@786
|
1671 |
if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti);
|
insilmaril@776
|
1672 |
}
|
insilmaril@776
|
1673 |
|
insilmaril@779
|
1674 |
// Trim list of selection rectangles
|
insilmaril@786
|
1675 |
while (treeItemsNew.count() < selboxList.count() )
|
insilmaril@776
|
1676 |
delete selboxList.takeFirst();
|
insilmaril@776
|
1677 |
|
insilmaril@775
|
1678 |
// Take care to tmp scroll/unscroll
|
insilmaril@775
|
1679 |
if (!oldsel.isEmpty())
|
insilmaril@775
|
1680 |
{
|
insilmaril@775
|
1681 |
QModelIndex ix=oldsel.indexes().first();
|
insilmaril@775
|
1682 |
if (ix.isValid() )
|
insilmaril@775
|
1683 |
{
|
insilmaril@775
|
1684 |
TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
|
insilmaril@779
|
1685 |
if (ti)
|
insilmaril@775
|
1686 |
{
|
insilmaril@779
|
1687 |
if (ti->isBranchLikeType() )
|
insilmaril@779
|
1688 |
{
|
insilmaril@779
|
1689 |
// reset tmp scrolled branches
|
insilmaril@779
|
1690 |
BranchItem *bi=(BranchItem*)ti;
|
insilmaril@796
|
1691 |
if (bi->resetTmpUnscroll() )
|
insilmaril@796
|
1692 |
do_reposition=true;
|
insilmaril@779
|
1693 |
}
|
insilmaril@779
|
1694 |
if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
|
insilmaril@779
|
1695 |
// Hide link if not needed
|
insilmaril@779
|
1696 |
((MapItem*)ti)->getLMO()->updateVisibility();
|
insilmaril@775
|
1697 |
}
|
insilmaril@775
|
1698 |
}
|
insilmaril@775
|
1699 |
}
|
insilmaril@775
|
1700 |
|
insilmaril@786
|
1701 |
if (!treeItemsNew.isEmpty())
|
insilmaril@775
|
1702 |
{
|
insilmaril@775
|
1703 |
QModelIndex ix=newsel.indexes().first();
|
insilmaril@775
|
1704 |
if (ix.isValid() )
|
insilmaril@775
|
1705 |
{
|
insilmaril@807
|
1706 |
newIndex=ix;
|
insilmaril@807
|
1707 |
|
insilmaril@775
|
1708 |
// Temporary unscroll if necessary
|
insilmaril@775
|
1709 |
TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
|
insilmaril@775
|
1710 |
if (ti->isBranchLikeType() )
|
insilmaril@775
|
1711 |
{
|
insilmaril@775
|
1712 |
BranchItem *bi=(BranchItem*)ti;
|
insilmaril@775
|
1713 |
if (bi->hasScrolledParent(bi) )
|
insilmaril@796
|
1714 |
{
|
insilmaril@796
|
1715 |
if (bi->parentBranch()->tmpUnscroll() )
|
insilmaril@796
|
1716 |
do_reposition=true;
|
insilmaril@796
|
1717 |
}
|
insilmaril@775
|
1718 |
}
|
insilmaril@779
|
1719 |
if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
|
insilmaril@779
|
1720 |
// Show link if needed
|
insilmaril@779
|
1721 |
((MapItem*)ti)->getLMO()->updateVisibility();
|
insilmaril@775
|
1722 |
}
|
insilmaril@775
|
1723 |
}
|
insilmaril@796
|
1724 |
if (do_reposition) model->reposition();
|
insilmaril@775
|
1725 |
|
insilmaril@731
|
1726 |
// Reduce rectangles
|
insilmaril@786
|
1727 |
while (treeItemsNew.count() < selboxList.count() )
|
insilmaril@731
|
1728 |
delete selboxList.takeFirst();
|
insilmaril@731
|
1729 |
|
insilmaril@731
|
1730 |
// Add additonal rectangles
|
insilmaril@731
|
1731 |
QGraphicsRectItem *sb;
|
insilmaril@786
|
1732 |
while (treeItemsNew.count() > selboxList.count() )
|
insilmaril@728
|
1733 |
{
|
insilmaril@731
|
1734 |
sb = mapScene->addRect(
|
insilmaril@731
|
1735 |
QRectF(0,0,0,0),
|
insilmaril@731
|
1736 |
QPen(selectionColor),
|
insilmaril@731
|
1737 |
selectionColor);
|
insilmaril@731
|
1738 |
sb->setZValue(Z_SELBOX);
|
insilmaril@731
|
1739 |
sb->show();
|
insilmaril@731
|
1740 |
selboxList.append (sb);
|
insilmaril@728
|
1741 |
}
|
insilmaril@731
|
1742 |
|
insilmaril@731
|
1743 |
// Reposition rectangles
|
insilmaril@731
|
1744 |
QRectF bbox;
|
insilmaril@732
|
1745 |
QModelIndex index;
|
insilmaril@732
|
1746 |
|
insilmaril@732
|
1747 |
LinkableMapObj *lmo;
|
insilmaril@786
|
1748 |
for (int i=0; i<treeItemsNew.count();++i)
|
insilmaril@731
|
1749 |
{
|
insilmaril@786
|
1750 |
lmo=((MapItem*)treeItemsNew.at(i) )->getLMO();
|
insilmaril@731
|
1751 |
bbox=lmo->getBBox();
|
insilmaril@786
|
1752 |
sb=selboxList.at(i);
|
insilmaril@731
|
1753 |
sb->setRect (
|
insilmaril@731
|
1754 |
bbox.x(),bbox.y(),
|
insilmaril@731
|
1755 |
bbox.width(), bbox.height());
|
insilmaril@731
|
1756 |
sb->setPen (selectionColor);
|
insilmaril@731
|
1757 |
sb->setBrush (selectionColor);
|
insilmaril@731
|
1758 |
i++;
|
insilmaril@731
|
1759 |
}
|
insilmaril@775
|
1760 |
|
insilmaril@804
|
1761 |
scene()->update();
|
insilmaril@729
|
1762 |
}
|
insilmaril@728
|
1763 |
|
insilmaril@753
|
1764 |
void MapEditor::updateData (const QModelIndex &sel)
|
insilmaril@729
|
1765 |
{
|
insilmaril@753
|
1766 |
TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
|
insilmaril@732
|
1767 |
|
insilmaril@746
|
1768 |
/* testing
|
insilmaril@753
|
1769 |
cout << "ME::updateData\n";
|
insilmaril@732
|
1770 |
|
insilmaril@753
|
1771 |
cout << " ti="<<ti<<endl;
|
insilmaril@753
|
1772 |
cout << " h="<<ti->getHeading().toStdString()<<endl;
|
insilmaril@729
|
1773 |
*/
|
insilmaril@753
|
1774 |
|
insilmaril@753
|
1775 |
if (ti->isBranchLikeType())
|
insilmaril@753
|
1776 |
{
|
insilmaril@785
|
1777 |
// cout << " ->updating...\n";
|
insilmaril@779
|
1778 |
BranchObj *bo=(BranchObj*) ( ((MapItem*)ti)->getLMO());
|
insilmaril@767
|
1779 |
bo->updateData();
|
insilmaril@753
|
1780 |
}
|
insilmaril@726
|
1781 |
}
|
insilmaril@412
|
1782 |
|
insilmaril@728
|
1783 |
void MapEditor::setSelectionColor (QColor col)
|
insilmaril@728
|
1784 |
{
|
insilmaril@728
|
1785 |
selectionColor=col;
|
insilmaril@732
|
1786 |
QItemSelection sel=model->getSelectionModel()->selection();
|
insilmaril@732
|
1787 |
updateSelection(sel,sel);
|
insilmaril@728
|
1788 |
}
|
insilmaril@728
|
1789 |
|
insilmaril@753
|
1790 |
|
insilmaril@728
|
1791 |
QColor MapEditor::getSelectionColor ()
|
insilmaril@728
|
1792 |
{
|
insilmaril@728
|
1793 |
return selectionColor;
|
insilmaril@728
|
1794 |
}
|
insilmaril@728
|
1795 |
|
insilmaril@728
|
1796 |
|