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 <joerg.bornemann@digia.com>
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
This commit is contained in:
Friedemann Kleint 2013-03-01 17:08:03 +01:00 committed by The Qt Project
parent 872a84c2e6
commit 3fa77de5c9
2 changed files with 33 additions and 13 deletions

View File

@ -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<HDC>(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<HDC>(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<HDC>(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.

View File

@ -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;