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
Utilities
Kate
Commits
c679c157
Commit
c679c157
authored
Feb 18, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Feb 18, 2021
Browse files
Use QTextLayout for better text rendering in BranchesDialog
parent
faebea45
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/project/branchesdialog.cpp
View file @
c679c157
...
...
@@ -86,31 +86,39 @@ public:
QStyleOptionViewItem
options
=
option
;
initStyleOption
(
&
options
,
index
);
QTextDocument
doc
;
auto
name
=
index
.
data
().
toString
();
const
QString
nameColor
=
option
.
palette
.
color
(
QPalette
::
Link
).
name
();
kfts
::
to_scored_fuzzy_matched_display_string
(
m_filterString
,
name
,
QStringLiteral
(
"<b style=
\"
color:%1;
\"
>"
).
arg
(
nameColor
),
QStringLiteral
(
"</b>"
));
QVector
<
QTextLayout
::
FormatRange
>
formats
;
QTextCharFormat
fmt
;
fmt
.
setForeground
(
options
.
palette
.
link
());
fmt
.
setFontWeight
(
QFont
::
Bold
);
auto
refType
=
(
GitUtils
::
RefType
)
index
.
data
(
BranchesDialogModel
::
RefType
).
toInt
();
auto
itemType
=
(
BranchesDialogModel
::
ItemType
)
index
.
data
(
BranchesDialogModel
::
ItemTypeRole
).
toInt
();
using
RefType
=
GitUtils
::
RefType
;
const
auto
fontSz
=
option
.
font
.
pointSize
();
name
=
QStringLiteral
(
"<span style=
\"
font-size:%1pt;
\"
>"
).
arg
(
fontSz
)
+
name
+
QStringLiteral
(
"</span>"
);
const
auto
itemType
=
(
BranchesDialogModel
::
ItemType
)
index
.
data
(
BranchesDialogModel
::
ItemTypeRole
).
toInt
();
const
bool
branchItem
=
itemType
==
BranchesDialogModel
::
BranchItem
;
const
int
offset
=
branchItem
?
0
:
2
;
if
(
itemType
==
BranchesDialogModel
::
CreateBranch
||
itemType
==
BranchesDialogModel
::
CreateBranchFrom
)
{
name
.
prepend
(
QStringLiteral
(
"+ <b>"
)).
append
(
QStringLiteral
(
"</b>"
));
}
else
{
formats
=
kfts
::
get_fuzzy_match_formats
(
m_filterString
,
name
,
offset
,
fmt
);
if
(
!
branchItem
)
{
name
=
QStringLiteral
(
"+ "
)
+
name
;
}
const
int
nameLen
=
name
.
length
();
int
len
=
6
;
if
(
branchItem
)
{
const
auto
refType
=
(
GitUtils
::
RefType
)
index
.
data
(
BranchesDialogModel
::
RefType
).
toInt
();
using
RefType
=
GitUtils
::
RefType
;
if
(
refType
==
RefType
::
Head
)
{
name
.
append
(
QStringLiteral
(
"
<span style=
\"
color:gray; font-size:%1pt;
\"
>local</span>"
).
arg
(
fontSz
-
1
));
name
.
append
(
QStringLiteral
(
"
local"
));
}
else
if
(
refType
==
RefType
::
Remote
)
{
name
.
append
(
QStringLiteral
(
" <span style=
\"
color:gray; font-size:%1pt;
\"
>remote</span>"
).
arg
(
fontSz
-
1
));
name
.
append
(
QStringLiteral
(
" remote"
));
len
=
7
;
}
}
doc
.
setHtml
(
name
);
doc
.
setDocumentMargin
(
2
);
QTextCharFormat
lf
;
lf
.
setFontItalic
(
true
);
lf
.
setForeground
(
Qt
::
gray
);
formats
.
append
({
nameLen
,
len
,
lf
});
painter
->
save
();
...
...
@@ -124,13 +132,11 @@ public:
options
.
text
=
QString
();
// clear old text
options
.
widget
->
style
()
->
drawControl
(
QStyle
::
CE_ItemViewItem
,
&
options
,
painter
,
options
.
widget
);
// draw text
painter
->
translate
(
option
.
rect
.
x
(),
option
.
rect
.
y
());
// leave space for icon
painter
->
translate
(
25
,
0
);
doc
.
drawContents
(
painter
);
if
(
itemType
==
BranchesDialogModel
::
BranchItem
)
{
painter
->
translate
(
25
,
0
);
}
kfts
::
paintItemViewText
(
painter
,
name
,
options
,
formats
);
painter
->
restore
();
}
...
...
addons/project/branchesdialogmodel.cpp
View file @
c679c157
...
...
@@ -44,8 +44,16 @@ QVariant BranchesDialogModel::data(const QModelIndex &idx, int role) const
}
else
if
(
role
==
Role
::
OriginalSorting
)
{
return
branch
.
dateSort
;
}
else
if
(
role
==
Qt
::
DecorationRole
)
{
static
const
auto
branchIcon
=
QIcon
(
QStringLiteral
(
":/icons/icons/sc-apps-git.svg"
));
return
branchIcon
;
if
(
branch
.
itemType
==
BranchItem
)
{
static
const
auto
branchIcon
=
QIcon
(
QStringLiteral
(
":/icons/icons/sc-apps-git.svg"
));
return
branchIcon
;
}
}
else
if
(
role
==
Qt
::
FontRole
)
{
if
(
branch
.
itemType
==
CreateBranch
||
branch
.
itemType
==
CreateBranchFrom
)
{
QFont
font
;
font
.
setBold
(
true
);
return
font
;
}
}
else
if
(
role
==
Role
::
CheckoutName
)
{
return
branch
.
refType
==
GitUtils
::
RefType
::
Remote
?
branch
.
name
.
mid
(
branch
.
remote
.
size
()
+
1
)
:
branch
.
name
;
}
else
if
(
role
==
Role
::
RefType
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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