diff -r 7a71a914afdb -r 6d2b32f305f9 mapeditor.cpp --- a/mapeditor.cpp Thu May 07 08:48:53 2009 +0000 +++ b/mapeditor.cpp Wed May 13 08:26:27 2009 +0000 @@ -19,7 +19,6 @@ extern QString clipboardFile; extern bool clipboardEmpty; extern bool debug; -extern FlagRowObj *standardFlagsDefault; extern QMenu* branchContextMenu; extern QMenu* branchAddContextMenu; @@ -41,6 +40,8 @@ mapScene= new QGraphicsScene(NULL); mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern)); + zoomFactor=zoomFactorTarget=1; + model=vm; model->setScene (mapScene); model->registerEditor(this); @@ -147,6 +148,105 @@ return mapScene; } +void MapEditor::setScrollBarPosTarget (const QRectF &rect) +{ + // Code copied from Qt sources + int xmargin=50; + int ymargin=50; + + qreal width = viewport()->width(); + qreal height = viewport()->height(); + QRectF viewRect = matrix().mapRect(rect); + + qreal left = horizontalScrollBar()->value(); + qreal right = left + width; + qreal top = verticalScrollBar()->value(); + qreal bottom = top + height; + + if (viewRect.left() <= left + xmargin) { + // need to scroll from the left + // if (!d->leftIndent) + scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5)); + } + if (viewRect.right() >= right - xmargin) { + // need to scroll from the right +// if (!d->leftIndent) + scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5)); + } + if (viewRect.top() <= top + ymargin) { + // need to scroll from the top + // if (!d->topIndent) + scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5)); + } + if (viewRect.bottom() >= bottom - ymargin) { + // need to scroll from the bottom +// if (!d->topIndent) + scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5)); + } + + if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running) + scrollBarPosAnimation.stop(); + scrollBarPosAnimation.setTargetObject (this); + scrollBarPosAnimation.setPropertyName ("scrollBarPos"); + scrollBarPosAnimation.setDuration(1000); + scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint); + scrollBarPosAnimation.setStartValue( + QPointF (horizontalScrollBar()->value() , + verticalScrollBar()->value() ) ); + scrollBarPosAnimation.setEndValue(scrollBarPosTarget); + scrollBarPosAnimation.start(); +} + +QPointF MapEditor::getScrollBarPosTarget() +{ + return scrollBarPosTarget; +} + + +void MapEditor::setScrollBarPos(const QPointF &p) +{ + scrollBarPos=p; + horizontalScrollBar()->setValue(int(p.x())); + verticalScrollBar()->setValue(int(p.y())); +} + +QPointF MapEditor::getScrollBarPos() +{ + return scrollBarPos; +} + +void MapEditor::setZoomFactorTarget (const qreal &zft) +{ + zoomFactorTarget=zft; + if (zoomAnimation.state()==QtAbstractAnimation::Running) + zoomAnimation.stop(); + //zoomAnimation=QtPropertyAnimation(this, "zoomFactor"); + zoomAnimation.setTargetObject (this); + zoomAnimation.setPropertyName ("zoomFactor"); + zoomAnimation.setDuration(1000); + zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint); + zoomAnimation.setStartValue(zoomFactor); + zoomAnimation.setEndValue(zft); + zoomAnimation.start(); +} + +qreal MapEditor::getZoomFactorTarget() +{ + return zoomFactorTarget; +} + + +void MapEditor::setZoomFactor(const qreal &zf) +{ + zoomFactor=zf; + setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false ); +} + +qreal MapEditor::getZoomFactor() +{ + return zoomFactor; +} + void MapEditor::print() { if ( !printer ) @@ -273,42 +373,70 @@ void MapEditor::testFunction1() { - BranchItem *cur=NULL; - BranchItem *prev=NULL; - int d; - cout << "ME::testFunction1 starting to walk the map...\n"; - while (model->next (cur,prev,d) ) - cout << "*** " <getHeading().toStdString()<getSelectedBranchObj()->getBBox(); + int xmargin=50; + int ymargin=50; + qreal width = viewport()->width(); + qreal height = viewport()->height(); + QRectF viewRect = matrix().mapRect(rect); - //BranchObj *bo=model->getSelectedBranchObj(); - //if (bo) model->moveAway (bo); - //if (bo) bo->setLinkStyle (LinkableMapObj::Line); - + qreal left = horizontalScrollBar()->value(); + qreal right = left + width; + qreal top = verticalScrollBar()->value(); + qreal bottom = top + height; + if (viewRect.left() <= left + xmargin) { + // need to scroll from the left + // if (!d->leftIndent) + horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5)); + } + if (viewRect.right() >= right - xmargin) { + // need to scroll from the right +// if (!d->leftIndent) + horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5)); + } + if (viewRect.top() <= top + ymargin) { + // need to scroll from the top + // if (!d->topIndent) + verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5)); + } + if (viewRect.bottom() >= bottom - ymargin) { + // need to scroll from the bottom +// if (!d->topIndent) + verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5)); + } + cout << "test1: hor="<value()<setDuration(5000); + //animation->setEasingCurve ( QtEasingCurve::OutElastic); + animation->setEasingCurve ( QtEasingCurve::OutQuint); + animation->setStartValue(sceneRect() ); + animation->setEndValue(QRectF(50, 50, 1000, 1000)); - if (cur->depth() >0 && !bo->hasScrolledParent(bo) ) - { - p=QPointF (qrand() %600-300, qrand () %600-300); - bo->setRelPos(); - q=bo->getRelPos(); - model->startAnimation (bo,p, q); - } - model->next(cur,prev,d); - } -*/ + animation->start(); +*/ +/* + QDialog *dia= new QDialog (this); + dia->setGeometry (50,50,10,10); + dia->show(); + dia ->raise(); + + QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry"); + animation->setDuration(1000); + //animation->setEasingCurve ( QtEasingCurve::OutElastic); + animation->setEasingCurve ( QtEasingCurve::OutQuint); + animation->setStartValue(QRect(50, 50, 10, 10)); + animation->setEndValue(QRect(250, 250, 100, 100)); + + animation->start(); + */ /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone) @@ -335,7 +463,6 @@ } cout <<" hidemode="<getSelectString (bsel->getParObj()); QString preNum=QString::number (seli->num(),10); QString preDstParStr; + bool relinked; if (e->state() & Qt::ShiftModifier && dst->getParObj()) { // Link above dst preDstParStr=model->getSelectString (dst->getParObj()); - model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()); + relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()); } else if (e->state() & Qt::ControlModifier && dst->getParObj()) { // Link below dst preDstParStr=model->getSelectString (dst->getParObj()); - model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)seli)->num()+1); + relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1); } else { // Append to dst preDstParStr=model->getSelectString(dst); - model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti); + relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti); if (dsti->depth()==0) bsel->move (savePos); } - QString postSelStr=model->getSelectString(lmosel); - QString postNum=QString::number (seli->num(),10); + if (relinked) + { + QString postSelStr=model->getSelectString(lmosel); + QString postNum=QString::number (seli->num(),10); - QString undoCom="linkTo (\""+ - preParStr+ "\"," + preNum +"," + - QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; + QString undoCom="linkTo (\""+ + preParStr+ "\"," + preNum +"," + + QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; - QString redoCom="linkTo (\""+ - preDstParStr + "\"," + postNum + "," + - QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; + QString redoCom="linkTo (\""+ + preDstParStr + "\"," + postNum + "," + + QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; - model->saveState ( - postSelStr,undoCom, - preSelStr, redoCom, - QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) ); + model->saveState ( + postSelStr,undoCom, + preSelStr, redoCom, + QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) ); - model->reposition(); // not necessary if we undo temporary move below + } } else { // No destination, undo temporary move @@ -1135,7 +1265,7 @@ if (ti->isBranchLikeType()) { BranchObj *bo=(BranchObj*)ti->getLMO(); - bo->updateHeading(); + bo->updateData(); } }