colourbutton.cpp 1.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *  colourbutton.cpp  -  colour selection button
 *  Program:  kalarm
 *  Copyright © 2008 by David Jarvie <djarvie@kde.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

David Jarvie's avatar
Krazy  
David Jarvie committed
21 22 23
#include "kalarm.h"
#include "colourbutton.moc"

24 25 26 27 28
#include <QMouseEvent>
#include <QKeyEvent>


ColourButton::ColourButton(QWidget* parent)
29 30
    : KColorButton(parent),
      mReadOnly(false)
31 32 33 34 35
{
}

void ColourButton::setReadOnly(bool ro)
{
36
    mReadOnly = ro;
37 38 39 40
}

void ColourButton::mousePressEvent(QMouseEvent* e)
{
41 42 43 44 45 46 47
    if (mReadOnly)
    {
        // Swallow up the event if it's the left button
        if (e->button() == Qt::LeftButton)
            return;
    }
    KColorButton::mousePressEvent(e);
48 49 50 51
}

void ColourButton::mouseReleaseEvent(QMouseEvent* e)
{
52 53
    if (!mReadOnly)
        KColorButton::mouseReleaseEvent(e);
54 55 56 57
}

void ColourButton::mouseMoveEvent(QMouseEvent* e)
{
58 59
    if (!mReadOnly)
        KColorButton::mouseMoveEvent(e);
60 61 62 63
}

void ColourButton::keyPressEvent(QKeyEvent* e)
{
64 65
    if (!mReadOnly  ||  e->key() == Qt::Key_Escape)
        KColorButton::keyPressEvent(e);
66 67 68 69
}

void ColourButton::keyReleaseEvent(QKeyEvent* e)
{
70 71
    if (!mReadOnly)
        KColorButton::keyReleaseEvent(e);
72
}
73 74

// vim: et sw=4: