Complete the color edition menu

This commit is contained in:
lupoDharkael
2017-05-23 17:57:40 +02:00
parent 54bad72272
commit 1ac73d6453
3 changed files with 54 additions and 7 deletions

View File

@@ -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) {

View File

@@ -21,19 +21,20 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSettings>
#include <QComboBox>
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);
}

View File

@@ -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