1.1 --- a/mapeditor.cpp Tue Apr 07 16:15:53 2009 +0000
1.2 +++ b/mapeditor.cpp Mon Apr 20 10:42:05 2009 +0000
1.3 @@ -279,6 +279,22 @@
1.4 }
1.5 }
1.6
1.7 +TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
1.8 +{
1.9 + // Start with mapcenter, no images allowed at rootItem
1.10 + int i=0;
1.11 + BranchItem *bi=model->getRootItem()->getFirstBranch();
1.12 + TreeItem *found=NULL;
1.13 + while (bi)
1.14 + {
1.15 + found=bi->findMapItem (p, exclude);
1.16 + if (found) return found;
1.17 + i++;
1.18 + bi=model->getRootItem()->getBranchNum(i);
1.19 + }
1.20 + return NULL;
1.21 +}
1.22 +
1.23 AttributeTable* MapEditor::attributeTable()
1.24 {
1.25 return attrTable;
1.26 @@ -405,7 +421,9 @@
1.27 // mouseEvent, we don't need to close here.
1.28
1.29 QPointF p = mapToScene(e->pos());
1.30 - LinkableMapObj* lmo=model->findMapObj(p, NULL);
1.31 + TreeItem *ti=findMapItem (p, NULL);
1.32 + LinkableMapObj* lmo=NULL;
1.33 + if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
1.34
1.35 if (lmo)
1.36 { // MapObj was found
1.37 @@ -487,7 +505,9 @@
1.38 }
1.39
1.40 QPointF p = mapToScene(e->pos());
1.41 - LinkableMapObj* lmo=model->findMapObj(p, NULL);
1.42 + TreeItem *ti=findMapItem (p, NULL);
1.43 + LinkableMapObj* lmo=NULL;
1.44 + if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
1.45
1.46 e->accept();
1.47
1.48 @@ -629,7 +649,10 @@
1.49 void MapEditor::mouseMoveEvent(QMouseEvent* e)
1.50 {
1.51 QPointF p = mapToScene(e->pos());
1.52 - LinkableMapObj *lmosel=model->getSelectedLMO();
1.53 + TreeItem *seli=model->getSelectedItem();
1.54 + LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
1.55 + if (seli)
1.56 + lmosel=seli->getLMO();
1.57
1.58 // Move the selected MapObj
1.59 if ( lmosel && movingObj)
1.60 @@ -649,7 +672,9 @@
1.61 // of selection back to absPos)
1.62
1.63 // Check if we could link
1.64 - LinkableMapObj* lmo=model->findMapObj(p, lmosel);
1.65 + TreeItem *dsti=findMapItem (p, seli);
1.66 + LinkableMapObj* dst=NULL;
1.67 + if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of lmo...
1.68
1.69
1.70 FloatObj *fio=model->getSelectedFloatImage();
1.71 @@ -662,15 +687,15 @@
1.72
1.73 // Relink float to new mapcenter or branch, if shift is pressed
1.74 // Only relink, if selection really has a new parent
1.75 - if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
1.76 - ( (typeid(*lmo)==typeid(BranchObj)) ||
1.77 - (typeid(*lmo)==typeid(MapCenterObj)) ) &&
1.78 - ( lmo != fio->getParObj())
1.79 + if ( (e->modifiers()==Qt::ShiftModifier) && dst &&
1.80 + ( (typeid(*dst)==typeid(BranchObj)) ||
1.81 + (typeid(*dst)==typeid(MapCenterObj)) ) &&
1.82 + ( dst != fio->getParObj())
1.83 )
1.84 {
1.85 if (typeid(*fio) == typeid(FloatImageObj) &&
1.86 - ( (typeid(*lmo)==typeid(BranchObj) ||
1.87 - typeid(*lmo)==typeid(MapCenterObj)) ))
1.88 + ( (typeid(*dst)==typeid(BranchObj) ||
1.89 + typeid(*dst)==typeid(MapCenterObj)) ))
1.90 {
1.91
1.92 // Also save the move which was done so far
1.93 @@ -685,7 +710,7 @@
1.94 fio->getParObj()->requestReposition();
1.95 model->reposition();
1.96
1.97 - model->linkFloatImageTo (model->getSelectString(lmo));
1.98 + model->linkFloatImageTo (model->getSelectString(dst));
1.99 //movingObj=lmosel;
1.100 //movingObj_orgRelPos=lmosel->getRelPos();
1.101
1.102 @@ -694,7 +719,7 @@
1.103 }
1.104 } else
1.105 { // selection != a FloatObj
1.106 - if (lmosel->getDepth()==0)
1.107 + if (lmosel->getDepth()==0) //FIXME-1 also moved mapcenters could be linked, but not working here...
1.108 {
1.109 // Move MapCenter
1.110 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
1.111 @@ -722,20 +747,17 @@
1.112 }
1.113
1.114 // Maybe we can relink temporary?
1.115 - if (lmo && (lmo!=lmosel) && model->getSelectedBranchObj() &&
1.116 - (typeid(*lmo)==typeid(BranchObj) ||
1.117 - typeid(*lmo)==typeid(MapCenterObj)) )
1.118 -
1.119 + if (dsti && (dst!=lmosel) && seli->isBranchLikeType() && dsti->isBranchLikeType() )
1.120 {
1.121 if (e->modifiers()==Qt::ControlModifier)
1.122 {
1.123 - // Special case: CTRL to link below lmo
1.124 - lmosel->setParObjTmp (lmo,p,+1);
1.125 + // Special case: CTRL to link below dst
1.126 + lmosel->setParObjTmp (dst,p,+1);
1.127 }
1.128 else if (e->modifiers()==Qt::ShiftModifier)
1.129 - lmosel->setParObjTmp (lmo,p,-1);
1.130 + lmosel->setParObjTmp (dst,p,-1);
1.131 else
1.132 - lmosel->setParObjTmp (lmo,p,0);
1.133 + lmosel->setParObjTmp (dst,p,0);
1.134 } else
1.135 {
1.136 lmosel->unsetParObjTmp();
1.137 @@ -775,16 +797,22 @@
1.138 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
1.139 {
1.140 QPointF p = mapToScene(e->pos());
1.141 - LinkableMapObj *dst;
1.142 - LinkableMapObj *lmosel=model->getSelectedLMO();
1.143 + TreeItem *dsti=findMapItem(p, NULL);
1.144 + LinkableMapObj* dst=NULL;
1.145 + if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of dst...
1.146 +
1.147 + TreeItem *seli=model->getSelectedItem();
1.148 + LinkableMapObj *lmosel=seli->getLMO(); // FIXME-2 get rid of lmosel
1.149 +
1.150 +
1.151 +
1.152 // Have we been picking color?
1.153 if (pickingColor)
1.154 {
1.155 pickingColor=false;
1.156 setCursor (Qt::ArrowCursor);
1.157 // Check if we are over another branch
1.158 - dst=model->findMapObj(p, NULL);
1.159 - if (dst && lmosel)
1.160 + if (dsti && lmosel)
1.161 {
1.162 if (e->state() & Qt::ShiftModifier)
1.163 model->colorBranch (((BranchObj*)dst)->getColor());
1.164 @@ -799,8 +827,7 @@
1.165 {
1.166 drawingLink=false;
1.167 // Check if we are over another branch
1.168 - dst=model->findMapObj(p, NULL);
1.169 - if (dst && lmosel)
1.170 + if (dsti && lmosel && dsti->isBranchLikeType() )
1.171 {
1.172 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
1.173 tmpXLink->updateXLink();
1.174 @@ -815,8 +842,13 @@
1.175 }
1.176
1.177 // Have we been moving something?
1.178 - if ( lmosel && movingObj )
1.179 + if ( seli && movingObj )
1.180 {
1.181 + if (dsti==seli)
1.182 + {
1.183 + dsti=NULL;
1.184 + dst=NULL;
1.185 + }
1.186 FloatImageObj *fo=model->getSelectedFloatImage();
1.187 if(fo)
1.188 {
1.189 @@ -836,10 +868,12 @@
1.190
1.191 // Check if we are over another branch, but ignore
1.192 // any found LMOs, which are FloatObjs
1.193 - dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
1.194
1.195 - if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
1.196 + if (dsti && (!dsti->isBranchLikeType() ))
1.197 + {
1.198 dst=NULL;
1.199 + dsti=NULL;
1.200 + }
1.201
1.202 BranchItem *bi=model->getSelectedBranchItem();
1.203 if (bi && bi->depth()==0)
1.204 @@ -858,7 +892,7 @@
1.205 }
1.206 }
1.207
1.208 - if (model->selectionType() == TreeItem::Branch )
1.209 + if (seli->getType() == TreeItem::Branch )
1.210 { // A branch was moved
1.211
1.212 // save the position in case we link to mapcenter
1.213 @@ -871,7 +905,7 @@
1.214 QString preSelStr=model->getSelectString(lmosel);
1.215
1.216 copyingObj=false;
1.217 - if (dst )
1.218 + if (dsti )
1.219 {
1.220 // We have a destination, relink to that
1.221
1.222 @@ -923,6 +957,7 @@
1.223
1.224 if (lmosel->getDepth()==1)
1.225 {
1.226 + cout << "ME::releaseMouse d=1\n"; // FIXME_1 better use depth
1.227 // The select string might be different _after_ moving around.
1.228 // Therefor reposition and then use string of old selection, too
1.229 model->reposition();
1.230 @@ -979,10 +1014,10 @@
1.231 if (e->button() == Qt::LeftButton )
1.232 {
1.233 QPointF p = mapToScene(e->pos());
1.234 - LinkableMapObj *lmo=model->findMapObj(p, NULL);
1.235 - if (lmo) { // MapObj was found
1.236 + TreeItem *ti=findMapItem (p, NULL);
1.237 + if (ti) { // MapObj was found
1.238 // First select the MapObj than edit heading
1.239 - model->select (lmo);
1.240 + model->select (ti);
1.241 editHeading();
1.242 }
1.243 }