1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2013 Mihail Ivchenko <ematirov@gmail.com>
4 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
5 // SPDX-FileCopyrightText: 2014 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
6 //
7 
8 #ifndef TOURITEMDELEGATE_H
9 #define TOURITEMDELEGATE_H
10 
11 #include <QStyledItemDelegate>
12 
13 class QListView;
14 
15 namespace Marble
16 {
17 
18 class MarbleWidget;
19 class GeoDataAnimatedUpdate;
20 class GeoDataPlaylist;
21 class GeoDataFeature;
22 class TourWidget;
23 
24 class TourItemDelegate : public QStyledItemDelegate
25 {
26 Q_OBJECT
27 
28 public:
29     TourItemDelegate( QListView* view, MarbleWidget* widget, TourWidget* tour );
30     void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
31     QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
32     QWidget* createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const override;
33     bool editable() const;
34     void setEditable( bool editable );
35     QModelIndex firstFlyTo() const;
36     bool editAnimatedUpdate(GeoDataAnimatedUpdate *animatedUpdate, bool create = true );
37     QString defaultFeatureId() const;
38     GeoDataFeature *findFeature( const QString &id ) const;
39 
40 public Q_SLOTS:
41     /** Editing duration for first flyTo element in playlist will be disabled.  */
42     void setFirstFlyTo( const QPersistentModelIndex &index );
43     /** Sets id of default feature for Remove Item */
44     void setDefaultFeatureId( const QString &id );
45 
46 Q_SIGNALS:
47     void editingChanged( const QModelIndex& index );
48     void edited( const QModelIndex& index );
49     void editableChanged( bool editable );
50     void firstFlyToChanged( const QPersistentModelIndex &newFirstFlyTo );
51     void featureIdsChanged( const QStringList& ids );
52     void defaultFeatureIdChanged( const QString& id );
53 
54 public:
55 
56     enum Element {
57         GeoDataElementIcon,
58         Label,
59         EditButton,
60         ActionButton
61     };
62 
63 protected:
64     bool editorEvent( QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index ) override;
65 
66 private Q_SLOTS:
67     void closeEditor(const QModelIndex& index);
68 
69 private:
70     static QRect position( Element element, const QStyleOptionViewItem &option );
71     static QStringList findIds(const GeoDataPlaylist &playlist, bool onlyFeatures = false);
72     GeoDataPlaylist *playlist() const;
73     QList<QPersistentModelIndex> m_editingIndices;
74     QListView* m_listView;
75     MarbleWidget *m_widget;
76     bool m_editable;
77     QPersistentModelIndex m_firstFlyTo;
78     QString m_defaultFeatureId;
79     TourWidget* m_tourWidget;
80 };
81 
82 } // namespace Marble
83 
84 #endif
85