QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTextOptions.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_TEXT_OPTIONS_H
7#define QSK_TEXT_OPTIONS_H
8
9#include "QskGlobal.h"
10
11#include <qmetatype.h>
12#include <qtextoption.h>
13
14#include <limits>
15
16class QSK_EXPORT QskTextOptions
17{
18 Q_GADGET
19
20 Q_PROPERTY( TextFormat format READ format WRITE setFormat )
21 Q_PROPERTY( Qt::TextElideMode elideMode READ elideMode WRITE setElideMode )
22 Q_PROPERTY( WrapMode wrapMode READ wrapMode WRITE setWrapMode )
23 Q_PROPERTY( FontSizeMode fontSizeMode READ fontSizeMode WRITE setFontSizeMode )
24 Q_PROPERTY( int maximumLineCount READ maximumLineCount WRITE setMaximumLineCount )
25
26 public:
27 enum FontSizeMode : quint8
28 {
29 FixedSize,
30 HorizontalFit,
31 VerticalFit,
32 Fit
33 };
34 Q_ENUM( FontSizeMode )
35
36 enum WrapMode : quint8
37 {
38 NoWrap = QTextOption::NoWrap,
39 WordWrap = QTextOption::WordWrap,
40 WrapAnywhere = QTextOption::WrapAnywhere,
41 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
42 };
43 Q_ENUM( WrapMode )
44
45 enum TextFormat : quint8
46 {
47 PlainText = Qt::PlainText,
48 RichText = Qt::RichText,
49 AutoText = Qt::AutoText,
50 MarkdownText = Qt::MarkdownText,
51 StyledText = 4 // taken from QQuickText::StyledText
52 };
53 Q_ENUM( TextFormat )
54
55 constexpr QskTextOptions() noexcept;
56
57 constexpr TextFormat format() const noexcept;
58 void setFormat( TextFormat ) noexcept;
59
60 TextFormat effectiveFormat( const QString& text ) const;
61
62 constexpr Qt::TextElideMode elideMode() const noexcept;
63 void setElideMode( Qt::TextElideMode ) noexcept;
64
65 constexpr Qt::TextElideMode effectiveElideMode() const noexcept;
66
67 constexpr FontSizeMode fontSizeMode() const noexcept;
68 void setFontSizeMode( FontSizeMode ) noexcept;
69
70 constexpr WrapMode wrapMode() const noexcept;
71 void setWrapMode( WrapMode ) noexcept;
72
73 constexpr int maximumLineCount() const noexcept;
74 void setMaximumLineCount( int ) noexcept;
75
76 constexpr bool operator==( const QskTextOptions& other ) const noexcept;
77 constexpr bool operator!=( const QskTextOptions& other ) const noexcept;
78
79 QskHashValue hash( QskHashValue seed ) const noexcept;
80
81 int textFlags() const noexcept;
82
83 private:
84 int m_maximumLineCount;
85 FontSizeMode m_fontSizeMode : 2;
86 WrapMode m_wrapMode : 4;
87 TextFormat m_format : 3;
88 unsigned int m_elideMode : 2;
89};
90
91inline constexpr QskTextOptions::QskTextOptions() noexcept
92 : m_maximumLineCount( std::numeric_limits< int >::max() )
93 , m_fontSizeMode( QskTextOptions::FixedSize )
94 , m_wrapMode( QskTextOptions::NoWrap )
95 , m_format( PlainText ) // AutoText ???
96 , m_elideMode( Qt::ElideNone )
97{
98}
99
100inline void QskTextOptions::setFormat( TextFormat format ) noexcept
101{
102 m_format = format;
103}
104
105constexpr inline QskTextOptions::TextFormat QskTextOptions::format() const noexcept
106{
107 return m_format;
108}
109
110inline void QskTextOptions::setElideMode( Qt::TextElideMode elideMode ) noexcept
111{
112 m_elideMode = elideMode;
113}
114
115constexpr inline Qt::TextElideMode QskTextOptions::elideMode() const noexcept
116{
117 return static_cast< Qt::TextElideMode >( m_elideMode );
118}
119
120constexpr inline Qt::TextElideMode QskTextOptions::effectiveElideMode() const noexcept
121{
122 return ( wrapMode() != QskTextOptions::NoWrap ) ?
123 Qt::ElideNone : static_cast< Qt::TextElideMode >( m_elideMode );
124}
125
126inline void QskTextOptions::setWrapMode( WrapMode wrapMode ) noexcept
127{
128 m_wrapMode = wrapMode;
129}
130
131constexpr inline QskTextOptions::WrapMode QskTextOptions::wrapMode() const noexcept
132{
133 return m_wrapMode;
134}
135
136inline void QskTextOptions::setFontSizeMode( FontSizeMode fontSizeMode ) noexcept
137{
138 m_fontSizeMode = fontSizeMode;
139}
140
141constexpr inline QskTextOptions::FontSizeMode QskTextOptions::fontSizeMode() const noexcept
142{
143 return m_fontSizeMode;
144}
145
146inline void QskTextOptions::setMaximumLineCount( int lineCount ) noexcept
147{
148 m_maximumLineCount = lineCount;
149}
150
151constexpr inline int QskTextOptions::maximumLineCount() const noexcept
152{
153 return m_maximumLineCount;
154}
155
156inline constexpr bool QskTextOptions::operator==(
157 const QskTextOptions& other ) const noexcept
158{
159 return ( m_format == other.m_format ) &&
160 ( m_elideMode == other.m_elideMode ) &&
161 ( m_wrapMode == other.m_wrapMode ) &&
162 ( m_fontSizeMode == other.m_fontSizeMode ) &&
163 ( m_maximumLineCount == other.m_maximumLineCount );
164}
165
166inline constexpr bool QskTextOptions::operator!=(
167 const QskTextOptions& other ) const noexcept
168{
169 return !( *this == other );
170}
171
172#ifndef QT_NO_DEBUG_STREAM
173class QDebug;
174
175QSK_EXPORT QDebug operator<<( QDebug, const QskTextOptions& );
176#endif
177
178Q_DECLARE_TYPEINFO( QskTextOptions, Q_MOVABLE_TYPE );
179Q_DECLARE_METATYPE( QskTextOptions )
180
181#endif