File indexing completed on 2024-05-12 16:36:48
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 2011 Paul Mendez <paulestebanms@gmail.com> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KPRSLIDESMANAGERVIEW_H 0022 #define KPRSLIDESMANAGERVIEW_H 0023 0024 #include <QListView> 0025 0026 /** 0027 * Class meant to hold a List View of slides thumbnails 0028 * This view lets display slides as thumbnails in a List view, using standard QT 0029 * view/model framework. It paint a line between thumbnails when dragging and 0030 * creates a pixmap the contains all icons of the items that are dragged. 0031 */ 0032 class KPrSlidesManagerView : public QListView 0033 { 0034 Q_OBJECT 0035 public: 0036 explicit KPrSlidesManagerView(QWidget *parent = 0); 0037 0038 ~KPrSlidesManagerView() override; 0039 0040 void paintEvent (QPaintEvent *event) override; 0041 0042 //It emits a slideDblClick signal and then calls the parent 0043 //implementation 0044 void mouseDoubleClickEvent(QMouseEvent *event) override; 0045 0046 void contextMenuEvent(QContextMenuEvent *event) override; 0047 0048 void startDrag (Qt::DropActions supportedActions) override; 0049 0050 void dropEvent(QDropEvent *ev) override; 0051 0052 void dragMoveEvent(QDragMoveEvent *ev) override; 0053 0054 void dragEnterEvent(QDragEnterEvent *event) override; 0055 0056 void dragLeaveEvent(QDragLeaveEvent *e) override; 0057 0058 //Reimplemented to provide suitable signals for selection and deselection of items 0059 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; 0060 0061 //Manage click events outside of items, to provide 0062 //a suitable active item for the context menu. 0063 bool eventFilter(QObject *watched, QEvent *event) override; 0064 0065 void focusOutEvent(QFocusEvent *event) override; 0066 0067 void focusInEvent(QFocusEvent *event) override; 0068 0069 /** 0070 * Creates a pixmap the contains the all icons of the items 0071 * that are dragged. 0072 */ 0073 QPixmap createDragPixmap() const; 0074 0075 /** 0076 * Calculates the index of the nearest item to the cursor position 0077 */ 0078 int cursorSlideIndex() const; 0079 0080 /** 0081 * Calculates row and column of the nearest item to the cursor position 0082 * return a QPair with 0, 0 for the first item. 0083 */ 0084 QPair<int, int> cursorRowAndColumn() const; 0085 0086 protected: 0087 void wheelEvent(QWheelEvent *event) override; 0088 0089 Q_SIGNALS: 0090 0091 /** Is emitted if the user has request a context menu */ 0092 void requestContextMenu(QContextMenuEvent *event); 0093 0094 /** Is emitted if the user has double click an item */ 0095 void slideDblClick(); 0096 0097 //lets update the active page when changing the current index 0098 //without a item selected event. 0099 /** Is emitted if the selection has been changed within a procedure code */ 0100 void indexChanged(QModelIndex index); 0101 0102 /** Is emitted when all items are deselected */ 0103 void selectionCleared(); 0104 0105 /** Is emitted when an item is selected */ 0106 void itemSelected(); 0107 0108 /** Is emitted when the view loses focus */ 0109 void focusLost(); 0110 0111 /** Is emitted when the view get focus */ 0112 void focusGot(); 0113 0114 /** Is emitted when Ctrl + Scrollwheel is used for zooming */ 0115 void zoomIn(); 0116 0117 /** Is emitted when Ctrl + Scrollwheel is used for zooming */ 0118 void zoomOut(); 0119 0120 private: 0121 /** 0122 * The rect of an items, essentially used to have the size of the full icon 0123 * 0124 * @return the rect of the item 0125 */ 0126 QRect itemSize() const; 0127 0128 /** 0129 * Setter for the dragging flag 0130 * 0131 * @param flag boolean 0132 */ 0133 void setDraggingFlag(bool flag = true); 0134 0135 /** 0136 * Permit to know if a slide is dragging 0137 * 0138 * @return boolean 0139 */ 0140 bool isDragging() const; 0141 0142 QRect m_itemSize; 0143 bool m_draggingFlag; 0144 int margin; 0145 0146 }; 0147 0148 #endif // KPRSLIDESMANAGERVIEW_H