Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
KolourPaint
Commits
80944bc6
Commit
80944bc6
authored
Jan 03, 2021
by
Martin Koller
Browse files
QLinkedList -> QList; port away from deprecated api; simplify code
parent
e3aab1b8
Changes
27
Hide whitespace changes
Inline
Side-by-side
commands/kpCommandHistoryBase.cpp
View file @
80944bc6
...
...
@@ -53,26 +53,16 @@
//---------------------------------------------------------------------
//template <typename T>
static
void
ClearPointerList
(
QLinkedList
<
kpCommand
*>
*
listPtr
)
static
void
ClearPointerList
(
QList
<
kpCommand
*>
&
list
)
{
if
(
!
listPtr
)
return
;
qDeleteAll
(
listPtr
->
begin
(),
listPtr
->
end
());
listPtr
->
clear
();
qDeleteAll
(
list
);
list
.
clear
();
}
struct
kpCommandHistoryBasePrivate
{
};
//--------------------------------------------------------------------------------
kpCommandHistoryBase
::
kpCommandHistoryBase
(
bool
doReadConfig
,
KActionCollection
*
ac
)
:
d
(
new
kpCommandHistoryBasePrivate
())
{
m_actionUndo
=
new
KToolBarPopupAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"edit-undo"
)),
undoActionText
(),
this
);
ac
->
addAction
(
KStandardAction
::
name
(
KStandardAction
::
Undo
),
m_actionUndo
);
...
...
@@ -109,14 +99,15 @@ kpCommandHistoryBase::kpCommandHistoryBase (bool doReadConfig,
}
}
//--------------------------------------------------------------------------------
kpCommandHistoryBase
::~
kpCommandHistoryBase
()
{
::
ClearPointerList
(
&
m_undoCommandList
);
::
ClearPointerList
(
&
m_redoCommandList
);
delete
d
;
::
ClearPointerList
(
m_undoCommandList
);
::
ClearPointerList
(
m_redoCommandList
);
}
//--------------------------------------------------------------------------------
// public
int
kpCommandHistoryBase
::
undoLimit
()
const
...
...
@@ -270,7 +261,7 @@ void kpCommandHistoryBase::addCommand (kpCommand *command, bool execute)
}
m_undoCommandList
.
push_front
(
command
);
::
ClearPointerList
(
&
m_redoCommandList
);
::
ClearPointerList
(
m_redoCommandList
);
#if DEBUG_KP_COMMAND_HISTORY
qCDebug
(
kpLogCommands
)
<<
"
\t
documentRestoredPosition="
<<
m_documentRestoredPosition
;
...
...
@@ -298,8 +289,8 @@ void kpCommandHistoryBase::clear ()
qCDebug
(
kpLogCommands
)
<<
"kpCommandHistoryBase::clear()"
;
#endif
::
ClearPointerList
(
&
m_undoCommandList
);
::
ClearPointerList
(
&
m_redoCommandList
);
::
ClearPointerList
(
m_undoCommandList
);
::
ClearPointerList
(
m_redoCommandList
);
m_documentRestoredPosition
=
0
;
...
...
@@ -483,28 +474,21 @@ void kpCommandHistoryBase::trimCommandListsUpdateActions ()
updateActions
();
}
//--------------------------------------------------------------------------------
// protected
void
kpCommandHistoryBase
::
trimCommandList
(
QLi
nkedLi
st
<
kpCommand
*>
*
commandList
)
void
kpCommandHistoryBase
::
trimCommandList
(
QList
<
kpCommand
*>
&
commandList
)
{
#if DEBUG_KP_COMMAND_HISTORY
qCDebug
(
kpLogCommands
)
<<
"kpCommandHistoryBase::trimCommandList()"
;
QTime
timer
;
timer
.
start
();
#endif
if
(
!
commandList
)
{
qCCritical
(
kpLogCommands
)
<<
"kpCommandHistoryBase::trimCommandList() passed 0 commandList"
;
return
;
}
#if DEBUG_KP_COMMAND_HISTORY
qCDebug
(
kpLogCommands
)
<<
"
\t
size="
<<
commandList
->
size
()
qCDebug
(
kpLogCommands
)
<<
"
\t
size="
<<
commandList
.
size
()
<<
" undoMinLimit="
<<
m_undoMinLimit
<<
" undoMaxLimit="
<<
m_undoMaxLimit
<<
" undoMaxLimitSizeLimit="
<<
m_undoMaxLimitSizeLimit
;
#endif
if
(
static_cast
<
int
>
(
commandList
->
size
()
)
<=
m_undoMinLimit
)
if
(
commandList
.
size
(
)
<=
m_undoMinLimit
)
{
#if DEBUG_KP_COMMAND_HISTORY
qCDebug
(
kpLogCommands
)
<<
"
\t\t
size under undoMinLimit - done"
;
...
...
@@ -517,12 +501,12 @@ void kpCommandHistoryBase::trimCommandList (QLinkedList <kpCommand *> *commandLi
qCDebug
(
kpLogCommands
)
<<
"
\t
size over undoMinLimit - iterating thru cmds:"
;
#endif
QLi
nkedLi
st
<
kpCommand
*>::
iterator
it
=
commandList
->
begin
();
QList
<
kpCommand
*>::
iterator
it
=
commandList
.
begin
();
int
upto
=
0
;
kpCommandSize
::
SizeType
sizeSoFar
=
0
;
while
(
it
!=
commandList
->
end
())
while
(
it
!=
commandList
.
end
())
{
bool
advanceIt
=
true
;
...
...
@@ -563,6 +547,8 @@ void kpCommandHistoryBase::trimCommandList (QLinkedList <kpCommand *> *commandLi
#endif
}
//--------------------------------------------------------------------------------
// protected
void
kpCommandHistoryBase
::
trimCommandLists
()
{
...
...
@@ -570,8 +556,8 @@ void kpCommandHistoryBase::trimCommandLists ()
qCDebug
(
kpLogCommands
)
<<
"kpCommandHistoryBase::trimCommandLists()"
;
#endif
trimCommandList
(
&
m_undoCommandList
);
trimCommandList
(
&
m_redoCommandList
);
trimCommandList
(
m_undoCommandList
);
trimCommandList
(
m_redoCommandList
);
#if DEBUG_KP_COMMAND_HISTORY
qCDebug
(
kpLogCommands
)
<<
"
\t
documentRestoredPosition="
<<
m_documentRestoredPosition
...
...
@@ -596,7 +582,7 @@ void kpCommandHistoryBase::trimCommandLists ()
static
void
populatePopupMenu
(
QMenu
*
popupMenu
,
const
QString
&
undoOrRedo
,
const
QLi
nkedLi
st
<
kpCommand
*>
&
commandList
)
const
QList
<
kpCommand
*>
&
commandList
)
{
if
(
!
popupMenu
)
{
return
;
...
...
@@ -604,7 +590,7 @@ static void populatePopupMenu (QMenu *popupMenu,
popupMenu
->
clear
();
QLi
nkedLi
st
<
kpCommand
*>::
const_iterator
it
=
commandList
.
begin
();
QList
<
kpCommand
*>::
const_iterator
it
=
commandList
.
begin
();
int
i
=
0
;
while
(
i
<
10
&&
it
!=
commandList
.
end
())
{
...
...
commands/kpCommandHistoryBase.h
View file @
80944bc6
...
...
@@ -32,7 +32,7 @@
#include <QObject>
#include <QString>
#include <QLi
nkedLi
st>
#include <QList>
#include "commands/kpCommandSize.h"
...
...
@@ -106,7 +106,7 @@ protected:
QString
redoActionToolTip
()
const
;
void
trimCommandListsUpdateActions
();
void
trimCommandList
(
QLi
nkedLi
st
<
kpCommand
*>
*
commandList
);
void
trimCommandList
(
QList
<
kpCommand
*>
&
commandList
);
void
trimCommandLists
();
void
updateActions
();
...
...
@@ -126,8 +126,8 @@ protected:
KToolBarPopupAction
*
m_actionUndo
,
*
m_actionRedo
;
// (Front element is the next one)
QLi
nkedLi
st
<
kpCommand
*>
m_undoCommandList
;
QLi
nkedLi
st
<
kpCommand
*>
m_redoCommandList
;
QList
<
kpCommand
*>
m_undoCommandList
;
QList
<
kpCommand
*>
m_redoCommandList
;
int
m_undoMinLimit
,
m_undoMaxLimit
;
kpCommandSize
::
SizeType
m_undoMaxLimitSizeLimit
;
...
...
@@ -140,9 +140,6 @@ protected:
//
// ASSUMPTION: will never have INT_MAX commands in any list.
int
m_documentRestoredPosition
;
private:
struct
kpCommandHistoryBasePrivate
*
const
d
;
};
...
...
commands/kpMacroCommand.cpp
View file @
80944bc6
...
...
@@ -38,14 +38,8 @@
//---------------------------------------------------------------------
struct
kpMacroCommandPrivate
{
};
kpMacroCommand
::
kpMacroCommand
(
const
QString
&
name
,
kpCommandEnvironment
*
environ
)
:
kpNamedCommand
(
name
,
environ
),
d
(
new
kpMacroCommandPrivate
())
:
kpNamedCommand
(
name
,
environ
)
{
}
...
...
@@ -53,8 +47,7 @@ kpMacroCommand::kpMacroCommand (const QString &name, kpCommandEnvironment *envir
kpMacroCommand
::~
kpMacroCommand
()
{
qDeleteAll
(
m_commandList
.
begin
(),
m_commandList
.
end
());
delete
d
;
qDeleteAll
(
m_commandList
);
}
//---------------------------------------------------------------------
...
...
@@ -96,14 +89,12 @@ void kpMacroCommand::execute ()
viewManager
()
->
setQueueUpdates
();
for
(
QLinkedList
<
kpCommand
*>::
const_iterator
it
=
m_commandList
.
begin
();
it
!=
m_commandList
.
end
();
++
it
)
foreach
(
kpCommand
*
command
,
m_commandList
)
{
#if DEBUG_KP_COMMAND_HISTORY
qCDebug
(
kpLogCommands
)
<<
"
\t
executing "
<<
(
*
it
)
->
name
();
qCDebug
(
kpLogCommands
)
<<
"
\t
executing "
<<
command
->
name
();
#endif
(
*
it
)
->
execute
();
command
->
execute
();
}
viewManager
()
->
restoreQueueUpdates
();
...
...
@@ -120,17 +111,12 @@ void kpMacroCommand::unexecute ()
viewManager
()
->
setQueueUpdates
();
QLinkedList
<
kpCommand
*>::
const_iterator
it
=
m_commandList
.
end
();
it
--
;
while
(
it
!=
m_commandList
.
end
())
for
(
int
i
=
m_commandList
.
count
()
-
1
;
i
>=
0
;
i
--
)
{
#if DEBUG_KP_COMMAND_HISTORY
qCDebug
(
kpLogCommands
)
<<
"
\t
unexecuting "
<<
(
*
it
)
->
name
();
qCDebug
(
kpLogCommands
)
<<
"
\t
unexecuting "
<<
m_commandList
[
i
]
->
name
();
#endif
(
*
it
)
->
unexecute
();
it
--
;
m_commandList
[
i
]
->
unexecute
();
}
viewManager
()
->
restoreQueueUpdates
();
...
...
@@ -139,9 +125,9 @@ void kpMacroCommand::unexecute ()
//---------------------------------------------------------------------
// public
void
kpMacroCommand
::
addCommand
(
kpCommand
*
command
)
void
kpMacroCommand
::
addCommand
(
kpCommand
*
command
)
{
m_commandList
.
push_back
(
command
);
m_commandList
.
append
(
command
);
}
//---------------------------------------------------------------------
commands/kpMacroCommand.h
View file @
80944bc6
...
...
@@ -32,7 +32,7 @@
#include "commands/kpNamedCommand.h"
#include <QLi
nkedLi
st>
#include <QList>
class
kpMacroCommand
:
public
kpNamedCommand
...
...
@@ -59,10 +59,7 @@ public:
void
addCommand
(
kpCommand
*
command
);
protected:
QLinkedList
<
kpCommand
*>
m_commandList
;
private:
struct
kpMacroCommandPrivate
*
const
d
;
QList
<
kpCommand
*>
m_commandList
;
};
...
...
document/kpDocument.cpp
View file @
80944bc6
...
...
@@ -157,7 +157,7 @@ bool kpDocument::urlExists (const QUrl &url) const
if
(
url
.
isEmpty
())
{
return
false
;
}
KIO
::
StatJob
*
job
=
KIO
::
stat
(
url
,
KIO
::
StatJob
::
SourceSide
,
0
);
KIO
::
StatJob
*
job
=
KIO
::
stat
Details
(
url
,
KIO
::
StatJob
::
SourceSide
,
KIO
::
StatNoDetails
);
KJobWidgets
::
setWindow
(
job
,
d
->
environ
->
dialogParent
());
return
job
->
exec
();
}
...
...
document/kpDocument_Save.cpp
View file @
80944bc6
...
...
@@ -239,14 +239,8 @@ bool kpDocument::savePixmapToDevice (const QImage &image,
imageToSave
.
setDotsPerMeterY
(
metaInfo
.
dotsPerMeterY
());
imageToSave
.
setOffset
(
metaInfo
.
offset
());
QList
<
QString
>
keyList
=
metaInfo
.
textKeys
();
for
(
QList
<
QString
>::
const_iterator
it
=
keyList
.
constBegin
();
it
!=
keyList
.
constEnd
();
++
it
)
{
imageToSave
.
setText
(
*
it
,
metaInfo
.
text
(
*
it
));
}
foreach
(
const
QString
&
key
,
metaInfo
.
textKeys
())
imageToSave
.
setText
(
key
,
metaInfo
.
text
(
key
));
//
// Save at required quality
...
...
@@ -254,9 +248,8 @@ bool kpDocument::savePixmapToDevice (const QImage &image,
int
quality
=
-
1
;
// default
if
(
useSaveOptionsQuality
)
{
quality
=
saveOptions
.
quality
();
}
if
(
useSaveOptionsQuality
)
quality
=
saveOptions
.
quality
();
#if DEBUG_KP_DOCUMENT
qCDebug
(
kpLogDocument
)
<<
"
\t
saving"
;
...
...
imagelib/kpDocumentMetaInfo.cpp
View file @
80944bc6
...
...
@@ -144,14 +144,8 @@ void kpDocumentMetaInfo::printDebug (const QString &prefix) const
<<
" Y="
<<
dotsPerMeterY
()
<<
" offset="
<<
offset
();
QList
<
QString
>
keyList
=
textKeys
();
for
(
QList
<
QString
>::
const_iterator
it
=
keyList
.
constBegin
();
it
!=
keyList
.
constEnd
();
++
it
)
{
qCDebug
(
kpLogImagelib
)
<<
"key="
<<
(
*
it
)
<<
" text="
<<
text
(
*
it
);
}
foreach
(
const
QString
&
key
,
textKeys
())
qCDebug
(
kpLogImagelib
)
<<
"key="
<<
key
<<
" text="
<<
text
(
key
);
qCDebug
(
kpLogImagelib
)
<<
usedPrefix
<<
"ENDS"
;
}
...
...
imagelib/kpFloodFill.cpp
View file @
80944bc6
...
...
@@ -33,7 +33,6 @@
#include <QApplication>
#include <QImage>
#include <QLinkedList>
#include <QList>
#include <QPainter>
...
...
@@ -64,7 +63,7 @@ public:
//---------------------------------------------------------------------
static
kpCommandSize
::
SizeType
FillLinesListSize
(
const
QLi
nkedLi
st
<
kpFillLine
>
&
fillLines
)
static
kpCommandSize
::
SizeType
FillLinesListSize
(
const
QList
<
kpFillLine
>
&
fillLines
)
{
return
(
fillLines
.
size
()
*
kpFillLine
::
size
());
}
...
...
@@ -77,10 +76,10 @@ struct kpFloodFillPrivate
// Copy of whatever was passed to the constructor.
//
kpImage
*
imagePtr
{}
;
int
x
{},
y
{}
;
kpImage
*
imagePtr
=
nullptr
;
int
x
=
0
,
y
=
0
;
kpColor
color
;
int
processedColorSimilarity
{}
;
int
processedColorSimilarity
=
0
;
//
...
...
@@ -94,12 +93,12 @@ struct kpFloodFillPrivate
// Set by Step 2.
//
QLi
nkedLi
st
<
kpFillLine
>
fillLines
;
QList
<
QLi
nkedLi
st
<
kpFillLine
>
>
fillLinesCache
;
QList
<
kpFillLine
>
fillLines
;
QList
<
QList
<
kpFillLine
>
>
fillLinesCache
;
QRect
boundingRect
;
bool
prepared
{}
;
bool
prepared
=
false
;
};
//---------------------------------------------------------------------
...
...
@@ -341,7 +340,7 @@ void kpFloodFill::prepare ()
// ready cache
for
(
int
i
=
0
;
i
<
d
->
imagePtr
->
height
();
i
++
)
{
d
->
fillLinesCache
.
append
(
QLi
nkedLi
st
<
kpFillLine
>
());
d
->
fillLinesCache
.
append
(
QList
<
kpFillLine
>
());
}
#if DEBUG_KP_FLOOD_FILL && 1
...
...
@@ -351,28 +350,23 @@ void kpFloodFill::prepare ()
// draw initial line
addLine
(
d
->
y
,
findMinX
(
d
->
y
,
d
->
x
),
findMaxX
(
d
->
y
,
d
->
x
));
for
(
QLinkedList
<
kpFillLine
>::
ConstIterator
it
=
d
->
fillLines
.
begin
();
it
!=
d
->
fillLines
.
end
();
++
it
)
for
(
int
i
=
0
;
i
<
d
->
fillLines
.
count
();
i
++
)
{
kpFillLine
&
fl
=
d
->
fillLines
[
i
];
#if DEBUG_KP_FLOOD_FILL && 0
qCDebug
(
kpLogImagelib
)
<<
"Expanding from y="
<<
(
*
it
)
.
m_y
<<
" x1="
<<
(
*
it
)
.
m_x1
<<
" x2="
<<
(
*
it
)
.
m_x2
qCDebug
(
kpLogImagelib
)
<<
"Expanding from y="
<<
fl
.
m_y
<<
" x1="
<<
fl
.
m_x1
<<
" x2="
<<
fl
.
m_x2
<<
endl
;
#endif
//
// Make more lines above and below current line.
//
// WARNING: Adds to end of "fillLines" (the linked list we are iterating
// through). Therefore, "fillLines" must remain a linked list
// - you cannot change it into a vector. Also, do not use
// "foreach" for this loop as that makes a copy of the linked
// list at the start and won't see new lines.
//
findAndAddLines
(
*
it
,
-
1
);
findAndAddLines
(
*
it
,
+
1
);
// WARNING: Adds to end of "fillLines" (the list we are iterating through).
findAndAddLines
(
fl
,
-
1
);
findAndAddLines
(
fl
,
+
1
);
}
#if DEBUG_KP_FLOOD_FILL && 1
...
...
imagelib/kpPainter.cpp
View file @
80944bc6
...
...
@@ -39,9 +39,9 @@
#include <QPainter>
#include <QPolygon>
#include <QRandomGenerator>
#include "kpLogCategories.h"
#include <KRandom>
//---------------------------------------------------------------------
...
...
@@ -56,14 +56,6 @@ bool kpPainter::pointsAreCardinallyAdjacent (const QPoint &p, const QPoint &q)
//---------------------------------------------------------------------
// Returns a random integer from 0 to 999 inclusive.
static
int
RandomNumberFrom0to999
()
{
return
(
KRandom
::
random
()
%
1000
);
}
//---------------------------------------------------------------------
// public static
QList
<
QPoint
>
kpPainter
::
interpolatePoints
(
const
QPoint
&
startPoint
,
const
QPoint
&
endPoint
,
...
...
@@ -79,8 +71,8 @@ QList <QPoint> kpPainter::interpolatePoints (const QPoint &startPoint,
Q_ASSERT
(
probability
>=
0.0
&&
probability
<=
1.0
);
const
int
probabilityTimes1000
=
qRound
(
probability
*
1000
);
#define SHOULD_DRAW() (probabilityTimes1000 == 1000
/*avoid
::
Random
NumberFrom0to999()
call*/
|| \
::
Random
NumberFrom0to999 (
) < probabilityTimes1000)
#define SHOULD_DRAW()
(
(probabilityTimes1000 == 1000
)
/*avoid
Q
Random
Generator
call*/
|| \
(Q
Random
Generator::global()->bounded(1000
) < probabilityTimes1000)
)
// Derived from the zSprite2 Graphics Engine.
...
...
@@ -361,9 +353,7 @@ static QRect WashLineHelper (QPainter *rgbPainter, void *data)
bool
didSomething
=
false
;
QList
<
QPoint
>
points
=
kpPainter
::
interpolatePoints
(
pack
->
startPoint
,
pack
->
endPoint
);
for
(
QList
<
QPoint
>::
const_iterator
pit
=
points
.
constBegin
();
pit
!=
points
.
constEnd
();
++
pit
)
foreach
(
const
QPoint
&
p
,
points
)
{
// OPT: This may be reading and possibly writing pixels that were
// visited on a previous iteration, since the pen is usually
...
...
@@ -376,7 +366,7 @@ static QRect WashLineHelper (QPainter *rgbPainter, void *data)
pack
->
colorToReplace
,
pack
->
readableImageRect
,
kpToolFlowBase
::
hotRectForMousePointAndBrushWidthHeight
(
*
pit
,
pack
->
penWidth
,
pack
->
penHeight
),
p
,
pack
->
penWidth
,
pack
->
penHeight
),
pack
->
processedColorSimilarity
))
{
didSomething
=
true
;
...
...
@@ -502,8 +492,8 @@ void kpPainter::sprayPoints (kpImage *image,
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
const
int
dx
=
(
K
Random
::
random
()
%
spraycanSize
)
-
radius
;
const
int
dy
=
(
K
Random
::
random
()
%
spraycanSize
)
-
radius
;
const
int
dx
=
(
Q
Random
Generator
::
global
()
->
generate
()
%
spraycanSize
)
-
radius
;
const
int
dy
=
(
Q
Random
Generator
::
global
()
->
generate
()
%
spraycanSize
)
-
radius
;
// Make it look circular.
// TODO: Can be done better by doing a random vector angle & length
...
...
layers/selections/text/kpPreeditText.cpp
View file @
80944bc6
...
...
@@ -73,7 +73,7 @@ kpPreeditText::kpPreeditText (const QInputMethodEvent *event)
break
;
}
}
qS
ort
(
m_textFormatList
.
begin
(),
m_textFormatList
.
end
(),
attributeLessThan
);
std
::
s
ort
(
m_textFormatList
.
begin
(),
m_textFormatList
.
end
(),
attributeLessThan
);
}
//---------------------------------------------------------------------
...
...
layers/selections/text/kpTextSelection.cpp
View file @
80944bc6
...
...
@@ -189,8 +189,7 @@ int kpTextSelection::minimumHeight () const
int
kpTextSelection
::
PreferredMinimumWidthForTextStyle
(
const
kpTextStyle
&
textStyle
)
{
const
int
about15CharsWidth
=
textStyle
.
fontMetrics
().
width
(
QStringLiteral
(
"1234567890abcde"
));
textStyle
.
fontMetrics
().
horizontalAdvance
(
QLatin1String
(
"1234567890abcde"
));
const
int
preferredMinWidth
=
qMax
(
150
,
...
...
@@ -292,31 +291,31 @@ void kpTextSelection::setTextLines (const QList <QString> &textLines_)
emit
changed
(
boundingRect
());
}
//--------------------------------------------------------------------------------
// public static
QString
kpTextSelection
::
T
extForTextLines
(
const
QList
<
QString
>
&
textLines
)
QString
kpTextSelection
::
t
extForTextLines
(
const
QList
<
QString
>
&
textLines
)
{
if
(
textLines
.
isEmpty
())
{
return
{};
}
if
(
textLines
.
isEmpty
())
return
QString
();
QString
bigString
=
textLines
[
0
];
QString
bigString
=
textLines
[
0
];
for
(
QList
<
QString
>::
const_iterator
it
=
textLines
.
begin
()
+
1
;
it
!=
textLines
.
end
();
++
it
)
for
(
int
i
=
1
;
i
<
textLines
.
count
();
i
++
)
{
bigString
+=
QLatin1String
(
"
\n
"
);
bigString
+=
(
*
it
)
;
bigString
+=
QLatin1String
(
"
\n
"
);
bigString
+=
textLines
[
i
]
;
}
return
bigString
;
}
//--------------------------------------------------------------------------------
// public
QString
kpTextSelection
::
text
()
const
{
return
kpTextSelection
::
T
extForTextLines
(
d
->
textLines
);
return
kpTextSelection
::
t
extForTextLines
(
d
->
textLines
);
}
...
...
layers/selections/text/kpTextSelection.h
View file @
80944bc6
...
...
@@ -209,7 +209,7 @@ public:
QList
<
QString
>
textLines
()
const
;
void
setTextLines
(
const
QList
<
QString
>
&
textLines
);
static
QString
T
extForTextLines
(
const
QList
<
QString
>
&
textLines
);
static
QString
t
extForTextLines
(
const
QList
<
QString
>
&
textLines
);
// Returns textLines() as one long newline-separated string.
// If the last text line is not empty, there is no trailing newline.
QString
text
()
const
;
...
...
layers/selections/text/kpTextSelection_Cursor.cpp
View file @
80944bc6
...
...
@@ -74,13 +74,13 @@ int kpTextSelection::closestTextColForPoint (const QPoint &point) const
const
QFontMetrics
fontMetrics
(
d
->
textStyle
.
fontMetrics
());
// (should be 0 but call just in case)
int
charLocalLeft
=
fontMetrics
.
width
(
d
->
textLines
[
row
],
0
);
int
charLocalLeft
=
fontMetrics
.
horizontalAdvance
(
d
->
textLines
[
row
],
0
);
// OPT: binary search or guess location then move
for
(
int
col
=
0
;
col
<
static_cast
<
int
>
(
d
->
textLines
[
row
].
length
());
col
++
)
{
// OPT: fontMetrics::charWidth() might be faster
const
int
nextCharLocalLeft
=
fontMetrics
.
width
(
d
->
textLines
[
row
],
col
+
1
);
const
int
nextCharLocalLeft
=
fontMetrics
.
horizontalAdvance
(
d
->
textLines
[
row
],
col
+
1
);
if
(
localX
<=
(
charLocalLeft
+
nextCharLocalLeft
)
/
2
)
{
return
col
;
}
...
...
@@ -119,7 +119,7 @@ QPoint kpTextSelection::pointForTextRowCol (int row, int col) const
{
line
.
insert
(
preeditText
.
position
().
x
(),
preeditText
.
preeditString
());
}
const
int
x
=
fontMetrics
.
width
(
line
.
left
(
col
));
const
int
x
=
fontMetrics
.
horizontalAdvance
(
line
.
left
(
col
));
const
int
y
=
row
*
fontMetrics
.
height
()
+
(
row
>=
1
?
row
*
fontMetrics
.
leading
()
:
0
);
...
...
layers/selections/text/kpTextSelection_Paint.cpp
View file @
80944bc6
...
...
@@ -73,12 +73,12 @@ void kpTextSelection::drawPreeditString(QPainter &painter, int &x, int y, const
{
str
=
preeditString
.
mid
(
i
,
start
-
i
);
painter
.
drawText
(
x
,
y
,
str
);
x
+=
painter
.
fontMetrics
().
width
(
str
);
x
+=
painter
.
fontMetrics
().
horizontalAdvance
(
str
);
}
painter
.
save
();
str
=
preeditString
.
mid
(
start
,
length
);