/* smplayer, GUI front-end for mplayer.
Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
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) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), Trolltech ASA
(or its successors, if any) and the KDE Free Qt Foundation, which shall
act as a proxy defined in Section 6 of version 3 of the license.
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, see <http://www.gnu.org/licenses/>.
*/
#define CODE_FOR_CLICK 1 // 0 = old code, 1 = code copied from QSlider, 2 = button swap
#include "Slider.h"
#include <QApplication>
#include <QMouseEvent>
#if CODE_FOR_CLICK <= 1
#include <QStyle>
#if CODE_FOR_CLICK == 1
#include <QStyleOption>
#endif
#endif
#if QT_VERSION < 0x040300
#define initStyleOption initStyleOption_Qt430
#endif //QT_VERSION
Slider::Slider(QWidget *parent):
QSlider(parent)
{
setOrientation(Qt::Horizontal);
setMouseTracking(true); //mouseMoveEvent without press.
}
Slider::~Slider()
{
}
#if CODE_FOR_CLICK == 1
// Function copied from qslider.cpp
inline int Slider::pick(const QPoint &pt) const
{
return orientation() == Qt::Horizontal ? pt.x() : pt.y();
}
// Function copied from qslider.cpp and modified to make it compile
void Slider::initStyleOption_Qt430(QStyleOptionSlider *option) const
{
if (!option)
return;
option->initFrom(this);
option->subControls = QStyle::SC_None;
option->activeSubControls = QStyle::SC_None;
option->orientation = orientation();
option->maximum = maximum();
option->minimum = minimum();
option->tickPosition = (QSlider::TickPosition) tickPosition();
option->tickInterval = tickInterval();
option->upsideDown = (orientation() == Qt::Horizontal) ?
(invertedAppearance() != (option->direction == Qt::RightToLeft))
: (!invertedAppearance());
option->direction = Qt::LeftToRight; // we use the upsideDown option instead
option->sliderPosition = sliderPosition();
option->sliderValue = value();
option->singleStep = singleStep();
option->pageStep = pageStep();
if (orientation() == Qt::Horizontal)
option->state |= QStyle::State_Horizontal;
}
// Function copied from qslider.cpp and modified to make it compile
int Slider::pixelPosToRangeValue(int pos) const
{
QStyleOptionSlider opt;
initStyleOption(&opt);
QRect gr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
int sliderMin, sliderMax, sliderLength;
if (orientation() == Qt::Horizontal) {
sliderLength = sr.width();
sliderMin = gr.x();
sliderMax = gr.right() - sliderLength + 1;
} else {
sliderLength = sr.height();
sliderMin = gr.y();
sliderMax = gr.bottom() - sliderLength + 1;
}
return QStyle::sliderValueFromPosition(minimum(), maximum(), pos - sliderMin,
sliderMax - sliderMin, opt.upsideDown);
}
void Slider::enterEvent(QEvent *event)
{
emit onEnter();
QSlider::enterEvent(event);
}
void Slider::leaveEvent(QEvent *e)
{
emit onLeave();
QSlider::leaveEvent(e);
}
void Slider::mouseMoveEvent(QMouseEvent *e)
{
const int o = style()->pixelMetric(QStyle::PM_SliderLength ) - 1;
int v = QStyle::sliderValueFromPosition(minimum(), maximum(), e->pos().x()-o/2, width()-o, false);
emit onHover(e->x(), v);
QSlider::mouseMoveEvent(e);
}
// Based on code from qslider.cpp
void Slider::mousePressEvent(QMouseEvent *e)
{
qDebug("pressed (%d, %d)", e->pos().x(), e->pos().y());
if (e->button() == Qt::LeftButton) {
QStyleOptionSlider opt;
initStyleOption(&opt);
const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
const QPoint center = sliderRect.center() - sliderRect.topLeft();
// to take half of the slider off for the setSliderPosition call we use the center - topLeft
if (!sliderRect.contains(e->pos())) {
qDebug("accept");
e->accept();
int v = pixelPosToRangeValue(pick(e->pos() - center));
setSliderPosition(v);
triggerAction(SliderMove);
setRepeatAction(SliderNoAction);
emit sliderMoved(v);//TODO: ok?
emit sliderPressed(); //TODO: ok?
} else {
QSlider::mousePressEvent(e);
}
} else {
QSlider::mousePressEvent(e);
}
}
#endif // CODE_FOR_CLICK == 1
#if CODE_FOR_CLICK == 2
void Slider::mousePressEvent(QMouseEvent *e)
{
// Swaps middle button click with left click
if (e->button() == Qt::LeftButton) {
QMouseEvent ev2(QEvent::MouseButtonRelease, e->pos(), e->globalPos(), Qt::MidButton, Qt::MidButton, e->modifiers());
QSlider::mousePressEvent(&ev2);
} else if (e->button() == Qt::MidButton) {
QMouseEvent ev2(QEvent::MouseButtonRelease, e->pos(), e->globalPos(), Qt::LeftButton, Qt::LeftButton, e->modifiers());
QSlider::mousePressEvent(&ev2);
}
else {
QSlider::mousePressEvent(e);
}
}
#endif // CODE_FOR_CLICK == 2
#if CODE_FOR_CLICK == 0
void Slider::mousePressEvent(QMouseEvent *e)
{
// FIXME:
// The code doesn't work well with right to left layout,
// so it's disabled.
if (qApp->isRightToLeft()) {
QSlider::mousePressEvent(e);
return;
}
int range = maximum()-minimum();
int pos = (e->x() * range) / width();
//qDebug( "width: %d x: %d", width(), e->x());
//qDebug( "range: %d pos: %d value: %d", range, pos, value());
// Calculate how many positions takes the slider handle
int metric = qApp->style()->pixelMetric(QStyle::PM_SliderLength);
double one_tick_pixels = (double)width() / range;
int slider_handle_positions = (int)(metric / one_tick_pixels);
/*
qDebug("metric: %d", metric );
qDebug("one_tick_pixels :%f", one_tick_pixels);
qDebug("width() :%d", width());
qDebug("slider_handle_positions: %d", slider_handle_positions);
*/
if (abs(pos - value()) > slider_handle_positions) {
setValue(pos);
emit sliderMoved(pos);
} else {
QSlider::mousePressEvent(e);
}
}
#endif
没有合适的资源?快使用搜索试试~ 我知道了~
QtAVPlayer工程
共91个文件
h:83个
cpp:3个
lib:2个
5星 · 超过95%的资源 需积分: 44 118 下载量 124 浏览量
2017-07-11
16:12:10
上传
评论 3
收藏 235KB RAR 举报
温馨提示
自己搭建的一个基于QtAV的工程,环境是Qt5.7-VS2013,工程中有自己编译好的QtAV的相关库文件
资源推荐
资源详情
资源评论
收起资源包目录
QtAvPlayerTest.rar (91个子文件)
qtav
lib
QtAV1.lib 727KB
QtAVWidgets1.lib 70KB
include
QtAV
Frame.h 4KB
AVOutput.h 3KB
AudioResampler.h 4KB
VideoShaderObject.h 3KB
VideoFrame.h 7KB
LibAVFilter.h 4KB
EncodeFilter.h 5KB
QtAV.h 2KB
VideoDecoder.h 4KB
VideoOutput.h 6KB
AudioDecoder.h 3KB
AVTranscoder.h 5KB
SubtitleFilter.h 5KB
OpenGLRendererBase.h 3KB
private
singleton.h 3KB
AVCompat.h 18KB
OpenGLRendererBase_p.h 2KB
AVDecoder_p.h 4KB
Filter_p.h 2KB
VideoShader_p.h 6KB
prepost.h 4KB
PlayerSubtitle.h 3KB
QPainterRenderer_p.h 2KB
AVOutput_p.h 2KB
AudioResampler_p.h 2KB
SubtitleProcessor.h 4KB
VideoRenderer_p.h 5KB
mkid.h 7KB
AVEncoder_p.h 3KB
factory.h 8KB
MediaIO_p.h 2KB
Frame_p.h 2KB
AudioOutputBackend.h 6KB
SurfaceInterop.h 3KB
FactoryDefine.h 7KB
MediaIO.h 6KB
QtAV 18B
OpenGLTypes.h 6KB
Filter.h 4KB
QtAV_Global.h 6KB
AVClock.h 6KB
GLSLFilter.h 3KB
Packet.h 3KB
AVPlayer.h 25KB
FilterContext.h 7KB
AudioOutput.h 9KB
FrameReader.h 3KB
Geometry.h 6KB
AudioEncoder.h 3KB
AudioFrame.h 3KB
QPainterRenderer.h 2KB
Statistics.h 4KB
GeometryRenderer.h 3KB
VideoFormat.h 9KB
AudioFormat.h 7KB
VideoFrameExtractor.h 4KB
VideoRenderer.h 11KB
VideoEncoder.h 4KB
version.h 2KB
VideoShader.h 10KB
SubImage.h 3KB
Subtitle.h 10KB
OpenGLVideo.h 4KB
OpenGLWindowRenderer.h 4KB
AVEncoder.h 4KB
ConvolutionShader.h 2KB
VideoCapture.h 5KB
dptr.h 6KB
AVDemuxer.h 8KB
AVError.h 3KB
AVMuxer.h 3KB
AVDecoder.h 4KB
QtAVWidgets
GraphicsItemRenderer.h 5KB
WidgetRenderer.h 4KB
OpenGLWidgetRenderer.h 4KB
VideoPreviewWidget.h 2KB
QtAVWidgets.h 1KB
GLWidgetRenderer2.h 4KB
version.h 2KB
GLWidgetRenderer.h 3KB
QtAVWidgets 25B
global.h 3KB
QOpenGLWidget.h 2KB
QtAvPlayerTest.pro 2KB
playerwidget.h 595B
playerwidget.cpp 3KB
main.cpp 323B
Slider.cpp 7KB
Slider.h 2KB
共 91 条
- 1
资源评论
- q145252019-01-02还可以 11111
- MKNDG2018-07-12还可以。值得借鉴。
- SunAdiya2018-02-27还没有下载成功,先看着,qtav对于学习很有帮助。
Ray_Chang_988
- 粉丝: 21
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功