forked from qt-creator/qt-creator
QmlDesigner: Add support for high dpi to form editor and puppet
We forward the device pixel ratio to the qml2puppet and render items in higher resolutions. We have to set the device pixel ratio on the pixmap manually, since it is not serialized. The option IgnoreDevicePixelRaio allows disabling high dpi awareness. Rendering in high dpi affects performance, but since we use shared memory this does not seem to be a serious issue. Change-Id: Ie9219b8fdb37841c24d4fb3f0ca259f0194ef65c Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
a6985eaa85
commit
bf3008292f
@@ -366,7 +366,13 @@ QImage QuickItemNodeInstance::renderImage() const
|
||||
|
||||
QRectF renderBoundingRect = boundingRect();
|
||||
|
||||
QImage renderImage = designerSupport()->renderImageForItem(quickItem(), renderBoundingRect, renderBoundingRect.size().toSize());
|
||||
QSize size = renderBoundingRect.size().toSize();
|
||||
static float devicePixelRatio = qgetenv("FORMEDITOR_DEVICE_PIXEL_RATIO").toDouble();
|
||||
size *= devicePixelRatio;
|
||||
|
||||
QImage renderImage = designerSupport()->renderImageForItem(quickItem(), renderBoundingRect, size);
|
||||
|
||||
renderImage.setDevicePixelRatio(devicePixelRatio);
|
||||
|
||||
return renderImage;
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
|
||||
#include "nodeinstance.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <modelnode.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
void qt_blurImage(QPainter *painter, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
|
||||
@@ -397,6 +398,7 @@ QPixmap NodeInstance::blurredRenderPixmap() const
|
||||
void NodeInstance::setRenderPixmap(const QImage &image)
|
||||
{
|
||||
d->renderPixmap = QPixmap::fromImage(image);
|
||||
d->renderPixmap.setDevicePixelRatio(QmlDesignerPlugin::formEditorDevicePixelRatio());
|
||||
d->blurredRenderPixmap = QPixmap();
|
||||
}
|
||||
|
||||
|
||||
@@ -414,6 +414,8 @@ QProcessEnvironment PuppetCreator::processEnvironment() const
|
||||
environment.set(QLatin1String("QT_LABS_CONTROLS_STYLE"), controlsStyle);
|
||||
}
|
||||
|
||||
environment.set(QLatin1String("FORMEDITOR_DEVICE_PIXEL_RATIO"), QString::number(QmlDesignerPlugin::formEditorDevicePixelRatio()));
|
||||
|
||||
const QString styleConfigFileName = getStyleConfigFileName();
|
||||
|
||||
/* QT_QUICK_CONTROLS_CONF is not supported for Qt Version < 5.8.1,
|
||||
|
||||
@@ -71,6 +71,7 @@ void DesignerSettings::fromSettings(QSettings *settings)
|
||||
restoreValue(settings, DesignerSettingsKey::DEBUG_PUPPET, QString());
|
||||
restoreValue(settings, DesignerSettingsKey::FORWARD_PUPPET_OUTPUT, QString());
|
||||
restoreValue(settings, DesignerSettingsKey::REFORMAT_UI_QML_FILES, true);
|
||||
restoreValue(settings, DesignerSettingsKey::IGNORE_DEVICE_PIXEL_RATIO, false);
|
||||
|
||||
settings->endGroup();
|
||||
settings->endGroup();
|
||||
|
||||
@@ -57,10 +57,9 @@ const char ENABLE_MODEL_EXCEPTION_OUTPUT[] = "WarnException";
|
||||
const char PUPPET_KILL_TIMEOUT[] = "PuppetKillTimeout";
|
||||
const char DEBUG_PUPPET[] = "DebugPuppet";
|
||||
const char FORWARD_PUPPET_OUTPUT[] = "ForwardPuppetOutput";
|
||||
const char REFORMAT_UI_QML_FILES[] = "ReformatUiQmlFiles"; /* This Setting is not exposed in ui.
|
||||
The setting can be used to turn off the feature,
|
||||
if there are serious issues */
|
||||
const char STATESEDITOR_EXPANDED[] = "StatesEditorExpanded";
|
||||
const char REFORMAT_UI_QML_FILES[] = "ReformatUiQmlFiles"; /* These settings are not exposed in ui. */
|
||||
const char IGNORE_DEVICE_PIXEL_RATIO[] = "IgnoreDevicePixelRaio"; /* The settings can be used to turn off the feature, if there are serious issues */
|
||||
}
|
||||
|
||||
class DesignerSettings : public QHash<QByteArray, QVariant>
|
||||
|
||||
@@ -67,6 +67,8 @@
|
||||
#include <qplugin.h>
|
||||
#include <QDebug>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
|
||||
Q_LOGGING_CATEGORY(qmldesignerLog, "qtc.qmldesigner")
|
||||
|
||||
@@ -483,6 +485,17 @@ void QmlDesignerPlugin::emitCurrentTextEditorChanged(Core::IEditor *editor)
|
||||
d->blockEditorChange = false;
|
||||
}
|
||||
|
||||
double QmlDesignerPlugin::formEditorDevicePixelRatio()
|
||||
{
|
||||
if (DesignerSettings::getValue(DesignerSettingsKey::IGNORE_DEVICE_PIXEL_RATIO).toBool())
|
||||
return 1;
|
||||
|
||||
const QList<QWindow *> topLevelWindows = QApplication::topLevelWindows();
|
||||
if (topLevelWindows.isEmpty())
|
||||
return 1;
|
||||
return topLevelWindows.first()->screen()->devicePixelRatio();
|
||||
}
|
||||
|
||||
QmlDesignerPlugin *QmlDesignerPlugin::instance()
|
||||
{
|
||||
return m_instance;
|
||||
|
||||
@@ -85,6 +85,8 @@ public:
|
||||
void switchToTextModeDeferred();
|
||||
void emitCurrentTextEditorChanged(Core::IEditor *editor);
|
||||
|
||||
static double formEditorDevicePixelRatio();
|
||||
|
||||
private: // functions
|
||||
void integrateIntoQtCreator(QWidget *modeWidget);
|
||||
void showDesigner();
|
||||
|
||||
Reference in New Issue
Block a user