diff -r 5db8dfd30ea2 -r c2a05fa925a1 mapeditor.cpp --- a/mapeditor.cpp Thu Nov 23 16:18:26 2006 +0000 +++ b/mapeditor.cpp Fri Dec 08 20:18:56 2006 +0000 @@ -1,5 +1,9 @@ #include "mapeditor.h" +#include +#include +#include +#include #include #include @@ -53,30 +57,34 @@ /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// -MapEditor::MapEditor( - QWidget* parent, const char* name, Qt::WFlags f) : - Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0) +MapEditor::MapEditor( QWidget* parent) : + QGraphicsView(parent), urlOperator(0), imageBuffer(0) { //cout << "Constructor ME "<setAcceptDrops(true); - mapCanvas = new Q3Canvas(width(),height()); - mapCanvas->setAdvancePeriod(30); - mapCanvas->setBackgroundColor (Qt::white); - - setCanvas (mapCanvas); + mapScene= new QGraphicsScene(parent); + //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent); + mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern)); + + + setScene (mapScene); + /* FIXME not needed in QT4? + // Maybe check QAbstractScrollArea... // Always show scroll bars (automatic would flicker sometimes) - setVScrollBarMode ( Q3ScrollView::AlwaysOn ); - setHScrollBarMode ( Q3ScrollView::AlwaysOn ); - - mapCenter = new MapCenterObj(mapCanvas); + setVScrollBarMode ( QScrollView::AlwaysOn ); + setHScrollBarMode ( QScrollView::AlwaysOn ); + */ + + mapCenter = new MapCenterObj(mapScene); mapCenter->setVisibility (true); mapCenter->setMapEditor (this); mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map")); - mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2); + //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2); + mapCenter->move(0,0); printer=NULL; @@ -157,60 +165,64 @@ return mapCenter; } -Q3Canvas* MapEditor::getCanvas() +QGraphicsScene * MapEditor::getScene() { - return mapCanvas; + return mapScene; } void MapEditor::adjustCanvasSize() { - // To adjust the canvas to map, viewport size and position, we have to + +/* FIXME QT4 probably not needed any longer! + + // To adjust the scene to map, viewport size and position, we have to // do some coordinate magic... // // Get rectangle of (scroll-)view. - // We want to be in canvas coords, so + // We want to be in scene coords, so // we map. Important if view is zoomed... - QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(), + QRectF view = inverseWorldMatrix().mapRect( QRectF( contentsX(), contentsY(), visibleWidth(), visibleHeight()) ); - // Now we need the bounding box of view AND map to calc the correct canvas size. + // Now we need the bounding box of view AND map to calc the correct scene size. // Why? Because if the map itself is moved out of view, the view has to be enlarged // to avoid jumping aroung... - QRect map=mapCenter->getTotalBBox(); + QRectF map=mapCenter->getTotalBBox(); // right edge - left edge int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x()); int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y()); - if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) || - !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight()) + if ( (cw!=mapScene->width()) || (ch!=mapScene->height()) || + !mapScene->onCanvas (map.topLeft()) || !mapScene->onCanvas (map.bottomRight()) ) { - // move the map on canvas (in order to not move it on screen) this is neccessary - // a) if topleft corner of canvas is left or above topleft corner of view and also left of + // move the map on scene (in order to not move it on screen) this is neccessary + // a) if topleft corner of scene is left or above topleft corner of view and also left of // above topleft corner of map. E.g. if map is completly inside view, but it would be possible - // to scroll to an empty area of canvas to the left. - // b) if topleft corner of map left of or above topleft of canvas + // to scroll to an empty area of scene to the left. + // b) if topleft corner of map left of or above topleft of scene int dx=0; int dy=0; - if (cw > mapCanvas->width() ) + if (cw > mapScene->width() ) { if (map.x()<0) dx=-map.x(); } - if (cw < mapCanvas->width() ) + if (cw < mapScene->width() ) dx=-min (view.x(),map.x()); - if (ch > mapCanvas->height() ) + if (ch > mapScene->height() ) { if (map.y()<0) dy=-map.y(); } - if (ch < mapCanvas->height() ) + if (ch < mapScene->height() ) { dy=-min (view.y(),map.y()); } // We really have to resize now. Let's go... - mapCanvas->resize (cw,ch); + // FIXME old code mapScene->resize (cw,ch); + mapScene->setSceneRect (QRectFF(0,0,cw,ch)); if ( (dx!=0) || (dy!=0) ) { mapCenter->moveAllBy(dx,dy); @@ -221,6 +233,8 @@ scrollBy (dx,dy); } } + + */ } bool MapEditor::isRepositionBlocked() @@ -257,12 +271,12 @@ d.mkdir (tmpMapDir); } -QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel) +QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel) { // tmpdir temporary directory to which data will be written // prefix mapname, which will be appended to images etc. // writeflags Only write flags for "real" save of map, not undo - // offset offset of bbox of whole map in canvas. + // offset offset of bbox of whole map in scene. // Needed for XML export // Save Header @@ -293,7 +307,7 @@ mapAttr+= attribut("author",mapCenter->getAuthor()) + attribut("comment",mapCenter->getComment()) + attribut("date",mapCenter->getDate()) + - attribut("backgroundColor", mapCanvas->backgroundColor().name() ) + + attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + attribut("linkStyle", ls ) + attribut("linkColor", defLinkColor.name() ) + attribut("defXLinkColor", defXLinkColor.name() ) + @@ -307,7 +321,7 @@ // Reset the counters before saving // TODO constr. of FIO creates lots of objects, better do this in some other way... - FloatImageObj (mapCanvas).resetSaveCounter(); + FloatImageObj (mapScene).resetSaveCounter(); // Build xml recursivly if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj)) @@ -447,7 +461,7 @@ // Save depending on how much needs to be saved if (saveSel) - backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel); + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel); QString undoCommand=""; if (savemode==UndoCommand) @@ -496,8 +510,8 @@ if (saveSel) cout << " saveSel="<getSelectString().ascii()<updateHistory (undoSet); setChanged(); - mainWindow->updateHistory (undoSet); updateActions(); } @@ -1136,9 +1150,9 @@ QString saveFile; if (savemode==CompleteMap || selection==NULL) - saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL); + saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); else - saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection); + saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),selection); if (!saveStringToDisk(fileDir+fname,saveFile)) return 1; @@ -1172,7 +1186,7 @@ printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString()); } - QRect totalBBox=mapCenter->getTotalBBox(); + QRectF totalBBox=mapCenter->getTotalBBox(); // Try to set orientation automagically // Note: Interpretation of generated postscript is amibiguous, if @@ -1201,15 +1215,18 @@ // Handle sizes of map and paper: // - // setWindow defines which part of the canvas will be transformed + // setWindow defines which part of the scene will be transformed // setViewport defines area on paper in device coordinates (dpi) // e.g. (0,50,700,700) is upper part on A4 // see also /usr/lib/qt3/doc/html/coordsys.html - double paperAspect = (double)printer->width() / (double)printer->height(); + Q3PaintDeviceMetrics metrics (printer); + + double paperAspect = (double)metrics.width() / (double)metrics.height(); double mapAspect = (double)totalBBox.width() / (double)totalBBox.height(); - QRect mapRect=totalBBox; + QRectF mapRect=totalBBox; +/* FIXME todo for QT4 Q3CanvasRectangle *frame=NULL; Q3CanvasText *footerFN=NULL; Q3CanvasText *footerDate=NULL; @@ -1221,32 +1238,31 @@ // Print frame around map mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, totalBBox.width()+20, totalBBox.height()+20); - frame=new Q3CanvasRectangle (mapRect,mapCanvas); + frame=new Q3CanvasRectangle (mapRect,mapScene); frame->setBrush (QColor(Qt::white)); frame->setPen (QColor(Qt::black)); frame->setZ(0); frame->show(); } - /* TODO remove after testing - QCanvasLine *l=new QCanvasLine (mapCanvas); - l->setPoints (0,0,mapRect.width(),mapRect.height()); - l->setPen (QPen(QColor(black), 1)); - l->setZ (200); - l->show(); - */ + // TODO remove after testing + //QCanvasLine *l=new QCanvasLine (mapScene); + //l->setPoints (0,0,mapRect.width(),mapRect.height()); + //l->setPen (QPen(QColor(black), 1)); + //l->setZ (200); + //l->show(); if (printFooter) { // Print footer below map QFont font; font.setPointSize(10); - footerFN=new Q3CanvasText (mapCanvas); + footerFN=new Q3CanvasText (mapScene); footerFN->setText ("VYM - " + fileName); footerFN->setFont(font); footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() ); footerFN->setZ(Z_TEXT); footerFN->show(); - footerDate=new Q3CanvasText (mapCanvas); + footerDate=new Q3CanvasText (mapScene); footerDate->setText (QDate::currentDate().toString(Qt::TextDate)); footerDate->setFont(font); footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() ); @@ -1258,19 +1274,21 @@ { pp.setWindow (mapRect); } +*/ if (mapAspect>=paperAspect) { // Fit horizontally to paper width - pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) ); + pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) ); } else { // Fit vertically to paper height - pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height()); + pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height()); } - mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer - + mapScene->render(&pp); // draw scene to printer + +/* // Delete Frame and footer if (footerFN) { @@ -1278,6 +1296,7 @@ delete (footerDate); } if (frame) delete (frame); +*/ // Restore selection if (oldselection) @@ -1291,9 +1310,20 @@ } } +void MapEditor::setAntiAlias (bool b) +{ + setRenderHint(QPainter::Antialiasing,b); +} + +void MapEditor::setSmoothPixmap(bool b) +{ + setRenderHint(QPainter::SmoothPixmapTransform,b); +} + QPixmap MapEditor::getPixmap() { - QRect mapRect=mapCenter->getTotalBBox(); +/* FIXME not ported yet to QT4 + QRectF mapRect=mapCenter->getTotalBBox(); QPixmap pix (mapRect.size()); QPainter pp (&pix); @@ -1307,7 +1337,7 @@ pp.setWindow (mapRect); - mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter + mapScene->drawArea(mapRect, &pp); // draw scene to painter // Restore selection @@ -1318,6 +1348,8 @@ } return pix; +*/ +return QPixmap(); } void MapEditor::setHideTmpMode (HideTmpMode mode) @@ -1326,7 +1358,7 @@ mapCenter->setHideTmp (hidemode); mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } HideTmpMode MapEditor::getHideTmpMode() @@ -1424,7 +1456,7 @@ { // write to directory QString clipfile="part"; - QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection); + QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),selection); QFile file; file.setName ( clipboardDir + "/"+clipfile+".xml"); @@ -1505,8 +1537,8 @@ undoSet.setEntry ("/history/curStep",QString::number(curStep)); undoSet.writeSettings(histPath); + mainWindow->updateHistory (undoSet); updateActions(); - mainWindow->updateHistory (undoSet); /* TODO remove testing cout << "ME::redo() end\n"; @@ -1747,11 +1779,11 @@ { if (selection) { - QString ps=qpointToString (selection->getAbsPos()); + QString ps=qpointfToString (selection->getAbsPos()); QString s=selection->getSelectString(); saveState( s, "move "+ps, - s, "move "+qpointToString (QPoint (x,y)), + s, "move "+qpointfToString (QPointF (x,y)), QString("Move %1 to %2").arg(getName(selection)).arg(ps)); selection->move(x,y); mapCenter->reposition(); @@ -1766,11 +1798,11 @@ typeid(*selection) == typeid(MapCenterObj) || typeid(*selection) == typeid (FloatImageObj))) { - QString ps=qpointToString (selection->getRelPos()); + QString ps=qpointfToString (selection->getRelPos()); QString s=selection->getSelectString(); saveState( s, "moveRel "+ps, - s, "moveRel "+qpointToString (QPoint (x,y)), + s, "moveRel "+qpointfToString (QPointF (x,y)), QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps)); ((OrnamentedObj*)selection)->move2RelPos (x,y); mapCenter->reposition(); @@ -1822,9 +1854,7 @@ { ok=true; ensureSelectionVisible(); - p = ((BranchObj*)selection)->getAbsPos(); - p.setX (p.x() - contentsX()); - p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2); + p=mapFromScene(selection->getAbsPos()); return ((BranchObj*)selection)->getHeading(); } ok=false; @@ -1967,7 +1997,7 @@ // We accept no MapCenterObj here, so we _have_ a parent { BranchObj* bo = (BranchObj*) selection; - QPoint p=bo->getRelPos(); + QPointF p=bo->getRelPos(); BranchObj *parbo=(BranchObj*)(selection->getParObj()); @@ -2443,29 +2473,67 @@ } } +void MapEditor::selectMapBackgroundImage () +{ + Q3FileDialog *fd=new Q3FileDialog( this); + fd->setMode (Q3FileDialog::ExistingFile); + fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); + ImagePreview *p =new ImagePreview (fd); + fd->setContentsPreviewEnabled( TRUE ); + fd->setContentsPreview( p, p ); + fd->setPreviewMode( Q3FileDialog::Contents ); + fd->setCaption(vymName+" - " +tr("Load background image")); + fd->setDir (lastImageDir); + fd->show(); + + if ( fd->exec() == QDialog::Accepted ) + { + // FIXME in QT4 use: lastImageDir=fd->directory(); + lastImageDir=QDir (fd->dirPath()); + setMapBackgroundImage (fd->selectedFile()); + } +} + +void MapEditor::setMapBackgroundImage (const QString &fn) +{ + QColor oldcol=mapScene->backgroundBrush().color(); + /* + saveState( + selection, + QString ("setMapBackgroundImage (%1)").arg(oldcol.name()), + selection, + QString ("setMapBackgroundImage (%1)").arg(col.name()), + QString("Set background color of map to %1").arg(col.name())); + */ + cout << "Trying to load "<setBackgroundBrush(brush); +} + void MapEditor::selectMapBackgroundColor() { - QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this ); + QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this ); if ( !col.isValid() ) return; - setBackgroundColor( col ); + setMapBackgroundColor( col ); } void MapEditor::setMapBackgroundColor(QColor col) { - QColor oldcol=mapCanvas->backgroundColor(); + QColor oldcol=mapScene->backgroundBrush().color(); saveState( selection, QString ("setMapBackgroundColor (%1)").arg(oldcol.name()), selection, QString ("setMapBackgroundColor (%1)").arg(col.name()), QString("Set background color of map to %1").arg(col.name())); - mapCanvas->setBackgroundColor (col); + mapScene->setBackgroundBrush(col); } QColor MapEditor::getMapBackgroundColor() { - return mapCanvas->backgroundColor(); + return mapScene->backgroundBrush().color(); } QColor MapEditor::getCurrentHeadingColor() @@ -2557,9 +2625,10 @@ void MapEditor::setViewCenter() { - // transform to CanvasView Coord: - QPoint p=worldMatrix().map(movingCenter); - center ( p.x(), p.y()); + // transform to sceneView Coord: + QPointF p=matrix().map(movingCenter); + //FIXME not ported yet to QT4 (center ist TextStream there) + //center ( p.x(), p.y()); } @@ -2756,7 +2825,7 @@ updateActions(); mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } } } @@ -2778,7 +2847,7 @@ updateActions(); mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } } @@ -2802,7 +2871,7 @@ updateActions(); mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } } @@ -2848,7 +2917,7 @@ { BranchObj* bo=(BranchObj*)selection; BranchObj* par=(BranchObj*)(bo->getParObj()); - QPoint p=bo->getRelPos(); + QPointF p=bo->getRelPos(); saveStateChangingPart( selection->getParObj(), selection, @@ -2892,11 +2961,7 @@ // Calc some stats QString stats; - int i=0; - Q3CanvasItemList l=canvas()->allItems(); - for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) - i++; - stats+=QString ("%1 items on canvas\n").arg (i,6); + stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6); uint b=0; uint f=0; @@ -3109,7 +3174,7 @@ ); bo->toggleScroll(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } } @@ -3171,7 +3236,7 @@ mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } delete (p); delete (fd); @@ -3335,7 +3400,7 @@ importDirInt (bo,QDir(fd->selectedFile()) ); mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } } } @@ -3386,17 +3451,6 @@ void MapEditor::testFunction() { - cout << "MapEditor::testFunction() called\n"; - - if (selection && - (typeid(*selection) == typeid(BranchObj)) || - (typeid(*selection) == typeid(MapCenterObj)) ) - { - BranchObj* bo=(BranchObj*)selection; - cout << bo->getHeading().ascii() <<" is scrolled: "<isScrolled()<calcBBoxSizeWithChilds(); - QRect totalBBox=mapCenter->getTotalBBox(); - QRect mapRect=totalBBox; + QRectF totalBBox=mapCenter->getTotalBBox(); + QRectF mapRect=totalBBox; QCanvasRectangle *frame=NULL; cout << " map has =("<setBrush (QColor(white)); frame->setPen (QColor(black)); - frame->setZ(0); + frame->setZValue(0); frame->show(); } else @@ -3442,32 +3496,35 @@ if (selection) { LinkableMapObj* lmo= dynamic_cast (selection); - QPoint p; + QPointF p; if (selection->getOrientation() == OrientLeftOfCenter) - p= worldMatrix().map(QPoint (lmo->x(),lmo->y())); - else - p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height())); - ensureVisible (p.x(), p.y() ); + p= matrix().map(QPointF (lmo->x(),lmo->y())); + else + p= matrix().map(QPointF (lmo->x()+lmo->width(),lmo->y()+lmo->height())); + ensureVisible (QRectF(p.x(), p.y(),0,0 )); + } } void MapEditor::updateViewCenter() { +/* FIXME still to port to QT4 inverseworldmatrix // Update movingCenter, so that we can zoom comfortably later - QRect rc = QRect( contentsX(), contentsY(), + QRectF rc = QRectF( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); - QRect canvasRect = inverseWorldMatrix().mapRect(rc); + QRectF canvasRect = inverseWorldMatrix().mapRect(rc); movingCenter.setX((canvasRect.right() + canvasRect.left())/2); movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2); + */ } -void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e ) +void MapEditor::contextMenuEvent ( QContextMenuEvent * e ) { // Lineedits are already closed by preceding // mouseEvent, we don't need to close here. - QPoint p = inverseWorldMatrix().map(e->pos()); + QPointF p = mapToScene(e->pos()); LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); if (lmo) @@ -3499,7 +3556,7 @@ } } else { // No MapObj found, we are on the Canvas itself - // Context Menu on Canvas + // Context Menu on scene updateActions(); canvasContextMenu->popup(e->globalPos() ); } @@ -3534,7 +3591,7 @@ setCursor (Qt::ArrowCursor); } -void MapEditor::contentsMousePressEvent(QMouseEvent* e) +void MapEditor::mousePressEvent(QMouseEvent* e) { // Ignore right clicks, these will go to context menus if (e->button() == Qt::RightButton ) @@ -3543,7 +3600,7 @@ return; } - QPoint p = inverseWorldMatrix().map(e->pos()); + QPointF p = mapToScene(e->pos()); LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); e->accept(); @@ -3602,7 +3659,7 @@ { drawingLink=true; linkingObj_src=bo_begin; - tmpXLink=new XLinkObj (mapCanvas); + tmpXLink=new XLinkObj (mapScene); tmpXLink->setBegin (bo_begin); tmpXLink->setEnd (p); tmpXLink->setColor(defXLinkColor); @@ -3649,27 +3706,31 @@ toggleScroll(); updateActions(); } else - { // No MapObj found, we are on the Canvas itself - // Left Button move Pos of CanvasView + { // No MapObj found, we are on the scene itself + // Left Button move Pos of sceneView if (e->button() == Qt::LeftButton ) { movingObj=NULL; // move Content not Obj movingObj_start=e->globalPos(); - movingCont_start=QPoint (contentsX(), contentsY() ); - movingVec=QPoint(0,0); + // FIXME not ported to QT4 yet (move canvasView) + //movingCont_start=QPointF (contentsX(), contentsY() ); + movingCont_start=QPointF ( + horizontalScrollBar()->value(), + verticalScrollBar()->value()); + movingVec=QPointF(0,0); setCursor(HandOpenCursor); } } } -void MapEditor::contentsMouseMoveEvent(QMouseEvent* e) +void MapEditor::mouseMoveEvent(QMouseEvent* e) { - QPoint p = inverseWorldMatrix().map(e->pos()); + QPointF p = mapToScene(e->pos()); // Move the selected MapObj if ( selection && movingObj) { - // To avoid jumping of the CanvasView, only + // To avoid jumping of the sceneView, only // ensureSelectionVisible, if not tmp linked if (!selection->hasParObjTmp()) ensureSelectionVisible (); @@ -3691,7 +3752,7 @@ FloatObj *fo=(FloatObj*)selection; fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); fo->setRelPos(); - fo->reposition(); + fo->updateLink(); //no need for reposition, if we update link here // Relink float to new mapcenter or branch, if shift is pressed // Only relink, if selection really has a new parent @@ -3703,7 +3764,8 @@ { if (typeid(*fo) == typeid(FloatImageObj)) { - //TODO undocom + //FIXME undocom for relinking of floats + //saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) ); FloatImageObj *fio=(FloatImageObj*)(fo); ((BranchObj*)(lmo))->addFloatImage (fio); @@ -3769,7 +3831,7 @@ } // no FloatImageObj - canvas()->update(); + scene()->update(); return; } // selection && moving_obj @@ -3780,22 +3842,25 @@ tmpXLink->updateXLink(); } - // Move CanvasView - if (!movingObj && !pickingColor &&!drawingLink) + // Move sceneView + //if (!movingObj && !pickingColor &&!drawingLink && e->button() == Qt::LeftButton ) + if (e->buttons() == Qt::LeftButton ) { - QPoint p=e->globalPos(); + QPointF p=e->globalPos(); movingVec.setX(-p.x() + movingObj_start.x() ); movingVec.setY(-p.y() + movingObj_start.y() ); - setContentsPos( movingCont_start.x() + movingVec.x(), - movingCont_start.y() + movingVec.y()); - - updateViewCenter(); + // FIXME not ported to QT4 yet (move canvasView) + //setContentsPos( movingCont_start.x() + movingVec.x(), + //movingCont_start.y() + movingVec.y(); + horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() )); + verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) ); } } -void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e) +void MapEditor::mouseReleaseEvent(QMouseEvent* e) { + QPointF p = mapToScene(e->pos()); LinkableMapObj *dst; // Have we been picking color? if (pickingColor) @@ -3803,7 +3868,7 @@ pickingColor=false; setCursor (Qt::ArrowCursor); // Check if we are over another branch - dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL); + dst=mapCenter->findMapObj(p, NULL); if (dst && selection) { if (e->state() & Qt::ShiftModifier) @@ -3825,7 +3890,7 @@ { drawingLink=false; // Check if we are over another branch - dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL); + dst=mapCenter->findMapObj(p, NULL); if (dst && selection) { tmpXLink->setEnd ( ((BranchObj*)(dst)) ); @@ -3847,8 +3912,8 @@ { // Moved FloatObj. Maybe we need to reposition FloatImageObj *fo=(FloatImageObj*)selection; - QString pold=qpointToString(movingObj_orgRelPos); - QString pnow=qpointToString(fo->getRelPos()); + QString pold=qpointfToString(movingObj_orgRelPos); + QString pnow=qpointfToString(fo->getRelPos()); saveState( selection, "moveRel "+pold, @@ -3863,7 +3928,7 @@ // Check if we are over another branch, but ignore // any found LMOs, which are FloatObjs - dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), + dst=mapCenter->findMapObj(mapToScene(e->pos() ), ((LinkableMapObj*)selection) ); if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) @@ -3878,7 +3943,7 @@ { // A branch was moved // save the position in case we link to mapcenter - QPoint savePos=QPoint (selection->x(),selection->y() ); + QPointF savePos=QPointF (selection->x(),selection->y() ); // Reset the temporary drawn link to the original one ((LinkableMapObj*)selection)->unsetParObjTmp(); @@ -3934,9 +3999,9 @@ // Therefor reposition and then use string of old selection, too mapCenter->reposition(); - QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() ); + QString ps=qpointfToString ( ((BranchObj*)selection)->getRelPos() ); saveState( - selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos), + selection->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), preSelStr, "moveRel "+ps, QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps)); @@ -3944,9 +4009,9 @@ // Draw the original link, before selection was moved around mapCenter->reposition(); } - // Finally resize canvas, if needed + // Finally resize scene, if needed adjustCanvasSize(); - canvas()->update(); + scene()->update(); movingObj=NULL; // Just make sure, that actions are still ok,e.g. the move branch up/down buttons... @@ -3957,11 +4022,11 @@ } -void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e) +void MapEditor::mouseDoubleClickEvent(QMouseEvent* e) { if (e->button() == Qt::LeftButton ) { - QPoint p = inverseWorldMatrix().map(e->pos()); + QPointF p = mapToScene(e->pos()); LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL); if (lmo) { // MapObj was found // First select the MapObj than edit heading @@ -3975,74 +4040,57 @@ void MapEditor::resizeEvent (QResizeEvent* e) { - Q3CanvasView::resizeEvent( e ); + QGraphicsView::resizeEvent( e ); adjustCanvasSize(); } void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) { - if (selection && - (typeid(*selection) == typeid(BranchObj)) || - (typeid(*selection) == typeid(MapCenterObj))) - { - if (event->mimeData()->hasFormat("image/png")) - { - cout <<"found png in dragenterevent\n"; - event->accept(); - return; - } - - if (event->mimeData()->hasFormat("text/uri-list")) - { - cout <<"found uri-list in dragenterevent\n"; - event->accept(); - return; - } - -/* - // If QImageDrag can decode mime type - if (Q3ImageDrag::canDecode(event)) - { - cout << "dragenterevent q3imagedrag\n"; - event->accept(); - return; - } -*/ - // If image are dragged from firefox - if (event->mimeData()->hasFormat("application/x-moz-file-promise-url") && - event->mimeData()->hasFormat("application/x-moz-nativeimage")) { - event->accept(true); - cout << "dragenterevent firefox\n"; - return; - } -/* - // If QUriDrag can decode mime type - if (Q3UriDrag::canDecode(event)) { - event->accept(); - cout << "accepted uri drag\n"; - return; - } + //FIXME not ported to QT4 yet + +// for (unsigned int i=0;event->format(i);i++) // Debug mime type +// cerr << event->format(i) << endl; + + if (selection && + (typeid(*selection) == typeid(BranchObj)) || + (typeid(*selection) == typeid(MapCenterObj))) { + + // If QImageDrag can decode mime type + if (Q3ImageDrag::canDecode(event)) { + event->accept(); + return; + } + + // If image are dragged from firefox + if (event->provides("application/x-moz-file-promise-url") && + event->provides("application/x-moz-nativeimage")) { + event->accept(true); + return; + } + + // If QUriDrag can decode mime type + if (Q3UriDrag::canDecode(event)) { + event->accept(); + return; + } + // If Uri are dragged from firefox - if (event->provides("_NETSCAPE_URL")){ - event->accept(); - cout << "dragenterevent NETSCAPE\n"; - return; - } - - // If QTextDrag can decode mime type - if (Q3TextDrag::canDecode(event)) { - event->accept(); - cout << "dragenterevent textdrag\n"; - return; - } -*/ - } - event->ignore(); + if (event->provides("_NETSCAPE_URL")){ + event->accept(); + return; + } + + // If QTextDrag can decode mime type + if (Q3TextDrag::canDecode(event)) { + event->accept(); + return; + } + + } + event->ignore(); } - - -/* FIXME needed in QT4? bool isUnicode16(const QByteArray &d) +bool isUnicode16(const QByteArray &d) { // TODO: make more precise check for unicode 16. // Guess unicode16 if any of second bytes are zero @@ -4051,17 +4099,16 @@ if (d.at(i*2+1)==0) return true; return false; } -*/ - + void MapEditor::contentsDropEvent(QDropEvent *event) { + //FIXME not ported to QT4 yet if (selection && (typeid(*selection) == typeid(BranchObj)) || (typeid(*selection) == typeid(MapCenterObj))) { bool update=false; QStringList uris; - QList urls; QString heading; @@ -4069,21 +4116,34 @@ { event->acceptProposedAction(); addFloatImageInt(event->mimeData()->imageData().value()); - cout << "Drop png...\n"; - } else if (event->mimeData()->hasFormat("application/x-moz-file-promise-url")&& - event->mimeData()->hasFormat("application/x-moz-nativeimage")) + cout << "accepted drop\n"; + } + + /* + if (event->provides("image/png")) { - cout << "Drop Mozilla...\n"; + QPixmap pix; + if (Q3ImageDrag::decode(event, pix)) + { + addFloatImageInt(pix); + event->accept(); + update=true; + } else + event->ignore(); + + } else if (event->provides("application/x-moz-file-promise-url") && + event->provides("application/x-moz-nativeimage")) + { // Contains url to the img src in unicode16 QByteArray d = event->encodedData("application/x-moz-file-promise-url"); QString url = QString((const QChar*)d.data(),d.size()/2); - //FIXME fetchImage(url); - event->acceptProposedAction(); + fetchImage(url); + event->accept(); update=true; - } else if (event->mimeData()->hasUrls()) - { - urls=event->mimeData()->urls(); - } /*else if (event->provides ("_NETSCAPE_URL")) + } else if (event->provides ("text/uri-list")) + { // Uris provided e.g. by konqueror + Q3UriDrag::decode (event,uris); + } else if (event->provides ("_NETSCAPE_URL")) { // Uris provided by Mozilla QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); uris.append(l[0]); @@ -4118,10 +4178,6 @@ } */ - for (int i=0; i0) { @@ -4165,7 +4221,7 @@ //saveStateComplete("Drop Event"); //TODO undo Command mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } } } @@ -4177,7 +4233,6 @@ (typeid(*selection) == typeid(MapCenterObj)) ) { BranchObj *bo=((BranchObj*)selection); - qWarning ("Warning: Image added by drop event: no undo/redo so far."); //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo))); //QString fn=fd->selectedFile(); //lastImageDir=fn.left(fn.findRev ("/")); @@ -4186,13 +4241,12 @@ fio->setOriginalFilename("Image added by Drag and Drop"); mapCenter->reposition(); adjustCanvasSize(); - canvas()->update(); + scene()->update(); } } -//void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/) -/* FIXME not needed in QT4 +void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/) { if (!imageBuffer) imageBuffer = new QBuffer(); if (!imageBuffer->isOpen()) { @@ -4235,5 +4289,3 @@ this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *))); urlOperator->get(); } - -*/