Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-gpu
Commits
4e68ddd0
Commit
4e68ddd0
authored
Jan 28, 2010
by
Rafaël Carré
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Qt4 Icon View: cache full rendering for each item
parent
3daab2d0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
54 deletions
+85
-54
modules/gui/qt4/components/playlist/icon_view.cpp
modules/gui/qt4/components/playlist/icon_view.cpp
+85
-54
No files found.
modules/gui/qt4/components/playlist/icon_view.cpp
View file @
4e68ddd0
...
...
@@ -40,92 +40,123 @@
#define ITEMS_SPACING 10
#define ART_RADIUS 5
static
QPixmap
find_art_pixmap
(
const
QString
&
url
)
{
QPixmap
pix
;
if
(
QPixmapCache
::
find
(
url
,
pix
)
)
/* great, we found it */
return
pix
;
if
(
url
.
isEmpty
()
||
!
pix
.
load
(
url
)
)
pix
=
QPixmap
(
":/noart64"
);
else
pix
=
pix
.
scaled
(
ART_SIZE
,
ART_SIZE
,
Qt
::
KeepAspectRatioByExpanding
);
QPixmapCache
::
insert
(
url
,
pix
);
/* save it for next time */
return
pix
;
}
static
const
QRect
drawRect
=
QRect
(
0
,
0
,
RECT_SIZE
,
RECT_SIZE
);
static
const
QRect
artRect
=
drawRect
.
adjusted
(
OFFSET
-
1
,
0
,
-
OFFSET
,
-
OFFSET
*
2
);
void
PlListViewItemDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
painter
->
setRenderHints
(
QPainter
::
Antialiasing
|
QPainter
::
SmoothPixmapTransform
);
/*if( option.state & QStyle::State_Selected )
painter->fillRect(option.rect, option.palette.highlight());*/
QApplication
::
style
()
->
drawPrimitive
(
QStyle
::
PE_PanelItemViewItem
,
&
option
,
painter
);
PLItem
*
currentItem
=
static_cast
<
PLItem
*>
(
index
.
internalPointer
()
);
assert
(
currentItem
);
QPixmap
artpix
;
QString
url
=
InputManager
::
decodeArtURL
(
currentItem
->
inputItem
()
);
char
*
meta
;
meta
=
input_item_GetTitleFbName
(
currentItem
->
inputItem
()
);
QString
title
=
qfu
(
meta
);
free
(
meta
);
meta
=
input_item_GetArtist
(
currentItem
->
inputItem
()
);
QString
artist
=
qfu
(
meta
);
free
(
meta
);
/* look up through all children and use the first picture found */
if
(
url
.
isEmpty
()
)
QString
artUrl
=
InputManager
::
decodeArtURL
(
currentItem
->
inputItem
()
);
// look up through all children and use the first picture found
if
(
artUrl
.
isEmpty
()
)
{
int
children
=
currentItem
->
childCount
();
for
(
int
i
=
0
;
i
<
children
;
i
++
)
{
PLItem
*
child
=
currentItem
->
child
(
i
);
u
rl
=
InputManager
::
decodeArtURL
(
child
->
inputItem
()
);
if
(
!
u
rl
.
isEmpty
()
)
artU
rl
=
InputManager
::
decodeArtURL
(
child
->
inputItem
()
);
if
(
!
artU
rl
.
isEmpty
()
)
break
;
}
}
QRect
artRect
=
option
.
rect
.
adjusted
(
OFFSET
-
1
,
0
,
-
OFFSET
,
-
OFFSET
*
2
);
artpix
=
find_art_pixmap
(
url
);
/* look in the QPixmapCache for art */
/*if( option.state & QStyle::State_Selected )
painter->fillRect(option.rect, option.palette.highlight());*/
QApplication
::
style
()
->
drawPrimitive
(
QStyle
::
PE_PanelItemViewItem
,
&
option
,
painter
);
QPainterPath
artRectPath
;
artRectPath
.
addRoundedRect
(
artRect
,
ART_RADIUS
,
ART_RADIUS
);
// picture where all the rendering happens and which will be cached
QPixmap
pix
;
QString
key
=
title
+
artist
+
artUrl
;
if
(
QPixmapCache
::
find
(
key
,
pix
))
{
// cool, we found it in the cache
painter
->
drawPixmap
(
option
.
rect
,
pix
);
return
;
}
// load album art
QPixmap
artPix
;
if
(
artUrl
.
isEmpty
()
||
!
artPix
.
load
(
artUrl
)
)
artPix
=
QPixmap
(
":/noart64"
);
else
artPix
=
artPix
.
scaled
(
ART_SIZE
,
ART_SIZE
,
Qt
::
KeepAspectRatioByExpanding
);
pix
=
QPixmap
(
RECT_SIZE
,
RECT_SIZE
);
pix
.
fill
(
Qt
::
transparent
);
QPainter
*
pixpainter
=
new
QPainter
(
&
pix
);
pixpainter
->
setRenderHints
(
QPainter
::
Antialiasing
|
QPainter
::
SmoothPixmapTransform
);
// Draw the drop shadow
painter
->
save
();
painter
->
setOpacity
(
0.7
);
painter
->
setBrush
(
QBrush
(
Qt
::
gray
)
);
painter
->
drawRoundedRect
(
artRect
.
adjusted
(
2
,
2
,
2
,
2
),
ART_RADIUS
,
ART_RADIUS
);
painter
->
restore
();
p
ixp
ainter
->
save
();
p
ixp
ainter
->
setOpacity
(
0.7
);
p
ixp
ainter
->
setBrush
(
QBrush
(
Qt
::
gray
)
);
p
ixp
ainter
->
drawRoundedRect
(
artRect
.
adjusted
(
2
,
2
,
2
,
2
),
ART_RADIUS
,
ART_RADIUS
);
p
ixp
ainter
->
restore
();
// Draw the art pixmap
painter
->
setClipPath
(
artRectPath
);
painter
->
drawPixmap
(
artRect
,
artpix
);
painter
->
setClipping
(
false
);
// Draw the art pix
QPainterPath
artRectPath
;
artRectPath
.
addRoundedRect
(
artRect
,
ART_RADIUS
,
ART_RADIUS
);
pixpainter
->
setClipPath
(
artRectPath
);
pixpainter
->
drawPixmap
(
artRect
,
artPix
);
pixpainter
->
setClipping
(
false
);
QColor
text
=
qApp
->
palette
().
text
().
color
();
QString
title
=
qfu
(
input_item_GetTitleFbName
(
currentItem
->
inputItem
()
)
);
QString
artist
=
qfu
(
input_item_GetArtist
(
currentItem
->
inputItem
()
)
);
painter
->
setPen
(
text
);
// Draw title
pixpainter
->
setPen
(
text
);
QFont
font
;
font
.
setPointSize
(
7
);
font
.
setItalic
(
true
);
font
.
setBold
(
index
.
data
(
Qt
::
FontRole
).
value
<
QFont
>
().
bold
()
);
painter
->
setFont
(
font
);
QFontMetrics
fm
=
painter
->
fontMetrics
();
QRect
t
itleRect
=
option
.
r
ect
.
adjusted
(
1
,
ART_SIZE
+
4
,
0
,
-
1
);
t
itle
Rect
.
setHeight
(
fm
.
height
()
+
2
);
p
ixp
ainter
->
setFont
(
font
);
QFontMetrics
fm
=
p
ixp
ainter
->
fontMetrics
();
QRect
t
extRect
=
drawR
ect
.
adjusted
(
1
,
ART_SIZE
+
4
,
0
,
-
1
);
t
ext
Rect
.
setHeight
(
fm
.
height
()
+
2
);
painter
->
drawText
(
titleRect
,
fm
.
elidedText
(
title
,
Qt
::
ElideRight
,
titleRect
.
width
()
),
pixpainter
->
drawText
(
textRect
,
fm
.
elidedText
(
title
,
Qt
::
ElideRight
,
textRect
.
width
()
),
QTextOption
(
Qt
::
AlignCenter
)
);
painter
->
setPen
(
text
.
lighter
(
240
)
);
// Draw artist
pixpainter
->
setPen
(
text
.
lighter
(
240
)
);
font
.
setItalic
(
false
);
painter
->
setFont
(
font
);
fm
=
painter
->
fontMetrics
();
QRect
artistRect
=
option
.
rect
.
adjusted
(
1
,
ART_SIZE
+
4
+
titleRect
.
height
(),
-
1
,
-
1
);
pixpainter
->
setFont
(
font
);
fm
=
pixpainter
->
fontMetrics
();
painter
->
drawText
(
artistRect
,
fm
.
elidedText
(
artist
,
Qt
::
ElideRight
,
artistRect
.
width
()
),
textRect
=
textRect
.
adjusted
(
0
,
textRect
.
height
(),
0
,
textRect
.
height
()
);
pixpainter
->
drawText
(
textRect
,
fm
.
elidedText
(
artist
,
Qt
::
ElideRight
,
textRect
.
width
()
),
QTextOption
(
Qt
::
AlignCenter
)
);
delete
pixpainter
;
// Ensure all paint operations have finished
// Here real drawing happens
painter
->
drawPixmap
(
option
.
rect
,
pix
);
// Cache the rendering
QPixmapCache
::
insert
(
key
,
pix
);
}
QSize
PlListViewItemDelegate
::
sizeHint
(
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
...
...
Write
Preview
Markdown
is supported
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