File: windowThumbnailModel.h

package info (click to toggle)
ukui-panel 4.0.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,148 kB
  • sloc: cpp: 28,423; xml: 476; sh: 51; makefile: 18
file content (144 lines) | stat: -rw-r--r-- 3,609 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 *
 *  * 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/>.
 *  *
 *  * Authors: Nicole <buxiaoqing@kylinos.cn>
 *  *          zyy <zhangyuanyuan1@kylinos.cn>
 *
 */

#ifndef WINDOW_THUMBNAIL_MODEL_H
#define WINDOW_THUMBNAIL_MODEL_H

#include <QObject>
#include <QAbstractListModel>
#include <QIcon>

#include <windowmanager/windowmanager.h>
using namespace kdk;

class ThumbnailItem {
public:
    QVariant m_winId;
    QString m_groupName;
};

class ThumbnailModelItem
{
    Q_GADGET

public:
    ThumbnailModelItem() = default;
    explicit ThumbnailModelItem(const ThumbnailItem &thumbnail);
    ~ThumbnailModelItem() = default;

    QVariant winId() const;
    QString groupName() const;
    void setData(const ThumbnailItem &thumbnail);

private:
    ThumbnailItem m_data;
};

//----------------Model------------------
class ThumbnailModelPrivate;
class ThumbnailModel : public QAbstractListModel
{
    Q_OBJECT

public:
    static ThumbnailModel *instance();
    ~ThumbnailModel();

    QVariant data(const QModelIndex &index, int role) const override;
    int rowCount(const QModelIndex &parent) const override;

    /**
     * @brief 初始化model数据
     * @param data
     */
    void setModelData(const QList<QVariant> &data, const QString &groupName);

    /**
     * @brief 清除model
     */
    Q_INVOKABLE void clear();

    Q_INVOKABLE QList<QVariant> getGroupWIndowList(QString groupName);

    /**
     * 关闭窗口
     * @param winId
     */
    Q_INVOKABLE void closeWindow(const QVariant &winId);
    /**
     * 激活窗口
     * @param winId
     */
    Q_INVOKABLE void activateWindow(const QVariant &winId);
    /**
     * 窗口标题
     * @param winId
     * @return
     */
    Q_INVOKABLE QString getWindowTitle(const QVariant &winId);
    /**
     * 窗口图标
     * @param winId
     * @return
     */
    Q_INVOKABLE QIcon getWindowIcon(const QVariant &winId);
    /**
     * @brief 窗口uuid
     * @param winId
     * @return
     */
    Q_INVOKABLE QString getWindowUuid(const QVariant &winId);

//private Q_SLOTS:
public Q_SLOTS:
    /**
     * @brief 预览图窗口的增加
     * @param winId
     */
    void onWIndowAdded(const QVariant &winId, const QString &groupName);
    /**
     * @brief 预览图窗口的减少
     * @param winId
     */
    void onWindowRemoved(const QVariant &winId);
    /**
     * @brief 预览图窗口的更新
     * @param winId
     */
    void updateWindow(int row, const QVariant &winId, const QString &groupName);
    /**
     * @brief 悬浮不同的group时更新model中的data信息
     */
    void updateModeData();

private:
    explicit ThumbnailModel(QObject *parent = nullptr);
    // 查找预览图在数组中的索引
    int findThumbnailIndex(const QVariant winId) const;

    ThumbnailModelPrivate *d = nullptr;

Q_SIGNALS:
    void updateWinIdList(QList<QVariant> viewModel);
};

#endif //WINDOW_THUMBNAIL_MODEL_H