29 #include <ktexteditor/editor.h>
30 #include <ktexteditor/editorchooser.h>
31 #include <ktexteditor/view.h>
32 #include <ktexteditor/configpage.h>
33 #include <ktexteditor/configinterface.h>
35 #include <klocalizedstring.h>
40 class HtmlEditorPrivate
46 K_GLOBAL_STATIC( HtmlEditorPrivate, instancePrivate )
50 return &instancePrivate->instance;
53 HtmlEditor::HtmlEditor() :
QObject()
55 mEditor = KTextEditor::EditorChooser::editor();
58 HtmlEditor::~HtmlEditor()
61 if ( !instancePrivate.isDestroyed() ) {
63 kDebug() <<
"editor deleted";
69 KTextEditor::Document *document = mEditor->createDocument( parent );
70 bool result = document->setHighlightingMode(
QLatin1String(
"html") );
72 kDebug() <<
"Syntax highlighting enabled";
74 KTextEditor::View *view = document->createView( parent );
75 QMenu *menu = view->defaultContextMenu();
77 KTextEditor::ConfigInterface *
interface = qobject_cast< KTextEditor::ConfigInterface* >( view );
80 KAction *actWordWrap =
new KAction( i18n(
"Dynamic Word Wrap" ), view );
81 actWordWrap->setCheckable(
true );
82 connect( actWordWrap, SIGNAL(triggered(
bool)),
this, SLOT(toggleWordWrap()) );
84 KAction *actLineNumber =
new KAction( i18n(
"Show line numbers"), view );
85 actLineNumber->setCheckable(
true );
86 connect( actLineNumber, SIGNAL(triggered(
bool)),
this, SLOT(toggleLineNumber()) );
88 QMenu *options =
new QMenu( i18n(
"Options" ), qobject_cast< QWidget* >( view ) );
89 options->addAction( actWordWrap );
90 options->addAction( actLineNumber );
95 interface->setConfigValue(
QLatin1String(
"dynamic-word-wrap"),
true );
98 view->setContextMenu( menu );
104 KTextEditor::ConfigPage *page = mEditor->configPage( number, parent );
112 void HtmlEditor::toggleWordWrap()
114 KTextEditor::View *view = qobject_cast< KTextEditor::View* >(
sender()->
parent() );
115 KTextEditor::ConfigInterface *
interface = qobject_cast< KTextEditor::ConfigInterface* >( view );
116 const bool result = interface->configValue( QLatin1String("dynamic-word-wrap") ).toBool();
117 interface->setConfigValue( QLatin1String("dynamic-word-wrap"), !( result ) );
120 void HtmlEditor::toggleLineNumber()
122 KTextEditor::View *view = qobject_cast< KTextEditor::View* >(
sender()->
parent() );
123 KTextEditor::ConfigInterface *
interface = qobject_cast< KTextEditor::ConfigInterface* >( view );
124 const bool result = interface->configValue( QLatin1String("line-numbers") ).toBool();
125 interface->setConfigValue( QLatin1String("line-numbers"), !( result ) );
QWidget * configPage(int number, QWidget *parent)
KTextEditor::View * createView(QWidget *parent)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)