Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions src/ui/widgets/savedcolorswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,57 @@

#include "savedcolorswidget.h"
#include "widgets/savedcolorbutton.h"
#include <QAction>
#include <QMenu>

#include <QIcon>
#include <QPalette>
#include <QSize>
#include <QToolButton>
#include <QSizePolicy>

#include "colorhelpers.h"
#include "Private/document.h"
#include "GUI/global.h"
#include "themesupport.h"

SavedColorsWidget::SavedColorsWidget(QWidget *parent)
: QWidget(parent) {
mMainLayout = new FlowLayout(this);
setLayout(mMainLayout);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);

mAddButton = new QToolButton(this);
mAddButton->setCursor(Qt::PointingHandCursor);
mAddButton->setFocusPolicy(Qt::NoFocus);
mAddButton->setToolTip(tr("Add bookmarked color"));
mAddButton->setIcon(QIcon::fromTheme("plus"));
mAddButton->setAutoRaise(false);
mAddButton->setCheckable(false);
eSizesUI::widget.add(mAddButton, [this](int size) {
mAddButton->setFixedSize(size, size);
const int iconSide = qMax(0, size);
mAddButton->setIconSize(QSize(iconSide, iconSide));
});
const QColor baseColor = ThemeSupport::getThemeButtonBaseColor();
const QColor baseDarkerColor = ThemeSupport::getThemeBaseDarkerColor();
const QColor borderColor = ThemeSupport::getThemeButtonBorderColor();
const QColor hoverColor = ThemeSupport::getThemeHighlightColor();
const QString style = QStringLiteral(
"QToolButton { background-color: %1; border: 1px solid %2; padding: 0; }"
"QToolButton:hover { background-color: %4; border: 1px solid %3; }"
"QToolButton:pressed { border: 2px solid %3; }")
.arg(baseColor.name(), borderColor.name(), hoverColor.name(), baseDarkerColor.name());
mAddButton->setStyleSheet(style);
connect(mAddButton, &QToolButton::clicked,
this, &SavedColorsWidget::addCurrentColorRequested);
mMainLayout->addWidget(mAddButton);

for(const auto& color : Document::sInstance->fColors) {
addColor(color);
}
connect(Document::sInstance, &Document::bookmarkColorAdded,
this, &SavedColorsWidget::addColor);
connect(Document::sInstance, &Document::bookmarkColorRemoved,
this, &SavedColorsWidget::removeColor);
setVisible(!mButtons.isEmpty());
}

void SavedColorsWidget::addColor(const QColor& color) {
Expand All @@ -50,7 +84,6 @@ void SavedColorsWidget::addColor(const QColor& color) {
this, &SavedColorsWidget::colorSet);
mMainLayout->addWidget(button);
mButtons << button;
setVisible(!mButtons.isEmpty());
}

void SavedColorsWidget::removeColor(const QColor &color) {
Expand All @@ -62,7 +95,6 @@ void SavedColorsWidget::removeColor(const QColor &color) {
break;
}
}
setVisible(!mButtons.isEmpty());
}

void SavedColorsWidget::setColor(const QColor &color) {
Expand Down
3 changes: 3 additions & 0 deletions src/ui/widgets/savedcolorswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "colorhelpers.h"

class SavedColorButton;
class QToolButton;

class UI_EXPORT SavedColorsWidget : public QWidget
{
Expand All @@ -48,10 +49,12 @@ class UI_EXPORT SavedColorsWidget : public QWidget

private:
FlowLayout *mMainLayout = nullptr;
QToolButton *mAddButton = nullptr;
QList<SavedColorButton*> mButtons;

signals:
void colorSet(QColor);
void addCurrentColorRequested();
};

#endif // SAVEDCOLORSWIDGET_H