File indexing completed on 2024-04-21 07:36:35

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2013 Mihail Ivchenko <ematirov@gmail.com>
0004 // SPDX-FileCopyrightText: 2014 Sanjiban Bairagya <sanjiban22393@gmail.com>
0005 // SPDX-FileCopyrightText: 2014 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0006 //
0007 
0008 #ifndef TOURITEMDELEGATE_H
0009 #define TOURITEMDELEGATE_H
0010 
0011 #include <QStyledItemDelegate>
0012 
0013 class QListView;
0014 
0015 namespace Marble
0016 {
0017 
0018 class MarbleWidget;
0019 class GeoDataAnimatedUpdate;
0020 class GeoDataPlaylist;
0021 class GeoDataFeature;
0022 class TourWidget;
0023 
0024 class TourItemDelegate : public QStyledItemDelegate
0025 {
0026 Q_OBJECT
0027 
0028 public:
0029     TourItemDelegate( QListView* view, MarbleWidget* widget, TourWidget* tour );
0030     void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
0031     QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
0032     QWidget* createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const override;
0033     bool editable() const;
0034     void setEditable( bool editable );
0035     QModelIndex firstFlyTo() const;
0036     bool editAnimatedUpdate(GeoDataAnimatedUpdate *animatedUpdate, bool create = true );
0037     QString defaultFeatureId() const;
0038     GeoDataFeature *findFeature( const QString &id ) const;
0039 
0040 public Q_SLOTS:
0041     /** Editing duration for first flyTo element in playlist will be disabled.  */
0042     void setFirstFlyTo( const QPersistentModelIndex &index );
0043     /** Sets id of default feature for Remove Item */
0044     void setDefaultFeatureId( const QString &id );
0045 
0046 Q_SIGNALS:
0047     void editingChanged( const QModelIndex& index );
0048     void edited( const QModelIndex& index );
0049     void editableChanged( bool editable );
0050     void firstFlyToChanged( const QPersistentModelIndex &newFirstFlyTo );
0051     void featureIdsChanged( const QStringList& ids );
0052     void defaultFeatureIdChanged( const QString& id );
0053 
0054 public:
0055 
0056     enum Element {
0057         GeoDataElementIcon,
0058         Label,
0059         EditButton,
0060         ActionButton
0061     };
0062 
0063 protected:
0064     bool editorEvent( QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index ) override;
0065 
0066 private Q_SLOTS:
0067     void closeEditor(const QModelIndex& index);
0068 
0069 private:
0070     static QRect position( Element element, const QStyleOptionViewItem &option );
0071     static QStringList findIds(const GeoDataPlaylist &playlist, bool onlyFeatures = false);
0072     GeoDataPlaylist *playlist() const;
0073     QList<QPersistentModelIndex> m_editingIndices;
0074     QListView* m_listView;
0075     MarbleWidget *m_widget;
0076     bool m_editable;
0077     QPersistentModelIndex m_firstFlyTo;
0078     QString m_defaultFeatureId;
0079     TourWidget* m_tourWidget;
0080 };
0081 
0082 } // namespace Marble
0083 
0084 #endif