資源簡介
很好的ubuntu opencv qt 三位一體的攝像頭源碼,有很強(qiáng)的實(shí)用性,請(qǐng)下載參考
代碼片段和文件信息
#include?“fullScreenWidget.h“
fullScreenWidget::fullScreenWidget()
{
??setWindowState(Qt::WindowActive|Qt::WindowFullScreen);
??tipWidth?=?300;?//溫馨提示框的寬度
??tipHeight?=?100;?//溫馨提示框的高度
??infoWidth?=?100;?//坐標(biāo)信息框的寬度
??infoHeight?=?50;?//坐標(biāo)信息框的高度
??initFullScreenWidget();
}
void?fullScreenWidget::initSelectedMenu()
{
??savePixmapAction?=?new?QAction(tr(“保存選區(qū)“)this);
??cancelAction?=?new?QAction(tr(“重選“)this);
??quitAction?=?new?QAction(tr(“退出“)this);
??contextMenu?=?new?QMenu(this);
??connect(savePixmapActionSIGNAL(triggered())thisSLOT(savePixmap()));
??connect(cancelActionSIGNAL(triggered())thisSLOT(cancelSelectedRect()));
??connect(quitActionSIGNAL(triggered())thisSLOT(hide()));
}
void?fullScreenWidget::savePixmap()
{
??QString?fileName;
??fileName?=?QFileDialog::getSaveFileName(thistr(“保存圖片“)QDir::currentPath()tr(“Images?(*.jpg?*.png?*.bmp)“));
??if(fileName.isNull())
????return;
??
??shotPixmap.save(fileName);
??hide();
}
void?fullScreenWidget::loadBackgroundPixmap(const?QPixmap?&bgPixmap)
{
??int?widthheight;
??width?=?QApplication::desktop()->size().width();
??height?=?QApplication::desktop()->size().height();
??loadBackgroundPixmap(bgPixmap00widthheight);
}
void?fullScreenWidget::loadBackgroundPixmap(const?QPixmap?&bgPixmap?int?x?int?y?int?width?int?height)
{
??loadPixmap?=?bgPixmap;
??screenx?=?x;
??screeny?=?y;
??screenwidth?=?width;
??screenheight?=?height;
??initFullScreenWidget();
}
QPixmap?fullScreenWidget::getFullScreenPixmap()
{
??initFullScreenWidget();
??QPixmap?result?=?QPixmap();
??result?=?QPixmap::grabWindow(QApplication::desktop()->winId());?//抓取當(dāng)前屏幕的圖片
??
??return?result;
}
void?fullScreenWidget::paintEvent(QPaintEvent?*event)
{
??QColor?shadowColor;
??shadowColor=?QColor(000100);?//陰影顏色設(shè)置
??painter.begin(this);?//進(jìn)行重繪
??painter.setPen(QPen(Qt::blue2Qt::SolidLineQt::FlatCap));//設(shè)置畫筆
??painter.drawPixmap(screenxscreenyloadPixmap);?//將背景圖片畫到窗體上
??painter.fillRect(screenxscreenyscreenwidthscreenheightshadowColor);?//畫影罩效果
??switch(currentShotState){
????case?initShot:
??????drawTipsText();
??????break;
????case?beginShot:
????case?finishShot:
??????selectedRect?=?getRect(beginPointendPoint);?//獲取選區(qū)
??????drawSelectedPixmap();
??????break;
????case?beginMoveShot:
????case?finishMoveShot:
??????selectedRect?=?getMoveAllSelectedRect();?//獲取選區(qū)
??????drawSelectedPixmap();
??????break;
????case?beginControl:
????case?finishControl:
??????selectedRect?=?getMoveControlSelectedRect();
??????drawSelectedPixmap();
??????break;
????default:
??????break;
??}??
??drawXYWHInfo();?//打印坐標(biāo)信息
??painter.end();??//重繪結(jié)束
??
??if(currentShotState?==?finishMoveShot?||?currentShotState?==?finishControl){
????updateBeginEndPointValue(selectedRect);?//當(dāng)移動(dòng)完選區(qū)后,更新beginPointendPoint;為下一次移動(dòng)做準(zhǔn)備工作
??}
}
void?fullScreenWidget::keyPressEvent(QKeyEvent?*event)
{
??if(event->key()?==?Qt::Key_Escape){
????initFullScreenWidget();
????hide();
??}
}
void?fullScreenWidget::mousePressEvent(QMouseEvent?*event)
{
??//當(dāng)開始進(jìn)行拖
評(píng)論
共有 條評(píng)論