File indexing completed on 2025-02-16 04:48:44

0001 /*
0002  *  colourbutton.cpp  -  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 #include "colourbutton.h"
0010 
0011 #include <QMouseEvent>
0012 #include <QKeyEvent>
0013 
0014 
0015 ColourButton::ColourButton(QWidget* parent)
0016     : KColorButton(parent)
0017 {
0018 }
0019 
0020 void ColourButton::setReadOnly(bool ro)
0021 {
0022     mReadOnly = ro;
0023 }
0024 
0025 void ColourButton::mousePressEvent(QMouseEvent* e)
0026 {
0027     if (mReadOnly)
0028     {
0029         // Swallow up the event if it's the left button
0030         if (e->button() == Qt::LeftButton)
0031             return;
0032     }
0033     KColorButton::mousePressEvent(e);
0034 }
0035 
0036 void ColourButton::mouseReleaseEvent(QMouseEvent* e)
0037 {
0038     if (!mReadOnly)
0039         KColorButton::mouseReleaseEvent(e);
0040 }
0041 
0042 void ColourButton::mouseMoveEvent(QMouseEvent* e)
0043 {
0044     if (!mReadOnly)
0045         KColorButton::mouseMoveEvent(e);
0046 }
0047 
0048 void ColourButton::keyPressEvent(QKeyEvent* e)
0049 {
0050     if (!mReadOnly  ||  e->key() == Qt::Key_Escape)
0051         KColorButton::keyPressEvent(e);
0052 }
0053 
0054 void ColourButton::keyReleaseEvent(QKeyEvent* e)
0055 {
0056     if (!mReadOnly)
0057         KColorButton::keyReleaseEvent(e);
0058 }
0059 
0060 #include "moc_colourbutton.cpp"
0061 
0062 // vim: et sw=4: