-rw-r--r-- | libopie/otabinfo.h | 16 | ||||
-rw-r--r-- | libopie/otabwidget.cpp | 48 | ||||
-rw-r--r-- | libopie/otabwidget.h | 10 |
3 files changed, 68 insertions, 6 deletions
diff --git a/libopie/otabinfo.h b/libopie/otabinfo.h index 8dbbcc2..6589638 100644 --- a/libopie/otabinfo.h +++ b/libopie/otabinfo.h | |||
@@ -60,57 +60,73 @@ public: | |||
60 | * @param parent Pointer to parent of this control. | 60 | * @param parent Pointer to parent of this control. |
61 | * @param name Name of control. | 61 | * @param name Name of control. |
62 | * @param s Style of widget selection control. | 62 | * @param s Style of widget selection control. |
63 | * @param p Position of the widget selection control. | 63 | * @param p Position of the widget selection control. |
64 | */ | 64 | */ |
65 | OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} | 65 | OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) | 68 | * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) |
69 | * @brief Object constructor. | 69 | * @brief Object constructor. |
70 | * | 70 | * |
71 | * @param id TabBar identifier for widget. | 71 | * @param id TabBar identifier for widget. |
72 | * @param control QWidget pointer to widget. | 72 | * @param control QWidget pointer to widget. |
73 | * @param icon QString name of icon file. | 73 | * @param icon QString name of icon file. |
74 | * @param label QString text label for OTabWidget selection control. | 74 | * @param label QString text label for OTabWidget selection control. |
75 | */ | 75 | */ |
76 | OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) | 76 | OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) |
77 | : i( id ), c( control ), p( icon ), l( label ) {} | 77 | : i( id ), c( control ), p( icon ), l( label ) {} |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * @fn id() | 80 | * @fn id() |
81 | * @brief Returns TabBar ID. | 81 | * @brief Returns TabBar ID. |
82 | */ | 82 | */ |
83 | int id() const { return i; } | 83 | int id() const { return i; } |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * @fn label() | 86 | * @fn label() |
87 | * @brief Returns text label for widget. | 87 | * @brief Returns text label for widget. |
88 | */ | 88 | */ |
89 | const QString &label() const { return l; } | 89 | const QString &label() const { return l; } |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * @fn setLabel( const QString &label ) | ||
93 | * @brief Set label for tab. | ||
94 | * | ||
95 | * @param label QString text label for OTabWidget selection control. | ||
96 | */ | ||
97 | void setLabel( const QString &label ) { l = label; } | ||
98 | |||
99 | /** | ||
92 | * @fn control() | 100 | * @fn control() |
93 | * @brief Returns pointer to widget. | 101 | * @brief Returns pointer to widget. |
94 | */ | 102 | */ |
95 | QWidget *control() const { return c; } | 103 | QWidget *control() const { return c; } |
96 | 104 | ||
97 | /** | 105 | /** |
98 | * @fn icon() | 106 | * @fn icon() |
99 | * @brief Returns name of icon file. | 107 | * @brief Returns name of icon file. |
100 | */ | 108 | */ |
101 | const QString &icon() const { return p; } | 109 | const QString &icon() const { return p; } |
102 | 110 | ||
111 | /** | ||
112 | * @fn setIcon( const QString &icon ) | ||
113 | * @brief Set icon for tab. | ||
114 | * | ||
115 | * @param icon QString name of icon file. | ||
116 | */ | ||
117 | void setIcon( const QString &icon ) { p = icon; } | ||
118 | |||
103 | private: | 119 | private: |
104 | int i; | 120 | int i; |
105 | QWidget *c; | 121 | QWidget *c; |
106 | QString p; | 122 | QString p; |
107 | QString l; | 123 | QString l; |
108 | }; | 124 | }; |
109 | 125 | ||
110 | /** | 126 | /** |
111 | * @class OTabInfoList | 127 | * @class OTabInfoList |
112 | * @brief A list of OTabInfo objects used by OTabWidget. | 128 | * @brief A list of OTabInfo objects used by OTabWidget. |
113 | */ | 129 | */ |
114 | typedef QList<OTabInfo> OTabInfoList; | 130 | typedef QList<OTabInfo> OTabInfoList; |
115 | 131 | ||
116 | #endif | 132 | #endif |
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp index bee3f35..99bf067 100644 --- a/libopie/otabwidget.cpp +++ b/libopie/otabwidget.cpp | |||
@@ -69,134 +69,170 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPositi | |||
69 | 69 | ||
70 | tabBar = new OTabBar( tabBarStack, "tabbar" ); | 70 | tabBar = new OTabBar( tabBarStack, "tabbar" ); |
71 | tabBarStack->addWidget( tabBar, 0 ); | 71 | tabBarStack->addWidget( tabBar, 0 ); |
72 | connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); | 72 | connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); |
73 | 73 | ||
74 | tabList = new QComboBox( false, tabBarStack, "tablist" ); | 74 | tabList = new QComboBox( false, tabBarStack, "tablist" ); |
75 | tabBarStack->addWidget( tabList, 1 ); | 75 | tabBarStack->addWidget( tabList, 1 ); |
76 | connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); | 76 | connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); |
77 | 77 | ||
78 | setTabStyle( s ); | 78 | setTabStyle( s ); |
79 | setTabPosition( p ); | 79 | setTabPosition( p ); |
80 | 80 | ||
81 | currentTab= 0x0; | 81 | currentTab= 0x0; |
82 | } | 82 | } |
83 | 83 | ||
84 | OTabWidget::~OTabWidget() | 84 | OTabWidget::~OTabWidget() |
85 | { | 85 | { |
86 | } | 86 | } |
87 | 87 | ||
88 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 88 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
89 | { | 89 | { |
90 | QPixmap iconset = loadSmooth( icon ); | 90 | QPixmap iconset = loadSmooth( icon ); |
91 | 91 | ||
92 | QTab *tab = new QTab(); | 92 | QTab *tab = new QTab(); |
93 | if ( tabBarStyle == IconTab ) | 93 | if ( tabBarStyle == IconTab ) |
94 | { | 94 | { |
95 | tab->label = QString::null; | 95 | tab->label = QString::null; |
96 | } | 96 | } |
97 | else | 97 | else |
98 | { | 98 | { |
99 | tab->label = label; | 99 | tab->label = label; |
100 | } | 100 | } |
101 | if ( tabBarStyle == IconTab || tabBarStyle == IconList) | 101 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) |
102 | { | 102 | { |
103 | tab->iconset = new QIconSet( iconset ); | 103 | tab->iconset = new QIconSet( iconset ); |
104 | } | 104 | } |
105 | int tabid = tabBar->addTab( tab ); | 105 | int tabid = tabBar->addTab( tab ); |
106 | 106 | ||
107 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 107 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) |
108 | { | 108 | { |
109 | tabList->insertItem( iconset, label, -1 ); | 109 | tabList->insertItem( iconset, label, -1 ); |
110 | } | 110 | } |
111 | else | 111 | else |
112 | { | 112 | { |
113 | tabList->insertItem( label ); | 113 | tabList->insertItem( label ); |
114 | } | 114 | } |
115 | 115 | ||
116 | widgetStack->addWidget( child, tabid ); | 116 | widgetStack->addWidget( child, tabid ); |
117 | widgetStack->raiseWidget( child ); | 117 | widgetStack->raiseWidget( child ); |
118 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | 118 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); |
119 | 119 | ||
120 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); | 120 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); |
121 | tabs.append( tabinfo ); | 121 | tabs.append( tabinfo ); |
122 | selectTab( tabinfo ); | 122 | selectTab( tabinfo ); |
123 | } | 123 | } |
124 | 124 | ||
125 | void OTabWidget::removePage( QWidget *childwidget ) | 125 | void OTabWidget::removePage( QWidget *childwidget ) |
126 | { | 126 | { |
127 | if ( childwidget ) | 127 | if ( childwidget ) |
128 | { | 128 | { |
129 | OTabInfo *tab = tabs.first(); | 129 | OTabInfo *tab = tabs.first(); |
130 | while ( tab && tab->control() != childwidget ) | 130 | while ( tab && tab->control() != childwidget ) |
131 | { | 131 | { |
132 | tab = tabs.next(); | 132 | tab = tabs.next(); |
133 | } | 133 | } |
134 | if ( tab && tab->control() == childwidget ) | 134 | if ( tab && tab->control() == childwidget ) |
135 | { | 135 | { |
136 | tabBar->setTabEnabled( tab->id(), FALSE ); | 136 | tabBar->setTabEnabled( tab->id(), FALSE ); |
137 | tabBar->removeTab( tabBar->tab( tab->id() ) ); | 137 | tabBar->removeTab( tabBar->tab( tab->id() ) ); |
138 | int i = 0; | 138 | int i = 0; |
139 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) | 139 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) |
140 | { | 140 | { |
141 | i++; | 141 | i++; |
142 | } | 142 | } |
143 | if ( tabList->text( i ) == tab->label() ) | 143 | if ( tabList->text( i ) == tab->label() ) |
144 | { | 144 | { |
145 | tabList->removeItem( i ); | 145 | tabList->removeItem( i ); |
146 | } | 146 | } |
147 | widgetStack->removeWidget( childwidget ); | 147 | widgetStack->removeWidget( childwidget ); |
148 | tabs.remove( tab ); | 148 | tabs.remove( tab ); |
149 | delete tab; | 149 | delete tab; |
150 | currentTab = tabs.current(); | 150 | currentTab = tabs.current(); |
151 | if ( !currentTab ) | 151 | if ( !currentTab ) |
152 | { | 152 | { |
153 | widgetStack->setFrameStyle( QFrame::NoFrame ); | 153 | widgetStack->setFrameStyle( QFrame::NoFrame ); |
154 | } | 154 | } |
155 | 155 | ||
156 | setUpLayout(); | 156 | setUpLayout(); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) | ||
162 | { | ||
163 | OTabInfo *currtab = tabs.first(); | ||
164 | while ( currtab && currtab->control() != widget ) | ||
165 | { | ||
166 | currtab = tabs.next(); | ||
167 | } | ||
168 | if ( currtab && currtab->control() == widget ) | ||
169 | { | ||
170 | QTab *tab = tabBar->tab( currtab->id() ); | ||
171 | QPixmap icon( loadSmooth( iconset ) ); | ||
172 | tab->setText( label ); | ||
173 | if ( tabBarStyle == IconTab ) | ||
174 | tab->setIconSet( icon ); | ||
175 | int i = 0; | ||
176 | while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) | ||
177 | { | ||
178 | i++; | ||
179 | } | ||
180 | if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) | ||
181 | { | ||
182 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | ||
183 | { | ||
184 | tabList->changeItem( icon, label, i ); | ||
185 | } | ||
186 | else | ||
187 | { | ||
188 | tabList->changeItem( label, i ); | ||
189 | } | ||
190 | } | ||
191 | currtab->setLabel( label ); | ||
192 | currtab->setIcon( iconset ); | ||
193 | } | ||
194 | setUpLayout(); | ||
195 | } | ||
196 | |||
161 | void OTabWidget::setCurrentTab( QWidget *childwidget ) | 197 | void OTabWidget::setCurrentTab( QWidget *childwidget ) |
162 | { | 198 | { |
163 | OTabInfo *newtab = tabs.first(); | 199 | OTabInfo *currtab = tabs.first(); |
164 | while ( newtab && newtab->control() != childwidget ) | 200 | while ( currtab && currtab->control() != childwidget ) |
165 | { | 201 | { |
166 | newtab = tabs.next(); | 202 | currtab = tabs.next(); |
167 | } | 203 | } |
168 | if ( newtab && newtab->control() == childwidget ) | 204 | if ( currtab && currtab->control() == childwidget ) |
169 | { | 205 | { |
170 | selectTab( newtab ); | 206 | selectTab( currtab ); |
171 | } | 207 | } |
172 | } | 208 | } |
173 | 209 | ||
174 | void OTabWidget::setCurrentTab( const QString &tabname ) | 210 | void OTabWidget::setCurrentTab( const QString &tabname ) |
175 | { | 211 | { |
176 | OTabInfo *newtab = tabs.first(); | 212 | OTabInfo *newtab = tabs.first(); |
177 | while ( newtab && newtab->label() != tabname ) | 213 | while ( newtab && newtab->label() != tabname ) |
178 | { | 214 | { |
179 | newtab = tabs.next(); | 215 | newtab = tabs.next(); |
180 | } | 216 | } |
181 | if ( newtab && newtab->label() == tabname ) | 217 | if ( newtab && newtab->label() == tabname ) |
182 | { | 218 | { |
183 | selectTab( newtab ); | 219 | selectTab( newtab ); |
184 | } | 220 | } |
185 | } | 221 | } |
186 | 222 | ||
187 | void OTabWidget::setCurrentTab(int tabindex) { | 223 | void OTabWidget::setCurrentTab(int tabindex) { |
188 | OTabInfo *newtab = tabs.first(); | 224 | OTabInfo *newtab = tabs.first(); |
189 | while ( newtab && newtab->id() != tabindex ) | 225 | while ( newtab && newtab->id() != tabindex ) |
190 | { | 226 | { |
191 | newtab = tabs.next(); | 227 | newtab = tabs.next(); |
192 | } | 228 | } |
193 | if ( newtab && newtab->id() == tabindex ) | 229 | if ( newtab && newtab->id() == tabindex ) |
194 | { | 230 | { |
195 | selectTab( newtab ); | 231 | selectTab( newtab ); |
196 | } | 232 | } |
197 | } | 233 | } |
198 | 234 | ||
199 | 235 | ||
200 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 236 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
201 | { | 237 | { |
202 | return tabBarStyle; | 238 | return tabBarStyle; |
diff --git a/libopie/otabwidget.h b/libopie/otabwidget.h index 74d683b..0aa9bb8 100644 --- a/libopie/otabwidget.h +++ b/libopie/otabwidget.h | |||
@@ -97,64 +97,74 @@ public: | |||
97 | * @param p Position of the widget selection control. | 97 | * @param p Position of the widget selection control. |
98 | * | 98 | * |
99 | * Constructs a new OTabWidget control with parent and name. The style and position parameters | 99 | * Constructs a new OTabWidget control with parent and name. The style and position parameters |
100 | * determine how the widget selection control will be displayed. | 100 | * determine how the widget selection control will be displayed. |
101 | */ | 101 | */ |
102 | OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); | 102 | OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * @fn ~OTabWidget() | 105 | * @fn ~OTabWidget() |
106 | * @brief Object destructor. | 106 | * @brief Object destructor. |
107 | */ | 107 | */ |
108 | ~OTabWidget(); | 108 | ~OTabWidget(); |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * @fn addTab( QWidget *child, const QString &icon, const QString &label ) | 111 | * @fn addTab( QWidget *child, const QString &icon, const QString &label ) |
112 | * @brief Add new widget to control. | 112 | * @brief Add new widget to control. |
113 | * | 113 | * |
114 | * @param child Widget control. | 114 | * @param child Widget control. |
115 | * @param icon Path to icon. | 115 | * @param icon Path to icon. |
116 | * @param label Text label. | 116 | * @param label Text label. |
117 | */ | 117 | */ |
118 | void addTab( QWidget *, const QString &, const QString & ); | 118 | void addTab( QWidget *, const QString &, const QString & ); |
119 | 119 | ||
120 | /** | 120 | /** |
121 | * @fn removePage( QWidget *widget ) | 121 | * @fn removePage( QWidget *widget ) |
122 | * @brief Remove widget from control. Does not delete widget. | 122 | * @brief Remove widget from control. Does not delete widget. |
123 | * | 123 | * |
124 | * @param widget Widget control to be removed. | 124 | * @param widget Widget control to be removed. |
125 | */ | 125 | */ |
126 | void removePage( QWidget * ); | 126 | void removePage( QWidget * ); |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * @fn changeTab( QWidget *widget, const QIconSet &icon, const QString &label ) | ||
130 | * @brief Change text and/or icon for existing tab | ||
131 | * | ||
132 | * @param child Widget control. | ||
133 | * @param icon Path to icon. | ||
134 | * @param label Text label. | ||
135 | */ | ||
136 | void changeTab( QWidget *, const QString &, const QString & ); | ||
137 | |||
138 | /** | ||
129 | * @fn tabStyle() | 139 | * @fn tabStyle() |
130 | * @brief Returns current widget selection control style. | 140 | * @brief Returns current widget selection control style. |
131 | */ | 141 | */ |
132 | TabStyle tabStyle() const; | 142 | TabStyle tabStyle() const; |
133 | 143 | ||
134 | /** | 144 | /** |
135 | * @fn setTabStyle( TabStyle s ) | 145 | * @fn setTabStyle( TabStyle s ) |
136 | * @brief Set the current widget selection control style. | 146 | * @brief Set the current widget selection control style. |
137 | * | 147 | * |
138 | * @param s New style to be used. | 148 | * @param s New style to be used. |
139 | */ | 149 | */ |
140 | void setTabStyle( TabStyle ); | 150 | void setTabStyle( TabStyle ); |
141 | 151 | ||
142 | /** | 152 | /** |
143 | * @fn tabPosition() | 153 | * @fn tabPosition() |
144 | * @brief Returns current widget selection control position. | 154 | * @brief Returns current widget selection control position. |
145 | */ | 155 | */ |
146 | TabPosition tabPosition() const; | 156 | TabPosition tabPosition() const; |
147 | 157 | ||
148 | /** | 158 | /** |
149 | * @fn setTabPosition( TabPosition p ) | 159 | * @fn setTabPosition( TabPosition p ) |
150 | * @brief Set the current widget selection control position. | 160 | * @brief Set the current widget selection control position. |
151 | * | 161 | * |
152 | * @param p New position of widget selection control. | 162 | * @param p New position of widget selection control. |
153 | */ | 163 | */ |
154 | void setTabPosition( TabPosition ); | 164 | void setTabPosition( TabPosition ); |
155 | 165 | ||
156 | /** | 166 | /** |
157 | * @fn setCurrentTab( QWidget *childwidget ) | 167 | * @fn setCurrentTab( QWidget *childwidget ) |
158 | * @brief Selects and brings to top the desired widget by using widget pointer. | 168 | * @brief Selects and brings to top the desired widget by using widget pointer. |
159 | * | 169 | * |
160 | * @param childwidget Widget to select. | 170 | * @param childwidget Widget to select. |