1 /* ============================================================
2 * Falkon - Qt web browser
3 * Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 * ============================================================ */
18 #pragma once
19 
20 #include <QPointer>
21 #include <QMimeData>
22 #include <QAbstractListModel>
23 
24 #include "qzcommon.h"
25 
26 class WebTab;
27 class BrowserWindow;
28 
29 class FALKON_EXPORT TabModelMimeData : public QMimeData
30 {
31     Q_OBJECT
32 
33 public:
34     explicit TabModelMimeData();
35 
36     WebTab *tab() const;
37     void setTab(WebTab *tab);
38 
39     bool hasFormat(const QString &format) const override;
40     QStringList formats() const override;
41 
42     static QString mimeType();
43 
44 private:
45     QPointer<WebTab> m_tab;
46 };
47 
48 class FALKON_EXPORT TabModel : public QAbstractListModel
49 {
50     Q_OBJECT
51 
52 public:
53     enum Roles {
54         WebTabRole = Qt::UserRole + 1,
55         TitleRole = Qt::UserRole + 2,
56         IconRole = Qt::UserRole + 3,
57         PinnedRole = Qt::UserRole + 4,
58         RestoredRole = Qt::UserRole + 5,
59         CurrentTabRole = Qt::UserRole + 6,
60         LoadingRole = Qt::UserRole + 7,
61         AudioPlayingRole = Qt::UserRole + 8,
62         AudioMutedRole = Qt::UserRole + 9,
63         BackgroundActivityRole = Qt::UserRole + 10
64     };
65 
66     explicit TabModel(BrowserWindow *window, QObject *parent = nullptr);
67 
68     QModelIndex tabIndex(WebTab *tab) const;
69     WebTab *tab(const QModelIndex &index) const;
70 
71     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
72     Qt::ItemFlags flags(const QModelIndex &index) const override;
73     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
74 
75     Qt::DropActions supportedDropActions() const override;
76     QStringList mimeTypes() const override;
77     QMimeData *mimeData(const QModelIndexList &indexes) const override;
78     bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
79     bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
80 
81 private:
82     void init();
83     void tabInserted(int index);
84     void tabRemoved(int index);
85     void tabMoved(int from, int to);
86 
87     BrowserWindow *m_window;
88     QVector<WebTab*> m_tabs;
89 };
90