diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2016-02-16 09:33:27 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2016-02-17 08:41:46 +0000 |
commit | 2d133d62ab7a1cbe141138b90b399dad71113f06 (patch) | |
tree | 397a81d730bda0695d0b4453bd0b0193e20261ca /ui/qt/find_line_edit.cpp | |
parent | cb962ca3e59a709d4070267780008a32d9fb6a39 (diff) |
Qt: Validate FindLineEdit regexp
Check if regexp is valid and set valid/invalid background color.
Change-Id: Ibf4d3fa84463afbd7c68631cfaddec8261807b8f
Reviewed-on: https://code.wireshark.org/review/13962
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui/qt/find_line_edit.cpp')
-rw-r--r-- | ui/qt/find_line_edit.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ui/qt/find_line_edit.cpp b/ui/qt/find_line_edit.cpp index 94d351033b..9ecf0235d7 100644 --- a/ui/qt/find_line_edit.cpp +++ b/ui/qt/find_line_edit.cpp @@ -20,6 +20,8 @@ */ #include "find_line_edit.h" +#include "color_utils.h" +#include "epan/prefs.h" #include <QAction> #include <QKeyEvent> @@ -49,15 +51,42 @@ void FindLineEdit::contextMenuEvent(QContextMenuEvent *event) delete menu; } +void FindLineEdit::keyPressEvent(QKeyEvent *event) +{ + QLineEdit::keyPressEvent(event); + + if (use_regex_) { + validateText(); + } +} + +void FindLineEdit::validateText() +{ + QString style("QLineEdit { background-color: %1; }"); + + if (!use_regex_ || text().isEmpty()) { + setStyleSheet(style.arg(QString(""))); + } else { + QRegExp regexp(text()); + if (regexp.isValid()) { + setStyleSheet(style.arg(ColorUtils::fromColorT(prefs.gui_text_valid).name())); + } else { + setStyleSheet(style.arg(ColorUtils::fromColorT(prefs.gui_text_invalid).name())); + } + } +} + void FindLineEdit::setUseTextual() { use_regex_ = false; + validateText(); emit useRegexFind(use_regex_); } void FindLineEdit::setUseRegex() { use_regex_ = true; + validateText(); emit useRegexFind(use_regex_); } |