34 #include <QtGui/QColor>
35 #include <QtGui/QCursor>
36 #include <QtGui/QDesktopWidget>
37 #include <QtCore/QDir>
38 #include <QtGui/QFont>
39 #include <QtGui/QFontDatabase>
40 #include <QtGui/QFontInfo>
41 #include <QtGui/QKeySequence>
42 #include <QtGui/QPixmap>
43 #include <QtGui/QPixmapCache>
44 #include <QApplication>
45 #include <QtDBus/QtDBus>
46 #include <QtGui/QStyleFactory>
47 #include <QDesktopServices>
48 #include "qplatformdefs.h"
51 #include <QtGui/QToolTip>
52 #include <QtGui/QWhatsThis>
60 return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));
66 #include <X11/Xcursor/Xcursor.h>
84 class KGlobalSettingsData
101 KGlobalSettingsData();
102 ~KGlobalSettingsData();
105 static KGlobalSettingsData*
self();
108 QFont font( FontTypes fontType );
113 void dropFontSettingsCache();
114 void dropMouseSettingsCache();
117 QFont* mFonts[FontTypesCount];
122 KGlobalSettingsData::KGlobalSettingsData()
126 for(
int i=0; i<FontTypesCount; ++i )
130 KGlobalSettingsData::~KGlobalSettingsData()
132 for(
int i=0; i<FontTypesCount; ++i )
136 delete mMouseSettings;
141 inline KGlobalSettingsData* KGlobalSettingsData::self()
143 return globalSettingsDataSingleton;
147 class KGlobalSettings::Private
151 : q(q), activated(false), paletteCreated(false)
153 kdeFullSession = !qgetenv(
"KDE_FULL_SESSION").isEmpty();
158 void _k_slotNotifyChange(
int,
int);
160 void propagateQtSettings();
161 void kdisplaySetPalette();
162 void kdisplaySetStyle();
163 void kdisplaySetFont();
164 void applyGUIStyle();
177 void applyCursorTheme();
179 static void reloadStyleSettings();
185 QPalette applicationPalette;
194 KGlobalSettings::KGlobalSettings()
195 :
QObject(0), d(new Private(this))
215 QDBusConnection::sessionBus().connect(
QString(),
"/KGlobalSettings",
"org.kde.KGlobalSettings",
216 "notifyChange",
this, SLOT(_k_slotNotifyChange(
int,
int)) );
220 d->kdisplaySetStyle();
221 d->kdisplaySetFont();
222 d->propagateQtSettings();
230 return g.
readEntry(
"StartDragDist", QApplication::startDragDistance());
250 effectsenabled = g.
readEntry(
"EffectsEnabled",
false);
271 completion = g.
readEntry(
"completionMode", -1);
286 #ifndef KDE_NO_DEPRECATED
296 if (s == QLatin1String(
"none")) {
297 return QKeySequence()[0];
302 if (shortCuts.count() < 1) {
303 return QKeySequence()[0];
308 if ( s.startsWith( QLatin1String(
"default(") ) ) {
309 s = s.mid( 8, s.length() - 9 );
312 return QKeySequence::fromString(s)[0];
370 return 0.1 * g.
readEntry(
"contrast", 7 );
389 const char* ConfigGroupKey;
390 const char* ConfigKey;
391 const char* FontName;
394 QFont::StyleHint StyleHint;
408 {
GeneralId,
"fixed",
"Monaco", 10, -1, QFont::TypeWriter },
411 #elif defined(Q_WS_MAEMO_5) || defined(MEEGO_EDITION_HARMATTAN)
413 {
GeneralId,
"fixed",
"Monospace", 16, -1, QFont::TypeWriter },
418 {
GeneralId,
"fixed",
"Monospace", 9, -1, QFont::TypeWriter },
422 {
"WM",
"activeFont",
DefaultFont, 8, -1, QFont::SansSerif },
427 QFont KGlobalSettingsData::font( FontTypes fontType )
429 QFont* cachedFont = mFonts[fontType];
433 const KFontData& fontData = DefaultFontData[fontType];
434 cachedFont =
new QFont( fontData.FontName, fontData.Size, fontData.Weight );
435 cachedFont->setStyleHint( fontData.StyleHint );
437 const KConfigGroup configGroup( KGlobal::config(), fontData.ConfigGroupKey );
438 *cachedFont = configGroup.readEntry( fontData.ConfigKey, *cachedFont );
440 mFonts[fontType] = cachedFont;
448 return KGlobalSettingsData::self()->font( KGlobalSettingsData::GeneralFont );
452 return KGlobalSettingsData::self()->font( KGlobalSettingsData::FixedFont );
456 return KGlobalSettingsData::self()->font( KGlobalSettingsData::ToolbarFont );
460 return KGlobalSettingsData::self()->font( KGlobalSettingsData::MenuFont );
464 return KGlobalSettingsData::self()->font( KGlobalSettingsData::WindowTitleFont );
468 return KGlobalSettingsData::self()->font( KGlobalSettingsData::TaskbarFont );
472 return KGlobalSettingsData::self()->font( KGlobalSettingsData::SmallestReadableFont );
476 QFont KGlobalSettingsData::largeFont(
const QString& text )
483 static const char*
const PreferredFontNames[] =
494 static const unsigned int PreferredFontNamesCount =
sizeof(PreferredFontNames)/
sizeof(
const char*);
495 for(
unsigned int i=0; i<PreferredFontNamesCount; ++i )
497 const QString fontName (PreferredFontNames[i]);
498 if (fam.removeAll(fontName)>0)
499 fam.prepend(fontName);
503 fam.prepend(mLargeFont->family());
507 for(QStringList::ConstIterator it = fam.constBegin();
508 it != fam.constEnd(); ++it)
510 if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
513 font.setPixelSize(75);
514 QFontMetrics metrics(font);
515 int h = metrics.height();
516 if ((h < 60) || ( h > 90))
520 for(
int i = 0; i < text.length(); i++)
522 if (!metrics.inFont(text[i]))
531 font.setPointSize(48);
532 mLargeFont =
new QFont(font);
536 mLargeFont =
new QFont( font(GeneralFont) );
537 mLargeFont->setPointSize(48);
542 return KGlobalSettingsData::self()->largeFont( text );
545 void KGlobalSettingsData::dropFontSettingsCache()
547 for(
int i=0; i<FontTypesCount; ++i )
565 QString setting = g.readEntry(
"MouseButtonMapping");
566 if (setting ==
"RightHanded")
568 else if (setting ==
"LeftHanded")
577 unsigned char map[20];
578 int num_buttons = XGetPointerMapping(QX11Info::display(), map, 20);
579 if( num_buttons == 2 )
581 if ( (
int)map[0] == 1 && (
int)map[1] == 2 )
583 else if ( (
int)map[0] == 2 && (
int)map[1] == 1 )
586 else if( num_buttons >= 3 )
588 if ( (
int)map[0] == 1 && (
int)map[2] == 3 )
590 else if ( (
int)map[0] == 3 && (
int)map[2] == 1 )
602 mMouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ?
610 return *mMouseSettings;
615 return KGlobalSettingsData::self()->mouseSettings();
618 void KGlobalSettingsData::dropMouseSettingsCache()
621 delete mMouseSettings;
628 QString path = QDesktopServices::storageLocation( QDesktopServices::DesktopLocation );
629 return path.isEmpty() ? QDir::homePath() : path;
637 s_autostartPath = KGlobal::dirs()->localkdedir() +
"Autostart/";
638 s_autostartPath = g.
readPathEntry(
"Autostart" , s_autostartPath );
639 s_autostartPath = QDir::cleanPath( s_autostartPath );
640 if ( !s_autostartPath.endsWith(
'/' ) ) {
641 s_autostartPath.append( QLatin1Char(
'/' ) );
643 return s_autostartPath;
648 QString path = QDesktopServices::storageLocation( QDesktopServices::DocumentsLocation );
649 return path.isEmpty() ? QDir::homePath() : path;
655 QString defaultDownloadPath = QDir::homePath() +
"/Downloads";
658 const QString xdgUserDirs = KGlobal::dirs()->localxdgconfdir() + QLatin1String(
"user-dirs.dirs" );
659 if( QFile::exists( xdgUserDirs ) ) {
662 downloadPath = g.
readPathEntry(
"XDG_DOWNLOAD_DIR", downloadPath ).remove(
'"' );
663 if ( downloadPath.isEmpty() ) {
664 downloadPath = defaultDownloadPath;
668 downloadPath = QDir::cleanPath( downloadPath );
669 QDir().mkpath(downloadPath);
670 if ( !downloadPath.endsWith(
'/' ) ) {
671 downloadPath.append( QLatin1Char(
'/' ) );
678 QString path = QDesktopServices::storageLocation( QDesktopServices::MoviesLocation );
679 return path.isEmpty() ? QDir::homePath() : path;
684 QString path = QDesktopServices::storageLocation( QDesktopServices::PicturesLocation );
685 return path.isEmpty() ? QDir::homePath() :path;
690 QString path = QDesktopServices::storageLocation( QDesktopServices::MusicLocation );
691 return path.isEmpty() ? QDir::homePath() : path;
697 return GetSystemMetrics(SM_CMONITORS) > 1;
699 QByteArray multiHead = qgetenv(
"KDE_MULTIHEAD");
700 if (!multiHead.isEmpty()) {
701 return (multiHead.toLower() ==
"true");
715 QDesktopWidget *dw = QApplication::desktop();
717 if (dw->isVirtualDesktop()) {
719 int scr = group.
readEntry(
"Unmanaged", -3);
720 if (group.
readEntry(
"XineramaEnabled",
true) && scr != -2) {
722 scr = dw->screenNumber(QCursor::pos());
723 return dw->screenGeometry(scr);
725 return dw->geometry();
728 return dw->geometry();
734 QDesktopWidget *dw = QApplication::desktop();
736 if (dw->isVirtualDesktop()) {
738 if (group.
readEntry(
"XineramaEnabled",
true) &&
739 group.
readEntry(
"XineramaPlacementEnabled",
true)) {
740 return dw->screenGeometry(dw->screenNumber(point));
742 return dw->geometry();
745 return dw->geometry();
751 QDesktopWidget *dw = QApplication::desktop();
753 if (dw->isVirtualDesktop()) {
755 if (group.
readEntry(
"XineramaEnabled",
true) &&
756 group.
readEntry(
"XineramaPlacementEnabled",
true)) {
758 return dw->screenGeometry(dw->screenNumber(w));
759 else return dw->screenGeometry(-1);
761 return dw->geometry();
764 return dw->geometry();
771 return g.
readEntry(
"ShowIconsOnPushButtons",
787 static bool _graphicEffectsInitialized =
false;
789 if (!_graphicEffectsInitialized) {
790 _graphicEffectsInitialized =
true;
791 Private::reloadStyleSettings();
810 return g.
readEntry(protocol, defaultSetting );
827 QDBusMessage
message = QDBusMessage::createSignal(
"/KGlobalSettings",
"org.kde.KGlobalSettings",
"notifyChange" );
829 args.append(static_cast<int>(changeType));
831 message.setArguments(args);
832 QDBusConnection::sessionBus().send(message);
834 if (qApp && qApp->type() != QApplication::Tty) {
836 extern void qt_x11_apply_settings_in_all_apps();
837 qt_x11_apply_settings_in_all_apps();
842 void KGlobalSettings::Private::_k_slotNotifyChange(
int changeType,
int arg)
847 KGlobal::config()->reparseConfiguration();
852 case ToolbarStyleChanged:
853 KGlobal::config()->reparseConfiguration();
854 emit q->toolbarAppearanceChanged(arg);
859 KGlobal::config()->reparseConfiguration();
860 paletteCreated =
false;
861 kdisplaySetPalette();
866 KGlobal::config()->reparseConfiguration();
867 KGlobalSettingsData::self()->dropFontSettingsCache();
873 case SettingsChanged: {
874 KGlobal::config()->reparseConfiguration();
875 SettingsCategory category =
static_cast<SettingsCategory
>(arg);
876 if (category == SETTINGS_QT) {
878 propagateQtSettings();
883 reloadStyleSettings();
886 KGlobalSettingsData::self()->dropMouseSettingsCache();
888 case SETTINGS_LOCALE:
889 KGlobal::locale()->reparseConfiguration();
894 emit q->settingsChanged(category);
900 KGlobal::config()->reparseConfiguration();
901 emit q->iconChanged(arg);
911 emit q->blockShortcuts(arg);
914 case NaturalSortingChanged:
915 emit q->naturalSortingChanged();
919 kWarning(240) <<
"Unknown type of change in KGlobalSettings::slotNotifyChange: " << changeType;
926 void KGlobalSettings::Private::applyGUIStyle()
930 if (!kde_overrideStyle.isEmpty()) {
931 const QLatin1String currentStyleName(qApp->style()->metaObject()->className());
932 if (0 != kde_overrideStyle.compare(currentStyleName, Qt::CaseInsensitive) &&
933 0 != (
QString(kde_overrideStyle + QLatin1String(
"Style"))).compare(currentStyleName, Qt::CaseInsensitive)) {
934 qApp->setStyle(kde_overrideStyle);
937 emit q->kdisplayStyleChanged();
940 const QLatin1String currentStyleName(qApp->style()->metaObject()->className());
942 if (kde_overrideStyle.isEmpty()) {
944 const KConfigGroup pConfig(KGlobal::config(),
"General");
947 if (styleStr.isEmpty() ||
950 0 == (
QString(styleStr + QLatin1String(
"Style"))).compare(currentStyleName, Qt::CaseInsensitive) ||
951 0 == styleStr.compare(currentStyleName, Qt::CaseInsensitive)) {
956 if (sp && currentStyleName == sp->metaObject()->className()) {
962 if ( !sp && styleStr != defaultStyle)
967 }
else if (0 != kde_overrideStyle.compare(currentStyleName, Qt::CaseInsensitive) &&
968 0 != (
QString(kde_overrideStyle + QLatin1String(
"Style"))).compare(currentStyleName, Qt::CaseInsensitive)) {
969 qApp->setStyle(kde_overrideStyle);
971 emit q->kdisplayStyleChanged();
977 return self()->d->createApplicationPalette(config);
982 return self()->d->createNewApplicationPalette(config);
985 QPalette KGlobalSettings::Private::createApplicationPalette(
const KSharedConfigPtr &config)
989 if (config == KGlobal::config() && paletteCreated) {
990 return applicationPalette;
992 return createNewApplicationPalette(config);
995 QPalette KGlobalSettings::Private::createNewApplicationPalette(
const KSharedConfigPtr &config)
999 QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
1000 QPalette::Disabled };
1005 for (
int i = 0; i < 3 ; i++ ) {
1006 QPalette::ColorGroup state = states[i];
1012 palette.setBrush( state, QPalette::WindowText, schemeWindow.foreground() );
1013 palette.setBrush( state, QPalette::Window, schemeWindow.background() );
1014 palette.setBrush( state, QPalette::Base, schemeView.background() );
1015 palette.setBrush( state, QPalette::Text, schemeView.foreground() );
1016 palette.setBrush( state, QPalette::Button, schemeButton.background() );
1017 palette.setBrush( state, QPalette::ButtonText, schemeButton.foreground() );
1018 palette.setBrush( state, QPalette::Highlight, schemeSelection.background() );
1019 palette.setBrush( state, QPalette::HighlightedText, schemeSelection.foreground() );
1020 palette.setBrush( state, QPalette::ToolTipBase, schemeTooltip.background() );
1021 palette.setBrush( state, QPalette::ToolTipText, schemeTooltip.foreground() );
1034 if (config == KGlobal::config()) {
1035 paletteCreated =
true;
1036 applicationPalette = palette;
1042 void KGlobalSettings::Private::kdisplaySetPalette()
1044 #if !defined(Q_WS_MAEMO_5) && !defined(Q_OS_WINCE) && !defined(MEEGO_EDITION_HARMATTAN)
1045 if (!kdeFullSession) {
1049 if (qApp->type() == QApplication::GuiClient) {
1050 QApplication::setPalette( q->createApplicationPalette() );
1052 emit q->kdisplayPaletteChanged();
1053 emit q->appearanceChanged();
1058 void KGlobalSettings::Private::kdisplaySetFont()
1060 #if !defined(Q_WS_MAEMO_5) && !defined(Q_OS_WINCE) && !defined(MEEGO_EDITION_HARMATTAN)
1061 if (!kdeFullSession) {
1065 if (qApp->type() == QApplication::GuiClient) {
1066 KGlobalSettingsData* data = KGlobalSettingsData::self();
1068 QApplication::setFont( data->font(KGlobalSettingsData::GeneralFont) );
1069 const QFont menuFont = data->font( KGlobalSettingsData::MenuFont );
1070 QApplication::setFont( menuFont,
"QMenuBar" );
1071 QApplication::setFont( menuFont,
"QMenu" );
1072 QApplication::setFont( menuFont,
"KPopupTitle" );
1073 QApplication::setFont( data->font(KGlobalSettingsData::ToolbarFont),
"QToolBar" );
1075 emit q->kdisplayFontChanged();
1076 emit q->appearanceChanged();
1081 void KGlobalSettings::Private::kdisplaySetStyle()
1083 if (qApp->type() == QApplication::GuiClient) {
1087 kdisplaySetPalette();
1092 void KGlobalSettings::Private::reloadStyleSettings()
1094 KConfigGroup g( KGlobal::config(),
"KDE-Global GUI Settings" );
1099 if (g.hasKey(
"GraphicEffectsLevel")) {
1109 void KGlobalSettings::Private::applyCursorTheme()
1111 #if defined(Q_WS_X11) && defined(HAVE_XCURSOR)
1116 int size = g.readEntry(
"cursorSize", -1);
1122 size = app->desktop()->screen(0)->logicalDpiY() * 16 / 72;
1129 XcursorSetTheme(QX11Info::display(), theme.isNull() ?
1130 "default" : QFile::encodeName(theme));
1131 XcursorSetDefaultSize(QX11Info::display(), size);
1133 emit q->cursorChanged();
1138 void KGlobalSettings::Private::propagateQtSettings()
1142 int num = cg.readEntry(
"CursorBlinkRate", QApplication::cursorFlashTime());
1143 if ((num != 0) && (num < 200))
1147 QApplication::setCursorFlashTime(num);
1151 num = cg.readEntry(
"DoubleClickInterval", QApplication::doubleClickInterval());
1152 QApplication::setDoubleClickInterval(num);
1153 num = cg.readEntry(
"StartDragTime", QApplication::startDragTime());
1154 QApplication::setStartDragTime(num);
1155 num = cg.readEntry(
"StartDragDist", QApplication::startDragDistance());
1156 QApplication::setStartDragDistance(num);
1157 num = cg.readEntry(
"WheelScrollLines", QApplication::wheelScrollLines());
1158 QApplication::setWheelScrollLines(num);
1159 bool showIcons = cg.readEntry(
"ShowIconsInMenuItems", !QApplication::testAttribute(Qt::AA_DontShowIconsInMenus));
1160 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus, !showIcons);
1163 emit q->settingsChanged(SETTINGS_QT);
1166 #include "kglobalsettings.moc"