1 /* This file is part of the KDE project
2  * Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net>
3  * Copyright (C) 2009 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifndef KOPADOCUMENTSTRUCTUREDOCKER_H
21 #define KOPADOCUMENTSTRUCTUREDOCKER_H
22 
23 #include <QDockWidget>
24 #include <QHash>
25 #include <KoDockFactoryBase.h>
26 #include <KoCanvasObserverBase.h>
27 #include <KoDocumentSectionView.h>
28 #include <KoPageApp.h>
29 
30 class KoShape;
31 class KoShapeLayer;
32 class KoPADocument;
33 class KoPADocumentModel;
34 class KoPAPageBase;
35 class KoViewItemContextBar;
36 class QAction;
37 class QButtonGroup;
38 
39 class KoPADocumentStructureDockerFactory : public KoDockFactoryBase
40 {
41 public:
42     explicit KoPADocumentStructureDockerFactory(KoDocumentSectionView::DisplayMode mode, KoPageApp::PageType pageType = KoPageApp::Page);
43 
44     QString id() const override;
45     QDockWidget* createDockWidget() override;
46 
defaultDockPosition()47     DockPosition defaultDockPosition() const override
48     {
49         return DockRight;
50     }
51 
52 private:
53     KoDocumentSectionView::DisplayMode m_mode;
54     KoPageApp::PageType m_pageType;
55 };
56 
57 class KoPADocumentStructureDocker : public QDockWidget, public KoCanvasObserverBase
58 {
59 Q_OBJECT
60 
61 public:
62     explicit KoPADocumentStructureDocker(KoDocumentSectionView::DisplayMode mode, KoPageApp::PageType pageType, QWidget* parent = 0);
63     ~KoPADocumentStructureDocker() override;
64 
65     void setCanvas(KoCanvasBase* canvas) override;
66     void unsetCanvas() override;
67     void setActivePage(KoPAPageBase *page);
68     void setMasterMode(bool master);
69 
70 protected:
71     /// This is the context menu for the slide show in the KoPADocumentStructure docker
72     void contextMenuEvent(QContextMenuEvent* event) override;
73 
74 Q_SIGNALS:
75     void pageChanged(KoPAPageBase *page);
76 
77     /// This signal will be emitted after the model for this docker has been reset
78     void dockerReset();
79 
80 public Q_SLOTS:
81     void updateView();
82 
83     void selectPages(int start, int count);
84 
85 private Q_SLOTS:
86     void slotButtonClicked(int buttonId);
87     void addLayer();
88     void addPage();
89     void deleteItem();
90     void raiseItem();
91     void lowerItem();
92     void itemClicked(const QModelIndex &index);
93     void minimalView();
94     void detailedView();
95     void thumbnailView();
96 
97     void itemSelected(const QItemSelection& selected, const QItemSelection& deselected);
98     void editCut();
99     void editCopy();
100     void editPaste();
101 
102 private:
103     void extractSelectedLayersAndShapes(QList<KoPAPageBase*> &pages, QList<KoShapeLayer*> &layers, QList<KoShape*> &shapes);
104     void setViewMode(KoDocumentSectionView::DisplayMode mode);
105     QModelIndex getRootIndex(const QModelIndex &index) const;
106 
107     KoDocumentSectionView::DisplayMode viewModeFromString(const QString& mode);
108     QString viewModeToString(KoDocumentSectionView::DisplayMode mode);
109 
110     KoPADocument * m_doc;
111     KoDocumentSectionView *m_sectionView;
112     KoPADocumentModel *m_model;
113     QHash<KoDocumentSectionView::DisplayMode, QAction*> m_viewModeActions;
114     QList<KoShape *> m_selectedShapes;
115     QButtonGroup *m_buttonGroup;
116     QAction* m_addLayerAction;
117     KoViewItemContextBar *m_itemsContextBar;
118 };
119 
120 #endif // KOPADOCUMENTSTRUCTUREDOCKER_H
121