/* * Cantata * * Copyright (c) 2011-2013 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 ENABLE_KDE_SUPPORT && !defined Q_OS_WIN #include "gtkstyle.h" #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; } void Icons::init() { calcIconColors(stdColor, highlightColor); singleIcon=createSingleIcon(stdColor, highlightColor); consumeIcon=createConsumeIcon(stdColor, highlightColor); menuIcon=createMenuIcon(stdColor, highlightColor); libraryIcon=Icon("cantata-view-media-library"); streamCategoryIcon=Icon(QLatin1String("oxygen")==QIcon::themeName() ? "inode-directory" : "folder-music"); radioStreamIcon=Icon("cantata-view-radiostream"); addRadioStreamIcon=Icon("cantata-radiostream-add"); QString iconFile=QString(INSTALL_PREFIX"/share/")+QCoreApplication::applicationName()+"/streamicons/stream.png"; if (QFile::exists(iconFile)) { streamIcon.addFile(iconFile); } if (streamIcon.isNull()) { streamIcon=Icon("applications-internet"); } artistIcon=Icon("view-media-artist"); albumIcon=Icon("media-optical"); playlistIcon=Icon("view-media-playlist"); dynamicRuleIcon=Icon("media-playlist-shuffle"); configureIcon=Icon("configure"); connectIcon=Icon("dialog-ok"); disconnectIcon=Icon("media-eject"); speakerIcon=Icon("speaker"); variousArtistsIcon=Icon("cantata-view-media-artist-various"); editIcon=Icon("document-edit"); clearListIcon=Icon("edit-clear-list"); repeatIcon=createRecolourableIcon("repeat", stdColor, highlightColor); shuffleIcon=createRecolourableIcon("shuffle", stdColor, highlightColor); #ifdef ENABLE_ONLINE_SERVICES jamendoIcon=Icon("cantata-view-services-jamendo"); magnatuneIcon=Icon("cantata-view-services-jamendo"); #endif filesIcon=Icon("document-multiple"); cancelIcon=Icon("dialog-cancel"); importIcon=Icon("document-import"); lyricsIcon=Icon("view-media-lyrics"); if (lyricsIcon.isNull()) { lyricsIcon=Icon("text-x-generic"); } if (editIcon.isNull()) { editIcon=Icon("text-editor"); } if (importIcon.isNull()) { importIcon=Icon("down"); } #ifndef ENABLE_KDE_SUPPORT appIcon.addFile(":cantata.svg"); shortcutsIcon=Icon("preferences-desktop-keyboard"); if (libraryIcon.isNull()) { libraryIcon=Icon::create("lib", constStdSizes); } if (radioStreamIcon.isNull()) { radioStreamIcon=Icon::create("radio", constStdSizes); } if (addRadioStreamIcon.isNull()) { addRadioStreamIcon=Icon::create("addradio", constStdSizes); } if (variousArtistsIcon.isNull()) { variousArtistsIcon=Icon::create("va", QList() << 16 << 22 << 32 << 48 << 64 << 128); } if (artistIcon.isNull()) { artistIcon=Icon::create("artist", QList() << 16 << 22 << 32 << 48 << 64 << 128); } #ifdef ENABLE_ONLINE_SERVICES if (jamendoIcon.isNull()) { jamendoIcon=Icon::create("jamendo", constStdSizes); } if (magnatuneIcon.isNull()) { magnatuneIcon=Icon::create("magnatune", constStdSizes); } #endif #ifndef Q_OS_WIN 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 (disconnectIcon.isNull()) { // disconnectIcon=Icon("media-eject"); //} if (speakerIcon.isNull()) { speakerIcon=Icon("audio-speakers"); if (speakerIcon.isNull()) { speakerIcon=Icon("gnome-volume-control"); } } if (dynamicRuleIcon.isNull()) { dynamicRuleIcon=Icon("text-x-generic"); } if (playlistIcon.isNull()) { playlistIcon=Icon("audio-x-mp3-playlist"); if (playlistIcon.isNull()) { playlistIcon=Icon("audio-x-generic"); } } 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 #endif // ENABLE_KDE_SUPPORT if (streamCategoryIcon.isNull()) { streamCategoryIcon=libraryIcon; } } 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); dynamicIcon=loadSidebarIcon("dynamic", textCol, highlightedTexCol); streamsIcon=loadSidebarIcon("streams", textCol, highlightedTexCol); #ifdef ENABLE_ONLINE_SERVICES onlineIcon=loadSidebarIcon("online", textCol, highlightedTexCol); #endif #ifdef ENABLE_DEVICES_SUPPORT devicesIcon=loadSidebarIcon("devices", textCol, highlightedTexCol); #endif } else { playqueueIcon=Icon("media-playback-start"); artistsIcon=artistIcon; albumsIcon=albumIcon; foldersIcon=Icon("inode-directory"); playlistsIcon=playlistIcon; dynamicIcon=dynamicRuleIcon; streamsIcon=radioStreamIcon; #ifdef ENABLE_ONLINE_SERVICES onlineIcon=Icon("applications-internet"); #endif #ifdef ENABLE_DEVICES_SUPPORT devicesIcon=Icon("multimedia-player"); #endif } } #if !defined ENABLE_KDE_SUPPORT && !defined Q_OS_WIN // 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 ENABLE_KDE_SUPPORT && !defined Q_OS_WIN 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"); toolbarVolumeMutedIcon=Icon("audio-volume-muted-symbolic"); toolbarVolumeLowIcon=Icon("audio-volume-low-symbolic"); toolbarVolumeMediumIcon=Icon("audio-volume-medium-symbolic"); toolbarVolumeHighIcon=Icon("audio-volume-high-symbolic"); QColor col(196, 196, 196); infoIcon=loadSidebarIcon("info", col, col); } else #endif if (QIcon::themeName()==QLatin1String("gnome")) { QColor col=QApplication::palette().color(QPalette::Active, QPalette::ButtonText); infoIcon=loadSidebarIcon("info", col, col); } if (infoIcon.isNull()) { infoIcon=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); } if (toolbarVolumeMutedIcon.isNull()) { toolbarVolumeMutedIcon=Icon("audio-volume-muted"); } if (toolbarVolumeLowIcon.isNull()) { toolbarVolumeLowIcon=Icon("audio-volume-low"); } if (toolbarVolumeMediumIcon.isNull()) { toolbarVolumeMediumIcon=Icon("audio-volume-medium"); } if (toolbarVolumeHighIcon.isNull()) { toolbarVolumeHighIcon=Icon("audio-volume-high"); } #ifdef PHONON_FOUND toolbarStreamIcon=streamIcon; #endif }