3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later*/
9 #include <ui/qt/widgets/find_line_edit.h>
10 #include <ui/qt/utils/color_utils.h>
11 #include "epan/prefs.h"
17 void FindLineEdit::contextMenuEvent(QContextMenuEvent *event)
19 QMenu *menu = createStandardContextMenu();
21 #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
26 action = menu->addAction(tr("Textual Find"));
27 action->setCheckable(true);
28 action->setChecked(!use_regex_);
29 connect(action, SIGNAL(triggered()), this, SLOT(setUseTextual()));
31 action = menu->addAction(tr("Regular Expression Find"));
32 action->setCheckable(true);
33 action->setChecked(use_regex_);
34 connect(action, SIGNAL(triggered()), this, SLOT(setUseRegex()));
37 menu->exec(event->globalPos());
41 void FindLineEdit::keyPressEvent(QKeyEvent *event)
43 QLineEdit::keyPressEvent(event);
50 void FindLineEdit::validateText()
52 QString style("QLineEdit { background-color: %1; }");
54 if (!use_regex_ || text().isEmpty()) {
55 setStyleSheet(style.arg(QString("")));
57 QRegExp regexp(text());
58 if (regexp.isValid()) {
59 setStyleSheet(style.arg(ColorUtils::fromColorT(prefs.gui_text_valid).name()));
61 setStyleSheet(style.arg(ColorUtils::fromColorT(prefs.gui_text_invalid).name()));
66 void FindLineEdit::setUseTextual()
70 emit useRegexFind(use_regex_);
73 void FindLineEdit::setUseRegex()
77 emit useRegexFind(use_regex_);
86 * indent-tabs-mode: nil
89 * ex: set shiftwidth=4 tabstop=8 expandtab:
90 * :indentSize=4:tabSize=8:noTabs=true: