* first try to implement closeTabs toRight. * removed .kdev4 * signals and slots mechanisms for closeTabstoRight now done correct. * feature: add option to close tabs to the right on right-click context menu. * indentation, whitespaces etc.
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
#include "QtTabBar.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
#include "QtContextMenu.h"
|
||||
#include "QtGraphicsView.h"
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
QtTabBar::QtTabBar(QWidget* parent): QTabBar(parent)
|
||||
{
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
@@ -19,3 +26,22 @@ QSize QtTabBar::minimumTabSizeHint(int index) const
|
||||
{
|
||||
return QSize(45, QTabBar::minimumTabSizeHint(index).height());
|
||||
}
|
||||
|
||||
void QtTabBar::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QtContextMenu menu(event, this);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user