📄 view.cpp
字号:
#include <QtGui>
#include "view.h"
#include "USB.h"
#include <qdatetime.h>
#include <qstring.h>
#include <qmessagebox.h>
#include "ui_new.h"
Highlight::view::view():timer(NULL)
{
plabel = new QLabel;
plabel->setBackgroundRole(QPalette::Base);
plabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
plabel->setAlignment(Qt::AlignCenter);
plabel->setScaledContents(true);
//scrollArea = new QScrollArea;
//scrollArea->setBackgroundRole(QPalette::Dark);
//scrollArea->setWidget(plabel);
//setCentralWidget(scrollArea);
layout = new QVBoxLayout();
layout->addWidget(plabel);
setLayout(layout);
addAction();
createMenu();
setWindowTitle(tr("viewer"));
format = "bmp";
direction = QDir::currentPath();
//resize(640,480);
QWidget::showFullScreen();
}
void Highlight::view::addAction()
{
act_start = new QAction(tr("start"),this);
act_start->setShortcut(tr("ctrl+s"));
QObject::connect(act_start,SIGNAL(triggered()), this,SLOT(start()));
act_close = new QAction(tr("close"),this);
act_close->setShortcut(tr("ctrl+c"));
act_close->setEnabled(false);
QObject::connect(act_close,SIGNAL(triggered()),this,SLOT(end()));
act_exit = new QAction(tr("exit"),this);
act_exit->setShortcut(tr("ctrl+e"));
QObject::connect(act_exit,SIGNAL(triggered()),this,SLOT(exit()));
act_capture = new QAction(tr("capture"),this);
act_capture->setShortcut(tr("ctrl+p"));
QObject::connect(act_capture,SIGNAL(triggered()),this,SLOT(capture()));
act_help = new QAction(tr("help"),this);
act_help->setShortcut(tr("ctrl+h"));
QObject::connect(act_help,SIGNAL(triggered()),this,SLOT(capture()));
act_fullscreen = new QAction(tr("Full Screen"),this);
act_fullscreen->setShortcut(tr("ctrl+e"));
QObject::connect(act_fullscreen,SIGNAL(triggered()),this,SLOT(showFullScreen()));
act_savepicture = new QAction(tr("Save Picture"),this);
act_savepicture->setShortcut(tr("ctrl+a"));
QObject::connect(act_savepicture,SIGNAL(triggered()),this,SLOT(savePicture()));
act_option = new QAction(tr("Option"),this);
act_option->setShortcut(tr("ctrl+o"));
QObject::connect(act_option,SIGNAL(triggered()),this,SLOT(option()));
start();
}
void Highlight::view::capture()
{
}
void Highlight::view::end()
{
device.closeDevice();
act_start->setEnabled(true);
act_close->setEnabled(false);
}
void Highlight::view::createMenu()
{
fileMenu = new QMenu(tr("&File"),this);
fileMenu->addAction(act_start);
fileMenu->addAction(act_close);
fileMenu->addSeparator();
fileMenu->addAction(act_exit);
popupMenu = new QMenu(this);
popupMenu->addAction(act_start);
popupMenu->addAction(act_close);
popupMenu->addAction(act_savepicture);
popupMenu->addSeparator();
popupMenu->addAction(act_exit);
popupMenu->addAction(act_option);
toolMenu = new QMenu(tr("&Tools"));
toolMenu->addAction(act_capture);
toolMenu->addAction(act_fullscreen);
//menuBar()->addMenu(fileMenu);
//menuBar()->addMenu(toolMenu);
}
void Highlight::view::exit()
{
//end();
if(act_close->isEnabled())
{
end();
}
QWidget::close();
}
void Highlight::view::start()
{
do
{
if(!device.openDevice())
return;
if(!device.initDevice())
return;
}while(false);
act_start->setEnabled(false);
act_close->setEnabled(true);
timer = new QTimer(this);
if(QObject::connect(timer,SIGNAL(timeout()), this, SLOT(update())))
{
#ifdef MYDEBUGE
Log.DoLog("connect success!\n");
#endif
}
timer->start(1);
#ifdef MYDEBUGE
Log.DoLog("timer!\n");
#endif
}
void Highlight::view::readPicture()
{
//QImage img(tr("Sunset.jpg"));
//plabel->setPixmap(QPixmap::fromImage(img));
//plabel->adjustSize();
}
void Highlight::view::help()
{
}
void Highlight::view::startCapture()
{
}
void Highlight::view::update()
{
if(device.isopen()&&device.isshow())
{
device.readData();
unsigned char* temp = device.getBuffer();
displayWidth = device.getCurrentWidth();//QImage img(device._WIDTH,device._HEIGHT,QImage::Format_RGB32);
displayHeight = device.getCurrentHeight();
static QImage img(displayWidth, displayHeight,QImage::Format_RGB32);
Log.DoLog( "QImage w %d, h %d\n", displayWidth, displayHeight);
unsigned char* tempImg = img.bits();
memcpy(tempImg, temp, displayWidth * displayHeight * 4);
/*for(int i=0;i<320*240;++i)
{
memcpy(&tempImg[4*i],&temp[3*i],3);
}*/
pixmap = QPixmap::fromImage(img);
plabel->setPixmap(pixmap);
}
}
void Highlight::view::mouseReleaseEvent ( QMouseEvent * event )
{
/*if (Qt::LeftButton == event->button())
{
popupMenu->popup(event->globalPos());
}*/
if(Qt::RightButton == event->button())
savePicture();
}
void Highlight::view::showFullScreen()
{
QWidget::showFullScreen();
}
void Highlight::view::savePicture()
{
if(device.isopen()&&device.isshow())
{
int i=0;
device.playMode(true);
while(i++<4)
{
device.readData();
unsigned char* temp = device.getBuffer();
displayWidth = device.getCurrentWidth();
displayHeight = device.getCurrentHeight();
Log.DoLog( "picing...w: %d, h: %d\n", displayWidth, displayHeight);
QImage img(displayWidth, displayHeight,QImage::Format_RGB32);
unsigned char* tempImg = img.bits();
memcpy(tempImg, temp, displayWidth * displayHeight * 4);
pixmap = QPixmap::fromImage(img);
if(3==i)
{
QTime time;
time = QTime::currentTime();
QString filename = time.toString("hh_mm_ss_zzz");
filename +="."+format;
filename = direction +"/"+filename;
pixmap.save(filename,format.toAscii());
}
sleep(1);
//device.playMode(false);
}
device.playMode(false);
}
}
void Highlight::view::option()
{
Ui::ImageSetting imgDlg(this);
//imgDlg.show();
imgDlg.exec();
#ifdef MYDEBUGE
Log.DoLog("option is called");
#endif
}
void Highlight::view::setFormat(const QString& newFormat)
{
format = newFormat;
}
QString Highlight::view::getFormat()
{
return format;
}
void Highlight::view::setDirection(const QString& newDirection)
{
direction = newDirection;
}
QString Highlight::view::getDirection()
{
return direction;
}
void Highlight::view::setContrast(int contrast)
{
device.setContrast(contrast);
}
void Highlight::view::setBrightness(int brightness)
{
device.setBrightness(brightness);
}
void Highlight::view::setHue(int hue)
{
device.setHue(hue);
}
void Highlight::view::setPlayMode(bool isHigh)
{
device.playMode(isHigh);
}
void Highlight::view::mouseDoubleClickEvent ( QMouseEvent * event )
{
option();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -