• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

How to use the KTextEditor Interfaces

Overview | Design | Coding Guidelines | Porting to KDE 4 | Using

This HOWTO will explain step by step how to load a KTextEditor component and plug a single View into a KMainWindow.

Tobics:

  • The Header File
  • The Mainwindow Implementation
  • Notes

The Header File

The following class only contains two pointers to a Document and its View.

#include <kxmlguiwindow.h>
namespace KTextEditor
{
class Document;
class View;
}
class MainWindow : public KXmlGuiWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
private:
KTextEditor::View *m_view;
KTextEditor::Document *m_document;
};
KTextEditor::Document
A KParts derived class representing a text document.
Definition: document.h:112
KTextEditor::View
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
KXmlGuiWindow
kxmlguiwindow.h
KTextEditor
Namespace for the KDE Text Editor Interfaces.
Definition: annotationinterface.h:31

The Mainwindow Implementation

The following source code queries for a Editor part by using the EditorChooser. If the returned Editor is invalid, we simply quit, otherwise we create a new document and a view and plug it into the mainwindow.

#include "mainwindow.h"
#include <ktexteditor/document.h>
#include <ktexteditor/view.h>
#include <ktexteditor/editor.h>
#include <ktexteditor/editorchooser.h>
#include <kxmlguifactory.h>
#include <kmessagebox.h>
MainWindow::MainWindow ()
: KXmlGuiWindow(),
m_view(0),
m_document(0)
{
KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();
if (!editor) {
KMessageBox::error(this, i18n("A KDE text-editor component could not be found;\n"
"please check your KDE installation."));
kapp->exit(1);
}
m_document = editor->createDocument(0);
m_view = m_document->createView(this);
setCentralWidget(m_view);
setXMLFile("mainwindowui.rc");
guiFactory()->addClient(m_view);
show ();
}
MainWindow::~MainWindow()
{
if (m_document) {
guiFactory()->removeClient(m_view);
// the document deletes its views itself
delete m_document;
}
}
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KTextEditor::Document::createView
virtual View * createView(QWidget *parent)=0
Create a new view attached to parent.
KTextEditor::EditorChooser::editor
static KTextEditor::Editor * editor(const QString &postfix=QString(), bool fallBackToKatePart=true)
Static accessor to get the Editor instance of the currently used KTextEditor component.
Definition: editorchooser.cpp:118
KTextEditor::Editor
Accessor interface for Editor part.
Definition: editor.h:103
KTextEditor::Editor::createDocument
virtual Document * createDocument(QObject *parent)=0
Create a new document object with parent.
document.h
editor.h
editorchooser.h
kapp
#define kapp
i18n
QString i18n(const char *text)
kmessagebox.h
kxmlguifactory.h
mainwindow.h
view.h

Notes

In order to compile link against the following libraries:

  • ktexteditor
  • kdeui
Author
Dominik Haumann <dhdev.nosp@m.@gmx.nosp@m..de>
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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