Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • alcroito/qt-ui-viewer
  • design-studio/design-viewer/qt-ui-viewer
2 results
Show changes
Commits on Source (1)
...@@ -13,13 +13,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) ...@@ -13,13 +13,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package( find_package(
QT NAMES Qt6 QT NAMES Qt6
COMPONENTS Core Widgets Quick Gui Qml Multimedia MultimediaWidgets Concurrent COMPONENTS Core Widgets Quick Gui Qml Multimedia MultimediaWidgets Concurrent QuickControls2
REQUIRED REQUIRED
) )
find_package( find_package(
Qt6 Qt6
COMPONENTS Core Widgets Quick Gui Qml Multimedia MultimediaWidgets Concurrent COMPONENTS Core Widgets Quick Gui Qml Multimedia MultimediaWidgets Concurrent QuickControls2
REQUIRED REQUIRED
) )
...@@ -49,6 +49,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ...@@ -49,6 +49,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::Qml Qt6::GuiPrivate Qt6::Qml Qt6::GuiPrivate
Qt6::Multimedia Qt6::MultimediaWidgets Qt6::Multimedia Qt6::MultimediaWidgets
Qt6::Concurrent Qt6::Concurrent
Qt6::QuickControls2
ZXing::ZXing ZXing::ZXing
) )
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <QMediaDevices> #include <QMediaDevices>
#include <QMessageBox> #include <QMessageBox>
#include <QPermission> #include <QPermission>
#include <QQmlContext>
#include <QQuickStyle>
#include <QSettings> #include <QSettings>
#include <QSslSocket> #include <QSslSocket>
#include <QVideoSink> #include <QVideoSink>
...@@ -61,29 +63,11 @@ Backend::Backend(QObject *parent) ...@@ -61,29 +63,11 @@ Backend::Backend(QObject *parent)
&ServiceConnector::downloadProgress, &ServiceConnector::downloadProgress,
this, this,
&Backend::downloadProgress); &Backend::downloadProgress);
}
void Backend::initialize()
{
const QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
qDebug() << "Qt Design Viewer";
qDebug() << "System information:";
qDebug() << "-- Qt version: " << QT_VERSION_STR;
qDebug() << "-- OpenSSL support: " << QVariant(QSslSocket::supportsSsl()).toString();
qDebug() << "-- Screen height: " << QString::number(screenGeometry.height());
qDebug() << "-- Screen width: " << QString::number(screenGeometry.width());
#ifdef QT_DEBUG // Initialize background update
const QString buildType = "Debug"; connect(&m_backgroundTimer, &QTimer::timeout, this, &Backend::updateUserProjectList);
#else m_backgroundTimer.setInterval(1000 * 10);
const QString buildType = "Release"; enableBackgroundUpdate(updateInBackground());
#endif
const QString buildInfo = QCoreApplication::applicationVersion() + "\nTechnology Preview - "
+ QString(GIT_VERSION) + "\nQt " + QString(QT_VERSION_STR) + " - "
+ buildType + " Build" + "\nQt Quick Components "
+ QString(QT_QUICK_COMPONENTS_VERSION) + "\nOpenSSL support: "
+ QVariant(QSslSocket::supportsSsl()).toString();
emit buildInfoChanged(buildInfo);
if (userHash().isEmpty()) if (userHash().isEmpty())
qDebug("User Hash is not registered. Scan QR code to register."); qDebug("User Hash is not registered. Scan QR code to register.");
...@@ -92,11 +76,27 @@ void Backend::initialize() ...@@ -92,11 +76,27 @@ void Backend::initialize()
updateUserProjectList(); updateUserProjectList();
} }
// Initialize background update #ifdef QT_DEBUG
connect(&m_backgroundTimer, &QTimer::timeout, this, &Backend::updateUserProjectList); const QString buildType = "Debug";
m_backgroundTimer.setInterval(1000 * 10); #else
enableBackgroundUpdate(updateInBackground()); const QString buildType = "Release";
qDebug() << "Initialization complete"; #endif
m_buildInfo = QCoreApplication::applicationVersion() + "\nTechnology Preview - "
+ QString(GIT_VERSION) + "\nQt " + QString(QT_VERSION_STR) + " - " + buildType
+ " Build" + "\nQt Quick Components " + QString(QT_QUICK_COMPONENTS_VERSION)
+ "\nOpenSSL support: " + QVariant(QSslSocket::supportsSsl()).toString();
const QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
qDebug() << "Qt Design Viewer";
qDebug() << "System information:";
qDebug() << "-- Qt version: " << QT_VERSION_STR;
qDebug() << "-- OpenSSL support: " << QVariant(QSslSocket::supportsSsl()).toString();
qDebug() << "-- Screen height: " << QString::number(screenGeometry.height());
qDebug() << "-- Screen width: " << QString::number(screenGeometry.width());
// initialize the main UI after a short delay
// because we need to make sure that the backend is fully initialized
QTimer::singleShot(100, this, &Backend::initMainUI);
} }
void Backend::enableBackgroundUpdate(const bool &enabled) void Backend::enableBackgroundUpdate(const bool &enabled)
...@@ -268,10 +268,42 @@ void Backend::openCamera() ...@@ -268,10 +268,42 @@ void Backend::openCamera()
m_captureSession->camera()->start(); m_captureSession->camera()->start();
} }
void Backend::initMainUI()
{
qDebug() << "Initializing main UI";
// qmlClearTypeRegistrations();
// qputenv("QT_QUICK_CONTROLS_STYLE", QByteArray("Material"));
// qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", QByteArray("Light"));
QQuickStyle::setStyle("Material");
m_view.reset(new QQuickView(), [](QQuickView *v) { v->deleteLater(); });
m_view->engine()->rootContext()->setContextProperty("backend", this);
m_view->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
m_view->setResizeMode(QQuickView::SizeRootObjectToView);
m_view->showMaximized();
connect(m_view.data(), &QQuickView::destroyed, this, [&] {
qDebug() << "Main UI is destroyed.";
});
}
void Backend::clearMainUI()
{
qDebug() << "Clearing main UI";
m_view.reset();
}
void Backend::initializeProjectManager() void Backend::initializeProjectManager()
{ {
// Workaround for QDS-11413
clearMainUI();
// End of workaround
m_projectManager.reset(new ProjectManager(autoScaleProject())); m_projectManager.reset(new ProjectManager(autoScaleProject()));
connect(m_projectManager.data(), &ProjectManager::closingProject, this, [&] { connect(m_projectManager.data(), &ProjectManager::closingProject, this, [&] {
qDebug() << "Project is closed";
// workaround for QDS-11413
initMainUI();
// end of workaround
emit popupClose(); emit popupClose();
m_projectManager.reset(); m_projectManager.reset();
}); });
......
...@@ -59,10 +59,11 @@ class Backend : public QObject ...@@ -59,10 +59,11 @@ class Backend : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QJsonArray projectList READ projectList NOTIFY projectListChanged) Q_PROPERTY(QJsonArray projectList READ projectList NOTIFY projectListChanged)
Q_PROPERTY(
int currentStackLayoutIndex READ currentStackLayoutIndex WRITE setCurrentStackLayoutIndex)
public: public:
explicit Backend(QObject *parent = nullptr); explicit Backend(QObject *parent = nullptr);
void initialize();
void setLogs(const QString &logs) void setLogs(const QString &logs)
{ {
m_logs = logs; m_logs = logs;
...@@ -70,11 +71,18 @@ public: ...@@ -70,11 +71,18 @@ public:
} }
QJsonArray projectList() const { return m_projectList; } QJsonArray projectList() const { return m_projectList; }
int currentStackLayoutIndex() const { return m_currentStackLayoutIndex; }
void setCurrentStackLayoutIndex(const int &index) { m_currentStackLayoutIndex = index; }
private: private:
// main UI
QSharedPointer<QQuickView> m_view;
// UI data // UI data
QString m_logs; QString m_logs;
QJsonArray m_projectList; QJsonArray m_projectList;
QString m_buildInfo;
int m_currentStackLayoutIndex = 0;
// Other members // Other members
ServiceConnector m_serviceConnector; ServiceConnector m_serviceConnector;
...@@ -91,29 +99,9 @@ private: ...@@ -91,29 +99,9 @@ private:
// member functions // member functions
void updatePopup(const QString &text, bool indeterminate = true); void updatePopup(const QString &text, bool indeterminate = true);
signals:
// UI signals - Home page
void projectListChanged();
void urlUpdated(QString);
void userHashChanged();
// UI signals - Logs page
void logsChanged(QString);
// UI signals - About page
void buildInfoChanged(QString);
// UI signals - Popup
void downloadProgress(float);
void popupProgressIndeterminateChanged(bool indeterminate);
void popupTextChanged(QString text);
void popupOpen();
void popupClose();
// UI signals - Network page
void networkUpdated(QString);
public slots: public slots:
QString buildInfo() const { return m_buildInfo; }
void scanQrCode(); void scanQrCode();
void openCamera(); void openCamera();
...@@ -140,6 +128,30 @@ private slots: ...@@ -140,6 +128,30 @@ private slots:
void initializeProjectManager(); void initializeProjectManager();
void enableBackgroundUpdate(const bool &enabled); void enableBackgroundUpdate(const bool &enabled);
void updateUserProjectList(); void updateUserProjectList();
void initMainUI();
void clearMainUI();
signals:
// UI signals - Home page
void projectListChanged();
void urlUpdated(QString);
void userHashChanged();
// UI signals - Logs page
void logsChanged(QString);
// UI signals - Popup
void downloadProgress(float);
void popupProgressIndeterminateChanged(bool indeterminate);
void popupTextChanged(QString text);
void popupOpen();
void popupClose();
// UI signals - Network page
void networkUpdated(QString);
// other signals
void resetQmlEngine();
}; };
#endif // DV_ANDROID_H #endif // DV_ANDROID_H
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <QApplication> #include <QApplication>
#include <QMessageBox> #include <QMessageBox>
#include <QQmlContext>
#include "backend.h" #include "backend.h"
...@@ -64,33 +63,28 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt ...@@ -64,33 +63,28 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt
newLog += logPrefix + localMsg + logSuffix + "\n"; newLog += logPrefix + localMsg + logSuffix + "\n";
__android_log_print(ANDROID_LOG_DEBUG, "Qt_UI_Viewer", "%s", qPrintable(newLog)); __android_log_print(ANDROID_LOG_DEBUG, "Qt_UI_Viewer", "%s", qPrintable(newLog));
if (type == QtWarningMsg) { if (type != QtDebugMsg) {
if (backend)
backend->setLogs(appLogs += newLog);
} else if (type == QtCriticalMsg || type == QtFatalMsg) {
QMessageBox msgBox{QMessageBox::Critical, "Critical:", msg, QMessageBox::Ok};
msgBox.exec();
if (backend) if (backend)
backend->setLogs(appLogs += newLog); backend->setLogs(appLogs += newLog);
if (type == QtCriticalMsg || type == QtFatalMsg) {
QMessageBox msgBox{QMessageBox::Critical, "Critical:", msg, QMessageBox::Ok};
msgBox.exec();
}
} }
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
qInstallMessageHandler(messageHandler); qInstallMessageHandler(messageHandler);
qDebug() << "Starting Qt Design Viewer";
QApplication app(argc, argv); QApplication app(argc, argv);
QApplication::setOrganizationName("Qt"); QApplication::setOrganizationName("Qt");
QApplication::setApplicationName(QStringLiteral("Qt Design Viewer")); QApplication::setApplicationName(QStringLiteral("Qt Design Viewer"));
QApplication::setApplicationVersion(QString("Built on %1 %2").arg(__DATE__, __TIME__)); QApplication::setApplicationVersion(QString("Built on %1 %2").arg(__DATE__, __TIME__));
QQuickView view;
backend = new Backend(); backend = new Backend();
view.engine()->rootContext()->setContextProperty("backend", backend);
view.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.showMaximized();
backend->initialize();
return app.exec(); return app.exec();
} }
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QJsonDocument> #include <QJsonDocument>
#include <QQuickItem> #include <QQuickItem>
#include <QQuickStyle>
#include <QRandomGenerator> #include <QRandomGenerator>
#include <QRegularExpression> #include <QRegularExpression>
#include <QResource> #include <QResource>
...@@ -240,6 +241,14 @@ bool ProjectManager::runProject(const QString &projectPath) ...@@ -240,6 +241,14 @@ bool ProjectManager::runProject(const QString &projectPath)
} }
qDebug() << "Initializing the qmlEngine"; qDebug() << "Initializing the qmlEngine";
// This is a workaround for QDS-11413
// The QML engines are not isolated from each other, so we need to clear the type registrations
// But that causes a crash in the main QML engine that we use for the main UI (initialized in main.cpp),
// so we need to reset the main engine as well.
// qmlClearTypeRegistrations();
// qputenv("QT_QUICK_CONTROLS_STYLE", QByteArray("Basic"));
QQuickStyle::setStyle("Basic");
m_qmlEngine.reset(new QQmlEngine); m_qmlEngine.reset(new QQmlEngine);
m_qmlEngine->clearComponentCache(); m_qmlEngine->clearComponentCache();
......
...@@ -22,7 +22,7 @@ Item { ...@@ -22,7 +22,7 @@ Item {
id: logs id: logs
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
horizontalAlignment: "AlignHCenter" horizontalAlignment: "AlignHCenter"
text: qsTr("Hello World") text: backend.buildInfo()
} }
Item { Item {
...@@ -30,12 +30,5 @@ Item { ...@@ -30,12 +30,5 @@ Item {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
} }
Connections {
target: backend
function onBuildInfoChanged(buildInfo){
logs.text = buildInfo;
}
}
} }
} }
...@@ -87,7 +87,9 @@ Item { ...@@ -87,7 +87,9 @@ Item {
Button { Button {
id: downloadUserProject id: downloadUserProject
text: qsTr("Run Project") text: qsTr("Run Project")
onClicked: backend.runUserProject(projectList.currentText) onClicked: {
backend.runUserProject(projectList.displayText);
}
enabled: false enabled: false
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
......
...@@ -10,7 +10,6 @@ Rectangle { ...@@ -10,7 +10,6 @@ Rectangle {
color: "#EAEAEA" color: "#EAEAEA"
state: "vertical" state: "vertical"
M.Material.theme: M.Material.Light M.Material.theme: M.Material.Light
M.Material.accent: M.Material.Blue M.Material.accent: M.Material.Blue
M.Material.primary: M.Material.Blue M.Material.primary: M.Material.Blue
...@@ -88,6 +87,8 @@ Rectangle { ...@@ -88,6 +87,8 @@ Rectangle {
anchors.rightMargin: 20 anchors.rightMargin: 20
anchors.leftMargin: 20 anchors.leftMargin: 20
anchors.topMargin: 10 anchors.topMargin: 10
currentIndex: backend.currentStackLayoutIndex
onCurrentIndexChanged: backend.currentStackLayoutIndex = currentIndex
HomePage { HomePage {
id: homePage id: homePage
...@@ -158,107 +159,90 @@ Rectangle { ...@@ -158,107 +159,90 @@ Rectangle {
id: scrollview id: scrollview
anchors.fill: parent anchors.fill: parent
ColumnLayout { ColumnLayout {
id: column id: column
anchors.fill: drawer anchors.fill: drawer
anchors.rightMargin: 10 anchors.rightMargin: 10
anchors.leftMargin: 10 anchors.leftMargin: 10
width: Math.max(implicitWidth, drawer.availableWidth) width: Math.max(implicitWidth, drawer.availableWidth)
height: Math.max(implicitHeight, drawer.availableHeight) height: Math.max(implicitHeight, drawer.availableHeight)
onActiveFocusChanged: if (!activeFocus) drawer.close()
TabButton {
id: home TabButton {
text: qsTr("Home") id: home
Layout.fillWidth: true text: qsTr("Home")
checked: true Layout.fillWidth: true
checkable: true checked: true
autoExclusive: true checkable: true
autoExclusive: true
Connections { onClicked: {
target: home
function onClicked(){
stackLayout.currentIndex = 0 stackLayout.currentIndex = 0
drawer.close()
} }
} }
}
TabButton { TabButton {
id: examples id: examples
text: qsTr("Examples") text: qsTr("Examples")
Layout.fillWidth: true Layout.fillWidth: true
checkable: true checkable: true
autoExclusive: true autoExclusive: true
onClicked: {
Connections {
target: examples
function onClicked(){
stackLayout.currentIndex = 1 stackLayout.currentIndex = 1
drawer.close()
} }
} }
}
TabButton {
id: logs
text: qsTr("Logs")
Layout.fillWidth: true
checkable: true
autoExclusive: true
Connections { TabButton {
target: logs id: logs
function onClicked(){ text: qsTr("Logs")
Layout.fillWidth: true
checkable: true
autoExclusive: true
onClicked: {
stackLayout.currentIndex = 2 stackLayout.currentIndex = 2
drawer.close()
} }
} }
}
TabButton {
id: network
text: qsTr("Network")
Layout.fillWidth: true
checkable: true
autoExclusive: true
visible: true;
Connections { TabButton {
target: network id: network
function onClicked(){ text: qsTr("Network")
Layout.fillWidth: true
checkable: true
autoExclusive: true
visible: true;
onClicked: {
stackLayout.currentIndex = 3 stackLayout.currentIndex = 3
drawer.close()
} }
} }
}
TabButton {
id: settings
text: qsTr("Settings")
Layout.fillWidth: true
checkable: true
autoExclusive: true
Connections { TabButton {
target: settings id: settings
function onClicked(){ text: qsTr("Settings")
Layout.fillWidth: true
checkable: true
autoExclusive: true
onClicked: {
stackLayout.currentIndex = 4 stackLayout.currentIndex = 4
drawer.close()
} }
} }
}
TabButton { TabButton {
id: about id: about
text: qsTr("About") text: qsTr("About")
Layout.fillWidth: true Layout.fillWidth: true
checkable: true checkable: true
autoExclusive: true autoExclusive: true
onClicked: {
Connections {
target: about
function onClicked(){
stackLayout.currentIndex = 5 stackLayout.currentIndex = 5
drawer.close()
} }
} }
} }
} }
}
} }
Button { Button {
......