forked from osmocom/wireshark
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>
This commit is contained in:
parent
5a3ad8fe06
commit
b55ae49ba1
|
@ -125,6 +125,7 @@ set(WIRESHARK_QT_HEADERS
|
||||||
stats_tree_dialog.h
|
stats_tree_dialog.h
|
||||||
service_response_time_dialog.h
|
service_response_time_dialog.h
|
||||||
simple_statistics_dialog.h
|
simple_statistics_dialog.h
|
||||||
|
stock_icon_tool_button.h
|
||||||
syntax_line_edit.h
|
syntax_line_edit.h
|
||||||
tap_parameter_dialog.h
|
tap_parameter_dialog.h
|
||||||
tcp_stream_dialog.h
|
tcp_stream_dialog.h
|
||||||
|
@ -259,6 +260,7 @@ set(WIRESHARK_QT_SRC
|
||||||
splash_overlay.cpp
|
splash_overlay.cpp
|
||||||
sparkline_delegate.cpp
|
sparkline_delegate.cpp
|
||||||
stock_icon.cpp
|
stock_icon.cpp
|
||||||
|
stock_icon_tool_button.cpp
|
||||||
syntax_line_edit.cpp
|
syntax_line_edit.cpp
|
||||||
tap_parameter_dialog.cpp
|
tap_parameter_dialog.cpp
|
||||||
tcp_stream_dialog.cpp
|
tcp_stream_dialog.cpp
|
||||||
|
|
|
@ -244,6 +244,7 @@ MOC_HDRS = \
|
||||||
sparkline_delegate.h \
|
sparkline_delegate.h \
|
||||||
splash_overlay.h \
|
splash_overlay.h \
|
||||||
stats_tree_dialog.h \
|
stats_tree_dialog.h \
|
||||||
|
stock_icon_tool_button.h \
|
||||||
syntax_line_edit.h \
|
syntax_line_edit.h \
|
||||||
tap_parameter_dialog.h \
|
tap_parameter_dialog.h \
|
||||||
tcp_stream_dialog.h \
|
tcp_stream_dialog.h \
|
||||||
|
@ -483,6 +484,7 @@ WIRESHARK_QT_SRC = \
|
||||||
sparkline_delegate.cpp \
|
sparkline_delegate.cpp \
|
||||||
splash_overlay.cpp \
|
splash_overlay.cpp \
|
||||||
stock_icon.cpp \
|
stock_icon.cpp \
|
||||||
|
stock_icon_tool_button.cpp \
|
||||||
syntax_line_edit.cpp \
|
syntax_line_edit.cpp \
|
||||||
tap_parameter_dialog.cpp \
|
tap_parameter_dialog.cpp \
|
||||||
tcp_stream_dialog.cpp \
|
tcp_stream_dialog.cpp \
|
||||||
|
|
|
@ -641,6 +641,7 @@ HEADERS += \
|
||||||
sequence_dialog.h \
|
sequence_dialog.h \
|
||||||
simple_dialog.h \
|
simple_dialog.h \
|
||||||
sparkline_delegate.h \
|
sparkline_delegate.h \
|
||||||
|
stock_icon_tool_button.h \
|
||||||
syntax_line_edit.h \
|
syntax_line_edit.h \
|
||||||
tap_parameter_dialog.h \
|
tap_parameter_dialog.h \
|
||||||
time_shift_dialog.h \
|
time_shift_dialog.h \
|
||||||
|
@ -760,6 +761,7 @@ SOURCES += \
|
||||||
splash_overlay.cpp \
|
splash_overlay.cpp \
|
||||||
stats_tree_dialog.cpp \
|
stats_tree_dialog.cpp \
|
||||||
stock_icon.cpp \
|
stock_icon.cpp \
|
||||||
|
stock_icon_tool_button.cpp \
|
||||||
syntax_line_edit.cpp \
|
syntax_line_edit.cpp \
|
||||||
tap_parameter_dialog.cpp \
|
tap_parameter_dialog.cpp \
|
||||||
tcp_stream_dialog.cpp \
|
tcp_stream_dialog.cpp \
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "capture_filter_edit.h"
|
#include "capture_filter_edit.h"
|
||||||
#include "capture_filter_syntax_worker.h"
|
#include "capture_filter_syntax_worker.h"
|
||||||
|
#include "stock_icon_tool_button.h"
|
||||||
#include "wireshark_application.h"
|
#include "wireshark_application.h"
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
@ -124,90 +125,54 @@ CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) :
|
||||||
setPlaceholderText(placeholder_text_);
|
setPlaceholderText(placeholder_text_);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// DFCombo
|
// These are fully implemented in DisplayFilterEdit but not here.
|
||||||
// Bookmark (star)
|
|
||||||
// DispalyFilterEdit
|
|
||||||
// Clear button
|
|
||||||
// Apply (right arrow) + Cancel (x) + Reload (arrowed circle)
|
|
||||||
// Combo drop-down
|
|
||||||
|
|
||||||
// XXX - Move bookmark and apply buttons to the toolbar a la Firefox, Chrome & Safari?
|
|
||||||
// XXX - Use native buttons on OS X?
|
|
||||||
|
|
||||||
if (!plain_) {
|
if (!plain_) {
|
||||||
bookmark_button_ = new QToolButton(this);
|
bookmark_button_ = new StockIconToolButton(this, "x-filter-bookmark");
|
||||||
bookmark_button_->setCursor(Qt::ArrowCursor);
|
bookmark_button_->setCursor(Qt::ArrowCursor);
|
||||||
bookmark_button_->setStyleSheet(QString(
|
bookmark_button_->setPopupMode(QToolButton::InstantPopup);
|
||||||
"QToolButton { /* all types of tool button */"
|
bookmark_button_->setToolTip(tr("Manage saved bookmarks."));
|
||||||
" border 0 0 0 0;"
|
bookmark_button_->setIconSize(QSize(14, 14));
|
||||||
#ifdef Q_OS_MAC
|
bookmark_button_->setStyleSheet(
|
||||||
" border-right: %1px solid gray;"
|
"QToolButton {"
|
||||||
#else
|
" border: none;"
|
||||||
" border-right: %1px solid palette(shadow);"
|
" background: transparent;" // Disables platform style on Windows.
|
||||||
#endif
|
" padding: 0 0 0 0;"
|
||||||
" border-top-left-radius: 3px;"
|
"}"
|
||||||
" border-bottom-left-radius: 3px;"
|
"QToolButton::menu-indicator { image: none; }"
|
||||||
" padding-left: 1px;"
|
|
||||||
" image: url(:/dfilter/dfilter_bookmark_normal.png) center;"
|
|
||||||
"}"
|
|
||||||
|
|
||||||
"QToolButton:hover {"
|
|
||||||
" image: url(:/dfilter/dfilter_bookmark_hover.png) center;"
|
|
||||||
"}"
|
|
||||||
"QToolButton:pressed {"
|
|
||||||
" image: url(:/dfilter/dfilter_bookmark_pressed.png) center;"
|
|
||||||
"}"
|
|
||||||
"QToolButton:disabled {"
|
|
||||||
" image: url(:/dfilter/dfilter_bookmark_disabled.png) center;"
|
|
||||||
"}"
|
|
||||||
).arg(plain_ ? 0 : 1)
|
|
||||||
);
|
);
|
||||||
connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked()));
|
connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plain_) {
|
if (!plain_) {
|
||||||
clear_button_ = new QToolButton(this);
|
clear_button_ = new StockIconToolButton(this, "x-filter-clear");
|
||||||
clear_button_->setCursor(Qt::ArrowCursor);
|
clear_button_->setCursor(Qt::ArrowCursor);
|
||||||
|
clear_button_->setToolTip(QString());
|
||||||
|
clear_button_->setIconSize(QSize(14, 14));
|
||||||
clear_button_->setStyleSheet(
|
clear_button_->setStyleSheet(
|
||||||
"QToolButton {"
|
"QToolButton {"
|
||||||
" image: url(:/dfilter/dfilter_erase_normal.png) center;"
|
" border: none;"
|
||||||
" border: none;"
|
" background: transparent;" // Disables platform style on Windows.
|
||||||
" width: 16px;"
|
" padding: 0 0 0 0;"
|
||||||
"}"
|
" margin-left: 1px;"
|
||||||
"QToolButton:hover {"
|
"}"
|
||||||
" image: url(:/dfilter/dfilter_erase_active.png) center;"
|
);
|
||||||
"}"
|
|
||||||
"QToolButton:pressed {"
|
|
||||||
" image: url(:/dfilter/dfilter_erase_selected.png) center;"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
clear_button_->hide();
|
|
||||||
connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear()));
|
connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear()));
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&)));
|
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&)));
|
||||||
|
|
||||||
if (!plain_) {
|
if (!plain_) {
|
||||||
apply_button_ = new QToolButton(this);
|
apply_button_ = new StockIconToolButton(this, "x-filter-apply");
|
||||||
apply_button_->setCursor(Qt::ArrowCursor);
|
apply_button_->setCursor(Qt::ArrowCursor);
|
||||||
apply_button_->setEnabled(false);
|
apply_button_->setEnabled(false);
|
||||||
|
apply_button_->setToolTip(tr("Apply this filter string to the display."));
|
||||||
|
apply_button_->setIconSize(QSize(24, 14));
|
||||||
apply_button_->setStyleSheet(
|
apply_button_->setStyleSheet(
|
||||||
"QToolButton { /* all types of tool button */"
|
"QToolButton {"
|
||||||
" border 0 0 0 0;"
|
" border: none;"
|
||||||
" border-top-right-radius: 3px;"
|
" background: transparent;" // Disables platform style on Windows.
|
||||||
" border-bottom-right-radius: 3px;"
|
" padding: 0 0 0 0;"
|
||||||
" padding-right: 1px;"
|
|
||||||
" image: url(:/dfilter/dfilter_apply_normal.png) center;"
|
|
||||||
"}"
|
|
||||||
|
|
||||||
"QToolButton:hover {"
|
|
||||||
" image: url(:/dfilter/dfilter_apply_hover.png) center;"
|
|
||||||
"}"
|
|
||||||
"QToolButton:pressed {"
|
|
||||||
" image: url(:/dfilter/dfilter_apply_pressed.png) center;"
|
|
||||||
"}"
|
|
||||||
"QToolButton:disabled {"
|
|
||||||
" image: url(:/dfilter/dfilter_apply_disabled.png) center;"
|
|
||||||
"}"
|
"}"
|
||||||
);
|
);
|
||||||
connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter()));
|
connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter()));
|
||||||
|
@ -244,6 +209,8 @@ CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) :
|
||||||
this, SLOT(setFilterSyntaxState(QString,bool,QString)));
|
this, SLOT(setFilterSyntaxState(QString,bool,QString)));
|
||||||
connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater()));
|
connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater()));
|
||||||
syntax_thread->start();
|
syntax_thread->start();
|
||||||
|
|
||||||
|
checkFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
|
||||||
|
@ -285,14 +252,17 @@ void CaptureFilterEdit::resizeEvent(QResizeEvent *)
|
||||||
if (clear_button_) {
|
if (clear_button_) {
|
||||||
clear_button_->move(contentsRect().right() - frameWidth - cbsz.width() - apsz.width(),
|
clear_button_->move(contentsRect().right() - frameWidth - cbsz.width() - apsz.width(),
|
||||||
contentsRect().top());
|
contentsRect().top());
|
||||||
|
clear_button_->setMinimumHeight(contentsRect().height());
|
||||||
clear_button_->setMaximumHeight(contentsRect().height());
|
clear_button_->setMaximumHeight(contentsRect().height());
|
||||||
}
|
}
|
||||||
if (apply_button_) {
|
if (apply_button_) {
|
||||||
apply_button_->move(contentsRect().right() - frameWidth - apsz.width(),
|
apply_button_->move(contentsRect().right() - frameWidth - apsz.width(),
|
||||||
contentsRect().top());
|
contentsRect().top());
|
||||||
|
apply_button_->setMinimumHeight(contentsRect().height());
|
||||||
apply_button_->setMaximumHeight(contentsRect().height());
|
apply_button_->setMaximumHeight(contentsRect().height());
|
||||||
}
|
}
|
||||||
if (bookmark_button_) {
|
if (bookmark_button_) {
|
||||||
|
bookmark_button_->setMinimumHeight(contentsRect().height());
|
||||||
bookmark_button_->setMaximumHeight(contentsRect().height());
|
bookmark_button_->setMaximumHeight(contentsRect().height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "syntax_line_edit.h"
|
#include "syntax_line_edit.h"
|
||||||
|
|
||||||
class CaptureFilterSyntaxWorker;
|
class CaptureFilterSyntaxWorker;
|
||||||
|
class StockIconToolButton;
|
||||||
|
|
||||||
class CaptureFilterEdit : public SyntaxLineEdit
|
class CaptureFilterEdit : public SyntaxLineEdit
|
||||||
{
|
{
|
||||||
|
@ -56,9 +57,9 @@ private:
|
||||||
bool plain_;
|
bool plain_;
|
||||||
bool field_name_only_;
|
bool field_name_only_;
|
||||||
QString placeholder_text_;
|
QString placeholder_text_;
|
||||||
QToolButton *bookmark_button_;
|
StockIconToolButton *bookmark_button_;
|
||||||
QToolButton *clear_button_;
|
StockIconToolButton *clear_button_;
|
||||||
QToolButton *apply_button_;
|
StockIconToolButton *apply_button_;
|
||||||
CaptureFilterSyntaxWorker *syntax_worker_;
|
CaptureFilterSyntaxWorker *syntax_worker_;
|
||||||
|
|
||||||
void buildCompletionList(const QString& primitive_word);
|
void buildCompletionList(const QString& primitive_word);
|
||||||
|
|
|
@ -31,23 +31,17 @@
|
||||||
|
|
||||||
#include "display_filter_edit.h"
|
#include "display_filter_edit.h"
|
||||||
#include "filter_dialog.h"
|
#include "filter_dialog.h"
|
||||||
#include "stock_icon.h"
|
#include "stock_icon_tool_button.h"
|
||||||
#include "syntax_line_edit.h"
|
#include "syntax_line_edit.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
#include <QApplication>
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QIcon>
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <QStyleOptionFrame>
|
|
||||||
#include <QToolButton>
|
|
||||||
|
|
||||||
#include "ui/utf8_entities.h"
|
#include "ui/utf8_entities.h"
|
||||||
|
|
||||||
|
@ -57,94 +51,6 @@
|
||||||
// - Add a separator or otherwise distinguish between recent items and fields
|
// - Add a separator or otherwise distinguish between recent items and fields
|
||||||
// in the completion dropdown.
|
// 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
|
#if defined(Q_OS_MAC) && 0
|
||||||
// http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSImage_Class/Reference/Reference.html
|
// 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
|
// http://www.virtualbox.org/svn/vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaSpecialControls.mm
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
#include "stock_icon.h"
|
#include "stock_icon_tool_button.h"
|
||||||
#include "wireshark_application.h"
|
#include "wireshark_application.h"
|
||||||
|
|
||||||
// To do:
|
// To do:
|
||||||
|
@ -126,26 +126,20 @@ ProgressFrame::ProgressFrame(QWidget *parent) :
|
||||||
" background: transparent;"
|
" background: transparent;"
|
||||||
"}"));
|
"}"));
|
||||||
|
|
||||||
int one_em = fontMetrics().height();
|
ui->stopButton->setStockIcon("x-filter-clear");
|
||||||
ui->pushButton->setIconSize(QSize(one_em, one_em));
|
ui->stopButton->setIconSize(QSize(14, 14));
|
||||||
ui->pushButton->setStyleSheet(QString(
|
ui->stopButton->setStyleSheet(
|
||||||
"QPushButton {"
|
"QToolButton {"
|
||||||
" image: url(:/dfilter/dfilter_erase_normal.png) center;"
|
" border: none;"
|
||||||
|
" background: transparent;" // Disables platform style on Windows.
|
||||||
|
" padding: 0px;"
|
||||||
|
" margin: 0px;"
|
||||||
" min-height: 0.8em;"
|
" min-height: 0.8em;"
|
||||||
" max-height: 1em;"
|
" max-height: 1em;"
|
||||||
" min-width: 0.8em;"
|
" min-width: 0.8em;"
|
||||||
" max-width: 1em;"
|
" max-width: 1em;"
|
||||||
" border: 0px;"
|
|
||||||
" padding: 0px;"
|
|
||||||
" margin: 0px;"
|
|
||||||
" background: transparent;"
|
|
||||||
"}"
|
"}"
|
||||||
"QPushButton:hover {"
|
);
|
||||||
" image: url(:/dfilter/dfilter_erase_active.png) center;"
|
|
||||||
"}"
|
|
||||||
"QPushButton:pressed {"
|
|
||||||
" image: url(:/dfilter/dfilter_erase_selected.png) center;"
|
|
||||||
"}"));
|
|
||||||
connect(this, SIGNAL(showRequested(bool,bool,gboolean*)),
|
connect(this, SIGNAL(showRequested(bool,bool,gboolean*)),
|
||||||
this, SLOT(show(bool,bool,gboolean*)));
|
this, SLOT(show(bool,bool,gboolean*)));
|
||||||
hide();
|
hide();
|
||||||
|
@ -267,7 +261,7 @@ void ProgressFrame::hide()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressFrame::on_pushButton_clicked()
|
void ProgressFrame::on_stopButton_clicked()
|
||||||
{
|
{
|
||||||
emit stopLoading();
|
emit stopLoading();
|
||||||
}
|
}
|
||||||
|
@ -279,9 +273,9 @@ void ProgressFrame::show(bool animate, bool terminate_is_stop, gboolean *stop_fl
|
||||||
stop_flag_ = stop_flag;
|
stop_flag_ = stop_flag;
|
||||||
|
|
||||||
if (stop_flag) {
|
if (stop_flag) {
|
||||||
ui->pushButton->show();
|
ui->stopButton->show();
|
||||||
} else {
|
} else {
|
||||||
ui->pushButton->hide();
|
ui->stopButton->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
#if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
||||||
|
|
|
@ -71,8 +71,8 @@ signals:
|
||||||
void setHidden();
|
void setHidden();
|
||||||
void stopLoading();
|
void stopLoading();
|
||||||
|
|
||||||
#if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
|
||||||
protected:
|
protected:
|
||||||
|
#if !defined(Q_OS_MAC) || QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_clicked();
|
void on_stopButton_clicked();
|
||||||
|
|
||||||
void show(bool animate, bool terminate_is_stop, gboolean *stop_flag);
|
void show(bool animate, bool terminate_is_stop, gboolean *stop_flag);
|
||||||
void setMaximumValue(int value);
|
void setMaximumValue(int value);
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="StockIconToolButton" name="stopButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -50,13 +50,17 @@
|
||||||
<height>12</height>
|
<height>12</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="flat">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>StockIconToolButton</class>
|
||||||
|
<extends>QToolButton</extends>
|
||||||
|
<header>stock_icon_tool_button.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
/* stock_icon_tool_button.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 "stock_icon_tool_button.h"
|
||||||
|
|
||||||
|
#include "stock_icon.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
StockIconToolButton::StockIconToolButton(QWidget * parent, QString stock_icon_name) :
|
||||||
|
QToolButton(parent),
|
||||||
|
leave_timer_(0)
|
||||||
|
{
|
||||||
|
if (!stock_icon_name.isEmpty()) {
|
||||||
|
setStockIcon(stock_icon_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StockIconToolButton::setIconMode(QIcon::Mode mode)
|
||||||
|
{
|
||||||
|
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 StockIconToolButton::setStockIcon(QString icon_name)
|
||||||
|
{
|
||||||
|
base_icon_ = StockIcon(icon_name);
|
||||||
|
setIconMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StockIconToolButton::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()
|
||||||
|
// on OS X if a tooltip appears:
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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:
|
||||||
|
*/
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* stock_icon_tool_button.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 STOCKICONTOOLBUTTON_H
|
||||||
|
#define STOCKICONTOOLBUTTON_H
|
||||||
|
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
|
class StockIconToolButton : public QToolButton
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit StockIconToolButton(QWidget * parent = 0, QString stock_icon_name = QString());
|
||||||
|
|
||||||
|
void setIconMode(QIcon::Mode mode = QIcon::Normal);
|
||||||
|
void setStockIcon(QString icon_name);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool event(QEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QIcon base_icon_;
|
||||||
|
int leave_timer_;
|
||||||
|
static const int leave_interval_ = 500; // ms
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STOCKICONTOOLBUTTON_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:
|
||||||
|
*/
|
Loading…
Reference in New Issue