2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-08-29 00:48:23 +08:00
|
|
|
#ifndef HEADERCOMPLETIONPOPUP_H
|
|
|
|
#define HEADERCOMPLETIONPOPUP_H
|
|
|
|
|
2022-04-14 22:25:49 +08:00
|
|
|
#include <QDir>
|
2021-08-29 00:48:23 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include "codecompletionlistview.h"
|
|
|
|
#include "../parser/cppparser.h"
|
|
|
|
|
2022-04-14 22:25:49 +08:00
|
|
|
enum class HeaderCompletionListItemType {
|
|
|
|
LocalHeader,
|
|
|
|
ProjectHeader,
|
|
|
|
SystemHeader
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HeaderCompletionListItem {
|
|
|
|
QString filename;
|
|
|
|
QString fullpath;
|
2023-03-11 19:30:56 +08:00
|
|
|
QString suffix;
|
|
|
|
QString noSuffixFilename;
|
2022-06-20 21:43:42 +08:00
|
|
|
bool isFolder;
|
2022-04-14 22:25:49 +08:00
|
|
|
int usageCount;
|
|
|
|
HeaderCompletionListItemType itemType;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PHeaderCompletionListItem=std::shared_ptr<HeaderCompletionListItem>;
|
|
|
|
|
2021-08-29 00:48:23 +08:00
|
|
|
class HeaderCompletionListModel: public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2022-04-14 22:25:49 +08:00
|
|
|
explicit HeaderCompletionListModel(const QList<PHeaderCompletionListItem>* files,QObject *parent = nullptr);
|
2021-08-29 00:48:23 +08:00
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
void notifyUpdated();
|
2022-04-14 22:25:49 +08:00
|
|
|
void setLocalColor(const QColor &newColor);
|
|
|
|
void setSystemColor(const QColor &newColor);
|
|
|
|
void setProjectColor(const QColor &newColor);
|
2021-08-29 00:48:23 +08:00
|
|
|
|
2022-06-20 21:43:42 +08:00
|
|
|
void setFolderColor(const QColor &newFolderColor);
|
|
|
|
|
2021-08-29 00:48:23 +08:00
|
|
|
private:
|
2022-06-20 21:43:42 +08:00
|
|
|
const QList<PHeaderCompletionListItem> *mFiles;
|
2022-04-14 22:25:49 +08:00
|
|
|
QColor mLocalColor;
|
|
|
|
QColor mSystemColor;
|
|
|
|
QColor mProjectColor;
|
2022-06-20 21:43:42 +08:00
|
|
|
QColor mFolderColor;
|
2021-08-29 00:48:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class HeaderCompletionPopup : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
HeaderCompletionPopup(QWidget* parent=nullptr);
|
|
|
|
~HeaderCompletionPopup();
|
|
|
|
void prepareSearch(const QString& phrase, const QString& fileName);
|
|
|
|
bool search(const QString& phrase, bool autoHideOnSingleResult);
|
|
|
|
void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback);
|
2022-04-14 22:25:49 +08:00
|
|
|
void setSuggestionColor(const QColor& localColor,
|
|
|
|
const QColor& projectColor,
|
2022-06-20 21:43:42 +08:00
|
|
|
const QColor& systemColor,
|
|
|
|
const QColor& folderColor);
|
2022-04-14 22:25:49 +08:00
|
|
|
QString selectedFilename(bool updateUsageCount);
|
2021-08-29 00:48:23 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void filterList(const QString& member);
|
|
|
|
void getCompletionFor(const QString& phrase);
|
2022-04-14 22:25:49 +08:00
|
|
|
void addFilesInPath(const QString& path, HeaderCompletionListItemType type);
|
2022-06-20 21:43:42 +08:00
|
|
|
void addFile(const QDir& dir, const QFileInfo &fileInfo, HeaderCompletionListItemType type);
|
2022-04-14 22:25:49 +08:00
|
|
|
void addFilesInSubDir(const QString& baseDirPath, const QString& subDirName, HeaderCompletionListItemType type);
|
2021-08-29 00:48:23 +08:00
|
|
|
private:
|
|
|
|
|
|
|
|
CodeCompletionListView* mListView;
|
|
|
|
HeaderCompletionListModel* mModel;
|
2022-04-14 22:25:49 +08:00
|
|
|
QHash<QString, PHeaderCompletionListItem> mFullCompletionList;
|
|
|
|
QList<PHeaderCompletionListItem> mCompletionList;
|
|
|
|
QHash<QString,int> mHeaderUsageCounts;
|
2021-08-29 00:48:23 +08:00
|
|
|
int mShowCount;
|
|
|
|
QSet<QString> mAddedFileNames;
|
|
|
|
|
|
|
|
PCppParser mParser;
|
|
|
|
QString mPhrase;
|
|
|
|
bool mIgnoreCase;
|
|
|
|
bool mSearchLocal;
|
|
|
|
QString mCurrentFile;
|
|
|
|
|
|
|
|
// QWidget interface
|
|
|
|
protected:
|
|
|
|
void hideEvent(QHideEvent *event) override;
|
|
|
|
|
|
|
|
// QObject interface
|
|
|
|
public:
|
|
|
|
bool event(QEvent *event) override;
|
2021-08-29 10:14:07 +08:00
|
|
|
void setParser(const PCppParser &newParser);
|
|
|
|
const QString &phrase() const;
|
|
|
|
bool ignoreCase() const;
|
|
|
|
void setIgnoreCase(bool newIgnoreCase);
|
|
|
|
bool searchLocal() const;
|
|
|
|
void setSearchLocal(bool newSearchLocal);
|
2021-08-29 00:48:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HEADERCOMPLETIONPOPUP_H
|