forked from osmocom/wireshark
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>
This commit is contained in:
parent
cb962ca3e5
commit
2d133d62ab
|
@ -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_);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,14 @@ signals:
|
|||
void useRegexFind(bool);
|
||||
|
||||
private slots:
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void setUseTextual();
|
||||
void setUseRegex();
|
||||
|
||||
private:
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void validateText();
|
||||
|
||||
bool use_regex_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue