Several noob questions for 2 patchs
Safa Alfulaij
safa1996alfulaij at gmail.com
Sun Sep 3 13:32:23 UTC 2017
Hi again!
Since there are some feature requests about it, I tried to make it possible.
Forcing the lines to be RightToLeft/LeftToRight.
It's just rubbish hacks right now, but if it's a good start, I'll try to
improve it!
Diff attached and pasted <https://paste.kde.org/pck2ckit8/3vvwwd>!
Note: Lines 49-54 of the diff: Fixing an issue with trailing spaces (They
appear on the letter not to it's left). Doesn't have anything to do with
the direction. If someone can commit it, please do!
Regards,
Safa
2017-09-02 17:46 GMT+03:00 Safa Alfulaij <safa1996alfulaij at gmail.com>:
> Hello everyone,
> So finally I sat and decided to fix some RTL problems with Kate.
> I fixed one issue, and now I'm trying to add a context menu (Unicode
> special characters).
> I'm very new to KDE programming and I didn't code much in C++, so please
> bear with my noob questions :)
>
> I added duplicates of some actions in KTextEditor::ViewPrivate::defaultContextMenu
> to see if it works or not, but I didn't see the repeated actions in the
> context menu. How is the context menu made? Where is the function? When is
> defaultContextMenu used?
>
> Another question is for my “ready” patch: I added a KateViewConfig config
> value for altering the behavior of the backspace key. Is this config class
> the correct one to use? There are several ones used in KTextEditor.
>
> Regards,
> Safa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kwrite-devel/attachments/20170903/b7cb813a/attachment.html>
-------------- next part --------------
diff -U 3 -H -d -r -N -- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/data/katepart5ui.rc /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/data/katepart5ui.rc
--- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/data/katepart5ui.rc 2017-07-02 11:10:54.000000000 +0300
+++ /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/data/katepart5ui.rc 2017-09-03 14:50:23.950671832 +0300
@@ -87,6 +87,7 @@
<Separator group="view_operations" />
<Action name="view_non_printable_spaces" group="view_operations" />
<Action name="view_word_count" group="view_operations" />
+ <Action name="set_visual_text_direction" group="view_operations" />
</Menu>
<Action name="bookmarks" />
diff -U 3 -H -d -r -N -- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/render/katerenderer.cpp /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/render/katerenderer.cpp
--- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/render/katerenderer.cpp 2017-07-02 11:10:54.000000000 +0300
+++ /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/render/katerenderer.cpp 2017-09-03 15:02:30.723401233 +0300
@@ -40,6 +40,8 @@
#include <QRegularExpression>
#include <QtMath> // qCeil
+#include <QDebug>
+
static const QChar tabChar(QLatin1Char('\t'));
static const QChar spaceChar(QLatin1Char(' '));
static const QChar nbSpaceChar(0xa0); // non-breaking space
@@ -56,6 +58,7 @@
, m_showTabs(true)
, m_showSpaces(true)
, m_showNonPrintableSpaces(false)
+ , m_visualTextDirection(0)
, m_printerFriendly(false)
, m_config(new KateRendererConfig(this))
{
@@ -118,6 +121,12 @@
m_showNonPrintableSpaces = on;
}
+void KateRenderer::setVisualTextDirection(int visualTextDirection)
+{
+ m_visualTextDirection = visualTextDirection;
+ qDebug() << "S " << m_visualTextDirection;
+}
+
void KateRenderer::setTabWidth(int tabWidth)
{
m_tabWidth = tabWidth;
@@ -724,7 +733,11 @@
if (spaceIndex >= trailingPos) {
while (spaceIndex >= line.startCol() && text.at(spaceIndex).isSpace()) {
if (text.at(spaceIndex) != QLatin1Char('\t') || !showTabs()) {
- paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart + spaceWidth() / 2.0, y);
+ if (range->layout()->textOption().alignment() == Qt::AlignRight) { // Reverse for RTL lines
+ paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart - spaceWidth() / 2.0, y);
+ } else {
+ paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart + spaceWidth() / 2.0, y);
+ }
}
--spaceIndex;
}
@@ -981,12 +994,30 @@
// Qt's text renderer ("scribe") version 4.2 assumes a "higher-level protocol"
// (such as KatePart) will specify the paragraph level, so it does not apply P2 & P3
// by itself. If this ever change in Qt, the next code block could be removed.
- if (isLineRightToLeft(lineLayout)) {
- opt.setAlignment(Qt::AlignRight);
- opt.setTextDirection(Qt::RightToLeft);
- } else {
- opt.setAlignment(Qt::AlignLeft);
- opt.setTextDirection(Qt::LeftToRight);
+ qDebug() << "S2 " << m_visualTextDirection;
+ switch (m_visualTextDirection) {
+ case 0: {
+ qDebug() << "S3 " << "0";
+ if (isLineRightToLeft(lineLayout)) {
+ opt.setAlignment(Qt::AlignRight);
+ opt.setTextDirection(Qt::RightToLeft);
+ } else {
+ opt.setAlignment(Qt::AlignLeft);
+ opt.setTextDirection(Qt::LeftToRight);
+ }
+ break;
+ }
+ case 1: {
+ qDebug() << "S3 " << "1";
+ opt.setAlignment(Qt::AlignRight);
+ opt.setTextDirection(Qt::RightToLeft);
+ break;
+ }
+ default: {
+ qDebug() << "S3 " << "2";
+ opt.setAlignment(Qt::AlignLeft);
+ opt.setTextDirection(Qt::LeftToRight);
+ }
}
l->setTextOption(opt);
diff -U 3 -H -d -r -N -- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/render/katerenderer.h /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/render/katerenderer.h
--- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/render/katerenderer.h 2017-07-02 11:10:54.000000000 +0300
+++ /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/render/katerenderer.h 2017-09-03 14:38:18.954599473 +0300
@@ -195,6 +195,11 @@
void setShowNonPrintableSpaces(const bool showNonPrintableSpaces);
/**
+ * Set the visual text direction of the document
+ */
+ void setVisualTextDirection(int visualTextDirection);
+
+ /**
* Sets the width of the tab. Helps performance.
* @param tabWidth new tab width
*/
@@ -406,6 +411,7 @@
bool m_showNonPrintableSpaces;
bool m_printerFriendly;
QColor m_caretOverrideColor;
+ int m_visualTextDirection;
QList<KTextEditor::Attribute::Ptr> m_attributes;
diff -U 3 -H -d -r -N -- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/view/kateview.cpp /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/view/kateview.cpp
--- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/view/kateview.cpp 2017-07-02 11:10:54.000000000 +0300
+++ /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/view/kateview.cpp 2017-09-03 15:19:42.094480482 +0300
@@ -786,6 +786,17 @@
m_setEndOfLine->setCurrentItem(m_doc->config()->eol());
connect(m_setEndOfLine, SIGNAL(triggered(int)), this, SLOT(setEol(int)));
+ a = m_visualTextDirection = new KSelectAction(i18n("&Text Direction"), this);
+ ac->addAction(QStringLiteral("set_visual_text_direction"), a);
+ a->setWhatsThis(i18n("Choose the visual text direction of this document"));
+ QStringList list3;
+ list3.append(i18nc("@item:inmenu Text Direction", "&Auto"));
+ list3.append(i18nc("@item:inmenu Text Direction", "&Right To Left"));
+ list3.append(i18nc("@item:inmenu Text Direction", "&Left To Right"));
+ m_visualTextDirection->setItems(list3);
+ m_visualTextDirection->setCurrentItem(0);
+ connect(m_visualTextDirection, SIGNAL(triggered(int)), this, SLOT(setVisualTextDirection(int)));
+
a = m_addBom = new KToggleAction(i18n("Add &Byte Order Mark (BOM)"), this);
m_addBom->setChecked(m_doc->config()->bom());
ac->addAction(QStringLiteral("add_bom"), a);
@@ -1561,6 +1572,13 @@
}
}
+void KTextEditor::ViewPrivate::setVisualTextDirection(int visualTextDirection)
+{
+ m_renderer->setVisualTextDirection(visualTextDirection);
+ m_viewInternal->cache()->relayoutLines(0, m_doc->lines());
+ m_viewInternal->update(); // force redraw
+}
+
void KTextEditor::ViewPrivate::setAddBom(bool enabled)
{
if (!doc()->isReadWrite()) {
diff -U 3 -H -d -r -N -- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/view/kateview.h /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/view/kateview.h
--- /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/original/src/view/kateview.h 2017-07-02 11:10:54.000000000 +0300
+++ /home/safa/Desktop/ktexteditorfixes/packages-fdf950424a339adfff847d4a39045b6d4ba1bf11/trunk/src/ktexteditor-5.36.0/src/view/kateview.h 2017-09-03 14:23:54.875947255 +0300
@@ -510,6 +510,7 @@
void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) Q_DECL_OVERRIDE;
public Q_SLOTS:
+ void setVisualTextDirection(int visualTextDirection);
void setEol(int eol);
void setAddBom(bool enabled);
void find();
@@ -643,6 +644,7 @@
KSelectAction *m_setEndOfLine;
KToggleAction *m_addBom;
+ KSelectAction *m_visualTextDirection;
QAction *m_cut;
QAction *m_copy;
More information about the KWrite-Devel
mailing list