1.1 --- a/mapeditor.cpp Tue Dec 15 09:14:59 2009 +0000
1.2 +++ b/mapeditor.cpp Mon Jan 04 20:36:06 2010 +0000
1.3 @@ -113,10 +113,7 @@
1.4
1.5 // Action to embed LineEdit for heading in Scene
1.6 editingHeading=false;
1.7 - lineEdit=new QLineEdit;
1.8 - lineEdit->hide();
1.9 - QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
1.10 - pw->setZValue (Z_LINEEDIT);
1.11 + lineEdit=NULL;
1.12
1.13 a = new QAction( tr( "Edit heading","MapEditor" ), this);
1.14 a->setShortcut ( Qt::Key_Return ); //Edit heading
1.15 @@ -405,35 +402,55 @@
1.16
1.17 QRectF MapEditor::getTotalBBox()
1.18 {
1.19 - QRectF r;
1.20 + QPen pen;
1.21 + pen.setWidth (1);
1.22 + pen.setCapStyle ( Qt::RoundCap );
1.23 +
1.24 + QRectF rt;
1.25 BranchObj *bo;
1.26 - for (int i=0;i<model->getRootItem()->branchCount(); i++)
1.27 + BranchItem *cur=NULL;
1.28 + BranchItem *prev=NULL;
1.29 + model->nextBranch(cur,prev);
1.30 + while (cur)
1.31 {
1.32 - bo=(BranchObj*)(model->getRootItem()->getBranchNum(i)->getLMO());
1.33 - if (bo) r=addBBox (bo->getTotalBBox(), r);
1.34 + if (!cur->hasHiddenExportParent())
1.35 + {
1.36 + bo=(BranchObj*)(cur->getLMO());
1.37 + if (bo && bo->isVisibleObj())
1.38 + {
1.39 + bo->calcBBoxSizeWithChildren();
1.40 + // FIXME-3 testing
1.41 + //QRectF r1=bo->getBBoxSizeWithChildren();
1.42 + QRectF r1=bo->getBBox();
1.43 + //pen.setColor ( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8));
1.44 + //mapScene->addRect (r1,pen);
1.45 +
1.46 + if (rt.isNull()) rt=r1;
1.47 + rt=addBBox (r1, rt);
1.48 + //FIXME-2 cout <<"ME: r1="<<r1<<" "<<cur->getHeadingStd()<<endl;
1.49 + //cout <<" rt="<<rt<<endl;
1.50 + }
1.51 + }
1.52 + model->nextBranch(cur,prev);
1.53 }
1.54 - return r;
1.55 + return rt;
1.56 }
1.57
1.58
1.59 -QPixmap MapEditor::getPixmap()
1.60 +QImage MapEditor::getImage()
1.61 {
1.62 QRectF mapRect=getTotalBBox();
1.63 - QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
1.64 + int w=mapRect.width()+2;
1.65 + int h=mapRect.height()+2;
1.66 +
1.67 + QImage pix (w,h,QImage::Format_RGB32);
1.68 +
1.69 QPainter pp (&pix);
1.70 -
1.71 +
1.72 pp.setRenderHints(renderHints());
1.73 -
1.74 - // Don't print the visualisation of selection
1.75 - model->unselect();
1.76 -
1.77 mapScene->render ( &pp,
1.78 - QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
1.79 + QRectF(0,0,w,h),
1.80 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
1.81 -
1.82 - // Restore selection
1.83 - model->reselect();
1.84 -
1.85 return pix;
1.86 }
1.87
1.88 @@ -448,6 +465,42 @@
1.89 setRenderHint(QPainter::SmoothPixmapTransform,b);
1.90 }
1.91
1.92 +void MapEditor::setHideTmp (bool b) // FIXME-4 better use signals
1.93 +{
1.94 +/*
1.95 + if (b)
1.96 + {
1.97 + setHideTmpMode (HideExport);
1.98 + mapCenter->calcBBoxSizeWithChilds();
1.99 + QRectF totalBBox=mapCenter->getTotalBBox();
1.100 + //QRectF mapRect=totalBBox;
1.101 + cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
1.102 +
1.103 + mapRect.setRect (totalBBox.x(), totalBBox.y(),
1.104 + totalBBox.width(), totalBBox.height());
1.105 +
1.106 + QCanvasRectangle *frame=new QCanvasRectangle (mapRect,mapScene);
1.107 + frame->setBrush (QColor(white));
1.108 + frame->setPen (QColor(black));
1.109 + frame->setZValue(0);
1.110 + frame->show();
1.111 +
1.112 + }
1.113 + else
1.114 + {
1.115 + setHideTmpMode (HideNone);
1.116 + }
1.117 + cout <<" hidemode="<<hidemode<<endl;
1.118 +*/
1.119 +/*
1.120 + // Toggle hidemode
1.121 + if (hidemode==HideExport)
1.122 + setHideTmpMode (HideNone);
1.123 + else
1.124 + setHideTmpMode (HideExport);
1.125 +*/
1.126 +}
1.127 +
1.128 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
1.129 {
1.130 // Start with mapcenter, no images allowed at rootItem
1.131 @@ -472,9 +525,7 @@
1.132 void MapEditor::testFunction1()
1.133 {
1.134 cout << "ME::test1 selected TI="<<model->getSelectedItem()<<endl;
1.135 -
1.136 - for (int i=0; i<200;i++)
1.137 - model->addNewBranch();
1.138 + model->setExportMode (true);
1.139
1.140 /*
1.141 // Code copied from Qt sources
1.142 @@ -543,44 +594,13 @@
1.143 animation->start();
1.144 */
1.145
1.146 -/* FIXME-4 Hide hidden stuff temporary, maybe add this as regular function somewhere
1.147 - if (hidemode==HideNone)
1.148 - {
1.149 - setHideTmpMode (HideExport);
1.150 - mapCenter->calcBBoxSizeWithChilds();
1.151 - QRectF totalBBox=mapCenter->getTotalBBox();
1.152 - QRectF mapRect=totalBBox;
1.153 - QCanvasRectangle *frame=NULL;
1.154 -
1.155 - cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
1.156 -
1.157 - mapRect.setRect (totalBBox.x(), totalBBox.y(),
1.158 - totalBBox.width(), totalBBox.height());
1.159 - frame=new QCanvasRectangle (mapRect,mapScene);
1.160 - frame->setBrush (QColor(white));
1.161 - frame->setPen (QColor(black));
1.162 - frame->setZValue(0);
1.163 - frame->show();
1.164 - }
1.165 - else
1.166 - {
1.167 - setHideTmpMode (HideNone);
1.168 - }
1.169 - cout <<" hidemode="<<hidemode<<endl;
1.170 - */
1.171 -
1.172 -/*
1.173 - // Toggle hidemode
1.174 - if (hidemode==HideExport)
1.175 - setHideTmpMode (HideNone);
1.176 - else
1.177 - setHideTmpMode (HideExport);
1.178 -*/
1.179 -
1.180 }
1.181
1.182 void MapEditor::testFunction2()
1.183 {
1.184 + model->setExportMode (false);
1.185 + return;
1.186 +
1.187 // Create list with all bounding polygons
1.188 QList <LinkableMapObj*> mapobjects;
1.189 QList <ConvexPolygon> polys;
1.190 @@ -899,6 +919,10 @@
1.191 {
1.192 model->setSelectionBlocked(true);
1.193
1.194 + lineEdit=new QLineEdit;
1.195 + QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
1.196 + pw->setZValue (Z_LINEEDIT);
1.197 +
1.198 lineEdit->setText (bi->getHeading());
1.199 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
1.200 lineEdit->setGeometry(p.x(),p.y(),230,25);
1.201 @@ -915,9 +939,10 @@
1.202 {
1.203 editingHeading=false;
1.204 lineEdit->releaseKeyboard();
1.205 + lineEdit->clearFocus();
1.206 model->setHeading (lineEdit->text() );
1.207 model->setSelectionBlocked(false);
1.208 - lineEdit->hide();
1.209 + delete (lineEdit);
1.210
1.211 // Maybe reselect previous branch
1.212 mainWindow->editHeadingFinished (model);
1.213 @@ -1281,7 +1306,7 @@
1.214
1.215 } // depth>0
1.216 // Maybe we can relink temporary?
1.217 - if (dsti) // FIXME-1 check if dsti is ancestor of myself!
1.218 + if (dsti)
1.219 {
1.220 if (e->modifiers()==Qt::ControlModifier)
1.221 {