Changeset View
Standalone View
src/panels/information/phononwidget.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 86 | { | |||
---|---|---|---|---|---|
90 | } | 90 | } | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | QUrl PhononWidget::url() const | 93 | QUrl PhononWidget::url() const | ||
94 | { | 94 | { | ||
95 | return m_url; | 95 | return m_url; | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | bool PhononWidget::eventFilter(QObject *object, QEvent *event) | ||||
elvisangelaccio: Coding style: opening brace should go the next line for functions. | |||||
99 | { | ||||
100 | Q_UNUSED(object); | ||||
elvisangelaccio: Missing space before brace | |||||
101 | if (event->type() == QEvent::MouseButtonPress) { | ||||
shubham: use qobjectcast | |||||
QEvent does not inherit QObject : qobject_cast can't be used to cast its instances. meven: QEvent does not inherit QObject : qobject_cast can't be used to cast its instances. | |||||
102 | const QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); | ||||
103 | if (mouseEvent->button() == Qt::LeftButton) { | ||||
104 | // toggle playback | ||||
105 | if (m_media && m_media->state() == Phonon::State::PlayingState) { | ||||
elvisangelaccio: Unnecessary semicolon | |||||
elvisangelaccio: Still not fixed ;) | |||||
106 | m_media->pause(); | ||||
107 | } else { | ||||
108 | play(); | ||||
109 | } | ||||
110 | return true; | ||||
111 | } | ||||
112 | } | ||||
113 | return false; | ||||
114 | } | ||||
115 | | ||||
98 | void PhononWidget::setVideoSize(const QSize& size) | 116 | void PhononWidget::setVideoSize(const QSize& size) | ||
99 | { | 117 | { | ||
100 | if (m_videoSize != size) { | 118 | if (m_videoSize != size) { | ||
101 | m_videoSize = size; | 119 | m_videoSize = size; | ||
Have you tried to override mousePressEvent() instead of using an event filter? elvisangelaccio: Have you tried to override `mousePressEvent()` instead of using an event filter? | |||||
I did. m_preview->installEventFilter(m_phononWidget); meven: I did.
I needed to have an eventFilter so that I can reuse this code directly… | |||||
Why would we need that? I just tried to move this code from eventFilter() to mousePressEvent() and it seems to work fine. elvisangelaccio: Why would we need that? I just tried to move this code from `eventFilter()` to `mousePressEvent… | |||||
It is so that the preview widget can be clicked to start video playback, and thanks to this eventFilter I can reuse directly the logic for both m_phononWidget and m_preview, just use installEventFilter / removeEventFilter. Btw, my latest changes completely hide the video controls as long as the video is not playing or paused. meven: It is so that the preview widget can be clicked to start video playback, and thanks to this… | |||||
102 | applyVideoSize(); | 120 | applyVideoSize(); | ||
103 | } | 121 | } | ||
104 | } | 122 | } | ||
105 | 123 | | |||
106 | QSize PhononWidget::videoSize() const | 124 | QSize PhononWidget::videoSize() const | ||
107 | { | 125 | { | ||
108 | return m_videoSize; | 126 | return m_videoSize; | ||
109 | } | 127 | } | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
167 | } | 185 | } | ||
168 | 186 | | |||
169 | void PhononWidget::stateChanged(Phonon::State newstate) | 187 | void PhononWidget::stateChanged(Phonon::State newstate) | ||
170 | { | 188 | { | ||
171 | setUpdatesEnabled(false); | 189 | setUpdatesEnabled(false); | ||
172 | switch (newstate) { | 190 | switch (newstate) { | ||
173 | case Phonon::PlayingState: | 191 | case Phonon::PlayingState: | ||
174 | case Phonon::BufferingState: | 192 | case Phonon::BufferingState: | ||
175 | m_stopButton->show(); | | |||
176 | m_playButton->hide(); | 193 | m_playButton->hide(); | ||
194 | m_stopButton->show(); | ||||
177 | break; | 195 | break; | ||
178 | default: | 196 | default: | ||
179 | m_stopButton->hide(); | 197 | m_stopButton->hide(); | ||
180 | m_playButton->show(); | 198 | m_playButton->show(); | ||
181 | break; | 199 | break; | ||
182 | } | 200 | } | ||
183 | setUpdatesEnabled(true); | 201 | setUpdatesEnabled(true); | ||
184 | } | 202 | } | ||
185 | 203 | | |||
186 | void PhononWidget::play() | 204 | void PhononWidget::play() | ||
187 | { | 205 | { | ||
188 | if (!m_media) { | 206 | if (!m_media) { | ||
189 | m_media = new Phonon::MediaObject(this); | 207 | m_media = new Phonon::MediaObject(this); | ||
190 | connect(m_media, &Phonon::MediaObject::stateChanged, | 208 | connect(m_media, &Phonon::MediaObject::stateChanged, | ||
191 | this, &PhononWidget::stateChanged); | 209 | this, &PhononWidget::stateChanged); | ||
192 | connect(m_media, &Phonon::MediaObject::finished, | 210 | connect(m_media, &Phonon::MediaObject::finished, | ||
193 | this, &PhononWidget::finished); | 211 | this, &PhononWidget::finished); | ||
194 | m_seekSlider->setMediaObject(m_media); | 212 | m_seekSlider->setMediaObject(m_media); | ||
195 | } | 213 | } | ||
196 | 214 | | |||
197 | if (!m_videoPlayer) { | 215 | if (!m_videoPlayer) { | ||
198 | m_videoPlayer = new EmbeddedVideoPlayer(this); | 216 | m_videoPlayer = new EmbeddedVideoPlayer(this); | ||
217 | m_videoPlayer->setCursor(Qt::PointingHandCursor); | ||||
199 | m_videoPlayer->installEventFilter(this); | 218 | m_videoPlayer->installEventFilter(this); | ||
200 | m_topLayout->insertWidget(0, m_videoPlayer); | 219 | m_topLayout->insertWidget(0, m_videoPlayer); | ||
anthonyfieroni: Why 2nd time ? | |||||
Good catch, thanks meven: Good catch, thanks
The first line was added by mistake in a previous diff, making the one added… | |||||
201 | Phonon::createPath(m_media, m_videoPlayer); | 220 | Phonon::createPath(m_media, m_videoPlayer); | ||
202 | applyVideoSize(); | 221 | applyVideoSize(); | ||
203 | } | 222 | } | ||
204 | 223 | | |||
205 | if (!m_audioOutput) { | 224 | if (!m_audioOutput) { | ||
206 | m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); | 225 | m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); | ||
207 | Phonon::createPath(m_media, m_audioOutput); | 226 | Phonon::createPath(m_media, m_audioOutput); | ||
208 | } | 227 | } | ||
Show All 38 Lines |
Coding style: opening brace should go the next line for functions.