diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-09-10 14:42:07 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-09-11 15:27:21 +0000 |
commit | b55ae49ba1947ae5cbf8ad12ff3b8855a5fd7813 (patch) | |
tree | b5c6c723a66d803b1c61b4602dd1b9bc835660cf /ui/qt/display_filter_edit.cpp | |
parent | 5a3ad8fe06f12fc68ccb99a2b1ebd90e2bbf263c (diff) |
Make StockIconToolButton independent.
A recent set of changes replaced the "dfilter_erase_" images with an
"x-filter-clear" stock icon set.
Move StockIconToolButton to its own compilation unit. Use it in
CaptureFilterEdit and ProgressFrame to load the "x-filter-clear" icon.
Bug: 11516
Change-Id: I5d5864d089fb56827d130d493d53e7de6a7c03b5
Reviewed-on: https://code.wireshark.org/review/10475
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/display_filter_edit.cpp')
-rw-r--r-- | ui/qt/display_filter_edit.cpp | 96 |
1 files changed, 1 insertions, 95 deletions
diff --git a/ui/qt/display_filter_edit.cpp b/ui/qt/display_filter_edit.cpp index ff2c6df435..863729f7e3 100644 --- a/ui/qt/display_filter_edit.cpp +++ b/ui/qt/display_filter_edit.cpp @@ -31,23 +31,17 @@ #include "display_filter_edit.h" #include "filter_dialog.h" -#include "stock_icon.h" +#include "stock_icon_tool_button.h" #include "syntax_line_edit.h" #include <QAction> #include <QAbstractItemView> -#include <QApplication> #include <QComboBox> #include <QCompleter> #include <QEvent> -#include <QIcon> -#include <QPixmap> #include <QMenu> -#include <QMouseEvent> #include <QPainter> #include <QStringListModel> -#include <QStyleOptionFrame> -#include <QToolButton> #include "ui/utf8_entities.h" @@ -57,94 +51,6 @@ // - Add a separator or otherwise distinguish between recent items and fields // in the completion dropdown. -// We want nice icons that render correctly, and that are responsive -// when the user hovers and clicks them. -// Using setIcon renders correctly on normal and retina displays. It is -// not completely responsive, particularly on OS X. -// Calling setStyleSheet is responsive, but does not render correctly on -// retina displays: https://bugreports.qt.io/browse/QTBUG-36825 -// Subclass QToolButton, which lets us catch events and set icons as needed. - -class StockIconToolButton : public QToolButton -{ -public: - explicit StockIconToolButton(QWidget * parent = 0, QString stock_icon_name = QString()) : - QToolButton(parent), - leave_timer_(0) - { - if (!stock_icon_name.isEmpty()) { - setStockIcon(stock_icon_name); - } - } - - void setIconMode(QIcon::Mode mode = QIcon::Normal) { - QIcon mode_icon; - QList<QIcon::State> states = QList<QIcon::State>() << QIcon::Off << QIcon::On; - foreach (QIcon::State state, states) { - foreach (QSize size, base_icon_.availableSizes(mode, state)) { - mode_icon.addPixmap(base_icon_.pixmap(size, mode, state), mode, state); - } - } - setIcon(mode_icon); - } - - void setStockIcon(QString icon_name) { - base_icon_ = StockIcon(icon_name); - setIconMode(); - } - -protected: - virtual bool event(QEvent *event) { - switch (event->type()) { - case QEvent::Enter: - if (isEnabled()) { - setIconMode(QIcon::Active); - if (leave_timer_ > 0) killTimer(leave_timer_); - leave_timer_ = startTimer(leave_interval_); - } - break; - case QEvent::MouseButtonPress: - if (isEnabled()) { - setIconMode(QIcon::Selected); - } - break; - case QEvent::Leave: - if (leave_timer_ > 0) killTimer(leave_timer_); - leave_timer_ = 0; - case QEvent::MouseButtonRelease: - setIconMode(); - break; - case QEvent::Timer: - { - // We can lose QEvent::Leave, QEvent::HoverLeave and underMouse() - // if a tooltip appears, at least OS X: - // https://bugreports.qt.io/browse/QTBUG-46379 - // Work around the issue by periodically checking the mouse - // position and scheduling a fake leave event when the mouse - // moves away. - QTimerEvent *te = (QTimerEvent *) event; - bool under_mouse = rect().contains(mapFromGlobal(QCursor::pos())); - if (te->timerId() == leave_timer_ && !under_mouse) { - killTimer(leave_timer_); - leave_timer_ = 0; - QMouseEvent *me = new QMouseEvent(QEvent::Leave, mapFromGlobal(QCursor::pos()), Qt::NoButton, Qt::NoButton, Qt::NoModifier); - QApplication::postEvent(this, me); - } - break; - } - default: - break; - } - - return QToolButton::event(event); - } - -private: - QIcon base_icon_; - int leave_timer_; - static const int leave_interval_ = 500; // ms -}; - #if defined(Q_OS_MAC) && 0 // http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html // http://www.virtualbox.org/svn/vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.mm |