File indexing completed on 2024-11-24 04:42:25

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