mapeditor.cpp
author insilmaril
Mon May 18 09:41:31 2009 +0000 (2009-05-18)
changeset 770 57ce1ba6d1cb
parent 767 6d2b32f305f9
child 772 e3f722759c7e
permissions -rw-r--r--
Fixed Standard Flags finally
insilmaril@0
     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@175
    10
#include "mainwindow.h"
insilmaril@175
    11
#include "misc.h"
insilmaril@314
    12
#include "warningdialog.h"
insilmaril@0
    13
insilmaril@0
    14
insilmaril@0
    15
extern int statusbarTime;
insilmaril@0
    16
extern Main *mainWindow;
insilmaril@164
    17
extern QString tmpVymDir;
insilmaril@166
    18
extern QString clipboardDir;
insilmaril@491
    19
extern QString clipboardFile;
insilmaril@166
    20
extern bool clipboardEmpty;
insilmaril@473
    21
extern bool debug;
insilmaril@0
    22
insilmaril@366
    23
extern QMenu* branchContextMenu;
insilmaril@366
    24
extern QMenu* branchAddContextMenu;
insilmaril@366
    25
extern QMenu* branchRemoveContextMenu;
insilmaril@366
    26
extern QMenu* branchLinksContextMenu;
insilmaril@366
    27
extern QMenu* branchXLinksContextMenuEdit;
insilmaril@366
    28
extern QMenu* branchXLinksContextMenuFollow;
insilmaril@366
    29
extern QMenu* floatimageContextMenu;
insilmaril@366
    30
extern QMenu* canvasContextMenu;
insilmaril@366
    31
insilmaril@0
    32
extern Settings settings;
insilmaril@269
    33
extern QString iconPath;
insilmaril@0
    34
insilmaril@0
    35
///////////////////////////////////////////////////////////////////////
insilmaril@0
    36
///////////////////////////////////////////////////////////////////////
insilmaril@720
    37
MapEditor::MapEditor( VymModel *vm) 
insilmaril@0
    38
{
insilmaril@0
    39
	//cout << "Constructor ME "<<this<<endl;
insilmaril@720
    40
	mapScene= new QGraphicsScene(NULL);
insilmaril@408
    41
	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
insilmaril@408
    42
insilmaril@767
    43
	zoomFactor=zoomFactorTarget=1;
insilmaril@767
    44
insilmaril@720
    45
	model=vm;
insilmaril@645
    46
	model->setScene (mapScene);
insilmaril@720
    47
	model->registerEditor(this);
insilmaril@727
    48
	model->makeDefault();	// No changes in model so far
insilmaril@408
    49
insilmaril@408
    50
    setScene (mapScene);
insilmaril@0
    51
insilmaril@0
    52
    printer=NULL;
insilmaril@0
    53
insilmaril@366
    54
	// Create bitmap cursors, platform dependant
insilmaril@404
    55
	HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);		
insilmaril@404
    56
	PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); 
insilmaril@404
    57
	CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); 
insilmaril@404
    58
	XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); 
insilmaril@398
    59
insilmaril@769
    60
	//setFocusPolicy (Qt::StrongFocus);	//FIXME-3
insilmaril@0
    61
insilmaril@0
    62
	pickingColor=false;
insilmaril@91
    63
	drawingLink=false;
insilmaril@93
    64
	copyingObj=false;
insilmaril@0
    65
insilmaril@0
    66
    editingBO=NULL;
insilmaril@0
    67
    movingObj=NULL;
insilmaril@0
    68
insilmaril@0
    69
	printFrame=true;
insilmaril@0
    70
	printFooter=true;
insilmaril@0
    71
insilmaril@417
    72
	setAcceptDrops (true);	
insilmaril@0
    73
insilmaril@746
    74
	//model->reposition();	//FIXME-3 really still needed?
insilmaril@381
    75
insilmaril@531
    76
insilmaril@769
    77
	// Shortcuts and actions
insilmaril@769
    78
	QAction *a;
insilmaril@769
    79
    a = new QAction("Select upper branch", this);
insilmaril@769
    80
	a->setShortcut (Qt::Key_Up );
insilmaril@769
    81
	a->setShortcutContext (Qt::WidgetShortcut);
insilmaril@769
    82
	addAction (a);
insilmaril@769
    83
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
insilmaril@769
    84
insilmaril@769
    85
    a = new QAction( "Select lower branch",this);
insilmaril@769
    86
	a->setShortcut ( Qt::Key_Down );
insilmaril@769
    87
	a->setShortcutContext (Qt::WidgetShortcut);
insilmaril@769
    88
	addAction (a);
insilmaril@769
    89
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
insilmaril@769
    90
insilmaril@769
    91
    a = new QAction( "Select left branch", this);
insilmaril@769
    92
	a->setShortcut (Qt::Key_Left );
insilmaril@769
    93
//	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@769
    94
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
    95
	addAction (a);
insilmaril@769
    96
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorLeft() ) );
insilmaril@769
    97
insilmaril@769
    98
    a = new QAction( "Select child branch", this);
insilmaril@769
    99
	a->setShortcut (Qt::Key_Right);
insilmaril@769
   100
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
   101
	addAction (a);
insilmaril@769
   102
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorRight() ) );
insilmaril@769
   103
insilmaril@769
   104
    a = new QAction(  "Select first branch", this);
insilmaril@769
   105
	a->setShortcut (Qt::Key_Home );
insilmaril@769
   106
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
   107
	addAction (a);
insilmaril@769
   108
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorFirst() ) );
insilmaril@769
   109
insilmaril@769
   110
    a = new QAction( "Select last branch",this);
insilmaril@769
   111
	a->setShortcut ( Qt::Key_End );
insilmaril@769
   112
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
   113
	addAction (a);
insilmaril@769
   114
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorLast() ) );
insilmaril@769
   115
insilmaril@720
   116
	// Action to embed LineEdit for heading in Scene
insilmaril@720
   117
	editingHeading=false;
insilmaril@720
   118
	lineEdit=new QLineEdit;
insilmaril@720
   119
	lineEdit->hide();
insilmaril@720
   120
	QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
insilmaril@720
   121
	pw->setZValue (100);
insilmaril@676
   122
insilmaril@769
   123
	a = new QAction( tr( "Edit heading","MapEditor" ), this);
insilmaril@720
   124
	a->setShortcut ( Qt::Key_Return );					//Edit heading
insilmaril@720
   125
	addAction (a);
insilmaril@720
   126
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
insilmaril@720
   127
	a = new QAction( tr( "Edit heading","MapEditor" ), this);
insilmaril@720
   128
	a->setShortcut ( Qt::Key_Enter);					//Edit heading
insilmaril@720
   129
	addAction (a);
insilmaril@720
   130
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
insilmaril@628
   131
insilmaril@728
   132
	// Selections
insilmaril@728
   133
	selectionColor =QColor (255,255,0);
insilmaril@728
   134
	
insilmaril@728
   135
insilmaril@746
   136
	// Attributes	//FIXME-2 testing only...
insilmaril@638
   137
	QString k;
insilmaril@638
   138
	AttributeDef *ad;
insilmaril@628
   139
	attrTable= new AttributeTable();
insilmaril@638
   140
	k="A - StringList";
insilmaril@638
   141
	ad=attrTable->addKey (k,StringList);
insilmaril@638
   142
	if (ad)
insilmaril@638
   143
	{
insilmaril@638
   144
		QStringList sl;
insilmaril@638
   145
		sl <<"val 1"<<"val 2"<< "val 3";
insilmaril@638
   146
		ad->setValue (QVariant (sl));
insilmaril@638
   147
	}
insilmaril@638
   148
	//attrTable->addValue ("Key A","P 1");
insilmaril@638
   149
	//attrTable->addValue ("Key A","P 2");
insilmaril@638
   150
	//attrTable->addValue ("Key A","P 3");
insilmaril@638
   151
	//attrTable->addValue ("Key A","P 4");
insilmaril@638
   152
	k="B - FreeString";
insilmaril@638
   153
	ad=attrTable->addKey (k,FreeString);
insilmaril@638
   154
	if (ad)
insilmaril@638
   155
	{
insilmaril@638
   156
		//attrTable->addValue ("Key B","w1");
insilmaril@638
   157
		//attrTable->addValue ("Key B","w2");
insilmaril@638
   158
	}
insilmaril@638
   159
	k="C - UniqueString";
insilmaril@638
   160
	ad=attrTable->addKey (k,UniqueString);
insilmaril@638
   161
	if (ad)
insilmaril@638
   162
	{
insilmaril@638
   163
	//attrTable->addKey ("Key Prio");
insilmaril@638
   164
	//attrTable->addValue ("Key Prio","Prio 1");
insilmaril@638
   165
	//attrTable->addValue ("Key Prio","Prio 2");
insilmaril@638
   166
	}
insilmaril@0
   167
}
insilmaril@0
   168
insilmaril@0
   169
MapEditor::~MapEditor()
insilmaril@0
   170
{
insilmaril@746
   171
	//cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
insilmaril@720
   172
	model->unregisterEditor(this);
insilmaril@0
   173
}
insilmaril@0
   174
insilmaril@645
   175
VymModel* MapEditor::getModel()
insilmaril@0
   176
{
insilmaril@645
   177
    return model;
insilmaril@0
   178
}
insilmaril@0
   179
insilmaril@408
   180
QGraphicsScene * MapEditor::getScene()
insilmaril@0
   181
{
insilmaril@408
   182
    return mapScene;
insilmaril@0
   183
}
insilmaril@0
   184
insilmaril@767
   185
void MapEditor::setScrollBarPosTarget (const QRectF &rect)
insilmaril@767
   186
{
insilmaril@767
   187
	// Code copied from Qt sources
insilmaril@767
   188
	int xmargin=50;
insilmaril@767
   189
	int ymargin=50;
insilmaril@767
   190
insilmaril@767
   191
    qreal width = viewport()->width();
insilmaril@767
   192
    qreal height = viewport()->height();
insilmaril@767
   193
    QRectF viewRect = matrix().mapRect(rect);
insilmaril@767
   194
insilmaril@767
   195
    qreal left = horizontalScrollBar()->value();
insilmaril@767
   196
    qreal right = left + width;
insilmaril@767
   197
    qreal top = verticalScrollBar()->value();
insilmaril@767
   198
    qreal bottom = top + height;
insilmaril@767
   199
insilmaril@767
   200
    if (viewRect.left() <= left + xmargin) {
insilmaril@767
   201
        // need to scroll from the left
insilmaril@767
   202
  //      if (!d->leftIndent)
insilmaril@767
   203
            scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
insilmaril@767
   204
    }
insilmaril@767
   205
    if (viewRect.right() >= right - xmargin) {
insilmaril@767
   206
        // need to scroll from the right
insilmaril@767
   207
//        if (!d->leftIndent)
insilmaril@767
   208
            scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
insilmaril@767
   209
    }
insilmaril@767
   210
    if (viewRect.top() <= top + ymargin) {
insilmaril@767
   211
        // need to scroll from the top
insilmaril@767
   212
   //     if (!d->topIndent)
insilmaril@767
   213
            scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
insilmaril@767
   214
    }
insilmaril@767
   215
    if (viewRect.bottom() >= bottom - ymargin) {
insilmaril@767
   216
        // need to scroll from the bottom
insilmaril@767
   217
//        if (!d->topIndent)
insilmaril@767
   218
            scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
insilmaril@767
   219
    }
insilmaril@767
   220
insilmaril@767
   221
	if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
insilmaril@767
   222
		scrollBarPosAnimation.stop();
insilmaril@767
   223
	scrollBarPosAnimation.setTargetObject (this);
insilmaril@767
   224
	scrollBarPosAnimation.setPropertyName ("scrollBarPos");
insilmaril@767
   225
	scrollBarPosAnimation.setDuration(1000);
insilmaril@767
   226
	scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@767
   227
	scrollBarPosAnimation.setStartValue(
insilmaril@767
   228
		QPointF (horizontalScrollBar()->value() ,
insilmaril@767
   229
		         verticalScrollBar()->value() ) );
insilmaril@767
   230
	scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
insilmaril@767
   231
	scrollBarPosAnimation.start();
insilmaril@767
   232
}
insilmaril@767
   233
insilmaril@767
   234
QPointF MapEditor::getScrollBarPosTarget()
insilmaril@767
   235
{
insilmaril@767
   236
    return scrollBarPosTarget;
insilmaril@767
   237
}
insilmaril@767
   238
insilmaril@767
   239
insilmaril@767
   240
void MapEditor::setScrollBarPos(const QPointF &p)
insilmaril@767
   241
{
insilmaril@767
   242
    scrollBarPos=p;
insilmaril@767
   243
	horizontalScrollBar()->setValue(int(p.x()));
insilmaril@767
   244
	verticalScrollBar()->setValue(int(p.y()));
insilmaril@767
   245
}
insilmaril@767
   246
insilmaril@767
   247
QPointF MapEditor::getScrollBarPos()
insilmaril@767
   248
{
insilmaril@767
   249
    return scrollBarPos;
insilmaril@767
   250
}
insilmaril@767
   251
insilmaril@767
   252
void MapEditor::setZoomFactorTarget (const qreal &zft)
insilmaril@767
   253
{
insilmaril@767
   254
	zoomFactorTarget=zft;
insilmaril@767
   255
	if (zoomAnimation.state()==QtAbstractAnimation::Running)
insilmaril@767
   256
		zoomAnimation.stop();
insilmaril@767
   257
	//zoomAnimation=QtPropertyAnimation(this, "zoomFactor");
insilmaril@767
   258
	zoomAnimation.setTargetObject (this);
insilmaril@767
   259
	zoomAnimation.setPropertyName ("zoomFactor");
insilmaril@767
   260
	zoomAnimation.setDuration(1000);
insilmaril@767
   261
	zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@767
   262
	zoomAnimation.setStartValue(zoomFactor);
insilmaril@767
   263
	zoomAnimation.setEndValue(zft);
insilmaril@767
   264
	zoomAnimation.start();
insilmaril@767
   265
}
insilmaril@767
   266
insilmaril@767
   267
qreal MapEditor::getZoomFactorTarget()
insilmaril@767
   268
{
insilmaril@767
   269
    return zoomFactorTarget;
insilmaril@767
   270
}
insilmaril@767
   271
insilmaril@767
   272
insilmaril@767
   273
void MapEditor::setZoomFactor(const qreal &zf)
insilmaril@767
   274
{
insilmaril@767
   275
    zoomFactor=zf;
insilmaril@767
   276
	setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
insilmaril@767
   277
}
insilmaril@767
   278
insilmaril@767
   279
qreal MapEditor::getZoomFactor()
insilmaril@767
   280
{
insilmaril@767
   281
    return zoomFactor;
insilmaril@767
   282
}
insilmaril@767
   283
insilmaril@0
   284
void MapEditor::print()
insilmaril@0
   285
{
insilmaril@0
   286
	if ( !printer ) 
insilmaril@0
   287
	{
insilmaril@0
   288
		printer = new QPrinter;
insilmaril@0
   289
		printer->setColorMode (QPrinter::Color);
insilmaril@366
   290
		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
insilmaril@412
   291
		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
insilmaril@412
   292
		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
insilmaril@0
   293
	}
insilmaril@0
   294
insilmaril@645
   295
	QRectF totalBBox=model->getTotalBBox();
insilmaril@0
   296
insilmaril@0
   297
	// Try to set orientation automagically
insilmaril@0
   298
	// Note: Interpretation of generated postscript is amibiguous, if 
insilmaril@0
   299
	// there are problems with landscape mode, see
insilmaril@0
   300
	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
insilmaril@0
   301
insilmaril@0
   302
	if (totalBBox.width()>totalBBox.height())
insilmaril@0
   303
		// recommend landscape
insilmaril@0
   304
		printer->setOrientation (QPrinter::Landscape);
insilmaril@0
   305
	else	
insilmaril@0
   306
		// recommend portrait
insilmaril@0
   307
		printer->setOrientation (QPrinter::Portrait);
insilmaril@0
   308
insilmaril@0
   309
	if ( printer->setup(this) ) 
insilmaril@0
   310
	// returns false, if printing is canceled
insilmaril@0
   311
	{
insilmaril@0
   312
		QPainter pp(printer);
insilmaril@0
   313
insilmaril@412
   314
		pp.setRenderHint(QPainter::Antialiasing,true);
insilmaril@412
   315
insilmaril@0
   316
		// Don't print the visualisation of selection
insilmaril@720
   317
		model->unselect();
insilmaril@0
   318
insilmaril@408
   319
		QRectF mapRect=totalBBox;
insilmaril@411
   320
		QGraphicsRectItem *frame=NULL;
insilmaril@412
   321
insilmaril@417
   322
		if (printFrame) 
insilmaril@0
   323
		{
insilmaril@417
   324
			// Print frame around map
insilmaril@417
   325
			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
insilmaril@417
   326
				totalBBox.width()+20, totalBBox.height()+20);
insilmaril@417
   327
			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
insilmaril@417
   328
			frame->setZValue(0);
insilmaril@417
   329
			frame->show();    
insilmaril@417
   330
		}		
insilmaril@417
   331
insilmaril@417
   332
insilmaril@412
   333
		double paperAspect = (double)printer->width()   / (double)printer->height();
insilmaril@412
   334
		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
insilmaril@417
   335
		int viewBottom;
insilmaril@0
   336
		if (mapAspect>=paperAspect)
insilmaril@0
   337
		{
insilmaril@0
   338
			// Fit horizontally to paper width
insilmaril@417
   339
			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
insilmaril@417
   340
			viewBottom=(int)(printer->width()/mapAspect);	
insilmaril@0
   341
		}	else
insilmaril@0
   342
		{
insilmaril@0
   343
			// Fit vertically to paper height
insilmaril@417
   344
			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
insilmaril@417
   345
			viewBottom=printer->height();	
insilmaril@0
   346
		}	
insilmaril@417
   347
		
insilmaril@417
   348
		if (printFooter) 
insilmaril@417
   349
		{
insilmaril@417
   350
			// Print footer below map
insilmaril@417
   351
			QFont font;		
insilmaril@417
   352
			font.setPointSize(10);
insilmaril@417
   353
			pp.setFont (font);
insilmaril@417
   354
			QRectF footerBox(0,viewBottom,printer->width(),15);
insilmaril@746
   355
			// FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
insilmaril@417
   356
			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
insilmaril@417
   357
		}
insilmaril@412
   358
		mapScene->render (
insilmaril@412
   359
			&pp, 
insilmaril@412
   360
			QRectF (0,0,printer->width(),printer->height()-15),
insilmaril@412
   361
			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
insilmaril@412
   362
		);
insilmaril@412
   363
		
insilmaril@412
   364
		// Viewport has paper dimension
insilmaril@412
   365
		if (frame)  delete (frame);
insilmaril@0
   366
insilmaril@0
   367
		// Restore selection
insilmaril@720
   368
		model->reselect();
insilmaril@119
   369
insilmaril@119
   370
		// Save settings in vymrc
insilmaril@366
   371
		settings.writeEntry("/mainwindow/printerName",printer->printerName());
insilmaril@412
   372
		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
insilmaril@412
   373
		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
insilmaril@0
   374
	}
insilmaril@0
   375
}
insilmaril@0
   376
insilmaril@408
   377
void MapEditor::setAntiAlias (bool b)
insilmaril@408
   378
{
insilmaril@408
   379
	setRenderHint(QPainter::Antialiasing,b);
insilmaril@408
   380
}
insilmaril@408
   381
insilmaril@408
   382
void MapEditor::setSmoothPixmap(bool b)
insilmaril@408
   383
{
insilmaril@408
   384
	setRenderHint(QPainter::SmoothPixmapTransform,b);
insilmaril@408
   385
}
insilmaril@408
   386
insilmaril@754
   387
TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
insilmaril@754
   388
{
insilmaril@754
   389
	// Start with mapcenter, no images allowed at rootItem
insilmaril@754
   390
	int i=0;
insilmaril@754
   391
	BranchItem *bi=model->getRootItem()->getFirstBranch();
insilmaril@754
   392
	TreeItem *found=NULL;
insilmaril@754
   393
	while (bi)
insilmaril@754
   394
	{
insilmaril@754
   395
		found=bi->findMapItem (p, exclude);
insilmaril@754
   396
		if (found) return found;
insilmaril@754
   397
		i++;
insilmaril@754
   398
		bi=model->getRootItem()->getBranchNum(i);
insilmaril@754
   399
	}
insilmaril@754
   400
	return NULL;
insilmaril@754
   401
}
insilmaril@754
   402
insilmaril@628
   403
AttributeTable* MapEditor::attributeTable()
insilmaril@628
   404
{
insilmaril@628
   405
	return attrTable;
insilmaril@628
   406
}
insilmaril@628
   407
insilmaril@527
   408
void MapEditor::testFunction1()
insilmaril@0
   409
{
insilmaril@767
   410
	
insilmaril@767
   411
	// Code copied from Qt sources
insilmaril@767
   412
	QRectF rect=model->getSelectedBranchObj()->getBBox();
insilmaril@767
   413
	int xmargin=50;
insilmaril@767
   414
	int ymargin=50;
insilmaril@741
   415
insilmaril@767
   416
    qreal width = viewport()->width();
insilmaril@767
   417
    qreal height = viewport()->height();
insilmaril@767
   418
    QRectF viewRect = matrix().mapRect(rect);
insilmaril@741
   419
insilmaril@767
   420
    qreal left = horizontalScrollBar()->value();
insilmaril@767
   421
    qreal right = left + width;
insilmaril@767
   422
    qreal top = verticalScrollBar()->value();
insilmaril@767
   423
    qreal bottom = top + height;
insilmaril@723
   424
insilmaril@767
   425
    if (viewRect.left() <= left + xmargin) {
insilmaril@767
   426
        // need to scroll from the left
insilmaril@767
   427
  //      if (!d->leftIndent)
insilmaril@767
   428
            horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
insilmaril@767
   429
    }
insilmaril@767
   430
    if (viewRect.right() >= right - xmargin) {
insilmaril@767
   431
        // need to scroll from the right
insilmaril@767
   432
//        if (!d->leftIndent)
insilmaril@767
   433
            horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
insilmaril@767
   434
    }
insilmaril@767
   435
    if (viewRect.top() <= top + ymargin) {
insilmaril@767
   436
        // need to scroll from the top
insilmaril@767
   437
   //     if (!d->topIndent)
insilmaril@767
   438
            verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
insilmaril@767
   439
    }
insilmaril@767
   440
    if (viewRect.bottom() >= bottom - ymargin) {
insilmaril@767
   441
        // need to scroll from the bottom
insilmaril@767
   442
//        if (!d->topIndent)
insilmaril@767
   443
            verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
insilmaril@767
   444
    }
insilmaril@767
   445
	cout << "test1:  hor="<<horizontalScrollBar()->value()<<endl;
insilmaril@767
   446
	cout << "test1:  ver="<<verticalScrollBar()->value()<<endl;
insilmaril@767
   447
}
insilmaril@741
   448
/*
insilmaril@767
   449
	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
insilmaril@767
   450
	 animation->setDuration(5000);
insilmaril@767
   451
	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
insilmaril@767
   452
	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@767
   453
	 animation->setStartValue(sceneRect() );
insilmaril@767
   454
	 animation->setEndValue(QRectF(50, 50, 1000, 1000));
insilmaril@740
   455
insilmaril@767
   456
	 animation->start();
insilmaril@767
   457
*/	 
insilmaril@767
   458
/*
insilmaril@767
   459
	QDialog *dia= new QDialog (this);
insilmaril@767
   460
	dia->setGeometry (50,50,10,10);
insilmaril@723
   461
insilmaril@767
   462
     dia->show();
insilmaril@767
   463
     dia ->raise();
insilmaril@767
   464
insilmaril@767
   465
	 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
insilmaril@767
   466
	 animation->setDuration(1000);
insilmaril@767
   467
	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
insilmaril@767
   468
	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@767
   469
	 animation->setStartValue(QRect(50, 50, 10, 10));
insilmaril@767
   470
	 animation->setEndValue(QRect(250, 250, 100, 100));
insilmaril@767
   471
insilmaril@767
   472
	 animation->start();
insilmaril@767
   473
 */
insilmaril@723
   474
insilmaril@420
   475
/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
insilmaril@260
   476
	if (hidemode==HideNone)
insilmaril@185
   477
	{
insilmaril@260
   478
		setHideTmpMode (HideExport);
insilmaril@260
   479
		mapCenter->calcBBoxSizeWithChilds();
insilmaril@408
   480
		QRectF totalBBox=mapCenter->getTotalBBox();
insilmaril@408
   481
		QRectF mapRect=totalBBox;
insilmaril@260
   482
		QCanvasRectangle *frame=NULL;
insilmaril@260
   483
insilmaril@260
   484
		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
insilmaril@260
   485
	
insilmaril@260
   486
		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
insilmaril@260
   487
			totalBBox.width(), totalBBox.height());
insilmaril@408
   488
		frame=new QCanvasRectangle (mapRect,mapScene);
insilmaril@260
   489
		frame->setBrush (QColor(white));
insilmaril@260
   490
		frame->setPen (QColor(black));
insilmaril@408
   491
		frame->setZValue(0);
insilmaril@260
   492
		frame->show();    
insilmaril@260
   493
	}	
insilmaril@260
   494
	else	
insilmaril@260
   495
	{
insilmaril@260
   496
		setHideTmpMode (HideNone);
insilmaril@260
   497
	}	
insilmaril@260
   498
	cout <<"  hidemode="<<hidemode<<endl;
insilmaril@301
   499
	*/
insilmaril@527
   500
	
insilmaril@527
   501
void MapEditor::testFunction2()
insilmaril@527
   502
{
insilmaril@645
   503
insilmaril@691
   504
/*
insilmaril@628
   505
	// Toggle hidemode
insilmaril@628
   506
	if (hidemode==HideExport)
insilmaril@628
   507
		setHideTmpMode (HideNone);
insilmaril@628
   508
	else	
insilmaril@628
   509
		setHideTmpMode (HideExport);
insilmaril@691
   510
*/		
insilmaril@105
   511
}
insilmaril@105
   512
insilmaril@769
   513
void MapEditor::cursorUp()
insilmaril@769
   514
{
insilmaril@769
   515
	model->selectUpperBranch();
insilmaril@769
   516
}
insilmaril@769
   517
insilmaril@769
   518
void MapEditor::cursorDown()	
insilmaril@769
   519
insilmaril@769
   520
{
insilmaril@769
   521
	model->selectLowerBranch();
insilmaril@769
   522
}
insilmaril@769
   523
insilmaril@769
   524
void MapEditor::cursorLeft()
insilmaril@769
   525
{
insilmaril@769
   526
	model->selectLeftBranch();
insilmaril@769
   527
}
insilmaril@769
   528
insilmaril@769
   529
void MapEditor::cursorRight()	
insilmaril@769
   530
{
insilmaril@769
   531
	model->selectRightBranch();
insilmaril@769
   532
}
insilmaril@769
   533
insilmaril@769
   534
void MapEditor::cursorFirst()	
insilmaril@769
   535
{
insilmaril@769
   536
	model->selectFirstBranch();
insilmaril@769
   537
}
insilmaril@769
   538
insilmaril@769
   539
void MapEditor::cursorLast()	
insilmaril@769
   540
{
insilmaril@769
   541
	model->selectLastBranch();
insilmaril@769
   542
}
insilmaril@769
   543
insilmaril@769
   544
insilmaril@720
   545
void MapEditor::editHeading()
insilmaril@720
   546
{
insilmaril@720
   547
	if (editingHeading)
insilmaril@720
   548
	{
insilmaril@720
   549
		editHeadingFinished();
insilmaril@720
   550
		return;
insilmaril@720
   551
	}
insilmaril@753
   552
	BranchObj *bo=model->getSelectedBranchObj();
insilmaril@753
   553
	BranchItem *bi=model->getSelectedBranchItem();
insilmaril@753
   554
	if (bo)	//FIXME-3
insilmaril@720
   555
	{
insilmaril@720
   556
		model->setSelectionBlocked(true);
insilmaril@720
   557
insilmaril@753
   558
		lineEdit->setText (bi->getHeading());
insilmaril@720
   559
		QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
insilmaril@720
   560
		lineEdit->setGeometry(p.x(),p.y(),230,25);
insilmaril@720
   561
		lineEdit->selectAll();
insilmaril@720
   562
		lineEdit->show();
insilmaril@720
   563
		lineEdit->setFocus();
insilmaril@720
   564
		lineEdit->grabKeyboard();
insilmaril@720
   565
		editingHeading=true;
insilmaril@720
   566
	}
insilmaril@720
   567
insilmaril@720
   568
}
insilmaril@720
   569
void MapEditor::editHeadingFinished()
insilmaril@720
   570
{
insilmaril@720
   571
	editingHeading=false;
insilmaril@720
   572
	lineEdit->releaseKeyboard();
insilmaril@720
   573
	model->setHeading (lineEdit->text() );
insilmaril@720
   574
	model->setSelectionBlocked(false);
insilmaril@720
   575
	lineEdit->hide();
insilmaril@720
   576
insilmaril@720
   577
	// Maybe reselect previous branch 
insilmaril@720
   578
	mainWindow->editHeadingFinished (model);
insilmaril@720
   579
}
insilmaril@720
   580
insilmaril@720
   581
insilmaril@408
   582
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
insilmaril@0
   583
{
insilmaril@0
   584
	// Lineedits are already closed by preceding
insilmaril@0
   585
	// mouseEvent, we don't need to close here.
insilmaril@0
   586
insilmaril@408
   587
    QPointF p = mapToScene(e->pos());
insilmaril@754
   588
    TreeItem *ti=findMapItem (p, NULL);
insilmaril@754
   589
    LinkableMapObj* lmo=NULL;
insilmaril@754
   590
	if (ti) lmo=ti->getLMO();	//FIXME-2 get rid of lmo...
insilmaril@0
   591
	
insilmaril@0
   592
    if (lmo) 
insilmaril@0
   593
	{	// MapObj was found
insilmaril@735
   594
		if (model->getSelectedLMO() != lmo)
insilmaril@0
   595
		{
insilmaril@0
   596
			// select the MapObj
insilmaril@720
   597
			model->select(lmo);
insilmaril@0
   598
		}
insilmaril@0
   599
		// Context Menu 
insilmaril@753
   600
		if (model->getSelectedBranchObj() ) 
insilmaril@0
   601
		{
insilmaril@424
   602
			// Context Menu on branch or mapcenter
insilmaril@746
   603
			//FIXME-3 model->updateActions(); needed?
insilmaril@424
   604
			branchContextMenu->popup(e->globalPos() );
insilmaril@424
   605
		} else
insilmaril@424
   606
		{
insilmaril@720
   607
			if (model->getSelectedFloatImage() )
insilmaril@0
   608
			{
insilmaril@0
   609
				// Context Menu on floatimage
insilmaril@746
   610
				// model->updateActions(); FIXME-3 needed?
insilmaril@0
   611
				floatimageContextMenu->popup(e->globalPos() );
insilmaril@0
   612
			}	
insilmaril@0
   613
		}	
insilmaril@0
   614
	} else 
insilmaril@0
   615
	{ // No MapObj found, we are on the Canvas itself
insilmaril@408
   616
		// Context Menu on scene
insilmaril@746
   617
		// model->updateActions(); FIXME-3 needed?
insilmaril@723
   618
		
insilmaril@723
   619
		// Open context menu synchronously to position new mapcenter
insilmaril@723
   620
		model->setContextPos (p);
insilmaril@723
   621
		canvasContextMenu->exec(e->globalPos() );
insilmaril@723
   622
		model->unsetContextPos ();
insilmaril@0
   623
    } 
insilmaril@329
   624
	e->accept();
insilmaril@0
   625
}
insilmaril@0
   626
insilmaril@398
   627
void MapEditor::keyPressEvent(QKeyEvent* e)
insilmaril@398
   628
{
insilmaril@411
   629
	if (e->modifiers() & Qt::ControlModifier)
insilmaril@398
   630
	{
insilmaril@398
   631
		switch (mainWindow->getModMode())
insilmaril@398
   632
		{
insilmaril@473
   633
			case Main::ModModeColor: 
insilmaril@398
   634
				setCursor (PickColorCursor);
insilmaril@398
   635
				break;
insilmaril@473
   636
			case Main::ModModeCopy: 
insilmaril@398
   637
				setCursor (CopyCursor);
insilmaril@398
   638
				break;
insilmaril@473
   639
			case Main::ModModeXLink: 
insilmaril@398
   640
				setCursor (XLinkCursor);
insilmaril@398
   641
				break;
insilmaril@398
   642
			default :
insilmaril@398
   643
				setCursor (Qt::ArrowCursor);
insilmaril@398
   644
				break;
insilmaril@398
   645
		} 
insilmaril@398
   646
	}	
insilmaril@398
   647
}
insilmaril@398
   648
insilmaril@398
   649
void MapEditor::keyReleaseEvent(QKeyEvent* e)
insilmaril@398
   650
{
insilmaril@411
   651
	if (!(e->modifiers() & Qt::ControlModifier))
insilmaril@398
   652
		setCursor (Qt::ArrowCursor);
insilmaril@398
   653
}
insilmaril@398
   654
insilmaril@408
   655
void MapEditor::mousePressEvent(QMouseEvent* e)
insilmaril@0
   656
{
insilmaril@329
   657
	// Ignore right clicks, these will go to context menus
insilmaril@366
   658
	if (e->button() == Qt::RightButton )
insilmaril@329
   659
	{
insilmaril@329
   660
		e->ignore();
insilmaril@329
   661
		return;
insilmaril@329
   662
	}
insilmaril@329
   663
insilmaril@491
   664
	//Ignore clicks while editing heading
insilmaril@720
   665
	if (model->isSelectionBlocked() ) 
insilmaril@491
   666
	{
insilmaril@491
   667
		e->ignore();
insilmaril@491
   668
		return;
insilmaril@491
   669
	}
insilmaril@491
   670
insilmaril@408
   671
    QPointF p = mapToScene(e->pos());
insilmaril@754
   672
    TreeItem *ti=findMapItem (p, NULL);
insilmaril@754
   673
    LinkableMapObj* lmo=NULL;
insilmaril@754
   674
	if (ti) lmo=ti->getLMO();	//FIXME-2 get rid of lmo...
insilmaril@0
   675
	
insilmaril@329
   676
	e->accept();
insilmaril@329
   677
insilmaril@442
   678
	//Take care of  system flags _or_ modifier modes
insilmaril@267
   679
	//
insilmaril@267
   680
	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
insilmaril@267
   681
		typeid(*lmo)==typeid(MapCenterObj) ))
insilmaril@267
   682
	{
insilmaril@267
   683
		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
insilmaril@267
   684
		if (!foname.isEmpty())
insilmaril@267
   685
		{
insilmaril@267
   686
			// systemFlag clicked
insilmaril@750
   687
			model->select (lmo);	// FIXME-3 was selectInt
insilmaril@267
   688
			if (foname=="url") 
insilmaril@267
   689
			{
insilmaril@366
   690
				if (e->state() & Qt::ControlModifier)
insilmaril@267
   691
					mainWindow->editOpenURLTab();
insilmaril@267
   692
				else	
insilmaril@267
   693
					mainWindow->editOpenURL();
insilmaril@267
   694
			}	
insilmaril@267
   695
			else if (foname=="vymLink")
insilmaril@267
   696
			{
insilmaril@267
   697
				mainWindow->editOpenVymLink();
insilmaril@267
   698
				// tabWidget may change, better return now
insilmaril@267
   699
				// before segfaulting...
insilmaril@267
   700
			} else if (foname=="note")
insilmaril@267
   701
				mainWindow->windowToggleNoteEditor();
insilmaril@267
   702
			else if (foname=="hideInExport")		
insilmaril@720
   703
				model->toggleHideExport();
insilmaril@746
   704
			// FIXME-3 needed? xelection.update();	
insilmaril@267
   705
			return;	
insilmaril@267
   706
		} 
insilmaril@720
   707
	}	
insilmaril@442
   708
	// No system flag clicked, take care of modmodes (CTRL-Click)
insilmaril@366
   709
	if (e->state() & Qt::ControlModifier)
insilmaril@0
   710
	{
insilmaril@473
   711
		if (mainWindow->getModMode()==Main::ModModeColor)
insilmaril@83
   712
		{
insilmaril@83
   713
				pickingColor=true;
insilmaril@398
   714
				setCursor (PickColorCursor);
insilmaril@83
   715
				return;
insilmaril@83
   716
		} 
insilmaril@473
   717
		if (mainWindow->getModMode()==Main::ModModeXLink)
insilmaril@83
   718
		{	
insilmaril@90
   719
			BranchObj *bo_begin=NULL;
insilmaril@90
   720
			if (lmo)
insilmaril@90
   721
				bo_begin=(BranchObj*)(lmo);
insilmaril@90
   722
			else	
insilmaril@753
   723
				bo_begin=model->getSelectedBranchObj();
insilmaril@90
   724
			if (bo_begin)	
insilmaril@83
   725
			{
insilmaril@83
   726
				drawingLink=true;
insilmaril@90
   727
				linkingObj_src=bo_begin;
insilmaril@408
   728
				tmpXLink=new XLinkObj (mapScene);
insilmaril@95
   729
				tmpXLink->setBegin (bo_begin);
insilmaril@95
   730
				tmpXLink->setEnd   (p);
insilmaril@720
   731
				tmpXLink->setColor(model->getMapDefXLinkColor());
insilmaril@720
   732
				tmpXLink->setWidth(model->getMapDefXLinkWidth());
insilmaril@95
   733
				tmpXLink->updateXLink();
insilmaril@95
   734
				tmpXLink->setVisibility (true);
insilmaril@83
   735
				return;
insilmaril@89
   736
			} 
insilmaril@267
   737
		}
insilmaril@442
   738
	}	// End of modmodes
insilmaril@442
   739
insilmaril@0
   740
    if (lmo) 
insilmaril@267
   741
	{	
insilmaril@738
   742
	/*
insilmaril@729
   743
		cout << "ME::mouse pressed\n";
insilmaril@729
   744
		cout << "  lmo="<<lmo<<endl;
insilmaril@729
   745
		cout << "  h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
insilmaril@738
   746
	*/
insilmaril@442
   747
		// Select the clicked object
insilmaril@729
   748
insilmaril@746
   749
		// FIXME-2 VM better let "find" return an index instead of lmo...
insilmaril@729
   750
		// Get index of clicked LMO
insilmaril@729
   751
		TreeItem *ti=lmo->getTreeItem();
insilmaril@738
   752
		/*
insilmaril@729
   753
		cout << "  lmo="<<lmo<<"    lmo(ti)="<<ti->getLMO()<<endl;
insilmaril@729
   754
		cout << "  ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
insilmaril@738
   755
		*/
insilmaril@729
   756
		//QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
insilmaril@738
   757
		model->select (ti);
insilmaril@442
   758
insilmaril@0
   759
		// Left Button	    Move Branches
insilmaril@366
   760
		if (e->button() == Qt::LeftButton )
insilmaril@0
   761
		{
insilmaril@424
   762
			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
insilmaril@424
   763
			//movingObj_start.setY( p.y() - selection->y() );	
insilmaril@424
   764
			movingObj_start.setX( p.x() - lmo->x() );	
insilmaril@424
   765
			movingObj_start.setY( p.y() - lmo->y() );	
insilmaril@129
   766
			movingObj_orgPos.setX (lmo->x() );
insilmaril@129
   767
			movingObj_orgPos.setY (lmo->y() );
insilmaril@720
   768
			lmo->setRelPos();
insilmaril@366
   769
			movingObj_orgRelPos=lmo->getRelPos();
insilmaril@129
   770
insilmaril@93
   771
			// If modMode==copy, then we want to "move" the _new_ object around
insilmaril@93
   772
			// then we need the offset from p to the _old_ selection, because of tmp
insilmaril@473
   773
			if (mainWindow->getModMode()==Main::ModModeCopy &&
insilmaril@366
   774
				e->state() & Qt::ControlModifier)
insilmaril@93
   775
			{
insilmaril@750
   776
				BranchItem *bi=model->getSelectedBranchItem();
insilmaril@750
   777
				if (bi)
insilmaril@93
   778
				{
insilmaril@93
   779
					copyingObj=true;
insilmaril@750
   780
					//FIXME-2   TreeItem::addBranch (BranchItem still missing) 
insilmaril@750
   781
					//bi->addBranch (model->getSelectedBranchItem());
insilmaril@720
   782
					model->unselect();
insilmaril@750
   783
					model->select(bi->getLastBranch());
insilmaril@645
   784
					model->reposition();
insilmaril@93
   785
				}
insilmaril@421
   786
			} 
insilmaril@421
   787
insilmaril@735
   788
			movingObj=model->getSelectedLMO();	
insilmaril@0
   789
		} else
insilmaril@0
   790
			// Middle Button    Toggle Scroll
insilmaril@0
   791
			// (On Mac OS X this won't work, but we still have 
insilmaril@0
   792
			// a button in the toolbar)
insilmaril@366
   793
			if (e->button() == Qt::MidButton )
insilmaril@720
   794
				model->toggleScroll();
insilmaril@746
   795
		// model->updateActions(); FIXME-3 needed?
insilmaril@746
   796
		// FIXME-3 needed? xelection.update();
insilmaril@0
   797
	} else 
insilmaril@408
   798
	{ // No MapObj found, we are on the scene itself
insilmaril@408
   799
		// Left Button	    move Pos of sceneView
insilmaril@366
   800
		if (e->button() == Qt::LeftButton )
insilmaril@0
   801
		{
insilmaril@0
   802
			movingObj=NULL;	// move Content not Obj
insilmaril@0
   803
			movingObj_start=e->globalPos();
insilmaril@408
   804
			movingCont_start=QPointF (
insilmaril@408
   805
				horizontalScrollBar()->value(),
insilmaril@408
   806
				verticalScrollBar()->value());
insilmaril@408
   807
			movingVec=QPointF(0,0);
insilmaril@398
   808
			setCursor(HandOpenCursor);
insilmaril@0
   809
		} 
insilmaril@0
   810
    } 
insilmaril@0
   811
}
insilmaril@0
   812
insilmaril@408
   813
void MapEditor::mouseMoveEvent(QMouseEvent* e)
insilmaril@0
   814
{
insilmaril@408
   815
    QPointF p = mapToScene(e->pos());
insilmaril@754
   816
	TreeItem *seli=model->getSelectedItem();
insilmaril@754
   817
	LinkableMapObj* lmosel=NULL;		//FIXME-2 get rid of lmosel
insilmaril@754
   818
	if (seli)
insilmaril@754
   819
		lmosel=seli->getLMO();
insilmaril@83
   820
insilmaril@0
   821
    // Move the selected MapObj
insilmaril@424
   822
    if ( lmosel && movingObj) 
insilmaril@0
   823
    {	
insilmaril@421
   824
		// reset cursor if we are moving and don't copy
insilmaril@473
   825
		if (mainWindow->getModMode()!=Main::ModModeCopy)
insilmaril@421
   826
			setCursor (Qt::ArrowCursor);
insilmaril@421
   827
insilmaril@408
   828
		// To avoid jumping of the sceneView, only 
insilmaril@763
   829
		// show selection, if not tmp linked
insilmaril@424
   830
		if (!lmosel->hasParObjTmp())
insilmaril@763
   831
			model->emitShowSelection();
insilmaril@0
   832
		
insilmaril@83
   833
		// Now move the selection, but add relative position 
insilmaril@83
   834
		// (movingObj_start) where selection was chosen with 
insilmaril@83
   835
		// mousepointer. (This avoids flickering resp. jumping 
insilmaril@0
   836
		// of selection back to absPos)
insilmaril@0
   837
		
insilmaril@0
   838
		// Check if we could link 
insilmaril@754
   839
		TreeItem *dsti=findMapItem (p, seli);
insilmaril@754
   840
		LinkableMapObj* dst=NULL;
insilmaril@754
   841
		if (dsti) dst=dsti->getLMO();	//FIXME-2 get rid of lmo...
insilmaril@0
   842
		
insilmaril@0
   843
insilmaril@720
   844
		FloatObj *fio=model->getSelectedFloatImage();
insilmaril@424
   845
		if (fio)
insilmaril@0
   846
		{
insilmaril@424
   847
			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@424
   848
			fio->setRelPos();
insilmaril@424
   849
			fio->updateLink(); //no need for reposition, if we update link here
insilmaril@735
   850
			model->updateSelection();	// position has changed
insilmaril@0
   851
insilmaril@0
   852
			// Relink float to new mapcenter or branch, if shift is pressed	
insilmaril@0
   853
			// Only relink, if selection really has a new parent
insilmaril@754
   854
			if ( (e->modifiers()==Qt::ShiftModifier) && dst &&
insilmaril@754
   855
				( (typeid(*dst)==typeid(BranchObj)) ||
insilmaril@754
   856
				  (typeid(*dst)==typeid(MapCenterObj)) ) &&
insilmaril@754
   857
				( dst != fio->getParObj())  
insilmaril@0
   858
				)
insilmaril@0
   859
			{
insilmaril@424
   860
				if (typeid(*fio) == typeid(FloatImageObj) && 
insilmaril@754
   861
				( (typeid(*dst)==typeid(BranchObj) ||
insilmaril@754
   862
				  typeid(*dst)==typeid(MapCenterObj)) ))  
insilmaril@0
   863
				{
insilmaril@420
   864
insilmaril@420
   865
					// Also save the move which was done so far
insilmaril@420
   866
					QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@420
   867
					QString pnow=qpointfToString(fio->getRelPos());
insilmaril@720
   868
					model->saveState(
insilmaril@753
   869
						fio->getTreeItem(),  // FIXME-3 
insilmaril@420
   870
						"moveRel "+pold,
insilmaril@753
   871
						fio->getTreeItem(),
insilmaril@420
   872
						"moveRel "+pnow,
insilmaril@726
   873
						QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
insilmaril@420
   874
					fio->getParObj()->requestReposition();
insilmaril@645
   875
					model->reposition();
insilmaril@420
   876
insilmaril@754
   877
					model->linkFloatImageTo (model->getSelectString(dst));
insilmaril@442
   878
					//movingObj=lmosel;
insilmaril@442
   879
					//movingObj_orgRelPos=lmosel->getRelPos();	
insilmaril@420
   880
insilmaril@645
   881
					model->reposition();
insilmaril@0
   882
				}	
insilmaril@0
   883
			}
insilmaril@388
   884
		} else	
insilmaril@388
   885
		{	// selection != a FloatObj
insilmaril@755
   886
			if (seli->depth()==0)		//FIXME-1 also moved mapcenters could be linked, but not working here...
insilmaril@0
   887
			{
insilmaril@388
   888
				// Move MapCenter
insilmaril@388
   889
				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
insilmaril@645
   890
					((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@0
   891
				else	
insilmaril@645
   892
					lmosel->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@645
   893
				model->updateRelPositions();
insilmaril@0
   894
			} else
insilmaril@0
   895
			{	
insilmaril@755
   896
				if (seli->depth()==1)
insilmaril@0
   897
				{
insilmaril@388
   898
					// Move mainbranch
insilmaril@0
   899
					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@388
   900
					lmosel->setRelPos();
insilmaril@0
   901
				} else
insilmaril@0
   902
				{
insilmaril@388
   903
					// Move ordinary branch
insilmaril@473
   904
					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
insilmaril@0
   905
						// Add width of bbox here, otherwise alignRelTo will cause jumping around
insilmaril@720
   906
						lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(), 
insilmaril@175
   907
							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
insilmaril@0
   908
					else	
insilmaril@175
   909
						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
insilmaril@720
   910
					lmosel->setRelPos();	
insilmaril@0
   911
				} 
insilmaril@0
   912
insilmaril@431
   913
				// Maybe we can relink temporary?
insilmaril@754
   914
				if (dsti && (dst!=lmosel) && seli->isBranchLikeType() && dsti->isBranchLikeType() )
insilmaril@0
   915
				{
insilmaril@388
   916
					if (e->modifiers()==Qt::ControlModifier)
insilmaril@0
   917
					{
insilmaril@754
   918
						// Special case: CTRL to link below dst
insilmaril@754
   919
						lmosel->setParObjTmp (dst,p,+1);
insilmaril@0
   920
					}
insilmaril@388
   921
					else if (e->modifiers()==Qt::ShiftModifier)
insilmaril@754
   922
						lmosel->setParObjTmp (dst,p,-1);
insilmaril@0
   923
					else
insilmaril@754
   924
						lmosel->setParObjTmp (dst,p,0);
insilmaril@0
   925
				} else	
insilmaril@0
   926
				{
insilmaril@93
   927
					lmosel->unsetParObjTmp();
insilmaril@0
   928
				}		
insilmaril@428
   929
				// reposition subbranch
insilmaril@428
   930
				lmosel->reposition();	
insilmaril@0
   931
			} // depth>0
insilmaril@0
   932
insilmaril@732
   933
			QItemSelection sel=model->getSelectionModel()->selection();
insilmaril@735
   934
			updateSelection(sel,sel);	// position has changed
insilmaril@732
   935
insilmaril@0
   936
		} // no FloatImageObj
insilmaril@0
   937
insilmaril@408
   938
		scene()->update();
insilmaril@0
   939
		return;
insilmaril@0
   940
	} // selection && moving_obj
insilmaril@0
   941
		
insilmaril@83
   942
	// Draw a link from one branch to another
insilmaril@83
   943
	if (drawingLink)
insilmaril@83
   944
	{
insilmaril@95
   945
		 tmpXLink->setEnd (p);
insilmaril@95
   946
		 tmpXLink->updateXLink();
insilmaril@83
   947
	}	 
insilmaril@83
   948
	
insilmaril@408
   949
    // Move sceneView 
insilmaril@411
   950
    if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
insilmaril@0
   951
	{
insilmaril@408
   952
		QPointF p=e->globalPos();
insilmaril@0
   953
		movingVec.setX(-p.x() + movingObj_start.x() );
insilmaril@0
   954
		movingVec.setY(-p.y() + movingObj_start.y() );
insilmaril@408
   955
		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
insilmaril@408
   956
		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
insilmaril@0
   957
    }
insilmaril@0
   958
}
insilmaril@0
   959
insilmaril@0
   960
insilmaril@408
   961
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
insilmaril@0
   962
{
insilmaril@408
   963
    QPointF p = mapToScene(e->pos());
insilmaril@754
   964
	TreeItem *seli=model->getSelectedItem();
insilmaril@754
   965
insilmaril@755
   966
	TreeItem *dsti=findMapItem(p, seli);
insilmaril@755
   967
	LinkableMapObj* dst=NULL;
insilmaril@755
   968
	if (dsti) dst=dsti->getLMO();	//FIXME-2 get rid of dst...
insilmaril@754
   969
insilmaril@754
   970
insilmaril@0
   971
	// Have we been picking color?
insilmaril@0
   972
	if (pickingColor)
insilmaril@0
   973
	{
insilmaril@0
   974
		pickingColor=false;
insilmaril@366
   975
		setCursor (Qt::ArrowCursor);
insilmaril@0
   976
		// Check if we are over another branch
insilmaril@760
   977
		if (dsti && seli) 
insilmaril@0
   978
		{	
insilmaril@366
   979
			if (e->state() & Qt::ShiftModifier)
insilmaril@720
   980
				model->colorBranch (((BranchObj*)dst)->getColor());
insilmaril@0
   981
			else	
insilmaril@720
   982
				model->colorSubtree (((BranchObj*)dst)->getColor());
insilmaril@0
   983
		} 
insilmaril@0
   984
		return;
insilmaril@0
   985
	}
insilmaril@83
   986
insilmaril@83
   987
	// Have we been drawing a link?
insilmaril@491
   988
	if (drawingLink)	
insilmaril@83
   989
	{
insilmaril@83
   990
		drawingLink=false;
insilmaril@83
   991
		// Check if we are over another branch
insilmaril@760
   992
		if (dsti && seli && dsti->isBranchLikeType() ) 
insilmaril@83
   993
		{	
insilmaril@95
   994
			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
insilmaril@95
   995
			tmpXLink->updateXLink();
insilmaril@746
   996
			tmpXLink->activate(); //FIXME-2 savestate missing
insilmaril@726
   997
			//model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );	
insilmaril@83
   998
		} else
insilmaril@83
   999
		{
insilmaril@95
  1000
			delete(tmpXLink);
insilmaril@95
  1001
			tmpXLink=NULL;
insilmaril@83
  1002
		}
insilmaril@83
  1003
		return;
insilmaril@83
  1004
	}
insilmaril@83
  1005
	
insilmaril@0
  1006
    // Have we been moving something?
insilmaril@754
  1007
    if ( seli && movingObj ) 
insilmaril@0
  1008
    {	
insilmaril@754
  1009
		if (dsti==seli) 
insilmaril@754
  1010
		{
insilmaril@754
  1011
			dsti=NULL;
insilmaril@754
  1012
			dst=NULL;
insilmaril@754
  1013
		}
insilmaril@720
  1014
		FloatImageObj *fo=model->getSelectedFloatImage();
insilmaril@424
  1015
		if(fo)
insilmaril@175
  1016
		{
insilmaril@388
  1017
			// Moved FloatObj. Maybe we need to reposition
insilmaril@408
  1018
		    QString pold=qpointfToString(movingObj_orgRelPos);
insilmaril@408
  1019
		    QString pnow=qpointfToString(fo->getRelPos());
insilmaril@720
  1020
			model->saveState(
insilmaril@753
  1021
				fo->getTreeItem(),	// FIXME-3
insilmaril@366
  1022
				"moveRel "+pold,
insilmaril@753
  1023
				fo->getTreeItem(),	// FIXME-3
insilmaril@366
  1024
				"moveRel "+pnow,
insilmaril@726
  1025
				QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
insilmaril@424
  1026
insilmaril@424
  1027
			fo->getParObj()->requestReposition();
insilmaril@645
  1028
			model->reposition();
insilmaril@175
  1029
		}	
insilmaril@175
  1030
insilmaril@0
  1031
		// Check if we are over another branch, but ignore 
insilmaril@0
  1032
		// any found LMOs, which are FloatObjs
insilmaril@0
  1033
insilmaril@754
  1034
		if (dsti && (!dsti->isBranchLikeType() )) 
insilmaril@754
  1035
		{
insilmaril@0
  1036
			dst=NULL;
insilmaril@754
  1037
			dsti=NULL;
insilmaril@754
  1038
		}	
insilmaril@0
  1039
		
insilmaril@753
  1040
		BranchItem *bi=model->getSelectedBranchItem();
insilmaril@753
  1041
		if (bi && bi->depth()==0)
insilmaril@497
  1042
		{	
insilmaril@753
  1043
            if (movingObj_orgPos != bi->getBranchObj()->getAbsPos())	// FIXME-3 check getBO here...
insilmaril@625
  1044
            {
insilmaril@625
  1045
                QString pold=qpointfToString(movingObj_orgPos);
insilmaril@753
  1046
                QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos());		// FIXME-3 check getBO here...
insilmaril@753
  1047
insilmaril@720
  1048
                model->saveState(
insilmaril@753
  1049
                    bi,
insilmaril@625
  1050
                    "move "+pold,
insilmaril@753
  1051
                    bi,
insilmaril@625
  1052
                    "move "+pnow,
insilmaril@753
  1053
                    QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
insilmaril@625
  1054
            }
insilmaril@388
  1055
		}
insilmaril@645
  1056
	
insilmaril@754
  1057
		if (seli->getType() == TreeItem::Branch )
insilmaril@388
  1058
		{	// A branch was moved
insilmaril@760
  1059
			LinkableMapObj* lmosel=NULL;		//FIXME-2 get rid of lmosel
insilmaril@760
  1060
			lmosel=seli->getLMO();
insilmaril@760
  1061
				
insilmaril@0
  1062
			// save the position in case we link to mapcenter
insilmaril@424
  1063
			QPointF savePos=QPointF (lmosel->getAbsPos()  );
insilmaril@0
  1064
insilmaril@0
  1065
			// Reset the temporary drawn link to the original one
insilmaril@424
  1066
			lmosel->unsetParObjTmp();
insilmaril@0
  1067
insilmaril@366
  1068
			// For Redo we may need to save original selection
insilmaril@684
  1069
			QString preSelStr=model->getSelectString(lmosel);
insilmaril@93
  1070
insilmaril@94
  1071
			copyingObj=false;	
insilmaril@755
  1072
			if (dsti && dsti->isBranchLikeType() ) 
insilmaril@93
  1073
			{
insilmaril@691
  1074
				// We have a destination, relink to that
insilmaril@691
  1075
insilmaril@753
  1076
				BranchObj* bsel=model->getSelectedBranchObj();
insilmaril@366
  1077
insilmaril@684
  1078
				QString preParStr=model->getSelectString (bsel->getParObj());
insilmaril@755
  1079
				QString preNum=QString::number (seli->num(),10);
insilmaril@366
  1080
				QString preDstParStr;
insilmaril@767
  1081
				bool relinked;
insilmaril@366
  1082
insilmaril@366
  1083
				if (e->state() & Qt::ShiftModifier && dst->getParObj())
insilmaril@366
  1084
				{	// Link above dst
insilmaril@684
  1085
					preDstParStr=model->getSelectString (dst->getParObj());
insilmaril@767
  1086
					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
insilmaril@366
  1087
				} else 
insilmaril@366
  1088
				if (e->state() & Qt::ControlModifier && dst->getParObj())
insilmaril@366
  1089
				{
insilmaril@366
  1090
					// Link below dst
insilmaril@684
  1091
					preDstParStr=model->getSelectString (dst->getParObj());
insilmaril@767
  1092
					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
insilmaril@366
  1093
				} else	
insilmaril@366
  1094
				{	// Append to dst
insilmaril@684
  1095
					preDstParStr=model->getSelectString(dst);
insilmaril@767
  1096
					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
insilmaril@755
  1097
					if (dsti->depth()==0) bsel->move (savePos);
insilmaril@366
  1098
				} 
insilmaril@767
  1099
				if (relinked)
insilmaril@767
  1100
				{
insilmaril@767
  1101
					QString postSelStr=model->getSelectString(lmosel);
insilmaril@767
  1102
					QString postNum=QString::number (seli->num(),10);
insilmaril@366
  1103
insilmaril@767
  1104
					QString undoCom="linkTo (\""+ 
insilmaril@767
  1105
						preParStr+ "\"," + preNum  +"," + 
insilmaril@767
  1106
						QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
insilmaril@366
  1107
insilmaril@767
  1108
					QString redoCom="linkTo (\""+ 
insilmaril@767
  1109
						preDstParStr + "\"," + postNum + "," +
insilmaril@767
  1110
						QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
insilmaril@366
  1111
insilmaril@767
  1112
					model->saveState (
insilmaril@767
  1113
						postSelStr,undoCom,
insilmaril@767
  1114
						preSelStr, redoCom,
insilmaril@767
  1115
						QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
insilmaril@691
  1116
insilmaril@767
  1117
				}
insilmaril@163
  1118
			} else
insilmaril@691
  1119
			{
insilmaril@691
  1120
				// No destination, undo  temporary move
insilmaril@691
  1121
insilmaril@755
  1122
				if (seli->depth()==1)
insilmaril@366
  1123
				{
insilmaril@366
  1124
					// The select string might be different _after_ moving around.
insilmaril@366
  1125
					// Therefor reposition and then use string of old selection, too
insilmaril@645
  1126
					model->reposition();
insilmaril@366
  1127
insilmaril@625
  1128
                    QPointF rp(lmosel->getRelPos());
insilmaril@625
  1129
                    if (rp != movingObj_orgRelPos)
insilmaril@625
  1130
                    {
insilmaril@625
  1131
                        QString ps=qpointfToString(rp);
insilmaril@720
  1132
                        model->saveState(
insilmaril@684
  1133
                            model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos), 
insilmaril@625
  1134
                            preSelStr, "moveRel "+ps, 
insilmaril@726
  1135
                            QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
insilmaril@625
  1136
                    }
insilmaril@366
  1137
				}
insilmaril@691
  1138
insilmaril@691
  1139
				// Draw the original link, before selection was moved around
insilmaril@755
  1140
				if (settings.value("/animation/use",false).toBool() && seli->depth()>1) 
insilmaril@691
  1141
				{
insilmaril@720
  1142
					lmosel->setRelPos();	// calc relPos first for starting point
insilmaril@753
  1143
					QPointF dst=bi->getBranchObj()->getParObj()->getChildPos();		// FIXME-3 check getBO here...
insilmaril@720
  1144
			//		if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
insilmaril@720
  1145
					
insilmaril@691
  1146
					model->startAnimation(
insilmaril@723
  1147
						(BranchObj*)lmosel,
insilmaril@691
  1148
						lmosel->getRelPos(),
insilmaril@720
  1149
						movingObj_orgRelPos
insilmaril@720
  1150
//						QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
insilmaril@691
  1151
					);	
insilmaril@691
  1152
				} else	
insilmaril@691
  1153
					model->reposition();
insilmaril@691
  1154
			}
insilmaril@0
  1155
		}
insilmaril@746
  1156
		model->updateSelection();  //FIXME-3 needed? at least not after pos of selection has changed...
insilmaril@408
  1157
		// Finally resize scene, if needed
insilmaril@408
  1158
		scene()->update();
insilmaril@0
  1159
		movingObj=NULL;		
insilmaril@366
  1160
insilmaril@366
  1161
		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
insilmaril@746
  1162
		// model->updateActions(); FIXME-3 neeeded? 
insilmaril@0
  1163
	} else 
insilmaril@83
  1164
		// maybe we moved View: set old cursor
insilmaril@366
  1165
		setCursor (Qt::ArrowCursor);
insilmaril@83
  1166
    
insilmaril@0
  1167
}
insilmaril@0
  1168
insilmaril@408
  1169
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
insilmaril@0
  1170
{
insilmaril@720
  1171
	if (model->isSelectionBlocked() ) 
insilmaril@491
  1172
	{
insilmaril@491
  1173
		e->ignore();
insilmaril@491
  1174
		return;
insilmaril@491
  1175
	}
insilmaril@491
  1176
insilmaril@366
  1177
	if (e->button() == Qt::LeftButton )
insilmaril@0
  1178
	{
insilmaril@408
  1179
		QPointF p = mapToScene(e->pos());
insilmaril@754
  1180
		TreeItem *ti=findMapItem (p, NULL);
insilmaril@754
  1181
		if (ti) {	// MapObj was found
insilmaril@0
  1182
			// First select the MapObj than edit heading
insilmaril@754
  1183
			model->select (ti);
insilmaril@720
  1184
			editHeading();
insilmaril@0
  1185
		}
insilmaril@0
  1186
	}
insilmaril@0
  1187
}
insilmaril@0
  1188
insilmaril@0
  1189
void MapEditor::resizeEvent (QResizeEvent* e)
insilmaril@0
  1190
{
insilmaril@408
  1191
	QGraphicsView::resizeEvent( e );
insilmaril@0
  1192
}
insilmaril@0
  1193
insilmaril@412
  1194
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
insilmaril@119
  1195
{
insilmaril@417
  1196
	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
insilmaril@417
  1197
	//	cerr << event->format(i) << endl;
insilmaril@417
  1198
insilmaril@417
  1199
	if (event->mimeData()->hasImage())
insilmaril@417
  1200
		event->acceptProposedAction();
insilmaril@417
  1201
	else	
insilmaril@417
  1202
		if (event->mimeData()->hasUrls())
insilmaril@417
  1203
			event->acceptProposedAction();
insilmaril@417
  1204
}
insilmaril@417
  1205
insilmaril@531
  1206
void MapEditor::dragMoveEvent(QDragMoveEvent *)
insilmaril@417
  1207
{
insilmaril@417
  1208
}
insilmaril@417
  1209
insilmaril@417
  1210
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
insilmaril@417
  1211
{
insilmaril@417
  1212
	event->accept();
insilmaril@119
  1213
}
insilmaril@129
  1214
insilmaril@412
  1215
void MapEditor::dropEvent(QDropEvent *event)
insilmaril@129
  1216
{
insilmaril@753
  1217
	BranchItem *selbi=model->getSelectedBranchItem();
insilmaril@753
  1218
	if (selbi)
insilmaril@128
  1219
	{
insilmaril@505
  1220
		if (debug)
insilmaril@505
  1221
			foreach (QString format,event->mimeData()->formats()) 
insilmaril@658
  1222
				cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
insilmaril@497
  1223
insilmaril@497
  1224
insilmaril@417
  1225
		QList <QUrl> uris;
insilmaril@417
  1226
		if (event->mimeData()->hasImage()) 
insilmaril@128
  1227
		{
insilmaril@417
  1228
			 QVariant imageData = event->mimeData()->imageData();
insilmaril@720
  1229
			 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
insilmaril@417
  1230
		} else
insilmaril@417
  1231
		if (event->mimeData()->hasUrls())
insilmaril@417
  1232
			uris=event->mimeData()->urls();
insilmaril@417
  1233
insilmaril@417
  1234
		if (uris.count()>0)
insilmaril@128
  1235
		{
insilmaril@417
  1236
			QStringList files;
insilmaril@417
  1237
			QString s;
insilmaril@417
  1238
			QString heading;
insilmaril@753
  1239
			BranchItem *bi;
insilmaril@428
  1240
			for (int i=0; i<uris.count();i++)
insilmaril@408
  1241
			{
insilmaril@428
  1242
				// Workaround to avoid adding empty branches
insilmaril@428
  1243
				if (!uris.at(i).toString().isEmpty())
insilmaril@417
  1244
				{
insilmaril@753
  1245
					bi=model->createBranch();
insilmaril@753
  1246
					if (bi)
insilmaril@417
  1247
					{
insilmaril@753
  1248
						   /* FIXME-2 
insilmaril@428
  1249
						s=uris.at(i).toLocalFile();
insilmaril@428
  1250
						if (!s.isEmpty()) 
insilmaril@428
  1251
						{
insilmaril@625
  1252
						   QString file = QDir::fromNativeSeparators(s);
insilmaril@428
  1253
						   heading = QFileInfo(file).baseName();
insilmaril@428
  1254
						   files.append(file);
insilmaril@428
  1255
						   if (file.endsWith(".vym", false))
insilmaril@753
  1256
							   bi->setVymLink(file);
insilmaril@428
  1257
						   else
insilmaril@753
  1258
							   bi->setURL(uris.at(i).toString());
insilmaril@428
  1259
					   } else 
insilmaril@428
  1260
					   {
insilmaril@428
  1261
						   bo->setURL(uris.at(i).toString());
insilmaril@428
  1262
					   }
insilmaril@753
  1263
							 */  
insilmaril@428
  1264
insilmaril@428
  1265
					   if (!heading.isEmpty())
insilmaril@753
  1266
						   bi->setHeading(heading);
insilmaril@428
  1267
					   else
insilmaril@753
  1268
						   bi->setHeading(uris.at(i).toString());
insilmaril@753
  1269
						   
insilmaril@428
  1270
					}
insilmaril@417
  1271
				}
insilmaril@417
  1272
			}
insilmaril@645
  1273
			model->reposition();
insilmaril@417
  1274
		}
insilmaril@417
  1275
	}	
insilmaril@417
  1276
	event->acceptProposedAction();
insilmaril@417
  1277
}
insilmaril@417
  1278
insilmaril@728
  1279
void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
insilmaril@728
  1280
{
insilmaril@731
  1281
	// Reduce rectangles
insilmaril@731
  1282
	while (newsel.indexes().count() < selboxList.count() )
insilmaril@731
  1283
		delete selboxList.takeFirst();
insilmaril@731
  1284
insilmaril@731
  1285
	// Add additonal rectangles
insilmaril@731
  1286
	QGraphicsRectItem *sb;
insilmaril@731
  1287
	while (newsel.indexes().count() > selboxList.count() )
insilmaril@728
  1288
	{
insilmaril@731
  1289
		sb = mapScene->addRect(
insilmaril@731
  1290
			QRectF(0,0,0,0), 
insilmaril@731
  1291
			QPen(selectionColor),
insilmaril@731
  1292
			selectionColor);
insilmaril@731
  1293
		sb->setZValue(Z_SELBOX);
insilmaril@731
  1294
		sb->show();
insilmaril@731
  1295
		selboxList.append (sb);
insilmaril@728
  1296
	}
insilmaril@731
  1297
insilmaril@731
  1298
	// Reposition rectangles
insilmaril@731
  1299
	int i=0;
insilmaril@731
  1300
	QRectF bbox;
insilmaril@732
  1301
	QModelIndex index;
insilmaril@732
  1302
insilmaril@732
  1303
	TreeItem *ti;
insilmaril@732
  1304
	LinkableMapObj *lmo;
insilmaril@731
  1305
	foreach (sb,selboxList)
insilmaril@731
  1306
	{
insilmaril@731
  1307
		index=newsel.indexes().at(i);
insilmaril@731
  1308
		ti= static_cast<TreeItem*>(index.internalPointer());
insilmaril@731
  1309
		lmo=ti->getLMO();
insilmaril@731
  1310
		bbox=lmo->getBBox();
insilmaril@731
  1311
		sb->setRect (
insilmaril@731
  1312
			bbox.x(),bbox.y(), 
insilmaril@731
  1313
			bbox.width(), bbox.height());
insilmaril@731
  1314
		sb->setPen (selectionColor);	
insilmaril@731
  1315
		sb->setBrush (selectionColor);	
insilmaril@731
  1316
		i++;
insilmaril@731
  1317
	}
insilmaril@729
  1318
}
insilmaril@728
  1319
insilmaril@753
  1320
void MapEditor::updateData (const QModelIndex &sel)
insilmaril@729
  1321
{
insilmaril@753
  1322
	TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
insilmaril@732
  1323
insilmaril@746
  1324
/* testing
insilmaril@753
  1325
	cout << "ME::updateData\n";
insilmaril@732
  1326
insilmaril@753
  1327
	cout << "  ti="<<ti<<endl;
insilmaril@753
  1328
	cout << "  h="<<ti->getHeading().toStdString()<<endl;
insilmaril@729
  1329
	*/
insilmaril@753
  1330
	
insilmaril@753
  1331
	if (ti->isBranchLikeType())
insilmaril@753
  1332
	{
insilmaril@753
  1333
		BranchObj *bo=(BranchObj*)ti->getLMO();
insilmaril@767
  1334
		bo->updateData();
insilmaril@753
  1335
	}
insilmaril@728
  1336
insilmaril@726
  1337
}
insilmaril@412
  1338
insilmaril@728
  1339
void MapEditor::setSelectionColor (QColor col)
insilmaril@728
  1340
{
insilmaril@728
  1341
	selectionColor=col;
insilmaril@732
  1342
	QItemSelection sel=model->getSelectionModel()->selection();
insilmaril@732
  1343
	updateSelection(sel,sel);
insilmaril@728
  1344
}
insilmaril@728
  1345
insilmaril@753
  1346
insilmaril@728
  1347
QColor MapEditor::getSelectionColor ()
insilmaril@728
  1348
{
insilmaril@728
  1349
	return selectionColor;
insilmaril@728
  1350
}
insilmaril@728
  1351
insilmaril@728
  1352