combobox.cpp 1.91 KB
Newer Older
David Jarvie's avatar
David Jarvie committed
1 2 3
/*
 *  combobox.cpp  -  combo box with read-only option
 *  Program:  kalarm
4
 *  Copyright © 2002,2005,2007 by David Jarvie <djarvie@kde.org>
David Jarvie's avatar
David Jarvie committed
5 6 7 8 9 10 11 12 13 14 15
 *
 *  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.
 *
David Jarvie's avatar
David Jarvie committed
16 17 18
 *  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
David Jarvie committed
19 20
 */

Laurent Montel's avatar
moc++  
Laurent Montel committed
21
#include "combobox.h"
22

Laurent Montel's avatar
Qt3to4  
Laurent Montel committed
23 24
#include <QMouseEvent>
#include <QKeyEvent>
Laurent Montel's avatar
Laurent Montel committed
25
#include <QLineEdit>
David Jarvie's avatar
David Jarvie committed
26

David Jarvie's avatar
David Jarvie committed
27
ComboBox::ComboBox(QWidget* parent)
28 29
    : KComboBox(parent),
      mReadOnly(false)
David Jarvie's avatar
David Jarvie committed
30 31 32 33
{ }

void ComboBox::setReadOnly(bool ro)
{
34 35 36 37 38 39
    if ((int)ro != (int)mReadOnly)
    {
        mReadOnly = ro;
        if (lineEdit())
            lineEdit()->setReadOnly(ro);
    }
David Jarvie's avatar
David Jarvie committed
40 41 42 43
}

void ComboBox::mousePressEvent(QMouseEvent* e)
{
44 45 46 47 48 49 50
    if (mReadOnly)
    {
        // Swallow up the event if it's the left button
        if (e->button() == Qt::LeftButton)
            return;
    }
    KComboBox::mousePressEvent(e);
David Jarvie's avatar
David Jarvie committed
51 52 53 54
}

void ComboBox::mouseReleaseEvent(QMouseEvent* e)
{
55 56
    if (!mReadOnly)
        KComboBox::mouseReleaseEvent(e);
David Jarvie's avatar
David Jarvie committed
57 58 59 60
}

void ComboBox::mouseMoveEvent(QMouseEvent* e)
{
61 62
    if (!mReadOnly)
        KComboBox::mouseMoveEvent(e);
David Jarvie's avatar
David Jarvie committed
63 64 65 66
}

void ComboBox::keyPressEvent(QKeyEvent* e)
{
67 68
    if (!mReadOnly  ||  e->key() == Qt::Key_Escape)
        KComboBox::keyPressEvent(e);
David Jarvie's avatar
David Jarvie committed
69 70 71 72
}

void ComboBox::keyReleaseEvent(QKeyEvent* e)
{
73 74
    if (!mReadOnly)
        KComboBox::keyReleaseEvent(e);
David Jarvie's avatar
David Jarvie committed
75
}
76

77
// vim: et sw=4: