F:/KPlato/koffice/libs/kotext/styles/KoListStyle.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2006 Thomas Zander <zander@kde.org>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; version 2.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public License
00014  * along with this library; see the file COPYING.LIB.  If not, write to
00015  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  * Boston, MA 02110-1301, USA.
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) // remove old one
00068         block.textList()->remove(block);
00069     if(block.textList() == 0 && textList) // add if new
00070         textList->add(block);
00071     if(block.textList() && textList == 0) {
00072         textList = block.textList(); // missed it ?
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     // copy all relevant properties.
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()) { // invalidate the counter part
00106             KoTextBlockData *userData = dynamic_cast<KoTextBlockData*> (tb.userData());
00107             if(userData)
00108                 userData->setCounterWidth(-1.0);
00109         }
00110     }
00111     else { // does not exist yet, this is the first parag that uses it :)
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 // TODO; what did I invent m_textLists for?  Can it be removed?

Généré le Wed Nov 22 23:41:11 2006 pour KPlato par  doxygen 1.5.1-p1