Advance Wayland and KDE package bring-up
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
add_executable(krichtexteditor)
|
||||
|
||||
target_sources(krichtexteditor PRIVATE
|
||||
main.cpp
|
||||
krichtexteditor.cpp
|
||||
)
|
||||
|
||||
target_include_directories(krichtexteditor PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
${CMAKE_CURRENT_BINARY_DIR}/..
|
||||
)
|
||||
ecm_mark_as_test(krichtexteditor)
|
||||
target_link_libraries(krichtexteditor Qt6::Test KF6::ConfigWidgets KF6::TextWidgets KF6::XmlGui)
|
||||
|
||||
#install(TARGETS krichtexteditor DESTINATION ${KDE_INSTALL_BINDIR})
|
||||
#install(FILES krichtexteditorui.rc DESTINATION ${KDE_INSTALL_KXMLGUIDIR}/krichtexteditor)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
KDE Rich Text Editor
|
||||
SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#include "krichtexteditor.h"
|
||||
|
||||
#include <KStandardActions>
|
||||
#include <kactioncollection.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QLabel>
|
||||
#include <QSaveFile>
|
||||
#include <QStatusBar>
|
||||
#include <QTest>
|
||||
#include <QTextStream>
|
||||
|
||||
KRichTextEditor::KRichTextEditor()
|
||||
: KXmlGuiWindow()
|
||||
{
|
||||
setupActions();
|
||||
|
||||
textArea = new KRichTextWidget(this);
|
||||
setCentralWidget(textArea);
|
||||
|
||||
actionCollection()->addActions(textArea->createActions());
|
||||
|
||||
setupGUI(KXmlGuiWindow::Default, QFINDTESTDATA("krichtexteditorui.rc"));
|
||||
|
||||
itemLabel = new QLabel;
|
||||
statusBar()->addWidget(itemLabel);
|
||||
|
||||
connect(textArea, &KRichTextWidget::cursorPositionChanged, this, &KRichTextEditor::cursorPositionChanged);
|
||||
}
|
||||
|
||||
KRichTextEditor::~KRichTextEditor()
|
||||
{
|
||||
}
|
||||
|
||||
void KRichTextEditor::setupActions()
|
||||
{
|
||||
KStandardActions::quit(qApp, &QCoreApplication::quit, actionCollection());
|
||||
|
||||
KStandardActions::open(this, &KRichTextEditor::openFile, actionCollection());
|
||||
|
||||
KStandardActions::save(this, &KRichTextEditor::saveFile, actionCollection());
|
||||
|
||||
KStandardActions::saveAs(this, qOverload<>(&KRichTextEditor::saveFileAs), actionCollection());
|
||||
|
||||
KStandardActions::openNew(this, &KRichTextEditor::newFile, actionCollection());
|
||||
}
|
||||
|
||||
void KRichTextEditor::cursorPositionChanged()
|
||||
{
|
||||
// Show link target in status bar
|
||||
if (textArea->textCursor().charFormat().isAnchor()) {
|
||||
QString text = textArea->currentLinkText();
|
||||
QString url = textArea->currentLinkUrl();
|
||||
itemLabel->setText(text + QStringLiteral(" -> ") + url);
|
||||
} else {
|
||||
itemLabel->setText(QString());
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextEditor::newFile()
|
||||
{
|
||||
// maybeSave
|
||||
fileName.clear();
|
||||
textArea->clear();
|
||||
}
|
||||
|
||||
void KRichTextEditor::saveFileAs(const QString &outputFileName)
|
||||
{
|
||||
QSaveFile file(outputFileName);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray outputByteArray;
|
||||
outputByteArray.append(textArea->toHtml().toUtf8());
|
||||
file.write(outputByteArray);
|
||||
if (!file.commit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fileName = outputFileName;
|
||||
}
|
||||
|
||||
void KRichTextEditor::saveFileAs()
|
||||
{
|
||||
saveFileAs(QFileDialog::getSaveFileName());
|
||||
}
|
||||
|
||||
void KRichTextEditor::saveFile()
|
||||
{
|
||||
if (!fileName.isEmpty()) {
|
||||
saveFileAs(fileName);
|
||||
} else {
|
||||
saveFileAs();
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextEditor::openFile()
|
||||
{
|
||||
QString fileNameFromDialog = QFileDialog::getOpenFileName();
|
||||
if (fileNameFromDialog.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(fileNameFromDialog);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
textArea->setTextOrHtml(QTextStream(&file).readAll());
|
||||
fileName = fileNameFromDialog;
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_krichtexteditor.cpp"
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
KDE Rich Text Editor
|
||||
SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#ifndef KRICHTEXTEDITOR_H
|
||||
#define KRICHTEXTEDITOR_H
|
||||
|
||||
#include <KRichTextWidget>
|
||||
|
||||
#include <kxmlguiwindow.h>
|
||||
|
||||
//@cond PRIVATE
|
||||
|
||||
class QLabel;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Test window for testing KRichTextWidget
|
||||
*/
|
||||
class KRichTextEditor : public KXmlGuiWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KRichTextEditor();
|
||||
~KRichTextEditor() override;
|
||||
|
||||
void setupActions();
|
||||
|
||||
private Q_SLOTS:
|
||||
void newFile();
|
||||
void openFile();
|
||||
void saveFile();
|
||||
void saveFileAs();
|
||||
void saveFileAs(const QString &outputFileName);
|
||||
void cursorPositionChanged();
|
||||
|
||||
private:
|
||||
KRichTextWidget *textArea;
|
||||
QString fileName;
|
||||
QLabel *itemLabel;
|
||||
};
|
||||
|
||||
//@endcond
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
|
||||
<gui name="krichtexteditor" version="14">
|
||||
|
||||
<MenuBar>
|
||||
<Menu noMerge="1" name="format"><text>F&ormat</text>
|
||||
<Action name="format_text_bold"/>
|
||||
<Action name="format_text_italic"/>
|
||||
<Action name="format_text_underline"/>
|
||||
<Action name="format_text_strikeout"/>
|
||||
<Action name="format_text_foreground_color"/>
|
||||
<Action name="format_text_background_color"/>
|
||||
<Action name="format_text_superscript"/>
|
||||
<Action name="format_text_subscript"/>
|
||||
<Separator/>
|
||||
<Action name="format_heading_level"/>
|
||||
<Separator/>
|
||||
<Menu name="alignment"><text>&Alignment</text>
|
||||
<Action name="format_align_left"/>
|
||||
<Action name="format_align_center"/>
|
||||
<Action name="format_align_right"/>
|
||||
<Action name="format_align_justify"/>
|
||||
</Menu>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_list_style"/>
|
||||
<Action name="format_list_indent_more"/>
|
||||
<Action name="format_list_indent_less"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="insert_horizontal_rule"/>
|
||||
<Action name="manage_link"/>
|
||||
<Action name="format_painter"/>
|
||||
</Menu>
|
||||
</MenuBar>
|
||||
|
||||
<ToolBar name="textToolBar" iconText="icononly"><text>Text Toolbar</text>
|
||||
<Action name="format_text_bold"/>
|
||||
<Action name="format_text_italic"/>
|
||||
<Action name="format_text_underline"/>
|
||||
<Action name="format_text_strikeout"/>
|
||||
<Action name="format_text_foreground_color"/>
|
||||
<Action name="format_text_background_color"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_font_family"/>
|
||||
<Action name="format_font_size"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_text_superscript"/>
|
||||
<Action name="format_text_subscript"/>
|
||||
</ToolBar>
|
||||
<ToolBar name="formatToolBar" iconText="icononly"><text>Format Toolbar</text>
|
||||
<Action name="format_heading_level"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_align_left"/>
|
||||
<Action name="format_align_center"/>
|
||||
<Action name="format_align_right"/>
|
||||
<Action name="format_align_justify"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="format_list_style"/>
|
||||
<Action name="format_list_indent_more"/>
|
||||
<Action name="format_list_indent_less"/>
|
||||
<Separator lineSeparator="true"/>
|
||||
<Action name="insert_horizontal_rule"/>
|
||||
<Action name="manage_link"/>
|
||||
<Action name="format_painter"/>
|
||||
<Action name="action_to_plain_text"/>
|
||||
</ToolBar>
|
||||
|
||||
</gui>
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
KDE Rich Text Editor
|
||||
SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#include "krichtexteditor.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication::setApplicationName(QStringLiteral("krichtexteditor"));
|
||||
QApplication app(argc, argv);
|
||||
KRichTextEditor *mw = new KRichTextEditor();
|
||||
mw->show();
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user