don't let spaceAdd ever become negative and break the layout.
[kdelibs.git] / kdeui / kernel / kglobalsettings.h
blob2ccd96fb882f4af9b681006d6841d7a867c35f8c
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_INSERTTEAROFFHANDLES 0
29 #define KDE_DEFAULT_AUTOSELECTDELAY -1
30 #define KDE_DEFAULT_CHANGECURSOR true
31 #define KDE_DEFAULT_LARGE_CURSOR false
32 #define KDE_DEFAULT_WHEEL_ZOOM false
33 #define KDE_DEFAULT_ICON_ON_PUSHBUTTON true
34 #define KDE_DEFAULT_OPAQUE_RESIZE true
35 #define KDE_DEFAULT_BUTTON_LAYOUT 0
36 #define KDE_DEFAULT_SHADE_SORT_COLUMN true
37 #define KDE_DEFAULT_ALLOW_DEFAULT_BACKGROUND_IMAGES true
39 class KUrl;
41 class QColor;
42 class QFont;
43 class QPoint;
44 class QRect;
45 class QWidget;
47 /**
48 * Access the KDE global configuration.
50 * @author David Faure \<faure@kde.org\>
52 class KDEUI_EXPORT KGlobalSettings : public QObject
54 Q_OBJECT
56 public:
57 ~KGlobalSettings();
59 /**
60 * Returns a threshold in pixels for drag & drop operations.
61 * As long as the mouse movement has not exceeded this number
62 * of pixels in either X or Y direction no drag operation may
63 * be started. This prevents spurious drags when the user intended
64 * to click on something but moved the mouse a bit while doing so.
66 * For this to work you must save the position of the mouse (oldPos)
67 * in the QWidget::mousePressEvent().
68 * When the position of the mouse (newPos)
69 * in a QWidget::mouseMoveEvent() exceeds this threshold
70 * you may start a drag
71 * which should originate from oldPos.
73 * Example code:
74 * \code
75 * void KColorCells::mousePressEvent( QMouseEvent *e )
76 * {
77 * mOldPos = e->pos();
78 * }
80 * void KColorCells::mouseMoveEvent( QMouseEvent *e )
81 * {
82 * if( !(e->state() && LeftButton)) return;
84 * int delay = KGlobalSettings::dndEventDelay();
85 * QPoint newPos = e->pos();
86 * if(newPos.x() > mOldPos.x()+delay || newPos.x() < mOldPos.x()-delay ||
87 * newPos.y() > mOldPos.y()+delay || newPos.y() < mOldPos.y()-delay)
88 * {
89 * // Drag color object
90 * int cell = posToCell(mOldPos); // Find color at mOldPos
91 * if ((cell != -1) && colors[cell].isValid())
92 * {
93 * KColorDrag *d = KColorDrag::makeDrag( colors[cell], this);
94 * d->dragCopy();
95 * }
96 * }
97 * }
98 * \endcode
99 * @return the threshold for drag & drop in pixels
102 static int dndEventDelay();
105 * Returns whether KDE runs in single (default) or double click
106 * mode.
107 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html
108 * @return true if single click mode, or false if double click mode.
110 static bool singleClick();
113 * This enum describes the return type for insertTearOffHandle() whether to insert
114 * a handle or not. Applications who independently want to use handles in their popup menus
115 * should test for Application level before calling the appropriate function in KMenu.
117 enum TearOffHandle {
118 Disable = 0, ///< disable tear-off handles
119 ApplicationLevel, ///< enable on application level
120 Enable ///< enable tear-off handles
124 * Returns whether tear-off handles are inserted in KMenus.
125 * @return whether tear-off handles are inserted in KMenus.
127 static TearOffHandle insertTearOffHandle();
130 * Checks whether the cursor changes over icons.
131 * @return the KDE setting for "change cursor over icon"
133 static bool changeCursorOverIcon();
136 * Returns the KDE setting for the auto-select option.
138 * @return the auto-select delay or -1 if auto-select is disabled.
140 static int autoSelectDelay();
143 * Returns the KDE setting for the shortcut key to open
144 * context menus.
146 * @return the key that pops up context menus.
147 * @deprecated Simply reimplement QWidget::contextMenuEvent() instead.
149 static KDE_DEPRECATED int contextMenuKey ();
152 * Returns the KDE setting for context menus.
154 * @return whether context menus should be shown on button press
155 * or button release (click).
157 static bool showContextMenusOnPress ();
160 * This enum describes the completion mode used for by the KCompletion class.
161 * See <a href="http://developer.kde.org/documentation/standards/kde/style/keys/completion.html">
162 * the styleguide</a>.
164 enum Completion {
166 * No completion is used.
168 CompletionNone=1,
170 * Text is automatically filled in whenever possible.
172 CompletionAuto,
174 * Same as automatic except shortest match is used for completion.
176 CompletionMan,
178 * Complete text much in the same way as a typical *nix shell would.
180 CompletionShell,
182 * Lists all possible matches in a popup list-box to choose from.
184 CompletionPopup,
186 * Lists all possible matches in a popup list-box to choose from, and automatically
187 * fill the result whenever possible.
189 CompletionPopupAuto
193 * Returns the preferred completion mode setting.
195 * @return Completion. Default is @p CompletionPopup.
197 static Completion completionMode();
200 * Describes the mouse settings.
202 struct KMouseSettings
204 enum { RightHanded = 0, LeftHanded = 1 };
205 int handed; // left or right
209 * This returns the current mouse settings.
210 * On Windows, settings are retrieved from the system.
211 * @return the current mouse settings
213 static KMouseSettings & mouseSettings();
216 * The path to the desktop directory of the current user.
217 * @return the user's desktop directory
219 static QString desktopPath();
222 * The path to the autostart directory of the current user.
223 * @return the path of the autostart directory
225 static QString autostartPath();
228 * The path where documents are stored of the current user.
229 * @return the path of the document directory
231 static QString documentPath();
235 * The default color to use for inactive titles.
236 * @return the inactive title color
238 static QColor inactiveTitleColor();
241 * The default color to use for inactive texts.
242 * @return the inactive text color
244 static QColor inactiveTextColor();
247 * The default color to use for active titles.
248 * @return the active title color
250 static QColor activeTitleColor();
253 * The default color to use for active texts.
254 * @return the active text color
256 static QColor activeTextColor();
259 * Returns the contrast for borders.
260 * @return the contrast (between 0 for minimum and 10 for maximum
261 * contrast)
263 static int contrast();
266 * Returns the contrast for borders as a floating point value.
267 * @param config pointer to the config from which to read the contrast
268 * setting (the default is to use KGlobal::config())
269 * @return the contrast (between 0.0 for minimum and 1.0 for maximum
270 * contrast)
272 static qreal contrastF(const KSharedConfigPtr &config = KSharedConfigPtr());
275 * Returns if the sorted column in a K3ListView shall be drawn with a
276 * shaded background color.
277 * @return true if the sorted column shall be shaded
279 static bool shadeSortColumn();
282 * Returns if default background images are allowed by the color scheme.
283 * A "default" background image is just that, i.e. the user has not
284 * actively selected a background image to use.
285 * @return true if default background images may be used
287 static bool allowDefaultBackgroundImages();
290 * Returns the default general font.
291 * @return the default general font.
293 static QFont generalFont();
296 * Returns the default fixed font.
297 * @return the default fixed font.
299 static QFont fixedFont();
302 * Returns the default toolbar font.
303 * @return the default toolbar font.
305 static QFont toolBarFont();
308 * Returns the default menu font.
309 * @return the default menu font.
311 static QFont menuFont();
314 * Returns the default window title font.
315 * @return the default window title font.
317 static QFont windowTitleFont();
320 * Returns the default taskbar font.
321 * @return the default taskbar font.
323 static QFont taskbarFont();
326 * Returns a font of approx. 48 pt. capable of showing @p text.
327 * @param text the text to test
328 * @return the font that is capable to show the text with 48 pt
330 static QFont largeFont(const QString &text = QString());
333 * Returns the smallest readable font. This can be used in dockers,
334 * rulers and other places where space is at a premium.
336 static QFont smallestReadableFont();
339 * Returns if the user specified multihead. In case the display
340 * has multiple screens, the return value of this function specifies
341 * if the user wants KDE to run on all of them or just on the primary
342 * On Windows, settings are retrieved from the system.
343 * @return true if the user chose multi head
345 static bool isMultiHead();
348 * Typically, QScrollView derived classes can be scrolled fast by
349 * holding down the Ctrl-button during wheel-scrolling.
350 * But QTextEdit and derived classes perform zooming instead of fast
351 * scrolling.
353 * This value determines whether the user wants to zoom or scroll fast
354 * with Ctrl-wheelscroll.
355 * @return true if the user wishes to zoom with the mouse wheel,
356 * false for scrolling
358 static bool wheelMouseZooms();
361 * This function returns the desktop geometry for an application's splash
362 * screen. It takes into account the user's display settings (number of
363 * screens, Xinerama, etc), and the user's preferences (if KDE should be
364 * Xinerama aware).
366 * @return the geometry to use for the desktop. Note that it might not
367 * start at (0,0).
369 static QRect splashScreenDesktopGeometry();
372 * This function returns the desktop geometry for an application that needs
373 * to set the geometry of a widget on the screen manually. It takes into
374 * account the user's display settings (number of screens, Xinerama, etc),
375 * and the user's preferences (if KDE should be Xinerama aware).
377 * Note that this can break in multi-head (not Xinerama) mode because this
378 * point could be on multiple screens. Use with care.
380 * @param point a reference point for the widget, for instance one that the
381 * widget should be adjacent or on top of.
383 * @return the geometry to use for the desktop. Note that it might not
384 * start at (0,0).
386 static QRect desktopGeometry(const QPoint& point);
389 * This function returns the desktop geometry for an application that needs
390 * to set the geometry of a widget on the screen manually. It takes into
391 * account the user's display settings (number of screens, Xinerama, etc),
392 * and the user's preferences (if KDE should be Xinerama aware).
394 * @param w the widget in question. This is used to determine which screen
395 * to use in Xinerama or multi-head mode.
397 * @return the geometry to use for the desktop. Note that it might not
398 * start at (0,0).
400 static QRect desktopGeometry(const QWidget* w);
403 * This function determines if the user wishes to see icons on the
404 * push buttons.
406 * @return Returns true if user wants to show icons.
408 static bool showIconsOnPushButtons();
411 * This function determines if the user wishes to see previews
412 * for the selected url
414 * @return Returns true if user wants to show previews.
416 static bool showFilePreview(const KUrl &);
419 * Whether the user wishes to use opaque resizing. Primarily
420 * intended for QSplitter::setOpaqueResize()
422 * @return Returns true if user wants to use opaque resizing.
424 static bool opaqueResize();
427 * The layout scheme to use for dialog buttons
429 * @return Returns the number of the scheme to use.
431 static int buttonLayout();
434 * Used to obtain the QPalette that will be used to set the application palette.
436 * This is only useful for configuration modules such as krdb and should not be
437 * used in normal circumstances.
438 * @param config KConfig from which to load the colors (passed as-is to
439 * ::KColorScheme).
441 * @return the QPalette
443 static QPalette createApplicationPalette(const KSharedConfigPtr &config = KSharedConfigPtr());
446 * An identifier for change signals.
447 * \see emitChange
449 enum ChangeType { PaletteChanged = 0, FontChanged, StyleChanged,
450 SettingsChanged, IconChanged, CursorChanged,
451 ToolbarStyleChanged, ClipboardConfigChanged,
452 BlockShortcuts };
455 * Notifies all KDE applications on the current display of a change.
457 * This is typically called by kcontrol modules after changing the corresponding
458 * config file. Do not call this from a normal KDE application.
460 static void emitChange(ChangeType changeType, int arg = 0);
463 * Return the KGlobalSettings singleton.
464 * This is used to connect to its signals, to be notified of changes.
466 static KGlobalSettings* self();
469 * Valid values for the settingsChanged signal
471 enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS,
472 SETTINGS_POPUPMENU, SETTINGS_QT, SETTINGS_SHORTCUTS };
474 Q_SIGNALS:
476 * Emitted when the application has changed its palette due to a KControl request.
478 * Normally, widgets will update their palette automatically, but you
479 * should connect to this to program special behavior.
481 void kdisplayPaletteChanged();
484 * Emitted when the application has changed its GUI style in response to a KControl request.
486 * Normally, widgets will update their styles automatically (as they would
487 * respond to an explicit setGUIStyle() call), but you should connect to
488 * this to program special behavior.
490 void kdisplayStyleChanged();
493 * Emitted when the application has changed its font in response to a KControl request.
495 * Normally widgets will update their fonts automatically, but you should
496 * connect to this to monitor global font changes, especially if you are
497 * using explicit fonts.
499 * Note: If you derive from a QWidget-based class, a faster method is to
500 * reimplement QWidget::changeEvent(). This is the preferred way
501 * to get informed about font updates.
503 void kdisplayFontChanged();
506 * Emitted when the application has changed either its GUI style, its font or its palette
507 * in response to a kdisplay request. Normally, widgets will update their styles
508 * automatically, but you should connect to this to program special
509 * behavior.
511 void appearanceChanged();
514 * Emitted when the settings for toolbars have been changed. KToolBar will know what to do.
516 void toolbarAppearanceChanged(int);
519 * Emitted when the global settings have been changed.
520 * KGlobalSettings takes care of calling reparseConfiguration on KGlobal::config()
521 * so that applications/classes using this only have to re-read the configuration
522 * @param category the category among the SettingsCategory enum.
524 void settingsChanged(int category);
527 * Emitted when the global icon settings have been changed.
528 * @param group the new group
530 void iconChanged(int group);
533 * Emitted when the cursor theme has been changed.
535 void cursorChanged();
538 * Emitted by BlockShortcuts
540 void blockShortcuts(int data);
542 private:
543 friend class KApplication;
545 KGlobalSettings();
547 class Private;
548 Private* const d;
550 Q_PRIVATE_SLOT(d, void _k_slotNotifyChange(int, int))
553 #endif