the controls slides in and out with an animation depending on mouse
events svn path=/trunk/KDE/kdelibs/; revision=925207
This commit is contained in:
parent
8035d0f4de
commit
1e4e0d86b4
|
@ -20,6 +20,7 @@
|
||||||
#include "videowidget.h"
|
#include "videowidget.h"
|
||||||
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QTimer>
|
||||||
#include <QGraphicsLinearLayout>
|
#include <QGraphicsLinearLayout>
|
||||||
#include <QGraphicsSceneResizeEvent>
|
#include <QGraphicsSceneResizeEvent>
|
||||||
|
|
||||||
|
@ -40,8 +41,11 @@ namespace Plasma
|
||||||
class VideoWidgetPrivate
|
class VideoWidgetPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VideoWidgetPrivate()
|
VideoWidgetPrivate(VideoWidget *video)
|
||||||
: ticking(false),
|
: q(video),
|
||||||
|
ticking(false),
|
||||||
|
animId(0),
|
||||||
|
hideTimer(0),
|
||||||
shownControls(VideoWidget::NoControls),
|
shownControls(VideoWidget::NoControls),
|
||||||
controlsWidget(0),
|
controlsWidget(0),
|
||||||
playButton(0),
|
playButton(0),
|
||||||
|
@ -67,8 +71,13 @@ public:
|
||||||
void showOpenFileDialog();
|
void showOpenFileDialog();
|
||||||
void openFile(const QString &path);
|
void openFile(const QString &path);
|
||||||
void stateChanged(Phonon::State newState, Phonon::State oldState);
|
void stateChanged(Phonon::State newState, Phonon::State oldState);
|
||||||
|
void animateControlWidget(bool show);
|
||||||
|
void hideControlWidget();
|
||||||
|
void slidingCompleted(QGraphicsItem *item);
|
||||||
|
|
||||||
|
|
||||||
|
VideoWidget *q;
|
||||||
|
|
||||||
Phonon::VideoWidget *videoWidget;
|
Phonon::VideoWidget *videoWidget;
|
||||||
Phonon::AudioOutput *audioOutput;
|
Phonon::AudioOutput *audioOutput;
|
||||||
Phonon::MediaObject *media;
|
Phonon::MediaObject *media;
|
||||||
|
@ -76,6 +85,8 @@ public:
|
||||||
bool ticking;
|
bool ticking;
|
||||||
|
|
||||||
//control widgets
|
//control widgets
|
||||||
|
int animId;
|
||||||
|
QTimer *hideTimer;
|
||||||
VideoWidget::Controls shownControls;
|
VideoWidget::Controls shownControls;
|
||||||
QGraphicsWidget *controlsWidget;
|
QGraphicsWidget *controlsWidget;
|
||||||
IconWidget *playButton;
|
IconWidget *playButton;
|
||||||
|
@ -150,11 +161,57 @@ void VideoWidgetPrivate::stateChanged(Phonon::State newState, Phonon::State oldS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoWidgetPrivate::animateControlWidget(bool show)
|
||||||
|
{
|
||||||
|
if (!controlsWidget || controlsWidget->isVisible() == show) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint oldPos(0,0);
|
||||||
|
QPoint newPos(0,0);
|
||||||
|
|
||||||
|
if (show) {
|
||||||
|
oldPos = QPoint(0, -controlsWidget->size().height());
|
||||||
|
} else {
|
||||||
|
newPos = QPoint(0, -controlsWidget->size().height());
|
||||||
|
}
|
||||||
|
|
||||||
|
controlsWidget->setPos(oldPos);
|
||||||
|
controlsWidget->show();
|
||||||
|
|
||||||
|
animId = Animator::self()->moveItem(
|
||||||
|
controlsWidget, Plasma::Animator::SlideOutMovement,
|
||||||
|
newPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetPrivate::hideControlWidget()
|
||||||
|
{
|
||||||
|
animateControlWidget(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetPrivate::slidingCompleted(QGraphicsItem *item)
|
||||||
|
{
|
||||||
|
Q_UNUSED(item)
|
||||||
|
|
||||||
|
animId = 0;
|
||||||
|
|
||||||
|
if (!controlsWidget) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (controlsWidget->pos().y() < 0) {
|
||||||
|
controlsWidget->hide();
|
||||||
|
} else {
|
||||||
|
hideTimer->start(3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VideoWidget::VideoWidget(QGraphicsWidget *parent)
|
VideoWidget::VideoWidget(QGraphicsWidget *parent)
|
||||||
: QGraphicsProxyWidget(parent),
|
: QGraphicsProxyWidget(parent),
|
||||||
d(new VideoWidgetPrivate)
|
d(new VideoWidgetPrivate(this))
|
||||||
{
|
{
|
||||||
d->videoWidget = new Phonon::VideoWidget;
|
d->videoWidget = new Phonon::VideoWidget;
|
||||||
d->audioOutput = new Phonon::AudioOutput(this);
|
d->audioOutput = new Phonon::AudioOutput(this);
|
||||||
|
@ -165,9 +222,14 @@ VideoWidget::VideoWidget(QGraphicsWidget *parent)
|
||||||
|
|
||||||
|
|
||||||
setWidget(d->videoWidget);
|
setWidget(d->videoWidget);
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
//FIXME: would be desiderable to have clipping on just when animating, seems that changing it on the fly messes up with visibility of children, indagate if is a qt bug
|
||||||
|
setFlags(flags()|QGraphicsItem::ItemClipsChildrenToShape);
|
||||||
|
|
||||||
connect(d->media, SIGNAL(tick(qint64)), this, SIGNAL(tick(qint64)));
|
connect(d->media, SIGNAL(tick(qint64)), this, SIGNAL(tick(qint64)));
|
||||||
connect(d->media, SIGNAL(aboutToFinish()), this, SIGNAL(aboutToFinish()));
|
connect(d->media, SIGNAL(aboutToFinish()), this, SIGNAL(aboutToFinish()));
|
||||||
|
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
|
||||||
|
this, SLOT(slidingCompleted(QGraphicsItem*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoWidget::~VideoWidget()
|
VideoWidget::~VideoWidget()
|
||||||
|
@ -203,12 +265,12 @@ void VideoWidget::setShownControls(Controls controls)
|
||||||
if (controls != NoControls && d->controlsWidget == 0) {
|
if (controls != NoControls && d->controlsWidget == 0) {
|
||||||
d->controlsWidget = new QGraphicsWidget(this);
|
d->controlsWidget = new QGraphicsWidget(this);
|
||||||
controlsLayout = new QGraphicsLinearLayout(Qt::Horizontal, d->controlsWidget);
|
controlsLayout = new QGraphicsLinearLayout(Qt::Horizontal, d->controlsWidget);
|
||||||
d->controlsWidget->setPos(0,0);
|
d->hideTimer = new QTimer(this);
|
||||||
d->controlsWidget->show();
|
connect(d->hideTimer, SIGNAL(timeout()), this, SLOT(hideControlWidget()));
|
||||||
d->controlsWidget->resize(size().width(), d->controlsWidget->size().height());
|
|
||||||
//controls == NoControls
|
//controls == NoControls
|
||||||
} else if (d->controlsWidget != 0) {
|
} else if (d->controlsWidget != 0) {
|
||||||
d->controlsWidget->deleteLater();
|
d->controlsWidget->deleteLater();
|
||||||
|
d->hideTimer->deleteLater();
|
||||||
d->controlsWidget = 0;
|
d->controlsWidget = 0;
|
||||||
|
|
||||||
//disconnect all the stuff that wasn't automatically disconnected 'cause widget deaths
|
//disconnect all the stuff that wasn't automatically disconnected 'cause widget deaths
|
||||||
|
@ -326,6 +388,10 @@ void VideoWidget::setShownControls(Controls controls)
|
||||||
d->openFileButton = 0;
|
d->openFileButton = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controlsLayout->activate();
|
||||||
|
d->controlsWidget->setPos(0,-d->controlsWidget->size().height());
|
||||||
|
d->controlsWidget->resize(size().width(), d->controlsWidget->size().height());
|
||||||
|
d->controlsWidget->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoWidget::Controls VideoWidget::shownControls() const
|
VideoWidget::Controls VideoWidget::shownControls() const
|
||||||
|
@ -394,6 +460,35 @@ void VideoWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
if (d->controlsWidget) {
|
||||||
|
d->animateControlWidget(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
if (d->controlsWidget) {
|
||||||
|
d->hideTimer->start(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
d->hideTimer->start(3000);
|
||||||
|
|
||||||
|
if (d->controlsWidget && !d->controlsWidget->isVisible()) {
|
||||||
|
d->animateControlWidget(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
|
||||||
#include <videowidget.moc>
|
#include <videowidget.moc>
|
||||||
|
|
|
@ -178,6 +178,9 @@ Q_SIGNALS:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||||
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VideoWidgetPrivate * const d;
|
VideoWidgetPrivate * const d;
|
||||||
|
@ -190,6 +193,8 @@ private:
|
||||||
Q_PRIVATE_SLOT(d, void volumeChanged(qreal value))
|
Q_PRIVATE_SLOT(d, void volumeChanged(qreal value))
|
||||||
Q_PRIVATE_SLOT(d, void showOpenFileDialog())
|
Q_PRIVATE_SLOT(d, void showOpenFileDialog())
|
||||||
Q_PRIVATE_SLOT(d, void stateChanged(Phonon::State newState, Phonon::State oldState))
|
Q_PRIVATE_SLOT(d, void stateChanged(Phonon::State newState, Phonon::State oldState))
|
||||||
|
Q_PRIVATE_SLOT(d, void hideControlWidget())
|
||||||
|
Q_PRIVATE_SLOT(d, void slidingCompleted(QGraphicsItem *item))
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
|
Loading…
Reference in New Issue
Block a user