kalarm/lib

combobox.cpp
1 /*
2  * combobox.cpp - combo box with read-only option
3  * Program: kalarm
4  * Copyright (c) 2002 by David Jarvie <software@astrojar.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include <tqlineedit.h>
22 #include "combobox.moc"
23 
24 
25 ComboBox::ComboBox(TQWidget* parent, const char* name)
26  : TQComboBox(parent, name),
27  mReadOnly(false)
28 { }
29 
30 ComboBox::ComboBox(bool rw, TQWidget* parent, const char* name)
31  : TQComboBox(rw, parent, name),
32  mReadOnly(false)
33 { }
34 
35 void ComboBox::setReadOnly(bool ro)
36 {
37  if ((int)ro != (int)mReadOnly)
38  {
39  mReadOnly = ro;
40  if (lineEdit())
41  lineEdit()->setReadOnly(ro);
42  }
43 }
44 
45 void ComboBox::mousePressEvent(TQMouseEvent* e)
46 {
47  if (mReadOnly)
48  {
49  // Swallow up the event if it's the left button
50  if (e->button() == TQt::LeftButton)
51  return;
52  }
53  TQComboBox::mousePressEvent(e);
54 }
55 
56 void ComboBox::mouseReleaseEvent(TQMouseEvent* e)
57 {
58  if (!mReadOnly)
59  TQComboBox::mouseReleaseEvent(e);
60 }
61 
62 void ComboBox::mouseMoveEvent(TQMouseEvent* e)
63 {
64  if (!mReadOnly)
65  TQComboBox::mouseMoveEvent(e);
66 }
67 
68 void ComboBox::keyPressEvent(TQKeyEvent* e)
69 {
70  if (!mReadOnly || e->key() == TQt::Key_Escape)
71  TQComboBox::keyPressEvent(e);
72 }
73 
74 void ComboBox::keyReleaseEvent(TQKeyEvent* e)
75 {
76  if (!mReadOnly)
77  TQComboBox::keyReleaseEvent(e);
78 }
virtual void setReadOnly(bool readOnly)
Sets whether the combo box is read-only for the user.
Definition: combobox.cpp:35
ComboBox(TQWidget *parent=0, const char *name=0)
Constructor.
Definition: combobox.cpp:25