aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2017-11-23 13:18:37 +0100
committerAnders Broman <a.broman58@gmail.com>2017-11-24 05:17:28 +0000
commitb99677dea95a8886429574713d5a78dde9181959 (patch)
tree1562708b567cd9ddabd1254e9dc9a485e3820128
parent73c01d6d0562f138b3aad83b6b2dcf8d3f09dcee (diff)
Qt: Add key event to reject changes in AddressEditorFrame
Also give focus to the name field. Change-Id: I409d48e513c04b510f1e3d838c05e1518e6d2e9d Reviewed-on: https://code.wireshark.org/review/24547 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--ui/qt/address_editor_frame.cpp31
-rw-r--r--ui/qt/address_editor_frame.h5
2 files changed, 28 insertions, 8 deletions
diff --git a/ui/qt/address_editor_frame.cpp b/ui/qt/address_editor_frame.cpp
index d340afa9e4..a56464b76e 100644
--- a/ui/qt/address_editor_frame.cpp
+++ b/ui/qt/address_editor_frame.cpp
@@ -34,6 +34,7 @@
#include <ui_address_editor_frame.h>
#include <QPushButton>
+#include <QKeyEvent>
#include <ui/qt/utils/qt_ui_utils.h>
@@ -104,6 +105,29 @@ void AddressEditorFrame::editAddresses(CaptureFile &cf, int column)
updateWidgets();
}
+void AddressEditorFrame::showEvent(QShowEvent *event)
+{
+ ui->nameLineEdit->setFocus();
+ ui->nameLineEdit->selectAll();
+
+ AccordionFrame::showEvent(event);
+}
+
+void AddressEditorFrame::keyPressEvent(QKeyEvent *event)
+{
+ if (event->modifiers() == Qt::NoModifier) {
+ if (event->key() == Qt::Key_Escape) {
+ on_buttonBox_rejected();
+ } else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
+ if (ui->buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
+ on_buttonBox_accepted();
+ }
+ }
+ }
+
+ AccordionFrame::keyPressEvent(event);
+}
+
void AddressEditorFrame::updateWidgets()
{
bool ok_enable = false;
@@ -131,13 +155,6 @@ void AddressEditorFrame::on_nameLineEdit_textEdited(const QString &)
updateWidgets();
}
-void AddressEditorFrame::on_nameLineEdit_returnPressed()
-{
- if (ui->buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
- on_buttonBox_accepted();
- }
-}
-
void AddressEditorFrame::on_buttonBox_accepted()
{
if (ui->addressComboBox->count() < 1 || ui->nameLineEdit->text().isEmpty()) {
diff --git a/ui/qt/address_editor_frame.h b/ui/qt/address_editor_frame.h
index eb57263c79..91a8935a50 100644
--- a/ui/qt/address_editor_frame.h
+++ b/ui/qt/address_editor_frame.h
@@ -48,12 +48,15 @@ signals:
void editAddressStatus(const QString &status);
void redissectPackets();
+protected:
+ virtual void showEvent(QShowEvent *event);
+ virtual void keyPressEvent(QKeyEvent *event);
+
private slots:
void updateWidgets();
void on_nameResolutionPreferencesToolButton_clicked();
void on_addressComboBox_currentIndexChanged(const QString &);
void on_nameLineEdit_textEdited(const QString &);
- void on_nameLineEdit_returnPressed();
void on_buttonBox_accepted();
void on_buttonBox_rejected();