~osomon/ubuntu-ui-extras/revert-changed-tests

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/Extras/plugin/browser/tabs-model.h

  • Committer: Ugo Riboni
  • Date: 2013-06-25 13:51:18 UTC
  • Revision ID: ugo.riboni@canonical.com-20130625135118-scs2wpej1kyg3fc1
Merge changes to Browser.qml related to tabs support, except autopilot tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
6
 * webbrowser-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * webbrowser-app 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
 
 
19
#ifndef __TABS_MODEL_H__
 
20
#define __TABS_MODEL_H__
 
21
 
 
22
// Qt
 
23
#include <QtCore/QAbstractListModel>
 
24
#include <QtCore/QList>
 
25
 
 
26
class QQuickItem;
 
27
 
 
28
class TabsModel : public QAbstractListModel
 
29
{
 
30
    Q_OBJECT
 
31
 
 
32
    Q_ENUMS(Roles)
 
33
 
 
34
    Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
 
35
    Q_PROPERTY(QQuickItem* currentWebview READ currentWebview NOTIFY currentWebviewChanged)
 
36
    Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
 
37
 
 
38
public:
 
39
    TabsModel(QObject* parent=0);
 
40
    ~TabsModel();
 
41
 
 
42
    enum Roles {
 
43
        Url = Qt::UserRole + 1,
 
44
        Title,
 
45
        Icon,
 
46
        Thumbnail,
 
47
        WebView
 
48
    };
 
49
 
 
50
    // reimplemented from QAbstractListModel
 
51
    QHash<int, QByteArray> roleNames() const;
 
52
    int rowCount(const QModelIndex& parent=QModelIndex()) const;
 
53
    QVariant data(const QModelIndex& index, int role) const;
 
54
 
 
55
    int currentIndex() const;
 
56
    void setCurrentIndex(int index);
 
57
 
 
58
    QQuickItem* currentWebview() const;
 
59
 
 
60
    Q_INVOKABLE int add(QQuickItem* webview);
 
61
    Q_INVOKABLE QQuickItem* remove(int index);
 
62
 
 
63
Q_SIGNALS:
 
64
    void currentIndexChanged() const;
 
65
    void currentWebviewChanged() const;
 
66
    void countChanged() const;
 
67
 
 
68
private Q_SLOTS:
 
69
    void onUrlChanged();
 
70
    void onTitleChanged();
 
71
    void onIconChanged();
 
72
 
 
73
private:
 
74
    QList<QQuickItem*> m_webviews;
 
75
    int m_currentIndex;
 
76
 
 
77
    bool checkValidTabIndex(int index) const;
 
78
    void onDataChanged(QQuickItem* webview, int role);
 
79
};
 
80
 
 
81
#endif // __TABS_MODEL_H__