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]); select(this->pages[index + 1]);
} }
delete page->getTab(); page->getTab()->deleteLater();
delete page; page->deleteLater();
this->pages.removeOne(page); this->pages.removeOne(page);

View file

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