diff options
Diffstat (limited to 'ui/qt/utils')
-rw-r--r-- | ui/qt/utils/color_utils.cpp | 172 | ||||
-rw-r--r-- | ui/qt/utils/color_utils.h | 87 | ||||
-rw-r--r-- | ui/qt/utils/qt_ui_utils.cpp | 273 | ||||
-rw-r--r-- | ui/qt/utils/qt_ui_utils.h | 238 | ||||
-rw-r--r-- | ui/qt/utils/stock_icon.cpp | 166 | ||||
-rw-r--r-- | ui/qt/utils/stock_icon.h | 62 | ||||
-rw-r--r-- | ui/qt/utils/tango_colors.h | 89 | ||||
-rw-r--r-- | ui/qt/utils/variant_pointer.h | 46 |
8 files changed, 1133 insertions, 0 deletions
diff --git a/ui/qt/utils/color_utils.cpp b/ui/qt/utils/color_utils.cpp new file mode 100644 index 0000000000..907adc8afe --- /dev/null +++ b/ui/qt/utils/color_utils.cpp @@ -0,0 +1,172 @@ +/* color_utils.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <ui/qt/utils/color_utils.h> +#include <ui/qt/utils/tango_colors.h> + +// Colors we use in various parts of the UI. +// +// New colors should be chosen from tango_colors.h. The expert and hidden +// colors come from the GTK+ UI and are grandfathered in. +// +// At some point we should probably make these configurable along with the +// graph and sequence colors. + +const QColor ColorUtils::expert_color_comment = QColor ( 0xb7, 0xf7, 0x74 ); /* Green */ +const QColor ColorUtils::expert_color_chat = QColor ( 0x80, 0xb7, 0xf7 ); /* Light blue */ +const QColor ColorUtils::expert_color_note = QColor ( 0xa0, 0xff, 0xff ); /* Bright turquoise */ +const QColor ColorUtils::expert_color_warn = QColor ( 0xf7, 0xf2, 0x53 ); /* Yellow */ +const QColor ColorUtils::expert_color_error = QColor ( 0xff, 0x5c, 0x5c ); /* Pale red */ +const QColor ColorUtils::expert_color_foreground = QColor ( 0x00, 0x00, 0x00 ); /* Black */ +const QColor ColorUtils::hidden_proto_item = QColor ( 0x44, 0x44, 0x44 ); /* Gray */ + +const QRgb ColorUtils::byte_view_hover_bg_ = tango_butter_2; +const QRgb ColorUtils::byte_view_hover_fg_ = tango_sky_blue_5; + +ColorUtils::ColorUtils(QObject *parent) : + QObject(parent) +{ +} + +QColor ColorUtils::byteViewHoverColor(bool background) +{ + return QColor(background ? byte_view_hover_bg_ : byte_view_hover_fg_); +} + +// +// A color_t has RGB values in [0,65535]. +// Qt RGB colors have RGB values in [0,255]. +// +// 65535/255 = 257 = 0x0101, so converting from [0,255] to +// [0,65535] involves just shifting the 8-bit value left 8 bits +// and ORing them together. +// +// Converting from [0,65535] to [0,255] without rounding involves +// just shifting the 16-bit value right 8 bits; I guess you could +// round them by adding 0x80 to the value before shifting. +// +QColor ColorUtils::fromColorT (const color_t *color) { + if (!color) return QColor(); + // Convert [0,65535] values to [0,255] values + return QColor(color->red >> 8, color->green >> 8, color->blue >> 8); +} + +QColor ColorUtils::fromColorT(color_t color) +{ + return fromColorT(&color); +} + +const color_t ColorUtils::toColorT(const QColor color) +{ + color_t colort; + + // Convert [0,255] values to [0,65535] values + colort.red = (color.red() << 8) | color.red(); + colort.green = (color.green() << 8) | color.green(); + colort.blue = (color.blue() << 8) | color.blue(); + + return colort; +} + +QRgb ColorUtils::alphaBlend(const QColor &color1, const QColor &color2, qreal alpha) +{ + alpha = qBound(qreal(0.0), alpha, qreal(1.0)); + + int r1 = color1.red() * alpha; + int g1 = color1.green() * alpha; + int b1 = color1.blue() * alpha; + int r2 = color2.red() * (1 - alpha); + int g2 = color2.green() * (1 - alpha); + int b2 = color2.blue() * (1 - alpha); + + QColor alpha_color(r1 + r2, g1 + g2, b1 + b2); + return alpha_color.rgb(); +} + +QRgb ColorUtils::alphaBlend(const QBrush &brush1, const QBrush &brush2, qreal alpha) +{ + return alphaBlend(brush1.color(), brush2.color(), alpha); +} + +QList<QRgb> ColorUtils::graph_colors_; +const QList<QRgb> ColorUtils::graphColors() +{ + if (graph_colors_.isEmpty()) { + // Available graph colors + // XXX - Add custom + graph_colors_ = QList<QRgb>() + << tango_aluminium_6 // Bar outline (use black instead)? + << tango_sky_blue_5 + << tango_butter_6 + << tango_chameleon_5 + << tango_scarlet_red_5 + << tango_plum_5 + << tango_orange_6 + << tango_aluminium_3 + << tango_sky_blue_3 + << tango_butter_3 + << tango_chameleon_3 + << tango_scarlet_red_3 + << tango_plum_3 + << tango_orange_3; + } + return graph_colors_; +} + +QRgb ColorUtils::graphColor(int item) +{ + if (graph_colors_.isEmpty()) graphColors(); // Init list. + return graph_colors_[item % graph_colors_.size()]; +} + +QList<QRgb> ColorUtils::sequence_colors_; +QRgb ColorUtils::sequenceColor(int item) +{ + if (sequence_colors_.isEmpty()) { + // Available sequence colors. Copied from gtk/graph_analysis.c. + // XXX - Add custom? + sequence_colors_ = QList<QRgb>() + << qRgb(144, 238, 144) + << qRgb(255, 160, 123) + << qRgb(255, 182, 193) + << qRgb(250, 250, 210) + << qRgb(255, 255, 52) + << qRgb(103, 205, 170) + << qRgb(224, 255, 255) + << qRgb(176, 196, 222) + << qRgb(135, 206, 254) + << qRgb(211, 211, 211); + } + return sequence_colors_[item % sequence_colors_.size()]; +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/utils/color_utils.h b/ui/qt/utils/color_utils.h new file mode 100644 index 0000000000..356c963539 --- /dev/null +++ b/ui/qt/utils/color_utils.h @@ -0,0 +1,87 @@ +/* color_utils.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef COLOR_UTILS_H +#define COLOR_UTILS_H + +#include <config.h> + +#include <glib.h> + +#include <epan/color_filters.h> + +#include <QBrush> +#include <QColor> +#include <QObject> + +class ColorUtils : public QObject +{ + Q_OBJECT +public: + explicit ColorUtils(QObject *parent = 0); + + static QColor fromColorT(const color_t *color); + static QColor fromColorT(color_t color); + static const color_t toColorT(const QColor color); + static QRgb alphaBlend(const QColor &color1, const QColor &color2, qreal alpha); + static QRgb alphaBlend(const QBrush &brush1, const QBrush &brush2, qreal alpha); + + // ...because they don't really fit anywhere else? + static const QColor expert_color_comment; /* green */ + static const QColor expert_color_chat; /* light blue */ + static const QColor expert_color_note; /* bright turquoise */ + static const QColor expert_color_warn; /* yellow */ + static const QColor expert_color_error; /* pale red */ + static const QColor expert_color_foreground; /* black */ + static const QColor hidden_proto_item; /* gray */ + + static const QList<QRgb> graphColors(); + static QRgb graphColor(int item); + static QRgb sequenceColor(int item); + static QColor byteViewHoverColor(bool background); + +signals: + +public slots: + +private: + static QList<QRgb> graph_colors_; + static QList<QRgb> sequence_colors_; + static const QRgb byte_view_hover_bg_; + static const QRgb byte_view_hover_fg_; +}; + +void color_filter_qt_add_cb(color_filter_t *colorf, gpointer user_data); + +#endif // COLOR_UTILS_H + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/utils/qt_ui_utils.cpp b/ui/qt/utils/qt_ui_utils.cpp new file mode 100644 index 0000000000..46debbcd14 --- /dev/null +++ b/ui/qt/utils/qt_ui_utils.cpp @@ -0,0 +1,273 @@ +/* qt_ui_utils.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <ui/qt/utils/qt_ui_utils.h> + +#include <epan/addr_resolv.h> +#include <epan/range.h> +#include <epan/to_str.h> +#include <epan/value_string.h> + +#include <ui/recent.h> +#include <ui/ui_util.h> + +#include <wsutil/str_util.h> + +#include <QAction> +#include <QApplication> +#include <QDateTime> +#include <QDesktopServices> +#include <QDesktopWidget> +#include <QDir> +#include <QFileInfo> +#include <QFontDatabase> +#include <QProcess> +#include <QUrl> +#include <QUuid> + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +// Qt::escape +#include <QTextDocument> +#endif + +/* Make the format_size_flags_e enum usable in C++ */ +format_size_flags_e operator|(format_size_flags_e lhs, format_size_flags_e rhs) { + return (format_size_flags_e) ((int)lhs| (int)rhs); +} + +/* + * We might want to create our own "wsstring" class with convenience + * methods for handling g_malloc()ed strings, GStrings, and a shortcut + * to .toUtf8().constData(). + */ + +gchar *qstring_strdup(QString q_string) { + return g_strdup(q_string.toUtf8().constData()); +} + +QString gchar_free_to_qstring(gchar *glib_string) { + return QString(gchar_free_to_qbytearray(glib_string)); +} + +QByteArray gchar_free_to_qbytearray(gchar *glib_string) +{ + QByteArray qt_bytearray(glib_string); + g_free(glib_string); + return qt_bytearray; +} + +QByteArray gstring_free_to_qbytearray(GString *glib_gstring) +{ + QByteArray qt_ba(glib_gstring->str); + g_string_free(glib_gstring, TRUE); + return qt_ba; +} + +const QString int_to_qstring(qint64 value, int field_width, int base) +{ + // Qt deprecated QString::sprintf in Qt 5.0, then added ::asprintf in + // Qt 5.5. Rather than navigate a maze of QT_VERSION_CHECKs, just use + // QString::arg. + QString int_qstr; + + switch (base) { + case 8: + int_qstr = "0"; + break; + case 16: + int_qstr = "0x"; + break; + default: + break; + } + + int_qstr += QString("%1").arg(value, field_width, base, QChar('0')); + return int_qstr; +} + +const QString address_to_qstring(const _address *address, bool enclose) +{ + QString address_qstr = QString(); + if (address) { + if (enclose && address->type == AT_IPv6) address_qstr += "["; + gchar *address_gchar_p = address_to_str(NULL, address); + address_qstr += address_gchar_p; + wmem_free(NULL, address_gchar_p); + if (enclose && address->type == AT_IPv6) address_qstr += "]"; + } + return address_qstr; +} + +const QString address_to_display_qstring(const _address *address) +{ + QString address_qstr = QString(); + if (address) { + gchar *address_gchar_p = address_to_display(NULL, address); + address_qstr = address_gchar_p; + wmem_free(NULL, address_gchar_p); + } + return address_qstr; +} + +const QString val_to_qstring(const guint32 val, const value_string *vs, const char *fmt) +{ + QString val_qstr = QString(); + gchar* gchar_p = val_to_str_wmem(NULL, val, vs, fmt); + val_qstr = gchar_p; + wmem_free(NULL, gchar_p); + + return val_qstr; +} + +const QString val_ext_to_qstring(const guint32 val, value_string_ext *vse, const char *fmt) +{ + QString val_qstr = QString(); + gchar* gchar_p = val_to_str_ext_wmem(NULL, val, vse, fmt); + val_qstr = gchar_p; + wmem_free(NULL, gchar_p); + + return val_qstr; +} + +const QString range_to_qstring(const epan_range *range) +{ + QString range_qstr = QString(); + if (range) { + gchar *range_gchar_p = range_convert_range(NULL, range); + range_qstr = range_gchar_p; + wmem_free(NULL, range_gchar_p); + } + return range_qstr; +} + +const QString bits_s_to_qstring(const double bits_s) +{ + return gchar_free_to_qstring( + format_size(bits_s, format_size_unit_none|format_size_prefix_si)); +} + +const QString file_size_to_qstring(const gint64 size) +{ + return gchar_free_to_qstring( + format_size(size, format_size_unit_bytes|format_size_prefix_si)); +} + +const QString time_t_to_qstring(time_t ti_time) +{ + QDateTime date_time = QDateTime::fromTime_t(uint(ti_time)); + QString time_str = date_time.toLocalTime().toString("yyyy-MM-dd hh:mm:ss"); + return time_str; +} + +QString html_escape(const QString plain_string) { +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + return Qt::escape(plain_string); +#else + return plain_string.toHtmlEscaped(); +#endif +} + + +void smooth_font_size(QFont &font) { + QFontDatabase fdb; + QList<int> size_list = fdb.smoothSizes(font.family(), font.styleName()); + + if (size_list.size() < 2) return; + + int last_size = size_list.takeFirst(); + foreach (int cur_size, size_list) { + if (font.pointSize() > last_size && font.pointSize() <= cur_size) { + font.setPointSize(cur_size); + return; + } + last_size = cur_size; + } +} + +bool qActionLessThan(const QAction * a1, const QAction * a2) { + return a1->text().compare(a2->text()) < 0; +} + +bool qStringCaseLessThan(const QString &s1, const QString &s2) +{ + return s1.compare(s2, Qt::CaseInsensitive) < 0; +} + +// http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt +void desktop_show_in_folder(const QString file_path) +{ + bool success = false; + +#if defined(Q_OS_WIN) + QString path = QDir::toNativeSeparators(file_path); + QString command = "explorer.exe /select," + path; + success = QProcess::startDetached(command); +#elif defined(Q_OS_MAC) + QStringList script_args; + QString escaped_path = file_path; + + escaped_path.replace('"', "\\\""); + script_args << "-e" + << QString("tell application \"Finder\" to reveal POSIX file \"%1\"") + .arg(escaped_path); + if (QProcess::execute("/usr/bin/osascript", script_args) == 0) { + success = true; + script_args.clear(); + script_args << "-e" + << "tell application \"Finder\" to activate"; + QProcess::execute("/usr/bin/osascript", script_args); + } +#else + // Is there a way to highlight the file using xdg-open? +#endif + if (!success) { // Last resort + QFileInfo file_info = file_path; + QDesktopServices::openUrl(QUrl::fromLocalFile(file_info.dir().absolutePath())); + } +} + +bool rect_on_screen(const QRect &rect) +{ + QDesktopWidget *desktop = qApp->desktop(); + for (int i = 0; i < desktop->screenCount(); i++) { + if (desktop->availableGeometry(i).contains(rect)) + return true; + } + + return false; +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/utils/qt_ui_utils.h b/ui/qt/utils/qt_ui_utils.h new file mode 100644 index 0000000000..3eb159c5f9 --- /dev/null +++ b/ui/qt/utils/qt_ui_utils.h @@ -0,0 +1,238 @@ +/* qt_gui_utils.h + * Declarations of GTK+-specific UI utility routines + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __QT_UI_UTILS_H__ +#define __QT_UI_UTILS_H__ + +// xxx - copied from ui/gtk/gui_utils.h + +/** @file + * Utility functions for working with the Wireshark and GLib APIs. + */ + +#include <config.h> + +#include <glib.h> + +#include <QString> + +class QAction; +class QFont; +class QRect; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +// These are defined elsewhere in ../gtk/ +#define RECENT_KEY_CAPTURE_FILE "recent.capture_file" +#define RECENT_KEY_REMOTE_HOST "recent.remote_host" + +struct _address; +struct epan_range; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/** Create a glib-compatible copy of a QString. + * + * @param q_string A QString. + * + * @return A copy of the QString. UTF-8 allocated with g_malloc(). + */ +gchar *qstring_strdup(QString q_string); + +/** Transfer ownership of a GLib character string to a newly constructed QString + * + * @param glib_string A string allocated with g_malloc() or NULL. Will be + * freed. + * + * @return A QString instance created from the input string. + */ +QString gchar_free_to_qstring(gchar *glib_string); + +/** Transfer ownership of a GLib character string to a newly constructed QString + * + * @param glib_string A string allocated with g_malloc() or NULL. Will be + * freed. + * + * @return A QByteArray instance created from the input string. + */ +QByteArray gchar_free_to_qbytearray(gchar *glib_string); + +/** Transfer ownership of a GLib character string to a newly constructed QByteArray + * + * @param glib_gstring A string allocated with g_malloc() or NULL. Will be + * freed. + * + * @return A QByteArray instance created from the input string. + */ +QByteArray gstring_free_to_qbytearray(GString *glib_gstring); + +/** Convert an integer to a formatted string representation. + * + * @param value The integer to format. + * @param field_width Width of the output, not including any base prefix. + * Output will be zero-padded. + * @param base Number base between 2 and 36 (limited by QString::arg). + * + * @return A QString representation of the integer + */ +const QString int_to_qstring(qint64 value, int field_width = 0, int base = 10); + +/** Convert an address to a QString using address_to_str(). + * + * @param address A pointer to an address. + * @param enclose Enclose IPv6 addresses in square brackets. + * + * @return A QString representation of the address. May be the null string (QString()) + */ +const QString address_to_qstring(const struct _address *address, bool enclose = false); + +/** Convert an address to a QString using address_to_display(). + * + * @param address A pointer to an address. + * + * @return A QString representation of the address. May be the null string (QString()) + */ +const QString address_to_display_qstring(const struct _address *address); + +/** Convert a value_string to a QString using val_to_str_wmem(). + * + * @param val The value to convert to string. + * @param vs value_string array. + * @param fmt Formatting for value not in array. + * + * @return A QString representation of the value_string. + */ +const QString val_to_qstring(const guint32 val, const struct _value_string *vs, const char *fmt) +G_GNUC_PRINTF(3, 0); + +/** Convert a value_string_ext to a QString using val_to_str_ext_wmem(). + * + * @param val The value to convert to string. + * @param vse value_string_ext array. + * @param fmt Formatting for value not in array. + * + * @return A QString representation of the value_string_ext. + */ +const QString val_ext_to_qstring(const guint32 val, struct _value_string_ext *vse, const char *fmt) +G_GNUC_PRINTF(3, 0); + +/** Convert a range to a QString using range_convert_range(). + * + * @param range A pointer to an range struct. + * + * @return A QString representation of the address. May be the null string (QString()) + */ +const QString range_to_qstring(const struct epan_range *range); + +/** Convert a bits per second value to a human-readable QString using format_size(). + * + * @param bits_s The value to convert to string. + * + * @return A QString representation of the data rate in SI units. + */ +const QString bits_s_to_qstring(const double bits_s); + +/** Convert a file size value to a human-readable QString using format_size(). + * + * @param size The value to convert to string. + * + * @return A QString representation of the file size in SI units. + */ +const QString file_size_to_qstring(const gint64 size); + +/** Convert a time_t value to a human-readable QString using QDateTime. + * + * @param ti_time The value to convert. + * + * @return A QString representation of the file size in SI units. + */ +const QString time_t_to_qstring(time_t ti_time); + +/** Escape HTML metacharacters in a string. + * + * @param plain_string String to convert. + * + * @return A QString with escaped metacharacters. + */ +QString html_escape(const QString plain_string); + +/** + * Round the current size of a font up to its next "smooth" size. + * If a smooth size can't be found the font is left unchanged. + * + * @param font The font to smooth. + */ +void smooth_font_size(QFont &font); + +/** + * Compare the text of two QActions. Useful for passing to std::sort. + * + * @param a1 First action + * @param a2 Second action + */ +bool qActionLessThan(const QAction *a1, const QAction *a2); + +/** + * Compare two QStrings, ignoring case. Useful for passing to std::sort. + * + * @param s1 First string + * @param s2 Second string + */ +bool qStringCaseLessThan(const QString &s1, const QString &s2); + +/** + * Given the path to a file, open its containing folder in the desktop + * shell. Highlight the file if possible. + * + * @param file_path Path to the file. + */ +void desktop_show_in_folder(const QString file_path); + +/** + * Test to see if a rect is visible on screen. + * + * @param rect The rect to test, typically a "recent.gui_geometry_*" setting. + * @return true if the rect is completely enclosed by one of the display + * screens, false otherwise. + */ +bool rect_on_screen(const QRect &rect); + +#endif /* __QT_UI_UTILS__H__ */ + +// XXX Add a routine to fetch the HWND corresponding to a widget using QPlatformIntegration + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/utils/stock_icon.cpp b/ui/qt/utils/stock_icon.cpp new file mode 100644 index 0000000000..985c60b2ec --- /dev/null +++ b/ui/qt/utils/stock_icon.cpp @@ -0,0 +1,166 @@ +/* stock_icon.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <ui/qt/utils/stock_icon.h> + +// Stock icons. Based on gtk/stock_icons.h + +// Toolbar icon sizes: +// macOS freestanding: 32x32, 32x32@2x, segmented (inside a button): <= 19x19 +// Windows: 16x16, 24x24, 32x32 +// GNOME: 24x24 (default), 48x48 + +// References: +// +// http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html +// http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html +// +// http://mithatkonar.com/wiki/doku.php/qt/icons +// +// https://developer.apple.com/library/mac/documentation/userexperience/conceptual/applehiguidelines/IconsImages/IconsImages.html#//apple_ref/doc/uid/20000967-TPXREF102 +// http://msdn.microsoft.com/en-us/library/windows/desktop/dn742485.aspx +// https://developer.gnome.org/hig-book/stable/icons-types.html.en +// http://msdn.microsoft.com/en-us/library/ms246582.aspx + +// To do: +// - 32x32, 48x48, 64x64, and unscaled (.svg) icons +// - Indent find & go actions when those panes are open. +// - Replace or remove: +// WIRESHARK_STOCK_CAPTURE_FILTER x-capture-filter +// WIRESHARK_STOCK_DISPLAY_FILTER x-display-filter +// GTK_STOCK_SELECT_COLOR x-coloring-rules +// GTK_STOCK_PREFERENCES preferences-system +// GTK_STOCK_HELP help-contents + +#include "wireshark_application.h" + +#include <QFile> +#include <QFontMetrics> +#include <QMap> +#include <QPainter> +#include <QStyle> + +// 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<QString, QStyle::StandardPixmap> icon_name_to_standard_pixmap_; + +StockIcon::StockIcon(const QString icon_name) : + QIcon() +{ + 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); + swap(theme_icon); + return; + } + + // 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]); + swap(standard_icon); + 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 "<name>.active" and + // "<name>.selected" for the Active and Selected modes, and + // "<name>.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); + } + } +} + +// Create a square icon filled with the specified color. +QIcon StockIcon::colorIcon(const QRgb bg_color, const QRgb fg_color, const QString glyph) +{ + QList<int> sizes = QList<int>() << 12 << 16 << 24 << 32 << 48; + QIcon color_icon; + + foreach (int size, sizes) { + QPixmap pm(size, size); + QPainter painter(&pm); + QRect border(0, 0, size - 1, size - 1); + painter.setPen(fg_color); + painter.setBrush(QColor(bg_color)); + painter.drawRect(border); + + if (!glyph.isEmpty()) { + QFont font(wsApp->font()); + font.setPointSizeF(size / 2.0); + painter.setFont(font); + QRectF bounding = painter.boundingRect(pm.rect(), glyph, Qt::AlignHCenter | Qt::AlignVCenter); + painter.drawText(bounding, glyph); + } + + color_icon.addPixmap(pm); + } + 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 + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/utils/stock_icon.h b/ui/qt/utils/stock_icon.h new file mode 100644 index 0000000000..3a20230d0c --- /dev/null +++ b/ui/qt/utils/stock_icon.h @@ -0,0 +1,62 @@ +/* stock_icon.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef STOCK_ICON_H +#define STOCK_ICON_H + +#include <QIcon> + +/** @file + * Goal: Beautiful icons appropriate for each of our supported platforms. + */ + +// Supported standard names: +// document-open + +// Supported custom names (see images/toolbar): +// x-capture-file-close +// x-capture-file-save + +class StockIcon : public QIcon +{ +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 + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/utils/tango_colors.h b/ui/qt/utils/tango_colors.h new file mode 100644 index 0000000000..c26d501971 --- /dev/null +++ b/ui/qt/utils/tango_colors.h @@ -0,0 +1,89 @@ +/* qt_gui_utils.h + * Tango theme colors + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __TANGO_COLORS_H__ +#define __TANGO_COLORS_H__ + +// http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines +// with added hues from http://emilis.info/other/extended_tango/ +// (all colors except aluminium) + +const QRgb tango_aluminium_1 = 0xeeeeec; +const QRgb tango_aluminium_2 = 0xd3d7cf; +const QRgb tango_aluminium_3 = 0xbabdb6; +const QRgb tango_aluminium_4 = 0x888a85; +const QRgb tango_aluminium_5 = 0x555753; +const QRgb tango_aluminium_6 = 0x2e3436; + +const QRgb tango_butter_1 = 0xfeffd0; +const QRgb tango_butter_2 = 0xfffc9c; +const QRgb tango_butter_3 = 0xfce94f; +const QRgb tango_butter_4 = 0xedd400; +const QRgb tango_butter_5 = 0xc4a000; +const QRgb tango_butter_6 = 0x725000; + +const QRgb tango_chameleon_1 = 0xe4ffc7; +const QRgb tango_chameleon_2 = 0xb7f774; +const QRgb tango_chameleon_3 = 0x8ae234; +const QRgb tango_chameleon_4 = 0x73d216; +const QRgb tango_chameleon_5 = 0x4e9a06; +const QRgb tango_chameleon_6 = 0x2a5703; + +const QRgb tango_chocolate_1 = 0xfaf0d7; +const QRgb tango_chocolate_2 = 0xefd0a7; +const QRgb tango_chocolate_3 = 0xe9b96e; +const QRgb tango_chocolate_4 = 0xc17d11; +const QRgb tango_chocolate_5 = 0x8f5902; +const QRgb tango_chocolate_6 = 0x503000; + +const QRgb tango_orange_1 = 0xfff0d7; +const QRgb tango_orange_2 = 0xffd797; +const QRgb tango_orange_3 = 0xfcaf3e; +const QRgb tango_orange_4 = 0xf57900; +const QRgb tango_orange_5 = 0xce5c00; +const QRgb tango_orange_6 = 0x8c3700; + +const QRgb tango_plum_1 = 0xfce0ff; +const QRgb tango_plum_2 = 0xe0c0e4; +const QRgb tango_plum_3 = 0xad7fa8; +const QRgb tango_plum_4 = 0x75507b; +const QRgb tango_plum_5 = 0x5c3566; +const QRgb tango_plum_6 = 0x371740; + +const QRgb tango_scarlet_red_1 = 0xffcccc; +const QRgb tango_scarlet_red_2 = 0xf78787; +const QRgb tango_scarlet_red_3 = 0xef2929; +const QRgb tango_scarlet_red_4 = 0xcc0000; +const QRgb tango_scarlet_red_5 = 0xa40000; +const QRgb tango_scarlet_red_6 = 0x600000; + +const QRgb tango_sky_blue_1 = 0xdaeeff; +const QRgb tango_sky_blue_2 = 0x97c4f0; +const QRgb tango_sky_blue_3 = 0x729fcf; +const QRgb tango_sky_blue_4 = 0x3465a4; +const QRgb tango_sky_blue_5 = 0x204a87; +const QRgb tango_sky_blue_6 = 0x0a3050; + +const QRgb ws_css_warn_background = tango_butter_2; +const QRgb ws_css_warn_text = tango_aluminium_6; + +#endif // __TANGO_COLORS_H__ diff --git a/ui/qt/utils/variant_pointer.h b/ui/qt/utils/variant_pointer.h new file mode 100644 index 0000000000..7069fc3db1 --- /dev/null +++ b/ui/qt/utils/variant_pointer.h @@ -0,0 +1,46 @@ +/* + * variant_pointer.h + * Range routines + * + * Roland Knall <rknall@gmail.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef UI_QT_VARIANT_POINTER_H_ +#define UI_QT_VARIANT_POINTER_H_ + +#include <QVariant> + +template <typename T> class VariantPointer +{ + +public: + static T* asPtr(QVariant v) + { + return (T *) v.value<void *>(); + } + + static QVariant asQVariant(T* ptr) + { + return qVariantFromValue((void *) ptr); + } +}; + +#endif /* UI_QT_VARIANT_POINTER_H_ */ |