QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTabButton.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskTabButton.h"
7#include "QskSkinlet.h"
8#include "QskTabBar.h"
9#include "QskTextOptions.h"
10#include "QskQuick.h"
11
12#include <qfontmetrics.h>
13#include <qpointer.h>
14
15QSK_SUBCONTROL( QskTabButton, Panel )
16QSK_SUBCONTROL( QskTabButton, Text )
17
18static inline QskTabBar* qskFindTabBar( const QskTabButton* button )
19{
20 return qskFindAncestorOf< QskTabBar* >( button->parentItem() );
21}
22
23class QskTabButton::PrivateData
24{
25 public:
26 PrivateData( const QString& txt )
27 : text( txt )
28 {
29 }
30
31 QString text;
32 QPointer< QskTabBar > tabBar;
33};
34
35QskTabButton::QskTabButton( QQuickItem* parent )
36 : QskTabButton( QString(), parent )
37{
38}
39
40QskTabButton::QskTabButton( const QString& text, QQuickItem* parent )
41 : Inherited( parent )
42 , m_data( new PrivateData( text ) )
43{
44 if ( parent )
45 m_data->tabBar = qskFindTabBar( this );
46
47 initSizePolicy( QskSizePolicy::MinimumExpanding,
48 QskSizePolicy::QskSizePolicy::MinimumExpanding );
49
50 setExclusive( true );
51}
52
53QskTabButton::~QskTabButton()
54{
55}
56
57bool QskTabButton::isCheckable() const
58{
59 return true;
60}
61
62void QskTabButton::setText( const QString& text )
63{
64 if ( m_data->text == text )
65 return;
66
67 m_data->text = text;
68 Q_EMIT textChanged( text );
69
71 update();
72}
73
74QString QskTabButton::text() const
75{
76 return m_data->text;
77}
78
79void QskTabButton::setTextOptions( const QskTextOptions& textOptions )
80{
81 if ( setTextOptionsHint( Text, textOptions ) )
82 Q_EMIT textOptionsChanged();
83}
84
85QskTextOptions QskTabButton::textOptions() const
86{
87 return textOptionsHint( Text );
88}
89
90void QskTabButton::resetTextOptions()
91{
92 if ( resetTextOptionsHint( Text ) )
93 Q_EMIT textOptionsChanged();
94}
95
96QRectF QskTabButton::layoutRectForSize( const QSizeF& size ) const
97{
98 return subControlContentsRect( size, Panel );
99}
100
102{
103 if ( m_data->tabBar )
104 return m_data->tabBar->effectiveVariation();
105
107}
108
109const QskTabBar* QskTabButton::tabBar() const
110{
111 return m_data->tabBar;
112}
113
114QskTabBar* QskTabButton::tabBar()
115{
116 return m_data->tabBar;
117}
118
119void QskTabButton::changeEvent( QEvent* event )
120{
121 switch ( event->type() )
122 {
123 case QEvent::LocaleChange:
124 {
125 if ( !m_data->text.isEmpty() )
126 {
127 // maybe QLocale::textDirection() has changed
128 update();
129 }
130
131 break;
132 }
133 case QEvent::ParentChange:
134 {
135 m_data->tabBar = qskFindTabBar( this );
136 break;
137 }
138 default:
139 break;
140 }
141
142 Inherited::changeEvent( event );
143}
144
145#include "moc_QskTabButton.cpp"
Variation
Some sort of variation.
Definition QskAspect.h:82
@ NoVariation
Definition QskAspect.h:83
QRectF subControlContentsRect(QskAspect::Subcontrol) const
void resetImplicitSize()
Definition QskItem.cpp:721
virtual void changeEvent(QEvent *)
Definition QskItem.cpp:859
void changeEvent(QEvent *) override
QRectF layoutRectForSize(const QSizeF &) const override
QskAspect::Variation effectiveVariation() const override