Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KNotes
Commits
ca089d32
Commit
ca089d32
authored
Nov 08, 2022
by
Laurent Montel
Browse files
Move class here (used only here)
parent
ee1098db
Pipeline
#264166
passed with stage
in 1 minute and 29 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
noteshared/src/CMakeLists.txt
View file @
ca089d32
...
...
@@ -45,6 +45,9 @@ set(libnoteshared_SRCS
dialog/selectednotefolderdialog.h
widget/notelistwidget.h
alarms/notealarmdialog.h
widget/richtexteditwithautocorrection.cpp
widget/richtexteditwithautocorrection.h
)
ecm_qt_declare_logging_category
(
libnoteshared_SRCS HEADER noteshared_debug.h IDENTIFIER NOTESHARED_LOG CATEGORY_NAME org.kde.pim.noteshared
...
...
noteshared/src/editor/noteeditor.cpp
View file @
ca089d32
...
...
@@ -4,12 +4,12 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include
"noteeditor.h"
#include
<PimCommonAutoCorrection/R
ich
T
extedit
W
ith
A
uto
C
orrection
>
#include
"widget/r
ich
t
extedit
w
ith
a
uto
c
orrection
.h"
using
namespace
NoteShared
;
NoteEditor
::
NoteEditor
(
QWidget
*
parent
)
:
KPIMTextEdit
::
RichTextEditorWidget
(
new
PimCommonAutoCorrection
::
RichTextEditWithAutoCorrection
(
parent
))
:
KPIMTextEdit
::
RichTextEditorWidget
(
new
NoteShared
::
RichTextEditWithAutoCorrection
(
parent
))
{
}
...
...
noteshared/src/widget/richtexteditwithautocorrection.cpp
0 → 100644
View file @
ca089d32
/*
SPDX-FileCopyrightText: 2013-2022 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include
"richtexteditwithautocorrection.h"
#include
<PimCommonAutoCorrection/AutoCorrection>
#include
<QKeyEvent>
using
namespace
NoteShared
;
class
NoteShared
::
RichTextEditWithAutoCorrectionPrivate
{
public:
RichTextEditWithAutoCorrectionPrivate
()
:
mAutoCorrection
(
new
PimCommonAutoCorrection
::
AutoCorrection
())
{
}
~
RichTextEditWithAutoCorrectionPrivate
()
{
if
(
mNeedToDelete
)
{
delete
mAutoCorrection
;
}
}
PimCommonAutoCorrection
::
AutoCorrection
*
mAutoCorrection
=
nullptr
;
bool
mNeedToDelete
=
true
;
};
RichTextEditWithAutoCorrection
::
RichTextEditWithAutoCorrection
(
QWidget
*
parent
)
:
KPIMTextEdit
::
RichTextEditor
(
parent
)
,
d
(
new
NoteShared
::
RichTextEditWithAutoCorrectionPrivate
)
{
}
RichTextEditWithAutoCorrection
::~
RichTextEditWithAutoCorrection
()
=
default
;
void
RichTextEditWithAutoCorrection
::
setAutocorrection
(
PimCommonAutoCorrection
::
AutoCorrection
*
autocorrect
)
{
d
->
mNeedToDelete
=
false
;
delete
d
->
mAutoCorrection
;
d
->
mAutoCorrection
=
autocorrect
;
}
PimCommonAutoCorrection
::
AutoCorrection
*
RichTextEditWithAutoCorrection
::
autocorrection
()
const
{
return
d
->
mAutoCorrection
;
}
void
RichTextEditWithAutoCorrection
::
setAutocorrectionLanguage
(
const
QString
&
language
)
{
PimCommonAutoCorrection
::
AutoCorrectionSettings
*
settings
=
d
->
mAutoCorrection
->
autoCorrectionSettings
();
settings
->
setLanguage
(
language
);
d
->
mAutoCorrection
->
setAutoCorrectionSettings
(
settings
);
}
static
bool
isSpecial
(
const
QTextCharFormat
&
charFormat
)
{
return
charFormat
.
isFrameFormat
()
||
charFormat
.
isImageFormat
()
||
charFormat
.
isListFormat
()
||
charFormat
.
isTableFormat
()
||
charFormat
.
isTableCellFormat
();
}
void
RichTextEditWithAutoCorrection
::
keyPressEvent
(
QKeyEvent
*
e
)
{
if
(
d
->
mAutoCorrection
&&
d
->
mAutoCorrection
->
autoCorrectionSettings
()
->
isEnabledAutoCorrection
())
{
if
((
e
->
key
()
==
Qt
::
Key_Space
)
||
(
e
->
key
()
==
Qt
::
Key_Enter
)
||
(
e
->
key
()
==
Qt
::
Key_Return
))
{
if
(
!
textCursor
().
hasSelection
())
{
const
QTextCharFormat
initialTextFormat
=
textCursor
().
charFormat
();
const
bool
richText
=
acceptRichText
();
int
position
=
textCursor
().
position
();
const
bool
addSpace
=
d
->
mAutoCorrection
->
autocorrect
(
richText
,
*
document
(),
position
);
QTextCursor
cur
=
textCursor
();
cur
.
setPosition
(
position
);
const
bool
spacePressed
=
(
e
->
key
()
==
Qt
::
Key_Space
);
const
QChar
insertChar
=
spacePressed
?
QLatin1Char
(
' '
)
:
QLatin1Char
(
'\n'
);
if
(
richText
&&
!
isSpecial
(
initialTextFormat
))
{
if
(
addSpace
||
!
spacePressed
)
{
cur
.
insertText
(
insertChar
,
initialTextFormat
);
}
}
else
{
if
(
addSpace
||
!
spacePressed
)
{
cur
.
insertText
(
insertChar
);
}
}
setTextCursor
(
cur
);
return
;
}
}
}
KPIMTextEdit
::
RichTextEditor
::
keyPressEvent
(
e
);
}
noteshared/src/widget/richtexteditwithautocorrection.h
0 → 100644
View file @
ca089d32
/*
SPDX-FileCopyrightText: 2013-2022 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include
<KPIMTextEdit/RichTextEditor>
namespace
PimCommonAutoCorrection
{
class
AutoCorrection
;
}
namespace
NoteShared
{
class
AutoCorrection
;
class
RichTextEditWithAutoCorrectionPrivate
;
/**
* @brief The RichTextEditWithAutoCorrection class
* @author Laurent Montel <montel@kde.org>
*/
class
RichTextEditWithAutoCorrection
:
public
KPIMTextEdit
::
RichTextEditor
{
Q_OBJECT
public:
explicit
RichTextEditWithAutoCorrection
(
QWidget
*
parent
=
nullptr
);
~
RichTextEditWithAutoCorrection
()
override
;
Q_REQUIRED_RESULT
PimCommonAutoCorrection
::
AutoCorrection
*
autocorrection
()
const
;
void
setAutocorrection
(
PimCommonAutoCorrection
::
AutoCorrection
*
autocorrect
);
void
setAutocorrectionLanguage
(
const
QString
&
language
);
protected:
void
keyPressEvent
(
QKeyEvent
*
e
)
override
;
private:
std
::
unique_ptr
<
RichTextEditWithAutoCorrectionPrivate
>
const
d
;
};
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment