added Dialogs::updateStyle()
This commit is contained in:
parent
b5ee1adc3f
commit
1f890920e6
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
#include "./dialogutils.h"
|
||||
|
||||
#ifdef GUI_NONE
|
||||
#include <QCoreApplication>
|
||||
# include <QCoreApplication>
|
||||
#else
|
||||
#include <QGuiApplication>
|
||||
#include <QPalette>
|
||||
#include <QWidget>
|
||||
# include <QGuiApplication>
|
||||
# include <QPalette>
|
||||
# include <QWidget>
|
||||
# include <QStyle>
|
||||
#endif
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue