1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "qmldesignericonprovider.h"
27 #include <qmldesignericons.h>
28 
29 
30 #include <utils/icon.h>
31 #include <utils/utilsicons.h>
32 
33 #include <coreplugin/icore.h>
34 
35 #include <QDebug>
36 
37 namespace QmlDesigner {
38 
QmlDesignerIconProvider()39 QmlDesignerIconProvider::QmlDesignerIconProvider()
40     : QQuickImageProvider(Pixmap)
41 {
42 
43 }
44 
iconPath()45 static Utils::FilePath iconPath()
46 {
47     return Core::ICore::resourcePath(
48         "qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/images/");
49 }
50 
requestPixmap(const QString & id,QSize * size,const QSize & requestedSize)51 QPixmap QmlDesignerIconProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
52 {
53     Q_UNUSED(requestedSize)
54 
55     QPixmap result = getPixmap(id);
56 
57     if (size)
58         *size = result.size();
59     return result;
60 }
61 
getPixmap(const QString & id)62 QPixmap QmlDesignerIconProvider::getPixmap(const QString &id)
63 {
64     using namespace Utils;
65 
66     QPixmap result;
67 
68     if (id == "close")
69         result = Utils::Icons::CLOSE_TOOLBAR.pixmap();
70     else if (id == "plus")
71         result = Utils::Icons::PLUS_TOOLBAR.pixmap();
72     else if (id == "expression")
73         result = Icon({{iconPath() / "expression.png", Theme::QmlDesigner_HighlightColor}}).pixmap();
74     else if (id == "placeholder")
75         result = Icon(iconPath() / "placeholder.png").pixmap();
76     else if (id == "submenu")
77         result = Icon(iconPath() / "submenu.png").pixmap();
78     else if (id == "up-arrow")
79         result = Icon({{iconPath() / "up-arrow.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
80     else if (id == "down-arrow")
81         result = Icon({{iconPath() / "down-arrow.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
82     else if (id == "checkbox-indicator")
83         result = Icon({
84                 { ":/qmldesigner/images/checkbox_indicator.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
85     else if (id == "tr")
86         result = Icon({
87                 { ":/qmldesigner/images/tr.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
88     else if (id == "ok")
89         result = Icon({
90                 { ":/utils/images/ok.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
91     else if (id == "error")
92         result = Icon({
93                 { ":/utils/images/broken.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
94     else if (id == "anchor-top")
95         result = Icon({
96                 { ":/qmldesigner/images/anchor_top.png", Theme::IconsBaseColor},
97                 { ":/qmldesigner/images/anchoreditem.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
98     else if (id == "anchor-right")
99         result = Icon({
100                 { ":/qmldesigner/images/anchor_right.png", Theme::IconsBaseColor},
101                 { ":/qmldesigner/images/anchoreditem.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
102     else if (id == "anchor-bottom")
103         result = Icon({
104                 { ":/qmldesigner/images/anchor_bottom.png", Theme::IconsBaseColor},
105                 { ":/qmldesigner/images/anchoreditem.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
106     else if (id == "anchor-left")
107         result = Icon({
108                 { ":/qmldesigner/images/anchor_left.png", Theme::IconsBaseColor},
109                 { ":/qmldesigner/images/anchoreditem.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
110     else if (id == "anchor-horizontal")
111         result = Icon({
112                 { ":/qmldesigner/images/anchor_horizontal.png", Theme::IconsBaseColor},
113                 { ":/qmldesigner/images/anchoreditem.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
114     else if (id == "anchor-vertical")
115         result = Icon({
116                 { ":/qmldesigner/images/anchor_vertical.png", Theme::IconsBaseColor},
117                 { ":/qmldesigner/images/anchoreditem.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
118     else if (id == "anchor-fill")
119         result = Icon({
120                 { ":/qmldesigner/images/anchor_fill.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
121     else if (id == "alignment-left")
122         result = Icon({
123                 { ":/qmldesigner/images/alignment_left.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
124     else if (id == "alignment-left-h")
125         result = Icon({
126                 { ":/qmldesigner/images/alignment_left.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
127     else if (id == "alignment-center")
128         result = Icon({
129                 { ":/qmldesigner/images/alignment_center.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
130     else if (id == "alignment-center-h")
131         result = Icon({
132                 { ":/qmldesigner/images/alignment_center.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
133     else if (id == "alignment-right")
134         result = Icon({
135                 { ":/qmldesigner/images/alignment_right.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
136     else if (id == "alignment-right-h")
137         result = Icon({
138                 { ":/qmldesigner/images/alignment_right.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
139     else if (id == "alignment-top")
140         result = Icon({
141                 { ":/qmldesigner/images/alignment_top.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
142     else if (id == "alignment-top-h")
143         result = Icon({
144                 { ":/qmldesigner/images/alignment_top.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
145     else if (id == "alignment-middle")
146         result = Icon({
147                 { ":/qmldesigner/images/alignment_middle.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
148     else if (id == "alignment-middle-h")
149         result = Icon({
150                 { ":/qmldesigner/images/alignment_middle.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
151     else if (id == "alignment-bottom")
152         result = Icon({
153                 { ":/qmldesigner/images/alignment_bottom.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
154     else if (id == "alignment-bottom-h")
155         result = Icon({
156                 { ":/qmldesigner/images/alignment_bottom.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
157     else if (id == "style-bold")
158         result = Icon({
159                 { ":/qmldesigner/images/style_bold.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
160     else if (id == "style-bold-h")
161         result = Icon({
162                 { ":/qmldesigner/images/style_bold.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
163     else if (id == "style-italic")
164         result = Icon({
165                 { ":/qmldesigner/images/style_italic.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
166     else if (id == "style-italic-h")
167         result = Icon({
168                 { ":/qmldesigner/images/style_italic.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
169     else if (id == "style-underline")
170         result = Icon({
171                 { ":/qmldesigner/images/style_underline.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
172     else if (id == "style-underline-h")
173         result = Icon({
174                 { ":/qmldesigner/images/style_underline.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
175     else if (id == "style-strikeout")
176         result = Icon({
177                 { ":/qmldesigner/images/style_strikeout.png", Theme::IconsBaseColor}}, Icon::Tint).pixmap();
178     else if (id == "style-strikeout-h")
179         result = Icon({
180                 { ":/qmldesigner/images/style_strikeout.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
181     else if (id == "alias-export-checked")
182         result = Icons::EXPORT_CHECKED.pixmap();
183     else if (id == "alias-export-unchecked")
184         result = Icons::EXPORT_UNCHECKED.pixmap();
185     else
186         qWarning() << Q_FUNC_INFO << "Image not found:" << id;
187 
188     return result;
189 }
190 
191 } // namespace QmlDesigner
192