- Use more font-awesome icons - for repeat, random, menu (on windows)

- Use SVG for consume
This commit is contained in:
Craig Drummond
2016-01-19 22:49:59 +00:00
committed by Craig Drummond
parent aee9b4f0e0
commit fb6a7aee07
17 changed files with 67 additions and 260 deletions

View File

@@ -1,15 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="stars.svg">icons/stars.svg</file>
<file alias="repeat16.png">icons/view-media-repeat16.png</file>
<file alias="repeat22.png">icons/view-media-repeat22.png</file>
<file alias="repeat24.png">icons/view-media-repeat24.png</file>
<file alias="repeat32.png">icons/view-media-repeat32.png</file>
<file alias="shuffle16.png">icons/view-media-shuffle16.png</file>
<file alias="shuffle22.png">icons/view-media-shuffle22.png</file>
<file alias="shuffle24.png">icons/view-media-shuffle24.png</file>
<file alias="shuffle32.png">icons/view-media-shuffle32.png</file>
<file alias="consume.svg">icons/consume.svg</file>
<file alias="sidebar-library">icons/sidebar-library.svg</file>
<file alias="sidebar-devices">icons/sidebar-devices.svg</file>

7
icons/consume.svg Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg id="svg2211" xmlns="http://www.w3.org/2000/svg" height="42.28" width="42.28" version="1.0">
<g id="layer2" transform="translate(.645 15.11)" stroke="#000">
<path id="path3178" d="m24.473 7.9a11.4 11.4 0 0 1 -12.824 5.312 11.4 11.4 0 0 1 -8.449 -11.012 11.4 11.4 0 0 1 8.449 -11.012 11.4 11.4 0 0 1 12.824 5.312l-9.873 5.7z" transform="matrix(1.5736 0 0 1.4684 -1.1223 2.5823)" stroke-width="3" fill="none"/>
<path id="path4158" d="m20-6a1 1 0 0 1 -1 1 1 1 0 0 1 -1 -1 1 1 0 0 1 1 -1 1 1 0 0 1 1 1z" transform="matrix(1.5748 0 0 1.4684 -8.0682 4.3444)" stroke-width="3.5"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 468 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 934 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 924 B

View File

@@ -64,40 +64,59 @@ public:
QPainter p(&pix);
if (fileName.isEmpty()) {
// Load fontawesome, if it is not already loaded
if (fontAwesomeFontName.isEmpty()) {
Q_INIT_RESOURCE(fontawesome);
QFile res(":fontawesome-4.3.0.ttf");
res.open(QIODevice::ReadOnly);
QByteArray fontData( res.readAll() );
res.close();
QString fontName;
double scale=0.9;
if (FontAwesome::ex_one==fontAwesomeIcon) {
fontName="serif";
} else {
// Load fontawesome, if it is not already loaded
if (fontAwesomeFontName.isEmpty()) {
Q_INIT_RESOURCE(fontawesome);
QFile res(":fontawesome-4.3.0.ttf");
res.open(QIODevice::ReadOnly);
QByteArray fontData( res.readAll() );
res.close();
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(QFontDatabase::addApplicationFontFromData(fontData));
if (!loadedFontFamilies.empty()) {
fontAwesomeFontName= loadedFontFamilies.at(0);
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(QFontDatabase::addApplicationFontFromData(fontData));
if (!loadedFontFamilies.empty()) {
fontAwesomeFontName= loadedFontFamilies.at(0);
}
}
}
double scale=1.0;
switch (fontAwesomeIcon) {
case FontAwesome::lastfmsquare:
case FontAwesome::lastfm:
scale=1.1;
break;
case FontAwesome::list:
if (!Utils::isHighDpi()) {
scale=1.05;
switch (fontAwesomeIcon) {
case FontAwesome::lastfmsquare:
case FontAwesome::lastfm:
scale=1.1;
break;
case FontAwesome::list:
if (!Utils::isHighDpi()) {
scale=1.05;
}
break;
default:
break;
}
default:
scale=0.9;
break;
fontName=fontAwesomeFontName;
}
QFont font(fontAwesomeFontName);
QFont font(fontName);
font.setPixelSize(qRound(rect.height()*scale));
if (FontAwesome::ex_one==fontAwesomeIcon) {
font.setBold(true);
}
p.setFont(font);
p.setPen(col);
p.drawText(QRect(0, 0, rect.width(), rect.height()), QString(QChar(static_cast<int>(fontAwesomeIcon))), QTextOption(Qt::AlignCenter|Qt::AlignVCenter));
p.setRenderHint(QPainter::HighQualityAntialiasing, true);
if (FontAwesome::ex_one==fontAwesomeIcon) {
QString str=QString::number(fontAwesomeIcon);
p.drawText(QRect(0, 0, rect.width(), rect.height()), str, QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
p.drawText(QRect(1, 0, rect.width(), rect.height()), str, QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
#ifndef Q_OS_MAC
p.drawText(QRect(-1, 0, rect.width(), rect.height()), str, QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
#endif
} else {
p.drawText(QRect(0, 0, rect.width(), rect.height()), QString(QChar(static_cast<int>(fontAwesomeIcon))), QTextOption(Qt::AlignCenter|Qt::AlignVCenter));
}
} else {
QSvgRenderer renderer;
QFile f(fileName);

View File

@@ -36,6 +36,8 @@
*/
namespace FontAwesome {
enum icon {
ex_one = 0x0001,
adjust = 0xf042,
adn = 0xf170,
aligncenter = 0xf037,

View File

@@ -20,46 +20,32 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <QDebug>
#include "icons.h"
#include "treeview.h"
#include "config.h"
#include "gui/settings.h"
#include "support/globalstatic.h"
#include "support/utils.cpp"
#include "support/utils.h"
#include "support/pathrequester.h"
#include "support/monoicon.h"
#include <QApplication>
#include <QPixmap>
#include <QFont>
#include <QPainter>
#include <QPalette>
#include <QDir>
#include <QFile>
#include <math.h>
#if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined ENABLE_UBUNTU
#include "support/gtkstyle.h"
#endif
#ifdef Q_OS_MAC
#include "support/osxstyle.h"
#endif
#include <QApplication>
#include <QPalette>
#include <QDir>
#include <QFile>
GLOBAL_STATIC(Icons, instance)
static QList<int> constStdSmallSizes=QList<int>() << 16 << 22 << 32 ;
static QList<int> constStdSizes=QList<int>() << constStdSmallSizes << 48; // << 64;
static QList<int> constMonoSvgSizes=QList<int>() << constStdSizes << 64;
static QList<int> constStdSizes=QList<int>() << 16 << 22 << 32 << 48; // << 64;
static const int constDarkLimit=80;
static const int constDarkValue=64;
static const int constLightLimit=240;
static const int constLightValue=240;
static bool inline isLight(const QColor &col)
{
return col.red()>100 && col.blue()>100 && col.green()>100;
}
static bool inline isVeryLight(const QColor &col, int limit=constLightValue)
{
return col.red()>=limit && col.blue()>=limit && col.green()>=limit;
@@ -80,113 +66,6 @@ static QColor clampColor(const QColor &color, int darkLimit=constDarkLimit, int
: color;
}
static QPixmap createSingleIconPixmap(int size, const QColor &col, double opacity=1.0)
{
QPixmap pix(size, size);
pix.fill(Qt::transparent);
QPainter p(&pix);
QFont font(QLatin1String("sans"));
font.setBold(false);
font.setItalic(false);
font.setPixelSize(size*0.9);
p.setFont(font);
p.setPen(col);
p.setOpacity(opacity);
p.setRenderHint(QPainter::Antialiasing, true);
p.drawText(QRect(0, 1, size, size), QLatin1String("1"), QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
p.drawText(QRect(1, 1, size, size), QLatin1String("1"), QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
p.drawText(QRect(-1, 1, size, size), QLatin1String("1"), QTextOption(Qt::AlignHCenter|Qt::AlignVCenter));
p.end();
return pix;
}
static QPixmap createConsumeIconPixmap(int size, const QColor &col, double opacity=1.0)
{
QPixmap pix(size, size);
pix.fill(Qt::transparent);
QPainter p(&pix);
int border=2;
if (22==size) {
border=3;
} else if (32==size) {
border=4;
} else if (48==size) {
border=5;
} else if (48==size) {
border=7;
} /*else if (64==size) {
border=6;
}*/
p.setPen(QPen(col, size/8.0));
p.setOpacity(opacity);
p.setRenderHint(QPainter::Antialiasing, true);
QRectF rect(border+0.5, border+0.5, size-(2*border), size-(2*border));
double distanceX=fabs(cos(35.0))*(rect.width()/2);
double distanceY=fabs(sin(35.0))*(rect.height()/2);
double midX=rect.x()+(rect.width()/2);
double midY=rect.y()+(rect.height()/2);
p.drawArc(rect, 40*16, 290*16);
p.drawLine(midX, midY, midX+distanceX, midY-distanceY);
p.drawLine(midX, midY, midX+distanceX, midY+distanceY);
p.drawPoint(midX, rect.y()+rect.height()/4);
p.end();
return pix;
}
#ifndef USE_SYSTEM_MENU_ICON
static QPixmap createMenuIconPixmap(int size, QColor col, double opacity=1.0)
{
static const int constShadeFactor=75;
QPixmap pix(size, size);
pix.fill(Qt::transparent);
QPainter p(&pix);
int lineWidth=3;
int space=2;
int borderX=1;
if (22==size) {
lineWidth=3;
space=3;
borderX=2;
} else if (32==size) {
lineWidth=5;
space=5;
borderX=3;
} else if (48==size) {
lineWidth=8;
space=6;
borderX=4;
} /*else if (64==size) {
lineWidth=10;
space=10;
borderX=6;
}*/
int borderY=((size-((3*lineWidth)+(2*space)))/2.0)+0.5;
p.setOpacity(opacity);
p.setRenderHint(QPainter::Antialiasing, true);
bool light=isLight(col);
if (light) {
col=col.darker(constShadeFactor);
} else {
col=col.lighter(constShadeFactor);
}
for (int i=0; i<3; ++i) {
int offset=i*(space+lineWidth);
QRectF rect(borderX+0.5, borderY+offset, size-(2*borderX), lineWidth);
QLinearGradient grad(rect.topLeft(), rect.bottomLeft());
col.setAlphaF(light ? 0.5 : 1.0);
grad.setColorAt(0, col);
col.setAlphaF(light ? 1.0 : 0.5);
grad.setColorAt(1, col);
p.fillPath(Utils::buildPath(rect, lineWidth/2.0), grad);
}
p.end();
return pix;
}
#endif
static QColor calcIconColor()
{
QColor bgnd=QApplication::palette().color(QPalette::Active, QPalette::Background);
@@ -194,98 +73,6 @@ static QColor calcIconColor()
return clampColor(text, constDarkLimit, bgnd.value()<224 ? 32 : 48);
}
static Icon createSingleIcon(const QColor &stdColor)
{
Icon icon;
foreach (int s, constStdSmallSizes) {
icon.addPixmap(createSingleIconPixmap(s, stdColor));
}
return icon;
}
static Icon createConsumeIcon(const QColor &stdColor)
{
Icon icon;
foreach (int s, constStdSmallSizes) {
icon.addPixmap(createConsumeIconPixmap(s, stdColor));
}
return icon;
}
#ifndef USE_SYSTEM_MENU_ICON
static Icon createMenuIcon(const QColor &stdColor)
{
Icon icon;
foreach (int s, constStdSizes) {
icon.addPixmap(createMenuIconPixmap(s, stdColor));
}
return icon;
}
#endif
static void recolourPix(QImage &img, const QColor &col, double opacity=1.0)
{
unsigned char *data=img.bits();
int numChannels=4;
int w=img.width();
int h=img.height();
int stride=img.bytesPerLine();
int r=col.red();
int g=col.green();
int b=col.blue();
int width=w*numChannels;
int offset=0;
for(int row=0; row<h; ++row) {
for(int column=0; column<width; column+=numChannels) {
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
/* ARGB */
data[offset+column]*=opacity;
data[offset+column+1] = r;
data[offset+column+2] = g;
data[offset+column+3] = b;
#else
/* BGRA */
data[offset+column] = b;
data[offset+column+1] = g;
data[offset+column+2] = r;
data[offset+column+3]*=opacity;
#endif
}
offset+=stride;
}
}
static QPixmap recolour(const QImage &img, const QColor &col, double opacity=1.0)
{
QImage i=img;
if (i.depth()!=32) {
i=i.convertToFormat(QImage::Format_ARGB32);
}
recolourPix(i, col, opacity);
return QPixmap::fromImage(i);
}
static Icon createRecolourableIcon(const QString &name, const QColor &stdColor, int extraSize=24)
{
if (QColor(Qt::black)==stdColor) {
// Text colour is black, so is icon, therefore no need to recolour!!!
return Icon::create(name, constStdSizes);
}
Icon icon;
QList<int> sizes=QList<int>() << constStdSizes << extraSize;
foreach (int s, sizes) {
QImage img(QChar(':')+name+QString::number(s));
if (!img.isNull()) {
icon.addPixmap(recolour(img, stdColor));
}
}
return icon;
}
#if !defined ENABLE_KDE_SUPPORT || defined Q_OS_MAC || defined Q_OS_WIN
#define ALWAYS_USE_MONO_ICONS
#endif
@@ -295,12 +82,12 @@ Icons::Icons()
QColor stdColor=calcIconColor();
QColor red(220, 0, 0);
singleIcon=createSingleIcon(stdColor);
consumeIcon=createConsumeIcon(stdColor);
singleIcon=MonoIcon::icon(FontAwesome::ex_one, stdColor, stdColor);
consumeIcon=MonoIcon::icon(":consume.svg", stdColor, stdColor);
#ifdef USE_SYSTEM_MENU_ICON
menuIcon=Icon("applications-system");
#else
menuIcon=createMenuIcon(stdColor);
menuIcon=MonoIcon::icon(FontAwesome::bars, stdColor, stdColor);
#endif
QString iconFile=QString(CANTATA_SYS_ICONS_DIR+"stream.png");
@@ -316,8 +103,8 @@ Icons::Icons()
folderIcon=Icon("inode-directory");
dynamicRuleIcon=Icon(QStringList() << "dynamic-playlist" << "media-playlist-shuffle" << "text-x-generic");
speakerIcon=Icon(QStringList() << "speaker" << "audio-speakers" << "gnome-volume-control");
repeatIcon=createRecolourableIcon("repeat", stdColor);
shuffleIcon=createRecolourableIcon("shuffle", stdColor);
repeatIcon=MonoIcon::icon(FontAwesome::refresh, stdColor, stdColor);
shuffleIcon=MonoIcon::icon(FontAwesome::random, stdColor, stdColor);
filesIcon=Icon(QStringList() << "folder-downloads" << "folder-download" << "folder" << "go-down");
radioStreamIcon=Icon::create("radio", constStdSizes);
addRadioStreamIcon=Icon::create("addradio", constStdSizes);
@@ -428,7 +215,7 @@ void Icons::initToolbarIcons(const QColor &toolbarText)
if (col==stdColor) {
toolbarMenuIcon=menuIcon;
} else {
toolbarMenuIcon=createMenuIcon(col);
toolbarMenuIcon=MonoIcon::icon(FontAwesome::bars, col, col);
}
#endif
}