# HG changeset patch # User insilmaril # Date 1249555337 0 # Node ID 6269016c99058eb6ef5223ca8f02fac149c1b713 # Parent 5987f9f15bac8134fa02895ca7977b1ab4dfd427 First changes to allow attributes diff -r 5987f9f15bac -r 6269016c9905 branchitem.cpp --- a/branchitem.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/branchitem.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -372,7 +372,7 @@ return (BranchObj*)lmo; } -BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) +BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) // FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel? { BranchObj *newbo; newbo=new BranchObj(scene); diff -r 5987f9f15bac -r 6269016c9905 branchobj.cpp --- a/branchobj.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/branchobj.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -127,7 +127,7 @@ if (!parObjTmpBuf) parObjTmpBuf=parObj; - // ignore mapcenter and mainbranch + // ignore mapcenter and mainbranch //FIXME-3 MCO meanwhile also could be relinked if (pi_depth<2) off=0; if (off==0) link2ParPos=false; @@ -135,17 +135,17 @@ link2ParPos=true; parObj=o; - // FIXME-2 depth=parObj->getDepth()+1; - // setLinkStyle calls updateLinkGeometry, only set it once - if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle()); + //LinkableMapObj::Style ls=getDefLinkStyle (lmo->getTreeItem() ); + //if (style!=ls ) setLinkStyle (ls); + setLinkStyle (lmo->getDefLinkStyle (lmo->getTreeItem())); // Move temporary to new position at destination // Usually the positioning would be done by reposition(), // but then also the destination branch would "Jump" around... // Better just do it approximately - if (treeItem->depth()==1) // FIXME-3 needed to recursively calc depth? - { // new parent is the mapcenter itself + if (parObj->getTreeItem()->depth()==0) + { // new parent is a mapcenter QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(), m.y() - o->getChildPos().y() )); @@ -192,8 +192,7 @@ link2ParPos=false; parObj=parObjTmpBuf; parObjTmpBuf=NULL; - //FIXME-2 depth=parObj->getDepth()+1; - setLinkStyle (getDefLinkStyle() ); + setLinkStyle (getDefLinkStyle(treeItem->parent() ) ); updateLinkGeometry(); } } @@ -588,9 +587,8 @@ case 1: fontsize=12; break; default: fontsize=10; break; } - + setLinkStyle(getDefLinkStyle(treeItem->parent() )); setLinkColor (); - setLinkStyle(getDefLinkStyle()); QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0"); font.setPointSize(fontsize); heading->setFont(font ); diff -r 5987f9f15bac -r 6269016c9905 linkablemapobj.cpp --- a/linkablemapobj.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/linkablemapobj.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -176,7 +176,7 @@ return rightPad; } -LinkableMapObj::Style LinkableMapObj::getDefLinkStyle () +LinkableMapObj::Style LinkableMapObj::getDefLinkStyle (TreeItem *parent) { VymModel *model=treeItem->getModel(); if (!model) @@ -185,7 +185,7 @@ //return UndefinedStyle; } Style ls=model->getMapLinkStyle(); - int depth=treeItem->depth(); + int depth=1+parent->depth(); if (depth==0) return UndefinedStyle; switch (ls) { @@ -215,7 +215,7 @@ void LinkableMapObj::setLinkStyle(Style newstyle) { - //if (newstyle=style) return; FIXME-3 + //if (newstyle==style) return; FIXME-3 delLink(); style=newstyle; diff -r 5987f9f15bac -r 6269016c9905 linkablemapobj.h --- a/linkablemapobj.h Mon Aug 03 10:42:12 2009 +0000 +++ b/linkablemapobj.h Thu Aug 06 10:42:17 2009 +0000 @@ -74,7 +74,7 @@ virtual qreal getTopPad(); virtual qreal getLeftPad(); virtual qreal getRightPad(); - Style getDefLinkStyle(); + Style getDefLinkStyle(TreeItem *parent); void setLinkStyle(Style); Style getLinkStyle(); diff -r 5987f9f15bac -r 6269016c9905 mainwindow.cpp --- a/mainwindow.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/mainwindow.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -549,6 +549,15 @@ connect( a, SIGNAL( triggered() ), this, SLOT( editDeleteSelection() ) ); actionDelete=a; + // Shortcut to add attribute + a= new QAction(tr( "Add attribute" ), this); + a->setShortcut ( Qt::Key_Q); + a->setShortcutContext (Qt::WindowShortcut); + addAction (a); + connect( a, SIGNAL( triggered() ), this, SLOT( editAddAttribute() ) ); + actionAddAttribute= a; + + // Shortcut to add mapcenter a= new QAction(QPixmap(iconPath+"newmapcenter.png"),tr( "Add mapcenter","Canvas context menu" ), this); a->setShortcut ( Qt::Key_M); @@ -2757,6 +2766,12 @@ if (m) m->unscrollChildren(); } +void Main::editAddAttribute() +{ + VymModel *m=currentModel(); + if (m) m->addAttribute(); +} + void Main::editAddMapCenter() { VymModel *m=currentModel(); diff -r 5987f9f15bac -r 6269016c9905 mainwindow.h --- a/mainwindow.h Mon Aug 03 10:42:12 2009 +0000 +++ b/mainwindow.h Thu Aug 06 10:42:17 2009 +0000 @@ -147,6 +147,7 @@ void editToggleScroll(); void editExpandAll(); void editUnscrollChildren(); + void editAddAttribute(); void editAddMapCenter(); void editNewBranch(); void editNewBranchBefore(); @@ -295,7 +296,7 @@ QAction *actionMapInfo; QAction *actionHeading; QAction *actionDelete; - + QAction *actionAddAttribute; public: QAction *actionAddMapCenter; diff -r 5987f9f15bac -r 6269016c9905 mapeditor.cpp --- a/mapeditor.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/mapeditor.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -1310,16 +1310,25 @@ // is not yet implemented elsewhere // Here in MapEditor we can only select Branches and Images + QList treeItemsNew; + QList treeItemsOld; + QModelIndex ix; foreach (ix,newsel.indexes() ) { TreeItem *ti= static_cast(ix.internalPointer()); - if (ti->getType()!=TreeItem::Branch && ti->getType()!=TreeItem::Image ) - newsel.indexes().removeOne (ix); + if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image ) + if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti); + } + foreach (ix,oldsel.indexes() ) + { + TreeItem *ti= static_cast(ix.internalPointer()); + if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::Image ) + if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti); } // Trim list of selection rectangles - while (newsel.indexes().count() < selboxList.count() ) + while (treeItemsNew.count() < selboxList.count() ) delete selboxList.takeFirst(); // Take care to tmp scroll/unscroll @@ -1344,7 +1353,7 @@ } } - if (!newsel.isEmpty()) + if (!treeItemsNew.isEmpty()) { QModelIndex ix=newsel.indexes().first(); if (ix.isValid() ) @@ -1365,12 +1374,12 @@ } // Reduce rectangles - while (newsel.indexes().count() < selboxList.count() ) + while (treeItemsNew.count() < selboxList.count() ) delete selboxList.takeFirst(); // Add additonal rectangles QGraphicsRectItem *sb; - while (newsel.indexes().count() > selboxList.count() ) + while (treeItemsNew.count() > selboxList.count() ) { sb = mapScene->addRect( QRectF(0,0,0,0), @@ -1381,19 +1390,18 @@ selboxList.append (sb); } + + // Reposition rectangles - int i=0; QRectF bbox; QModelIndex index; - TreeItem *ti; LinkableMapObj *lmo; - foreach (sb,selboxList) + for (int i=0; i(index.internalPointer()); - lmo=((MapItem*)ti)->getLMO(); + lmo=((MapItem*)treeItemsNew.at(i) )->getLMO(); bbox=lmo->getBBox(); + sb=selboxList.at(i); sb->setRect ( bbox.x(),bbox.y(), bbox.width(), bbox.height()); diff -r 5987f9f15bac -r 6269016c9905 tex/vym.tex --- a/tex/vym.tex Mon Aug 03 10:42:12 2009 +0000 +++ b/tex/vym.tex Thu Aug 06 10:42:17 2009 +0000 @@ -663,10 +663,11 @@ \subsection{RichText: Colours, paragraphs and formatted text} \vym supports formatted text (QT Rich Text) in the noteeditor since version 1.4.7. Colours and text attributes (e.g. italic, bold) can be -set with the buttons above the text. The text itself is divided into -paragraphs. For each paragraph the format can be set (e.g. centered, -right). A paragraph is ended when a \key{Return} is entered. If you just -want to begin a new line, press \key{CTRL-Return}. +set with the buttons above the text. +%The text itself is divided into +%paragraphs. For each paragraph the format can be set (e.g. centered, +%right). A paragraph is ended when a \key{Return} is entered. If you just +%want to begin a new line, press \key{CTRL-Return}. \subsection{Fonts and how to switch them quickly} The noteeditor is designed to be used for simple notes, not really as a full diff -r 5987f9f15bac -r 6269016c9905 treeitem.cpp --- a/treeitem.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/treeitem.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -72,8 +72,11 @@ imageOffset=0; imageCounter=0; + attributeCounter=0; + attributeOffset=0; + note.setNote(""); - // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-2 + // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-3 // isNoteInEditor=false; hidden=false; @@ -87,7 +90,7 @@ /* -void TreeItem::copy (OrnamentedObj* other) //FIXME-2 probably need deep copy of branches and data! +void TreeItem::copy (OrnamentedObj* other) //FIXME-3 probably need deep copy of branches and data! { note.copy (other->note); @@ -111,9 +114,10 @@ { switch (item->type) { + case Attribute: return attributeOffset + attributeCounter; + case Image: return imageOffset + imageCounter; case MapCenter: return branchOffset + branchCounter; case Branch: return branchOffset + branchCounter; - case Image: return imageOffset + imageCounter; default: return -1; } } @@ -124,12 +128,18 @@ item->rootItem=rootItem; item->setModel (model); + if (item->type == Attribute) + { + // attribute are on top of list + childItems.insert (attributeCounter,item); + attributeCounter++; + imageOffset++; + branchOffset++; + } + if (item->type == Image) { - childItems.insert (imageCounter,item); - // images are on top of list - if (imageCounter==0) - imageOffset=0; + childItems.insert (imageCounter+imageOffset,item); imageCounter++; branchOffset++; } @@ -138,8 +148,6 @@ { // branches are on bottom of list childItems.append(item); - if (branchCounter==0) - branchOffset=childItems.count()-1; branchCounter++; } } @@ -150,14 +158,20 @@ qWarning ("TreeItem::removeChild tried to remove non existing item?!\n"); else { - if (childItems.at(row)->isBranchLikeType()) - branchCounter--; + if (childItems.at(row)->type==Attribute) + { + attributeCounter--; + imageOffset--; + branchOffset--; + } if (childItems.at(row)->type==Image) { imageCounter--; - if (branchOffset>0) - branchOffset--; + branchOffset--; } + if (childItems.at(row)->isBranchLikeType()) + branchCounter--; + childItems.removeAt (row); } } @@ -210,6 +224,11 @@ return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated... } +int TreeItem::attributeCount() const +{ + return attributeCounter; +} + int TreeItem::row() const { if (parentItem) diff -r 5987f9f15bac -r 6269016c9905 treeitem.h --- a/treeitem.h Mon Aug 03 10:42:12 2009 +0000 +++ b/treeitem.h Thu Aug 06 10:42:17 2009 +0000 @@ -20,7 +20,7 @@ class TreeItem:public XMLObj { public: - enum Type {Undefined,MapCenter,Branch,Image}; //FIXME-3 MapCenter still needed? + enum Type {Undefined,MapCenter,Branch,Image,Attribute}; //FIXME-3 MapCenter still needed? enum HideTmpMode {HideNone, HideExport}; TreeItem(); @@ -48,6 +48,7 @@ virtual int branchCount() const; virtual int imageCount() const; virtual int xlinkCount() const; + virtual int attributeCount() const; virtual int row() const; virtual int column() const; @@ -130,7 +131,6 @@ virtual QStringList activeSystemFlagNames(); - virtual bool canMoveDown(); virtual bool canMoveUp(); @@ -187,6 +187,9 @@ int imageOffset; int imageCounter; + int attributeOffset; + int attributeCounter; + bool hidden; //! Hidden in export if true }; diff -r 5987f9f15bac -r 6269016c9905 vym.pro --- a/vym.pro Mon Aug 03 10:42:12 2009 +0000 +++ b/vym.pro Thu Aug 06 10:42:17 2009 +0000 @@ -35,6 +35,7 @@ adaptormodel.h \ animpoint.h \ attribute.h \ + attributeitem.h \ # attributedelegate.h\ # attributedialog.h \ # attributewidget.h \ @@ -96,6 +97,7 @@ adaptormodel.cpp \ animpoint.cpp \ attribute.cpp \ + attributeitem.cpp \ # attributedelegate.cpp \ # attributedialog.cpp \ # attributewidget.cpp \ diff -r 5987f9f15bac -r 6269016c9905 vymmodel.cpp --- a/vymmodel.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/vymmodel.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -3,6 +3,7 @@ #include "vymmodel.h" +#include "attributeitem.h" #include "treeitem.h" #include "branchitem.h" #include "editxlinkdialog.h" @@ -126,8 +127,8 @@ findPrevious=NULL; EOFind=false; - // animations - animationUse=settings.readBoolEntry("/animation/use",false); + // animations // FIXME-3 switch to new animation system + animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated animationTicks=settings.readNumEntry("/animation/ticks",10); animationInterval=settings.readNumEntry("/animation/interval",50); animObjList.clear(); @@ -1982,6 +1983,33 @@ return NULL; } +AttributeItem* VymModel::addAttribute() +{ + cout << "VM::addAttribute\n"; + + TreeItem *selti=getSelectedItem(); + if (selti) + { + QList cData; + cData << "new attribute" << "undef"<<"undef"; + AttributeItem *a=new AttributeItem (cData); + + emit (layoutAboutToBeChanged() ); + + QModelIndex parix=index(selti); + int n=selti->getRowNumAppend (a); + beginInsertRows (parix,n,n+1); + selti->appendChild (a); + endInsertRows (); + + emit (layoutChanged() ); + + reposition(); + return a; + } + return NULL; +} + BranchItem* VymModel::addMapCenter () { BranchItem *bi=addMapCenter (contextPos); @@ -4056,7 +4084,7 @@ while (cur) { bo=(BranchObj*)(cur->getLMO() ); - bo->setLinkStyle(bo->getDefLinkStyle()); + bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View cur=next(cur,prev); } reposition(); diff -r 5987f9f15bac -r 6269016c9905 vymmodel.h --- a/vymmodel.h Mon Aug 03 10:42:12 2009 +0000 +++ b/vymmodel.h Thu Aug 06 10:42:17 2009 +0000 @@ -15,6 +15,7 @@ #include "treeitem.h" #include "treemodel.h" +class AttributeItem; class BranchItem; class MapEditor; @@ -290,6 +291,8 @@ BranchItem* createBranch(BranchItem *dst); //!< Create Branch ImageItem* createImage(BranchItem *dst); //!< Create image + AttributeItem* addAttribute(); + /*! \brief Add new mapcenter Disclaimer: Still experimental, not fully supported yet. diff -r 5987f9f15bac -r 6269016c9905 xml-vym.cpp --- a/xml-vym.cpp Mon Aug 03 10:42:12 2009 +0000 +++ b/xml-vym.cpp Thu Aug 06 10:42:17 2009 +0000 @@ -366,7 +366,7 @@ lastBranch->toggleScroll(); // (interesting for import of KDE bookmarks) -/* if (!a.value( "frameType").isEmpty() ) FIXME-2 +/* if (!a.value( "frameType").isEmpty() ) FIXME-3 lastOO->setFrameType (a.value("frameType")); //Compatibility 1.8.1 */