From e0ce1a32b9376e6605b9def0311ad3a6cfc0dc82 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Tue, 20 Feb 2024 10:09:55 +0700 Subject: [PATCH] Implement basic support for title and copyright decoration --- src/core/projectinfo.cpp | 120 ++++++++++++++++++++++++++++++++++++++ src/core/projectinfo.h | 4 ++ src/qml/qgismobileapp.qml | 84 ++++++++++++++++++++++++++ 3 files changed, 208 insertions(+) diff --git a/src/core/projectinfo.cpp b/src/core/projectinfo.cpp index aad9c0609b..6c5d7b0b0a 100644 --- a/src/core/projectinfo.cpp +++ b/src/core/projectinfo.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -508,3 +510,121 @@ void ProjectInfo::restoreSettings( QString &projectFilePath, QgsProject *project } settings.endGroup(); } + +QVariantMap ProjectInfo::getTitleDecorationConfiguration() +{ + QVariantMap configuration; + const QString configurationName = QStringLiteral( "TitleLabel" ); + + if ( QgsProject::instance()->readBoolEntry( configurationName, QStringLiteral( "/Enabled" ), false ) ) + { + QString text = QgsProject::instance()->readEntry( configurationName, QStringLiteral( "/Label" ), QString() ); + if ( !text.isEmpty() ) + { + text.replace( QStringLiteral( "\n" ), QStringLiteral( "
" ) ); + QTextDocument doc; + doc.setHtml( text ); + text = doc.toPlainText(); + } + + QColor backgroundColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( configurationName, QStringLiteral( "/BackgroundColor" ), QStringLiteral( "0,0,0,99" ) ) ); + QColor color = QColor( Qt::black ); + QColor outlineColor = QColor( Qt::white ); + bool hasOutline = false; + + QDomDocument doc; + QDomElement elem; + const QString textXml = QgsProject::instance()->readEntry( configurationName, QStringLiteral( "/Font" ) ); + if ( !textXml.isEmpty() ) + { + doc.setContent( textXml ); + elem = doc.documentElement(); + QgsReadWriteContext rwContext; + rwContext.setPathResolver( QgsProject::instance()->pathResolver() ); + QgsTextFormat textFormat; + textFormat.readXml( elem, rwContext ); + + color = textFormat.color(); + if ( textFormat.buffer().enabled() ) + { + hasOutline = true; + outlineColor = textFormat.buffer().color(); + } + } + + configuration["text"] = text; + configuration["backgroundColor"] = backgroundColor; + configuration["color"] = color; + configuration["hasOutline"] = hasOutline; + configuration["outlineColor"] = outlineColor; + } + else + { + configuration["text"] = QString(); + configuration["backgroundColor"] = QColor( Qt::transparent ); + configuration["color"] = QColor( Qt::black ); + configuration["hasOutline"] = false; + configuration["outlineColor"] = QColor( Qt::white ); + } + + return configuration; +} + +QVariantMap ProjectInfo::getCopyrightDecorationConfiguration() +{ + QVariantMap configuration; + const QString configurationName = QStringLiteral( "CopyrightLabel" ); + + if ( QgsProject::instance()->readBoolEntry( configurationName, QStringLiteral( "/Enabled" ), false ) ) + { + QString text = QgsProject::instance()->readEntry( configurationName, QStringLiteral( "/Label" ), QString() ); + if ( !text.isEmpty() ) + { + text.replace( QStringLiteral( "\n" ), QStringLiteral( "
" ) ); + QTextDocument doc; + doc.setHtml( text ); + text = doc.toPlainText(); + } + + QColor backgroundColor = QColor( Qt::transparent ); + QColor color = QColor( Qt::black ); + QColor outlineColor = QColor( Qt::white ); + bool hasOutline = false; + + QDomDocument doc; + QDomElement elem; + const QString textXml = QgsProject::instance()->readEntry( configurationName, QStringLiteral( "/Font" ) ); + if ( !textXml.isEmpty() ) + { + doc.setContent( textXml ); + elem = doc.documentElement(); + QgsReadWriteContext rwContext; + rwContext.setPathResolver( QgsProject::instance()->pathResolver() ); + QgsTextFormat textFormat; + textFormat.readXml( elem, rwContext ); + + color = textFormat.color(); + if ( textFormat.buffer().enabled() ) + { + hasOutline = true; + outlineColor = textFormat.buffer().color(); + } + } + + configuration["text"] = text; + configuration["backgroundColor"] = backgroundColor; + configuration["color"] = color; + configuration["hasOutline"] = hasOutline; + configuration["outlineColor"] = outlineColor; + } + else + { + configuration["text"] = QString(); + configuration["backgroundColor"] = QColor( Qt::transparent ); + configuration["color"] = QColor( Qt::black ); + configuration["hasOutline"] = false; + configuration["outlineColor"] = QColor( Qt::white ); + } + + return configuration; +} diff --git a/src/core/projectinfo.h b/src/core/projectinfo.h index 3daf7b2d62..71fbee3dec 100644 --- a/src/core/projectinfo.h +++ b/src/core/projectinfo.h @@ -157,6 +157,10 @@ class ProjectInfo : public QObject //! Restore various project settings static void restoreSettings( QString &projectFilePath, QgsProject *project, QgsQuickMapCanvasMap *mapCanvas, FlatLayerTreeModel *layerTree ); + Q_INVOKABLE QVariantMap getTitleDecorationConfiguration(); + + Q_INVOKABLE QVariantMap getCopyrightDecorationConfiguration(); + signals: void filePathChanged(); diff --git a/src/qml/qgismobileapp.qml b/src/qml/qgismobileapp.qml index b0874a22c5..50c5e14162 100644 --- a/src/qml/qgismobileapp.qml +++ b/src/qml/qgismobileapp.qml @@ -794,6 +794,76 @@ ApplicationWindow { mapSettings: mapCanvas.mapSettings mapDistance: moveFeaturesToolbar.moveFeaturesRequested ? mapCanvas.mapSettings.center.y - moveFeaturesToolbar.startPoint.y : 0 } + + Rectangle { + id: titleDecorationBackground + + visible: titleDecoration.text != '' + + anchors.left: parent.left + anchors.leftMargin: 56 + anchors.top: parent.top + anchors.topMargin: mainWindow.sceneTopMargin + 4 + + width: parent.width - anchors.leftMargin * 2 + height: 48 + radius: 4 + + color:'#55000000' + + Text { + id: titleDecoration + + width: parent.width - 4 + height: parent.height + leftPadding: 2 + rightPadding: 2 + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + elide: Text.ElideRight + + font.pointSize: Theme.tipFont.pointSize + font.bold: true + + text: '' + } + } + + Rectangle { + id: copyrightDecorationBackground + + visible: copyrightDecoration.text != '' + + anchors.left: parent.left + anchors.leftMargin: 56 + anchors.bottom: parent.bottom + anchors.bottomMargin: 56 + + width: parent.width - anchors.leftMargin * 2 + height: 48 + radius: 4 + + color:'#55000000' + Text { + id: copyrightDecoration + + width: parent.width - 4 + height: parent.height + leftPadding: 2 + rightPadding: 2 + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignBottom + wrapMode: Text.WordWrap + elide: Text.ElideRight + + font: Theme.tinyFont + + text: '' + } + } } Column { @@ -3291,6 +3361,20 @@ ApplicationWindow { mapCanvasBackground.color = mapCanvas.mapSettings.backgroundColor + var titleDecorationConfiguration = projectInfo.getTitleDecorationConfiguration(); + titleDecoration.text = titleDecorationConfiguration["text"]; + titleDecoration.color = titleDecorationConfiguration["color"]; + titleDecoration.style = titleDecorationConfiguration["hasOutline"] === true ? Text.Outline : Text.Normal; + titleDecoration.styleColor = titleDecorationConfiguration["outlineColor"]; + titleDecorationBackground.color = titleDecorationConfiguration["backgroundColor"]; + + var copyrightDecorationConfiguration = projectInfo.getCopyrightDecorationConfiguration(); + copyrightDecoration.text = copyrightDecorationConfiguration["text"]; + copyrightDecoration.color = copyrightDecorationConfiguration["color"]; + copyrightDecoration.style = copyrightDecorationConfiguration["hasOutline"] === true ? Text.Outline : Text.Normal; + copyrightDecoration.styleColor = copyrightDecorationConfiguration["outlineColor"]; + copyrightDecorationBackground.color = copyrightDecorationConfiguration["backgroundColor"]; + recentProjectListModel.reloadModel() var cloudProjectId = QFieldCloudUtils.getProjectId(qgisProject.fileName)