File indexing completed on 2024-05-05 16:46:53
0001 /* 0002 SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de> 0003 SPDX-FileCopyrightText: 2016 Kevin Funk <kfunk@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_PLUGIN_QUICKOPENWIDGET_H 0009 #define KDEVPLATFORM_PLUGIN_QUICKOPENWIDGET_H 0010 0011 #include "ui_quickopenwidget.h" 0012 0013 #include <QMenu> 0014 #include <QTime> 0015 #include <QTimer> 0016 0017 class QuickOpenModel; 0018 0019 class QAbstractProxyModel; 0020 class QLineEdit; 0021 0022 /// Will delete itself once the dialog is closed, so use QPointer when referencing it permanently 0023 class QuickOpenWidget 0024 : public QMenu 0025 { 0026 Q_OBJECT 0027 public: 0028 /** 0029 * @param initialItems List of items that should initially be enabled in the quickopen-list. If empty, all are enabled. 0030 * @param initialScopes List of scopes that should initially be enabled in the quickopen-list. If empty, all are enabled. 0031 * @param listOnly when this is true, the given items will be listed, but all filtering using checkboxes is disabled. 0032 * @param noSearchField when this is true, no search-line is shown. 0033 * */ 0034 QuickOpenWidget(QuickOpenModel* model, const QStringList& initialItems, const QStringList& initialScopes, bool listOnly = false, bool noSearchField = false); 0035 ~QuickOpenWidget() override; 0036 void setPreselectedText(const QString& text); 0037 void prepareShow(); 0038 0039 void setAlternativeSearchField(QLineEdit* alterantiveSearchField); 0040 0041 bool sortingEnabled() const; 0042 void setSortingEnabled(bool enabled); 0043 0044 //Shows OK + Cancel. By default they are hidden 0045 void showStandardButtons(bool show); 0046 void showSearchField(bool show); 0047 Q_SIGNALS: 0048 void scopesChanged(const QStringList& scopes); 0049 void itemsChanged(const QStringList& scopes); 0050 void ready(); 0051 private Q_SLOTS: 0052 void callRowSelected(); 0053 0054 void updateTimerInterval(bool cheapFilterChange); 0055 0056 void accept(); 0057 void textChanged(const QString& str); 0058 void updateProviders(); 0059 void doubleClicked (const QModelIndex& index); 0060 0061 void applyFilter(); 0062 private: 0063 void showEvent(QShowEvent*) override; 0064 0065 bool eventFilter (QObject* watched, QEvent* event) override; 0066 0067 void avoidMenuAltFocus(); 0068 0069 QuickOpenModel* m_model; 0070 QAbstractProxyModel* m_proxy = nullptr; 0071 bool m_sortingEnabled = false; 0072 bool m_expandedTemporary, m_hadNoCommandSinceAlt; 0073 QTime m_altDownTime; 0074 QString m_preselectedText; 0075 QTimer m_filterTimer; 0076 QString m_filter; 0077 public: 0078 Ui::QuickOpenWidget ui; 0079 0080 friend class QuickOpenWidgetDialog; 0081 friend class QuickOpenPlugin; 0082 friend class QuickOpenLineEdit; 0083 }; 0084 0085 class QuickOpenWidgetDialog 0086 : public QObject 0087 { 0088 Q_OBJECT 0089 public: 0090 QuickOpenWidgetDialog(const QString& title, QuickOpenModel* model, const QStringList& initialItems, const QStringList& initialScopes, bool listOnly = false, bool noSearchField = false); 0091 ~QuickOpenWidgetDialog() override; 0092 0093 /// Shows the dialog 0094 void run(); 0095 0096 QuickOpenWidget* widget() const 0097 { 0098 return m_widget; 0099 } 0100 private: 0101 QDialog* m_dialog; /// @warning m_dialog is also the parent 0102 QuickOpenWidget* m_widget; 0103 }; 0104 0105 #endif