Skip to content

Commit

Permalink
work on custom icon
Browse files Browse the repository at this point in the history
  • Loading branch information
wdehoog committed Jul 14, 2018
1 parent e8ee289 commit 6d900fd
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 8 deletions.
3 changes: 2 additions & 1 deletion playspot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ HEADERS += \
src/o2/o2reply.h \
src/o2/o2replyserver.h \
src/o2/o2spotify.h \
src/spotify.h
src/spotify.h \
src/IconProvider.h

#QMAKE_LFLAGS += -lavahi-client -lavahi-common
8 changes: 5 additions & 3 deletions qml/components/MenuButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ IconButton {
height: icon.height

x: Theme.paddingMedium
y: Theme.paddingMedium
icon.height: Theme.iconSizeMedium
y: Theme.paddingLarge*1.5
icon.height: Theme.iconSizeSmall
icon.fillMode: Image.PreserveAspectFit
icon.source: "image://theme/icon-m-menu" /*navPanel.expanded
icon.source: "image://hutspot-icons/icon-m-toolbar"

/*"image://theme/icon-m-menu" navPanel.expanded
? "image://theme/icon-m-down"
: "image://theme/icon-m-up"*/
onClicked: {
Expand Down
Binary file added qml/icons/icon-m-toolbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions qml/pages/Playing.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ Page {
}
}

PushUpMenu {
MenuItem {
text: qsTr("Login")
onClicked: spotify.doO2Auth(Spotify._scope, app.auth_using_browser.value)
}
MenuItem {
text: qsTr("Refresh Token")
onClicked: spotify.refreshToken()
}
}

/* playbackState
.context type uri
.is_playing
Expand Down
42 changes: 42 additions & 0 deletions src/IconProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef ICONPROVIDER_H
#define ICONPROVIDER_H

#include <sailfishapp.h>
#include <QQuickImageProvider>
#include <QPainter>
#include <QColor>

class IconProvider : public QQuickImageProvider
{
public:
IconProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap)
{
}

QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
QStringList parts = id.split('?');

QPixmap sourcePixmap(SailfishApp::pathTo("qml/icons/" + parts.at(0) + ".png").toString(QUrl::RemoveScheme));

if (size)
*size = sourcePixmap.size();

if (parts.length() > 1)
if (QColor::isValidColor(parts.at(1)))
{
QPainter painter(&sourcePixmap);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.fillRect(sourcePixmap.rect(), parts.at(1));
painter.end();
}

if (requestedSize.width() > 0 && requestedSize.height() > 0)
return sourcePixmap.scaled(requestedSize.width(), requestedSize.height(), Qt::IgnoreAspectRatio);
else
return sourcePixmap;
}
};

#endif // ICONPROVIDER_H

5 changes: 5 additions & 0 deletions src/hutspot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <sailfishapp.h>

#include "IconProvider.h"
#include "spotify.h"
//#include "servicebrowser.h"

Expand All @@ -31,6 +32,10 @@ int main(int argc, char *argv[])
Spotify spotify;
view->rootContext()->setContextProperty("spotify", &spotify);

// custom icon loader
QQmlEngine *engine = view->engine();
engine->addImageProvider(QLatin1String("hutspot-icons"), new IconProvider);

// ServiceBrowser serviceBrowser;
// view->rootContext()->setContextProperty("serviceBrowser", &serviceBrowser);

Expand Down
18 changes: 14 additions & 4 deletions translations/hutspot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,22 +359,32 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Playing.qml" line="119"/>
<location filename="../qml/pages/Playing.qml" line="83"/>
<source>Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Playing.qml" line="87"/>
<source>Refresh Token</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Playing.qml" line="130"/>
<source>no artist known</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Playing.qml" line="292"/>
<location filename="../qml/pages/Playing.qml" line="303"/>
<source>No Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Playing.qml" line="316"/>
<location filename="../qml/pages/Playing.qml" line="327"/>
<source>No tracks found</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Playing.qml" line="388"/>
<location filename="../qml/pages/Playing.qml" line="399"/>
<source>Connection lost with Spotify servers</source>
<translation type="unfinished"></translation>
</message>
Expand Down

0 comments on commit 6d900fd

Please sign in to comment.