|
|
@@ -1,5 +1,5 @@ |
|
|
|
|
|
|
|
|
#include <QMenu> |
|
|
#include <QWindow> |
|
|
#include <QScreen> |
|
|
#include <QImageWriter> |
|
@@ -10,6 +10,7 @@ |
|
|
#include "qgsvectorlayer.h" |
|
|
#include "qgsproject.h" |
|
|
#include "qgsmessagelog.h" |
|
|
#include "qgisapp.h" |
|
|
|
|
|
QgsAppScreenShots::QgsAppScreenShots( const QString &saveDirectory ) |
|
|
: mSaveDirectory( saveDirectory ) |
|
@@ -27,14 +28,9 @@ void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, Gr |
|
|
int w = -1; |
|
|
int h = -1; |
|
|
|
|
|
QScreen *screen = QGuiApplication::primaryScreen(); |
|
|
QScreen *scr = screen( widget ); |
|
|
if ( widget ) |
|
|
{ |
|
|
const QWindow *window = widget->windowHandle(); |
|
|
if ( window ) |
|
|
{ |
|
|
screen = window->screen(); |
|
|
} |
|
|
widget->raise(); |
|
|
if ( mode == GrabWidget ) |
|
|
{ |
|
@@ -52,7 +48,7 @@ void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, Gr |
|
|
} |
|
|
if ( !widget || mode != GrabWidget ) |
|
|
{ |
|
|
pix = screen->grabWindow( 0, x, y, w, h ); |
|
|
pix = scr->grabWindow( 0, x, y, w, h ); |
|
|
} |
|
|
|
|
|
const QString &fileName = mSaveDirectory + "/" + name + ".png"; |
|
@@ -61,15 +57,57 @@ void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, Gr |
|
|
QgsMessageLog::logMessage( QString( "Screenshot saved: %1 (%2)" ).arg( fileName, metaEnum.key( mode ) ) ); |
|
|
} |
|
|
|
|
|
void QgsAppScreenShots::moveWidgetTo( QWidget *widget, Qt::Corner corner, Reference reference ) |
|
|
{ |
|
|
QRect screenGeom; |
|
|
switch ( reference ) |
|
|
{ |
|
|
case Screen: |
|
|
screenGeom = screen( widget )->geometry(); |
|
|
break; |
|
|
case Widget: |
|
|
case QgisApp: |
|
|
// TODO |
|
|
return; |
|
|
} |
|
|
|
|
|
switch ( corner ) |
|
|
{ |
|
|
case Qt::BottomLeftCorner: |
|
|
widget->move( 0, screenGeom.height() - widget->frameGeometry().height() ); |
|
|
break; |
|
|
case Qt::BottomRightCorner: |
|
|
case Qt::TopRightCorner: |
|
|
case Qt::TopLeftCorner: |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
QScreen *QgsAppScreenShots::screen( QWidget *widget ) |
|
|
{ |
|
|
QScreen *screen = QGuiApplication::primaryScreen(); |
|
|
if ( widget ) |
|
|
{ |
|
|
const QWindow *window = widget->windowHandle(); |
|
|
if ( window ) |
|
|
{ |
|
|
screen = window->screen(); |
|
|
} |
|
|
} |
|
|
return screen; |
|
|
} |
|
|
|
|
|
void QgsAppScreenShots::takeScreenshots( Categories categories ) |
|
|
{ |
|
|
if ( !categories || categories.testFlag( VectorLayerProperties ) ) |
|
|
takeVectorLayerProperties(); |
|
|
} |
|
|
|
|
|
// !!!!! SCREENSHOTS !!!! |
|
|
|
|
|
void QgsAppScreenShots::takeVectorLayerProperties() |
|
|
{ |
|
|
QgsVectorLayerProperties *dlg = new QgsVectorLayerProperties( mVectorLayer ); |
|
|
QgsVectorLayerProperties *dlg = new QgsVectorLayerProperties( mVectorLayer, QgisApp::instance() ); |
|
|
dlg->show(); |
|
|
// ---------------- |
|
|
// do all the pages |
|
@@ -80,14 +118,20 @@ void QgsAppScreenShots::takeVectorLayerProperties() |
|
|
QCoreApplication::processEvents(); |
|
|
QString name = dlg->mOptionsListWidget->item( row )[0].text().toLower(); |
|
|
name.replace( " ", "_" ); |
|
|
saveScreenshot( name, dlg ); |
|
|
//saveScreenshot( name, dlg ); |
|
|
} |
|
|
// ------------------ |
|
|
// style menu clicked |
|
|
dlg->mOptionsListWidget->setCurrentRow( 0 ); |
|
|
dlg->adjustSize(); |
|
|
moveWidgetTo( dlg, Qt::BottomLeftCorner ); |
|
|
QCoreApplication::processEvents(); |
|
|
dlg->mBtnStyle->click(); |
|
|
QCoreApplication::processEvents(); |
|
|
saveScreenshot( "style", dlg ); |
|
|
QCoreApplication::processEvents(); |
|
|
dlg->mBtnStyle->menu()->hide(); |
|
|
QCoreApplication::processEvents(); |
|
|
|
|
|
// exit properly |
|
|
dlg->close(); |
|
|