NDEVR
API Documentation
NDEVRTheme.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVR
28File: NDEVRLightingTheme
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/INIInterface.h>
35#include <NDEVR/RGBColor.h>
36#include <QPropertyAnimation>
37#include <QProxyStyle>
38#include <QPalette>
39class QFont;
40namespace NDEVR
41{
51 class NDEVRProxyStyle;
55 class ThemeChanger : public QPropertyAnimation
56 {
57 Q_OBJECT
58 Q_PROPERTY(float percent READ percent WRITE setPercent)
59 public:
75 float percent() const;
80 void setPercent(float percent);
84
85 protected:
86 QPropertyAnimation* m_animation;
87 };
88
94 class NDEVR_WIDGETS_API NDEVRProxyStyle : public QProxyStyle, public INIInterface
95 {
96 Q_OBJECT
97 public:
106 NDEVRProxyStyle(const File& ini_file);
111 NDEVRProxyStyle(QStyle* style);
113 public:
126 int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override;
134 virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const override;
142 void drawControl(ControlElement element, const QStyleOption *opt, QPainter *painter, const QWidget *widget) const override;
150 void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = nullptr) const override;
159 void drawArrow(Qt::ArrowType type, QPainter *painter, const QStyleOption *option, const QRect &rect, const QColor &color) const;
170 void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled,
171 const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const override;
179 virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override;
187 QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const override;
196 QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override;
206 QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const override;
214 QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const override;
223 QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override;
232 int styleHint(StyleHint stylehint, const QStyleOption *opt = nullptr,
233 const QWidget *widget = nullptr, QStyleHintReturn* returnData = nullptr) const override;
238 virtual QPalette standardPalette() const override;
260 QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const override;
283 void setLightingTheme(NDEVRLightingTheme theme, bool force_update = false, bool save_settings = true);
300 void setUseRoundedButtons(bool use_rounded_buttons);
316 bool isGlobalStyle() const;
321 virtual void getINI(INIFactory& factory) override;
330 NDEVRLightingTheme theme() const { return m_theme; };
355 void polish(QWidget *widget) override;
368 static QFont OriginalFont();
387 protected:
394 void drawRoundedButtonBackground(const QStyleOption* opt, QPainter* p, int radius = Constant<int>::Max) const;
407 void init();
413 signals:
419 protected:
421 protected:
434 };
435 template class NDEVR_WIDGETS_API StringStream<NDEVRLightingTheme>;
436}
437
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:107
INIInterface()
Constructs an INIInterface with no default INI file.
Responsible for setting up the core style of the application including size of various widgets and co...
Definition NDEVRTheme.h:95
void saveSettings()
Persists the current style settings to storage.
fltp08 m_touch_text_scale_vert
Vertical text scale factor for touch mode.
Definition NDEVRTheme.h:429
fltp08 m_touch_text_scale_horz
Horizontal text scale factor for touch mode.
Definition NDEVRTheme.h:430
QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const override
Returns the sub-element rectangle for a given element type.
void drawRoundedButtonBackground(const QStyleOption *opt, QPainter *p, int radius=Constant< int >::Max) const
Draws a rounded button background.
NDEVRLightingTheme oldTheme() const
Returns the theme that was active before the most recent theme change.
void updateUIFromStyle()
Refreshes the entire UI to reflect current style settings.
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget=nullptr) const override
Draws a complex control such as a scroll bar or slider.
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *painter, const QWidget *widget) const override
Draws a control element such as a button or label.
NDEVRLightingTheme theme() const
Returns the currently active lighting theme.
Definition NDEVRTheme.h:330
static NDEVRProxyStyle * s_global_style
The singleton global style instance.
Definition NDEVRTheme.h:412
void setUseRoundedButtons(bool use_rounded_buttons)
Enables or disables rounded button rendering.
void lightingThemeChangedSignal(NDEVRLightingTheme theme)
Emitted when the lighting theme changes.
NDEVRLightingTheme m_old_theme
The previously active theme before the last change.
Definition NDEVRTheme.h:423
TimeSpan fadeOutAnimationTime() const
Returns the duration of fade-out animations.
TimeSpan resizeAnimationTime() const
Returns the duration of widget resize animations.
void setToDefaultColors()
Resets all theme colors to their default values.
QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const override
Returns the bounding rectangle for an item pixmap.
static NDEVRProxyStyle * GlobalStyle()
Returns the singleton global style instance.
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
Returns the standard icon for a given pixmap type.
fltp08 baseTextScale() const
Returns the base text scaling factor.
void updateResolutionPixelMetric()
Recalculates the resolution-dependent pixel metric based on the current display.
QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const override
Returns the bounding rectangle for item text.
void setToDefaultSizes()
Resets all UI size metrics to their default values.
fltp08 desktopFontScale()
Returns the desktop font scaling factor.
void setLightingThemeAnimated(NDEVRLightingTheme start, NDEVRLightingTheme end, fltp04 percent)
Sets the lighting theme with an animated transition at a specific percentage.
void polish(QWidget *widget) override
Polishes a widget by applying NDEVR-specific style adjustments.
NDEVRProxyStyle(const File &ini_file)
Constructs the proxy style and loads settings from an INI file.
fltp08 m_desktop_text_scale
Text scale factor for desktop mode.
Definition NDEVRTheme.h:431
NDEVRProxyStyle(QStyle *style)
Constructs the proxy style wrapping an existing QStyle.
fltp08 m_touch_ui_scale_horz
Horizontal UI scale factor for touch mode.
Definition NDEVRTheme.h:426
void drawArrow(Qt::ArrowType type, QPainter *painter, const QStyleOption *option, const QRect &rect, const QColor &color) const
Draws an arrow indicator in the given direction.
void setLightingThemeAnimated(NDEVRLightingTheme theme)
Sets the lighting theme with an animated transition from the current theme.
NDEVRLightingTheme m_theme
The currently active lighting theme.
Definition NDEVRTheme.h:424
int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const override
Returns a style hint value for the given hint type.
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const override
Draws a primitive style element with custom NDEVR rendering.
QPalette themePalette(NDEVRLightingTheme theme) const
Returns the palette for a specific lighting theme.
fltp08 m_desktop_ui_scale
UI scale factor for desktop mode.
Definition NDEVRTheme.h:428
bool m_touch_use_rounded_buttons
Whether rounded button rendering is enabled in touch mode.
Definition NDEVRTheme.h:433
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override
Computes the size for a widget given its contents type.
void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const override
Draws text within a styled context.
QPalette interpolatedThemePalette(NDEVRLightingTheme start, NDEVRLightingTheme end, fltp04 percent) const
Returns a palette that interpolates between two themes.
fltp04 m_theme_transition_percent
Current animation progress during theme transitions.
Definition NDEVRTheme.h:422
virtual void getINI(INIFactory &factory) override
Serializes or deserializes theme settings through an INI factory.
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const override
Draws a pixmap within a styled context.
TimeSpan fadeInAnimationTime() const
Returns the duration of fade-in animations.
void updateFontScale()
Recalculates the font scale based on current settings.
bool isGlobalStyle() const
Checks whether this instance is the global singleton style.
void updateIconOverrideTheme()
Updates the icon theme override to match the current lighting theme.
RGBColor theme_colors[NDEVRLightingTheme::e_num_of_themes][QPalette::NColorRoles]
Per-theme color table indexed by theme and palette role.
Definition NDEVRTheme.h:420
fltp08 m_touch_ui_scale_vert
Vertical UI scale factor for touch mode.
Definition NDEVRTheme.h:427
bool usingRoundedButtons() const
Checks whether rounded buttons are currently enabled.
void init()
Initializes the proxy style with default values and system metrics.
fltp08 baseUIScale() const
Returns the base UI scaling factor.
RGBColor disabledColor(NDEVRLightingTheme theme) const
Returns the disabled-state color for a given theme.
NDEVRProxyStyle()
Constructs the proxy style with default settings.
void setLightingTheme(NDEVRLightingTheme theme, bool force_update=false, bool save_settings=true)
Sets the active lighting theme immediately.
QStyle * m_native_theme
The platform native style used as a fallback.
Definition NDEVRTheme.h:425
fltp08 m_resolution_pixel_metric
A DPI-aware pixel metric for the current display.
Definition NDEVRTheme.h:432
virtual QPalette standardPalette() const override
Returns the standard palette for the current theme.
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
Returns a pixel metric value scaled for the current UI settings.
fltp04 themeTransitionPercent()
Returns the current theme transition animation percentage.
TimeSpan paletteAnimationTime() const
Returns the duration of palette transition animations.
static StringView ColorThemeIcon(NDEVRLightingTheme theme)
Returns the icon name associated with a given lighting theme.
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override
Returns the sub-control rectangle for a complex control.
static QFont OriginalFont()
Returns the original application font before any scaling is applied.
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
Logic for reading or writing to a string or a user friendly, TranslatedString.
The core String View class for the NDEVR API.
Definition StringView.h:58
void setPercent(float percent)
Sets the current interpolation percentage and updates the style.
QPropertyAnimation * m_animation
The underlying Qt property animation driver.
Definition NDEVRTheme.h:86
NDEVRLightingTheme end
The theme at the end of the animation.
Definition NDEVRTheme.h:82
void startAnimation()
Begins the theme transition animation.
NDEVRProxyStyle * style
The proxy style being animated.
Definition NDEVRTheme.h:83
NDEVRLightingTheme start
The theme at the beginning of the animation.
Definition NDEVRTheme.h:81
float percent() const
Returns the current interpolation percentage of the animation.
ThemeChanger(NDEVRLightingTheme start, NDEVRLightingTheme end, NDEVRProxyStyle *style)
Constructs a ThemeChanger animation between two themes.
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
double fltp08
Defines an alias representing an 8 byte floating-point number.
NDEVRLightingTheme
Enumerates the available UI color themes.
Definition NDEVRTheme.h:46
@ e_light_theme
A light color theme with dark text on light backgrounds.
Definition NDEVRTheme.h:48
@ e_dark_theme
A dark color theme with light text on dark backgrounds.
Definition NDEVRTheme.h:47
@ e_num_of_themes
The total number of available themes.
Definition NDEVRTheme.h:49