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
6196b032
Commit
6196b032
authored
Oct 07, 2011
by
Jean-Baptiste Kempf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Qt: first attempt at a QMenuView
parent
a8bf1141
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
0 deletions
+183
-0
modules/gui/qt4/Modules.am
modules/gui/qt4/Modules.am
+3
-0
modules/gui/qt4/util/qmenuview.cpp
modules/gui/qt4/util/qmenuview.cpp
+123
-0
modules/gui/qt4/util/qmenuview.hpp
modules/gui/qt4/util/qmenuview.hpp
+57
-0
No files found.
modules/gui/qt4/Modules.am
View file @
6196b032
...
...
@@ -70,6 +70,7 @@ nodist_SOURCES_qt4 = \
util/timetooltip.moc.cpp \
util/customwidgets.moc.cpp \
util/searchlineedit.moc.cpp \
util/qmenuview.moc.cpp \
util/qvlcapp.moc.cpp \
util/pictureflow.moc.cpp \
util/buttons/RoundButton.moc.cpp \
...
...
@@ -309,6 +310,7 @@ SOURCES_qt4 = qt4.cpp \
util/customwidgets.cpp \
util/searchlineedit.cpp \
util/registry.cpp \
util/qmenuview.cpp \
util/qt_dirs.cpp \
util/pictureflow.cpp \
util/buttons/BrowseButton.cpp \
...
...
@@ -389,6 +391,7 @@ noinst_HEADERS = \
util/searchlineedit.hpp \
util/qvlcframe.hpp \
util/qvlcapp.hpp \
util/qmenuview.hpp \
util/qt_dirs.hpp \
util/registry.hpp \
util/pictureflow.hpp \
...
...
modules/gui/qt4/util/qmenuview.cpp
0 → 100644
View file @
6196b032
/*****************************************************************************
* QMenuView
****************************************************************************
* Copyright © 2011 VLC authors and VideoLAN
* $Id$
*
* Authors: Jean-Baptiste Kempf <jb@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "qt4.hpp"
#include "util/qmenuview.hpp"
#include "components/playlist/vlc_model.hpp"
/* data( IsCurrentRole ) */
#include <QFont>
#include <QVariant>
#include <assert.h>
/***
* This is a simple view, like a QListView, but displayed as a QMenu
* So far, this is quite limited.
*
* This is now linked to VLC's models. It should be splittable in the future.
*
* TODO: - limit the number of the menu, as a Q_PROPERTY
* - limit the width of the entries
* - deal with a root item
***/
Q_DECLARE_METATYPE
(
QModelIndex
);
// So we can store it in a QVariant
QMenuView
::
QMenuView
(
QWidget
*
parent
)
:
QMenu
(
parent
)
{
m_model
=
NULL
;
/* Rebuild the Menu just before showing it */
CONNECT
(
this
,
aboutToShow
(),
this
,
rebuild
()
);
/* */
CONNECT
(
this
,
triggered
(
QAction
*
),
this
,
activate
(
QAction
*
)
);
}
/* */
void
QMenuView
::
rebuild
()
{
if
(
!
m_model
)
return
;
/* Clear all Items */
clear
();
/* Rebuild from root */
build
(
QModelIndex
()
);
}
/* */
void
QMenuView
::
build
(
const
QModelIndex
&
parent
)
{
for
(
int
i
=
0
;
i
<
m_model
->
rowCount
(
parent
);
i
++
)
{
QModelIndex
idx
=
m_model
->
index
(
i
,
0
,
parent
);
if
(
m_model
->
hasChildren
(
idx
)
)
{
build
(
idx
);
}
else
{
addAction
(
createActionFromIndex
(
idx
)
);
}
}
}
/* Create individual actions */
QAction
*
QMenuView
::
createActionFromIndex
(
QModelIndex
index
)
{
QIcon
icon
=
qvariant_cast
<
QIcon
>
(
index
.
data
(
Qt
::
DecorationRole
)
);
QAction
*
action
=
new
QAction
(
icon
,
index
.
data
().
toString
(),
this
);
/* Display in bold the active element */
if
(
index
.
data
(
VLCModel
::
IsCurrentRole
).
toBool
()
)
{
QFont
font
;
font
.
setBold
(
true
);
action
->
setFont
(
font
);
}
/* Some items could be hypothetically disabled */
action
->
setEnabled
(
index
.
flags
().
testFlag
(
Qt
::
ItemIsEnabled
)
);
/* */
QVariant
variant
;
variant
.
setValue
(
index
);
action
->
setData
(
variant
);
return
action
;
}
/* QMenu action trigger */
void
QMenuView
::
activate
(
QAction
*
action
)
{
assert
(
m_model
);
QVariant
variant
=
action
->
data
();
if
(
variant
.
canConvert
<
QModelIndex
>
()
)
{
emit
activated
(
variant
.
value
<
QModelIndex
>
());
}
}
modules/gui/qt4/util/qmenuview.hpp
0 → 100644
View file @
6196b032
/*****************************************************************************
* QMenuView
****************************************************************************
* Copyright © 2011 VLC authors and VideoLAN
* $Id$
*
* Authors: Jean-Baptiste Kempf <jb@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _QMENU_VIEW_H_
#define _QMENU_VIEW_H_
#include <QMenu>
#include <QAbstractItemModel>
class
QMenuView
:
public
QMenu
{
Q_OBJECT
;
public:
QMenuView
(
QWidget
*
parent
=
0
);
virtual
~
QMenuView
(){}
/* Model */
void
setModel
(
QAbstractItemModel
*
model
)
{
m_model
=
model
;
}
QAbstractItemModel
*
model
()
const
{
return
m_model
;
}
private:
QAbstractItemModel
*
m_model
;
QAction
*
createActionFromIndex
(
QModelIndex
index
);
void
build
(
const
QModelIndex
&
parent
);
private
slots
:
void
rebuild
();
void
activate
(
QAction
*
);
signals:
void
activated
(
const
QModelIndex
&
index
);
};
#endif
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