~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/keyboard/kcmmisc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * kcmmisc.cpp
 
3
 *
 
4
 * Copyright (c) 1997 Patrick Dowler dowler@morgul.fsh.uvic.ca
 
5
 *
 
6
 * Layout management, cleanups:
 
7
 * Copyright (c) 1999 Dirk A. Mueller <dmuell@gmx.net>
 
8
 *
 
9
 * Requires the Qt widget libraries, available at no cost at
 
10
 * http://www.troll.no/
 
11
 *
 
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.
 
16
 *
 
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.
 
21
 *
 
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.
 
25
 */
 
26
 
 
27
#include "kcmmisc.h"
 
28
#include "ui_kcmmiscwidget.h"
 
29
 
 
30
#include <math.h>
 
31
 
 
32
#include <QtGui/QCheckBox>
 
33
#include <QtGui/QWhatsThis>
 
34
#include <QtGui/QX11Info>
 
35
 
 
36
#include <klocale.h>
 
37
#include <kconfig.h>
 
38
#include <knuminput.h>
 
39
 
 
40
#include <X11/Xlib.h>
 
41
 
 
42
 
 
43
KCMiscKeyboardWidget::KCMiscKeyboardWidget(QWidget *parent)
 
44
        : QWidget(parent),
 
45
          ui(*new Ui_KeyboardConfigWidget)
 
46
{
 
47
  ui.setupUi(this);
 
48
 
 
49
  ui.delay->setRange(100, 5000, 50);
 
50
  ui.delay->setSliderEnabled(false);
 
51
  ui.rate->setRange(0.2, 50, 5, false);
 
52
 
 
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);
 
58
 
 
59
  ui.rateSlider->setRange(20, 5000);
 
60
  ui.rateSlider->setSingleStep(30);
 
61
  ui.rateSlider->setPageStep(500);
 
62
  ui.rateSlider->setTickInterval(498);
 
63
 
 
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)));
 
70
 
 
71
  connect(ui.click, SIGNAL(valueChanged(int)), this, SLOT(changed()));
 
72
  connect(ui.numlockButtonGroup, SIGNAL(released(int)), this, SLOT(changed()));
 
73
 
 
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 );
 
77
//#endif
 
78
//#if !defined(HAVE_XKB) && !defined(HAVE_XF86MISC)
 
79
//  ui.delay->setDisabled( true );
 
80
//  ui.rate->setDisabled( true );
 
81
//#endif
 
82
}
 
83
 
 
84
KCMiscKeyboardWidget::~KCMiscKeyboardWidget()
 
85
{
 
86
        delete &ui;
 
87
}
 
88
 
 
89
int  KCMiscKeyboardWidget::getClick()
 
90
{
 
91
    return ui.click->value();
 
92
}
 
93
 
 
94
// set the slider and LCD values
 
95
void KCMiscKeyboardWidget::setRepeat(TriState keyboardRepeat, int delay_, double rate_)
 
96
{
 
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_);
 
103
}
 
104
 
 
105
void KCMiscKeyboardWidget::setClickVolume(int v)
 
106
{
 
107
    ui.click->setValue(v);
 
108
}
 
109
 
 
110
TriState TriStateHelper::getTriState(const KButtonGroup* group)
 
111
{
 
112
    int selected = group->selected();
 
113
    return selected < 0 ? STATE_UNCHANGED : getTriState(selected);
 
114
}
 
115
 
 
116
void TriStateHelper::setTriState(KButtonGroup* group, TriState state)
 
117
{
 
118
    group->setSelected( getInt(state) );
 
119
}
 
120
 
 
121
void KCMiscKeyboardWidget::load()
 
122
{
 
123
  KConfigGroup config(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Keyboard");
 
124
 
 
125
  ui.delay->blockSignals(true);
 
126
  ui.rate->blockSignals(true);
 
127
  ui.click->blockSignals(true);
 
128
 
 
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;
 
133
  }
 
134
  else if( key == "false" || key == TriStateHelper::getString(STATE_OFF)) {
 
135
          keyboardRepeat = STATE_OFF;
 
136
  }
 
137
  else {
 
138
          keyboardRepeat = STATE_UNCHANGED;
 
139
  }
 
140
 
 
141
//  keyboardRepeat = (key ? AutoRepeatModeOn : AutoRepeatModeOff);
 
142
  float delay = config.readEntry( "RepeatDelay", 660 );
 
143
  float rate = config.readEntry( "RepeatRate", 25. );
 
144
  setRepeat(keyboardRepeat, delay, rate);
 
145
 
 
146
  XKeyboardState kbd;
 
147
  XGetKeyboardControl(QX11Info::display(), &kbd);
 
148
 
 
149
  clickVolume = config.readEntry("ClickVolume", kbd.key_click_percent);
 
150
  setClickVolume(clickVolume);
 
151
  //  setRepeat(kbd.global_auto_repeat, ui.delay->value(), ui.rate->value());
 
152
 
 
153
  numlockState = TriStateHelper::getTriState(config.readEntry( "NumLock", TriStateHelper::getInt(STATE_UNCHANGED) ));
 
154
  TriStateHelper::setTriState( ui.numlockButtonGroup, numlockState );
 
155
 
 
156
  ui.delay->blockSignals(false);
 
157
  ui.rate->blockSignals(false);
 
158
  ui.click->blockSignals(false);
 
159
}
 
160
 
 
161
void KCMiscKeyboardWidget::save()
 
162
{
 
163
  KConfigGroup config(KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals), "Keyboard");
 
164
 
 
165
  clickVolume = getClick();
 
166
  keyboardRepeat = TriStateHelper::getTriState(ui.keyboardRepeatButtonGroup);
 
167
  numlockState = TriStateHelper::getTriState(ui.numlockButtonGroup);
 
168
 
 
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) );
 
174
  config.sync();
 
175
}
 
176
 
 
177
void KCMiscKeyboardWidget::defaults()
 
178
{
 
179
    setClickVolume(50);
 
180
    setRepeat(STATE_ON, 660, 25);
 
181
    TriStateHelper::setTriState( ui.numlockButtonGroup, STATE_UNCHANGED );
 
182
    emit changed(true);
 
183
}
 
184
 
 
185
QString KCMiscKeyboardWidget::quickHelp() const
 
186
{
 
187
  return QString();
 
188
 
 
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." */
 
195
}
 
196
 
 
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));
 
200
 
 
201
        ui.delay->setValue((int)floor(0.5 + linearValue));
 
202
 
 
203
        emit changed(true);
 
204
}
 
205
 
 
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));
 
209
 
 
210
        ui.delaySlider->setValue ((int)floor (0.5 + logVal));
 
211
 
 
212
        emit changed(true);
 
213
}
 
214
 
 
215
void KCMiscKeyboardWidget::rateSliderChanged (int value) {
 
216
        ui.rate->setValue(value/100.0);
 
217
 
 
218
        emit changed(true);
 
219
}
 
220
 
 
221
void KCMiscKeyboardWidget::rateSpinboxChanged (double value) {
 
222
        ui.rateSlider->setValue ((int)(value*100));
 
223
 
 
224
        emit changed(true);
 
225
}
 
226
 
 
227
void KCMiscKeyboardWidget::changed()
 
228
{
 
229
  emit changed(true);
 
230
}
 
231
 
 
232
void KCMiscKeyboardWidget::keyboardRepeatStateChanged(int selection)
 
233
{
 
234
        bool enabled = selection == TriStateHelper::getInt(STATE_ON);
 
235
        ui.keyboardRepeatParamsGroupBox->setEnabled(enabled);
 
236
        changed();
 
237
}