kalarm/lib

combobox.cpp

00001 /*
00002  *  combobox.cpp  -  combo box with read-only option
00003  *  Program:  kalarm
00004  *  Copyright (C) 2002 by David Jarvie  software@astrojar.org.uk
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include <qlineedit.h>
00022 #include "combobox.moc"
00023 
00024 
00025 ComboBox::ComboBox(QWidget* parent, const char* name)
00026     : QComboBox(parent, name),
00027       mReadOnly(false)
00028 { }
00029 
00030 ComboBox::ComboBox(bool rw, QWidget* parent, const char* name)
00031     : QComboBox(rw, parent, name),
00032       mReadOnly(false)
00033 { }
00034 
00035 void ComboBox::setReadOnly(bool ro)
00036 {
00037     if ((int)ro != (int)mReadOnly)
00038     {
00039         mReadOnly = ro;
00040         if (lineEdit())
00041             lineEdit()->setReadOnly(ro);
00042     }
00043 }
00044 
00045 void ComboBox::mousePressEvent(QMouseEvent* e)
00046 {
00047     if (mReadOnly)
00048     {
00049         // Swallow up the event if it's the left button
00050         if (e->button() == LeftButton)
00051             return;
00052     }
00053     QComboBox::mousePressEvent(e);
00054 }
00055 
00056 void ComboBox::mouseReleaseEvent(QMouseEvent* e)
00057 {
00058     if (!mReadOnly)
00059         QComboBox::mouseReleaseEvent(e);
00060 }
00061 
00062 void ComboBox::mouseMoveEvent(QMouseEvent* e)
00063 {
00064     if (!mReadOnly)
00065         QComboBox::mouseMoveEvent(e);
00066 }
00067 
00068 void ComboBox::keyPressEvent(QKeyEvent* e)
00069 {
00070     if (!mReadOnly  ||  e->key() == Qt::Key_Escape)
00071         QComboBox::keyPressEvent(e);
00072 }
00073 
00074 void ComboBox::keyReleaseEvent(QKeyEvent* e)
00075 {
00076     if (!mReadOnly)
00077         QComboBox::keyReleaseEvent(e);
00078 }
KDE Home | KDE Accessibility Home | Description of Access Keys