1
/* This file is part of the KDE project
2
Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16
Boston, MA 02111-1307, USA.
19
#ifndef _KACTION_SELECTOR_H_
20
#define _KACTION_SELECTOR_H_
30
class KActionSelectorPrivate;
33
@short A widget for selecting and arranging actions/objects
34
This widget allows the user to select from a set of objects and arrange
35
the order of the selected ones using two list boxes labeled "Available"
36
and "Used" with horizontal arrows in between to move selected objects between
37
the two, and vertical arrows on the right to arrange the order of the selected
40
The widget moves objects to the other listbox when doubleclicked if
41
the property moveOnDoubleClick is set to true (default). See moveOnDoubleClick()
42
and setMoveOnDoubleClick().
44
The user control the widget using the keyboard if enabled (default),
47
Note that this may conflist with keyboard selection in the selected list box,
48
if you set that to anything else than QListBox::Single (which is the default).
50
To use it, simply construct an instance and then add items to the two listboxes,
51
available through lbAvailable() and lbSelected(). Whenever you want, you can retrieve
52
the selected options using QListBox methods on lbSelected().
54
This way, you can use your own QListBoxItem class, allowing you to easily
55
store object data in those.
57
When an item is moved to a listbox, it is placed below the current item
60
Standard arrow icons are used, but you can use icons of your own choice if desired,
61
see setButtonIcon(). It is also possible to set tooltips and whatsthis help
62
for the buttons. See setButtonTooltip() and setButtonWhatsThis().
64
To set whatsthis or tooltips for the listboxes, access them through
65
availableListbox() and selectedListBox().
67
All the moving buttons are automatically set enabled as expected.
69
Signals are sent each time an item is moved, allowing you to follow the
70
users actions if you need to. See addedToSelection(), removedFromSelection(),
71
movedUp() and movedDown()
73
@author Anders Lund <anders@alweb.dk>
76
class KActionSelector : public QWidget {
78
Q_ENUMS( ButtonIconSize InsertionPolicy )
79
Q_PROPERTY( bool moveOnDoubleClick READ moveOnDoubleClick WRITE setMoveOnDoubleClick )
80
Q_PROPERTY( bool keyboardEnabled READ keyboardEnabled WRITE setKeyboardEnabled )
81
Q_PROPERTY( QString availableLabel READ availableLabel WRITE setAvailableLabel )
82
Q_PROPERTY( QString selectedLabel READ selectedLabel WRITE setSelectedLabel )
83
Q_PROPERTY( ButtonIconSize buttonIconSize READ buttonIconSize WRITE setButtonIconSize )
84
Q_PROPERTY( InsertionPolicy availableInsertionPolicy READ availableInsertionPolicy WRITE setAvailableInsertionPolicy )
85
Q_PROPERTY( InsertionPolicy selectedInsertionPolicy READ selectedInsertionPolicy WRITE setSelectedInsertionPolicy )
86
Q_PROPERTY( bool showUpDownButtons READ showUpDownButtons WRITE setShowUpDownButtons )
89
KActionSelector( QWidget *parent=0, const char *name=0 );
93
@return The QListBox holding the available actions
95
QListBox *availableListBox();
98
@return The QListBox holding the selected actions
100
QListBox *selectedListBox();
103
This enum indentifies the moving buttons
113
This enum identifies the icon sizes, used for the move buttons.
114
The values correspond to the following pixel sizes:
115
@li SmallIcon - the return value of IconSize( KIcon::Small ), the user defined size
116
of a small icon in KDE. This is the default setting.
122
enum ButtonIconSize {
131
This enum defines policies for where to insert moved items in a listbox.
132
The following policies are currently defined:
133
@li BelowCurrent - The item is inserted below the listbox'
134
currentItem() or at the end if there is no curent item.
135
@li Sorted - The listbox is sort()ed after one or more items are inserted.
136
@li AtTop - The item is inserted at index 0 in the listbox.
137
@li AtBottom - The item is inserted at the end of the listbox.
139
@sa availableInsertionPolicy(), setAvailableInsertionPolicy(),
140
selectedInsertionPolicy(), setSelectedInsertionPolicy().
142
enum InsertionPolicy {
150
@return Wheather moveOnDoubleClcik is enabled.
152
If enabled, an item in any listbox will be moved to the other one whenever
154
@sa setMoveOnDoubleClick()
156
bool moveOnDoubleClick() const;
159
Sets moveOnDoubleClick to @p enable
160
@sa moveOnDoubleClick()
162
void setMoveOnDoubleClick( bool enable );
165
@return Weather keyboard control is enabled.
167
When Keyboard control is enabled, the widget will react to
168
the following keyboard actions:
169
@li CTRL + Right - simulate clicking the add button
170
@li CTRL + Left - simulate clicking the remove button
171
@li CTRL + Up - simulate clicking the up button
172
@li CTRL + Down - simulate clicking the down button
174
Additionally, pressing RETURN or ENTER on one of the list boxes
175
will cause the current item of that listbox to be moved to the other
178
The keyboard actions are enabled by default.
180
@sa setKeyboardEnabled()
182
bool keyboardEnabled() const;
185
Sets the keyboard enabled depending on @p enable.
186
@sa keyboardEnabled()
188
void setKeyboardEnabled( bool enable );
191
@return The text of the label for the available items listbox.
193
QString availableLabel() const;
196
Sets the label for the available items listbox to @p text.
197
Note that this label has the listbox as its @e buddy, so that
198
if you have a single ampersand in the text, the following character
199
will become the accellerator to focus te listbox.
201
void setAvailableLabel( const QString & text );
204
@return the label of the selected items listbox.
206
QString selectedLabel() const;
209
Sets the label for the selected items listbox to @p text.
210
Note that this label has the listbox as its @e buddy, so that
211
if you have a single ampersand in the text, the following character
212
will become the accellerator to focus te listbox.
214
void setSelectedLabel( const QString & text );
217
@return the current ButtonIconSize.
219
ButtonIconSize buttonIconSize() const;
222
Sets the button icon size.
223
See ButtonIconSize for the possible values and their pixel meaning.
225
void setButtonIconSize( ButtonIconSize size );
228
@return The current insertion policy for the available listbox.
229
The default policy for the available listbox is Sorted.
230
See also InsertionPolicy, setAvailableInsertionPolicy().
232
InsertionPolicy availableInsertionPolicy() const;
235
Sets the insertion policy for the available listbox.
236
See also InsertionPolicy, availableInsertionPolicy().
238
void setAvailableInsertionPolicy( InsertionPolicy policy );
241
@return The current insertion policy for the selected listbox.
242
The default policy for the selected listbox is BelowCurrent.
243
See also InsertionPolicy, setSelectedInsertionPolicy().
245
InsertionPolicy selectedInsertionPolicy() const;
248
Sets the insertion policy for the selected listbox.
249
See also InsertionPolicy, selectedInsertionPolicy().
251
void setSelectedInsertionPolicy( InsertionPolicy policy );
254
@return wheather the Up and Down buttons should be displayed.
256
bool showUpDownButtons() const;
259
Sets wheather the Up and Down buttons should be displayed
262
void setShowUpDownButtons( bool show );
265
Sets the pixmap of the button @p button to @p icon.
266
It calls SmallIconSet(pm) to generate the icon set.
268
void setButtonIcon( const QString &icon, MoveButton button );
271
Sets the iconset for button @p button to @p iconset.
272
You can use this method to et a costum icon set. Either
273
created by @ref QIconSet, or use the application instance of
274
@ref KIconLoader (recommended).
276
void setButtonIconSet( const QIconSet &iconset, MoveButton button );
279
Sets the tooltip for the button @p button to @p tip.
281
void setButtonTooltip( const QString &tip, MoveButton button );
284
Sets the whatsthis help for button @p button to @p text.
286
void setButtonWhatsThis( const QString &text, MoveButton button );
289
Sets the enabled state of all moving buttons to reflect the current
292
Be sure to call this if you add or removes items to either listbox after the
295
void setButtonsEnabled();
299
Emitted when an item is moved to the "selected" listbox.
301
void added( QListBoxItem *item );
304
Emitted when an item is moved out of the "selected" listbox.
306
void removed( QListBoxItem *item );
309
Emitted when an item is moved upwards in the "selected" listbox.
311
void movedUp( QListBoxItem *item );
314
Emitted when an item is moved downwards in the "selected" listbox.
316
void movedDown( QListBoxItem *item );
319
Emitted when an item is moved to the "selected" listbox.
321
// void addedToSelection( QListBoxItem *item );
325
Reimplemented for internal reasons.
326
(calls setButtonsEnabled())
332
Reimplamented for internal reasons.
334
void keyPressEvent( QKeyEvent * );
337
Reimplemented for internal reasons.
339
bool eventFilter( QObject *, QEvent * );
343
Move selected item from available box to the selected box
345
void buttonAddClicked();
348
Move selected item from selected box to available box
350
void buttonRemoveClicked();
353
Move selected item in selected box upwards
355
void buttonUpClicked();
358
Move seleted item in selected box downwards
360
void buttonDownClicked();
363
Moves the item @p item to the other listbox if moveOnDoubleClick is enabled.
365
void itemDoubleClicked( QListBoxItem *item );
368
connected to both list boxes to set the buttons enabled
370
void slotCurrentChanged( QListBoxItem * ) { setButtonsEnabled(); };
375
Move item @p item to the other listbox
377
void moveItem( QListBoxItem *item );
380
loads the icons for the move buttons.
385
@return the index to insert an item into listbox @p lb,
386
given InsertionPolicy @p policy.
388
Note that if policy is Sorted, this will return -1.
389
Sort the listbox after inserting the item in that case.
391
int insertionIndex( QListBox *lb, InsertionPolicy policy );
396
KActionSelectorPrivate *d;
399
#endif // _KACTION_SELECTOR_H_