summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/searchdialog/csearchanalysis.h
blob: 6fed8eae3c1d01d87d04dfa9c896e925735b2a41 (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 <tqwidget.h>
#include <tqstring.h>
#include <tqcanvas.h>
#include <tqdict.h>
#include <tqtooltip.h>

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


class TQTextEdit;

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 TQCanvas {
	Q_OBJECT
public:
	CSearchAnalysis(TQObject *parent=0, const char *name=0);
	virtual ~CSearchAnalysis();
	/**
	* Starts the analysis of the search result.
	* This should be called only once because
	* TQCanvas 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 TQColor getColor(int index);
	/*
	* This function returns a pointer to the list of AnalysisItems
	*/
	TQDict<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 TQString book, CSwordModuleInfo* module );

	ListCSwordModuleInfo m_moduleList;
	TQDict<CSearchAnalysisItem> m_canvasItemList;
	TQMap<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, TQWidget* parentDialog);
	~CSearchAnalysisDialog();

protected: // Protected methods
	/**
	 * Initializes the widgets TQT_SIGNAL and TQT_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 TQCanvasRectangle  {
public:
	/**
	* Standard constructor.
	*/
	CSearchAnalysisItem(TQCanvas* parent, const int moduleCount, const TQString& 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 TQString getToolTip();

private:
	virtual void draw (TQPainter & painter);

	ListCSwordModuleInfo* m_moduleList;
	double *m_scaleFactor;
	TQString m_bookName;
	int m_moduleCount;
	TQMemArray<int> m_resultCountArray;
	TQPixmap* m_bufferPixmap;
};

class CSearchAnalysisLegendItem : public TQCanvasRectangle  {

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

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

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

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

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

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

#endif