kutils: drop the hidden controls option

it is very tricky to do it correctly, especially with KMainWindow and the
like doing their thing with menu/status bars

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-29 06:20:37 +02:00
parent 7408c3b692
commit 238f9c37bc
2 changed files with 3 additions and 101 deletions

View file

@ -38,22 +38,18 @@ public:
void updatePlayText(const QString &string);
void updateStatus(const QString &string);
void updateControls(const bool visible);
KMediaWidget* m_q;
KMediaPlayer *m_player;
bool m_dragdrop;
bool m_fullscreen;
bool m_hiddencontrols;
bool m_smoothvolume;
QWidget *m_parent;
QMainWindow *m_parenthack;
QSize m_parentsizehack;
QTimeLine m_volumeline;
int m_timerid;
QString m_path;
bool m_replay;
bool m_visible;
QString m_playtext;
Ui_KMediaWidgetUI *m_ui;
};
@ -61,11 +57,9 @@ public:
KMediaWidgetPrivate::KMediaWidgetPrivate(KMediaWidget* q)
: m_q(q),
m_player(nullptr),
m_dragdrop(false), m_fullscreen(false), m_hiddencontrols(false), m_smoothvolume(false),
m_dragdrop(false), m_fullscreen(false), m_smoothvolume(false),
m_parent(nullptr), m_parenthack(nullptr),
m_timerid(0),
m_replay(false),
m_visible(false),
m_ui(nullptr)
{
}
@ -103,15 +97,6 @@ void KMediaWidgetPrivate::updateStatus(const QString &string)
}
}
void KMediaWidgetPrivate::updateControls(const bool visible)
{
if (m_hiddencontrols && visible != m_visible) {
m_ui->w_frame->setVisible(visible);
emit m_q->controlsHidden(visible);
m_visible = visible;
}
}
KMediaWidget::KMediaWidget(QWidget *parent, KMediaOptions options)
: QWidget(parent),
d(new KMediaWidgetPrivate(this))
@ -121,7 +106,6 @@ KMediaWidget::KMediaWidget(QWidget *parent, KMediaOptions options)
d->m_player = new KMediaPlayer(d->m_ui->w_player);
d->m_dragdrop = (options & DragDrop) != options;
d->m_fullscreen = (options & FullscreenVideo) != options;
d->m_hiddencontrols = (options & HiddenControls) != options;
d->m_smoothvolume = (options & SmoothVolume) != options;
d->m_parent = parent;
@ -158,18 +142,10 @@ KMediaWidget::KMediaWidget(QWidget *parent, KMediaOptions options)
if (!d->m_fullscreen) {
d->m_ui->w_fullscreen->setVisible(false);
}
if (d->m_hiddencontrols) {
d->m_visible = true;
setMouseTracking(false);
}
}
KMediaWidget::~KMediaWidget()
{
if (d->m_timerid >= 0) {
killTimer(d->m_timerid);
}
if (d->m_volumeline.state() == QTimeLine::Running) {
d->m_volumeline.stop();
setVolume(d->m_volumeline.endFrame());
@ -305,18 +281,6 @@ void KMediaWidget::setFullscreen(const int value)
}
}
void KMediaWidget::resetControlsTimer()
{
if (d->m_timerid >= 0) {
killTimer(d->m_timerid);
d->m_timerid = 0;
}
// do not hide the controls if path is not loaded
if (!d->m_player->path().isEmpty()) {
d->m_timerid = startTimer(3000);
}
}
QSize KMediaWidget::sizeHint() const
{
return d->m_ui->w_player->sizeHint();
@ -338,29 +302,6 @@ void KMediaWidget::mouseDoubleClickEvent(QMouseEvent *event)
event->ignore();
}
void KMediaWidget::mouseMoveEvent(QMouseEvent *event)
{
if (d->m_hiddencontrols) {
resetControlsTimer();
d->updateControls(true);
}
event->ignore();
}
void KMediaWidget::timerEvent(QTimerEvent *event)
{
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()) {
d->updateControls(false);
event->accept();
} else {
event->ignore();
}
}
void KMediaWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls()) {
@ -433,27 +374,11 @@ void KMediaWidget::_updateLoaded()
d->updateStatus(title);
}
_updatePlay(!d->m_player->isPlaying());
if (d->m_hiddencontrols) {
setMouseTracking(true);
resetControlsTimer();
d->updateControls(true);
}
}
void KMediaWidget::_updateFinished()
{
d->m_replay = true;
if (d->m_hiddencontrols) {
// show the controls until the next open
if (d->m_timerid >= 0) {
killTimer(d->m_timerid);
d->m_timerid = 0;
}
setMouseTracking(false);
d->updateControls(true);
}
_updatePlay(true);
}

View file

@ -65,12 +65,10 @@ public:
DragDrop = 0x1,
//! @brief Provide fullscreen option, it is such because it will ask the parent to do it
FullscreenVideo = 0x2,
//! @brief After a certain amount of time the controls will hide and show again when needed
HiddenControls = 0x4,
//! @brief Whenever path is loaded the volume is slowly increased
SmoothVolume = 0x8,
SmoothVolume = 0x4,
//! @brief All available options
AllOptions = DragDrop | FullscreenVideo | HiddenControls | SmoothVolume,
AllOptions = DragDrop | FullscreenVideo | SmoothVolume,
//! @brief Default options
DefaultOptions = NoOptions
};
@ -101,10 +99,6 @@ public:
protected:
//! @brief Reimplementation to support fullscreen
virtual void mouseDoubleClickEvent(QMouseEvent *event);
//! @brief Reimplementation to support hidden controls
virtual void mouseMoveEvent(QMouseEvent *event);
//! @brief Reimplementation to support hidden controls
virtual void timerEvent(QTimerEvent *event);
//! @brief Reimplementation to support Drag-n-Drop
virtual void dragEnterEvent(QDragEnterEvent *event);
//! @brief Reimplementation to support Drag-n-Drop
@ -143,23 +137,6 @@ public Q_SLOTS:
@see KMediaPlayer::isFullscreen, KMediaPlayer::setFullscreen
*/
void setFullscreen(const int value = -1);
/*!
@brief Reset internal media controls hide/unhide timer, simulating user interactivity
@see controlsHidden
*/
void resetControlsTimer();
Q_SIGNALS:
/*!
@brief Signals that controls were hidden/unhidden
@note This signal can be used to show/hide parent widget elements, such as menubar, when
the media controls of this widget are hidden/unhidden. You will have to setup mouse
tracking for the widgets connected (directly or indirectly) and call
@p resetControlsTimer() to ensure that this signal is not emited while the widgets
are beeing interacted with, hidding them without reason.
@see resetControlsTimer
*/
void controlsHidden(const bool hidden);
private Q_SLOTS:
void _updatePlay(const bool paused);