3 #include "playerpanel.h"
4 #include "minislider.h"
7 void PlayerPanel::stateChanged (int state
) {
8 qDebug() << "state changed to" << state
;
10 if (state
== QMPwidget::IdleState
) {
11 m_player
->load(playlistNext());
14 if (state
== QMPwidget::StoppedState
) {
16 m_controlpanel
->show();
19 if (state
== QMPwidget::PlayingState
&& mediaInfo().ok
) {
20 m_streamPositionSlider
->setMaxValue(mediaInfo().length
);
21 m_streamPositionSlider
->setEnabled(mediaInfo().seekable
);
25 PlayerPanel::PlayerPanel(QWidget
* parent
)
26 : m_playlistPosition(0)
30 QPalette palette
= this->palette();
31 palette
.setColor(QPalette::Window
, Qt::black
);
32 palette
.setColor(QPalette::WindowText
, Qt::gray
);
34 palette
.setColor(QPalette::Text
, Qt::gray
);
37 setFrameStyle(QFrame::Plain
| QFrame::Box
);
40 m_controlpanel
= new ControlPanel(this, this);
42 m_controlpanel
->installEventFilter(this);
44 m_layout
.setSpacing(0);
45 m_layout
.setMargin(0);
46 m_layout
.addWidget(m_controlpanel
);
51 bool PlayerPanel::eventFilter(QObject
*obj
, QEvent
*event
) {
52 if (event
->type() != QEvent::FocusIn
&& event
->type() != QEvent::FocusOut
)
55 QPalette palette
= this->palette();
56 if (event
->type() == QEvent::FocusIn
)
57 palette
.setColor(QPalette::WindowText
, Qt::yellow
);
59 palette
.setColor(QPalette::WindowText
, Qt::gray
);
65 Player
* PlayerPanel::player() { return m_player
; }
67 void PlayerPanel::setStatus(QString status
) { m_controlpanel
->setStatus(status
); }
69 int PlayerPanel::playlistCount() { return m_playlist
.size(); }
71 void PlayerPanel::shufflePlaylist() {
72 Q_ASSERT_X(m_playlist
.size()>1,"PlayerPanel","shufflePlaylist");
73 std::random_shuffle(m_playlist
.begin(), m_playlist
.end());
76 QStringList
& PlayerPanel::playlist() {
80 QString
PlayerPanel::playlistNext() {
81 Q_ASSERT_X(!m_playlist
.isEmpty(),"PlayerPanel","playlistNext");
83 if (m_playlistPosition
>=playlistCount())
84 m_playlistPosition
= 0;
86 return playlist()[m_playlistPosition
++];
89 void PlayerPanel::startPlayer()
91 m_controlpanel
->hide();
93 QStringList playerArgs
;
95 playerArgs
.append("-vo");
97 if (QSysInfo::WindowsVersion
>= QSysInfo::WV_VISTA
)
98 playerArgs
.append("direct3d,");
100 playerArgs
.append("directx,");
102 playerArgs
.append("xv,gl2,gl,x11"); // OSD rendering doesn't work with gl2 (and probably gl neither)
104 playerArgs
.append("-zoom"); // e.g. vo=x11
105 playerArgs
.append("-idx");
106 playerArgs
.append("-softvol");
108 playerArgs
.append("-nosound"); // DEBUG
110 m_player
= new Player(playerArgs
, playlistNext(), this);
111 connect(m_player
->process(), SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));
113 m_playerstatus
= new QFrame(this);
114 QGridLayout
* playerstatuslayout
= new QGridLayout
;
115 playerstatuslayout
->setColumnStretch(0,1);
116 m_playerstatus
->setLayout(playerstatuslayout
);
118 m_streamPositionSlider
= new StreamSlider(this);
119 connect(m_streamPositionSlider
, SIGNAL(valueChanged(int)), m_player
, SLOT(seek(int)));
120 connect(m_player
->process(), SIGNAL(streamPositionChanged(double)), m_streamPositionSlider
, SLOT(setValue(double)));
121 playerstatuslayout
->addWidget(m_streamPositionSlider
, 0, 0);
123 m_volumeSlider
= new VolumeSlider(this);
124 m_player
->setVolume(100);
125 m_volumeSlider
->setValue(100);
126 connect(m_volumeSlider
, SIGNAL(valueChanged(int)), m_player
, SLOT(setVolume(int)));
127 playerstatuslayout
->addWidget(m_volumeSlider
, 0, 1);
129 m_layout
.addWidget(m_playerstatus
);
131 m_playerstatus
->hide();
133 m_layout
.addWidget(m_player
);
135 m_player
->installEventFilter(this);
140 void PlayerPanel::queueMediaFile (QString
& filename
)
142 m_playlist
.append(filename
);
144 m_controlpanel
->setPlayEnabled(true);
146 if (m_playlist
.size()>1)
147 m_controlpanel
->setShuffleEnabled(true);
150 void PlayerPanel::queuePlaylistFile (QString
& filename
)
152 qDebug() << "loading playlist" << filename
;
154 QFile
playlistFile(filename
);
156 if (!playlistFile
.open(QIODevice::ReadOnly
| QIODevice::Text
)) {
157 qWarning() << "couldn't open playlist file" << filename
;
161 while (!playlistFile
.atEnd()) {
162 QString
line(playlistFile
.readLine());
163 line
= line
.left(line
.size()-1);
164 //qDebug() << "loading playlist entry" << line;
165 this->queueMediaFile(line
);
169 void PlayerPanel::queueFile (QString
& filename
)
171 if (filename
.contains(QRegExp("txt$")))
172 this->queuePlaylistFile(filename
);
174 this->queueMediaFile(filename
);
176 setStatus(QString("%2 files total in playlist now.").arg(this->playlistCount()));
179 int PlayerPanel::queueFiles (QStringList
& filenames
)
181 int oldPlaylistSize
= this->playlistCount();
183 for (int i
=0; i
<filenames
.size(); ++i
) {
184 QString
filename(filenames
[i
]);
185 this->queueFile(filename
);
188 int newPlaylistSize
= this->playlistCount();
190 int nloaded
= newPlaylistSize
- oldPlaylistSize
;
192 setStatus(QString("Loaded %1 files. %2 files total in playlist now.")
193 .arg(nloaded
).arg(newPlaylistSize
));