QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTextOptions.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskTextOptions.h"
7#include <qtextdocument.h>
8
9static void qskRegisterTextOptions()
10{
11 qRegisterMetaType< QskTextOptions >();
12
13#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
14 QMetaType::registerEqualsComparator< QskTextOptions >();
15#endif
16}
17
18Q_CONSTRUCTOR_FUNCTION( qskRegisterTextOptions )
19
20int QskTextOptions::textFlags() const noexcept
21{
22 int flags = 0;
23
24 switch ( m_wrapMode )
25 {
26 case QskTextOptions::NoWrap:
27 {
28 // flags |= Qt::TextSingleLine;
29 break;
30 }
31 case QskTextOptions::WordWrap:
32 {
33 flags |= Qt::TextWordWrap;
34 break;
35 }
36 case QskTextOptions::WrapAnywhere:
37 {
38 flags |= Qt::TextWrapAnywhere;
39 break;
40 }
41 case QskTextOptions::Wrap:
42 {
43 // ???
44 flags |= Qt::TextWrapAnywhere;
45 flags |= Qt::TextWordWrap;
46 break;
47 }
48 }
49
50 return flags;
51}
52
53QskTextOptions::TextFormat QskTextOptions::effectiveFormat( const QString& text ) const
54{
55 if ( text.isEmpty() )
56 return PlainText;
57
58 if ( m_format == QskTextOptions::AutoText )
59 return Qt::mightBeRichText( text ) ? StyledText : PlainText;
60 else
61 return m_format;
62}
63
64QskHashValue QskTextOptions::hash( QskHashValue seed ) const noexcept
65{
66 auto hash = qHash( m_maximumLineCount, seed );
67 hash = qHash( m_fontSizeMode, hash );
68 hash = qHash( m_wrapMode, hash );
69 hash = qHash( m_format, hash );
70 hash = qHash( m_elideMode, hash );
71
72 return hash;
73}
74
75#ifndef QT_NO_DEBUG_STREAM
76
77#include <qdebug.h>
78
79QDebug operator<<( QDebug debug, const QskTextOptions& options )
80{
81 QDebugStateSaver saver( debug );
82 debug.nospace();
83 debug << "TextOptions" << '(';
84 debug << options.format() << "," << options.elideMode()
85 << options.fontSizeMode() << options.wrapMode()
86 << "," << options.maximumLineCount();
87 debug << ')';
88 return debug;
89}
90
91#endif
92
93#include "moc_QskTextOptions.cpp"