Skip to content

Commit 5e4510f

Browse files
committed
[composer] Switch to using qscintilla for html editor in html item properties. Sponsored by City of Uster, Switzerland.
1 parent 3f90dbb commit 5e4510f

4 files changed

Lines changed: 36 additions & 18 deletions

File tree

src/app/composer/qgscomposerhtmlwidget.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@
2020
#include "qgscomposition.h"
2121
#include <QFileDialog>
2222
#include <QSettings>
23+
#include <Qsci/qsciscintilla.h>
24+
#include <Qsci/qscilexerhtml.h>
2325

2426
QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame ): QgsComposerItemBaseWidget( 0, html ), mHtml( html ), mFrame( frame )
2527
{
2628
setupUi( this );
2729

30+
//setup html editor
31+
mHtmlEditor = new QsciScintilla( this );
32+
mHtmlEditor->setLexer( new QsciLexerHTML );
33+
mHtmlEditor->setFolding( QsciScintilla::BoxedFoldStyle );
34+
//hide the line numbers
35+
mHtmlEditor->setMarginWidth( 1, 0 );
36+
37+
connect( mHtmlEditor, SIGNAL( textChanged() ), this, SLOT( htmlEditorChanged() ) );
38+
htmlEditorLayout->addWidget( mHtmlEditor );
39+
2840
blockSignals( true );
2941
mResizeModeComboBox->addItem( tr( "Use existing frames" ), QgsComposerMultiFrame::UseExistingFrames );
3042
mResizeModeComboBox->addItem( tr( "Extend to next page" ), QgsComposerMultiFrame::ExtendToNextPage );
@@ -62,7 +74,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block )
6274
mResizeModeComboBox->blockSignals( block );
6375
mUseSmartBreaksCheckBox->blockSignals( block );
6476
mMaxDistanceSpinBox->blockSignals( block );
65-
mHtmlTextEdit->blockSignals( block );
77+
mHtmlEditor->blockSignals( block );
6678
mRadioManualSource->blockSignals( block );
6779
mRadioUrlSource->blockSignals( block );
6880
}
@@ -149,14 +161,14 @@ void QgsComposerHtmlWidget::on_mMaxDistanceSpinBox_valueChanged( double val )
149161
mHtml->setMaxBreakDistance( val );
150162
}
151163

152-
void QgsComposerHtmlWidget::on_mHtmlTextEdit_textChanged()
164+
void QgsComposerHtmlWidget::htmlEditorChanged()
153165
{
154166
if ( !mHtml )
155167
{
156168
return;
157169
}
158170

159-
mHtml->setHtml( mHtmlTextEdit->toPlainText() );
171+
mHtml->setHtml( mHtmlEditor->text() );
160172
}
161173

162174
void QgsComposerHtmlWidget::on_mRadioManualSource_clicked( bool checked )
@@ -167,7 +179,7 @@ void QgsComposerHtmlWidget::on_mRadioManualSource_clicked( bool checked )
167179
}
168180

169181
mHtml->setContentMode( checked ? QgsComposerHtml::ManualHtml : QgsComposerHtml::Url );
170-
mHtmlTextEdit->setEnabled( checked );
182+
mHtmlEditor->setEnabled( checked );
171183
mUrlLineEdit->setEnabled( !checked );
172184
mFileToolButton->setEnabled( !checked );
173185

@@ -182,7 +194,7 @@ void QgsComposerHtmlWidget::on_mRadioUrlSource_clicked( bool checked )
182194
}
183195

184196
mHtml->setContentMode( checked ? QgsComposerHtml::Url : QgsComposerHtml::ManualHtml );
185-
mHtmlTextEdit->setEnabled( !checked );
197+
mHtmlEditor->setEnabled( !checked );
186198
mUrlLineEdit->setEnabled( checked );
187199
mFileToolButton->setEnabled( checked );
188200

@@ -236,12 +248,12 @@ void QgsComposerHtmlWidget::setGuiElementValues()
236248
mMaxDistanceSpinBox->setValue( mHtml->maxBreakDistance() );
237249

238250
mAddFramePushButton->setEnabled( mHtml->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
239-
mHtmlTextEdit->setPlainText( mHtml->html() );
251+
mHtmlEditor->setText( mHtml->html() );
240252

241253
mRadioUrlSource->setChecked( mHtml->contentMode() == QgsComposerHtml::Url );
242254
mUrlLineEdit->setEnabled( mHtml->contentMode() == QgsComposerHtml::Url );
243255
mFileToolButton->setEnabled( mHtml->contentMode() == QgsComposerHtml::Url );
244256
mRadioManualSource->setChecked( mHtml->contentMode() == QgsComposerHtml::ManualHtml );
245-
mHtmlTextEdit->setEnabled( mHtml->contentMode() == QgsComposerHtml::ManualHtml );
257+
mHtmlEditor->setEnabled( mHtml->contentMode() == QgsComposerHtml::ManualHtml );
246258
blockSignals( false );
247259
}

src/app/composer/qgscomposerhtmlwidget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
class QgsComposerHtml;
2222
class QgsComposerFrame;
23+
class QsciScintilla;
2324

2425
class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsComposerHtmlWidgetBase
2526
{
@@ -34,7 +35,7 @@ class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo
3435
void on_mResizeModeComboBox_currentIndexChanged( int index );
3536
void on_mUseSmartBreaksCheckBox_toggled( bool checked );
3637
void on_mMaxDistanceSpinBox_valueChanged( double val );
37-
void on_mHtmlTextEdit_textChanged();
38+
void htmlEditorChanged();
3839
void on_mRadioManualSource_clicked( bool checked );
3940
void on_mRadioUrlSource_clicked( bool checked );
4041

@@ -50,6 +51,7 @@ class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo
5051

5152
QgsComposerHtml* mHtml;
5253
QgsComposerFrame* mFrame;
54+
QsciScintilla *mHtmlEditor;
5355
};
5456

5557
#endif // QGSCOMPOSERHTMLWIDGET_H

src/core/composer/qgscomposerhtml.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument&
391391
QString urlString = itemElem.attribute( "url" );
392392
if ( !urlString.isEmpty() )
393393
{
394-
setUrl( QUrl( urlString ) );
394+
mUrl = urlString;
395395
}
396+
loadHtml();
397+
398+
//since frames had to be created before, we need to emit a changed signal to refresh the widget
399+
emit changed();
396400
return true;
397401
}

src/ui/qgscomposerhtmlwidgetbase.ui

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<rect>
4747
<x>0</x>
4848
<y>0</y>
49-
<width>391</width>
50-
<height>519</height>
49+
<width>407</width>
50+
<height>360</height>
5151
</rect>
5252
</property>
5353
<layout class="QVBoxLayout" name="mainLayout">
@@ -62,15 +62,15 @@
6262
<property name="collapsed" stdset="0">
6363
<bool>false</bool>
6464
</property>
65-
<layout class="QFormLayout" name="formLayout">
66-
<item row="1" column="0">
65+
<layout class="QGridLayout" name="gridLayout_2">
66+
<item row="0" column="0">
6767
<widget class="QRadioButton" name="mRadioUrlSource">
6868
<property name="text">
6969
<string>URL</string>
7070
</property>
7171
</widget>
7272
</item>
73-
<item row="1" column="1">
73+
<item row="0" column="1">
7474
<layout class="QHBoxLayout" name="horizontalLayout">
7575
<item>
7676
<widget class="QLineEdit" name="mUrlLineEdit"/>
@@ -84,23 +84,23 @@
8484
</item>
8585
</layout>
8686
</item>
87-
<item row="2" column="0" colspan="2">
87+
<item row="1" column="0" colspan="2">
8888
<widget class="QRadioButton" name="mRadioManualSource">
8989
<property name="text">
9090
<string>Source:</string>
9191
</property>
9292
</widget>
9393
</item>
9494
<item row="3" column="0" colspan="2">
95-
<widget class="QPlainTextEdit" name="mHtmlTextEdit"/>
96-
</item>
97-
<item row="4" column="0" colspan="2">
9895
<widget class="QPushButton" name="mReloadPushButton">
9996
<property name="text">
10097
<string>Refresh HTML</string>
10198
</property>
10299
</widget>
103100
</item>
101+
<item row="2" column="0" colspan="2">
102+
<layout class="QVBoxLayout" name="htmlEditorLayout"/>
103+
</item>
104104
</layout>
105105
</widget>
106106
</item>

0 commit comments

Comments
 (0)