summaryrefslogtreecommitdiff
path: root/libopie
authordrw <drw>2003-02-16 21:54:23 (UTC)
committer drw <drw>2003-02-16 21:54:23 (UTC)
commit8ecc375c803dc57b160bd0335891fcaf4f6de1df (patch) (side-by-side diff)
treea89c1ccc6e3a469bb8fa435dfedce9386333cb72 /libopie
parente0eb3f016d7f8a1e1e5548ef8aa115fef8999697 (diff)
downloadopie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.zip
opie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.tar.gz
opie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.tar.bz2
Added changeTab() to OTabWidget to dynamically change tab name and/or icon (stumbled upon request for this in TinyKate todo)
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabinfo.h16
-rw-r--r--libopie/otabwidget.cpp48
-rw-r--r--libopie/otabwidget.h10
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
@@ -89,6 +89,14 @@ public:
const QString &label() const { return l; }
/**
+ * @fn setLabel( const QString &label )
+ * @brief Set label for tab.
+ *
+ * @param label QString text label for OTabWidget selection control.
+ */
+ void setLabel( const QString &label ) { l = label; }
+
+/**
* @fn control()
* @brief Returns pointer to widget.
*/
@@ -100,6 +108,14 @@ public:
*/
const QString &icon() const { return p; }
+/**
+ * @fn setIcon( const QString &icon )
+ * @brief Set icon for tab.
+ *
+ * @param icon QString name of icon file.
+ */
+ void setIcon( const QString &icon ) { p = icon; }
+
private:
int i;
QWidget *c;
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
index bee3f35..99bf067 100644
--- a/libopie/otabwidget.cpp
+++ b/libopie/otabwidget.cpp
@@ -98,7 +98,7 @@ void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &lab
{
tab->label = label;
}
- if ( tabBarStyle == IconTab || tabBarStyle == IconList)
+ if ( tabBarStyle == IconTab || tabBarStyle == IconList )
{
tab->iconset = new QIconSet( iconset );
}
@@ -158,16 +158,52 @@ void OTabWidget::removePage( QWidget *childwidget )
}
}
+void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
+{
+ OTabInfo *currtab = tabs.first();
+ while ( currtab && currtab->control() != widget )
+ {
+ currtab = tabs.next();
+ }
+ if ( currtab && currtab->control() == widget )
+ {
+ QTab *tab = tabBar->tab( currtab->id() );
+ QPixmap icon( loadSmooth( iconset ) );
+ tab->setText( label );
+ if ( tabBarStyle == IconTab )
+ tab->setIconSet( icon );
+ int i = 0;
+ while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
+ {
+ i++;
+ }
+ if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
+ {
+ if ( tabBarStyle == IconTab || tabBarStyle == IconList )
+ {
+ tabList->changeItem( icon, label, i );
+ }
+ else
+ {
+ tabList->changeItem( label, i );
+ }
+ }
+ currtab->setLabel( label );
+ currtab->setIcon( iconset );
+ }
+ setUpLayout();
+}
+
void OTabWidget::setCurrentTab( QWidget *childwidget )
{
- OTabInfo *newtab = tabs.first();
- while ( newtab && newtab->control() != childwidget )
+ OTabInfo *currtab = tabs.first();
+ while ( currtab && currtab->control() != childwidget )
{
- newtab = tabs.next();
+ currtab = tabs.next();
}
- if ( newtab && newtab->control() == childwidget )
+ if ( currtab && currtab->control() == childwidget )
{
- selectTab( newtab );
+ selectTab( currtab );
}
}
diff --git a/libopie/otabwidget.h b/libopie/otabwidget.h
index 74d683b..0aa9bb8 100644
--- a/libopie/otabwidget.h
+++ b/libopie/otabwidget.h
@@ -126,6 +126,16 @@ public:
void removePage( QWidget * );
/**
+ * @fn changeTab( QWidget *widget, const QIconSet &icon, const QString &label )
+ * @brief Change text and/or icon for existing tab
+ *
+ * @param child Widget control.
+ * @param icon Path to icon.
+ * @param label Text label.
+ */
+ void changeTab( QWidget *, const QString &, const QString & );
+
+/**
* @fn tabStyle()
* @brief Returns current widget selection control style.
*/