Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows consistent behavior and appearance across all opacity controls
- Loading branch information
1 parent
a326224
commit e58f25d
Showing
11 changed files
with
433 additions
and
0 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
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,66 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsopacitywidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsOpacityWidget : QWidget | ||
{ | ||
%Docstring | ||
A widget for setting an opacity value. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsopacitywidget.h" | ||
%End | ||
public: | ||
|
||
explicit QgsOpacityWidget( QWidget *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Constructor for QgsOpacityWidget. | ||
%End | ||
|
||
double opacity() const; | ||
%Docstring | ||
Returns the current opacity selected in the widget, where opacity ranges from 0.0 (transparent) | ||
to 1.0 (opaque). | ||
.. seealso:: setOpacity() | ||
.. seealso:: opacityChanged() | ||
:rtype: float | ||
%End | ||
|
||
public slots: | ||
|
||
void setOpacity( double opacity ); | ||
%Docstring | ||
Sets the current ``opacity`` to show in the widget, where ``opacity`` ranges from 0.0 (transparent) | ||
to 1.0 (opaque). | ||
.. seealso:: opacity() | ||
.. seealso:: opacityChanged() | ||
%End | ||
|
||
signals: | ||
|
||
void opacityChanged( double opacity ); | ||
%Docstring | ||
Emitted when the ``opacity`` is changed in the widget, where ``opacity`` ranges from 0.0 (transparent) | ||
to 1.0 (opaque). | ||
.. seealso:: setOpacity() | ||
.. seealso:: opacity() | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgsopacitywidget.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*************************************************************************** | ||
qgsopacitywidgetplugin.cpp | ||
------------------------- | ||
Date : 30.05.2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall.dawson@gmail.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 "qgiscustomwidgets.h" | ||
#include "qgsopacitywidget.h" | ||
#include "qgsopacitywidgetplugin.h" | ||
|
||
|
||
QgsOpacityWidgetPlugin::QgsOpacityWidgetPlugin( QObject *parent ) | ||
: QObject( parent ) | ||
, mInitialized( false ) | ||
{ | ||
} | ||
|
||
|
||
QString QgsOpacityWidgetPlugin::name() const | ||
{ | ||
return "QgsOpacityWidget"; | ||
} | ||
|
||
QString QgsOpacityWidgetPlugin::group() const | ||
{ | ||
return QgisCustomWidgets::groupName(); | ||
} | ||
|
||
QString QgsOpacityWidgetPlugin::includeFile() const | ||
{ | ||
return "qgsopacitywidget.h"; | ||
} | ||
|
||
QIcon QgsOpacityWidgetPlugin::icon() const | ||
{ | ||
return QIcon( ":/images/icons/qgis-icon-60x60.png" ); | ||
} | ||
|
||
bool QgsOpacityWidgetPlugin::isContainer() const | ||
{ | ||
return false; | ||
} | ||
|
||
QWidget *QgsOpacityWidgetPlugin::createWidget( QWidget *parent ) | ||
{ | ||
return new QgsOpacityWidget( parent ); | ||
} | ||
|
||
bool QgsOpacityWidgetPlugin::isInitialized() const | ||
{ | ||
return mInitialized; | ||
} | ||
|
||
void QgsOpacityWidgetPlugin::initialize( QDesignerFormEditorInterface *core ) | ||
{ | ||
Q_UNUSED( core ); | ||
if ( mInitialized ) | ||
return; | ||
mInitialized = true; | ||
} | ||
|
||
|
||
QString QgsOpacityWidgetPlugin::toolTip() const | ||
{ | ||
return tr( "A widget for specifying an opacity value." ); | ||
} | ||
|
||
QString QgsOpacityWidgetPlugin::whatsThis() const | ||
{ | ||
return tr( "A widget for specifying an opacity value." ); | ||
} | ||
|
||
QString QgsOpacityWidgetPlugin::domXml() const | ||
{ | ||
return QString( "<ui language=\"c++\">\n" | ||
" <widget class=\"%1\" name=\"mOpacityWidget\">\n" | ||
" <property name=\"geometry\">\n" | ||
" <rect>\n" | ||
" <x>0</x>\n" | ||
" <y>0</y>\n" | ||
" <width>160</width>\n" | ||
" <height>27</height>\n" | ||
" </rect>\n" | ||
" </property>\n" | ||
" </widget>\n" | ||
"</ui>\n" ) | ||
.arg( name() ); | ||
} |
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,51 @@ | ||
/*************************************************************************** | ||
qgsopacitywidgetplugin.h | ||
----------------------- | ||
Date : 30.05.2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall.dawson@gmail.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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSOPACITYWIDGETPLUGIN_H | ||
#define QGSOPACITYWIDGETPLUGIN_H | ||
|
||
|
||
#include <QtGlobal> | ||
#include <QtUiPlugin/QDesignerCustomWidgetInterface> | ||
#include <QtUiPlugin/QDesignerExportWidget> | ||
#include "qgis_customwidgets.h" | ||
|
||
|
||
class CUSTOMWIDGETS_EXPORT QgsOpacityWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface | ||
{ | ||
Q_OBJECT | ||
Q_INTERFACES( QDesignerCustomWidgetInterface ) | ||
|
||
public: | ||
explicit QgsOpacityWidgetPlugin( QObject *parent = 0 ); | ||
|
||
private: | ||
bool mInitialized; | ||
|
||
// QDesignerCustomWidgetInterface interface | ||
public: | ||
QString name() const override; | ||
QString group() const override; | ||
QString includeFile() const override; | ||
QIcon icon() const override; | ||
bool isContainer() const override; | ||
QWidget *createWidget( QWidget *parent ) override; | ||
bool isInitialized() const override; | ||
void initialize( QDesignerFormEditorInterface *core ) override; | ||
QString toolTip() const override; | ||
QString whatsThis() const override; | ||
QString domXml() const override; | ||
}; | ||
#endif // QGSOPACITYWIDGETPLUGIN_H |
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 @@ | ||
/*************************************************************************** | ||
qgsopacitywidget.cpp | ||
------------------- | ||
Date : May 2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall.dawson@gmail.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 "qgsopacitywidget.h" | ||
#include "qgsdoublespinbox.h" | ||
#include <QHBoxLayout> | ||
#include <QSlider> | ||
|
||
QgsOpacityWidget::QgsOpacityWidget( QWidget *parent ) | ||
: QWidget( parent ) | ||
{ | ||
QHBoxLayout *layout = new QHBoxLayout(); | ||
layout->setContentsMargins( 0, 0, 0, 0 ); | ||
layout->setSpacing( 0 ); | ||
setLayout( layout ); | ||
|
||
mSlider = new QSlider(); | ||
mSlider->setMinimum( 0 ); | ||
mSlider->setMaximum( 1000 ); | ||
mSlider->setSingleStep( 10 ); | ||
mSlider->setPageStep( 100 ); | ||
mSlider->setValue( 1000 ); | ||
mSlider->setOrientation( Qt::Horizontal ); | ||
layout->addWidget( mSlider, 1 ); | ||
|
||
mSpinBox = new QgsDoubleSpinBox(); | ||
mSpinBox->setMinimum( 0.0 ); | ||
mSpinBox->setMaximum( 100.0 ); | ||
mSpinBox->setValue( 100.0 ); | ||
mSpinBox->setClearValue( 100.0 ); | ||
mSpinBox->setMinimumSize( QSize( 100, 0 ) ); | ||
mSpinBox->setDecimals( 1 ); | ||
mSpinBox->setSuffix( tr( " %" ) ); | ||
layout->addWidget( mSpinBox, 0 ); | ||
|
||
setFocusProxy( mSpinBox ); | ||
|
||
connect( mSlider, &QSlider::valueChanged, this, [ = ]( int value ) { mSpinBox->setValue( value / 10.0 ); } ); | ||
connect( mSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double value ) { whileBlocking( mSlider )->setValue( value * 10 ); } ); | ||
connect( mSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsOpacityWidget::spinChanged ); | ||
} | ||
|
||
double QgsOpacityWidget::opacity() const | ||
{ | ||
return mSpinBox->value() / 100.0; | ||
} | ||
|
||
void QgsOpacityWidget::setOpacity( double opacity ) | ||
{ | ||
mSpinBox->setValue( opacity * 100.0 ); | ||
} | ||
|
||
void QgsOpacityWidget::spinChanged( double value ) | ||
{ | ||
emit opacityChanged( value / 100.0 ); | ||
} | ||
|
Oops, something went wrong.