summaryrefslogtreecommitdiffstats
path: root/src/searchlist.h
blob: 3986b4ba16158c27a666e18ef5cf33d071b87cc3 (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
/***************************************************************************
 *
 * Copyright (C) 2005 Elad Lahav (elad_lahav@users.sourceforge.net)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ***************************************************************************/

#ifndef SEARCHLIST_H
#define SEARCHLIST_H

#include <ntqwidget.h>
#include <ntqvbox.h>
#include <ntqlineedit.h>
#include <ntqlistview.h>
#include <ntqtooltip.h>

class SearchList;

/**
 * Defines a line text edit for searchable list view.
 * The widget is based on TQLineEdit with additional key functions
 * Supported key events (up and down) are emitted as signals
 * @author Albert Yosher
 */
class SearchLineEdit : public TQLineEdit
{
   Q_OBJECT
public:
	SearchLineEdit(TQWidget* pParent) : TQLineEdit(pParent) {};
	~SearchLineEdit() {};
	
signals:
	/**
	 * Emitted when one of the up/down or page up/page down keys were pressed
	 * inside this edit widget.
	 * @param	pEvent	The event received for this key press
	 */
	void keyPressed(TQKeyEvent* pEvent);
	
private:
	virtual void keyPressEvent(TQKeyEvent*);
};

/**
 * A tool-tip class for the search list.
 * Enables sub-classes of the list to provide a customised tool-tip for each 
 * list item.
 * @author Gabor Fekete
 */
class ListToolTip : public TQToolTip
{
public:
	ListToolTip(SearchList* pParent);

protected:
	virtual void maybeTip(const TQPoint& pt);
	
private:
	/** The owner widget. */
	SearchList* m_pList;
};


/**
 * Defines a searchable list view.
 * The widget is composed of a list view, and an edit box used to enter
 * search data. Whenever the text in the edit box changes, the list view is
 * set to point to the first item that matches the new text.
 * @author Elad Lahav
 */
class SearchList : public TQVBox
{
   Q_OBJECT

public: 
	SearchList(int nSearchCol, TQWidget* pParent = 0, const char* szName = 0);
	~SearchList();

	/**
	 * @return	A pointer to the list part of the widget.
	 */
	TQListView* getList() { return m_pList; }
	
	/**
	 * Constructs a tool-tip for the given item.
	 * @param	pItem	The item for which a tip is required
	 * @param	sTip	The constructed tip string (on return)
	 * @return	True to display the tip, false otherwise
	 */
	virtual bool getTip(TQListViewItem* pItem, TQString& sTip) = 0;

public slots:
	void slotSetFocus();

protected:
	/** The search edit-box. */
	TQLineEdit* m_pEdit;
	
	/** The list part of the widget. */
	TQListView* m_pList;

	/**
	 * Called whenever the user selects an item in the list by either double-
	 * clicking it, or by highlighting the item and pressing the ENTER key.
	 * @param	pItem	The selected list item
	 */
	virtual void processItemSelected(TQListViewItem* pItem) = 0;
	
protected slots:
	void slotFindItem(const TQString&);
	void slotItemSelected(TQListViewItem*);
	void slotItemSelected();
	void slotKeyPressed(TQKeyEvent*);
	
private:
	/** Specifies the search column, i.e., the list column whose strings are
		compared with the text in the search edit-box. */
	int m_nSearchCol;
	
	/** A tool-tip for the list entries. */
	ListToolTip* m_pToolTip;
};

#endif