PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/src/qt/qtbase/src/gui/kernel/qstylehints.cpp

https://gitlab.com/x33n/phantomjs
C++ | 340 lines | 137 code | 27 blank | 176 comment | 2 complexity | 10936733f95456bdd069dfdd99d1809f MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the QtGui module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and Digia. For licensing terms and
  14. ** conditions see http://qt.digia.com/licensing. For further information
  15. ** use the contact form at http://qt.digia.com/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 2.1 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 2.1 requirements
  23. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  24. **
  25. ** In addition, as a special exception, Digia gives you certain additional
  26. ** rights. These rights are described in the Digia Qt LGPL Exception
  27. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  28. **
  29. ** GNU General Public License Usage
  30. ** Alternatively, this file may be used under the terms of the GNU
  31. ** General Public License version 3.0 as published by the Free Software
  32. ** Foundation and appearing in the file LICENSE.GPL included in the
  33. ** packaging of this file. Please review the following information to
  34. ** ensure the GNU General Public License version 3.0 requirements will be
  35. ** met: http://www.gnu.org/copyleft/gpl.html.
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include <qstylehints.h>
  42. #include <qpa/qplatformintegration.h>
  43. #include <qpa/qplatformtheme.h>
  44. #include <private/qguiapplication_p.h>
  45. QT_BEGIN_NAMESPACE
  46. static inline QVariant hint(QPlatformIntegration::StyleHint h)
  47. {
  48. return QGuiApplicationPrivate::platformIntegration()->styleHint(h);
  49. }
  50. static inline QVariant themeableHint(QPlatformTheme::ThemeHint th,
  51. QPlatformIntegration::StyleHint ih)
  52. {
  53. if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
  54. const QVariant themeHint = theme->themeHint(th);
  55. if (themeHint.isValid())
  56. return themeHint;
  57. }
  58. return QGuiApplicationPrivate::platformIntegration()->styleHint(ih);
  59. }
  60. class QStyleHintsPrivate : public QObjectPrivate
  61. {
  62. Q_DECLARE_PUBLIC(QStyleHints)
  63. public:
  64. inline QStyleHintsPrivate()
  65. : m_mouseDoubleClickInterval(-1)
  66. , m_startDragDistance(-1)
  67. , m_startDragTime(-1)
  68. , m_keyboardInputInterval(-1)
  69. , m_cursorFlashTime(-1)
  70. {}
  71. int m_mouseDoubleClickInterval;
  72. int m_startDragDistance;
  73. int m_startDragTime;
  74. int m_keyboardInputInterval;
  75. int m_cursorFlashTime;
  76. };
  77. /*!
  78. \class QStyleHints
  79. \since 5.0
  80. \brief The QStyleHints class contains platform specific hints and settings.
  81. \inmodule QtGui
  82. An object of this class, obtained from QGuiApplication, provides access to certain global
  83. user interface parameters of the current platform.
  84. Access is read only; typically the platform itself provides the user a way to tune these
  85. parameters.
  86. Access to these parameters are useful when implementing custom user interface components, in that
  87. they allow the components to exhibit the same behaviour and feel as other components.
  88. \sa QGuiApplication::styleHints(), QPlatformTheme
  89. */
  90. QStyleHints::QStyleHints()
  91. : QObject(*new QStyleHintsPrivate(), 0)
  92. {
  93. }
  94. /*!
  95. Sets the \a mouseDoubleClickInterval.
  96. \internal
  97. \sa mouseDoubleClickInterval()
  98. \since 5.3
  99. */
  100. void QStyleHints::setMouseDoubleClickInterval(int mouseDoubleClickInterval)
  101. {
  102. Q_D(QStyleHints);
  103. d->m_mouseDoubleClickInterval = mouseDoubleClickInterval;
  104. }
  105. /*!
  106. Returns the time limit in milliseconds that distinguishes a double click
  107. from two consecutive mouse clicks.
  108. */
  109. int QStyleHints::mouseDoubleClickInterval() const
  110. {
  111. Q_D(const QStyleHints);
  112. return d->m_mouseDoubleClickInterval >= 0 ?
  113. d->m_mouseDoubleClickInterval :
  114. themeableHint(QPlatformTheme::MouseDoubleClickInterval, QPlatformIntegration::MouseDoubleClickInterval).toInt();
  115. }
  116. /*!
  117. Returns the time limit in milliseconds that activates
  118. a press and hold.
  119. \since 5.3
  120. */
  121. int QStyleHints::mousePressAndHoldInterval() const
  122. {
  123. return themeableHint(QPlatformTheme::MousePressAndHoldInterval, QPlatformIntegration::MousePressAndHoldInterval).toInt();
  124. }
  125. /*!
  126. Sets the \a startDragDistance.
  127. \internal
  128. \sa startDragDistance()
  129. \since 5.3
  130. */
  131. void QStyleHints::setStartDragDistance(int startDragDistance)
  132. {
  133. Q_D(QStyleHints);
  134. d->m_startDragDistance = startDragDistance;
  135. }
  136. /*!
  137. Returns the distance, in pixels, that the mouse must be moved with a button
  138. held down before a drag and drop operation will begin.
  139. If you support drag and drop in your application, and want to start a drag
  140. and drop operation after the user has moved the cursor a certain distance
  141. with a button held down, you should use this property's value as the
  142. minimum distance required.
  143. For example, if the mouse position of the click is stored in \c startPos
  144. and the current position (e.g. in the mouse move event) is \c currentPos,
  145. you can find out if a drag should be started with code like this:
  146. \snippet code/src_gui_kernel_qapplication.cpp 6
  147. \sa startDragTime(), QPoint::manhattanLength(), {Drag and Drop}
  148. */
  149. int QStyleHints::startDragDistance() const
  150. {
  151. Q_D(const QStyleHints);
  152. return d->m_startDragDistance >= 0 ?
  153. d->m_startDragDistance :
  154. themeableHint(QPlatformTheme::StartDragDistance, QPlatformIntegration::StartDragDistance).toInt();
  155. }
  156. /*!
  157. Sets the \a startDragDragTime.
  158. \internal
  159. \sa startDragTime()
  160. \since 5.3
  161. */
  162. void QStyleHints::setStartDragTime(int startDragTime)
  163. {
  164. Q_D(QStyleHints);
  165. d->m_startDragTime = startDragTime;
  166. }
  167. /*!
  168. Returns the time, in milliseconds, that a mouse button must be held down
  169. before a drag and drop operation will begin.
  170. If you support drag and drop in your application, and want to start a drag
  171. and drop operation after the user has held down a mouse button for a
  172. certain amount of time, you should use this property's value as the delay.
  173. \sa startDragDistance(), {Drag and Drop}
  174. */
  175. int QStyleHints::startDragTime() const
  176. {
  177. Q_D(const QStyleHints);
  178. return d->m_startDragTime >= 0 ?
  179. d->m_startDragTime :
  180. themeableHint(QPlatformTheme::StartDragTime, QPlatformIntegration::StartDragTime).toInt();
  181. }
  182. /*!
  183. Returns the limit for the velocity, in pixels per second, that the mouse may
  184. be moved, with a button held down, for a drag and drop operation to begin.
  185. A value of 0 means there is no such limit.
  186. \sa startDragDistance(), {Drag and Drop}
  187. */
  188. int QStyleHints::startDragVelocity() const
  189. {
  190. return themeableHint(QPlatformTheme::StartDragVelocity, QPlatformIntegration::StartDragVelocity).toInt();
  191. }
  192. /*!
  193. Sets the \a keyboardInputInterval.
  194. \internal
  195. \sa keyboardInputInterval()
  196. \since 5.3
  197. */
  198. void QStyleHints::setKeyboardInputInterval(int keyboardInputInterval)
  199. {
  200. Q_D(QStyleHints);
  201. d->m_keyboardInputInterval = keyboardInputInterval;
  202. }
  203. /*!
  204. Returns the time limit, in milliseconds, that distinguishes a key press
  205. from two consecutive key presses.
  206. */
  207. int QStyleHints::keyboardInputInterval() const
  208. {
  209. Q_D(const QStyleHints);
  210. return d->m_keyboardInputInterval >= 0 ?
  211. d->m_keyboardInputInterval :
  212. themeableHint(QPlatformTheme::KeyboardInputInterval, QPlatformIntegration::KeyboardInputInterval).toInt();
  213. }
  214. /*!
  215. Returns the rate, in events per second, in which additional repeated key
  216. presses will automatically be generated if a key is being held down.
  217. */
  218. int QStyleHints::keyboardAutoRepeatRate() const
  219. {
  220. return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toInt();
  221. }
  222. /*!
  223. Sets the \a cursorFlashTime.
  224. \internal
  225. \sa cursorFlashTime()
  226. \since 5.3
  227. */
  228. void QStyleHints::setCursorFlashTime(int cursorFlashTime)
  229. {
  230. Q_D(QStyleHints);
  231. d->m_cursorFlashTime = cursorFlashTime;
  232. }
  233. /*!
  234. Returns the text cursor's flash (blink) time in milliseconds.
  235. The flash time is the time used to display, invert and restore the
  236. caret display. Usually the text cursor is displayed for half the cursor
  237. flash time, then hidden for the same amount of time.
  238. */
  239. int QStyleHints::cursorFlashTime() const
  240. {
  241. Q_D(const QStyleHints);
  242. return d->m_cursorFlashTime >= 0 ?
  243. d->m_cursorFlashTime :
  244. themeableHint(QPlatformTheme::CursorFlashTime, QPlatformIntegration::CursorFlashTime).toInt();
  245. }
  246. /*!
  247. Returns \c true if the platform defaults to windows being fullscreen,
  248. otherwise \c false.
  249. \note The platform may still choose to show certain windows non-fullscreen,
  250. such as popups or dialogs. This method only returns the default behavior.
  251. \sa QWindow::show()
  252. */
  253. bool QStyleHints::showIsFullScreen() const
  254. {
  255. return hint(QPlatformIntegration::ShowIsFullScreen).toBool();
  256. }
  257. /*!
  258. Returns the time, in milliseconds, a typed letter is displayed unshrouded
  259. in a text input field in password mode.
  260. */
  261. int QStyleHints::passwordMaskDelay() const
  262. {
  263. return themeableHint(QPlatformTheme::PasswordMaskDelay, QPlatformIntegration::PasswordMaskDelay).toInt();
  264. }
  265. /*!
  266. Returns the character used to mask the characters typed into text input
  267. fields in password mode.
  268. */
  269. QChar QStyleHints::passwordMaskCharacter() const
  270. {
  271. return themeableHint(QPlatformTheme::PasswordMaskCharacter, QPlatformIntegration::PasswordMaskCharacter).toChar();
  272. }
  273. /*!
  274. Returns the gamma value used in font smoothing.
  275. */
  276. qreal QStyleHints::fontSmoothingGamma() const
  277. {
  278. return hint(QPlatformIntegration::FontSmoothingGamma).toReal();
  279. }
  280. /*!
  281. Returns \c true if right-to-left writing direction is enabled,
  282. otherwise \c false.
  283. */
  284. bool QStyleHints::useRtlExtensions() const
  285. {
  286. return hint(QPlatformIntegration::UseRtlExtensions).toBool();
  287. }
  288. /*!
  289. Returns \c true if focus objects (line edits etc) should receive
  290. input focus after a touch/mouse release. This is normal behavior on
  291. touch platforms. On desktop platforms, the standard is to set
  292. focus already on touch/mouse press.
  293. */
  294. bool QStyleHints::setFocusOnTouchRelease() const
  295. {
  296. return hint(QPlatformIntegration::SetFocusOnTouchRelease).toBool();
  297. }
  298. QT_END_NAMESPACE