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 #include <QDesktopWidget>
29 switch (documentStatus) {
31 if (documentPath.isEmpty()) {
32 return QCoreApplication::translate(
"Utilities::windowTitle",
"Unsaved - %1").arg(QCoreApplication::applicationName());
34 const QFileInfo file(documentPath);
35 return QCoreApplication::translate(
"Utilities::windowTitle",
"%1 - %2 - %3")
36 .arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
39 if (documentPath.isEmpty()) {
40 return QCoreApplication::translate(
"Utilities::windowTitle",
"*Unsaved - %1").arg(QCoreApplication::applicationName());
42 const QFileInfo file(documentPath);
43 return QCoreApplication::translate(
"Utilities::windowTitle",
"*%1 - %2 - %3")
44 .arg(file.fileName(), file.dir().path(), QCoreApplication::applicationName());
47 return QCoreApplication::applicationName();
54 #if defined(QT_UTILITIES_GUI_QTWIDGETS) || defined(QT_UTILITIES_GUI_QTQUICK)
61 QColor windowFrameColor()
63 return QGuiApplication::palette().window().color().darker(108);
69 QColor instructionTextColor()
71 const auto baseColor = QGuiApplication::palette().base().color();
72 return (baseColor.value() > 204 && baseColor.saturation() < 63) ? QColor(0x00, 0x33, 0x99) : QGuiApplication::palette().
text().color();
81 const QString &dialogStyle()
84 static const auto style = QStringLiteral(
"#mainWidget { color: palette(text); background-color: "
85 "palette(base); border: none; }"
86 "#bottomWidget { background-color: palette(window); "
87 "color: palette(window-text); border-top: 1px solid %1; }"
88 "QMessageBox QLabel, QInputDialog QLabel, "
89 "*[classNames~=\"heading\"] { font-size: 12pt; color: %2; "
91 "*[classNames~=\"input-invalid\"] { color: red; }")
92 .arg(windowFrameColor().name(), instructionTextColor().name());
94 static const auto style = QStringLiteral(
"*[classNames~=\"heading\"] { font-weight: bold; }"
95 "*[classNames~=\"input-invalid\"] { color: red; }");
100 #ifdef QT_UTILITIES_GUI_QTWIDGETS
102 QRect availableScreenGeometryAtPoint(
const QPoint &point)
104 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
105 QScreen *
const screen = QGuiApplication::screenAt(point);
109 return screen->availableGeometry();
111 return QApplication::desktop()->availableGeometry(point);
122 void centerWidget(QWidget *widget,
const QWidget *parent,
const QPoint *position)
124 widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(),
125 parent ? parent->geometry() : availableScreenGeometryAtPoint(position ? *position : QCursor::pos())));
135 void cornerWidget(QWidget *widget,
const QPoint *position)
137 const QPoint cursorPos(position ? *position : QCursor::pos());
138 const QRect availableGeometry(availableScreenGeometryAtPoint(cursorPos));
139 const Qt::Alignment alignment
140 = (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight)
141 | (cursorPos.y() - availableGeometry.top() < availableGeometry.bottom() - cursorPos.y() ? Qt::AlignTop : Qt::AlignBottom);
142 widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, alignment, widget->size(), availableGeometry));
148 void makeHeading(QWidget *widget)
150 widget->setProperty(
"classNames", widget->property(
"classNames").toStringList() << QStringLiteral(
"heading"));
159 void updateStyle(QWidget *widget)
161 widget->style()->unpolish(widget);
162 widget->style()->polish(widget);