Changeset View
Changeset View
Standalone View
Standalone View
src/mode/katemodemenulist.h
1 | /* This file is part of the KDE libraries and the Kate part. | 1 | /* This file is part of the KDE libraries and the KTextEditor project. | ||
---|---|---|---|---|---|
2 | * | 2 | * | ||
3 | * Copyright (C) 2019 Nibaldo González S. <nibgonz@gmail.com> | 3 | * Copyright (C) 2019 Nibaldo González S. <nibgonz@gmail.com> | ||
4 | * | 4 | * | ||
5 | * This library is free software; you can redistribute it and/or | 5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Library General Public | 6 | * modify it under the terms of the GNU Library General Public | ||
7 | * License as published by the Free Software Foundation; either | 7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2 of the License, or (at your option) any later version. | 8 | * version 2 of the License, or (at your option) any later version. | ||
9 | * | 9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | 10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Library General Public License for more details. | 13 | * Library General Public License for more details. | ||
14 | * | 14 | * | ||
15 | * You should have received a copy of the GNU Library General Public License | 15 | * You should have received a copy of the GNU Library General Public License | ||
16 | * along with this library; see the file COPYING.LIB. If not, write to | 16 | * along with this library; see the file COPYING.LIB. If not, write to | ||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | * | ||||
20 | * --------------------------------------------------------------------- | ||||
21 | * NOTE: The KateModeMenuListData::SearchLine class is based on | ||||
22 | * KListWidgetSearchLine, by Scott Wheeler <wheeler@kde.org> and | ||||
23 | * Gustavo Sverzut Barbieri <gsbarbieri@users.sourceforge.net>. | ||||
24 | * See: https://api.kde.org/frameworks/kitemviews/html/classKListWidgetSearchLine.html | ||||
25 | * | ||||
26 | * TODO: Add keyboard shortcut to show the menu. Put the menu in | ||||
27 | * the center of the window if the status bar is hidden. | ||||
28 | * See: KateModeMenuList::showEvent() | ||||
19 | */ | 29 | */ | ||
20 | 30 | | |||
21 | #ifndef KATEMODEMENULIST_H | 31 | #ifndef KATEMODEMENULIST_H | ||
22 | #define KATEMODEMENULIST_H | 32 | #define KATEMODEMENULIST_H | ||
23 | 33 | | |||
24 | #include <QMenu> | 34 | #include <QMenu> | ||
25 | #include <QPushButton> | 35 | #include <QListView> | ||
26 | #include <QListWidget> | 36 | #include <QStandardItemModel> | ||
37 | #include <QLineEdit> | ||||
27 | #include <QScrollBar> | 38 | #include <QScrollBar> | ||
39 | #include <QPushButton> | ||||
28 | #include <QGridLayout> | 40 | #include <QGridLayout> | ||
29 | #include <QString> | 41 | #include <QString> | ||
30 | #include <QLabel> | 42 | #include <QLabel> | ||
31 | #include <QIcon> | 43 | #include <QIcon> | ||
32 | #include <QKeyEvent> | 44 | #include <QKeyEvent> | ||
33 | 45 | | |||
34 | #include <KListWidgetSearchLine> | | |||
35 | | ||||
36 | #include "katemodemanager.h" | 46 | #include "katemodemanager.h" | ||
37 | 47 | | |||
38 | namespace KTextEditor { class DocumentPrivate; } | 48 | namespace KTextEditor { class DocumentPrivate; } | ||
39 | 49 | | |||
50 | namespace KateModeMenuListData { class ListView; class ListItem; class SearchLine; } | ||||
51 | | ||||
40 | /** | 52 | /** | ||
41 | * Class of menu to select the | 53 | * Class of menu to select the | ||
42 | * syntax highlighting language (mode menu). | 54 | * syntax highlighting language (mode menu). | ||
43 | * Provides a menu with a scrollable list plus search bar. | 55 | * Provides a menu with a scrollable list plus search bar. | ||
44 | * | 56 | * | ||
45 | * This is an alternative to the classic mode menu of the KateModeMenu class. | 57 | * This is an alternative to the classic mode menu of the KateModeMenu class. | ||
46 | * | 58 | * | ||
47 | * @see KateModeManager, KateFileType, KateModeMenu | 59 | * @see KateModeManager, KateFileType, KateModeMenu | ||
48 | */ | 60 | */ | ||
49 | class KateModeMenuList : public QMenu | 61 | class KateModeMenuList : public QMenu | ||
50 | { | 62 | { | ||
51 | Q_OBJECT | 63 | Q_OBJECT | ||
52 | 64 | | |||
53 | public: | 65 | public: | ||
54 | /** | 66 | /** | ||
55 | * Alignment with respect to the trigger button. | 67 | * Alignment with respect to the trigger button. | ||
56 | * "Default" is the normal alignment (left alignment in Left-to-right layouts). | 68 | * "Default" is the normal alignment (left alignment in Left-to-right layouts). | ||
57 | * "Inverse" uses right alignment in Left-to-right layouts and left | 69 | * "Inverse" uses right alignment in Left-to-right layouts and left | ||
58 | * alignment in Right-to-left layouts (used in some languages). | 70 | * alignment in Right-to-left layouts (used in some languages). | ||
59 | * "Left" or "Right" forces the alignment. | 71 | * "Left" and "Right" forces the alignment. | ||
60 | * @see setButton(), QWidget::layoutDirection(), Qt::LayoutDirection | 72 | * @see setButton(), QWidget::layoutDirection(), Qt::LayoutDirection | ||
61 | */ | 73 | */ | ||
62 | enum AlignmentButton { | 74 | enum AlignmentButton { | ||
63 | Default, | 75 | Default, | ||
64 | Inverse, | 76 | Inverse, | ||
65 | Left, | 77 | Left, | ||
66 | Right | 78 | Right | ||
67 | }; | 79 | }; | ||
68 | /** | 80 | /** | ||
69 | * Search bar position, above or below the list. | 81 | * Search bar position, above or below the list. | ||
70 | */ | 82 | */ | ||
71 | enum SearchBarPosition { | 83 | enum SearchBarPosition { | ||
72 | Top, | 84 | Top, | ||
73 | Bottom | 85 | Bottom | ||
74 | }; | 86 | }; | ||
87 | /** | ||||
88 | * Defines where the list will scroll after clearing the search or changing the view. | ||||
89 | * @see setAutoScroll(), autoScroll() | ||||
90 | */ | ||||
91 | enum AutoScroll { | ||||
92 | ScrollToSelectedItem, | ||||
93 | ScrollToTop | ||||
94 | }; | ||||
75 | 95 | | |||
76 | /** | 96 | /** | ||
77 | * @param searchBarPos Search bar position, can be top or bottom. | 97 | * @param searchBarPos Search bar position, can be top or bottom. | ||
78 | * @see SearchBarPosition | 98 | * @see SearchBarPosition | ||
79 | */ | 99 | */ | ||
80 | KateModeMenuList(const SearchBarPosition searchBarPos = Bottom) : QMenu() | 100 | KateModeMenuList(const SearchBarPosition searchBarPos = Bottom) : QMenu() | ||
81 | { | 101 | { | ||
82 | init(searchBarPos); | 102 | init(searchBarPos); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
124 | * | 144 | * | ||
125 | * @see AlignmentButton | 145 | * @see AlignmentButton | ||
126 | */ | 146 | */ | ||
127 | void setButton(QPushButton *button, const bool bAutoUpdateTextButton = false, AlignmentButton position = Inverse); | 147 | void setButton(QPushButton *button, const bool bAutoUpdateTextButton = false, AlignmentButton position = Inverse); | ||
128 | 148 | | |||
129 | /** | 149 | /** | ||
130 | * Define the size of the list widget, in pixels. | 150 | * Define the size of the list widget, in pixels. | ||
131 | */ | 151 | */ | ||
132 | inline void setSizeList(const int height, const int width = 260) | 152 | inline void setSizeList(const int height, const int width = 260); | ||
153 | | ||||
154 | /** | ||||
155 | * Define the scroll when cleaning the search or changing the view. | ||||
156 | * The default value is AutoScroll::ScrollToSelectedItem. | ||||
157 | * @see AutoScroll | ||||
158 | */ | ||||
159 | void setAutoScroll(AutoScroll scroll) | ||||
133 | { | 160 | { | ||
134 | m_list->setSizeList(height, width); | 161 | m_autoScroll = scroll; | ||
135 | } | 162 | } | ||
136 | 163 | | |||
137 | /** | 164 | /** | ||
138 | * Set document to apply the syntax highlighting. | 165 | * Set document to apply the syntax highlighting. | ||
139 | * @see KTextEditor::DocumentPrivate | 166 | * @see KTextEditor::DocumentPrivate | ||
140 | */ | 167 | */ | ||
141 | void updateMenu(KTextEditor::Document *doc); | 168 | void updateMenu(KTextEditor::Document *doc); | ||
142 | 169 | | |||
143 | protected: | 170 | protected: | ||
171 | friend KateModeMenuListData::ListView; | ||||
172 | friend KateModeMenuListData::ListItem; | ||||
173 | friend KateModeMenuListData::SearchLine; | ||||
174 | | ||||
175 | /** | ||||
176 | * Action when displaying the menu. | ||||
177 | * Override from QWidget. | ||||
178 | */ | ||||
179 | void showEvent(QShowEvent *event) override; | ||||
180 | | ||||
181 | private: | ||||
182 | void init(const SearchBarPosition searchBarPos); | ||||
183 | | ||||
184 | /** | ||||
185 | * Load the data model with the syntax highlighting definitions to show in the list. | ||||
186 | */ | ||||
187 | void loadHighlightingModel(); | ||||
188 | | ||||
189 | /** | ||||
190 | * Scroll the list, according to AutoScroll. | ||||
191 | * @see AutoScroll | ||||
192 | */ | ||||
193 | void autoScroll(); | ||||
194 | | ||||
195 | /** | ||||
196 | * Set a custom word wrap on a text line, according to a maximum width (in pixels). | ||||
197 | * @param text Line of text | ||||
198 | * @param maxWidth Width of the text container, in pixels. | ||||
199 | * @param fontMetrics Font metrics. See QWidget::fontMetrics() | ||||
200 | */ | ||||
201 | QString setWordWrap(const QString &text, const int maxWidth, const QFontMetrics &fontMetrics) const; | ||||
202 | | ||||
203 | /** | ||||
204 | * Update the selected item in the list, with the active syntax highlighting. | ||||
205 | * This method only changes the selected item, doesn't apply | ||||
206 | * syntax highlighting in the document, or hides the menu. | ||||
207 | * @see selectHighlighting(), selectHighlightingFromExternal(), selectHighlightingSetVisibility() | ||||
208 | */ | ||||
209 | void updateSelectedItem(KateModeMenuListData::ListItem *item); | ||||
210 | | ||||
211 | /** | ||||
212 | * Select an item from the list and apply the syntax highlighting in the document. | ||||
213 | * This is equivalent to KateModeMenuList::selectHighlighting(). | ||||
214 | * @param bHideMenu If the menu should be hidden after applying the highlight. | ||||
215 | * @see selectHighlighting() | ||||
216 | */ | ||||
217 | void selectHighlightingSetVisibility(QStandardItem *pItem, const bool bHideMenu); | ||||
218 | | ||||
219 | /** | ||||
220 | * Load message when the list is empty in the search. | ||||
221 | */ | ||||
222 | inline void loadEmptyMsg(); | ||||
223 | | ||||
224 | AutoScroll m_autoScroll = ScrollToSelectedItem; | ||||
225 | AlignmentButton m_position; | ||||
226 | bool m_bAutoUpdateTextButton; | ||||
227 | | ||||
228 | QPushButton *m_pushButton = nullptr; | ||||
229 | QLabel *m_emptyListMsg = nullptr; | ||||
230 | QGridLayout *m_layoutList = nullptr; | ||||
231 | QScrollBar *m_scroll = nullptr; | ||||
232 | | ||||
233 | KateModeMenuListData::SearchLine *m_searchBar = nullptr; | ||||
234 | KateModeMenuListData::ListView *m_list = nullptr; | ||||
235 | QStandardItemModel *m_model = nullptr; | ||||
236 | | ||||
237 | /** | ||||
238 | * Item with active syntax highlighting. | ||||
239 | */ | ||||
240 | KateModeMenuListData::ListItem *m_selectedItem = nullptr; | ||||
144 | 241 | | |||
145 | /** | 242 | /** | ||
243 | * Icon for selected/active item (checkbox). | ||||
244 | * NOTE: Selected and inactive items show an icon with incorrect color, | ||||
245 | * however, this isn't a problem, since the list widget is never inactive. | ||||
246 | */ | ||||
247 | const QIcon m_checkIcon = QIcon::fromTheme(QStringLiteral("checkbox")); | ||||
248 | static const int m_iconSize = 16; | ||||
249 | | ||||
250 | QPointer<KTextEditor::DocumentPrivate> m_doc; | ||||
251 | | ||||
252 | private Q_SLOTS: | ||||
253 | /** | ||||
254 | * Action when selecting a item in the list. This also applies | ||||
255 | * the syntax highlighting in the document and hides the menu. | ||||
256 | * This is equivalent to KateModeMenuList::selectHighlightingSetVisibility(). | ||||
257 | * @see selectHighlightingSetVisibility(), updateSelectedItem() | ||||
258 | */ | ||||
259 | void selectHighlighting(const QModelIndex &index); | ||||
260 | }; | ||||
261 | | ||||
262 | | ||||
263 | namespace KateModeMenuListData | ||||
264 | { | ||||
265 | /** | ||||
146 | * Class of List Widget. | 266 | * Class of List Widget. | ||
147 | */ | 267 | */ | ||
148 | class ModeListWidget : public QListWidget | 268 | class ListView : public QListView | ||
149 | { | 269 | { | ||
150 | public: | 270 | Q_OBJECT | ||
151 | ModeListWidget(KateModeMenuList *menu) : QListWidget(menu) | 271 | | ||
272 | private: | ||||
273 | ListView(KateModeMenuList *menu) : QListView(menu) | ||||
152 | { | 274 | { | ||
153 | m_parentMenu = menu; | 275 | m_parentMenu = menu; | ||
154 | } | 276 | } | ||
155 | 277 | | |||
156 | /** | 278 | public: | ||
157 | * Add item, setting the default properties. | | |||
158 | */ | | |||
159 | void addDefaultItem(QListWidgetItem *item); | | |||
160 | | ||||
161 | /** | 279 | /** | ||
162 | * Define the size of the widget list. | 280 | * Define the size of the widget list. | ||
163 | * @p height and @p width are values in pixels. | 281 | * @p height and @p width are values in pixels. | ||
164 | */ | 282 | */ | ||
165 | void setSizeList(const int height, const int width = 260); | 283 | void setSizeList(const int height, const int width = 260); | ||
166 | 284 | | |||
285 | inline void setCurrentItem(const int rowItem) | ||||
286 | { | ||||
287 | selectionModel()->setCurrentIndex(m_parentMenu->m_model->index(rowItem, 0), QItemSelectionModel::ClearAndSelect); | ||||
288 | } | ||||
289 | inline QStandardItem* currentItem() const | ||||
290 | { | ||||
291 | return m_parentMenu->m_model->item(currentIndex().row(), 0); | ||||
292 | } | ||||
293 | | ||||
294 | inline void scrollToItem(const int rowItem, QAbstractItemView::ScrollHint hint = QAbstractItemView::PositionAtCenter) | ||||
295 | { | ||||
296 | scrollTo(m_parentMenu->m_model->index(rowItem, 0), hint); | ||||
297 | } | ||||
298 | | ||||
167 | protected: | 299 | protected: | ||
168 | /** | 300 | /** | ||
169 | * Override from QListWidget. | 301 | * Override from QListView. | ||
170 | */ | 302 | */ | ||
171 | void keyPressEvent(QKeyEvent *event) override; | 303 | void keyPressEvent(QKeyEvent *event) override; | ||
172 | 304 | | |||
173 | private: | 305 | private: | ||
174 | KateModeMenuList *m_parentMenu = nullptr; | 306 | KateModeMenuList *m_parentMenu = nullptr; | ||
307 | friend KateModeMenuList; | ||||
175 | }; | 308 | }; | ||
176 | 309 | | |||
177 | 310 | | |||
178 | /** | 311 | /** | ||
179 | * Class of an Item of the List Widget. | 312 | * Class of an Item of the Data Model of the List. | ||
180 | * @see ModeListWidget, KateFileType | 313 | * @see KateModeMenuListData::ListView, KateFileType, QStandardItemModel | ||
181 | */ | 314 | */ | ||
182 | class ModeListWidgetItem : public QListWidgetItem | 315 | class ListItem : public QStandardItem | ||
183 | { | 316 | { | ||
184 | public: | 317 | private: | ||
185 | ModeListWidgetItem() : QListWidgetItem() { } | 318 | ListItem() : QStandardItem() { } | ||
319 | | ||||
320 | const KateFileType *m_type = nullptr; | ||||
321 | const QString *m_searchName = nullptr; | ||||
322 | | ||||
323 | friend KateModeMenuList; | ||||
186 | 324 | | |||
325 | public: | ||||
187 | /** | 326 | /** | ||
188 | * Associate this item with a KateFileType object. | 327 | * Associate this item with a KateFileType object. | ||
189 | */ | 328 | */ | ||
190 | inline void setMode(KateFileType *type) | 329 | inline void setMode(KateFileType *type) | ||
191 | { | 330 | { | ||
192 | m_type = type; | 331 | m_type = type; | ||
193 | return; | | |||
194 | } | 332 | } | ||
195 | inline const KateFileType* getMode() | 333 | const KateFileType* getMode() const | ||
196 | { | 334 | { | ||
197 | return m_type; | 335 | return m_type; | ||
198 | } | 336 | } | ||
199 | inline bool hasMode() const | 337 | bool hasMode() const | ||
200 | { | 338 | { | ||
201 | return m_type; | 339 | return m_type; | ||
202 | } | 340 | } | ||
203 | 341 | | |||
204 | /** | 342 | /** | ||
205 | * Generate name of the item used for the search. | 343 | * Generate name of the item used for the search. | ||
206 | * @param itemName Pointer to the item name, can be an attribute of a KateFileType object. | 344 | * @param itemName Pointer to the item name, can be an attribute of a KateFileType object. | ||
207 | * @return True if a new name is generated for the search. | 345 | * @return True if a new name is generated for the search. | ||
208 | */ | 346 | */ | ||
209 | bool generateSearchName(const QString *itemName); | 347 | bool generateSearchName(const QString *itemName); | ||
210 | 348 | | |||
211 | /** | 349 | /** | ||
212 | * Find matches in the extensions of the item mode, with a @p text. | 350 | * Find matches in the extensions of the item mode, with a @p text. | ||
213 | * @param text Text to match, without dots or asterisks. For example, in | 351 | * @param text Text to match, without dots or asterisks. For example, in | ||
214 | * a common extension, it corresponds to the text after "*." | 352 | * a common extension, it corresponds to the text after "*." | ||
215 | * @return True if a match is found, false if not. | 353 | * @return True if a match is found, false if not. | ||
216 | */ | 354 | */ | ||
217 | bool matchExtension(const QString &text); | 355 | bool matchExtension(const QString &text) const; | ||
218 | 356 | | |||
219 | inline const QString* getSearchName() | 357 | const QString* getSearchName() const | ||
220 | { | 358 | { | ||
221 | return m_searchName; | 359 | return m_searchName; | ||
222 | } | 360 | } | ||
223 | | ||||
224 | private: | | |||
225 | const KateFileType *m_type = nullptr; | | |||
226 | const QString *m_searchName = nullptr; | | |||
227 | }; | 361 | }; | ||
228 | 362 | | |||
229 | 363 | | |||
230 | /** | 364 | /** | ||
231 | * Class of Search Bar Widget. | 365 | * Class of Search Bar. | ||
366 | * Based on the KListWidgetSearchLine class. | ||||
232 | */ | 367 | */ | ||
233 | class ModeLineEdit : public KListWidgetSearchLine | 368 | class SearchLine : public QLineEdit | ||
234 | { | 369 | { | ||
235 | public: | 370 | Q_OBJECT | ||
236 | ModeLineEdit(KateModeMenuList *menu, QListWidget *listWidget) : KListWidgetSearchLine(menu, listWidget) | 371 | | ||
372 | private: | ||||
373 | SearchLine(KateModeMenuList *menu) : QLineEdit(menu) | ||||
237 | { | 374 | { | ||
238 | m_parentMenu = menu; | 375 | m_parentMenu = menu; | ||
376 | init(); | ||||
239 | } | 377 | } | ||
240 | ~ModeLineEdit() { }; | 378 | ~SearchLine() { }; | ||
241 | 379 | | |||
242 | /** | 380 | void init(); | ||
243 | * Override from KListWidgetSearchLine. | | |||
244 | */ | | |||
245 | void updateSearch(const QString &s = QString()) override; | | |||
246 | void clear(); | | |||
247 | 381 | | |||
248 | private: | | |||
249 | /** | 382 | /** | ||
250 | * Select result of the items search. | 383 | * Select result of the items search. | ||
251 | * Used only by ModeLineEdit::updateSearch(). | 384 | * Used only by KateModeMenuListData::SearchLine::updateSearch(). | ||
252 | */ | 385 | */ | ||
253 | void setSearchResult(const int rowItem, bool &bEmptySection, int &lastSection, int &lastItem); | 386 | void setSearchResult(const int rowItem, bool &bEmptySection, int &lastSection, int &lastItem); | ||
254 | 387 | | |||
255 | KateModeMenuList *m_parentMenu = nullptr; | | |||
256 | | ||||
257 | bool m_bSearchStateClear = true; | | |||
258 | bool m_bSearchStateAutoScroll = false; | | |||
259 | }; | | |||
260 | | ||||
261 | | ||||
262 | /** | | |||
263 | * Action when displaying the menu. | | |||
264 | * Override from QWidget. | | |||
265 | */ | | |||
266 | void showEvent(QShowEvent *event) override; | | |||
267 | | ||||
268 | private: | | |||
269 | void init(const SearchBarPosition searchBarPos); | | |||
270 | | ||||
271 | /** | | |||
272 | * Load the syntax highlighting definitions in the widget of list of items. | | |||
273 | */ | | |||
274 | void loadHighlightingList(); | | |||
275 | | ||||
276 | /** | | |||
277 | * Set a custom word wrap on a text line, according to a maximum width (in pixels). | | |||
278 | * @param text Line of text | | |||
279 | * @param maxWidth Width of the text container, in pixels. | | |||
280 | * @param fontMetrics Font metrics. See QWidget::fontMetrics() | | |||
281 | */ | | |||
282 | QString setWordWrap(const QString &text, const int maxWidth, const QFontMetrics &fontMetrics) const; | | |||
283 | | ||||
284 | /** | | |||
285 | * Update the selected item in the list widget. | | |||
286 | * This method only changes the selected item, doesn't apply | | |||
287 | * syntax highlighting in the document, or hides the menu. | | |||
288 | * @see selectHighlighting(), selectHighlightingFromExternal(), selectHighlightingSetVisibility() | | |||
289 | */ | | |||
290 | void updateSelectedItem(ModeListWidgetItem *item); | | |||
291 | | ||||
292 | /** | | |||
293 | * Select an item from the list and apply the syntax highlighting in the document. | | |||
294 | * This is equivalent to KateModeMenuList::selectHighlighting(). | | |||
295 | * @param bHideMenu If the menu should be hidden after applying the highlight. | | |||
296 | * @see selectHighlighting() | | |||
297 | */ | | |||
298 | void selectHighlightingSetVisibility(QListWidgetItem *pItem, const bool bHideMenu); | | |||
299 | | ||||
300 | /** | 388 | /** | ||
301 | * Load message when the list is empty in the search. | 389 | * Delay in search results after typing, in milliseconds. | ||
390 | * Default value: 200 | ||||
302 | */ | 391 | */ | ||
303 | inline void loadEmptyMsg(); | 392 | static const int m_searchDelay = 170; | ||
304 | | ||||
305 | QPushButton *m_pushButton = nullptr; | | |||
306 | AlignmentButton m_position; | | |||
307 | bool m_bAutoUpdateTextButton; | | |||
308 | 393 | | |||
309 | QGridLayout *m_layoutList = nullptr; | 394 | bool m_bSearchStateAutoScroll = false; | ||
310 | QLabel *m_emptyListMsg = nullptr; | 395 | QString m_search = QString(); | ||
311 | 396 | int m_queuedSearches = 0; | |||
312 | ModeLineEdit *m_searchBar = nullptr; | 397 | Qt::CaseSensitivity m_caseSensitivity = Qt::CaseInsensitive; | ||
313 | ModeListWidget *m_list = nullptr; | | |||
314 | QScrollBar *m_scroll = nullptr; | | |||
315 | 398 | | |||
316 | /** | 399 | KateModeMenuList *m_parentMenu = nullptr; | ||
317 | * Item with active syntax highlighting. | 400 | friend KateModeMenuList; | ||
318 | */ | | |||
319 | ModeListWidgetItem *m_selectedItem = nullptr; | | |||
320 | 401 | | |||
402 | protected: | ||||
321 | /** | 403 | /** | ||
322 | * Icon for selected item (checkbox). | 404 | * Override from QLineEdit. This allows you to navigate through | ||
323 | * NOTE: Selected and inactive items show an icon with incorrect color, | 405 | * the menu and write in the search bar simultaneously with the keyboard. | ||
324 | * however, this isn't a problem, since the list widget is never inactive. | | |||
325 | */ | 406 | */ | ||
326 | const QIcon m_checkIcon = QIcon::fromTheme(QStringLiteral("checkbox")); | 407 | void keyPressEvent(QKeyEvent *event) override; | ||
327 | static const int m_iconSize = 16; | | |||
328 | 408 | | |||
329 | QPointer<KTextEditor::DocumentPrivate> m_doc; | 409 | public Q_SLOTS: | ||
410 | virtual void clear(); | ||||
411 | virtual void updateSearch(const QString &s = QString()); | ||||
330 | 412 | | |||
331 | private Q_SLOTS: | 413 | private Q_SLOTS: | ||
332 | /** | 414 | void _k_queueSearch(const QString &s); | ||
333 | * Action when selecting a item in the list. This also applies | 415 | void _k_activateSearch(); | ||
334 | * the syntax highlighting in the document and hides the menu. | | |||
335 | * This is equivalent to KateModeMenuList::selectHighlightingSetVisibility(). | | |||
336 | * @see selectHighlightingSetVisibility(), updateSelectedItem() | | |||
337 | */ | | |||
338 | void selectHighlighting(QListWidgetItem *pItem); | | |||
339 | }; | 416 | }; | ||
417 | } | ||||
340 | 418 | | |||
341 | #endif // KATEMODEMENULIST_H | 419 | #endif // KATEMODEMENULIST_H |