-rw-r--r-- | library/menubutton.cpp | 41 | ||||
-rw-r--r-- | library/menubutton.h | 6 |
2 files changed, 45 insertions, 2 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 | } |
@@ -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 | /*! |
@@ -208,9 +209,45 @@ void MenuButton::setLabel(const QString& label) | |||
208 | 209 | ||
209 | void MenuButton::updateLabel() | 210 | void MenuButton::updateLabel() |
210 | { | 211 | { |
212 | if(useLabel) | ||
213 | { | ||
211 | QString t = pop->text(cur); | 214 | QString t = pop->text(cur); |
212 | if ( !lab.isEmpty() ) | 215 | if ( !lab.isEmpty() ) |
213 | t = lab.arg(t); | 216 | t = lab.arg(t); |
214 | setText(t); | 217 | setText(t); |
215 | } | 218 | } |
219 | } | ||
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 | } | ||
216 | 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 | } | ||
diff --git a/library/menubutton.h b/library/menubutton.h index 6582b1e..ee5dcf1 100644 --- a/library/menubutton.h +++ b/library/menubutton.h | |||
@@ -31,6 +31,7 @@ public: | |||
31 | 31 | ||
32 | void clear(); | 32 | void clear(); |
33 | 33 | ||
34 | |||
34 | int currentItem() const; | 35 | int currentItem() const; |
35 | QString currentText() const; | 36 | QString currentText() const; |
36 | 37 | ||
@@ -40,6 +41,10 @@ public: | |||
40 | void insertSeparator(); | 41 | void insertSeparator(); |
41 | 42 | ||
42 | void setLabel(const QString& label); | 43 | void setLabel(const QString& label); |
44 | int count(); | ||
45 | void remove(int id); | ||
46 | QString text(int id); | ||
47 | void setUseLabel(bool b); | ||
43 | 48 | ||
44 | signals: | 49 | signals: |
45 | void selected(int); | 50 | void selected(int); |
@@ -50,6 +55,7 @@ public slots: | |||
50 | void select(const QString&); | 55 | void select(const QString&); |
51 | 56 | ||
52 | private: | 57 | private: |
58 | bool useLabel; | ||
53 | void init(); | 59 | void init(); |
54 | QStringList txts; | 60 | QStringList txts; |
55 | QPopupMenu* pop; | 61 | QPopupMenu* pop; |