summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIvan Komissarov <ABBAPOH@gmail.com>2014-05-06 16:36:29 +0400
committerIvan Komissarov <ABBAPOH@gmail.com>2014-07-10 08:29:10 +0200
commit84c5e4866f8e825da306b8520f95b124e7c2c3ab (patch)
treed64bcf39a31de7e0b771c6a8b954591d2ab3c9e7 /src
parent5835407df13ecfd8d313eb2b8fc216f8cfe1f9e5 (diff)
Added autoHide property to QTabBar
This property is used to automatically hide tab bar if it has only one tab. Originally-by: Denis Kovalskiy <denimnumber1@gmail.com> Change-Id: I6967f760010fa55bad6a5986c29abe7ccf625cf8 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qtabbar.cpp40
-rw-r--r--src/widgets/widgets/qtabbar.h4
-rw-r--r--src/widgets/widgets/qtabbar_p.h4
-rw-r--r--src/widgets/widgets/qtabwidget.cpp23
-rw-r--r--src/widgets/widgets/qtabwidget.h4
5 files changed, 74 insertions, 1 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index 789ec2f6fd..e8fdc65711 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -632,6 +632,14 @@ void QTabBarPrivate::layoutWidgets(int start)
}
}
+void QTabBarPrivate::autoHideTabs()
+{
+ Q_Q(QTabBar);
+
+ if (autoHide)
+ q->setVisible(q->count() > 1);
+}
+
void QTabBarPrivate::_q_closeTab()
{
Q_Q(QTabBar);
@@ -861,6 +869,7 @@ int QTabBar::insertTab(int index, const QIcon& icon, const QString &text)
}
tabInserted(index);
+ d->autoHideTabs();
return index;
}
@@ -936,6 +945,7 @@ void QTabBar::removeTab(int index)
setCurrentIndex(d->currentIndex - 1);
}
d->refresh();
+ d->autoHideTabs();
tabRemoved(index);
}
}
@@ -2267,6 +2277,36 @@ void QTabBar::setDocumentMode(bool enabled)
}
/*!
+ \property QTabBar::autoHide
+ \brief If true, the tab bar is automatically hidden when it contains less
+ than 2 tabs.
+ \since 5.4
+
+ By default, this property is false.
+
+ \sa QWidget::visible
+*/
+
+bool QTabBar::autoHide() const
+{
+ Q_D(const QTabBar);
+ return d->autoHide;
+}
+
+void QTabBar::setAutoHide(bool hide)
+{
+ Q_D(QTabBar);
+ if (d->autoHide == hide)
+ return;
+
+ d->autoHide = hide;
+ if (hide)
+ d->autoHideTabs();
+ else
+ setVisible(true);
+}
+
+/*!
Sets \a widget on the tab \a index. The widget is placed
on the left or right hand side depending upon the \a position.
\since 4.5
diff --git a/src/widgets/widgets/qtabbar.h b/src/widgets/widgets/qtabbar.h
index a0e52c2f86..a1616b1524 100644
--- a/src/widgets/widgets/qtabbar.h
+++ b/src/widgets/widgets/qtabbar.h
@@ -70,6 +70,7 @@ class Q_WIDGETS_EXPORT QTabBar: public QWidget
Q_PROPERTY(bool expanding READ expanding WRITE setExpanding)
Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
+ Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
public:
explicit QTabBar(QWidget* parent=0);
@@ -166,6 +167,9 @@ public:
bool documentMode() const;
void setDocumentMode(bool set);
+ bool autoHide() const;
+ void setAutoHide(bool hide);
+
public Q_SLOTS:
void setCurrentIndex(int index);
diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h
index 3228308bc6..1238057e2a 100644
--- a/src/widgets/widgets/qtabbar_p.h
+++ b/src/widgets/widgets/qtabbar_p.h
@@ -77,7 +77,7 @@ public:
:currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false),
drawBase(true), scrollOffset(0), elideModeSetByUser(false), useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false),
selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false),
- dragInProgress(false), documentMode(false), movingTab(0)
+ dragInProgress(false), documentMode(false), autoHide(false), movingTab(0)
#ifdef Q_WS_MAC
, previousPressedIndex(-1)
#endif
@@ -184,6 +184,7 @@ public:
void updateMacBorderMetrics();
bool isTabInMacUnifiedToolbarArea() const;
void setupMovableTab();
+ void autoHideTabs();
void makeVisible(int index);
QSize iconSize;
@@ -201,6 +202,7 @@ public:
bool movable;
bool dragInProgress;
bool documentMode;
+ bool autoHide;
QWidget *movingTab;
#ifdef Q_WS_MAC
diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp
index fced1c01ec..616b66b80b 100644
--- a/src/widgets/widgets/qtabwidget.cpp
+++ b/src/widgets/widgets/qtabwidget.cpp
@@ -1351,6 +1351,29 @@ void QTabWidget::setDocumentMode(bool enabled)
}
/*!
+ \property QTabWidget::tabBarAutoHide
+ \brief If true, the tab bar is automatically hidden when it contains less
+ than 2 tabs.
+ \since 5.4
+
+ By default, this property is false.
+
+ \sa QWidget::visible
+*/
+
+bool QTabWidget::tabBarAutoHide() const
+{
+ Q_D(const QTabWidget);
+ return d->tabs->autoHide();
+}
+
+void QTabWidget::setTabBarAutoHide(bool enabled)
+{
+ Q_D(QTabWidget);
+ return d->tabs->setAutoHide(enabled);
+}
+
+/*!
Removes all the pages, but does not delete them. Calling this function
is equivalent to calling removeTab() until the tab widget is empty.
*/
diff --git a/src/widgets/widgets/qtabwidget.h b/src/widgets/widgets/qtabwidget.h
index 83c2e31d28..046e544bf0 100644
--- a/src/widgets/widgets/qtabwidget.h
+++ b/src/widgets/widgets/qtabwidget.h
@@ -68,6 +68,7 @@ class Q_WIDGETS_EXPORT QTabWidget : public QWidget
Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
+ Q_PROPERTY(bool tabBarAutoHide READ tabBarAutoHide WRITE setTabBarAutoHide)
public:
explicit QTabWidget(QWidget *parent = 0);
@@ -140,6 +141,9 @@ public:
bool documentMode() const;
void setDocumentMode(bool set);
+ bool tabBarAutoHide() const;
+ void setTabBarAutoHide(bool enabled);
+
void clear();
QTabBar* tabBar() const;