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
Plasma
Plasma Workspace
Commits
45185e25
Commit
45185e25
authored
Jan 20, 2022
by
Eugene Popov
🇺🇦
Committed by
Fushan Wen
Feb 18, 2022
Browse files
A better fix for BUG 431673
parent
1f5a8b86
Changes
6
Hide whitespace changes
Inline
Side-by-side
klipper/CMakeLists.txt
View file @
45185e25
...
...
@@ -18,6 +18,7 @@ set(libklipper_common_SRCS
actionstreewidget.cpp
editactiondialog.cpp
clipcommandprocess.cpp
utils.cpp
)
ecm_qt_declare_logging_category
(
libklipper_common_SRCS HEADER klipper_debug.h IDENTIFIER KLIPPER_LOG CATEGORY_NAME org.kde.klipper DESCRIPTION
"klipper"
EXPORT KLIPPER
)
...
...
klipper/autotests/CMakeLists.txt
View file @
45185e25
...
...
@@ -17,3 +17,12 @@ target_link_libraries(testHistoryModel
)
add_test
(
NAME klipper-testHistoryModel COMMAND testHistoryModel
)
ecm_mark_as_test
(
testHistoryModel
)
# Test Utils
add_executable
(
testKlipperUtils utilstest.cpp
)
target_link_libraries
(
testKlipperUtils
Qt::Test
libklipper_common_static
)
add_test
(
NAME klipper-testUtils COMMAND testKlipperUtils
)
ecm_mark_as_test
(
testKlipperUtils
)
klipper/autotests/utilstest.cpp
0 → 100644
View file @
45185e25
#include
"../utils.h"
#include
<QObject>
#include
<QtTest>
class
UtilsTest
:
public
QObject
{
Q_OBJECT
private
Q_SLOTS
:
void
testSimplifiedText
();
};
void
UtilsTest
::
testSimplifiedText
()
{
const
QString
text
=
QStringLiteral
(
" Some text
\n
to
\t\t
test "
);
QCOMPARE
(
Utils
::
simplifiedText
(
text
,
1000
),
QStringLiteral
(
"Some text to test"
));
QCOMPARE
(
Utils
::
simplifiedText
(
text
,
17
),
QStringLiteral
(
"Some text to test"
));
QCOMPARE
(
Utils
::
simplifiedText
(
text
,
10
),
QStringLiteral
(
"Some text"
));
QCOMPARE
(
Utils
::
simplifiedText
(
text
,
0
),
QStringLiteral
(
""
));
}
QTEST_MAIN
(
UtilsTest
)
#include
"utilstest.moc"
klipper/popupproxy.cpp
View file @
45185e25
...
...
@@ -13,6 +13,7 @@
#include
"historyitem.h"
#include
"klipperpopup.h"
#include
"utils.h"
PopupProxy
::
PopupProxy
(
KlipperPopup
*
parent
,
int
menu_height
,
int
menu_width
)
:
QObject
(
parent
)
...
...
@@ -77,7 +78,7 @@ void PopupProxy::tryInsertItem(HistoryItem const *const item, int &remainingHeig
QPixmap
image
(
item
->
image
());
if
(
image
.
isNull
())
{
// Squeeze text strings so that do not take up the entire screen (or more)
QString
text
=
m_proxy_for_menu
->
fontMetrics
().
elidedText
(
item
->
text
().
simplified
(
),
Qt
::
Elide
Middle
,
m_menu_width
);
QString
text
=
m_proxy_for_menu
->
fontMetrics
().
elidedText
(
Utils
::
simplifiedText
(
item
->
text
(),
1000
),
Qt
::
Elide
Right
,
m_menu_width
);
text
.
replace
(
QLatin1Char
(
'&'
),
QLatin1String
(
"&&"
));
action
->
setText
(
text
);
}
else
{
...
...
klipper/utils.cpp
0 → 100644
View file @
45185e25
/*
SPDX-FileCopyrightText: 2022 Popov Eugene <popov895@ukr.net>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include
"utils.h"
QString
Utils
::
simplifiedText
(
const
QString
&
text
,
int
maxLength
)
{
if
(
text
.
length
()
<=
maxLength
)
{
return
text
.
simplified
();
}
QString
simplifiedText
;
simplifiedText
.
reserve
(
maxLength
);
bool
wasSpaceBefore
=
false
;
for
(
int
i
=
0
,
n
=
text
.
length
();
i
<
n
;
++
i
)
{
if
(
simplifiedText
.
length
()
==
maxLength
)
{
break
;
}
const
QChar
c
=
text
.
at
(
i
);
if
(
c
.
isSpace
())
{
if
(
wasSpaceBefore
||
simplifiedText
.
isEmpty
())
{
continue
;
}
simplifiedText
.
append
(
QLatin1Char
(
' '
));
wasSpaceBefore
=
true
;
}
else
{
simplifiedText
.
append
(
c
);
wasSpaceBefore
=
false
;
}
}
if
(
simplifiedText
.
endsWith
(
QLatin1Char
(
' '
)))
{
simplifiedText
.
chop
(
1
);
}
return
simplifiedText
;
}
klipper/utils.h
0 → 100644
View file @
45185e25
/*
SPDX-FileCopyrightText: 2022 Popov Eugene <popov895@ukr.net>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include
<QString>
class
Utils
{
public:
/**
* Returns a simplified text of a maximum length of maxLength
*/
static
QString
simplifiedText
(
const
QString
&
text
,
int
maxLength
);
};
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