diff --git a/src/Application.cpp b/src/Application.cpp --- a/src/Application.cpp +++ b/src/Application.cpp @@ -422,18 +422,6 @@ if (m_parser->isSet(QStringLiteral("fullscreen"))) { window->viewFullScreen(true); } - - // override default tabbbar visibility - // FIXME: remove those magic number - // see ViewContainer::NavigationVisibility - if (m_parser->isSet(QStringLiteral("show-tabbar"))) { - // always show - window->viewManager()->setNavigationVisibility(0); - } - if (m_parser->isSet(QStringLiteral("hide-tabbar"))) { - // never show - window->viewManager()->setNavigationVisibility(2); - } } return window; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -93,7 +93,6 @@ TerminalDisplay.cpp TerminalDisplayAccessible.cpp ViewContainer.cpp - ViewContainerTabBar.cpp ViewManager.cpp ViewProperties.cpp ViewSplitter.cpp diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -764,11 +764,7 @@ removeMenuAccelerators(); } - _viewManager->setNavigationVisibility(KonsoleSettings::tabBarVisibility()); _viewManager->setNavigationPosition(KonsoleSettings::tabBarPosition()); - _viewManager->setNavigationBehavior(KonsoleSettings::newTabBehavior()); - _viewManager->setNavigationTabWidthExpanding(KonsoleSettings::expandTabWidth()); - _viewManager->setShowQuickButtons(KonsoleSettings::showQuickButtons()); if (KonsoleSettings::tabBarUseUserStyleSheet()) { setNavigationStyleSheetFromFile(KonsoleSettings::tabBarUserStyleSheetFile()); diff --git a/src/ViewContainer.h b/src/ViewContainer.h --- a/src/ViewContainer.h +++ b/src/ViewContainer.h @@ -27,29 +27,23 @@ #include #include #include +#include // Konsole #include "Profile.h" -class QStackedWidget; -class QWidget; -class QHBoxLayout; -class QVBoxLayout; - -// TabbedViewContainer // Qt class QPoint; class QToolButton; class QMenu; class QDropEvent; -// KDE -class QMenu; - namespace Konsole { class IncrementalSearchBar; class ViewProperties; +class ViewManager; class TabbedViewContainer; + /** * An interface for container widgets which can hold one or more views. * @@ -60,123 +54,25 @@ * to actually add or remove view widgets from the container widget, as well * as updating any navigation aids. */ -class ViewContainer : public QObject +class TabbedViewContainer : public QTabWidget { Q_OBJECT public: - /** - * This enum describes the options for positioning the - * container's navigation widget. - */ - enum NavigationPosition { - /** Position the navigation widget above the views. */ - NavigationPositionTop, - /** Position the navigation widget below the views. */ - NavigationPositionBottom, - /** Position the navigation widget to the left of the views. */ - NavigationPositionLeft, - /** Position the navigation widget to the right of the views. */ - NavigationPositionRight - }; - /** * Constructs a new view container with the specified parent. * * @param position The initial position of the navigation widget * @param parent The parent object of the container */ - ViewContainer(NavigationPosition position, QObject *parent); + TabbedViewContainer(ViewManager *connectedViewManager, QWidget *parent); /** * Called when the ViewContainer is destroyed. When reimplementing this in * subclasses, use object->deleteLater() to delete any widgets or other objects * instead of 'delete object'. */ - ~ViewContainer() Q_DECL_OVERRIDE; - - /** 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 NavigationVisibility { - /** Always show the navigation widget. */ - AlwaysShowNavigation, - /** Show the navigation widget only when the container has more than one view. */ - ShowNavigationAsNeeded, - /** Always hide the navigation widget. */ - AlwaysHideNavigation - }; - /* - * Sets the visibility of the view container's navigation widget. - * - * The ViewContainer sub-class is responsible for ensuring that this - * setting is respected as views are added or removed from the - * container. - * - * ViewContainer sub-classes should reimplement the - * navigationVisibilityChanged() method to respond to changes - * of this property. - */ - void setNavigationVisibility(NavigationVisibility mode); - /** - * Returns the current mode for controlling the visibility of the - * the view container's navigation widget. - */ - NavigationVisibility navigationVisibility() const; - - /** - * Sets the position of the navigation widget with - * respect to the main content area. - * - * Depending on the ViewContainer subclass, not all - * positions from the NavigationPosition enum may be - * supported. A list of supported positions can be - * obtained by calling supportedNavigationPositions() - * - * ViewContainer sub-classes should re-implement the - * navigationPositionChanged() method to respond - * to changes of this property. - */ - void setNavigationPosition(NavigationPosition position); - - /** - * Returns the position of the navigation widget with - * respect to the main content area. - */ - NavigationPosition navigationPosition() const; - - /** - * Set whether tab width are expanding - */ - void setNavigationTabWidthExpanding(bool expand); - - /** - * Returns the list of supported navigation positions. - * The supported positions will depend upon the type of the - * navigation widget used by the ViewContainer subclass. - * - * The base implementation returns one item, NavigationPositionTop - */ - virtual QList supportedNavigationPositions() const; - - /** Sets the navigation text mode - * If mode is true, use the width of the title; otherwise use the - * default width calculations. - */ - void setNavigationTextMode(bool mode); - - /** Sets the stylesheet for visual appearance - * - * The default implementation does nothing. - */ - virtual void setStyleSheet(const QString &styleSheet) - { - Q_UNUSED(styleSheet); - } + ~TabbedViewContainer() Q_DECL_OVERRIDE; /** Adds a new view to the container widget */ void addView(QWidget *view, ViewProperties *navigationItem, int index = -1); @@ -186,26 +82,11 @@ /** Returns the ViewProperties instance associated with a particular view in the container */ ViewProperties *viewProperties(QWidget *view) const; + void setTabActivity(int index, bool activity); - /** Returns a list of the contained views */ - const QList views() const; - - /** - * Returns the view which currently has the focus or 0 if none - * of the child views have the focus. - */ - virtual QWidget *activeView() const = 0; - - /** - * Changes the focus to the specified view and updates - * navigation aids to reflect the change. - */ - virtual void setActiveView(QWidget *widget) = 0; - - /** - * @return the search widget for this view - */ - IncrementalSearchBar *searchBar(); + void updateTitle(ViewProperties *item); + void updateIcon(ViewProperties *item); + void updateActivity(ViewProperties *item); /** Changes the active view to the next view */ void activateNextView(); @@ -237,52 +118,32 @@ */ void moveActiveView(MoveDirection direction); - /** Enum describing extra UI features which can be - * provided by the container. */ - enum Feature { - /** 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 which can be clicked to close views quickly. */ - QuickCloseView = 2 - }; - Q_DECLARE_FLAGS(Features, Feature) - /** - * Sets which additional features are enabled in this container. - * The default implementation does thing. Sub-classes should re-implement this - * to hide or show the relevant parts of their UI - */ - virtual void setFeatures(Features features); - /** Returns a bitwise-OR of enabled extra UI features. See setFeatures() */ - Features features() const; - /** Returns a bitwise-OR of supported extra UI features. The default - * implementation returns 0 (no extra features) */ - virtual Features supportedFeatures() const - { - return nullptr; - } - /** Sets the menu to be shown when the new view button is clicked. * Only valid if the QuickNewView feature is enabled. * The default implementation does nothing. */ - virtual void setNewViewMenu(QMenu *menu) - { - Q_UNUSED(menu); - } + // TODO: Reenable this later. + // void setNewViewMenu(QMenu *menu); + void renameTab(int index); + ViewManager *connectedViewManager(); + void currentTabChanged(int index); + void closeCurrentTab(); + void wheelScrolled(int delta); -Q_SIGNALS: - /** Emitted when the container is deleted */ - void destroyed(ViewContainer *container); + void tabDoubleClicked(int index); + void openTabContextMenu(const QPoint &point); +Q_SIGNALS: /** Emitted when the container has no more children */ - void empty(ViewContainer *container); + void empty(TabbedViewContainer *container); /** Emitted when the user requests to open a new view */ void newViewRequest(); /** Requests creation of a new view, with the selected profile. */ void newViewRequest(Profile::Ptr); + void closeTab(TabbedViewContainer *tabbedViewContainer, QWidget *index); + /** * Emitted when the user requests to move a view from another container * into this container. If 'success' is set to true by a connected slot @@ -312,41 +173,12 @@ * Performs the task of adding the view widget * to the container widget. */ - virtual void addViewWidget(QWidget *view, int index) = 0; + void addViewWidget(QWidget *view, int index); /** * Performs the task of removing the view widget * from the container widget. */ - virtual void removeViewWidget(QWidget *view) = 0; - - /** - * Called when the navigation display mode changes. - * See setNavigationVisibility - */ - virtual void navigationVisibilityChanged(NavigationVisibility) - { - } - - /** - * Called when the navigation tab width expanding option changes. - * See setNavigationTabWidthExpanding - */ - virtual void navigationTabWidthExpandingChanged(bool) - { - } - - /** - * Called when the navigation position changes to re-layout - * the container and place the navigation widget in the - * specified position. - */ - virtual void navigationPositionChanged(NavigationPosition) - { - } - - virtual void navigationTextModeChanged(bool) - { - } + void removeViewWidget(QWidget *view); /** Returns the widgets which are associated with a particular navigation item */ QList widgetsForItem(ViewProperties *item) const; @@ -357,110 +189,19 @@ * @param fromIndex Current index of the widget to move * @param toIndex New index for the widget */ - virtual void moveViewWidget(int fromIndex, int toIndex); + void moveViewWidget(int fromIndex, int toIndex); private Q_SLOTS: void viewDestroyed(QObject *view); - void searchBarDestroyed(); private: - Q_DISABLE_COPY(ViewContainer) - void forgetView(QWidget *view); - NavigationVisibility _navigationVisibility; - NavigationPosition _navigationPosition; - QList _views; QHash _navigation; - Features _features; - IncrementalSearchBar *_searchBar; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(ViewContainer::Features) - -class ViewContainerTabBar; -class ViewManager; - -/** - * An alternative tabbed view container which uses a QTabBar and QStackedWidget - * combination for navigation instead of QTabWidget - */ -class TabbedViewContainer : public ViewContainer -{ - Q_OBJECT - -public: - /** - * Constructs a new tabbed view container. Supported positions - * are NavigationPositionTop and NavigationPositionBottom. - */ - TabbedViewContainer(NavigationPosition position, ViewManager *connectedViewManager, - QObject *parent); - ~TabbedViewContainer() Q_DECL_OVERRIDE; - - QWidget *containerWidget() const Q_DECL_OVERRIDE; - QWidget *activeView() const Q_DECL_OVERRIDE; - void setActiveView(QWidget *view) Q_DECL_OVERRIDE; - QList supportedNavigationPositions() const Q_DECL_OVERRIDE; - void setFeatures(Features features) Q_DECL_OVERRIDE; - Features supportedFeatures() const Q_DECL_OVERRIDE; - void setNewViewMenu(QMenu *menu) Q_DECL_OVERRIDE; - void setStyleSheet(const QString &styleSheet) Q_DECL_OVERRIDE; - void setTabBarVisible(bool visible); - - // return associated view manager - ViewManager *connectedViewManager(); - -protected: - void addViewWidget(QWidget *view, int index) Q_DECL_OVERRIDE; - void removeViewWidget(QWidget *view) Q_DECL_OVERRIDE; - void navigationVisibilityChanged(NavigationVisibility mode) Q_DECL_OVERRIDE; - void navigationPositionChanged(NavigationPosition position) Q_DECL_OVERRIDE; - void navigationTabWidthExpandingChanged(bool expand) Q_DECL_OVERRIDE; - void navigationTextModeChanged(bool useTextWidth) Q_DECL_OVERRIDE; - void moveViewWidget(int fromIndex, int toIndex) Q_DECL_OVERRIDE; - -private Q_SLOTS: - void updateTitle(ViewProperties *item); - void updateIcon(ViewProperties *item); - void updateActivity(ViewProperties *item); - void currentTabChanged(int index); - void closeCurrentTab(); - void wheelScrolled(int delta); - - void tabDoubleClicked(int index); - void openTabContextMenu(const QPoint &point); - void tabContextMenuCloseTab(); - void tabContextMenuRenameTab(); - void tabContextMenuDetachTab(); - void startTabDrag(int index); - void querySourceIndex(const QDropEvent *event, int &sourceIndex); - void onMoveViewRequest(int index, const QDropEvent *event, bool &success, - TabbedViewContainer *sourceTabbedContainer); - -Q_SIGNALS: - void detachTab(ViewContainer *self, QWidget *activeView); - void closeTab(ViewContainer *self, QWidget *activeView); - -private: - Q_DISABLE_COPY(TabbedViewContainer) - - void dynamicTabBarVisibility(); - void setTabActivity(int index, bool activity); - void renameTab(int index); - void updateVisibilityOfQuickButtons(); - void widgetRemoved(int index); - - ViewContainerTabBar *_tabBar; - QPointer _stackWidget; - QPointer _containerWidget; ViewManager *_connectedViewManager; - QVBoxLayout *_layout; - QHBoxLayout *_tabBarLayout; - QToolButton *_newTabButton; - QToolButton *_closeTabButton; - int _contextMenuTabIndex; QMenu *_contextPopupMenu; }; + } #endif //VIEWCONTAINER_H diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -21,29 +21,21 @@ // Own #include "ViewContainer.h" - #include // Qt -#include -#include -#include -#include -#include -#include -#include +#include +#include // KDE #include #include #include #include -#include // Konsole #include "IncrementalSearchBar.h" #include "ViewProperties.h" -#include "ViewContainerTabBar.h" #include "ProfileList.h" #include "ViewManager.h" #include "KonsoleSettings.h" @@ -53,266 +45,19 @@ using namespace Konsole; -ViewContainer::ViewContainer(NavigationPosition position, QObject *parent) : - QObject(parent), - _navigationVisibility(AlwaysShowNavigation), - _navigationPosition(position), - _views(QList()), - _navigation(QHash()), - _features(nullptr), - _searchBar(nullptr) -{ -} - -ViewContainer::~ViewContainer() -{ - foreach (QWidget *view, _views) { - disconnect(view, &QWidget::destroyed, this, &Konsole::ViewContainer::viewDestroyed); - } - - if (_searchBar != nullptr) { - _searchBar->deleteLater(); - } - - emit destroyed(this); -} - -void ViewContainer::moveViewWidget(int, int) -{ -} - -void ViewContainer::setFeatures(Features features) -{ - _features = features; -} - -ViewContainer::Features ViewContainer::features() const -{ - return _features; -} - -void ViewContainer::moveActiveView(MoveDirection direction) -{ - const int currentIndex = _views.indexOf(activeView()); - int newIndex = -1; - - switch (direction) { - case MoveViewLeft: - newIndex = qMax(currentIndex - 1, 0); - break; - case MoveViewRight: - newIndex = qMin(currentIndex + 1, _views.count() - 1); - break; - } - - Q_ASSERT(newIndex != -1); - - moveViewWidget(currentIndex, newIndex); - - _views.swap(currentIndex, newIndex); - - setActiveView(_views[newIndex]); -} - -void ViewContainer::setNavigationVisibility(NavigationVisibility mode) -{ - _navigationVisibility = mode; - navigationVisibilityChanged(mode); -} - -ViewContainer::NavigationPosition ViewContainer::navigationPosition() const -{ - return _navigationPosition; -} - -void ViewContainer::setNavigationPosition(NavigationPosition position) -{ - // assert that this position is supported - Q_ASSERT(supportedNavigationPositions().contains(position)); - - _navigationPosition = position; - - navigationPositionChanged(position); -} - -QList ViewContainer::supportedNavigationPositions() const -{ - return QList() << NavigationPositionTop; -} - -void ViewContainer::setNavigationTabWidthExpanding(bool expand) -{ - navigationTabWidthExpandingChanged(expand); -} - -ViewContainer::NavigationVisibility ViewContainer::navigationVisibility() const -{ - return _navigationVisibility; -} - -void ViewContainer::setNavigationTextMode(bool mode) -{ - navigationTextModeChanged(mode); -} - -void ViewContainer::addView(QWidget *view, ViewProperties *item, int index) -{ - if (index == -1) { - _views.append(view); - } else { - _views.insert(index, view); - } - - _navigation[view] = item; - - connect(view, &QWidget::destroyed, this, &Konsole::ViewContainer::viewDestroyed); - - addViewWidget(view, index); - - emit viewAdded(view, item); -} - -void ViewContainer::viewDestroyed(QObject *view) -{ - QWidget *widget = qobject_cast(view); - forgetView(widget); -} - -void ViewContainer::forgetView(QWidget *view) -{ - _views.removeAll(view); - _navigation.remove(view); - - emit viewRemoved(view); - - if (_views.count() == 0) { - emit empty(this); - } -} - -void ViewContainer::removeView(QWidget *view) -{ - disconnect(view, &QWidget::destroyed, this, &Konsole::ViewContainer::viewDestroyed); - removeViewWidget(view); - forgetView(view); -} - -const QList ViewContainer::views() const -{ - return _views; -} - -IncrementalSearchBar *ViewContainer::searchBar() -{ - if (_searchBar == nullptr) { - _searchBar = new IncrementalSearchBar(nullptr); - _searchBar->setVisible(false); - connect(_searchBar, &Konsole::IncrementalSearchBar::destroyed, this, - &Konsole::ViewContainer::searchBarDestroyed); - } - return _searchBar; -} - -void ViewContainer::searchBarDestroyed() -{ - _searchBar = nullptr; -} - -void ViewContainer::activateNextView() -{ - QWidget *active = activeView(); - - int index = _views.indexOf(active); - - if (index == -1) { - return; - } - - if (index == _views.count() - 1) { - index = 0; - } else { - index++; - } - - setActiveView(_views.at(index)); -} - -void ViewContainer::activateLastView() -{ - setActiveView(_views.at(_views.count() - 1)); -} - -void ViewContainer::activatePreviousView() -{ - QWidget *active = activeView(); - - int index = _views.indexOf(active); - - if (index == -1) { - return; - } - - if (index == 0) { - index = _views.count() - 1; - } else { - index--; - } - - setActiveView(_views.at(index)); -} - -ViewProperties *ViewContainer::viewProperties(QWidget *view) const -{ - Q_ASSERT(_navigation.contains(view)); - - return _navigation[view]; -} - -QList ViewContainer::widgetsForItem(ViewProperties *item) const +TabbedViewContainer::TabbedViewContainer(ViewManager *connectedViewManager, QWidget *parent) : + QTabWidget(parent), + _connectedViewManager(connectedViewManager) { - return _navigation.keys(item); -} + tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); -TabbedViewContainer::TabbedViewContainer(NavigationPosition position, - ViewManager *connectedViewManager, QObject *parent) : - ViewContainer(position, parent), - _tabBar(nullptr), - _stackWidget(nullptr), - _containerWidget(nullptr), - _connectedViewManager(connectedViewManager), - _layout(nullptr), - _tabBarLayout(nullptr), - _newTabButton(nullptr), - _closeTabButton(nullptr), - _contextMenuTabIndex(0), - _contextPopupMenu(nullptr) -{ - _containerWidget = new QWidget; - _stackWidget = new QStackedWidget(); - connect(_stackWidget.data(), &QStackedWidget::widgetRemoved, this, - &TabbedViewContainer::widgetRemoved); - - // The tab bar - _tabBar = new ViewContainerTabBar(_containerWidget, this); - _tabBar->setContextMenuPolicy(Qt::CustomContextMenu); - _tabBar->setSupportedMimeType(ViewProperties::mimeType()); - - connect(_tabBar, &Konsole::ViewContainerTabBar::currentChanged, this, - &Konsole::TabbedViewContainer::currentTabChanged); - connect(_tabBar, &Konsole::ViewContainerTabBar::tabBarDoubleClicked, this, + connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, &Konsole::TabbedViewContainer::tabDoubleClicked); - connect(_tabBar, &Konsole::ViewContainerTabBar::querySourceIndex, this, - &Konsole::TabbedViewContainer::querySourceIndex); - connect(_tabBar, &Konsole::ViewContainerTabBar::moveViewRequest, this, - &Konsole::TabbedViewContainer::onMoveViewRequest); - connect(_tabBar, &Konsole::ViewContainerTabBar::customContextMenuRequested, this, + connect(tabBar(), &QTabBar::customContextMenuRequested, this, &Konsole::TabbedViewContainer::openTabContextMenu); - connect(_tabBar, &Konsole::ViewContainerTabBar::initiateDrag, this, - &Konsole::TabbedViewContainer::startTabDrag); - // The context menu of tab bar - _contextPopupMenu = new QMenu(_tabBar); + _contextPopupMenu = new QMenu(tabBar()); connect(_contextPopupMenu, &QMenu::aboutToHide, this, [this]() { // Remove the read-only action when the popup closes for (auto &action : _contextPopupMenu->actions()) { @@ -324,288 +69,127 @@ }); #if defined(ENABLE_DETACHING) - _contextPopupMenu->addAction(QIcon::fromTheme(QStringLiteral("tab-detach")), - i18nc("@action:inmenu", "&Detach Tab"), this, - SLOT(tabContextMenuDetachTab())); +// _contextPopupMenu->addAction(QIcon::fromTheme(QStringLiteral("tab-detach")), +// i18nc("@action:inmenu", "&Detach Tab"), this, +// SLOT(tabContextMenuDetachTab())); #endif _contextPopupMenu->addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18nc("@action:inmenu", "&Rename Tab..."), this, SLOT(tabContextMenuRenameTab())); const auto contextPopupMenuActions = _contextPopupMenu->actions(); contextPopupMenuActions.last()->setObjectName(QStringLiteral("edit-rename")); - _contextPopupMenu->addSeparator(); - - _contextPopupMenu->addAction(QIcon::fromTheme(QStringLiteral("tab-close")), - i18nc("@action:inmenu", "&Close Tab"), this, - SLOT(tabContextMenuCloseTab())); - // The 'new tab' and 'close tab' button - _newTabButton = new QToolButton(_containerWidget); - _newTabButton->setFocusPolicy(Qt::NoFocus); - _newTabButton->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); - _newTabButton->setToolTip(i18nc("@info:tooltip", "Create new tab")); - _newTabButton->setWhatsThis(i18nc("@info:whatsthis", - "Create a new tab. Press and hold to select profile from menu")); - _newTabButton->adjustSize(); - - auto profileMenu = new QMenu(_newTabButton); + auto profileMenu = new QMenu(); auto profileList = new ProfileList(false, profileMenu); profileList->syncWidgetActions(profileMenu, true); connect(profileList, &Konsole::ProfileList::profileSelected, this, - static_cast(&Konsole::TabbedViewContainer:: - newViewRequest)); - setNewViewMenu(profileMenu); - - _closeTabButton = new QToolButton(_containerWidget); - _closeTabButton->setFocusPolicy(Qt::NoFocus); - _closeTabButton->setIcon(QIcon::fromTheme(QStringLiteral("tab-close"))); - _closeTabButton->setToolTip(i18nc("@info:tooltip", "Close tab")); - _closeTabButton->setWhatsThis(i18nc("@info:whatsthis", "Close the active tab")); - _closeTabButton->adjustSize(); - - // 'new tab' button is initially hidden. It will be shown when setFeatures() - // is called with the QuickNewView flag enabled. The 'close tab' is the same. - _newTabButton->setHidden(true); - _closeTabButton->setHidden(true); - - connect(_newTabButton, &QToolButton::clicked, this, - static_cast(&Konsole::TabbedViewContainer::newViewRequest)); - connect(_closeTabButton, &QToolButton::clicked, this, - &Konsole::TabbedViewContainer::closeCurrentTab); - - // Combine tab bar and 'new/close tab' buttons - _tabBarLayout = new QHBoxLayout; - _tabBarLayout->setSpacing(0); - _tabBarLayout->setContentsMargins(0, 0, 0, 0); - _tabBarLayout->addWidget(_newTabButton); - _tabBarLayout->addWidget(_tabBar); - _tabBarLayout->addWidget(_closeTabButton); - - // The search bar - searchBar()->setParent(_containerWidget); - - // The overall layout - _layout = new QVBoxLayout; - _layout->setSpacing(0); - _layout->setContentsMargins(0, 0, 0, 0); - - setNavigationPosition(position); - - _containerWidget->setLayout(_layout); + static_cast(&Konsole::TabbedViewContainer::newViewRequest)); + // setNewViewMenu(profileMenu); } -void TabbedViewContainer::setNewViewMenu(QMenu *menu) +TabbedViewContainer::~TabbedViewContainer() { - _newTabButton->setMenu(menu); -} + for(int i = 0, end = count(); i < end; i++) { + auto view = widget(i); + disconnect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); + } -ViewContainer::Features TabbedViewContainer::supportedFeatures() const -{ - return QuickNewView | QuickCloseView; + emit destroyed(this); } -void TabbedViewContainer::setFeatures(Features features) +void TabbedViewContainer::moveActiveView(MoveDirection direction) { - ViewContainer::setFeatures(features); - updateVisibilityOfQuickButtons(); -} + const int currentIndex = indexOf(currentWidget()); + int newIndex = -1; -void TabbedViewContainer::closeCurrentTab() -{ - if (_stackWidget->currentIndex() != -1) { - emit closeTab(this, _stackWidget->widget(_stackWidget->currentIndex())); + switch (direction) { + case MoveViewLeft: + newIndex = qMax(currentIndex - 1, 0); + break; + case MoveViewRight: + newIndex = qMin(currentIndex + 1, count() - 1); + break; } -} -void TabbedViewContainer::updateVisibilityOfQuickButtons() -{ - const bool tabBarHidden = _tabBar->isHidden(); - _newTabButton->setVisible(!tabBarHidden && ((features() & QuickNewView) != 0)); - _closeTabButton->setVisible(!tabBarHidden && ((features() & QuickCloseView) != 0)); -} - -void TabbedViewContainer::setTabBarVisible(bool visible) -{ - _tabBar->setVisible(visible); - updateVisibilityOfQuickButtons(); -} - -QList TabbedViewContainer::supportedNavigationPositions() const -{ - return QList() << NavigationPositionTop << NavigationPositionBottom; + Q_ASSERT(newIndex != -1); + auto swappedWidget = widget(newIndex); + auto currentWidget = widget(currentIndex); + removeTab(newIndex); + removeTab(currentIndex); } -void TabbedViewContainer::navigationPositionChanged(NavigationPosition position) +void TabbedViewContainer::addView(QWidget *view, ViewProperties *item, int index) { - // this method assumes that there are three or zero items in the layout - Q_ASSERT(_layout->count() == 3 || _layout->count() == 0); - - // clear all existing items from the layout - _layout->removeItem(_tabBarLayout); - _tabBarLayout->setParent(nullptr); // suppress the warning of "already has a parent" - _layout->removeWidget(_stackWidget); - _layout->removeWidget(searchBar()); - - if (position == NavigationPositionTop) { - _layout->insertLayout(-1, _tabBarLayout); - _layout->insertWidget(-1, _stackWidget); - _layout->insertWidget(-1, searchBar()); - _tabBar->setShape(QTabBar::RoundedNorth); - } else if (position == NavigationPositionBottom) { - _layout->insertWidget(-1, _stackWidget); - _layout->insertWidget(-1, searchBar()); - _layout->insertLayout(-1, _tabBarLayout); - _tabBar->setShape(QTabBar::RoundedSouth); + if (index == -1) { + addTab(view, item->icon(), item->title()); } else { - Q_ASSERT(false); // should never reach here + insertTab(index, view, item->icon(), item->title()); } + + _navigation[view] = item; + connect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); + emit viewAdded(view, item); } -void TabbedViewContainer::navigationTabWidthExpandingChanged(bool expand) +void TabbedViewContainer::viewDestroyed(QObject *view) { - _tabBar->setExpanding(expand); + QWidget *widget = qobject_cast(view); + forgetView(widget); } -void TabbedViewContainer::navigationVisibilityChanged(NavigationVisibility mode) +void TabbedViewContainer::forgetView(QWidget *view) { - if (mode == AlwaysShowNavigation && _tabBar->isHidden()) { - setTabBarVisible(true); - } - - if (mode == AlwaysHideNavigation && !_tabBar->isHidden()) { - setTabBarVisible(false); - } - - if (mode == ShowNavigationAsNeeded) { - dynamicTabBarVisibility(); + _navigation.remove(view); + emit viewRemoved(view); + if (count() == 0) { + emit empty(this); } } -void TabbedViewContainer::dynamicTabBarVisibility() +void TabbedViewContainer::removeView(QWidget *view) { - if (_tabBar->count() > 1 && _tabBar->isHidden()) { - setTabBarVisible(true); - } - - if (_tabBar->count() < 2 && !_tabBar->isHidden()) { - setTabBarVisible(false); - } + const int idx = indexOf(view); + disconnect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); + removeTab(idx); + forgetView(view); } -void TabbedViewContainer::setStyleSheet(const QString &styleSheet) +void TabbedViewContainer::activateNextView() { - _tabBar->setStyleSheet(styleSheet); + QWidget *active = currentWidget(); + int index = indexOf(active); + setCurrentIndex(index == count() - 1 ? 0 : index + 1); } -// TODO: Only called via dbus method - remove -void TabbedViewContainer::navigationTextModeChanged(bool useTextWidth) +void TabbedViewContainer::activateLastView() { - // Qt 5.9 changed how tabs are displayed - if (useTextWidth) { - _tabBar->setStyleSheet(QStringLiteral("QTabBar::tab { }")); - _tabBar->setExpanding(false); - _tabBar->setElideMode(Qt::ElideNone); - } else { - _tabBar->setStyleSheet(QStringLiteral("QTabBar::tab { min-width: 2em; max-width: 25em }")); - _tabBar->setExpanding(true); - _tabBar->setElideMode(Qt::ElideLeft); - } + setCurrentIndex(count() - 1); } -TabbedViewContainer::~TabbedViewContainer() +void TabbedViewContainer::activatePreviousView() { - if (!_containerWidget.isNull()) { - _containerWidget->deleteLater(); - } + QWidget *active = currentWidget(); + int index = indexOf(active); + setCurrentIndex(index == 0 ? count() - 1 : index - 1); } -void TabbedViewContainer::startTabDrag(int index) +ViewProperties *TabbedViewContainer::viewProperties(QWidget *view) const { - QPointer drag = new QDrag(_tabBar); - const QRect tabRect = _tabBar->tabRect(index); - QPixmap tabPixmap = _tabBar->dragDropPixmap(index); - - drag->setPixmap(tabPixmap); - - // offset the tab position so the tab will follow the cursor exactly - // where it was clicked (as opposed to centering on the origin of the pixmap) - QPoint mappedPos = _tabBar->mapFromGlobal(QCursor::pos()); - mappedPos.rx() -= tabRect.x(); - - drag->setHotSpot(mappedPos); - - const int id = viewProperties(views()[index])->identifier(); - QWidget *view = views()[index]; - drag->setMimeData(ViewProperties::createMimeData(id)); - - // start dragging - const Qt::DropAction action = drag->exec(); - - if ((!drag.isNull()) && (drag->target() != nullptr)) { - switch (action) { - case Qt::MoveAction: - // The MoveAction indicates the widget has been successfully - // moved into another tabbar/container, so remove the widget in - // current tabbar/container. - // - // Deleting the view may cause the view container to be deleted, - // which will also delete the QDrag object. This can cause a - // crash if Qt's internal drag-and-drop handling tries to delete - // it later. - // - // For now set the QDrag's parent to 0 so that it won't be - // deleted if this view container is destroyed. - // - // FIXME: Resolve this properly - drag->setParent(nullptr); - removeView(view); - break; - case Qt::IgnoreAction: - // The IgnoreAction is used by the tabbar to indicate the - // special case of dropping one tab into its existing position. - // So nothing need to do here. - break; - default: - break; - } - } else { - // if the tab is dragged onto something that does not accept this - // drop(for example, a different application or a different konsole - // process), then detach the tab to achieve the effect of "dragging tab - // out of current window and into its own window" - // - // It feels unnatural to do the detach when this is only one tab in the - // tabbar - if (_tabBar->count() > 1) { - emit detachTab(this, view); - } - } - delete drag; + Q_ASSERT(_navigation.contains(view)); + return _navigation[view]; } -void TabbedViewContainer::querySourceIndex(const QDropEvent *event, int &sourceIndex) +QList TabbedViewContainer::widgetsForItem(ViewProperties *item) const { - const int droppedId = ViewProperties::decodeMimeData(event->mimeData()); - - const QList viewList = views(); - const int count = viewList.count(); - int index = -1; - for (index = 0; index < count; index++) { - const int id = viewProperties(viewList[index])->identifier(); - if (id == droppedId) { - break; - } - } - - sourceIndex = index; + return _navigation.keys(item); } -void TabbedViewContainer::onMoveViewRequest(int index, const QDropEvent *event, bool &success, - TabbedViewContainer *sourceTabbedContainer) +void TabbedViewContainer::closeCurrentTab() { - const int droppedId = ViewProperties::decodeMimeData(event->mimeData()); - emit moveViewRequest(index, droppedId, success, sourceTabbedContainer); + if (currentIndex() != -1) { + emit closeTab(this, widget(currentIndex())); + } } void TabbedViewContainer::tabDoubleClicked(int index) @@ -619,29 +203,32 @@ void TabbedViewContainer::renameTab(int index) { - viewProperties(views()[index])->rename(); + // TODO: Fix rename. + // _navigation[index]->rename(); } void TabbedViewContainer::openTabContextMenu(const QPoint &point) { if (point.isNull()) { return; } - _contextMenuTabIndex = _tabBar->tabAt(point); - if (_contextMenuTabIndex < 0) { + const int contextMenuTabIndex = tabBar()->tabAt(point); + if (contextMenuTabIndex < 0) { return; } #if defined(ENABLE_DETACHING) // Enable 'Detach Tab' menu item only if there is more than 1 tab // Note: the code is coupled with that action's position within the menu QAction *detachAction = _contextPopupMenu->actions().at(0); - detachAction->setEnabled(_tabBar->count() > 1); + detachAction->setEnabled(count() > 1); #endif // Add the read-only action - SessionController *sessionController = qobject_cast(viewProperties(views()[_contextMenuTabIndex])); + auto controller = _navigation[widget(contextMenuTabIndex)]; + auto sessionController = qobject_cast(controller); + if (sessionController != nullptr) { auto collection = sessionController->actionCollection(); auto readonlyAction = collection->action(QStringLiteral("view-readonly")); @@ -659,50 +246,14 @@ } } - _contextPopupMenu->exec(_tabBar->mapToGlobal(point)); -} - -void TabbedViewContainer::tabContextMenuCloseTab() -{ - _tabBar->setCurrentIndex(_contextMenuTabIndex);// Required for this to work - emit closeTab(this, _stackWidget->widget(_contextMenuTabIndex)); -} - -void TabbedViewContainer::tabContextMenuDetachTab() -{ - emit detachTab(this, _stackWidget->widget(_contextMenuTabIndex)); -} - -void TabbedViewContainer::tabContextMenuRenameTab() -{ - renameTab(_contextMenuTabIndex); -} - -void TabbedViewContainer::moveViewWidget(int fromIndex, int toIndex) -{ - QString text = _tabBar->tabText(fromIndex); - QIcon icon = _tabBar->tabIcon(fromIndex); - - // FIXME (KF5?)- This will lose properties of the tab other than - // their text and icon when moving them - - QWidget *widget = _stackWidget->widget(fromIndex); - // this also removes the tab from the tab bar - _stackWidget->removeWidget(widget); - _stackWidget->insertWidget(toIndex, widget); - - _tabBar->insertTab(toIndex, icon, text); - - if (navigationVisibility() == ShowNavigationAsNeeded) { - dynamicTabBarVisibility(); - } + _contextPopupMenu->exec(tabBar()->mapToGlobal(point)); } void TabbedViewContainer::currentTabChanged(int index) { - _stackWidget->setCurrentIndex(index); - if (_stackWidget->widget(index) != nullptr) { - emit activeViewChanged(_stackWidget->widget(index)); + setCurrentIndex(index); + if (widget(index) != nullptr) { + emit activeViewChanged(widget(index)); } // clear activity indicators @@ -718,111 +269,65 @@ } } -QWidget *TabbedViewContainer::containerWidget() const -{ - return _containerWidget; -} - -QWidget *TabbedViewContainer::activeView() const -{ - return _stackWidget->currentWidget(); -} - -void TabbedViewContainer::setActiveView(QWidget *view) -{ - const int index = _stackWidget->indexOf(view); - - Q_ASSERT(index != -1); - - _stackWidget->setCurrentWidget(view); - _tabBar->setCurrentIndex(index); -} - void TabbedViewContainer::addViewWidget(QWidget *view, int index) { - _stackWidget->insertWidget(index, view); - _stackWidget->updateGeometry(); - ViewProperties *item = viewProperties(view); connect(item, &Konsole::ViewProperties::titleChanged, this, &Konsole::TabbedViewContainer::updateTitle); connect(item, &Konsole::ViewProperties::iconChanged, this, &Konsole::TabbedViewContainer::updateIcon); connect(item, &Konsole::ViewProperties::activity, this, &Konsole::TabbedViewContainer::updateActivity); - _tabBar->insertTab(index, item->icon(), item->title()); - - if (navigationVisibility() == ShowNavigationAsNeeded) { - dynamicTabBarVisibility(); - } -} - -void TabbedViewContainer::removeViewWidget(QWidget *view) -{ - if (_stackWidget.isNull()) { - return; - } - _stackWidget->removeWidget(view); -} - -void TabbedViewContainer::widgetRemoved(int index) -{ - Q_ASSERT(index != -1); - - _tabBar->removeTab(index); - - if (navigationVisibility() == ShowNavigationAsNeeded) { - dynamicTabBarVisibility(); - } + insertTab(index, view, item->icon(), item->title()); } void TabbedViewContainer::setTabActivity(int index, bool activity) { - const QPalette &palette = _tabBar->palette(); + const QPalette &palette = tabBar()->palette(); KColorScheme colorScheme(palette.currentColorGroup()); const QColor colorSchemeActive = colorScheme.foreground(KColorScheme::ActiveText).color(); const QColor normalColor = palette.text().color(); const QColor activityColor = KColorUtils::mix(normalColor, colorSchemeActive); QColor color = activity ? activityColor : QColor(); - if (color != _tabBar->tabTextColor(index)) { - _tabBar->setTabTextColor(index, color); + if (color != tabBar()->tabTextColor(index)) { + tabBar()->setTabTextColor(index, color); } } void TabbedViewContainer::updateActivity(ViewProperties *item) { foreach (QWidget *widget, widgetsForItem(item)) { - const int index = _stackWidget->indexOf(widget); + const int index = indexOf(widget); - if (index != _stackWidget->currentIndex()) { + if (index != currentIndex()) { setTabActivity(index, true); } } } void TabbedViewContainer::updateTitle(ViewProperties *item) { foreach (QWidget *widget, widgetsForItem(item)) { - const int index = _stackWidget->indexOf(widget); + const int index = indexOf(widget); QString tabText = item->title(); - _tabBar->setTabToolTip(index, tabText); + setTabToolTip(index, tabText); // To avoid having & replaced with _ (shortcut indicator) tabText.replace(QLatin1Char('&'), QLatin1String("&&")); - _tabBar->setTabText(index, tabText); + setTabText(index, tabText); } } void TabbedViewContainer::updateIcon(ViewProperties *item) { foreach (QWidget *widget, widgetsForItem(item)) { - const int index = _stackWidget->indexOf(widget); - _tabBar->setTabIcon(index, item->icon()); + const int index = indexOf(widget); + setTabIcon(index, item->icon()); } } diff --git a/src/ViewContainerTabBar.h b/src/ViewContainerTabBar.h deleted file mode 100644 --- a/src/ViewContainerTabBar.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - This file is part of the Konsole Terminal. - - Copyright 2006-2008 Robert Knight - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. -*/ - -#ifndef VIEWCONTAINERTABBAR_H -#define VIEWCONTAINERTABBAR_H - -#include -#include - -class QLabel; - -namespace Konsole { -class TabbedViewContainer; - -class ViewContainerTabBar : public QTabBar -{ - Q_OBJECT - -public: - ViewContainerTabBar(QWidget *parent, TabbedViewContainer *container); - ~ViewContainerTabBar() Q_DECL_OVERRIDE; - - // returns a pixmap image of a tab for use with QDrag - QPixmap dragDropPixmap(int tab); - - // set the mimetype of which the tabbar support d&d - void setSupportedMimeType(const QString &mimeType); - - // return associated tabbed container - TabbedViewContainer *connectedTabbedViewContainer(); - -Q_SIGNALS: - void initiateDrag(int index); - void querySourceIndex(const QDropEvent *event, int &sourceIndex) const; - void moveViewRequest(int index, const QDropEvent *event, bool &success, - TabbedViewContainer *sourceTabbedContainer); - -protected: - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; - void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; - void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; - void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(ViewContainerTabBar) - - // show the indicator arrow which shows where a dropped tab will - // be inserted at 'index' - void setDropIndicator(int index, bool drawDisabled = false); - - // returns the index at which a tab will be inserted if the mouse - // in a drag-drop operation is released at 'pos' - int dropIndex(const QPoint &pos) const; - - // returns true if the tab to be dropped in a drag-drop operation - // is the same as the tab at the drop location - bool proposedDropIsSameTab(const QDropEvent *event) const; - - QLabel *_dropIndicator; - int _dropIndicatorIndex; - bool _drawIndicatorDisabled; - QString _supportedMimeType; - TabbedViewContainer *_connectedContainer; - QPoint _dragStart; - QElapsedTimer *_mousePressTimer; -}; -} - -#endif // VIEWCONTAINERTABBAR_H diff --git a/src/ViewContainerTabBar.cpp b/src/ViewContainerTabBar.cpp deleted file mode 100644 --- a/src/ViewContainerTabBar.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - This file is part of the Konsole Terminal. - - Copyright 2006-2008 Robert Knight - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. -*/ - -// Own -#include "ViewContainerTabBar.h" -#include "ViewContainer.h" - -// Qt -#include -#include -#include -#include -#include -#include -#include - -// KDE -#include - -using Konsole::ViewContainerTabBar; -using Konsole::TabbedViewContainer; - -ViewContainerTabBar::ViewContainerTabBar(QWidget *parent, TabbedViewContainer *container) : - QTabBar(parent), - _dropIndicator(nullptr), - _dropIndicatorIndex(-1), - _drawIndicatorDisabled(false), - _supportedMimeType(QString()), - _connectedContainer(container), - _dragStart(QPoint()), - _mousePressTimer(nullptr) -{ - setDrawBase(true); - setDocumentMode(true); - setFocusPolicy(Qt::NoFocus); - setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); - setElideMode(Qt::ElideLeft); - - setAcceptDrops(true); - setMouseTracking(true); - - _mousePressTimer = new QElapsedTimer(); - - setWhatsThis(xi18nc("@info:whatsthis", - "Tab Bar" - "The tab bar allows you to switch and move tabs. You can double-click a tab to change its name.")); -} - -ViewContainerTabBar::~ViewContainerTabBar() -{ - delete _mousePressTimer; -} - -void ViewContainerTabBar::mousePressEvent(QMouseEvent *event) -{ - _mousePressTimer->start(); - - if (event->buttons() == Qt::LeftButton) { - _dragStart = event->pos(); - } - QTabBar::mousePressEvent(event); -} - -void ViewContainerTabBar::mouseMoveEvent(QMouseEvent *event) -{ - if (event->buttons() == Qt::LeftButton) { - QPoint dragPos = _dragStart - event->pos(); - if (dragPos.manhattanLength() > QApplication::startDragDistance()) { - int tab = tabAt(_dragStart); - if (tab != -1) { - emit initiateDrag(tab); - } - } - } - QTabBar::mouseMoveEvent(event); -} - -void ViewContainerTabBar::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasFormat(_supportedMimeType) - && event->source() != nullptr) { - event->acceptProposedAction(); - } -} - -void ViewContainerTabBar::dragLeaveEvent(QDragLeaveEvent *) -{ - setDropIndicator(-1); -} - -void ViewContainerTabBar::dragMoveEvent(QDragMoveEvent *event) -{ - if (event->mimeData()->hasFormat(_supportedMimeType) - && event->source() != nullptr) { - int index = dropIndex(event->pos()); - if (index == -1) { - index = count(); - } - - setDropIndicator(index, proposedDropIsSameTab(event)); - - event->acceptProposedAction(); - } -} - -void ViewContainerTabBar::dropEvent(QDropEvent *event) -{ - setDropIndicator(-1); - - if (!event->mimeData()->hasFormat(_supportedMimeType)) { - event->ignore(); - return; - } - - if (proposedDropIsSameTab(event)) { - event->setDropAction(Qt::IgnoreAction); - event->accept(); - return; - } - - const int index = dropIndex(event->pos()); - bool success = false; - - ViewContainerTabBar *sourceContainerTabBar - = qobject_cast(event->source()); - - // check if the moved tab is the last of source view. - if (sourceContainerTabBar->count() == 1) { - TabbedViewContainer *sourceTabbedContainer - = sourceContainerTabBar->connectedTabbedViewContainer(); - emit moveViewRequest(index, event, success, sourceTabbedContainer); - } else { - emit moveViewRequest(index, event, success, nullptr); - } - - if (success) { - event->accept(); - } else { - event->ignore(); - } -} - -TabbedViewContainer *ViewContainerTabBar::connectedTabbedViewContainer() -{ - return _connectedContainer; -} - -void ViewContainerTabBar::setDropIndicator(int index, bool drawDisabled) -{ - if ((parentWidget() == nullptr) || _dropIndicatorIndex == index) { - return; - } - - _dropIndicatorIndex = index; - const int ARROW_SIZE = 32; - const bool north = shape() == QTabBar::RoundedNorth || shape() == QTabBar::TriangularNorth; - - if ((_dropIndicator == nullptr) || _drawIndicatorDisabled != drawDisabled) { - if (_dropIndicator == nullptr) { - _dropIndicator = new QLabel(parentWidget()); - _dropIndicator->resize(ARROW_SIZE, ARROW_SIZE); - } - - QIcon::Mode drawMode = drawDisabled ? QIcon::Disabled : QIcon::Normal; - const QString iconName = north ? QStringLiteral("arrow-up") : QStringLiteral("arrow-down"); - _dropIndicator->setPixmap(QIcon::fromTheme(iconName).pixmap(ARROW_SIZE, ARROW_SIZE, - drawMode)); - _drawIndicatorDisabled = drawDisabled; - } - - if (index < 0) { - _dropIndicator->hide(); - return; - } - - const QRect rect = tabRect(index < count() ? index : index - 1); - - QPoint pos; - if (index < count()) { - pos = rect.topLeft(); - } else { - pos = rect.topRight(); - } - - if (north) { - pos.ry() += ARROW_SIZE; - } else { - pos.ry() -= ARROW_SIZE; - } - - pos.rx() -= ARROW_SIZE / 2; - - _dropIndicator->move(mapTo(parentWidget(), pos)); - _dropIndicator->show(); -} - -void ViewContainerTabBar::setSupportedMimeType(const QString &mimeType) -{ - _supportedMimeType = mimeType; -} - -int ViewContainerTabBar::dropIndex(const QPoint &pos) const -{ - int tab = tabAt(pos); - if (tab < 0) { - return tab; - } - - // pick the closest tab boundary - QRect rect = tabRect(tab); - if ((pos.x() - rect.left()) > (rect.width() / 2)) { - tab++; - } - - if (tab == count()) { - return -1; - } - - return tab; -} - -bool ViewContainerTabBar::proposedDropIsSameTab(const QDropEvent *event) const -{ - const bool sameTabBar = event->source() == this; - if (!sameTabBar) { - return false; - } - - const int index = dropIndex(event->pos()); - int sourceIndex = -1; - emit querySourceIndex(event, sourceIndex); - - const bool sourceAndDropAreLast = sourceIndex == count() - 1 && index == -1; - return sourceIndex == index || sourceIndex == index - 1 || sourceAndDropAreLast; -} - -QPixmap ViewContainerTabBar::dragDropPixmap(int tab) -{ - Q_ASSERT(tab >= 0 && tab < count()); - - // QWidget::grab() (depreciated QPixmap::grabWidget()) - // does not show right and bottom edges on certain themes - // (curved corners) so increase size of rectangle. - const QRect rect = tabRect(tab); - const int borderWidth = 1; - - QPixmap tabPixmap(rect.width() + borderWidth, - rect.height() + borderWidth); - QPainter painter(&tabPixmap); - painter.drawPixmap(0, 0, grab(rect)); - QPen borderPen; - borderPen.setBrush(palette().dark()); - borderPen.setWidth(borderWidth); - painter.setPen(borderPen); - painter.drawRect(0, 0, rect.width(), rect.height()); - painter.end(); - - return tabPixmap; -} diff --git a/src/ViewManager.h b/src/ViewManager.h --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -27,17 +27,15 @@ // Konsole #include "Profile.h" -#include "ViewContainer.h" class KActionCollection; class KConfigGroup; namespace Konsole { class ColorScheme; -class IncrementalSearchBar; class Session; class TerminalDisplay; - +class TabbedViewContainer; class SessionController; class ViewProperties; class ViewSplitter; @@ -153,23 +151,15 @@ */ SessionController *activeViewController() const; - /** - * Returns the search bar. - */ - IncrementalSearchBar *searchBar() const; - /** * Session management */ void saveSessions(KConfigGroup &group); void restoreSessions(const KConfigGroup &group); - void setNavigationVisibility(int visibility); + void setTabbarAutoHide(bool autoHide); void setNavigationPosition(int position); - void setNavigationBehavior(int behavior); - void setNavigationTabWidthExpanding(bool expand); void setNavigationStyleSheet(const QString &styleSheet); - void setShowQuickButtons(bool show); int managerId() const; @@ -295,9 +285,6 @@ */ Q_SCRIPTABLE void moveSessionRight(); - /** DBus slot that sets ALL tabs' width to match their text */ - Q_SCRIPTABLE void setTabWidthToText(bool); - private Q_SLOTS: // called when the "Split View Left/Right" menu item is selected void splitLeftRight(); @@ -340,7 +327,7 @@ // called when the views in a container owned by this view manager // changes - void containerViewsChanged(ViewContainer *container); + void containerViewsChanged(TabbedViewContainer *container); // called when a profile changes void profileChanged(Profile::Ptr profile); @@ -363,28 +350,28 @@ void containerMoveViewRequest(int index, int id, bool &success, TabbedViewContainer *sourceTabbedContainer); - void detachView(ViewContainer *container, QWidget *view); + void detachView(TabbedViewContainer *container, QWidget *view); - void closeTabFromContainer(ViewContainer *container, QWidget *tab); + void closeTabFromContainer(TabbedViewContainer *container, QWidget *tab); private: Q_DISABLE_COPY(ViewManager) - void createView(Session *session, ViewContainer *container, int index); + void createView(Session *session, TabbedViewContainer *container, int index); static const ColorScheme *colorSchemeForProfile(const Profile::Ptr profile); void setupActions(); // takes a view from a view container owned by a different manager and places it in // newContainer owned by this manager - void takeView(ViewManager *otherManager, ViewContainer *otherContainer, - ViewContainer *newContainer, TerminalDisplay *view); + void takeView(ViewManager *otherManager, TabbedViewContainer *otherContainer, + TabbedViewContainer *newContainer, TerminalDisplay *view); void splitView(Qt::Orientation orientation); // creates a new container which can hold terminal displays - ViewContainer *createContainer(); + TabbedViewContainer *createContainer(); // removes a container and emits appropriate signals - void removeContainer(ViewContainer *container); + void removeContainer(TabbedViewContainer *container); // creates a new terminal display // the 'session' is used so that the terminal display's random seed @@ -396,9 +383,6 @@ // about the session ( such as title and associated icon ) to the display. SessionController *createController(Session *session, TerminalDisplay *view); - // Sets the possible features for a container. - void setContainerFeatures(ViewContainer* container); - private: QPointer _viewSplitter; QPointer _pluggedController; @@ -408,14 +392,7 @@ KActionCollection *_actionCollection; NavigationMethod _navigationMethod; - - ViewContainer::NavigationVisibility _navigationVisibility; - ViewContainer::NavigationPosition _navigationPosition; - bool _showQuickButtons; - bool _navigationTabWidthExpanding; - NewTabBehavior _newTabBehavior; QString _navigationStyleSheet; - int _managerId; static int lastManagerId; }; diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -44,6 +44,7 @@ #include "ProfileManager.h" #include "ViewSplitter.h" #include "Enumeration.h" +#include "ViewContainer.h" using namespace Konsole; @@ -55,13 +56,6 @@ _pluggedController(nullptr), _sessionMap(QHash()), _actionCollection(collection), - _navigationMethod(TabbedNavigation), - _navigationVisibility(ViewContainer::AlwaysShowNavigation), - _navigationPosition(ViewContainer::NavigationPositionTop), - _showQuickButtons(false), - _navigationTabWidthExpanding(true), - _newTabBehavior(PutNewTabAtTheEnd), - _navigationStyleSheet(QString()), _managerId(0) { // create main view area @@ -109,9 +103,9 @@ QWidget *ViewManager::activeView() const { - ViewContainer *container = _viewSplitter->activeContainer(); + TabbedViewContainer *container = _viewSplitter->activeContainer(); if (container != nullptr) { - return container->activeView(); + return container->currentWidget(); } else { return nullptr; } @@ -280,14 +274,7 @@ void ViewManager::switchToView(int index) { - Q_ASSERT(index >= 0); - ViewContainer *container = _viewSplitter->activeContainer(); - Q_ASSERT(container); - QList containerViews = container->views(); - if (index >= containerViews.count()) { - return; - } - container->setActiveView(containerViews.at(index)); + _viewSplitter->activeContainer()->setCurrentIndex(index); } void ViewManager::updateDetachViewState() @@ -301,7 +288,7 @@ auto activeContainer = _viewSplitter->activeContainer(); const bool shouldEnable = splitView || ((activeContainer != nullptr) - && activeContainer->views().count() >= 2); + && activeContainer->count() >= 2); QAction *detachAction = _actionCollection->action(QStringLiteral("detach-view")); @@ -312,16 +299,16 @@ void ViewManager::moveActiveViewLeft() { - ViewContainer *container = _viewSplitter->activeContainer(); + TabbedViewContainer *container = _viewSplitter->activeContainer(); Q_ASSERT(container); - container->moveActiveView(ViewContainer::MoveViewLeft); + container->moveActiveView(TabbedViewContainer::MoveViewLeft); } void ViewManager::moveActiveViewRight() { - ViewContainer *container = _viewSplitter->activeContainer(); + TabbedViewContainer *container = _viewSplitter->activeContainer(); Q_ASSERT(container); - container->moveActiveView(ViewContainer::MoveViewRight); + container->moveActiveView(TabbedViewContainer::MoveViewRight); } void ViewManager::nextContainer() @@ -331,40 +318,33 @@ void ViewManager::nextView() { - ViewContainer *container = _viewSplitter->activeContainer(); - + TabbedViewContainer *container = _viewSplitter->activeContainer(); Q_ASSERT(container); - container->activateNextView(); } void ViewManager::previousView() { - ViewContainer *container = _viewSplitter->activeContainer(); - + TabbedViewContainer *container = _viewSplitter->activeContainer(); Q_ASSERT(container); - container->activatePreviousView(); } void ViewManager::lastView() { - ViewContainer *container = _viewSplitter->activeContainer(); - + TabbedViewContainer *container = _viewSplitter->activeContainer(); Q_ASSERT(container); - container->activateLastView(); } void ViewManager::detachActiveView() { // find the currently active view and remove it from its container - ViewContainer *container = _viewSplitter->activeContainer(); - - detachView(container, container->activeView()); + TabbedViewContainer *container = _viewSplitter->activeContainer(); + detachView(container, container->currentWidget()); } -void ViewManager::detachView(ViewContainer *container, QWidget *view) +void ViewManager::detachView(TabbedViewContainer *container, QWidget *view) { #if !defined(ENABLE_DETACHING) return; @@ -393,7 +373,7 @@ // unless it is the only container in the window, in which case it is left empty // so that there is always an active container if (_viewSplitter->containers().count() > 1 - && container->views().count() == 0) { + && container->count() == 0) { removeContainer(container); } } @@ -451,11 +431,12 @@ void ViewManager::splitView(Qt::Orientation orientation) { - ViewContainer *container = createContainer(); + TabbedViewContainer *container = createContainer(); // iterate over each session which has a view in the current active // container and create a new view for that session in a new container - foreach (QWidget *view, _viewSplitter->activeContainer()->views()) { + for(int i = 0, end = _viewSplitter->activeContainer()->count(); i < end; i++) { + auto view = _viewSplitter->activeContainer()->widget(i); Session *session = _sessionMap[qobject_cast(view)]; TerminalDisplay *display = createTerminalDisplay(session); const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); @@ -472,21 +453,22 @@ emit splitViewToggle(_viewSplitter->containers().count() > 0); // focus the new container - container->containerWidget()->setFocus(); + container->currentWidget()->setFocus(); // ensure that the active view is focused after the split / unsplit - ViewContainer *activeContainer = _viewSplitter->activeContainer(); - QWidget *activeView = activeContainer != nullptr ? activeContainer->activeView() : nullptr; + TabbedViewContainer *activeContainer = _viewSplitter->activeContainer(); + QWidget *activeView = activeContainer != nullptr ? activeContainer->currentWidget() : nullptr; if (activeView != nullptr) { activeView->setFocus(Qt::OtherFocusReason); } } -void ViewManager::removeContainer(ViewContainer *container) +void ViewManager::removeContainer(TabbedViewContainer *container) { // remove session map entries for views in this container - foreach (QWidget *view, container->views()) { + for(int i = 0, end = container->count(); i < end; i++) { + auto view = container->widget(i); TerminalDisplay *display = qobject_cast(view); Q_ASSERT(display); _sessionMap.remove(display); @@ -512,7 +494,7 @@ { // only do something if there is more than one container active if (_viewSplitter->containers().count() > 1) { - ViewContainer *container = _viewSplitter->activeContainer(); + TabbedViewContainer *container = _viewSplitter->activeContainer(); removeContainer(container); @@ -524,9 +506,9 @@ void ViewManager::closeOtherContainers() { - ViewContainer *active = _viewSplitter->activeContainer(); + TabbedViewContainer *active = _viewSplitter->activeContainer(); - foreach (ViewContainer *container, _viewSplitter->containers()) { + foreach (TabbedViewContainer *container, _viewSplitter->containers()) { if (container != active) { removeContainer(container); } @@ -574,12 +556,7 @@ return _pluggedController; } -IncrementalSearchBar *ViewManager::searchBar() const -{ - return _viewSplitter->activeSplitter()->activeContainer()->searchBar(); -} - -void ViewManager::createView(Session *session, ViewContainer *container, int index) +void ViewManager::createView(Session *session, TabbedViewContainer *container, int index) { // notify this view manager when the session finishes so that its view // can be deleted @@ -594,19 +571,8 @@ // set initial size const QSize &preferredSize = session->preferredSize(); - // FIXME: +1 is needed here for getting the expected rows - // Note that the display shouldn't need to take into account the tabbar. - // However, it appears that taking into account the tabbar is needed. - // If tabbar is not visible, no +1 is needed here; however, depending on - // settings/tabbar style, +2 might be needed. - // 1st attempt at fixing the above: - // Guess if tabbar will NOT be visible; ignore ShowNavigationAsNeeded - int heightAdjustment = 0; - if (_navigationVisibility != ViewContainer::AlwaysHideNavigation) { - heightAdjustment = 2; - } - display->setSize(preferredSize.width(), preferredSize.height() + heightAdjustment); + display->setSize(preferredSize.width(), preferredSize.height()); ViewProperties *properties = createController(session, display); _sessionMap[display] = session; @@ -617,7 +583,7 @@ session->setDarkBackground(colorSchemeForProfile(profile)->hasDarkBackground()); if (container == _viewSplitter->activeContainer()) { - container->setActiveView(display); + container->setCurrentWidget(display); display->setFocus(Qt::OtherFocusReason); } @@ -628,92 +594,71 @@ { // create the default container if (_viewSplitter->containers().count() == 0) { - ViewContainer *container = createContainer(); + TabbedViewContainer *container = createContainer(); _viewSplitter->addContainer(container, Qt::Vertical); emit splitViewToggle(false); } // new tab will be put at the end by default. int index = -1; - if (_newTabBehavior == PutNewTabAfterCurrentTab) { - QWidget *view = activeView(); - if (view != nullptr) { - QList views = _viewSplitter->activeContainer()->views(); - index = views.indexOf(view) + 1; - } - } - // iterate over the view containers owned by this view manager // and create a new terminal display for the session in each of them, along with // a controller for the session/display pair - foreach (ViewContainer *container, _viewSplitter->containers()) { + foreach (TabbedViewContainer *container, _viewSplitter->containers()) { createView(session, container, index); } } -ViewContainer *ViewManager::createContainer() +TabbedViewContainer *ViewManager::createContainer() { - auto *container = new TabbedViewContainer(_navigationPosition, this, _viewSplitter); - if (_navigationMethod == TabbedNavigation) { - connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); - connect(container, &TabbedViewContainer::closeTab, this, - &ViewManager::closeTabFromContainer); - } - - // FIXME: these code feels duplicated - container->setNavigationVisibility(_navigationVisibility); - container->setNavigationPosition(_navigationPosition); - container->setNavigationTabWidthExpanding(_navigationTabWidthExpanding); - container->setStyleSheet(_navigationStyleSheet); - setContainerFeatures(container); + auto *container = new TabbedViewContainer(this, _viewSplitter); + //TODO: Fix Detaching. + // connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); + connect(container, &TabbedViewContainer::closeTab, this, &ViewManager::closeTabFromContainer); // connect signals and slots - connect(container, &Konsole::ViewContainer::viewAdded, this, + connect(container, &Konsole::TabbedViewContainer::viewAdded, this, [this, container]() { containerViewsChanged(container); }); - connect(container, &Konsole::ViewContainer::viewRemoved, this, + connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, [this, container]() { containerViewsChanged(container); }); connect(container, - static_cast(&Konsole::ViewContainer::newViewRequest), this, + static_cast(&Konsole::TabbedViewContainer::newViewRequest), this, static_cast(&Konsole::ViewManager::newViewRequest)); connect(container, - static_cast(&Konsole::ViewContainer::newViewRequest), + static_cast(&Konsole::TabbedViewContainer::newViewRequest), this, static_cast(&Konsole::ViewManager::newViewRequest)); - connect(container, &Konsole::ViewContainer::moveViewRequest, this, + connect(container, &Konsole::TabbedViewContainer::moveViewRequest, this, &Konsole::ViewManager::containerMoveViewRequest); - connect(container, &Konsole::ViewContainer::viewRemoved, this, + connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, &Konsole::ViewManager::viewDestroyed); - connect(container, &Konsole::ViewContainer::activeViewChanged, this, + connect(container, &Konsole::TabbedViewContainer::activeViewChanged, this, &Konsole::ViewManager::viewActivated); - if (_navigationMethod != TabbedNavigation) { - container->setTabBarVisible(false); - } - return container; } void ViewManager::containerMoveViewRequest(int index, int id, bool &success, TabbedViewContainer *sourceTabbedContainer) { - ViewContainer *container = qobject_cast(sender()); + TabbedViewContainer *container = qobject_cast(sender()); SessionController *controller = qobject_cast(ViewProperties::propertiesById(id)); if (controller == nullptr) { return; } // do not move the last tab in a split view. if (sourceTabbedContainer != nullptr) { - QPointer sourceContainer = qobject_cast(sourceTabbedContainer); + QPointer sourceContainer = qobject_cast(sourceTabbedContainer); if (_viewSplitter->containers().contains(sourceContainer)) { return; @@ -738,8 +683,6 @@ if (_actionCollection == nullptr) { return; } - _navigationMethod = method; - KActionCollection *collection = _actionCollection; // FIXME: The following disables certain actions for the KPart that it @@ -751,7 +694,7 @@ // a method should be devised to only enable those that are used, perhaps // by using a separate action collection. - const bool enable = (_navigationMethod != NoNavigation); + const bool enable = (method != NoNavigation); auto enableAction = [&enable, &collection](const QString& actionName) { auto *action = collection->action(actionName); @@ -775,7 +718,7 @@ return _navigationMethod; } -void ViewManager::containerViewsChanged(ViewContainer *container) +void ViewManager::containerViewsChanged(TabbedViewContainer *container) { if ((!_viewSplitter.isNull()) && container == _viewSplitter->activeContainer()) { emit viewPropertiesChanged(viewProperties()); @@ -931,11 +874,13 @@ { QList list; - ViewContainer *container = _viewSplitter->activeContainer(); + TabbedViewContainer *container = _viewSplitter->activeContainer(); Q_ASSERT(container); + list.reserve(container->count()); - foreach (QWidget *view, container->views()) { + for(int i = 0, end = container->count(); i < end; i++) { + auto view = container->widget(i); ViewProperties *properties = container->viewProperties(view); Q_ASSERT(properties); list << properties; @@ -949,20 +894,22 @@ // find all unique session restore IDs QList ids; QSet unique; + int tab = 1; + + TabbedViewContainer *container = _viewSplitter->activeContainer(); + ids.reserve(container->count()); // first: sessions in the active container, preserving the order - ViewContainer *container = _viewSplitter->activeContainer(); Q_ASSERT(container); if (container == nullptr) { return; } - TerminalDisplay *activeview = qobject_cast(container->activeView()); - QListIterator viewIter(container->views()); - int tab = 1; - while (viewIter.hasNext()) { - TerminalDisplay *view = qobject_cast(viewIter.next()); + TerminalDisplay *activeview = qobject_cast(container->currentWidget()); + for (int i = 0, end = container->count(); i < end; i++) { + TerminalDisplay *view = qobject_cast(container->widget(i)); Q_ASSERT(view); + Session *session = _sessionMap[view]; ids << SessionManager::instance()->getRestoreId(session); unique.insert(session); @@ -1011,7 +958,7 @@ } if (display != nullptr) { - _viewSplitter->activeContainer()->setActiveView(display); + _viewSplitter->activeContainer()->setCurrentWidget(display); display->setFocus(Qt::OtherFocusReason); } @@ -1058,9 +1005,9 @@ QHash::const_iterator i; for (i = _sessionMap.constBegin(); i != _sessionMap.constEnd(); ++i) { if (i.value()->sessionId() == sessionId) { - ViewContainer *container = _viewSplitter->activeContainer(); + TabbedViewContainer *container = _viewSplitter->activeContainer(); if (container != nullptr) { - container->setActiveView(i.key()); + container->setCurrentWidget(i.key()); } } } @@ -1154,81 +1101,33 @@ moveActiveViewRight(); } -void ViewManager::setTabWidthToText(bool useTextWidth) -{ - ViewContainer *container = _viewSplitter->activeContainer(); - Q_ASSERT(container); - container->setNavigationTextMode(useTextWidth); -} - -void ViewManager::closeTabFromContainer(ViewContainer *container, QWidget *tab) +void ViewManager::closeTabFromContainer(TabbedViewContainer *container, QWidget *tab) { SessionController *controller = qobject_cast(container->viewProperties(tab)); Q_ASSERT(controller); if (controller != nullptr) { controller->closeSession(); } } -void ViewManager::setNavigationVisibility(int visibility) +void ViewManager::setTabbarAutoHide(bool autoHide) { - _navigationVisibility = static_cast(visibility); - - foreach (ViewContainer *container, _viewSplitter->containers()) { - container->setNavigationVisibility(_navigationVisibility); + foreach (TabbedViewContainer *container, _viewSplitter->containers()) { + container->setTabBarAutoHide(autoHide); } } void ViewManager::setNavigationPosition(int position) { - _navigationPosition = static_cast(position); - - foreach (ViewContainer *container, _viewSplitter->containers()) { - Q_ASSERT(container->supportedNavigationPositions().contains(_navigationPosition)); - container->setNavigationPosition(_navigationPosition); - } -} - -void ViewManager::setNavigationTabWidthExpanding(bool expand) -{ - _navigationTabWidthExpanding = expand; - - foreach (ViewContainer *container, _viewSplitter->containers()) { - container->setNavigationTabWidthExpanding(expand); + auto navigationPosition = static_cast(position); + foreach (TabbedViewContainer *container, _viewSplitter->containers()) { + container->setTabPosition(navigationPosition); } } void ViewManager::setNavigationStyleSheet(const QString &styleSheet) { - _navigationStyleSheet = styleSheet; - - foreach (ViewContainer *container, _viewSplitter->containers()) { - container->setStyleSheet(_navigationStyleSheet); + foreach (TabbedViewContainer *container, _viewSplitter->containers()) { + container->setStyleSheet(styleSheet); } } - -void ViewManager::setContainerFeatures(ViewContainer *container) -{ - if (_showQuickButtons) { - container->setFeatures(container->features() - | ViewContainer::QuickNewView - | ViewContainer::QuickCloseView); - } else { - container->setFeatures(container->features() - & ~ViewContainer::QuickNewView - & ~ViewContainer::QuickCloseView); - } -} -void ViewManager::setShowQuickButtons(bool show) -{ - _showQuickButtons = show; - - for (auto *container : _viewSplitter->containers()) { - setContainerFeatures(container); - } -} - -void ViewManager::setNavigationBehavior(int behavior) -{ - _newTabBehavior = static_cast(behavior); -} diff --git a/src/ViewSplitter.h b/src/ViewSplitter.h --- a/src/ViewSplitter.h +++ b/src/ViewSplitter.h @@ -29,7 +29,7 @@ class QFocusEvent; namespace Konsole { -class ViewContainer; +class TabbedViewContainer; /** * A splitter which holds a number of ViewContainer objects and allows @@ -65,10 +65,10 @@ * will be created, into which the container will * be inserted. */ - void addContainer(ViewContainer *container, Qt::Orientation orientation); + void addContainer(TabbedViewContainer *container, Qt::Orientation orientation); /** Removes a container from the splitter. The container is not deleted. */ - void removeContainer(ViewContainer *container); + void removeContainer(TabbedViewContainer *container); /** Returns the child ViewSplitter widget which currently has the focus */ ViewSplitter *activeSplitter(); @@ -84,17 +84,17 @@ * mySplitter->activeSplitter()->activeContainer() where mySplitter * is the ViewSplitter widget at the top of the hierarchy. */ - ViewContainer *activeContainer() const; + TabbedViewContainer *activeContainer() const; /** * Gives the focus to the active view in the specified container */ - void setActiveContainer(ViewContainer *container); + void setActiveContainer(TabbedViewContainer *container); /** * Returns a list of the containers held by this splitter */ - QList containers() const + QList containers() const { return _containers; } @@ -113,7 +113,7 @@ * The sizes of the remaining containers are increased or decreased * uniformly to maintain the width of the splitter. */ - void adjustContainerSize(ViewContainer *container, int percentage); + void adjustContainerSize(TabbedViewContainer *container, int percentage); /** * Gives the focus to the active view in the previous container @@ -162,26 +162,26 @@ private: // Adds container to splitter's internal list and // connects signals and slots - void registerContainer(ViewContainer *container); + void registerContainer(TabbedViewContainer *container); // Removes container from splitter's internal list and // removes signals and slots - void unregisterContainer(ViewContainer *container); + void unregisterContainer(TabbedViewContainer *container); void updateSizes(); private Q_SLOTS: // Called to indicate that a child ViewContainer has been deleted - void containerDestroyed(ViewContainer *container); + void containerDestroyed(TabbedViewContainer *container); // Called to indicate that a child ViewContainer is empty - void containerEmpty(ViewContainer *container); + void containerEmpty(TabbedViewContainer *container); // Called to indicate that a child ViewSplitter is empty // (ie. all child widgets have been deleted) void childEmpty(ViewSplitter *splitter); private: - QList _containers; + QList _containers; bool _recursiveSplitting; }; } diff --git a/src/ViewSplitter.cpp b/src/ViewSplitter.cpp --- a/src/ViewSplitter.cpp +++ b/src/ViewSplitter.cpp @@ -28,11 +28,11 @@ #include "ViewContainer.h" using Konsole::ViewSplitter; -using Konsole::ViewContainer; +using Konsole::TabbedViewContainer; ViewSplitter::ViewSplitter(QWidget *parent) : QSplitter(parent), - _containers(QList()), + _containers(QList()), _recursiveSplitting(true) { } @@ -46,9 +46,9 @@ } } -void ViewSplitter::adjustContainerSize(ViewContainer *container, int percentage) +void ViewSplitter::adjustContainerSize(TabbedViewContainer *container, int percentage) { - int containerIndex = indexOf(container->containerWidget()); + int containerIndex = indexOf(container); Q_ASSERT(containerIndex != -1); @@ -85,20 +85,20 @@ return splitter; } -void ViewSplitter::registerContainer(ViewContainer *container) +void ViewSplitter::registerContainer(TabbedViewContainer *container) { _containers << container; // Connecting to container::destroyed() using the new-style connection // syntax causes a crash at exit. I don't know why. Using the old-style // syntax works. //connect(container , static_cast(&Konsole::ViewContainer::destroyed) , this , &Konsole::ViewSplitter::containerDestroyed); //connect(container , &Konsole::ViewContainer::empty , this , &Konsole::ViewSplitter::containerEmpty); - connect(container, SIGNAL(destroyed(ViewContainer*)), this, - SLOT(containerDestroyed(ViewContainer*))); - connect(container, SIGNAL(empty(ViewContainer*)), this, SLOT(containerEmpty(ViewContainer*))); + connect(container, SIGNAL(destroyed(TabbedViewContainer*)), this, + SLOT(containerDestroyed(TabbedViewContainer*))); + connect(container, SIGNAL(empty(TabbedViewContainer*)), this, SLOT(containerEmpty(TabbedViewContainer*))); } -void ViewSplitter::unregisterContainer(ViewContainer *container) +void ViewSplitter::unregisterContainer(TabbedViewContainer *container) { _containers.removeAll(container); disconnect(container, nullptr, this, nullptr); @@ -134,22 +134,22 @@ return _recursiveSplitting; } -void ViewSplitter::removeContainer(ViewContainer *container) +void ViewSplitter::removeContainer(TabbedViewContainer *container) { Q_ASSERT(containers().contains(container)); unregisterContainer(container); } -void ViewSplitter::addContainer(ViewContainer *container, Qt::Orientation containerOrientation) +void ViewSplitter::addContainer(TabbedViewContainer *container, Qt::Orientation containerOrientation) { ViewSplitter *splitter = activeSplitter(); if (splitter->count() < 2 || containerOrientation == splitter->orientation() || !_recursiveSplitting) { splitter->registerContainer(container); - splitter->addWidget(container->containerWidget()); + splitter->addWidget(container); if (splitter->orientation() != containerOrientation) { splitter->setOrientation(containerOrientation); @@ -161,37 +161,37 @@ connect(newSplitter, &Konsole::ViewSplitter::empty, splitter, &Konsole::ViewSplitter::childEmpty); - ViewContainer *oldContainer = splitter->activeContainer(); - const int oldContainerIndex = splitter->indexOf(oldContainer->containerWidget()); + TabbedViewContainer *oldContainer = splitter->activeContainer(); + const int oldContainerIndex = splitter->indexOf(oldContainer); splitter->unregisterContainer(oldContainer); newSplitter->registerContainer(oldContainer); newSplitter->registerContainer(container); - newSplitter->addWidget(oldContainer->containerWidget()); - newSplitter->addWidget(container->containerWidget()); + newSplitter->addWidget(oldContainer); + newSplitter->addWidget(container); newSplitter->setOrientation(containerOrientation); newSplitter->updateSizes(); newSplitter->show(); splitter->insertWidget(oldContainerIndex, newSplitter); } } -void ViewSplitter::containerEmpty(ViewContainer * /*container*/) +void ViewSplitter::containerEmpty(TabbedViewContainer * /*container*/) { int children = 0; - foreach (ViewContainer *container, _containers) { - children += container->views().count(); + foreach (TabbedViewContainer *container, _containers) { + children += container->count(); } if (children == 0) { emit allContainersEmpty(); } } -void ViewSplitter::containerDestroyed(ViewContainer *container) +void ViewSplitter::containerDestroyed(TabbedViewContainer *container) { Q_ASSERT(_containers.contains(container)); @@ -204,7 +204,7 @@ void ViewSplitter::activateNextContainer() { - ViewContainer *active = activeContainer(); + TabbedViewContainer *active = activeContainer(); int index = _containers.indexOf(active); @@ -223,7 +223,7 @@ void ViewSplitter::activatePreviousContainer() { - ViewContainer *active = activeContainer(); + TabbedViewContainer *active = activeContainer(); int index = _containers.indexOf(active); @@ -236,23 +236,23 @@ setActiveContainer(_containers.at(index)); } -void ViewSplitter::setActiveContainer(ViewContainer *container) +void ViewSplitter::setActiveContainer(TabbedViewContainer *container) { - QWidget *activeView = container->activeView(); + QWidget *activeView = container->currentWidget(); if (activeView != nullptr) { activeView->setFocus(Qt::OtherFocusReason); } } -ViewContainer *ViewSplitter::activeContainer() const +TabbedViewContainer *ViewSplitter::activeContainer() const { if (QWidget *focusW = focusWidget()) { - ViewContainer *focusContainer = nullptr; + TabbedViewContainer *focusContainer = nullptr; while (focusW != nullptr) { - foreach (ViewContainer *container, _containers) { - if (container->containerWidget() == focusW) { + foreach (TabbedViewContainer *container, _containers) { + if (container == focusW) { focusContainer = container; break; }