summaryrefslogtreecommitdiffstats
path: root/korn/keditlistboxman.h
blob: b683a364c2498a8189478beea419d246787b7f76 (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
/*
 * Copyright (C) 2004, Mart Kelder (mart.kde@hccnet.nl)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef MK_KEDITLISTBOXMAN_H
#define MK_KEDITLISTBOXMAN_H

#include <keditlistbox.h>

class KConfig;

class TQString;
class TQWidget;

/**
 * This class is a extention on KEditListBox.
 * It also handles the configuration.
 * @author Mart Kelder (mart.kde@hccnet.nl)
 */
class KEditListBoxManager : public KEditListBox
{ Q_OBJECT
public:
	/**
	 * Constructor: @see KEditListBoxManager::KEditListBoxManager( const TQString&, TQWidget, const char * name, bool, int )
	 */
	KEditListBoxManager(	TQWidget *parent = 0, const char *name = 0,
			bool checkAtEntering=true, int buttons = All );
			
	/**
	 * The save as above, but with other options for KEditListBox.
	 */
	KEditListBoxManager(	const TQString& title, TQWidget *parent = 0,
			const char *name = 0, bool checkAtEntering=true,
			int buttons = All );
		
	/**
	 * The save as above, but with other options for KEditListBox.
	 */
	KEditListBoxManager(	const TQString& title,
			const KEditListBox::CustomEditor &customEditor,
			TQWidget *parent = 0, const char *name = 0,
			bool checkAtEntering = true, int buttons = All );
	
	/**
	 * Destructor
	 */		
	~KEditListBoxManager();
	
	
	/** 
	 * Set the KConfig object (required before doing something
	 * @param config The KConfig-object
	 */
	void setConfig( KConfig* config );
	/**
	 * Sets the groupName. groupName should contain at least one %1.
	 * It is used for makeing groupnames.
	 * @param name The groupname
	 */
	void setGroupName( const TQString& name );
	
	/**
	 * Sets the subGroupName. subGroupName should contain %1 and %2.
	 * It is used to execute operations on a group and its subgroups.
	 * @param name The groupname
	 */
	void setSubGroupName( const TQString& name );
private:
	/** 
	 * This functions is called from and only from the constructor to prevent writing the
	 * same code for all constructors
	 */
	void init();
	
	/**
	 * This function reads the names out the config.
	 */
	void readNames();
private:
	KConfig *_config; //Stores the KConfig-object
	TQString *_groupName; //Stores the groupName string.
	TQString *_subGroupName;
	int _prevCount;

private slots:
	//These comes directly from the KEditListBox itselfs.
	void slotChanged();
	void slotAdded( const TQString& );
	void slotRemoved( const TQString& );
	
	void slotActivated( TQListBoxItem* );
private:
	/**
	 * This private method moves an item. It is called from slotChanged().
	 * @param src The number of the source-group.
	 * @param dest The number of the destanation-group
	 */
	void moveItem( int src, int dest );
	
	/**
	 * This private functions switch to groups: first^=last; last^=first; first^=last
	 * @param first the first number of a group.
	 * @param last the second number of a group (and the last number).
	 */
	void changeItem( int first, int last );
	
	/**
	 * This function is called if the user change the name of the group
	 */
	void changedText();
	
signals:
	/**
	 * This signal is emitted when somebody selects an item
	 * @param text The text of the newly selected item.
	 */
	void activated( const TQString& text );
	
	/**
	 * This signal is emitted when defaults have to be set.
	 * @param name The name of the object: this is filled in the KEditListBox;
	 * @param config The configuration in which the config have to be parsed.
	 * @param index The number of the item.
	 * this config is already in the right group.
	 */
	void setDefaults( const TQString& name, const int index, KConfig* config );

	void elementsSwapped( int, int );
	void elementDeleted( int );
	
};

#endif //MK_KEDITLISTBOXMAN_H