Skip to content

Commit

Permalink
qt: fix build on qt 6.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Aug 13, 2023
1 parent 9b9412b commit 7e80469
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 25 deletions.
4 changes: 4 additions & 0 deletions application/application.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
QT += core gui opengl widgets svg

greaterThan(QT_MAJOR_VERSION, 5) {
QT += openglwidgets svgwidgets
}

TARGET = dust3d
TEMPLATE = app

Expand Down
2 changes: 2 additions & 0 deletions application/sources/cut_face_preview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ QImage* buildCutFaceTemplatePreviewImage(const std::vector<dust3d::Vector2>& cut
QPainter painter;
painter.begin(image);
painter.setRenderHint(QPainter::Antialiasing);
#if QT_VERSION < 0x060000
painter.setRenderHint(QPainter::HighQualityAntialiasing);
#endif

QPen pen(Theme::red, 2);
painter.setPen(pen);
Expand Down
18 changes: 9 additions & 9 deletions application/sources/document_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1307,10 +1307,10 @@ QShortcut* DocumentWindow::createShortcut(QKeySequence key)
void DocumentWindow::initializeToolShortcuts(SkeletonGraphicsWidget* graphicsWidget)
{
defineShortcut(Qt::Key_A, graphicsWidget, &SkeletonGraphicsWidget::shortcutAddMode);
defineShortcut(Qt::CTRL + Qt::Key_A, graphicsWidget, &SkeletonGraphicsWidget::shortcutSelectAll);
defineShortcut(Qt::CTRL + Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutUndo);
defineShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutRedo);
defineShortcut(Qt::CTRL + Qt::Key_Y, graphicsWidget, &SkeletonGraphicsWidget::shortcutRedo);
defineShortcut(Qt::CTRL | Qt::Key_A, graphicsWidget, &SkeletonGraphicsWidget::shortcutSelectAll);
defineShortcut(Qt::CTRL | Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutUndo);
defineShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutRedo);
defineShortcut(Qt::CTRL | Qt::Key_Y, graphicsWidget, &SkeletonGraphicsWidget::shortcutRedo);
defineShortcut(Qt::Key_Z, graphicsWidget, &SkeletonGraphicsWidget::shortcutZlock);
defineShortcut(Qt::Key_Y, graphicsWidget, &SkeletonGraphicsWidget::shortcutYlock);
defineShortcut(Qt::Key_X, graphicsWidget, &SkeletonGraphicsWidget::shortcutXlock);
Expand All @@ -1325,12 +1325,12 @@ void DocumentWindow::initializeCanvasShortcuts(SkeletonGraphicsWidget* graphicsW
{
defineShortcut(Qt::Key_Delete, graphicsWidget, &SkeletonGraphicsWidget::shortcutDelete);
defineShortcut(Qt::Key_Backspace, graphicsWidget, &SkeletonGraphicsWidget::shortcutDelete);
defineShortcut(Qt::CTRL + Qt::Key_X, graphicsWidget, &SkeletonGraphicsWidget::shortcutCut);
defineShortcut(Qt::CTRL + Qt::Key_C, graphicsWidget, &SkeletonGraphicsWidget::shortcutCopy);
defineShortcut(Qt::CTRL + Qt::Key_V, graphicsWidget, &SkeletonGraphicsWidget::shortcutPaste);
defineShortcut(Qt::ALT + Qt::Key_Minus, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomRenderedModelByMinus10);
defineShortcut(Qt::CTRL | Qt::Key_X, graphicsWidget, &SkeletonGraphicsWidget::shortcutCut);
defineShortcut(Qt::CTRL | Qt::Key_C, graphicsWidget, &SkeletonGraphicsWidget::shortcutCopy);
defineShortcut(Qt::CTRL | Qt::Key_V, graphicsWidget, &SkeletonGraphicsWidget::shortcutPaste);
defineShortcut(Qt::ALT | Qt::Key_Minus, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomRenderedModelByMinus10);
defineShortcut(Qt::Key_Minus, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomSelectedByMinus1);
defineShortcut(Qt::ALT + Qt::Key_Equal, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomRenderedModelBy10);
defineShortcut(Qt::ALT | Qt::Key_Equal, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomRenderedModelBy10);
defineShortcut(Qt::Key_Equal, graphicsWidget, &SkeletonGraphicsWidget::shortcutZoomSelectedBy1);
defineShortcut(Qt::Key_Comma, graphicsWidget, &SkeletonGraphicsWidget::shortcutRotateSelectedByMinus1);
defineShortcut(Qt::Key_Period, graphicsWidget, &SkeletonGraphicsWidget::shortcutRotateSelectedBy1);
Expand Down
1 change: 1 addition & 0 deletions application/sources/fbx_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "fbxdocument.h"
#include <QImage>
#include <QObject>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QString>
Expand Down
6 changes: 3 additions & 3 deletions application/sources/float_number_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ FloatNumberWidget::FloatNumberWidget(QWidget* parent, bool singleLine)
QBoxLayout* layout = nullptr;
if (singleLine) {
layout = new QHBoxLayout(this);
layout->setMargin(2);
layout->setContentsMargins(2, 2, 2, 2);
layout->addWidget(m_slider);
layout->addWidget(m_label);
} else {
layout = new QVBoxLayout(this);
layout->setMargin(2);
layout->setContentsMargins(2, 2, 2, 2);
layout->addWidget(m_label);
layout->addWidget(m_slider);
}
Expand All @@ -41,7 +41,7 @@ void FloatNumberWidget::setSliderFixedWidth(float width)

void FloatNumberWidget::updateValueLabel(float value)
{
QString valueString = QString().sprintf("%.2f", value);
QString valueString = QString().asprintf("%.2f", value);
if (m_itemName.isEmpty())
m_label->setText(valueString);
else
Expand Down
5 changes: 3 additions & 2 deletions application/sources/flow_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ QLayoutItem* FlowLayout::takeAt(int index)

Qt::Orientations FlowLayout::expandingDirections() const
{
return 0;
return {};
}

bool FlowLayout::hasHeightForWidth() const
Expand Down Expand Up @@ -149,7 +149,8 @@ QSize FlowLayout::minimumSize() const
foreach (item, itemList)
size = size.expandedTo(item->minimumSize());

size += QSize(2 * margin(), 2 * margin());
const QMargins margins = contentsMargins();
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
return size;
}

Expand Down
4 changes: 2 additions & 2 deletions application/sources/int_number_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ IntNumberWidget::IntNumberWidget(QWidget* parent, bool singleLine)
QBoxLayout* layout = nullptr;
if (singleLine) {
layout = new QHBoxLayout(this);
layout->setMargin(2);
layout->setContentsMargins(2, 2, 2, 2);
layout->addWidget(m_slider);
layout->addWidget(m_label);
} else {
layout = new QVBoxLayout(this);
layout->setMargin(2);
layout->setContentsMargins(2, 2, 2, 2);
layout->addWidget(m_label);
layout->addWidget(m_slider);
}
Expand Down
8 changes: 4 additions & 4 deletions application/sources/model_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ bool ModelWidget::inputMousePressEventFromOtherWidget(QMouseEvent* event, bool n
}
if (!shouldStartMove && !m_mousePickTargetPositionInModelSpace.isNull())
emit mousePressed();
} else if (event->button() == Qt::MidButton) {
} else if (event->button() == Qt::MiddleButton) {
shouldStartMove = m_moveEnabled;
}
if (shouldStartMove) {
Expand Down Expand Up @@ -250,7 +250,7 @@ bool ModelWidget::inputMouseMoveEventFromOtherWidget(QMouseEvent* event)
int dx = pos.x() - m_lastPos.x();
int dy = pos.y() - m_lastPos.y();

if ((event->buttons() & Qt::MidButton) || (m_moveStarted && (event->buttons() & Qt::LeftButton))) {
if ((event->buttons() & Qt::MiddleButton) || (m_moveStarted && (event->buttons() & Qt::LeftButton))) {
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
if (m_moveStarted) {
if (m_moveAndZoomByWindow) {
Expand Down Expand Up @@ -297,7 +297,7 @@ bool ModelWidget::inputWheelEventFromOtherWidget(QWheelEvent* event)

if (m_mousePickingEnabled) {
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
emit addMouseRadius((float)event->delta() / 200 / height());
emit addMouseRadius((float)event->pixelDelta().y() / 200 / height());
return true;
}
}
Expand All @@ -306,7 +306,7 @@ bool ModelWidget::inputWheelEventFromOtherWidget(QWheelEvent* event)
return false;

qreal delta = geometry().height() * 0.1f;
if (event->delta() < 0)
if (event->pixelDelta().y() < 0)
delta = -delta;
zoom(delta);

Expand Down
2 changes: 1 addition & 1 deletion application/sources/part_manage_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PartManageWidget::PartManageWidget(Document* document, QWidget* parent)

QHBoxLayout* toolsLayout = new QHBoxLayout;
toolsLayout->setSpacing(0);
toolsLayout->setMargin(0);
toolsLayout->setContentsMargins(0, 0, 0, 0);

setStyleSheet("QPushButton:disabled {border: 0; color: " + Theme::gray.name() + "}");

Expand Down
2 changes: 1 addition & 1 deletion application/sources/skeleton_graphics_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ void SkeletonGraphicsWidget::scaleSelected(float delta)
bool SkeletonGraphicsWidget::wheel(QWheelEvent* event)
{
float delta = 0;
if (event->delta() > 0)
if (event->pixelDelta().y() > 0)
delta = 1;
else
delta = -1;
Expand Down
2 changes: 2 additions & 0 deletions application/sources/theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ void Theme::initToolButton(QPushButton* button)
void Theme::initCheckbox(QCheckBox* checkbox)
{
QPalette palette = checkbox->palette();
#if QT_VERSION < 0x060000
palette.setColor(QPalette::Background, Theme::white);
#endif
checkbox->setPalette(palette);
}

Expand Down
6 changes: 4 additions & 2 deletions application/sources/uv_map_generator.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "uv_map_generator.h"
#include "image_forever.h"
#include <QMatrix>
#include <QTransform>
#include <QPainter>
#include <dust3d/base/part_target.h>
#include <dust3d/uv/uv_map_packer.h>
Expand Down Expand Up @@ -165,7 +165,9 @@ void UvMapGenerator::generateTextureColorImage()
QPainter colorTexturePainter;
colorTexturePainter.begin(m_textureColorImage.get());
colorTexturePainter.setRenderHint(QPainter::Antialiasing);
#if QT_VERSION < 0x060000
colorTexturePainter.setRenderHint(QPainter::HighQualityAntialiasing);
#endif
colorTexturePainter.setPen(Qt::NoPen);

for (const auto& layout : m_mapPacker->packedLayouts()) {
Expand All @@ -183,7 +185,7 @@ void UvMapGenerator::generateTextureColorImage()
auto scaledImage = image->scaled(QSize(layout.height * UvMapGenerator::m_textureSize,
layout.width * UvMapGenerator::m_textureSize));
QPoint center = scaledImage.rect().center();
QMatrix matrix;
QTransform matrix;
matrix.translate(center.x(), center.y());
matrix.rotate(90);
auto rotatedImage = scaledImage.transformed(matrix).mirrored(true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void WaitingSpinnerWidget::updateSize() {
setFixedSize(size, size);
} else {
QFontMetrics fm(font());
QSize textSize = QSize(fm.width(_text), fm.height());
QSize textSize = fm.size(Qt::TextSingleLine, _text);
setFixedSize(std::max(size, textSize.width()), size + size / 4 + textSize.height());
}
}
Expand Down

0 comments on commit 7e80469

Please sign in to comment.