SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "xkbobject.h"
XkbObject::XkbObject(XkbDescPtr xkb_, QObject *parent)
: QObject(parent)
, xkb(xkb_)
{
Q_ASSERT(xkb);
}
QColor XkbObject::colorFromName(const QString &colorName) const
{
const QColor easyColor = QColor::fromString(colorName);
if (easyColor.isValid()) {
return easyColor;
}
if (colorName.startsWith("grey") || colorName.startsWith("gray")) {
bool ok = false;
const int grayPct = colorName.sliced(4).toInt(&ok);
if (!ok) {
return QColor("gray");
}
return QColor::fromHsvF(0.0, 0.0, 1 - grayPct / 100.0);
}
if (colorName == "green30") {
const QColor green = QColor("green");
return QColor::fromHsvF(green.hueF(), green.saturationF(), 0.3);
}
return QColor();
}
QColor XkbObject::colorFromIndex(int index) const
{
if (!xkb->geom) {
return QColor();
}
return colorFromName(xkb->geom->colors[index].spec);
}