Skip to content

Commit

Permalink
widgets: add VideoPreviewWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Feb 13, 2015
1 parent c5fa2c7 commit b8a3213
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 136 deletions.
29 changes: 21 additions & 8 deletions examples/player/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 49,6 @@
#include <QWheelEvent>
#include "Button.h"
#include "ClickableMenu.h"
#include "Preview.h"
#include "Slider.h"
#include "StatisticsView.h"
#include "TVView.h"
Expand Down Expand Up @@ -125,6 124,10 @@ MainWindow::MainWindow(QWidget *parent) :

MainWindow::~MainWindow()
{
if (m_preview) {
m_preview->close();
delete m_preview;
}
mpHistory->save();
mpPlayList->save();
if (mpVolumeSlider && !mpVolumeSlider->parentWidget()) {
Expand Down Expand Up @@ -876,6 879,15 @@ void MainWindow::seekToMSec(int msec)
void MainWindow::seek()
{
mpPlayer->seek((qint64)mpTimeSlider->value());
if (!m_preview)
return;
m_preview->setTimestamp(mpTimeSlider->value());
m_preview->preview();
const int w = 160;
const int h = 90;
m_preview->setWindowFlags(m_preview->windowFlags() |Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
m_preview->resize(w, h);
m_preview->show();
}

void MainWindow::showHideVolumeBar()
Expand Down Expand Up @@ -1223,21 1235,22 @@ void MainWindow::onTimeSliderHover(int pos, int value)
QPoint gpos = mapToGlobal(mpTimeSlider->pos() QPoint(pos, 0));
QToolTip::showText(gpos, QTime(0, 0, 0).addMSecs(value).toString("HH:mm:ss"));
if (!m_preview)
m_preview = new Preview();
m_preview = new VideoPreviewWidget();
m_preview->setFile(mpPlayer->file());
m_preview->setTimestamp(value);
m_preview->preview();
const int w = 160;
const int h = 90;
m_preview->widget()->setWindowFlags(m_preview->widget()->windowFlags() |Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
m_preview->widget()->resize(160, 90);
m_preview->widget()->move(gpos - QPoint(w/2, h));
m_preview->widget()->show();
m_preview->setWindowFlags(m_preview->windowFlags() |Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
m_preview->resize(w, h);
m_preview->move(gpos - QPoint(w/2, h));
m_preview->show();
}

void MainWindow::onTimeSliderLeave()
{
if (m_preview && m_preview->widget())
m_preview->widget()->hide();
if (m_preview && m_preview)
m_preview->hide();
}

void MainWindow::handleError(const AVError &e)
Expand Down
3 changes: 2 additions & 1 deletion examples/player/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 33,7 @@ class AVClock;
class VideoRenderer;
class LibAVFilter;
class SubtitleFilter;
class VideoPreviewWidget;
}
class QMenu;
class QTimeEdit;
Expand Down Expand Up @@ -195,7 196,7 @@ private slots:

OSDFilter *mpOSD;
QtAV::SubtitleFilter *mpSubtitle;
Preview *m_preview;
QtAV::VideoPreviewWidget *m_preview;
};


Expand Down
79 changes: 0 additions & 79 deletions examples/player/Preview.cpp

This file was deleted.

46 changes: 0 additions & 46 deletions examples/player/Preview.h

This file was deleted.

2 changes: 0 additions & 2 deletions examples/player/player.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,6 @@ SOURCES = main.cpp \
MainWindow.cpp \
Button.cpp \
ClickableMenu.cpp \
Preview.cpp \
StatisticsView.cpp \
Slider.cpp \
TVView.cpp \
Expand All @@ -43,7 42,6 @@ HEADERS = \
MainWindow.h \
Button.h \
ClickableMenu.h \
Preview.h \
StatisticsView.h \
Slider.h \
TVView.h \
Expand Down
1 change: 1 addition & 0 deletions widgets/QtAVWidgets/QtAVWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 28,6 @@
#include <QtAVWidgets/WidgetRenderer.h>
//#include <QtAVWidgets/GLWidgetRenderer.h>
#include <QtAVWidgets/GLWidgetRenderer2.h>
#include <QtAVWidgets/VideoPreviewWidget.h>

#endif // QTAVWIDGETS_H
63 changes: 63 additions & 0 deletions widgets/QtAVWidgets/VideoPreviewWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 1,63 @@
/******************************************************************************
VideoRendererTypes: type id and manually id register function
Copyright (C) 2015 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/

#ifndef QTAV_VIDEOPREVIEWWIDGET_H
#define QTAV_VIDEOPREVIEWWIDGET_H

#include <QWidget>
#include "QtAVWidgets/global.h"

namespace QtAV {

class VideoFrame;
class VideoOutput;
class VideoFrameExtractor;
class Q_AVWIDGETS_EXPORT VideoPreviewWidget : public QWidget
{
Q_OBJECT
public:
explicit VideoPreviewWidget(QWidget *parent = 0);
void setTimestamp(qint64 msec);
qint64 timestamp() const;
void preview();
void setFile(const QString& file);
QString file() const;
// default is false
void setKeepAspectRatio(bool value = true);
bool isKeepAspectRatio() const;
Q_SIGNALS:
void timestampChanged();
void fileChanged();
protected:
virtual void resizeEvent(QResizeEvent *);
private Q_SLOTS:
void displayFrame(const QtAV::VideoFrame& frame); //parameter VideoFrame
void displayNoFrame();

private:
bool m_keep_ar;
QString m_file;
VideoFrameExtractor *m_extractor;
VideoOutput *m_out;
};

} //namespace QtAV
#endif // QTAV_VIDEOPREVIEWWIDGET_H
Loading

0 comments on commit b8a3213

Please sign in to comment.