29
29
#include < QMessageBox>
30
30
#include < QMenu>
31
31
#include < QDesktopServices>
32
+ #include < QShortcut>
32
33
33
34
TabDiagnostics::TabDiagnostics (MainWindow &window, std::shared_ptr<Ui::MainWindow> ui) : Tab(TAB_DIAGNOSTIC, window, ui) {
35
+ this ->connect (this ->ui ->diagnostic_search_edit , SIGNAL (textEdited (QString)), this , SLOT (on_search_textEdited (QString)));
36
+ this ->connect (this ->ui ->diagnostic_search_edit , SIGNAL (returnPressed ()), this , SLOT (on_search_find_pressed ()));
37
+ this ->connect (this ->ui ->diagnostic_search_next , SIGNAL (clicked ()), this , SLOT (on_search_next_pressed ()));
38
+ this ->connect (this ->ui ->diagnostic_search_prev , SIGNAL (clicked ()), this , SLOT (on_search_prev_pressed ()));
39
+ this ->connect (this ->ui ->diagnostic_search_mode , SIGNAL (clicked ()), this , SLOT (on_search_mode_pressed ()));
40
+ this ->connect (this ->ui ->diagnostic_status_text , SIGNAL (customContextMenuRequested (QPoint)), this ,
41
+ SLOT (on_customContextMenuRequested (const QPoint &)));
42
+ this ->connect (this ->ui ->diagnostic_status_text , SIGNAL (returnPressed ()), this , SLOT (on_search_find_pressed ()));
43
+ this ->connect (this ->ui ->diagnostic_search_hide , SIGNAL (clicked ()), this , SLOT (on_hide_search ()));
44
+
45
+ QShortcut *shortcut = new QShortcut (QKeySequence (Qt::CTRL + Qt::Key_F), this ->ui ->diagnostic_status_text );
46
+ this ->connect (shortcut, SIGNAL (activated ()), this , SLOT (on_show_search ()));
47
+
48
+ Configurator &configurator = Configurator::Get ();
49
+
50
+ this ->ui ->diagnostic_search_edit ->setText (configurator.diagnostic_search_text .c_str ());
51
+ this ->ui ->diagnostic_search_next ->setIcon (::Get (::ICON_NEXT));
52
+ this ->ui ->diagnostic_search_prev ->setIcon (::Get (::ICON_PREV));
53
+ this ->ui ->diagnostic_search_mode ->setIcon (::Get (::ICON_MODE));
54
+ this ->ui ->diagnostic_search_hide ->setIcon (::Get (::ICON_EXIT));
55
+
34
56
this ->ui ->diagnostic_status_text ->installEventFilter (&window);
35
57
this ->ui ->diagnostic_status_text ->document ()->setMaximumBlockCount (65536 );
36
58
this ->ui ->diagnostic_status_text ->setContextMenuPolicy (Qt::CustomContextMenu);
37
- this ->connect (this ->ui ->diagnostic_status_text , SIGNAL (customContextMenuRequested (QPoint)), this ,
38
- SLOT (on_customContextMenuRequested (const QPoint &)));
39
59
60
+ this ->ShowSearch (false );
40
61
this ->UpdateStatus ();
41
62
}
42
63
@@ -53,6 +74,20 @@ void TabDiagnostics::UpdateStatus() {
53
74
configurator.Override (OVERRIDE_AREA_LOADER_SETTINGS_BIT);
54
75
}
55
76
77
+ void TabDiagnostics::ShowSearch (bool visible) {
78
+ this ->ui ->diagnostic_search_edit ->setVisible (visible);
79
+ this ->ui ->diagnostic_search_next ->setVisible (visible && mode_next);
80
+ this ->ui ->diagnostic_search_next ->setEnabled (!this ->ui ->diagnostic_search_edit ->text ().isEmpty ());
81
+ this ->ui ->diagnostic_search_prev ->setVisible (visible && !mode_next);
82
+ this ->ui ->diagnostic_search_prev ->setEnabled (!this ->ui ->diagnostic_search_edit ->text ().isEmpty ());
83
+ this ->ui ->diagnostic_search_mode ->setVisible (visible);
84
+ this ->ui ->diagnostic_search_hide ->setVisible (visible);
85
+
86
+ if (visible) {
87
+ this ->ui ->diagnostic_search_edit ->setFocus ();
88
+ }
89
+ }
90
+
56
91
void TabDiagnostics::UpdateUI (UpdateUIMode mode) {
57
92
(void )mode;
58
93
@@ -68,6 +103,64 @@ bool TabDiagnostics::EventFilter(QObject *target, QEvent *event) {
68
103
return false ;
69
104
}
70
105
106
+ void TabDiagnostics::on_show_search () { this ->ShowSearch (true ); }
107
+
108
+ void TabDiagnostics::on_hide_search () { this ->ShowSearch (false ); }
109
+
110
+ void TabDiagnostics::on_search_textEdited (const QString &text) {
111
+ this ->ui ->diagnostic_search_next ->setEnabled (!this ->ui ->diagnostic_search_edit ->text ().isEmpty () && mode_next);
112
+ this ->ui ->diagnostic_search_prev ->setEnabled (!this ->ui ->diagnostic_search_edit ->text ().isEmpty () && !mode_next);
113
+
114
+ Configurator &configurator = Configurator::Get ();
115
+ configurator.diagnostic_search_text = text.toStdString ();
116
+ }
117
+
118
+ void TabDiagnostics::on_search_next_pressed () {
119
+ this ->mode_next = true ;
120
+ this ->ShowSearch (true );
121
+ this ->on_search_find_pressed ();
122
+ }
123
+
124
+ void TabDiagnostics::on_search_prev_pressed () {
125
+ this ->mode_next = false ;
126
+ this ->ShowSearch (true );
127
+ this ->on_search_find_pressed ();
128
+ }
129
+
130
+ void TabDiagnostics::on_search_find_pressed () {
131
+ QTextDocument::FindFlags flags =
132
+ QTextDocument::FindFlags (0 ); // = QTextDocument::FindBackward | QTextDocument::FindCaseSensitively |
133
+ // QTextDocument::FindWholeWords;
134
+ if (!mode_next) {
135
+ flags |= QTextDocument::FindBackward;
136
+ }
137
+
138
+ this ->ui ->diagnostic_status_text ->setFocus ();
139
+ this ->ui ->diagnostic_status_text ->find (this ->ui ->diagnostic_search_edit ->text (), flags);
140
+ }
141
+
142
+ void TabDiagnostics::on_search_mode_pressed () {
143
+ QMenu menu (this ->ui ->diagnostic_search_mode );
144
+ QAction *action_next = new QAction (" Find Next" , nullptr );
145
+ action_next->setShortcut (QKeySequence (Qt::Key_F3));
146
+ menu.addAction (action_next);
147
+ QAction *action_prev = new QAction (" Find Previous" , nullptr );
148
+ action_prev->setShortcut (QKeySequence (Qt::Key_Shift + Qt::Key_F3));
149
+ menu.addAction (action_prev);
150
+
151
+ QPoint point (this ->window .mapToGlobal (this ->ui ->diagnostic_search_mode ->pos ()));
152
+ QAction *action = menu.exec (point);
153
+ if (action == action_next) {
154
+ this ->mode_next = true ;
155
+ this ->ui ->diagnostic_search_next ->setVisible (true );
156
+ this ->ui ->diagnostic_search_prev ->setVisible (false );
157
+ } else if (action == action_prev) {
158
+ this ->mode_next = false ;
159
+ this ->ui ->diagnostic_search_next ->setVisible (false );
160
+ this ->ui ->diagnostic_search_prev ->setVisible (true );
161
+ }
162
+ }
163
+
71
164
void TabDiagnostics::on_customContextMenuRequested (const QPoint &pos) {
72
165
Configurator &configurator = Configurator::Get ();
73
166
@@ -82,6 +175,12 @@ void TabDiagnostics::on_customContextMenuRequested(const QPoint &pos) {
82
175
action_save->setEnabled (!this ->status .empty ());
83
176
menu->addAction (action_save);
84
177
178
+ menu->addSeparator ();
179
+
180
+ QAction *action_search = new QAction (" Search..." , nullptr );
181
+ action_search->setEnabled (!configurator.GetShowDiagnosticSearch ());
182
+ menu->addAction (action_search);
183
+
85
184
QAction *action = menu->exec (this ->ui ->diagnostic_status_text ->mapToGlobal (pos));
86
185
87
186
if (action == action_refresh) {
@@ -96,6 +195,8 @@ void TabDiagnostics::on_customContextMenuRequested(const QPoint &pos) {
96
195
this ->status .clear ();
97
196
this ->ui ->diagnostic_status_text ->clear ();
98
197
}
198
+ } else if (action == action_search) {
199
+ this ->ShowSearch (true );
99
200
} else if (action == action_save) {
100
201
const QString selected_path =
101
202
QFileDialog::getSaveFileName (this ->ui ->diagnostic_group_box_refresh , " Select Log file..." ,
0 commit comments