Beispiel #1
0
void
Thumbnail::paintOverImage(
    QPainter& painter, QTransform const& image_to_display,
    QTransform const& thumb_to_display)
{
    if (m_contentRect.isNull()) {
        return;
    }

    painter.setRenderHint(QPainter::Antialiasing, false);

    QPen pen(QColor(0x00, 0x00, 0xff));
    pen.setWidth(1);
    pen.setCosmetic(true);
    painter.setPen(pen);

    painter.setBrush(QColor(0x00, 0x00, 0xff, 50));

    QRectF content_rect(imageToThumb().mapRect(m_contentRect));

    // Adjust to compensate for pen width.
    content_rect.adjust(-1, -1, 1, 1);

    // toRect() is necessary because we turn off antialiasing.
    // For some reason, if we let Qt round the coordinates,
    // the result is slightly different.
    painter.drawRect(content_rect.toRect());
}
void
CImageButtonWithStyle::OnNotifyCustomDraw (NMHDR * pNotifyStruct, LRESULT* result)
{
	LPNMCUSTOMDRAW pCustomDraw = (LPNMCUSTOMDRAW) pNotifyStruct;
	ASSERT(pCustomDraw->hdr.hwndFrom == m_hWnd);
	ASSERT(pCustomDraw->hdr.code = NM_CUSTOMDRAW);

	DWORD style = GetStyle();
	if ((style & (BS_BITMAP | BS_ICON)) == 0 || !g_xpStyle.IsAppThemed() || !g_xpStyle.IsThemeActive())
	{
		// not icon or bitmap button, or themes not active - draw normally
		*result = CDRF_DODEFAULT;
		return;
	}

	if (pCustomDraw->dwDrawStage == CDDS_PREERASE)
		// erase background (according to parent window's themed background
		g_xpStyle.DrawThemeParentBackground(m_hWnd, pCustomDraw->hdc, &pCustomDraw->rc);

	if (pCustomDraw->dwDrawStage == CDDS_PREERASE || pCustomDraw->dwDrawStage == CDDS_PREPAINT)
	{
		// get theme handle
		HTHEME hTheme = g_xpStyle.OpenThemeData(m_hWnd, L"BUTTON");
		ASSERT(hTheme != NULL);
		if (hTheme == NULL)
		{
			// fail gracefully
			*result = CDRF_DODEFAULT;
			return;
		}

		// determine state for DrawThemeBackground()
		// note: order of these tests is significant
		int state_id = PBS_NORMAL;

		if (style & WS_DISABLED)
			state_id = PBS_DISABLED;
		else if (pCustomDraw->uItemState & CDIS_SELECTED)
			state_id = PBS_PRESSED;
		else if (pCustomDraw->uItemState & CDIS_HOT)
			state_id = PBS_HOT;
		else if (GetCheck())//T4: Added Checkbox support
			state_id = PBS_PRESSED;
		else if (style & BS_DEFPUSHBUTTON)
			state_id = PBS_DEFAULTED;

		// draw themed button background appropriate to button state
		g_xpStyle.DrawThemeBackground(hTheme,
		                              pCustomDraw->hdc, BP_PUSHBUTTON,
		                              state_id,
		                              &pCustomDraw->rc, NULL);

		// get content rectangle (space inside button for image)
		CRect content_rect(pCustomDraw->rc);
		g_xpStyle.GetThemeBackgroundContentRect(hTheme,
		                                        pCustomDraw->hdc, BP_PUSHBUTTON,
		                                        state_id,
		                                        &pCustomDraw->rc,
		                                        &content_rect);
		// we're done with the theme
		g_xpStyle.CloseThemeData(hTheme);

		// draw the image
		if (style & BS_BITMAP)
		{
			draw_bitmap(pCustomDraw->hdc, &content_rect, style);
		}
		else
		{
			ASSERT(style & BS_ICON);                // since we bailed out at top otherwise
			draw_icon(pCustomDraw->hdc, &content_rect, style);
		}

		// finally, draw the focus rectangle if needed
		//T4: We don't need focus here
		/*if (pCustomDraw->uItemState & CDIS_FOCUS)
		   {
		        // draw focus rectangle
		        DrawFocusRect (pCustomDraw->hdc, &content_rect);
		   }*/

		*result = CDRF_SKIPDEFAULT;
		return;
	}

	// we should never get here, since we should only get CDDS_PREERASE or CDDS_PREPAINT
	ASSERT(false);
	*result = CDRF_DODEFAULT;
}