From 4bf24a45983560d63372767486963e630d0b473b Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Fri, 26 May 2017 02:08:55 +0200 Subject: [PATCH] Huge change in color configuration --- docs/dev/qsettings.md | 4 + src/capture/button.cpp | 40 ++++++-- src/capture/button.h | 8 ++ src/capture/capturewidget.cpp | 18 ++-- src/capture/capturewidget.h | 2 +- src/config/configwindow.cpp | 2 +- src/config/uicoloreditor.cpp | 91 +++++++++--------- src/config/uicoloreditor.h | 14 ++- src/controller.cpp | 4 +- translation/Internationalization_es.ts | 128 +++++++++++++------------ 10 files changed, 175 insertions(+), 136 deletions(-) diff --git a/docs/dev/qsettings.md b/docs/dev/qsettings.md index 317aa2d1..f0f73f3c 100644 --- a/docs/dev/qsettings.md +++ b/docs/dev/qsettings.md @@ -18,3 +18,7 @@ - value: "uiColor" - type: QColor - description: color of buttons and the selection. +- contast UI color + - value: "contastUiColor" + - type: QColor + - description: color of buttons awhile selected. diff --git a/src/capture/button.cpp b/src/capture/button.cpp index e85e7617..75ea97da 100644 --- a/src/capture/button.cpp +++ b/src/capture/button.cpp @@ -69,6 +69,8 @@ void Button::initButton() { emergeAnimation->setDuration(80); emergeAnimation->setStartValue(QSize(0, 0)); emergeAnimation->setEndValue(QSize(BUTTON_SIZE, BUTTON_SIZE)); + + setStyleSheet(getStyle()); } // getIcon returns the icon for the type of button, this method lets @@ -142,11 +144,12 @@ QIcon Button::getIcon(const Type t, bool isWhite) { QString Button::getStyle() { QSettings settings; - QColor mainColor = settings.value("uiColor").value(); - return getStyle(mainColor); + m_mainColor = settings.value("uiColor").value(); + return getStyle(m_mainColor); } QString Button::getStyle(const QColor &mainColor) { + m_mainColor = mainColor; QString baseSheet = "Button { border-radius: %3;" "background-color: %1; color: %4 }" "Button:hover { background-color: %2; }" @@ -154,22 +157,19 @@ QString Button::getStyle(const QColor &mainColor) { "background-color: %1; }"; QColor contrast(mainColor.darker(120)); - int sumRGB = mainColor.red() + mainColor.green() + mainColor.blue(); - if (sumRGB < 130) { + if (mainColor.valueF() < 0.5) { contrast = mainColor.lighter(160); } - bool iconsAreWhite = QSettings().value("whiteIconColor").toBool(); + QString color = "black"; - if (iconsAreWhite) { color = "white"; } + if (iconIsWhite(mainColor)) { 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) { - QSettings settings; - bool isWhite = settings.value("whiteIconColor").toBool(); - return getIcon(t, isWhite); + return getIcon(t, iconIsWhite(m_mainColor)); } void Button::enterEvent(QEvent *e) { @@ -212,6 +212,26 @@ void Button::animatedShow() { Button::Type Button::getButtonType() const { return m_buttonType; } + +void Button::updateIconColor(const QColor &c) { + setIcon(getIcon(m_buttonType, iconIsWhite(c))); +} + +void Button::updateIconColor() { + setIcon(getIcon(m_buttonType, iconIsWhite())); +} + +bool Button::iconIsWhite(const QColor &c) { + bool isWhite = true; + if (c.valueF() > 0.65) { + isWhite = false; + } + return isWhite; +} + +bool Button::iconIsWhite() const { + return iconIsWhite(m_mainColor); +} // getButtonBaseSize returns the base size of the buttons size_t Button::getButtonBaseSize() { return BUTTON_SIZE; @@ -271,3 +291,5 @@ Button::typeData Button::typeName = { {Button::Type::imageUploader, QT_TR_NOOP("Image Uploader")}, {Button::Type::move, QT_TR_NOOP("Move")} }; + +QColor Button::m_mainColor = QSettings().value("uiColor").value(); diff --git a/src/capture/button.h b/src/capture/button.h index 583ac984..89143eb6 100644 --- a/src/capture/button.h +++ b/src/capture/button.h @@ -63,6 +63,12 @@ public: Type getButtonType() const; + void updateIconColor(const QColor &); + void updateIconColor(); + + bool iconIsWhite() const; + static bool iconIsWhite(const QColor &); + void animatedShow(); protected: @@ -86,6 +92,8 @@ private: typedef QMap typeData; static typeData typeTooltip; static typeData typeName; + static QColor m_mainColor; + void initButton(); }; diff --git a/src/capture/capturewidget.cpp b/src/capture/capturewidget.cpp index 23eddfb0..14a06dca 100644 --- a/src/capture/capturewidget.cpp +++ b/src/capture/capturewidget.cpp @@ -38,7 +38,6 @@ #include #include #include -#include // CaptureWidget is the main component used to capture the screen. It contains an // are of selection with its respective buttons. @@ -82,10 +81,9 @@ CaptureWidget::CaptureWidget(QWidget *parent) : createCapture(); resize(m_screenshot->getScreenshot().size()); // init interface color - m_uiColor = QSettings().value("uiColor").value(); - m_reversedUiColor = QColor(255 - m_uiColor.red(), - 255 - m_uiColor.green(), - 255 - m_uiColor.blue()); + QSettings settings; + m_uiColor = settings.value("uiColor").value(); + m_contrastUiColor = settings.value("contastUiColor").value(); show(); m_colorPicker = new ColorPicker(this); @@ -100,13 +98,11 @@ CaptureWidget::~CaptureWidget() { // selection in the capture void CaptureWidget::redefineButtons() { QSettings settings; - QString buttonStyle = Button::getStyle(); auto buttonsInt = settings.value("buttons").value >(); QVector vectorButtons; for (auto i: buttonsInt) { auto t = static_cast(i); Button *b = new Button(t, this); - b->setStyleSheet(buttonStyle); if (t == Button::Type::selectionIndicator) { m_sizeIndButton = b; } @@ -457,13 +453,13 @@ void CaptureWidget::setState(Button *b) { } else { m_state = newState; if (m_lastPressedButton) { - m_lastPressedButton->setGraphicsEffect(0); + m_lastPressedButton->setStyleSheet(Button::getStyle()); + m_lastPressedButton->updateIconColor(); } m_lastPressedButton = b; if (m_state != Button::Type::move) { - QGraphicsColorizeEffect *e =new QGraphicsColorizeEffect(this); - e->setColor(m_reversedUiColor); - m_lastPressedButton->setGraphicsEffect(e); + m_lastPressedButton->setStyleSheet(Button::getStyle(m_contrastUiColor)); + m_lastPressedButton->updateIconColor(m_contrastUiColor); } } } diff --git a/src/capture/capturewidget.h b/src/capture/capturewidget.h index 9ad1e5c1..69ab4296 100644 --- a/src/capture/capturewidget.h +++ b/src/capture/capturewidget.h @@ -118,7 +118,7 @@ private: ButtonHandler *m_buttonHandler; QColor m_uiColor; - QColor m_reversedUiColor; + QColor m_contrastUiColor; ColorPicker *m_colorPicker; }; diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index 1d62a3d2..249853bb 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -29,7 +29,7 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_DeleteOnClose); - setFixedSize(280, 400); + setFixedSize(400, 400); setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); setWindowIcon(QIcon(":img/flameshot.svg")); setWindowTitle(tr("Configuration")); diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp index 224c1655..0aae7a18 100644 --- a/src/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -23,6 +23,7 @@ #include #include #include +#include UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) { setFrameStyle(QFrame::StyledPanel); @@ -30,8 +31,7 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) { hLayout = new QHBoxLayout; vLayout = new QVBoxLayout; - initButton(); - initComboBox(); + initButtons(); initColorWheel(); hLayout->addLayout(vLayout); setLayout(hLayout); @@ -40,13 +40,18 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) { void UIcolorEditor::updateUIcolor() { QSettings settings; - settings.setValue("uiColor", m_uiColor); + if (m_lastButtonPressed == m_buttonMainColor) { + settings.setValue("uiColor", m_uiColor); + } else { + settings.setValue("contastUiColor", m_uiColor); + } } void UIcolorEditor::updateLocalColor(const QColor c) { m_uiColor = c; QString style = Button::getStyle(c); - m_button->setStyleSheet(style); + m_lastButtonPressed->setStyleSheet(style); + updateButtonIcon(); } void UIcolorEditor::initColorWheel() { @@ -65,53 +70,53 @@ void UIcolorEditor::initColorWheel() { hLayout->addWidget(colorWheel); } -void UIcolorEditor::initButton() { - QFrame *frame = new QFrame(this); +void UIcolorEditor::initButtons() { const int extraSize = 10; int frameSize = Button::getButtonBaseSize() + extraSize; + + vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this)); + + QFrame *frame = new QFrame(this); 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); + m_buttonMainColor = new Button(Button::Type::circle, frame); + m_buttonMainColor->move(m_buttonMainColor->x() + extraSize/2, m_buttonMainColor->y() + extraSize/2); + QHBoxLayout *h1 = new QHBoxLayout(); + h1->addWidget(frame); + h1->addWidget(new QLabel(tr("Main Color"), this)); + vLayout->addLayout(h1); - m_button->setToolTip(tr("Color preview")); + m_buttonMainColor->setToolTip(tr("Main Color")); + + QFrame *frame2 = new QFrame(this); + frame2->setFixedSize(frameSize, frameSize); + frame2->setFrameStyle(QFrame::StyledPanel); + + m_buttonContrast = new Button(Button::Type::circle, frame2); + QColor contrastColor = QSettings().value("contastUiColor").value(); + m_buttonContrast->setStyleSheet(Button::getStyle(contrastColor)); + m_buttonContrast->move(m_buttonContrast->x() + extraSize/2, + m_buttonContrast->y() + extraSize/2); + + QHBoxLayout *h2 = new QHBoxLayout(); + h2->addWidget(frame2); + h2->addWidget(new QLabel(tr("Contrast Color"), this)); + vLayout->addLayout(h2); + + m_buttonContrast->setToolTip(tr("Contrast Color")); + + m_lastButtonPressed = m_buttonMainColor; + connect(m_buttonMainColor, &Button::pressedButton, + this, &UIcolorEditor::changeLastButton); + connect(m_buttonContrast, &Button::pressedButton, + this, &UIcolorEditor::changeLastButton); } -UIcolorEditor::colorToStringMap UIcolorEditor::iconColorToString = { - {iconColor::White, QT_TR_NOOP("White Icon")}, - {iconColor::Black, QT_TR_NOOP("Black Icon")} -}; - -void UIcolorEditor::initComboBox() { - QComboBox *comboBox = new QComboBox(this); - - QString textWhite = tr(iconColorToString[iconColor::White]); - QString textBlack = tr(iconColorToString[iconColor::Black]); - - 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); - - comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow); - vLayout->addWidget(comboBox); - +void UIcolorEditor::updateButtonIcon() { + m_lastButtonPressed->setIcon(Button::getIcon(m_buttonMainColor->getButtonType())); } -void UIcolorEditor::updateButtonIcon(const QString &text) { - bool iconsAreWhite = true; - QString blackMessage = tr(iconColorToString[iconColor::Black]); - if (text == blackMessage) { - iconsAreWhite = false; - } - m_button->setIcon(Button::getIcon(m_button->getButtonType(), iconsAreWhite)); - QSettings().setValue("whiteIconColor", iconsAreWhite); +void UIcolorEditor::changeLastButton(Button *b) { + m_lastButtonPressed = b; } diff --git a/src/config/uicoloreditor.h b/src/config/uicoloreditor.h index d9529338..1d64c055 100644 --- a/src/config/uicoloreditor.h +++ b/src/config/uicoloreditor.h @@ -32,22 +32,20 @@ public: private slots: void updateUIcolor(); void updateLocalColor(const QColor); - void updateButtonIcon(const QString &); + void updateButtonIcon(); + void changeLastButton(Button *); private: QColor m_uiColor; - Button *m_button; + Button *m_buttonMainColor; + Button *m_buttonContrast; + Button *m_lastButtonPressed; QHBoxLayout *hLayout; QVBoxLayout *vLayout; void initColorWheel(); - void initButton(); - void initComboBox(); - - enum class iconColor {Black, White}; - typedef QMap colorToStringMap; - static colorToStringMap iconColorToString; + void initButtons(); }; #endif // UICOLORPICKER_H diff --git a/src/controller.cpp b/src/controller.cpp index fae0b84a..2cb22337 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -89,8 +89,8 @@ void Controller::initDefaults() { settings.setValue("initiated", true); settings.setValue("drawColor", QColor(Qt::red)); //settings.setValue("mouseVisible", false); - settings.setValue("whiteIconColor", true); - settings.setValue("uiColor", QColor(136, 0, 170)); + settings.setValue("uiColor", QColor(116, 0, 150)); + settings.setValue("contastUiColor", QColor(86, 0, 120)); QList buttons; for (int i = 0; i < static_cast(Button::Type::last); ++i) { diff --git a/translation/Internationalization_es.ts b/translation/Internationalization_es.ts index 535c6635..9eb2ee5f 100644 --- a/translation/Internationalization_es.ts +++ b/translation/Internationalization_es.ts @@ -4,162 +4,162 @@ Button - + Shows the dimensions of the selection (X Y) Muestra la dimensión de ls selección (X Y) - + Sets the visibility of the mouse pointer Selecciona la visibilidad del puntero del ratón - + Leaves the capture screen Cierra la pantalla de captura - + Copies the selecion into the clipboard Copia la selección al portapapeles - + Opens the save image window Abre la ventana de guardar imagen - + Sets the paint tool to a pencil Establece el lápiz como herramienta de dibujo - + Sets the paint tool to a line drawer Establece la línea como herramienta de dibujo - + Sets the paint tool to an arrow drawer Establece la flecha como herramienta de dibujo - + Sets the paint tool to a rectagle drawer Establece el rectángulo como herramienta de dibujo - + Sets the paint tool to a circle drawer Establece el círculo como herramienta de dibujo - + Sets the paint tool to a marker Establece el marcador como herramienta de dibujo - + Sets the paint tool to a text creator Establece el texto como herramienta de dibujo - + Opens the color picker widget Abre el selector de color - + Undo the last modification Deshace la última modificación - + Upload the selection to Imgur Sube la selección a Imgur - + Move the selection area Mueve la selección - + Selection Size Indicator Indicador de Tamaño de Selección - + Mouse Visibility Visibilidad del Ratón - + Exit Salir - + Copy Copiar - + Save Guardar - + Pencil Lápiz - + Line Línea - + Arrow Flecha - + Rectangle Rectángulo - + Circle Círculo - + Marker Marcador - + Text Texto - + Color Picker Selector de Color - + Undo Deshacer - + Image Uploader Subir Imagen - + Move Mover Selección @@ -167,7 +167,7 @@ CaptureWidget - + Uploading image... Subiendo imagen... @@ -175,17 +175,17 @@ ConfigWindow - + Configuration Configuración - + UI color editor Editor de color de interfaz - + Button selection Selección de botones @@ -193,17 +193,17 @@ Controller - + &Configuration &Configuración - + &Information &Información - + &Quit &Salir @@ -211,67 +211,67 @@ InfoWindow - + About Información - + <b>Shortcuts</b> <b>Atajos</b> - + <b>License</b> <b>Licencia</b> - + Right Click Click Derecho - + Move selection 1px Mueve la selección 1px - + Resize selection 1px Redimensiona la selección 1px - + Quit capture Salir de la captura - + Copy to clipboard Copiar al portapapeles - + Save selection as a file Guarda la selección como un archivo - + Undo the last modification Deshacer la última modificación - + Show color picker Muestra el selector de color - + Key Tecla - + Description Descripción @@ -302,19 +302,25 @@ UIcolorEditor - - Color preview - Previsualización de color + Select a Button to change the color + Selecciona un Botón para cambiar el color - - White Icon - Icono Blanco + + Select a Button to modify it + Selecciona un Botón para modificarlo - - Black Icon - Icono Negro + + + Main Color + Color Principal + + + + + Contrast Color + Color de Contraste