summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/searchdialog/csearchanalysis.h
blob: 013efaa51a524bd61fc9ae661a61e0f1594c9c2f (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2006 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



#ifndef CSEARCHANALYSIS_H
#define CSEARCHANALYSIS_H

//BibleTime includes

#include "backend/cswordmoduleinfo.h"
#include "backend/cswordbackend.h"
#include "backend/cswordmodulesearch.h"

#include "util/cpointers.h"

//Sword includes


//Qt includes
#include <qwidget.h>
#include <qstring.h>
#include <qcanvas.h>
#include <qdict.h>
#include <qtooltip.h>

//KDE includes
#include <kdialog.h>
#include <kdialogbase.h>
#include <klistview.h>


class QTextEdit;

namespace Search {
	namespace Analysis {

//forward declarations
class CSearchAnalysisItem;
class CSearchAnalysisLegendItem;
class CSearchAnalysisView;

/**
 * CSearchDialogAnaylsis shows the graphical analysis of the search result.
 * @author The BibleTime Team
 */
class CSearchAnalysis : public QCanvas {
	Q_OBJECT
public:
	CSearchAnalysis(QObject *parent=0, const char *name=0);
	virtual ~CSearchAnalysis();
	/**
	* Starts the analysis of the search result.
	* This should be called only once because
	* QCanvas handles the updates automatically.
	*/
	void analyse(ListCSwordModuleInfo modules);
	/**
	* This function returns a color for each module
	* @return The color at position index in the list
	*/
	static QColor getColor(int index);
	/*
	* This function returns a pointer to the list of AnalysisItems
	*/
	QDict<CSearchAnalysisItem>* getSearchAnalysisItemList();
	void reset();

protected slots: // Protected slots
	/**
	* No descriptions
	*/
	void slotResized();

protected:
	void setModules(ListCSwordModuleInfo modules);

private:
	/**
	* Returns the count of the book in the module
	*/
	const unsigned int getCount( const QString book, CSwordModuleInfo* module );

	ListCSwordModuleInfo m_moduleList;
	QDict<CSearchAnalysisItem> m_canvasItemList;
	QMap<CSwordModuleInfo*,unsigned int> m_lastPosList;
	int m_maxCount;
	double m_scaleFactor;
	CSearchAnalysisLegendItem* m_legend;

public slots: // Public slots
	void saveAsHTML();
};


class CSearchAnalysisDialog : public KDialogBase  {
	Q_OBJECT
public:
	CSearchAnalysisDialog(ListCSwordModuleInfo modules, QWidget* parentDialog);
	~CSearchAnalysisDialog();

protected: // Protected methods
	/**
	 * Initializes the widgets SIGNAL and SLOT connections,.
	 */
	void initConnections();
	
	/**
	 * Initializes this dialog.
	 */
	void initView();

private:
	CSearchAnalysis* m_analysis;
	CSearchAnalysisView* m_analysisView;
};


//----------------------------------------------------------
//----------------------------------------------------------

/** Paints the bars for one book for one or more modules
 *
 */
class CSearchAnalysisItem : public QCanvasRectangle  {
public:
	/**
	* Standard constructor.
	*/
	CSearchAnalysisItem(QCanvas* parent, const int moduleCount, const QString& bookname, double *scaleFactor, ListCSwordModuleInfo* modules);
	virtual ~CSearchAnalysisItem();
	/**
	* Sets the resultcount of this item
	*/
	void setCountForModule( const int moduleIndex, const int count);

	/**
	* Returns the resultcount of this item
	*/
	int getCountForModule( const int moduleIndex);
	/**
	* Returns the width of this item.
	*/
	virtual int width();
	/**
	* Returns the tooltip for this item.
	*/
	const QString getToolTip();

private:
	virtual void draw (QPainter & painter);

	ListCSwordModuleInfo* m_moduleList;
	double *m_scaleFactor;
	QString m_bookName;
	int m_moduleCount;
	QMemArray<int> m_resultCountArray;
	QPixmap* m_bufferPixmap;
};

class CSearchAnalysisLegendItem : public QCanvasRectangle  {

public:
	CSearchAnalysisLegendItem(QCanvas* parent, ListCSwordModuleInfo* list );

private:
	virtual void draw (QPainter & painter);
	ListCSwordModuleInfo* m_moduleList;
};

//----------------------------------------------------------
//----------------------------------------------------------
class CSearchAnalysisView : public QCanvasView  {
	Q_OBJECT
public:
	/**
	* Standard constructor
	*/
	CSearchAnalysisView(QCanvas* canvas, QWidget* parent);
	/**
	* Returns the sizeHint for this view
	* We give back the size of the parent widgetas default.
	* This is a reimplementation from QCanvasView::sizeHint().
	*/
	virtual QSize sizeHint();
	/**
	* Returns the item at position p.
	* If there no item at that point return 0.
	*/
	CSearchAnalysisItem* itemAt( const QPoint& p );

protected:
	/**
	* Reimplementation.
	*/
	virtual void resizeEvent(QResizeEvent* e);

private:
	class ToolTip : public QToolTip {
	public:
		ToolTip(QWidget* parent);
		virtual ~ToolTip() {}
		;
		/**
		* Displays a tooltip for position p
		*/
		virtual void maybeTip(const QPoint &pos);
	};
	
	ToolTip* m_toolTip;
};

	} //end of namespace Search::Analysis
} //end of namespace Search

#endif