Hide the tab bar when there are no tabs in it

This commit is contained in:
David Sansome 2010-05-21 10:57:40 +00:00
parent e572fbf487
commit 0ef6a2dc88
2 changed files with 47 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include <QUndoStack>
#include <QInputDialog>
#include <QSettings>
#include <QTimeLine>
const char* PlaylistContainer::kSettingsGroup = "Playlist";
@ -30,7 +31,9 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
ui_(new Ui_PlaylistContainer),
undo_(NULL),
redo_(NULL),
starting_up_(true)
starting_up_(true),
tab_bar_visible_(false),
tab_bar_animation_(new QTimeLine(500, this))
{
ui_->setupUi(this);
@ -44,6 +47,9 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
ui_->tab_bar->setMovable(true);
ui_->tab_bar->setShape(QTabBar::RoundedSouth);
connect(tab_bar_animation_, SIGNAL(frameChanged(int)), SLOT(SetTabBarHeight(int)));
ui_->tab_bar->setMaximumHeight(0);
// Connections
connect(ui_->clear, SIGNAL(clicked()), SLOT(ClearFilter()));
connect(ui_->tab_bar, SIGNAL(currentChanged(int)), SLOT(Save()));
@ -152,14 +158,32 @@ void PlaylistContainer::PlaylistAdded(int id, const QString &name) {
ui_->tab_bar->InsertTab(id, index, name);
// Are we startup up, should we select this tab?
if (starting_up_ && settings_.value("current_playlist", 0).toInt() == id) {
if (starting_up_ && settings_.value("current_playlist", 1).toInt() == id) {
starting_up_ = false;
ui_->tab_bar->set_current_id(id);
}
if (ui_->tab_bar->count() > 1) {
// Have to do this here because sizeHint() is only valid when there's a
// tab in the bar.
tab_bar_animation_->setFrameRange(0, ui_->tab_bar->sizeHint().height());
if (!isVisible()) {
// Skip the animation since the window is hidden (eg. if we're still
// loading the UI).
tab_bar_visible_ = true;
ui_->tab_bar->setMaximumHeight(tab_bar_animation_->endFrame());
} else {
SetTabBarVisible(true);
}
}
}
void PlaylistContainer::PlaylistRemoved(int id) {
ui_->tab_bar->RemoveTab(id);
if (ui_->tab_bar->count() <= 1)
SetTabBarVisible(false);
}
void PlaylistContainer::PlaylistRenamed(int id, const QString &new_name) {
@ -190,3 +214,16 @@ void PlaylistContainer::Save() {
settings_.setValue("current_playlist", ui_->tab_bar->current_id());
}
void PlaylistContainer::SetTabBarVisible(bool visible) {
if (tab_bar_visible_ == visible)
return;
tab_bar_visible_ = visible;
tab_bar_animation_->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward);
tab_bar_animation_->start();
}
void PlaylistContainer::SetTabBarHeight(int height) {
ui_->tab_bar->setMaximumHeight(height);
}

View File

@ -26,6 +26,8 @@ class Playlist;
class PlaylistManager;
class PlaylistView;
class QTimeLine;
class PlaylistContainer : public QWidget {
Q_OBJECT
@ -65,6 +67,9 @@ private slots:
void Save();
void SetTabBarVisible(bool visible);
void SetTabBarHeight(int height);
private:
void UpdateActiveIcon(const QIcon& icon);
@ -77,6 +82,9 @@ private:
QSettings settings_;
bool starting_up_;
bool tab_bar_visible_;
QTimeLine* tab_bar_animation_;
};
#endif // PLAYLISTCONTAINER_H