swift
icon.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_ICON_H
7 #define SWIFT_MISC_ICON_H
8 
9 #include <QIcon>
10 #include <QMetaType>
11 #include <QPixmap>
12 #include <QString>
13 
14 #include "misc/icons.h"
15 #include "misc/metaclass.h"
18 #include "misc/mixin/mixindbus.h"
19 #include "misc/mixin/mixinhash.h"
20 #include "misc/mixin/mixinjson.h"
22 #include "misc/mixin/mixinstring.h"
23 #include "misc/swiftmiscexport.h"
24 
25 namespace swift::misc
26 {
30  public mixin::MetaType<CIcon>,
31  public mixin::HashByMetaClass<CIcon>,
32  public mixin::DBusByMetaClass<CIcon>,
33  public mixin::DataStreamByMetaClass<CIcon>,
34  public mixin::JsonByMetaClass<CIcon>,
35  public mixin::EqualsByMetaClass<CIcon>,
36  public mixin::LessThanByMetaClass<CIcon>,
37  public mixin::CompareByMetaClass<CIcon>,
38  public mixin::String<CIcon>
39  {
40  public:
42  CIcon() {}
43 
45  CIcon(CIcons::IconIndex index);
46 
48  // CIcon(const QPixmap &pixmap, const QString &descriptiveText);
49 
51  // CIcon(const QString &resourceFilePath, const QString &descriptiveText);
52 
54  const QString &getDescriptiveText() const { return m_descriptiveText; }
55 
57  const QString &getFileResourcePath() const { return m_fileResourcePath; }
58 
60  bool hasFileResourcePath() const { return !m_fileResourcePath.isEmpty(); }
61 
63  CIcons::IconIndex getIndex() const;
64 
66  bool isIndexBased() const;
67 
69  bool isGenerated() const;
70 
72  bool isFileBased() const;
73 
75  bool isSet() const;
76 
78  QPixmap toPixmap() const;
79 
81  CIcons::IconIndex toIcon() const { return m_index; }
82 
84  QIcon toQIcon() const;
85 
87  void setRotation(int degrees) { m_rotateDegrees = degrees; }
88 
90  void setDescriptiveText(const QString &text) { m_descriptiveText = text; }
91 
93  operator QPixmap() const { return this->toPixmap(); }
94 
96  QString convertToQString(bool i18n = false) const;
97 
99  static const CIcon &iconByIndex(CIcons::IconIndex index);
100 
102  static const CIcon &iconByIndex(int index);
103 
105  static const CSequence<CIcon> &allIcons();
106 
107  private:
109  CIcon(CIcons::IconIndex index, const QString &descriptiveText);
110 
111  CIcons::IconIndex m_index = CIcons::NotSet;
112  int m_rotateDegrees = 0;
113  QString m_descriptiveText;
114  QString m_fileResourcePath;
115  QPixmap m_pixmap;
116 
118  CIcon,
119  SWIFT_METAMEMBER(index),
121  SWIFT_METAMEMBER(descriptiveText),
122  SWIFT_METAMEMBER(fileResourcePath));
123  };
124 } // namespace swift::misc
125 
126 Q_DECLARE_METATYPE(swift::misc::CIcon)
127 
128 #endif // SWIFT_MISC_ICON_H
Value object for icons. An icon is stored in the global icon repository and identified by its index....
Definition: icon.h:39
CIcons::IconIndex toIcon() const
Identity function.
Definition: icon.h:81
CIcon()
Default constructor.
Definition: icon.h:42
void setDescriptiveText(const QString &text)
Set descriptive text.
Definition: icon.h:90
void setRotation(int degrees)
Rotate by n degrees.
Definition: icon.h:87
const QString & getDescriptiveText() const
Constructor for generated icon.
Definition: icon.h:54
bool hasFileResourcePath() const
Resource path available?
Definition: icon.h:60
const QString & getFileResourcePath() const
Resource path if any.
Definition: icon.h:57
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition: icons.h:32
CRTP class template from which a derived class can inherit non-member compare() implemented by metacl...
Definition: mixincompare.h:216
CRTP class template from which a derived class can inherit common methods dealing with marshalling in...
Definition: mixindbus.h:71
CRTP class template to generate QDataStream marshalling methods using CMetaClass.
CRTP class template from which a derived class can inherit operator== implemented by metaclass.
Definition: mixincompare.h:46
CRTP class template from which a derived class can inherit common methods dealing with hashing instan...
Definition: mixinhash.h:48
CRTP class template from which a derived class can inherit common methods dealing with JSON by metatu...
Definition: mixinjson.h:90
CRTP class template from which a derived class can inherit operator< implemented by metaclass.
Definition: mixincompare.h:136
CRTP class template from which a derived class can inherit common methods dealing with the metatype o...
Definition: mixinmetatype.h:29
CRTP class template from which a derived class can inherit string streaming operations.
Definition: mixinstring.h:31
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
@ DisabledForComparison
Element will be ignored by compare() and comparison operators.
Definition: metaclass.h:202
@ DisabledForHashing
Element will be ignored by qHash()
Definition: metaclass.h:205
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.