diff --git a/src/core/iconloader.cpp b/src/core/iconloader.cpp index 1f4cf3dc6..caa0a3d76 100644 --- a/src/core/iconloader.cpp +++ b/src/core/iconloader.cpp @@ -50,7 +50,7 @@ void IconLoader::Init() { } -QIcon IconLoader::Load(const QString &name, const int size) { +QIcon IconLoader::Load(const QString &name, const int fixed_size, const int min_size, const int max_size) { QIcon ret; @@ -60,15 +60,16 @@ QIcon IconLoader::Load(const QString &name, const int size) { } QList sizes; - sizes.clear(); - if (size == 0) { sizes << 22 << 32 << 48 << 64; } - else sizes << size; + if (fixed_size == 0) { sizes << 22 << 32 << 48 << 64; } + else sizes << fixed_size; if (system_icons_) { IconMapper::IconProperties icon_prop; if (IconMapper::iconmapper_.contains(name)) { icon_prop = IconMapper::iconmapper_[name]; } + if (min_size != 0) icon_prop.min_size = min_size; + if (max_size != 0) icon_prop.max_size = max_size; if (icon_prop.allow_system_icon) { ret = QIcon::fromTheme(name); if (ret.isNull()) { @@ -76,8 +77,36 @@ QIcon IconLoader::Load(const QString &name, const int size) { ret = QIcon::fromTheme(alt_name); if (!ret.isNull()) break; } + if (ret.isNull()) { + qLog(Warning) << "Couldn't load icon" << name << "from system theme icons."; + } + } + if (!ret.isNull()) { + if (fixed_size != 0 && !ret.availableSizes().contains(QSize(fixed_size, fixed_size))) { + qLog(Warning) << "Can't use system icon for" << name << "icon does not have fixed size." << fixed_size; + ret = QIcon(); + } + else { + int size_smallest = 0; + int size_largest = 0; + for (const QSize &s : ret.availableSizes()) { + if (s.width() != s.height()) { + qLog(Warning) << "Can't use system icon for" << name << "icon is not proportional."; + ret = QIcon(); + } + if (size_smallest == 0 || s.width() < size_smallest) size_smallest = s.width(); + if (s.width() > size_largest) size_largest = s.width(); + } + if (size_smallest != 0 && icon_prop.min_size != 0 && size_smallest < icon_prop.min_size) { + qLog(Warning) << "Can't use system icon for" << name << "icon too small." << size_smallest; + ret = QIcon(); + } + else if (size_largest != 0 && icon_prop.max_size != 0 && size_largest > icon_prop.max_size) { + qLog(Warning) << "Can't use system icon for" << name << "icon too large." << size_largest; + ret = QIcon(); + } + } } - if (ret.isNull()) qLog(Warning) << "Couldn't load icon" << name << "from system theme icons."; } if (!ret.isNull()) return ret; } diff --git a/src/core/iconloader.h b/src/core/iconloader.h index 8aa80d134..c02ae4f3a 100644 --- a/src/core/iconloader.h +++ b/src/core/iconloader.h @@ -26,7 +26,7 @@ class IconLoader { public: static void Init(); - static QIcon Load(const QString &name, const int size = 0); + static QIcon Load(const QString &name, const int fixed_size = 0, const int min_size = 0, const int max_size = 0); private: explicit IconLoader() {} static bool system_icons_; diff --git a/src/core/iconmapper.h b/src/core/iconmapper.h index 3bbf74819..91e37db02 100644 --- a/src/core/iconmapper.h +++ b/src/core/iconmapper.h @@ -17,6 +17,8 @@ * */ +#pragma once + #include "config.h" #include @@ -25,8 +27,8 @@ namespace IconMapper { struct IconProperties { - explicit IconProperties() : min_size(0), max_size(0) {} - IconProperties(const QStringList &_names, const int _min_size, const int _max_size, const bool _allow_system_icon = true) : names(_names), min_size(_min_size), max_size(_max_size), allow_system_icon(_allow_system_icon) {} + explicit IconProperties() : min_size(0), max_size(0), allow_system_icon(true) {} + IconProperties(const QStringList &_names, const int _min_size = 16, const int _max_size = 512, const bool _allow_system_icon = true) : names(_names), min_size(_min_size), max_size(_max_size), allow_system_icon(_allow_system_icon) {} QStringList names; int min_size; int max_size; @@ -35,99 +37,100 @@ struct IconProperties { static const QMap iconmapper_ = { - { "albums", { {"media-optical"}, 0, 0 } }, - { "alsa", { {}, 0, 0 } }, - { "application-exit", { {}, 0, 0 } }, - { "applications-internet", { {}, 0, 0 } }, - { "bluetooth", { {"preferences-system-bluetooth", "bluetooth-active"}, 0, 0 } }, - { "cdcase", { {"cdcover", "media-optical"}, 0, 0 } }, - { "media-optical", { {"cd"}, 0, 0 } }, - { "configure", { {}, 0, 0 } }, - { "device-ipod-nano", { {}, 0, 0 } }, - { "device-ipod", { {}, 0, 0 } }, - { "device-phone", { {}, 0, 0 } }, - { "device", { {"drive-removable-media-usb-pendrive"}, 0, 0 } }, - { "device-usb-drive", { {}, 0, 0 } }, - { "device-usb-flash", { {}, 0, 0 } }, - { "dialog-error", { {}, 0, 0 } }, - { "dialog-information", { {}, 0, 0 } }, - { "dialog-ok-apply", { {}, 0, 0 } }, - { "dialog-password", { {}, 0, 0 } }, - { "dialog-warning", { {}, 0, 0 } }, - { "document-download", { {}, 0, 0 } }, - { "document-new", { {}, 0, 0 } }, - { "document-open-folder", { {}, 0, 0 } }, - { "document-open", { {}, 0, 0 } }, - { "document-save", { {}, 0, 0 } }, - { "document-search", { {}, 0, 0 } }, - { "download", { {"applications-internet", "network-workgroup"}, 0, 0 } }, - { "edit-clear-list", { {}, 0, 0 } }, + { "albums", { {"media-optical"}} }, + { "alsa", { {}} }, + { "application-exit", { {}} }, + { "applications-internet", { {}} }, + { "bluetooth", { {"preferences-system-bluetooth", "bluetooth-active"}} }, + { "cdcase", { {"cdcover", "media-optical"}} }, + { "media-optical", { {"cd"}} }, + { "configure", { {}} }, + { "device-ipod-nano", { {}} }, + { "device-ipod", { {}} }, + { "device-phone", { {}} }, + { "device", { {"drive-removable-media-usb-pendrive"}} }, + { "device-usb-drive", { {}} }, + { "device-usb-flash", { {}} }, + { "dialog-error", { {}} }, + { "dialog-information", { {}} }, + { "dialog-ok-apply", { {}} }, + { "dialog-password", { {}} }, + { "dialog-warning", { {}} }, + { "document-download", { {}} }, + { "document-new", { {}} }, + { "document-open-folder", { {}} }, + { "document-open", { {}} }, + { "document-save", { {}} }, + { "document-search", { {}} }, + { "document-open-remote", { {}} }, + { "download", { {"applications-internet", "network-workgroup"}} }, + { "edit-clear-list", { {}} }, { "edit-clear-locationbar-ltr", { {}, 0, 0, false } }, - { "edit-copy", { {}, 0, 0 } }, - { "edit-delete", { {}, 0, 0 } }, - { "edit-find", { {}, 0, 0 } }, - { "edit-redo", { {}, 0, 0 } }, - { "edit-rename", { {}, 0, 0 } }, - { "edit-undo", { {}, 0, 0 } }, - { "electrocompaniet", { {}, 0, 0 } }, - { "equalizer", { {"view-media-equalizer"}, 0, 0 } }, - { "folder-new", { {}, 0, 0 } }, - { "folder", { {}, 0, 0 } }, - { "folder-sound", { {"folder-music"}, 0, 0 } }, - { "footsteps", { {"go-jump"}, 0, 0 } }, - { "go-down", { {}, 0, 0 } }, - { "go-home", { {}, 0, 0 } }, - { "go-jump", { {}, 0, 0 } }, - { "go-next", { {}, 0, 0 } }, - { "go-previous", { {}, 0, 0 } }, - { "go-up", { {}, 0, 0 } }, - { "gstreamer", { {"phonon-gstreamer"}, 0, 0 } }, - { "headset", { {"audio-headset"}, 0, 0 } }, - { "help-hint", { {}, 0, 0 } }, - { "intel", { {}, 0, 0 } }, - { "jack", { {"audio-input-line"}, 0, 0 } }, - { "keyboard", { {"input-keyboard"}, 0, 0 } }, - { "list-add", { {}, 0, 0 } }, - { "list-remove", { {}, 0, 0 } }, - { "love", { {"heart", "emblem-favorite"}, 0, 0 } }, - { "mcintosh-player", { {}, 0, 0 } }, - { "mcintosh", { {}, 0, 0 } }, - { "mcintosh-text", { {}, 0, 0 } }, - { "media-eject", { {}, 0, 0 } }, - { "media-playback-pause", { {"media-pause"}, 0, 0 } }, - { "media-playlist-repeat", { {}, 0, 0 } }, - { "media-playlist-shuffle", { {""}, 0, 0 } }, - { "media-playback-start", { {"media-play", "media-playback-playing"}, 0, 0 } }, - { "media-seek-backward", { {}, 0, 0 } }, - { "media-seek-forward", { {}, 0, 0 } }, - { "media-skip-backward", { {}, 0, 0 } }, - { "media-skip-forward", { {}, 0, 0 } }, - { "media-playback-stop", { {"media-stop"}, 0, 0 } }, - { "moodbar", { {"preferences-desktop-icons"}, 0, 0 } }, - { "nvidia", { {}, 0, 0 } }, - { "pulseaudio", { {}, 0, 0 } }, - { "realtek", { {}, 0, 0 } }, - { "scrobble-disabled", { {}, 0, 0 } }, - { "scrobble", { {}, 0, 0 } }, - { "search", { {}, 0, 0 } }, - { "soundcard", { {"audiocard", "audio-card"}, 0, 0 } }, - { "speaker", { {}, 0, 0 } }, - { "star-grey", { {}, 0, 0 } }, - { "star", { {}, 0, 0 } }, - { "strawberry", { {}, 0, 0 } }, - { "subsonic", { {}, 0, 0 } }, - { "tidal", { {}, 0, 0 } }, - { "tools-wizard", { {}, 0, 0 } }, - { "view-choose", { {}, 0, 0 } }, - { "view-fullscreen", { {}, 0, 0 } }, - { "view-media-lyrics", { {}, 0, 0 } }, - { "view-media-playlist", { {}, 0, 0 } }, - { "view-media-visualization", { {"preferences-desktop-theme"}, 0, 0 } }, - { "view-refresh", { {}, 0, 0 } }, - { "library-music", { {"vinyl"}, 0, 0 } }, - { "vlc", { {}, 0, 0 } }, - { "xine", { {}, 0, 0 } }, - { "zoom-in", { {}, 0, 0 } }, + { "edit-copy", { {}} }, + { "edit-delete", { {}} }, + { "edit-find", { {}} }, + { "edit-redo", { {}} }, + { "edit-rename", { {}} }, + { "edit-undo", { {}} }, + { "electrocompaniet", { {}} }, + { "equalizer", { {"view-media-equalizer"}} }, + { "folder-new", { {}} }, + { "folder", { {}} }, + { "folder-sound", { {"folder-music"}} }, + { "footsteps", { {"go-jump"}} }, + { "go-down", { {}} }, + { "go-home", { {}} }, + { "go-jump", { {}} }, + { "go-next", { {}} }, + { "go-previous", { {}} }, + { "go-up", { {}} }, + { "gstreamer", { {"phonon-gstreamer"}} }, + { "headset", { {"audio-headset"}} }, + { "help-hint", { {}} }, + { "intel", { {}} }, + { "jack", { {"audio-input-line"}} }, + { "keyboard", { {"input-keyboard"}} }, + { "list-add", { {}} }, + { "list-remove", { {}} }, + { "love", { {"heart", "emblem-favorite"}} }, + { "mcintosh-player", { {}} }, + { "mcintosh", { {}} }, + { "mcintosh-text", { {}} }, + { "media-eject", { {}} }, + { "media-playback-pause", { {"media-pause"}} }, + { "media-playlist-repeat", { {}} }, + { "media-playlist-shuffle", { {""}} }, + { "media-playback-start", { {"media-play", "media-playback-playing"}} }, + { "media-seek-backward", { {}} }, + { "media-seek-forward", { {}} }, + { "media-skip-backward", { {}} }, + { "media-skip-forward", { {}} }, + { "media-playback-stop", { {"media-stop"}} }, + { "moodbar", { {"preferences-desktop-icons"}} }, + { "nvidia", { {}} }, + { "pulseaudio", { {}} }, + { "realtek", { {}} }, + { "scrobble-disabled", { {}} }, + { "scrobble", { {}} }, + { "search", { {}} }, + { "soundcard", { {"audiocard", "audio-card"}} }, + { "speaker", { {}} }, + { "star-grey", { {}} }, + { "star", { {}} }, + { "strawberry", { {}} }, + { "subsonic", { {}} }, + { "tidal", { {}} }, + { "tools-wizard", { {}} }, + { "view-choose", { {}} }, + { "view-fullscreen", { {}} }, + { "view-media-lyrics", { {}} }, + { "view-media-playlist", { {}} }, + { "view-media-visualization", { {"preferences-desktop-theme"}} }, + { "view-refresh", { {}} }, + { "library-music", { {"vinyl"}} }, + { "vlc", { {}} }, + { "xine", { {}} }, + { "zoom-in", { {}} }, { "zoom-out", { {}, 0, 0 } } };