Factorize code for formatting window titles into QPlatformWindow.

Change-Id: I0dcccd08916fc2ea1b795681e9b98a9550ef51b6
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
David Faure 2012-12-14 18:25:03 +01:00 committed by The Qt Project
parent 132ba92ec2
commit ca19cba2ac
4 changed files with 28 additions and 23 deletions

View File

@ -42,6 +42,7 @@
#include "qplatformwindow.h" #include "qplatformwindow.h"
#include "qplatformwindow_p.h" #include "qplatformwindow_p.h"
#include <private/qguiapplication_p.h>
#include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface.h>
#include <QtGui/qwindow.h> #include <QtGui/qwindow.h>
#include <QtGui/qscreen.h> #include <QtGui/qscreen.h>
@ -424,6 +425,29 @@ bool QPlatformWindow::frameStrutEventsEnabled() const
return false; 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 \class QPlatformWindow
\since 4.8 \since 4.8

View File

@ -131,6 +131,8 @@ public:
virtual bool frameStrutEventsEnabled() const; virtual bool frameStrutEventsEnabled() const;
protected: protected:
static QString formatWindowTitle(const QString &title, const QString &separator);
QScopedPointer<QPlatformWindowPrivate> d_ptr; QScopedPointer<QPlatformWindowPrivate> d_ptr;
private: private:
Q_DISABLE_COPY(QPlatformWindow) Q_DISABLE_COPY(QPlatformWindow)

View File

@ -1216,18 +1216,7 @@ void QWindowsWindow::setWindowTitle(const QString &title)
if (QWindowsContext::verboseWindows) if (QWindowsContext::verboseWindows)
qDebug() << __FUNCTION__ << this << window() <<title; qDebug() << __FUNCTION__ << this << window() <<title;
if (m_data.hwnd) { if (m_data.hwnd) {
const QString fullTitle = formatWindowTitle(title, QStringLiteral(" - "));
QString fullTitle = title;
if (QGuiApplicationPrivate::displayName) {
// Append display name, if set.
if (!fullTitle.isEmpty())
fullTitle += QStringLiteral(" - ");
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();
}
SetWindowText(m_data.hwnd, (const wchar_t*)fullTitle.utf16()); SetWindowText(m_data.hwnd, (const wchar_t*)fullTitle.utf16());
} }
} }

View File

@ -1122,18 +1122,8 @@ void QXcbWindow::setParent(const QPlatformWindow *parent)
void QXcbWindow::setWindowTitle(const QString &title) void QXcbWindow::setWindowTitle(const QString &title)
{ {
QString fullTitle = title; const QString fullTitle = formatWindowTitle(title, QString::fromUtf8(" \xe2\x80\x94 ")); // unicode character U+2014, EM DASH
if (QGuiApplicationPrivate::displayName) {
// Append display name, if set.
if (!fullTitle.isEmpty())
fullTitle += QString::fromUtf8(" \xe2\x80\x94 "); // unicode character U+2014, EM DASH
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();
}
const QByteArray ba = fullTitle.toUtf8(); const QByteArray ba = fullTitle.toUtf8();
Q_XCB_CALL(xcb_change_property(xcb_connection(), Q_XCB_CALL(xcb_change_property(xcb_connection(),
XCB_PROP_MODE_REPLACE, XCB_PROP_MODE_REPLACE,
m_window, m_window,