File indexing completed on 2024-05-12 16:36:42

0001 /* This file is part of the KDE project
0002 * Copyright (C) 2011 Paul Mendez <paulestebanms@gmail.com>
0003 *
0004 * This library is free software; you can redistribute it and/or
0005 * modify it under the terms of the GNU Library General Public
0006 * License as published by the Free Software Foundation; either
0007 * version 2 of the License, or (at your option) any later version.
0008 *
0009 * This library is distributed in the hope that it will be useful,
0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012 * Library General Public License for more details.
0013 *
0014 * You should have received a copy of the GNU Library General Public License
0015 * along with this library; see the file COPYING.LIB.  If not, write to
0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017 * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KPRCUSTOMSLIDESHOWSMODEL_H
0021 #define KPRCUSTOMSLIDESHOWSMODEL_H
0022 
0023 #include <QAbstractListModel>
0024 #include <QSize>
0025 
0026 class KPrCustomSlideShows;
0027 class KoPAPageBase;
0028 class KPrDocument;
0029 
0030 #include "stage_export.h"
0031 
0032 /**
0033  * Class meant to hold the model for Custom Slide Shows View
0034  * This model lets display slides as thumbnails in a List view, using standard QT
0035  * view/model framework. It supports add, remove and move slides of a custom slide show
0036  * and add, remove or rename slide Shows
0037  */
0038 class STAGE_TEST_EXPORT KPrCustomSlideShowsModel : public QAbstractListModel
0039 {
0040     Q_OBJECT
0041 public:
0042 
0043     //List the actions that you could perform with slides
0044     //within a custom show.
0045     enum CustomShowActions
0046     {
0047         SlidesAdd,       ///< add slides
0048         SlidesDelete,    ///< delete slides
0049         SlidesMove       ///< move slides
0050     };
0051 
0052     explicit KPrCustomSlideShowsModel(KPrDocument *document, QObject *parent = 0);
0053 
0054     ~KPrCustomSlideShowsModel() override;
0055 
0056     QVariant data(const QModelIndex &index, int role) const override;
0057 
0058     int rowCount(const QModelIndex &parent) const override;
0059 
0060     QModelIndex index(int row, int column, const QModelIndex &parent) const override;
0061 
0062     QStringList mimeTypes() const override;
0063 
0064     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0065 
0066     Qt::DropActions supportedDropActions() const override;
0067 
0068     Qt::ItemFlags flags(const QModelIndex &index) const override;
0069 
0070     bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
0071 
0072     /**
0073      * @brief Set the current KPrCustomSlideShows
0074      *
0075      * @param customShows the KPrCustomSlideShows class
0076      */
0077     void setCustomSlideShows(KPrCustomSlideShows *customShows);
0078 
0079     /**
0080      * @brief Returns the active slide show name
0081      *
0082      * @return the active slide show name
0083      */
0084     QString activeCustomSlideShow() const;
0085 
0086     /**
0087      * @brief Set the active custom slide show by name
0088      *
0089      * @param name of the custom slide show
0090      */
0091     void setActiveSlideShow(const QString &name);
0092 
0093     /**
0094      * @brief Set the active custom slide show by index
0095      *
0096      * @param index of the custom slide show within the KPrCustomSlideShows class
0097      */
0098     void setActiveSlideShow(int index);
0099 
0100     /**
0101      * Setter of the size with a rect
0102      *
0103      * @param size which is a QRect
0104      */
0105     void setIconSize(const QSize &size);
0106 
0107     /**
0108      * @brief Returns the current slide show names list
0109      *
0110      * @return the current slide show names list
0111      */
0112     QStringList customShowsNamesList() const;
0113 
0114     /**
0115      * @brief setter of the current document
0116      *
0117      * @param document the document
0118      */
0119     void setDocument(KPrDocument *document);
0120 
0121     /**
0122      * @brief Deletes all the occurrences of a given list of slides indexes from current custom SlideShows
0123      *
0124      * @param slideIndexes list of slide indexes to be removed
0125      */
0126     void removeSlidesByIndexes(const QModelIndexList &slideIndexes);
0127 
0128     /**
0129      * @brief Add a given list of slides to the current custom slide show
0130      *
0131      * @param pages list of slides to be added.
0132      * @param row the insertion will be performed before the given row
0133      */
0134     void addSlides(const QList<KoPAPageBase *> &pages, const int &row);
0135 
0136     /**
0137      * @brief Manage all edit actions on a custom slide show
0138      *
0139      * @param action action to be performed according to CustomShowsAction Enum
0140      * @param slides list of slides to be added or moved
0141      * @param indexes list of indexes of the slides to be deleted
0142      * @param beginRow destination row for copy and move actions
0143      * @return true if the action success
0144      */
0145     bool doCustomSlideShowAction(const CustomShowActions &action, const QList<KoPAPageBase *> &slides, QList<int> indexes, int beginRow = 0);
0146 
0147     /**
0148      * @brief Insert a new Custom SlideShow
0149      *
0150      * @param name The name of the new SlideShow
0151      */
0152     void addNewCustomShow(const QString &name);
0153 
0154     /**
0155      * @brief Replaces a custom SlideShow name with the given SlideShow name
0156      *
0157      * @param oldName The name of the SlideShow to be renamed
0158      * @param newName The new name of the SlideShow
0159      */
0160     void renameCustomShow(const QString &oldName, const QString &newName);
0161 
0162     /**
0163      * @brief Delete a Custom SlideShow by its name
0164      *
0165      * @param name The name of the SlideShow to be removed
0166      */
0167     void removeCustomShow(const QString &name);
0168 
0169     /**
0170      * @brief Change active custom slide show and notify the change
0171      * If name exists change active custom slide show to name otherwise
0172      * switch to the default slide set
0173      *
0174      * @param name of the Custom Slide Show
0175      */
0176     void updateCustomSlideShowsList(const QString &name);
0177 
0178     QStringList namesByPage(KoPAPageBase *page);
0179 
0180 Q_SIGNALS:
0181     /** Notify a change of the active custom slide show */
0182     void customSlideShowsChanged();
0183 
0184     /** Notify a need of page selection after coping or moving pages */
0185     void selectPages(int start, int number);
0186 
0187 private Q_SLOTS:
0188     /** emit signals indicating a change in the model layout or items */
0189     void updateModel();
0190 
0191 private:
0192     QList<KoPAPageBase *> decodeSlidesList(const QByteArray &encoded);
0193 
0194     KPrCustomSlideShows *m_customSlideShows;
0195     QString m_activeCustomSlideShowName;
0196     QSize m_iconSize;
0197     KPrDocument *m_document;
0198 
0199 };
0200 
0201 #endif // KPRCUSTOMSLIDESHOWSMODEL_H