chore: use DrawnButton instead of NotebookButton (#6371)
This commit is contained in:
+1
-1
@@ -81,7 +81,7 @@
|
|||||||
- Dev: Simplified string literals to be a re-export of Qt functions. (#6175)
|
- 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: Fixed incorrect lua generation of static methods for typescript plugins. (#6190, #6223)
|
||||||
- Dev: Merged top/bottom and left/right notebook layouts. (#6215)
|
- 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 "add split" button (part of the split header) a natively rendered button. (#6349)
|
||||||
- Dev: Made Settings & Account button on Linux/macOS SVGs. (#6267)
|
- Dev: Made Settings & Account button on Linux/macOS SVGs. (#6267)
|
||||||
- Dev: Some more setting widget refactors. (#6317)
|
- Dev: Some more setting widget refactors. (#6317)
|
||||||
|
|||||||
@@ -623,8 +623,6 @@ set(SOURCE_FILES
|
|||||||
widgets/buttons/InitUpdateButton.hpp
|
widgets/buttons/InitUpdateButton.hpp
|
||||||
widgets/buttons/LabelButton.cpp
|
widgets/buttons/LabelButton.cpp
|
||||||
widgets/buttons/LabelButton.hpp
|
widgets/buttons/LabelButton.hpp
|
||||||
widgets/buttons/NotebookButton.cpp
|
|
||||||
widgets/buttons/NotebookButton.hpp
|
|
||||||
widgets/buttons/PixmapButton.cpp
|
widgets/buttons/PixmapButton.cpp
|
||||||
widgets/buttons/PixmapButton.hpp
|
widgets/buttons/PixmapButton.hpp
|
||||||
widgets/buttons/SignalLabel.cpp
|
widgets/buttons/SignalLabel.cpp
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
#include "singletons/StreamerMode.hpp"
|
#include "singletons/StreamerMode.hpp"
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
|
#include "widgets/buttons/DrawnButton.hpp"
|
||||||
#include "widgets/buttons/InitUpdateButton.hpp"
|
#include "widgets/buttons/InitUpdateButton.hpp"
|
||||||
#include "widgets/buttons/NotebookButton.hpp"
|
|
||||||
#include "widgets/buttons/PixmapButton.hpp"
|
#include "widgets/buttons/PixmapButton.hpp"
|
||||||
#include "widgets/buttons/SvgButton.hpp"
|
#include "widgets/buttons/SvgButton.hpp"
|
||||||
#include "widgets/dialogs/SettingsDialog.hpp"
|
#include "widgets/dialogs/SettingsDialog.hpp"
|
||||||
@@ -38,9 +38,35 @@ namespace chatterino {
|
|||||||
|
|
||||||
Notebook::Notebook(QWidget *parent)
|
Notebook::Notebook(QWidget *parent)
|
||||||
: BaseWidget(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_->setHidden(true);
|
||||||
|
this->addButton_->enableDrops({"chatterino/split"});
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
this->addButton_, &Button::dropEvent, this, [this](QDropEvent *event) {
|
||||||
|
auto *draggedSplit = dynamic_cast<Split *>(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);
|
this->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this);
|
||||||
|
|
||||||
@@ -673,6 +699,8 @@ void Notebook::setShowAddButton(bool value)
|
|||||||
this->showAddButton_ = value;
|
this->showAddButton_ = value;
|
||||||
|
|
||||||
this->addButton_->setHidden(!value);
|
this->addButton_->setHidden(!value);
|
||||||
|
|
||||||
|
this->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notebook::resizeAddButton()
|
void Notebook::resizeAddButton()
|
||||||
@@ -1157,11 +1185,6 @@ void Notebook::addNotebookActionsToMenu(QMenu *menu)
|
|||||||
menu->addAction(this->toggleTopMostAction_);
|
menu->addAction(this->toggleTopMostAction_);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotebookButton *Notebook::getAddButton()
|
|
||||||
{
|
|
||||||
return this->addButton_;
|
|
||||||
}
|
|
||||||
|
|
||||||
NotebookTab *Notebook::getTabFromPage(QWidget *page)
|
NotebookTab *Notebook::getTabFromPage(QWidget *page)
|
||||||
{
|
{
|
||||||
for (auto &it : this->items_)
|
for (auto &it : this->items_)
|
||||||
@@ -1222,7 +1245,7 @@ bool Notebook::shouldShowTab(const NotebookTab *tab) const
|
|||||||
SplitNotebook::SplitNotebook(Window *parent)
|
SplitNotebook::SplitNotebook(Window *parent)
|
||||||
: Notebook(parent)
|
: Notebook(parent)
|
||||||
{
|
{
|
||||||
this->connect(this->getAddButton(), &NotebookButton::leftClicked, [this]() {
|
QObject::connect(this->addButton_, &Button::leftClicked, [this]() {
|
||||||
QTimer::singleShot(80, this, [this] {
|
QTimer::singleShot(80, this, [this] {
|
||||||
this->addPage(true);
|
this->addPage(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ class Button;
|
|||||||
class PixmapButton;
|
class PixmapButton;
|
||||||
class SvgButton;
|
class SvgButton;
|
||||||
class Window;
|
class Window;
|
||||||
|
class DrawnButton;
|
||||||
class UpdateDialog;
|
class UpdateDialog;
|
||||||
class NotebookButton;
|
|
||||||
class NotebookTab;
|
class NotebookTab;
|
||||||
class SplitContainer;
|
class SplitContainer;
|
||||||
class Split;
|
class Split;
|
||||||
@@ -133,7 +133,7 @@ protected:
|
|||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
|
|
||||||
NotebookButton *getAddButton();
|
DrawnButton *addButton_;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T *addCustomButton(auto &&...args)
|
T *addCustomButton(auto &&...args)
|
||||||
@@ -217,7 +217,6 @@ private:
|
|||||||
QMenu *menu_ = nullptr;
|
QMenu *menu_ = nullptr;
|
||||||
QWidget *selectedPage_ = nullptr;
|
QWidget *selectedPage_ = nullptr;
|
||||||
|
|
||||||
NotebookButton *addButton_;
|
|
||||||
std::vector<Button *> customButtons_;
|
std::vector<Button *> customButtons_;
|
||||||
|
|
||||||
bool allowUserTabManagement_ = false;
|
bool allowUserTabManagement_ = false;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMimeData>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
||||||
@@ -97,6 +98,32 @@ void Button::setMenu(std::unique_ptr<QMenu> menu)
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Button::enableDrops(const std::vector<QString> &acceptedDropMimes_)
|
||||||
|
{
|
||||||
|
this->setAcceptDrops(true);
|
||||||
|
this->acceptedDropMimes = acceptedDropMimes_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
auto anyMatches = std::ranges::any_of(
|
||||||
|
this->acceptedDropMimes, [event](const QString &acceptedMime) {
|
||||||
|
return event->mimeData()->hasFormat(acceptedMime);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!anyMatches)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event->acceptProposedAction();
|
||||||
|
|
||||||
|
this->addClickEffect(QPoint{
|
||||||
|
this->width() / 2,
|
||||||
|
this->height() / 2,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Button::paintEvent(QPaintEvent * /*event*/)
|
void Button::paintEvent(QPaintEvent * /*event*/)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|||||||
@@ -100,7 +100,13 @@ public:
|
|||||||
/// Setter for #menu()
|
/// Setter for #menu()
|
||||||
void setMenu(std::unique_ptr<QMenu> menu);
|
void setMenu(std::unique_ptr<QMenu> menu);
|
||||||
|
|
||||||
|
/// Enable drops for this button
|
||||||
|
void enableDrops(const std::vector<QString> &acceptedDropMimes_);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
/// Emitted when a successful drop event has occurred on the button.
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
|
|
||||||
/// @brief Emitted after the user left-clicked the button.
|
/// @brief Emitted after the user left-clicked the button.
|
||||||
///
|
///
|
||||||
/// A click is only emitted if the user released the mouse above the button
|
/// A click is only emitted if the user released the mouse above the button
|
||||||
@@ -121,6 +127,8 @@ Q_SIGNALS:
|
|||||||
void leftMousePress();
|
void leftMousePress();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
|
||||||
void paintEvent(QPaintEvent * /*event*/) override;
|
void paintEvent(QPaintEvent * /*event*/) override;
|
||||||
|
|
||||||
/// @brief Paint the contents to be shown below the button
|
/// @brief Paint the contents to be shown below the button
|
||||||
@@ -216,6 +224,11 @@ private:
|
|||||||
bool pixmapValid_ = false;
|
bool pixmapValid_ = false;
|
||||||
bool cachePixmap_ = false;
|
bool cachePixmap_ = false;
|
||||||
bool opaqueContent_ = false;
|
bool opaqueContent_ = false;
|
||||||
|
|
||||||
|
/// List of Mimes (e.g. chatterino/split) that are accepted as drop events on this button
|
||||||
|
///
|
||||||
|
/// Controlled by the enableDrops function
|
||||||
|
std::vector<QString> acceptedDropMimes;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|||||||
@@ -1,162 +0,0 @@
|
|||||||
#include "widgets/buttons/NotebookButton.hpp"
|
|
||||||
|
|
||||||
#include "Application.hpp"
|
|
||||||
#include "common/QLogging.hpp"
|
|
||||||
#include "singletons/Theme.hpp"
|
|
||||||
#include "widgets/Notebook.hpp"
|
|
||||||
#include "widgets/splits/DraggedSplit.hpp"
|
|
||||||
#include "widgets/splits/Split.hpp"
|
|
||||||
#include "widgets/splits/SplitContainer.hpp"
|
|
||||||
|
|
||||||
#include <QMimeData>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QPainterPath>
|
|
||||||
#include <QRadialGradient>
|
|
||||||
|
|
||||||
namespace chatterino {
|
|
||||||
|
|
||||||
NotebookButton::NotebookButton(Type type_, Notebook *parent)
|
|
||||||
: Button(parent)
|
|
||||||
, parent_(parent)
|
|
||||||
, type(type_)
|
|
||||||
{
|
|
||||||
switch (this->type)
|
|
||||||
{
|
|
||||||
case Type::Plus: {
|
|
||||||
this->setAcceptDrops(true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotebookButton::themeChangedEvent()
|
|
||||||
{
|
|
||||||
this->setMouseEffectColor(this->theme->tabs.regular.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotebookButton::paintContent(QPainter &painter)
|
|
||||||
{
|
|
||||||
QColor background;
|
|
||||||
QColor foreground;
|
|
||||||
|
|
||||||
if (this->leftMouseButtonDown() || this->mouseOver())
|
|
||||||
{
|
|
||||||
background = this->theme->tabs.regular.backgrounds.hover;
|
|
||||||
foreground = this->theme->tabs.regular.text;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
background = this->theme->tabs.regular.backgrounds.regular;
|
|
||||||
foreground = this->theme->tabs.regular.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.setPen(Qt::NoPen);
|
|
||||||
|
|
||||||
float h = height(), w = width();
|
|
||||||
|
|
||||||
switch (this->type)
|
|
||||||
{
|
|
||||||
case Type::Plus: {
|
|
||||||
painter.setPen([&] {
|
|
||||||
QColor tmp = foreground;
|
|
||||||
if (isDraggingSplit())
|
|
||||||
{
|
|
||||||
tmp = this->theme->tabs.selected.line.regular;
|
|
||||||
}
|
|
||||||
else if (!this->mouseOver())
|
|
||||||
{
|
|
||||||
tmp.setAlpha(180);
|
|
||||||
}
|
|
||||||
return tmp;
|
|
||||||
}());
|
|
||||||
QRect rect = this->rect();
|
|
||||||
int s = h * 4 / 9;
|
|
||||||
|
|
||||||
painter.drawLine(rect.left() + rect.width() / 2 - (s / 2),
|
|
||||||
rect.top() + rect.height() / 2,
|
|
||||||
rect.left() + rect.width() / 2 + (s / 2),
|
|
||||||
rect.top() + rect.height() / 2);
|
|
||||||
painter.drawLine(rect.left() + rect.width() / 2,
|
|
||||||
rect.top() + rect.height() / 2 - (s / 2),
|
|
||||||
rect.left() + rect.width() / 2,
|
|
||||||
rect.top() + rect.height() / 2 + (s / 2));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotebookButton::dragEnterEvent(QDragEnterEvent *event)
|
|
||||||
{
|
|
||||||
if (this->type != Type::Plus)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!event->mimeData()->hasFormat("chatterino/split"))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event->acceptProposedAction();
|
|
||||||
|
|
||||||
this->addClickEffect(QPoint{
|
|
||||||
this->width() / 2,
|
|
||||||
this->height() / 2,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotebookButton::dropEvent(QDropEvent *event)
|
|
||||||
{
|
|
||||||
if (this->type != Type::Plus)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *draggedSplit = dynamic_cast<Split *>(event->source());
|
|
||||||
if (!draggedSplit)
|
|
||||||
{
|
|
||||||
qCDebug(chatterinoWidget)
|
|
||||||
<< "Dropped something that wasn't a split onto a notebook button";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *notebook = dynamic_cast<Notebook *>(this->parentWidget());
|
|
||||||
if (!notebook)
|
|
||||||
{
|
|
||||||
qCDebug(chatterinoWidget) << "Dropped a split onto a notebook button "
|
|
||||||
"without a parent notebook";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event->acceptProposedAction();
|
|
||||||
|
|
||||||
auto *page = new SplitContainer(notebook);
|
|
||||||
auto *tab = notebook->addPage(page);
|
|
||||||
page->setTab(tab);
|
|
||||||
|
|
||||||
draggedSplit->setParent(page);
|
|
||||||
page->insertSplit(draggedSplit);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotebookButton::hideEvent(QHideEvent *)
|
|
||||||
{
|
|
||||||
if (isAppAboutToQuit())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->parent_->refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotebookButton::showEvent(QShowEvent *)
|
|
||||||
{
|
|
||||||
if (isAppAboutToQuit())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->parent_->refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace chatterino
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "widgets/buttons/Button.hpp"
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
namespace chatterino {
|
|
||||||
|
|
||||||
class Notebook;
|
|
||||||
|
|
||||||
class NotebookButton : public Button
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum class Type : std::uint8_t {
|
|
||||||
Plus,
|
|
||||||
};
|
|
||||||
|
|
||||||
NotebookButton(Type type_, Notebook *parent);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintContent(QPainter &painter) override;
|
|
||||||
|
|
||||||
void themeChangedEvent() override;
|
|
||||||
void dragEnterEvent(QDragEnterEvent *) override;
|
|
||||||
void dropEvent(QDropEvent *) override;
|
|
||||||
|
|
||||||
void hideEvent(QHideEvent *) override;
|
|
||||||
void showEvent(QShowEvent *) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Notebook *parent_ = nullptr;
|
|
||||||
QPoint mousePos_;
|
|
||||||
Type type = Type::Plus;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace chatterino
|
|
||||||
Reference in New Issue
Block a user