QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSubWindow.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskSubWindow.h"
7#include "QskAspect.h"
8#include "QskGraphic.h"
9#include "QskGraphicProvider.h"
10#include "QskTextOptions.h"
11#include "QskQuick.h"
12
13#include <qurl.h>
14
15QSK_SUBCONTROL( QskSubWindow, Panel )
16QSK_SUBCONTROL( QskSubWindow, TitleBarPanel )
17QSK_SUBCONTROL( QskSubWindow, TitleBarSymbol )
18QSK_SUBCONTROL( QskSubWindow, TitleBarText )
19
20namespace
21{
22 inline QskAspect aspectDecoration()
23 {
24 return QskSubWindow::TitleBarPanel | QskAspect::Style;
25 }
26}
27
28class QskSubWindow::PrivateData
29{
30 public:
31 PrivateData()
32 : isWindowIconSourceDirty( false )
33 {
34 }
35
36 QString windowTitle;
37
38 QUrl windowIconSource;
39 QskGraphic windowIcon;
40
41 bool isWindowIconSourceDirty : 1;
42};
43
44QskSubWindow::QskSubWindow( QQuickItem* parent )
45 : Inherited( parent )
46 , m_data( new PrivateData() )
47{
48 setMargins( 0 );
49 initSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::MinimumExpanding );
50
51 setAutoLayoutChildren( true );
52}
53
54QskSubWindow::~QskSubWindow()
55{
56}
57
58void QskSubWindow::setDecorations( Decorations decorations )
59{
60 if ( setFlagHint( aspectDecoration(), decorations ) )
61 Q_EMIT decorationsChanged( decorations );
62}
63
64QskSubWindow::Decorations QskSubWindow::decorations() const
65{
66 return flagHint< QskSubWindow::Decorations >( aspectDecoration() );
67}
68
69void QskSubWindow::setDecoration( Decoration decoration, bool on )
70{
71 auto d = decorations();
72
73 if ( on )
74 d |= decoration;
75 else
76 d &= ~decoration;
77
78 setDecorations( d );
79}
80
81void QskSubWindow::resetDecorations()
82{
83 if ( resetSkinHint( aspectDecoration() ) )
84 Q_EMIT decorationsChanged( decorations() );
85}
86
87bool QskSubWindow::hasDecoration( Decoration decoration ) const
88{
89 return decorations() & decoration;
90}
91
92void QskSubWindow::setWindowTitle( const QString& title )
93{
94 if ( m_data->windowTitle != title )
95 {
96 m_data->windowTitle = title;
97
98 update();
99 Q_EMIT windowTitleChanged();
100 }
101}
102
103QString QskSubWindow::windowTitle() const
104{
105 return m_data->windowTitle;
106}
107
108void QskSubWindow::setWindowTitleTextOptions( const QskTextOptions& options )
109{
110 if ( setTextOptionsHint( TitleBarText, options ) )
111 Q_EMIT windowTitleTextOptionsChanged();
112}
113
114QskTextOptions QskSubWindow::windowTitleTextOptions() const
115{
116 return textOptionsHint( TitleBarText );
117}
118
119void QskSubWindow::setWindowIconSource( const QString& url )
120{
121 setWindowIconSource( QUrl( url ) );
122}
123
124void QskSubWindow::setWindowIconSource( const QUrl& url )
125{
126 if ( m_data->windowIconSource == url )
127 return;
128
129 m_data->windowIconSource = url;
130 m_data->windowIcon.reset();
131
132 m_data->isWindowIconSourceDirty = true;
133
134 polish();
135 update();
136
137 Q_EMIT windowIconSourceChanged();
138}
139
140QUrl QskSubWindow::windowIconSource() const
141{
142 return m_data->windowIconSource;
143}
144
145void QskSubWindow::setWindowIcon( const QskGraphic& graphic )
146{
147 if ( graphic != m_data->windowIcon )
148 {
149 m_data->windowIcon = graphic;
150
151 if ( !m_data->windowIconSource.isEmpty() )
152 {
153 m_data->windowIconSource = QString();
154 m_data->isWindowIconSourceDirty = false;
155
156 Q_EMIT windowIconSourceChanged();
157 }
158
159 polish();
160 update();
161
162 Q_EMIT windowIconChanged();
163 }
164}
165
166QskGraphic QskSubWindow::windowIcon() const
167{
168 return m_data->windowIcon;
169}
170
171bool QskSubWindow::hasWindowIcon() const
172{
173 return !( windowIcon().isEmpty() && windowIconSource().isEmpty() );
174}
175
176QRectF QskSubWindow::titleBarRect() const
177{
178 return subControlRect( TitleBarPanel );
179}
180
181bool QskSubWindow::event( QEvent* event )
182{
183 if ( event->type() == QEvent::LayoutRequest )
185
186 return Inherited::event( event );
187}
188
189void QskSubWindow::updateLayout()
190{
191 if ( m_data->isWindowIconSourceDirty )
192 {
193 if ( !m_data->windowIconSource.isEmpty() )
194 {
195 m_data->windowIcon = Qsk::loadGraphic( m_data->windowIconSource );
196 Q_EMIT windowIconChanged();
197 }
198
199 m_data->isWindowIconSourceDirty = false;
200 }
201
202 Inherited::updateLayout();
203}
204
205QRectF QskSubWindow::layoutRectForSize( const QSizeF& size ) const
206{
207 QRectF rect;
208 rect.setSize( size );
209 rect.setTop( subControlRect( size, TitleBarPanel ).bottom() );
210
211 return innerBox( Panel, rect );
212}
213
214QSizeF QskSubWindow::layoutSizeHint(
215 Qt::SizeHint which, const QSizeF& constraint ) const
216{
217 // the size we get from the children
218 auto hint = Inherited::layoutSizeHint( which, constraint );
219
220 if ( which == Qt::PreferredSize )
221 {
222 // should be Minimum Width/Height from the skin hints
223 if ( hint.width() < 0.0 )
224 hint.setWidth( 100 );
225
226 if ( hint.height() < 0.0 )
227 hint.setHeight( 80 );
228 }
229
230 return hint;
231}
232
233void QskSubWindow::itemChange( QQuickItem::ItemChange change,
234 const QQuickItem::ItemChangeData& value )
235{
236 Inherited::itemChange( change, value );
237
238 switch ( change )
239 {
240 case QQuickItem::ItemChildAddedChange:
241 case QQuickItem::ItemChildRemovedChange:
242 {
243 if ( qskIsVisibleToLayout( value.item ) )
244 {
246 polish();
247 }
248 break;
249 }
250 default:
251 ;
252 }
253}
254
255void QskSubWindow::updateResources()
256{
257 setOpacity( fadingFactor() );
258 Inherited::updateResources();
259}
260
261QskAspect QskSubWindow::fadingAspect() const
262{
263 return QskSubWindow::Panel | QskAspect::Position;
264}
265
266#include "moc_QskSubWindow.cpp"
Lookup key for a QskSkinHintTable.
Definition QskAspect.h:15
QRectF subControlRect(QskAspect::Subcontrol) const
A paint device for scalable graphics.
Definition QskGraphic.h:28
QRectF rect
Definition QskItem.h:21
void resetImplicitSize()
Definition QskItem.cpp:721
bool resetSkinHint(QskAspect)
Remove a hint from the local hint table.
bool setFlagHint(QskAspect, int flag)
Sets a flag hint.
QRectF innerBox(QskAspect, const QRectF &outerBox) const
Calculate the rectangle, whith paddings, indentations being subtracted.
QRectF layoutRectForSize(const QSizeF &) const override