QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskIcon.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_ICON_H
7#define QSK_ICON_H
8
9#include "QskGlobal.h"
10#include "QskGraphic.h"
11
12#include <qurl.h>
13#include <qmetatype.h>
14#include <qshareddata.h>
15
16/*
17 Most controls offer 2 way to pass an icon:
18
19 - URL
20 - QskGraphic
21
22 For the vast majority of the application icons URLs are used
23 that will be loaded at runtime by a QskGraphicProvider.
24 ( QML code always uses URLs )
25
26 QskIcon implements a lazy loading strategy, that avoids unsatisfying
27 startup performance from loading to many icons in advance.
28 */
29
30class QSK_EXPORT QskIcon
31{
32 Q_GADGET
33
34 Q_PROPERTY( QskGraphic graphic READ graphic WRITE setGraphic )
35 Q_PROPERTY( QUrl source READ source WRITE setSource )
36
37 public:
38 QskIcon();
39
40 QskIcon( const QString& );
41 QskIcon( const QUrl& );
42 QskIcon( const QskGraphic& );
43
44 bool operator==( const QskIcon& ) const noexcept;
45 bool operator!=( const QskIcon& ) const noexcept;
46
47 bool isNull() const;
48
49 void setSource( const QUrl& );
50 QUrl source() const noexcept;
51
52 void setGraphic( const QskGraphic& );
53 QskGraphic graphic() const;
54
55 QskGraphic maybeGraphic() const noexcept;
56
57 QskHashValue hash( QskHashValue ) const;
58
59 private:
60 QUrl m_source;
61
62 class Data : public QSharedData
63 {
64 public:
65 ~Data() { delete graphic; }
66 QskGraphic* graphic = nullptr;
67 };
68
69 mutable QExplicitlySharedDataPointer< Data > m_data;
70};
71
72Q_DECLARE_METATYPE( QskIcon )
73
74inline QskIcon::QskIcon( const QString& source )
75 : QskIcon( QUrl( source ) )
76{
77}
78
79inline bool QskIcon::isNull() const
80{
81 if ( m_data->graphic )
82 return m_data->graphic->isNull();
83
84 return m_source.isEmpty();
85}
86
87inline QUrl QskIcon::source() const noexcept
88{
89 return m_source;
90}
91
92inline QskGraphic QskIcon::maybeGraphic() const noexcept
93{
94 return m_data->graphic ? *m_data->graphic : QskGraphic();
95}
96
97inline bool QskIcon::operator!=( const QskIcon& other ) const noexcept
98{
99 return ( !( *this == other ) );
100}
101
102#ifndef QT_NO_DEBUG_STREAM
103
104class QDebug;
105
106QSK_EXPORT QDebug operator<<( QDebug, const QskIcon& );
107
108#endif
109
110#endif
A paint device for scalable graphics.
Definition QskGraphic.h:28