mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kutils: fix hidden media controls bugs and declare API as stable
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
6194aefb7a
commit
1e129fc882
4 changed files with 51 additions and 41 deletions
|
@ -313,6 +313,7 @@ QStringList KAbstractPlayer::protocols() const
|
|||
static QStringList s_protocols;
|
||||
if (s_protocols.isEmpty()) {
|
||||
s_protocols = option("protocol-list").toStringList();
|
||||
s_protocols.removeDuplicates();
|
||||
}
|
||||
return s_protocols;
|
||||
}
|
||||
|
|
|
@ -223,7 +223,6 @@ public:
|
|||
|
||||
For an extended version of this class check out @p KMediaPlayer and @p KMediaWidget.
|
||||
|
||||
@warning The API is not stable yet and it may break in the future!
|
||||
@since 4.19
|
||||
@see KMediaPlayer, KMediaWidget
|
||||
*/
|
||||
|
@ -283,7 +282,6 @@ private:
|
|||
|
||||
@note You should construct it with parent widget, preferably a QMainWindow, so that it can be
|
||||
layered on top of it. Otherwise when a video is played the widget will be floating.
|
||||
@warning The API is not stable yet and it may break in the future!
|
||||
@since 4.19
|
||||
@see KMediaWidget
|
||||
*/
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "kmediaplayer.h"
|
||||
#include "kmediawidget.h"
|
||||
|
@ -39,9 +38,10 @@ public:
|
|||
QWidget *m_parent;
|
||||
QMainWindow *m_parenthack;
|
||||
QSize m_parentsizehack;
|
||||
QElapsedTimer m_timer;
|
||||
int m_timerid;
|
||||
QString m_path;
|
||||
bool m_replay;
|
||||
bool m_visible;
|
||||
Ui_KMediaWidgetPrivate *m_ui;
|
||||
};
|
||||
|
||||
|
@ -84,12 +84,16 @@ KMediaWidget::KMediaWidget(QWidget *parent, KMediaOptions options)
|
|||
}
|
||||
|
||||
if (options & HiddenControls) {
|
||||
d->m_visible = true;
|
||||
setMouseTracking(true);
|
||||
}
|
||||
}
|
||||
|
||||
KMediaWidget::~KMediaWidget()
|
||||
{
|
||||
if (d->m_timerid >= 0) {
|
||||
killTimer(d->m_timerid);
|
||||
}
|
||||
d->m_player->stop();
|
||||
d->m_player->deleteLater();
|
||||
delete d->m_ui;
|
||||
|
@ -110,8 +114,10 @@ void KMediaWidget::open(const QString path)
|
|||
d->m_ui->w_position->setEnabled(d->m_player->isSeekable());
|
||||
|
||||
if (d->m_options & HiddenControls) {
|
||||
startTimer(200);
|
||||
d->m_timer.start();
|
||||
if (d->m_timerid >= 0) {
|
||||
killTimer(d->m_timerid);
|
||||
}
|
||||
d->m_timerid = startTimer(3000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,30 +241,61 @@ void KMediaWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
void KMediaWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->m_options & HiddenControls) {
|
||||
d->m_timer.restart();
|
||||
if (d->m_timerid >= 0) {
|
||||
killTimer(d->m_timerid);
|
||||
}
|
||||
d->m_timerid = startTimer(3000);
|
||||
_updateControls(true);
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void KMediaWidget::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (d->m_timer.elapsed() > 3000
|
||||
if (event->timerId() == d->m_timerid
|
||||
&& !d->m_ui->w_play->isDown()
|
||||
&& !d->m_ui->w_position->isSliderDown()
|
||||
&& !d->m_ui->w_volume->isSliderDown()
|
||||
&& !d->m_ui->w_fullscreen->isDown()) {
|
||||
_updateControls(false);
|
||||
} else {
|
||||
_updateControls(true);
|
||||
}
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void KMediaWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void KMediaWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const QList<QUrl> urls = event->mimeData()->urls();
|
||||
QStringList invalid;
|
||||
foreach (const QUrl url, urls) {
|
||||
QString urlstring = url.toString();
|
||||
if (!d->m_player->isPathSupported(urlstring)) {
|
||||
kDebug() << i18n("ignoring unsupported:\n%1", urlstring);
|
||||
invalid.append(urlstring);
|
||||
continue;
|
||||
}
|
||||
open(urlstring);
|
||||
}
|
||||
if (!invalid.isEmpty()) {
|
||||
QMessageBox::warning(this, i18n("Invalid paths"),
|
||||
i18n("Some paths are invalid:\n%1", invalid.join("\n")));
|
||||
} else {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void KMediaWidget::_updateControls(const bool visible)
|
||||
{
|
||||
if (visible != d->m_ui->w_frame->isVisible()) {
|
||||
if (visible != d->m_visible) {
|
||||
d->m_ui->w_frame->setVisible(visible);
|
||||
emit controlsHidden(visible);
|
||||
d->m_visible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,7 +366,9 @@ void KMediaWidget::_updateFinished()
|
|||
|
||||
if (d->m_options & HiddenControls) {
|
||||
// show the controls until the next open
|
||||
d->m_timer.invalidate();
|
||||
if (d->m_timerid >= 0) {
|
||||
killTimer(d->m_timerid);
|
||||
}
|
||||
_updateControls(true);
|
||||
}
|
||||
_updatePlay(true);
|
||||
|
@ -349,32 +388,5 @@ void KMediaWidget::_updateError(const QString error)
|
|||
d->m_ui->w_position->setEnabled(false);
|
||||
}
|
||||
|
||||
void KMediaWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void KMediaWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const QList<QUrl> urls = event->mimeData()->urls();
|
||||
QStringList invalid;
|
||||
foreach (const QUrl url, urls) {
|
||||
QString urlstring = url.toString();
|
||||
if (!d->m_player->isPathSupported(urlstring)) {
|
||||
kDebug() << i18n("ignoring unsupported:\n%1", urlstring);
|
||||
invalid.append(urlstring);
|
||||
continue;
|
||||
}
|
||||
open(urlstring);
|
||||
}
|
||||
if (!invalid.isEmpty()) {
|
||||
QMessageBox::warning(this, i18n("Invalid paths"),
|
||||
i18n("Some paths are invalid:\n%1", invalid.join("\n")));
|
||||
} else {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_kmediawidget.cpp"
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <QMainWindow>
|
||||
#include <QElapsedTimer>
|
||||
#include <QMouseEvent>
|
||||
#include <kmediaplayer_export.h>
|
||||
#include <kmediaplayer.h>
|
||||
|
||||
|
@ -49,7 +49,6 @@ class KMediaWidgetPrivate;
|
|||
layered on top of it. Otherwise when a video is played the widget will be floating. Ensuring
|
||||
that the widget has parent is a key to the fullscreen support as it will ask the parent to
|
||||
maximize itself when that needs to happen to ensure that the media controls are visible.
|
||||
@warning The API is not stable yet and it may break in the future!
|
||||
@see KMediaPlayer
|
||||
@todo keyboard shortcuts
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue