19 #include "kglobalsettings.h"
23 #include <tqfontdatabase.h>
27 #include <ksimpleconfig.h>
28 #include <kapplication.h>
34 #include "qt_windows.h"
35 #include <win32_utils.h>
36 static QRgb qt_colorref2qrgb(COLORREF col)
38 return tqRgb(GetRValue(col),GetGValue(col),GetBValue(col));
44 #include <kshortcut.h>
45 #include <kstandarddirs.h>
46 #include <kcharsets.h>
49 #include <tqfontinfo.h>
51 #include <kprotocolinfo.h>
53 #include <tqtextcodec.h>
54 #include <tqtextstream.h>
61 TQString* KGlobalSettings::s_desktopPath = 0;
62 TQString* KGlobalSettings::s_autostartPath = 0;
63 TQString* KGlobalSettings::s_trashPath = 0;
64 TQString* KGlobalSettings::s_documentPath = 0;
65 TQFont *KGlobalSettings::_generalFont = 0;
66 TQFont *KGlobalSettings::_fixedFont = 0;
67 TQFont *KGlobalSettings::_toolBarFont = 0;
68 TQFont *KGlobalSettings::_menuFont = 0;
69 TQFont *KGlobalSettings::_windowTitleFont = 0;
70 TQFont *KGlobalSettings::_taskbarFont = 0;
71 TQFont *KGlobalSettings::_largeFont = 0;
72 TQColor *KGlobalSettings::_trinity4Blue = 0;
73 TQColor *KGlobalSettings::_inactiveBackground = 0;
74 TQColor *KGlobalSettings::_inactiveForeground = 0;
75 TQColor *KGlobalSettings::_activeBackground = 0;
76 TQColor *KGlobalSettings::_buttonBackground = 0;
77 TQColor *KGlobalSettings::_selectBackground = 0;
78 TQColor *KGlobalSettings::_linkColor = 0;
79 TQColor *KGlobalSettings::_visitedLinkColor = 0;
80 TQColor *KGlobalSettings::alternateColor = 0;
86 void readXdgUserDirs(TQString *desktop, TQString *documents)
88 TQFile f( TQDir::homeDirPath() +
"/.config/user-dirs.dirs" );
90 if (!f.open(IO_ReadOnly))
95 s.setCodec( TQTextCodec::codecForLocale() );
97 TQString line = s.readLine();
98 while (!line.isNull())
100 if (line.startsWith(
"XDG_DESKTOP_DIR="))
101 *desktop = line.remove(
"XDG_DESKTOP_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
102 else if (line.startsWith(
"XDG_DOCUMENTS_DIR="))
103 *documents = line.remove(
"XDG_DOCUMENTS_DIR=").remove(
"\"").replace(
"$HOME", TQDir::homeDirPath());
112 return g.
readNumEntry(
"StartDragDist", TQApplication::startDragDistance());
118 return g.
readBoolEntry(
"SingleClick", KDE_DEFAULT_SINGLECLICK);
124 return g.
readBoolEntry(
"IconUseRoundedRect", KDE_DEFAULT_ICONTEXTROUNDED);
133 tearoff = g.
readNumEntry(
"InsertTearOffHandle", KDE_DEFAULT_INSERTTEAROFFHANDLES);
140 return g.
readBoolEntry(
"ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
146 return g.
readBoolEntry(
"VisualActivate", KDE_DEFAULT_VISUAL_ACTIVATE);
154 "VisualActivateSpeed",
155 KDE_DEFAULT_VISUAL_ACTIVATE_SPEED
164 return g.
readNumEntry(
"AutoSelectDelay", KDE_DEFAULT_AUTOSELECTDELAY);
190 return cut.keyCodeQt();
203 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION));
205 if (!_inactiveBackground)
206 _inactiveBackground =
new TQColor(157, 170, 186);
208 return g.
readColorEntry(
"inactiveBackground", _inactiveBackground );
215 return qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT));
217 if (!_inactiveForeground)
218 _inactiveForeground =
new TQColor(221,221,221);
220 return g.
readColorEntry(
"inactiveForeground", _inactiveForeground );
227 return qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION));
230 if (!_activeBackground)
231 _activeBackground =
new TQColor(65,142,220);
240 return qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT));
255 if (!_buttonBackground)
256 _buttonBackground =
new TQColor(221,223,228);
300 if (!_selectBackground)
301 _selectBackground =
new TQColor(103,141,178);
316 if (base == Qt::white)
317 return TQColor(238,246,255);
321 base.hsv( &h, &s, &v );
323 return base.dark(106);
324 else if (base != Qt::black)
325 return base.light(110);
327 return TQColor(32,32,32);
334 return g.
readBoolEntry(
"shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
341 _linkColor =
new TQColor(0,0,238);
348 if (!_visitedLinkColor)
349 _visitedLinkColor =
new TQColor(82,24,139);
357 return *_generalFont;
360 _generalFont =
new TQFont(
"Sans Serif", 10);
361 _generalFont->setPointSize(10);
362 _generalFont->setStyleHint(TQFont::SansSerif);
367 return *_generalFont;
376 _fixedFont =
new TQFont(
"Monospace", 10);
377 _fixedFont->setPointSize(10);
378 _fixedFont->setStyleHint(TQFont::TypeWriter);
389 return *_toolBarFont;
392 _toolBarFont =
new TQFont(
"Sans Serif", 10);
393 _toolBarFont->setPointSize(10);
394 _toolBarFont->setStyleHint(TQFont::SansSerif);
397 *_toolBarFont = g.
readFontEntry(
"toolBarFont", _toolBarFont);
399 return *_toolBarFont;
408 _menuFont =
new TQFont(
"Sans Serif", 10);
409 _menuFont->setPointSize(10);
410 _menuFont->setStyleHint(TQFont::SansSerif);
421 return *_windowTitleFont;
424 _windowTitleFont =
new TQFont(
"Sans Serif", 9, TQFont::Bold);
425 _windowTitleFont->setPointSize(10);
426 _windowTitleFont->setStyleHint(TQFont::SansSerif);
429 *_windowTitleFont = g.
readFontEntry(
"activeFont", _windowTitleFont);
431 return *_windowTitleFont;
437 return *_taskbarFont;
440 _taskbarFont =
new TQFont(
"Sans Serif", 10);
441 _taskbarFont->setPointSize(10);
442 _taskbarFont->setStyleHint(TQFont::SansSerif);
445 *_taskbarFont = g.
readFontEntry(
"taskbarFont", _taskbarFont);
447 return *_taskbarFont;
454 TQStringList fam = db.families();
457 if (fam.remove(
"Arial"))
458 fam.prepend(
"Arial");
459 if (fam.remove(
"Verdana"))
460 fam.prepend(
"Verdana");
461 if (fam.remove(
"Tahoma"))
462 fam.prepend(
"Tahoma");
463 if (fam.remove(
"Lucida Sans"))
464 fam.prepend(
"Lucida Sans");
465 if (fam.remove(
"Lucidux Sans"))
466 fam.prepend(
"Lucidux Sans");
467 if (fam.remove(
"Nimbus Sans"))
468 fam.prepend(
"Nimbus Sans");
469 if (fam.remove(
"Gothic I"))
470 fam.prepend(
"Gothic I");
473 fam.prepend(_largeFont->family());
475 for(TQStringList::ConstIterator it = fam.begin();
476 it != fam.end(); ++it)
478 if (db.isSmoothlyScalable(*it) && !db.isFixedPitch(*it))
481 font.setPixelSize(75);
482 TQFontMetrics metrics(font);
483 int h = metrics.height();
484 if ((h < 60) || ( h > 90))
488 for(
unsigned int i = 0; i < text.length(); i++)
490 if (!metrics.inFont(text[i]))
499 font.setPointSize(48);
500 _largeFont =
new TQFont(font);
505 _largeFont->setPointSize(48);
509 void KGlobalSettings::initStatic()
511 if ( s_desktopPath != 0 )
514 s_desktopPath =
new TQString();
515 s_autostartPath =
new TQString();
516 s_trashPath =
new TQString();
517 s_documentPath =
new TQString();
522 readXdgUserDirs(s_desktopPath, s_documentPath);
524 if (s_desktopPath->isEmpty() ==
true) {
525 *s_desktopPath = TQDir::homeDirPath() +
"/Desktop/";
527 *s_desktopPath = TQDir::cleanDirPath( *s_desktopPath );
528 if ( !s_desktopPath->endsWith(
"/") )
529 s_desktopPath->append(
'/');
531 if (s_documentPath->isEmpty() ==
true) {
533 *s_documentPath = getWin32ShellFoldersPath(
"Personal");
535 *s_documentPath = TQDir::homeDirPath() +
"/Documents/";
538 *s_documentPath = TQDir::cleanDirPath( *s_documentPath );
539 if ( !s_documentPath->endsWith(
"/"))
540 s_documentPath->append(
'/');
543 *s_trashPath = *s_desktopPath + i18n(
"Trash") +
"/";
544 *s_trashPath = g.readPathEntry(
"Trash" , *s_trashPath);
545 *s_trashPath = TQDir::cleanDirPath( *s_trashPath );
546 if ( !s_trashPath->endsWith(
"/") )
547 s_trashPath->append(
'/');
549 if ( !g.hasKey(
"Trash" ) )
551 g.writePathEntry(
"Trash", *s_trashPath,
true,
true );
557 *s_autostartPath = g.readPathEntry(
"Autostart" , *s_autostartPath);
558 *s_autostartPath = TQDir::cleanDirPath( *s_autostartPath );
559 if ( !s_autostartPath->endsWith(
"/") )
560 s_autostartPath->append(
'/');
564 kapp->addKipcEventMask(KIPC::SettingsChanged);
567 void KGlobalSettings::initColors()
569 if (!_trinity4Blue) {
570 if (TQPixmap::defaultDepth() > 8)
571 _trinity4Blue =
new TQColor(103,141,178);
573 _trinity4Blue =
new TQColor(0, 0, 192);
576 alternateColor =
new TQColor(237, 244, 249);
579 void KGlobalSettings::rereadFontSettings()
589 delete _windowTitleFont;
590 _windowTitleFont = 0L;
595 void KGlobalSettings::rereadPathSettings()
597 kdDebug() <<
"KGlobalSettings::rereadPathSettings" <<
endl;
598 delete s_autostartPath;
599 s_autostartPath = 0L;
602 delete s_desktopPath;
604 delete s_documentPath;
610 if ( ! s_mouseSettings )
617 TQString setting = g.
readEntry(
"MouseButtonMapping");
618 if (setting ==
"RightHanded")
619 s.handed = KMouseSettings::RightHanded;
620 else if (setting ==
"LeftHanded")
621 s.handed = KMouseSettings::LeftHanded;
628 s.handed = KMouseSettings::RightHanded;
629 unsigned char map[20];
630 int num_buttons = XGetPointerMapping(kapp->getDisplay(), map, 20);
631 if( num_buttons == 2 )
633 if ( (
int)map[0] == 1 && (int)map[1] == 2 )
634 s.handed = KMouseSettings::RightHanded;
635 else if ( (
int)map[0] == 2 && (int)map[1] == 1 )
636 s.handed = KMouseSettings::LeftHanded;
638 else if( num_buttons >= 3 )
640 if ( (
int)map[0] == 1 && (int)map[2] == 3 )
641 s.handed = KMouseSettings::RightHanded;
642 else if ( (
int)map[0] == 3 && (int)map[2] == 1 )
643 s.handed = KMouseSettings::LeftHanded;
653 s_mouseSettings->handed = (GetSystemMetrics(SM_SWAPBUTTON) ? KMouseSettings::LeftHanded : KMouseSettings::RightHanded);
655 return *s_mouseSettings;
658 void KGlobalSettings::rereadMouseSettings()
661 delete s_mouseSettings;
662 s_mouseSettings = 0L;
669 return GetSystemMetrics(SM_CMONITORS) > 1;
671 TQCString multiHead = getenv(
"KDE_MULTIHEAD");
672 if (!multiHead.isEmpty()) {
673 return (multiHead.lower() ==
"true");
682 return g.
readBoolEntry(
"WheelMouseZooms", KDE_DEFAULT_WHEEL_ZOOM );
687 TQDesktopWidget *dw = TQApplication::desktop();
689 if (dw->isVirtualDesktop()) {
692 if (group.
readBoolEntry(
"XineramaEnabled",
true) && scr != -2) {
694 scr = dw->screenNumber(TQCursor::pos());
695 return dw->screenGeometry(scr);
697 return dw->geometry();
700 return dw->geometry();
706 TQDesktopWidget *dw = TQApplication::desktop();
708 if (dw->isVirtualDesktop()) {
712 return dw->screenGeometry(dw->screenNumber(point));
714 return dw->geometry();
717 return dw->geometry();
723 TQDesktopWidget *dw = TQApplication::desktop();
725 if (dw->isVirtualDesktop()) {
730 return dw->screenGeometry(dw->screenNumber(w));
731 else return dw->screenGeometry(-1);
733 return dw->geometry();
736 return dw->geometry();
744 KDE_DEFAULT_ICON_ON_PUSHBUTTON);
751 bool defaultSetting = KProtocolInfo::showFilePreview( protocol );
759 KDE_DEFAULT_KONQ_ACTIVATION_EFFECT);
766 KDE_DEFAULT_OPAQUE_RESIZE);
773 KDE_DEFAULT_BUTTON_LAYOUT);