Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

feature: add close tabs to the right, #822 #875

Merged
merged 5 commits into from Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/lib_gui/qt/element/QtTabBar.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "QtTabBar.h"
#include <QtContextMenu.h>
#include <QtGraphicsView.h>
#include <logging.h>
#include <QContextMenuEvent>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow convention:
For Qt headers we don't add '.h' e.g. #include <QContextMenuEvent>
For own headers we use double quotations e.g. #include "QtContextMenu.h"
Qt headers are placed above own headers (see other files)


QtTabBar::QtTabBar(QWidget* parent): QTabBar(parent)
{
Expand All @@ -19,3 +23,22 @@ QSize QtTabBar::minimumTabSizeHint(int index) const
{
return QSize(45, QTabBar::minimumTabSizeHint(index).height());
}

void QtTabBar::contextMenuEvent(QContextMenuEvent* event)
{
QtContextMenu menu(event, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your whole implementation uses the wrong indentation. Please change everything to tabs instead of spaces.

QAction * m_closeTabsToRight = new QAction("Close tabs to the right", this);
menu.addAction(m_closeTabsToRight);

connect(m_closeTabsToRight, &QAction::triggered, this, [&]()
{
// We dont want to close tabs right of the current active tab.
// No, our intend is to close tabs right of the currently hovered tab.
auto tabNum = tabAt(event->pos());
LOG_INFO("Handling closeTabs... emitting signal to close tabs right of tab nr. " + std::to_string(tabNum));
emit signalCloseTabsToRight(tabNum);
});

menu.show();
return;
}
9 changes: 9 additions & 0 deletions src/lib_gui/qt/element/QtTabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@

class QtTabBar: public QTabBar
{
Q_OBJECT

public:
QtTabBar(QWidget* parent = nullptr);

signals:
void signalCloseTabsToRight(int tabNum);

protected:
QSize minimumSizeHint() const override;

QSize tabSizeHint(int index) const override;
QSize minimumTabSizeHint(int index) const override;

// New ContextMenu that lets the user close all tabs to the
// right of current mouse position.
void contextMenuEvent(QContextMenuEvent* event) override;
};

#endif // QT_TAB_BAR_H
1 change: 1 addition & 0 deletions src/lib_gui/qt/graphics/base/QtGraphicsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private slots:

void legendClicked();


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this change.

private:
bool moves() const;

Expand Down
14 changes: 14 additions & 0 deletions src/lib_gui/qt/view/QtTabsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ QtTabsView::QtTabsView(ViewLayout* viewLayout)
layout->addWidget(back);

connect(addButton, &QPushButton::clicked, this, &QtTabsView::addTab);
connect(m_tabBar, &QtTabBar::signalCloseTabsToRight, this, &QtTabsView::closeTabsToRight);
}

void QtTabsView::createWidgetWrapper()
Expand Down Expand Up @@ -271,3 +272,16 @@ void QtTabsView::setStyleSheet()
utility::setWidgetBackgroundColor(
m_widget, ColorScheme::getInstance()->getColor("tab/bar/background"));
}

void QtTabsView::closeTabsToRight(int tabNum)
{
LOG_INFO("Closing tabs to the right of tab nr. " + std::to_string(tabNum));
// We are closing tabs to the right, hence the increase.
tabNum++;
// Now close tabs at position tabNum until count has decreased low enough.
while(tabNum < m_tabBar->count() )
{
m_tabBar->removeTab(tabNum);
}
}

1 change: 1 addition & 0 deletions src/lib_gui/qt/view/QtTabsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private slots:
void insertTab(bool showTab, SearchMatch match);
void changedTab(int index);
void removeTab(int index);
void closeTabsToRight(int index);

private:
void setTabState(int idx, const std::vector<SearchMatch>& matches);
Expand Down