File indexing completed on 2024-05-12 16:40:07
0001 /* This file is part of the KDE project 0002 Copyright (C) 2011-2015 Jarosław Staniek <staniek@kde.org> 0003 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this program; see the file COPYING. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KEXISEARCHLINEEDIT_H 0022 #define KEXISEARCHLINEEDIT_H 0023 0024 #include <QPair> 0025 #include <QModelIndex> 0026 #include <QLineEdit> 0027 #include <KexiSearchableModel.h> 0028 0029 class KexiSearchableModel; 0030 0031 //! @short Search line edit with advanced autocompletion 0032 /*! It works like QLineEdit with QCompleter but uses fork of QCompleter 0033 for full-text-search. 0034 @note Qt Embedded features of QLineEdit+QCompleter 0035 (i.e. those marked with ifdef QT_KEYPAD_NAVIGATION) are not ported. */ 0036 class KexiSearchLineEdit : public QLineEdit 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(bool highlightMatchingSubstrings READ highlightMatchingSubstrings WRITE setHighlightMatchingSubstrings) 0040 0041 public: 0042 explicit KexiSearchLineEdit(QWidget *parent = 0); 0043 0044 virtual ~KexiSearchLineEdit(); 0045 0046 /*! Add searchable model to the main window. This extends search to a new area. 0047 One example is Project Navigator. */ 0048 void addSearchableModel(KexiSearchableModel *model); 0049 0050 /*! Removes searchable model from the main window. @a model is not deleted. */ 0051 void removeSearchableModel(KexiSearchableModel *model); 0052 0053 /*! @return true if matching substrings are highlighted in completion list. 0054 @see setHighlightMatchingSubstrings() */ 0055 bool highlightMatchingSubstrings() const; 0056 0057 /*! If @a highlight is true makes matching substrings are highlighted in completion list. 0058 By default highlighting is on. 0059 @see highlightMatchingSubstrings() */ 0060 void setHighlightMatchingSubstrings(bool highlight); 0061 0062 public Q_SLOTS: 0063 void setFocus(); 0064 0065 private Q_SLOTS: 0066 void slotCompletionHighlighted(const QString &newText); 0067 void slotCompletionHighlighted(const QModelIndex &index); 0068 void slotCompletionActivated(const QModelIndex &index); 0069 void slotClearShortcutActivated(); 0070 0071 protected: 0072 virtual void inputMethodEvent(QInputMethodEvent *e) override; 0073 virtual void focusInEvent(QFocusEvent *e) override; 0074 virtual void focusOutEvent(QFocusEvent *e) override; 0075 virtual void keyPressEvent(QKeyEvent *e) override; 0076 virtual void changeEvent(QEvent *event) override; 0077 0078 private: 0079 void connectCompleter(); 0080 void disconnectCompleter(); 0081 bool advanceToEnabledItem(int dir); 0082 void complete(int key); 0083 QString textBeforeSelection() const; 0084 QString textAfterSelection() const; 0085 int selectionEnd() const; 0086 0087 QPair<QModelIndex, KexiSearchableModel*> mapCompletionIndexToSource(const QModelIndex &index) const; 0088 0089 class Private; 0090 Private * const d; 0091 }; 0092 0093 #endif