1/* This file is part of the KDE project
2 Copyright (C) 2007 - 2010 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17* Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KPTVIEWLIST_H
21#define KPTVIEWLIST_H
22
23#include "kplato_export.h"
24
25#include "kptschedulemodel.h"
26
27#include <QTreeWidget>
28
29class QDomElement;
30
31class KoDocument;
32class KoView;
33
34class QComboBox;
35
36namespace KPlato
37{
38
39class View;
40class ViewBase;
41class ViewListItem;
42class ViewListWidget;
43
44class MainDocument;
45class Context;
46class ScheduleManager;
47
48#define TIP_USE_DEFAULT_TEXT "TIP_USE_DEFAULT_TEXT"
49
50//--------------
51struct ViewInfo
52{
53 QString name;
54 QString tip;
55};
56
57//--------------
58class KPLATO_EXPORT ViewListItem : public QTreeWidgetItem
59{
60 public:
61 enum ItemType { ItemType_Category = Type, ItemType_SubView = UserType };
62
63 enum DataRole { DataRole_View = Qt::UserRole, DataRole_Document };
64
65 ViewListItem( const QString &tag, const QStringList &strings, int type = ItemType_Category );
66 ViewListItem( QTreeWidget *parent, const QString &tag, const QStringList &strings, int type = ItemType_Category );
67 ViewListItem( QTreeWidgetItem *parent, const QString &tag, const QStringList &strings, int type = ItemType_Category );
68
69 void setView( ViewBase *view );
70 ViewBase *view() const;
71 void setDocument( KoDocument *doc );
72 KoDocument *document() const;
73
74 void setViewInfo( const ViewInfo &vi ) { m_viewinfo = vi; }
75 QString viewType() const;
76 QString tag() const { return m_tag; }
77 void save( QDomElement &element ) const;
78
79 void setReadWrite( bool rw );
80
81 private:
82 QString m_tag;
83 ViewInfo m_viewinfo;
84};
85
86class KPLATO_EXPORT ViewListTreeWidget : public QTreeWidget
87{
88 Q_OBJECT
89public:
90 explicit ViewListTreeWidget( QWidget *parent );
91 ViewListItem *findCategory( const QString &cat );
92
93 /// Return the category of @p view
94 ViewListItem *category( const KoView *view ) const;
95
96 void save( QDomElement &element ) const;
97
98protected:
99 void drawRow( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
100 virtual void mousePressEvent ( QMouseEvent *event );
101 /// Setup drop enabled/disabled dependent on the selected item
102 virtual void startDrag( Qt::DropActions supportedActions );
103 /// If modified by the drop, emit modified
104 void dropEvent( QDropEvent *event );
105
106signals:
107 void activated( QTreeWidgetItem* );
108 void updateViewInfo( ViewListItem *itm );
109 void modified();
110
111private slots:
112 void handleMousePress( QTreeWidgetItem *item );
113};
114
115class KPLATO_EXPORT ViewListWidget : public QWidget
116{
117Q_OBJECT
118public:
119 ViewListWidget( MainDocument *part, QWidget *parent );//QString name, KXmlGuiWindow *parent );
120 ~ViewListWidget();
121
122 /// Set read/write permission on all views.
123 void setReadWrite( bool rw );
124 /// Add a category if it does not already exist
125 ViewListItem *addCategory( const QString &tag, const QString& name );
126 /// Return a list of all categories
127 QList<ViewListItem*> categories() const;
128
129 /// Return the category with @p tag
130 ViewListItem *findCategory( const QString &tag ) const;
131 /// Return the category of @p view
132 ViewListItem *category( const KoView *view ) const;
133
134 /// Create a unique tag
135 QString uniqueTag( const QString &seed ) const;
136 /// Add a sub-view
137 ViewListItem *addView(QTreeWidgetItem *category, const QString &tag, const QString &name, ViewBase *view, KoDocument *doc, const QString &iconName = QString(), int index = -1 );
138
139 void setSelected( QTreeWidgetItem *item );
140 ViewListItem *currentItem() const;
141 void setCurrentItem( QTreeWidgetItem *item );
142 ViewListItem *currentCategory() const;
143 KoView *findView( const QString &tag ) const;
144 ViewListItem *findItem( const QString &tag ) const;
145 ViewListItem *findItem( const QString &tag, QTreeWidgetItem* parent ) const;
146 ViewListItem *findItem( const ViewBase *view, QTreeWidgetItem* parent = 0 ) const;
147
148 /// Remove @p item, don't emit signal
149 int removeViewListItem( ViewListItem *item );
150 /// Add @p item to @p parent at @p index, don't emit signal
151 void addViewListItem( ViewListItem *item, QTreeWidgetItem *parent, int index );
152
153 /// Remove @p item, emit signal
154 int takeViewListItem( ViewListItem *item );
155 /// Add @p item to @p parent at @ index, emit signal
156 void insertViewListItem( ViewListItem *item, QTreeWidgetItem *parent, int index );
157
158 void save( QDomElement &element ) const;
159
160 ViewListItem *previousViewItem() const { return m_prev; }
161
162 ScheduleManager *selectedSchedule() const;
163
164signals:
165 void activated( ViewListItem*, ViewListItem* );
166 void createView();
167 void viewListItemRemoved( ViewListItem *item );
168 void viewListItemInserted( ViewListItem *item, ViewListItem *parent, int index );
169
170 void selectionChanged( ScheduleManager* );
171
172 void updateViewInfo( ViewListItem *itm );
173
174 void modified();
175
176public slots:
177 void setProject( Project *project );
178 void setSelectedSchedule( ScheduleManager *sm );
179 void setModified();
180
181protected slots:
182 void slotActivated( QTreeWidgetItem *item, QTreeWidgetItem *prev );
183 void slotItemChanged( QTreeWidgetItem *item, int col );
184 void renameCategory();
185 void slotAddView();
186 void slotRemoveCategory();
187 void slotRemoveView();
188 void slotEditViewTitle();
189 void slotEditDocumentTitle();
190 void slotConfigureItem();
191
192 void slotCurrentScheduleChanged( int );
193 void slotScheduleManagerAdded( ScheduleManager* );
194
195 void slotDialogFinished( int result );
196
197protected:
198 virtual void contextMenuEvent ( QContextMenuEvent *event );
199
200private:
201 void setupContextMenus();
202
203private:
204 MainDocument *m_part;
205 ViewListTreeWidget *m_viewlist;
206 QComboBox *m_currentSchedule;
207 ScheduleSortFilterModel m_sfModel;
208 ScheduleItemModel m_model;
209
210 ViewListItem *m_contextitem;
211 QList<QAction*> m_categoryactions;
212 QList<QAction*> m_viewactions;
213 QList<QAction*> m_listactions;
214
215 ViewListItem *m_prev;
216
217 ScheduleManager *m_temp;
218};
219
220} //Kplato namespace
221
222#endif
223