?上一期我們實現(xiàn)了播放、暫停、重播、倍速功能,這期來談?wù)勅绾螌崿F(xiàn)鼠標(biāo)滾輪放大縮小和移動;如果還沒看過上期,請移步
【Qt+FFmpeg】解碼播放本地視頻(一)_logani的博客-CSDN博客【Qt+FFmpeg】解碼播放本地視頻(二)——實現(xiàn)播放、暫停、重播、倍速功能_logani的博客-CSDN博客
其實播放視頻就是播放一幀一幀的圖片,鼠標(biāo)滾輪放大縮小和移動就是對繪圖事件中的圖片位置進行操作
實現(xiàn)效果
目錄
一、FFmpeg解碼流程圖
二、滾輪放大、縮小、移動功能實現(xiàn)
1.滾輪放大縮小
(1)需要定義的變量
(2)滾輪事件
(3)繪圖事件中設(shè)置
2.移動
(1)鼠標(biāo)點擊事件中記錄當(dāng)前鼠標(biāo)位置
?(2)鼠標(biāo)移動事件?
(3)鼠標(biāo)雙擊事件
一、FFmpeg解碼流程圖
二、滾輪放大、縮小、移動功能實現(xiàn)
1.滾輪放大縮小
(1)需要定義的變量
double factor;//放大縮小的倍數(shù)
int XPtInterval = 0; //平移X軸的值
int YPtInterval = 0; //平移Y軸的值
bool Pressed; //鼠標(biāo)是否被摁壓
QPoint oldPos; //舊的鼠標(biāo)位置
setMouseTracking(true);//開啟鼠標(biāo)追蹤
this->Pressed = false;
this->factor = 1.0;
this->XPtInterval = 0;
this->YPtInterval = 0;
(2)滾輪事件
void playVideoWidget::wheelEvent(QWheelEvent *event)//圖片放大縮小
{
double numDegrees = event->delta() / 8.0;
double numSteps = numDegrees / 15.0;
factor *= pow(1.1, numSteps);
if (factor< 0.07)
{
factor = 0.07;
}
else if(factor>50)
{
factor = 50;
}
update();
}
(3)繪圖事件中設(shè)置
設(shè)置放大縮小的倍數(shù),同時進行平移操作
void playVideoWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if(!this->image.isNull())//如果圖片不為空
{
painter.translate(0+ XPtInterval, 0+ YPtInterval);//進行平移
painter.drawImage(QRect(0,0,this->width()*factor,(this->height()-45)*factor),this->image);
}
}
2.移動
(1)鼠標(biāo)點擊事件中記錄當(dāng)前鼠標(biāo)位置
記錄鼠標(biāo)為點擊狀態(tài)
void playVideoWidget::mousePressEvent(QMouseEvent *event)
{
oldPos = event->pos();
Pressed = true;
}
?(2)鼠標(biāo)移動事件?
當(dāng)鼠標(biāo)按下時,獲取當(dāng)前鼠標(biāo)的位置,減去之前位置計算出移動的距離,繪圖事件中進行偏移
當(dāng)鼠標(biāo)釋放時,記錄鼠標(biāo)處于非點擊狀態(tài)?
void playVideoWidget::mouseMoveEvent(QMouseEvent *event)//移動
{
if(Pressed!=false)//按下鼠標(biāo)
{
this->setCursor(Qt::SizeAllCursor);//設(shè)置光標(biāo)
QPoint pos = event->pos();
int xPtInterval = pos.x() - oldPos.x();//計算移動的距離
int yPtInterval = pos.y() - oldPos.y();
XPtInterval += xPtInterval;//加上偏移的距離
YPtInterval += yPtInterval;
oldPos = pos;//更新位置
update();
}
}
void playVideoWidget::mouseReleaseEvent(QMouseEvent *event)//鼠標(biāo)釋放
{
Pressed = false;
this->setCursor(Qt::ArrowCursor);//設(shè)置光標(biāo)
}
(3)鼠標(biāo)雙擊事件
鼠標(biāo)雙擊復(fù)原為初始狀態(tài)
void playVideoWidget::mouseDoubleClickEvent(QMouseEvent *event)//雙擊初始化為開始
{
factor=1.0;
XPtInterval = 0;
YPtInterval = 0;
update();
}
?文章來源地址http://www.zghlxwxcb.cn/news/detail-497834.html
感謝觀看?。。?!
以上就是全部內(nèi)容,如果對您有幫助,歡迎點贊評論,或者發(fā)現(xiàn)有哪里寫錯的,歡迎指正!
文章來源:http://www.zghlxwxcb.cn/news/detail-497834.html
?
到了這里,關(guān)于【Qt+FFmpeg】鼠標(biāo)滾輪放大、縮小、移動——解碼播放本地視頻(三)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!