diff --git a/CMakeLists.txt b/CMakeLists.txt index fde4462..57c305b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default project(qglengine) find_package(QAD REQUIRED) -qad_find_qt(Qt5 Core Gui OpenGL Xml) -if (NOT Qt5_FOUND) - message(WARNING "Building ${PROJECT_NAME} available only on Qt5!") +qad_find_qt(Qt5 Qt6 Core Gui OpenGL OpenGLWidgets Xml) +if (NOT Qt5_FOUND AND NOT Qt6_FOUND) + message(WARNING "Building ${PROJECT_NAME} available only on Qt5/6!") else() find_package(OpenGL REQUIRED) include(SHSTKQtMacros) diff --git a/core/hdr.cpp b/core/hdr.cpp index d1e2248..7e4af1d 100644 --- a/core/hdr.cpp +++ b/core/hdr.cpp @@ -17,7 +17,8 @@ */ #include "hdr_p.h" -#include "qmath.h" +#include +#include #define RGBE_DATA_RED 2 #define RGBE_DATA_GREEN 1 diff --git a/formats/loader_assimp.cpp b/formats/loader_assimp.cpp index fe53b77..9b20ee2 100644 --- a/formats/loader_assimp.cpp +++ b/formats/loader_assimp.cpp @@ -252,7 +252,7 @@ Scene * loadScene(const QString & filepath) { scene->setName(root->name()); foreach (ObjectBase * o, root->children()) scene->addObject(o); - lights.removeAll(0); + lights.removeAll(nullptr); qDeleteAll(lights); return scene; diff --git a/mouse_controller.cpp b/mouse_controller.cpp index 0863f14..d5ef0aa 100644 --- a/mouse_controller.cpp +++ b/mouse_controller.cpp @@ -77,7 +77,13 @@ void MouseController::mouseReleaseEvent(QMouseEvent * e) { } if (e->button() == Qt::RightButton) { 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) { QVector3D axe_vector; axe_vector[a] = 1.; QMatrix4x4 axis_mat = view->camera()->fullViewMatrix() * rs.axis_mat; - QVector3D center_screen = axis_mat * rs.selection_center; - QVector3D axe_screen = ((axis_mat * (rs.selection_center + axe_vector)) - center_screen).normalized(); + QVector3D center_screen = axis_mat.map(rs.selection_center); + QVector3D axe_screen = (axis_mat.map(rs.selection_center + axe_vector) - center_screen).normalized(); QVector3D mouse_vector(cpos - lastPos); mouse_vector[1] *= -1.; if (cur_action == RendererService::haMove) { @@ -200,9 +206,14 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) { } QRect g_rect(QPoint(), view->size()); if (mouseRotate_) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) float dx = e->x() - lastPos.x(); 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_) { view->camera()->orbitZ (dx / 4.f); view->camera()->orbitXY(dy / 4.f); @@ -257,8 +268,13 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) { return; } lastPos = g_rect.center(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) int dx = e->x() - lastPos.x(); 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())); return; } @@ -268,8 +284,14 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) { void MouseController::wheelEvent(QWheelEvent * e) { if (mouseRotate_) { - if (e->delta() > 0) view->camera()->flyCloser(0.1f); - if (e->delta() < 0) view->camera()->flyFarer(0.1f); + double ang = +#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->glWheelEvent(e); @@ -283,6 +305,6 @@ void MouseController::leaveEvent(QEvent * ) { void MouseController::mouseDoubleClickEvent(QMouseEvent * e) { - if (e->buttons().testFlag(Qt::MidButton)) + if (e->buttons().testFlag(QT_MID_BUTTON)) emit view->doubleClick(); } diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt index 355566a..4a1d6fb 100644 --- a/plugin/CMakeLists.txt +++ b/plugin/CMakeLists.txt @@ -1,6 +1,6 @@ if (DESIGNER_PLUGINS) - if (NOT Qt5) - message(WARNING "Building ${PROJECT_NAME} available only on Qt5!") + if (NOT Qt5 AND NOT Qt6) + message(WARNING "Building ${PROJECT_NAME} available only on Qt5/6!") else() project(qglengine_plugin) include_directories("..") @@ -8,7 +8,7 @@ if (DESIGNER_PLUGINS) add_definitions(-DQT_NO_DEBUG) add_definitions(-DQT_SHARED) 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_wrap(${SRC} CPPS out_CPP QMS out_QM) qt_add_library(${PROJECT_NAME} SHARED out_CPP) diff --git a/renderer.cpp b/renderer.cpp index 9bc5d29..843bfd8 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -240,7 +240,7 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) { setUniformCamera(prog, cam); setUniformViewCorners(prog, cam); 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_decay", qMax(view->fogDecay(), 0.001f)); prog->setUniformValue("fog_density", view->fogDensity()); diff --git a/renderer_base.cpp b/renderer_base.cpp index 5dfb3f7..54626c8 100644 --- a/renderer_base.cpp +++ b/renderer_base.cpp @@ -122,7 +122,7 @@ void RendererBase::setUniformViewCorners(QOpenGLShaderProgram * prog, Camera * c corner_dirs[2] = (mproji * QVector4D( 1, 1, 0, 1)); corner_dirs[3] = (mproji * QVector4D( 1, -1, 0, 1)); 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("world_corners[%1]").arg(i).toLatin1().constData(), world_dirs[i]); } diff --git a/widgets/CMakeLists.txt b/widgets/CMakeLists.txt index ff0d122..52ef500 100644 --- a/widgets/CMakeLists.txt +++ b/widgets/CMakeLists.txt @@ -3,7 +3,7 @@ project(qglengine_widgets) if (POLICY CMP0017) cmake_policy(SET CMP0017 NEW) endif() -qad_find_qt(Qt5 Core Gui Widgets) +qad_find_qt(Qt5 Qt6 Core Gui Widgets) qad_sources(SRC) qad_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM) file(GLOB PHS "*_p.h") diff --git a/widgets/primitiveeditor.cpp b/widgets/primitiveeditor.cpp index dd6ed6d..a10de68 100644 --- a/widgets/primitiveeditor.cpp +++ b/widgets/primitiveeditor.cpp @@ -19,6 +19,7 @@ #include "primitiveeditor.h" #include "ui_primitiveeditor.h" #include +#include #include "glprimitives.h" #include "glmesh.h" @@ -59,7 +60,7 @@ PrimitiveEditor::PrimitiveEditor(QWidget *parent) : QWidget(parent), ui(new Ui:: QMetaEnum me = metaObject()->enumerator(0); for (int i=0; icomboPrimitives->addItem(me.key(i)); - all.unite(editors[(PrimitiveType)me.value(i)].toSet()); + all.unite(QList2QSet(editors[(PrimitiveType)me.value(i)])); } all_editors = all.values(); foreach (QWidget * w, all_editors) { diff --git a/widgets/propertyeditor.cpp b/widgets/propertyeditor.cpp index 1feafae..c111199 100644 --- a/widgets/propertyeditor.cpp +++ b/widgets/propertyeditor.cpp @@ -47,19 +47,83 @@ QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & inde connect((QComboBox*)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed())); } } else { +#if QT_VERSION_MAJOR <= 5 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; - case QVariant::UInt: w = new QSpinBox(parent); type = 3; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; - case QVariant::LongLong: w = new QSpinBox(parent); type = 4; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; - case QVariant::ULongLong: w = new QSpinBox(parent); type = 5; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; - 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::Bool: w = new QCheckBox(parent); type = 7; ((QCheckBox*)w)->setChecked(value.toBool()); connect((QCheckBox*)w, SIGNAL(toggled(bool)), this, SLOT(changed())); break; - case QVariant::Color: w = new ColorButton(parent); type = 8; ((ColorButton*)w)->setUseAlphaChannel(true); ((ColorButton*)w)->setColor(value.value()); connect((ColorButton*)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed())); break; - 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; - 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; - 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; - 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::String: default: w = new CLineEdit(parent); type = 1; ((CLineEdit*)w)->setDefaultText(value.toString()); connect((CLineEdit*)w, SIGNAL(textChanged(QString)), this, SLOT(changed())); break; +#else + switch (value.metaType().id()) { +#endif +#if QT_VERSION_MAJOR <= 5 + case QVariant::Int: +#else + case QMetaType::Int: +#endif + w = new QSpinBox(parent); type = 2; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break; +#if QT_VERSION_MAJOR <= 5 + case QVariant::UInt: +#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()); 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); } } 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: +#else + case QMetaType::Int: +#endif text.setNum(value.toInt()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::UInt: +#else + case QMetaType::UInt: +#endif text.setNum(value.toUInt()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::LongLong: +#else + case QMetaType::LongLong: +#endif text.setNum(value.toLongLong()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::ULongLong: +#else + case QMetaType::ULongLong: +#endif text.setNum(value.toULongLong()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Double: +#else + case QMetaType::Double: +#endif text.setNum(value.toDouble(), 'f', 3); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Bool: +#else + case QMetaType::Bool: +#endif so = new QStyleOptionButton(); so->rect = option.rect; 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; style->drawControl(QStyle::CE_CheckBox, so, painter); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Color: +#else + case QMetaType::QColor: +#endif rect = option.rect;//style->subElementRect(QStyle::QStyle::SE_FrameContents, so); rect.setRect(rect.x() + 3, rect.y() + 3, rect.width() - 6, rect.height() - 6); painter->fillRect(rect, ab); painter->fillRect(rect, value.value()); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Point: +#else + case QMetaType::QPoint: +#endif text = pointString(value.toPoint()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::PointF: +#else + case QMetaType::QPointF: +#endif text = pointString(value.toPointF()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Rect: +#else + case QMetaType::QRect: +#endif text = rectString(value.toRect()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::RectF: +#else + case QMetaType::QRectF: +#endif text = rectString(value.toRectF()); style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role); break; +#if QT_VERSION_MAJOR <= 5 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()), Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, value.toString(), role); break; diff --git a/widgets/propertyeditor.h b/widgets/propertyeditor.h index a494ef5..6b1f245 100644 --- a/widgets/propertyeditor.h +++ b/widgets/propertyeditor.h @@ -61,7 +61,9 @@ private slots: typedef QPair 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 { Q_OBJECT