Skip to content

Commit

Permalink
Implement basic support for title and copyright decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Feb 20, 2024
1 parent 2693c52 commit e0ce1a3
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/core/projectinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <QDateTime>
#include <QFileInfo>
#include <QString>
#include <QTextDocument>
#include <qgscolorutils.h>
#include <qgslayertree.h>
#include <qgslayertreemodel.h>
#include <qgsmaplayerstyle.h>
Expand Down Expand Up @@ -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( "<br>" ) );
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( "<br>" ) );
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;
}
4 changes: 4 additions & 0 deletions src/core/projectinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
84 changes: 84 additions & 0 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e0ce1a3

Please sign in to comment.