summaryrefslogtreecommitdiffstats
path: root/pictureviewer2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pictureviewer2.cpp')
-rw-r--r--pictureviewer2.cpp47
1 files changed, 16 insertions, 31 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);
}
}
}