/* * Cantata * * Copyright (c) 2011-2014 Craig Drummond * * ---- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "icons.h" #include "config.h" #include "settings.h" #include #include #include #include #include #include #include #include #if !defined Q_OS_WIN && !defined Q_OS_MAC #include "gtkstyle.h" #endif #ifdef ENABLE_KDE_SUPPORT K_GLOBAL_STATIC(Icons, instance) #endif Icons * Icons::self() { #ifdef ENABLE_KDE_SUPPORT return instance; #else static Icons *instance=0; if(!instance) { instance=new Icons; } return instance; #endif } static QList constStdSizes=QList() << 16 << 22 << 32 << 48; static const double constDisabledOpacity=0.5; static const int constShadeFactor=75; 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=200) { return col.red()>=limit && col.blue()>=limit && col.green()>=limit; } static bool inline isVeryDark(const QColor &col, int limit=80) { return col.red() sizes=QList() << 16 << 22 << 32 << 48 << 64; QColor col=clampColor(adjusted, constDarkLimit, darkValue, constLightLimit, lightValue); foreach (int s, sizes) { QImage img=std.pixmap(s, s, mode).toImage().convertToFormat(QImage::Format_ARGB32); recolourPix(img, col); i.addPixmap(QPixmap::fromImage(img), mode); } } } static Icon loadSidebarIcon(const QString &name, const QColor &normal, const QColor &selected) { Icon i; updateSidebarIcon(i, name, normal, QIcon::Normal); if (normal!=selected) { updateSidebarIcon(i, name, selected, QIcon::Selected); } return i; } Icons::Icons() { calcIconColors(stdColor, highlightColor); singleIcon=createSingleIcon(stdColor, highlightColor); consumeIcon=createConsumeIcon(stdColor, highlightColor); menuIcon=createMenuIcon(stdColor, highlightColor); #ifdef ENABLE_STREAMS streamCategoryIcon=Icon(QLatin1String("oxygen")==Icon::currentTheme().toLower() ? "inode-directory" : "folder-music"); #endif #ifdef Q_OS_WIN QString iconFile=QCoreApplication::applicationDirPath()+"/icons/stream.png"; #else QString iconFile=QString(INSTALL_PREFIX"/share/")+QCoreApplication::applicationName()+"/icons/stream.png"; #endif if (QFile::exists(iconFile)) { streamIcon.addFile(iconFile); } if (streamIcon.isNull()) { streamIcon=Icon("applications-internet"); } albumIcon=Icon("media-optical"); podcastIcon=Icon("inode-directory"); downloadedPodcastEpisodeIcon=Icon("document-save-as"); audioFileIcon=Icon("audio-x-generic"); playlistIcon=Icon("view-media-playlist"); folderIcon=Icon("inode-directory"); #ifdef ENABLE_DYNAMIC dynamicRuleIcon=Icon("media-playlist-shuffle"); #endif configureIcon=Icon("configure"); connectIcon=Icon("dialog-ok"); disconnectIcon=Icon("media-eject"); speakerIcon=Icon("speaker"); editIcon=Icon("document-edit"); searchIcon=Icon("edit-find"); clearListIcon=Icon("edit-clear-list"); repeatIcon=createRecolourableIcon("repeat", stdColor, highlightColor); shuffleIcon=createRecolourableIcon("shuffle", stdColor, highlightColor); filesIcon=Icon("document-multiple"); cancelIcon=Icon("dialog-cancel"); importIcon=Icon("document-import"); if (editIcon.isNull()) { editIcon=Icon("text-editor"); } if (importIcon.isNull()) { importIcon=Icon("down"); } libraryIcon=Icon::create("lib", constStdSizes); radioStreamIcon=Icon::create("radio", constStdSizes); addRadioStreamIcon=Icon::create("addradio", constStdSizes); variousArtistsIcon=Icon::create("va", QList() << 16 << 22 << 32 << 48 << 64 << 128); artistIcon=Icon::create("artist", QList() << 16 << 22 << 32 << 48 << 64 << 128); #ifndef ENABLE_KDE_SUPPORT QList appSizes=QList() << 16 << 22 << 24 << 32 << 48 << 64; foreach (int s, appSizes) { appIcon.addFile(QString(":cantata%1.png").arg(s), QSize(s, s)); } appIcon.addFile(":cantata.svg"); shortcutsIcon=Icon("preferences-desktop-keyboard"); #if !defined Q_OS_WIN && !defined Q_OS_MAC if (shortcutsIcon.isNull()) { shortcutsIcon=Icon("keyboard"); } if (albumIcon.isNull()) { albumIcon=Icon("media-optical-audio"); } if (configureIcon.isNull()) { configureIcon=Icon("gtk-preferences"); } if (connectIcon.isNull()) { connectIcon=Icon("gtk-stock-ok"); if (connectIcon.isNull()) { connectIcon=Icon("go-bottom"); } } if (speakerIcon.isNull()) { speakerIcon=Icon("audio-speakers"); if (speakerIcon.isNull()) { speakerIcon=Icon("gnome-volume-control"); } } #ifdef ENABLE_DYNAMIC if (dynamicRuleIcon.isNull()) { dynamicRuleIcon=Icon("text-x-generic"); } #endif if (playlistIcon.isNull()) { playlistIcon=Icon("audio-x-mp3-playlist"); if (playlistIcon.isNull()) { playlistIcon=audioFileIcon; } } if (editIcon.isNull()) { editIcon=Icon("gtk-edit"); } if (clearListIcon.isNull()) { clearListIcon=Icon("edit-clear"); } if (filesIcon.isNull()) { filesIcon=Icon("empty"); } if (cancelIcon.isNull()) { cancelIcon=Icon("gtk-cancel"); } #endif // Q_OS_WIN && Q_OS_MAC #endif // ENABLE_KDE_SUPPORT #ifdef ENABLE_STREAMS if (streamCategoryIcon.isNull()) { streamCategoryIcon=libraryIcon; } #endif } void Icons::initSidebarIcons() { if (Settings::self()->monoSidebarIcons()) { QColor textCol=QApplication::palette().color(QPalette::Active, QPalette::ButtonText); QColor highlightedTexCol=QApplication::palette().color(QPalette::Active, QPalette::HighlightedText); playqueueIcon=loadSidebarIcon("playqueue", textCol, highlightedTexCol); artistsIcon=loadSidebarIcon("artists", textCol, highlightedTexCol); albumsIcon=loadSidebarIcon("albums", textCol, highlightedTexCol); foldersIcon=loadSidebarIcon("folders", textCol, highlightedTexCol); playlistsIcon=loadSidebarIcon("playlists", textCol, highlightedTexCol); #ifdef ENABLE_DYNAMIC dynamicIcon=loadSidebarIcon("dynamic", textCol, highlightedTexCol); #endif #ifdef ENABLE_STREAMS streamsIcon=loadSidebarIcon("streams", textCol, highlightedTexCol); #endif #ifdef ENABLE_ONLINE_SERVICES onlineIcon=loadSidebarIcon("online", textCol, highlightedTexCol); #endif infoSidebarIcon=loadSidebarIcon("info", textCol, highlightedTexCol); #ifdef ENABLE_DEVICES_SUPPORT devicesIcon=loadSidebarIcon("devices", textCol, highlightedTexCol); #endif searchTabIcon=loadSidebarIcon("search", textCol, highlightedTexCol); } else { playqueueIcon=Icon("media-playback-start"); artistsIcon=artistIcon; albumsIcon=albumIcon; foldersIcon=Icon("inode-directory"); playlistsIcon=playlistIcon; #ifdef ENABLE_DYNAMIC dynamicIcon=dynamicRuleIcon; #endif #ifdef ENABLE_STREAMS streamsIcon=radioStreamIcon; #endif #ifdef ENABLE_ONLINE_SERVICES onlineIcon=Icon("applications-internet"); #endif if (QLatin1String("gnome")==Icon::currentTheme().toLower()) { QColor col=QApplication::palette().color(QPalette::Active, QPalette::ButtonText); infoSidebarIcon=loadSidebarIcon("info", col, col); } else { infoSidebarIcon=Icon("dialog-information"); } #ifdef ENABLE_DEVICES_SUPPORT devicesIcon=Icon("multimedia-player"); #endif searchTabIcon=searchIcon; } } #if !defined ENABLE_KDE_SUPPORT && !defined Q_OS_WIN && !defined Q_OS_MAC // FIXME -- needed? // For some reason, the -symbolic icons on Ubuntu have a lighter colour when disabled! // This looks odd to me, so base the disabled icon on the enabled version but with opacity // set to default value... static void setDisabledOpacity(Icon &icon) { Icon copy; for (int i=0; i<2; ++i) { QIcon::State state=(QIcon::State)i; for (int j=0; j<4; ++j) { QIcon::Mode mode=(QIcon::Mode)j; QList sizes=constStdSizes; foreach (const int sz, sizes) { if (QIcon::Disabled==mode) { QPixmap pix=icon.pixmap(QSize(sz, sz), QIcon::Normal, state); if (!pix.isNull()) { QPixmap dis(sz, sz); dis.fill(Qt::transparent); QPainter p(&dis); p.setOpacity(constDisabledOpacity); p.drawPixmap(0, 0, pix); p.end(); copy.addPixmap(dis, mode, state); } } else { copy.addPixmap(icon.pixmap(QSize(sz, sz), mode, state), mode, state); } } } } icon=copy; } #else #define setDisabledOpacity(A) ; #endif void Icons::initToolbarIcons(const QColor &color, bool forceLight) { bool light=forceLight || isLight(color); if (light) { QColor col(Qt::white); QColor highlight(col.darker(constShadeFactor)); toolbarMenuIcon=createMenuIcon(col, highlight); } else { toolbarMenuIcon=menuIcon; } #if !defined Q_OS_WIN && !defined Q_OS_MAC if (light && GtkStyle::useSymbolicIcons()) { toolbarPrevIcon=Icon("media-skip-backward-symbolic"); toolbarPlayIcon=Icon("media-playback-start-symbolic"); toolbarPauseIcon=Icon("media-playback-pause-symbolic"); toolbarStopIcon=Icon("media-playback-stop-symbolic"); toolbarNextIcon=Icon("media-skip-forward-symbolic"); QColor col(196, 196, 196); infoIcon=loadSidebarIcon("info", col, col); } else #endif if (QLatin1String("gnome")==Icon::currentTheme().toLower()) { QColor col=QApplication::palette().color(QPalette::Active, QPalette::ButtonText); infoIcon=loadSidebarIcon("info", col, col); } if (infoIcon.isNull()) { infoIcon=Icon("dialog-information"); } #if !defined ENABLE_KDE_SUPPORT && !defined Q_OS_WIN && !defined Q_OS_MAC if (QLatin1String("gnome")==Icon::currentTheme().toLower()) { QColor col=QApplication::palette().color(QPalette::Active, QPalette::ButtonText); contextIcon=loadSidebarIcon("info", col, col); } else #endif contextIcon=Icon("dialog-information"); if (toolbarPrevIcon.isNull()) { toolbarPrevIcon=Icon::getMediaIcon("media-skip-backward"); } else { setDisabledOpacity(toolbarPrevIcon); } if (toolbarPlayIcon.isNull()) { toolbarPlayIcon=Icon::getMediaIcon("media-playback-start"); } else { setDisabledOpacity(toolbarPlayIcon); } if (toolbarPauseIcon.isNull()) { toolbarPauseIcon=Icon::getMediaIcon("media-playback-pause"); } else { setDisabledOpacity(toolbarPauseIcon); } if (toolbarStopIcon.isNull()) { toolbarStopIcon=Icon::getMediaIcon("media-playback-stop"); } else { setDisabledOpacity(toolbarStopIcon); } if (toolbarNextIcon.isNull()) { toolbarNextIcon=Icon::getMediaIcon("media-skip-forward"); } else { setDisabledOpacity(toolbarNextIcon); } }