00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "ChangeFollower.h"
00020 #include "KoCharacterStyle.h"
00021 #include "KoParagraphStyle.h"
00022
00023 #include <QVector>
00024 #include <QTextDocument>
00025 #include <QTextCursor>
00026 #include <QTextBlock>
00027 #include <kdebug.h>
00028
00029 ChangeFollower::ChangeFollower(QTextDocument *parent, KoStyleManager *manager)
00030 : QObject(parent),
00031 m_document(parent),
00032 m_styleManager(manager)
00033 {
00034 }
00035
00036 ChangeFollower::~ChangeFollower() {
00037 if(m_styleManager)
00038 m_styleManager->remove(this);
00039 }
00040
00041 void ChangeFollower::processUpdates(const QList<int> &changedStyles) {
00042 if(m_styleManager == 0) {
00043
00044
00045 deleteLater();
00046 return;
00047 }
00048
00049 QTextCursor cursor (m_document);
00050 QTextBlock block = cursor.block();
00051 while(block.isValid()) {
00052 QTextBlockFormat bf = block.blockFormat();
00053 int id = bf.intProperty(KoParagraphStyle::StyleId);
00054 if(id > 0 && changedStyles.contains(id)) {
00055 cursor.setPosition( block.position() );
00056 KoParagraphStyle *style = m_styleManager->paragraphStyle(id);
00057 Q_ASSERT(style);
00058
00059 style->applyStyle(bf);
00060 cursor.setBlockFormat(bf);
00061 }
00062 QTextBlock::iterator iter = block.begin();
00063 while(! iter.atEnd()) {
00064 QTextFragment fragment = iter.fragment();
00065 QTextCharFormat cf = fragment.charFormat();
00066 id = cf.intProperty(KoCharacterStyle::StyleId);
00067 if(id > 0 && changedStyles.contains(id)) {
00068
00069 cursor.setPosition(block.position() + fragment.position());
00070 cursor.setPosition(block.position() + fragment.position() +
00071 fragment.length(), QTextCursor::KeepAnchor);
00072 KoCharacterStyle *style = m_styleManager->characterStyle(id);
00073 Q_ASSERT(style);
00074
00075 style->applyStyle(cf);
00076 cursor.mergeCharFormat(cf);
00077 }
00078 iter++;
00079 }
00080 block = block.next();
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 }