00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "KoListStyle.h"
00020 #include "Styles_p.h"
00021 #include "KoTextBlockData.h"
00022
00023 #include <QTextBlock>
00024 #include <QTextCursor>
00025
00026 KoListStyle::KoListStyle() {
00027 m_refCount = 0;
00028 m_stylesPrivate = new StylePrivate();
00029 setStyle(DiscItem);
00030 setStartValue(1);
00031 }
00032
00033 KoListStyle::KoListStyle(const KoListStyle &orig) {
00034 m_refCount = 0;
00035 m_stylesPrivate = new StylePrivate();
00036 m_stylesPrivate->copyMissing(orig.m_stylesPrivate);
00037 m_name = orig.name();
00038 }
00039
00040 void KoListStyle::setProperty(int key, const QVariant &value) {
00041 m_stylesPrivate->add(key, value);
00042 }
00043
00044 int KoListStyle::propertyInt(int key) const {
00045 const QVariant *variant = m_stylesPrivate->get(key);
00046 if(variant == 0)
00047 return 0;
00048 return variant->toInt();
00049 }
00050
00051 bool KoListStyle::propertyBoolean(int key) const {
00052 const QVariant *variant = m_stylesPrivate->get(key);
00053 if(variant == 0)
00054 return false;
00055 return variant->toBool();
00056 }
00057
00058 QString KoListStyle::propertyString(int key) const {
00059 const QVariant *variant = m_stylesPrivate->get(key);
00060 if(variant == 0)
00061 return QString();
00062 return qvariant_cast<QString>(variant);
00063 }
00064
00065 void KoListStyle::applyStyle(const QTextBlock &block) {
00066 QTextList *textList = m_textLists.value(block.document());
00067 if(textList && block.textList() && block.textList() != textList)
00068 block.textList()->remove(block);
00069 if(block.textList() == 0 && textList)
00070 textList->add(block);
00071 if(block.textList() && textList == 0) {
00072 textList = block.textList();
00073 m_textLists.insert(block.document(), QPointer<QTextList>(textList));
00074 }
00075
00076 QTextListFormat format;
00077 if(block.textList())
00078 format = block.textList()->format();
00079
00080
00081 static const int properties[] = {
00082 QTextListFormat::ListStyle,
00083 ListItemPrefix,
00084 ListItemSuffix,
00085 ConsecutiveNumbering,
00086 StartValue,
00087 Level,
00088 DisplayLevel,
00089 CharacterStyleId,
00090 BulletCharacter,
00091 BulletSize,
00092 -1
00093 };
00094
00095 int i=0;
00096 while(properties[i] != -1) {
00097 QVariant const *variant = m_stylesPrivate->get(properties[i]);
00098 if(variant) format.setProperty(properties[i], *variant);
00099 i++;
00100 }
00101
00102 if(textList) {
00103 textList->setFormat(format);
00104 QTextBlock tb = textList->item(0);
00105 if(tb.isValid()) {
00106 KoTextBlockData *userData = dynamic_cast<KoTextBlockData*> (tb.userData());
00107 if(userData)
00108 userData->setCounterWidth(-1.0);
00109 }
00110 }
00111 else {
00112 QTextCursor cursor(block);
00113 textList = cursor.createList(format);
00114 m_textLists.insert(block.document(), QPointer<QTextList>(textList));
00115 }
00116 }
00117
00118 void KoListStyle::apply(const KoListStyle &other) {
00119 m_name = other.name();
00120 m_stylesPrivate->clearAll();
00121 m_stylesPrivate->copyMissing(other.m_stylesPrivate);
00122 }
00123
00124