-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Locked aspect ratio state for Save as image/PDF" (#4880)
Sponsored by Andreas Neumann.
- Loading branch information
Showing
13 changed files
with
427 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsratiolockbutton.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsRatioLockButton : QToolButton | ||
{ | ||
%Docstring | ||
A cross platform button subclass used to represent a locked / unlocked ratio state. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsratiolockbutton.h" | ||
%End | ||
public: | ||
|
||
QgsRatioLockButton( QWidget *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Construct a new ratio lock button. | ||
Use ``parent`` to attach a parent QWidget to the button. | ||
%End | ||
|
||
void setLocked( const bool locked ); | ||
%Docstring | ||
Sets whether the button state is locked. | ||
\param locked locked state | ||
.. seealso:: locked | ||
%End | ||
|
||
bool locked() const; | ||
%Docstring | ||
Returns whether the button state is locked. | ||
:return: true if the button state is locked. | ||
.. seealso:: setLocked | ||
:rtype: bool | ||
%End | ||
|
||
signals: | ||
|
||
void lockChanged( const bool locked ); | ||
%Docstring | ||
Emitted whenever the lock state changes. | ||
%End | ||
|
||
protected: | ||
|
||
virtual void changeEvent( QEvent *e ); | ||
|
||
virtual void showEvent( QShowEvent *e ); | ||
|
||
virtual void resizeEvent( QResizeEvent *event ); | ||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsratiolockbutton.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/*************************************************************************** | ||
qgsratiolockbutton.cpp - Lock button | ||
-------------------------------------- | ||
Date : July, 2017 | ||
Copyright : (C) 2017 by Mathieu Pellerin | ||
Email : nirvn dot asia at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsratiolockbutton.h" | ||
|
||
#include <QApplication> | ||
#include <QMouseEvent> | ||
#include <QPainter> | ||
#include <QPushButton> | ||
#include <QWidget> | ||
|
||
QgsRatioLockButton::QgsRatioLockButton( QWidget *parent ) | ||
: QToolButton( parent ) | ||
, mLocked( false ) | ||
|
||
{ | ||
setMinimumSize( QSize( 24, 24 ) ); | ||
setCheckable( true ); | ||
setAutoRaise( true ); | ||
connect( this, &QPushButton::clicked, this, &QgsRatioLockButton::buttonClicked ); | ||
} | ||
|
||
void QgsRatioLockButton::setLocked( const bool locked ) | ||
{ | ||
if ( mLocked != locked ) | ||
buttonClicked(); | ||
} | ||
|
||
void QgsRatioLockButton::buttonClicked() | ||
{ | ||
mLocked = !mLocked; | ||
setDown( mLocked ); | ||
|
||
emit lockChanged( mLocked ); | ||
|
||
drawButton(); | ||
} | ||
|
||
void QgsRatioLockButton::changeEvent( QEvent *e ) | ||
{ | ||
if ( e->type() == QEvent::EnabledChange ) | ||
{ | ||
drawButton(); | ||
} | ||
QToolButton::changeEvent( e ); | ||
} | ||
|
||
void QgsRatioLockButton::showEvent( QShowEvent *e ) | ||
{ | ||
drawButton(); | ||
QToolButton::showEvent( e ); | ||
} | ||
|
||
void QgsRatioLockButton::resizeEvent( QResizeEvent *event ) | ||
{ | ||
QToolButton::resizeEvent( event ); | ||
drawButton(); | ||
} | ||
|
||
void QgsRatioLockButton::drawButton() | ||
{ | ||
QSize currentIconSize; | ||
|
||
#ifdef Q_OS_WIN | ||
currentIconSize = QSize( width() - 10, height() - 6 ); | ||
#else | ||
currentIconSize = QSize( width() - 10, height() - 12 ); | ||
#endif | ||
|
||
if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 ) | ||
{ | ||
return; | ||
} | ||
|
||
QPixmap pm; | ||
pm = QPixmap( currentIconSize ); | ||
pm.fill( Qt::transparent ); | ||
|
||
QPainter painter; | ||
QPen pen = ( QColor( 136, 136, 136 ) ); | ||
pen.setWidth( 2 ); | ||
|
||
painter.begin( &pm ); | ||
painter.setPen( pen ); | ||
|
||
painter.drawLine( 1, 1, currentIconSize.width() / 2, 1 ); | ||
painter.drawLine( currentIconSize.width() / 2, 1, currentIconSize.width() / 2, currentIconSize.height() / 2 - 13 ); | ||
painter.drawLine( currentIconSize.width() / 2, currentIconSize.height() / 2 + 13, currentIconSize.width() / 2, currentIconSize.height() - 2 ); | ||
painter.drawLine( currentIconSize.width() / 2, currentIconSize.height() - 2, 1, currentIconSize.height() - 2 ); | ||
|
||
QImage image( mLocked ? QStringLiteral( ":/images/themes/default/lockedGray.svg" ) : QStringLiteral( ":/images/themes/default/unlockedGray.svg" ) ); | ||
painter.drawImage( QRectF( currentIconSize.width() / 2 - 8, currentIconSize.height() / 2 - 8, 16, 16 ), image, QRectF( 0, 0, 16, 16 ) ); | ||
|
||
painter.end(); | ||
|
||
setIconSize( currentIconSize ); | ||
setIcon( pm ); | ||
} |
Oops, something went wrong.