From ca19cba2ac3cf9785b9a2211c4ba7d1e14d87bf2 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 14 Dec 2012 18:25:03 +0100 Subject: [PATCH] Factorize code for formatting window titles into QPlatformWindow. Change-Id: I0dcccd08916fc2ea1b795681e9b98a9550ef51b6 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qplatformwindow.cpp | 24 +++++++++++++++++++ src/gui/kernel/qplatformwindow.h | 2 ++ .../platforms/windows/qwindowswindow.cpp | 13 +--------- src/plugins/platforms/xcb/qxcbwindow.cpp | 12 +--------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 01377d1aa03..b710701e7f8 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -42,6 +42,7 @@ #include "qplatformwindow.h" #include "qplatformwindow_p.h" +#include #include #include #include @@ -424,6 +425,29 @@ bool QPlatformWindow::frameStrutEventsEnabled() const return false; } +/*! + Call this method to put together a window title composed of + \a title + \a separator + the application display name + + If the display name isn't set, and the title is empty, the raw app name is used. +*/ +QString QPlatformWindow::formatWindowTitle(const QString &title, const QString &separator) +{ + QString fullTitle = title; + if (QGuiApplicationPrivate::displayName) { + // Append display name, if set. + if (!fullTitle.isEmpty()) + fullTitle += separator; + fullTitle += *QGuiApplicationPrivate::displayName; + } else if (fullTitle.isEmpty()) { + // Don't let the window title be completely empty, use the app name as fallback. + fullTitle = QCoreApplication::applicationName(); + } + return fullTitle; +} + /*! \class QPlatformWindow \since 4.8 diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index d435198349b..fe62d7b67b8 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -131,6 +131,8 @@ public: virtual bool frameStrutEventsEnabled() const; protected: + static QString formatWindowTitle(const QString &title, const QString &separator); + QScopedPointer d_ptr; private: Q_DISABLE_COPY(QPlatformWindow) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 5d6d4620b7e..2708d7d428a 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1216,18 +1216,7 @@ void QWindowsWindow::setWindowTitle(const QString &title) if (QWindowsContext::verboseWindows) qDebug() << __FUNCTION__ << this << window() <