qt6 support

This commit is contained in:
2022-01-31 19:54:39 +03:00
parent 73240ef898
commit fb56502f13
11 changed files with 175 additions and 33 deletions

View File

@@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
project(qglengine) project(qglengine)
find_package(QAD REQUIRED) find_package(QAD REQUIRED)
qad_find_qt(Qt5 Core Gui OpenGL Xml) qad_find_qt(Qt5 Qt6 Core Gui OpenGL OpenGLWidgets Xml)
if (NOT Qt5_FOUND) if (NOT Qt5_FOUND AND NOT Qt6_FOUND)
message(WARNING "Building ${PROJECT_NAME} available only on Qt5!") message(WARNING "Building ${PROJECT_NAME} available only on Qt5/6!")
else() else()
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
include(SHSTKQtMacros) include(SHSTKQtMacros)

View File

@@ -17,7 +17,8 @@
*/ */
#include "hdr_p.h" #include "hdr_p.h"
#include "qmath.h" #include <qmath.h>
#include <QByteArray>
#define RGBE_DATA_RED 2 #define RGBE_DATA_RED 2
#define RGBE_DATA_GREEN 1 #define RGBE_DATA_GREEN 1

View File

@@ -252,7 +252,7 @@ Scene * loadScene(const QString & filepath) {
scene->setName(root->name()); scene->setName(root->name());
foreach (ObjectBase * o, root->children()) foreach (ObjectBase * o, root->children())
scene->addObject(o); scene->addObject(o);
lights.removeAll(0); lights.removeAll(nullptr);
qDeleteAll(lights); qDeleteAll(lights);
return scene; return scene;

View File

@@ -77,7 +77,13 @@ void MouseController::mouseReleaseEvent(QMouseEvent * e) {
} }
if (e->button() == Qt::RightButton) { if (e->button() == Qt::RightButton) {
if (view->renderer_.edit_mode && !view->scene()->selectedObjects().isEmpty()) if (view->renderer_.edit_mode && !view->scene()->selectedObjects().isEmpty())
view->popupMenu(e->globalPos()); view->popupMenu(
#if QT_VERSION_MAJOR <= 5
((QMouseEvent*)e)->globalPos()
#else
((QMouseEvent*)e)->globalPosition().toPoint()
#endif
);
} }
} }
} }
@@ -131,8 +137,8 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
foreach (int a, axis) { foreach (int a, axis) {
QVector3D axe_vector; axe_vector[a] = 1.; QVector3D axe_vector; axe_vector[a] = 1.;
QMatrix4x4 axis_mat = view->camera()->fullViewMatrix() * rs.axis_mat; QMatrix4x4 axis_mat = view->camera()->fullViewMatrix() * rs.axis_mat;
QVector3D center_screen = axis_mat * rs.selection_center; QVector3D center_screen = axis_mat.map(rs.selection_center);
QVector3D axe_screen = ((axis_mat * (rs.selection_center + axe_vector)) - center_screen).normalized(); QVector3D axe_screen = (axis_mat.map(rs.selection_center + axe_vector) - center_screen).normalized();
QVector3D mouse_vector(cpos - lastPos); QVector3D mouse_vector(cpos - lastPos);
mouse_vector[1] *= -1.; mouse_vector[1] *= -1.;
if (cur_action == RendererService::haMove) { if (cur_action == RendererService::haMove) {
@@ -200,9 +206,14 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
} }
QRect g_rect(QPoint(), view->size()); QRect g_rect(QPoint(), view->size());
if (mouseRotate_) { if (mouseRotate_) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
float dx = e->x() - lastPos.x(); float dx = e->x() - lastPos.x();
float dy = e->y() - lastPos.y(); float dy = e->y() - lastPos.y();
if (e->buttons().testFlag(Qt::MidButton)) { #else
float dx = e->position().toPoint().x() - lastPos.x();
float dy = e->position().toPoint().y() - lastPos.y();
#endif
if (e->buttons().testFlag(QT_MID_BUTTON)) {
if (cameraOrbit_) { if (cameraOrbit_) {
view->camera()->orbitZ (dx / 4.f); view->camera()->orbitZ (dx / 4.f);
view->camera()->orbitXY(dy / 4.f); view->camera()->orbitXY(dy / 4.f);
@@ -257,8 +268,13 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
return; return;
} }
lastPos = g_rect.center(); lastPos = g_rect.center();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
int dx = e->x() - lastPos.x(); int dx = e->x() - lastPos.x();
int dy = e->y() - lastPos.y(); int dy = e->y() - lastPos.y();
#else
int dx = e->position().toPoint().x() - lastPos.x();
int dy = e->position().toPoint().y() - lastPos.y();
#endif
emit view->glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers())); emit view->glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers()));
return; return;
} }
@@ -268,8 +284,14 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
void MouseController::wheelEvent(QWheelEvent * e) { void MouseController::wheelEvent(QWheelEvent * e) {
if (mouseRotate_) { if (mouseRotate_) {
if (e->delta() > 0) view->camera()->flyCloser(0.1f); double ang =
if (e->delta() < 0) view->camera()->flyFarer(0.1f); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
e->delta();
#else
e->angleDelta().y();
#endif
if (ang > 0) view->camera()->flyCloser(0.1f);
if (ang < 0) view->camera()->flyFarer(0.1f);
emit view->cameraPosChanged(view->camera()->pos()); emit view->cameraPosChanged(view->camera()->pos());
} }
emit view->glWheelEvent(e); emit view->glWheelEvent(e);
@@ -283,6 +305,6 @@ void MouseController::leaveEvent(QEvent * ) {
void MouseController::mouseDoubleClickEvent(QMouseEvent * e) { void MouseController::mouseDoubleClickEvent(QMouseEvent * e) {
if (e->buttons().testFlag(Qt::MidButton)) if (e->buttons().testFlag(QT_MID_BUTTON))
emit view->doubleClick(); emit view->doubleClick();
} }

View File

@@ -1,6 +1,6 @@
if (DESIGNER_PLUGINS) if (DESIGNER_PLUGINS)
if (NOT Qt5) if (NOT Qt5 AND NOT Qt6)
message(WARNING "Building ${PROJECT_NAME} available only on Qt5!") message(WARNING "Building ${PROJECT_NAME} available only on Qt5/6!")
else() else()
project(qglengine_plugin) project(qglengine_plugin)
include_directories("..") include_directories("..")
@@ -8,7 +8,7 @@ if (DESIGNER_PLUGINS)
add_definitions(-DQT_NO_DEBUG) add_definitions(-DQT_NO_DEBUG)
add_definitions(-DQT_SHARED) add_definitions(-DQT_SHARED)
add_definitions(-DQDESIGNER_EXPORT_WIDGETS) add_definitions(-DQDESIGNER_EXPORT_WIDGETS)
find_qt(Qt5 Core Designer Gui Widgets OpenGL) find_qt(Qt5 Qt6 Core Designer Gui Widgets OpenGL)
qt_sources(SRC) qt_sources(SRC)
qt_wrap(${SRC} CPPS out_CPP QMS out_QM) qt_wrap(${SRC} CPPS out_CPP QMS out_QM)
qt_add_library(${PROJECT_NAME} SHARED out_CPP) qt_add_library(${PROJECT_NAME} SHARED out_CPP)

View File

@@ -240,7 +240,7 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) {
setUniformCamera(prog, cam); setUniformCamera(prog, cam);
setUniformViewCorners(prog, cam); setUniformViewCorners(prog, cam);
prog->setUniformValue("lights_start", lights_start[pass.second]); prog->setUniformValue("lights_start", lights_start[pass.second]);
prog->setUniformValue("lights_count", cur_lights[pass.second].size()); prog->setUniformValue("lights_count", (int)cur_lights[pass.second].size());
prog->setUniformValue("fog_color", view->fogColor()); prog->setUniformValue("fog_color", view->fogColor());
prog->setUniformValue("fog_decay", qMax(view->fogDecay(), 0.001f)); prog->setUniformValue("fog_decay", qMax(view->fogDecay(), 0.001f));
prog->setUniformValue("fog_density", view->fogDensity()); prog->setUniformValue("fog_density", view->fogDensity());

View File

@@ -122,7 +122,7 @@ void RendererBase::setUniformViewCorners(QOpenGLShaderProgram * prog, Camera * c
corner_dirs[2] = (mproji * QVector4D( 1, 1, 0, 1)); corner_dirs[2] = (mproji * QVector4D( 1, 1, 0, 1));
corner_dirs[3] = (mproji * QVector4D( 1, -1, 0, 1)); corner_dirs[3] = (mproji * QVector4D( 1, -1, 0, 1));
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
world_dirs[i] = mviewi.mapVector(corner_dirs[i].toVector3D()); world_dirs[i] = QVector4D(mviewi.mapVector(corner_dirs[i].toVector3D()));
prog->setUniformValue(QString("view_corners[%1]").arg(i).toLatin1().constData(), corner_dirs[i]); prog->setUniformValue(QString("view_corners[%1]").arg(i).toLatin1().constData(), corner_dirs[i]);
prog->setUniformValue(QString("world_corners[%1]").arg(i).toLatin1().constData(), world_dirs[i]); prog->setUniformValue(QString("world_corners[%1]").arg(i).toLatin1().constData(), world_dirs[i]);
} }

View File

@@ -3,7 +3,7 @@ project(qglengine_widgets)
if (POLICY CMP0017) if (POLICY CMP0017)
cmake_policy(SET CMP0017 NEW) cmake_policy(SET CMP0017 NEW)
endif() endif()
qad_find_qt(Qt5 Core Gui Widgets) qad_find_qt(Qt5 Qt6 Core Gui Widgets)
qad_sources(SRC) qad_sources(SRC)
qad_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM) qad_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
file(GLOB PHS "*_p.h") file(GLOB PHS "*_p.h")

View File

@@ -19,6 +19,7 @@
#include "primitiveeditor.h" #include "primitiveeditor.h"
#include "ui_primitiveeditor.h" #include "ui_primitiveeditor.h"
#include <QMetaEnum> #include <QMetaEnum>
#include <qad_types.h>
#include "glprimitives.h" #include "glprimitives.h"
#include "glmesh.h" #include "glmesh.h"
@@ -59,7 +60,7 @@ PrimitiveEditor::PrimitiveEditor(QWidget *parent) : QWidget(parent), ui(new Ui::
QMetaEnum me = metaObject()->enumerator(0); QMetaEnum me = metaObject()->enumerator(0);
for (int i=0; i<me.keyCount(); ++i) { for (int i=0; i<me.keyCount(); ++i) {
ui->comboPrimitives->addItem(me.key(i)); ui->comboPrimitives->addItem(me.key(i));
all.unite(editors[(PrimitiveType)me.value(i)].toSet()); all.unite(QList2QSet(editors[(PrimitiveType)me.value(i)]));
} }
all_editors = all.values(); all_editors = all.values();
foreach (QWidget * w, all_editors) { foreach (QWidget * w, all_editors) {

View File

@@ -47,19 +47,83 @@ QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & inde
connect((QComboBox*)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed())); connect((QComboBox*)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
} }
} else { } else {
#if QT_VERSION_MAJOR <= 5
switch (value.type()) { switch (value.type()) {
case QVariant::Int: w = new QSpinBox(parent); type = 2; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; #else
case QVariant::UInt: w = new QSpinBox(parent); type = 3; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; switch (value.metaType().id()) {
case QVariant::LongLong: w = new QSpinBox(parent); type = 4; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; #endif
case QVariant::ULongLong: w = new QSpinBox(parent); type = 5; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; #if QT_VERSION_MAJOR <= 5
case QVariant::Double: w = new QDoubleSpinBox(parent); type = 6; ((QDoubleSpinBox*)w)->setRange(-999999999, 999999999); ((QDoubleSpinBox*)w)->setDecimals(3); connect((QDoubleSpinBox*)w, SIGNAL(valueChanged(double)), this, SLOT(changed())); break; case QVariant::Int:
case QVariant::Bool: w = new QCheckBox(parent); type = 7; ((QCheckBox*)w)->setChecked(value.toBool()); connect((QCheckBox*)w, SIGNAL(toggled(bool)), this, SLOT(changed())); break; #else
case QVariant::Color: w = new ColorButton(parent); type = 8; ((ColorButton*)w)->setUseAlphaChannel(true); ((ColorButton*)w)->setColor(value.value<QColor>()); connect((ColorButton*)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed())); break; case QMetaType::Int:
case QVariant::Point: w = new QPointEdit(parent); type = 9; ((QPointEdit*)w)->setDecimals(0); ((QPointEdit*)w)->setValue(QPointF(value.toPoint())); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break; #endif
case QVariant::PointF: w = new QPointEdit(parent); type = 10; ((QPointEdit*)w)->setDecimals(3); ((QPointEdit*)w)->setValue(value.toPointF()); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break; w = new QSpinBox(parent); type = 2; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
case QVariant::Rect: w = new QRectEdit(parent); type = 11; ((QRectEdit*)w)->setDecimals(0); ((QRectEdit*)w)->setValue(QRectF(value.toRect())); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break; #if QT_VERSION_MAJOR <= 5
case QVariant::RectF: w = new QRectEdit(parent); type = 12; ((QRectEdit*)w)->setDecimals(3); ((QRectEdit*)w)->setValue(value.toRectF()); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break; case QVariant::UInt:
case QVariant::String: default: w = new CLineEdit(parent); type = 1; ((CLineEdit*)w)->setDefaultText(value.toString()); connect((CLineEdit*)w, SIGNAL(textChanged(QString)), this, SLOT(changed())); break; #else
case QMetaType::UInt:
#endif
w = new QSpinBox(parent); type = 3; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::LongLong:
#else
case QMetaType::LongLong:
#endif
w = new QSpinBox(parent); type = 4; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::ULongLong:
#else
case QMetaType::ULongLong:
#endif
w = new QSpinBox(parent); type = 5; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Double:
#else
case QMetaType::Double:
#endif
w = new QDoubleSpinBox(parent); type = 6; ((QDoubleSpinBox*)w)->setRange(-999999999, 999999999); ((QDoubleSpinBox*)w)->setDecimals(3); connect((QDoubleSpinBox*)w, SIGNAL(valueChanged(double)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Bool:
#else
case QMetaType::Bool:
#endif
w = new QCheckBox(parent); type = 7; ((QCheckBox*)w)->setChecked(value.toBool()); connect((QCheckBox*)w, SIGNAL(toggled(bool)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Color:
#else
case QMetaType::QColor:
#endif
w = new ColorButton(parent); type = 8; ((ColorButton*)w)->setUseAlphaChannel(true); ((ColorButton*)w)->setColor(value.value<QColor>()); connect((ColorButton*)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Point:
#else
case QMetaType::QPoint:
#endif
w = new QPointEdit(parent); type = 9; ((QPointEdit*)w)->setDecimals(0); ((QPointEdit*)w)->setValue(QPointF(value.toPoint())); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::PointF:
#else
case QMetaType::QPointF:
#endif
w = new QPointEdit(parent); type = 10; ((QPointEdit*)w)->setDecimals(3); ((QPointEdit*)w)->setValue(value.toPointF()); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Rect:
#else
case QMetaType::QRect:
#endif
w = new QRectEdit(parent); type = 11; ((QRectEdit*)w)->setDecimals(0); ((QRectEdit*)w)->setValue(QRectF(value.toRect())); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::RectF:
#else
case QMetaType::QRectF:
#endif
w = new QRectEdit(parent); type = 12; ((QRectEdit*)w)->setDecimals(3); ((QRectEdit*)w)->setValue(value.toRectF()); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break;
#if QT_VERSION_MAJOR <= 5
case QVariant::String: default:
#else
case QMetaType::QString: default:
#endif
w = new CLineEdit(parent); type = 1; ((CLineEdit*)w)->setDefaultText(value.toString()); connect((CLineEdit*)w, SIGNAL(textChanged(QString)), this, SLOT(changed())); break;
} }
} }
} }
@@ -159,33 +223,61 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
} }
} else { } else {
switch (value.type()) { #if QT_VERSION_MAJOR <= 5
switch (value.type()) {
#else
switch (value.metaType().id()) {
#endif
#if QT_VERSION_MAJOR <= 5
case QVariant::Int: case QVariant::Int:
#else
case QMetaType::Int:
#endif
text.setNum(value.toInt()); text.setNum(value.toInt());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::UInt: case QVariant::UInt:
#else
case QMetaType::UInt:
#endif
text.setNum(value.toUInt()); text.setNum(value.toUInt());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::LongLong: case QVariant::LongLong:
#else
case QMetaType::LongLong:
#endif
text.setNum(value.toLongLong()); text.setNum(value.toLongLong());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::ULongLong: case QVariant::ULongLong:
#else
case QMetaType::ULongLong:
#endif
text.setNum(value.toULongLong()); text.setNum(value.toULongLong());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Double: case QVariant::Double:
#else
case QMetaType::Double:
#endif
text.setNum(value.toDouble(), 'f', 3); text.setNum(value.toDouble(), 'f', 3);
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Bool: case QVariant::Bool:
#else
case QMetaType::Bool:
#endif
so = new QStyleOptionButton(); so = new QStyleOptionButton();
so->rect = option.rect; so->rect = option.rect;
so->state = option.state; so->state = option.state;
@@ -194,33 +286,57 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
((QStyleOptionButton*)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off) | option.state; ((QStyleOptionButton*)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off) | option.state;
style->drawControl(QStyle::CE_CheckBox, so, painter); style->drawControl(QStyle::CE_CheckBox, so, painter);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Color: case QVariant::Color:
#else
case QMetaType::QColor:
#endif
rect = option.rect;//style->subElementRect(QStyle::QStyle::SE_FrameContents, so); rect = option.rect;//style->subElementRect(QStyle::QStyle::SE_FrameContents, so);
rect.setRect(rect.x() + 3, rect.y() + 3, rect.width() - 6, rect.height() - 6); rect.setRect(rect.x() + 3, rect.y() + 3, rect.width() - 6, rect.height() - 6);
painter->fillRect(rect, ab); painter->fillRect(rect, ab);
painter->fillRect(rect, value.value<QColor>()); painter->fillRect(rect, value.value<QColor>());
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Point: case QVariant::Point:
#else
case QMetaType::QPoint:
#endif
text = pointString(value.toPoint()); text = pointString(value.toPoint());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::PointF: case QVariant::PointF:
#else
case QMetaType::QPointF:
#endif
text = pointString(value.toPointF()); text = pointString(value.toPointF());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::Rect: case QVariant::Rect:
#else
case QMetaType::QRect:
#endif
text = rectString(value.toRect()); text = rectString(value.toRect());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::RectF: case QVariant::RectF:
#else
case QMetaType::QRectF:
#endif
text = rectString(value.toRectF()); text = rectString(value.toRectF());
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
break; break;
#if QT_VERSION_MAJOR <= 5
case QVariant::String: default: case QVariant::String: default:
#else
case QMetaType::QString: default:
#endif
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, value.toString()), style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, value.toString()),
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, value.toString(), role); Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, value.toString(), role);
break; break;

View File

@@ -61,7 +61,9 @@ private slots:
typedef QPair<QMetaProperty, QVariant> PropertyValuePair; typedef QPair<QMetaProperty, QVariant> PropertyValuePair;
Q_DECLARE_METATYPE (PropertyValuePair) Q_DECLARE_METATYPE (PropertyValuePair)
Q_DECLARE_METATYPE (QMetaProperty) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Q_DECLARE_METATYPE (QMetaProperty)
#endif
class PropertyEditor: public QTreeWidget { class PropertyEditor: public QTreeWidget {
Q_OBJECT Q_OBJECT