QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
34class GUI_EXPORT QgsColorButton : public QToolButton
35{
36#ifdef SIP_RUN
38 if ( qobject_cast<QgsColorButton *>( sipCpp ) )
39 sipType = sipType_QgsColorButton;
40 else
41 sipType = NULL;
43#endif
44
45
46 Q_OBJECT
47 Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
48 Q_PROPERTY( QColor color READ color WRITE setColor )
49 Q_PROPERTY( bool allowOpacity READ allowOpacity WRITE setAllowOpacity )
50 Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
51 Q_PROPERTY( Behavior behavior READ behavior WRITE setBehavior )
52 Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
53 Q_PROPERTY( bool showNoColor READ showNoColor WRITE setShowNoColor )
54 Q_PROPERTY( QString noColorString READ noColorString WRITE setNoColorString )
55 Q_PROPERTY( QString context READ context WRITE setContext )
56
57 public:
62 {
63 ShowDialog = 0,
64 SignalOnly
65 };
66 Q_ENUM( Behavior )
67
68
75 QgsColorButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &cdt = QString(), QgsColorSchemeRegistry *registry = nullptr );
76
77 QSize minimumSizeHint() const override;
78 QSize sizeHint() const override;
79
85 QColor color() const;
86
93 void setAllowOpacity( bool allowOpacity );
94
101 bool allowOpacity() const { return mAllowOpacity; }
102
108 void setColorDialogTitle( const QString &title );
109
115 QString colorDialogTitle() const;
116
123 void setShowMenu( bool showMenu );
124
130 bool showMenu() const { return menu() ? true : false; }
131
138 void setBehavior( Behavior behavior );
139
145 Behavior behavior() const { return mBehavior; }
146
154 void setDefaultColor( const QColor &color );
155
163 QColor defaultColor() const { return mDefaultColor; }
164
174 void setShowNoColor( const bool showNoColorOption ) { mShowNoColorOption = showNoColorOption; }
175
185 bool showNoColor() const { return mShowNoColorOption; }
186
195 void setNoColorString( const QString &noColorString ) { mNoColorString = noColorString; }
196
204 void setShowNull( bool showNull, const QString &nullString = QString() );
205
211 bool showNull() const;
212
218 bool isNull() const;
219
228 QString noColorString() const { return mNoColorString; }
229
237 void setContext( const QString &context ) { mContext = context; }
238
246 QString context() const { return mContext; }
247
255 void setColorSchemeRegistry( QgsColorSchemeRegistry *registry ) { mColorSchemeRegistry = registry; }
256
264 QgsColorSchemeRegistry *colorSchemeRegistry() { return mColorSchemeRegistry; }
265
280 void linkToProjectColor( const QString &name );
281
288 QString linkedProjectColorName() const { return mLinkedColorName; }
289
298 static QPixmap createMenuIcon( const QColor &color, bool showChecks = true );
299
300 public slots:
301
308 void setColor( const QColor &color );
309
318 void setButtonBackground( const QColor &color = QColor() );
319
324 void copyColor();
325
331 void pasteColor();
332
336 void activatePicker();
337
344 void setToNoColor();
345
352 void setToDefaultColor();
353
360 void setToNull();
361
370 void unlink();
371
372 signals:
373
379 void colorChanged( const QColor &color );
380
387 void colorClicked( const QColor &color );
388
395 void cleared();
396
406 void unlinked();
407
408 protected:
409 bool event( QEvent *e ) override;
410 void changeEvent( QEvent *e ) override;
411 void showEvent( QShowEvent *e ) override;
412 void resizeEvent( QResizeEvent *event ) override;
413
417 static const QPixmap &transparentBackground();
418
422 void mousePressEvent( QMouseEvent *e ) override;
423
427 void mouseMoveEvent( QMouseEvent *e ) override;
428
432 void mouseReleaseEvent( QMouseEvent *e ) override;
433
437 void keyPressEvent( QKeyEvent *e ) override;
438
442 void dragEnterEvent( QDragEnterEvent *e ) override;
443
447 void dragLeaveEvent( QDragLeaveEvent *e ) override;
448
452 void dropEvent( QDropEvent *e ) override;
453
454 void wheelEvent( QWheelEvent *event ) override;
455
456 private:
458 QString mColorDialogTitle;
459 QColor mColor;
460 QSize mMinimumSize;
461
462 QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
463
464 QColor mDefaultColor;
465
467 QColor mCurrentColor;
468
469 QString mContext;
470 bool mAllowOpacity = false;
471 bool mColorSet = false;
472
473 bool mShowNoColorOption = false;
474 QString mNoColorString;
475 bool mShowNull = false;
476 QString mNullColorString;
477
478 QPoint mDragStartPosition;
479 bool mPickingColor = false;
480
481 QMenu *mMenu = nullptr;
482
483 QSize mIconSize;
484 QString mLinkedColorName;
485 bool mShowMenu = true;
486
495 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
496
503 void stopPicking( QPoint eventPos, bool samplingColor = true );
504
505 QColor linkedProjectColor() const;
506
507 private slots:
508
509 void buttonClicked();
510
511 void showColorDialog();
512
516 void setValidColor( const QColor &newColor );
517
522 void setValidTemporaryColor( const QColor &newColor );
523
528 void addRecentColor( const QColor &color );
529
533 void prepareMenu();
534
535 friend class QgsColorTooltip;
536};
537
538#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 to generate color tooltip
Base class for any widget that can be shown as a 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