• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

blogilo

  • sources
  • kde-4.14
  • kdepim
  • blogilo
  • src
  • composer
htmleditor.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Blogilo, A KDE Blogging Client
3 
4  Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
5  Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License or (at your option) version 3 or any later version
11  accepted by the membership of KDE e.V. (or its successor approved
12  by the membership of KDE e.V.), which shall act as a proxy
13  defined in Section 14 of version 3 of the license.
14 
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, see http://www.gnu.org/licenses/
23 */
24 
25 #include "htmleditor.h"
26 
27 
28 #include <kglobal.h>
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>
34 #include <kaction.h>
35 #include <klocalizedstring.h>
36 
37 
38 #include <QMenu>
39 
40 class HtmlEditorPrivate
41 {
42 public:
43  HtmlEditor instance;
44 };
45 
46 K_GLOBAL_STATIC( HtmlEditorPrivate, instancePrivate )
47 
48 HtmlEditor* HtmlEditor::self()
49 {
50  return &instancePrivate->instance;
51 }
52 
53 HtmlEditor::HtmlEditor() : QObject()
54 {
55  mEditor = KTextEditor::EditorChooser::editor();
56 }
57 
58 HtmlEditor::~HtmlEditor()
59 {
60  kDebug();
61  if ( !instancePrivate.isDestroyed() ) {
62  delete mEditor;
63  kDebug() << "editor deleted";
64  }
65 }
66 
67 KTextEditor::View* HtmlEditor::createView( QWidget* parent )
68 {
69  KTextEditor::Document *document = mEditor->createDocument( parent );
70  bool result = document->setHighlightingMode( QLatin1String("html") );
71  if ( result ) {
72  kDebug() << "Syntax highlighting enabled";
73  }
74  KTextEditor::View *view = document->createView( parent );
75  QMenu *menu = view->defaultContextMenu();
76 
77  KTextEditor::ConfigInterface *interface = qobject_cast< KTextEditor::ConfigInterface* >( view );
78 
79  if ( interface ) {
80  KAction *actWordWrap = new KAction( i18n( "Dynamic Word Wrap" ), view );
81  actWordWrap->setCheckable( true );
82  connect( actWordWrap, SIGNAL(triggered(bool)), this, SLOT(toggleWordWrap()) );
83 
84  KAction *actLineNumber = new KAction( i18n("Show line numbers"), view );
85  actLineNumber->setCheckable( true );
86  connect( actLineNumber, SIGNAL(triggered(bool)), this, SLOT(toggleLineNumber()) );
87 
88  QMenu *options = new QMenu( i18n( "Options" ), qobject_cast< QWidget* >( view ) );
89  options->addAction( actWordWrap );
90  options->addAction( actLineNumber );
91 
92  menu->addSeparator();
93  menu->addMenu( options );
94 
95  interface->setConfigValue( QLatin1String("dynamic-word-wrap"), true );
96  actWordWrap->setChecked( true );
97  }
98  view->setContextMenu( menu );
99  return view;
100 }
101 
102 QWidget* HtmlEditor::configPage( int number, QWidget* parent )
103 {
104  KTextEditor::ConfigPage *page = mEditor->configPage( number, parent );
105  if ( !page ) {
106  return NULL;
107  } else {
108  return page;
109  }
110 }
111 
112 void HtmlEditor::toggleWordWrap()
113 {
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 ) );
118 }
119 
120 void HtmlEditor::toggleLineNumber()
121 {
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 ) );
126 }
127 
QWidget
QObject::sender
QObject * sender() const
QAction::setChecked
void setChecked(bool)
QObject
HtmlEditor
Definition: htmleditor.h:42
htmleditor.h
QMenu::addSeparator
QAction * addSeparator()
HtmlEditor::configPage
QWidget * configPage(int number, QWidget *parent)
Definition: htmleditor.cpp:102
QMenu
HtmlEditor::createView
KTextEditor::View * createView(QWidget *parent)
Definition: htmleditor.cpp:67
QLatin1String
QMenu::addMenu
QAction * addMenu(QMenu *menu)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:16 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

blogilo

Skip menu "blogilo"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal