From 5e4510f547f698c0f10beefee7c389c921d70b84 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 7 Jul 2014 23:14:09 +1000 Subject: [PATCH] [composer] Switch to using qscintilla for html editor in html item properties. Sponsored by City of Uster, Switzerland. --- src/app/composer/qgscomposerhtmlwidget.cpp | 26 ++++++++++++++++------ src/app/composer/qgscomposerhtmlwidget.h | 4 +++- src/core/composer/qgscomposerhtml.cpp | 6 ++++- src/ui/qgscomposerhtmlwidgetbase.ui | 18 +++++++-------- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/app/composer/qgscomposerhtmlwidget.cpp b/src/app/composer/qgscomposerhtmlwidget.cpp index 3a31f5ede46..72a3b81a4c3 100644 --- a/src/app/composer/qgscomposerhtmlwidget.cpp +++ b/src/app/composer/qgscomposerhtmlwidget.cpp @@ -20,11 +20,23 @@ #include "qgscomposition.h" #include #include +#include +#include QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame ): QgsComposerItemBaseWidget( 0, html ), mHtml( html ), mFrame( frame ) { setupUi( this ); + //setup html editor + mHtmlEditor = new QsciScintilla( this ); + mHtmlEditor->setLexer( new QsciLexerHTML ); + mHtmlEditor->setFolding( QsciScintilla::BoxedFoldStyle ); + //hide the line numbers + mHtmlEditor->setMarginWidth( 1, 0 ); + + connect( mHtmlEditor, SIGNAL( textChanged() ), this, SLOT( htmlEditorChanged() ) ); + htmlEditorLayout->addWidget( mHtmlEditor ); + blockSignals( true ); mResizeModeComboBox->addItem( tr( "Use existing frames" ), QgsComposerMultiFrame::UseExistingFrames ); mResizeModeComboBox->addItem( tr( "Extend to next page" ), QgsComposerMultiFrame::ExtendToNextPage ); @@ -62,7 +74,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block ) mResizeModeComboBox->blockSignals( block ); mUseSmartBreaksCheckBox->blockSignals( block ); mMaxDistanceSpinBox->blockSignals( block ); - mHtmlTextEdit->blockSignals( block ); + mHtmlEditor->blockSignals( block ); mRadioManualSource->blockSignals( block ); mRadioUrlSource->blockSignals( block ); } @@ -149,14 +161,14 @@ void QgsComposerHtmlWidget::on_mMaxDistanceSpinBox_valueChanged( double val ) mHtml->setMaxBreakDistance( val ); } -void QgsComposerHtmlWidget::on_mHtmlTextEdit_textChanged() +void QgsComposerHtmlWidget::htmlEditorChanged() { if ( !mHtml ) { return; } - mHtml->setHtml( mHtmlTextEdit->toPlainText() ); + mHtml->setHtml( mHtmlEditor->text() ); } void QgsComposerHtmlWidget::on_mRadioManualSource_clicked( bool checked ) @@ -167,7 +179,7 @@ void QgsComposerHtmlWidget::on_mRadioManualSource_clicked( bool checked ) } mHtml->setContentMode( checked ? QgsComposerHtml::ManualHtml : QgsComposerHtml::Url ); - mHtmlTextEdit->setEnabled( checked ); + mHtmlEditor->setEnabled( checked ); mUrlLineEdit->setEnabled( !checked ); mFileToolButton->setEnabled( !checked ); @@ -182,7 +194,7 @@ void QgsComposerHtmlWidget::on_mRadioUrlSource_clicked( bool checked ) } mHtml->setContentMode( checked ? QgsComposerHtml::Url : QgsComposerHtml::ManualHtml ); - mHtmlTextEdit->setEnabled( !checked ); + mHtmlEditor->setEnabled( !checked ); mUrlLineEdit->setEnabled( checked ); mFileToolButton->setEnabled( checked ); @@ -236,12 +248,12 @@ void QgsComposerHtmlWidget::setGuiElementValues() mMaxDistanceSpinBox->setValue( mHtml->maxBreakDistance() ); mAddFramePushButton->setEnabled( mHtml->resizeMode() == QgsComposerMultiFrame::UseExistingFrames ); - mHtmlTextEdit->setPlainText( mHtml->html() ); + mHtmlEditor->setText( mHtml->html() ); mRadioUrlSource->setChecked( mHtml->contentMode() == QgsComposerHtml::Url ); mUrlLineEdit->setEnabled( mHtml->contentMode() == QgsComposerHtml::Url ); mFileToolButton->setEnabled( mHtml->contentMode() == QgsComposerHtml::Url ); mRadioManualSource->setChecked( mHtml->contentMode() == QgsComposerHtml::ManualHtml ); - mHtmlTextEdit->setEnabled( mHtml->contentMode() == QgsComposerHtml::ManualHtml ); + mHtmlEditor->setEnabled( mHtml->contentMode() == QgsComposerHtml::ManualHtml ); blockSignals( false ); } diff --git a/src/app/composer/qgscomposerhtmlwidget.h b/src/app/composer/qgscomposerhtmlwidget.h index c0732486b10..5f812fafbee 100644 --- a/src/app/composer/qgscomposerhtmlwidget.h +++ b/src/app/composer/qgscomposerhtmlwidget.h @@ -20,6 +20,7 @@ class QgsComposerHtml; class QgsComposerFrame; +class QsciScintilla; class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsComposerHtmlWidgetBase { @@ -34,7 +35,7 @@ class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo void on_mResizeModeComboBox_currentIndexChanged( int index ); void on_mUseSmartBreaksCheckBox_toggled( bool checked ); void on_mMaxDistanceSpinBox_valueChanged( double val ); - void on_mHtmlTextEdit_textChanged(); + void htmlEditorChanged(); void on_mRadioManualSource_clicked( bool checked ); void on_mRadioUrlSource_clicked( bool checked ); @@ -50,6 +51,7 @@ class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo QgsComposerHtml* mHtml; QgsComposerFrame* mFrame; + QsciScintilla *mHtmlEditor; }; #endif // QGSCOMPOSERHTMLWIDGET_H diff --git a/src/core/composer/qgscomposerhtml.cpp b/src/core/composer/qgscomposerhtml.cpp index ee75e61ae53..4dbe78b87e5 100644 --- a/src/core/composer/qgscomposerhtml.cpp +++ b/src/core/composer/qgscomposerhtml.cpp @@ -391,7 +391,11 @@ bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument& QString urlString = itemElem.attribute( "url" ); if ( !urlString.isEmpty() ) { - setUrl( QUrl( urlString ) ); + mUrl = urlString; } + loadHtml(); + + //since frames had to be created before, we need to emit a changed signal to refresh the widget + emit changed(); return true; } diff --git a/src/ui/qgscomposerhtmlwidgetbase.ui b/src/ui/qgscomposerhtmlwidgetbase.ui index 9f081ea54ef..819972f7135 100644 --- a/src/ui/qgscomposerhtmlwidgetbase.ui +++ b/src/ui/qgscomposerhtmlwidgetbase.ui @@ -46,8 +46,8 @@ 0 0 - 391 - 519 + 407 + 360 @@ -62,15 +62,15 @@ false - - + + URL - + @@ -84,7 +84,7 @@ - + Source: @@ -92,15 +92,15 @@ - - - Refresh HTML + + +