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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
//
// KDE Help Options
//
// (c) Martin R. Jones 1996
//
#include <qbttngrp.h>
#include <qradiobt.h>
#include <qpushbt.h>
#include <qcombo.h>
#include <qlabel.h>
#include <qchkbox.h>
#include <kapp.h>
#include <kconfig.h>
#include <X11/Xlib.h>
#include "kcolorbtn.h"
#include "options.h"
#include "dbnew.h"
#include "options.moc"
#include <klocale.h>
//-----------------------------------------------------------------------------
KFontOptions::KFontOptions( QWidget *parent, const char *name )
: QWidget( parent, name )
{
readOptions();
QRadioButton *rb;
QLabel *label;
QButtonGroup *bg = new QButtonGroup( klocale->translate("Font Size"), this );
bg->setExclusive( TRUE );
bg->setGeometry( 15, 15, 300, 50 );
rb = new QRadioButton( klocale->translate("Small"), bg );
rb->setGeometry( 10, 20, 80, 20 );
rb->setChecked( fSize == 3 );
rb = new QRadioButton( klocale->translate("Medium"), bg );
rb->setGeometry( 100, 20, 80, 20 );
rb->setChecked( fSize == 4 );
rb = new QRadioButton( klocale->translate("Large"), bg );
rb->setGeometry( 200, 20, 80, 20 );
rb->setChecked( fSize == 5 );
label = new QLabel( klocale->translate("Standard Font"), this );
label->setGeometry( 15, 90, 100, 20 );
QComboBox *cb = new QComboBox( false, this );
cb->setGeometry( 120, 90, 180, 25 );
getFontList( standardFonts, "-*-*-*-*-*-*-*-*-*-*-p-*-*-*" );
cb->insertStrList( &standardFonts );
QStrListIterator sit( standardFonts );
int i;
for ( i = 0; sit.current(); ++sit, i++ )
{
if ( !strcmp( stdName, sit.current() ) )
cb->setCurrentItem( i );
}
connect( cb, SIGNAL( activated( const char * ) ),
SLOT( slotStandardFont( const char * ) ) );
label = new QLabel( klocale->translate( "Fixed Font"), this );
label->setGeometry( 15, 130, 100, 20 );
cb = new QComboBox( false, this );
cb->setGeometry( 120, 130, 180, 25 );
getFontList( fixedFonts, "-*-*-*-*-*-*-*-*-*-*-m-*-*-*" );
cb->insertStrList( &fixedFonts );
QStrListIterator fit( fixedFonts );
for ( i = 0; fit.current(); ++fit, i++ )
{
if ( !strcmp( fixedName, fit.current() ) )
cb->setCurrentItem( i );
}
connect( cb, SIGNAL( activated( const char * ) ),
SLOT( slotFixedFont( const char * ) ) );
connect( bg, SIGNAL( clicked( int ) ), SLOT( slotFontSize( int ) ) );
}
void KFontOptions::readOptions()
{
KConfig *config = KApplication::getKApplication()->getConfig();
config->setGroup( "Appearance" );
QString fs = config->readEntry( "BaseFontSize" );
if ( !fs.isEmpty() )
{
fSize = fs.toInt();
if ( fSize < 3 )
fSize = 3;
else if ( fSize > 5 )
fSize = 5;
}
else
fSize = 3;
stdName = config->readEntry( "StandardFont" );
if ( stdName.isEmpty() )
stdName = "times";
fixedName = config->readEntry( "FixedFont" );
if ( fixedName.isEmpty() )
fixedName = "courier";
}
void KFontOptions::getFontList( QStrList &list, const char *pattern )
{
int num;
char **xFonts = XListFonts( qt_xdisplay(), pattern, 200, &num );
for ( int i = 0; i < num; i++ )
{
addFont( list, xFonts[i] );
}
XFreeFontNames( xFonts );
}
void KFontOptions::addFont( QStrList &list, const char *xfont )
{
const char *ptr = strchr( xfont, '-' );
if ( !ptr )
return;
ptr = strchr( ptr + 1, '-' );
if ( !ptr )
return;
QString font = ptr + 1;
int pos;
if ( ( pos = font.find( '-' ) ) > 0 )
{
font.truncate( pos );
if ( font.find( "open look", 0, false ) >= 0 )
return;
QStrListIterator it( list );
for ( ; it.current(); ++it )
if ( it.current() == font )
return;
list.append( font );
}
}
void KFontOptions::slotApplyPressed()
{
QString o;
KConfig *config = KApplication::getKApplication()->getConfig();
config->setGroup( "Appearance" );
QString fs;
fs.setNum( fSize );
o = config->writeEntry( "BaseFontSize", fs );
if ( o.isNull() || o.toInt() != fSize )
emit fontSize( fSize );
o = config->writeEntry( "StandardFont", stdName );
if ( o.isNull() || o != stdName )
emit standardFont( stdName );
o = config->writeEntry( "FixedFont", fixedName );
if ( o.isNull() || o != fixedName )
emit fixedFont( fixedName );
config->sync();
}
void KFontOptions::slotFontSize( int i )
{
fSize = i+3;
}
void KFontOptions::slotStandardFont( const char *n )
{
stdName = n;
}
void KFontOptions::slotFixedFont( const char *n )
{
fixedName = n;
}
//-----------------------------------------------------------------------------
KColorOptions::KColorOptions( QWidget *parent, const char *name )
: QWidget( parent, name )
{
readOptions();
KColorButton *colorBtn;
QLabel *label;
label = new QLabel( klocale->translate("Background Color:"), this );
label->setGeometry( 35, 20, 150, 25 );
colorBtn = new KColorButton( bgColor, this );
colorBtn->setGeometry( 185, 20, 80, 30 );
connect( colorBtn, SIGNAL( changed( const QColor & ) ),
SLOT( slotBgColorChanged( const QColor & ) ) );
label = new QLabel( klocale->translate("Normal Text Color:"), this );
label->setGeometry( 35, 60, 150, 25 );
colorBtn = new KColorButton( textColor, this );
colorBtn->setGeometry( 185, 60, 80, 30 );
connect( colorBtn, SIGNAL( changed( const QColor & ) ),
SLOT( slotTextColorChanged( const QColor & ) ) );
label = new QLabel( klocale->translate("URL Link Color:"), this );
label->setGeometry( 35, 100, 150, 25 );
colorBtn = new KColorButton( linkColor, this );
colorBtn->setGeometry( 185, 100, 80, 30 );
connect( colorBtn, SIGNAL( changed( const QColor & ) ),
SLOT( slotLinkColorChanged( const QColor & ) ) );
label = new QLabel( klocale->translate("Followed Link Color:"), this );
label->setGeometry( 35, 140, 150, 25 );
colorBtn = new KColorButton( vLinkColor, this );
colorBtn->setGeometry( 185, 140, 80, 30 );
connect( colorBtn, SIGNAL( changed( const QColor & ) ),
SLOT( slotVLinkColorChanged( const QColor & ) ) );
}
void KColorOptions::readOptions()
{
KConfig *config = KApplication::getKApplication()->getConfig();
config->setGroup( "Appearance" );
bgColor = config->readColorEntry( "BgColor", &white );
textColor = config->readColorEntry( "TextColor", &black );
linkColor = config->readColorEntry( "LinkColor", &blue );
vLinkColor = config->readColorEntry( "VLinkColor", &magenta );
changed = false;
}
void KColorOptions::slotApplyPressed()
{
KConfig *config = KApplication::getKApplication()->getConfig();
config->setGroup( "Appearance" );
config->writeEntry( "BgColor", bgColor );
config->writeEntry( "TextColor", textColor );
config->writeEntry( "LinkColor", linkColor );
config->writeEntry( "VLinkColor", vLinkColor );
if ( changed )
emit colorsChanged( bgColor, textColor, linkColor, vLinkColor );
config->sync();
}
void KColorOptions::slotBgColorChanged( const QColor &col )
{
if ( bgColor != col )
changed = true;
bgColor = col;
}
void KColorOptions::slotTextColorChanged( const QColor &col )
{
if ( textColor != col )
changed = true;
textColor = col;
}
void KColorOptions::slotLinkColorChanged( const QColor &col )
{
if ( linkColor != col )
changed = true;
linkColor = col;
}
void KColorOptions::slotVLinkColorChanged( const QColor &col )
{
if ( vLinkColor != col )
changed = true;
vLinkColor = col;
}
//-----------------------------------------------------------------------------
KHelpOptionsDialog::KHelpOptionsDialog( QWidget *parent, const char *name )
: QTabDialog( parent, name )
{
setCaption( klocale->translate("KDE Help Options") );
resize( 350, 300 );
setOKButton( klocale->translate("OK") );
setCancelButton( klocale->translate("Cancel") );
setApplyButton( klocale->translate("Apply") );
fontOptions = new KFontOptions( this, klocale->translate("Fonts") );
addTab( fontOptions, klocale->translate("Fonts") );
connect( this, SIGNAL( applyButtonPressed() ),
fontOptions, SLOT( slotApplyPressed() ) );
colorOptions = new KColorOptions( this, klocale->translate("Colors") );
addTab( colorOptions, klocale->translate("Colors") );
connect( this, SIGNAL( applyButtonPressed() ),
colorOptions, SLOT( slotApplyPressed() ) );
}
|