kalarm/lib
combobox.cpp
Go to the documentation of this file.00001 /* 00002 * combobox.cpp - combo box with read-only option 00003 * Program: kalarm 00004 * Copyright © 2002,2005,2007 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> 00022 #include <QMouseEvent> 00023 #include <QKeyEvent> 00024 00025 #include "combobox.moc" 00026 00027 00028 ComboBox::ComboBox(QWidget* parent) 00029 : KComboBox(parent), 00030 mReadOnly(false) 00031 { } 00032 00033 void ComboBox::setReadOnly(bool ro) 00034 { 00035 if ((int)ro != (int)mReadOnly) 00036 { 00037 mReadOnly = ro; 00038 if (lineEdit()) 00039 lineEdit()->setReadOnly(ro); 00040 } 00041 } 00042 00043 void ComboBox::mousePressEvent(QMouseEvent* e) 00044 { 00045 if (mReadOnly) 00046 { 00047 // Swallow up the event if it's the left button 00048 if (e->button() == Qt::LeftButton) 00049 return; 00050 } 00051 KComboBox::mousePressEvent(e); 00052 } 00053 00054 void ComboBox::mouseReleaseEvent(QMouseEvent* e) 00055 { 00056 if (!mReadOnly) 00057 KComboBox::mouseReleaseEvent(e); 00058 } 00059 00060 void ComboBox::mouseMoveEvent(QMouseEvent* e) 00061 { 00062 if (!mReadOnly) 00063 KComboBox::mouseMoveEvent(e); 00064 } 00065 00066 void ComboBox::keyPressEvent(QKeyEvent* e) 00067 { 00068 if (!mReadOnly || e->key() == Qt::Key_Escape) 00069 KComboBox::keyPressEvent(e); 00070 } 00071 00072 void ComboBox::keyReleaseEvent(QKeyEvent* e) 00073 { 00074 if (!mReadOnly) 00075 KComboBox::keyReleaseEvent(e); 00076 }
KDE 4.2 API Reference