1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/*
* keyboard.cpp
*
* Copyright (c) 1997 Patrick Dowler dowler@morgul.fsh.uvic.ca
*
* Requires the Qt widget libraries, available at no cost at
* http://www.troll.no/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <iostream.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <qfileinf.h>
#include <qstring.h>
#include <qmsgbox.h>
#include <kmsgbox.h>
#include "keyboard.h"
#include <X11/Xlib.h>
#include "geom.h"
static bool GUI;
KeyboardConfig::~KeyboardConfig ()
{
if (GUI)
{
delete click;
delete c;
delete clabel;
delete percent;
delete repeatOn;
delete repeatOff;
delete repeatBox;
}
}
KeyboardConfig::KeyboardConfig (QWidget * parent, const char *name, bool init)
: KConfigWidget (parent, name)
{
if (init)
GUI = FALSE;
else
GUI = TRUE;
if (GUI)
{
repeatBox = new QButtonGroup(klocale->translate("Keyboard repeat"),
this, "repeat");
repeatOn = new QRadioButton(klocale->translate("On"), repeatBox, "on");
repeatOff = new QRadioButton(klocale->translate("Off"), repeatBox, "off");
click = new KSlider(0,100,10,100, KSlider::Horizontal, this, "click");
c = new QLCDNumber (3, this, "c");
c->setFrameStyle( QFrame::NoFrame );
clabel = new QLabel(klocale->translate("Key click volume"), this);
percent = new QLabel("%", this);
connect( click, SIGNAL(valueChanged(int)), c, SLOT(display(int)) );
repeatOn->adjustSize();
repeatOff->adjustSize();
c->adjustSize();
clabel->adjustSize();
percent->adjustSize();
}
config = kapp->getConfig();
GetSettings();
}
void KeyboardConfig::resizeEvent(QResizeEvent *)
{
int h = SPACE_YO;
QFontMetrics fm = repeatBox->font();
int titleH = fm.height();
int titleW = fm.width(repeatBox->title());
int buttonH = repeatOn->height();
int buttonW = max( repeatOn->width(), repeatOff->width() );
int boxH = 2*buttonH + 3*SPACE_YI + titleH;
int boxW = 0;
if (boxW < titleW + 4*SPACE_XI)
boxW = titleW + 4*SPACE_XI;
if (boxW < buttonW + 2*SPACE_XI)
boxW = buttonW + 2*SPACE_XI;
int h_box = h;
h += boxH + SPACE_YO;
repeatOn->move(SPACE_XI, SPACE_YI + titleH);
repeatOff->move(SPACE_XI, 2*SPACE_YI + buttonH + titleH);
repeatBox->setGeometry(SPACE_XO, h_box, boxW, boxH);
int w = 0;
w = max(w, clabel->width());
clabel->move(SPACE_XO, h);
QSize qsh = click->sizeHint();
click->setGeometry(w + 2*SPACE_XO, h, 200, qsh.height());
h += (QMAX( qsh.height(),clabel->height()) + SPACE_YI);
int center = click->x() + ( click->width() - c->width() )/2;
c->move(center, h);
int dh = ( c->height() - percent->height() )/2;
percent->move(c->x() + c->width() + 3, h+dh);
h += c->height() + SPACE_YO;
}
// return the current LCD setting
int KeyboardConfig::getRepeat()
{
if (repeatOn->isChecked())
return AutoRepeatModeOn;
else
return AutoRepeatModeOff;
}
int KeyboardConfig::getClick()
{
return c->intValue();
}
// set the slider and LCD values
void KeyboardConfig::setRepeat(int r)
{
repeatOn->setChecked(FALSE);
repeatOff->setChecked(FALSE);
if (r == AutoRepeatModeOn)
repeatOn->setChecked(TRUE);
else
repeatOff->setChecked(TRUE);
}
void KeyboardConfig::setClick(int v)
{
click->setValue(v);
c->display(v);
}
void KeyboardConfig::GetSettings( void )
{
XKeyboardState kbd;
XGetKeyboardControl(kapp->getDisplay(), &kbd);
config->setGroup("Keyboard");
QString key = config->readEntry("KeyboardRepeat");
if (key == NULL)
keyboardRepeat = kbd.global_auto_repeat;
else if (key == "on")
keyboardRepeat = AutoRepeatModeOn;
else
keyboardRepeat = AutoRepeatModeOff;
clickVolume = config->readNumEntry("ClickVolume",-1);
if (clickVolume == -1)
clickVolume = kbd.key_click_percent;
// the GUI should reflect the real values
if (GUI)
{
setClick(kbd.key_click_percent);
setRepeat(kbd.global_auto_repeat);
}
}
void KeyboardConfig::saveParams( void )
{
XKeyboardControl kbd;
if (GUI)
{
clickVolume = getClick();
keyboardRepeat = getRepeat();
}
kbd.key_click_percent = clickVolume;
kbd.auto_repeat_mode = keyboardRepeat;
XChangeKeyboardControl(kapp->getDisplay(),
KBKeyClickPercent | KBAutoRepeatMode,
&kbd);
config->setGroup("Keyboard");
config->writeEntry("ClickVolume",clickVolume);
if (keyboardRepeat == AutoRepeatModeOn)
config->writeEntry("KeyboardRepeat","on");
else
config->writeEntry("KeyboardRepeat","off");
config->sync();
}
void KeyboardConfig::loadSettings()
{
GetSettings();
}
void KeyboardConfig::applySettings()
{
saveParams();
}
#include "keyboard.moc"
|