slider.cpp
00001 /* 00002 * slider.cpp - slider control with read-only option 00003 * Program: kalarm 00004 * Copyright (c) 2004 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 "slider.moc" 00022 00023 00024 Slider::Slider(TQWidget* parent, const char* name) 00025 : TQSlider(parent, name), 00026 mReadOnly(false) 00027 { } 00028 00029 Slider::Slider(Qt::Orientation o, TQWidget* parent, const char* name) 00030 : TQSlider(o, parent, name), 00031 mReadOnly(false) 00032 { } 00033 00034 Slider::Slider(int minval, int maxval, int pageStep, int value, Qt::Orientation o, TQWidget* parent, const char* name) 00035 : TQSlider(minval, maxval, pageStep, value, o, parent, name), 00036 mReadOnly(false) 00037 { } 00038 00039 /****************************************************************************** 00040 * Set the read-only status. If read-only, the slider can be moved by the 00041 * application, but not by the user. 00042 */ 00043 void Slider::setReadOnly(bool ro) 00044 { 00045 mReadOnly = ro; 00046 } 00047 00048 /****************************************************************************** 00049 * Event handlers to intercept events if in read-only mode. 00050 * Any events which could change the slider value are discarded. 00051 */ 00052 void Slider::mousePressEvent(TQMouseEvent* e) 00053 { 00054 if (mReadOnly) 00055 { 00056 // Swallow up the event if it's the left button 00057 if (e->button() == Qt::LeftButton) 00058 return; 00059 } 00060 TQSlider::mousePressEvent(e); 00061 } 00062 00063 void Slider::mouseReleaseEvent(TQMouseEvent* e) 00064 { 00065 if (!mReadOnly) 00066 TQSlider::mouseReleaseEvent(e); 00067 } 00068 00069 void Slider::mouseMoveEvent(TQMouseEvent* e) 00070 { 00071 if (!mReadOnly) 00072 TQSlider::mouseMoveEvent(e); 00073 } 00074 00075 void Slider::keyPressEvent(TQKeyEvent* e) 00076 { 00077 if (!mReadOnly || e->key() == TQt::Key_Escape) 00078 TQSlider::keyPressEvent(e); 00079 } 00080 00081 void Slider::keyReleaseEvent(TQKeyEvent* e) 00082 { 00083 if (!mReadOnly) 00084 TQSlider::keyReleaseEvent(e); 00085 }