Merge lp:~larsu/ubuntu-ui-toolkit/add-unity-theme-icon-provider into lp:ubuntu-ui-toolkit

Proposed by Lars Karlitski
Status: Superseded
Proposed branch: lp:~larsu/ubuntu-ui-toolkit/add-unity-theme-icon-provider
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 128 lines (+79/-3)
4 files modified
modules/Ubuntu/Components/plugin/plugin.cpp (+3/-1)
modules/Ubuntu/Components/plugin/plugin.pro (+4/-2)
modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp (+41/-0)
modules/Ubuntu/Components/plugin/unitythemeiconprovider.h (+31/-0)
To merge this branch: bzr merge lp:~larsu/ubuntu-ui-toolkit/add-unity-theme-icon-provider
Reviewer Review Type Date Requested Status
Nick Dedekind (community) Needs Fixing
Zsombor Egri Needs Fixing
Antti Kaijanmäki (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+179011@code.launchpad.net

This proposal has been superseded by a proposal from 2013-08-19.

Commit message

Add UnityThemeIconProvider

A QQuickImageProvider that loads icons from the current icon theme, following the xdg icon spec. It can be used like this:

  image://theme/icon-name,fallback-icon-name,another-fallback-icon-name

Description of the change

Add UnityThemeIconProvider

A QQuickImageProvider that loads icons from the current icon theme, following the xdg icon spec. It can be used like this:

  image://theme/icon-name,fallback-icon-name,another-fallback-icon-name

This is supposed to replace the gicon provider. I left that one in for now because it's still used by some components.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

Looks valid! I need this for the Launcher. Somebody, please, top approve.

review: Approve
Revision history for this message
Zsombor Egri (zsombi) wrote :

Unit tests testing API and component functionality is missing. The MR cannot be approved without that.
Code wise looks good.

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

Getting fuzzy icons.
Please use available sizes if not provided.

QIcon themedIcon = QIcon::fromTheme(id);
if (requestedSize.isValid()) {
    return themedIcon.pixmap(requestedSize);
} else {
    return themedIcon.pixmap(themedIcon.availableSizes().last());
}

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

Actually a more robust solution:
I've proposed these changes to qmenumodel where this provider currently resides.

    if (!icon.isNull()) {
        if (requestedSize.isValid()) {
            return themedIcon.pixmap(requestedSize);
        } else {
            QList<QSize> sizes = icon.availableSizes();
            if (sizes.count() > 0 && sizes.last().isValid()) {
                return icon.pixmap(sizes.last());
            } else {
                return icon.pixmap(QSize(32,32));
            }
        }
    }
    return QPixmap();

Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

superseding this one with a public branch MR.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/plugin.cpp'
2--- modules/Ubuntu/Components/plugin/plugin.cpp 2013-07-29 11:38:38 +0000
3+++ modules/Ubuntu/Components/plugin/plugin.cpp 2013-08-07 16:20:41 +0000
4@@ -42,6 +42,7 @@
5 #include "ucfontutils.h"
6 #include "ucarguments.h"
7 #include "ucargument.h"
8+#include "unitythemeiconprovider.h"
9
10 #include <sys/types.h>
11 #include <unistd.h>
12@@ -180,8 +181,9 @@
13
14 engine->addImageProvider(QLatin1String("scaling"), new UCScalingImageProvider);
15
16- // register gicon provider
17+ // register icon providers
18 engine->addImageProvider(QLatin1String("gicon"), new GIconProvider);
19+ engine->addImageProvider(QLatin1String("theme"), new UnityThemeIconProvider);
20
21 // Necessary for Screen.orientation (from import QtQuick.Window 2.0) to work
22 QGuiApplication::primaryScreen()->setOrientationUpdateMask(
23
24=== modified file 'modules/Ubuntu/Components/plugin/plugin.pro'
25--- modules/Ubuntu/Components/plugin/plugin.pro 2013-07-09 22:14:33 +0000
26+++ modules/Ubuntu/Components/plugin/plugin.pro 2013-08-07 16:20:41 +0000
27@@ -41,7 +41,8 @@
28 ucubuntuanimation.h \
29 ucfontutils.h \
30 ucarguments.h \
31- ucargument.h
32+ ucargument.h \
33+ unitythemeiconprovider.h
34
35 SOURCES += plugin.cpp \
36 uctheme.cpp \
37@@ -61,7 +62,8 @@
38 ucubuntuanimation.cpp \
39 ucfontutils.cpp \
40 ucarguments.cpp \
41- ucargument.cpp
42+ ucargument.cpp \
43+ unitythemeiconprovider.cpp
44
45 # deployment rules for the plugin
46 installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
47
48=== added file 'modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp'
49--- modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 1970-01-01 00:00:00 +0000
50+++ modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 2013-08-07 16:20:41 +0000
51@@ -0,0 +1,41 @@
52+/*
53+ * Copyright 2013 Canonical Ltd.
54+ *
55+ * This program is free software; you can redistribute it and/or modify
56+ * it under the terms of the GNU Lesser General Public License as published by
57+ * the Free Software Foundation; version 3.
58+ *
59+ * This program is distributed in the hope that it will be useful,
60+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
61+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62+ * GNU Lesser General Public License for more details.
63+ *
64+ * You should have received a copy of the GNU Lesser General Public License
65+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
66+ *
67+ * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
68+ */
69+
70+#include "unitythemeiconprovider.h"
71+
72+#include <QIcon>
73+
74+UnityThemeIconProvider::UnityThemeIconProvider():
75+ QQuickImageProvider(QQuickImageProvider::Pixmap)
76+{
77+}
78+
79+QPixmap UnityThemeIconProvider::requestPixmap(const QString &id, QSize *realSize, const QSize &requestedSize)
80+{
81+ QIcon icon;
82+
83+ Q_FOREACH (QString name, id.split(",", QString::SkipEmptyParts)) {
84+ icon = QIcon::fromTheme(name);
85+ if (!icon.isNull())
86+ break;
87+ }
88+
89+ QPixmap pixmap = icon.pixmap(requestedSize.isValid() ? requestedSize : QSize(64, 64));
90+ *realSize = pixmap.size();
91+ return pixmap;
92+}
93
94=== added file 'modules/Ubuntu/Components/plugin/unitythemeiconprovider.h'
95--- modules/Ubuntu/Components/plugin/unitythemeiconprovider.h 1970-01-01 00:00:00 +0000
96+++ modules/Ubuntu/Components/plugin/unitythemeiconprovider.h 2013-08-07 16:20:41 +0000
97@@ -0,0 +1,31 @@
98+/*
99+ * Copyright 2013 Canonical Ltd.
100+ *
101+ * This program is free software; you can redistribute it and/or modify
102+ * it under the terms of the GNU Lesser General Public License as published by
103+ * the Free Software Foundation; version 3.
104+ *
105+ * This program is distributed in the hope that it will be useful,
106+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
107+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108+ * GNU Lesser General Public License for more details.
109+ *
110+ * You should have received a copy of the GNU Lesser General Public License
111+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
112+ *
113+ * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
114+ */
115+
116+#ifndef UNITY_THEME_ICON_PROVIDER_H
117+#define UNITY_THEME_ICON_PROVIDER_H
118+
119+#include <QQuickImageProvider>
120+
121+class UnityThemeIconProvider: public QQuickImageProvider
122+{
123+public:
124+ UnityThemeIconProvider();
125+ QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
126+};
127+
128+#endif

Subscribers

People subscribed via source and target branches

to status/vote changes: