From 1f890920e63b9dedd600efe23cca815d1a38b4a9 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 5 Feb 2016 20:23:02 +0100 Subject: [PATCH] added Dialogs::updateStyle() --- misc/desktoputils.cpp | 2 +- misc/dialogutils.cpp | 58 +++++++++++++++++++++++++++++++++---------- misc/dialogutils.h | 14 +++++++---- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/misc/desktoputils.cpp b/misc/desktoputils.cpp index 796ee55..4178a59 100644 --- a/misc/desktoputils.cpp +++ b/misc/desktoputils.cpp @@ -9,7 +9,7 @@ namespace DesktopUtils { /*! * \brief Shows the specified file or directory using the default file browser. - * \remarks + * \remarks \a path musn't be specified as URL. (Conversion to URL is the purpose of this function). */ bool LIB_EXPORT openLocalFileOrDir(const QString &path) { diff --git a/misc/dialogutils.cpp b/misc/dialogutils.cpp index d8693c6..8d69a12 100644 --- a/misc/dialogutils.cpp +++ b/misc/dialogutils.cpp @@ -1,17 +1,22 @@ #include "./dialogutils.h" #ifdef GUI_NONE -#include +# include #else -#include -#include -#include +# include +# include +# include +# include #endif #include #include namespace Dialogs { +/*! + * \brief Generates the window title string for the specified \a documentStatus + * and \a documentPath. + */ QString generateWindowTitle(DocumentStatus documentStatus, const QString &documentPath) { switch(documentStatus) { @@ -38,38 +43,65 @@ QString generateWindowTitle(DocumentStatus documentStatus, const QString &docume #ifndef GUI_NONE -#ifdef Q_OS_WIN32 +# ifdef Q_OS_WIN32 + +/*! + * \brief Returns the color used to draw frames. + */ QColor windowFrameColor() { return QGuiApplication::palette().window().color().darker(108); } +/*! + * \brief Returns the color used to draw instructions. + */ QColor instructionTextColor() { const auto baseColor = QGuiApplication::palette().base().color(); return (baseColor.value() > 204 && baseColor.saturation() < 63) ? QColor(0x00, 0x33, 0x99) : QGuiApplication::palette().text().color(); } -#endif +# endif +/*! + * \brief Returns the stylesheet for dialogs and other windows used in my applications. + */ const QString &dialogStyle() { -#ifdef Q_OS_WIN32 - static const auto style = QStringLiteral(" #mainWidget { color: palette(text); background-color: palette(base); border: none; }" - " #bottomWidget { background-color: palette(window); color: palette(window-text); border-top: 1px solid %1; }" - " QMessageBox QLabel, QInputDialog QLabel, *[classNames~=\"heading\"] { font-size: 12pt; color: %2; } ").arg( +# ifdef Q_OS_WIN32 + static const auto style = QStringLiteral("#mainWidget { color: palette(text); background-color: palette(base); border: none; }" + "#bottomWidget { background-color: palette(window); color: palette(window-text); border-top: 1px solid %1; }" + "QMessageBox QLabel, QInputDialog QLabel, *[classNames~=\"heading\"] { font-size: 12pt; color: %2; }" + "*[classNames~=\"input-invalid\"] { color: red; }").arg( windowFrameColor().name(), instructionTextColor().name()); -#else - static const auto style = QStringLiteral(" *[classNames~=\"heading\"] { font-weight: bold; } "); -#endif +# else + static const auto style = QStringLiteral("*[classNames~=\"heading\"] { font-weight: bold; }" + "*[classNames~=\"input-invalid\"] { color: red; }"); +# endif return style; } +/*! + * \brief Makes \a widget a heading. + */ void makeHeading(QWidget *widget) { widget->setProperty("classNames", widget->property("classNames").toStringList() << QStringLiteral("heading")); } +/*! + * \brief Updates the widget style. + * \remarks Useful when dynamic properties are used in the stylesheet because + * the widget style does not update automatically when a property changes. + */ +void updateStyle(QWidget *widget) +{ + widget->style()->unpolish(widget); + widget->style()->polish(widget); + widget->update(); +} + #endif } // namespace Dialogs diff --git a/misc/dialogutils.h b/misc/dialogutils.h index 10057e7..042b1f4 100644 --- a/misc/dialogutils.h +++ b/misc/dialogutils.h @@ -11,21 +11,25 @@ QT_FORWARD_DECLARE_CLASS(QColor) namespace Dialogs { +/*! + * \brief The DocumentStatus enum specifies the status of the document in a window. + */ enum class DocumentStatus { - NoDocument, - Saved, - Unsaved + NoDocument, /**< There is no document opened. The document path is ignored in this case. */ + Saved, /**< There is a document opened. All modifications have been saved yet. */ + Unsaved /**< There is a document opened and there are unsaved modifications. */ }; QString LIB_EXPORT generateWindowTitle(DocumentStatus documentStatus, const QString &documentPath); #ifndef GUI_NONE -#ifdef Q_OS_WIN32 +# ifdef Q_OS_WIN32 QColor LIB_EXPORT windowFrameColor(); QColor LIB_EXPORT instructionTextColor(); -#endif +# endif const QString LIB_EXPORT &dialogStyle(); void LIB_EXPORT makeHeading(QWidget *widget); +void LIB_EXPORT updateStyle(QWidget *widget); #endif } // namespace Dialogs