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