File indexing completed on 2025-01-26 05:08:10

0001 #pragma once
0002 
0003 /*
0004  * SPDX-FileCopyrightText: 2009 Craig Drummond <craig@kde.org>
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include <QAbstractItemModel>
0009 #include <QTreeView>
0010 
0011 class QContextMenuEvent;
0012 
0013 namespace KFI
0014 {
0015 class CFcEngine;
0016 
0017 class CPreviewListItem
0018 {
0019 public:
0020     CPreviewListItem(const QString &name, quint32 style, const QString &file, int index)
0021         : m_name(name)
0022         , m_file(file)
0023         , m_style(style)
0024         , m_index(index)
0025     {
0026     }
0027 
0028     const QString &name() const
0029     {
0030         return m_name;
0031     }
0032     quint32 style() const
0033     {
0034         return m_style;
0035     }
0036     const QString &file() const
0037     {
0038         return m_file;
0039     }
0040     int index() const
0041     {
0042         return m_index;
0043     }
0044 
0045 private:
0046     QString m_name, m_file;
0047     quint32 m_style;
0048     int m_index;
0049 };
0050 
0051 class CPreviewList : public QAbstractItemModel
0052 {
0053     Q_OBJECT
0054 
0055 public:
0056     CPreviewList(QObject *parent = nullptr);
0057     ~CPreviewList() override
0058     {
0059         clear();
0060     }
0061 
0062     QVariant data(const QModelIndex &index, int role) const override;
0063     Qt::ItemFlags flags(const QModelIndex &index) const override;
0064     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0065     QModelIndex parent(const QModelIndex &index) const override;
0066     int rowCount(const QModelIndex &parent = QModelIndex()) const override
0067     {
0068         Q_UNUSED(parent)
0069         return m_items.count();
0070     }
0071     int columnCount(const QModelIndex &parent = QModelIndex()) const override
0072     {
0073         Q_UNUSED(parent)
0074         return 1;
0075     }
0076     void clear();
0077     void showFonts(const QModelIndexList &font);
0078 
0079 private:
0080     QList<CPreviewListItem *> m_items;
0081 };
0082 
0083 class CPreviewListView : public QTreeView
0084 {
0085     Q_OBJECT
0086 
0087 public:
0088     CPreviewListView(CFcEngine *eng, QWidget *parent);
0089     ~CPreviewListView() override
0090     {
0091     }
0092 
0093     void refreshPreviews();
0094     void showFonts(const QModelIndexList &fonts);
0095     void contextMenuEvent(QContextMenuEvent *ev) override;
0096 
0097 Q_SIGNALS:
0098 
0099     void showMenu(const QPoint &pos);
0100 
0101 private:
0102     CPreviewList *m_model;
0103 };
0104 
0105 }