1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "locator.h" 29 30 #include <extensionsystem/iplugin.h> 31 #include <utils/optional.h> 32 33 #include <QFutureWatcher> 34 #include <QPointer> 35 #include <QWidget> 36 37 #include <functional> 38 39 QT_BEGIN_NAMESPACE 40 class QAbstractItemModel; 41 class QAction; 42 class QMenu; 43 QT_END_NAMESPACE 44 45 namespace Utils { class FancyLineEdit; } 46 47 namespace Core { 48 namespace Internal { 49 50 class LocatorModel; 51 class CompletionList; 52 53 class LocatorWidget 54 : public QWidget 55 { 56 Q_OBJECT 57 58 public: 59 explicit LocatorWidget(Locator *locator); 60 ~LocatorWidget() override; 61 62 void showText(const QString &text, int selectionStart = -1, int selectionLength = 0); 63 QString currentText() const; 64 QAbstractItemModel *model() const; 65 66 void updatePlaceholderText(Command *command); 67 68 void scheduleAcceptEntry(const QModelIndex &index); 69 70 static ExtensionSystem::IPlugin::ShutdownFlag aboutToShutdown( 71 const std::function<void()> &emitAsynchronousShutdownFinished); 72 73 signals: 74 void showCurrentItemToolTip(); 75 void lostFocus(); 76 void hidePopup(); 77 void selectRow(int row); 78 void handleKey(QKeyEvent *keyEvent); // only use with DirectConnection, event is deleted 79 void parentChanged(); 80 void showPopup(); 81 82 private: 83 void showPopupDelayed(); 84 void showPopupNow(); 85 void acceptEntry(int row); 86 static void showConfigureDialog(); 87 void addSearchResults(int firstIndex, int endIndex); 88 void handleSearchFinished(); 89 void updateFilterList(); 90 bool isInMainWindow() const; 91 92 void updatePreviousFocusWidget(QWidget *previous, QWidget *current); 93 bool eventFilter(QObject *obj, QEvent *event) override; 94 95 void updateCompletionList(const QString &text); 96 static QList<ILocatorFilter*> filtersFor(const QString &text, QString &searchText); 97 void setProgressIndicatorVisible(bool visible); 98 99 LocatorModel *m_locatorModel = nullptr; 100 101 static bool m_shuttingDown; 102 static QFuture<void> m_sharedFuture; 103 static LocatorWidget *m_sharedFutureOrigin; 104 105 QMenu *m_filterMenu = nullptr; 106 QAction *m_refreshAction = nullptr; 107 QAction *m_configureAction = nullptr; 108 Utils::FancyLineEdit *m_fileLineEdit = nullptr; 109 QTimer m_showPopupTimer; 110 QFutureWatcher<LocatorFilterEntry> *m_entriesWatcher = nullptr; 111 QString m_requestedCompletionText; 112 bool m_needsClearResult = true; 113 bool m_updateRequested = false; 114 bool m_rerunAfterFinished = false; 115 bool m_possibleToolTipRequest = false; 116 QWidget *m_progressIndicator = nullptr; 117 QTimer m_showProgressTimer; 118 Utils::optional<int> m_rowRequestedForAccept; 119 QPointer<QWidget> m_previousFocusWidget; 120 }; 121 122 class LocatorPopup : public QWidget 123 { 124 public: 125 LocatorPopup(LocatorWidget *locatorWidget, QWidget *parent = nullptr); 126 127 CompletionList *completionList() const; 128 LocatorWidget *inputWidget() const; 129 130 void focusOutEvent (QFocusEvent *event) override; 131 bool event(QEvent *event) override; 132 bool eventFilter(QObject *watched, QEvent *event) override; 133 134 protected: 135 QSize preferredSize(); 136 virtual void doUpdateGeometry(); 137 virtual void inputLostFocus(); 138 139 QPointer<QWidget> m_window; 140 CompletionList *m_tree = nullptr; 141 142 private: 143 void updateWindow(); 144 145 LocatorWidget *m_inputWidget = nullptr; 146 }; 147 148 LocatorWidget *createStaticLocatorWidget(Locator *locator); 149 LocatorPopup *createLocatorPopup(Locator *locator, QWidget *parent); 150 151 } // namespace Internal 152 } // namespace Core 153