File indexing completed on 2024-06-09 04:03:35

0001 /*
0002  *  Portions Copyright (C) 2009 by Davide Bettio <davide.bettio@kdemail.net>
0003  *  Copyright (C) 2010 Parker Coates <coates@kde.org>
0004  *
0005  *  This program is free software; you can redistribute it and/or
0006  *  modify it under the terms of the GNU General Public License as
0007  *  published by the Free Software Foundation; either version 2 of
0008  *  the License, or (at your option) any later version.
0009  *
0010  *  This program is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  *  GNU General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU General Public License
0016  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  *
0018  */
0019 
0020 #ifndef KCARDTHEMEWIDGET_P_H
0021 #define KCARDTHEMEWIDGET_P_H
0022 
0023 #include "kcardthemewidget.h"
0024 // own
0025 #include "kcardtheme.h"
0026 // KF
0027 #include <KImageCache>
0028 // Qt
0029 #include <QAbstractItemDelegate>
0030 #include <QMutex>
0031 #include <QSet>
0032 #include <QThread>
0033 
0034 class KLineEdit;
0035 class QPushButton;
0036 class QListView;
0037 
0038 namespace KNSWidgets
0039 {
0040 class Button;
0041 }
0042 
0043 class PreviewThread : public QThread
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     PreviewThread(const KCardThemeWidgetPrivate *d, const QList<KCardTheme> &themes);
0049     void run() override;
0050     void halt();
0051 
0052 Q_SIGNALS:
0053     void previewRendered(const KCardTheme &theme, const QImage &image);
0054 
0055 private:
0056     const KCardThemeWidgetPrivate *const d;
0057     const QList<KCardTheme> m_themes;
0058     bool m_haltFlag;
0059     QMutex m_haltMutex;
0060 };
0061 
0062 class CardThemeModel : public QAbstractListModel
0063 {
0064     Q_OBJECT
0065 
0066 public:
0067     explicit CardThemeModel(KCardThemeWidgetPrivate *d, QObject *parent = nullptr);
0068     virtual ~CardThemeModel();
0069 
0070     void reload();
0071     QModelIndex indexOf(const QString &dirName) const;
0072 
0073     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0074     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0075 
0076 private Q_SLOTS:
0077     void deleteThread();
0078     void submitPreview(const KCardTheme &theme, const QImage &image);
0079 
0080 private:
0081     const KCardThemeWidgetPrivate *const d;
0082     QMap<QString, KCardTheme> m_themes;
0083     QMap<QString, QPixmap *> m_previews;
0084     PreviewThread *m_thread;
0085 };
0086 
0087 class CardThemeDelegate : public QAbstractItemDelegate
0088 {
0089 public:
0090     explicit CardThemeDelegate(KCardThemeWidgetPrivate *d, QObject *parent = nullptr);
0091 
0092     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0093     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0094 
0095 private:
0096     const KCardThemeWidgetPrivate *const d;
0097 };
0098 
0099 class KCardThemeWidgetPrivate : public QObject
0100 {
0101     Q_OBJECT
0102 
0103 public:
0104     explicit KCardThemeWidgetPrivate(KCardThemeWidget *parent);
0105 
0106 public Q_SLOTS:
0107     void updateLineEdit(const QModelIndex &index);
0108     void updateListView(const QString &dirName);
0109 
0110 public:
0111     KCardThemeWidget *q;
0112 
0113     KImageCache *cache;
0114 
0115     CardThemeModel *model;
0116     QListView *listView;
0117     KLineEdit *hiddenLineEdit;
0118     KNSWidgets::Button *newDeckButton;
0119 
0120     int itemMargin;
0121     int textHeight;
0122     qreal abstractPreviewWidth;
0123     QSize baseCardSize;
0124     QSize previewSize;
0125     QSize itemSize;
0126     QString previewString;
0127     QList<QList<QString>> previewLayout;
0128     QSet<QString> requiredFeatures;
0129 };
0130 
0131 #endif