File indexing completed on 2024-05-19 05:05:51

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2019 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_PROGRAM_DOCUMENTLIST_H
0021 #define KBIBTEX_PROGRAM_DOCUMENTLIST_H
0022 
0023 #include <QListView>
0024 #include <QAbstractListModel>
0025 #include <QListWidgetItem>
0026 #include <QStyledItemDelegate>
0027 #include <QTabWidget>
0028 #include <QUrl>
0029 
0030 #include "openfileinfo.h"
0031 
0032 class KFileItem;
0033 
0034 class OpenFileInfoManager;
0035 
0036 class DocumentListDelegate : public QStyledItemDelegate
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit DocumentListDelegate(QObject *parent = nullptr);
0042 
0043     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0044     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0045 
0046 };
0047 
0048 class DocumentListModel : public QAbstractListModel
0049 {
0050     Q_OBJECT
0051 
0052 public:
0053     explicit DocumentListModel(OpenFileInfo::StatusFlag statusFlag, QObject *parent = nullptr);
0054     ~DocumentListModel() override;
0055 
0056     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0057     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0058     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0059 
0060 private:
0061     class DocumentListModelPrivate;
0062     DocumentListModelPrivate *d;
0063 
0064 private Q_SLOTS:
0065     void listsChanged(OpenFileInfo::StatusFlags statusFlags);
0066 };
0067 
0068 class DocumentListView : public QListView
0069 {
0070     Q_OBJECT
0071 
0072 public:
0073     DocumentListView(OpenFileInfo::StatusFlag statusFlag, QWidget *parent);
0074     ~DocumentListView() override;
0075 
0076 private Q_SLOTS:
0077     void addToFavorites();
0078     void removeFromFavorites();
0079     void openFile();
0080     void closeFile();
0081 
0082 protected:
0083     void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
0084 
0085 private:
0086     class DocumentListViewPrivate;
0087     DocumentListViewPrivate *d;
0088 };
0089 
0090 class DocumentList : public QTabWidget
0091 {
0092     Q_OBJECT
0093 
0094 public:
0095     enum class Category { OpenFiles = 0, RecentFiles = 1, Favorites = 2 };
0096 
0097     explicit DocumentList(QWidget *parent = nullptr);
0098     ~DocumentList();
0099 
0100 Q_SIGNALS:
0101     void openFile(const QUrl &url);
0102 
0103 private Q_SLOTS:
0104     void fileSelected(const KFileItem &item);
0105 
0106 private:
0107     class DocumentListPrivate;
0108     DocumentListPrivate *d;
0109 };
0110 
0111 #endif // KBIBTEX_PROGRAM_DOCUMENTLIST_H