Skip to content
Permalink
Browse files
[composer] Switch to using qscintilla for html editor in html item pr…
…operties. Sponsored by City of Uster, Switzerland.
  • Loading branch information
nyalldawson committed Jul 16, 2014
1 parent 3f90dbb commit 5e4510f547f698c0f10beefee7c389c921d70b84
@@ -20,11 +20,23 @@
#include "qgscomposition.h"
#include <QFileDialog>
#include <QSettings>
#include <Qsci/qsciscintilla.h>
#include <Qsci/qscilexerhtml.h>

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 );
}
@@ -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
@@ -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;
}
@@ -46,8 +46,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>391</width>
<height>519</height>
<width>407</width>
<height>360</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@@ -62,15 +62,15 @@
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QRadioButton" name="mRadioUrlSource">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="mUrlLineEdit"/>
@@ -84,23 +84,23 @@
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="mRadioManualSource">
<property name="text">
<string>Source:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPlainTextEdit" name="mHtmlTextEdit"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="mReloadPushButton">
<property name="text">
<string>Refresh HTML</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<layout class="QVBoxLayout" name="htmlEditorLayout"/>
</item>
</layout>
</widget>
</item>

0 comments on commit 5e4510f

Please sign in to comment.