kopia lustrzana https://gitlab.com/eliggett/wfview
Added color picker functions and demonstration UI elements
rodzic
ab65f8e38d
commit
1423e7c300
|
@ -38,4 +38,52 @@ void QLedLabel::setState(State state)
|
|||
void QLedLabel::setState(bool state)
|
||||
{
|
||||
setState(state ? StateOk : StateError);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
55
wfmain.cpp
55
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);
|
||||
}
|
||||
|
|
10
wfmain.h
10
wfmain.h
|
@ -16,6 +16,8 @@
|
|||
#include <QMetaType>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QColorDialog>
|
||||
#include <QColor>
|
||||
|
||||
#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,\
|
||||
|
|
143
wfmain.ui
143
wfmain.ui
|
@ -3081,6 +3081,139 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_9">
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>User-defined colors</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>767</width>
|
||||
<height>192</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer_29">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="colorSetBtnGrid">
|
||||
<property name="text">
|
||||
<string>Grid...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_44">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_46">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pushButton_5">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="colorLabelGrid">
|
||||
<property name="text">
|
||||
<string>GRID</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="label_45">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLedLabel" name="colorSwatchGrid" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
|
@ -3089,7 +3222,7 @@
|
|||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
@ -4017,11 +4150,17 @@
|
|||
<header>meter.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QLedLabel</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qledlabel.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="underlayButtonGroup"/>
|
||||
<buttongroup name="buttonGroup"/>
|
||||
<buttongroup name="underlayButtonGroup"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
|
|
Ładowanie…
Reference in New Issue