-rw-r--r-- | library/menubutton.cpp | 71 |
1 files changed, 54 insertions, 17 deletions
diff --git a/library/menubutton.cpp b/library/menubutton.cpp index 007761f..4357460 100644 --- a/library/menubutton.cpp +++ b/library/menubutton.cpp | |||
@@ -67,6 +67,7 @@ | |||
67 | MenuButton::MenuButton( const QStringList& items, QWidget* parent, const char* name) : | 67 | MenuButton::MenuButton( const QStringList& items, QWidget* parent, const char* name) : |
68 | QPushButton(parent,name) | 68 | QPushButton(parent,name) |
69 | { | 69 | { |
70 | useLabel = true; | ||
70 | init(); | 71 | init(); |
71 | insertItems(items); | 72 | insertItems(items); |
72 | } | 73 | } |
@@ -98,8 +99,8 @@ void MenuButton::init() | |||
98 | */ | 99 | */ |
99 | void MenuButton::clear() | 100 | void MenuButton::clear() |
100 | { | 101 | { |
101 | delete pop; | 102 | delete pop; |
102 | init(); | 103 | init(); |
103 | } | 104 | } |
104 | 105 | ||
105 | /*! | 106 | /*! |
@@ -111,10 +112,10 @@ void MenuButton::insertItems( const QStringList& items ) | |||
111 | { | 112 | { |
112 | QStringList::ConstIterator it=items.begin(); | 113 | QStringList::ConstIterator it=items.begin(); |
113 | for (; it!=items.end(); ++it) { | 114 | for (; it!=items.end(); ++it) { |
114 | if ( (*it) == "--" ) | 115 | if ( (*it) == "--" ) |
115 | insertSeparator(); | 116 | insertSeparator(); |
116 | else | 117 | else |
117 | insertItem(*it); | 118 | insertItem(*it); |
118 | } | 119 | } |
119 | } | 120 | } |
120 | 121 | ||
@@ -127,7 +128,7 @@ void MenuButton::insertItems( const QStringList& items ) | |||
127 | void MenuButton::insertItem( const QIconSet& icon, const QString& text ) | 128 | void MenuButton::insertItem( const QIconSet& icon, const QString& text ) |
128 | { | 129 | { |
129 | pop->insertItem(icon, text, nitems++); | 130 | pop->insertItem(icon, text, nitems++); |
130 | if ( nitems==1 ) select(0); | 131 | // if ( nitems==1 ) select(0); |
131 | } | 132 | } |
132 | 133 | ||
133 | /*! | 134 | /*! |
@@ -139,7 +140,7 @@ void MenuButton::insertItem( const QIconSet& icon, const QString& text ) | |||
139 | void MenuButton::insertItem( const QString& text ) | 140 | void MenuButton::insertItem( const QString& text ) |
140 | { | 141 | { |
141 | pop->insertItem(text, nitems++); | 142 | pop->insertItem(text, nitems++); |
142 | if ( nitems==1 ) select(0); | 143 | // if ( nitems==1 ) select(0); |
143 | } | 144 | } |
144 | 145 | ||
145 | /*! | 146 | /*! |
@@ -158,10 +159,10 @@ void MenuButton::insertSeparator() | |||
158 | void MenuButton::select(const QString& s) | 159 | void MenuButton::select(const QString& s) |
159 | { | 160 | { |
160 | for (int i=0; i<nitems; i++) { | 161 | for (int i=0; i<nitems; i++) { |
161 | if ( pop->text(i) == s ) { | 162 | if ( pop->text(i) == s ) { |
162 | select(i); | 163 | select(i); |
163 | break; | 164 | break; |
164 | } | 165 | } |
165 | } | 166 | } |
166 | } | 167 | } |
167 | 168 | ||
@@ -174,7 +175,7 @@ void MenuButton::select(int s) | |||
174 | cur = s; | 175 | cur = s; |
175 | updateLabel(); | 176 | updateLabel(); |
176 | if ( pop->iconSet(cur) ) | 177 | if ( pop->iconSet(cur) ) |
177 | setIconSet(*pop->iconSet(cur)); | 178 | setIconSet(*pop->iconSet(cur)); |
178 | emit selected(cur); | 179 | emit selected(cur); |
179 | emit selected(currentText()); | 180 | emit selected(currentText()); |
180 | } | 181 | } |
@@ -208,9 +209,45 @@ void MenuButton::setLabel(const QString& label) | |||
208 | 209 | ||
209 | void MenuButton::updateLabel() | 210 | void MenuButton::updateLabel() |
210 | { | 211 | { |
211 | QString t = pop->text(cur); | 212 | if(useLabel) |
212 | if ( !lab.isEmpty() ) | 213 | { |
213 | t = lab.arg(t); | 214 | QString t = pop->text(cur); |
214 | setText(t); | 215 | if ( !lab.isEmpty() ) |
216 | t = lab.arg(t); | ||
217 | setText(t); | ||
218 | } | ||
215 | } | 219 | } |
216 | 220 | ||
221 | |||
222 | /*! | ||
223 | remove item at id | ||
224 | */ | ||
225 | void MenuButton::remove(int id) | ||
226 | { | ||
227 | pop->removeItem(id); | ||
228 | nitems--; | ||
229 | } | ||
230 | |||
231 | /*! | ||
232 | return count of items in menu | ||
233 | */ | ||
234 | int MenuButton::count() | ||
235 | { | ||
236 | return nitems; | ||
237 | } | ||
238 | |||
239 | /*! | ||
240 | returns text of item id | ||
241 | */ | ||
242 | QString MenuButton::text(int id) | ||
243 | { | ||
244 | return pop->text(id); | ||
245 | } | ||
246 | |||
247 | /*! | ||
248 | sets true or false the use of label | ||
249 | */ | ||
250 | void MenuButton::setUseLabel(bool b) | ||
251 | { | ||
252 | useLabel = b; | ||
253 | } | ||