14#include <QStyleOption>
33 updateAccessibleName();
41 updateAccessibleName();
48 d->state = (state == Off ? Off : On);
53 updateAccessibleName();
80 if (d->state == state) {
84 d->state = (state == Off ? Off : On);
86 updateAccessibleName();
91 if (d->shape == shape) {
101 if (d->color == color) {
106 updateCachedPixmap();
111 if (d->darkFactor == darkFactor) {
115 d->darkFactor = darkFactor;
116 updateCachedPixmap();
119int KLed::darkFactor()
const
121 return d->darkFactor;
126 if (d->look == look) {
131 updateCachedPixmap();
136 d->state = (d->state == On ? Off : On);
137 updateCachedPixmap();
138 updateAccessibleName();
153 updateCachedPixmap();
156QSize KLed::sizeHint()
const
161 return QSize(iconSize, iconSize);
164QSize KLed::minimumSizeHint()
const
166 return QSize(16, 16);
169void KLed::updateAccessibleName()
171#ifndef QT_NO_ACCESSIBILITY
172 QString onName =
tr(
"LED on",
"Accessible name of a Led whose state is on");
173 QString offName =
tr(
"LED off",
"Accessible name of a Led whose state is off");
176 if (lastName.
isEmpty() || lastName == onName || lastName == offName) {
184void KLed::updateCachedPixmap()
186 d->cachedPixmap[Off] =
QPixmap();
187 d->cachedPixmap[On] =
QPixmap();
193 if (!d->cachedPixmap[d->state].isNull()) {
195 painter.drawPixmap(1, 1, d->cachedPixmap[d->state]);
200 if (d->shape == Circular) {
206 const int smallestSize = qMin(
size.width(),
size.height());
213 const QColor fillColor = d->state != Off ? d->color : d->color.darker(d->darkFactor);
214 fillGradient.setColorAt(0.0, fillColor.
lighter(250));
215 fillGradient.setColorAt(0.5, fillColor.
lighter(130));
216 fillGradient.setColorAt(1.0, fillColor);
220 if (d->state == On) {
221 QColor glowOverlay = fillColor;
230 p.fillRect(0, 0, 1, 1,
start);
232 p.fillRect(0, 0, 1, 1, glowOverlay);
235 borderColor = img.pixel(0, 0);
237 borderGradient.setColorAt(0.2, borderColor);
239 borderGradient.setColorAt(0.8, borderColor);
241 painter.
begin(&image);
244 const QBrush penBrush = (d->look == Flat) ?
QBrush(borderColor) :
QBrush(borderGradient);
245 const qreal penWidth = smallestSize / 8.0;
247 QRectF r(penWidth / 2.0, penWidth / 2.0,
size.width() - penWidth,
size.height() - penWidth);
248 if (d->shape == Rectangular) {
257 painter.
drawPixmap(1, 1, d->cachedPixmap[d->state]);
261#include "moc_kled.cpp"
void on()
Sets the state of the widget to On.
void setColor(const QColor &color)
Set the color of the widget.
State
Status of the light is on/off.
void setDarkFactor(int darkFactor)
Sets the factor to darken the LED in KLed::Off state.
~KLed() override
Destroys the LED widget.
Look
Displays a flat, round or sunken LED.
void setShape(Shape shape)
Set the shape of the LED.
KLed(QWidget *parent=nullptr)
Constructs a green, round LED widget which will initially be turned on.
void off()
Sets the state of the widget to Off.
void setState(State state)
Sets the state of the widget to On or Off.
void toggle()
Toggles the state of the led from Off to On or vice versa.
void setLook(Look look)
Sets the look of the widget.
Q_SCRIPTABLE Q_NOREPLY void start()
QColor lighter(int factor) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
CompositionMode_SourceOver
bool begin(QPaintDevice *device)
void drawEllipse(const QPoint ¢er, int rx, int ry)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void drawRect(const QRect &rectangle)
void setBrush(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
void setRenderHint(RenderHint hint, bool on)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
bool isEmpty() const const
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const const=0
void initFrom(const QWidget *widget)
QTextStream & center(QTextStream &stream)