Commit e239b429 authored by Aleksi Suomalainen's avatar Aleksi Suomalainen Committed by GitHub

Merge pull request #43 from eekkelund/icon-provider

Add fontawesome icons to image provider Glacier#884
parents e4cfec83 bcb99bee
/****************************************************************************************
**
** Copyright (C) 2017 Eetu Kahelin
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
import QtQuick 2.6
import QtQuick.Controls 1.0 //needed for the Stack attached property
import QtQuick.Controls.Nemo 1.0
import QtQuick.Controls.Styles.Nemo 1.0
Page {
id: root
headerTools: HeaderToolsLayout { showBackButton: true; title: "Icon example" }
allowedOrientations: Qt.PortraitOrientation | Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation | Qt.InvertedPortraitOrientation
Column {
spacing: Theme.itemSpacingMedium
anchors.centerIn: parent
//fontawesome
IconButton {
source: "image://theme/compass"
}
//fontawesome
IconButton {
width: height
height: Theme.itemHeightExtraLarge
source: "image://theme/bell"
enabled:false
}
//fontawesome
IconButton {
source: "image://theme/address-book?" + Theme.fillColor
}
//glacier
IconButton {
width: height
height: Theme.itemHeightExtraLarge
source: "image://theme/icon-m-framework-close-thumbnail"
}
}
}
...@@ -116,6 +116,10 @@ ApplicationWindow { ...@@ -116,6 +116,10 @@ ApplicationWindow {
title: "Query Dialog" title: "Query Dialog"
page: "content/QueryDialogPage.qml" page: "content/QueryDialogPage.qml"
} }
ListElement {
title: "Icons"
page: "content/IconPage.qml"
}
} }
......
...@@ -24,29 +24,15 @@ qml.files += \ ...@@ -24,29 +24,15 @@ qml.files += \
content/ButtonRowPage.qml \ content/ButtonRowPage.qml \
content/QueryDialogPage.qml \ content/QueryDialogPage.qml \
content/ListViewPage.qml \ content/ListViewPage.qml \
content/SelectRollerPage.qml content/SelectRollerPage.qml \
content/IconPage.qml
qml.path = /usr/share/glacier-components/content qml.path = /usr/share/glacier-components/content
images.files = images/*.png images.files = images/*.png
images.path = /usr/share/glacier-components/images images.path = /usr/share/glacier-components/images
OTHER_FILES += \ OTHER_FILES += $$qml.files
main.qml \
content/AndroidDelegate.qml \
content/ButtonPage.qml \
content/ProgressBarPage.qml \
content/SliderPage.qml \
content/TabBarPage.qml \
content/TextInputPage.qml \
content/LiveCoding.qml \
content/SpinnerPage.qml \
content/LabelPage.qml \
content/CheckboxPage.qml \
content/ButtonRowPage.qml \
content/QueryDialogPage.qml \
content/ListViewPage.qml \
content/SelectRollerPage.qml
desktop.path = /usr/share/applications desktop.path = /usr/share/applications
......
/****************************************************************************************
**
** Copyright (C) 2017 Eetu Kahelin
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
import QtQuick 2.6
import QtQuick.Controls 1.0
import QtQuick.Controls.Nemo 1.0
import QtQuick.Controls.Styles.Nemo 1.0
Button {
property color highlightColor: Theme.accentColor
property bool highlighted: pressed
property bool _showPress: highlighted || pressTimer.running
property string source
property string highlightSource: {
if (source != "") {
var tmpSrc = source.toString()
var i = tmpSrc.lastIndexOf("?")
if (i !== -1) {
tmpSrc = tmpSrc.substring(0, i)
}
return tmpSrc + "?" + highlightColor
} else {
return ""
}
}
onPressedChanged: {
if (pressed) {
pressTimer.start()
}
}
width: Theme.itemHeightLarge
height: width
style: IconButtonStyle { }
Timer {
id: pressTimer
interval: 20
}
}
...@@ -21,7 +21,8 @@ QML_FILES += \ ...@@ -21,7 +21,8 @@ QML_FILES += \
ListView.qml \ ListView.qml \
ListViewItemWithActions.qml\ ListViewItemWithActions.qml\
GlacierRoller.qml \ GlacierRoller.qml \
GlacierRollerItem.qml GlacierRollerItem.qml \
IconButton.qml
OTHER_FILES += qmldir \ OTHER_FILES += qmldir \
$$QML_FILES $$QML_FILES
......
...@@ -30,3 +30,8 @@ QImage NemoImageProvider::requestImage(const QString &id, QSize *size, const QSi ...@@ -30,3 +30,8 @@ QImage NemoImageProvider::requestImage(const QString &id, QSize *size, const QSi
Q_UNUSED(requestedSize); Q_UNUSED(requestedSize);
return m_client->readImage(id); return m_client->readImage(id);
} }
QPixmap NemoImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
Q_UNUSED(size);
return m_client->requestPixmap(id,requestedSize);
}
...@@ -27,6 +27,7 @@ class NemoImageProvider : public QQuickImageProvider ...@@ -27,6 +27,7 @@ class NemoImageProvider : public QQuickImageProvider
public: public:
explicit NemoImageProvider(); explicit NemoImageProvider();
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize); QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
private: private:
MLocalThemeDaemonClient* m_client; MLocalThemeDaemonClient* m_client;
}; };
......
...@@ -23,6 +23,7 @@ ListView 1.0 ListView.qml ...@@ -23,6 +23,7 @@ ListView 1.0 ListView.qml
ListViewItemWithActions 1.0 ListViewItemWithActions.qml ListViewItemWithActions 1.0 ListViewItemWithActions.qml
GlacierRoller 1.0 GlacierRoller.qml GlacierRoller 1.0 GlacierRoller.qml
GlacierRollerItem 1.0 GlacierRollerItem.qml GlacierRollerItem 1.0 GlacierRollerItem.qml
IconButton 1.0 IconButton.qml
# MIRRORED CONTROLS: # MIRRORED CONTROLS:
# These are the controls that we take directly from official QQC. # These are the controls that we take directly from official QQC.
......
...@@ -48,9 +48,9 @@ MLocalThemeDaemonClient::MLocalThemeDaemonClient(const QString &testPath, QObjec ...@@ -48,9 +48,9 @@ MLocalThemeDaemonClient::MLocalThemeDaemonClient(const QString &testPath, QObjec
MAbstractThemeDaemonClient(parent), MAbstractThemeDaemonClient(parent),
m_pixmapCache(), m_pixmapCache(),
m_imageDirNodes() m_imageDirNodes()
#ifdef HAVE_MLITE #ifdef HAVE_MLITE
, themeItem("/meegotouch/theme/name") , themeItem("/meegotouch/theme/name")
#endif #endif
{ {
QStringList themeRoots; QStringList themeRoots;
QString themeRoot = testPath; QString themeRoot = testPath;
...@@ -111,6 +111,7 @@ MLocalThemeDaemonClient::MLocalThemeDaemonClient(const QString &testPath, QObjec ...@@ -111,6 +111,7 @@ MLocalThemeDaemonClient::MLocalThemeDaemonClient(const QString &testPath, QObjec
inheritanceChain.insert(nextTheme); inheritanceChain.insert(nextTheme);
// the paths should be stored in reverse order than in the inheritance chain // the paths should be stored in reverse order than in the inheritance chain
themeRoots.prepend(themeRoot + QDir::separator() + nextTheme + QDir::separator() + QLatin1String("meegotouch")); themeRoots.prepend(themeRoot + QDir::separator() + nextTheme + QDir::separator() + QLatin1String("meegotouch"));
themeRoots.prepend(themeRoot + QDir::separator() + nextTheme + QDir::separator() + QLatin1String("fontawesome"));
QString parentTheme = themeIndexFile.value("X-MeeGoTouch-Metatheme/X-Inherits", "").toString(); QString parentTheme = themeIndexFile.value("X-MeeGoTouch-Metatheme/X-Inherits", "").toString();
...@@ -148,7 +149,8 @@ MLocalThemeDaemonClient::~MLocalThemeDaemonClient() ...@@ -148,7 +149,8 @@ MLocalThemeDaemonClient::~MLocalThemeDaemonClient()
QPixmap MLocalThemeDaemonClient::requestPixmap(const QString &id, const QSize &requestedSize) QPixmap MLocalThemeDaemonClient::requestPixmap(const QString &id, const QSize &requestedSize)
{ {
QPixmap pixmap; QPixmap pixmap;
qDebug() << "ID requested: " << id;
QStringList parts = id.split('?');
QSize size = requestedSize; QSize size = requestedSize;
if (size.width() < 1) { if (size.width() < 1) {
...@@ -158,20 +160,30 @@ QPixmap MLocalThemeDaemonClient::requestPixmap(const QString &id, const QSize &r ...@@ -158,20 +160,30 @@ QPixmap MLocalThemeDaemonClient::requestPixmap(const QString &id, const QSize &r
size.rheight() = 0; size.rheight() = 0;
} }
const PixmapIdentifier pixmapId(id, size); const PixmapIdentifier pixmapId(parts.at(0), size);
pixmap = m_pixmapCache.value(pixmapId); pixmap = m_pixmapCache.value(pixmapId);
if (pixmap.isNull()) { if (pixmap.isNull()) {
// The pixmap is not cached yet. Decode the image and // The pixmap is not cached yet. Decode the image and
// store it into the cache as pixmap. // store it into the cache as pixmap.
const QImage image = readImage(id); const QImage image = readImage(parts.at(0));
if (!image.isNull()) { if (!image.isNull()) {
pixmap = QPixmap::fromImage(image); pixmap = QPixmap::fromImage(image);
if (requestedSize.isValid() && (pixmap.size() != requestedSize)) { }
pixmap = pixmap.scaled(requestedSize); if (parts.length() > 1)
if (parts.length() > 1 && QColor::isValidColor(parts.at(1)))
{
QPainter painter(&pixmap);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.fillRect(pixmap.rect(), parts.at(1));
painter.end();
} }
m_pixmapCache.insert(pixmapId, pixmap); if (requestedSize.width() > 0 && requestedSize.height() > 0)
} pixmap = pixmap.scaled(requestedSize.width(), requestedSize.height(), Qt::IgnoreAspectRatio);
else
pixmap = pixmap;
m_pixmapCache.insert(pixmapId, pixmap);
} }
return pixmap; return pixmap;
} }
......
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#include <QHash> #include <QHash>
#include <QPixmap> #include <QPixmap>
#include <QString> #include <QString>
#include <QPainter>
#include <QColor>
#ifdef HAVE_MLITE #ifdef HAVE_MLITE
#include <mgconfitem.h> #include <mgconfitem.h>
......
...@@ -46,7 +46,7 @@ ButtonStyle { ...@@ -46,7 +46,7 @@ ButtonStyle {
RadialGradient { RadialGradient {
x: control.pressX - width/2 x: control.pressX - width/2
y: control.pressY - height/2 y: control.pressY - height/2
width: Theme.itemWidthMedium width: Theme.itemWidthSmall
height: width height: width
visible: control.pressed visible: control.pressed
......
/****************************************************************************************
**
** Copyright (C) 2017 Eetu Kahelin
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
import QtQuick 2.6
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0
ButtonStyle {
background: Image {
fillMode: Image.PreserveAspectFit
opacity: control.enabled ? 1.0 : 0.5
source:control._showPress ? control.highlightSource : control.source
}
}
...@@ -20,3 +20,4 @@ SpinBoxStyle 1.0 SpinBoxStyle.qml ...@@ -20,3 +20,4 @@ SpinBoxStyle 1.0 SpinBoxStyle.qml
TabViewStyle 1.0 TabViewStyle.qml TabViewStyle 1.0 TabViewStyle.qml
TableViewStyle 1.0 TableViewStyle.qml TableViewStyle 1.0 TableViewStyle.qml
TextFieldStyle 1.0 TextFieldStyle.qml TextFieldStyle 1.0 TextFieldStyle.qml
IconButtonStyle 1.0 IconButtonStyle.qml
...@@ -27,6 +27,7 @@ QML_FILES = \ ...@@ -27,6 +27,7 @@ QML_FILES = \
TextFieldStyle.qml \ TextFieldStyle.qml \
ToolBarStyle.qml \ ToolBarStyle.qml \
ToolButtonStyle.qml \ ToolButtonStyle.qml \
IconButtonStyle.qml
# Images # Images
QML_FILES += \ QML_FILES += \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment