fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kdeui / kernel / kglobalsettings.h
blob5a41d2194452fed7e49249aab4e0e11ed66d7748
1 /* This file is part of the KDE libraries
2 Copyright (C) 2000,2006 David Faure <faure@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #ifndef _KGLOBALSETTINGS_H
19 #define _KGLOBALSETTINGS_H
21 #include <kdeui_export.h>
22 #include <ksharedconfig.h>
23 #include <QtCore/QObject>
24 #include <QtCore/QString>
25 #include <QtGui/QPalette>
27 #define KDE_DEFAULT_SINGLECLICK true
28 #define KDE_DEFAULT_SMOOTHSCROLL true
29 #define KDE_DEFAULT_INSERTTEAROFFHANDLES 0
30 #define KDE_DEFAULT_AUTOSELECTDELAY -1
31 #define KDE_DEFAULT_CHANGECURSOR true
32 #define KDE_DEFAULT_LARGE_CURSOR false
33 #define KDE_DEFAULT_WHEEL_ZOOM false
34 #define KDE_DEFAULT_ICON_ON_PUSHBUTTON true
35 #define KDE_DEFAULT_OPAQUE_RESIZE true
36 #define KDE_DEFAULT_BUTTON_LAYOUT 0
37 #define KDE_DEFAULT_SHADE_SORT_COLUMN true
38 #define KDE_DEFAULT_ALLOW_DEFAULT_BACKGROUND_IMAGES true
40 class KUrl;
42 class QColor;
43 class QFont;
44 class QPoint;
45 class QRect;
46 class QWidget;
48 /**
49 * Access the KDE global configuration.
51 * @author David Faure \<faure@kde.org\>
53 class KDEUI_EXPORT KGlobalSettings : public QObject
55 Q_OBJECT
57 public:
58 ~KGlobalSettings();
60 /**
61 * Returns a threshold in pixels for drag & drop operations.
62 * As long as the mouse movement has not exceeded this number
63 * of pixels in either X or Y direction no drag operation may
64 * be started. This prevents spurious drags when the user intended
65 * to click on something but moved the mouse a bit while doing so.
67 * For this to work you must save the position of the mouse (oldPos)
68 * in the QWidget::mousePressEvent().
69 * When the position of the mouse (newPos)
70 * in a QWidget::mouseMoveEvent() exceeds this threshold
71 * you may start a drag
72 * which should originate from oldPos.
74 * Example code:
75 * \code
76 * void KColorCells::mousePressEvent( QMouseEvent *e )
77 * {
78 * mOldPos = e->pos();
79 * }
81 * void KColorCells::mouseMoveEvent( QMouseEvent *e )
82 * {
83 * if( !(e->state() && LeftButton)) return;
85 * int delay = KGlobalSettings::dndEventDelay();
86 * QPoint newPos = e->pos();
87 * if(newPos.x() > mOldPos.x()+delay || newPos.x() < mOldPos.x()-delay ||
88 * newPos.y() > mOldPos.y()+delay || newPos.y() < mOldPos.y()-delay)
89 * {
90 * // Drag color object
91 * int cell = posToCell(mOldPos); // Find color at mOldPos
92 * if ((cell != -1) && colors[cell].isValid())
93 * {
94 * KColorDrag *d = KColorDrag::makeDrag( colors[cell], this);
95 * d->dragCopy();
96 * }
97 * }
98 * }
99 * \endcode
100 * @return the threshold for drag & drop in pixels
103 static int dndEventDelay();
106 * Returns whether KDE runs in single (default) or double click
107 * mode.
108 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html
109 * @return true if single click mode, or false if double click mode.
111 static bool singleClick();
114 * Returns if item views should force smooth scrolling.
115 * @return true if smooth scrolling is enabled for item view, false otherwise.
116 * @since 4.2
118 static bool smoothScroll();
121 * This enum describes the return type for insertTearOffHandle() whether to insert
122 * a handle or not. Applications who independently want to use handles in their popup menus
123 * should test for Application level before calling the appropriate function in KMenu.
125 enum TearOffHandle {
126 Disable = 0, ///< disable tear-off handles
127 ApplicationLevel, ///< enable on application level
128 Enable ///< enable tear-off handles
132 * Returns whether tear-off handles are inserted in KMenus.
133 * @return whether tear-off handles are inserted in KMenus.
135 static TearOffHandle insertTearOffHandle();
138 * Checks whether the cursor changes over icons.
139 * @return the KDE setting for "change cursor over icon"
141 static bool changeCursorOverIcon();
144 * Returns the KDE setting for the auto-select option.
146 * @return the auto-select delay or -1 if auto-select is disabled.
148 static int autoSelectDelay();
151 * Returns the KDE setting for the shortcut key to open
152 * context menus.
154 * @return the key that pops up context menus.
155 * @deprecated Simply reimplement QWidget::contextMenuEvent() instead.
157 static KDE_DEPRECATED int contextMenuKey ();
160 * Returns the KDE setting for context menus.
162 * @return whether context menus should be shown on button press
163 * or button release (click).
165 static bool showContextMenusOnPress ();
168 * This enum describes the completion mode used for by the KCompletion class.
169 * See <a href="http://developer.kde.org/documentation/standards/kde/style/keys/completion.html">
170 * the styleguide</a>.
172 enum Completion {
174 * No completion is used.
176 CompletionNone=1,
178 * Text is automatically filled in whenever possible.
180 CompletionAuto,
182 * Same as automatic except shortest match is used for completion.
184 CompletionMan,
186 * Complete text much in the same way as a typical *nix shell would.
188 CompletionShell,
190 * Lists all possible matches in a popup list-box to choose from.
192 CompletionPopup,
194 * Lists all possible matches in a popup list-box to choose from, and automatically
195 * fill the result whenever possible.
197 CompletionPopupAuto
201 * Returns the preferred completion mode setting.
203 * @return Completion. Default is @p CompletionPopup.
205 static Completion completionMode();
208 * Describes the mouse settings.
210 struct KMouseSettings
212 enum { RightHanded = 0, LeftHanded = 1 };
213 int handed; // left or right
217 * This returns the current mouse settings.
218 * On Windows, settings are retrieved from the system.
219 * @return the current mouse settings
221 static KMouseSettings & mouseSettings();
224 * The path to the desktop directory of the current user.
225 * @return the user's desktop directory
227 static QString desktopPath();
230 * The path to the autostart directory of the current user.
231 * @return the path of the autostart directory
233 static QString autostartPath();
236 * The path where documents are stored of the current user.
237 * @return the path of the document directory
239 static QString documentPath();
242 * The path where music are stored of the current user.
243 * @return the path of the music directory
245 static QString musicPath();
248 * The path where videos are stored of the current user.
249 * @return the path of the video directory
251 static QString videosPath();
254 * The path where download are stored of the current user.
255 * @return the path of the download directory
257 static QString downloadPath();
260 * The path where pictures are stored of the current user.
261 * @return the path of the pictures directory
263 static QString picturesPath();
266 * The default color to use for inactive titles.
267 * @return the inactive title color
269 static QColor inactiveTitleColor();
272 * The default color to use for inactive texts.
273 * @return the inactive text color
275 static QColor inactiveTextColor();
278 * The default color to use for active titles.
279 * @return the active title color
281 static QColor activeTitleColor();
284 * The default color to use for active texts.
285 * @return the active text color
287 static QColor activeTextColor();
290 * Returns the contrast for borders.
291 * @return the contrast (between 0 for minimum and 10 for maximum
292 * contrast)
294 static int contrast();
297 * Returns the contrast for borders as a floating point value.
298 * @param config pointer to the config from which to read the contrast
299 * setting (the default is to use KGlobal::config())
300 * @return the contrast (between 0.0 for minimum and 1.0 for maximum
301 * contrast)
303 static qreal contrastF(const KSharedConfigPtr &config = KSharedConfigPtr());
306 * Returns if the sorted column in a K3ListView shall be drawn with a
307 * shaded background color.
308 * @return true if the sorted column shall be shaded
310 static bool shadeSortColumn();
313 * Returns if default background images are allowed by the color scheme.
314 * A "default" background image is just that, i.e. the user has not
315 * actively selected a background image to use.
316 * @return true if default background images may be used
318 static bool allowDefaultBackgroundImages();
321 * Returns the default general font.
322 * @return the default general font.
324 static QFont generalFont();
327 * Returns the default fixed font.
328 * @return the default fixed font.
330 static QFont fixedFont();
333 * Returns the default toolbar font.
334 * @return the default toolbar font.
336 static QFont toolBarFont();
339 * Returns the default menu font.
340 * @return the default menu font.
342 static QFont menuFont();
345 * Returns the default window title font.
346 * @return the default window title font.
348 static QFont windowTitleFont();
351 * Returns the default taskbar font.
352 * @return the default taskbar font.
354 static QFont taskbarFont();
357 * Returns a font of approx. 48 pt. capable of showing @p text.
358 * @param text the text to test
359 * @return the font that is capable to show the text with 48 pt
361 static QFont largeFont(const QString &text = QString());
364 * Returns the smallest readable font. This can be used in dockers,
365 * rulers and other places where space is at a premium.
367 static QFont smallestReadableFont();
370 * Returns if the user specified multihead. In case the display
371 * has multiple screens, the return value of this function specifies
372 * if the user wants KDE to run on all of them or just on the primary
373 * On Windows, settings are retrieved from the system.
374 * @return true if the user chose multi head
376 static bool isMultiHead();
379 * Typically, QScrollView derived classes can be scrolled fast by
380 * holding down the Ctrl-button during wheel-scrolling.
381 * But QTextEdit and derived classes perform zooming instead of fast
382 * scrolling.
384 * This value determines whether the user wants to zoom or scroll fast
385 * with Ctrl-wheelscroll.
386 * @return true if the user wishes to zoom with the mouse wheel,
387 * false for scrolling
389 static bool wheelMouseZooms();
392 * This function returns the desktop geometry for an application's splash
393 * screen. It takes into account the user's display settings (number of
394 * screens, Xinerama, etc), and the user's preferences (if KDE should be
395 * Xinerama aware).
397 * @return the geometry to use for the desktop. Note that it might not
398 * start at (0,0).
400 static QRect splashScreenDesktopGeometry();
403 * This function returns the desktop geometry for an application that needs
404 * to set the geometry of a widget on the screen manually. It takes into
405 * account the user's display settings (number of screens, Xinerama, etc),
406 * and the user's preferences (if KDE should be Xinerama aware).
408 * Note that this can break in multi-head (not Xinerama) mode because this
409 * point could be on multiple screens. Use with care.
411 * @param point a reference point for the widget, for instance one that the
412 * widget should be adjacent or on top of.
414 * @return the geometry to use for the desktop. Note that it might not
415 * start at (0,0).
417 static QRect desktopGeometry(const QPoint& point);
420 * This function returns the desktop geometry for an application that needs
421 * to set the geometry of a widget on the screen manually. It takes into
422 * account the user's display settings (number of screens, Xinerama, etc),
423 * and the user's preferences (if KDE should be Xinerama aware).
425 * @param w the widget in question. This is used to determine which screen
426 * to use in Xinerama or multi-head mode.
428 * @return the geometry to use for the desktop. Note that it might not
429 * start at (0,0).
431 static QRect desktopGeometry(const QWidget* w);
434 * This function determines if the user wishes to see icons on the
435 * push buttons.
437 * @return Returns true if user wants to show icons.
439 static bool showIconsOnPushButtons();
441 enum GraphicEffect {
442 NoEffects = 0x0000, ///< GUI with no effects at all.
443 GradientEffects = 0x0001, ///< GUI with only gradients enabled.
444 SimpleAnimationEffects = 0x0002, ///< GUI with simple animations enabled.
445 ComplexAnimationEffects = 0x0006 ///< GUI with complex animations enabled.
446 ///< Note that ComplexAnimationsEffects implies SimpleAnimationEffects.
449 Q_DECLARE_FLAGS(GraphicEffects, GraphicEffect)
452 * This function determines the desired level of effects on the GUI.
454 * @since 4.1
456 static GraphicEffects graphicEffectsLevel();
459 * This function determines the default level of effects on the GUI
460 * depending on the system capabilities.
462 * @since 4.1
464 static GraphicEffects graphicEffectsLevelDefault();
467 * This function determines if the user wishes to see previews
468 * for the selected url
470 * @return Returns true if user wants to show previews.
472 static bool showFilePreview(const KUrl &);
475 * Whether the user wishes to use opaque resizing. Primarily
476 * intended for QSplitter::setOpaqueResize()
478 * @return Returns true if user wants to use opaque resizing.
480 static bool opaqueResize();
483 * The layout scheme to use for dialog buttons
485 * @return Returns the number of the scheme to use.
487 static int buttonLayout();
490 * Used to obtain the QPalette that will be used to set the application palette.
492 * This is only useful for configuration modules such as krdb and should not be
493 * used in normal circumstances.
494 * @param config KConfig from which to load the colors (passed as-is to
495 * ::KColorScheme).
497 * @return the QPalette
499 static QPalette createApplicationPalette(const KSharedConfigPtr &config = KSharedConfigPtr());
502 * An identifier for change signals.
503 * \see emitChange
505 enum ChangeType { PaletteChanged = 0, FontChanged, StyleChanged,
506 SettingsChanged, IconChanged, CursorChanged,
507 ToolbarStyleChanged, ClipboardConfigChanged,
508 BlockShortcuts };
511 * Notifies all KDE applications on the current display of a change.
513 * This is typically called by kcontrol modules after changing the corresponding
514 * config file. Do not call this from a normal KDE application.
516 static void emitChange(ChangeType changeType, int arg = 0);
519 * Return the KGlobalSettings singleton.
520 * This is used to connect to its signals, to be notified of changes.
522 static KGlobalSettings* self();
525 * Valid values for the settingsChanged signal
527 enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS,
528 SETTINGS_POPUPMENU, SETTINGS_QT, SETTINGS_SHORTCUTS };
530 Q_SIGNALS:
532 * Emitted when the application has changed its palette due to a KControl request.
534 * Normally, widgets will update their palette automatically, but you
535 * should connect to this to program special behavior.
537 * Note: If you derive from a QWidget-based class, a faster method is to
538 * reimplement QWidget::changeEvent() and catch QEvent::PaletteChange.
539 * This is the preferred way to get informed about palette updates.
541 void kdisplayPaletteChanged();
544 * Emitted when the application has changed its GUI style in response to a KControl request.
546 * Normally, widgets will update their styles automatically (as they would
547 * respond to an explicit setGUIStyle() call), but you should connect to
548 * this to program special behavior.
550 * Note: If you derive from a QWidget-based class, a faster method is to
551 * reimplement QWidget::changeEvent() and catch QEvent::StyleChange.
552 * This is the preferred way to get informed about style updates.
554 void kdisplayStyleChanged();
557 * Emitted when the application has changed its font in response to a KControl request.
559 * Normally widgets will update their fonts automatically, but you should
560 * connect to this to monitor global font changes, especially if you are
561 * using explicit fonts.
563 * Note: If you derive from a QWidget-based class, a faster method is to
564 * reimplement QWidget::changeEvent() and catch QEvent::FontChange.
565 * This is the preferred way to get informed about font updates.
567 void kdisplayFontChanged();
570 * Emitted when the application has changed either its GUI style, its font or its palette
571 * in response to a kdisplay request. Normally, widgets will update their styles
572 * automatically, but you should connect to this to program special
573 * behavior.
575 void appearanceChanged();
578 * Emitted when the settings for toolbars have been changed. KToolBar will know what to do.
580 void toolbarAppearanceChanged(int);
583 * Emitted when the global settings have been changed.
584 * KGlobalSettings takes care of calling reparseConfiguration on KGlobal::config()
585 * so that applications/classes using this only have to re-read the configuration
586 * @param category the category among the SettingsCategory enum.
588 void settingsChanged(int category);
591 * Emitted when the global icon settings have been changed.
592 * @param group the new group
594 void iconChanged(int group);
597 * Emitted when the cursor theme has been changed.
599 void cursorChanged();
602 * Emitted by BlockShortcuts
604 void blockShortcuts(int data);
606 private:
607 friend class KApplication;
609 KGlobalSettings();
611 class Private;
612 Private* const d;
614 Q_PRIVATE_SLOT(d, void _k_slotNotifyChange(int, int))
617 Q_DECLARE_OPERATORS_FOR_FLAGS(KGlobalSettings::GraphicEffects)
619 #endif