4
* Copyright (c) 1997 Patrick Dowler dowler@morgul.fsh.uvic.ca
6
* Layout management, cleanups:
7
* Copyright (c) 1999 Dirk A. Mueller <dmuell@gmx.net>
9
* Requires the Qt widget libraries, available at no cost at
10
* http://www.troll.no/
12
* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
#include "ui_kcmmiscwidget.h"
32
#include <QtGui/QCheckBox>
33
#include <QtGui/QWhatsThis>
34
#include <QtGui/QX11Info>
38
#include <knuminput.h>
43
KCMiscKeyboardWidget::KCMiscKeyboardWidget(QWidget *parent)
45
ui(*new Ui_KeyboardConfigWidget)
49
ui.delay->setRange(100, 5000, 50);
50
ui.delay->setSliderEnabled(false);
51
ui.rate->setRange(0.2, 50, 5, false);
53
sliderMax = (int)floor (0.5 + 2*(log(5000.0L)-log(100.0L)) / (log(5000.0L)-log(4999.0L)));
54
ui.delaySlider->setRange(0, sliderMax);
55
ui.delaySlider->setSingleStep(sliderMax/100);
56
ui.delaySlider->setPageStep(sliderMax/10);
57
ui.delaySlider->setTickInterval(sliderMax/10);
59
ui.rateSlider->setRange(20, 5000);
60
ui.rateSlider->setSingleStep(30);
61
ui.rateSlider->setPageStep(500);
62
ui.rateSlider->setTickInterval(498);
64
connect(ui.keyboardRepeatButtonGroup, SIGNAL(clicked()), this, SLOT(changed()));
65
connect(ui.keyboardRepeatButtonGroup, SIGNAL(changed(int)), this, SLOT(keyboardRepeatStateChanged(int)));
66
connect(ui.delay, SIGNAL(valueChanged(int)), this, SLOT(delaySpinboxChanged(int)));
67
connect(ui.delaySlider, SIGNAL(valueChanged(int)), this, SLOT(delaySliderChanged(int)));
68
connect(ui.rate, SIGNAL(valueChanged(double)), this, SLOT(rateSpinboxChanged(double)));
69
connect(ui.rateSlider, SIGNAL(valueChanged(int)), this, SLOT(rateSliderChanged(int)));
71
connect(ui.click, SIGNAL(valueChanged(int)), this, SLOT(changed()));
72
connect(ui.numlockButtonGroup, SIGNAL(released(int)), this, SLOT(changed()));
74
// Not sure why we need this - if XKB is not found the whole keyboard module won't be compiled
75
//#if !defined(HAVE_XTEST) && !defined(HAVE_XKB)
76
// ui.numlockButtonGroup->setDisabled( true );
78
//#if !defined(HAVE_XKB) && !defined(HAVE_XF86MISC)
79
// ui.delay->setDisabled( true );
80
// ui.rate->setDisabled( true );
84
KCMiscKeyboardWidget::~KCMiscKeyboardWidget()
89
int KCMiscKeyboardWidget::getClick()
91
return ui.click->value();
94
// set the slider and LCD values
95
void KCMiscKeyboardWidget::setRepeat(TriState keyboardRepeat, int delay_, double rate_)
97
TriStateHelper::setTriState( ui.keyboardRepeatButtonGroup, keyboardRepeat );
98
// ui.repeatBox->setChecked(r == AutoRepeatModeOn);
99
ui.delay->setValue(delay_);
100
ui.rate->setValue(rate_);
101
delaySpinboxChanged(delay_);
102
rateSpinboxChanged(rate_);
105
void KCMiscKeyboardWidget::setClickVolume(int v)
107
ui.click->setValue(v);
110
TriState TriStateHelper::getTriState(const KButtonGroup* group)
112
int selected = group->selected();
113
return selected < 0 ? STATE_UNCHANGED : getTriState(selected);
116
void TriStateHelper::setTriState(KButtonGroup* group, TriState state)
118
group->setSelected( getInt(state) );
121
void KCMiscKeyboardWidget::load()
123
KConfigGroup config(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Keyboard");
125
ui.delay->blockSignals(true);
126
ui.rate->blockSignals(true);
127
ui.click->blockSignals(true);
129
// need to read as string to support old "true/false" parameter
130
QString key = config.readEntry("KeyboardRepeating", TriStateHelper::getString(STATE_ON));
131
if( key == "true" || key == TriStateHelper::getString(STATE_ON)) {
132
keyboardRepeat = STATE_ON;
134
else if( key == "false" || key == TriStateHelper::getString(STATE_OFF)) {
135
keyboardRepeat = STATE_OFF;
138
keyboardRepeat = STATE_UNCHANGED;
141
// keyboardRepeat = (key ? AutoRepeatModeOn : AutoRepeatModeOff);
142
float delay = config.readEntry( "RepeatDelay", 660 );
143
float rate = config.readEntry( "RepeatRate", 25. );
144
setRepeat(keyboardRepeat, delay, rate);
147
XGetKeyboardControl(QX11Info::display(), &kbd);
149
clickVolume = config.readEntry("ClickVolume", kbd.key_click_percent);
150
setClickVolume(clickVolume);
151
// setRepeat(kbd.global_auto_repeat, ui.delay->value(), ui.rate->value());
153
numlockState = TriStateHelper::getTriState(config.readEntry( "NumLock", TriStateHelper::getInt(STATE_UNCHANGED) ));
154
TriStateHelper::setTriState( ui.numlockButtonGroup, numlockState );
156
ui.delay->blockSignals(false);
157
ui.rate->blockSignals(false);
158
ui.click->blockSignals(false);
161
void KCMiscKeyboardWidget::save()
163
KConfigGroup config(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Keyboard");
165
clickVolume = getClick();
166
keyboardRepeat = TriStateHelper::getTriState(ui.keyboardRepeatButtonGroup);
167
numlockState = TriStateHelper::getTriState(ui.numlockButtonGroup);
169
config.writeEntry("ClickVolume",clickVolume);
170
config.writeEntry("KeyboardRepeating", TriStateHelper::getInt(keyboardRepeat));
171
config.writeEntry("RepeatRate", ui.rate->value() );
172
config.writeEntry("RepeatDelay", ui.delay->value() );
173
config.writeEntry("NumLock", TriStateHelper::getInt(numlockState) );
177
void KCMiscKeyboardWidget::defaults()
180
setRepeat(STATE_ON, 660, 25);
181
TriStateHelper::setTriState( ui.numlockButtonGroup, STATE_UNCHANGED );
185
QString KCMiscKeyboardWidget::quickHelp() const
189
/* "<h1>Keyboard</h1> This module allows you to choose options"
190
" for the way in which your keyboard works. The actual effect of"
191
" setting these options depends upon the features provided by your"
192
" keyboard hardware and the X server on which KDE is running.<p>"
193
" For example, you may find that changing the key click volume"
194
" has no effect because this feature is not available on your system." */
197
void KCMiscKeyboardWidget::delaySliderChanged (int value) {
198
double alpha = sliderMax / (log(5000.0L) - log(100.0L));
199
double linearValue = exp (value/alpha + log(100.0L));
201
ui.delay->setValue((int)floor(0.5 + linearValue));
206
void KCMiscKeyboardWidget::delaySpinboxChanged (int value) {
207
double alpha = sliderMax / (log(5000.0L) - log(100.0L));
208
double logVal = alpha * (log((double)value)-log(100.0L));
210
ui.delaySlider->setValue ((int)floor (0.5 + logVal));
215
void KCMiscKeyboardWidget::rateSliderChanged (int value) {
216
ui.rate->setValue(value/100.0);
221
void KCMiscKeyboardWidget::rateSpinboxChanged (double value) {
222
ui.rateSlider->setValue ((int)(value*100));
227
void KCMiscKeyboardWidget::changed()
232
void KCMiscKeyboardWidget::keyboardRepeatStateChanged(int selection)
234
bool enabled = selection == TriStateHelper::getInt(STATE_ON);
235
ui.keyboardRepeatParamsGroupBox->setEnabled(enabled);