Warning, file /office/calligra/libs/main/KoDocumentSectionView.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002   Copyright (c) 2006 Gábor Lehel <illissius@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 KO_DOCUMENT_SECTION_VIEW_H
0021 #define KO_DOCUMENT_SECTION_VIEW_H
0022 
0023 #include <QTreeView>
0024 #include "komain_export.h"
0025 
0026 class QStyleOptionViewItem;
0027 class KoDocumentSectionModel;
0028 
0029 /**
0030  * A View widget on document sections (for example, layers, pages,
0031  * sheets...). The widget can show the document sections as big
0032  * thumbnails, in a listview with two rows of informative text and
0033  * icons per document section or as single rows of text and property
0034  * icons.
0035  *
0036  * The KoDocumentSectionView is designed as a Qt4 model-view widget.
0037  * See the relevant (extensive) Qt documentation about the design
0038  * basis for this widget.
0039  *
0040  * Usage: simply use this widget in your designer .ui file. Karbon's
0041  * layerboxes are KoDocumentSectionView based.
0042  */
0043 class KOMAIN_EXPORT KoDocumentSectionView: public QTreeView
0044 {
0045     Q_OBJECT
0046 Q_SIGNALS:
0047     /**
0048      * Emitted whenever the user clicks with the secondary mouse
0049      * button on an item. It is up to the application to design the
0050      * contents of the context menu and show it.
0051      */
0052     void contextMenuRequested(const QPoint &globalPos, const QModelIndex &index);
0053     void selectionChanged(const QModelIndexList &);
0054 public:
0055 
0056     /**
0057      * Create a new KoDocumentSectionView.
0058      */
0059     explicit KoDocumentSectionView(QWidget *parent = 0);
0060     ~KoDocumentSectionView() override;
0061 
0062     /// how items should be displayed
0063     enum DisplayMode {
0064         /// large fit-to-width thumbnails, with only titles or page numbers
0065         ThumbnailMode,
0066 
0067         /// smaller thumbnails, with titles and property icons in two rows
0068         DetailedMode,
0069 
0070         /// no thumbnails, with titles and property icons in a single row
0071         MinimalMode
0072     };
0073 
0074     void paintEvent (QPaintEvent *event) override;
0075 
0076     void dropEvent(QDropEvent *ev) override;
0077 
0078     void dragEnterEvent(QDragEnterEvent *e) override;
0079 
0080     void dragMoveEvent(QDragMoveEvent *ev) override;
0081 
0082     void dragLeaveEvent(QDragLeaveEvent *e) override;
0083 
0084     /**
0085      * Set the display mode of the view to one of the options.
0086      *
0087      * @param mode The KoDocumentSectionView::DisplayMode mode
0088      */
0089     void setDisplayMode(DisplayMode mode);
0090 
0091     /**
0092      * @return the currently active display mode
0093      */
0094     DisplayMode displayMode() const;
0095 
0096     /**
0097      * Add toggle actions for all the properties associated with the
0098      * current document section associated with the model index to the
0099      * specified menu.
0100      *
0101      * For instance, if a document section can be locked and visible,
0102      * the menu will be expanded with locked and visible toggle
0103      * actions.
0104      *
0105      * For instance
0106      @code
0107      KoDocumentSectionView * sectionView;
0108      QModelIndex index = getCurrentDocumentSection();
0109      QMenu menu;
0110      if (index.isValid()) {
0111          sectionView->addPropertyActions(&menu, index);
0112      } else {
0113          menu.addAction(...); // Something to create a new document section, for example.
0114      }
0115 
0116      @endcode
0117      *
0118      * @param menu A pointer to the menu that will be expanded with
0119      * the toggle actions
0120      * @param index The model index associated with the document
0121      * section that may or may not provide a number of toggle actions.
0122      */
0123     void addPropertyActions(QMenu *menu, const QModelIndex &index);
0124 
0125 
0126 protected:
0127     bool viewportEvent(QEvent *event) override;
0128     void contextMenuEvent(QContextMenuEvent *event) override;
0129     virtual void showContextMenu(const QPoint &globalPos, const QModelIndex &index);
0130     void startDrag (Qt::DropActions supportedActions) override;
0131     QPixmap createDragPixmap() const;
0132 
0133     /**
0134      * Calculates the index of the nearest item to the cursor position
0135      */
0136     int cursorPageIndex() const;
0137 
0138 protected Q_SLOTS:
0139     void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
0140     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
0141     void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
0142 
0143 private Q_SLOTS:
0144     void slotActionToggled(bool on, const QPersistentModelIndex &index, int property);
0145 
0146 private:
0147 
0148     /**
0149      * Permit to know if a slide is dragging
0150      *
0151      * @return boolean
0152      */
0153     bool isDragging() const;
0154 
0155     /**
0156      * Setter for the dragging flag
0157      *
0158      * @param flag boolean
0159      */
0160     void setDraggingFlag(bool flag = true);
0161 
0162     bool m_draggingFlag;
0163 
0164     QStyleOptionViewItem optionForIndex(const QModelIndex &index) const;
0165     typedef KoDocumentSectionModel Model;
0166     class PropertyAction;
0167     class Private;
0168     Private* const d;
0169 };
0170 
0171 #endif