# HG changeset patch # User insilmaril # Date 1262637366 0 # Node ID 8f987e376035023b1dadc12d03ba27a3eb6039c8 # Parent 25ee6b988b737ae24120c6515987e4d15f1ecbfb various fixes diff -r 25ee6b988b73 -r 8f987e376035 branchitem.cpp --- a/branchitem.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/branchitem.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -178,7 +178,12 @@ { // Needed to hide relinked branch, if parent is scrolled if (lmo) - lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled()); + { + if (hasScrolledParent(this) || hidden) + lmo->setVisibility (false); + else + lmo->setVisibility (true); + } } void BranchItem::setHeadingColor (QColor color) diff -r 25ee6b988b73 -r 8f987e376035 branchobj.cpp --- a/branchobj.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/branchobj.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -26,22 +26,6 @@ init(); } -/* -BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all? -{ -// cout << "Const BranchObj (s,p)\n"; - scene=s; - setParObj (p); - if (treeItem->depth()==1) // FIXME-3 needed to recursively calc depth? - // Calc angle to mapCenter if I am a mainbranch - // needed for reordering the mainbranches clockwise - // around mapcenter - angle=getAngle (QPointF (x() - parObj->getChildPos().x() , - (y() - parObj->getChildPos().y() ) ) ); - init(); -} -*/ - BranchObj::~BranchObj () { // cout << "Destr BranchObj of "<getHeading().toStdString()<<")"<isScrolled() ) return r; +/* FIXME-2 really include children _here_ ? likely not needed anymore, but done in TreeItem */ for (int i=0; ibranchCount(); ++i) if (!treeItem->getBranchNum(i)->isHidden()) r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r); @@ -643,9 +628,11 @@ (have been NULL at least in calcBBoxSizeWithChilds...) */ - for (int i=0; iimageCount(); ++i) +/* FIXME-2 in + for (int i=0; iimageCount(); ++i if (!treeItem->isHidden()) r=addBBox(treeItem->getImageObjNum(i)->getTotalBBox(),r); +*/ return r; } @@ -672,7 +659,7 @@ return MapObj::getBoundingPolygon(); } - calcBBoxSizeWithChildren(); //FIXME-3 really needed? + calcBBoxSizeWithChildren(); //FIXME-2 really needed? QPolygonF p; p<getModel(); - if (model) - return model->getSelectString (this); - else - return QString(); -} - void BranchObj::setAnimation(const AnimPoint &ap) { anim=ap; diff -r 25ee6b988b73 -r 8f987e376035 branchobj.h --- a/branchobj.h Tue Dec 15 09:14:59 2009 +0000 +++ b/branchobj.h Mon Jan 04 20:36:06 2010 +0000 @@ -51,7 +51,6 @@ virtual ConvexPolygon getBoundingPolygon(); virtual void calcBBoxSizeWithChildren(); // calc size of BBox including children recursivly - virtual QString getSelectString(); virtual void setAnimation(const AnimPoint &ap); virtual bool animate(); diff -r 25ee6b988b73 -r 8f987e376035 demos/vym-projectplan.vym Binary file demos/vym-projectplan.vym has changed diff -r 25ee6b988b73 -r 8f987e376035 exports.cpp --- a/exports.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/exports.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -14,6 +14,23 @@ ExportBase::ExportBase() { + init(); +} + +ExportBase::ExportBase(VymModel *m) +{ + init(); + model=m; +} + +ExportBase::~ExportBase() +{ + // Cleanup tmpdir + removeDir (tmpDir); +} + +void ExportBase::init() +{ indentPerDepth=" "; bool ok; tmpDir.setPath (makeTmpDir(ok,"vym-export")); @@ -23,12 +40,6 @@ cancelFlag=false; } -ExportBase::~ExportBase() -{ - // Cleanup tmpdir - removeDir (tmpDir); -} - void ExportBase::setDir(const QDir &d) { outDir=d; @@ -262,7 +273,7 @@ { // Make indentstring curIndent=""; - for (i=0;idepth()-1;i++) curIndent+= indentPerDepth; + for (i=1;idepth()-1;i++) curIndent+= indentPerDepth; if (!cur->hasHiddenExportParent() ) { @@ -460,6 +471,176 @@ } //////////////////////////////////////////////////////////////////////// +ExportHTML::ExportHTML():ExportBase() +{ + init(); +} + +ExportHTML::ExportHTML(VymModel *m):ExportBase(m) +{ + init(); +} + +void ExportHTML::init() +{ + singularDelimiter=": "; + noSingulars=true; + frameURLs=true; + useMapColors=true; + + if (model &&model->getMapEditor()) + offset=model->getMapEditor()->getTotalBBox().topLeft(); +} + +QString ExportHTML::getBranchText(BranchItem *current) +{ + if (current) + { + bool vis=false; + QRectF hr; + LinkableMapObj *lmo=current->getLMO(); + if (lmo) + { + hr=((BranchObj*)lmo)->getBBoxHeading(); + if (lmo->isVisibleObj()) vis=true; + } + QString col; + QString id=model->getSelectString(current); + if (useMapColors) + col=QString("style='color:%1'").arg(current->getHeadingColor().name()); + QString s=QString("") + .arg(current->depth()) + .arg(col) + .arg(id); + QString url=current->getURL(); + if (!url.isEmpty()) + { + s+=QString ("").arg(url); + s+=QString ("%1").arg(quotemeta(current->getHeading())); + s+=""; + + QRectF fbox=current->getBBoxFlag ("system-url"); + if (vis) + imageMap+=QString(" \n") + .arg(fbox.left()-offset.x()) + .arg(fbox.top()-offset.y()) + .arg(fbox.right()-offset.x()) + .arg(fbox.bottom()-offset.y()) + .arg(url); + } else + s+=quotemeta(current->getHeading()); + s+=""; + + if (vis) + imageMap+=QString(" \n") + .arg(hr.left()-offset.x()) + .arg(hr.top()-offset.y()) + .arg(hr.right()-offset.x()) + .arg(hr.bottom()-offset.y()) + .arg(id); + + // Include note + if (!current->getNoteObj().isEmpty()) + s+="
"+current->getNote()+"
"; + + return s; + } + return QString(); +} + +QString ExportHTML::buildList (BranchItem *current) +{ + QString r; + + uint i=0; + BranchItem *bi=current->getFirstBranch(); + + // Only add itemized list, if we have more than one subitem. + // For only one subitem, just add a separator to keep page more compact + bool noSingularsHere=false; + if (current->branchCount()<2 && noSingulars) noSingularsHere=true; + + if (bi) + { + if (!noSingularsHere) + r+="
    \n"; + else + r+=singularDelimiter; + + while (bi) + { + if (!bi->hasHiddenExportParent() ) + { + if (!noSingularsHere) r+="
  • "; + r+=getBranchText (bi); + if (!bi->getURL().isEmpty() && frameURLs && noSingularsHere) + // Add frame, if we have subitems to an URL + r+="
    "+buildList (bi)+"
    "; // recursivly add deeper branches + else + r+=buildList (bi); // recursivly add deeper branches + if (!noSingularsHere) r+="
  • "; + r+="\n"; + } + i++; + bi=current->getBranchNum(i); + } + + if (!noSingularsHere) r+="
\n"; + } + return r; +} + +void ExportHTML::doExport() +{ + QFile file (outputFile); + if ( !file.open( QIODevice::WriteOnly ) ) + { + QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile)); + mainWindow->statusMessage(QString(QObject::tr("Export failed."))); + return; + } + QTextStream ts( &file ); // use LANG decoding here... + ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8 + + // Write header + ts<<""+model->getMapName()<<""; + ts<<" \n"; + + // Include image + ts<<"
\n"; + + + // Main loop over all mapcenters + QString s; + TreeItem *rootItem=model->getRootItem(); + BranchItem *bi; + for (int i=0; ibranchCount(); i++) + { + bi=rootItem->getBranchNum(i); + if (!bi->hasHiddenExportParent()) + { + ts<\n"+imageMap+"\n"; + + // Write footer + ts<<"
\n"; + ts<<" \n\ + \n\ + \n\ + \n\ + \n\ + \n \ +
"+model->getFileName()+""+model->getDate()+" vym "+model->getVersion()+"
\n"; + ts<<""; + file.close(); +} + +//////////////////////////////////////////////////////////////////////// void ExportTaskjuggler::doExport() { model->exportXML(tmpDir.path(),false); @@ -550,11 +731,11 @@ BranchItem *bi=current->getFirstBranch(); if (bi) { - if (!bi->hasHiddenExportParent() ) // FIXME-3 use BranchItem... + // Start list + r+="\n"; + while (bi) { - // Start list - r+="\n"; - while (bi) + if (!bi->hasHiddenExportParent() ) { r+=""; r+=quotemeta(bi->getHeading()); @@ -564,11 +745,11 @@ r+=""; r+=buildList (bi); // recursivly add deeper branches r+="\n"; - i++; - bi=current->getBranchNum(i); } - r+="\n"; + i++; + bi=current->getBranchNum(i); } + r+="\n"; } return r; } diff -r 25ee6b988b73 -r 8f987e376035 exports.h --- a/exports.h Tue Dec 15 09:14:59 2009 +0000 +++ b/exports.h Mon Jan 04 20:36:06 2010 +0000 @@ -18,7 +18,9 @@ { public: ExportBase(); + ExportBase(VymModel *m); virtual ~ExportBase(); + virtual void init(); virtual void setDir(const QDir&); virtual void setFile(const QString &); virtual QString getFile (); @@ -92,6 +94,27 @@ }; /////////////////////////////////////////////////////////////////////// +class ExportHTML:public ExportBase +{ +public: + ExportHTML(); + ExportHTML(VymModel *m); + virtual void init(); + virtual void doExport(); +private: + QString getBranchText(BranchItem *); + QString buildList (BranchItem *); + QString imageMap; + + bool frameURLs; + bool noSingulars; + QString singularDelimiter; + bool useMapColors; + + QPointF offset; +}; + +/////////////////////////////////////////////////////////////////////// class ExportTaskjuggler:public ExportXMLBase { public: diff -r 25ee6b988b73 -r 8f987e376035 flagrowobj.h --- a/flagrowobj.h Tue Dec 15 09:14:59 2009 +0000 +++ b/flagrowobj.h Mon Jan 04 20:36:06 2010 +0000 @@ -32,8 +32,8 @@ void activate (Flag *flag); void deactivate(const QString&); void setShowFlags (bool); + FlagObj* findFlag (const QString&); private: - FlagObj* findFlag (const QString&); QList flag; bool showFlags; // FloatObjects want to hide their flags }; diff -r 25ee6b988b73 -r 8f987e376035 mainwindow.cpp --- a/mainwindow.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/mainwindow.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -411,9 +411,15 @@ connect( a, SIGNAL( triggered() ), this, SLOT( fileExportOOPresentation() ) ); fileExportMenu->addAction (a); - a = new QAction( "Webpage (XHTML)...",this ); - a->setShortcut (Qt::ALT + Qt::Key_X); //Export XHTML + a = new QAction( "Webpage (HTML)...",this ); + a->setShortcut (Qt::ALT + Qt::Key_X); //Export HTML a->setStatusTip ( tr( "Export as %1","status tip file menu").arg(tr(" webpage (XHTML)","status tip file menu"))); + connect( a, SIGNAL( triggered() ), this, SLOT( fileExportHTML() ) ); + fileExportMenu->addAction (a); + + a = new QAction( "Webpage (XHTML)...",this ); //Export XHTML + + //a->setShortcut (Qt::ALT + Qt::SHIFT + Qt::Key_X); a->setStatusTip ( tr( "Export as %1","status tip file menu").arg(tr(" webpage (XHTML)","status tip file menu"))); connect( a, SIGNAL( triggered() ), this, SLOT( fileExportXHTML() ) ); fileExportMenu->addAction (a); @@ -1040,7 +1046,7 @@ tb->setObjectName ("viewTB"); QMenu *viewMenu = menuBar()->addMenu ( tr( "&View" )); - Switchboard switchboard; //FIXME-1 testing... + Switchboard switchboard; //FIXME-2 testing... QAction *a; a = new QAction(QPixmap(iconPath+"viewmag-reset.png"), tr( "reset Zoom","View action" ), this); @@ -2218,6 +2224,12 @@ if (m) m->exportXML(); } +void Main::fileExportHTML() +{ + VymModel *m=currentModel(); + if (m) m->exportHTML(); +} + void Main::fileExportXHTML() { @@ -2833,7 +2845,11 @@ void Main::editAddAttribute() { VymModel *m=currentModel(); - if (m) m->addAttribute(); + if (m) + { + + m->addAttribute(); + } } void Main::editAddMapCenter() diff -r 25ee6b988b73 -r 8f987e376035 mainwindow.h --- a/mainwindow.h Tue Dec 15 09:14:59 2009 +0000 +++ b/mainwindow.h Mon Jan 04 20:36:06 2010 +0000 @@ -94,6 +94,7 @@ void fileImportMM(); void fileImportDir(); void fileExportXML(); + void fileExportHTML(); void fileExportXHTML(); void fileExportImage(); void fileExportAO(); diff -r 25ee6b988b73 -r 8f987e376035 mapeditor.cpp --- a/mapeditor.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/mapeditor.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -113,10 +113,7 @@ // Action to embed LineEdit for heading in Scene editingHeading=false; - lineEdit=new QLineEdit; - lineEdit->hide(); - QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit); - pw->setZValue (Z_LINEEDIT); + lineEdit=NULL; a = new QAction( tr( "Edit heading","MapEditor" ), this); a->setShortcut ( Qt::Key_Return ); //Edit heading @@ -405,35 +402,55 @@ QRectF MapEditor::getTotalBBox() { - QRectF r; + QPen pen; + pen.setWidth (1); + pen.setCapStyle ( Qt::RoundCap ); + + QRectF rt; BranchObj *bo; - for (int i=0;igetRootItem()->branchCount(); i++) + BranchItem *cur=NULL; + BranchItem *prev=NULL; + model->nextBranch(cur,prev); + while (cur) { - bo=(BranchObj*)(model->getRootItem()->getBranchNum(i)->getLMO()); - if (bo) r=addBBox (bo->getTotalBBox(), r); + if (!cur->hasHiddenExportParent()) + { + bo=(BranchObj*)(cur->getLMO()); + if (bo && bo->isVisibleObj()) + { + bo->calcBBoxSizeWithChildren(); + // FIXME-3 testing + //QRectF r1=bo->getBBoxSizeWithChildren(); + QRectF r1=bo->getBBox(); + //pen.setColor ( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8)); + //mapScene->addRect (r1,pen); + + if (rt.isNull()) rt=r1; + rt=addBBox (r1, rt); + //FIXME-2 cout <<"ME: r1="<getHeadingStd()<setBrush (QColor(white)); + frame->setPen (QColor(black)); + frame->setZValue(0); + frame->show(); + + } + else + { + setHideTmpMode (HideNone); + } + cout <<" hidemode="<setBrush (QColor(white)); - frame->setPen (QColor(black)); - frame->setZValue(0); - frame->show(); - } - else - { - setHideTmpMode (HideNone); - } - cout <<" hidemode="<setExportMode (false); + return; + // Create list with all bounding polygons QList mapobjects; QList polys; @@ -899,6 +919,10 @@ { model->setSelectionBlocked(true); + lineEdit=new QLineEdit; + QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit); + pw->setZValue (Z_LINEEDIT); + lineEdit->setText (bi->getHeading()); QPoint p = mapTo (this,bo->getAbsPos().toPoint() ); lineEdit->setGeometry(p.x(),p.y(),230,25); @@ -915,9 +939,10 @@ { editingHeading=false; lineEdit->releaseKeyboard(); + lineEdit->clearFocus(); model->setHeading (lineEdit->text() ); model->setSelectionBlocked(false); - lineEdit->hide(); + delete (lineEdit); // Maybe reselect previous branch mainWindow->editHeadingFinished (model); @@ -1281,7 +1306,7 @@ } // depth>0 // Maybe we can relink temporary? - if (dsti) // FIXME-1 check if dsti is ancestor of myself! + if (dsti) { if (e->modifiers()==Qt::ControlModifier) { diff -r 25ee6b988b73 -r 8f987e376035 mapeditor.h --- a/mapeditor.h Tue Dec 15 09:14:59 2009 +0000 +++ b/mapeditor.h Mon Jan 04 20:36:06 2010 +0000 @@ -52,9 +52,10 @@ public: void print(); //!< Print the map QRectF getTotalBBox(); //!< Bounding box of all items in map - QPixmap getPixmap(); //!< Get a pixmap of the map + QImage getImage (); //!< Get a pixmap of the map void setAntiAlias (bool); //!< Set or unset antialiasing void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps + void setHideTmp (bool); //!< Hide parts temporary public: TreeItem *findMapItem (QPointF p,TreeItem *exclude); //! find item in map at position p. Ignore item exclude diff -r 25ee6b988b73 -r 8f987e376035 mapitem.cpp --- a/mapitem.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/mapitem.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -104,6 +104,14 @@ return s; } +QRectF MapItem::getBBoxFlag (const QString &fname) +{ + if (lmo) + return ((OrnamentedObj*)lmo)->getBBoxFlag (fname); + else + return QRectF (); +} + LinkableMapObj* MapItem::getLMO() { return lmo; diff -r 25ee6b988b73 -r 8f987e376035 mapitem.h --- a/mapitem.h Tue Dec 15 09:14:59 2009 +0000 +++ b/mapitem.h Mon Jan 04 20:36:06 2010 +0000 @@ -54,6 +54,7 @@ virtual QString getMapAttr(); //! Get attributes for saving as XML + virtual QRectF getBBoxFlag (const QString &fname); //! get bbox of flag protected: diff -r 25ee6b988b73 -r 8f987e376035 misc.cpp --- a/misc.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/misc.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -30,7 +30,7 @@ ostream &operator<< (ostream &stream, QRectF const &r) { - stream << "tL="< cData; cData << "new attribute" << "undef"; AttributeItem *a=new AttributeItem (cData); - + if (addAttribute (a)) return a; + } + return NULL; +} + +AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing +{ + BranchItem *selbi=getSelectedBranch(); + if (selbi) + { emit (layoutAboutToBeChanged() ); QModelIndex parix=index(selbi); - int n=selbi->getRowNumAppend (a); + int n=selbi->getRowNumAppend (ai); beginInsertRows (parix,n,n); - selbi->appendChild (a); + selbi->appendChild (ai); endInsertRows (); emit (layoutChanged() ); reposition(); - return a; + return ai; } return NULL; } @@ -2435,9 +2449,14 @@ unselect(); saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi))); - TreeItem *pi=deleteItem (selbi); + BranchItem *pi=(BranchItem*)(deleteItem (selbi)); if (pi) { + if (pi->isScrolled() && pi->branchCount()==0) + { + pi->unScroll(); + emitDataHasChanged(pi); + } select (pi); emitShowSelection(); } @@ -4074,8 +4093,9 @@ } setExportMode (true); - QPixmap pix (mapEditor->getPixmap()); - pix.save(fname, format); + mapEditor->getScene()->update(); // FIXME-2 check this... + QImage img (mapEditor->getImage()); //FIXME-2 calls getTotalBBox, but also in ExportHTML::doExport() + img.save(fname, format); setExportMode (false); } @@ -4167,6 +4187,62 @@ } } +void VymModel::exportHTML (const QString &dir, bool askForName) +{ + ExportXHTMLDialog dia(NULL); + dia.setFilePath (filePath ); + dia.setMapName (mapName ); + dia.readSettings(); + if (dir!="") dia.setDir (dir); + + bool ok=true; + + /* + if (askForName) + { + if (dia.exec()!=QDialog::Accepted) + ok=false; + else + { + QDir d (dia.getDir()); + // Check, if warnings should be used before overwriting + // the output directory + if (d.exists() && d.count()>0) + { + WarningDialog warn; + warn.showCancelButton (true); + warn.setText(QString( + "The directory %1 is not empty.\n" + "Do you risk to overwrite some of its contents?").arg(d.path() )); + warn.setCaption("Warning: Directory not empty"); + warn.setShowAgainName("mainwindow/overwrite-dir-xhtml"); + + if (warn.exec()!=QDialog::Accepted) ok=false; + } + } + } +*/ + ok=true; + if (ok) + { + // Hide stuff during export, if settings want this + setExportMode (true); + + ExportHTML ex (this); + ex.setFile ("x/xxx.html"); + ex.doExport(); + setExportMode (false); + + //exportXML (dia.getDir(),false ); + //dia.doExport(mapName ); + //if (dia.hasChanged()) setChanged(); + + // Write image, too + exportImage ("x/xxx.png",false,"PNG"); + + } +} + void VymModel::exportXHTML (const QString &dir, bool askForName) { ExportXHTMLDialog dia(NULL); @@ -4795,10 +4871,13 @@ void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode) { hidemode=mode; - for (int i=0;ichildCount();i++) - rootItem->child(i)->setHideTmp (mode); + for (int i=0;ibranchCount();i++) + rootItem->getBranchNum(i)->setHideTmp (mode); reposition(); - // FIXME-3 needed? scene()->update(); + if (mode==TreeItem::HideExport) + unselect(); + else + reselect(); } ////////////////////////////////////////////// diff -r 25ee6b988b73 -r 8f987e376035 vymmodel.h --- a/vymmodel.h Tue Dec 15 09:14:59 2009 +0000 +++ b/vymmodel.h Mon Jan 04 20:36:06 2010 +0000 @@ -237,6 +237,7 @@ //////////////////////////////////////////// public: void setVersion(const QString &); + QString getVersion(); void setAuthor (const QString &); QString getAuthor (); void setComment (const QString &); @@ -316,6 +317,7 @@ XLinkItem* createXLink(BranchItem *dst,bool createMO=false); //!< Create XLink starting at dst AttributeItem* addAttribute(); + AttributeItem* addAttribute(AttributeItem* ); /*! \brief Add new mapcenter @@ -438,7 +440,8 @@ /*! Export as ASCII text to file */ void exportASCII (QString fname="",bool askForName=true); - /*! Export as XHTML to directory */ + /*! Export as HTML to directory */ + void exportHTML(const QString& dir="", bool askForName=true); void exportXHTML(const QString& dir="", bool askForName=true); /*! Export as OpenOfficeOrg presentation */