diff --git a/capture/button.cpp b/capture/button.cpp index d7651729..60c6b0b7 100644 --- a/capture/button.cpp +++ b/capture/button.cpp @@ -28,12 +28,9 @@ namespace { const int BUTTON_SIZE = 30; } -Button::Button(Type t, QWidget *parent) : QPushButton(parent) { - setFocusPolicy(Qt::NoFocus); - m_buttonType = t; - resize(BUTTON_SIZE, BUTTON_SIZE); - setMouseTracking(true); - setMask(QRegion(QRect(-1,-1,BUTTON_SIZE+2, BUTTON_SIZE+2), QRegion::Ellipse)); +Button::Button(Type t, QWidget *parent) : QPushButton(parent), + m_buttonType(t) { + initButton(); if (t == Button::Type::selectionIndicator) { QFont f = this->font(); @@ -41,14 +38,33 @@ Button::Button(Type t, QWidget *parent) : QPushButton(parent) { } else { setIcon(getIcon(t)); } - setToolTip(typeTooltip[t]); +} + +Button::Button(Button::Type t, bool isWhite, QWidget *parent) : QPushButton(parent), + m_buttonType(t) { + initButton(); + + if (t == Button::Type::selectionIndicator) { + QFont f = this->font(); + setFont(QFont(f.family(), 7, QFont::Bold)); + } else { + setIcon(getIcon(t, isWhite)); + } +} + +void Button::initButton() { + setFocusPolicy(Qt::NoFocus); + resize(BUTTON_SIZE, BUTTON_SIZE); + setMouseTracking(true); + setMask(QRegion(QRect(-1,-1,BUTTON_SIZE+2, BUTTON_SIZE+2), QRegion::Ellipse)); + + setToolTip(typeTooltip[m_buttonType]); emergeAnimation = new QPropertyAnimation(this, "size", this); emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad); emergeAnimation->setDuration(80); emergeAnimation->setStartValue(QSize(0, 0)); emergeAnimation->setEndValue(QSize(BUTTON_SIZE, BUTTON_SIZE)); - } // getIcon returns the icon for the type of button, this method lets @@ -123,6 +139,10 @@ QIcon Button::getIcon(const Type t, bool isWhite) { QString Button::getStyle() { QSettings settings; QColor mainColor = settings.value("uiColor").value(); + return getStyle(mainColor); +} + +QString Button::getStyle(QColor mainColor) { QString baseSheet = "Button { border-radius: 15px;" "background-color: %1; color: white }" "Button:hover { background-color: %2; }" diff --git a/capture/button.h b/capture/button.h index 86ad4830..717d5b69 100644 --- a/capture/button.h +++ b/capture/button.h @@ -50,10 +50,12 @@ public: }; explicit Button(Type, QWidget *parent = 0); + explicit Button(Type, bool isWhite, QWidget *parent = 0); static QIcon getIcon(const Type); static QIcon getIcon(const Type, bool isWhite); static QString getStyle(); + static QString getStyle(QColor); static size_t getButtonBaseSize(); static Button::Type getTypeByName(QString); static QString getTypeName(Button::Type); @@ -82,6 +84,8 @@ private: typedef std::map typeData; static typeData typeTooltip; static typeData typeName; + + void initButton(); }; #endif // BUTTON_H diff --git a/config/configwindow.cpp b/config/configwindow.cpp index 2c9ce491..15d1c61f 100644 --- a/config/configwindow.cpp +++ b/config/configwindow.cpp @@ -21,6 +21,7 @@ #include "config/uicoloreditor.h" #include #include +#include #include #include @@ -33,12 +34,12 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QWidget(parent){ QVBoxLayout *baseLayout = new QVBoxLayout(this); - QLabel *colorSelectionLabel = new QLabel("Choose the UI color", this); + QLabel *colorSelectionLabel = new QLabel("UI color editor", this); baseLayout->addWidget(colorSelectionLabel); baseLayout->addWidget(new UIcolorEditor(this)); - QLabel *buttonSelectLabel = new QLabel("Choose the buttons to enable", this); + QLabel *buttonSelectLabel = new QLabel("Button selection", this); baseLayout->addWidget(buttonSelectLabel); ButtonListView *m_buttonListView = new ButtonListView(this); diff --git a/config/uicoloreditor.cpp b/config/uicoloreditor.cpp index 638a3b2d..56c4cccd 100644 --- a/config/uicoloreditor.cpp +++ b/config/uicoloreditor.cpp @@ -1,33 +1,21 @@ #include "uicoloreditor.h" #include "color_wheel.hpp" -#include "buttonlistview.h" +#include "capture/button.h" #include #include #include -UIcolorEditor::UIcolorEditor(QWidget *parent) : QWidget(parent) { +UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) { setFixedSize(200,130); - QHBoxLayout *hLayout = new QHBoxLayout; - QVBoxLayout *vLayout = new QVBoxLayout; - setLayout(hLayout); + setFrameStyle(QFrame::StyledPanel); - color_widgets::ColorWheel *colorWheel = new color_widgets::ColorWheel(this); - connect(colorWheel, &color_widgets::ColorWheel::mouseReleaseOnColor, this, - &UIcolorEditor::updateUIcolor); - connect(colorWheel, &color_widgets::ColorWheel::colorChanged, this, - &UIcolorEditor::updateLocalColor); - - QSettings settings; - m_uiColor = settings.value("uiColor").value(); - - colorWheel->setColor(m_uiColor); - colorWheel->setFixedSize(100,100); - hLayout->addWidget(colorWheel); + hLayout = new QHBoxLayout; + vLayout = new QVBoxLayout; + initButton(); + initColorWheel(); hLayout->addLayout(vLayout); - - setLayout(hLayout); } @@ -38,4 +26,32 @@ void UIcolorEditor::updateUIcolor() { void UIcolorEditor::updateLocalColor(QColor c) { m_uiColor = c; + QString style = Button::getStyle(c); + m_button->setStyleSheet(style); +} + +void UIcolorEditor::initColorWheel() { + color_widgets::ColorWheel *colorWheel = new color_widgets::ColorWheel(this); + connect(colorWheel, &color_widgets::ColorWheel::mouseReleaseOnColor, this, + &UIcolorEditor::updateUIcolor); + connect(colorWheel, &color_widgets::ColorWheel::colorChanged, this, + &UIcolorEditor::updateLocalColor); + + QSettings settings; + m_uiColor = settings.value("uiColor").value(); + + colorWheel->setColor(m_uiColor); + colorWheel->setFixedSize(100,100); + + hLayout->addWidget(colorWheel); +} + +void UIcolorEditor::initButton() { + bool iconsAreWhite = false; + 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()); } diff --git a/config/uicoloreditor.h b/config/uicoloreditor.h index dff47375..66db87d5 100644 --- a/config/uicoloreditor.h +++ b/config/uicoloreditor.h @@ -1,9 +1,13 @@ #ifndef UICOLORPICKER_H #define UICOLORPICKER_H -#include +#include -class UIcolorEditor : public QWidget { +class QVBoxLayout; +class QHBoxLayout; +class Button; + +class UIcolorEditor : public QFrame { Q_OBJECT public: explicit UIcolorEditor(QWidget *parent = 0); @@ -14,6 +18,13 @@ private slots: private: QColor m_uiColor; + Button *m_button; + + QHBoxLayout *hLayout; + QVBoxLayout *vLayout; + + void initColorWheel(); + void initButton(); }; #endif // UICOLORPICKER_H