Add ui color edition with preview
This commit is contained in:
@@ -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<QColor>();
|
||||
return getStyle(mainColor);
|
||||
}
|
||||
|
||||
QString Button::getStyle(QColor mainColor) {
|
||||
QString baseSheet = "Button { border-radius: 15px;"
|
||||
"background-color: %1; color: white }"
|
||||
"Button:hover { background-color: %2; }"
|
||||
|
||||
@@ -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<Button::Type, const QString> typeData;
|
||||
static typeData typeTooltip;
|
||||
static typeData typeName;
|
||||
|
||||
void initButton();
|
||||
};
|
||||
|
||||
#endif // BUTTON_H
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "config/uicoloreditor.h"
|
||||
#include <QIcon>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QDebug>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,33 +1,21 @@
|
||||
#include "uicoloreditor.h"
|
||||
#include "color_wheel.hpp"
|
||||
#include "buttonlistview.h"
|
||||
#include "capture/button.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QSettings>
|
||||
|
||||
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<QColor>();
|
||||
|
||||
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<QColor>();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#ifndef UICOLORPICKER_H
|
||||
#define UICOLORPICKER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QFrame>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user