summaryrefslogtreecommitdiff
path: root/library/menubutton.cpp
Unidiff
Diffstat (limited to 'library/menubutton.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/menubutton.cpp71
1 files changed, 50 insertions, 21 deletions
diff --git a/library/menubutton.cpp b/library/menubutton.cpp
index 6b1fa2b..f5c832c 100644
--- a/library/menubutton.cpp
+++ b/library/menubutton.cpp
@@ -1,7 +1,7 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
@@ -25,25 +25,44 @@
25 \class MenuButton menubutton.h 25 \class MenuButton menubutton.h
26 \brief The MenuButton class is a pushbutton with a menu. 26 \brief The MenuButton class is a pushbutton with a menu.
27 27
28 Similar in function to a QComboBox. 28 When the user presses the menubutton's pushbutton, the menu pops up.
29 A menu is composed of menu items each of which has a string label,
30 and optionally an icon.
31
32 The index of the item that the user's input device (e.g. stylus) is
33 pointing at is the currentItem(), whose text is available using
34 currentText().
35
36 Menu items are inserted with the \link MenuButton::MenuButton()
37 constructor\endlink, insertItem() or insertItems(). Separators are
38 inserted with insertSeparator(). All the items in the menu can be
39 removed by calling clear().
40
41 Items can be selected programmatically using select(). When a menu
42 item is selected (programmatically or by the user), the selected()
43 signal is emitted.
44
45 \ingroup qtopiaemb
29*/ 46*/
30 47
31/*! 48/*!
32 \fn void MenuButton::selected(int index) 49 \overload void MenuButton::selected(int index)
33 50
34 This signal is emitted when the item at \a index is selected. 51 This signal is emitted when the item at position \a index is selected.
35*/ 52*/
36 53
37/*! 54/*!
38 \fn void MenuButton::selected(const QString& text) 55 \fn void MenuButton::selected(const QString& text)
39 56
40 This signal is emitted when the item with the given \a text is selected. 57 This signal is emitted when the item with the label \a text is selected.
41*/ 58*/
42 59
43 60
44/*! 61/*!
45 Constructs a MenuButton with the given \a items added (see insertItems()). 62 Constructs a MenuButton. A menu item is created (see insertItem()
46 The standard \a parent an \a name arguments are passed to the base class. 63 and insertItems()) for each string in the \a items string list. The
64 standard \a parent an \a name arguments are passed to the base
65 class.
47*/ 66*/
48MenuButton::MenuButton( const QStringList& items, QWidget* parent, const char* name) : 67MenuButton::MenuButton( const QStringList& items, QWidget* parent, const char* name) :
49 QPushButton(parent,name) 68 QPushButton(parent,name)
@@ -56,7 +75,7 @@ MenuButton::MenuButton( const QStringList& items, QWidget* parent, const char* n
56 Constructs an empty MenuButton. 75 Constructs an empty MenuButton.
57 The standard \a parent an \a name arguments are passed to the base class. 76 The standard \a parent an \a name arguments are passed to the base class.
58 77
59 \sa insertItems() 78 \sa insertItem() insertItems()
60*/ 79*/
61MenuButton::MenuButton( QWidget* parent, const char* name) : 80MenuButton::MenuButton( QWidget* parent, const char* name) :
62 QPushButton(parent,name) 81 QPushButton(parent,name)
@@ -75,7 +94,7 @@ void MenuButton::init()
75} 94}
76 95
77/*! 96/*!
78 Removes all items from the button and menu. 97 Removes all the menu items from the button and menu.
79*/ 98*/
80void MenuButton::clear() 99void MenuButton::clear()
81{ 100{
@@ -84,8 +103,9 @@ void MenuButton::clear()
84} 103}
85 104
86/*! 105/*!
87 Inserts string \a items into the menu. The string "--" represents 106 A menu item is created (see insertItem()) for each string in the \a
88 a separator. 107 items string list. If any string is "--" a separator (see
108 insertSeparator()) is inserted in its place.
89*/ 109*/
90void MenuButton::insertItems( const QStringList& items ) 110void MenuButton::insertItems( const QStringList& items )
91{ 111{
@@ -99,16 +119,22 @@ void MenuButton::insertItems( const QStringList& items )
99} 119}
100 120
101/*! 121/*!
102 Inserts an \a icon and \a text into the menu. 122 Inserts a menu item with the icon \a icon and label \a text into
123 the menu.
124
125 \sa insertItems()
103*/ 126*/
104void MenuButton::insertItem( const QIconSet& icon, const QString& text ) 127void MenuButton::insertItem( const QIconSet& icon, const QString& text=QString::null )
105{ 128{
106 pop->insertItem(icon, text, nitems++); 129 pop->insertItem(icon, text, nitems++);
107 if ( nitems==1 ) select(0); 130 if ( nitems==1 ) select(0);
108} 131}
109 132
110/*! 133/*!
111 Inserts \a text into the menu. 134 \overload
135 Inserts a menu item with the label \a text into the menu.
136
137 \sa insertItems()
112*/ 138*/
113void MenuButton::insertItem( const QString& text ) 139void MenuButton::insertItem( const QString& text )
114{ 140{
@@ -117,7 +143,9 @@ void MenuButton::insertItem( const QString& text )
117} 143}
118 144
119/*! 145/*!
120 Inserts a visual separator into the menu. 146 Inserts a separator into the menu.
147
148 \sa insertItems()
121*/ 149*/
122void MenuButton::insertSeparator() 150void MenuButton::insertSeparator()
123{ 151{
@@ -125,7 +153,7 @@ void MenuButton::insertSeparator()
125} 153}
126 154
127/*! 155/*!
128 Selects the items with text \a s. 156 Selects the items with label text \a s.
129*/ 157*/
130void MenuButton::select(const QString& s) 158void MenuButton::select(const QString& s)
131{ 159{
@@ -138,7 +166,8 @@ void MenuButton::select(const QString& s)
138} 166}
139 167
140/*! 168/*!
141 Selects the item at index \a s. 169 \overload
170 Selects the item at index position \a s.
142*/ 171*/
143void MenuButton::select(int s) 172void MenuButton::select(int s)
144{ 173{
@@ -151,7 +180,7 @@ void MenuButton::select(int s)
151} 180}
152 181
153/*! 182/*!
154 Returns the index of the current item. 183 Returns the index position of the current item.
155*/ 184*/
156int MenuButton::currentItem() const 185int MenuButton::currentItem() const
157{ 186{
@@ -159,7 +188,7 @@ int MenuButton::currentItem() const
159} 188}
160 189
161/*! 190/*!
162 Returns the text of the current item. 191 Returns the label text of the current item.
163*/ 192*/
164QString MenuButton::currentText() const 193QString MenuButton::currentText() const
165{ 194{
@@ -167,7 +196,7 @@ QString MenuButton::currentText() const
167} 196}
168 197
169/*! 198/*!
170 Sets the label. If \a label is empty, the 199 Sets the menubutton's label. If \a label is empty, the
171 current item text is displayed, otherwise \a label should contain 200 current item text is displayed, otherwise \a label should contain
172 "%1", which will be replaced by the current item text. 201 "%1", which will be replaced by the current item text.
173*/ 202*/