remove QgsColorButton in favor of V2

This commit is contained in:
Denis Rouzaud 2016-08-04 13:49:59 +02:00
parent 138e1139aa
commit 3e197ae74a
65 changed files with 1187 additions and 2297 deletions

View File

@ -21,12 +21,13 @@ This page tries to maintain a list with incompatible changes that happened in pr
\subsection qgis_api_break_3_0_removed_classes Removed Classes
<ul>
<li>QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngineV2.</li>
<li>QgsMapCanvasMap. It is an internal class used by map canvas.</li>
<li>QgsMapRenderer. It has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.</li>
<li>QgsColorbutton was removed. QgsColorButtonV2 has now been renamed to QgsColorButton. Hence, QgsColorButtonV2 does not exist anymore.
<li>QgsCRSCache was removed. QgsCoordinateReferenceSystem now internally uses a cache for CRS creation,
so there is no longer a need for the separate cache class. Code which previously called QgsCRSCache::updateCRSCache()
should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinateTransformCache::instance()->invalidateCrs( authid ).</li>
<li>QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngineV2.</li>
<li>QgsMapCanvasMap. It is an internal class used by map canvas.</li>
<li>QgsMapRenderer. It has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.</li>
<li>QgsPseudoColorShader. This shader has been broken for some time and was replaced by QgsSingleBandPseudoColorRenderer.</li>
</ul>

View File

@ -5,7 +5,7 @@ typedef QList< QPair< QColor, QString > > QgsNamedColorList;
* \class QgsColorScheme
* \brief Abstract base class for color schemes
*
* A color scheme for display in QgsColorButtonV2. Color schemes return lists
* A color scheme for display in QgsColorButton. Color schemes return lists
* of colors with an optional associated color name. The colors returned
* can be generated using an optional base color.
* \note Added in version 2.5

View File

@ -46,7 +46,7 @@
%End
%Include qgscharacterselectdialog.sip
%Include qgscolorbutton.sip
%Include qgscolorbuttonv2.sip
%Include qgscolorbutton.sip
%Include qgscolordialog.sip
%Include qgscolorschemelist.sip
%Include qgscolorswatchgrid.sip

View File

@ -2,103 +2,294 @@
/** \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
* Offers live updates to button from color chooser dialog. An attached drop down menu allows for copying
* and pasting colors, picking colors from the screen, and selecting colors from color swatch grids.
* \note Added in version 2.5
*/
class QgsColorButton: QPushButton
class QgsColorButton : QToolButton
{
%TypeHeaderCode
#include <qgscolorbutton.h>
%End
public:
/**
* Construct a new color button.
*
/** Specifies the behaviour when the button is clicked
*/
enum Behaviour
{
ShowDialog, /*!< show a color picker dialog when clicked */
SignalOnly /*!< emit colorClicked signal only, no dialog */
};
/** 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
* @param registry a color scheme registry for color swatch grids to show in the drop down menu. If not
* specified, the button will use the global color scheme registry
*/
QgsColorButton( QWidget *parent /TransferThis/ = 0, const QString& cdt = "", const QColorDialog::ColorDialogOptions& cdo = 0 );
~QgsColorButton();
QgsColorButton( QWidget *parent /TransferThis/ = 0, const QString& cdt = "", QgsColorSchemeRegistry* registry = 0 );
/**
* Specify the current color. Will emit a colorChanged signal if the color is different to the previous.
*
* @param color the new color
*/
void setColor( const QColor &color );
/**
* Return the currently selected color.
*
* @return the currently selected color
virtual ~QgsColorButton();
virtual QSize sizeHint() const;
/** Return the currently selected color.
* @returns currently selected color
* @see setColor
*/
QColor color() const;
/**
* Specify the options for the color chooser dialog (e.g. alpha).
*
* @param cdo Options for the color chooser dialog
/** Sets whether alpha modification (transparency) is permitted
* for the color. Defaults to false.
* @param allowAlpha set to true to allow alpha modification
* @see allowAlpha
*/
void setColorDialogOptions( const QColorDialog::ColorDialogOptions& cdo );
void setAllowAlpha( const bool allowAlpha );
/**
* Returns the options for the color chooser dialog.
*
* @return Options for the color chooser dialog
/** Returns whether alpha modification (transparency) is permitted
* for the color.
* @returns true if alpha modification is allowed
* @see setAllowAlpha
*/
QColorDialog::ColorDialogOptions colorDialogOptions();
bool allowAlpha() const;
/**
* Set the title, which the color chooser dialog will show.
*
* @param cdt Title for the color chooser dialog
/** Set the title for the color chooser dialog window.
* @param title Title for the color chooser dialog
* @see colorDialogTitle
*/
void setColorDialogTitle( const QString& cdt );
void setColorDialogTitle( const QString& title );
/**
* Returns the title, which the color chooser dialog shows.
*
* @return Title for the color chooser dialog
/** Returns the title for the color chooser dialog window.
* @returns title for the color chooser dialog
* @see setColorDialogTitle
*/
QString colorDialogTitle();
QString colorDialogTitle() const;
/**
* Whether the button accepts live updates from QColorDialog.
/** Returns whether the button accepts live updates from QColorDialog.
* @returns true if the button will be accepted immediately when the dialog's color changes
* @see setAcceptLiveUpdates
*/
bool acceptLiveUpdates();
bool acceptLiveUpdates() const;
/**
* Sets whether the button accepts live updates from QColorDialog.
* Live updates may cause changes that are not undoable on QColorDialog cancel.
/** Sets whether the button accepts live updates from QColorDialog. Live updates may cause changes
* that are not undoable on QColorDialog cancel.
* @param accept set to true to enable live updates
* @see acceptLiveUpdates
*/
void setAcceptLiveUpdates( bool accept );
void setAcceptLiveUpdates( const bool accept );
/** Sets whether the drop down menu should be shown for the button. The default behaviour is to
* show the menu.
* @param showMenu set to false to hide the drop down menu
* @see showMenu
*/
void setShowMenu( const bool showMenu );
/** Returns whether the drop down menu is shown for the button.
* @returns true if drop down menu is shown
* @see setShowMenu
*/
bool showMenu() const;
/** Sets the behaviour for when the button is clicked. The default behaviour is to show
* a color picker dialog.
* @param behaviour behaviour when button is clicked
* @see behaviour
*/
void setBehaviour( const Behaviour behaviour );
/** Returns the behaviour for when the button is clicked.
* @returns behaviour when button is clicked
* @see setBehaviour
*/
Behaviour behaviour() const;
/** Sets the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @param color default color for the button. Set to an invalid QColor to disable the default color
* option.
* @see defaultColor
*/
void setDefaultColor( const QColor& color );
/** Returns the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @returns default color for the button. Returns an invalid QColor if the default color
* option is disabled.
* @see setDefaultColor
*/
QColor defaultColor() const;
/** Sets whether the "no color" option should be shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @param showNoColorOption set to true to show the no color option. This is disabled by default.
* @see showNoColor
* @see setNoColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setShowNoColor( const bool showNoColorOption );
/** Returns whether the "no color" option is shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @returns true if the no color option is shown.
* @see setShowNoColor
* @see noColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
bool showNoColor() const;
/** Sets the string to use for the "no color" option in the button's drop down menu.
* @param noColorString string to use for the "no color" menu option
* @see noColorString
* @see setShowNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setNoColorString( const QString& noColorString );
/** Sets whether a set to null (clear) option is shown in the button's drop down menu.
* @param showNull set to true to show a null option
* @note added in QGIS 2.16
* @see showNull()
* @see isNull()
*/
void setShowNull( bool showNull );
/** Returns whether the set to null (clear) option is shown in the button's drop down menu.
* @note added in QGIS 2.16
* @see setShowNull()
* @see isNull()
*/
bool showNull() const;
/** Returns true if the current color is null.
* @note added in QGIS 2.16
* @see setShowNull()
* @see showNull()
*/
bool isNull() const;
/** Returns the string used for the "no color" option in the button's drop down menu.
* @returns string used for the "no color" menu option
* @see setNoColorString
* @see showNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
QString noColorString() const;
/** Sets the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @param context context string for the color button's color swatch grids
* @see context
*/
void setContext( const QString& context );
/** Returns the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @returns context string for the color button's color swatch grids
* @see setContext
*/
QString context() const;
/** Sets the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @param registry color scheme registry for the button. Set to 0 to hide all color
* swatch grids from the button's drop down menu.
* @see colorSchemeRegistry
*/
void setColorSchemeRegistry( QgsColorSchemeRegistry* registry );
/** Returns the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @returns color scheme registry for the button. If returned value is 0 then all color
* swatch grids are hidden from the button's drop down menu.
* @see setColorSchemeRegistry
*/
QgsColorSchemeRegistry* colorSchemeRegistry();
public slots:
/**
* Sets the background pixmap for the button based upon color and transparency.
/** Sets the current color for the button. Will emit a colorChanged signal if the color is different
* to the previous color.
* @param color new color for the button
* @see color
*/
void setColor( const QColor &color );
/** Sets the background pixmap for the button based upon color and transparency.
* 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
* @param color Color for button background
* @param color Color for button background. If no color is specified, the button's current
* color will be used
*/
void setButtonBackground( QColor color = QColor() );
void setButtonBackground( const QColor &color = QColor() );
/** Copies the current color to the clipboard
* @see pasteColor
*/
void copyColor();
/** Pastes a color from the clipboard to the color button. If clipboard does not contain a valid
* color or string representation of a color, then no change is applied.
* @see copyColor
*/
void pasteColor();
/** Activates the color picker tool, which allows for sampling a color from anywhere on the screen
*/
void activatePicker();
/** Sets color to a totally transparent color.
* @note If the color button is not set to show an alpha channel in the color
* dialog (see setColorDialogOptions) then the color will not be changed.
*/
void setToNoColor();
/** Sets color to the button's default color, if set.
* @see setDefaultColor
* @see defaultColor
*/
void setToDefaultColor();
/** Sets color to null.
* @see setToDefaultColor()
* @see setToNoColor()
* @note added in QGIS 2.16
*/
void setToNull();
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.
*
/** Is emitted whenever a new color is set for the button. 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 );
/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
* @param color button color
* @see setBehaviour
* @see behaviour
*/
void colorClicked( const QColor &color );
protected:
void changeEvent( QEvent* e );
void showEvent( QShowEvent* e );
static const QPixmap& transpBkgrd();
void resizeEvent( QResizeEvent *event );
/** Returns a checkboard pattern pixmap for use as a background to transparent colors
*/
static const QPixmap& transparentBackground();
/**
* Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
@ -125,8 +316,14 @@ class QgsColorButton: QPushButton
*/
void dragEnterEvent( QDragEnterEvent * e );
/**
* Reimplemented to reset button appearance after drag leave
*/
void dragLeaveEvent( QDragLeaveEvent *e );
/**
* Reimplemented to accept dropped colors
*/
void dropEvent( QDropEvent *e );
};

View File

@ -1,329 +0,0 @@
/** \ingroup gui
* \class QgsColorButtonV2
* 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. An attached drop down menu allows for copying
* and pasting colors, picking colors from the screen, and selecting colors from color swatch grids.
* \note Added in version 2.5
*/
class QgsColorButtonV2 : QToolButton
{
%TypeHeaderCode
#include <qgscolorbuttonv2.h>
%End
public:
/** Specifies the behaviour when the button is clicked
*/
enum Behaviour
{
ShowDialog, /*!< show a color picker dialog when clicked */
SignalOnly /*!< emit colorClicked signal only, no dialog */
};
/** 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 registry a color scheme registry for color swatch grids to show in the drop down menu. If not
* specified, the button will use the global color scheme registry
*/
QgsColorButtonV2( QWidget *parent /TransferThis/ = 0, const QString& cdt = "", QgsColorSchemeRegistry* registry = 0 );
virtual ~QgsColorButtonV2();
virtual QSize sizeHint() const;
/** Return the currently selected color.
* @returns currently selected color
* @see setColor
*/
QColor color() const;
/** Sets whether alpha modification (transparency) is permitted
* for the color. Defaults to false.
* @param allowAlpha set to true to allow alpha modification
* @see allowAlpha
*/
void setAllowAlpha( const bool allowAlpha );
/** Returns whether alpha modification (transparency) is permitted
* for the color.
* @returns true if alpha modification is allowed
* @see setAllowAlpha
*/
bool allowAlpha() const;
/** Set the title for the color chooser dialog window.
* @param title Title for the color chooser dialog
* @see colorDialogTitle
*/
void setColorDialogTitle( const QString& title );
/** Returns the title for the color chooser dialog window.
* @returns title for the color chooser dialog
* @see setColorDialogTitle
*/
QString colorDialogTitle() const;
/** Returns whether the button accepts live updates from QColorDialog.
* @returns true if the button will be accepted immediately when the dialog's color changes
* @see setAcceptLiveUpdates
*/
bool acceptLiveUpdates() const;
/** Sets whether the button accepts live updates from QColorDialog. Live updates may cause changes
* that are not undoable on QColorDialog cancel.
* @param accept set to true to enable live updates
* @see acceptLiveUpdates
*/
void setAcceptLiveUpdates( const bool accept );
/** Sets whether the drop down menu should be shown for the button. The default behaviour is to
* show the menu.
* @param showMenu set to false to hide the drop down menu
* @see showMenu
*/
void setShowMenu( const bool showMenu );
/** Returns whether the drop down menu is shown for the button.
* @returns true if drop down menu is shown
* @see setShowMenu
*/
bool showMenu() const;
/** Sets the behaviour for when the button is clicked. The default behaviour is to show
* a color picker dialog.
* @param behaviour behaviour when button is clicked
* @see behaviour
*/
void setBehaviour( const Behaviour behaviour );
/** Returns the behaviour for when the button is clicked.
* @returns behaviour when button is clicked
* @see setBehaviour
*/
Behaviour behaviour() const;
/** Sets the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @param color default color for the button. Set to an invalid QColor to disable the default color
* option.
* @see defaultColor
*/
void setDefaultColor( const QColor& color );
/** Returns the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @returns default color for the button. Returns an invalid QColor if the default color
* option is disabled.
* @see setDefaultColor
*/
QColor defaultColor() const;
/** Sets whether the "no color" option should be shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @param showNoColorOption set to true to show the no color option. This is disabled by default.
* @see showNoColor
* @see setNoColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setShowNoColor( const bool showNoColorOption );
/** Returns whether the "no color" option is shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @returns true if the no color option is shown.
* @see setShowNoColor
* @see noColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
bool showNoColor() const;
/** Sets the string to use for the "no color" option in the button's drop down menu.
* @param noColorString string to use for the "no color" menu option
* @see noColorString
* @see setShowNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setNoColorString( const QString& noColorString );
/** Sets whether a set to null (clear) option is shown in the button's drop down menu.
* @param showNull set to true to show a null option
* @note added in QGIS 2.16
* @see showNull()
* @see isNull()
*/
void setShowNull( bool showNull );
/** Returns whether the set to null (clear) option is shown in the button's drop down menu.
* @note added in QGIS 2.16
* @see setShowNull()
* @see isNull()
*/
bool showNull() const;
/** Returns true if the current color is null.
* @note added in QGIS 2.16
* @see setShowNull()
* @see showNull()
*/
bool isNull() const;
/** Returns the string used for the "no color" option in the button's drop down menu.
* @returns string used for the "no color" menu option
* @see setNoColorString
* @see showNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
QString noColorString() const;
/** Sets the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @param context context string for the color button's color swatch grids
* @see context
*/
void setContext( const QString& context );
/** Returns the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @returns context string for the color button's color swatch grids
* @see setContext
*/
QString context() const;
/** Sets the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @param registry color scheme registry for the button. Set to 0 to hide all color
* swatch grids from the button's drop down menu.
* @see colorSchemeRegistry
*/
void setColorSchemeRegistry( QgsColorSchemeRegistry* registry );
/** Returns the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @returns color scheme registry for the button. If returned value is 0 then all color
* swatch grids are hidden from the button's drop down menu.
* @see setColorSchemeRegistry
*/
QgsColorSchemeRegistry* colorSchemeRegistry();
public slots:
/** Sets the current color for the button. Will emit a colorChanged signal if the color is different
* to the previous color.
* @param color new color for the button
* @see color
*/
void setColor( const QColor &color );
/** Sets the background pixmap for the button based upon color and transparency.
* 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
* @param color Color for button background. If no color is specified, the button's current
* color will be used
*/
void setButtonBackground( const QColor &color = QColor() );
/** Copies the current color to the clipboard
* @see pasteColor
*/
void copyColor();
/** Pastes a color from the clipboard to the color button. If clipboard does not contain a valid
* color or string representation of a color, then no change is applied.
* @see copyColor
*/
void pasteColor();
/** Activates the color picker tool, which allows for sampling a color from anywhere on the screen
*/
void activatePicker();
/** Sets color to a totally transparent color.
* @note If the color button is not set to show an alpha channel in the color
* dialog (see setColorDialogOptions) then the color will not be changed.
*/
void setToNoColor();
/** Sets color to the button's default color, if set.
* @see setDefaultColor
* @see defaultColor
*/
void setToDefaultColor();
/** Sets color to null.
* @see setToDefaultColor()
* @see setToNoColor()
* @note added in QGIS 2.16
*/
void setToNull();
signals:
/** Is emitted whenever a new color is set for the button. 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 );
/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
* @param color button color
* @see setBehaviour
* @see behaviour
*/
void colorClicked( const QColor &color );
protected:
void changeEvent( QEvent* e );
void showEvent( QShowEvent* e );
void resizeEvent( QResizeEvent *event );
/** Returns a checkboard pattern pixmap for use as a background to transparent colors
*/
static const QPixmap& transparentBackground();
/**
* Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
*/
void mousePressEvent( QMouseEvent* e );
/**
* Reimplemented to allow dragging colors from button
*/
void mouseMoveEvent( QMouseEvent *e );
/**
* 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 );
/**
* Reimplemented to accept dragged colors
*/
void dragEnterEvent( QDragEnterEvent * e );
/**
* Reimplemented to reset button appearance after drag leave
*/
void dragLeaveEvent( QDragLeaveEvent *e );
/**
* Reimplemented to accept dropped colors
*/
void dropEvent( QDropEvent *e );
};

View File

@ -23,7 +23,7 @@
#include "qgscomposertablev2.h"
class QCheckBox;
class QgsColorButtonV2;
class QgsColorButton;
/** A dialog for customisation of the cell background colors for a QgsComposerTableV2
* /note added in QGIS 2.12
@ -53,7 +53,7 @@ class QgsComposerTableBackgroundColorsDialog: public QDialog, private Ui::QgsCom
QgsComposerTableV2* mComposerTable;
QMap< QgsComposerTableV2::CellStyleGroup, QCheckBox* > mCheckBoxMap;
QMap< QgsComposerTableV2::CellStyleGroup, QgsColorButtonV2* > mColorButtonMap;
QMap< QgsComposerTableV2::CellStyleGroup, QgsColorButton* > mColorButtonMap;
/** Sets the GUI elements to the values of the table*/

View File

@ -517,7 +517,7 @@ void QgsLabelingGui::connectValueChanged( QList<QWidget *> widgets, const char *
{
connect( w , SIGNAL( valueChanged( double ) ), this, slot );
}
else if ( QgsColorButtonV2* w = qobject_cast<QgsColorButtonV2*>( widget ) )
else if ( QgsColorButton* w = qobject_cast<QgsColorButton*>( widget ) )
{
connect( w, SIGNAL( colorChanged( QColor ) ), this, slot );
}

View File

@ -33,7 +33,7 @@ typedef QList< QPair< QColor, QString > > QgsNamedColorList;
* \class QgsColorScheme
* \brief Abstract base class for color schemes
*
* A color scheme for display in QgsColorButtonV2. Color schemes return lists
* A color scheme for display in QgsColorButton. Color schemes return lists
* of colors with an optional associated color name. The colors returned
* can be generated using an optional base color.
* \note Added in version 2.5

View File

@ -20,7 +20,6 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
qgiscustomwidgets.cpp
qgscollapsiblegroupboxplugin.cpp
qgscolorbuttonplugin.cpp
qgscolorbuttonv2plugin.cpp
qgsdatetimeeditplugin.cpp
qgsdatadefinedbuttonplugin.cpp
qgsdockwidgetplugin.cpp
@ -45,7 +44,6 @@ SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
qgiscustomwidgets.h
qgscollapsiblegroupboxplugin.h
qgscolorbuttonplugin.h
qgscolorbuttonv2plugin.h
qgsdatetimeeditplugin.h
qgsdatadefinedbuttonplugin.h
qgsdockwidgetplugin.h
@ -76,7 +74,6 @@ SET(QGIS_CUSTOMWIDGETS_HDRS
qgiscustomwidgets.h
qgscollapsiblegroupboxplugin.h
qgscolorbuttonplugin.h
qgscolorbuttonv2plugin.h
qgsdatetimeeditplugin.h
qgsdatadefinedbuttonplugin.h
qgsdockwidgetplugin.h

View File

@ -18,7 +18,6 @@
#include "qgiscustomwidgets.h"
#include "qgscollapsiblegroupboxplugin.h"
#include "qgscolorbuttonplugin.h"
#include "qgscolorbuttonv2plugin.h"
#include "qgsdatadefinedbuttonplugin.h"
#include "qgsdatetimeeditplugin.h"
#include "qgsdockwidgetplugin.h"
@ -42,7 +41,6 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
{
mWidgets.append( new QgsCollapsibleGroupBoxPlugin( this ) );
mWidgets.append( new QgsColorButtonPlugin( this ) );
mWidgets.append( new QgsColorButtonV2Plugin( this ) );
mWidgets.append( new QgsDataDefinedButtonPlugin( this ) );
mWidgets.append( new QgsDateTimeEditPlugin( this ) );
mWidgets.append( new QgsDockWidgetPlugin( this ) );

View File

@ -1,7 +1,7 @@
/***************************************************************************
qgscolorbuttonplugin.cpp
--------------------------------------
Date : 25.04.2014
Date : 18.08.2014
Copyright : (C) 2014 Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************

View File

@ -1,7 +1,7 @@
/***************************************************************************
qgscolorbuttonplugin.h
--------------------------------------
Date : 25.04.2014
Date : 18.08.2014
Copyright : (C) 2014 Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
@ -13,8 +13,8 @@
* *
***************************************************************************/
#ifndef QGSCOLORBUTTONPLUGIN_H
#define QGSCOLORBUTTONPLUGIN_H
#ifndef QgsColorButtonPLUGIN_H
#define QgsColorButtonPLUGIN_H
#include <QtGlobal>
@ -52,4 +52,4 @@ class CUSTOMWIDGETS_EXPORT QgsColorButtonPlugin : public QObject, public QDesign
QString whatsThis() const override;
QString domXml() const override;
};
#endif // QGSCOLORBUTTONPLUGIN_H
#endif // QgsColorButtonPLUGIN_H

View File

@ -1,97 +0,0 @@
/***************************************************************************
qgscolorbuttonv2plugin.cpp
--------------------------------------
Date : 18.08.2014
Copyright : (C) 2014 Denis Rouzaud
Email : denis.rouzaud@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 "qgscolorbuttonv2plugin.h"
#include "qgscolorbuttonv2.h"
QgsColorButtonV2Plugin::QgsColorButtonV2Plugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}
QString QgsColorButtonV2Plugin::name() const
{
return "QgsColorButtonV2";
}
QString QgsColorButtonV2Plugin::group() const
{
return QgisCustomWidgets::groupName();
}
QString QgsColorButtonV2Plugin::includeFile() const
{
return "qgscolorbuttonv2.h";
}
QIcon QgsColorButtonV2Plugin::icon() const
{
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
}
bool QgsColorButtonV2Plugin::isContainer() const
{
return false;
}
QWidget *QgsColorButtonV2Plugin::createWidget( QWidget *parent )
{
return new QgsColorButtonV2( parent );
}
bool QgsColorButtonV2Plugin::isInitialized() const
{
return mInitialized;
}
void QgsColorButtonV2Plugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}
QString QgsColorButtonV2Plugin::toolTip() const
{
return tr( "Select color" );
}
QString QgsColorButtonV2Plugin::whatsThis() const
{
return "";
}
QString QgsColorButtonV2Plugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mColorButton\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>27</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}

View File

@ -1,55 +0,0 @@
/***************************************************************************
qgscolorbuttonv2plugin.h
--------------------------------------
Date : 18.08.2014
Copyright : (C) 2014 Denis Rouzaud
Email : denis.rouzaud@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 QGSCOLORBUTTONV2PLUGIN_H
#define QGSCOLORBUTTONV2PLUGIN_H
#include <QtGlobal>
#if QT_VERSION < 0x050000
#include <QDesignerCustomWidgetCollectionInterface>
#include <QDesignerExportWidget>
#else
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
#include <QtUiPlugin/QDesignerExportWidget>
#endif
class CUSTOMWIDGETS_EXPORT QgsColorButtonV2Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )
public:
explicit QgsColorButtonV2Plugin( 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 // QGSCOLORBUTTONV2PLUGIN_H

View File

@ -183,7 +183,6 @@ SET(QGIS_GUI_SRCS
qgscodeeditorsql.cpp
qgscollapsiblegroupbox.cpp
qgscolorbutton.cpp
qgscolorbuttonv2.cpp
qgscolordialog.cpp
qgscolorschemelist.cpp
qgscolorswatchgrid.cpp
@ -343,7 +342,6 @@ SET(QGIS_GUI_MOC_HDRS
qgscodeeditorsql.h
qgscollapsiblegroupbox.h
qgscolorbutton.h
qgscolorbuttonv2.h
qgscolordialog.h
qgscolorschemelist.h
qgscolorswatchgrid.h

View File

@ -14,7 +14,7 @@
***************************************************************************/
#include "qgscolorwidgetwrapper.h"
#include "qgscolorbuttonv2.h"
#include "qgscolorbutton.h"
#include <QLayout>
@ -49,7 +49,7 @@ QWidget* QgsColorWidgetWrapper::createWidget( QWidget* parent )
container->setLayout( layout );
layout->setMargin( 0 );
layout->setContentsMargins( 0, 0, 0, 0 );
QgsColorButtonV2* button = new QgsColorButtonV2();
QgsColorButton* button = new QgsColorButton();
button->setContext( QString( "editor" ) );
layout->addWidget( button );
layout->addStretch();
@ -59,10 +59,10 @@ QWidget* QgsColorWidgetWrapper::createWidget( QWidget* parent )
void QgsColorWidgetWrapper::initWidget( QWidget* editor )
{
mColorButton = qobject_cast<QgsColorButtonV2*>( editor );
mColorButton = qobject_cast<QgsColorButton*>( editor );
if ( !mColorButton )
{
mColorButton = editor->findChild<QgsColorButtonV2*>();
mColorButton = editor->findChild<QgsColorButton*>();
}
mColorButton->setShowNull( true );

View File

@ -18,7 +18,7 @@
#include "qgseditorwidgetwrapper.h"
class QgsColorButtonV2;
class QgsColorButton;
/** \ingroup gui
* Wraps a color widget. Users will be able to choose a color.
@ -47,7 +47,7 @@ class GUI_EXPORT QgsColorWidgetWrapper : public QgsEditorWidgetWrapper
private:
void updateConstraintWidgetStatus( bool constraintValid ) override;
QgsColorButtonV2* mColorButton;
QgsColorButton* mColorButton;
};
#endif // QGSCOLORWIDGETWRAPPER_H

View File

@ -19,6 +19,9 @@
#include "qgslogger.h"
#include "qgssymbollayerv2utils.h"
#include "qgscursors.h"
#include "qgscolorswatchgrid.h"
#include "qgscolorschemeregistry.h"
#include "qgscolorwidgets.h"
#include <QPainter>
#include <QSettings>
@ -28,63 +31,58 @@
#include <QClipboard>
#include <QDrag>
#include <QDesktopWidget>
#include <QStyle>
#include <QStyleOptionToolButton>
#include <QWidgetAction>
#include <QLabel>
#include <QGridLayout>
#include <QPushButton>
#ifdef Q_OS_WIN
#include <windows.h>
QString QgsColorButton::fullPath( const QString &path )
{
TCHAR buf[MAX_PATH];
int len = GetLongPathName( path.toUtf8().constData(), buf, MAX_PATH );
if ( len == 0 || len > MAX_PATH )
{
QgsDebugMsg( QString( "GetLongPathName('%1') failed with %2: %3" )
.arg( path ).arg( len ).arg( GetLastError() ) );
return path;
}
QString res = QString::fromUtf8( buf );
return res;
}
#endif
/*!
\class QgsColorButton
\brief 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
A subclass of QPushButton is needed to draw the button content because
some platforms such as Mac OS X and Windows XP enforce a consistent
GUI look by always using the button color of the current style and
not allowing button backgrounds to be changed on a button by button basis.
Therefore, a wholely stylesheet-based button is used for the no-text variant.
This class is a simplified version of QtColorButton, an internal class used
by Qt Designer to do the same thing.
*/
QgsColorButton::QgsColorButton( QWidget *parent, const QString& cdt, const QColorDialog::ColorDialogOptions& cdo )
: QPushButton( parent )
QgsColorButton::QgsColorButton( QWidget *parent, const QString& cdt, QgsColorSchemeRegistry* registry )
: QToolButton( parent )
, mBehaviour( QgsColorButton::ShowDialog )
, mColorDialogTitle( cdt.isEmpty() ? tr( "Select Color" ) : cdt )
, mColor( Qt::black )
, mColorDialogOptions( cdo )
, mColor( QColor() )
, mDefaultColor( QColor() ) //default to invalid color
, mAllowAlpha( false )
, mAcceptLiveUpdates( true )
, mTempPNG( nullptr )
, mColorSet( false )
, mShowNoColorOption( false )
, mNoColorString( tr( "No color" ) )
, mShowNull( false )
, mPickingColor( false )
, mMenu( nullptr )
{
//if a color scheme registry was specified, use it, otherwise use the global instance
mColorSchemeRegistry = registry ? registry : QgsColorSchemeRegistry::instance();
setAcceptDrops( true );
connect( this, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
setMinimumSize( QSize( 24, 16 ) );
connect( this, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
//setup dropdown menu
mMenu = new QMenu( this );
connect( mMenu, SIGNAL( aboutToShow() ), this, SLOT( prepareMenu() ) );
setMenu( mMenu );
setPopupMode( QToolButton::MenuButtonPopup );
}
QgsColorButton::~QgsColorButton()
{
if ( mTempPNG.exists() )
mTempPNG.remove();
}
const QPixmap& QgsColorButton::transpBkgrd()
QSize QgsColorButton::sizeHint() const
{
//make sure height of button looks good under different platforms
#ifdef Q_OS_WIN
return QSize( 120, 22 );
#else
return QSize( 120, 28 );
#endif
}
const QPixmap& QgsColorButton::transparentBackground()
{
static QPixmap transpBkgrd;
@ -94,7 +92,7 @@ const QPixmap& QgsColorButton::transpBkgrd()
return transpBkgrd;
}
void QgsColorButton::onButtonClicked()
void QgsColorButton::showColorDialog()
{
QColor newColor;
QSettings settings;
@ -104,15 +102,16 @@ void QgsColorButton::onButtonClicked()
if ( useNative )
{
// use native o/s dialogs
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
{
newColor = QgsColorDialog::getLiveColor(
color(), this, SLOT( setValidColor( const QColor& ) ),
this->parentWidget(), mColorDialogTitle, mColorDialogOptions );
this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
}
else
{
newColor = QColorDialog::getColor( color(), this->parentWidget(), mColorDialogTitle, mColorDialogOptions );
newColor = QColorDialog::getColor( color(), this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
}
}
else
@ -122,13 +121,13 @@ void QgsColorButton::onButtonClicked()
{
newColor = QgsColorDialogV2::getLiveColor(
color(), this, SLOT( setValidColor( const QColor& ) ),
this->parentWidget(), mColorDialogTitle, mColorDialogOptions & QColorDialog::ShowAlphaChannel );
this->parentWidget(), mColorDialogTitle, mAllowAlpha );
}
else
{
QgsColorDialogV2 dialog( this, 0, color() );
dialog.setTitle( mColorDialogTitle );
dialog.setAllowAlpha( mColorDialogOptions & QColorDialog::ShowAlphaChannel );
dialog.setAllowAlpha( mAllowAlpha );
if ( dialog.exec() )
{
@ -140,12 +139,56 @@ void QgsColorButton::onButtonClicked()
if ( newColor.isValid() )
{
setValidColor( newColor );
addRecentColor( newColor );
}
// reactivate button's window
activateWindow();
}
void QgsColorButton::setToDefaultColor()
{
if ( !mDefaultColor.isValid() )
{
return;
}
setColor( mDefaultColor );
}
void QgsColorButton::setToNull()
{
setColor( QColor() );
}
bool QgsColorButton::event( QEvent *e )
{
if ( e->type() == QEvent::ToolTip )
{
QString name = this->color().name();
int hue = this->color().hue();
int value = this->color().value();
int saturation = this->color().saturation();
QString info = QString( "HEX: %1 \n"
"RGB: %2 \n"
"HSV: %3,%4,%4" ).arg( name )
.arg( QgsSymbolLayerV2Utils::encodeColor( this->color() ) )
.arg( hue ).arg( value ).arg( saturation );
setToolTip( info );
}
return QToolButton::event( e );
}
void QgsColorButton::setToNoColor()
{
if ( mAllowAlpha )
{
QColor noColor = QColor( mColor );
noColor.setAlpha( 0 );
setColor( noColor );
}
}
void QgsColorButton::mousePressEvent( QMouseEvent *e )
{
if ( mPickingColor )
@ -157,55 +200,34 @@ void QgsColorButton::mousePressEvent( QMouseEvent *e )
if ( e->button() == Qt::RightButton )
{
showContextMenu( e );
QToolButton::showMenu();
return;
}
else if ( e->button() == Qt::LeftButton )
{
mDragStartPosition = e->pos();
}
QPushButton::mousePressEvent( e );
}
QMimeData * QgsColorButton::createColorMimeData() const
{
QMimeData *mimeData = new QMimeData;
mimeData->setColorData( QVariant( mColor ) );
mimeData->setText( mColor.name() );
return mimeData;
QToolButton::mousePressEvent( e );
}
bool QgsColorButton::colorFromMimeData( const QMimeData * mimeData, QColor& resultColor )
{
//attempt to read color data directly from mime
QColor mimeColor = mimeData->colorData().value<QColor>();
bool hasAlpha = false;
QColor mimeColor = QgsSymbolLayerV2Utils::colorFromMimeData( mimeData, hasAlpha );
if ( mimeColor.isValid() )
{
if ( !( mColorDialogOptions & QColorDialog::ShowAlphaChannel ) )
if ( !mAllowAlpha )
{
//remove alpha channel
mimeColor.setAlpha( 255 );
}
resultColor = mimeColor;
return true;
}
//attempt to intrepret a color from mime text data
bool hasAlpha = false;
QColor textColor = QgsSymbolLayerV2Utils::parseColorWithAlpha( mimeData->text(), hasAlpha );
if ( textColor.isValid() )
{
if ( !( mColorDialogOptions & QColorDialog::ShowAlphaChannel ) )
{
//remove alpha channel
textColor.setAlpha( 255 );
}
else if ( !hasAlpha )
{
//mime color has no explicit alpha component, so keep existing alpha
textColor.setAlpha( mColor.alpha() );
mimeColor.setAlpha( mColor.alpha() );
}
resultColor = textColor;
resultColor = mimeColor;
return true;
}
@ -232,37 +254,25 @@ void QgsColorButton::mouseMoveEvent( QMouseEvent *e )
}
//handle dragging colors from button
if ( !( e->buttons() & Qt::LeftButton ) )
if ( !( e->buttons() & Qt::LeftButton ) || !mColor.isValid() )
{
QPushButton::mouseMoveEvent( e );
//left button not depressed or no color set, so not a drag
QToolButton::mouseMoveEvent( e );
return;
}
if (( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
{
QPushButton::mouseMoveEvent( e );
//mouse not moved, so not a drag
QToolButton::mouseMoveEvent( e );
return;
}
//user is dragging color
QDrag *drag = new QDrag( this );
drag->setMimeData( createColorMimeData() );
//craft a pixmap for the drag icon
QImage colorImage( 50, 50, QImage::Format_RGB32 );
QPainter imagePainter;
imagePainter.begin( &colorImage );
//start with a light gray background
imagePainter.fillRect( QRect( 0, 0, 50, 50 ), QBrush( QColor( 200, 200, 200 ) ) );
//draw rect with white border, filled with current color
QColor pixmapColor = mColor;
pixmapColor.setAlpha( 255 );
imagePainter.setBrush( QBrush( pixmapColor ) );
imagePainter.setPen( QPen( Qt::white ) );
imagePainter.drawRect( QRect( 1, 1, 47, 47 ) );
imagePainter.end();
//set as drag pixmap
drag->setPixmap( QPixmap::fromImage( colorImage ) );
drag->setMimeData( QgsSymbolLayerV2Utils::colorToMimeData( mColor ) );
drag->setPixmap( QgsColorWidget::createDragIcon( mColor ) );
drag->exec( Qt::CopyAction );
setDown( false );
}
@ -277,13 +287,14 @@ void QgsColorButton::mouseReleaseEvent( QMouseEvent *e )
return;
}
QPushButton::mouseReleaseEvent( e );
QToolButton::mouseReleaseEvent( e );
}
void QgsColorButton::stopPicking( QPointF eventPos, bool sampleColor )
{
//release mouse and reset cursor
//release mouse and keyboard, and reset cursor
releaseMouse();
releaseKeyboard();
unsetCursor();
mPickingColor = false;
@ -298,14 +309,15 @@ void QgsColorButton::stopPicking( QPointF eventPos, bool sampleColor )
QImage snappedImage = snappedPixmap.toImage();
//extract color from pixel and set color
setColor( snappedImage.pixel( 0, 0 ) );
addRecentColor( mColor );
}
void QgsColorButton::keyPressEvent( QKeyEvent *e )
{
if ( !mPickingColor )
{
//if not picking a color, use default push button behaviour
QPushButton::keyPressEvent( e );
//if not picking a color, use default tool button behaviour
QToolButton::keyPressEvent( e );
return;
}
@ -319,93 +331,188 @@ void QgsColorButton::dragEnterEvent( QDragEnterEvent *e )
QColor mimeColor;
if ( colorFromMimeData( e->mimeData(), mimeColor ) )
{
//if so, we accept the drag, and temporarily change the button's color
//to match the dragged color. This gives immediate feedback to the user
//that colors can be dropped here
e->acceptProposedAction();
setButtonBackground( mimeColor );
}
}
void QgsColorButton::dragLeaveEvent( QDragLeaveEvent *e )
{
Q_UNUSED( e );
//reset button color
setButtonBackground( mColor );
}
void QgsColorButton::dropEvent( QDropEvent *e )
{
//is dropped data valid color data?
QColor mimeColor;
if ( colorFromMimeData( e->mimeData(), mimeColor ) )
{
//accept drop and set new color
e->acceptProposedAction();
setColor( mimeColor );
addRecentColor( mimeColor );
}
}
void QgsColorButton::showContextMenu( QMouseEvent *event )
{
QMenu colorContextMenu;
QAction* copyColorAction = new QAction( tr( "Copy color" ), nullptr );
colorContextMenu.addAction( copyColorAction );
QAction* pasteColorAction = new QAction( tr( "Paste color" ), nullptr );
pasteColorAction->setEnabled( false );
colorContextMenu.addAction( pasteColorAction );
#ifndef Q_OS_MAC
//disabled for OSX, as it is impossible to grab the mouse under OSX
//see note for QWidget::grabMouse() re OSX Cocoa
//http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse
QAction* pickColorAction = new QAction( tr( "Pick color" ), nullptr );
colorContextMenu.addSeparator();
colorContextMenu.addAction( pickColorAction );
#endif
QColor clipColor;
if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
{
pasteColorAction->setEnabled( true );
}
QAction* selectedAction = colorContextMenu.exec( event->globalPos() );
if ( selectedAction == copyColorAction )
{
//copy color
QApplication::clipboard()->setMimeData( createColorMimeData() );
}
else if ( selectedAction == pasteColorAction )
{
//paste color
setColor( clipColor );
}
#ifndef Q_OS_MAC
else if ( selectedAction == pickColorAction )
{
//pick color
QPixmap samplerPixmap = QPixmap(( const char ** ) sampler_cursor );
setCursor( QCursor( samplerPixmap, 0, 0 ) );
grabMouse();
mPickingColor = true;
}
delete pickColorAction;
#endif
delete copyColorAction;
delete pasteColorAction;
}
void QgsColorButton::setValidColor( const QColor& newColor )
{
if ( newColor.isValid() )
{
setColor( newColor );
addRecentColor( newColor );
}
}
QPixmap QgsColorButton::createMenuIcon( const QColor &color, const bool showChecks )
{
//create an icon pixmap
QPixmap pixmap( 16, 16 );
pixmap.fill( Qt::transparent );
QPainter p;
p.begin( &pixmap );
//start with checkboard pattern
if ( showChecks )
{
QBrush checkBrush = QBrush( transparentBackground() );
p.setPen( Qt::NoPen );
p.setBrush( checkBrush );
p.drawRect( 0, 0, 15, 15 );
}
//draw color over pattern
p.setBrush( QBrush( color ) );
//draw border
p.setPen( QColor( 197, 197, 197 ) );
p.drawRect( 0, 0, 15, 15 );
p.end();
return pixmap;
}
void QgsColorButton::buttonClicked()
{
switch ( mBehaviour )
{
case ShowDialog:
showColorDialog();
return;
case SignalOnly:
emit colorClicked( mColor );
return;
}
}
void QgsColorButton::prepareMenu()
{
//we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
//QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
//for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
//menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
mMenu->clear();
if ( mShowNull )
{
QAction* nullAction = new QAction( tr( "Clear color" ), this );
nullAction->setIcon( createMenuIcon( Qt::transparent, false ) );
mMenu->addAction( nullAction );
connect( nullAction, SIGNAL( triggered() ), this, SLOT( setToNull() ) );
}
//show default color option if set
if ( mDefaultColor.isValid() )
{
QAction* defaultColorAction = new QAction( tr( "Default color" ), this );
defaultColorAction->setIcon( createMenuIcon( mDefaultColor ) );
mMenu->addAction( defaultColorAction );
connect( defaultColorAction, SIGNAL( triggered() ), this, SLOT( setToDefaultColor() ) );
}
if ( mShowNoColorOption && mAllowAlpha )
{
QAction* noColorAction = new QAction( mNoColorString, this );
noColorAction->setIcon( createMenuIcon( Qt::transparent, false ) );
mMenu->addAction( noColorAction );
connect( noColorAction, SIGNAL( triggered() ), this, SLOT( setToNoColor() ) );
}
mMenu->addSeparator();
QgsColorWheel* colorWheel = new QgsColorWheel( mMenu );
colorWheel->setColor( color() );
QgsColorWidgetAction* colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu );
colorAction->setDismissOnColorSelection( false );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
mMenu->addAction( colorAction );
if ( mColorSchemeRegistry )
{
//get schemes with ShowInColorButtonMenu flag set
QList< QgsColorScheme* > schemeList = mColorSchemeRegistry->schemes( QgsColorScheme::ShowInColorButtonMenu );
QList< QgsColorScheme* >::iterator it = schemeList.begin();
for ( ; it != schemeList.end(); ++it )
{
QgsColorSwatchGridAction* colorAction = new QgsColorSwatchGridAction( *it, mMenu, mContext, this );
colorAction->setBaseColor( mColor );
mMenu->addAction( colorAction );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setValidColor( const QColor& ) ) );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( addRecentColor( const QColor& ) ) );
}
}
mMenu->addSeparator();
QAction* copyColorAction = new QAction( tr( "Copy color" ), this );
mMenu->addAction( copyColorAction );
connect( copyColorAction, SIGNAL( triggered() ), this, SLOT( copyColor() ) );
QAction* pasteColorAction = new QAction( tr( "Paste color" ), this );
//enable or disable paste action based on current clipboard contents. We always show the paste
//action, even if it's disabled, to give hint to the user that pasting colors is possible
QColor clipColor;
if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
{
pasteColorAction->setIcon( createMenuIcon( clipColor ) );
}
else
{
pasteColorAction->setEnabled( false );
}
mMenu->addAction( pasteColorAction );
connect( pasteColorAction, SIGNAL( triggered() ), this, SLOT( pasteColor() ) );
#ifndef Q_OS_MAC
//disabled for OSX, as it is impossible to grab the mouse under OSX
//see note for QWidget::grabMouse() re OSX Cocoa
//http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse
QAction* pickColorAction = new QAction( tr( "Pick color" ), this );
mMenu->addAction( pickColorAction );
connect( pickColorAction, SIGNAL( triggered() ), this, SLOT( activatePicker() ) );
#endif
QAction* chooseColorAction = new QAction( tr( "Choose color..." ), this );
mMenu->addAction( chooseColorAction );
connect( chooseColorAction, SIGNAL( triggered() ), this, SLOT( showColorDialog() ) );
}
void QgsColorButton::changeEvent( QEvent* e )
{
if ( e->type() == QEvent::EnabledChange )
{
setButtonBackground();
}
QPushButton::changeEvent( e );
QToolButton::changeEvent( e );
}
#if 0 // causes too many cyclical updates, but may be needed on some platforms
void QgsColorButton::paintEvent( QPaintEvent* e )
{
QPushButton::paintEvent( e );
QToolButton::paintEvent( e );
if ( !mBackgroundSet )
{
@ -417,15 +524,19 @@ void QgsColorButton::paintEvent( QPaintEvent* e )
void QgsColorButton::showEvent( QShowEvent* e )
{
setButtonBackground();
QPushButton::showEvent( e );
QToolButton::showEvent( e );
}
void QgsColorButton::resizeEvent( QResizeEvent *event )
{
QToolButton::resizeEvent( event );
//recalculate icon size and redraw icon
mIconSize = QSize();
setButtonBackground( mColor );
}
void QgsColorButton::setColor( const QColor &color )
{
if ( !color.isValid() )
{
return;
}
QColor oldColor = mColor;
mColor = color;
@ -443,134 +554,109 @@ void QgsColorButton::setColor( const QColor &color )
mColorSet = true;
}
void QgsColorButton::setButtonBackground( QColor color )
void QgsColorButton::addRecentColor( const QColor& color )
{
QgsRecentColorScheme::addRecentColor( color );
}
void QgsColorButton::setButtonBackground( const QColor &color )
{
QColor backgroundColor = color;
if ( !color.isValid() )
{
color = mColor;
backgroundColor = mColor;
}
if ( !text().isEmpty() )
QSize currentIconSize;
//icon size is button size with a small margin
if ( menu() )
{
// generate icon pixmap for regular pushbutton
setFlat( false );
QPixmap pixmap;
pixmap = QPixmap( iconSize() );
pixmap.fill( QColor( 0, 0, 0, 0 ) );
int iconW = iconSize().width();
int iconH = iconSize().height();
QRect rect( 0, 0, iconW, iconH );
// QPainterPath::addRoundRect has flaws, draw chamfered corners instead
QPainterPath roundRect;
int chamfer = 3;
int inset = 1;
roundRect.moveTo( chamfer, inset );
roundRect.lineTo( iconW - chamfer, inset );
roundRect.lineTo( iconW - inset, chamfer );
roundRect.lineTo( iconW - inset, iconH - chamfer );
roundRect.lineTo( iconW - chamfer, iconH - inset );
roundRect.lineTo( chamfer, iconH - inset );
roundRect.lineTo( inset, iconH - chamfer );
roundRect.lineTo( inset, chamfer );
roundRect.closeSubpath();
QPainter p;
p.begin( &pixmap );
p.setRenderHint( QPainter::Antialiasing );
p.setClipPath( roundRect );
p.setPen( Qt::NoPen );
if ( color.alpha() < 255 )
if ( !mIconSize.isValid() )
{
p.drawTiledPixmap( rect, transpBkgrd() );
//calculate size of push button part of widget (ie, without the menu dropdown button part)
QStyleOptionToolButton opt;
initStyleOption( &opt );
QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
this );
//make sure height of icon looks good under different platforms
#ifdef Q_OS_WIN
mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
#else
mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
#endif
}
p.setBrush( color );
p.drawRect( rect );
p.end();
// set this pixmap as icon
setIcon( QIcon( pixmap ) );
currentIconSize = mIconSize;
}
else
{
// generate temp background image file with checkerboard canvas to be used via stylesheet
// set flat, or inline spacing (widget margins) needs to be manually calculated and set
setFlat( true );
bool useAlpha = ( mColorDialogOptions & QColorDialog::ShowAlphaChannel );
// in case margins need to be adjusted
QString margin = QString( "%1px %2px %3px %4px" ).arg( 0 ).arg( 0 ).arg( 0 ).arg( 0 );
//QgsDebugMsg( QString( "%1 margin: %2" ).arg( objectName() ).arg( margin ) );
QString bkgrd = QString( " background-color: rgba(%1,%2,%3,%4);" )
.arg( color.red() )
.arg( color.green() )
.arg( color.blue() )
.arg( useAlpha ? color.alpha() : 255 );
if ( useAlpha && color.alpha() < 255 )
{
QPixmap pixmap = transpBkgrd();
QRect rect( 0, 0, pixmap.width(), pixmap.height() );
QPainter p;
p.begin( &pixmap );
p.setRenderHint( QPainter::Antialiasing );
p.setPen( Qt::NoPen );
p.setBrush( mColor );
p.drawRect( rect );
p.end();
if ( mTempPNG.open() )
{
mTempPNG.setAutoRemove( false );
pixmap.save( mTempPNG.fileName(), "PNG" );
mTempPNG.close();
}
QString bgFileName = mTempPNG.fileName();
//no menu
#ifdef Q_OS_WIN
//on windows, mTempPNG will use a shortened path for the temporary folder name
//this does not work with stylesheets, resulting in the whole button disappearing (#10187)
bgFileName = fullPath( bgFileName );
currentIconSize = QSize( width() - 10, height() - 6 );
#else
currentIconSize = QSize( width() - 10, height() - 12 );
#endif
bkgrd = QString( " background-image: url(%1);" ).arg( bgFileName );
}
if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
{
return;
}
//create an icon pixmap
QPixmap pixmap( currentIconSize );
pixmap.fill( Qt::transparent );
if ( backgroundColor.isValid() )
{
QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
QPainter p;
p.begin( &pixmap );
p.setRenderHint( QPainter::Antialiasing );
p.setPen( Qt::NoPen );
if ( mAllowAlpha && backgroundColor.alpha() < 255 )
{
//start with checkboard pattern
QBrush checkBrush = QBrush( transparentBackground() );
p.setBrush( checkBrush );
p.drawRoundedRect( rect, 3, 3 );
}
// TODO: get OS-style focus color and switch border to that color when button in focus
setStyleSheet( QString( "QgsColorButton{"
" %1"
" background-position: top left;"
" background-origin: content;"
" background-clip: content;"
" padding: 2px;"
" margin: %2;"
" outline: none;"
" border-style: %4;"
" border-width: 1px;"
" border-color: rgb(%3,%3,%3);"
" border-radius: 3px;} "
"QgsColorButton:pressed{"
" %1"
" background-position: top left;"
" background-origin: content;"
" background-clip: content;"
" padding: 1px;"
" margin: %2;"
" outline: none;"
" border-style: inset;"
" border-width: 2px;"
" border-color: rgb(128,128,128);"
" border-radius: 4px;} " )
.arg( bkgrd,
margin,
isEnabled() ? "128" : "110",
isEnabled() ? "outset" : "dotted" ) );
//draw semi-transparent color on top
p.setBrush( backgroundColor );
p.drawRoundedRect( rect, 3, 3 );
p.end();
}
setIconSize( currentIconSize );
setIcon( pixmap );
}
void QgsColorButton::copyColor()
{
//copy color
QApplication::clipboard()->setMimeData( QgsSymbolLayerV2Utils::colorToMimeData( mColor ) );
}
void QgsColorButton::pasteColor()
{
QColor clipColor;
if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
{
//paste color
setColor( clipColor );
addRecentColor( clipColor );
}
}
void QgsColorButton::activatePicker()
{
//pick color
QPixmap samplerPixmap = QPixmap(( const char ** ) sampler_cursor );
setCursor( QCursor( samplerPixmap, 0, 0 ) );
grabMouse();
grabKeyboard();
mPickingColor = true;
}
QColor QgsColorButton::color() const
@ -578,22 +664,52 @@ QColor QgsColorButton::color() const
return mColor;
}
void QgsColorButton::setColorDialogOptions( const QColorDialog::ColorDialogOptions& cdo )
void QgsColorButton::setAllowAlpha( const bool allowAlpha )
{
mColorDialogOptions = cdo;
mAllowAlpha = allowAlpha;
}
QColorDialog::ColorDialogOptions QgsColorButton::colorDialogOptions()
void QgsColorButton::setColorDialogTitle( const QString& title )
{
return mColorDialogOptions;
mColorDialogTitle = title;
}
void QgsColorButton::setColorDialogTitle( const QString& cdt )
{
mColorDialogTitle = cdt;
}
QString QgsColorButton::colorDialogTitle()
QString QgsColorButton::colorDialogTitle() const
{
return mColorDialogTitle;
}
void QgsColorButton::setShowMenu( const bool showMenu )
{
setMenu( showMenu ? mMenu : nullptr );
setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
//force recalculation of icon size
mIconSize = QSize();
setButtonBackground( mColor );
}
void QgsColorButton::setBehaviour( const QgsColorButton::Behaviour behaviour )
{
mBehaviour = behaviour;
}
void QgsColorButton::setDefaultColor( const QColor& color )
{
mDefaultColor = color;
}
void QgsColorButton::setShowNull( bool showNull )
{
mShowNull = showNull;
}
bool QgsColorButton::showNull() const
{
return mShowNull;
}
bool QgsColorButton::isNull() const
{
return !mColor.isValid();
}

View File

@ -16,114 +16,315 @@
#define QGSCOLORBUTTON_H
#include <QColorDialog>
#include <QPushButton>
#include <QToolButton>
#include <QTemporaryFile>
class QMimeData;
class QgsColorSchemeRegistry;
/** \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
* Offers live updates to button from color chooser dialog. An attached drop down menu allows for copying
* and pasting colors, picking colors from the screen, and selecting colors from color swatch grids.
* \note Added in version 2.5
*/
class GUI_EXPORT QgsColorButton: public QPushButton
class GUI_EXPORT QgsColorButton : public QToolButton
{
Q_OBJECT
Q_ENUMS( Behaviour )
Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
Q_PROPERTY( QColor color READ color WRITE setColor )
Q_FLAGS( QColorDialog::ColorDialogOptions )
Q_PROPERTY( QColorDialog::ColorDialogOptions colorDialogOptions READ colorDialogOptions WRITE setColorDialogOptions )
Q_PROPERTY( bool allowAlpha READ allowAlpha WRITE setAllowAlpha )
Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
Q_PROPERTY( Behaviour behaviour READ behaviour WRITE setBehaviour )
Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
Q_PROPERTY( bool showNoColor READ showNoColor WRITE setShowNoColor )
Q_PROPERTY( QString noColorString READ noColorString WRITE setNoColorString )
Q_PROPERTY( QString context READ context WRITE setContext )
public:
/**
* Construct a new color button.
*
/** Specifies the behaviour when the button is clicked
*/
enum Behaviour
{
ShowDialog = 0, /*!< show a color picker dialog when clicked */
SignalOnly /*!< emit colorClicked signal only, no dialog */
};
/** 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
* @param registry a color scheme registry for color swatch grids to show in the drop down menu. If not
* specified, the button will use the global color scheme registry
*/
QgsColorButton( QWidget *parent = nullptr, const QString& cdt = "", const QColorDialog::ColorDialogOptions& cdo = QColorDialog::ColorDialogOptions() );
~QgsColorButton();
QgsColorButton( QWidget *parent = nullptr, const QString& cdt = "", QgsColorSchemeRegistry* registry = nullptr );
/**
* Specify the current color. Will emit a colorChanged signal if the color is different to the previous.
*
* @param color the new color
*/
void setColor( const QColor &color );
/**
* Return the currently selected color.
*
* @return the currently selected color
virtual ~QgsColorButton();
virtual QSize sizeHint() const override;
/** Return the currently selected color.
* @returns currently selected color
* @see setColor
*/
QColor color() const;
/**
* Specify the options for the color chooser dialog (e.g. alpha).
*
* @param cdo Options for the color chooser dialog
/** Sets whether alpha modification (transparency) is permitted
* for the color. Defaults to false.
* @param allowAlpha set to true to allow alpha modification
* @see allowAlpha
*/
void setColorDialogOptions( const QColorDialog::ColorDialogOptions& cdo );
void setAllowAlpha( const bool allowAlpha );
/**
* Returns the options for the color chooser dialog.
*
* @return Options for the color chooser dialog
/** Returns whether alpha modification (transparency) is permitted
* for the color.
* @returns true if alpha modification is allowed
* @see setAllowAlpha
*/
QColorDialog::ColorDialogOptions colorDialogOptions();
bool allowAlpha() const { return mAllowAlpha; }
/**
* Set the title, which the color chooser dialog will show.
*
* @param cdt Title for the color chooser dialog
/** Set the title for the color chooser dialog window.
* @param title Title for the color chooser dialog
* @see colorDialogTitle
*/
void setColorDialogTitle( const QString& cdt );
void setColorDialogTitle( const QString& title );
/**
* Returns the title, which the color chooser dialog shows.
*
* @return Title for the color chooser dialog
/** Returns the title for the color chooser dialog window.
* @returns title for the color chooser dialog
* @see setColorDialogTitle
*/
QString colorDialogTitle();
QString colorDialogTitle() const;
/**
* Whether the button accepts live updates from QColorDialog.
/** Returns whether the button accepts live updates from QColorDialog.
* @returns true if the button will be accepted immediately when the dialog's color changes
* @see setAcceptLiveUpdates
*/
bool acceptLiveUpdates() { return mAcceptLiveUpdates; }
bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
/**
* Sets whether the button accepts live updates from QColorDialog.
* Live updates may cause changes that are not undoable on QColorDialog cancel.
/** Sets whether the button accepts live updates from QColorDialog. Live updates may cause changes
* that are not undoable on QColorDialog cancel.
* @param accept set to true to enable live updates
* @see acceptLiveUpdates
*/
void setAcceptLiveUpdates( bool accept ) { mAcceptLiveUpdates = accept; }
void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
/** Sets whether the drop down menu should be shown for the button. The default behaviour is to
* show the menu.
* @param showMenu set to false to hide the drop down menu
* @see showMenu
*/
void setShowMenu( const bool showMenu );
/** Returns whether the drop down menu is shown for the button.
* @returns true if drop down menu is shown
* @see setShowMenu
*/
bool showMenu() const { return menu() ? true : false; }
/** Sets the behaviour for when the button is clicked. The default behaviour is to show
* a color picker dialog.
* @param behaviour behaviour when button is clicked
* @see behaviour
*/
void setBehaviour( const Behaviour behaviour );
/** Returns the behaviour for when the button is clicked.
* @returns behaviour when button is clicked
* @see setBehaviour
*/
Behaviour behaviour() const { return mBehaviour; }
/** Sets the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @param color default color for the button. Set to an invalid QColor to disable the default color
* option.
* @see defaultColor
*/
void setDefaultColor( const QColor& color );
/** Returns the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @returns default color for the button. Returns an invalid QColor if the default color
* option is disabled.
* @see setDefaultColor
*/
QColor defaultColor() const { return mDefaultColor; }
/** Sets whether the "no color" option should be shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @param showNoColorOption set to true to show the no color option. This is disabled by default.
* @see showNoColor
* @see setNoColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setShowNoColor( const bool showNoColorOption ) { mShowNoColorOption = showNoColorOption; }
/** Returns whether the "no color" option is shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @returns true if the no color option is shown.
* @see setShowNoColor
* @see noColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
bool showNoColor() const { return mShowNoColorOption; }
/** Sets the string to use for the "no color" option in the button's drop down menu.
* @param noColorString string to use for the "no color" menu option
* @see noColorString
* @see setShowNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setNoColorString( const QString& noColorString ) { mNoColorString = noColorString; }
/** Sets whether a set to null (clear) option is shown in the button's drop down menu.
* @param showNull set to true to show a null option
* @note added in QGIS 2.16
* @see showNull()
* @see isNull()
*/
void setShowNull( bool showNull );
/** Returns whether the set to null (clear) option is shown in the button's drop down menu.
* @note added in QGIS 2.16
* @see setShowNull()
* @see isNull()
*/
bool showNull() const;
/** Returns true if the current color is null.
* @note added in QGIS 2.16
* @see setShowNull()
* @see showNull()
*/
bool isNull() const;
/** Returns the string used for the "no color" option in the button's drop down menu.
* @returns string used for the "no color" menu option
* @see setNoColorString
* @see showNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
QString noColorString() const { return mNoColorString; }
/** Sets the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @param context context string for the color button's color swatch grids
* @see context
*/
void setContext( const QString& context ) { mContext = context; }
/** Returns the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @returns context string for the color button's color swatch grids
* @see setContext
*/
QString context() const { return mContext; }
/** Sets the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @param registry color scheme registry for the button. Set to 0 to hide all color
* swatch grids from the button's drop down menu.
* @see colorSchemeRegistry
*/
void setColorSchemeRegistry( QgsColorSchemeRegistry* registry ) { mColorSchemeRegistry = registry; }
/** Returns the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @returns color scheme registry for the button. If returned value is 0 then all color
* swatch grids are hidden from the button's drop down menu.
* @see setColorSchemeRegistry
*/
QgsColorSchemeRegistry* colorSchemeRegistry() { return mColorSchemeRegistry; }
public slots:
/**
* Sets the background pixmap for the button based upon color and transparency.
/** Sets the current color for the button. Will emit a colorChanged signal if the color is different
* to the previous color.
* @param color new color for the button
* @see color
*/
void setColor( const QColor &color );
/** Sets the background pixmap for the button based upon color and transparency.
* 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
* @param color Color for button background
* @param color Color for button background. If no color is specified, the button's current
* color will be used
*/
void setButtonBackground( QColor color = QColor() );
void setButtonBackground( const QColor &color = QColor() );
/** Copies the current color to the clipboard
* @see pasteColor
*/
void copyColor();
/** Pastes a color from the clipboard to the color button. If clipboard does not contain a valid
* color or string representation of a color, then no change is applied.
* @see copyColor
*/
void pasteColor();
/** Activates the color picker tool, which allows for sampling a color from anywhere on the screen
*/
void activatePicker();
/** Sets color to a totally transparent color.
* @note If the color button is not set to show an alpha channel in the color
* dialog (see setColorDialogOptions) then the color will not be changed.
* @see setToNull()
*/
void setToNoColor();
/** Sets color to the button's default color, if set.
* @see setDefaultColor
* @see defaultColor
* @see setToNull()
*/
void setToDefaultColor();
/** Sets color to null.
* @see setToDefaultColor()
* @see setToNoColor()
* @note added in QGIS 2.16
*/
void setToNull();
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.
*
/** Is emitted whenever a new color is set for the button. 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 );
/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
* @param color button color
* @see setBehaviour
* @see behaviour
*/
void colorClicked( const QColor &color );
protected:
bool event( QEvent *e ) override;
void changeEvent( QEvent* e ) override;
void showEvent( QShowEvent* e ) override;
static const QPixmap& transpBkgrd();
void resizeEvent( QResizeEvent *event ) override;
/** Returns a checkboard pattern pixmap for use as a background to transparent colors
*/
static const QPixmap& transparentBackground();
/**
* Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
@ -150,72 +351,82 @@ class GUI_EXPORT QgsColorButton: public QPushButton
*/
void dragEnterEvent( QDragEnterEvent * e ) override;
/**
* Reimplemented to reset button appearance after drag leave
*/
void dragLeaveEvent( QDragLeaveEvent *e ) override;
/**
* Reimplemented to accept dropped colors
*/
void dropEvent( QDropEvent *e ) override;
private:
Behaviour mBehaviour;
QString mColorDialogTitle;
QColor mColor;
QColorDialog::ColorDialogOptions mColorDialogOptions;
QgsColorSchemeRegistry* mColorSchemeRegistry;
QColor mDefaultColor;
QString mContext;
bool mAllowAlpha;
bool mAcceptLiveUpdates;
QTemporaryFile mTempPNG;
bool mColorSet; // added in QGIS 2.1
bool mColorSet;
bool mShowNoColorOption;
QString mNoColorString;
bool mShowNull;
QPoint mDragStartPosition;
bool mPickingColor;
/**
* Shows the color button context menu and handles copying and pasting color values.
*/
void showContextMenu( QMouseEvent* event );
QMenu* mMenu;
/**
* Creates mime data from the current color. Sets both the mime data's color data, and the
* mime data's text with the color's hex code.
* @note added in 2.3
* @see colorFromMimeData
*/
QMimeData* createColorMimeData() const;
QSize mIconSize;
/**
* Attempts to parse mimeData as a color, either via the mime data's color data or by
/** Attempts to parse mimeData as a color, either via the mime data's color data or by
* parsing a textual representation of a color.
* @returns true if mime data could be intrepreted as a color
* @param mimeData mime data
* @param resultColor QColor to store evaluated color
* @note added in 2.3
* @see createColorMimeData
*/
bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
#ifdef Q_OS_WIN
/**
* Expands a shortened Windows path to its full path name.
* @returns full path name.
* @param path a (possibly) shortened Windows path
* @note added in 2.3
*/
QString fullPath( const QString &path );
#endif
/**
* Ends a color picking operation
/** Ends a color picking operation
* @param eventPos global position of pixel to sample color from
* @param sampleColor set to true to actually sample the color, false to just cancel
* the color picking operation
* @note added in 2.5
*/
void stopPicking( QPointF eventPos, bool sampleColor = true );
private slots:
void onButtonClicked();
/** Create a color icon for display in the drop down menu
* @param color for icon
* @param showChecks set to true to display a checkboard pattern behind
* transparent colors
*/
QPixmap createMenuIcon( const QColor &color, const bool showChecks = true );
/**
* Sets color for button, if valid.
private slots:
void buttonClicked();
void showColorDialog();
/** Sets color for button, if valid.
*/
void setValidColor( const QColor& newColor );
/** Adds a color to the recent colors list
* @param color to add to recent colors list
*/
void addRecentColor( const QColor& color );
/** Creates the drop down menu entries
*/
void prepareMenu();
};
#endif

View File

@ -1,715 +0,0 @@
/***************************************************************************
qgscolorbuttonv2.cpp - Button which displays a color
--------------------------------------
Date : 12-Dec-2006
Copyright : (C) 2006 by Tom Elwertowski
Email : telwertowski at users dot sourceforge dot net
***************************************************************************
* *
* 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 "qgscolorbuttonv2.h"
#include "qgscolordialog.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgssymbollayerv2utils.h"
#include "qgscursors.h"
#include "qgscolorswatchgrid.h"
#include "qgscolorschemeregistry.h"
#include "qgscolorwidgets.h"
#include <QPainter>
#include <QSettings>
#include <QTemporaryFile>
#include <QMouseEvent>
#include <QMenu>
#include <QClipboard>
#include <QDrag>
#include <QDesktopWidget>
#include <QStyle>
#include <QStyleOptionToolButton>
#include <QWidgetAction>
#include <QLabel>
#include <QGridLayout>
#include <QPushButton>
QgsColorButtonV2::QgsColorButtonV2( QWidget *parent, const QString& cdt, QgsColorSchemeRegistry* registry )
: QToolButton( parent )
, mBehaviour( QgsColorButtonV2::ShowDialog )
, mColorDialogTitle( cdt.isEmpty() ? tr( "Select Color" ) : cdt )
, mColor( QColor() )
, mDefaultColor( QColor() ) //default to invalid color
, mAllowAlpha( false )
, mAcceptLiveUpdates( true )
, mColorSet( false )
, mShowNoColorOption( false )
, mNoColorString( tr( "No color" ) )
, mShowNull( false )
, mPickingColor( false )
, mMenu( nullptr )
{
//if a color scheme registry was specified, use it, otherwise use the global instance
mColorSchemeRegistry = registry ? registry : QgsColorSchemeRegistry::instance();
setAcceptDrops( true );
setMinimumSize( QSize( 24, 16 ) );
connect( this, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
//setup dropdown menu
mMenu = new QMenu( this );
connect( mMenu, SIGNAL( aboutToShow() ), this, SLOT( prepareMenu() ) );
setMenu( mMenu );
setPopupMode( QToolButton::MenuButtonPopup );
}
QgsColorButtonV2::~QgsColorButtonV2()
{
}
QSize QgsColorButtonV2::sizeHint() const
{
//make sure height of button looks good under different platforms
#ifdef Q_OS_WIN
return QSize( 120, 22 );
#else
return QSize( 120, 28 );
#endif
}
const QPixmap& QgsColorButtonV2::transparentBackground()
{
static QPixmap transpBkgrd;
if ( transpBkgrd.isNull() )
transpBkgrd = QgsApplication::getThemePixmap( "/transp-background_8x8.png" );
return transpBkgrd;
}
void QgsColorButtonV2::showColorDialog()
{
QColor newColor;
QSettings settings;
//using native color dialogs?
bool useNative = settings.value( "/qgis/native_color_dialogs", false ).toBool();
if ( useNative )
{
// use native o/s dialogs
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
{
newColor = QgsColorDialog::getLiveColor(
color(), this, SLOT( setValidColor( const QColor& ) ),
this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
}
else
{
newColor = QColorDialog::getColor( color(), this->parentWidget(), mColorDialogTitle, mAllowAlpha ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 );
}
}
else
{
//use QGIS style color dialogs
if ( mAcceptLiveUpdates && settings.value( "/qgis/live_color_dialogs", false ).toBool() )
{
newColor = QgsColorDialogV2::getLiveColor(
color(), this, SLOT( setValidColor( const QColor& ) ),
this->parentWidget(), mColorDialogTitle, mAllowAlpha );
}
else
{
QgsColorDialogV2 dialog( this, 0, color() );
dialog.setTitle( mColorDialogTitle );
dialog.setAllowAlpha( mAllowAlpha );
if ( dialog.exec() )
{
newColor = dialog.color();
}
}
}
if ( newColor.isValid() )
{
setValidColor( newColor );
addRecentColor( newColor );
}
// reactivate button's window
activateWindow();
}
void QgsColorButtonV2::setToDefaultColor()
{
if ( !mDefaultColor.isValid() )
{
return;
}
setColor( mDefaultColor );
}
void QgsColorButtonV2::setToNull()
{
setColor( QColor() );
}
bool QgsColorButtonV2::event( QEvent *e )
{
if ( e->type() == QEvent::ToolTip )
{
QString name = this->color().name();
int hue = this->color().hue();
int value = this->color().value();
int saturation = this->color().saturation();
QString info = QString( "HEX: %1 \n"
"RGB: %2 \n"
"HSV: %3,%4,%4" ).arg( name )
.arg( QgsSymbolLayerV2Utils::encodeColor( this->color() ) )
.arg( hue ).arg( value ).arg( saturation );
setToolTip( info );
}
return QToolButton::event( e );
}
void QgsColorButtonV2::setToNoColor()
{
if ( mAllowAlpha )
{
QColor noColor = QColor( mColor );
noColor.setAlpha( 0 );
setColor( noColor );
}
}
void QgsColorButtonV2::mousePressEvent( QMouseEvent *e )
{
if ( mPickingColor )
{
//don't show dialog if in color picker mode
e->accept();
return;
}
if ( e->button() == Qt::RightButton )
{
QToolButton::showMenu();
return;
}
else if ( e->button() == Qt::LeftButton )
{
mDragStartPosition = e->pos();
}
QToolButton::mousePressEvent( e );
}
bool QgsColorButtonV2::colorFromMimeData( const QMimeData * mimeData, QColor& resultColor )
{
bool hasAlpha = false;
QColor mimeColor = QgsSymbolLayerV2Utils::colorFromMimeData( mimeData, hasAlpha );
if ( mimeColor.isValid() )
{
if ( !mAllowAlpha )
{
//remove alpha channel
mimeColor.setAlpha( 255 );
}
else if ( !hasAlpha )
{
//mime color has no explicit alpha component, so keep existing alpha
mimeColor.setAlpha( mColor.alpha() );
}
resultColor = mimeColor;
return true;
}
//could not get color from mime data
return false;
}
void QgsColorButtonV2::mouseMoveEvent( QMouseEvent *e )
{
if ( mPickingColor )
{
//currently in color picker mode
if ( e->buttons() & Qt::LeftButton )
{
//if left button depressed, sample color under cursor and temporarily update button color
//to give feedback to user
QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), e->globalPos().x(), e->globalPos().y(), 1, 1 );
QImage snappedImage = snappedPixmap.toImage();
QColor hoverColor = snappedImage.pixel( 0, 0 );
setButtonBackground( hoverColor );
}
e->accept();
return;
}
//handle dragging colors from button
if ( !( e->buttons() & Qt::LeftButton ) || !mColor.isValid() )
{
//left button not depressed or no color set, so not a drag
QToolButton::mouseMoveEvent( e );
return;
}
if (( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
{
//mouse not moved, so not a drag
QToolButton::mouseMoveEvent( e );
return;
}
//user is dragging color
QDrag *drag = new QDrag( this );
drag->setMimeData( QgsSymbolLayerV2Utils::colorToMimeData( mColor ) );
drag->setPixmap( QgsColorWidget::createDragIcon( mColor ) );
drag->exec( Qt::CopyAction );
setDown( false );
}
void QgsColorButtonV2::mouseReleaseEvent( QMouseEvent *e )
{
if ( mPickingColor )
{
//end color picking operation by sampling the color under cursor
stopPicking( e->globalPos() );
e->accept();
return;
}
QToolButton::mouseReleaseEvent( e );
}
void QgsColorButtonV2::stopPicking( QPointF eventPos, bool sampleColor )
{
//release mouse and keyboard, and reset cursor
releaseMouse();
releaseKeyboard();
unsetCursor();
mPickingColor = false;
if ( !sampleColor )
{
//not sampling color, nothing more to do
return;
}
//grab snapshot of pixel under mouse cursor
QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), eventPos.x(), eventPos.y(), 1, 1 );
QImage snappedImage = snappedPixmap.toImage();
//extract color from pixel and set color
setColor( snappedImage.pixel( 0, 0 ) );
addRecentColor( mColor );
}
void QgsColorButtonV2::keyPressEvent( QKeyEvent *e )
{
if ( !mPickingColor )
{
//if not picking a color, use default tool button behaviour
QToolButton::keyPressEvent( e );
return;
}
//cancel picking, sampling the color if space was pressed
stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
}
void QgsColorButtonV2::dragEnterEvent( QDragEnterEvent *e )
{
//is dragged data valid color data?
QColor mimeColor;
if ( colorFromMimeData( e->mimeData(), mimeColor ) )
{
//if so, we accept the drag, and temporarily change the button's color
//to match the dragged color. This gives immediate feedback to the user
//that colors can be dropped here
e->acceptProposedAction();
setButtonBackground( mimeColor );
}
}
void QgsColorButtonV2::dragLeaveEvent( QDragLeaveEvent *e )
{
Q_UNUSED( e );
//reset button color
setButtonBackground( mColor );
}
void QgsColorButtonV2::dropEvent( QDropEvent *e )
{
//is dropped data valid color data?
QColor mimeColor;
if ( colorFromMimeData( e->mimeData(), mimeColor ) )
{
//accept drop and set new color
e->acceptProposedAction();
setColor( mimeColor );
addRecentColor( mimeColor );
}
}
void QgsColorButtonV2::setValidColor( const QColor& newColor )
{
if ( newColor.isValid() )
{
setColor( newColor );
addRecentColor( newColor );
}
}
QPixmap QgsColorButtonV2::createMenuIcon( const QColor &color, const bool showChecks )
{
//create an icon pixmap
QPixmap pixmap( 16, 16 );
pixmap.fill( Qt::transparent );
QPainter p;
p.begin( &pixmap );
//start with checkboard pattern
if ( showChecks )
{
QBrush checkBrush = QBrush( transparentBackground() );
p.setPen( Qt::NoPen );
p.setBrush( checkBrush );
p.drawRect( 0, 0, 15, 15 );
}
//draw color over pattern
p.setBrush( QBrush( color ) );
//draw border
p.setPen( QColor( 197, 197, 197 ) );
p.drawRect( 0, 0, 15, 15 );
p.end();
return pixmap;
}
void QgsColorButtonV2::buttonClicked()
{
switch ( mBehaviour )
{
case ShowDialog:
showColorDialog();
return;
case SignalOnly:
emit colorClicked( mColor );
return;
}
}
void QgsColorButtonV2::prepareMenu()
{
//we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any
//QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size
//for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this
//menu is opened, otherwise color schemes like the recent color scheme grid are meaningless
mMenu->clear();
if ( mShowNull )
{
QAction* nullAction = new QAction( tr( "Clear color" ), this );
nullAction->setIcon( createMenuIcon( Qt::transparent, false ) );
mMenu->addAction( nullAction );
connect( nullAction, SIGNAL( triggered() ), this, SLOT( setToNull() ) );
}
//show default color option if set
if ( mDefaultColor.isValid() )
{
QAction* defaultColorAction = new QAction( tr( "Default color" ), this );
defaultColorAction->setIcon( createMenuIcon( mDefaultColor ) );
mMenu->addAction( defaultColorAction );
connect( defaultColorAction, SIGNAL( triggered() ), this, SLOT( setToDefaultColor() ) );
}
if ( mShowNoColorOption && mAllowAlpha )
{
QAction* noColorAction = new QAction( mNoColorString, this );
noColorAction->setIcon( createMenuIcon( Qt::transparent, false ) );
mMenu->addAction( noColorAction );
connect( noColorAction, SIGNAL( triggered() ), this, SLOT( setToNoColor() ) );
}
mMenu->addSeparator();
QgsColorWheel* colorWheel = new QgsColorWheel( mMenu );
colorWheel->setColor( color() );
QgsColorWidgetAction* colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu );
colorAction->setDismissOnColorSelection( false );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
mMenu->addAction( colorAction );
if ( mColorSchemeRegistry )
{
//get schemes with ShowInColorButtonMenu flag set
QList< QgsColorScheme* > schemeList = mColorSchemeRegistry->schemes( QgsColorScheme::ShowInColorButtonMenu );
QList< QgsColorScheme* >::iterator it = schemeList.begin();
for ( ; it != schemeList.end(); ++it )
{
QgsColorSwatchGridAction* colorAction = new QgsColorSwatchGridAction( *it, mMenu, mContext, this );
colorAction->setBaseColor( mColor );
mMenu->addAction( colorAction );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setValidColor( const QColor& ) ) );
connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( addRecentColor( const QColor& ) ) );
}
}
mMenu->addSeparator();
QAction* copyColorAction = new QAction( tr( "Copy color" ), this );
mMenu->addAction( copyColorAction );
connect( copyColorAction, SIGNAL( triggered() ), this, SLOT( copyColor() ) );
QAction* pasteColorAction = new QAction( tr( "Paste color" ), this );
//enable or disable paste action based on current clipboard contents. We always show the paste
//action, even if it's disabled, to give hint to the user that pasting colors is possible
QColor clipColor;
if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
{
pasteColorAction->setIcon( createMenuIcon( clipColor ) );
}
else
{
pasteColorAction->setEnabled( false );
}
mMenu->addAction( pasteColorAction );
connect( pasteColorAction, SIGNAL( triggered() ), this, SLOT( pasteColor() ) );
#ifndef Q_OS_MAC
//disabled for OSX, as it is impossible to grab the mouse under OSX
//see note for QWidget::grabMouse() re OSX Cocoa
//http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse
QAction* pickColorAction = new QAction( tr( "Pick color" ), this );
mMenu->addAction( pickColorAction );
connect( pickColorAction, SIGNAL( triggered() ), this, SLOT( activatePicker() ) );
#endif
QAction* chooseColorAction = new QAction( tr( "Choose color..." ), this );
mMenu->addAction( chooseColorAction );
connect( chooseColorAction, SIGNAL( triggered() ), this, SLOT( showColorDialog() ) );
}
void QgsColorButtonV2::changeEvent( QEvent* e )
{
if ( e->type() == QEvent::EnabledChange )
{
setButtonBackground();
}
QToolButton::changeEvent( e );
}
#if 0 // causes too many cyclical updates, but may be needed on some platforms
void QgsColorButtonV2::paintEvent( QPaintEvent* e )
{
QToolButton::paintEvent( e );
if ( !mBackgroundSet )
{
setButtonBackground();
}
}
#endif
void QgsColorButtonV2::showEvent( QShowEvent* e )
{
setButtonBackground();
QToolButton::showEvent( e );
}
void QgsColorButtonV2::resizeEvent( QResizeEvent *event )
{
QToolButton::resizeEvent( event );
//recalculate icon size and redraw icon
mIconSize = QSize();
setButtonBackground( mColor );
}
void QgsColorButtonV2::setColor( const QColor &color )
{
QColor oldColor = mColor;
mColor = color;
// handle when initially set color is same as default (Qt::black); consider it a color change
if ( oldColor != mColor || ( mColor == QColor( Qt::black ) && !mColorSet ) )
{
setButtonBackground();
if ( isEnabled() )
{
// TODO: May be beneficial to have the option to set color without emitting this signal.
// Now done by blockSignals( bool ) where button is used
emit colorChanged( mColor );
}
}
mColorSet = true;
}
void QgsColorButtonV2::addRecentColor( const QColor& color )
{
QgsRecentColorScheme::addRecentColor( color );
}
void QgsColorButtonV2::setButtonBackground( const QColor &color )
{
QColor backgroundColor = color;
if ( !color.isValid() )
{
backgroundColor = mColor;
}
QSize currentIconSize;
//icon size is button size with a small margin
if ( menu() )
{
if ( !mIconSize.isValid() )
{
//calculate size of push button part of widget (ie, without the menu dropdown button part)
QStyleOptionToolButton opt;
initStyleOption( &opt );
QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
this );
//make sure height of icon looks good under different platforms
#ifdef Q_OS_WIN
mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
#else
mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
#endif
}
currentIconSize = mIconSize;
}
else
{
//no menu
#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;
}
//create an icon pixmap
QPixmap pixmap( currentIconSize );
pixmap.fill( Qt::transparent );
if ( backgroundColor.isValid() )
{
QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
QPainter p;
p.begin( &pixmap );
p.setRenderHint( QPainter::Antialiasing );
p.setPen( Qt::NoPen );
if ( mAllowAlpha && backgroundColor.alpha() < 255 )
{
//start with checkboard pattern
QBrush checkBrush = QBrush( transparentBackground() );
p.setBrush( checkBrush );
p.drawRoundedRect( rect, 3, 3 );
}
//draw semi-transparent color on top
p.setBrush( backgroundColor );
p.drawRoundedRect( rect, 3, 3 );
p.end();
}
setIconSize( currentIconSize );
setIcon( pixmap );
}
void QgsColorButtonV2::copyColor()
{
//copy color
QApplication::clipboard()->setMimeData( QgsSymbolLayerV2Utils::colorToMimeData( mColor ) );
}
void QgsColorButtonV2::pasteColor()
{
QColor clipColor;
if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) )
{
//paste color
setColor( clipColor );
addRecentColor( clipColor );
}
}
void QgsColorButtonV2::activatePicker()
{
//pick color
QPixmap samplerPixmap = QPixmap(( const char ** ) sampler_cursor );
setCursor( QCursor( samplerPixmap, 0, 0 ) );
grabMouse();
grabKeyboard();
mPickingColor = true;
}
QColor QgsColorButtonV2::color() const
{
return mColor;
}
void QgsColorButtonV2::setAllowAlpha( const bool allowAlpha )
{
mAllowAlpha = allowAlpha;
}
void QgsColorButtonV2::setColorDialogTitle( const QString& title )
{
mColorDialogTitle = title;
}
QString QgsColorButtonV2::colorDialogTitle() const
{
return mColorDialogTitle;
}
void QgsColorButtonV2::setShowMenu( const bool showMenu )
{
setMenu( showMenu ? mMenu : nullptr );
setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
//force recalculation of icon size
mIconSize = QSize();
setButtonBackground( mColor );
}
void QgsColorButtonV2::setBehaviour( const QgsColorButtonV2::Behaviour behaviour )
{
mBehaviour = behaviour;
}
void QgsColorButtonV2::setDefaultColor( const QColor& color )
{
mDefaultColor = color;
}
void QgsColorButtonV2::setShowNull( bool showNull )
{
mShowNull = showNull;
}
bool QgsColorButtonV2::showNull() const
{
return mShowNull;
}
bool QgsColorButtonV2::isNull() const
{
return !mColor.isValid();
}

View File

@ -1,432 +0,0 @@
/***************************************************************************
qgscolorbutton.h - Color button
--------------------------------------
Date : 12-Dec-2006
Copyright : (C) 2006 by Tom Elwertowski
Email : telwertowski at users dot sourceforge dot net
***************************************************************************
* *
* 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 QGSCOLORBUTTONV2_H
#define QGSCOLORBUTTONV2_H
#include <QColorDialog>
#include <QToolButton>
#include <QTemporaryFile>
class QMimeData;
class QgsColorSchemeRegistry;
/** \ingroup gui
* \class QgsColorButtonV2
* 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. An attached drop down menu allows for copying
* and pasting colors, picking colors from the screen, and selecting colors from color swatch grids.
* \note Added in version 2.5
*/
class GUI_EXPORT QgsColorButtonV2 : public QToolButton
{
Q_OBJECT
Q_ENUMS( Behaviour )
Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates )
Q_PROPERTY( QColor color READ color WRITE setColor )
Q_PROPERTY( bool allowAlpha READ allowAlpha WRITE setAllowAlpha )
Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
Q_PROPERTY( Behaviour behaviour READ behaviour WRITE setBehaviour )
Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
Q_PROPERTY( bool showNoColor READ showNoColor WRITE setShowNoColor )
Q_PROPERTY( QString noColorString READ noColorString WRITE setNoColorString )
Q_PROPERTY( QString context READ context WRITE setContext )
public:
/** Specifies the behaviour when the button is clicked
*/
enum Behaviour
{
ShowDialog = 0, /*!< show a color picker dialog when clicked */
SignalOnly /*!< emit colorClicked signal only, no dialog */
};
/** 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 registry a color scheme registry for color swatch grids to show in the drop down menu. If not
* specified, the button will use the global color scheme registry
*/
QgsColorButtonV2( QWidget *parent = nullptr, const QString& cdt = "", QgsColorSchemeRegistry* registry = nullptr );
virtual ~QgsColorButtonV2();
virtual QSize sizeHint() const override;
/** Return the currently selected color.
* @returns currently selected color
* @see setColor
*/
QColor color() const;
/** Sets whether alpha modification (transparency) is permitted
* for the color. Defaults to false.
* @param allowAlpha set to true to allow alpha modification
* @see allowAlpha
*/
void setAllowAlpha( const bool allowAlpha );
/** Returns whether alpha modification (transparency) is permitted
* for the color.
* @returns true if alpha modification is allowed
* @see setAllowAlpha
*/
bool allowAlpha() const { return mAllowAlpha; }
/** Set the title for the color chooser dialog window.
* @param title Title for the color chooser dialog
* @see colorDialogTitle
*/
void setColorDialogTitle( const QString& title );
/** Returns the title for the color chooser dialog window.
* @returns title for the color chooser dialog
* @see setColorDialogTitle
*/
QString colorDialogTitle() const;
/** Returns whether the button accepts live updates from QColorDialog.
* @returns true if the button will be accepted immediately when the dialog's color changes
* @see setAcceptLiveUpdates
*/
bool acceptLiveUpdates() const { return mAcceptLiveUpdates; }
/** Sets whether the button accepts live updates from QColorDialog. Live updates may cause changes
* that are not undoable on QColorDialog cancel.
* @param accept set to true to enable live updates
* @see acceptLiveUpdates
*/
void setAcceptLiveUpdates( const bool accept ) { mAcceptLiveUpdates = accept; }
/** Sets whether the drop down menu should be shown for the button. The default behaviour is to
* show the menu.
* @param showMenu set to false to hide the drop down menu
* @see showMenu
*/
void setShowMenu( const bool showMenu );
/** Returns whether the drop down menu is shown for the button.
* @returns true if drop down menu is shown
* @see setShowMenu
*/
bool showMenu() const { return menu() ? true : false; }
/** Sets the behaviour for when the button is clicked. The default behaviour is to show
* a color picker dialog.
* @param behaviour behaviour when button is clicked
* @see behaviour
*/
void setBehaviour( const Behaviour behaviour );
/** Returns the behaviour for when the button is clicked.
* @returns behaviour when button is clicked
* @see setBehaviour
*/
Behaviour behaviour() const { return mBehaviour; }
/** Sets the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @param color default color for the button. Set to an invalid QColor to disable the default color
* option.
* @see defaultColor
*/
void setDefaultColor( const QColor& color );
/** Returns the default color for the button, which is shown in the button's drop down menu for the
* "default color" option.
* @returns default color for the button. Returns an invalid QColor if the default color
* option is disabled.
* @see setDefaultColor
*/
QColor defaultColor() const { return mDefaultColor; }
/** Sets whether the "no color" option should be shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @param showNoColorOption set to true to show the no color option. This is disabled by default.
* @see showNoColor
* @see setNoColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setShowNoColor( const bool showNoColorOption ) { mShowNoColorOption = showNoColorOption; }
/** Returns whether the "no color" option is shown in the button's drop down menu. If selected,
* the "no color" option sets the color button's color to a totally transparent color.
* @returns true if the no color option is shown.
* @see setShowNoColor
* @see noColorString
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
bool showNoColor() const { return mShowNoColorOption; }
/** Sets the string to use for the "no color" option in the button's drop down menu.
* @param noColorString string to use for the "no color" menu option
* @see noColorString
* @see setShowNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
void setNoColorString( const QString& noColorString ) { mNoColorString = noColorString; }
/** Sets whether a set to null (clear) option is shown in the button's drop down menu.
* @param showNull set to true to show a null option
* @note added in QGIS 2.16
* @see showNull()
* @see isNull()
*/
void setShowNull( bool showNull );
/** Returns whether the set to null (clear) option is shown in the button's drop down menu.
* @note added in QGIS 2.16
* @see setShowNull()
* @see isNull()
*/
bool showNull() const;
/** Returns true if the current color is null.
* @note added in QGIS 2.16
* @see setShowNull()
* @see showNull()
*/
bool isNull() const;
/** Returns the string used for the "no color" option in the button's drop down menu.
* @returns string used for the "no color" menu option
* @see setNoColorString
* @see showNoColor
* @note The "no color" option is only shown if the color button is set to show an alpha channel in the color
* dialog (see setColorDialogOptions)
*/
QString noColorString() const { return mNoColorString; }
/** Sets the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @param context context string for the color button's color swatch grids
* @see context
*/
void setContext( const QString& context ) { mContext = context; }
/** Returns the context string for the color button. The context string is passed to all color swatch
* grids shown in the button's drop down menu, to allow them to customise their display colors
* based on the context.
* @returns context string for the color button's color swatch grids
* @see setContext
*/
QString context() const { return mContext; }
/** Sets the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @param registry color scheme registry for the button. Set to 0 to hide all color
* swatch grids from the button's drop down menu.
* @see colorSchemeRegistry
*/
void setColorSchemeRegistry( QgsColorSchemeRegistry* registry ) { mColorSchemeRegistry = registry; }
/** Returns the color scheme registry for the button, which controls the color swatch grids
* that are shown in the button's drop down menu.
* @returns color scheme registry for the button. If returned value is 0 then all color
* swatch grids are hidden from the button's drop down menu.
* @see setColorSchemeRegistry
*/
QgsColorSchemeRegistry* colorSchemeRegistry() { return mColorSchemeRegistry; }
public slots:
/** Sets the current color for the button. Will emit a colorChanged signal if the color is different
* to the previous color.
* @param color new color for the button
* @see color
*/
void setColor( const QColor &color );
/** Sets the background pixmap for the button based upon color and transparency.
* 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
* @param color Color for button background. If no color is specified, the button's current
* color will be used
*/
void setButtonBackground( const QColor &color = QColor() );
/** Copies the current color to the clipboard
* @see pasteColor
*/
void copyColor();
/** Pastes a color from the clipboard to the color button. If clipboard does not contain a valid
* color or string representation of a color, then no change is applied.
* @see copyColor
*/
void pasteColor();
/** Activates the color picker tool, which allows for sampling a color from anywhere on the screen
*/
void activatePicker();
/** Sets color to a totally transparent color.
* @note If the color button is not set to show an alpha channel in the color
* dialog (see setColorDialogOptions) then the color will not be changed.
* @see setToNull()
*/
void setToNoColor();
/** Sets color to the button's default color, if set.
* @see setDefaultColor
* @see defaultColor
* @see setToNull()
*/
void setToDefaultColor();
/** Sets color to null.
* @see setToDefaultColor()
* @see setToNoColor()
* @note added in QGIS 2.16
*/
void setToNull();
signals:
/** Is emitted whenever a new color is set for the button. 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 );
/** Emitted when the button is clicked, if the button's behaviour is set to SignalOnly
* @param color button color
* @see setBehaviour
* @see behaviour
*/
void colorClicked( const QColor &color );
protected:
bool event( QEvent *e ) override;
void changeEvent( QEvent* e ) override;
void showEvent( QShowEvent* e ) override;
void resizeEvent( QResizeEvent *event ) override;
/** Returns a checkboard pattern pixmap for use as a background to transparent colors
*/
static const QPixmap& transparentBackground();
/**
* Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
*/
void mousePressEvent( QMouseEvent* e ) override;
/**
* Reimplemented to allow dragging colors from button
*/
void mouseMoveEvent( QMouseEvent *e ) override;
/**
* Reimplemented to allow color picking
*/
void mouseReleaseEvent( QMouseEvent *e ) override;
/**
* Reimplemented to allow cancelling color pick via keypress, and sample via space bar press
*/
void keyPressEvent( QKeyEvent *e ) override;
/**
* Reimplemented to accept dragged colors
*/
void dragEnterEvent( QDragEnterEvent * e ) override;
/**
* Reimplemented to reset button appearance after drag leave
*/
void dragLeaveEvent( QDragLeaveEvent *e ) override;
/**
* Reimplemented to accept dropped colors
*/
void dropEvent( QDropEvent *e ) override;
private:
Behaviour mBehaviour;
QString mColorDialogTitle;
QColor mColor;
QgsColorSchemeRegistry* mColorSchemeRegistry;
QColor mDefaultColor;
QString mContext;
bool mAllowAlpha;
bool mAcceptLiveUpdates;
bool mColorSet;
bool mShowNoColorOption;
QString mNoColorString;
bool mShowNull;
QPoint mDragStartPosition;
bool mPickingColor;
QMenu* mMenu;
QSize mIconSize;
/** Attempts to parse mimeData as a color, either via the mime data's color data or by
* parsing a textual representation of a color.
* @returns true if mime data could be intrepreted as a color
* @param mimeData mime data
* @param resultColor QColor to store evaluated color
* @see createColorMimeData
*/
bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
/** Ends a color picking operation
* @param eventPos global position of pixel to sample color from
* @param sampleColor set to true to actually sample the color, false to just cancel
* the color picking operation
*/
void stopPicking( QPointF eventPos, bool sampleColor = true );
/** Create a color icon for display in the drop down menu
* @param color for icon
* @param showChecks set to true to display a checkboard pattern behind
* transparent colors
*/
QPixmap createMenuIcon( const QColor &color, const bool showChecks = true );
private slots:
void buttonClicked();
void showColorDialog();
/** Sets color for button, if valid.
*/
void setValidColor( const QColor& newColor );
/** Adds a color to the recent colors list
* @param color to add to recent colors list
*/
void addRecentColor( const QColor& color );
/** Creates the drop down menu entries
*/
void prepareMenu();
};
#endif

View File

@ -101,37 +101,37 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& c
mAlphaSlider->setComponent( QgsColorWidget::Alpha );
mSwatchButton1->setShowMenu( false );
mSwatchButton1->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton1->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton2->setShowMenu( false );
mSwatchButton2->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton2->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton3->setShowMenu( false );
mSwatchButton3->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton3->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton4->setShowMenu( false );
mSwatchButton4->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton4->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton5->setShowMenu( false );
mSwatchButton5->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton5->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton6->setShowMenu( false );
mSwatchButton6->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton6->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton7->setShowMenu( false );
mSwatchButton7->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton7->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton8->setShowMenu( false );
mSwatchButton8->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton8->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton9->setShowMenu( false );
mSwatchButton9->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton9->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton10->setShowMenu( false );
mSwatchButton10->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton10->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton11->setShowMenu( false );
mSwatchButton11->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton11->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton12->setShowMenu( false );
mSwatchButton12->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton12->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton13->setShowMenu( false );
mSwatchButton13->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton13->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton14->setShowMenu( false );
mSwatchButton14->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton14->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton15->setShowMenu( false );
mSwatchButton15->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton15->setBehaviour( QgsColorButton::SignalOnly );
mSwatchButton16->setShowMenu( false );
mSwatchButton16->setBehaviour( QgsColorButtonV2::SignalOnly );
mSwatchButton16->setBehaviour( QgsColorButton::SignalOnly );
//restore custom colors
mSwatchButton1->setColor( settings.value( "/Windows/ColorDialog/customColor1", QVariant( QColor() ) ).value<QColor>() );
mSwatchButton2->setColor( settings.value( "/Windows/ColorDialog/customColor2", QVariant( QColor() ) ).value<QColor>() );

View File

@ -160,7 +160,7 @@ void QgsRendererV2PropertiesDialog::connectValueChanged( QList<QWidget *> widget
{
connect( w , SIGNAL( valueChanged( double ) ), this, slot );
}
else if ( QgsColorButtonV2* w = qobject_cast<QgsColorButtonV2*>( widget ) )
else if ( QgsColorButton* w = qobject_cast<QgsColorButton*>( widget ) )
{
connect( w, SIGNAL( colorChanged( QColor ) ), this, slot );
}

View File

@ -461,7 +461,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="mRegionColorButton">
<widget class="QgsColorButton" name="mRegionColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -567,9 +567,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -133,7 +133,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="mArrowHeadOutlineColorButton">
<widget class="QgsColorButton" name="mArrowHeadOutlineColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -165,7 +165,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="mArrowHeadFillColorButton">
<widget class="QgsColorButton" name="mArrowHeadFillColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -285,9 +285,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -374,7 +374,7 @@
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QgsColorButtonV2" name="mBackgroundColorButton">
<widget class="QgsColorButton" name="mBackgroundColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -471,7 +471,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QgsColorButtonV2" name="mGridColorButton">
<widget class="QgsColorButton" name="mGridColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -552,7 +552,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QgsColorButtonV2" name="mHeaderFontColorButton">
<widget class="QgsColorButton" name="mHeaderFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -655,7 +655,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QgsColorButtonV2" name="mContentFontColorButton">
<widget class="QgsColorButton" name="mContentFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -775,9 +775,9 @@
<header location="global">qgsmaplayercombobox.h</header>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -416,7 +416,7 @@
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QgsColorButtonV2" name="mFrameColorButton">
<widget class="QgsColorButton" name="mFrameColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -535,7 +535,7 @@
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QgsColorButtonV2" name="mBackgroundColorButton">
<widget class="QgsColorButton" name="mBackgroundColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -742,9 +742,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -268,7 +268,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QgsColorButtonV2" name="mFontColorButton">
<widget class="QgsColorButton" name="mFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -336,9 +336,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -500,7 +500,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="mFontColorButton">
<widget class="QgsColorButton" name="mFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -683,7 +683,7 @@
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QgsColorButtonV2" name="mRasterBorderColorButton">
<widget class="QgsColorButton" name="mRasterBorderColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -1003,9 +1003,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -841,7 +841,7 @@
</widget>
</item>
<item row="2" column="2">
<widget class="QgsColorButtonV2" name="mGridFramePenColorButton">
<widget class="QgsColorButton" name="mGridFramePenColorButton">
<property name="minimumSize">
<size>
<width>100</width>
@ -867,7 +867,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QgsColorButtonV2" name="mGridFrameFill1ColorButton">
<widget class="QgsColorButton" name="mGridFrameFill1ColorButton">
<property name="minimumSize">
<size>
<width>100</width>
@ -886,7 +886,7 @@
</widget>
</item>
<item row="3" column="2">
<widget class="QgsColorButtonV2" name="mGridFrameFill2ColorButton">
<widget class="QgsColorButton" name="mGridFrameFill2ColorButton">
<property name="minimumSize">
<size>
<width>100</width>
@ -1132,7 +1132,7 @@
</widget>
</item>
<item row="14" column="1">
<widget class="QgsColorButtonV2" name="mAnnotationFontColorButton">
<widget class="QgsColorButton" name="mAnnotationFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -1430,9 +1430,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -362,7 +362,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="mOutlineColorButton">
<widget class="QgsColorButton" name="mOutlineColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -381,7 +381,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="mFillColorButton">
<widget class="QgsColorButton" name="mFillColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -501,9 +501,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -478,7 +478,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QgsColorButtonV2" name="mFontColorButton">
<widget class="QgsColorButton" name="mFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -521,7 +521,7 @@
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QgsColorButtonV2" name="mFillColorButton">
<widget class="QgsColorButton" name="mFillColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -564,7 +564,7 @@
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QgsColorButtonV2" name="mFillColor2Button">
<widget class="QgsColorButton" name="mFillColor2Button">
<property name="minimumSize">
<size>
<width>120</width>
@ -607,7 +607,7 @@
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QgsColorButtonV2" name="mStrokeColorButton">
<widget class="QgsColorButton" name="mStrokeColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -665,9 +665,9 @@
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -15,7 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="12" column="2">
<widget class="QgsColorButtonV2" name="mLastRowColorButton">
<widget class="QgsColorButton" name="mLastRowColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -92,7 +92,7 @@
</widget>
</item>
<item row="3" column="2">
<widget class="QgsColorButtonV2" name="mOddColumnsColorButton">
<widget class="QgsColorButton" name="mOddColumnsColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -117,7 +117,7 @@
</widget>
</item>
<item row="5" column="2">
<widget class="QgsColorButtonV2" name="mEvenColumnsColorButton">
<widget class="QgsColorButton" name="mEvenColumnsColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -142,7 +142,7 @@
</widget>
</item>
<item row="11" column="2">
<widget class="QgsColorButtonV2" name="mFirstRowColorButton">
<widget class="QgsColorButton" name="mFirstRowColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -167,7 +167,7 @@
</widget>
</item>
<item row="9" column="2">
<widget class="QgsColorButtonV2" name="mLastColumnColorButton">
<widget class="QgsColorButton" name="mLastColumnColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -212,7 +212,7 @@
</spacer>
</item>
<item row="8" column="2">
<widget class="QgsColorButtonV2" name="mFirstColumnColorButton">
<widget class="QgsColorButton" name="mFirstColumnColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -237,7 +237,7 @@
</widget>
</item>
<item row="1" column="2">
<widget class="QgsColorButtonV2" name="mDefaultColorButton">
<widget class="QgsColorButton" name="mDefaultColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -262,7 +262,7 @@
</widget>
</item>
<item row="10" column="2">
<widget class="QgsColorButtonV2" name="mHeaderRowColorButton">
<widget class="QgsColorButton" name="mHeaderRowColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -311,7 +311,7 @@
</widget>
</item>
<item row="7" column="2">
<widget class="QgsColorButtonV2" name="mEvenRowsColorButton">
<widget class="QgsColorButton" name="mEvenRowsColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -343,7 +343,7 @@
</widget>
</item>
<item row="6" column="2">
<widget class="QgsColorButtonV2" name="mOddRowsColorButton">
<widget class="QgsColorButton" name="mOddRowsColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -371,9 +371,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View File

@ -273,7 +273,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="mGridColorButton">
<widget class="QgsColorButton" name="mGridColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -374,7 +374,7 @@
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QgsColorButtonV2" name="mHeaderFontColorButton">
<widget class="QgsColorButton" name="mHeaderFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -409,7 +409,7 @@
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QgsColorButtonV2" name="mContentFontColorButton">
<widget class="QgsColorButton" name="mContentFontColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -466,9 +466,9 @@
<header location="global">qgsmaplayercombobox.h</header>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View File

@ -274,7 +274,7 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QgsColorButtonV2" name="mColorizeColorButton">
<widget class="QgsColorButton" name="mColorizeColorButton">
<property name="minimumSize">
<size>
<width>100</width>
@ -324,9 +324,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -46,7 +46,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QgsColorButtonV2" name="mColorBtn">
<widget class="QgsColorButton" name="mColorBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -243,9 +243,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -77,7 +77,7 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QgsColorButtonV2" name="mShadowColorBtn">
<widget class="QgsColorButton" name="mShadowColorBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -276,9 +276,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -61,7 +61,7 @@
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QgsColorButtonV2" name="mBackgroundColorButton">
<widget class="QgsColorButton" name="mBackgroundColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -104,7 +104,7 @@
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QgsColorButtonV2" name="mFrameColorButton">
<widget class="QgsColorButton" name="mFrameColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -141,9 +141,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@ -205,7 +205,7 @@
<number>1</number>
</property>
<item row="1" column="0">
<widget class="QgsColorButtonV2" name="mSwatchButton9">
<widget class="QgsColorButton" name="mSwatchButton9">
<property name="minimumSize">
<size>
<width>38</width>
@ -224,7 +224,7 @@
</widget>
</item>
<item row="1" column="2">
<widget class="QgsColorButtonV2" name="mSwatchButton11">
<widget class="QgsColorButton" name="mSwatchButton11">
<property name="minimumSize">
<size>
<width>38</width>
@ -243,7 +243,7 @@
</widget>
</item>
<item row="1" column="3">
<widget class="QgsColorButtonV2" name="mSwatchButton12">
<widget class="QgsColorButton" name="mSwatchButton12">
<property name="minimumSize">
<size>
<width>38</width>
@ -262,7 +262,7 @@
</widget>
</item>
<item row="0" column="4">
<widget class="QgsColorButtonV2" name="mSwatchButton5">
<widget class="QgsColorButton" name="mSwatchButton5">
<property name="minimumSize">
<size>
<width>38</width>
@ -281,7 +281,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="mSwatchButton2">
<widget class="QgsColorButton" name="mSwatchButton2">
<property name="minimumSize">
<size>
<width>38</width>
@ -300,7 +300,7 @@
</widget>
</item>
<item row="0" column="2">
<widget class="QgsColorButtonV2" name="mSwatchButton3">
<widget class="QgsColorButton" name="mSwatchButton3">
<property name="minimumSize">
<size>
<width>38</width>
@ -319,7 +319,7 @@
</widget>
</item>
<item row="0" column="0">
<widget class="QgsColorButtonV2" name="mSwatchButton1">
<widget class="QgsColorButton" name="mSwatchButton1">
<property name="minimumSize">
<size>
<width>38</width>
@ -338,7 +338,7 @@
</widget>
</item>
<item row="1" column="4">
<widget class="QgsColorButtonV2" name="mSwatchButton13">
<widget class="QgsColorButton" name="mSwatchButton13">
<property name="minimumSize">
<size>
<width>38</width>
@ -357,7 +357,7 @@
</widget>
</item>
<item row="0" column="5">
<widget class="QgsColorButtonV2" name="mSwatchButton6">
<widget class="QgsColorButton" name="mSwatchButton6">
<property name="minimumSize">
<size>
<width>38</width>
@ -376,7 +376,7 @@
</widget>
</item>
<item row="0" column="6">
<widget class="QgsColorButtonV2" name="mSwatchButton7">
<widget class="QgsColorButton" name="mSwatchButton7">
<property name="minimumSize">
<size>
<width>38</width>
@ -395,7 +395,7 @@
</widget>
</item>
<item row="1" column="5">
<widget class="QgsColorButtonV2" name="mSwatchButton14">
<widget class="QgsColorButton" name="mSwatchButton14">
<property name="minimumSize">
<size>
<width>38</width>
@ -414,7 +414,7 @@
</widget>
</item>
<item row="1" column="6">
<widget class="QgsColorButtonV2" name="mSwatchButton15">
<widget class="QgsColorButton" name="mSwatchButton15">
<property name="minimumSize">
<size>
<width>38</width>
@ -433,7 +433,7 @@
</widget>
</item>
<item row="0" column="7">
<widget class="QgsColorButtonV2" name="mSwatchButton8">
<widget class="QgsColorButton" name="mSwatchButton8">
<property name="minimumSize">
<size>
<width>38</width>
@ -452,7 +452,7 @@
</widget>
</item>
<item row="1" column="7">
<widget class="QgsColorButtonV2" name="mSwatchButton16">
<widget class="QgsColorButton" name="mSwatchButton16">
<property name="minimumSize">
<size>
<width>38</width>
@ -471,7 +471,7 @@
</widget>
</item>
<item row="0" column="3">
<widget class="QgsColorButtonV2" name="mSwatchButton4">
<widget class="QgsColorButton" name="mSwatchButton4">
<property name="minimumSize">
<size>
<width>38</width>
@ -490,7 +490,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="mSwatchButton10">
<widget class="QgsColorButton" name="mSwatchButton10">
<property name="minimumSize">
<size>
<width>38</width>
@ -910,9 +910,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -181,7 +181,7 @@ p, li { white-space: pre-wrap; }
<item row="2" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QgsColorButtonV2" name="pbnColorChooser">
<widget class="QgsColorButton" name="pbnColorChooser">
<property name="minimumSize">
<size>
<width>150</width>
@ -222,9 +222,9 @@ p, li { white-space: pre-wrap; }
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -55,7 +55,7 @@
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QgsColorButtonV2" name="pbnChangeColor">
<widget class="QgsColorButton" name="pbnChangeColor">
<property name="minimumSize">
<size>
<width>150</width>
@ -379,9 +379,9 @@
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -610,7 +610,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="mBackgroundColorButton">
<widget class="QgsColorButton" name="mBackgroundColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -774,7 +774,7 @@
</spacer>
</item>
<item row="3" column="1">
<widget class="QgsColorButtonV2" name="mDiagramPenColorButton">
<widget class="QgsColorButton" name="mDiagramPenColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -1925,9 +1925,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -277,7 +277,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="btnBackgroundColor">
<widget class="QgsColorButton" name="btnBackgroundColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -315,7 +315,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="btnTextColor">
<widget class="QgsColorButton" name="btnTextColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -600,9 +600,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -296,7 +296,7 @@
</spacer>
</item>
<item>
<widget class="QgsColorButtonV2" name="mPreviewBackgroundBtn">
<widget class="QgsColorButton" name="mPreviewBackgroundBtn">
<property name="minimumSize">
<size>
<width>100</width>
@ -1011,7 +1011,7 @@
</widget>
</item>
<item row="7" column="1">
<widget class="QgsColorButtonV2" name="btnTextColor">
<widget class="QgsColorButton" name="btnTextColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -2299,7 +2299,7 @@ font-style: italic;</string>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="btnBufferColor">
<widget class="QgsColorButton" name="btnBufferColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -2570,7 +2570,7 @@ font-style: italic;</string>
</widget>
</item>
<item row="18" column="1">
<widget class="QgsColorButtonV2" name="mShapeBorderColorBtn">
<widget class="QgsColorButton" name="mShapeBorderColorBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -3020,7 +3020,7 @@ font-style: italic;</string>
<widget class="QgsPenJoinStyleComboBox" name="mShapePenStyleCmbBx"/>
</item>
<item row="17" column="1">
<widget class="QgsColorButtonV2" name="mShapeFillColorBtn">
<widget class="QgsColorButton" name="mShapeFillColorBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -3331,7 +3331,7 @@ font-style: italic;</string>
<number>0</number>
</property>
<item row="10" column="1">
<widget class="QgsColorButtonV2" name="mShadowColorBtn">
<widget class="QgsColorButton" name="mShadowColorBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -6377,9 +6377,9 @@ font-style: italic;</string>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -338,7 +338,7 @@
</layout>
</item>
<item row="3" column="2">
<widget class="QgsColorButtonV2" name="mFontColorButton">
<widget class="QgsColorButton" name="mFontColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -409,7 +409,7 @@
</layout>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="mBufferColorButton">
<widget class="QgsColorButton" name="mBufferColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -624,9 +624,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -2771,7 +2771,7 @@
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="4">
<widget class="QgsColorButtonV2" name="pbnCanvasColor">
<widget class="QgsColorButton" name="pbnCanvasColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -2835,7 +2835,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="pbnSelectionColor">
<widget class="QgsColorButton" name="pbnSelectionColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -3163,7 +3163,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="mIdentifyHighlightColorButton">
<widget class="QgsColorButton" name="mIdentifyHighlightColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -3332,7 +3332,7 @@
<widget class="QComboBox" name="mAngleUnitsComboBox"/>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="pbnMeasureColor">
<widget class="QgsColorButton" name="pbnMeasureColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -3588,7 +3588,7 @@
</widget>
</item>
<item row="0" column="4">
<widget class="QgsColorButtonV2" name="mGridColorButton">
<widget class="QgsColorButton" name="mGridColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -3925,7 +3925,7 @@
</widget>
</item>
<item row="0" column="5">
<widget class="QgsColorButtonV2" name="mFillColorToolButton">
<widget class="QgsColorButton" name="mFillColorToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -3963,7 +3963,7 @@
</widget>
</item>
<item row="0" column="3">
<widget class="QgsColorButtonV2" name="mLineColorToolButton">
<widget class="QgsColorButton" name="mLineColorToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -5362,9 +5362,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -62,7 +62,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="mLabelColorButton">
<widget class="QgsColorButton" name="mLabelColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -117,7 +117,7 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="mCircleColorButton">
<widget class="QgsColorButton" name="mCircleColorButton">
<property name="minimumSize">
<size>
<width>120</width>
@ -257,9 +257,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -295,7 +295,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="pbnSelectionColor">
<widget class="QgsColorButton" name="pbnSelectionColor">
<property name="minimumSize">
<size>
<width>120</width>
@ -330,7 +330,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="pbnCanvasColor">
<widget class="QgsColorButton" name="pbnCanvasColor">
<property name="minimumSize">
<size>
<width>120</width>
@ -2575,9 +2575,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -751,7 +751,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="btnColorizeColor">
<widget class="QgsColorButton" name="btnColorizeColor">
<property name="minimumSize">
<size>
<width>100</width>
@ -2195,9 +2195,9 @@ p, li { white-space: pre-wrap; }
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -295,7 +295,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="btnColorizeColor">
<widget class="QgsColorButton" name="btnColorizeColor">
<property name="minimumSize">
<size>
<width>100</width>
@ -440,9 +440,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -68,7 +68,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="mFontColorButton">
<widget class="QgsColorButton" name="mFontColorButton">
<property name="minimumSize">
<size>
<width>100</width>
@ -117,9 +117,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
</customwidget>
</customwidgets>
<tabstops>

View File

@ -27,7 +27,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="btnColor1">
<widget class="QgsColorButton" name="btnColor1">
<property name="minimumSize">
<size>
<width>120</width>
@ -56,7 +56,7 @@
</widget>
</item>
<item>
<widget class="QgsColorButtonV2" name="btnColor2">
<widget class="QgsColorButton" name="btnColor2">
<property name="minimumSize">
<size>
<width>120</width>
@ -331,9 +331,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -42,7 +42,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="mRoofColorButton">
<widget class="QgsColorButton" name="mRoofColorButton">
<property name="text">
<string>...</string>
</property>
@ -56,7 +56,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="mWallColorButton">
<widget class="QgsColorButton" name="mWallColorButton">
<property name="text">
<string>...</string>
</property>
@ -89,7 +89,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="mShadowColorButton">
<widget class="QgsColorButton" name="mShadowColorButton">
<property name="text">
<string>...</string>
</property>
@ -144,9 +144,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View File

@ -343,7 +343,7 @@
<number>0</number>
</property>
<item>
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
<widget class="QgsColorButton" name="btnChangeColorFill">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -424,7 +424,7 @@
<number>0</number>
</property>
<item>
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
<widget class="QgsColorButton" name="btnChangeColorBorder">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -584,9 +584,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -271,7 +271,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QgsColorButtonV2" name="btnColor">
<widget class="QgsColorButton" name="btnColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -317,7 +317,7 @@
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QgsColorButtonV2" name="btnBorderColor">
<widget class="QgsColorButton" name="btnBorderColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -454,9 +454,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -79,7 +79,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColor2">
<widget class="QgsColorButton" name="btnChangeColor2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -200,7 +200,7 @@
</layout>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColor">
<widget class="QgsColorButton" name="btnChangeColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -539,9 +539,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -220,7 +220,7 @@
</layout>
</item>
<item row="2" column="1" colspan="3">
<widget class="QgsColorButtonV2" name="btnChangeColor2">
<widget class="QgsColorButton" name="btnChangeColor2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -259,7 +259,7 @@
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QgsColorButtonV2" name="btnChangeColor">
<widget class="QgsColorButton" name="btnChangeColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -418,9 +418,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -195,7 +195,7 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QgsColorButtonV2" name="btnChangeBorderColor">
<widget class="QgsColorButton" name="btnChangeBorderColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -248,7 +248,7 @@
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QgsColorButtonV2" name="btnChangeColor">
<widget class="QgsColorButton" name="btnChangeColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -331,9 +331,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -100,7 +100,7 @@
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QgsColorButtonV2" name="btnChangeColor">
<widget class="QgsColorButton" name="btnChangeColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -287,9 +287,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -47,7 +47,7 @@
<number>0</number>
</property>
<item>
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
<widget class="QgsColorButton" name="btnChangeColorFill">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -476,7 +476,7 @@
<number>0</number>
</property>
<item>
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
<widget class="QgsColorButton" name="btnChangeColorBorder">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -520,9 +520,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -47,7 +47,7 @@
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QgsColorButtonV2" name="mChangeBorderColorButton">
<widget class="QgsColorButton" name="mChangeBorderColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -129,7 +129,7 @@
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QgsColorButtonV2" name="mChangeColorButton">
<widget class="QgsColorButton" name="mChangeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -307,9 +307,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -347,7 +347,7 @@
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QgsColorButtonV2" name="mChangeColorButton">
<widget class="QgsColorButton" name="mChangeColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -406,7 +406,7 @@
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QgsColorButtonV2" name="mChangeBorderColorButton">
<widget class="QgsColorButton" name="mChangeBorderColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -536,9 +536,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View File

@ -212,7 +212,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="btnColor">
<widget class="QgsColorButton" name="btnColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -410,9 +410,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButtonV2</class>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbuttonv2.h</header>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>

View File

@ -19,7 +19,7 @@ ADD_PYTHON_TEST(PyQgsAttributeTableModel test_qgsattributetablemodel.py)
#ADD_PYTHON_TEST(PyQgsAuthenticationSystem test_qgsauthsystem.py)
ADD_PYTHON_TEST(PyQgsBlendModes test_qgsblendmodes.py)
ADD_PYTHON_TEST(PyQgsCategorizedSymbolRendererV2 test_qgscategorizedsymbolrendererv2.py)
ADD_PYTHON_TEST(PyQgsColorButtonV2 test_qgscolorbuttonv2.py)
ADD_PYTHON_TEST(PyQgsColorButton test_qgscolorbutton.py)
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py)

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsColorButtonV2.
"""QGIS Unit tests for QgsColorButton.
.. note:: 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
@ -14,13 +14,13 @@ __revision__ = '$Format:%H$'
import qgis # NOQA
from qgis.gui import QgsColorButtonV2
from qgis.gui import QgsColorButton
from qgis.testing import start_app, unittest
from qgis.PyQt.QtGui import QColor
start_app()
class TestQgsColorButtonV2(unittest.TestCase):
class TestQgsColorButton(unittest.TestCase):
def testClearingColors(self):
"""
@ -28,7 +28,7 @@ class TestQgsColorButtonV2(unittest.TestCase):
"""
# start with a valid color
button = QgsColorButtonV2()
button = QgsColorButton()
button.setAllowAlpha(True)
button.setColor(QColor(255, 100, 200, 255))
self.assertEqual(button.color(), QColor(255, 100, 200, 255))