Material: Material editor enhancements (#11764)
Continues the work of the material subsystem improvements. Add support for embedded SVG files. These are not the same as image files so need to be handled differently. Add the ability to filter materials in the editor when called from code. This allows programs to select objects supporting specific models, complete models, older models, etc. Updated tests, and refactored code. New models and materials supporting patterns such as used by the TechDraw workbench. fixes #11686 - checks for the presense of a model property before assinging a value. This can happen when a required model definition is not available. --------- Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <QPainter>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSvgRenderer>
|
||||
#include <QTextStream>
|
||||
#include <QVariant>
|
||||
#endif
|
||||
@@ -59,9 +60,109 @@
|
||||
using namespace MatGui;
|
||||
|
||||
MaterialDelegate::MaterialDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
: BaseDelegate(parent)
|
||||
{}
|
||||
|
||||
Materials::MaterialValue::ValueType MaterialDelegate::getType(const QModelIndex& index) const
|
||||
{
|
||||
auto treeModel = dynamic_cast<const QStandardItemModel*>(index.model());
|
||||
auto item = treeModel->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
QString propertyType;
|
||||
if (group->child(row, 1)) {
|
||||
propertyType = group->child(row, 2)->text();
|
||||
}
|
||||
|
||||
return Materials::MaterialValue::mapType(propertyType);
|
||||
}
|
||||
|
||||
QString MaterialDelegate::getUnits(const QModelIndex& index) const
|
||||
{
|
||||
auto treeModel = dynamic_cast<const QStandardItemModel*>(index.model());
|
||||
auto item = treeModel->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
QString propertyUnits;
|
||||
if (group->child(row, 1)) {
|
||||
propertyUnits = group->child(row, 3)->text();
|
||||
}
|
||||
return propertyUnits;
|
||||
}
|
||||
|
||||
QVariant MaterialDelegate::getValue(const QModelIndex& index) const
|
||||
{
|
||||
auto treeModel = dynamic_cast<const QStandardItemModel*>(index.model());
|
||||
auto item = treeModel->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
QVariant propertyValue;
|
||||
if (group->child(row, 1)) {
|
||||
auto material = group->child(row, 1)->data().value<std::shared_ptr<Materials::Material>>();
|
||||
auto propertyName = group->child(row, 0)->text();
|
||||
propertyValue = material->getProperty(propertyName)->getValue();
|
||||
}
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
void MaterialDelegate::setValue(QAbstractItemModel* model,
|
||||
const QModelIndex& index,
|
||||
const QVariant& value) const
|
||||
{
|
||||
auto matModel = dynamic_cast<const QStandardItemModel*>(model);
|
||||
auto item = matModel->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
if (group->child(row, 1)) {
|
||||
auto material = group->child(row, 1)->data().value<std::shared_ptr<Materials::Material>>();
|
||||
auto propertyName = group->child(row, 0)->text();
|
||||
material->getProperty(propertyName)->setValue(value);
|
||||
group->child(row, 1)->setText(value.toString());
|
||||
}
|
||||
|
||||
notifyChanged(model, index);
|
||||
}
|
||||
|
||||
void MaterialDelegate::notifyChanged(const QAbstractItemModel* model,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
Base::Console().Log("MaterialDelegate::notifyChanged()\n");
|
||||
auto treeModel = dynamic_cast<const QStandardItemModel*>(model);
|
||||
auto item = treeModel->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
if (group->child(row, 1)) {
|
||||
auto material = group->child(row, 1)->data().value<std::shared_ptr<Materials::Material>>();
|
||||
auto propertyName = group->child(row, 0)->text();
|
||||
auto propertyValue = material->getProperty(propertyName)->getValue();
|
||||
material->setEditStateAlter();
|
||||
Base::Console().Log("MaterialDelegate::notifyChanged() - marked altered\n");
|
||||
|
||||
Q_EMIT const_cast<MaterialDelegate*>(this)->propertyChange(propertyName,
|
||||
propertyValue.toString());
|
||||
}
|
||||
}
|
||||
|
||||
bool MaterialDelegate::editorEvent(QEvent* event,
|
||||
QAbstractItemModel* model,
|
||||
const QStyleOptionViewItem& option,
|
||||
@@ -82,38 +183,35 @@ bool MaterialDelegate::editorEvent(QEvent* event,
|
||||
int row = index.row();
|
||||
|
||||
QString propertyName = group->child(row, 0)->text();
|
||||
QString propertyType = QString::fromStdString("String");
|
||||
if (group->child(row, 2)) {
|
||||
propertyType = group->child(row, 2)->text();
|
||||
}
|
||||
|
||||
std::string type = propertyType.toStdString();
|
||||
if (type == "Color") {
|
||||
showColorModal(item, propertyName);
|
||||
auto type = getType(index);
|
||||
if (type == Materials::MaterialValue::Color) {
|
||||
showColorModal(propertyName, item);
|
||||
// Mark as handled
|
||||
return true;
|
||||
}
|
||||
if (type == "MultiLineString") {
|
||||
showMultiLineString(propertyName, item);
|
||||
if (type == Materials::MaterialValue::MultiLineString) {
|
||||
showMultiLineStringModal(propertyName, item);
|
||||
// Mark as handled
|
||||
return true;
|
||||
}
|
||||
if (type == "List" || type == "FileList" || type == "ImageList") {
|
||||
if (type == Materials::MaterialValue::List || type == Materials::MaterialValue::FileList
|
||||
|| type == Materials::MaterialValue::ImageList) {
|
||||
showListModal(propertyName, item);
|
||||
// Mark as handled
|
||||
return true;
|
||||
}
|
||||
if (type == "2DArray") {
|
||||
if (type == Materials::MaterialValue::Array2D) {
|
||||
showArray2DModal(propertyName, item);
|
||||
// Mark as handled
|
||||
return true;
|
||||
}
|
||||
if (type == "3DArray") {
|
||||
if (type == Materials::MaterialValue::Array3D) {
|
||||
showArray3DModal(propertyName, item);
|
||||
// Mark as handled
|
||||
return true;
|
||||
}
|
||||
if (type == "Image") {
|
||||
if (type == Materials::MaterialValue::Image || type == Materials::MaterialValue::SVG) {
|
||||
showImageModal(propertyName, item);
|
||||
// Mark as handled
|
||||
return true;
|
||||
@@ -123,7 +221,7 @@ bool MaterialDelegate::editorEvent(QEvent* event,
|
||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
void MaterialDelegate::showColorModal(QStandardItem* item, QString propertyName)
|
||||
void MaterialDelegate::showColorModal(const QString& propertyName, QStandardItem* item)
|
||||
{
|
||||
QColor currentColor; // = d->col;
|
||||
currentColor.setRgba(parseColor(item->text()));
|
||||
@@ -166,11 +264,7 @@ void MaterialDelegate::showImageModal(const QString& propertyName, QStandardItem
|
||||
|
||||
dlg->adjustSize();
|
||||
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {
|
||||
if (result == QDialog::Accepted) {
|
||||
Base::Console().Log("Accepted\n");
|
||||
}
|
||||
});
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {});
|
||||
|
||||
dlg->exec();
|
||||
}
|
||||
@@ -184,16 +278,12 @@ void MaterialDelegate::showListModal(const QString& propertyName, QStandardItem*
|
||||
|
||||
dlg->adjustSize();
|
||||
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {
|
||||
if (result == QDialog::Accepted) {
|
||||
Base::Console().Log("Accepted\n");
|
||||
}
|
||||
});
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {});
|
||||
|
||||
dlg->exec();
|
||||
}
|
||||
|
||||
void MaterialDelegate::showMultiLineString(const QString& propertyName, QStandardItem* item)
|
||||
void MaterialDelegate::showMultiLineStringModal(const QString& propertyName, QStandardItem* item)
|
||||
{
|
||||
auto material = item->data().value<std::shared_ptr<Materials::Material>>();
|
||||
auto dlg = new TextEdit(propertyName, material);
|
||||
@@ -202,11 +292,7 @@ void MaterialDelegate::showMultiLineString(const QString& propertyName, QStandar
|
||||
|
||||
dlg->adjustSize();
|
||||
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {
|
||||
if (result == QDialog::Accepted) {
|
||||
Base::Console().Log("Accepted\n");
|
||||
}
|
||||
});
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {});
|
||||
|
||||
dlg->exec();
|
||||
}
|
||||
@@ -221,11 +307,7 @@ void MaterialDelegate::showArray2DModal(const QString& propertyName, QStandardIt
|
||||
|
||||
dlg->adjustSize();
|
||||
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {
|
||||
if (result == QDialog::Accepted) {
|
||||
Base::Console().Log("Accepted\n");
|
||||
}
|
||||
});
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {});
|
||||
|
||||
dlg->exec();
|
||||
}
|
||||
@@ -239,11 +321,7 @@ void MaterialDelegate::showArray3DModal(const QString& propertyName, QStandardIt
|
||||
|
||||
dlg->adjustSize();
|
||||
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {
|
||||
if (result == QDialog::Accepted) {
|
||||
Base::Console().Log("Accepted\n");
|
||||
}
|
||||
});
|
||||
connect(dlg, &QDialog::finished, this, [&](int result) {});
|
||||
|
||||
dlg->exec();
|
||||
}
|
||||
@@ -267,207 +345,40 @@ void MaterialDelegate::paint(QPainter* painter,
|
||||
return;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
|
||||
QString propertyName = group->child(row, 0)->text();
|
||||
QString propertyType = QString::fromStdString("String");
|
||||
if (group->child(row, 2)) {
|
||||
propertyType = group->child(row, 2)->text();
|
||||
}
|
||||
QString propertyValue = QString::fromStdString("");
|
||||
if (group->child(row, 1)) {
|
||||
propertyValue = group->child(row, 1)->text();
|
||||
}
|
||||
|
||||
std::string type = propertyType.toStdString();
|
||||
if (type == "Color") {
|
||||
painter->save();
|
||||
;
|
||||
|
||||
QColor color;
|
||||
color.setRgba(qRgba(0, 0, 0, 255)); // Black border
|
||||
int left = option.rect.left() + 2;
|
||||
int width = option.rect.width() - 4;
|
||||
if (option.rect.width() > 75) {
|
||||
left += (option.rect.width() - 75) / 2;
|
||||
width = 71;
|
||||
}
|
||||
painter->fillRect(left,
|
||||
option.rect.top() + 2,
|
||||
width,
|
||||
option.rect.height() - 4,
|
||||
QBrush(color));
|
||||
|
||||
color.setRgba(parseColor(propertyValue));
|
||||
left = option.rect.left() + 5;
|
||||
width = option.rect.width() - 10;
|
||||
if (option.rect.width() > 75) {
|
||||
left += (option.rect.width() - 75) / 2;
|
||||
width = 65;
|
||||
}
|
||||
painter->fillRect(left,
|
||||
option.rect.top() + 5,
|
||||
width,
|
||||
option.rect.height() - 10,
|
||||
QBrush(color));
|
||||
|
||||
painter->restore();
|
||||
auto type = getType(index);
|
||||
if (type == Materials::MaterialValue::Quantity) {
|
||||
paintQuantity(painter, option, index);
|
||||
return;
|
||||
}
|
||||
if (type == "Image") {
|
||||
painter->save();
|
||||
|
||||
QImage img;
|
||||
if (!propertyValue.isEmpty()) {
|
||||
Base::Console().Log("Loading image\n");
|
||||
QByteArray by = QByteArray::fromBase64(propertyValue.toUtf8());
|
||||
img = QImage::fromData(by, "PNG").scaled(64, 64, Qt::KeepAspectRatio);
|
||||
}
|
||||
QRect target(option.rect);
|
||||
if (target.width() > target.height()) {
|
||||
target.setWidth(target.height());
|
||||
}
|
||||
else {
|
||||
target.setHeight(target.width());
|
||||
}
|
||||
painter->drawImage(target, img, img.rect());
|
||||
|
||||
painter->restore();
|
||||
if (type == Materials::MaterialValue::Image) {
|
||||
paintImage(painter, option, index);
|
||||
return;
|
||||
}
|
||||
if (type == "List" || type == "FileList" || type == "ImageList") {
|
||||
painter->save();
|
||||
|
||||
QImage table(QString::fromStdString(":/icons/list.svg"));
|
||||
QRect target(option.rect);
|
||||
if (target.width() > target.height()) {
|
||||
target.setWidth(target.height());
|
||||
}
|
||||
else {
|
||||
target.setHeight(target.width());
|
||||
}
|
||||
painter->drawImage(target, table, table.rect());
|
||||
|
||||
painter->restore();
|
||||
if (type == Materials::MaterialValue::SVG) {
|
||||
paintSVG(painter, option, index);
|
||||
return;
|
||||
}
|
||||
if (type == "MultiLineString") {
|
||||
painter->save();
|
||||
|
||||
QImage table(QString::fromStdString(":/icons/multiline.svg"));
|
||||
QRect target(option.rect);
|
||||
if (target.width() > target.height()) {
|
||||
target.setWidth(target.height());
|
||||
}
|
||||
else {
|
||||
target.setHeight(target.width());
|
||||
}
|
||||
painter->drawImage(target, table, table.rect());
|
||||
|
||||
painter->restore();
|
||||
if (type == Materials::MaterialValue::Color) {
|
||||
paintColor(painter, option, index);
|
||||
return;
|
||||
}
|
||||
if (type == "2DArray" || type == "3DArray") {
|
||||
painter->save();
|
||||
|
||||
QImage table(QString::fromStdString(":/icons/table.svg"));
|
||||
QRect target(option.rect);
|
||||
if (target.width() > target.height()) {
|
||||
target.setWidth(target.height());
|
||||
}
|
||||
else {
|
||||
target.setHeight(target.width());
|
||||
}
|
||||
painter->drawImage(target, table, table.rect());
|
||||
|
||||
painter->restore();
|
||||
if (type == Materials::MaterialValue::List || type == Materials::MaterialValue::FileList
|
||||
|| type == Materials::MaterialValue::ImageList) {
|
||||
paintList(painter, option, index);
|
||||
return;
|
||||
}
|
||||
if (type == Materials::MaterialValue::MultiLineString) {
|
||||
paintMultiLineString(painter, option, index);
|
||||
return;
|
||||
}
|
||||
if (type == Materials::MaterialValue::Array2D || type == Materials::MaterialValue::Array3D) {
|
||||
paintArray(painter, option, index);
|
||||
return;
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
||||
QSize MaterialDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
if (index.column() != 1) {
|
||||
return QStyledItemDelegate::sizeHint(option, index);
|
||||
}
|
||||
|
||||
auto treeModel = dynamic_cast<const QStandardItemModel*>(index.model());
|
||||
|
||||
// Check we're not the material model root. This is also used to access the entry columns
|
||||
auto item = treeModel->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return QStyledItemDelegate::sizeHint(option, index);
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
|
||||
QString propertyType = QString::fromStdString("String");
|
||||
if (group->child(row, 2)) {
|
||||
propertyType = group->child(row, 2)->text();
|
||||
}
|
||||
|
||||
std::string type = propertyType.toStdString();
|
||||
if (type == "Color") {
|
||||
return {75, 23}; // Standard QPushButton size
|
||||
}
|
||||
if (type == "Image") {
|
||||
return {64, 64};
|
||||
}
|
||||
if (type == "2DArray" || type == "3DArray" || type == "MultiLineString" || type == "List"
|
||||
|| type == "FileList" || type == "ImageList") {
|
||||
return {23, 23};
|
||||
}
|
||||
|
||||
return QStyledItemDelegate::sizeHint(option, index);
|
||||
}
|
||||
|
||||
void MaterialDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
QVariant propertyType = editor->property("Type");
|
||||
auto model = dynamic_cast<const QStandardItemModel*>(index.model());
|
||||
QStandardItem* item = model->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
QString propertyName = group->child(row, 0)->text();
|
||||
|
||||
std::string type = propertyType.toString().toStdString();
|
||||
if (type == "File") {
|
||||
auto chooser = dynamic_cast<Gui::FileChooser*>(editor);
|
||||
item->setText(chooser->fileName());
|
||||
}
|
||||
else if (type == "Quantity") {
|
||||
auto input = dynamic_cast<Gui::InputField*>(editor);
|
||||
item->setText(input->getQuantityString());
|
||||
}
|
||||
else {
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialDelegate::setModelData(QWidget* editor,
|
||||
QAbstractItemModel* model,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
|
||||
auto item = dynamic_cast<const QStandardItemModel*>(model)->itemFromIndex(index);
|
||||
auto group = item->parent();
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
QString propertyName = group->child(row, 0)->text();
|
||||
Q_EMIT const_cast<MaterialDelegate*>(this)->propertyChange(propertyName, item->text());
|
||||
}
|
||||
|
||||
QWidget* MaterialDelegate::createEditor(QWidget* parent,
|
||||
const QStyleOptionViewItem& styleOption,
|
||||
const QModelIndex& index) const
|
||||
@@ -487,52 +398,27 @@ QWidget* MaterialDelegate::createEditor(QWidget* parent,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
|
||||
QString propertyName = group->child(row, 0)->text();
|
||||
QString propertyType = QString::fromStdString("String");
|
||||
if (group->child(row, 2)) {
|
||||
propertyType = group->child(row, 2)->text();
|
||||
}
|
||||
|
||||
QString propertyValue = QString::fromStdString("");
|
||||
if (group->child(row, 1)) {
|
||||
propertyValue = group->child(row, 1)->text();
|
||||
}
|
||||
|
||||
QString propertyUnits = QString::fromStdString("");
|
||||
if (group->child(row, 1)) {
|
||||
propertyUnits = group->child(row, 3)->text();
|
||||
}
|
||||
|
||||
QWidget* editor =
|
||||
createWidget(parent, propertyName, propertyType, propertyValue, propertyUnits);
|
||||
QVariant value = treeModel->data(index);
|
||||
QWidget* editor = createWidget(parent, value, index);
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
QWidget* MaterialDelegate::createWidget(QWidget* parent,
|
||||
const QString& propertyName,
|
||||
const QString& propertyType,
|
||||
const QString& propertyValue,
|
||||
const QString& propertyUnits) const
|
||||
const QVariant& item,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
Q_UNUSED(propertyName);
|
||||
|
||||
QWidget* widget = nullptr;
|
||||
|
||||
std::string type = propertyType.toStdString();
|
||||
if (type == "String" || type == "URL") {
|
||||
widget = new Gui::PrefLineEdit(parent);
|
||||
}
|
||||
else if (type == "Integer") {
|
||||
auto type = getType(index);
|
||||
if (type == Materials::MaterialValue::Integer) {
|
||||
auto spinner = new Gui::IntSpinBox(parent);
|
||||
spinner->setMinimum(0);
|
||||
spinner->setMaximum(INT_MAX);
|
||||
spinner->setValue(propertyValue.toInt());
|
||||
spinner->setValue(item.toInt());
|
||||
widget = spinner;
|
||||
}
|
||||
else if (type == "Float") {
|
||||
else if (type == Materials::MaterialValue::Float) {
|
||||
auto spinner = new Gui::DoubleSpinBox(parent);
|
||||
|
||||
// the magnetic permeability is the parameter for which many decimals matter
|
||||
@@ -544,64 +430,43 @@ QWidget* MaterialDelegate::createWidget(QWidget* parent,
|
||||
|
||||
spinner->setMinimum(std::numeric_limits<double>::min());
|
||||
spinner->setMaximum(std::numeric_limits<double>::max());
|
||||
spinner->setValue(propertyValue.toDouble());
|
||||
spinner->setValue(item.toDouble());
|
||||
widget = spinner;
|
||||
}
|
||||
else if (type == "Boolean") {
|
||||
else if (type == Materials::MaterialValue::Boolean) {
|
||||
auto combo = new Gui::PrefComboBox(parent);
|
||||
combo->insertItem(0, QString::fromStdString(""));
|
||||
combo->insertItem(1, tr("False"));
|
||||
combo->insertItem(2, tr("True"));
|
||||
combo->setCurrentText(propertyValue);
|
||||
combo->setCurrentText(item.toString());
|
||||
widget = combo;
|
||||
}
|
||||
else if (type == "Quantity") {
|
||||
else if (type == Materials::MaterialValue::Quantity) {
|
||||
auto input = new Gui::InputField(parent);
|
||||
input->setMinimum(std::numeric_limits<double>::min());
|
||||
input->setMaximum(std::numeric_limits<double>::max());
|
||||
input->setUnitText(propertyUnits); // TODO: Ensure this exists
|
||||
input->setUnitText(getUnits(index));
|
||||
input->setPrecision(6);
|
||||
input->setQuantityString(propertyValue);
|
||||
input->setValue(item.value<Base::Quantity>());
|
||||
|
||||
widget = input;
|
||||
}
|
||||
else if (type == "File") {
|
||||
else if (type == Materials::MaterialValue::File) {
|
||||
auto chooser = new Gui::FileChooser(parent);
|
||||
if (!propertyValue.isEmpty()) {
|
||||
chooser->setFileName(propertyValue);
|
||||
if (!item.toString().isEmpty()) {
|
||||
chooser->setFileName(item.toString());
|
||||
}
|
||||
|
||||
widget = chooser;
|
||||
}
|
||||
else {
|
||||
// Default editor
|
||||
widget = new QLineEdit(parent);
|
||||
auto lineEdit = new Gui::PrefLineEdit(parent);
|
||||
lineEdit->setText(item.toString());
|
||||
widget = lineEdit;
|
||||
}
|
||||
|
||||
widget->setProperty("Type", propertyType);
|
||||
// widget->setParent(parent);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
QRgb MaterialDelegate::parseColor(const QString& color) const
|
||||
{
|
||||
QString trimmed = color;
|
||||
trimmed.replace(QRegularExpression(QString::fromStdString("\\(([^<]*)\\)")),
|
||||
QString::fromStdString("\\1"));
|
||||
QStringList parts = trimmed.split(QString::fromStdString(","));
|
||||
if (parts.length() < 3) {
|
||||
return qRgba(0, 0, 0, 255);
|
||||
}
|
||||
int red = parts.at(0).toDouble() * 255;
|
||||
int green = parts.at(1).toDouble() * 255;
|
||||
int blue = parts.at(2).toDouble() * 255;
|
||||
int alpha = 255;
|
||||
if (parts.length() > 3) {
|
||||
alpha = parts.at(3).toDouble() * 255;
|
||||
}
|
||||
|
||||
return qRgba(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
#include "moc_MaterialDelegate.cpp"
|
||||
|
||||
Reference in New Issue
Block a user