diff --git a/qledlabel.cpp b/qledlabel.cpp index 640b1c4..5370b5e 100644 --- a/qledlabel.cpp +++ b/qledlabel.cpp @@ -38,4 +38,52 @@ void QLedLabel::setState(State state) void QLedLabel::setState(bool state) { setState(state ? StateOk : StateError); -} \ No newline at end of file +} + +void QLedLabel::setColor(QColor customColor, bool applyGradient=true) +{ + QColor top,middle,bottom; + this->baseColor = customColor; + + if(applyGradient) + { + top = customColor.lighter(200); + middle = customColor; + bottom = customColor.darker(200); + } else { + top = customColor; + middle = customColor; + bottom = customColor; + } + + // Stop 0 is the upper corner color, white-ish + // Stop 0.4 is the middle color + // Stop 1 is the bottom-right corner, darker. + + QString colorSS = QString("color: white;\ + border-radius: %1;background-color: \ + qlineargradient(spread:pad, x1:0.04, \ + y1:0.0565909, x2:0.799, y2:0.795, \ + stop:0 \ + rgba(%2, %3, %4, %5), \ + stop:0.41206 \ + rgba(%6, %7, %8, %9), \ + stop:1 \ + rgba(%10, %11, %12, %13));").arg(SIZE / 3) + .arg(top.red()).arg(top.green()).arg(top.blue()).arg(top.alpha()) + .arg(middle.red()).arg(middle.green()).arg(middle.blue()).arg(middle.alpha()) + .arg(bottom.red()).arg(bottom.green()).arg(bottom.blue()).arg(bottom.alpha()); + + setStyleSheet(colorSS); +} + +void QLedLabel::setColor(QString colorString, bool applyGradient=true) +{ + QColor c = QColor(colorString); + setColor(c, applyGradient); +} + +QColor QLedLabel::getColor() +{ + return baseColor; +} diff --git a/qledlabel.h b/qledlabel.h index b5dc706..824fbac 100644 --- a/qledlabel.h +++ b/qledlabel.h @@ -22,6 +22,12 @@ signals: public slots: void setState(State state); void setState(bool state); + void setColor(QColor customColor, bool applyGradient); + void setColor(QString colorString, bool applyGradient); + QColor getColor(); + +private: + QColor baseColor; }; #endif // QLEDLABEL_H diff --git a/wfmain.cpp b/wfmain.cpp index 01fe55b..4e07fd3 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -6219,3 +6219,58 @@ void wfmain::on_debugBtn_clicked() // adjustSize(); } + +void wfmain::setColorElement(QColor color, + QLedLabel *led, + QLabel *label, + QLineEdit *lineText) +{ + if(led != Q_NULLPTR) + { + led->setColor(color, true); + } + if(label != Q_NULLPTR) + { + label->setText(color.name(QColor::HexArgb)); + } + if(lineText != Q_NULLPTR) + { + lineText->setText(color.name(QColor::HexArgb)); + } +} + +void wfmain::setColorElement(QColor color, QLedLabel *led, QLabel *label) +{ + setColorElement(color, led, label, Q_NULLPTR); +} + +void wfmain::setColorElement(QColor color, QLedLabel *led, QLineEdit *lineText) +{ + setColorElement(color, led, Q_NULLPTR, lineText); +} + +QColor wfmain::getColor(QColor initialColor) +{ + QColorDialog::ColorDialogOptions options; + options.setFlag(QColorDialog::ShowAlphaChannel, true); + options.setFlag(QColorDialog::DontUseNativeDialog, true); + QColor selColor = QColorDialog::getColor(initialColor, this, "Select Color", options); + return selColor; +} + +void wfmain::getSetColor(QLedLabel *led, QLabel *label) +{ + QColor selColor = getColor(led->getColor()); + setColorElement(selColor, led, label); +} + +void wfmain::getSetColor(QLedLabel *led, QLineEdit *line) +{ + QColor selColor = getColor(led->getColor()); + setColorElement(selColor, led, line); +} + +void wfmain::on_colorSetBtnGrid_clicked() +{ + getSetColor(ui->colorSwatchGrid, ui->colorLabelGrid); +} diff --git a/wfmain.h b/wfmain.h index 664dc8a..ba21879 100644 --- a/wfmain.h +++ b/wfmain.h @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "logcategories.h" #include "commhandler.h" @@ -553,6 +555,8 @@ private slots: void on_underlayAverageBuffer_toggled(bool checked); + void on_colorSetBtnGrid_clicked(); + private: Ui::wfmain *ui; void closeEvent(QCloseEvent *event); @@ -833,6 +837,12 @@ private: void useColors(); // set the plot up void setDefPrefs(); // populate default values to default prefs void setTuningSteps(); + void setColorElement(QColor color, QLedLabel *led, QLabel *label); + void setColorElement(QColor color, QLedLabel *led, QLineEdit *lineText); + void setColorElement(QColor color, QLedLabel *led, QLabel *label, QLineEdit *lineText); + QColor getColor(QColor initialColor); + void getSetColor(QLedLabel *led, QLabel *label); + void getSetColor(QLedLabel *led, QLineEdit *line); quint64 roundFrequency(quint64 frequency, unsigned int tsHz); quint64 roundFrequencyWithStep(quint64 oldFreq, int steps,\ diff --git a/wfmain.ui b/wfmain.ui index 6b92776..682777e 100644 --- a/wfmain.ui +++ b/wfmain.ui @@ -3081,6 +3081,139 @@ + + + + + 0 + 0 + + + + User-defined colors + + + + + + true + + + + + 0 + 0 + 767 + 192 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Grid... + + + + + + + PushButton + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + PushButton + + + + + + + PushButton + + + + + + + PushButton + + + + + + + GRID + + + + + + + PushButton + + + + + + + TextLabel + + + + + + + + 15 + 15 + + + + + 15 + 15 + + + + + + + + + + + @@ -3089,7 +3222,7 @@ 20 - 40 + 20 @@ -4017,11 +4150,17 @@
meter.h
1 + + QLedLabel + QWidget +
qledlabel.h
+ 1 +
- +