From 2e86064a483c4151ca3a0749ad8ac9636dd26d3a Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 17 Aug 2017 19:15:03 +0200 Subject: [PATCH] closing tabs with middle mouse and context menu --- src/widgets/notebook.cpp | 4 ++-- src/widgets/notebooktab.cpp | 33 ++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index b04dea70d..5c3ee785f 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -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); diff --git a/src/widgets/notebooktab.cpp b/src/widgets/notebooktab.cpp index 9bf833c47..cf85bc78a 100644 --- a/src/widgets/notebooktab.cpp +++ b/src/widgets/notebooktab.cpp @@ -4,9 +4,9 @@ #include "widgets/notebook.hpp" #include "widgets/textinputdialog.hpp" +#include #include #include -#include 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,13 +219,19 @@ void NotebookTab::mouseReleaseEvent(QMouseEvent *event) { this->mouseDown = false; - if (!SettingsManager::getInstance().hideTabX.get() && this->mouseDownX && - this->getXRect().contains(event->pos())) { - this->mouseDownX = false; - - this->notebook->removePage(this->page); + if (event->button() == Qt::MiddleButton) { + if (this->rect().contains(event->pos())) { + this->notebook->removePage(this->page); + } } 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(); + } } }