Skip to content
Permalink
Browse files

parent to QgisApp for proper style + move dialogs to corner so menu a…

…re opened within dialogs
  • Loading branch information
3nids committed Sep 27, 2018
1 parent 2e1274e commit 46a58c9971d5c756a1658658b2a4250ea4cf3189
Showing with 66 additions and 13 deletions.
  1. +54 −10 src/app/qgsappscreenshots.cpp
  2. +12 −3 src/app/qgsappscreenshots.h
@@ -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();
@@ -3,6 +3,7 @@

#include <QObject>

class QScreen;
class QgsVectorLayer;

class QgsAppScreenShots
@@ -17,6 +18,13 @@ class QgsAppScreenShots
};
Q_ENUM( GrabMode )

enum Reference
{
Widget,
QgisApp,
Screen
};

enum Category
{
VectorLayerProperties = 1,
@@ -31,11 +39,12 @@ class QgsAppScreenShots
void takeScreenshots( Categories categories = nullptr );

private:
void takeVectorLayerProperties();


QScreen *screen( QWidget *widget = nullptr );
void moveWidgetTo( QWidget *widget, Qt::Corner corner, Reference reference = Screen );
void saveScreenshot( const QString &name, QWidget *widget = nullptr, GrabMode mode = GrabWidgetAndFrame );

void takeVectorLayerProperties();

QString mSaveDirectory;
QgsVectorLayer *mVectorLayer = nullptr;
};

0 comments on commit 46a58c9

Please sign in to comment.
You can’t perform that action at this time.