closing tabs with middle mouse and context menu

This commit is contained in:
fourtf 2017-08-17 19:15:03 +02:00
parent 6b0a7f507e
commit 2e86064a48
2 changed files with 20 additions and 17 deletions

View file

@ -76,8 +76,8 @@ void Notebook::removePage(NotebookPage *page)
select(this->pages[index + 1]);
}
delete page->getTab();
delete page;
page->getTab()->deleteLater();
page->deleteLater();
this->pages.removeOne(page);

View file

@ -4,9 +4,9 @@
#include "widgets/notebook.hpp"
#include "widgets/textinputdialog.hpp"
#include <QApplication>
#include <QDebug>
#include <QPainter>
#include <QApplication>
namespace chatterino {
namespace widgets {
@ -50,8 +50,9 @@ NotebookTab::NotebookTab(Notebook *_notebook)
});
this->menu.addAction("Close", [=]() {
// this->notebook->removePage(this->page); //
qDebug() << "TODO: Implement"; //
this->notebook->removePage(this->page);
qDebug() << "lmoa";
});
this->menu.addAction("Enable highlights on new message", []() {
@ -205,14 +206,10 @@ void NotebookTab::mousePressEvent(QMouseEvent *event)
this->update();
this->notebook->select(page);
switch (event->button()) {
case Qt::LeftButton: {
this->notebook->select(page);
} break;
case Qt::RightButton: {
this->notebook->select(page);
this->menu.popup(event->globalPos());
} break;
}
@ -222,6 +219,11 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
{
this->mouseDown = false;
if (event->button() == Qt::MiddleButton) {
if (this->rect().contains(event->pos())) {
this->notebook->removePage(this->page);
}
} else {
if (!SettingsManager::getInstance().hideTabX.get() && this->mouseDownX &&
this->getXRect().contains(event->pos())) {
this->mouseDownX = false;
@ -230,6 +232,7 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event)
} else {
this->update();
}
}
}
void NotebookTab::enterEvent(QEvent *)