File indexing completed on 2024-11-24 04:34:17

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2017 Thomas Fischer <fischer@unix-ag.uni-kl.de>
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
0018  ***************************************************************************/
0019 
0020 #ifndef KBIBTEX_GUI_FINDPDFUI_P_H
0021 #define KBIBTEX_GUI_FINDPDFUI_P_H
0022 
0023 #include <KWidgetItemDelegate>
0024 
0025 #include <FindPDF>
0026 
0027 class QListView;
0028 
0029 /**
0030  * @author Thomas Fischer <fischer@unix-ag.uni-kl.de>
0031  */
0032 class PDFItemDelegate : public KWidgetItemDelegate
0033 {
0034     Q_OBJECT
0035 
0036 private:
0037     QListView *m_parent;
0038 
0039 public:
0040     PDFItemDelegate(QListView *itemView, QObject *parent);
0041 
0042     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0043 
0044 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0045     void updateItemWidgets(const QList<QWidget *> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const override;
0046 #else
0047     void updateItemWidgets(const QList<QWidget *> &widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const override;
0048 #endif
0049 
0050     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const override;
0051 
0052 protected:
0053     /// get the list of widgets
0054     QList<QWidget *> createItemWidgets(const QModelIndex &index) const override;
0055 
0056 private Q_SLOTS:
0057     void slotViewPDF();
0058     void slotRadioNoDownloadToggled(bool);
0059     void slotRadioDownloadToggled(bool);
0060     void slotRadioURLonlyToggled(bool);
0061 };
0062 
0063 
0064 /**
0065  * @author Thomas Fischer <fischer@unix-ag.uni-kl.de>
0066  */
0067 class PDFListModel : public QAbstractListModel
0068 {
0069     Q_OBJECT
0070 
0071 public:
0072     explicit PDFListModel(QList<FindPDF::ResultItem> &resultList, QObject *parent = nullptr);
0073 
0074     enum PDFListModelRole {
0075         /// URL of a PDF file
0076         URLRole = Qt::UserRole + 1234,
0077         /// A textual representation, e.g. text extracted from the PDF file
0078         TextualPreviewRole = Qt::UserRole + 1237,
0079         /// Local, temporal copy of a remote PDF file
0080         TempFileNameRole = Qt::UserRole + 1236,
0081         /// Returns a FindPDF::DownloadMode, may be either
0082         /// 'NoDownload', 'Download', or 'URLonly'
0083         DownloadModeRole = Qt::UserRole + 1235
0084     };
0085 
0086     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0087     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0088     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0089     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0090 
0091 private:
0092     QList<FindPDF::ResultItem> &m_resultList;
0093 };
0094 
0095 
0096 #endif // KBIBTEX_GUI_FINDPDFUI_P_H