From 3fa77de5c97ed120ee519240481f57cc308d077b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 1 Mar 2013 17:08:03 +0100 Subject: Aero-Style-QWizard: Fix drawing when used as a child widget. Introduce function to retrieve HDC with transformation. Paint Vista-style items at correct location when used as a child widget (for example, in Qt Designer). Disable special drawing that works only for top-levels. Task-number: QTBUG-29904 Change-Id: Ic902fd30e8050317b24ab7f7e2757ef1e16407f9 Reviewed-by: Joerg Bornemann Reviewed-by: Oliver Wolff --- src/widgets/dialogs/qwizard_win.cpp | 44 ++++++++++++++++++++++++++----------- src/widgets/dialogs/qwizard_win_p.h | 2 ++ 2 files changed, 33 insertions(+), 13 deletions(-) (limited to 'src/widgets/dialogs') diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 2586ced60f..30ee0e32a9 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -221,9 +221,11 @@ void QVistaBackButton::paintEvent(QPaintEvent *) QRect r = rect(); HANDLE theme = pOpenThemeData(0, L"Navigation"); //RECT rect; + QPoint origin; + const HDC hdc = QVistaHelper::backingStoreDC(parentWidget(), &origin); RECT clipRect; - int xoffset = QWidget::mapToParent(r.topLeft()).x() - 1; - int yoffset = QWidget::mapToParent(r.topLeft()).y() - 1; + int xoffset = origin.x() + QWidget::mapToParent(r.topLeft()).x() - 1; + int yoffset = origin.y() + QWidget::mapToParent(r.topLeft()).y() - 1; clipRect.top = r.top() + yoffset; clipRect.bottom = r.bottom() + yoffset; @@ -238,8 +240,6 @@ void QVistaBackButton::paintEvent(QPaintEvent *) else if (underMouse()) state = WIZ_NAV_BB_HOT; - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - HDC hdc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore())); pDrawThemeBackground(theme, hdc, WIZ_NAV_BACKBUTTON, state, &clipRect, &clipRect); } @@ -358,11 +358,11 @@ Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); void QVistaHelper::drawTitleBar(QPainter *painter) { Q_ASSERT(backButton_); - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - QBackingStore *backingStore = backButton_->backingStore(); - HDC hdc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); + QPoint origin; + const bool isWindow = wizard->isWindow(); + const HDC hdc = QVistaHelper::backingStoreDC(wizard, &origin); - if (vistaState() == VistaAero) + if (vistaState() == VistaAero && isWindow) drawBlackRect(QRect(0, 0, wizard->width(), titleBarSize() + topOffset()), hdc); const int btnTop = backButton_->mapToParent(QPoint()).y(); @@ -383,14 +383,20 @@ void QVistaHelper::drawTitleBar(QPainter *painter) glowOffset = glowSize(); } - drawTitleText( - painter, text, - QRect(titleOffset() - glowOffset, verticalCenter - textHeight / 2, textWidth, textHeight), - hdc); + const QRect textRectangle(titleOffset() - glowOffset, verticalCenter - textHeight / 2, textWidth, textHeight); + if (isWindow) { + drawTitleText(painter, text, textRectangle, hdc); + } else { + painter->save(); + painter->setFont(font); + painter->drawText(textRectangle, Qt::AlignVCenter | Qt::AlignHCenter, text); + painter->restore(); + } const QIcon windowIcon = wizard->windowIcon(); if (!windowIcon.isNull()) { - QRect rect(leftMargin(), verticalCenter - iconSize() / 2, iconSize(), iconSize()); + const QRect rect(origin.x() + leftMargin(), + origin.y() + verticalCenter - iconSize() / 2, iconSize(), iconSize()); const HICON hIcon = qt_pixmapToWinHICON(windowIcon.pixmap(iconSize())); DrawIconEx(hdc, rect.left(), rect.top(), hIcon, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT); DestroyIcon(hIcon); @@ -642,6 +648,18 @@ HFONT QVistaHelper::getCaptionFont(HANDLE hTheme) return CreateFontIndirect(&lf); } +// Return a HDC for the wizard along with the transformation if the +// wizard is a child window. +HDC QVistaHelper::backingStoreDC(const QWidget *wizard, QPoint *offset) +{ + HDC hdc = static_cast(QGuiApplication::platformNativeInterface()->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), wizard->backingStore())); + *offset = QPoint(0, 0); + if (!wizard->windowHandle()) + if (QWidget *nativeParent = wizard->nativeParentWidget()) + *offset = wizard->mapTo(nativeParent, *offset); + return hdc; +} + HWND QVistaHelper::wizardHWND() const { // Obtain the HWND if the wizard is a top-level window. diff --git a/src/widgets/dialogs/qwizard_win_p.h b/src/widgets/dialogs/qwizard_win_p.h index 80d437bc23..badaab52d9 100644 --- a/src/widgets/dialogs/qwizard_win_p.h +++ b/src/widgets/dialogs/qwizard_win_p.h @@ -107,6 +107,8 @@ public: } static int topOffset(); + static HDC backingStoreDC(const QWidget *wizard, QPoint *offset); + private: static HFONT getCaptionFont(HANDLE hTheme); HWND wizardHWND() const; -- cgit v1.2.3