Browse Source

Add context menu for tabs in search widget (#14926)

In searchwidget you can close all opened tabs or selected tab using menu. Closes #5628.
adaptive-webui-19844
Anton 4 years ago committed by GitHub
parent
commit
a51742b47c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/gui/search/searchwidget.cpp
  2. 1
      src/gui/search/searchwidget.h

16
src/gui/search/searchwidget.cpp

@ -39,6 +39,7 @@ @@ -39,6 +39,7 @@
#include <QDebug>
#include <QEvent>
#include <QMessageBox>
#include <QMenu>
#include <QMouseEvent>
#include <QObject>
#include <QRegularExpression>
@ -162,6 +163,15 @@ bool SearchWidget::eventFilter(QObject *object, QEvent *event) @@ -162,6 +163,15 @@ bool SearchWidget::eventFilter(QObject *object, QEvent *event)
closeTab(tabIndex);
return true;
}
if (mouseEvent->button() == Qt::RightButton)
{
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addAction(tr("Close tab"), this, [this, tabIndex]() { closeTab(tabIndex); });
menu->addAction(tr("Close all tabs"), this, &SearchWidget::closeAllTabs);
menu->popup(QCursor::pos());
return true;
}
return false;
}
return QWidget::eventFilter(object, event);
@ -381,3 +391,9 @@ void SearchWidget::closeTab(int index) @@ -381,3 +391,9 @@ void SearchWidget::closeTab(int index)
delete tab;
}
void SearchWidget::closeAllTabs()
{
for (int i = (m_allTabs.size() - 1); i >= 0; --i)
closeTab(i);
}

1
src/gui/search/searchwidget.h

@ -65,6 +65,7 @@ private: @@ -65,6 +65,7 @@ private:
bool eventFilter(QObject *object, QEvent *event) override;
void tabChanged(int index);
void closeTab(int index);
void closeAllTabs();
void tabStatusChanged(QWidget *tab);
void selectMultipleBox(int index);
void toggleFocusBetweenLineEdits();

Loading…
Cancel
Save