2023-04-11 10:19:35 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* 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-05-22 21:29:43 +08:00
|
|
|
#ifndef RESULTVIEW_H
|
|
|
|
#define RESULTVIEW_H
|
|
|
|
#include <QTreeView>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QLabel>
|
2021-05-27 10:25:15 +08:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QApplication>
|
2021-05-22 21:29:43 +08:00
|
|
|
#include "search-result-model.h"
|
|
|
|
#include "show-more-label.h"
|
|
|
|
#include "title-label.h"
|
2021-05-25 19:42:40 +08:00
|
|
|
#include "result-view-delegate.h"
|
2021-05-22 21:29:43 +08:00
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
namespace UkuiSearch {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
|
|
|
class ResultView : public QTreeView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ResultView(const QString &plugin_id, QWidget *parent = nullptr);
|
|
|
|
~ResultView() = default;
|
|
|
|
bool isSelected();
|
2021-05-27 10:25:15 +08:00
|
|
|
int showHeight();
|
2021-08-18 14:23:14 +08:00
|
|
|
int getResultNum();
|
|
|
|
QModelIndex getModlIndex(int row, int column);
|
|
|
|
SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void clearSelectedRow();
|
2021-05-25 19:42:40 +08:00
|
|
|
void onRowDoubleClickedSlot(const QModelIndex &);
|
2021-08-18 14:23:14 +08:00
|
|
|
void onRowSelectedSlot(const QModelIndex &index);
|
2021-05-27 10:25:15 +08:00
|
|
|
void onItemListChanged(const int &);
|
|
|
|
void setExpanded(const bool &);
|
|
|
|
const bool &isExpanded();
|
|
|
|
void onMenuTriggered(QAction *);
|
|
|
|
|
2021-09-08 15:41:28 +08:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QMouseEvent *event);
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event);
|
2021-09-09 11:23:59 +08:00
|
|
|
void mouseMoveEvent(QMouseEvent *event);
|
2022-08-18 17:27:10 +08:00
|
|
|
bool viewportEvent(QEvent *event);
|
2021-09-08 15:41:28 +08:00
|
|
|
|
2021-05-22 21:29:43 +08:00
|
|
|
private:
|
|
|
|
void initConnections();
|
|
|
|
SearchResultModel * m_model = nullptr;
|
|
|
|
QString m_plugin_id;
|
|
|
|
bool m_is_selected = false;
|
2022-06-15 15:54:50 +08:00
|
|
|
ResultViewDelegate * m_styleDelegate = nullptr;
|
2021-05-27 10:25:15 +08:00
|
|
|
int m_count = 0;
|
2021-09-08 16:34:32 +08:00
|
|
|
QModelIndex m_tmpCurrentIndex;
|
|
|
|
QModelIndex m_tmpMousePressIndex;
|
2022-08-18 17:27:10 +08:00
|
|
|
QTimer *m_touchTimer;
|
2021-05-22 21:29:43 +08:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void startSearch(const QString &);
|
|
|
|
void stopSearch();
|
|
|
|
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
|
2021-08-02 13:46:59 +08:00
|
|
|
void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&);
|
2021-05-27 10:25:15 +08:00
|
|
|
void listLengthChanged(const int &);
|
|
|
|
void rowClicked();
|
2021-08-12 14:57:25 +08:00
|
|
|
void lableReset();
|
2021-05-22 21:29:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ResultWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ResultWidget(const QString &plugin_id, QWidget *parent = nullptr);
|
|
|
|
~ResultWidget() = default;
|
|
|
|
QString pluginId();
|
2022-04-15 15:52:15 +08:00
|
|
|
QString pluginName();
|
2021-05-22 21:29:43 +08:00
|
|
|
void setEnabled(const bool&);
|
2021-08-12 14:57:25 +08:00
|
|
|
void clearResult();
|
2021-08-18 14:23:14 +08:00
|
|
|
int getResultNum();
|
|
|
|
void setResultSelection(const QModelIndex &index);
|
|
|
|
void clearResultSelection();
|
|
|
|
QModelIndex getModlIndex(int row, int column);
|
|
|
|
void activateIndex();
|
|
|
|
QModelIndex getCurrentSelection();
|
|
|
|
bool getExpandState();
|
|
|
|
SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index);
|
2021-10-20 16:30:20 +08:00
|
|
|
void resetTitleLabel();
|
|
|
|
void setTitileLableHide(bool state);
|
2021-05-25 19:42:40 +08:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void expandListSlot();
|
|
|
|
void reduceListSlot();
|
2021-05-27 10:25:15 +08:00
|
|
|
void onListLengthChanged(const int &);
|
2021-05-25 19:42:40 +08:00
|
|
|
|
2021-05-22 21:29:43 +08:00
|
|
|
private:
|
|
|
|
void initUi();
|
|
|
|
void initConnections();
|
2021-08-20 10:07:53 +08:00
|
|
|
|
|
|
|
QString m_plugin_id;
|
2022-04-15 15:52:15 +08:00
|
|
|
QString m_plugin_name;
|
2021-08-20 10:07:53 +08:00
|
|
|
bool m_enabled = true;
|
2021-05-22 21:29:43 +08:00
|
|
|
QVBoxLayout * m_mainLyt = nullptr;
|
|
|
|
TitleLabel * m_titleLabel = nullptr;
|
|
|
|
ResultView * m_resultView = nullptr;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void startSearch(const QString &);
|
|
|
|
void stopSearch();
|
|
|
|
void currentRowChanged(const QString &, const SearchPluginIface::ResultInfo&);
|
2021-08-02 13:46:59 +08:00
|
|
|
void sendBestListData(const QString &, const SearchPluginIface::ResultInfo&);
|
2021-05-22 21:29:43 +08:00
|
|
|
void clearSelectedRow();
|
2021-05-27 10:25:15 +08:00
|
|
|
void sizeChanged();
|
|
|
|
void rowClicked();
|
2021-08-12 14:57:25 +08:00
|
|
|
void resizeWidth(const int &);
|
2021-10-20 16:30:20 +08:00
|
|
|
void showMoreClicked();
|
|
|
|
void retractClicked();
|
2021-05-22 21:29:43 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // RESULTVIEW_H
|