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
28 {
29 FixedSize,
30 HorizontalFit,
31 VerticalFit,
32 Fit
33 };
34 Q_ENUM( FontSizeMode )
35
36 enum WrapMode
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
46 {
47 PlainText = Qt::PlainText,
48 RichText = Qt::RichText,
49 AutoText = Qt::AutoText,
50 StyledText = 4 // taken from QQuickText::StyledText
51 };
52 Q_ENUM( TextFormat )
53
54 constexpr QskTextOptions() noexcept;
55
56 constexpr TextFormat format() const noexcept;
57 void setFormat( TextFormat ) noexcept;
58
59 TextFormat effectiveFormat( const QString& text ) const;
60
61 constexpr Qt::TextElideMode elideMode() const noexcept;
62 void setElideMode( Qt::TextElideMode ) noexcept;
63
64 constexpr Qt::TextElideMode effectiveElideMode() const noexcept;
65
66 constexpr FontSizeMode fontSizeMode() const noexcept;
67 void setFontSizeMode( FontSizeMode ) noexcept;
68
69 constexpr WrapMode wrapMode() const noexcept;
70 void setWrapMode( WrapMode ) noexcept;
71
72 constexpr int maximumLineCount() const noexcept;
73 void setMaximumLineCount( int ) noexcept;
74
75 constexpr bool operator==( const QskTextOptions& other ) const noexcept;
76 constexpr bool operator!=( const QskTextOptions& other ) const noexcept;
77
78 QskHashValue hash( QskHashValue seed ) const noexcept;
79
80 int textFlags() const noexcept;
81
82 private:
83 int m_maximumLineCount;
84 FontSizeMode m_fontSizeMode : 2;
85 WrapMode m_wrapMode : 4;
86 TextFormat m_format : 3;
87 Qt::TextElideMode m_elideMode : 2;
88};
89
90inline constexpr QskTextOptions::QskTextOptions() noexcept
91 : m_maximumLineCount( std::numeric_limits< int >::max() )
92 , m_fontSizeMode( QskTextOptions::FixedSize )
93 , m_wrapMode( QskTextOptions::NoWrap )
94 , m_format( PlainText ) // AutoText ???
95 , m_elideMode( Qt::ElideNone )
96{
97}
98
99inline void QskTextOptions::setFormat( TextFormat format ) noexcept
100{
101 m_format = format;
102}
103
104constexpr inline QskTextOptions::TextFormat QskTextOptions::format() const noexcept
105{
106 return m_format;
107}
108
109inline void QskTextOptions::setElideMode( Qt::TextElideMode elideMode ) noexcept
110{
111 m_elideMode = elideMode;
112}
113
114constexpr inline Qt::TextElideMode QskTextOptions::elideMode() const noexcept
115{
116 return m_elideMode;
117}
118
119constexpr inline Qt::TextElideMode QskTextOptions::effectiveElideMode() const noexcept
120{
121 return ( m_wrapMode != QskTextOptions::NoWrap ) ? Qt::ElideNone : m_elideMode;
122}
123
124inline void QskTextOptions::setWrapMode( WrapMode wrapMode ) noexcept
125{
126 m_wrapMode = wrapMode;
127}
128
129constexpr inline QskTextOptions::WrapMode QskTextOptions::wrapMode() const noexcept
130{
131 return m_wrapMode;
132}
133
134inline void QskTextOptions::setFontSizeMode( FontSizeMode fontSizeMode ) noexcept
135{
136 m_fontSizeMode = fontSizeMode;
137}
138
139constexpr inline QskTextOptions::FontSizeMode QskTextOptions::fontSizeMode() const noexcept
140{
141 return m_fontSizeMode;
142}
143
144inline void QskTextOptions::setMaximumLineCount( int lineCount ) noexcept
145{
146 m_maximumLineCount = lineCount;
147}
148
149constexpr inline int QskTextOptions::maximumLineCount() const noexcept
150{
151 return m_maximumLineCount;
152}
153
154inline constexpr bool QskTextOptions::operator==(
155 const QskTextOptions& other ) const noexcept
156{
157 return ( m_format == other.m_format ) &&
158 ( m_elideMode == other.m_elideMode ) &&
159 ( m_wrapMode == other.m_wrapMode ) &&
160 ( m_fontSizeMode == other.m_fontSizeMode ) &&
161 ( m_maximumLineCount == other.m_maximumLineCount );
162}
163
164inline constexpr bool QskTextOptions::operator!=(
165 const QskTextOptions& other ) const noexcept
166{
167 return !( *this == other );
168}
169
170#ifndef QT_NO_DEBUG_STREAM
171class QDebug;
172
173QSK_EXPORT QDebug operator<<( QDebug, const QskTextOptions& );
174#endif
175
176Q_DECLARE_TYPEINFO( QskTextOptions, Q_MOVABLE_TYPE );
177Q_DECLARE_METATYPE( QskTextOptions )
178
179#endif