Skip to content
Snippets Groups Projects
Commit 864e89fc authored by Burak Hançerli's avatar Burak Hançerli :headphones:
Browse files

Merge branch 'QDS-10489/handle-device-orientation' into 'master'

QDS-10489 Handle device orientation

Closes QDS-10489

See merge request design-studio/cloud-services/design-viewer!8
parents f4d4ea40 34583d7c
No related branches found
No related tags found
1 merge request!8QDS-10489 Handle device orientation
Pipeline #61757 passed
......@@ -20,6 +20,7 @@ build-android-multiarch:
image: "${QDS_CI_REGISTRY_IMAGE}/${QDS_CI_JOB_TARGET_PLATFORM}:${QDS_CI_QT_VERSION}-${QDS_CI_JOB_TARGET_PLATFORM}-${QDS_CI_JOB_TARGET_ARCH}"
variables:
QDS_CI_JOB_TARGET_PLATFORM: "android"
QDS_CI_QT_VERSION: "652"
rules:
- if: $QDS_CI_QT_VERSION_ANDROID != "none"
parallel:
......
......@@ -35,6 +35,8 @@
#include <QScrollBar>
#include <QSslSocket>
#define QSTRN QString::number
void DvAndroid::printLog(const QString &log)
{
QDateTime now = QDateTime::currentDateTime();
......@@ -56,7 +58,7 @@ void DvAndroid::printError(const QString &error, const QString &fileName, int li
.append(" (")
.append(fileName)
.append(":")
.append(QString::number(line))
.append(QSTRN(line))
.append(")"));
}
......@@ -87,9 +89,8 @@ QSharedPointer<QNetworkReply> DvAndroid::fetchResource(const QString &url)
this,
[&](qint64 bytesReceived, qint64 bytesTotal) {
float percentage = roundf((float) bytesReceived / (float) bytesTotal * 100);
printLog("Download progress " + QString::number(percentage) + "% - "
+ QString::number(bytesReceived) + "/"
+ QString::number(bytesTotal));
printLog("Download progress " + QSTRN(percentage) + "% - "
+ QSTRN(bytesReceived) + "/" + QSTRN(bytesTotal));
});
loop.exec();
......@@ -135,6 +136,8 @@ void DvAndroid::setupUi()
// configure line edit
m_lineEdit->setPlaceholderText("Enter project URL here");
m_lineEdit->setText(
"https://designviewer.qt.io/#17e8907b3b84b8206d45be4f551f4e25/TestTwo.qmlrc");
// configure the button
m_button->setText("Download and run project");
......@@ -152,8 +155,8 @@ void DvAndroid::printSysInfo()
printLog("System information:");
printLog("-- Qt version: " + QString(QT_VERSION_STR));
printLog("-- OpenSSL support: " + QVariant(QSslSocket::supportsSsl()).toString());
printLog("-- Screen height: " + QString::number(screenGeometry.height()));
printLog("-- Screen width: " + QString::number(screenGeometry.width()));
printLog("-- Screen height: " + QSTRN(screenGeometry.height()));
printLog("-- Screen width: " + QSTRN(screenGeometry.width()));
}
void DvAndroid::updateLogo()
......@@ -211,76 +214,57 @@ void DvAndroid::fetchAndRunProject()
}
}
void DvAndroid::showAppWindow()
void DvAndroid::orientateWindow(Qt::ScreenOrientation orientation)
{
QQuickItem *contentItem{m_quickWindow->contentItem()};
QQuickItem *contentItem = m_quickWindow->contentItem();
QQuickItem *childItem{contentItem->childItems().at(0)};
const QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
printLog("Initial sizing:");
printLog("-- Primary screen height: " + QString::number(screenGeometry.height()));
printLog("-- Primary screen width: " + QString::number(screenGeometry.width()));
printLog("-- Content item height: " + QString::number(contentItem->height()));
printLog("-- Content item width: " + QString::number(contentItem->width()));
printLog("-- Content item scale: " + QString::number(contentItem->scale()));
printLog("-- Child item height: " + QString::number(childItem->height()));
printLog("-- Child item width: " + QString::number(childItem->width()));
printLog("-- Child item scale: " + QString::number(childItem->scale()));
printLog("Adapting orientation. Initial sizing:");
printLog("-- Screen size: " + QSTRN(screenGeometry.height()) + " x "
+ QSTRN(screenGeometry.width()));
printLog("-- Quick window size: " + QSTRN(m_quickWindow->height()) + " x "
+ QSTRN(m_quickWindow->width()));
printLog("-- Child size: " + QSTRN(childItem->height()) + " x " + QSTRN(childItem->width()));
printLog("-- Child pos: " + QSTRN(childItem->x()) + ", " + QSTRN(childItem->y()));
printLog("-- Child scale: " + QSTRN(childItem->scale()));
printLog("Calculating the new size and scale...");
const QSizeF contentSize = childItem->size();
const QSizeF newContentSize = contentSize.scaled(screenGeometry.size().toSizeF(),
Qt::AspectRatioMode::KeepAspectRatio);
const qreal newScale = newContentSize.width() / contentSize.width();
const int leftOffset = childItem->width() - screenGeometry.width();
const int newLeftOffset = (leftOffset * (-0.5)) * newScale;
printLog("Calculated item height: " + QString::number(newContentSize.height()));
printLog("Calculated item width: " + QString::number(newContentSize.width()));
printLog("Calculated item scale: " + QString::number(newScale));
printLog("Current left offset: " + QString::number(leftOffset));
printLog("Calculated left offset: " + QString::number(newLeftOffset));
contentItem->setScale(newScale);
if (leftOffset > 0) {
printLog("Left offset is bigger than 0");
printLog("Setting new left offset: " + QString::number(newLeftOffset));
contentItem->setX(newLeftOffset);
}
for (const auto &cItem : contentItem->childItems()) {
qDebug() << cItem << cItem->objectName();
}
const QSizeF newContentSize = childItem->size().scaled(screenGeometry.size().toSizeF(),
Qt::AspectRatioMode::KeepAspectRatio);
printLog("Initializing and showing the QML app window");
const qreal newScale = newContentSize.height() / childItem->size().height();
const qreal newX = (childItem->width() - screenGeometry.width()) / -2.0f;
const qreal newY = (childItem->height() - screenGeometry.height()) / -2.0f;
m_quickWindow->setFlags(m_quickWindow->flags() | Qt::WindowStaysOnTopHint);
m_quickWindow->show();
m_quickWindow->raise();
m_quickWindow->requestActivate();
childItem->setScale(newScale);
childItem->setPosition(QPointF(newX, newY));
printLog("-- Calculated item height: " + QSTRN(newContentSize.height()));
printLog("-- Calculated item width: " + QSTRN(newContentSize.width()));
printLog("-- Calculated item scale: " + QSTRN(newScale));
printLog("-- Calculated item pos..: " + QSTRN(newX) + "," + QSTRN(newY));
printLog("Final Sizing:");
printLog("-- Main window height: " + QString::number(m_mainWindow.height()));
printLog("-- Main window width: " + QString::number(m_mainWindow.width()));
printLog("-- Quick window height: " + QString::number(m_quickWindow->height()));
printLog("-- Quick window width: " + QString::number(m_quickWindow->width()));
printLog("-- Quick window pos-x: " + QString::number(m_quickWindow->position().x()));
printLog("-- Quick window pos-y: " + QString::number(m_quickWindow->position().y()));
printLog("-- Content item height: " + QString::number(contentItem->height()));
printLog("-- Content item width: " + QString::number(contentItem->width()));
printLog("-- Content item scale: " + QString::number(contentItem->scale()));
printLog("-- Content item pos-x: " + QString::number(contentItem->x()));
printLog("-- Content item pos-y: " + QString::number(contentItem->y()));
printLog("-- Child content item height: " + QString::number(childItem->height()));
printLog("-- Child content item width: " + QString::number(childItem->width()));
printLog("-- Child content item scale: " + QString::number(childItem->scale()));
printLog("-- Child content pos-x: " + QString::number(childItem->x()));
printLog("-- Child content pos-y: " + QString::number(childItem->y()));
printLog("-- Child height: " + QSTRN(childItem->height()));
printLog("-- Child width: " + QSTRN(childItem->width()));
printLog("-- Child scale: " + QSTRN(childItem->scale()));
printLog("-- Child pos-x: " + QSTRN(childItem->x()));
printLog("-- Child pos-y: " + QSTRN(childItem->y()));
}
void DvAndroid::showAppWindow()
{
QScreen *screen = QGuiApplication::primaryScreen();
QObject::connect(screen, &QScreen::orientationChanged, this, &DvAndroid::orientateWindow);
orientateWindow(screen->orientation());
printLog("Initializing and showing the QML app window");
m_quickWindow->show();
m_mainWindow.hide();
QObject::connect(m_quickWindow.data(), &QQuickWindow::closing, &m_mainWindow, &QWidget::show);
}
#endif // !defined(Q_OS_WASM)
......@@ -71,6 +71,7 @@ private:
private slots:
void fetchAndRunProject();
void orientateWindow(Qt::ScreenOrientation orientation);
};
#endif // DV_ANDROID_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment