diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp index d1a63b37f..efaef9bee 100644 --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -280,7 +280,7 @@ void EditProfileDialog::setupTabsPage(const Profile::Ptr info) << i18n("Above Terminal Displays") ); _ui->tabBarPositionCombo->setCurrentIndex(tabPosition); - _ui->newTabButton->setChecked(info->property(Profile::ShowNewTabButton)); + _ui->newTabButton->setChecked(info->property(Profile::ShowNewAndCloseTabButtons)); // signals and slots connect( _ui->tabBarVisibilityCombo , SIGNAL(activated(int)) , this , @@ -309,7 +309,7 @@ void EditProfileDialog::setupTabsPage(const Profile::Ptr info) this , SLOT(insertRemoteTabTitleText(const QString&)) ); } void EditProfileDialog::showNewTabButton(bool show) -{ _tempProfile->setProperty(Profile::ShowNewTabButton,show); } +{ _tempProfile->setProperty(Profile::ShowNewAndCloseTabButtons,show); } void EditProfileDialog::tabBarVisibilityChanged(int newValue) { _tempProfile->setProperty( Profile::TabBarMode , newValue ); diff --git a/src/EditProfileDialog.ui b/src/EditProfileDialog.ui index 12013f7d3..647dfbc25 100644 --- a/src/EditProfileDialog.ui +++ b/src/EditProfileDialog.ui @@ -374,7 +374,7 @@ - Show 'New Tab' button in tab bar + Show 'New Tab' and 'Close Tab' buttons in tab bar diff --git a/src/Profile.cpp b/src/Profile.cpp index 205826797..1d3f19d5d 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -79,7 +79,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = , { TabBarMode , "TabBarMode" , GENERAL_GROUP , QVariant::Int } , { TabBarPosition , "TabBarPosition" , GENERAL_GROUP , QVariant::Int } , { StartInCurrentSessionDir , "StartInCurrentSessionDir" , GENERAL_GROUP , QVariant::Bool } - , { ShowNewTabButton, "ShowNewTabButton" , GENERAL_GROUP , QVariant::Bool } + , { ShowNewAndCloseTabButtons, "ShowNewAndCloseTabButtons" , GENERAL_GROUP , QVariant::Bool } // Appearance , { Font , "Font" , APPEARANCE_GROUP , QVariant::Font } @@ -151,7 +151,7 @@ FallbackProfile::FallbackProfile() setProperty(TabBarPosition,TabBarBottom); setProperty(ShowMenuBar,true); setProperty(StartInCurrentSessionDir,true); - setProperty(ShowNewTabButton,false); + setProperty(ShowNewAndCloseTabButtons,false); setProperty(KeyBindings,"default"); setProperty(ColorScheme,"Linux"); diff --git a/src/Profile.h b/src/Profile.h index 97eddc988..7ba3911d3 100644 --- a/src/Profile.h +++ b/src/Profile.h @@ -190,8 +190,8 @@ public: * currently active session. */ StartInCurrentSessionDir, - /** (bool) Whether a 'New Tab' button should be shown on the tab bar */ - ShowNewTabButton + /** (bool) Whether a 'New Tab' and 'Close Tab' buttons should be shown on the tab bar */ + ShowNewAndCloseTabButtons }; /** diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp index 2057e68b6..175c7c7cd 100644 --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -615,15 +615,22 @@ TabbedViewContainerV2::TabbedViewContainerV2(NavigationPosition position , QObje _stackWidget = new QStackedWidget(); _tabBar = new ViewContainerTabBar(_containerWidget,this); _tabBar->setDrawBase(true); + + const int cornerButtonWidth = 50; _newTabButton = new KPushButton(KIcon("tab-new"),QString(),_containerWidget); // The button width here is hard coded, it would be better to use the value from // the current style (see QTabWidget::setUpLayout()) - _newTabButton->setFixedWidth(50); + _newTabButton->setFixedWidth(cornerButtonWidth); _newTabButton->setFlat(true); // new tab button is initially hidden, it will be shown when setFeatures() is called // with the QuickNewView flag enabled _newTabButton->setHidden(true); + _closeTabButton = new KPushButton(KIcon("tab-close"),QString(),_containerWidget); + _closeTabButton->setFixedWidth(cornerButtonWidth); + _closeTabButton->setFlat(true); + _closeTabButton->setHidden(true); + connect( _tabBar , SIGNAL(currentChanged(int)) , this , SLOT(currentTabChanged(int)) ); connect( _tabBar , SIGNAL(tabDoubleClicked(int)) , this , SLOT(tabDoubleClicked(int)) ); connect( _tabBar , SIGNAL(newTabRequest()) , this , SIGNAL(newViewRequest()) ); @@ -633,6 +640,7 @@ TabbedViewContainerV2::TabbedViewContainerV2(NavigationPosition position , QObje connect( _tabBar , SIGNAL(initiateDrag(int)) , this , SLOT(startTabDrag(int)) ); connect( _newTabButton , SIGNAL(clicked()) , this , SIGNAL(newViewRequest()) ); + connect( _closeTabButton , SIGNAL(clicked()) , this , SLOT(closeCurrentTab()) ); _layout = new TabbedViewContainerV2Layout; _layout->setSpacing(0); @@ -642,7 +650,7 @@ TabbedViewContainerV2::TabbedViewContainerV2(NavigationPosition position , QObje _tabBarLayout->setMargin(0); _tabBarLayout->addWidget(_newTabButton); _tabBarLayout->addWidget(_tabBar); - + _tabBarLayout->addWidget(_closeTabButton); _tabBarSpacer = new QSpacerItem(0,TabBarSpace); _layout->addWidget(_stackWidget); @@ -667,11 +675,15 @@ TabbedViewContainerV2::TabbedViewContainerV2(NavigationPosition position , QObje void TabbedViewContainerV2::setNewViewMenu(QMenu* menu) { _newTabButton->setDelayedMenu(menu); } ViewContainer::Features TabbedViewContainerV2::supportedFeatures() const -{ return QuickNewView; } +{ return QuickNewView|QuickCloseView; } void TabbedViewContainerV2::setFeatures(Features features) { ViewContainer::setFeatures(features); + const bool tabBarVisible = _tabBar->isVisible(); + _newTabButton->setVisible(tabBarVisible && (features & QuickNewView)); + _closeTabButton->setVisible(tabBarVisible && (features & QuickCloseView)); +#if 0 if (features & QuickNewView) { _newTabButton->setHidden(false); @@ -680,10 +692,28 @@ void TabbedViewContainerV2::setFeatures(Features features) else _newTabButton->setHidden(true); + if (features & QuickCloseView) + { + _closeTabButton->setHidden(false); + _closeTabButton->show(); + } + else + _closeTabButton->setHidden(true); +#endif +#if 0 if (features & QuickCloseView) _tabBar->setCloseButtonEnabled(true); else _tabBar->setCloseButtonEnabled(false); +#endif + +} +void TabbedViewContainerV2::closeCurrentTab() +{ + if (_stackWidget->currentIndex() != -1) + { + closeTab(_stackWidget->currentIndex()); + } } void TabbedViewContainerV2::closeTab(int tab) { @@ -695,7 +725,8 @@ void TabbedViewContainerV2::closeTab(int tab) void TabbedViewContainerV2::setTabBarVisible(bool visible) { _tabBar->setVisible(visible); - _newTabButton->setVisible(visible); + _newTabButton->setVisible(visible && (features() & QuickNewView)); + _closeTabButton->setVisible(visible && (features() & QuickCloseView)); if ( visible ) { _tabBarSpacer->changeSize(0,TabBarSpace); diff --git a/src/ViewContainer.h b/src/ViewContainer.h index 882188313..f3df3e64a 100644 --- a/src/ViewContainer.h +++ b/src/ViewContainer.h @@ -227,7 +227,7 @@ public: /** Provides a button which can be clicked to create new views quickly. * When the button is clicked, a newViewRequest() signal is emitted. */ QuickNewView = 1, - /** Provides a button or buttons which can be clicked to close views quickly. */ + /** Provides a button which can be clicked to close views quickly. */ QuickCloseView = 2 }; Q_DECLARE_FLAGS(Features,Feature) @@ -473,6 +473,7 @@ private slots: void updateActivity(ViewProperties* item); void currentTabChanged(int index); void closeTab(int index); + void closeCurrentTab(); void wheelScrolled(int delta); void tabDoubleClicked(int index); @@ -490,6 +491,7 @@ private: TabbedViewContainerV2Layout* _layout; QHBoxLayout* _tabBarLayout; KPushButton* _newTabButton; + KPushButton* _closeTabButton; static const int TabBarSpace = 2; }; diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 93567d61b..6ad135554 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -584,7 +584,6 @@ ViewContainer* ViewManager::createContainer(const Profile::Ptr info) default: container = new StackedViewContainer(_viewSplitter); } - container->setFeatures(ViewContainer::QuickCloseView); // connect signals and slots connect( container , SIGNAL(viewAdded(QWidget*,ViewProperties*)) , _containerSignalMapper , @@ -715,7 +714,7 @@ void ViewManager::applyProfile(TerminalDisplay* view , const Profile::Ptr info, ViewContainer* container = _viewSplitter->activeContainer(); int tabBarMode = info->property(Profile::TabBarMode); int tabBarPosition = info->property(Profile::TabBarPosition); - bool showNewTabButton = info->property(Profile::ShowNewTabButton); + bool showNewCloseButtons = info->property(Profile::ShowNewAndCloseTabButtons); if ( tabBarMode == Profile::AlwaysHideTabBar ) container->setNavigationDisplayMode(ViewContainer::AlwaysHideNavigation); @@ -734,14 +733,15 @@ void ViewManager::applyProfile(TerminalDisplay* view , const Profile::Ptr info, if ( container->supportedNavigationPositions().contains(position) ) container->setNavigationPosition(position); - if (showNewTabButton && - (container->supportedFeatures() & ViewContainer::QuickNewView)) + if (showNewCloseButtons) { - container->setFeatures(container->features() | ViewContainer::QuickNewView); + container->setFeatures(container->features() + | ViewContainer::QuickNewView | ViewContainer::QuickCloseView); container->setNewViewMenu(createNewViewMenu()); } else - container->setFeatures(container->features() & ~ViewContainer::QuickNewView); + container->setFeatures(container->features() + & ~ViewContainer::QuickNewView & ~ViewContainer::QuickCloseView); } // load colour scheme