From 66de69aeaee944cf3130dc75fe3ecb7f383be897 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Tue, 22 Sep 2015 09:08:39 -0700 Subject: Use the Qt-provided media icons. Use Qt's standard pixmaps to build our media playback, stop, and pause icons. Note that we probably don't want to do this for all of the available standard pixmaps. Change-Id: I78541a46a65583d7365cd601c578ebe8f197c060 Reviewed-on: https://code.wireshark.org/review/10609 Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte --- Makefile.am | 3 - image/toolbar.qrc | 2 - image/toolbar/12x12/media-playback-start.png | Bin 256 -> 0 bytes image/toolbar/12x12/media-playback-start.svg | 185 ------------------------ image/toolbar/12x12/media-playback-start@2x.png | Bin 443 -> 0 bytes image/toolbar/svg-to-png.sh | 4 +- ui/qt/stock_icon.cpp | 89 +++++++----- ui/qt/stock_icon.h | 3 + 8 files changed, 61 insertions(+), 225 deletions(-) delete mode 100644 image/toolbar/12x12/media-playback-start.png delete mode 100644 image/toolbar/12x12/media-playback-start.svg delete mode 100644 image/toolbar/12x12/media-playback-start@2x.png diff --git a/Makefile.am b/Makefile.am index 876a6f4fcb..e4d7986d5c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -955,9 +955,6 @@ EXTRA_DIST = \ image/stock_dialog_warning_48.xpm \ image/text2pcap.rc.in \ image/tfshark.rc.in \ - image/toolbar/12x12/media-playback-start.png \ - image/toolbar/12x12/media-playback-start.svg \ - image/toolbar/12x12/media-playback-start@2x.png \ image/toolbar/14x14/x-filter-bookmark.active.png \ image/toolbar/14x14/x-filter-bookmark.active.svg \ image/toolbar/14x14/x-filter-bookmark.active@2x.png \ diff --git a/image/toolbar.qrc b/image/toolbar.qrc index f4b9ec7208..1c9b546070 100644 --- a/image/toolbar.qrc +++ b/image/toolbar.qrc @@ -9,8 +9,6 @@ copy-8.png - toolbar/12x12/media-playback-start.png - toolbar/12x12/media-playback-start@2x.png toolbar/14x14/x-filter-clear.png toolbar/14x14/x-filter-clear@2x.png toolbar/14x14/x-filter-clear.active.png diff --git a/image/toolbar/12x12/media-playback-start.png b/image/toolbar/12x12/media-playback-start.png deleted file mode 100644 index 065d7550e2..0000000000 Binary files a/image/toolbar/12x12/media-playback-start.png and /dev/null differ diff --git a/image/toolbar/12x12/media-playback-start.svg b/image/toolbar/12x12/media-playback-start.svg deleted file mode 100644 index 25156d9dd2..0000000000 --- a/image/toolbar/12x12/media-playback-start.svg +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - diff --git a/image/toolbar/12x12/media-playback-start@2x.png b/image/toolbar/12x12/media-playback-start@2x.png deleted file mode 100644 index 7bdf1bdeca..0000000000 Binary files a/image/toolbar/12x12/media-playback-start@2x.png and /dev/null differ diff --git a/image/toolbar/svg-to-png.sh b/image/toolbar/svg-to-png.sh index cf78ac9587..a4fbc27152 100755 --- a/image/toolbar/svg-to-png.sh +++ b/image/toolbar/svg-to-png.sh @@ -52,7 +52,6 @@ ICONS=" go-last go-next go-previous - media-playback-start x-capture-file-close x-capture-file-save x-capture-file-reload @@ -84,7 +83,8 @@ ICONS=" QRC_FILES="" -for SIZE in 12x12 14x14 16x16 24x14 24x14 ; do +# 12x12 +for SIZE in 14x14 16x16 24x14 24x14 ; do WIDTH=${SIZE/x*/} HEIGHT=${SIZE/*x/} SIZE_DIR=${SIZE} diff --git a/ui/qt/stock_icon.cpp b/ui/qt/stock_icon.cpp index c29fdfac47..ee7231593d 100644 --- a/ui/qt/stock_icon.cpp +++ b/ui/qt/stock_icon.cpp @@ -54,54 +54,67 @@ #include #include +#include #include #include -QString path_pfx_ = ":/icons/toolbar/"; +// XXX We're using icons in more than just the toolbar. +static const QString path_pfx_ = ":/icons/toolbar/"; + +// Map FreeDesktop icon names to Qt standard pixmaps. +static QMap icon_name_to_standard_pixmap_; StockIcon::StockIcon(const QString icon_name) : QIcon() { - if (icon_name.compare("document-open") == 0) { - QIcon dir_icon = fromTheme(icon_name, wsApp->style()->standardIcon(QStyle::SP_DirIcon)); -#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) - swap(dir_icon); -#endif - return; + if (icon_name_to_standard_pixmap_.isEmpty()) { + fillIconNameMap(); } + // Does our theme contain this icon? + // X11 only as per the QIcon documentation. if (hasThemeIcon(icon_name)) { QIcon theme_icon = fromTheme(icon_name); #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) swap(theme_icon); #endif return; - } else { - QStringList types = QStringList() << "12x12" << "14x14" << "16x16" << "24x14" << "24x24"; - foreach (QString type, types) { - QString icon_path = path_pfx_ + QString("%1/%2.png").arg(type).arg(icon_name); - if (QFile::exists(icon_path)) { - addFile(icon_path); - } - - // Along with each name check for ".active" and - // ".selected" for the Active and Selected modes, and - // ".on" to use for the on (checked) state. - // XXX Allow more (or all) combinations. - QString icon_path_active = path_pfx_ + QString("%1/%2.active.png").arg(type).arg(icon_name); - if (QFile::exists(icon_path_active)) { - addFile(icon_path_active, QSize(), QIcon::Active, QIcon::On); - } - - QString icon_path_selected = path_pfx_ + QString("%1/%2.selected.png").arg(type).arg(icon_name); - if (QFile::exists(icon_path_selected)) { - addFile(icon_path_selected, QSize(), QIcon::Selected, QIcon::On); - } - - QString icon_path_on = path_pfx_ + QString("%1/%2.on.png").arg(type).arg(icon_name); - if (QFile::exists(icon_path_on)) { - addFile(icon_path_on, QSize(), QIcon::Normal, QIcon::On); - } + } + + // Is this is an icon we've manually mapped to a standard pixmap below? + if (icon_name_to_standard_pixmap_.contains(icon_name)) { + QIcon standard_icon = wsApp->style()->standardIcon(icon_name_to_standard_pixmap_[icon_name]); +#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) + swap(standard_icon); +#endif + return; + } + + // Is this one of our locally sourced, cage-free, organic icons? + QStringList types = QStringList() << "14x14" << "16x16" << "24x14" << "24x24"; + foreach (QString type, types) { + QString icon_path = path_pfx_ + QString("%1/%2.png").arg(type).arg(icon_name); + if (QFile::exists(icon_path)) { + addFile(icon_path); + } + + // Along with each name check for ".active" and + // ".selected" for the Active and Selected modes, and + // ".on" to use for the on (checked) state. + // XXX Allow more (or all) combinations. + QString icon_path_active = path_pfx_ + QString("%1/%2.active.png").arg(type).arg(icon_name); + if (QFile::exists(icon_path_active)) { + addFile(icon_path_active, QSize(), QIcon::Active, QIcon::On); + } + + QString icon_path_selected = path_pfx_ + QString("%1/%2.selected.png").arg(type).arg(icon_name); + if (QFile::exists(icon_path_selected)) { + addFile(icon_path_selected, QSize(), QIcon::Selected, QIcon::On); + } + + QString icon_path_on = path_pfx_ + QString("%1/%2.on.png").arg(type).arg(icon_name); + if (QFile::exists(icon_path_on)) { + addFile(icon_path_on, QSize(), QIcon::Normal, QIcon::On); } } } @@ -133,6 +146,16 @@ QIcon StockIcon::colorIcon(const QRgb bg_color, const QRgb fg_color, const QStri return color_icon; } +void StockIcon::fillIconNameMap() +{ + // Note that some of Qt's standard pixmaps are awful. We shouldn't add an + // entry just because a match can be made. + icon_name_to_standard_pixmap_["document-open"] = QStyle::SP_DirIcon; + icon_name_to_standard_pixmap_["media-playback-pause"] = QStyle::SP_MediaPause; + icon_name_to_standard_pixmap_["media-playback-start"] = QStyle::SP_MediaPlay; + icon_name_to_standard_pixmap_["media-playback-stop"] = QStyle::SP_MediaStop; +} + /* * Editor modelines * diff --git a/ui/qt/stock_icon.h b/ui/qt/stock_icon.h index 0700bbe60f..3a20230d0c 100644 --- a/ui/qt/stock_icon.h +++ b/ui/qt/stock_icon.h @@ -41,6 +41,9 @@ public: explicit StockIcon(const QString icon_name); static QIcon colorIcon(const QRgb bg_color, const QRgb fg_color, const QString glyph = QString()); + +private: + void fillIconNameMap(); }; #endif // STOCK_ICON_H -- cgit v1.2.3