| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
// Adapted from Avogadro 1.0 by Geoffrey Hutchison |
| 7 |
// Contributed to Avogadro 2.0 by Geoffrey Hutchison |
| 8 |
|
| 9 |
#ifndef AVOGADRO_QTGUI_COLORBUTTON_H |
| 10 |
#define AVOGADRO_QTGUI_COLORBUTTON_H |
| 11 |
|
| 12 |
#include "avogadroqtguiexport.h" |
| 13 |
|
| 14 |
#include <QAbstractButton> |
| 15 |
#include <QColor> |
| 16 |
|
| 17 |
namespace Avogadro { |
| 18 |
namespace QtGui { |
| 19 |
|
| 20 |
/** |
| 21 |
* @class ColorButton colorbutton.h <avogadro/colorbutton.h> |
| 22 |
* @author Geoffrey Hutchison |
| 23 |
* @brief A button to show the current color and bring up the QColorDialog. |
| 24 |
* |
| 25 |
* This class implements a QAbstractButton to display a colored rectangle. |
| 26 |
* When clicked by the user, it brings up a color picker to select a new |
| 27 |
* color. |
| 28 |
* |
| 29 |
* The widget has a default minimum size of 35x20 pixels. |
| 30 |
*/ |
| 31 |
|
| 32 |
class AVOGADROQTGUI_EXPORT ColorButton : public QAbstractButton |
| 33 |
{ |
| 34 |
Q_OBJECT |
| 35 |
|
| 36 |
public: |
| 37 |
ColorButton(QWidget* parent = nullptr); |
| 38 |
explicit ColorButton(const QColor& initial, QWidget* parent = nullptr); |
| 39 |
|
| 40 |
/** |
| 41 |
* Redraw the widget (i.e., refresh the colored rectangle) |
| 42 |
*/ |
| 43 |
void paintEvent(QPaintEvent*) override; |
| 44 |
|
| 45 |
/** |
| 46 |
* @param color the new color to be used |
| 47 |
*/ |
| 48 |
void setColor(const QColor& color); |
| 49 |
|
| 50 |
/** |
| 51 |
* @param title custom title for color choice dialog |
| 52 |
*/ |
| 53 |
void setDialogTitle(const QString title = ""); |
| 54 |
|
| 55 |
/** |
| 56 |
* @return the current color |
| 57 |
*/ |
| 58 |
QColor color() const; |
| 59 |
|
| 60 |
Q_SIGNALS: |
| 61 |
/** |
| 62 |
* emit any time the color is changed, either by a user or by setColor() |
| 63 |
*/ |
| 64 |
void colorChanged(const QColor&); |
| 65 |
|
| 66 |
public Q_SLOTS: |
| 67 |
/** |
| 68 |
* Call for a change in the current color |
| 69 |
*/ |
| 70 |
void changeColor(); |
| 71 |
|
| 72 |
protected: |
| 73 |
/** |
| 74 |
* Generic event handler, currently defaults to calling parent class |
| 75 |
* (included for future compatibility) |
| 76 |
*/ |
| 77 |
bool event(QEvent* e) override; |
| 78 |
|
| 79 |
QColor m_color; //!< The current color |
| 80 |
QString m_title; //!< The current dialog title |
| 81 |
}; |
| 82 |
|
| 83 |
} // namespace QtGui |
| 84 |
} // namespace Avogadro |
| 85 |
|
| 86 |
#endif |