hotScreenLabel->addAction(savePixmap);
shotScreenLabel->setContextMenuPolicy(Qt::ActionsContextMenu);
}
void Widget::createConnects()
{
//主窗口信号槽*****************************************************************
connect(ui->pbtnShot, SIGNAL(clicked()), this, SLOT(grapWindowScreen()));
connect(ui->pbtnShotAndMin, SIGNAL(clicked()), this, SLOT(miniWindows()));
connect(ui->pbtnMin, SIGNAL(clicked()), this, SLOT(miniWindows()));
connect(savePixmap, SIGNAL(triggered()), this, SLOT(saveShotPixmap()));
//主窗口信号槽*****************************************************************
//托盘信号槽*******************************************************************
connect(restore, SIGNAL(triggered()), this, SLOT(restoreWindows()));
connect(mini, SIGNAL(triggered()), this, SLOT(miniWindows()));
connect(quit, SIGNAL(triggered()), this, SLOT(quitApplication()));
//托盘信号槽*******************************************************************
}
void Widget::createEventFilter()
{
fullScreenLabel->installEventFilter(this);
}
QString Widget::getSaveShotPixmap()
{
return QFileDialog::getSaveFileName(shotScreenLabel,
tr("Open Image"),
".",
tr("Image Files(*.JPG *.PNG)"));
}
void Widget::grapWindowScreen()
{
if (!fullScreenLabel)
{
fullScreenLabel = new QLabel();
}
//获取全屏截图fullScreenPixmap,并将其放入fullScreenLabel
fullScreenPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
fullScreenLabel->setPixmap(fullScreenPixmap);
//label全屏显示
fullScreenLabel->showFullScreen();
}
void Widget::miniWindows()
{
showMinimized();
grapWindowScreen();
}
void Widget::restoreWindows()
{
showNormal();
}
void Widget::quitApplication()
{
qApp->quit();
}
void Widget::saveShotPixmap()
{
QString fileName = getSaveShotPixmap();
if (!fileName.isNull())
{
fullScreenPixmap.save(fileName);
}
}