Commit 47b4c206 authored by Doug Beney's avatar Doug Beney

Initial commit

parents
# Emacs
*~
*#
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.dll
*.dylib
# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
QT += core gui widgets
TARGET = CrossPlatformIconsExample
CONFIG += c++11
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
library-files/crossplatformicon.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
library-files/crossplatformicon.h
INCLUDEPATH += library-files
RESOURCES += \
icons.qrc
<RCC>
<qresource prefix="/">
<file>icons/elementary/actions/16/mail-reply-sender.svg</file>
<file>icons/elementary/index.theme</file>
<file>icons/elementary/custom/cool-tux-penguin.png</file>
</qresource>
</RCC>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
id="svg3842"
height="16"
width="16"
version="1.1">
<defs
id="defs3844">
<linearGradient
id="linearGradient833">
<stop
id="stop829"
offset="0"
style="stop-color:#cd9ef7;stop-opacity:1" />
<stop
id="stop831"
offset="1"
style="stop-color:#a56de2;stop-opacity:1" />
</linearGradient>
<linearGradient
gradientTransform="matrix(0,-0.39447799,-0.42344634,0,16.496307,18.346218)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient4087-5"
id="linearGradient3842"
y2="15.991243"
x2="20.576487"
y1="15.991243"
x1="38.940514" />
<linearGradient
id="linearGradient4087-5">
<stop
offset="0"
style="stop-color:#ffffff;stop-opacity:1"
id="stop4089-8" />
<stop
offset="0.51153916"
style="stop-color:#ffffff;stop-opacity:0.23529412"
id="stop4091-2" />
<stop
offset="0.58522105"
style="stop-color:#ffffff;stop-opacity:0.15686275"
id="stop4093-6" />
<stop
offset="1"
style="stop-color:#ffffff;stop-opacity:0.39215687"
id="stop4095-0" />
</linearGradient>
<linearGradient
osb:paint="solid"
id="linearGradient4526">
<stop
id="stop4528"
offset="0"
style="stop-color:#ffffff;stop-opacity:1;" />
</linearGradient>
<linearGradient
gradientUnits="userSpaceOnUse"
y2="13.175975"
x2="10.520687"
y1="1.6559753"
x1="10.520687"
id="linearGradient835"
xlink:href="#linearGradient833" />
</defs>
<metadata
id="metadata3847">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<path
d="M 11.609066,13.158733 C 15.360687,9.8888911 14.166667,4.5555577 8.5000001,4.4127097 l 0,-2.7623493 -6.1393131,4.6031707 6.1393131,4.6031699 0,-2.7401299 C 11.798204,7.9885457 13.506338,10.99578 11.148455,13.158733 Z"
id="path3503-1"
style="display:block;overflow:visible;visibility:visible;fill:url(#linearGradient835);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.96392483;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:7;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none" />
<path
d="M 12.490365,11.55524 C 14.108815,9.6597811 12.899303,4.9810147 7.5283734,5.3482481 L 7.4716267,3.645395 3.9030546,6.2535311 l 3.5685721,2.6373086 0,-1.6856033 C 12.611167,6.7086084 12.973845,10.789004 12.490365,11.55524 Z"
id="path3505-3"
style="display:block;overflow:visible;visibility:visible;opacity:0.52999998;fill:none;stroke:url(#linearGradient3842);stroke-width:0.96392483;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:7;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none" />
<path
d="M 11.609066,13.158733 C 15.360687,9.888891 14.166667,4.5555576 8.5000001,4.4127096 l 0,-2.7623493 -6.1393131,4.6031707 6.1393131,4.60317 0,-2.74013 c 3.2982039,-0.1280254 5.0063379,2.879209 2.6484549,5.042162 z"
id="path3503-1-0"
style="display:inline;overflow:visible;visibility:visible;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#7239b3;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color:#000000;clip-rule:nonzero;opacity:0.5;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;filter-blend-mode:normal;filter-gaussianBlur-deviation:0;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
</svg>
[Icon Theme]
Name=some-custom-theme
Comment=The mail-sender-reply icon is from the Elementary icon pack.
[custom]
Size=256
MinSize=8
MaxSize=256
Type=Scalable
[actions/16]
Size=16
MinSize=8
MaxSize=23
Type=Scalable
#include "crossplatformicon.h"
#include <QPixmap>
#include <QDebug>
QString CrossPlatformIcon::m_fallbackThemeName = "breeze-qownnotes";
QString CrossPlatformIcon::m_themeName = "Adwaita";
CrossPlatformIcon *CrossPlatformIcon::m_IconManager = new CrossPlatformIcon;
CrossPlatformIcon *CrossPlatformIcon::IconManager()
{
return m_IconManager;
}
void CrossPlatformIcon::destroyIconManager()
{
delete m_IconManager;
}
QString CrossPlatformIcon::themeName()
{
return m_themeName;
}
QString CrossPlatformIcon::fallbackThemeName()
{
return m_fallbackThemeName;
}
void CrossPlatformIcon::setThemeName( QString themeName )
{
m_themeName = themeName;
emit m_IconManager->themeNameChanged( themeName );
}
void CrossPlatformIcon::setFallbackThemeName( QString fallbackThemeName )
{
m_fallbackThemeName = fallbackThemeName;
emit m_IconManager->fallbackThemeNameChanged( fallbackThemeName );
}
/*
* Function get:
* This function first checks if an icon with a theme pack exists
* in the current theme. If it does, it returns the QIcon.
* Otherwise, it will switch to a fallback icon theme temporarily
* locate that
*/
QIcon CrossPlatformIcon::get(QString name, int size)
{
// If theme icon exists, return it.
if ( QIcon::hasThemeIcon(name) )
return QIcon::fromTheme( name );
// Grab icon from Vibrato Notes icon set and return it.
QIcon::setThemeName( m_fallbackThemeName );
// If fallback theme does not have icon either,
// switch back to the system icon theme and
// return a blank QIcon
if ( !QIcon::hasThemeIcon(name) ) {
QIcon::setThemeName( m_themeName );
return QIcon();
}
// Grab the theme icon
QIcon iconRaw = QIcon::fromTheme( name );
QList<QSize> iconSizes = iconRaw.availableSizes();
// Convert the icon to a pixmap.
QIcon iconPixmap;
if ( size > 0 )
iconPixmap = iconRaw.pixmap( size );
else
iconPixmap = iconRaw.pixmap( iconSizes[ iconSizes.length()-1 ].width() );
QIcon icon = QIcon( iconPixmap );
// Set the icon theme back to the system theme
QIcon::setThemeName( m_themeName );
return icon;
}
#ifndef CROSSPLATFORMICON_H
#define CROSSPLATFORMICON_H
#include <QObject>
#include <QIcon>
class CrossPlatformIcon : public QObject
{
Q_OBJECT
public:
static CrossPlatformIcon *IconManager();
static void destroyIconManager();
static QString themeName();
static QString fallbackThemeName();
static QIcon get(QString name, int size=-1);
public slots:
static void setThemeName( QString themeName );
static void setFallbackThemeName( QString fallbackThemeName );
signals:
void themeNameChanged(QString themeName);
void fallbackThemeNameChanged(QString fallbackThemeName);
private:
static QString m_fallbackThemeName;
static QString m_themeName;
static CrossPlatformIcon *m_IconManager;
};
#endif // CROSSPLATFORMICON_H
#include <QApplication>
#include <QFrame>
#include <QVBoxLayout>
#include <QPushButton>
#include <crossplatformicon.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// First we set the main theme. In this case, we'll set it to the system icon theme.
CrossPlatformIcon::setThemeName( QIcon::themeName() );
// Next we'll set a fallback icon theme
CrossPlatformIcon::setFallbackThemeName("elementary");
QVBoxLayout *l = new QVBoxLayout;
QPushButton *b1 = new QPushButton("Button 1");
QPushButton *b2 = new QPushButton("Button 2");
b1->setIcon( CrossPlatformIcon::get("mail-reply-sender") );
b2->setIcon( CrossPlatformIcon::get("cool-tux-penguin") );
l->addWidget( b1 );
l->addWidget( b2 );
QFrame *f = new QFrame;
f->setLayout(l);
f->show();
int status = a.exec();
CrossPlatformIcon::destroyIconManager();
return status;
}
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