diff --git a/CHANGELOG.md b/CHANGELOG.md index 8045bb27..67602d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,7 +81,7 @@ - Dev: Simplified string literals to be a re-export of Qt functions. (#6175) - Dev: Fixed incorrect lua generation of static methods for typescript plugins. (#6190, #6223) - Dev: Merged top/bottom and left/right notebook layouts. (#6215) -- Dev: Refactored `Button` and friends. (#6102, #6255, #6266, #6302, #6268, #6334) +- Dev: Refactored `Button` and friends. (#6102, #6255, #6266, #6302, #6268, #6334, #6371) - Dev: Made "add split" button (part of the split header) a natively rendered button. (#6349) - Dev: Made Settings & Account button on Linux/macOS SVGs. (#6267) - Dev: Some more setting widget refactors. (#6317) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31d33ae2..dea61951 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -623,8 +623,6 @@ set(SOURCE_FILES widgets/buttons/InitUpdateButton.hpp widgets/buttons/LabelButton.cpp widgets/buttons/LabelButton.hpp - widgets/buttons/NotebookButton.cpp - widgets/buttons/NotebookButton.hpp widgets/buttons/PixmapButton.cpp widgets/buttons/PixmapButton.hpp widgets/buttons/SignalLabel.cpp diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index e99ffc5f..f70d9417 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -10,8 +10,8 @@ #include "singletons/StreamerMode.hpp" #include "singletons/Theme.hpp" #include "singletons/WindowManager.hpp" +#include "widgets/buttons/DrawnButton.hpp" #include "widgets/buttons/InitUpdateButton.hpp" -#include "widgets/buttons/NotebookButton.hpp" #include "widgets/buttons/PixmapButton.hpp" #include "widgets/buttons/SvgButton.hpp" #include "widgets/dialogs/SettingsDialog.hpp" @@ -38,9 +38,35 @@ namespace chatterino { Notebook::Notebook(QWidget *parent) : BaseWidget(parent) - , addButton_(new NotebookButton(NotebookButton::Type::Plus, this)) + , addButton_(new DrawnButton(DrawnButton::Symbol::Plus, + { + .padding = 6, + .thickness = 1, + }, + this)) { this->addButton_->setHidden(true); + this->addButton_->enableDrops({"chatterino/split"}); + + QObject::connect( + this->addButton_, &Button::dropEvent, this, [this](QDropEvent *event) { + auto *draggedSplit = dynamic_cast(event->source()); + if (!draggedSplit) + { + qCDebug(chatterinoWidget) << "Dropped something that wasn't a " + "split onto a notebook button"; + return; + } + + event->acceptProposedAction(); + + auto *page = new SplitContainer(this); + auto *tab = this->addPage(page); + page->setTab(tab); + + draggedSplit->setParent(page); + page->insertSplit(draggedSplit); + }); this->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this); @@ -673,6 +699,8 @@ void Notebook::setShowAddButton(bool value) this->showAddButton_ = value; this->addButton_->setHidden(!value); + + this->refresh(); } void Notebook::resizeAddButton() @@ -1157,11 +1185,6 @@ void Notebook::addNotebookActionsToMenu(QMenu *menu) menu->addAction(this->toggleTopMostAction_); } -NotebookButton *Notebook::getAddButton() -{ - return this->addButton_; -} - NotebookTab *Notebook::getTabFromPage(QWidget *page) { for (auto &it : this->items_) @@ -1222,7 +1245,7 @@ bool Notebook::shouldShowTab(const NotebookTab *tab) const SplitNotebook::SplitNotebook(Window *parent) : Notebook(parent) { - this->connect(this->getAddButton(), &NotebookButton::leftClicked, [this]() { + QObject::connect(this->addButton_, &Button::leftClicked, [this]() { QTimer::singleShot(80, this, [this] { this->addPage(true); }); diff --git a/src/widgets/Notebook.hpp b/src/widgets/Notebook.hpp index 04b4a76d..71786363 100644 --- a/src/widgets/Notebook.hpp +++ b/src/widgets/Notebook.hpp @@ -19,8 +19,8 @@ class Button; class PixmapButton; class SvgButton; class Window; +class DrawnButton; class UpdateDialog; -class NotebookButton; class NotebookTab; class SplitContainer; class Split; @@ -133,7 +133,7 @@ protected: void mousePressEvent(QMouseEvent *event) override; void paintEvent(QPaintEvent *) override; - NotebookButton *getAddButton(); + DrawnButton *addButton_; template T *addCustomButton(auto &&...args) @@ -217,7 +217,6 @@ private: QMenu *menu_ = nullptr; QWidget *selectedPage_ = nullptr; - NotebookButton *addButton_; std::vector