Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
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
Commits
0823125e
Commit
0823125e
authored
Mar 08, 2014
by
Francois Cartegnie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Qt: VLCModel/TreeView: delegate cover rendering (fix #10206)
parent
a1f1c15f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
55 deletions
+53
-55
modules/gui/qt4/components/playlist/playlist_model.cpp
modules/gui/qt4/components/playlist/playlist_model.cpp
+14
-40
modules/gui/qt4/components/playlist/sorting.h
modules/gui/qt4/components/playlist/sorting.h
+1
-1
modules/gui/qt4/components/playlist/views.cpp
modules/gui/qt4/components/playlist/views.cpp
+9
-1
modules/gui/qt4/components/playlist/views.hpp
modules/gui/qt4/components/playlist/views.hpp
+9
-0
modules/gui/qt4/components/playlist/vlc_model.cpp
modules/gui/qt4/components/playlist/vlc_model.cpp
+19
-12
modules/gui/qt4/components/playlist/vlc_model.hpp
modules/gui/qt4/components/playlist/vlc_model.hpp
+1
-1
No files found.
modules/gui/qt4/components/playlist/playlist_model.cpp
View file @
0823125e
...
...
@@ -381,7 +381,7 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
break
;
}
}
return
QVariant
(
artUrl
)
;
return
artUrl
;
}
else
{
...
...
@@ -391,51 +391,25 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
}
return
QVariant
(
returninfo
);
}
else
if
(
role
==
Qt
::
DecorationRole
&&
index
.
column
()
==
0
)
else
if
(
role
==
Qt
::
DecorationRole
)
{
/* Used to segfault here because i_type wasn't always initialized */
return
QVariant
(
icons
[
item
->
inputItem
()
->
i_type
]
);
switch
(
columnToMeta
(
index
.
column
())
)
{
case
COLUMN_TITLE
:
/* Used to segfault here because i_type wasn't always initialized */
return
QVariant
(
icons
[
item
->
inputItem
()
->
i_type
]
);
case
COLUMN_COVER
:
/* !warn: changes tree item line height. Otherwise, override
* delegate's sizehint */
return
getArtPixmap
(
index
,
QSize
(
16
,
16
)
);
default:
return
QVariant
();
}
}
else
if
(
role
==
Qt
::
FontRole
)
{
return
QVariant
(
QFont
()
);
}
else
if
(
role
==
Qt
::
ToolTipRole
)
{
int
i_art_policy
=
var_GetInteger
(
p_playlist
,
"album-art"
);
QString
artUrl
;
/* FIXME: Skip, as we don't want the pixmap and do not know the cached art file */
if
(
i_art_policy
==
ALBUM_ART_ALL
)
artUrl
=
getArtUrl
(
index
);
if
(
artUrl
.
isEmpty
()
)
artUrl
=
":/noart"
;
QString
duration
=
qtr
(
"unknown"
);
QString
name
;
PL_LOCK
;
input_item_t
*
p_item
=
item
->
inputItem
();
if
(
!
p_item
)
{
PL_UNLOCK
;
return
QVariant
();
}
if
(
p_item
->
i_duration
>
0
)
{
char
*
psz
=
psz_column_meta
(
item
->
inputItem
(),
COLUMN_DURATION
);
duration
=
qfu
(
psz
);
free
(
psz
);
}
name
=
qfu
(
p_item
->
psz_name
);
PL_UNLOCK
;
QPixmap
image
=
getArtPixmap
(
index
,
QSize
(
128
,
128
)
);
QByteArray
bytes
;
QBuffer
buffer
(
&
bytes
);
buffer
.
open
(
QIODevice
::
WriteOnly
);
image
.
save
(
&
buffer
,
"BMP"
);
/* uncompressed, see qpixmap#reading-and-writing-image-files */
return
QVariant
(
QString
(
"<img width=
\"
128
\"
height=
\"
128
\"
align=
\"
left
\"
src=
\"
data:image/bmp;base64,%1
\"
/><div><b>%2</b><br/>%3</div>"
)
.
arg
(
bytes
.
toBase64
().
constData
()
)
.
arg
(
name
)
.
arg
(
qtr
(
"Duration"
)
+
": "
+
duration
)
);
}
else
if
(
role
==
Qt
::
BackgroundRole
&&
isCurrent
(
index
)
)
{
return
QVariant
(
QBrush
(
Qt
::
gray
)
);
...
...
modules/gui/qt4/components/playlist/sorting.h
View file @
0823125e
...
...
@@ -61,7 +61,7 @@ static inline const char * psz_column_title( uint32_t i_column )
case
COLUMN_DESCRIPTION
:
return
VLC_META_DESCRIPTION
;
case
COLUMN_URI
:
return
_
(
"URI"
);
case
COLUMN_RATING
:
return
VLC_META_RATING
;
case
COLUMN_COVER
:
return
VLC_META_ART_URL
;
case
COLUMN_COVER
:
return
_
(
"Cover"
)
;
default:
abort
();
}
}
...
...
modules/gui/qt4/components/playlist/views.cpp
View file @
0823125e
...
...
@@ -288,6 +288,13 @@ void PlTreeViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
}
}
void
CellPixmapDelegate
::
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
{
QPixmap
pixmap
=
index
.
data
(
Qt
::
DecorationRole
).
value
<
QPixmap
>
();
painter
->
drawPixmap
(
option
.
rect
.
topLeft
(),
pixmap
.
scaled
(
option
.
rect
.
size
(),
Qt
::
KeepAspectRatio
)
);
}
static
inline
void
plViewStartDrag
(
QAbstractItemView
*
view
,
const
Qt
::
DropActions
&
supportedActions
)
{
QDrag
*
drag
=
new
QDrag
(
view
);
...
...
@@ -415,7 +422,8 @@ bool PlListView::viewportEvent ( QEvent * event )
PlTreeView
::
PlTreeView
(
QAbstractItemModel
*
,
QWidget
*
parent
)
:
QTreeView
(
parent
)
{
setItemDelegate
(
new
PlTreeViewItemDelegate
(
this
)
);
setItemDelegateForColumn
(
VLCModel
::
metaToColumn
(
COLUMN_COVER
),
new
CellPixmapDelegate
(
this
)
);
setIconSize
(
QSize
(
20
,
20
)
);
setAlternatingRowColors
(
true
);
setAnimated
(
true
);
...
...
modules/gui/qt4/components/playlist/views.hpp
View file @
0823125e
...
...
@@ -78,6 +78,15 @@ public:
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
;
};
class
CellPixmapDelegate
:
public
QStyledItemDelegate
{
Q_OBJECT
public:
CellPixmapDelegate
(
QWidget
*
parent
=
0
)
:
QStyledItemDelegate
(
parent
)
{}
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionViewItem
&
option
,
const
QModelIndex
&
index
)
const
;
};
class
PlIconView
:
public
QListView
{
Q_OBJECT
...
...
modules/gui/qt4/components/playlist/vlc_model.cpp
View file @
0823125e
...
...
@@ -76,18 +76,10 @@ QString VLCModel::getMeta( const QModelIndex & index, int meta )
data
().
toString
();
}
QString
VLCModel
::
getArtUrl
(
const
QModelIndex
&
index
)
{
return
index
.
model
()
->
index
(
index
.
row
(),
columnFromMeta
(
COLUMN_COVER
),
index
.
parent
()
)
.
data
().
toString
();
}
QPixmap
VLCModel
::
getArtPixmap
(
const
QModelIndex
&
index
,
const
QSize
&
size
)
{
QString
artUrl
=
VLCModel
::
getArtUrl
(
index
)
;
QString
artUrl
=
index
.
sibling
(
index
.
row
(),
VLCModel
::
columnFromMeta
(
COLUMN_COVER
)
).
data
().
toString
();
QPixmap
artPix
;
QString
key
=
artUrl
+
QString
(
"%1%2"
).
arg
(
size
.
width
()).
arg
(
size
.
height
());
...
...
@@ -141,6 +133,21 @@ int VLCModel::columnToMeta( int _column )
return
meta
;
}
int
VLCModel
::
metaToColumn
(
int
_meta
)
{
int
meta
=
1
,
column
=
0
;
while
(
meta
!=
COLUMN_END
)
{
if
(
meta
&
_meta
)
break
;
meta
<<=
1
;
column
++
;
}
return
column
;
}
int
VLCModel
::
itemId
(
const
QModelIndex
&
index
,
int
type
)
const
{
AbstractPLItem
*
item
=
getItem
(
index
);
...
...
@@ -198,8 +205,8 @@ void VLCModel::ensureArtRequested( const QModelIndex &index )
QModelIndex
child
;
for
(
int
row
=
0
;
row
<
nbnodes
;
row
++
)
{
child
=
index
.
child
(
row
,
0
);
if
(
child
.
isValid
()
&&
getArtUrl
(
child
).
isEmpty
()
)
child
=
index
.
child
(
row
,
COLUMN_COVER
);
if
(
child
.
isValid
()
&&
child
.
data
().
toString
(
).
isEmpty
()
)
THEMIM
->
getIM
()
->
requestArtUpdate
(
getInputItem
(
child
)
);
}
}
...
...
modules/gui/qt4/components/playlist/vlc_model.hpp
View file @
0823125e
...
...
@@ -163,9 +163,9 @@ public:
/* Custom */
static
int
columnToMeta
(
int
_column
);
static
int
metaToColumn
(
int
meta
);
static
QString
getMeta
(
const
QModelIndex
&
index
,
int
meta
);
static
QPixmap
getArtPixmap
(
const
QModelIndex
&
index
,
const
QSize
&
size
);
static
QString
getArtUrl
(
const
QModelIndex
&
index
);
protected:
/* Custom methods / helpers */
...
...
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