Skip to content
Permalink
Browse files

Merge pull request #474 from dakcarto/color-button_mk_10

[FEATURE] QgsColorButton shows a color chooser dialog on click, checkboard color when translucent, and live updates during color choosing
  • Loading branch information
dakcarto committed Mar 22, 2013
2 parents 0594453 + 70ef5a7 commit a006d999585850391d59da4c4f48e3c5fb7a2b8d
Showing with 1,603 additions and 1,537 deletions.
  1. +1 −0 images/images.qrc
  2. BIN images/themes/default/transp-background_8x8.png
  3. +1 −0 python/gui/gui.sip
  4. +84 −15 python/gui/qgscolorbutton.sip
  5. +29 −0 python/gui/qgscolordialog.sip
  6. +1 −1 python/gui/symbology-ng/qgsrulebasedrendererv2widget.sip
  7. +9 −9 python/gui/symbology-ng/qgssymbollayerv2widget.sip
  8. +1 −1 python/gui/symbology-ng/qgssymbolslistwidget.sip
  9. +2 −2 python/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.sip
  10. +8 −13 src/app/composer/qgscomposerarrowwidget.cpp
  11. +1 −1 src/app/composer/qgscomposerarrowwidget.h
  12. +60 −50 src/app/composer/qgscomposeritemwidget.cpp
  13. +11 −3 src/app/composer/qgscomposeritemwidget.h
  14. +3 −11 src/app/composer/qgscomposertablewidget.cpp
  15. +1 −1 src/app/composer/qgscomposertablewidget.h
  16. +3 −8 src/app/composer/qgscompositionwidget.cpp
  17. +1 −1 src/app/composer/qgscompositionwidget.h
  18. +8 −24 src/app/qgsannotationwidget.cpp
  19. +2 −2 src/app/qgsannotationwidget.h
  20. +6 −16 src/app/qgscontinuouscolordialog.cpp
  21. +2 −2 src/app/qgscontinuouscolordialog.h
  22. +5 −10 src/app/qgsdecorationcopyrightdialog.cpp
  23. +1 −1 src/app/qgsdecorationcopyrightdialog.h
  24. +0 −8 src/app/qgsdecorationscalebardialog.cpp
  25. +0 −1 src/app/qgsdecorationscalebardialog.h
  26. +6 −26 src/app/qgsdiagramproperties.cpp
  27. +0 −2 src/app/qgsdiagramproperties.h
  28. +14 −20 src/app/qgslabelinggui.cpp
  29. +3 −3 src/app/qgslabelinggui.h
  30. +76 −43 src/app/qgslabelpropertydialog.cpp
  31. +2 −2 src/app/qgslabelpropertydialog.h
  32. +7 −42 src/app/qgsoptions.cpp
  33. +0 −20 src/app/qgsoptions.h
  34. +2 −23 src/app/qgsprojectproperties.cpp
  35. +0 −10 src/app/qgsprojectproperties.h
  36. +8 −32 src/app/qgssinglesymboldialog.cpp
  37. +2 −2 src/app/qgssinglesymboldialog.h
  38. +4 −11 src/app/qgstextannotationdialog.cpp
  39. +1 −1 src/app/qgstextannotationdialog.h
  40. +1 −1 src/core/symbology-ng/qgslinesymbollayerv2.cpp
  41. +1 −1 src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
  42. +5 −1 src/gui/CMakeLists.txt
  43. +229 −44 src/gui/qgscolorbutton.cpp
  44. +111 −17 src/gui/qgscolorbutton.h
  45. +49 −0 src/gui/qgscolordialog.cpp
  46. +53 −0 src/gui/qgscolordialog.h
  47. +14 −18 src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
  48. +2 −2 src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h
  49. +4 −22 src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp
  50. +2 −2 src/gui/symbology-ng/qgspointdisplacementrendererwidget.h
  51. +7 −4 src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
  52. +1 −1 src/gui/symbology-ng/qgsrulebasedrendererv2widget.h
  53. +3 −0 src/gui/symbology-ng/qgsstylev2managerdialog.cpp
  54. +45 −133 src/gui/symbology-ng/qgssymbollayerv2widget.cpp
  55. +12 −12 src/gui/symbology-ng/qgssymbollayerv2widget.h
  56. +7 −15 src/gui/symbology-ng/qgssymbolslistwidget.cpp
  57. +1 −1 src/gui/symbology-ng/qgssymbolslistwidget.h
  58. +3 −0 src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
  59. +54 −44 src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp
  60. +5 −2 src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.h
  61. +4 −10 src/plugins/grass/qgsgrassregion.cpp
  62. +1 −1 src/plugins/grass/qgsgrassregion.h
  63. +21 −15 src/plugins/grass/qgsgrassregionbase.ui
  64. +24 −42 src/ui/qgsannotationwidgetbase.ui
  65. +1 −1 src/ui/qgscategorizedsymbolrendererv2widget.ui
  66. +7 −2 src/ui/qgscomposerarrowwidgetbase.ui
  67. +32 −68 src/ui/qgscomposeritemwidgetbase.ui
  68. +7 −32 src/ui/qgscomposertablewidgetbase.ui
  69. +19 −50 src/ui/qgscompositionwidgetbase.ui
  70. +16 −30 src/ui/qgscontinuouscolordialogbase.ui
  71. +11 −24 src/ui/qgsdecorationcopyrightdialog.ui
  72. +8 −24 src/ui/qgsdecorationscalebardialog.ui
  73. +25 −49 src/ui/qgsdiagrampropertiesbase.ui
  74. +1 −1 src/ui/qgsgraduatedsymbolrendererv2widget.ui
  75. +27 −135 src/ui/qgslabelingguibase.ui
  76. +19 −19 src/ui/qgslabelpropertydialogbase.ui
  77. +148 −77 src/ui/qgsoptionsbase.ui
  78. +3 −15 src/ui/qgspointdisplacementrendererwidgetbase.ui
  79. +74 −45 src/ui/qgsprojectpropertiesbase.ui
  80. +15 −15 src/ui/qgssinglesymboldialogbase.ui
  81. +16 −7 src/ui/qgstextannotationdialogbase.ui
  82. +41 −42 src/ui/qgsvectorgradientcolorrampv2dialogbase.ui
  83. +5 −5 src/ui/symbollayer/widget_ellipse.ui
  84. +3 −3 src/ui/symbollayer/widget_fontmarker.ui
  85. +3 −3 src/ui/symbollayer/widget_linedecoration.ui
  86. +3 −3 src/ui/symbollayer/widget_linepatternfill.ui
  87. +5 −5 src/ui/symbollayer/widget_simplefill.ui
  88. +72 −59 src/ui/symbollayer/widget_simpleline.ui
  89. +5 −5 src/ui/symbollayer/widget_simplemarker.ui
  90. +5 −5 src/ui/symbollayer/widget_svgfill.ui
  91. +5 −5 src/ui/symbollayer/widget_svgmarker.ui
  92. +3 −3 src/ui/symbollayer/widget_symbolslist.ui
@@ -279,6 +279,7 @@
<file>themes/default/symbologyUp.png</file>
<file>themes/default/tracking.png</file>
<file>themes/default/transformed.png</file>
<file>themes/default/transp-background_8x8.png</file>
<file>themes/default/user.png</file>
<file>themes/default/mActionAddHtml.png</file>
<file>themes/gis/mActionAddArrow.png</file>
Binary file not shown.
@@ -12,6 +12,7 @@
%Include qgsattributeeditor.sip
%Include qgscollapsiblegroupbox.sip
%Include qgscolorbutton.sip
%Include qgscolordialog.sip
%Include qgscomposerview.sip
%Include qgscredentialdialog.sip
%Include qgsdetaileditemdata.sip
@@ -1,34 +1,103 @@

/** \ingroup gui
* \class QgsColorButton
* A cross platform button subclass for selecting colors. Will open a color chooser dialog when clicked.
* Offers live updates to button from color chooser dialog
* @note inherited base class moved from QToolButton to QPushButton in QGIS 1.9
*/

class QgsColorButton : QToolButton
class QgsColorButton: QPushButton
{
%TypeHeaderCode
#include <qgscolorbutton.h>
%End

public:
QgsColorButton( QWidget *parent = 0 );
/**
* Construct a new color button.
*
* @param parent The parent QWidget for the dialog
* @param cdt The title to show in the color chooser dialog
* @param cdo Options for the color chooser dialog
* @note changed in 1.9
*/
QgsColorButton( QWidget *parent = 0, QString cdt = "", QColorDialog::ColorDialogOptions cdo = 0 );
~QgsColorButton();

/**
* Specify the current color. Will emit a colorChanged signal if the color is different to the previous.
*
* @param color the new color
* @note added in 1.9
*/
void setColor( const QColor &color );
/**
* Return the currently selected color.
*
* @return the currently selected color
* @note added in 1.9
*/
QColor color() const;

protected:
void paintEvent( QPaintEvent *e );
/**
* Specify the options for the color chooser dialog (e.g. alpha).
*
* @param cdo Options for the color chooser dialog
* @note added in 1.9
*/
void setColorDialogOptions( QColorDialog::ColorDialogOptions cdo );

};
/**
* Returns the options for the color chooser dialog.
*
* @return Options for the color chooser dialog
* @note added in 1.9
*/
QColorDialog::ColorDialogOptions colorDialogOptions();

/**
* Set the title, which the color chooser dialog will show.
*
* @param cdt Title for the color chooser dialog
* @note added in 1.9
*/
void setColorDialogTitle( QString cdt );

class QgsColorButtonV2 : QPushButton
{
%TypeHeaderCode
#include <qgscolorbutton.h>
%End
/**
* Returns the title, which the color chooser dialog shows.
*
* @return Title for the color chooser dialog
* @note added in 1.9
*/
QString colorDialogTitle();

public:
QgsColorButtonV2( QWidget* parent = 0 );
QgsColorButtonV2( QString text, QWidget* parent = 0 );
/**
* Whether the button accepts live updates from QColorDialog.
*
* @note added in 1.9
*/
bool acceptLiveUpdates();

void setColor( const QColor &color );
QColor color() const;
/**
* Sets whether the button accepts live updates from QColorDialog.
* Live updates may cause changes that are not undoable on QColorDialog cancel.
*
* @note added in 1.9
*/
void setAcceptLiveUpdates( bool accept );

signals:
/**
* Is emitted, whenever a new color is accepted. The color is always valid.
* In case the new color is the same, no signal is emitted, to avoid infinite loops.
*
* @param color New color
* @note added in 1.9
*/
void colorChanged( const QColor &color );

protected:
void changeEvent( QEvent* e );
void paintEvent( QPaintEvent* e );
static const QPixmap& transpBkgrd();
};
@@ -0,0 +1,29 @@

/** \ingroup gui
* \class QgsColorDialog
* A dialog for selecting a color
*/

class QgsColorDialog : QObject
{
%TypeHeaderCode
#include <qgscolordialog.h>
%End
public:
QgsColorDialog();
~QgsColorDialog();

/** Return a color selection from a QColorDialog, with live updating of interim selections.
* @param initialColor The initial color of the selection dialog.
* @param updateObject The receiver object of the live updating.
* @param updateSlot The receiver object's slot for live updating (e.g. SLOT( setValidColor( const QColor& ) ) ).
* @param parent Parent widget. Usually 0 is best for native system color dialogs.
* @param title The title of the QColorDialog.
* @param options ColorDialogOptions passed to QColorDialog.
* @return Selected color on accepted() or initialColor on rejected().
*/
static QColor getLiveColor( const QColor& initialColor, QObject* updateObject, const char* updateSlot,
QWidget* parent = 0,
const QString& title = "",
QColorDialog::ColorDialogOptions options = 0 );
};
@@ -96,7 +96,7 @@ class QgsRendererRulePropsDialog : QDialog
%End

public:
QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style );
QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = 0 );
~QgsRendererRulePropsDialog();

QgsRuleBasedRendererV2::Rule* rule();
@@ -34,7 +34,7 @@ class QgsSimpleLineSymbolLayerV2Widget : QgsSymbolLayerV2Widget

public slots:
void penWidthChanged();
void colorChanged();
void colorChanged( const QColor& color );
void penStyleChanged();
void offsetChanged();
void on_mCustomCheckBox_stateChanged( int state );
@@ -65,8 +65,8 @@ class QgsSimpleMarkerSymbolLayerV2Widget : QgsSymbolLayerV2Widget

public slots:
void setName();
void setColorBorder();
void setColorFill();
void setColorBorder( const QColor& color );
void setColorFill( const QColor& color );
void setSize();
void setAngle();
void setOffset();
@@ -90,8 +90,8 @@ class QgsSimpleFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
virtual QgsSymbolLayerV2* symbolLayer();

public slots:
void setColor();
void setBorderColor();
void setColor( const QColor& color );
void setBorderColor( const QColor& color );
void setBrushStyle();
void borderWidthChanged();
void borderStyleChanged();
@@ -150,8 +150,8 @@ class QgsSvgMarkerSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void setOffset();
void on_mFileToolButton_clicked();
void on_mFileLineEdit_textEdited( const QString& text );
void on_mChangeColorButton_clicked();
void on_mChangeBorderColorButton_clicked();
void on_mChangeColorButton_colorChanged( const QColor& color );
void on_mChangeBorderColorButton_colorChanged( const QColor& color );
void on_mBorderWidthSpinBox_valueChanged( double d );

protected:
@@ -180,7 +180,7 @@ class QgsLineDecorationSymbolLayerV2Widget : QgsSymbolLayerV2Widget
virtual QgsSymbolLayerV2* symbolLayer();

public slots:
void colorChanged();
void colorChanged( const QColor& color );
void penWidthChanged();
};

@@ -252,7 +252,7 @@ class QgsFontMarkerSymbolLayerV2Widget : QgsSymbolLayerV2Widget

public slots:
void setFontFamily( const QFont& font );
void setColor();
void setColor( const QColor& color );
void setSize( double size );
void setAngle( double angle );
void setCharacter( const QChar& chr );
@@ -8,7 +8,7 @@ class QgsSymbolsListWidget : QWidget

public slots:
void setSymbolFromStyle( const QModelIndex & index );
void setSymbolColor();
void setSymbolColor( const QColor& color );
void setMarkerAngle( double angle );
void setMarkerSize( double size );
void setLineWidth( double width );
@@ -8,8 +8,8 @@ class QgsVectorGradientColorRampV2Dialog : QDialog
QgsVectorGradientColorRampV2Dialog( QgsVectorGradientColorRampV2* ramp, QWidget* parent = NULL );

public slots:
void setColor1();
void setColor2();
void setColor1( const QColor& color );
void setColor2( const QColor& color );

void toggledStops( bool on );
void addStop();
@@ -77,25 +77,17 @@ void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
mArrow->endCommand();
}

void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
void QgsComposerArrowWidget::on_mArrowColorButton_colorChanged( const QColor& newColor )
{
if ( !mArrow )
{
return;
}

#if QT_VERSION >= 0x040500
QColor newColor = QColorDialog::getColor( mArrow->arrowColor(), 0, tr( "Arrow color" ), QColorDialog::ShowAlphaChannel );
#else
QColor newColor = QColorDialog::getColor( mArrow->arrowColor() );
#endif
if ( newColor.isValid() )
{
mArrow->beginCommand( tr( "Arrow color changed" ) );
mArrow->setArrowColor( newColor );
mArrow->update();
mArrow->endCommand();
}
mArrow->beginCommand( tr( "Arrow color changed" ) );
mArrow->setArrowColor( newColor );
mArrow->update();
mArrow->endCommand();
}

void QgsComposerArrowWidget::blockAllSignals( bool block )
@@ -120,6 +112,9 @@ void QgsComposerArrowWidget::setGuiElementValues()
}

blockAllSignals( true );
mArrowColorButton->setColor( mArrow->arrowColor() );
mArrowColorButton->setColorDialogTitle( tr( "Select arrow color" ) );
mArrowColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mOutlineWidthSpinBox->setValue( mArrow->outlineWidth() );
mArrowHeadWidthSpinBox->setValue( mArrow->arrowHeadWidth() );

@@ -42,7 +42,7 @@ class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidget
private slots:
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mArrowHeadWidthSpinBox_valueChanged( double d );
void on_mArrowColorButton_clicked();
void on_mArrowColorButton_colorChanged( const QColor& newColor );
void on_mDefaultMarkerRadioButton_toggled( bool toggled );
void on_mNoMarkerRadioButton_toggled( bool toggled );
void on_mSvgMarkerRadioButton_toggled( bool toggled );

0 comments on commit a006d99

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