00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "KoStyleManager.h"
00020 #include "KoParagraphStyle.h"
00021 #include "KoCharacterStyle.h"
00022 #include "ChangeFollower.h"
00023
00024 #include <QTimer>
00025 #include <kdebug.h>
00026 #include <klocale.h>
00027
00028 KoStyleManager::KoStyleManager(QObject *parent)
00029 : QObject(parent),
00030 m_updateTriggered(false)
00031 {
00032 m_standard = new KoParagraphStyle();
00033 m_standard->setLeftMargin(0);
00034 m_standard->setTopMargin(0);
00035 m_standard->setBottomMargin(0);
00036 m_standard->setRightMargin(0);
00037 m_standard->setTextIndent(0);
00038 m_standard->setIndent(0);
00039 m_standard->setAlignment(Qt::AlignLeft);
00040 m_standard->setName( i18n("[No Paragraph Style]"));
00041 add(m_standard);
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 }
00054
00055 void KoStyleManager::add(KoCharacterStyle *style) {
00056 if(m_charStyles.contains(style))
00057 return;
00058 style->setStyleId( s_stylesNumber++ );
00059 m_charStyles.append(style);
00060 }
00061
00062 void KoStyleManager::add(KoParagraphStyle *style) {
00063 if(m_paragStyles.contains(style))
00064 return;
00065 style->setStyleId( s_stylesNumber++ );
00066 m_paragStyles.append(style);
00067 if(style->characterStyle())
00068 add(style->characterStyle());
00069 }
00070
00071 void KoStyleManager::remove(KoCharacterStyle *style) {
00072 m_charStyles.removeAll(style);
00073 }
00074
00075 void KoStyleManager::remove(KoParagraphStyle *style) {
00076 m_paragStyles.removeAll(style);
00077 }
00078
00079 void KoStyleManager::remove(ChangeFollower *cf) {
00080 m_documentUpdaterProxies.removeAll(cf);
00081 }
00082
00083 void KoStyleManager::alteredStyle(const KoParagraphStyle *style) {
00084 Q_ASSERT(style);
00085 int id = style->styleId();
00086 if(id <= 0) {
00087 kWarning(32500) << "alteredStyle received from a non registered style!" << endl;
00088 return;
00089 }
00090 if(! m_updateQueue.contains(id))
00091 m_updateQueue.append(id);
00092 requestFireUpdate();
00093
00094
00095 foreach(KoParagraphStyle *ps, m_paragStyles) {
00096 if(ps->parent() == style)
00097 alteredStyle(ps);
00098 }
00099 }
00100
00101 void KoStyleManager::alteredStyle(const KoCharacterStyle *style) {
00102 Q_ASSERT(style);
00103 int id = style->styleId();
00104 if(id <= 0) {
00105 kWarning(32500) << "alteredStyle received from a non registered style!" << endl;
00106 return;
00107 }
00108 if(! m_updateQueue.contains(id))
00109 m_updateQueue.append(id);
00110 requestFireUpdate();
00111 }
00112
00113 void KoStyleManager::updateAlteredStyles() {
00114 foreach(ChangeFollower *cf, m_documentUpdaterProxies) {
00115 cf->processUpdates(m_updateQueue);
00116 }
00117 m_updateQueue.clear();
00118 m_updateTriggered = false;
00119 }
00120
00121 void KoStyleManager::requestFireUpdate() {
00122 if(m_updateTriggered)
00123 return;
00124 QTimer::singleShot(0, this, SLOT(updateAlteredStyles()));
00125 m_updateTriggered = true;
00126 }
00127
00128 void KoStyleManager::add(QTextDocument *document) {
00129 foreach(ChangeFollower *cf, m_documentUpdaterProxies) {
00130 if(cf->document() == document) {
00131 return;
00132 }
00133 }
00134 ChangeFollower *cf = new ChangeFollower(document, this);
00135 m_documentUpdaterProxies.append(cf);
00136 }
00137
00138 void KoStyleManager::remove(QTextDocument *document) {
00139 foreach(ChangeFollower *cf, m_documentUpdaterProxies) {
00140 if(cf->document() == document) {
00141 m_documentUpdaterProxies.removeAll(cf);
00142 return;
00143 }
00144 }
00145 }
00146
00147 KoCharacterStyle *KoStyleManager::characterStyle(int id) const {
00148 foreach(KoCharacterStyle *style, m_charStyles) {
00149 if(style->styleId() == id)
00150 return style;
00151 }
00152 return 0;
00153 }
00154
00155 KoParagraphStyle *KoStyleManager::paragraphStyle(int id) const {
00156 foreach(KoParagraphStyle *style, m_paragStyles) {
00157 if(style->styleId() == id)
00158 return style;
00159 }
00160 return 0;
00161 }
00162
00163 KoCharacterStyle *KoStyleManager::characterStyle(const QString &name) const {
00164 foreach(KoCharacterStyle *style, m_charStyles) {
00165 if(style->name() == name)
00166 return style;
00167 }
00168 return 0;
00169 }
00170
00171 KoParagraphStyle *KoStyleManager::paragraphStyle(const QString &name) const {
00172 foreach(KoParagraphStyle *style, m_paragStyles) {
00173 if(style->name() == name)
00174 return style;
00175 }
00176 return 0;
00177 }
00178
00179 KoParagraphStyle *KoStyleManager::defaultParagraphStyle() const {
00180 return m_standard;
00181 }
00182
00183
00184 int KoStyleManager::s_stylesNumber = 100;
00185
00186 #include "KoStyleManager.moc"