3 #include <QCoreApplication>
7 #if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
8 #include <QGuiApplication>
12 #if defined(QT_UTILITIES_GUI_QTWIDGETS)
13 #include <QApplication>
15 #if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
16 #include <QDesktopWidget>
31 switch (documentStatus) {
32 case DocumentStatus::Saved:
33 if (documentPath.isEmpty()) {
34 return QCoreApplication::translate(
"Utilities::windowTitle",
"Unsaved - %1").arg(QCoreApplication::applicationName());
36 const QFileInfo file(documentPath);
37 return QCoreApplication::translate(
"Utilities::windowTitle",
"%1 - %2 - %3")
38 .arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
41 if (documentPath.isEmpty()) {
42 return QCoreApplication::translate(
"Utilities::windowTitle",
"*Unsaved - %1").arg(QCoreApplication::applicationName());
44 const QFileInfo file(documentPath);
45 return QCoreApplication::translate(
"Utilities::windowTitle",
"*%1 - %2 - %3")
46 .arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
48 case DocumentStatus::NoDocument:
49 return QCoreApplication::applicationName();
56 #if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
63 QColor windowFrameColor()
65 return QGuiApplication::palette().window().color().darker(108);
71 QColor instructionTextColor()
73 const auto baseColor = QGuiApplication::palette().base().color();
74 return (baseColor.value() > 204 && baseColor.saturation() < 63) ? QColor(0x00, 0x33, 0x99) : QGuiApplication::palette().
text().color();
83 const QString &dialogStyle()
86 static const auto style = QStringLiteral(
"#mainWidget { color: palette(text); background-color: "
87 "palette(base); border: none; }"
88 "#bottomWidget { background-color: palette(window); "
89 "color: palette(window-text); border-top: 1px solid %1; }"
90 "QMessageBox QLabel, QInputDialog QLabel, "
91 "*[classNames~=\"heading\"] { font-size: 12pt; color: %2; "
93 "*[classNames~=\"input-invalid\"] { color: red; }")
94 .arg(windowFrameColor().name(), instructionTextColor().name());
96 static const auto style = QStringLiteral(
"*[classNames~=\"heading\"] { font-weight: bold; }"
97 "*[classNames~=\"input-invalid\"] { color: red; }");
102 #ifdef QT_UTILITIES_GUI_QTWIDGETS
104 QRect availableScreenGeometryAtPoint(
const QPoint &point)
106 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
107 QScreen *
const screen = QGuiApplication::screenAt(point);
111 return screen->availableGeometry();
113 return QApplication::desktop()->availableGeometry(point);
124 void centerWidget(QWidget *widget,
const QWidget *parent,
const QPoint *position)
126 widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(),
127 parent ? parent->geometry() : availableScreenGeometryAtPoint(position ? *position : QCursor::pos())));
137 void cornerWidget(QWidget *widget,
const QPoint *position)
139 const QPoint cursorPos(position ? *position : QCursor::pos());
140 const QRect availableGeometry(availableScreenGeometryAtPoint(cursorPos));
141 const Qt::Alignment alignment
142 = (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight)
143 | (cursorPos.y() - availableGeometry.top() < availableGeometry.bottom() - cursorPos.y() ? Qt::AlignTop : Qt::AlignBottom);
144 widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, alignment, widget->size(), availableGeometry));
150 void makeHeading(QWidget *widget)
152 widget->setProperty(
"classNames", widget->property(
"classNames").toStringList() << QStringLiteral(
"heading"));
161 void updateStyle(QWidget *widget)
163 widget->style()->unpolish(widget);
164 widget->style()->polish(widget);