QGIS API Documentation 3.43.0-Master (32433f7016e)
qgscolorbutton.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscolorbutton.h - Color button
3 --------------------------------------
4 Date : 12-Dec-2006
5 Copyright : (C) 2006 by Tom Elwertowski
6 Email : telwertowski at users dot sourceforge dot net
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSCOLORBUTTON_H
16#define QGSCOLORBUTTON_H
17
18#include <QColorDialog>
19#include <QToolButton>
20#include "qgis_gui.h"
21#include "qgis_sip.h"
22
23class QMimeData;
25class QgsPanelWidget;
26
37class GUI_EXPORT QgsColorButton : public QToolButton
38{
39#ifdef SIP_RUN
41 if ( qobject_cast<QgsColorButton *>( sipCpp ) )
42 sipType = sipType_QgsColorButton;
43 else
44 sipType = NULL;
46#endif
47
48
49 Q_OBJECT
50 Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
51 Q_PROPERTY( QColor color READ color WRITE setColor )
52 Q_PROPERTY( bool allowOpacity READ allowOpacity WRITE setAllowOpacity )
53 Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
54 Q_PROPERTY( Behavior behavior READ behavior WRITE setBehavior )
55 Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
56 Q_PROPERTY( bool showNoColor READ showNoColor WRITE setShowNoColor )
57 Q_PROPERTY( QString noColorString READ noColorString WRITE setNoColorString )
58 Q_PROPERTY( QString context READ context WRITE setContext )
59
60 public:
65 {
66 ShowDialog = 0,
67 SignalOnly
68 };
69 Q_ENUM( Behavior )
70
71
78 QgsColorButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &cdt = QString(), QgsColorSchemeRegistry *registry = nullptr );
79
80 QSize minimumSizeHint() const override;
81 QSize sizeHint() const override;
82
88 QColor color() const;
89
96 void setAllowOpacity( bool allowOpacity );
97
104 bool allowOpacity() const { return mAllowOpacity; }
105
111 void setColorDialogTitle( const QString &title );
112
118 QString colorDialogTitle() const;
119
126 void setShowMenu( bool showMenu );
127
133 bool showMenu() const { return menu() ? true : false; }
134
141 void setBehavior( Behavior behavior );
142
148 Behavior behavior() const { return mBehavior; }
149
157 void setDefaultColor( const QColor &color );
158
166 QColor defaultColor() const { return mDefaultColor; }
167
177 void setShowNoColor( const bool showNoColorOption ) { mShowNoColorOption = showNoColorOption; }
178
188 bool showNoColor() const { return mShowNoColorOption; }
189
198 void setNoColorString( const QString &noColorString ) { mNoColorString = noColorString; }
199
207 void setShowNull( bool showNull, const QString &nullString = QString() );
208
214 bool showNull() const;
215
221 bool isNull() const;
222
231 QString noColorString() const { return mNoColorString; }
232
240 void setContext( const QString &context ) { mContext = context; }
241
249 QString context() const { return mContext; }
250
258 void setColorSchemeRegistry( QgsColorSchemeRegistry *registry ) { mColorSchemeRegistry = registry; }
259
267 QgsColorSchemeRegistry *colorSchemeRegistry() { return mColorSchemeRegistry; }
268
283 void linkToProjectColor( const QString &name );
284
291 QString linkedProjectColorName() const { return mLinkedColorName; }
292
301 static QPixmap createMenuIcon( const QColor &color, bool showChecks = true );
302
303 public slots:
304
311 void setColor( const QColor &color );
312
321 void setButtonBackground( const QColor &color = QColor() );
322
327 void copyColor();
328
334 void pasteColor();
335
339 void activatePicker();
340
347 void setToNoColor();
348
355 void setToDefaultColor();
356
363 void setToNull();
364
373 void unlink();
374
375 signals:
376
382 void colorChanged( const QColor &color );
383
390 void colorClicked( const QColor &color );
391
398 void cleared();
399
409 void unlinked();
410
411 protected:
412 bool event( QEvent *e ) override;
413 void changeEvent( QEvent *e ) override;
414 void showEvent( QShowEvent *e ) override;
415 void resizeEvent( QResizeEvent *event ) override;
416
420 static const QPixmap &transparentBackground();
421
425 void mousePressEvent( QMouseEvent *e ) override;
426
430 void mouseMoveEvent( QMouseEvent *e ) override;
431
435 void mouseReleaseEvent( QMouseEvent *e ) override;
436
440 void keyPressEvent( QKeyEvent *e ) override;
441
445 void dragEnterEvent( QDragEnterEvent *e ) override;
446
450 void dragLeaveEvent( QDragLeaveEvent *e ) override;
451
455 void dropEvent( QDropEvent *e ) override;
456
457 void wheelEvent( QWheelEvent *event ) override;
458
459 private:
461 QString mColorDialogTitle;
462 QColor mColor;
463 QSize mMinimumSize;
464
465 QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
466
467 QColor mDefaultColor;
468
470 QColor mCurrentColor;
471
472 QString mContext;
473 bool mAllowOpacity = false;
474 bool mColorSet = false;
475
476 bool mShowNoColorOption = false;
477 QString mNoColorString;
478 bool mShowNull = false;
479 QString mNullColorString;
480
481 QPoint mDragStartPosition;
482 bool mPickingColor = false;
483
484 QMenu *mMenu = nullptr;
485
486 QSize mIconSize;
487 QString mLinkedColorName;
488 bool mShowMenu = true;
489
498 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
499
506 void stopPicking( QPoint eventPos, bool samplingColor = true );
507
508 QColor linkedProjectColor() const;
509
510 private slots:
511
512 void buttonClicked();
513
514 void showColorDialog();
515
519 void setValidColor( const QColor &newColor );
520
525 void setValidTemporaryColor( const QColor &newColor );
526
531 void addRecentColor( const QColor &color );
532
536 void prepareMenu();
537
538 friend class QgsColorTooltip;
539};
540
541#endif
A cross platform button subclass for selecting colors.
bool showNoColor() const
Returns whether the "no color" option is shown in the button's drop-down menu.
bool showMenu() const
Returns whether the drop-down menu is shown for the button.
void setColorSchemeRegistry(QgsColorSchemeRegistry *registry)
Sets the color scheme registry for the button, which controls the color swatch grids that are shown i...
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
void setNoColorString(const QString &noColorString)
Sets the string to use for the "no color" option in the button's drop-down menu.
bool allowOpacity() const
Returns whether opacity modification (transparency) is permitted for the color.
Behavior
Specifies the behavior when the button is clicked.
@ ShowDialog
Show a color picker dialog when clicked.
void unlinked()
Emitted when the color is unlinked, e.g.
void setContext(const QString &context)
Sets the context string for the color button.
QString context() const
Returns the context string for the color button.
QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the color scheme registry for the button, which controls the color swatch grids that are show...
Behavior behavior() const
Returns the behavior for when the button is clicked.
void colorClicked(const QColor &color)
Emitted when the button is clicked, if the button's behavior is set to SignalOnly.
void setShowNoColor(const bool showNoColorOption)
Sets whether the "no color" option should be shown in the button's drop-down menu.
void cleared()
Emitted when the color is cleared (set to null).
QColor defaultColor() const
Returns the default color for the button, which is shown in the button's drop-down menu for the "defa...
QString linkedProjectColorName() const
Returns the linked project color name, if set.
QString noColorString() const
Returns the string used for the "no color" option in the button's drop-down menu.
Registry of color schemes.
Helper class for generating color tooltips.
Base class for any widget that can be shown as an inline panel.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:208