1 #pragma once
2 
3 /*
4  * SPDX-FileCopyrightText: 2009 Craig Drummond <craig@kde.org>
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7 
8 #include <QAbstractItemModel>
9 #include <QTreeView>
10 
11 class QContextMenuEvent;
12 
13 namespace KFI
14 {
15 class CFcEngine;
16 
17 class CPreviewListItem
18 {
19 public:
CPreviewListItem(const QString & name,quint32 style,const QString & file,int index)20     CPreviewListItem(const QString &name, quint32 style, const QString &file, int index)
21         : itsName(name)
22         , itsFile(file)
23         , itsStyle(style)
24         , itsIndex(index)
25     {
26     }
27 
name()28     const QString &name() const
29     {
30         return itsName;
31     }
style()32     quint32 style() const
33     {
34         return itsStyle;
35     }
file()36     const QString &file() const
37     {
38         return itsFile;
39     }
index()40     int index() const
41     {
42         return itsIndex;
43     }
44 
45 private:
46     QString itsName, itsFile;
47     quint32 itsStyle;
48     int itsIndex;
49 };
50 
51 class CPreviewList : public QAbstractItemModel
52 {
53     Q_OBJECT
54 
55 public:
56     CPreviewList(QObject *parent = nullptr);
~CPreviewList()57     ~CPreviewList() override
58     {
59         clear();
60     }
61 
62     QVariant data(const QModelIndex &index, int role) const override;
63     Qt::ItemFlags flags(const QModelIndex &index) const override;
64     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
65     QModelIndex parent(const QModelIndex &index) const override;
66     int rowCount(const QModelIndex &parent = QModelIndex()) const override
67     {
68         Q_UNUSED(parent)
69         return itsItems.count();
70     }
71     int columnCount(const QModelIndex &parent = QModelIndex()) const override
72     {
73         Q_UNUSED(parent)
74         return 1;
75     }
76     void clear();
77     void showFonts(const QModelIndexList &font);
78 
79 private:
80     QList<CPreviewListItem *> itsItems;
81 };
82 
83 class CPreviewListView : public QTreeView
84 {
85     Q_OBJECT
86 
87 public:
88     CPreviewListView(CFcEngine *eng, QWidget *parent);
~CPreviewListView()89     ~CPreviewListView() override
90     {
91     }
92 
93     void refreshPreviews();
94     void showFonts(const QModelIndexList &fonts);
95     void contextMenuEvent(QContextMenuEvent *ev) override;
96 
97 Q_SIGNALS:
98 
99     void showMenu(const QPoint &pos);
100 
101 private:
102     CPreviewList *itsModel;
103 };
104 
105 }
106