Skip to content

Commit

Permalink
parent to QgisApp for proper style + move dialogs to corner so menu a…
Browse files Browse the repository at this point in the history
…re opened within dialogs
  • Loading branch information
3nids committed Oct 4, 2018
1 parent 2e1274e commit 46a58c9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
64 changes: 54 additions & 10 deletions src/app/qgsappscreenshots.cpp
@@ -1,5 +1,5 @@


#include <QMenu>
#include <QWindow>
#include <QScreen>
#include <QImageWriter>
Expand All @@ -10,6 +10,7 @@
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgsmessagelog.h"
#include "qgisapp.h"

QgsAppScreenShots::QgsAppScreenShots( const QString &saveDirectory )
: mSaveDirectory( saveDirectory )
Expand All @@ -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 )
{
Expand All @@ -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";
Expand All @@ -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
Expand All @@ -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();
Expand Down
15 changes: 12 additions & 3 deletions src/app/qgsappscreenshots.h
Expand Up @@ -3,6 +3,7 @@

#include <QObject>

class QScreen;
class QgsVectorLayer;

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

enum Reference
{
Widget,
QgisApp,
Screen
};

enum Category
{
VectorLayerProperties = 1,
Expand All @@ -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;
};
Expand Down

0 comments on commit 46a58c9

Please sign in to comment.