aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2012-08-23 02:59:31 +0000
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2012-08-23 02:59:31 +0000
commit83a2aaff5bff55b22be24c49bd325a42be3ae962 (patch)
treee8b75939934a9dfbea7ee8237f5955618c082816 /ui/qt
parenta7b4439eb478ae69714820f146f6ba727ad2b6ea (diff)
Catch key events where needed and direct them to the display filter
QLineEdit. Use Tango colors for syntax highlighting. Rename a few variables. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@44620 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/display_filter_edit.cpp117
-rw-r--r--ui/qt/display_filter_edit.h18
-rw-r--r--ui/qt/main_window.cpp62
-rw-r--r--ui/qt/main_window.h1
-rw-r--r--ui/qt/packet_list.cpp8
-rw-r--r--ui/qt/packet_list.h2
6 files changed, 112 insertions, 96 deletions
diff --git a/ui/qt/display_filter_edit.cpp b/ui/qt/display_filter_edit.cpp
index c6ec014b1d..a0dc1b7cf5 100644
--- a/ui/qt/display_filter_edit.cpp
+++ b/ui/qt/display_filter_edit.cpp
@@ -30,6 +30,7 @@
#include <epan/proto.h>
#include "display_filter_edit.h"
+#include "tango_colors.h"
#include "ui/utf8_entities.h"
@@ -82,17 +83,17 @@ UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
// XXX - We need simplified (button- and dropdown-free) versions for use in dialogs and field-only checking.
DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, bool plain) :
- QLineEdit(parent), m_plain(plain)
+ QLineEdit(parent), plain_(plain)
{
- m_fieldNameOnly = false;
- m_syntaxState = Empty;
+ field_name_only_ = false;
+ syntax_state_ = Empty;
setAccessibleName(tr("Display filter entry"));
- if (m_plain) {
- m_emptyFilterMessage = QString(tr("Enter a display filter %1")).arg(UTF8_HORIZONTAL_ELLIPSIS);
+ if (plain_) {
+ empty_filter_message_ = QString(tr("Enter a display filter %1")).arg(UTF8_HORIZONTAL_ELLIPSIS);
} else {
- m_emptyFilterMessage = QString(tr("Apply a display filter %1 <%2/>")).arg(UTF8_HORIZONTAL_ELLIPSIS)
+ empty_filter_message_ = QString(tr("Apply a display filter %1 <%2/>")).arg(UTF8_HORIZONTAL_ELLIPSIS)
.arg(DEFAULT_MODIFIER);
}
@@ -106,9 +107,9 @@ DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, bool plain) :
// XXX - Move bookmark and apply buttons to the toolbar a la Firefox, Chrome & Safari?
// XXX - Use native buttons on OS X?
- m_bookmarkButton = new QToolButton(this);
- m_bookmarkButton->setCursor(Qt::ArrowCursor);
- m_bookmarkButton->setStyleSheet(QString(
+ bookmark_button_ = new QToolButton(this);
+ bookmark_button_->setCursor(Qt::ArrowCursor);
+ bookmark_button_->setStyleSheet(QString(
"QToolButton { /* all types of tool button */"
" border 0 0 0 0;"
" border-right: %1px solid gray;"
@@ -132,13 +133,13 @@ DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, bool plain) :
// " stop: 0 #dadbde, stop: 1 #f6f7fa);"
// "}"
- ).arg(m_plain ? 0 : 1)
+ ).arg(plain_ ? 0 : 1)
);
- connect(m_bookmarkButton, SIGNAL(clicked()), this, SLOT(showDisplayFilterDialog()));
+ connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(showDisplayFilterDialog()));
- m_clearButton = new QToolButton(this);
- m_clearButton->setCursor(Qt::ArrowCursor);
- m_clearButton->setStyleSheet(
+ clear_button_ = new QToolButton(this);
+ clear_button_->setCursor(Qt::ArrowCursor);
+ clear_button_->setStyleSheet(
"QToolButton {"
" image: url(:/dfilter/dfilter_erase_normal.png);"
" border: none;"
@@ -151,15 +152,15 @@ DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, bool plain) :
" image: url(:/dfilter/dfilter_erase_selected.png);"
"}"
);
- m_clearButton->hide();
- connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear()));
+ clear_button_->hide();
+ connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&)));
- m_applyButton = NULL;
- if (!m_plain) {
- m_applyButton = new QToolButton(this);
- m_applyButton->setCursor(Qt::ArrowCursor);
- m_applyButton->setStyleSheet(
+ apply_button_ = NULL;
+ if (!plain_) {
+ apply_button_ = new QToolButton(this);
+ apply_button_->setCursor(Qt::ArrowCursor);
+ apply_button_->setStyleSheet(
"QToolButton { /* all types of tool button */"
" border 0 0 0 0;"
" border-top-right-radius: 3px;"
@@ -175,20 +176,20 @@ DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, bool plain) :
" image: url(:/dfilter/dfilter_apply_pressed.png);"
"}"
);
- connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyDisplayFilter()));
+ connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyDisplayFilter()));
connect(this, SIGNAL(returnPressed()), this, SLOT(applyDisplayFilter()));
}
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- QSize bksz = m_bookmarkButton->sizeHint();
- QSize cbsz = m_clearButton->sizeHint();
+ QSize bksz = bookmark_button_->sizeHint();
+ QSize cbsz = clear_button_->sizeHint();
QSize apsz;
- if (m_applyButton) {
- apsz = m_applyButton->sizeHint();
+ if (apply_button_) {
+ apsz = apply_button_->sizeHint();
} else {
apsz.setHeight(0); apsz.setWidth(0);
}
- m_syntaxStyleSheet = QString(
+ syntax_style_sheet_ = QString(
"DisplayFilterEdit {"
" padding-left: %1px;"
" margin-left: %2px;"
@@ -197,22 +198,19 @@ DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, bool plain) :
"}"
// Should the backgrounds fade away on the right?
- // Tango "Scarlet Red"
"DisplayFilterEdit[syntaxState=\"%4\"] {"
" color: white;"
- " background-color: rgba(239, 41, 41, 128);"
+ " background-color: #%7;"
"}"
- // Tango "Butter"
"DisplayFilterEdit[syntaxState=\"%5\"] {"
- " color: black;"
- " background-color: rgba(252, 233, 79, 128);"
+ " color: #%8;"
+ " background-color: #%9;"
"}"
- // Tango "Chameleon
"DisplayFilterEdit[syntaxState=\"%6\"] {"
- " color: black;"
- " background-color: rgba(138, 226, 52, 128);"
+ " color: #%8;"
+ " background-color: #%10;"
"}"
)
.arg(frameWidth + 1)
@@ -220,8 +218,13 @@ DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, bool plain) :
.arg(cbsz.width() + apsz.width() + frameWidth + 1)
.arg(Invalid)
.arg(Deprecated)
- .arg(Valid);
- setStyleSheet(m_syntaxStyleSheet);
+ .arg(Valid)
+ .arg(tango_scarlet_red_1, 6, 16, QChar('0')) // Invalid
+ .arg(tango_aluminium_6, 6, 16, QChar('0')) // Deprecated/valid foreground
+ .arg(tango_butter_1, 6, 16, QChar('0')) // Deprecated
+ .arg(tango_chameleon_1, 6, 16, QChar('0')) // Valid
+ ;
+ setStyleSheet(syntax_style_sheet_);
}
void DisplayFilterEdit::paintEvent(QPaintEvent *evt) {
@@ -244,7 +247,7 @@ void DisplayFilterEdit::paintEvent(QPaintEvent *evt) {
cr.setLeft(cr.left() + 2);
cr.setRight(cr.right() - 2);
- p.drawText(cr, Qt::AlignLeft|Qt::AlignVCenter, m_emptyFilterMessage);
+ p.drawText(cr, Qt::AlignLeft|Qt::AlignVCenter, empty_filter_message_);
}
// else check filter syntax and set the background accordingly
// XXX - Should we add little warning/error icons as well?
@@ -252,18 +255,18 @@ void DisplayFilterEdit::paintEvent(QPaintEvent *evt) {
void DisplayFilterEdit::resizeEvent(QResizeEvent *)
{
- QSize cbsz = m_clearButton->sizeHint();
+ QSize cbsz = clear_button_->sizeHint();
QSize apsz;
- if (m_applyButton) {
- apsz = m_applyButton->sizeHint();
+ if (apply_button_) {
+ apsz = apply_button_->sizeHint();
} else {
apsz.setHeight(0); apsz.setWidth(0);
}
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- m_clearButton->move(rect().right() - frameWidth - cbsz.width() - apsz.width(),
+ clear_button_->move(rect().right() - frameWidth - cbsz.width() - apsz.width(),
(rect().bottom() + 1 - cbsz.height())/2);
- if (m_applyButton) {
- m_applyButton->move(rect().right() - frameWidth - apsz.width(),
+ if (apply_button_) {
+ apply_button_->move(rect().right() - frameWidth - apsz.width(),
(rect().bottom() + 1 - apsz.height())/2);
}
}
@@ -274,22 +277,22 @@ void DisplayFilterEdit::checkFilter(const QString& text)
GPtrArray *depr = NULL;
guchar c;
- m_clearButton->setVisible(!text.isEmpty());
+ clear_button_->setVisible(!text.isEmpty());
popFilterSyntaxStatus();
- if (m_fieldNameOnly && (c = proto_check_field_name(text.toUtf8().constData()))) {
- m_syntaxState = Invalid;
+ if (field_name_only_ && (c = proto_check_field_name(text.toUtf8().constData()))) {
+ syntax_state_ = Invalid;
emit pushFilterSyntaxStatus(QString().sprintf("Illegal character in field name: '%c'", c));
} else if (dfilter_compile(text.toUtf8().constData(), &dfp)) {
if (dfp != NULL) {
depr = dfilter_deprecated_tokens(dfp);
}
if (text.length() < 1) {
- m_syntaxState = Empty;
+ syntax_state_ = Empty;
} else if (depr) {
/* You keep using that word. I do not think it means what you think it means. */
- m_syntaxState = Deprecated;
+ syntax_state_ = Deprecated;
/*
* We're being lazy and only printing the first "problem" token.
* Would it be better to print all of them?
@@ -297,11 +300,11 @@ void DisplayFilterEdit::checkFilter(const QString& text)
emit pushFilterSyntaxWarning(QString().sprintf("\"%s\" may have unexpected results (see the User's Guide)",
(const char *) g_ptr_array_index(depr, 0)));
} else {
- m_syntaxState = Valid;
+ syntax_state_ = Valid;
}
dfilter_free(dfp);
} else {
- m_syntaxState = Invalid;
+ syntax_state_ = Invalid;
QString invalidMsg(tr("Invalid filter"));
if (dfilter_error_msg) {
invalidMsg.append(QString().sprintf(": %s", dfilter_error_msg));
@@ -309,9 +312,9 @@ void DisplayFilterEdit::checkFilter(const QString& text)
emit pushFilterSyntaxStatus(invalidMsg);
}
- setStyleSheet(m_syntaxStyleSheet);
- if (m_applyButton) {
- m_applyButton->setEnabled(m_syntaxState == Empty || m_syntaxState == Valid);
+ setStyleSheet(syntax_style_sheet_);
+ if (apply_button_) {
+ apply_button_->setEnabled(syntax_state_ == Empty || syntax_state_ == Valid);
}
}
@@ -326,7 +329,7 @@ void DisplayFilterEdit::applyDisplayFilter()
gchar *dftext = NULL;
cf_status_t cf_status;
- if (m_syntaxState != Valid && m_syntaxState != Empty) {
+ if (syntax_state_ != Valid && syntax_state_ != Empty) {
return;
}
@@ -336,8 +339,8 @@ void DisplayFilterEdit::applyDisplayFilter()
g_free(dftext);
if (cf_status == CF_OK) {
- if (m_applyButton) {
- m_applyButton->setEnabled(false);
+ if (apply_button_) {
+ apply_button_->setEnabled(false);
}
if (dfString.length() < 1) {
// gtk_widget_set_sensitive (g_object_get_data (G_OBJECT(filter_cm), E_DFILTER_CLEAR_KEY), FALSE);
diff --git a/ui/qt/display_filter_edit.h b/ui/qt/display_filter_edit.h
index 2c0f05dfe1..3ffd29b5e1 100644
--- a/ui/qt/display_filter_edit.h
+++ b/ui/qt/display_filter_edit.h
@@ -35,7 +35,7 @@ public:
explicit DisplayFilterEdit(QWidget *parent = 0, bool plain = false);
enum SyntaxState { Empty, Invalid, Deprecated, Valid };
SyntaxState syntaxState() const
- { return m_syntaxState; }
+ { return syntax_state_; }
protected:
@@ -50,14 +50,14 @@ private slots:
void applyDisplayFilter();
private:
- bool m_plain;
- bool m_fieldNameOnly;
- SyntaxState m_syntaxState;
- QString m_emptyFilterMessage;
- QString m_syntaxStyleSheet;
- QToolButton *m_bookmarkButton;
- QToolButton *m_clearButton;
- QToolButton *m_applyButton;
+ bool plain_;
+ bool field_name_only_;
+ SyntaxState syntax_state_;
+ QString empty_filter_message_;
+ QString syntax_style_sheet_;
+ QToolButton *bookmark_button_;
+ QToolButton *clear_button_;
+ QToolButton *apply_button_;
signals:
void pushFilterSyntaxStatus(QString&);
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index e525fe5175..a7073a6012 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -69,10 +69,10 @@ MainWindow::MainWindow(QWidget *parent) :
updateRecentFiles();
df_combo_box_ = new DisplayFilterCombo();
- const DisplayFilterEdit *dfEdit = dynamic_cast<DisplayFilterEdit *>(df_combo_box_->lineEdit());
- connect(dfEdit, SIGNAL(pushFilterSyntaxStatus(QString&)), main_ui_->statusBar, SLOT(pushFilterStatus(QString&)));
- connect(dfEdit, SIGNAL(popFilterSyntaxStatus()), main_ui_->statusBar, SLOT(popFilterStatus()));
- connect(dfEdit, SIGNAL(pushFilterSyntaxWarning(QString&)), main_ui_->statusBar, SLOT(pushTemporaryStatus(QString&)));
+ const DisplayFilterEdit *df_edit = dynamic_cast<DisplayFilterEdit *>(df_combo_box_->lineEdit());
+ connect(df_edit, SIGNAL(pushFilterSyntaxStatus(QString&)), main_ui_->statusBar, SLOT(pushFilterStatus(QString&)));
+ connect(df_edit, SIGNAL(popFilterSyntaxStatus()), main_ui_->statusBar, SLOT(popFilterStatus()));
+ connect(df_edit, SIGNAL(pushFilterSyntaxWarning(QString&)), main_ui_->statusBar, SLOT(pushTemporaryStatus(QString&)));
#ifdef _WIN32
// Qt <= 4.7 doesn't seem to style Windows toolbars. If we wanted to be really fancy we could use Blur Behind:
@@ -117,19 +117,21 @@ MainWindow::MainWindow(QWidget *parent) :
packet_list_ = new PacketList(splitter_v_);
- ProtoTree *protoTree = new ProtoTree(splitter_v_);
- protoTree->setHeaderHidden(true);
+ ProtoTree *proto_tree = new ProtoTree(splitter_v_);
+ proto_tree->setHeaderHidden(true);
+ proto_tree->installEventFilter(this);
- ByteViewTab *byteViewTab = new ByteViewTab(splitter_v_);
- byteViewTab->setTabPosition(QTabWidget::South);
- byteViewTab->setDocumentMode(true);
+ ByteViewTab *byte_view_tab = new ByteViewTab(splitter_v_);
+ byte_view_tab->setTabPosition(QTabWidget::South);
+ byte_view_tab->setDocumentMode(true);
- packet_list_->setProtoTree(protoTree);
- packet_list_->setByteViewTab(byteViewTab);
+ packet_list_->setProtoTree(proto_tree);
+ packet_list_->setByteViewTab(byte_view_tab);
+ packet_list_->installEventFilter(this);
splitter_v_->addWidget(packet_list_);
- splitter_v_->addWidget(protoTree);
- splitter_v_->addWidget(byteViewTab);
+ splitter_v_->addWidget(proto_tree);
+ splitter_v_->addWidget(byte_view_tab);
main_ui_->mainStack->addWidget(splitter_v_);
@@ -156,16 +158,16 @@ MainWindow::MainWindow(QWidget *parent) :
packet_list_, SLOT(goLastPacket()));
connect(main_ui_->actionViewExpandSubtrees, SIGNAL(triggered()),
- protoTree, SLOT(expandSubtrees()));
+ proto_tree, SLOT(expandSubtrees()));
connect(main_ui_->actionViewExpandAll, SIGNAL(triggered()),
- protoTree, SLOT(expandAll()));
+ proto_tree, SLOT(expandAll()));
connect(main_ui_->actionViewCollapseAll, SIGNAL(triggered()),
- protoTree, SLOT(collapseAll()));
+ proto_tree, SLOT(collapseAll()));
- connect(protoTree, SIGNAL(protoItemSelected(QString&)),
+ connect(proto_tree, SIGNAL(protoItemSelected(QString&)),
main_ui_->statusBar, SLOT(pushFieldStatus(QString&)));
- connect(protoTree, SIGNAL(protoItemSelected(bool)),
+ connect(proto_tree, SIGNAL(protoItemSelected(bool)),
main_ui_->actionViewExpandSubtrees, SLOT(setEnabled(bool)));
main_ui_->mainStack->setCurrentWidget(main_welcome_);
@@ -176,6 +178,23 @@ MainWindow::~MainWindow()
delete main_ui_;
}
+bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
+
+ // The user typed some text. Start filling in a filter.
+ // We may need to be more choosy here. We just need to catch events for the packet list,
+ // proto tree, and main welcome widgets.
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *kevt = static_cast<QKeyEvent *>(event);
+ if (kevt->text().length() > 0 && kevt->text()[0].isPrint()) {
+ df_combo_box_->lineEdit()->insert(kevt->text());
+ df_combo_box_->lineEdit()->setFocus();
+ return true;
+ }
+ }
+
+ return QObject::eventFilter(obj, event);
+}
+
void MainWindow::keyPressEvent(QKeyEvent *event) {
// Explicitly focus on the display filter combo.
@@ -195,13 +214,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) {
return; // goToLineEdit didn't want it and we don't either.
}
- // The user typed some text. Start filling in a filter.
- // XXX We need to install an event filter for the packet list and proto tree
- // XXX Disabled for now. For some reason we crash here when pressing enter or esc.
-// if ((event->modifiers() == Qt::NoModifier || event->modifiers() == Qt::ShiftModifier) && event->text().length() > 0) {
-// QApplication::sendEvent(df_combo_box_, event);
-// }
-
// Move up & down the packet list.
if (event->key() == Qt::Key_F7) {
packet_list_->goPreviousPacket();
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index 024d1ab1db..c181421042 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -54,6 +54,7 @@ public:
~MainWindow();
protected:
+ bool eventFilter(QObject *obj, QEvent *event);
void keyPressEvent(QKeyEvent *event);
private:
diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp
index fe46b42d4d..f126179ea0 100644
--- a/ui/qt/packet_list.cpp
+++ b/ui/qt/packet_list.cpp
@@ -260,14 +260,14 @@ PacketList::PacketList(QWidget *parent) :
byte_view_tab_ = NULL;
}
-void PacketList::setProtoTree (ProtoTree *protoTree) {
- proto_tree_ = protoTree;
+void PacketList::setProtoTree (ProtoTree *proto_tree) {
+ proto_tree_ = proto_tree;
connect(proto_tree_, SIGNAL(goToFrame(int)), this, SLOT(goToPacket(int)));
}
-void PacketList::setByteViewTab (ByteViewTab *byteViewTab) {
- byte_view_tab_ = byteViewTab;
+void PacketList::setByteViewTab (ByteViewTab *byte_view_tab) {
+ byte_view_tab_ = byte_view_tab;
}
PacketListModel *PacketList::packetListModel() const {
diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h
index 25b79ece64..5dc0440c5c 100644
--- a/ui/qt/packet_list.h
+++ b/ui/qt/packet_list.h
@@ -38,7 +38,7 @@ class PacketList : public QTreeView
public:
explicit PacketList(QWidget *parent = 0);
PacketListModel *packetListModel() const;
- void setProtoTree(ProtoTree *protoTree);
+ void setProtoTree(ProtoTree *proto_tree);
void setByteViewTab(ByteViewTab *byteViewTab);
void clear();
void writeRecent(FILE *rf);