00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kglobalsettings.h"
00021 #include <config.h>
00022
00023 #include <kconfig.h>
00024
00025 #include <kdebug.h>
00026 #include <kglobal.h>
00027 #include <kstandarddirs.h>
00028 #include <kcharsets.h>
00029 #include <klocale.h>
00030 #include <kprotocolinfo.h>
00031 #include <kcomponentdata.h>
00032 #include <kcolorscheme.h>
00033 #include <kapplication.h>
00034
00035 #include <kstyle.h>
00036
00037 #include <QtGui/QColor>
00038 #include <QtGui/QCursor>
00039 #include <QtGui/QDesktopWidget>
00040 #include <QtCore/QDir>
00041 #include <QtGui/QFont>
00042 #include <QtGui/QFontDatabase>
00043 #include <QtGui/QFontInfo>
00044 #include <QtGui/QKeySequence>
00045 #include <QtGui/QPixmap>
00046 #include <QtGui/QPixmapCache>
00047
00048 #include <QApplication>
00049 #include <QtDBus/QtDBus>
00050 #include <QtGui/QStyleFactory>
00051 #include <QDesktopServices>
00052
00053
00054 #include <QtGui/QToolTip>
00055 #include <QtGui/QWhatsThis>
00056
00057 #ifdef Q_WS_WIN
00058 #include <windows.h>
00059 #include <kkernel_win.h>
00060
00061 static QRgb qt_colorref2qrgb(COLORREF col)
00062 {
00063 return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));
00064 }
00065 #endif
00066 #ifdef Q_WS_X11
00067 #include <X11/Xlib.h>
00068 #ifdef HAVE_XCURSOR
00069 #include <X11/Xcursor/Xcursor.h>
00070 #endif
00071 #include "fixx11h.h"
00072 #include <QX11Info>
00073 #endif
00074
00075 #include <stdlib.h>
00076 #include <kconfiggroup.h>
00077
00078
00079
00080 static KGlobalSettings::GraphicEffects _graphicEffects = KGlobalSettings::NoEffects;
00081
00082
00083
00084
00085 class KGlobalSettingsData
00086 {
00087 public:
00088
00089 enum FontTypes
00090 {
00091 GeneralFont = 0,
00092 FixedFont,
00093 ToolbarFont,
00094 MenuFont,
00095 WindowTitleFont,
00096 TaskbarFont ,
00097 SmallestReadableFont,
00098 FontTypesCount
00099 };
00100
00101 public:
00102 KGlobalSettingsData();
00103 ~KGlobalSettingsData();
00104
00105 public:
00106 static KGlobalSettingsData* self();
00107
00108 public:
00109 QFont font( FontTypes fontType );
00110 QFont largeFont( const QString& text );
00111 KGlobalSettings::KMouseSettings& mouseSettings();
00112
00113 public:
00114 void dropFontSettingsCache();
00115 void dropMouseSettingsCache();
00116
00117 protected:
00118 QFont* mFonts[FontTypesCount];
00119 QFont* mLargeFont;
00120 KGlobalSettings::KMouseSettings* mMouseSettings;
00121 };
00122
00123 KGlobalSettingsData::KGlobalSettingsData()
00124 : mLargeFont( 0 ),
00125 mMouseSettings( 0 )
00126 {
00127 for( int i=0; i<FontTypesCount; ++i )
00128 mFonts[i] = 0;
00129 }
00130
00131 KGlobalSettingsData::~KGlobalSettingsData()
00132 {
00133 for( int i=0; i<FontTypesCount; ++i )
00134 delete mFonts[i];
00135 delete mLargeFont;
00136
00137 delete mMouseSettings;
00138 }
00139
00140 K_GLOBAL_STATIC( KGlobalSettingsData, globalSettingsDataSingleton )
00141
00142 inline KGlobalSettingsData* KGlobalSettingsData::self()
00143 {
00144 return globalSettingsDataSingleton;
00145 }
00146
00147
00148 class KGlobalSettings::Private
00149 {
00150 public:
00151 Private(KGlobalSettings *q)
00152 : q(q)
00153 {
00154 }
00155
00156 void _k_slotNotifyChange(int, int);
00157
00158 void propagateSettings(SettingsCategory category);
00159 void kdisplaySetPalette();
00160 void kdisplaySetStyle();
00161 void kdisplaySetFont();
00162 void applyGUIStyle();
00163
00175 void applyCursorTheme();
00176
00180 static void rereadOtherSettings();
00181
00182 KGlobalSettings *q;
00183 };
00184
00185 KGlobalSettings* KGlobalSettings::self()
00186 {
00187 K_GLOBAL_STATIC(KGlobalSettings, s_self)
00188 return s_self;
00189 }
00190
00191 KGlobalSettings::KGlobalSettings()
00192 : QObject(0), d(new Private(this))
00193 {
00194 d->kdisplaySetStyle();
00195 d->kdisplaySetFont();
00196 d->propagateSettings(SETTINGS_QT);
00197
00198 QDBusConnection::sessionBus().connect( QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
00199 "notifyChange", this, SLOT(_k_slotNotifyChange(int,int)) );
00200 }
00201
00202 KGlobalSettings::~KGlobalSettings()
00203 {
00204 delete d;
00205 }
00206
00207 int KGlobalSettings::dndEventDelay()
00208 {
00209 KConfigGroup g( KGlobal::config(), "General" );
00210 return g.readEntry("StartDragDist", QApplication::startDragDistance());
00211 }
00212
00213 bool KGlobalSettings::singleClick()
00214 {
00215 KConfigGroup g( KGlobal::config(), "KDE" );
00216 return g.readEntry("SingleClick", KDE_DEFAULT_SINGLECLICK );
00217 }
00218
00219 bool KGlobalSettings::smoothScroll()
00220 {
00221 KConfigGroup g( KGlobal::config(), "KDE" );
00222 return g.readEntry("SmoothScroll", KDE_DEFAULT_SMOOTHSCROLL );
00223 }
00224
00225 KGlobalSettings::TearOffHandle KGlobalSettings::insertTearOffHandle()
00226 {
00227 int tearoff;
00228 bool effectsenabled;
00229 KConfigGroup g( KGlobal::config(), "KDE" );
00230 effectsenabled = g.readEntry( "EffectsEnabled", false);
00231 tearoff = g.readEntry("InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
00232 return effectsenabled ? (TearOffHandle) tearoff : Disable;
00233 }
00234
00235 bool KGlobalSettings::changeCursorOverIcon()
00236 {
00237 KConfigGroup g( KGlobal::config(), "KDE" );
00238 return g.readEntry("ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
00239 }
00240
00241 int KGlobalSettings::autoSelectDelay()
00242 {
00243 KConfigGroup g( KGlobal::config(), "KDE" );
00244 return g.readEntry("AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
00245 }
00246
00247 KGlobalSettings::Completion KGlobalSettings::completionMode()
00248 {
00249 int completion;
00250 KConfigGroup g( KGlobal::config(), "General" );
00251 completion = g.readEntry("completionMode", -1);
00252 if ((completion < (int) CompletionNone) ||
00253 (completion > (int) CompletionPopupAuto))
00254 {
00255 completion = (int) CompletionPopup;
00256 }
00257 return (Completion) completion;
00258 }
00259
00260 bool KGlobalSettings::showContextMenusOnPress ()
00261 {
00262 KConfigGroup g(KGlobal::config(), "ContextMenus");
00263 return g.readEntry("ShowOnPress", true);
00264 }
00265
00266 int KGlobalSettings::contextMenuKey ()
00267 {
00268 KConfigGroup g(KGlobal::config(), "Shortcuts");
00269 QString s = g.readEntry ("PopupMenuContext", "Menu");
00270
00271
00272
00273
00274
00275 if (s == QLatin1String("none")) {
00276 return QKeySequence()[0];
00277 }
00278
00279 const QStringList shortCuts = s.split(';');
00280
00281 if (shortCuts.count() < 1) {
00282 return QKeySequence()[0];
00283 }
00284
00285 s = shortCuts.at(0);
00286
00287 if ( s.startsWith( "default(" ) ) {
00288 s = s.mid( 8, s.length() - 9 );
00289 }
00290
00291 return QKeySequence::fromString(s)[0];
00292 }
00293
00294
00295 QColor KGlobalSettings::inactiveTitleColor()
00296 {
00297 #ifdef Q_WS_WIN
00298 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
00299 #else
00300 KConfigGroup g( KGlobal::config(), "WM" );
00301 return g.readEntry( "inactiveBackground", QColor(224, 223, 222) );
00302 #endif
00303 }
00304
00305
00306 QColor KGlobalSettings::inactiveTextColor()
00307 {
00308 #ifdef Q_WS_WIN
00309 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
00310 #else
00311 KConfigGroup g( KGlobal::config(), "WM" );
00312 return g.readEntry( "inactiveForeground", QColor(20, 19, 18) );
00313 #endif
00314 }
00315
00316
00317 QColor KGlobalSettings::activeTitleColor()
00318 {
00319 #ifdef Q_WS_WIN
00320 return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
00321 #else
00322 KConfigGroup g( KGlobal::config(), "WM" );
00323 return g.readEntry( "activeBackground", QColor(96, 148, 207));
00324 #endif
00325 }
00326
00327
00328 QColor KGlobalSettings::activeTextColor()
00329 {
00330 #ifdef Q_WS_WIN
00331 return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
00332 #else
00333 KConfigGroup g( KGlobal::config(), "WM" );
00334 return g.readEntry( "activeForeground", QColor(255, 255, 255) );
00335 #endif
00336 }
00337
00338 int KGlobalSettings::contrast()
00339 {
00340 KConfigGroup g( KGlobal::config(), "KDE" );
00341 return g.readEntry( "contrast", 7 );
00342 }
00343
00344 qreal KGlobalSettings::contrastF(const KSharedConfigPtr &config)
00345 {
00346 if (config) {
00347 KConfigGroup g( config, "KDE" );
00348 return 0.1 * g.readEntry( "contrast", 7 );
00349 }
00350 return 0.1 * (qreal)contrast();
00351 }
00352
00353 bool KGlobalSettings::shadeSortColumn()
00354 {
00355 KConfigGroup g( KGlobal::config(), "General" );
00356 return g.readEntry( "shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
00357 }
00358
00359 bool KGlobalSettings::allowDefaultBackgroundImages()
00360 {
00361 KConfigGroup g( KGlobal::config(), "General" );
00362 return g.readEntry( "allowDefaultBackgroundImages", KDE_DEFAULT_ALLOW_DEFAULT_BACKGROUND_IMAGES );
00363 }
00364
00365 struct KFontData
00366 {
00367 const char* ConfigGroupKey;
00368 const char* ConfigKey;
00369 const char* FontName;
00370 int Size;
00371 int Weight;
00372 QFont::StyleHint StyleHint;
00373 };
00374
00375
00376 static const char GeneralId[] = "General";
00377 static const char DefaultFont[] = "Sans Serif";
00378 #ifdef Q_WS_MAC
00379 static const char DefaultMacFont[] = "Lucida Grande";
00380 #endif
00381
00382 static const KFontData DefaultFontData[KGlobalSettingsData::FontTypesCount] =
00383 {
00384 #ifdef Q_WS_MAC
00385 { GeneralId, "font", DefaultMacFont, 13, -1, QFont::SansSerif },
00386 { GeneralId, "fixed", "Monaco", 10, -1, QFont::TypeWriter },
00387 { GeneralId, "toolBarFont", DefaultMacFont, 11, -1, QFont::SansSerif },
00388 { GeneralId, "menuFont", DefaultMacFont, 13, -1, QFont::SansSerif },
00389 #else
00390 { GeneralId, "font", DefaultFont, 10, -1, QFont::SansSerif },
00391 { GeneralId, "fixed", "Monospace", 10, -1, QFont::TypeWriter },
00392 { GeneralId, "toolBarFont", DefaultFont, 8, -1, QFont::SansSerif },
00393 { GeneralId, "menuFont", DefaultFont, 10, -1, QFont::SansSerif },
00394 #endif
00395 { "WM", "activeFont", DefaultFont, 9, QFont::Bold, QFont::SansSerif },
00396 { GeneralId, "taskbarFont", DefaultFont, 10, -1, QFont::SansSerif },
00397 { GeneralId, "smallestReadableFont", DefaultFont, 8, -1, QFont::SansSerif }
00398 };
00399
00400 QFont KGlobalSettingsData::font( FontTypes fontType )
00401 {
00402 QFont* cachedFont = mFonts[fontType];
00403
00404 if (!cachedFont)
00405 {
00406 const KFontData& fontData = DefaultFontData[fontType];
00407 cachedFont = new QFont( fontData.FontName, fontData.Size, fontData.Weight );
00408 cachedFont->setStyleHint( fontData.StyleHint );
00409
00410 const KConfigGroup configGroup( KGlobal::config(), fontData.ConfigGroupKey );
00411 *cachedFont = configGroup.readEntry( fontData.ConfigKey, *cachedFont );
00412
00413 mFonts[fontType] = cachedFont;
00414 }
00415
00416 return *cachedFont;
00417 }
00418
00419 QFont KGlobalSettings::generalFont()
00420 {
00421 return KGlobalSettingsData::self()->font( KGlobalSettingsData::GeneralFont );
00422 }
00423 QFont KGlobalSettings::fixedFont()
00424 {
00425 return KGlobalSettingsData::self()->font( KGlobalSettingsData::FixedFont );
00426 }
00427 QFont KGlobalSettings::toolBarFont()
00428 {
00429 return KGlobalSettingsData::self()->font( KGlobalSettingsData::ToolbarFont );
00430 }
00431 QFont KGlobalSettings::menuFont()
00432 {
00433 return KGlobalSettingsData::self()->font( KGlobalSettingsData::MenuFont );
00434 }
00435 QFont KGlobalSettings::windowTitleFont()
00436 {
00437 return KGlobalSettingsData::self()->font( KGlobalSettingsData::WindowTitleFont );
00438 }
00439 QFont KGlobalSettings::taskbarFont()
00440 {
00441 return KGlobalSettingsData::self()->font( KGlobalSettingsData::TaskbarFont );
00442 }
00443 QFont KGlobalSettings::smallestReadableFont()
00444 {
00445 return KGlobalSettingsData::self()->font( KGlobalSettingsData::SmallestReadableFont );
00446 }
00447
00448
00449 QFont KGlobalSettingsData::largeFont( const QString& text )
00450 {
00451 QFontDatabase db;
00452 QStringList fam = db.families();
00453
00454
00455
00456 static const char* PreferredFontNames[] =
00457 {
00458 "Arial",
00459 "Sans Serif",
00460 "Verdana",
00461 "Tahoma",
00462 "Lucida Sans",
00463 "Lucidux Sans",
00464 "Nimbus Sans",
00465 "Gothic I"
00466 };
00467 static const unsigned int PreferredFontNamesCount = sizeof(PreferredFontNames)/sizeof(const char*);
00468 for( unsigned int i=0; i<PreferredFontNamesCount; ++i )
00469 {
00470 const QString fontName (PreferredFontNames[i]);
00471 if (fam.removeAll(fontName)>0)
00472 fam.prepend(fontName);
00473 }
00474
00475 if (mLargeFont)
00476 fam.prepend(mLargeFont->family());
00477
00478 for(QStringList::ConstIterator it = fam.constBegin();
00479 it != fam.constEnd(); ++it)
00480 {
00481 if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
00482 {
00483 QFont font(*it);
00484 font.setPixelSize(75);
00485 QFontMetrics metrics(font);
00486 int h = metrics.height();
00487 if ((h < 60) || ( h > 90))
00488 continue;
00489
00490 bool ok = true;
00491 for(int i = 0; i < text.length(); i++)
00492 {
00493 if (!metrics.inFont(text[i]))
00494 {
00495 ok = false;
00496 break;
00497 }
00498 }
00499 if (!ok)
00500 continue;
00501
00502 font.setPointSize(48);
00503 mLargeFont = new QFont(font);
00504 return *mLargeFont;
00505 }
00506 }
00507 mLargeFont = new QFont( font(GeneralFont) );
00508 mLargeFont->setPointSize(48);
00509 return *mLargeFont;
00510 }
00511 QFont KGlobalSettings::largeFont( const QString& text )
00512 {
00513 return KGlobalSettingsData::self()->largeFont( text );
00514 }
00515
00516 void KGlobalSettingsData::dropFontSettingsCache()
00517 {
00518 for( int i=0; i<FontTypesCount; ++i )
00519 {
00520 delete mFonts[i];
00521 mFonts[i] = 0;
00522 }
00523 delete mLargeFont;
00524 }
00525
00526 KGlobalSettings::KMouseSettings& KGlobalSettingsData::mouseSettings()
00527 {
00528 if (!mMouseSettings)
00529 {
00530 mMouseSettings = new KGlobalSettings::KMouseSettings;
00531 KGlobalSettings::KMouseSettings& s = *mMouseSettings;
00532
00533 #ifndef Q_WS_WIN
00534 KConfigGroup g( KGlobal::config(), "Mouse" );
00535 QString setting = g.readEntry("MouseButtonMapping");
00536 if (setting == "RightHanded")
00537 s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00538 else if (setting == "LeftHanded")
00539 s.handed = KGlobalSettings::KMouseSettings::LeftHanded;
00540 else
00541 {
00542 #ifdef Q_WS_X11
00543
00544
00545
00546 s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00547 unsigned char map[20];
00548 int num_buttons = XGetPointerMapping(QX11Info::display(), map, 20);
00549 if( num_buttons == 2 )
00550 {
00551 if ( (int)map[0] == 1 && (int)map[1] == 2 )
00552 s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00553 else if ( (int)map[0] == 2 && (int)map[1] == 1 )
00554 s.handed = KGlobalSettings::KMouseSettings::LeftHanded;
00555 }
00556 else if( num_buttons >= 3 )
00557 {
00558 if ( (int)map[0] == 1 && (int)map[2] == 3 )
00559 s.handed = KGlobalSettings::KMouseSettings::RightHanded;
00560 else if ( (int)map[0] == 3 && (int)map[2] == 1 )
00561 s.handed = KGlobalSettings::KMouseSettings::LeftHanded;
00562 }
00563 #else
00564
00565 #endif
00566 }
00567 #endif //Q_WS_WIN
00568 }
00569 #ifdef Q_WS_WIN
00570
00571 mMouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ?
00572 KGlobalSettings::KMouseSettings::LeftHanded :
00573 KGlobalSettings::KMouseSettings::RightHanded);
00574 #endif
00575 return *mMouseSettings;
00576 }
00577
00578 KGlobalSettings::KMouseSettings & KGlobalSettings::mouseSettings()
00579 {
00580 return KGlobalSettingsData::self()->mouseSettings();
00581 }
00582
00583 void KGlobalSettingsData::dropMouseSettingsCache()
00584 {
00585 #ifndef Q_WS_WIN
00586 delete mMouseSettings;
00587 mMouseSettings = 0;
00588 #endif
00589 }
00590
00591 QString KGlobalSettings::desktopPath()
00592 {
00593 QString path = QDesktopServices::storageLocation( QDesktopServices::DesktopLocation );
00594 return path.isEmpty() ? QDir::homePath() : path;
00595 }
00596
00597
00598 QString KGlobalSettings::autostartPath()
00599 {
00600 QString s_autostartPath;
00601 KConfigGroup g( KGlobal::config(), "Paths" );
00602 s_autostartPath = KGlobal::dirs()->localkdedir() + "Autostart/";
00603 s_autostartPath = g.readPathEntry( "Autostart" , s_autostartPath );
00604 s_autostartPath = QDir::cleanPath( s_autostartPath );
00605 if ( !s_autostartPath.endsWith( '/' ) ) {
00606 s_autostartPath.append( QLatin1Char( '/' ) );
00607 }
00608 return s_autostartPath;
00609 }
00610
00611 QString KGlobalSettings::documentPath()
00612 {
00613 QString path = QDesktopServices::storageLocation( QDesktopServices::DocumentsLocation );
00614 return path.isEmpty() ? QDir::homePath() : path;
00615 }
00616
00617 QString KGlobalSettings::downloadPath()
00618 {
00619
00620 QString downloadPath = QDir::homePath();
00621 #ifndef Q_WS_WIN
00622 const QString xdgUserDirs = KGlobal::dirs()->localxdgconfdir() + QLatin1String( "user-dirs.dirs" );
00623 if( QFile::exists( xdgUserDirs ) ) {
00624 KConfig xdgUserConf( xdgUserDirs, KConfig::SimpleConfig );
00625 KConfigGroup g( &xdgUserConf, "" );
00626 downloadPath = g.readPathEntry( "XDG_DOWNLOAD_DIR", downloadPath ).remove( '"' );
00627 }
00628 #endif
00629 downloadPath = QDir::cleanPath( downloadPath );
00630 if ( !downloadPath.endsWith( '/' ) ) {
00631 downloadPath.append( QLatin1Char( '/' ) );
00632 }
00633 return downloadPath;
00634 }
00635
00636 QString KGlobalSettings::videosPath()
00637 {
00638 QString path = QDesktopServices::storageLocation( QDesktopServices::MoviesLocation );
00639 return path.isEmpty() ? QDir::homePath() : path;
00640 }
00641
00642 QString KGlobalSettings::picturesPath()
00643 {
00644 QString path = QDesktopServices::storageLocation( QDesktopServices::PicturesLocation );
00645 return path.isEmpty() ? QDir::homePath() :path;
00646 }
00647
00648 QString KGlobalSettings::musicPath()
00649 {
00650 QString path = QDesktopServices::storageLocation( QDesktopServices::MusicLocation );
00651 return path.isEmpty() ? QDir::homePath() : path;
00652 }
00653
00654 bool KGlobalSettings::isMultiHead()
00655 {
00656 #ifdef Q_WS_WIN
00657 return GetSystemMetrics(SM_CMONITORS) > 1;
00658 #else
00659 QByteArray multiHead = qgetenv("KDE_MULTIHEAD");
00660 if (!multiHead.isEmpty()) {
00661 return (multiHead.toLower() == "true");
00662 }
00663 return false;
00664 #endif
00665 }
00666
00667 bool KGlobalSettings::wheelMouseZooms()
00668 {
00669 KConfigGroup g( KGlobal::config(), "KDE" );
00670 return g.readEntry( "WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
00671 }
00672
00673 QRect KGlobalSettings::splashScreenDesktopGeometry()
00674 {
00675 QDesktopWidget *dw = QApplication::desktop();
00676
00677 if (dw->isVirtualDesktop()) {
00678 KConfigGroup group(KGlobal::config(), "Windows");
00679 int scr = group.readEntry("Unmanaged", -3);
00680 if (group.readEntry("XineramaEnabled", true) && scr != -2) {
00681 if (scr == -3)
00682 scr = dw->screenNumber(QCursor::pos());
00683 return dw->screenGeometry(scr);
00684 } else {
00685 return dw->geometry();
00686 }
00687 } else {
00688 return dw->geometry();
00689 }
00690 }
00691
00692 QRect KGlobalSettings::desktopGeometry(const QPoint& point)
00693 {
00694 QDesktopWidget *dw = QApplication::desktop();
00695
00696 if (dw->isVirtualDesktop()) {
00697 KConfigGroup group(KGlobal::config(), "Windows");
00698 if (group.readEntry("XineramaEnabled", true) &&
00699 group.readEntry("XineramaPlacementEnabled", true)) {
00700 return dw->screenGeometry(dw->screenNumber(point));
00701 } else {
00702 return dw->geometry();
00703 }
00704 } else {
00705 return dw->geometry();
00706 }
00707 }
00708
00709 QRect KGlobalSettings::desktopGeometry(const QWidget* w)
00710 {
00711 QDesktopWidget *dw = QApplication::desktop();
00712
00713 if (dw->isVirtualDesktop()) {
00714 KConfigGroup group(KGlobal::config(), "Windows");
00715 if (group.readEntry("XineramaEnabled", true) &&
00716 group.readEntry("XineramaPlacementEnabled", true)) {
00717 if (w)
00718 return dw->screenGeometry(dw->screenNumber(w));
00719 else return dw->screenGeometry(-1);
00720 } else {
00721 return dw->geometry();
00722 }
00723 } else {
00724 return dw->geometry();
00725 }
00726 }
00727
00728 bool KGlobalSettings::showIconsOnPushButtons()
00729 {
00730 KConfigGroup g( KGlobal::config(), "KDE" );
00731 return g.readEntry("ShowIconsOnPushButtons",
00732 KDE_DEFAULT_ICON_ON_PUSHBUTTON);
00733 }
00734
00735 KGlobalSettings::GraphicEffects KGlobalSettings::graphicEffectsLevel()
00736 {
00737
00738
00739
00740 static bool _graphicEffectsInitialized = false;
00741
00742 if (!_graphicEffectsInitialized) {
00743 _graphicEffectsInitialized = true;
00744 Private::rereadOtherSettings();
00745 }
00746
00747 return _graphicEffects;
00748 }
00749
00750 KGlobalSettings::GraphicEffects KGlobalSettings::graphicEffectsLevelDefault()
00751 {
00752
00753
00754
00755 return ComplexAnimationEffects;
00756 }
00757
00758 bool KGlobalSettings::showFilePreview(const KUrl &url)
00759 {
00760 KConfigGroup g(KGlobal::config(), "PreviewSettings");
00761 QString protocol = url.protocol();
00762 bool defaultSetting = KProtocolInfo::showFilePreview( protocol );
00763 return g.readEntry(protocol, defaultSetting );
00764 }
00765
00766 bool KGlobalSettings::opaqueResize()
00767 {
00768 KConfigGroup g( KGlobal::config(), "KDE" );
00769 return g.readEntry("OpaqueResize", KDE_DEFAULT_OPAQUE_RESIZE);
00770 }
00771
00772 int KGlobalSettings::buttonLayout()
00773 {
00774 KConfigGroup g( KGlobal::config(), "KDE" );
00775 return g.readEntry("ButtonLayout", KDE_DEFAULT_BUTTON_LAYOUT);
00776 }
00777
00778 void KGlobalSettings::emitChange(ChangeType changeType, int arg)
00779 {
00780 QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange" );
00781 QList<QVariant> args;
00782 args.append(static_cast<int>(changeType));
00783 args.append(arg);
00784 message.setArguments(args);
00785 QDBusConnection::sessionBus().send(message);
00786 #ifdef Q_WS_X11
00787
00788 extern void qt_x11_apply_settings_in_all_apps();
00789 qt_x11_apply_settings_in_all_apps();
00790 #endif
00791 }
00792
00793 void KGlobalSettings::Private::_k_slotNotifyChange(int changeType, int arg)
00794 {
00795 switch(changeType) {
00796 case StyleChanged:
00797 KGlobal::config()->reparseConfiguration();
00798 kdisplaySetStyle();
00799 break;
00800
00801 case ToolbarStyleChanged:
00802 KGlobal::config()->reparseConfiguration();
00803 emit q->toolbarAppearanceChanged(arg);
00804 break;
00805
00806 case PaletteChanged:
00807 KGlobal::config()->reparseConfiguration();
00808 kdisplaySetPalette();
00809 break;
00810
00811 case FontChanged:
00812 KGlobal::config()->reparseConfiguration();
00813 KGlobalSettingsData::self()->dropFontSettingsCache();
00814 kdisplaySetFont();
00815 break;
00816
00817 case SettingsChanged: {
00818 KGlobal::config()->reparseConfiguration();
00819 rereadOtherSettings();
00820 SettingsCategory category = static_cast<SettingsCategory>(arg);
00821 if (category == SETTINGS_MOUSE) {
00822 KGlobalSettingsData::self()->dropMouseSettingsCache();
00823 }
00824 propagateSettings(category);
00825 break;
00826 }
00827 case IconChanged:
00828 QPixmapCache::clear();
00829 KGlobal::config()->reparseConfiguration();
00830 emit q->iconChanged(arg);
00831 break;
00832
00833 case CursorChanged:
00834 applyCursorTheme();
00835 break;
00836
00837 case BlockShortcuts:
00838
00839
00840 emit q->blockShortcuts(arg);
00841 break;
00842
00843 default:
00844 kWarning(101) << "Unknown type of change in KGlobalSettings::slotNotifyChange: " << changeType;
00845 }
00846 }
00847
00848
00849 QString kde_overrideStyle;
00850
00851 void KGlobalSettings::Private::applyGUIStyle()
00852 {
00853 const QLatin1String currentStyleName(qApp->style()->metaObject()->className());
00854
00855 if (kde_overrideStyle.isEmpty()) {
00856 const QString &defaultStyle = KStyle::defaultStyle();
00857 const KConfigGroup pConfig(KGlobal::config(), "General");
00858 const QString &styleStr = pConfig.readEntry("widgetStyle", defaultStyle);
00859
00860 if (styleStr.isEmpty() ||
00861
00862
00863 0 == (styleStr + QLatin1String("Style")).compare(currentStyleName, Qt::CaseInsensitive) ||
00864 0 == styleStr.compare(currentStyleName, Qt::CaseInsensitive)) {
00865 return;
00866 }
00867
00868 QStyle* sp = QStyleFactory::create( styleStr );
00869 if (sp && currentStyleName == sp->metaObject()->className()) {
00870 delete sp;
00871 return;
00872 }
00873
00874
00875 if ( !sp && styleStr != defaultStyle)
00876 sp = QStyleFactory::create( defaultStyle );
00877 if ( !sp )
00878 sp = QStyleFactory::create( QStyleFactory::keys().first() );
00879 qApp->setStyle(sp);
00880 } else if (0 != kde_overrideStyle.compare(currentStyleName, Qt::CaseInsensitive) &&
00881 0 != (kde_overrideStyle + QLatin1String("Style")).compare(currentStyleName, Qt::CaseInsensitive)) {
00882 qApp->setStyle(kde_overrideStyle);
00883 }
00884 emit q->kdisplayStyleChanged();
00885 }
00886
00887 QPalette KGlobalSettings::createApplicationPalette(const KSharedConfigPtr &config)
00888 {
00889 QPalette palette;
00890
00891 QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
00892 QPalette::Disabled };
00893
00894
00895 KColorScheme schemeTooltip(QPalette::Active, KColorScheme::Tooltip, config);
00896
00897 for ( int i = 0; i < 3 ; i++ ) {
00898 QPalette::ColorGroup state = states[i];
00899 KColorScheme schemeView(state, KColorScheme::View, config);
00900 KColorScheme schemeWindow(state, KColorScheme::Window, config);
00901 KColorScheme schemeButton(state, KColorScheme::Button, config);
00902 KColorScheme schemeSelection(state, KColorScheme::Selection, config);
00903
00904 palette.setBrush( state, QPalette::WindowText, schemeWindow.foreground() );
00905 palette.setBrush( state, QPalette::Window, schemeWindow.background() );
00906 palette.setBrush( state, QPalette::Base, schemeView.background() );
00907 palette.setBrush( state, QPalette::Text, schemeView.foreground() );
00908 palette.setBrush( state, QPalette::Button, schemeButton.background() );
00909 palette.setBrush( state, QPalette::ButtonText, schemeButton.foreground() );
00910 palette.setBrush( state, QPalette::Highlight, schemeSelection.background() );
00911 palette.setBrush( state, QPalette::HighlightedText, schemeSelection.foreground() );
00912 palette.setBrush( state, QPalette::ToolTipBase, schemeTooltip.background() );
00913 palette.setBrush( state, QPalette::ToolTipText, schemeTooltip.foreground() );
00914
00915 palette.setColor( state, QPalette::Light, schemeWindow.shade( KColorScheme::LightShade ) );
00916 palette.setColor( state, QPalette::Midlight, schemeWindow.shade( KColorScheme::MidlightShade ) );
00917 palette.setColor( state, QPalette::Mid, schemeWindow.shade( KColorScheme::MidShade ) );
00918 palette.setColor( state, QPalette::Dark, schemeWindow.shade( KColorScheme::DarkShade ) );
00919 palette.setColor( state, QPalette::Shadow, schemeWindow.shade( KColorScheme::ShadowShade ) );
00920
00921 palette.setBrush( state, QPalette::AlternateBase, schemeView.background( KColorScheme::AlternateBackground) );
00922 palette.setBrush( state, QPalette::Link, schemeView.foreground( KColorScheme::LinkText ) );
00923 palette.setBrush( state, QPalette::LinkVisited, schemeView.foreground( KColorScheme::VisitedText ) );
00924 }
00925
00926 return palette;
00927 }
00928
00929 void KGlobalSettings::Private::kdisplaySetPalette()
00930 {
00931
00932 KConfigGroup cg( KGlobal::config(), "General" );
00933 if (cg.readEntry("nopaletteChange", false))
00934 return;
00935
00936 if (qobject_cast<KApplication *>(qApp) && qApp->type() == QApplication::GuiClient) {
00937 QApplication::setPalette( q->createApplicationPalette() );
00938 }
00939 emit q->kdisplayPaletteChanged();
00940 emit q->appearanceChanged();
00941 }
00942
00943
00944 void KGlobalSettings::Private::kdisplaySetFont()
00945 {
00946 if (qobject_cast<KApplication *>(qApp) && qApp->type() == QApplication::GuiClient) {
00947 KGlobalSettingsData* data = KGlobalSettingsData::self();
00948
00949 QApplication::setFont( data->font(KGlobalSettingsData::GeneralFont) );
00950 const QFont menuFont = data->font( KGlobalSettingsData::MenuFont );
00951 QApplication::setFont( menuFont, "QMenuBar" );
00952 QApplication::setFont( menuFont, "QMenu" );
00953 QApplication::setFont( menuFont, "KPopupTitle" );
00954 QApplication::setFont( data->font(KGlobalSettingsData::ToolbarFont), "QToolBar" );
00955
00956 #if 0
00957
00958 Q3StyleSheet* sheet = Q3StyleSheet::defaultSheet();
00959 const QFont fixedFont = data->font( KGlobalSettingsData::FixedFont );
00960 sheet->item( QLatin1String("pre"))->setFontFamily(fixedFont.family() );
00961 sheet->item( QLatin1String("code"))->setFontFamily(fixedFont.family() );
00962 sheet->item( QLatin1String("tt"))->setFontFamily(fixedFont.family() );
00963 #endif
00964 }
00965 emit q->kdisplayFontChanged();
00966 emit q->appearanceChanged();
00967 }
00968
00969
00970 void KGlobalSettings::Private::kdisplaySetStyle()
00971 {
00972 if (qobject_cast<KApplication *>(qApp) && qApp->type() == QApplication::GuiClient) {
00973 applyGUIStyle();
00974
00975
00976 kdisplaySetPalette();
00977 }
00978 }
00979
00980
00981 void KGlobalSettings::Private::rereadOtherSettings()
00982 {
00983 KConfigGroup g( KGlobal::config(), "KDE-Global GUI Settings" );
00984
00985
00986
00987
00988 if (g.hasKey("GraphicEffectsLevel")) {
00989 _graphicEffects = ((GraphicEffects) g.readEntry("GraphicEffectsLevel", QVariant((int) NoEffects)).toInt());
00990
00991 return;
00992 }
00993
00994 _graphicEffects = KGlobalSettings::graphicEffectsLevelDefault();
00995 }
00996
00997
00998 void KGlobalSettings::Private::applyCursorTheme()
00999 {
01000 #if defined(Q_WS_X11) && defined(HAVE_XCURSOR)
01001 KConfig config("kcminputrc");
01002 KConfigGroup g(&config, "Mouse");
01003
01004 QString theme = g.readEntry("cursorTheme", QString());
01005 int size = g.readEntry("cursorSize", -1);
01006
01007
01008 if (size == -1)
01009 {
01010 QApplication *app = static_cast<QApplication*>(QApplication::instance());
01011 size = app->desktop()->screen(0)->logicalDpiY() * 16 / 72;
01012 }
01013
01014
01015
01016
01017
01018 XcursorSetTheme(QX11Info::display(), theme.isNull() ?
01019 "default" : QFile::encodeName(theme));
01020 XcursorSetDefaultSize(QX11Info::display(), size);
01021
01022 emit q->cursorChanged();
01023 #endif
01024 }
01025
01026
01027 void KGlobalSettings::Private::propagateSettings(SettingsCategory arg)
01028 {
01029 KConfigGroup cg( KGlobal::config(), "KDE" );
01030
01031 int num = cg.readEntry("CursorBlinkRate", QApplication::cursorFlashTime());
01032 if ((num != 0) && (num < 200))
01033 num = 200;
01034 if (num > 2000)
01035 num = 2000;
01036 QApplication::setCursorFlashTime(num);
01037 num = cg.readEntry("DoubleClickInterval", QApplication::doubleClickInterval());
01038 QApplication::setDoubleClickInterval(num);
01039 num = cg.readEntry("StartDragTime", QApplication::startDragTime());
01040 QApplication::setStartDragTime(num);
01041 num = cg.readEntry("StartDragDist", QApplication::startDragDistance());
01042 QApplication::setStartDragDistance(num);
01043 num = cg.readEntry("WheelScrollLines", QApplication::wheelScrollLines());
01044 QApplication::setWheelScrollLines(num);
01045
01046 emit q->settingsChanged(arg);
01047 }
01048
01049 #include "kglobalsettings.moc"