File indexing completed on 2024-05-26 16:15:52

0001 /* This file is part of the KDE project
0002  * Copyright (C)  2006, 2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C)  2008 Girish Ramakrishnan <girish@forwardbias.in>
0004  * Copyright (C)  2011 Pierre Ducroquet <pinaraf@pinaraf.info>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  */
0021 #ifndef KOTEXT_H
0022 #define KOTEXT_H
0023 
0024 #include "kotext_export.h"
0025 
0026 #include <KoDocumentResourceManager.h>
0027 #include <styles/KoCharacterStyle.h>
0028 
0029 #include <QChar>
0030 #include <QMetaType>
0031 #include <QTextOption>
0032 
0033 class QStringList;
0034 
0035 /**
0036  * Generic namespace of the Calligra Text library for helper methods and data.
0037  */
0038 namespace KoText
0039 {
0040 KOTEXT_EXPORT QStringList underlineTypeList();
0041 KOTEXT_EXPORT QStringList underlineStyleList();
0042 KOTEXT_EXPORT Qt::Alignment alignmentFromString(const QString &align);
0043 KOTEXT_EXPORT QString alignmentToString(Qt::Alignment align);
0044 KOTEXT_EXPORT Qt::Alignment valignmentFromString(const QString &align);
0045 KOTEXT_EXPORT QString valignmentToString(Qt::Alignment align);
0046 
0047 /// This enum contains values to be used as keys in KoCanvasResourceManager
0048 enum CanvasResource {
0049     CurrentTextDocument = 382490375, ///< set by the text plugin whenever the document is changed
0050     CurrentTextPosition = 183523,   ///<  used by the text plugin whenever the position is changed
0051     CurrentTextAnchor = 341899485,   ///<  used by the text plugin whenever the anchor-position is changed
0052     SelectedTextPosition = 21314576,   ///<  used by the text plugin whenever the alternative selection is changed
0053     ///  used by the text plugin whenever the alternative selection anchor-position is changed
0054     SelectedTextAnchor = 3344189
0055 };
0056 
0057 /// For paragraphs each tab definition is represented by this struct.
0058 struct KOTEXT_EXPORT Tab {
0059     Tab();
0060     qreal position;    ///< distance in ps-points from the edge of the text-shape
0061     QTextOption::TabType type;       ///< Determine which type is used.
0062     QChar delimiter;    ///< If type is DelimitorTab; tab until this char was found in the text.
0063     KoCharacterStyle::LineType leaderType; // none/single/double
0064     KoCharacterStyle::LineStyle leaderStyle; // solid/dotted/dash/...
0065     KoCharacterStyle::LineWeight leaderWeight; // auto/bold/thin/length/percentage/...
0066     qreal leaderWidth; // the width value if length/percentage
0067     QColor leaderColor; ///< if color is valid, then use this instead of the (current) text color
0068     QString leaderText;   ///< character to print as the leader (filler of the tabbed space)
0069 
0070     bool operator==(const Tab &tab) const;
0071 };
0072 
0073 /**
0074  * Text resources per calligra-document.
0075  * \sa KoDocumentResourceManager KoShapeController::resourceManager()
0076  */
0077 enum DocumentResource {
0078     ChangeTracker = KoDocumentResourceManager::KoTextStart + 1, ///< KoChangeTracker
0079     InlineTextObjectManager, ///< The KoText inline-text-object manager. KoInlineTextObjectManager
0080     TextRangeManager, ///< The KoText inline-text-object manager. KoInlineTextObjectManager
0081     StyleManager,           ///< The KoStyleManager
0082     PageProvider,            ///< The KoPageProvider
0083     /** The KoDocumentRdf for the document,
0084         this will be a KoDocumentRdfBase when Soprano support is not compiled in. */
0085     DocumentRdf
0086 
0087 };
0088 
0089 enum KoTextFrameProperty {
0090     SubFrameType = QTextFormat::UserProperty + 1
0091 };
0092 
0093 enum KoSubFrameType {
0094     AuxillaryFrameType = 1,
0095     NoteFrameType
0096 };
0097 
0098 /// Text in the objects will be positioned according to the direction.
0099 enum Direction {
0100     AutoDirection,      ///< Take the direction from the text.
0101     LeftRightTopBottom, ///< Text layout for most western languages
0102     RightLeftTopBottom, ///< Text layout for languages like Hebrew
0103     TopBottomRightLeft,  ///< Vertical text layout.
0104     TopBottomLeftRight,  ///< Vertical text layout. ?
0105     InheritDirection    ///< Direction is unspecified and should come from the container
0106 };
0107 
0108 /// convert the string version of directions (as specified in XSL and ODF) to the Direction enum
0109 KOTEXT_EXPORT Direction directionFromString(const QString &direction);
0110 /// convert the Direction enum to the string version of directions (as specified in XSL and ODF)
0111 KOTEXT_EXPORT QString directionToString(Direction direction);
0112 
0113 /// There are several possible text breaks
0114 enum KoTextBreakProperty {
0115     NoBreak = 0,         ///< No text break
0116     ColumnBreak,     ///< Column break
0117     PageBreak        ///< Page break
0118 };
0119 
0120 /// convert the string version of text break (as specified in ODF) to the KoTextBreakProperty enum
0121 KOTEXT_EXPORT KoTextBreakProperty textBreakFromString(const QString &textBreak);
0122 /// convert the KoTextBreakProperty enum to the string version of text break (as specified in ODF)
0123 KOTEXT_EXPORT QString textBreakToString (KoTextBreakProperty textBreak);
0124 
0125 ///TODO: move to KoUnit ?
0126 KOTEXT_EXPORT QTextLength parseLength (const QString &length);
0127 }
0128 
0129 Q_DECLARE_TYPEINFO(KoText::Tab, Q_MOVABLE_TYPE);
0130 Q_DECLARE_METATYPE(KoText::Tab)
0131 
0132 #endif