From 2c6b36ac375d749a80f446264e5bbe7fc630d311 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Fri, 4 May 2007 02:46:53 +0000 Subject: [PATCH] Respect 'Show Menu Bar' and tab bar display mode profile settings. svn path=/branches/work/konsole-split-view/; revision=660887 --- konsole/Application.cpp | 2 +- konsole/EditProfileDialog.cpp | 4 +-- konsole/MainWindow.cpp | 3 +++ konsole/MainWindow.h | 1 + konsole/ViewContainer.cpp | 50 +++++++++++++++++++++++++++++++++++ konsole/ViewContainer.h | 31 ++++++++++++++++++++-- konsole/ViewManager.cpp | 13 +++++++++ konsole/ViewManager.h | 3 +++ 8 files changed, 102 insertions(+), 5 deletions(-) diff --git a/konsole/Application.cpp b/konsole/Application.cpp index 14f16443..dbe2341c 100644 --- a/konsole/Application.cpp +++ b/konsole/Application.cpp @@ -147,7 +147,7 @@ void Application::detachView(Session* session) void Application::createSession(const QString& key , ViewManager* view) { Session* session = SessionManager::instance()->createSession(key); - + // create view before starting the session process so that the session doesn't suffer // a change in terminal size right after the session starts. some applications such as GNU Screen // and Midnight Commander don't like this happening diff --git a/konsole/EditProfileDialog.cpp b/konsole/EditProfileDialog.cpp index f823c9d0..7aa32226 100644 --- a/konsole/EditProfileDialog.cpp +++ b/konsole/EditProfileDialog.cpp @@ -117,8 +117,8 @@ void EditProfileDialog::setupGeneralPage(const Profile* info) int tabMode = info->property(Profile::TabBarMode).value(); RadioOption tabModes[] = { {_ui->alwaysHideTabBarButton,Profile::AlwaysHideTabBar,SLOT(alwaysHideTabBar())}, - {_ui->alwaysShowTabBarButton,Profile::AlwaysShowTabBar,SLOT(showTabBarAsNeeded())}, - {_ui->autoShowTabBarButton,Profile::ShowTabBarAsNeeded,SLOT(alwaysShowTabBar())}, + {_ui->alwaysShowTabBarButton,Profile::AlwaysShowTabBar,SLOT(alwaysShowTabBar())}, + {_ui->autoShowTabBarButton,Profile::ShowTabBarAsNeeded,SLOT(showTabBarAsNeeded())}, {0,0,0} }; setupRadio( tabModes , tabMode ); diff --git a/konsole/MainWindow.cpp b/konsole/MainWindow.cpp index 08ecd7bf..b8084288 100644 --- a/konsole/MainWindow.cpp +++ b/konsole/MainWindow.cpp @@ -76,6 +76,9 @@ MainWindow::MainWindow() connect( _viewManager , SIGNAL(viewPropertiesChanged(const QList&)) , bookmarkHandler() , SLOT(setViews(const QList&)) ); + connect( _viewManager , SIGNAL(setMenuBarVisible(bool)) , menuBar() , + SLOT(setVisible(bool)) ); + // create main window widgets setupWidgets(); diff --git a/konsole/MainWindow.h b/konsole/MainWindow.h index 5ffb3524..3ecfec32 100644 --- a/konsole/MainWindow.h +++ b/konsole/MainWindow.h @@ -34,6 +34,7 @@ class ViewSplitter; class ViewManager; class ViewProperties; class SessionController; +class Profile; class ProfileList; class BookmarkHandler; diff --git a/konsole/ViewContainer.cpp b/konsole/ViewContainer.cpp index d9ba37a3..c586a4c3 100644 --- a/konsole/ViewContainer.cpp +++ b/konsole/ViewContainer.cpp @@ -49,10 +49,32 @@ using namespace Konsole; +ViewContainer::ViewContainer(QObject* parent) + : QObject(parent) + , _navigationDisplayMode(AlwaysShowNavigation) +{ +} ViewContainer::~ViewContainer() { emit destroyed(this); } +void ViewContainer::setNavigationDisplayMode(NavigationDisplayMode mode) +{ + _navigationDisplayMode = mode; + + if ( mode == AlwaysShowNavigation ) + qDebug() << "Always show nav"; + else if ( mode == AlwaysHideNavigation ) + qDebug() << "Always hide nav"; + else if ( mode == ShowNavigationAsNeeded ) + qDebug() << "Show nav as needed"; + + navigationDisplayModeChanged(mode); +} +ViewContainer::NavigationDisplayMode ViewContainer::navigationDisplayMode() const +{ + return _navigationDisplayMode; +} void ViewContainer::addView(QWidget* view , ViewProperties* item) { _views << view; @@ -383,6 +405,28 @@ TabbedViewContainerV2::TabbedViewContainerV2(QObject* parent) : ViewContainer(pa _containerWidget->setLayout(layout); } +void TabbedViewContainerV2::navigationDisplayModeChanged(NavigationDisplayMode mode) +{ + if ( mode == AlwaysShowNavigation && _tabBar->isHidden() ) + _tabBar->setVisible(true); + + if ( mode == AlwaysHideNavigation && !_tabBar->isHidden() ) + _tabBar->setVisible(false); + + if ( mode == ShowNavigationAsNeeded ) + dynamicTabBarVisibility(); +} +void TabbedViewContainerV2::dynamicTabBarVisibility() +{ + qDebug() << "tab bar count:" << _tabBar->count(); + qDebug() << "tab var hidden:" << _tabBar->isHidden(); + + if ( _tabBar->count() > 1 && _tabBar->isHidden() ) + _tabBar->show(); + + if ( _tabBar->count() < 2 && !_tabBar->isHidden() ) + _tabBar->hide(); +} TabbedViewContainerV2::~TabbedViewContainerV2() { _containerWidget->deleteLater(); @@ -418,6 +462,9 @@ void TabbedViewContainerV2::addViewWidget( QWidget* view ) connect( item , SIGNAL(titleChanged(ViewProperties*)) , this , SLOT(updateTitle(ViewProperties*))); connect( item , SIGNAL(iconChanged(ViewProperties*) ) , this ,SLOT(updateIcon(ViewProperties*))); _tabBar->addTab( item->icon() , item->title() ); + + if ( navigationDisplayMode() == ShowNavigationAsNeeded ) + dynamicTabBarVisibility(); } void TabbedViewContainerV2::removeViewWidget( QWidget* view ) { @@ -427,6 +474,9 @@ void TabbedViewContainerV2::removeViewWidget( QWidget* view ) _stackWidget->removeWidget(view); _tabBar->removeTab(index); + + if ( navigationDisplayMode() == ShowNavigationAsNeeded ) + dynamicTabBarVisibility(); } void TabbedViewContainerV2::updateTitle(ViewProperties* item) diff --git a/konsole/ViewContainer.h b/konsole/ViewContainer.h index 21b1d620..6da89465 100644 --- a/konsole/ViewContainer.h +++ b/konsole/ViewContainer.h @@ -68,7 +68,8 @@ class ViewContainer : public QObject Q_OBJECT public: - ViewContainer(QObject* parent) : QObject(parent) {} + /** Constructs a new view container with the specified parent. */ + ViewContainer(QObject* parent); /** * Called when the ViewContainer is destroyed. When reimplementing this in @@ -80,6 +81,22 @@ public: /** Returns the widget which contains the view widgets */ virtual QWidget* containerWidget() const = 0; + /** + * This enum describes the options for showing or hiding the + * container's navigation widget. + */ + enum NavigationDisplayMode + { + AlwaysShowNavigation, + AlwaysHideNavigation, + ShowNavigationAsNeeded + }; + + /** TODO: Document me. */ + void setNavigationDisplayMode(NavigationDisplayMode mode); + /** TODO: Document me. */ + NavigationDisplayMode navigationDisplayMode() const; + /** Adds a new view to the container widget */ void addView(QWidget* view , ViewProperties* navigationItem); @@ -145,7 +162,13 @@ protected: * from the container widget. */ virtual void removeViewWidget(QWidget* view) = 0; - + + /** + * Called when the navigation display mode changes. + * See setNavigationDisplayMode + */ + virtual void navigationDisplayModeChanged(NavigationDisplayMode) {}; + /** Returns the widgets which are associated with a particular navigation item */ QList widgetsForItem( ViewProperties* item ) const; @@ -153,6 +176,7 @@ private slots: void viewDestroyed(QObject* view); private: + NavigationDisplayMode _navigationDisplayMode; QList _views; QHash _navigation; }; @@ -235,6 +259,7 @@ public: protected: virtual void addViewWidget(QWidget* view); virtual void removeViewWidget(QWidget* view); + virtual void navigationDisplayModeChanged(NavigationDisplayMode mode); private slots: void updateTitle(ViewProperties* item); @@ -242,6 +267,8 @@ private slots: void currentTabChanged(int index); private: + void dynamicTabBarVisibility(); + ViewContainerTabBar* _tabBar; QStackedWidget* _stackWidget; QWidget* _containerWidget; diff --git a/konsole/ViewManager.cpp b/konsole/ViewManager.cpp index d84ce20a..084b9d5a 100644 --- a/konsole/ViewManager.cpp +++ b/konsole/ViewManager.cpp @@ -511,6 +511,19 @@ void ViewManager::loadViewSettings(TerminalDisplay* view , Profile* info) colorScheme = ColorSchemeManager::instance()->defaultColorScheme(); Q_ASSERT( colorScheme ); + // menu bar visibility + emit setMenuBarVisible( info->property(Profile::ShowMenuBar).value() ); + + // tab bar visibility + ViewContainer* container = _viewSplitter->activeContainer(); + int tabBarMode = info->property(Profile::TabBarMode).value(); + if ( tabBarMode == Profile::AlwaysHideTabBar ) + container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation); + else if ( tabBarMode == Profile::AlwaysShowTabBar ) + container->setNavigationDisplayMode(ViewContainer::AlwaysShowNavigation); + else if ( tabBarMode == Profile::ShowTabBarAsNeeded ) + container->setNavigationDisplayMode(ViewContainer::ShowNavigationAsNeeded); + // load colour scheme view->setColorTable(colorScheme->colorTable()); diff --git a/konsole/ViewManager.h b/konsole/ViewManager.h index ec509bef..609d2669 100644 --- a/konsole/ViewManager.h +++ b/konsole/ViewManager.h @@ -131,6 +131,9 @@ signals: // 'multipleViews' - true if the manager has multiple containers or false otherwise void splitViewToggle(bool multipleViews); + /** TODO: Document me. */ + void setMenuBarVisible(bool); + private slots: // called when the "Split View Left/Right" menu item is selected void splitLeftRight(); -- GitLab