diff --git a/src/ui/widgets/colortoolbutton.cpp b/src/ui/widgets/colortoolbutton.cpp index 6e77620e3..6e05f6a5c 100644 --- a/src/ui/widgets/colortoolbutton.cpp +++ b/src/ui/widgets/colortoolbutton.cpp @@ -25,6 +25,7 @@ #include "Animators/coloranimator.h" #include "Animators/outlinesettingsanimator.h" #include "Animators/paintsettingsanimator.h" +#include "GUI/global.h" #include "Private/document.h" #include "colorsetting.h" #include "themesupport.h" @@ -35,53 +36,17 @@ using namespace Friction::Ui; -class AWidget : public QWidget -{ -public: - AWidget(QWidget *parent = nullptr) : QWidget(parent) {} - -protected: - void showEvent(QShowEvent *e) override - { - adjustSize(); // force resize since it's a popup - QWidget::showEvent(e); - } -}; - -class AScrollArea : public QScrollArea -{ -public: - AScrollArea(QWidget *parent = nullptr) : QScrollArea(parent) - { - setObjectName("NoMarginVerticalScrollBar"); - setPalette(ThemeSupport::getDarkerPalette()); - setAutoFillBackground(true); - setWidgetResizable(true); - setContentsMargins(0, 0, 0, 0); - setBackgroundRole(QPalette::Window); - setFrameShadow(QFrame::Plain); - setFrameShape(QFrame::NoFrame); - } - -protected: - void showEvent(QShowEvent *e) override - { - widget()->update(); - widget()->adjustSize(); - setWidget(takeWidget()); - QWidget::showEvent(e); - } -}; - ColorToolButton::ColorToolButton(Document& document, QWidget *parent, const bool fillOnly, const bool strokeOnly, const bool flatOnly) - : ToolButton(parent) + : QToolButton(parent) , mIsFillOnly(fillOnly) , mIsStrokeOnly(strokeOnly) , mIsFlatOnly(flatOnly) + , mPop(nullptr) + , mScroll(nullptr) , mColor(Qt::transparent) , mColorLabel(nullptr) , mBackgroundWidget(nullptr) @@ -89,18 +54,25 @@ ColorToolButton::ColorToolButton(Document& document, , mColorAct(nullptr) , mDocument(document) { - setAutoPopup(false); // TODO: add to settings (auto/click popup) + setFocusPolicy(Qt::NoFocus); setPopupMode(ToolButtonPopupMode::InstantPopup); - const auto pop = new AWidget(this); - const auto popLay = new QVBoxLayout(pop); + mPop = new QWidget(this); + mPop->setObjectName("DarkWidget"); + const auto popLay = new QVBoxLayout(mPop); + + mPop->setMinimumSize({300, 235}); - pop->setContentsMargins(10, 10, 10, 10); - pop->setMinimumSize({300, mIsFlatOnly ? 200 : 260}); - popLay->setMargin(0); + mScroll = new QScrollArea(this); + mScroll->setObjectName("DarkWidget"); + mScroll->setFocusPolicy(Qt::NoFocus); - const auto area = new AScrollArea(this); - popLay->addWidget(area); + mScroll->setBackgroundRole(QPalette::Window); + mScroll->setFrameShadow(QFrame::Plain); + mScroll->setFrameShape(QFrame::NoFrame); + mScroll->setWidgetResizable(true); + + popLay->addWidget(mScroll); if (!mIsFlatOnly) { mFillStrokeWidget = new FillStrokeSettingsWidget(mDocument, @@ -109,15 +81,16 @@ ColorToolButton::ColorToolButton(Document& document, mIsFillOnly, mIsStrokeOnly); mFillStrokeWidget->setContentsMargins(0, 0, 0, 0); - area->setWidget(mFillStrokeWidget); + mScroll->setWidget(mFillStrokeWidget); } else { mBackgroundWidget = new ColorSettingsWidget(this); + mBackgroundWidget->setObjectName("DarkWidget"); mBackgroundWidget->setColorModeVisible(false); - area->setWidget(mBackgroundWidget); + mScroll->setWidget(mBackgroundWidget); } mColorAct = new QWidgetAction(this); - mColorAct->setDefaultWidget(pop); + mColorAct->setDefaultWidget(mPop); mColorLabel = new ColorLabel(this, false); @@ -196,3 +169,19 @@ QColor ColorToolButton::color() const if (mColorTarget) { return mColorTarget->getColor(); } return mColor; } + +void ColorToolButton::mousePressEvent(QMouseEvent *e) +{ + if (mFillStrokeWidget) { mFillStrokeWidget->adjustSize(); } + else if (mBackgroundWidget) { mBackgroundWidget->adjustSize(); } + + mScroll->setWidget(mScroll->takeWidget()); + mScroll->adjustSize(); + mScroll->setMinimumHeight(mScroll->widget()->sizeHint().height() + 10); + + mPop->adjustSize(); + + qDebug() << "pop" << mPop->sizeHint() << "scroll" << mScroll->sizeHint(); + + QToolButton::mousePressEvent(e); +} diff --git a/src/ui/widgets/colortoolbutton.h b/src/ui/widgets/colortoolbutton.h index fd438c27f..ac8491891 100644 --- a/src/ui/widgets/colortoolbutton.h +++ b/src/ui/widgets/colortoolbutton.h @@ -27,22 +27,22 @@ #include "ui_global.h" #include "Private/document.h" -#include "gradientwidgets/gradientwidget.h" #include "Animators/coloranimator.h" #include "widgets/colorlabel.h" -#include "widgets/toolbutton.h" #include "conncontextptr.h" #include "widgets/colorsettingswidget.h" #include "widgets/fillstrokesettings.h" +#include #include #include +#include namespace Friction { namespace Ui { - class UI_EXPORT ColorToolButton : public ToolButton + class UI_EXPORT ColorToolButton : public QToolButton { public: ColorToolButton(Document& document, @@ -57,10 +57,15 @@ namespace Friction void updateColor(); QColor color() const; + protected: + void mousePressEvent(QMouseEvent *e) override; + private: bool mIsFillOnly; bool mIsStrokeOnly; bool mIsFlatOnly; + QWidget *mPop; + QScrollArea *mScroll; QColor mColor; ColorLabel *mColorLabel; ColorSettingsWidget *mBackgroundWidget; diff --git a/src/ui/widgets/fillstrokesettings.cpp b/src/ui/widgets/fillstrokesettings.cpp index c8ca670d1..a8a78d0ec 100644 --- a/src/ui/widgets/fillstrokesettings.cpp +++ b/src/ui/widgets/fillstrokesettings.cpp @@ -322,11 +322,11 @@ FillStrokeSettingsWidget::FillStrokeSettingsWidget(Document &document, mLayout->setContentsMargins(0, 0, 0, 0); mLayout->setMargin(0); + mFillAndStrokeWidget->setObjectName("DarkWidget"); if (noScroll) { mLayout->addWidget(mFillAndStrokeWidget); } else { const auto mFillStrokeArea = new ScrollArea(this); - mFillAndStrokeWidget->setObjectName("DarkWidget"); mFillStrokeArea->setWidget(mFillAndStrokeWidget); mLayout->addWidget(mFillStrokeArea); }