From 08b20e4d5b6dc60a31007d07a05e4bd0243abada Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 2 Dec 2018 23:16:04 +0930 Subject: [PATCH] Fit right sub widget size #19 --- dust3d.pro | 4 ++-- src/documentwindow.cpp | 12 ++++++------ src/floatnumberwidget.cpp | 3 ++- src/parttreewidget.cpp | 3 +-- src/theme.cpp | 22 ++++++++++++++-------- src/theme.h | 2 ++ 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/dust3d.pro b/dust3d.pro index 800fa0b4..4cd08568 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -4,10 +4,10 @@ DEFINES += NDEBUG RESOURCES += resources.qrc isEmpty(HUMAN_VERSION) { - HUMAN_VERSION = "1.0.0-beta.8" + HUMAN_VERSION = "1.0.0-beta.9" } isEmpty(VERSION) { - VERSION = 1.0.0.8 + VERSION = 1.0.0.9 } REPOSITORY_URL = "https://github.com/huxingyi/dust3d" diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 245d8933..0c31ce8c 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -117,7 +117,7 @@ DocumentWindow::DocumentWindow() : QVBoxLayout *toolButtonLayout = new QVBoxLayout; toolButtonLayout->setSpacing(0); - toolButtonLayout->setContentsMargins(5, 10, 4, 0); + toolButtonLayout->setContentsMargins(Theme::dp2px(5), Theme::dp2px(10), Theme::dp2px(4), 0); QPushButton *addButton = new QPushButton(QChar(fa::plus)); Theme::initAwesomeButton(addButton); @@ -177,15 +177,15 @@ DocumentWindow::DocumentWindow() : toolButtonLayout->addWidget(dragButton); toolButtonLayout->addWidget(zoomInButton); toolButtonLayout->addWidget(zoomOutButton); - toolButtonLayout->addSpacing(10); + toolButtonLayout->addSpacing(Theme::dp2px(10)); toolButtonLayout->addWidget(m_xlockButton); toolButtonLayout->addWidget(m_ylockButton); toolButtonLayout->addWidget(m_zlockButton); toolButtonLayout->addWidget(m_radiusLockButton); - toolButtonLayout->addSpacing(10); + toolButtonLayout->addSpacing(Theme::dp2px(10)); toolButtonLayout->addWidget(rotateCounterclockwiseButton); toolButtonLayout->addWidget(rotateClockwiseButton); - toolButtonLayout->addSpacing(10); + toolButtonLayout->addSpacing(Theme::dp2px(10)); toolButtonLayout->addWidget(regenerateButton); @@ -204,7 +204,7 @@ DocumentWindow::DocumentWindow() : mainLeftLayout->addLayout(toolButtonLayout); mainLeftLayout->addStretch(); mainLeftLayout->addLayout(logoLayout); - mainLeftLayout->addSpacing(10); + mainLeftLayout->addSpacing(Theme::dp2px(10)); SkeletonGraphicsWidget *graphicsWidget = new SkeletonGraphicsWidget(m_document); m_graphicsWidget = graphicsWidget; @@ -298,7 +298,7 @@ DocumentWindow::DocumentWindow() : mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addLayout(mainLeftLayout); mainLayout->addWidget(containerWidget); - mainLayout->addSpacing(3); + mainLayout->addSpacing(Theme::dp2px(3)); QWidget *centralWidget = new QWidget; centralWidget->setLayout(mainLayout); diff --git a/src/floatnumberwidget.cpp b/src/floatnumberwidget.cpp index 2a3297bd..c13fb35e 100644 --- a/src/floatnumberwidget.cpp +++ b/src/floatnumberwidget.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "theme.h" #include "floatnumberwidget.h" FloatNumberWidget::FloatNumberWidget(QWidget *parent, bool singleLine) : @@ -8,7 +9,7 @@ FloatNumberWidget::FloatNumberWidget(QWidget *parent, bool singleLine) : { m_slider = new QSlider(Qt::Horizontal, this); m_slider->setRange(0, 100); - m_slider->setFixedWidth(120); + m_slider->setFixedWidth(Theme::dp2px(120)); m_label = new QLabel(this); m_label->setAlignment(Qt::AlignLeft); diff --git a/src/parttreewidget.cpp b/src/parttreewidget.cpp index f118d6fc..980c9c7d 100644 --- a/src/parttreewidget.cpp +++ b/src/parttreewidget.cpp @@ -963,8 +963,7 @@ void PartTreeWidget::partUnchecked(QUuid partId) QSize PartTreeWidget::sizeHint() const { - QSize size = PartWidget::preferredSize(); - return QSize(size.width() * 1.35, size.height() * 5.5); + return QSize(Theme::sidebarPreferredWidth, 0); } bool PartTreeWidget::isComponentSelected(QUuid componentId) diff --git a/src/theme.cpp b/src/theme.cpp index cdddc774..dd2526ba 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -43,24 +43,30 @@ int Theme::posePreviewImageSize = 0; int Theme::motionPreviewImageSize = 0; int Theme::sidebarPreferredWidth = 0; int Theme::normalButtonSize = 0; +double Theme::dpi = 0; + +float Theme::dp2px(float dp) +{ + return dp / 72 * Theme::dpi; +} void Theme::initAwsomeBaseSizes() { + Theme::dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch(); + Theme::toolIconFontSize = QApplication::font().pixelSize(); if (-1 == Theme::toolIconFontSize) { - double dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch(); - Theme::toolIconFontSize = (float)QApplication::font().pointSize() / 72 * dpi; + Theme::toolIconFontSize = Theme::dp2px(QApplication::font().pointSize()); } - Theme::toolIconFontSize *= 0.7; - Theme::toolIconSize = (int)(Theme::toolIconFontSize * 1.67); + Theme::toolIconSize = (int)(Theme::toolIconFontSize * 1.5); Theme::miniIconFontSize = (int)(Theme::toolIconFontSize * 0.64); Theme::miniIconSize = (int)(Theme::miniIconFontSize * 1.67); Theme::partPreviewImageSize = (Theme::miniIconSize * 3); - Theme::materialPreviewImageSize = 75; - Theme::posePreviewImageSize = 75; - Theme::motionPreviewImageSize = 75; - Theme::sidebarPreferredWidth = 200; + Theme::materialPreviewImageSize = Theme::dp2px(62); + Theme::posePreviewImageSize = Theme::dp2px(62); + Theme::motionPreviewImageSize = Theme::dp2px(62); + Theme::sidebarPreferredWidth = Theme::dp2px(150); Theme::normalButtonSize = Theme::toolIconSize * 2; qDebug() << "Theme::toolIconFontSize:" << Theme::toolIconFontSize; diff --git a/src/theme.h b/src/theme.h index b8a32433..8991cc31 100644 --- a/src/theme.h +++ b/src/theme.h @@ -42,6 +42,7 @@ public: static int miniIconSize; static int sidebarPreferredWidth; static int normalButtonSize; + static double dpi; public: static void initAwesomeButton(QPushButton *button); static void initAwesomeLabel(QLabel *label); @@ -51,6 +52,7 @@ public: static void initAwesomeToolButton(QPushButton *button); static void initAwesomeToolButtonWithoutFont(QPushButton *button); static void initAwsomeBaseSizes(); + static float dp2px(float dp); }; #endif