summaryrefslogtreecommitdiff
path: root/src/frontend/mainindex/bookshelf/cbookshelfindex.h
blob: bd210698a297b253a0311ea199cc617a0eaf09be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#ifndef CBOOKSHELFINDEX_H
#define CBOOKSHELFINDEX_H

//BibleTime includes
#include "btindexitem.h"
#include "backend/btmoduletreeitem.h"
class CSwordModuleInfo;
#include "frontend/displaywindow/cdisplaywindow.h"

#include "util/cpointers.h"

//Qt includes
#include <QTimer>
#include <QList>
#include <QTreeWidget>
#include <QTreeWidgetItem>



class CSearchDialog;
class QWidget;
class QDropEvent;
class QDragMoveEvent;
class QDragLeaveEvent;
class BTMimeData;
class QMenu;
class QActionGroup;
class QMouseEvent;
class BTModuleTreeItem;



/**
* The widget which manages the modules. The modules are put into own,
* fixed subfolders sorted by category and/or language.
* @author The BibleTime team
*/
class CBookshelfIndex : public QTreeWidget {
	Q_OBJECT

public:
	CBookshelfIndex(QWidget *parent);
	virtual ~CBookshelfIndex();
	
	void initTree();
	/**
	* Opens the searchdialog using the given modules using the given search text.
	*/
	void emitModulesChosen( QList<CSwordModuleInfo*> modules, QString key );

	/** Helper method for "freezing" modules while opening them in windows. */
	void unfreezeModules(QList<CSwordModuleInfo*>);

public slots:

	/**
	* Reloads the main index's Sword dependend things like modules
	*/
	void reloadSword(CSwordBackend::SetupChangedReason);

	/**
	 * Opens the searchdialog for the selected modules.
	 */
	void actionSearchInModules();

protected:

	/** Handle mouse clicks.*/
	virtual void mouseReleaseEvent(QMouseEvent* event);

	/** Empty re-implementation to prevent unwanted opening of folders with some styles.*/
	virtual void mouseDoubleClickEvent(QMouseEvent*) {}

	/**
	* Initialize the SIGNAL<->SLOT connections
	*/
	void initConnections();
	/**
	* Reimplementation. Returns the drag object for the current selection.
	*/
	virtual QMimeData* dragObject();
	/**
	* Reimplementation from QTreeWidget (QAbstractItemView). Returns true if the drag is acceptable for the listview.
	*/
	virtual void dragEnterEvent( QDragEnterEvent* event );
	virtual void dragMoveEvent( QDragMoveEvent* event );
	virtual void dropEvent( QDropEvent* event );

	/** Receive style change event to change single/double click activation behaviour. */
	virtual void changeEvent(QEvent*);
	
	/**
	* Reimplementation from QAbstractItemView. Takes care of movable items.
	*/
	virtual void startDrag(Qt::DropActions supportedActions);
	/**
	* TODO: qt4 Reimplementation to support the items dragEnter and dragLeave functions.
	*/
	virtual void contentsDragMoveEvent( QDragMoveEvent* event );
	/**
	 * Reimplementation.
	 */
	virtual void contentsDragLeaveEvent( QDragLeaveEvent* e );
	

protected slots: // Protected slots
	/**
	* Called when the selection is changed.
	*/
	void slotModifySelection();
	/**
	* Is called when an item was clicked or activated.
	*/
	void slotExecuted( QTreeWidgetItem* );
	
	/**
	* Shows the context menu at the given position.
	*/
	void contextMenu(const QPoint&);

	/**
	* Changes the grouping.
	*/
	void actionChangeGrouping(QAction* action);

	/**
	* Shows information about the current module.
	*/

	/**
	* Show or hide the hidden modules, depending on the action check state.
	*/
	void actionShowModules(bool checked);

	/**
	* Set the selected modules hidden.
	*/
	void actionHideModules();


	void actionAboutModule();
	/**
	* Unlocks the current module.
	*/
	void actionUnlockModule();
	void autoOpenTimeout();
	
	/**
	* Opens a plain text editor window to edit the modules content.
	*/
	void actionEditModulePlain();
	/**
	* Opens an HTML editor window to edit the modules content.
	*/
	void actionEditModuleHTML();

	void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);


private:
	CSearchDialog* m_searchDialog;
	//ToolTip* m_toolTip;
	bool m_itemsMovable;
	QTreeWidgetItem* m_autoOpenFolder;
	QTimer m_autoOpenTimer;
	BTModuleTreeItem::Grouping m_grouping; //temporary solution - this should be in config
	QActionGroup* m_groupingGroup;
	int m_mouseReleaseEventModifiers;
	bool m_showHidden;
	QSet<QString> m_frozenModules;

	/**
	* Initializes the view.
	*/
	void initView();
	void initActions();

	/** Convenience function for creating a new QAction. */
	QAction* newQAction(const QString& text, const QString& pix, int shortcut, const QObject* receiver, const char* slot, QObject* parent);

	QList<QAction*> m_actionList;

	QMenu* m_popup;

signals:
	/**
	* Is emitted when a module should be opened,
	*/
	void createReadDisplayWindow( QList<CSwordModuleInfo*>, const QString& );
	/**
	 * Is emitted when a write window should be created.
	 */
	void createWriteDisplayWindow( CSwordModuleInfo*, const QString&, const CDisplayWindow::WriteWindowType& );

};

#endif