Skip to content

Commit

Permalink
Merge pull request #474 from dakcarto/color-button_mk_10
Browse files Browse the repository at this point in the history
[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 a006d99
Show file tree
Hide file tree
Showing 92 changed files with 1,603 additions and 1,537 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Binary file added images/themes/default/transp-background_8x8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 84 additions & 15 deletions python/gui/qgscolorbutton.sip
Original file line number Diff line number Diff line change
@@ -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();
};
29 changes: 29 additions & 0 deletions python/gui/qgscolordialog.sip
Original file line number Diff line number Diff line change
@@ -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 );
};
2 changes: 1 addition & 1 deletion python/gui/symbology-ng/qgsrulebasedrendererv2widget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions python/gui/symbology-ng/qgssymbollayerv2widget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -180,7 +180,7 @@ class QgsLineDecorationSymbolLayerV2Widget : QgsSymbolLayerV2Widget
virtual QgsSymbolLayerV2* symbolLayer();

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

Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion python/gui/symbology-ng/qgssymbolslistwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 8 additions & 13 deletions src/app/composer/qgscomposerarrowwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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() );

Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerarrowwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Loading

0 comments on commit a006d99

Please sign in to comment.