File indexing completed on 2024-11-24 04:42:24
0001 /* 0002 * colourbutton.h - colour selection button 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2008 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <KColorButton> 0012 0013 0014 /** 0015 * @short A colour selection button with read-only option. 0016 * 0017 * The ColourButton class is a KColorButton with a read-only option. 0018 * 0019 * The widget may be set as read-only. This has the same effect as disabling it, except 0020 * that its appearance is unchanged. 0021 * 0022 * @author David Jarvie <djarvie@kde.org> 0023 */ 0024 class ColourButton : public KColorButton 0025 { 0026 Q_OBJECT 0027 public: 0028 /** Constructor. 0029 * @param parent The parent object of this widget. 0030 */ 0031 explicit ColourButton(QWidget* parent = nullptr); 0032 /** Returns the selected colour. */ 0033 QColor colour() const { return color(); } 0034 /** Sets the selected colour to @p c. */ 0035 void setColour(const QColor& c) { setColor(c); } 0036 /** Returns true if the widget is read only. */ 0037 bool isReadOnly() const { return mReadOnly; } 0038 /** Sets whether the button can be changed by the user. 0039 * @param readOnly True to set the widget read-only, false to set it read-write. 0040 */ 0041 virtual void setReadOnly(bool readOnly); 0042 protected: 0043 void mousePressEvent(QMouseEvent*) override; 0044 void mouseReleaseEvent(QMouseEvent*) override; 0045 void mouseMoveEvent(QMouseEvent*) override; 0046 void keyPressEvent(QKeyEvent*) override; 0047 void keyReleaseEvent(QKeyEvent*) override; 0048 private: 0049 bool mReadOnly {false}; // value cannot be changed 0050 }; 0051 0052 // vim: et sw=4: