kalarm/lib

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(QWidget* parent, const char* name)
00025     : QSlider(parent, name),
00026       mReadOnly(false)
00027 { }
00028 
00029 Slider::Slider(Orientation o, QWidget* parent, const char* name)
00030     : QSlider(o, parent, name),
00031       mReadOnly(false)
00032 { }
00033 
00034 Slider::Slider(int minval, int maxval, int pageStep, int value, Orientation o, QWidget* parent, const char* name)
00035     : QSlider(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(QMouseEvent* e)
00053 {
00054     if (mReadOnly)
00055     {
00056         // Swallow up the event if it's the left button
00057         if (e->button() == LeftButton)
00058             return;
00059     }
00060     QSlider::mousePressEvent(e);
00061 }
00062 
00063 void Slider::mouseReleaseEvent(QMouseEvent* e)
00064 {
00065     if (!mReadOnly)
00066         QSlider::mouseReleaseEvent(e);
00067 }
00068 
00069 void Slider::mouseMoveEvent(QMouseEvent* e)
00070 {
00071     if (!mReadOnly)
00072         QSlider::mouseMoveEvent(e);
00073 }
00074 
00075 void Slider::keyPressEvent(QKeyEvent* e)
00076 {
00077     if (!mReadOnly  ||  e->key() == Qt::Key_Escape)
00078         QSlider::keyPressEvent(e);
00079 }
00080 
00081 void Slider::keyReleaseEvent(QKeyEvent* e)
00082 {
00083     if (!mReadOnly)
00084         QSlider::keyReleaseEvent(e);
00085 }
KDE Home | KDE Accessibility Home | Description of Access Keys