QGIS API Documentation 3.39.0-Master (f549811d78c)
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
37#ifdef SIP_RUN
39 if ( qobject_cast<QgsColorButton *>( sipCpp ) )
40 sipType = sipType_QgsColorButton;
41 else
42 sipType = NULL;
44#endif
45
46
47 Q_OBJECT
48 Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle )
49 Q_PROPERTY( QColor color READ color WRITE setColor )
50 Q_PROPERTY( bool allowOpacity READ allowOpacity WRITE setAllowOpacity )
51 Q_PROPERTY( bool showMenu READ showMenu WRITE setShowMenu )
52 Q_PROPERTY( Behavior behavior READ behavior WRITE setBehavior )
53 Q_PROPERTY( QColor defaultColor READ defaultColor WRITE setDefaultColor )
54 Q_PROPERTY( bool showNoColor READ showNoColor WRITE setShowNoColor )
55 Q_PROPERTY( QString noColorString READ noColorString WRITE setNoColorString )
56 Q_PROPERTY( QString context READ context WRITE setContext )
57
58 public:
59
64 {
65 ShowDialog = 0,
66 SignalOnly
67 };
68 Q_ENUM( Behavior )
69
70
77 QgsColorButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &cdt = QString(), QgsColorSchemeRegistry *registry = nullptr );
78
79 QSize minimumSizeHint() const override;
80 QSize sizeHint() const override;
81
87 QColor color() const;
88
95 void setAllowOpacity( bool allowOpacity );
96
103 bool allowOpacity() const { return mAllowOpacity; }
104
110 void setColorDialogTitle( const QString &title );
111
117 QString colorDialogTitle() const;
118
125 void setShowMenu( bool showMenu );
126
132 bool showMenu() const { return menu() ? true : false; }
133
140 void setBehavior( Behavior behavior );
141
147 Behavior behavior() const { return mBehavior; }
148
156 void setDefaultColor( const QColor &color );
157
165 QColor defaultColor() const { return mDefaultColor; }
166
176 void setShowNoColor( const bool showNoColorOption ) { mShowNoColorOption = showNoColorOption; }
177
187 bool showNoColor() const { return mShowNoColorOption; }
188
197 void setNoColorString( const QString &noColorString ) { mNoColorString = noColorString; }
198
206 void setShowNull( bool showNull, const QString &nullString = QString() );
207
213 bool showNull() const;
214
220 bool isNull() const;
221
230 QString noColorString() const { return mNoColorString; }
231
239 void setContext( const QString &context ) { mContext = context; }
240
248 QString context() const { return mContext; }
249
257 void setColorSchemeRegistry( QgsColorSchemeRegistry *registry ) { mColorSchemeRegistry = registry; }
258
266 QgsColorSchemeRegistry *colorSchemeRegistry() { return mColorSchemeRegistry; }
267
282 void linkToProjectColor( const QString &name );
283
290 QString linkedProjectColorName() const { return mLinkedColorName; }
291
300 static QPixmap createMenuIcon( const QColor &color, bool showChecks = true );
301
302 public slots:
303
310 void setColor( const QColor &color );
311
320 void setButtonBackground( const QColor &color = QColor() );
321
326 void copyColor();
327
333 void pasteColor();
334
338 void activatePicker();
339
346 void setToNoColor();
347
354 void setToDefaultColor();
355
362 void setToNull();
363
372 void unlink();
373
374 signals:
375
381 void colorChanged( const QColor &color );
382
389 void colorClicked( const QColor &color );
390
397 void cleared();
398
408 void unlinked();
409
410 protected:
411
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:
460
462 QString mColorDialogTitle;
463 QColor mColor;
464 QSize mMinimumSize;
465
466 QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
467
468 QColor mDefaultColor;
469
471 QColor mCurrentColor;
472
473 QString mContext;
474 bool mAllowOpacity = false;
475 bool mColorSet = false;
476
477 bool mShowNoColorOption = false;
478 QString mNoColorString;
479 bool mShowNull = false;
480 QString mNullColorString;
481
482 QPoint mDragStartPosition;
483 bool mPickingColor = false;
484
485 QMenu *mMenu = nullptr;
486
487 QSize mIconSize;
488 QString mLinkedColorName;
489 bool mShowMenu = true;
490
499 bool colorFromMimeData( const QMimeData *mimeData, QColor &resultColor );
500
507 void stopPicking( QPoint eventPos, bool samplingColor = true );
508
509 QColor linkedProjectColor() const;
510
511 private slots:
512
513 void buttonClicked();
514
515 void showColorDialog();
516
520 void setValidColor( const QColor &newColor );
521
526 void setValidTemporaryColor( const QColor &newColor );
527
532 void addRecentColor( const QColor &color );
533
537 void prepareMenu();
538
539 friend class QgsColorTooltip;
540};
541
542#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