storytext.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef STORYTEXT_H_
00026 #define STORYTEXT_H_
00027
00028 #include <QObject>
00029 #include <QString>
00030 #include <QList>
00031 #include <cassert>
00032
00033
00034 #include "text/frect.h"
00035 #include "text/specialchars.h"
00036 #include "sctextstruct.h"
00037 #include "style.h"
00038 #include "styles/charstyle.h"
00039 #include "styles/paragraphstyle.h"
00040 #include "desaxe/saxio.h"
00041
00042 #ifdef NLS_CONFORMANCE
00043 #define NLS_PRIVATE private
00044 #else
00045 #define NLS_PRIVATE public
00046 #endif
00047
00048 class CharStyle;
00049 class ParagraphStyle;
00050 class PageItem;
00051
00052
00053 class ScribusDoc;
00054 class ScText_Shared;
00055 class ResourceCollection;
00056
00057
00058 struct LineSpec
00059 {
00060 double x;
00061 double y;
00062 double width;
00063 double ascent;
00064 double descent;
00065
00066 int firstItem;
00067 int lastItem;
00068 double naturalWidth;
00069 };
00070
00087 class SCRIBUS_API StoryText : public QObject, public SaxIO
00088 {
00089 Q_OBJECT
00090
00091 public:
00092 StoryText(ScribusDoc * doc);
00093 StoryText();
00094 StoryText(const StoryText & other);
00095 StoryText& operator= (const StoryText & other);
00096 virtual ~StoryText();
00097
00098 static const Xml_string saxxDefaultElem;
00099 static void desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
00100
00101 virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
00102 virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
00103
00104 void clear();
00105 StoryText copy() const;
00106 void insert(int pos, const StoryText& other, bool onlySelection = false);
00107 void append(const StoryText& other) { insert(length(), other, false); }
00108 void removeChars(int pos, uint len);
00109 void insertChars(int pos, QString txt, bool applyNeighbourStyle = false);
00110 void insertObject(int pos, PageItem* obj);
00111 void replaceChar(int pos, QChar ch);
00112
00113 void hyphenateWord(int pos, uint len, char* hyphens);
00114
00115 int length() const;
00116 QChar text(int pos) const;
00117 QString text(int pos, uint len) const;
00118 PageItem* object(int pos) const;
00119
00120 int nextCharPos(int c);
00121 int prevCharPos(int c);
00122 int nextWordPos(int c);
00123 int prevWordPos(int c);
00124 int nextLinePos(int c, double oldX);
00125 int prevLinePos(int c, double oldX);
00126 int nextFramePos(int c);
00127 int prevFramePos(int c);
00128
00129 const CharStyle& charStyle(int pos) const;
00130 const ParagraphStyle& paragraphStyle(int pos) const;
00131 const ParagraphStyle& defaultStyle() const;
00132 void setDefaultStyle(const ParagraphStyle& style);
00133 void setCharStyle(int pos, uint len, const CharStyle& style);
00134 void setStyle(int pos, const ParagraphStyle& style);
00135 void applyCharStyle(int pos, uint len, const CharStyle& style);
00136 void applyStyle(int pos, const ParagraphStyle& style);
00137 void eraseCharStyle(int pos, uint len, const CharStyle& style);
00138 void eraseStyle(int pos, const ParagraphStyle& style);
00139 void replaceStyles(QMap<QString,QString> newNameForOld);
00140 void replaceCharStyles(QMap<QString,QString> newNameForOld);
00141
00142 void getNamedResources(ResourceCollection& lists) const;
00143 void replaceNamedResources(ResourceCollection& newNames);
00144
00145 uint nrOfParagraphs() const;
00146 int startOfParagraph(uint index) const;
00147 int endOfParagraph(uint index) const;
00148 int nrOfParagraph(uint index) const;
00149
00150 uint nrOfRuns() const;
00151 int startOfRun(uint index) const;
00152 int endOfRun(uint index) const;
00153
00154
00155 int nextChar(int pos);
00156 int prevChar(int pos);
00157 int nextWord(int pos);
00158 int prevWord(int pos);
00159 int nextSentence(int pos);
00160 int prevSentence(int pos);
00161 int nextParagraph(int pos);
00162 int prevParagraph(int pos);
00163
00164
00165
00166 int startOfLine(int pos);
00167 int endOfLine(int pos);
00168 int prevLine(int pos);
00169 int nextLine(int pos);
00170 int startOfFrame(int pos);
00171 int endOfFrame(int pos);
00172
00173
00174
00175 void selectAll();
00176 void deselectAll();
00177 void removeSelection();
00178 void select(int pos, uint len, bool on = true);
00179 bool selected(int pos) const;
00180 int startOfSelection() const;
00181 int endOfSelection() const;
00182 int lengthOfSelection() const;
00183
00184
00185
00186
00188 void invalidateObject(const PageItem* embedded);
00190 void invalidateLayout();
00191
00192 public slots:
00194 void invalidateAll();
00195
00196
00197
00198 public:
00199
00200
00201 bool overflows() const;
00203 int layout(int startItem);
00204 uint nrOfItems() const;
00205
00206 ScText * item(uint index);
00207 const ScText * item(uint index) const;
00208 public:
00209 ScText * item_p(uint index) { return item(index); }
00210
00212 const QString itemText(uint index) const;
00214 const CharStyle itemStyle(uint index) const;
00216 int startOfItem(uint index) const;
00218 int endOfItem(uint index) const;
00219
00220
00221
00222
00223
00224 int screenToPosition(FPoint coord) const;
00225 FRect boundingBox(int pos, uint len = 1) const;
00226
00227 uint lines() const { return (uint) m_lines.count(); }
00228
00229 LineSpec line(uint i) const { return m_lines[i]; }
00230
00231 void appendLine(const LineSpec& ls)
00232 {
00233 assert( ls.firstItem >= 0 );
00234 assert( ls.firstItem < length() );
00235 assert( ls.lastItem >= 0 && ls.firstItem - ls.lastItem < 1 );
00236 assert( ls.lastItem < length() );
00237 m_lines.append(ls);
00238 if (lastFrameItem < firstFrameItem) {
00239 firstFrameItem = ls.firstItem;
00240 lastFrameItem = ls.lastItem;
00241 }
00242 else {
00243 firstFrameItem = qMin(firstFrameItem, ls.firstItem);
00244 lastFrameItem = qMax(lastFrameItem, ls.lastItem);
00245 }
00246 }
00247
00248 void clearLines()
00249 {
00250 m_lines.clear();
00251 firstFrameItem = 0;
00252 lastFrameItem = -1;
00253 }
00254
00255 int firstInFrame() { return firstFrameItem; }
00256 int lastInFrame() { return lastFrameItem; }
00257
00258 private:
00259 ScribusDoc * doc;
00260 int selFirst, selLast;
00261 int firstFrameItem, lastFrameItem;
00262 QList<LineSpec> m_lines;
00263 bool m_validLayout;
00264 double m_magicX;
00265 int m_lastMagicPos;
00266
00268 void invalidate(int firstRun, int lastRun);
00269 void removeParSep(int pos);
00270 void insertParSep(int pos);
00271
00272
00273
00277
00279 ScText_Shared * d;
00281
00283
00284 };
00285
00286
00287 #endif