/* * 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 "gui/settings.h" #include "support/globalstatic.h" #include #include #include #include #include #include #include #include #if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined ENABLE_UBUNTU #include "support/gtkstyle.h" #endif GLOBAL_STATIC(Icons, instance) static QList constStdSizes=QList() << 16 << 22 << 32 << 48; 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; } static bool inline isVeryDark(const QColor &col, int limit=constDarkValue) { return col.red() sizes=QList() << 16 << 22 << 32 << 48 << 64; QColor col=clampColor(color, 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 loadMonoSvgIcon(const QString &type, const QString &name, const QColor &normal, const QColor &selected) { Icon i; updateMonoSvgIcon(i, type, name, normal, QIcon::Normal); if (normal!=selected) { updateMonoSvgIcon(i, type, name, selected, QIcon::Selected); } return i; } static Icon loadSidebarIcon(const QString &name, const QColor &normal, const QColor &selected) { return loadMonoSvgIcon(QLatin1String("sidebar"), name, normal, selected); } #if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined ENABLE_UBUNTU static void setDisabledOpacity(Icon &icon) { static const double constDisabledOpacity=0.5; 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; } static Icon loadMediaIcon(const QString &name, const QColor &normal, const QColor &selected) { Icon icon=loadMonoSvgIcon(QLatin1String("media"), name, normal, selected); setDisabledOpacity(icon); return icon; } #endif Icons::Icons() { QColor stdColor=calcIconColor(); singleIcon=createSingleIcon(stdColor); consumeIcon=createConsumeIcon(stdColor); #ifdef USE_SYSTEM_MENU_ICON menuIcon=Icon("applications-system"); #else menuIcon=createMenuIcon(stdColor); #endif #ifdef ENABLE_STREAMS streamCategoryIcon=Icon(QLatin1String("oxygen")==Icon::currentTheme().toLower() ? "inode-directory" : "folder-music"); #endif QString iconFile=QString(CANTATA_SYS_ICONS_DIR+"stream.png"); 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"); dynamicRuleIcon=Icon("media-playlist-shuffle"); 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); shuffleIcon=createRecolourableIcon("shuffle", stdColor); 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, true); artistIcon=Icon::create("artist", QList() << 16 << 22 << 32 << 48 << 64 << 128, true); lastFmIcon.addFile(":lastfm.svg"); #ifndef ENABLE_KDE_SUPPORT #ifndef ENABLE_UBUNTU appIcon.addFile(":cantata.svg"); #endif shortcutsIcon=Icon("preferences-desktop-keyboard"); #if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined ENABLE_UBUNTU 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 } static bool monoSb=true; bool Icons::monoSidebarIcons() { return monoSb; } void Icons::initSidebarIcons() { if (Settings::self()->monoSidebarIcons()) { monoSb=true; QColor textCol=QApplication::palette().color(QPalette::Active, QPalette::WindowText); QColor highlightedTexCol=QApplication::palette().color(QPalette::Active, QPalette::HighlightedText); playqueueIcon=loadSidebarIcon(QLatin1String("playqueue"), textCol, highlightedTexCol); artistsIcon=loadSidebarIcon(QLatin1String("artists"), textCol, highlightedTexCol); albumsIcon=loadSidebarIcon(QLatin1String("albums"), textCol, highlightedTexCol); foldersIcon=loadSidebarIcon(QLatin1String("folders"), textCol, highlightedTexCol); playlistsIcon=loadSidebarIcon(QLatin1String("playlists"), textCol, highlightedTexCol); #ifdef ENABLE_DYNAMIC dynamicIcon=loadSidebarIcon(QLatin1String("dynamic"), textCol, highlightedTexCol); #endif #ifdef ENABLE_STREAMS streamsIcon=loadSidebarIcon(QLatin1String("streams"), textCol, highlightedTexCol); #endif #ifdef ENABLE_ONLINE_SERVICES onlineIcon=loadSidebarIcon(QLatin1String("online"), textCol, highlightedTexCol); #endif infoSidebarIcon=loadSidebarIcon(QLatin1String("info"), textCol, highlightedTexCol); #ifdef ENABLE_DEVICES_SUPPORT devicesIcon=loadSidebarIcon(QLatin1String("devices"), textCol, highlightedTexCol); #endif searchTabIcon=loadSidebarIcon(QLatin1String("search"), textCol, highlightedTexCol); } else { monoSb=false; 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::WindowText); infoSidebarIcon=loadSidebarIcon("info", col, col); } else { infoSidebarIcon=Icon("dialog-information"); } #ifdef ENABLE_DEVICES_SUPPORT devicesIcon=Icon("multimedia-player"); #endif searchTabIcon=searchIcon; } } void Icons::initToolbarIcons(const QColor &toolbarText) { #ifdef USE_SYSTEM_MENU_ICON Q_UNUSED(toolbarText) #endif QColor stdColor=calcIconColor(); #if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined ENABLE_UBUNTU if (GtkStyle::useSymbolicIcons()) { bool rtl=Qt::RightToLeft==QApplication::layoutDirection(); QColor col=GtkStyle::symbolicColor(); toolbarPrevIcon=loadMediaIcon(QLatin1String(rtl ? "prev-rtl" : "prev"), col, col); toolbarPlayIcon=loadMediaIcon(QLatin1String(rtl ? "play-rtl" : "play"), col, col); toolbarPauseIcon=loadMediaIcon(QLatin1String("pause"), col, col); toolbarStopIcon=loadMediaIcon(QLatin1String("stop"), col, col); toolbarNextIcon=loadMediaIcon(QLatin1String(rtl ? "next-rtl" : "next"), col, col); infoIcon=loadSidebarIcon("info", col, col); #ifdef USE_SYSTEM_MENU_ICON toolbarMenuIcon=loadMonoSvgIcon(QLatin1String("menu"), QLatin1String("icon"), col, col); menuIcon=loadMonoSvgIcon(QLatin1String("menu"), QLatin1String("icon"), stdColor, stdColor); #else if (col==stdColor) { toolbarMenuIcon=menuIcon; } else { toolbarMenuIcon=createMenuIcon(col); } #endif } else #endif { #ifdef USE_SYSTEM_MENU_ICON toolbarMenuIcon=menuIcon; #else if (toolbarText==stdColor) { toolbarMenuIcon=menuIcon; } else { toolbarMenuIcon=createMenuIcon(toolbarText); } #endif if (QLatin1String("gnome")==Icon::currentTheme().toLower()) { QColor col=QApplication::palette().color(QPalette::Active, QPalette::WindowText); 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::WindowText); contextIcon=loadSidebarIcon("info", col, col); } else #endif contextIcon=Icon("dialog-information"); if (toolbarPrevIcon.isNull()) { toolbarPrevIcon=Icon::getMediaIcon("media-skip-backward"); } if (toolbarPlayIcon.isNull()) { toolbarPlayIcon=Icon::getMediaIcon("media-playback-start"); } if (toolbarPauseIcon.isNull()) { toolbarPauseIcon=Icon::getMediaIcon("media-playback-pause"); } if (toolbarStopIcon.isNull()) { toolbarStopIcon=Icon::getMediaIcon("media-playback-stop"); } if (toolbarNextIcon.isNull()) { toolbarNextIcon=Icon::getMediaIcon("media-skip-forward"); } }