Warning, file /office/calligra/libs/textlayout/KoTextLayoutArea.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2011 C. Boemann <cbo@kogmbh.com>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef KOTEXTLAYOUTAREA_H
0021 #define KOTEXTLAYOUTAREA_H
0022 
0023 #include "kotextlayout_export.h"
0024 
0025 #include <KoText.h>
0026 #include <KoTextDocumentLayout.h>
0027 
0028 class KoTextBlockData;
0029 class KoInlineNote;
0030 class KoPointedAt;
0031 class KoParagraphStyle;
0032 class KoCharAreaInfo;
0033 
0034 class FrameIterator;
0035 
0036 class QTextList;
0037 class QRectF;
0038 
0039 /**
0040  * When layouting text the text is chopped up into physical area of space.
0041  *
0042  * Examples of such areas are:
0043  * <ul>
0044  *  <li>RootArea (corresponds to a text shape, or a spreadsheet cell)
0045  *  <li>TableArea (the kind of table that appears in text documents)
0046  *  <li>SectionArea, that splits text into columns
0047  * </ul>
0048  *
0049  * Each of these are implemented through subclasses, and this is just the interface.
0050  *
0051  * Layout happens until maximalAllowedY() is reached. That maximum may be set by
0052  * the RootArea, but it may also be set by, for example, a row in a table with
0053  * fixed height.
0054  */
0055 class KOTEXTLAYOUT_EXPORT KoTextLayoutArea
0056 {
0057 public:
0058     /// constructor
0059     explicit KoTextLayoutArea(KoTextLayoutArea *parent, KoTextDocumentLayout *documentLayout);
0060     virtual ~KoTextLayoutArea();
0061 
0062     /// Returns true if the area starts at the cursor position
0063     bool isStartingAt(FrameIterator *cursor) const;
0064 
0065     /**
0066      * These methods are deprecated since they lead to wrong assumptions.
0067      * Only use these methods after discussing with boemann. The problem
0068      * is related to tables (and paragraphs) split over more than one page,
0069      * in which case these methods just don't give correct or enough information.
0070      */
0071     Q_DECL_DEPRECATED QTextFrame::iterator startTextFrameIterator() const;
0072     Q_DECL_DEPRECATED QTextFrame::iterator endTextFrameIterator() const;
0073 
0074     /// Layouts as much as we can
0075     bool layout(FrameIterator *cursor);
0076 
0077     /// Returns the bounding rectangle in textdocument coordinates.
0078     QRectF boundingRect() const;
0079 
0080     virtual KoText::Direction parentTextDirection() const;
0081 
0082     KoTextLayoutArea *parent() const;
0083     KoTextDocumentLayout *documentLayout() const;
0084 
0085     /// Sets the left,right and top coordinate of the reference rect we place ourselves within
0086     /// The content may be smaller or bigger than that depending on our margins
0087     void setReferenceRect(qreal left, qreal right, qreal top, qreal maximumAllowedBottom);
0088 
0089     /// Returns the left,right,top and bottom coordinate of the reference rect.
0090     QRectF referenceRect() const;
0091 
0092     /// The left coordinate of the reference rect we place ourselves within
0093     /// The content may be smaller or bigger than that depending on our margins
0094     qreal left() const;
0095 
0096     /// The right coordinate of the reference rect we place ourselves within
0097     /// The content may be smaller or bigger than that depending on our margins
0098     qreal right() const;
0099 
0100     /// The top coordinate of the reference rect we place ourselves within
0101     /// The content may be smaller or bigger than that depending on our margins
0102     qreal top() const;
0103 
0104     /// The bottom coordinate of the reference rect we place ourselves within
0105     /// The content may be smaller or bigger than that depending on our margins
0106     /// bottom() can be used to place contents following this area
0107     qreal bottom() const;
0108 
0109     /// The maximum allowed bottom coordinate of the reference rect we place ourselves within
0110     /// The real bottom will be determined during layout
0111     qreal maximumAllowedBottom() const;
0112 
0113     FrameIterator *footNoteCursorToNext() const;
0114 
0115     KoInlineNote *continuedNoteToNext() const;
0116 
0117     int footNoteAutoCount() const;
0118 
0119     void setFootNoteCountInDoc(int count);
0120 
0121     void setFootNoteFromPrevious(FrameIterator *footNoteCursor, KoInlineNote *note);
0122 
0123     /// Sets the maximum allowed width before wrapping text.
0124     /// Setting this also indicates that we don't want wrapping.
0125     /// 0 means wrapping is allowed
0126     /// This has to be set before each layout(), and the layout() will change the reference rect
0127     /// right value to fit snugly (minimum the old right value) and so that no wrapping occurs up
0128     /// to maximumAllowedWidth
0129     void setNoWrap(qreal maximumAllowedWidth);
0130 
0131     /// Set if and how this area acts as a layout environment
0132     void setLayoutEnvironmentResctictions(bool isLayoutEnvironment, bool actsHorizontally);
0133 
0134     /// Returns the rect of the layout environment (see odf style:flow-with-text).
0135     QRectF layoutEnvironmentRect() const;
0136 
0137     qreal textIndent(const QTextBlock &block, QTextList *textList, const KoParagraphStyle &pStyle) const;
0138     void setExtraTextIndent(qreal extraTextIndent);
0139     qreal x() const;
0140     qreal width() const;
0141 
0142     /// Set if Area accepts page breaks, default is false;
0143     void setAcceptsPageBreak(bool accept);
0144 
0145     /// Areas that accept page breaks return true, default is false;
0146     bool acceptsPageBreak() const;
0147 
0148     /// Set if Area accepts column breaks, default is false;
0149     void setAcceptsColumnBreak(bool accept);
0150 
0151     /// Areas that accept column breaks return true, default is false;
0152     bool acceptsColumnBreak() const;
0153 
0154     /// Should be set to true when first starting layouting page
0155     /// Should be set to false when we add anything during layout
0156     void setVirginPage(bool virgin);
0157 
0158     /// returns true if we have not yet added anything to the page
0159     bool virginPage() const;
0160 
0161     /// Sets the amount the contents should be vertically offset due to any outside induced
0162     /// vertical alignment
0163     void setVerticalAlignOffset(qreal offset);
0164     qreal verticalAlignOffset() const;
0165 
0166     void paint(QPainter *painter, const KoTextDocumentLayout::PaintContext &context);
0167 
0168     KoPointedAt hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
0169 
0170     /// Calc a bounding box rect of the selection
0171     /// or invalid if not
0172     QRectF selectionBoundingBox(QTextCursor &cursor) const;
0173 
0174     static const int MaximumTabPos = 10000;
0175 
0176     /**
0177      * Returns a list of all the characters of the text rendered in this area
0178      * and the rectangles they cover from the point of view of text selection markup.
0179      * The rectangles are given in the coordinates the KoTextLayoutArea uses.
0180      * The list is generated on each call and not cached, so only call when needed.
0181      *
0182      * This method is specific to the needs of the plugins for Okular and should not
0183      * be interesting to other API consumers.
0184      *
0185      * Returns an empty list if layouting was not yet completed.
0186      */
0187     QVector<KoCharAreaInfo> generateCharAreaInfos() const;
0188 
0189 protected:
0190     void setBottom(qreal bottom);
0191 
0192     /// If this area has the responsibility to show footnotes then store
0193     /// it so it can later be in the m_pregisteredFootnotes
0194     /// returns the height of the foot note
0195     virtual qreal preregisterFootNote(KoInlineNote *note, qreal bottomOfText);
0196 
0197     /// Takes all preregistered footnotes and create Areas out of them
0198     void confirmFootNotes();
0199 
0200     /// Set the Left of the boundingRect to the min of what it was and x
0201     void expandBoundingLeft(qreal x);
0202 
0203     /// Set the Right of the boundingRect to the max of what it was and x
0204     void expandBoundingRight(qreal x);
0205 
0206 private:
0207     /// remove tables and paragraphs that are keep-with-next
0208     void backtrackKeepWithNext(FrameIterator *cursor);
0209 
0210     bool layoutBlock(FrameIterator *cursor);
0211 
0212     bool presentationListTabWorkaround(qreal indent, qreal labelBoxWidth, qreal presentationListTabValue);
0213 
0214     /// Returns vertical height of line
0215     qreal addLine(QTextLine &line, FrameIterator *cursor, KoTextBlockData &blockData);
0216 
0217     /// looks for footnotes and preregisters them
0218     void findFootNotes(const QTextBlock &block, const QTextLine &line, qreal bottomOfText);
0219 
0220     void clearPreregisteredFootNotes();
0221 
0222     void drawListItem(QPainter *painter, QTextBlock &block);
0223 
0224     void decorateParagraph(QPainter *painter, QTextBlock &block, bool showFormattingCharacter, bool showSpellChecking);
0225 
0226     void drawStrikeOuts(QPainter *painter, const QTextCharFormat &currentCharFormat, const QString &text, const QTextLine &line, qreal x1, qreal x2, const int startOfFragmentInBlock, const int fragmentToLineOffset) const;
0227 
0228     void drawOverlines(QPainter *painter, const QTextCharFormat &currentCharFormat, const QString &text, const QTextLine &line, qreal x1, qreal x2, const int startOfFragmentInBlock, const int fragmentToLineOffset) const;
0229 
0230     void drawUnderlines(QPainter *painter, const QTextCharFormat &currentCharFormat, const QString &text, const QTextLine &line, qreal x1, qreal x2, const int startOfFragmentInBlock, const int fragmentToLineOffset) const;
0231 
0232     int decorateTabsAndFormatting(QPainter *painter, const QTextFragment& currentFragment, const QTextLine &line, const int startOfFragmentInBlock, const QVariantList& tabList, int currentTabStop, bool showFormattingCharacter);
0233 
0234     void decorateListLabel(QPainter *painter, const KoTextBlockData &blockData, const QTextLine &listLabelLine, const QTextBlock &listItem);
0235 
0236     void handleBordersAndSpacing(KoTextBlockData &blockData, QTextBlock *block);
0237 
0238     void decorateParagraphSections(QPainter* painter, QTextBlock& block);
0239 
0240 private:
0241     class Private;
0242     Private * const d;
0243 };
0244 
0245 #endif