pushbutton.cpp
00001 /* 00002 * pushbutton.cpp - push button 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 "pushbutton.moc" 00022 00023 00024 PushButton::PushButton(TQWidget* parent, const char* name) 00025 : TQPushButton(parent, name), 00026 mFocusPolicy(focusPolicy()), 00027 mReadOnly(false) 00028 { } 00029 00030 PushButton::PushButton(const TQString& text, TQWidget* parent, const char* name) 00031 : TQPushButton(text, parent, name), 00032 mFocusPolicy(focusPolicy()), 00033 mReadOnly(false) 00034 { } 00035 00036 PushButton::PushButton(const TQIconSet& icon, const TQString& text, TQWidget* parent, const char* name) 00037 : TQPushButton(icon, text, parent, name), 00038 mFocusPolicy(focusPolicy()), 00039 mReadOnly(false) 00040 { } 00041 00042 void PushButton::setReadOnly(bool ro) 00043 { 00044 if ((int)ro != (int)mReadOnly) 00045 { 00046 mReadOnly = ro; 00047 setFocusPolicy(ro ? TQ_NoFocus : mFocusPolicy); 00048 if (ro) 00049 clearFocus(); 00050 } 00051 } 00052 00053 void PushButton::mousePressEvent(TQMouseEvent* e) 00054 { 00055 if (mReadOnly) 00056 { 00057 // Swallow up the event if it's the left button 00058 if (e->button() == Qt::LeftButton) 00059 return; 00060 } 00061 TQPushButton::mousePressEvent(e); 00062 } 00063 00064 void PushButton::mouseReleaseEvent(TQMouseEvent* e) 00065 { 00066 if (mReadOnly) 00067 { 00068 // Swallow up the event if it's the left button 00069 if (e->button() == Qt::LeftButton) 00070 return; 00071 } 00072 TQPushButton::mouseReleaseEvent(e); 00073 } 00074 00075 void PushButton::mouseMoveEvent(TQMouseEvent* e) 00076 { 00077 if (!mReadOnly) 00078 TQPushButton::mouseMoveEvent(e); 00079 } 00080 00081 void PushButton::keyPressEvent(TQKeyEvent* e) 00082 { 00083 if (mReadOnly) 00084 switch (e->key()) 00085 { 00086 case TQt::Key_Up: 00087 case TQt::Key_Left: 00088 case TQt::Key_Right: 00089 case TQt::Key_Down: 00090 // Process keys which shift the focus 00091 break; 00092 default: 00093 return; 00094 } 00095 TQPushButton::keyPressEvent(e); 00096 } 00097 00098 void PushButton::keyReleaseEvent(TQKeyEvent* e) 00099 { 00100 if (!mReadOnly) 00101 TQPushButton::keyReleaseEvent(e); 00102 }