diff -r 922d7f6c4e6c -r 1cc7bbf75f0b mapeditor.cpp --- a/mapeditor.cpp Fri Dec 29 13:52:19 2006 +0000 +++ b/mapeditor.cpp Fri Jan 05 11:17:32 2007 +0000 @@ -62,7 +62,6 @@ //cout << "Constructor ME "<setAcceptDrops(true); mapScene= new QGraphicsScene(parent); //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent); @@ -134,8 +133,7 @@ // Create temporary files makeTmpDirs(); - // Initially set movingCentre - updateViewCenter(); + setAcceptDrops (true); mapCenter->reposition(); // for positioning heading @@ -522,20 +520,6 @@ addMapInsertInt(t,y); } } - } else if (com=="colorItem") - { - if (!selection) - { - api.setError (Aborted,"Nothing selected"); - } else if ( typeid(*selection) != typeid(BranchObj) && - typeid(*selection) != typeid(MapCenterObj)) - { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) - { - QColor c=api.parColor (ok,0); - if (ok) colorItem (c); - } } else if (com=="colorBranch") { if (!selection) @@ -550,6 +534,20 @@ QColor c=api.parColor (ok,0); if (ok) colorBranch (c); } + } else if (com=="colorSubtree") + { + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(1)) + { + QColor c=api.parColor (ok,0); + if (ok) colorSubtree (c); + } } else if (com=="cut") { if (!selection) @@ -1126,7 +1124,6 @@ { QPainter pp(printer); - //pp.setRenderHints(renderHints()); pp.setRenderHint(QPainter::Antialiasing,true); // Don't print the visualisation of selection @@ -1140,79 +1137,49 @@ QRectF mapRect=totalBBox; QGraphicsRectItem *frame=NULL; - if (printFrame || printFooter) + if (printFrame) { - - if (printFrame) - { - // Print frame around map - mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, - totalBBox.width()+20, totalBBox.height()+20); - frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush)); - frame->setZValue(0); - frame->show(); - } - - if (printFooter) - { - // Print footer below map - QFont font; - font.setPointSize(10); - pp.setFont (font); - QRectF footerBox(0,printer->height()-15,printer->width(),15); - pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName); - pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate)); - } - } - - /* + // Print frame around map + mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, + totalBBox.width()+20, totalBBox.height()+20); + frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush)); + frame->setZValue(0); + frame->show(); + } + + double paperAspect = (double)printer->width() / (double)printer->height(); double mapAspect = (double)mapRect.width() / (double)mapRect.height(); - cout <<"mapAspect="<=paperAspect) { // Fit horizontally to paper width - pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) ); - qWarning ("Fit hor"); + //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) ); + viewBottom=(int)(printer->width()/mapAspect); } else { // Fit vertically to paper height - pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height()); - qWarning ("Fit ver"); + //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height()); + viewBottom=printer->height(); } - */ + + if (printFooter) + { + // Print footer below map + QFont font; + font.setPointSize(10); + pp.setFont (font); + QRectF footerBox(0,viewBottom,printer->width(),15); + pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName); + pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate)); + } mapScene->render ( &pp, - //pp.viewport(), QRectF (0,0,printer->width(),printer->height()-15), QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height()) ); - //render (&pp,printer->pageRect(), QRect ((int)mapRect.x(),(int)mapRect.y(),400,400)); - - //pp.setWindow (QRect (mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())); - //mapScene->render(&pp); // draw scene to printer - // Viewport has paper dimension - pp.drawLine (QLine (0,0,printer->width(),printer->height())); - cout << "sceneRect: " - <sceneRect().x()<<"," - <sceneRect().y()<<"," - <sceneRect().width()<<"," - <sceneRect().height()<<","<height()<getTotalBBox(); - QPixmap pix (mapRect.size()); + QPixmap pix (); QPainter pp (&pix); // Don't print the visualisation of selection @@ -1256,7 +1223,9 @@ pp.setWindow (mapRect); - mapScene->drawArea(mapRect, &pp); // draw scene to painter + //mapScene->drawArea(mapRect, &pp); // draw scene to painter + mapScene->render(&pp); // draw scene to painter + // Restore selection @@ -1268,7 +1237,6 @@ return pix; */ -return QPixmap(); } void MapEditor::setHideTmpMode (HideTmpMode mode) @@ -1885,7 +1853,7 @@ if (newbo) { saveState( - selection, // FIXME addNewBranch (int pos) sholdnt newbo be deleted here??? + newbo, "delete ()", selection, QString ("addBranch (%1)").arg(pos-2), @@ -2449,7 +2417,7 @@ return Qt::black; } -void MapEditor::colorItem(QColor c) +void MapEditor::colorBranch (QColor c) { if (selection) { @@ -2459,9 +2427,9 @@ BranchObj *bo=(BranchObj*)selection; saveState( selection, - QString ("colorItem (%1)").arg(bo->getColor().name()), + QString ("colorBranch (%1)").arg(bo->getColor().name()), selection, - QString ("colorItem (%1)").arg(c.name()), + QString ("colorBranch (%1)").arg(c.name()), QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name()) ); bo->setColor(c); // color branch @@ -2469,7 +2437,7 @@ } } -void MapEditor::colorBranch(QColor c) +void MapEditor::colorSubtree (QColor c) { if (selection) { @@ -2480,10 +2448,10 @@ saveStateChangingPart( selection, selection, - QString ("colorBranch (%1)").arg(c.name()), + QString ("colorSubtree (%1)").arg(c.name()), QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name()) ); - bo->setColorChilds(c); // color links, color childs + bo->setColorSubtree (c); // color links, color childs } } } @@ -2519,14 +2487,6 @@ } } -void MapEditor::setViewCenter() -{ - // transform to sceneView Coord: - QPointF p=matrix().map(movingCenter); - //FIXME setViewCenter not ported yet to QT4 (center ist TextStream there) - //center ( p.x(), p.y()); -} - BranchObj* MapEditor::findText (QString s, bool cs) { @@ -3393,18 +3353,6 @@ } -void MapEditor::updateViewCenter() -{ -/* FIXME updateViewCenter still to port to QT4 inverseworldmatrix - // Update movingCenter, so that we can zoom comfortably later - QRectF rc = QRectF( contentsX(), contentsY(), - visibleWidth(), visibleHeight() ); - QRectF canvasRect = inverseWorldMatrix().mapRect(rc); - movingCenter.setX((canvasRect.right() + canvasRect.left())/2); - movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2); - */ -} - void MapEditor::contextMenuEvent ( QContextMenuEvent * e ) { // Lineedits are already closed by preceding @@ -3751,15 +3699,9 @@ if (dst && selection) { if (e->state() & Qt::ShiftModifier) - { - ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor()); - ((BranchObj*)selection)->setLinkColor (); - } + colorBranch (((BranchObj*)(dst))->getColor()); else - { - ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor()); - ((BranchObj*)selection)->setLinkColor (); - } + colorSubtree (((BranchObj*)(dst))->getColor()); } return; } @@ -3921,48 +3863,81 @@ void MapEditor::dragEnterEvent(QDragEnterEvent *event) { - for (unsigned int i=0;event->format(i);i++) // Debug mime type - cerr << event->format(i) << endl; - - if (event->mimeData()->hasFormat("image/png")) - event->acceptProposedAction(); + //for (unsigned int i=0;event->format(i);i++) // Debug mime type + // cerr << event->format(i) << endl; + + if (event->mimeData()->hasImage()) + event->acceptProposedAction(); + else + if (event->mimeData()->hasUrls()) + event->acceptProposedAction(); +} + +void MapEditor::dragMoveEvent(QDragMoveEvent *event) +{ +} + +void MapEditor::dragLeaveEvent(QDragLeaveEvent *event) +{ + event->accept(); } void MapEditor::dropEvent(QDropEvent *event) { - if (event->mimeData()->hasFormat("image/png")) -} - -void MapEditor::contentsDropEvent(QDropEvent *event) -{ - //FIXME dropEvent not ported to QT4 yet if (selection && (typeid(*selection) == typeid(BranchObj)) || (typeid(*selection) == typeid(MapCenterObj))) { - bool update=false; - QStringList uris; - QString heading; - - - if (event->mimeData()->hasFormat("image/png")) + QList uris; + if (event->mimeData()->hasImage()) { - event->acceptProposedAction(); - addFloatImageInt(event->mimeData()->imageData().value()); - cout << "accepted drop\n"; - } - - /* - if (event->provides("image/png")) + QVariant imageData = event->mimeData()->imageData(); + addFloatImageInt (qvariant_cast(imageData)); + } else + if (event->mimeData()->hasUrls()) + uris=event->mimeData()->urls(); + + if (uris.count()>0) { - QPixmap pix; - if (Q3ImageDrag::decode(event, pix)) + QStringList files; + QString s; + QString heading; + BranchObj *bo; + for (int i=0; iaccept(); - update=true; - } else - event->ignore(); + bo=((BranchObj*)selection)->addBranch(); + if (bo) + { + s=uris.at(i).toLocalFile(); + if (!s.isEmpty()) + { + QString file = QDir::convertSeparators(s); + heading = QFileInfo(file).baseName(); + files.append(file); + if (file.endsWith(".vym", false)) + bo->setVymLink(file); + else + bo->setURL(uris.at(i).toString()); + } else + { + bo->setURL(uris.at(i).toString()); + } + + if (!heading.isEmpty()) + bo->setHeading(heading); + else + bo->setHeading(uris.at(i).toString()); + } + } + mapCenter->reposition(); + } + } + event->acceptProposedAction(); +} + +/* +void MapEditor::contentsDropEvent(QDropEvent *event) +{ } else if (event->provides("application/x-moz-file-promise-url") && event->provides("application/x-moz-nativeimage")) @@ -4009,101 +3984,10 @@ event->accept(); update= true; } + */ - /* not ported yet QSTRINGLIST has no next... - if (uris.count()>0) - { - QStringList files; - QStringList urls; - QString s; - BranchObj *bo; - for (const char* u=uris.first(); u; u=uris.next()) - { - bo=((BranchObj*)selection)->addBranch(); - if (bo) - { - s=Q3UriDrag::uriToLocalFile(u); - if (!s.isEmpty()) - { - QString file = QDir::convertSeparators(s); - heading = QFileInfo(file).baseName(); - files.append(file); - if (file.endsWith(".vym", false)) - bo->setVymLink(file); - else - bo->setURL(u); - } else - { - urls.append (u); - bo->setURL(u); - } - - if (!heading.isEmpty()) - bo->setHeading(heading); - else - bo->setHeading(u); - } - } - update=true; - } - */ - if (update) - { - //FIXME dropEvent: saveState has to be called earlier for each of the drops... - //saveStateComplete("Drop Event"); //TODO undo Command - mapCenter->reposition(); - scene()->update(); - } - } -} - - -void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) -{ - //FIXME contentsDragEnterEvent 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(); - return; - } - - // If QTextDrag can decode mime type - if (Q3TextDrag::canDecode(event)) { - event->accept(); - return; - } - - } - event->ignore(); -} + bool isUnicode16(const QByteArray &d) {