3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "stock_icon.h"
24 // Stock icons. Based on gtk/stock_icons.h
26 // Toolbar icon sizes:
27 // OS X freestanding: 32x32, 32x32@2x, segmented (inside a button): <= 19x19
28 // Windows: 16x16, 24x24, 32x32
29 // GNOME: 24x24 (default), 48x48
33 // http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
34 // http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
36 // http://mithatkonar.com/wiki/doku.php/qt/icons
38 // https://developer.apple.com/library/mac/documentation/userexperience/conceptual/applehiguidelines/IconsImages/IconsImages.html#//apple_ref/doc/uid/20000967-TPXREF102
39 // http://msdn.microsoft.com/en-us/library/windows/desktop/dn742485.aspx
40 // https://developer.gnome.org/hig-book/stable/icons-types.html.en
41 // http://msdn.microsoft.com/en-us/library/ms246582.aspx
44 // - 32x32, 48x48, 64x64, and unscaled (.svg) icons
45 // - Indent find & go actions when those panes are open.
46 // - Replace or remove:
47 // WIRESHARK_STOCK_CAPTURE_FILTER x-capture-filter
48 // WIRESHARK_STOCK_DISPLAY_FILTER x-display-filter
49 // GTK_STOCK_SELECT_COLOR x-coloring-rules
50 // GTK_STOCK_PREFERENCES preferences-system
51 // GTK_STOCK_HELP help-contents
53 #include "wireshark_application.h"
56 #include <QFontMetrics>
61 // XXX We're using icons in more than just the toolbar.
62 static const QString path_pfx_ = ":/icons/toolbar/";
64 // Map FreeDesktop icon names to Qt standard pixmaps.
65 static QMap<QString, QStyle::StandardPixmap> icon_name_to_standard_pixmap_;
67 StockIcon::StockIcon(const QString icon_name) :
70 if (icon_name_to_standard_pixmap_.isEmpty()) {
74 // Does our theme contain this icon?
75 // X11 only as per the QIcon documentation.
76 if (hasThemeIcon(icon_name)) {
77 QIcon theme_icon = fromTheme(icon_name);
78 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
84 // Is this is an icon we've manually mapped to a standard pixmap below?
85 if (icon_name_to_standard_pixmap_.contains(icon_name)) {
86 QIcon standard_icon = wsApp->style()->standardIcon(icon_name_to_standard_pixmap_[icon_name]);
87 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
93 // Is this one of our locally sourced, cage-free, organic icons?
94 QStringList types = QStringList() << "14x14" << "16x16" << "24x14" << "24x24";
95 foreach (QString type, types) {
96 QString icon_path = path_pfx_ + QString("%1/%2.png").arg(type).arg(icon_name);
97 if (QFile::exists(icon_path)) {
101 // Along with each name check for "<name>.active" and
102 // "<name>.selected" for the Active and Selected modes, and
103 // "<name>.on" to use for the on (checked) state.
104 // XXX Allow more (or all) combinations.
105 QString icon_path_active = path_pfx_ + QString("%1/%2.active.png").arg(type).arg(icon_name);
106 if (QFile::exists(icon_path_active)) {
107 addFile(icon_path_active, QSize(), QIcon::Active, QIcon::On);
110 QString icon_path_selected = path_pfx_ + QString("%1/%2.selected.png").arg(type).arg(icon_name);
111 if (QFile::exists(icon_path_selected)) {
112 addFile(icon_path_selected, QSize(), QIcon::Selected, QIcon::On);
115 QString icon_path_on = path_pfx_ + QString("%1/%2.on.png").arg(type).arg(icon_name);
116 if (QFile::exists(icon_path_on)) {
117 addFile(icon_path_on, QSize(), QIcon::Normal, QIcon::On);
122 // Create a square icon filled with the specified color.
123 QIcon StockIcon::colorIcon(const QRgb bg_color, const QRgb fg_color, const QString glyph)
125 QList<int> sizes = QList<int>() << 12 << 16 << 24 << 32 << 48;
128 foreach (int size, sizes) {
129 QPixmap pm(size, size);
130 QPainter painter(&pm);
131 QRect border(0, 0, size - 1, size - 1);
132 painter.setPen(fg_color);
133 painter.setBrush(QColor(bg_color));
134 painter.drawRect(border);
136 if (!glyph.isEmpty()) {
137 QFont font(wsApp->font());
138 font.setPointSizeF(size / 2.0);
139 painter.setFont(font);
140 QRectF bounding = painter.boundingRect(pm.rect(), glyph, Qt::AlignHCenter | Qt::AlignVCenter);
141 painter.drawText(bounding, glyph);
144 color_icon.addPixmap(pm);
149 void StockIcon::fillIconNameMap()
151 // Note that some of Qt's standard pixmaps are awful. We shouldn't add an
152 // entry just because a match can be made.
153 icon_name_to_standard_pixmap_["document-open"] = QStyle::SP_DirIcon;
154 icon_name_to_standard_pixmap_["media-playback-pause"] = QStyle::SP_MediaPause;
155 icon_name_to_standard_pixmap_["media-playback-start"] = QStyle::SP_MediaPlay;
156 icon_name_to_standard_pixmap_["media-playback-stop"] = QStyle::SP_MediaStop;
165 * indent-tabs-mode: nil
168 * ex: set shiftwidth=4 tabstop=8 expandtab:
169 * :indentSize=4:tabSize=8:noTabs=true: