2010-01-15 23:55:23 +00:00
|
|
|
|
2013-01-08 14:22:27 -07:00
|
|
|
/** \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
|
|
|
|
*/
|
2010-01-15 23:55:23 +00:00
|
|
|
|
2013-01-08 14:22:27 -07:00
|
|
|
class QgsColorButton: QPushButton
|
2010-01-15 23:55:23 +00:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgscolorbutton.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
2013-01-08 11:59:47 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
QgsColorButton( QWidget *parent /TransferThis/ = 0, const QString& cdt = "", const QColorDialog::ColorDialogOptions& cdo = 0 );
|
2010-01-15 23:55:23 +00:00
|
|
|
~QgsColorButton();
|
|
|
|
|
2013-01-08 11:59:47 +01:00
|
|
|
/**
|
|
|
|
* Specify the current color. Will emit a colorChanged signal if the color is different to the previous.
|
|
|
|
*
|
|
|
|
* @param color the new color
|
|
|
|
*/
|
2010-01-15 23:55:23 +00:00
|
|
|
void setColor( const QColor &color );
|
2013-01-08 11:59:47 +01:00
|
|
|
/**
|
|
|
|
* Return the currently selected color.
|
|
|
|
*
|
|
|
|
* @return the currently selected color
|
|
|
|
*/
|
2010-01-15 23:55:23 +00:00
|
|
|
QColor color() const;
|
|
|
|
|
2013-01-08 11:59:47 +01:00
|
|
|
/**
|
|
|
|
* Specify the options for the color chooser dialog (e.g. alpha).
|
|
|
|
*
|
|
|
|
* @param cdo Options for the color chooser dialog
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
void setColorDialogOptions( const QColorDialog::ColorDialogOptions& cdo );
|
2013-01-08 11:59:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the options for the color chooser dialog.
|
|
|
|
*
|
|
|
|
* @return Options for the color chooser dialog
|
|
|
|
*/
|
|
|
|
QColorDialog::ColorDialogOptions colorDialogOptions();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the title, which the color chooser dialog will show.
|
|
|
|
*
|
|
|
|
* @param cdt Title for the color chooser dialog
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
void setColorDialogTitle( const QString& cdt );
|
2013-01-08 11:59:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the title, which the color chooser dialog shows.
|
|
|
|
*
|
|
|
|
* @return Title for the color chooser dialog
|
|
|
|
*/
|
|
|
|
QString colorDialogTitle();
|
|
|
|
|
2013-01-08 14:22:27 -07:00
|
|
|
/**
|
|
|
|
* Whether the button accepts live updates from QColorDialog.
|
|
|
|
*/
|
|
|
|
bool acceptLiveUpdates();
|
2010-01-15 23:55:23 +00:00
|
|
|
|
2013-01-08 14:22:27 -07:00
|
|
|
/**
|
|
|
|
* Sets whether the button accepts live updates from QColorDialog.
|
|
|
|
* Live updates may cause changes that are not undoable on QColorDialog cancel.
|
|
|
|
*/
|
|
|
|
void setAcceptLiveUpdates( bool accept );
|
2013-01-08 11:59:47 +01:00
|
|
|
|
2013-03-28 07:43:52 -06:00
|
|
|
public slots:
|
|
|
|
/**
|
2014-07-06 21:26:47 +10:00
|
|
|
* Sets the background pixmap for the button based upon color and transparency.
|
2013-03-28 07:43:52 -06:00
|
|
|
* Call directly to update background after adding/removing QColorDialog::ShowAlphaChannel option
|
|
|
|
* but the color has not changed, i.e. setColor() wouldn't update button and
|
|
|
|
* you want the button to retain the set color's alpha component regardless
|
2014-07-06 21:26:47 +10:00
|
|
|
* @param color Color for button background
|
2013-03-28 07:43:52 -06:00
|
|
|
*/
|
2014-07-06 21:26:47 +10:00
|
|
|
void setButtonBackground( QColor color = QColor() );
|
2013-03-28 07:43:52 -06:00
|
|
|
|
2013-01-08 11:59:47 +01:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
void colorChanged( const QColor &color );
|
2010-01-15 23:55:23 +00:00
|
|
|
|
2013-01-08 14:22:27 -07:00
|
|
|
protected:
|
|
|
|
void changeEvent( QEvent* e );
|
2014-01-27 09:22:24 +01:00
|
|
|
void showEvent( QShowEvent* e );
|
2013-01-08 14:22:27 -07:00
|
|
|
static const QPixmap& transpBkgrd();
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2014-11-21 01:17:21 +01:00
|
|
|
/**
|
2014-05-27 23:22:50 +02:00
|
|
|
* Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
|
2014-05-12 23:58:47 +10:00
|
|
|
*/
|
|
|
|
void mousePressEvent( QMouseEvent* e );
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2014-05-22 00:48:35 +10:00
|
|
|
/**
|
|
|
|
* Reimplemented to allow dragging colors from button
|
|
|
|
*/
|
|
|
|
void mouseMoveEvent( QMouseEvent *e );
|
|
|
|
|
2014-07-06 21:26:47 +10:00
|
|
|
/**
|
|
|
|
* Reimplemented to allow color picking
|
|
|
|
*/
|
|
|
|
void mouseReleaseEvent( QMouseEvent *e );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplemented to allow cancelling color pick via keypress, and sample via space bar press
|
|
|
|
*/
|
|
|
|
void keyPressEvent( QKeyEvent *e );
|
|
|
|
|
2014-05-22 00:48:35 +10:00
|
|
|
/**
|
|
|
|
* Reimplemented to accept dragged colors
|
|
|
|
*/
|
2014-10-20 22:50:15 +02:00
|
|
|
void dragEnterEvent( QDragEnterEvent * e );
|
2014-05-22 00:48:35 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplemented to accept dropped colors
|
|
|
|
*/
|
|
|
|
void dropEvent( QDropEvent *e );
|
2010-01-15 23:55:23 +00:00
|
|
|
};
|