1 /* This file is part of the KDE project
2  * Copyright (C) 2012 Paul Mendez <paulestebanms@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 // Heavily based in CollectionItemModel work of Peter Simonsson <peter.simonsson@gmail.com>
21 
22 #ifndef KPRCOLLECTIONITEMMODEL_H
23 #define KPRCOLLECTIONITEMMODEL_H
24 
25 #include <QAbstractItemModel>
26 #include <QVector>
27 #include <QString>
28 #include <QIcon>
29 #include <KoXmlReader.h>
30 
31 /**
32  * Struct containing the information stored in CollectionItemModel item
33  */
34 struct KPrCollectionItem
35 {
36     QString id;                     //animation id
37     QString name;                   //animation name (text to be displayed on animations view)
38     QString toolTip;                // text of animation tool tip
39     QIcon icon;                     // icon of the animation type
40     KoXmlElement animationContext;  //xml data used to instantiate animations of this type
41 };
42 
43 Q_DECLARE_TYPEINFO(KPrCollectionItem, Q_MOVABLE_TYPE);
44 
45 /** Model used to store predefined animations data */
46 class KPrCollectionItemModel : public QAbstractListModel
47 {
48     Q_OBJECT
49 public:
50     explicit KPrCollectionItemModel(QObject *parent = 0);
51 
52     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
53     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
54     Qt::ItemFlags flags(const QModelIndex &index) const override;
55     Qt::DropActions supportedDragActions() const override;
56 
57     /**
58      * @brief Set the list of KoCollectionItem to be stored in the model
59      *
60      * @param newlist List of KPrCollectionItem
61      */
62     void setAnimationClassList(const QVector<KPrCollectionItem> &newlist);
63 
animationClassList()64     QVector<KPrCollectionItem> animationClassList() const {return m_animationClassList;}
65 
66     /**
67      * @brief Return the xml context for the animation on index
68      *
69      * @param index of the animation
70      */
71     KoXmlElement animationContext(const QModelIndex &index) const;
72 
73 private:
74     QVector<KPrCollectionItem> m_animationClassList;
75     QString m_family;
76 };
77 #endif // KPRCOLLECTIONITEMMODEL_H
78