1.1 --- a/mapeditor.cpp Wed Oct 29 17:42:34 2008 +0000
1.2 +++ b/mapeditor.cpp Tue Nov 04 12:09:10 2008 +0000
1.3 @@ -43,7 +43,7 @@
1.4 model=vm;
1.5 model->setScene (mapScene);
1.6 model->registerEditor(this);
1.7 - model->addMapCenter(); // FIXME create this in MapEditor until BO and MCO are independent of scene
1.8 +// model->addMapCenter(); // FIXME create this in MapEditor until BO and MCO are independent of scene
1.9 model->makeDefault(); // No changes in model so far
1.10
1.11 setScene (mapScene);
1.12 @@ -82,15 +82,18 @@
1.13
1.14 QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
1.15 a->setShortcut ( Qt::Key_Return ); //Edit heading
1.16 - //a->setShortcutContext (Qt::WindowShortcut);
1.17 addAction (a);
1.18 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
1.19 a = new QAction( tr( "Edit heading","MapEditor" ), this);
1.20 a->setShortcut ( Qt::Key_Enter); //Edit heading
1.21 - //a->setShortcutContext (Qt::WindowShortcut);
1.22 addAction (a);
1.23 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
1.24
1.25 + // Selections
1.26 + selModel=vm->getSelectionModel();
1.27 + selectionColor =QColor (255,255,0);
1.28 +
1.29 +
1.30 // Attributes //FIXME testing only...
1.31 QString k;
1.32 AttributeDef *ad;
1.33 @@ -273,12 +276,6 @@
1.34 }
1.35 }
1.36
1.37 -void MapEditor::updateSelection()
1.38 -{
1.39 - // Tell selection to update geometries
1.40 - model->updateSelection();
1.41 -}
1.42 -
1.43 AttributeTable* MapEditor::attributeTable()
1.44 {
1.45 return attrTable;
1.46 @@ -1041,26 +1038,71 @@
1.47 event->acceptProposedAction();
1.48 }
1.49
1.50 +void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1.51 +{
1.52 + cout << "ME::updateSelection\n";
1.53
1.54 + QGraphicsRectItem *sb;
1.55
1.56 -bool isUnicode16(const QByteArray &d)
1.57 -{
1.58 - // TODO: make more precise check for unicode 16.
1.59 - // Guess unicode16 if any of second bytes are zero
1.60 - unsigned int length = max(0,d.size()-2)/2;
1.61 - for (unsigned int i = 0; i<length ; i++)
1.62 - if (d.at(i*2+1)==0) return true;
1.63 - return false;
1.64 -}
1.65 -
1.66 + // Check if selection is empty
1.67 + if (newsel.indexes().isEmpty() )
1.68 + {
1.69 + if (!selboxList.isEmpty())
1.70 + while (!selboxList.isEmpty() )
1.71 + delete selboxList.takeFirst();
1.72 + return;
1.73 + }
1.74
1.75 -void MapEditor::setSelectionModel (QItemSelectionModel *sm)
1.76 -{
1.77 - selModel=sm;
1.78 + if (selboxList.isEmpty())
1.79 + {
1.80 + sb = mapScene->addRect(
1.81 + QRectF(0,0,0,0),
1.82 + QPen(selectionColor),
1.83 + selectionColor);
1.84 + sb->setZValue(Z_SELBOX);
1.85 + sb->show();
1.86 + selboxList.append (sb);
1.87 + } else
1.88 + sb=selboxList.first();
1.89 +
1.90 + QModelIndex index=newsel.indexes().first(); // TODO no multiselections yet
1.91 +
1.92 + TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
1.93 + LinkableMapObj *lmo=item->getLMO();
1.94 +
1.95 + int w=0; // FIXME what for?
1.96 + if (lmo)
1.97 + {
1.98 + QRectF bbox=lmo->getBBox();
1.99 + selboxList.first()->setRect (
1.100 + bbox.x()-w,bbox.y()-w,
1.101 + bbox.width()+2*w, bbox.height()+2*w);
1.102 + selboxList.first()->setPen (selectionColor);
1.103 + selboxList.first()->setBrush (selectionColor);
1.104 + }
1.105 +
1.106 +
1.107 +
1.108 }
1.109
1.110 -QItemSelectionModel* MapEditor::selectionModel ()
1.111 +void MapEditor::updateSelectionGeometry() // FIXME VM only called from VM::animate...
1.112 {
1.113 - return selModel;
1.114 + cout << "ME::updateSelectionGeometry\n";
1.115 +
1.116 + // Tell selection to update geometries
1.117 + model->updateSelection();
1.118 }
1.119
1.120 +
1.121 +void MapEditor::setSelectionColor (QColor col)
1.122 +{
1.123 + selectionColor=col;
1.124 + updateSelectionGeometry();
1.125 +}
1.126 +
1.127 +QColor MapEditor::getSelectionColor ()
1.128 +{
1.129 + return selectionColor;
1.130 +}
1.131 +
1.132 +