From 1ac73d6453e447e6973a90d5542bf35345f3794e Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Tue, 23 May 2017 17:57:40 +0200 Subject: [PATCH] Complete the color edition menu --- src/capture/button.cpp | 9 +++++-- src/config/uicoloreditor.cpp | 50 ++++++++++++++++++++++++++++++++---- src/config/uicoloreditor.h | 2 ++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/capture/button.cpp b/src/capture/button.cpp index 809b3401..4d9e7aca 100644 --- a/src/capture/button.cpp +++ b/src/capture/button.cpp @@ -146,7 +146,7 @@ QString Button::getStyle() { QString Button::getStyle(const QColor &mainColor) { QString baseSheet = "Button { border-radius: %3;" - "background-color: %1; color: white }" + "background-color: %1; color: %4 }" "Button:hover { background-color: %2; }" "Button:pressed:!hover { " "background-color: %1; }"; @@ -154,7 +154,12 @@ QString Button::getStyle(const QColor &mainColor) { if (mainColor.name() < QColor(30,30,30).name()) { contrast = contrast.lighter(120); } - return baseSheet.arg(mainColor.name()).arg(contrast.name()).arg(BUTTON_SIZE/2); + bool iconsAreWhite = QSettings().value("whiteIconColor").toBool(); + QString color = "black"; + if (iconsAreWhite) { color = "white"; } + + return baseSheet.arg(mainColor.name()).arg(contrast.name()) + .arg(BUTTON_SIZE/2).arg(color); } // get icon returns the icon for the type of button QIcon Button::getIcon(const Type t) { diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp index 9e5a56a2..e75ff6fc 100644 --- a/src/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -21,19 +21,20 @@ #include #include #include +#include UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) { - setFixedSize(200,130); setFrameStyle(QFrame::StyledPanel); hLayout = new QHBoxLayout; vLayout = new QVBoxLayout; initButton(); + initComboBox(); initColorWheel(); hLayout->addLayout(vLayout); - setLayout(hLayout); + } void UIcolorEditor::updateUIcolor() { @@ -47,6 +48,15 @@ void UIcolorEditor::updateLocalColor(const QColor c) { m_button->setStyleSheet(style); } +void UIcolorEditor::updateButtonIcon(const QString &text) { + bool iconsAreWhite = true; + if (text.contains("Black")) { + iconsAreWhite = false; + } + m_button->setIcon(Button::getIcon(m_button->getButtonType(), iconsAreWhite)); + QSettings().setValue("whiteIconColor", iconsAreWhite); +} + void UIcolorEditor::initColorWheel() { color_widgets::ColorWheel *colorWheel = new color_widgets::ColorWheel(this); connect(colorWheel, &color_widgets::ColorWheel::mouseReleaseOnColor, this, @@ -64,11 +74,41 @@ void UIcolorEditor::initColorWheel() { } void UIcolorEditor::initButton() { + QFrame *frame = new QFrame(this); + const int extraSize = 10; + int frameSize = Button::getButtonBaseSize() + extraSize; + frame->setFixedSize(frameSize, frameSize); + frame->setFrameStyle(QFrame::StyledPanel); + bool iconsAreWhite = QSettings().value("whiteIconColor").toBool(); + m_button = new Button(Button::Type::circle, iconsAreWhite, frame); + m_button->move(m_button->x() + extraSize/2, m_button->y() + extraSize/2); + vLayout->addWidget(frame); + // QString bgColor = this->palette().color(QWidget::backgroundRole()).name(); // if (bgColor < QColor(Qt::gray).name()) { // iconsAreWhite = true; -// } - m_button = new Button(Button::Type::circle, iconsAreWhite, this); - m_button->setStyleSheet(Button::getStyle()); + // } +} + +void UIcolorEditor::initComboBox() { + QComboBox *comboBox = new QComboBox(this); + comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow); + comboBox->setFixedSize(comboBox->width(), comboBox->height()); + + vLayout->addWidget(comboBox); + + QString textWhite = "White Icon"; + QString textBlack = "Black Icon"; + + comboBox->addItem(textWhite); + comboBox->addItem(textBlack); + bool iconsAreWhite = QSettings().value("whiteIconColor").toBool(); + if (iconsAreWhite) { + comboBox->setCurrentText(textWhite); + } else { + comboBox->setCurrentText(textBlack); + } + connect(comboBox, &QComboBox::currentTextChanged, this, &UIcolorEditor::updateButtonIcon); + } diff --git a/src/config/uicoloreditor.h b/src/config/uicoloreditor.h index 2062c1eb..0f43dc04 100644 --- a/src/config/uicoloreditor.h +++ b/src/config/uicoloreditor.h @@ -32,6 +32,7 @@ public: private slots: void updateUIcolor(); void updateLocalColor(const QColor); + void updateButtonIcon(const QString &); private: QColor m_uiColor; @@ -42,6 +43,7 @@ private: void initColorWheel(); void initButton(); + void initComboBox(); }; #endif // UICOLORPICKER_H