summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-04-03 17:29:06 +0200
committerArno <am@disconnect.de>2012-04-03 17:29:06 +0200
commit5bf304d22564666621c35919b2d9aea1aa5b4b5a (patch)
treef63dd73a9c0ce4aeaeb2ca8af084075ea00638da
parent3405dbb9a1b6601bf7c343d676a4abe4e5981a29 (diff)
downloadSheMov-5bf304d22564666621c35919b2d9aea1aa5b4b5a.tar.gz
SheMov-5bf304d22564666621c35919b2d9aea1aa5b4b5a.tar.bz2
SheMov-5bf304d22564666621c35919b2d9aea1aa5b4b5a.zip
Finally fix MappingItem
Well, the comment was right. The previous implementation was fishy at best. It simply didn't work. Could have been so ease. Just look at the commit size :) Don't forget that there will be an empty line at the beginning of the QTextDocument if you don't check the first insert.
-rw-r--r--pictureviewer2.cpp47
-rw-r--r--pictureviewer2.h2
2 files changed, 17 insertions, 32 deletions
diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp
index 848fd00..8aef518 100644
--- a/pictureviewer2.cpp
+++ b/pictureviewer2.cpp
@@ -20,7 +20,6 @@
#include <QSettings>
#include <QTextDocument>
#include <QTextCursor>
-#include <QTextList>
#include "pictureviewer2.h"
#include "pictureswidget.h"
@@ -284,42 +283,28 @@ void PictureViewer2::setGradient(const QPixmap &pic){
QTextDocument *PictureViewer2::treeToString(const SmTreeItem *root) const{
QTextDocument *retval = new QTextDocument;
- retval->setIndentWidth(1);
+ retval->setIndentWidth(2);
retval->setDocumentMargin(8);
QTextCursor *cursor = new QTextCursor(retval);
- QTextListFormat listFormat;
- listFormat.setStyle(QTextListFormat::ListDisc);
- listFormat.setIndent(10);
- for(int i = 0 ; i < root->childCount(); ++i){
- cursor->createList(listFormat);
- cursor->insertText(root->child(i)->data(0).toString());
- treeToStringRecursive(root->child(i), cursor);
- }
+ treeToStringRecursive(root, cursor, 0);
return retval;
}
-void PictureViewer2::treeToStringRecursive(const SmTreeItem *parent, QTextCursor *cursor) const{
- //hell, this kinda does what it's supposed to, but it seems fishy...
- //don't like the break and checking the parent...
- for(int i = 0 ; i < parent->childCount(); ++i){
- QTextListFormat listFormat;
- listFormat.setStyle(QTextListFormat::ListDisc);
- listFormat.setIndent(cursor->currentList()->format().indent() + 5);
+void PictureViewer2::treeToStringRecursive(const SmTreeItem *parent, QTextCursor *cursor, int indent) const{
+ for(int i = 0; i < parent->childCount(); ++i){
+ QTextBlockFormat fmt;
+ fmt.setIndent(indent * 5);
+ //to prevent a stupid empty line with a <br />...
+ if(indent > 0){
+ cursor->insertBlock(fmt);
+ }
+ QChar bullet(0x2640);
+ if(indent % 2){
+ bullet = QChar(0x2642);
+ }
+ cursor->insertText(QString("%1 %2").arg(bullet).arg(parent->child(i)->data(0).toString()));
if(parent->child(i)->childCount()){
- cursor->insertList(listFormat);
- cursor->insertText(parent->child(i)->data(0).toString());
- treeToStringRecursive(parent->child(i), cursor);
- return;
- }else{
- const SmTreeItem *p = parent;
- cursor->insertList(listFormat);
- for(int j = 0; j < p->childCount(); ++j){
- if(j != 0){
- cursor->insertBlock();
- }
- cursor->insertText(p->child(j)->data(0).toString());
- }
- break;
+ treeToStringRecursive(parent->child(i), cursor, indent + 1);
}
}
}
diff --git a/pictureviewer2.h b/pictureviewer2.h
index c776c53..4b5915d 100644
--- a/pictureviewer2.h
+++ b/pictureviewer2.h
@@ -62,7 +62,7 @@ class PictureViewer2 : public QGraphicsView {
void setupDialog();
void setGradient(const QPixmap &pic);
QTextDocument *treeToString(const SmTreeItem *root) const;
- void treeToStringRecursive(const SmTreeItem *parent, QTextCursor *cursor) const;
+ void treeToStringRecursive(const SmTreeItem *parent, QTextCursor *cursor, int indent) const;
QPointF getPos(PictureViewer2Item *item, int pos, const QPointF &movPos);
QString constructWindowTitle() const;
PicDataList mFiles;