示例#1
0
void MainWindow::W7ToolbarSetImages() {
    QPixmap img;
    QBitmap mask;
    HIMAGELIST himl = ImageList_Create(20, 20, ILC_COLOR32, 4, 0);

    img = QIcon(":/back.png").pixmap(20);
    mask  = img.createMaskFromColor(Qt::transparent);
    ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha), mask.toWinHBITMAP());

    img = QIcon(":/play.png").pixmap(20);
    mask  = img.createMaskFromColor(Qt::transparent);
    ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha), mask.toWinHBITMAP());

    img = QIcon(":/forward.png").pixmap(20);
    mask  = img.createMaskFromColor(Qt::transparent);
    ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha), mask.toWinHBITMAP());

    img = QIcon(":/pause.png").pixmap(20);
    mask  = img.createMaskFromColor(Qt::transparent);
    ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha), mask.toWinHBITMAP());

    if (m_w7toolbar) m_w7toolbar->ThumbBarSetImageList(this->winId(), himl);

    ImageList_Destroy(himl);
}
示例#2
0
void EmfPaintEngine::drawImage(const QRectF & r, const QImage & image, const QRectF &, Qt::ImageConversionFlags flags)
{
	QMatrix m = painter()->worldMatrix();
	QPointF p = m.map(r.topLeft());
	int x = qRound(p.x());
	int y = qRound(p.y());
	int width = qRound(r.width());
	int height = qRound(r.height());

#ifdef Q_WS_WIN
	setClipping();
	QPixmap pix = QPixmap::fromImage (image.scaled(width, height), flags);

	HBITMAP hbtmp = pix.toWinHBITMAP();
	HDC hDC = CreateCompatibleDC(metaDC);
    SelectObject(hDC, hbtmp);
    BitBlt(metaDC, x, y, width, height, hDC, 0, 0, SRCCOPY);
    DeleteObject(hbtmp);
    DeleteDC(hDC);

	resetClipping();
#else
	QImage imag = image.scaled(width, height);
	for (int i = 0; i < width; i++){
		for (int j = 0; j < height; j++){
			QRgb rgb = imag.pixel(i, j);
			if (qAlpha(rgb) == 255)
				SetPixel(metaDC, x + i, y + j, RGB(qRed(rgb), qGreen(rgb), qBlue(rgb)));
		}
	}
#endif
}
示例#3
0
void EmfPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap & pix, const QPointF &)
{
	setClipping();

#ifdef Q_WS_WIN
	HBITMAP hBmp = pix.toWinHBITMAP();
	HBRUSH wbrush = CreatePatternBrush(hBmp);

	QMatrix m = painter()->worldMatrix();
	QRectF dr = m.mapRect(r);

	RECT rect;
	rect.left = qRound(dr.left());
	rect.top = qRound(dr.top());
	rect.right = qRound(dr.right());
	rect.bottom = qRound(dr.bottom());

	FillRect(metaDC, &rect, wbrush);

	DeleteObject(hBmp);
	DeleteObject(wbrush);
#else
	int width = qRound(r.width());
	int height = qRound(r.height());

	QPixmap pixmap(width, height);
	QPainter p(&pixmap);
	p.drawTiledPixmap(0, 0, width, height, pix);
	p.end();

	drawPixmap(r, pixmap, QRectF());
#endif

	resetClipping();
}
void IntegratedMainWindow::sendPreviewInternal()
{
    QPixmap pix = sendPreview();
    if (!pix.isNull())
    {
        HBITMAP hBitmap = pix.toWinHBITMAP();
        DwmSetIconicLivePreviewBitmap(winId(), hBitmap, 0, d->m_windowFrameForIconicThumbnails ? DWM_SIT_DISPLAYFRAME : 0);
        if (hBitmap)
        {
            DeleteObject(hBitmap);
        }
    }
}
/*!
    Sends the image that will appear as the window's iconic thumbnail.

    The image should not be larger than 200 by 108 pixels but will be
    scaled down preserving aspect ratio if necessary. To use the Windows
    default iconic thumbnail (an image of the window itself) pass a
    null pixmap.
 */
void IntegratedMainWindow::sendThumbnailInternal()
{
    QPixmap pix = sendThumbnail();
    if (!pix.isNull())
    {
        // If our image is larger than Windows said it could be in winEvent, scale it down
        if (pix.width() > d->m_maxThumbnailSize.width() || pix.height() > d->m_maxThumbnailSize.height())
        {
            pix = pix.scaled(d->m_maxThumbnailSize, Qt::KeepAspectRatio);
        }

        // Assert that our image does not exceed either of Windows' requested maximum dimensions
        Q_ASSERT(pix.width() <= d->m_maxThumbnailSize.width() && pix.height() <= d->m_maxThumbnailSize.height());

        // Convert our pixmap to Windows bitmap and send it to the DWM
        HBITMAP hBitmap = pix.toWinHBITMAP();
        DwmSetIconicThumbnail(winId(), hBitmap, d->m_windowFrameForIconicThumbnails ? DWM_SIT_DISPLAYFRAME : 0);
        if (hBitmap)
        {
            DeleteObject(hBitmap);
        }
    }
}
示例#6
0
void MainInterface::createTaskBarButtons()
{
    taskbar_wmsg = WM_NULL;
    /*Here is the code for the taskbar thumb buttons
    FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
    FIXME:the play button's picture doesn't changed to pause when clicked
    */

    CoInitialize( 0 );

    if( S_OK == CoCreateInstance( CLSID_TaskbarList,
                NULL, CLSCTX_INPROC_SERVER,
                IID_ITaskbarList3,
                (void **)&p_taskbl) )
    {
        p_taskbl->HrInit();

        if( (himl = ImageList_Create( 20, //cx
                        20, //cy
                        ILC_COLOR32,//flags
                        4,//initial nb of images
                        0//nb of images that can be added
                        ) ) != NULL )
        {
            QPixmap img   = QPixmap(":/win7/prev");
            QPixmap img2  = QPixmap(":/win7/pause");
            QPixmap img3  = QPixmap(":/win7/play");
            QPixmap img4  = QPixmap(":/win7/next");
            QBitmap mask  = img.createMaskFromColor(Qt::transparent);
            QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
            QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
            QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);

            if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
                msg_Err( p_intf, "First ImageList_Add failed" );
            if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
                msg_Err( p_intf, "Second ImageList_Add failed" );
            if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
                msg_Err( p_intf, "Third ImageList_Add failed" );
            if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
                msg_Err( p_intf, "Fourth ImageList_Add failed" );
        }

        // Define an array of two buttons. These buttons provide images through an
        // image list and also provide tooltips.
        THUMBBUTTONMASK dwMask = THUMBBUTTONMASK(THB_BITMAP | THB_FLAGS);

        THUMBBUTTON thbButtons[3];
        thbButtons[0].dwMask = dwMask;
        thbButtons[0].iId = 0;
        thbButtons[0].iBitmap = 0;
        thbButtons[0].dwFlags = THBF_HIDDEN;

        thbButtons[1].dwMask = dwMask;
        thbButtons[1].iId = 1;
        thbButtons[1].iBitmap = 2;
        thbButtons[1].dwFlags = THBF_HIDDEN;

        thbButtons[2].dwMask = dwMask;
        thbButtons[2].iId = 2;
        thbButtons[2].iBitmap = 3;
        thbButtons[2].dwFlags = THBF_HIDDEN;

        HRESULT hr = p_taskbl->ThumbBarSetImageList(winId(), himl );
        if(S_OK != hr)
            msg_Err( p_intf, "ThumbBarSetImageList failed with error %08lx", hr );
        else
        {
            hr = p_taskbl->ThumbBarAddButtons(winId(), 3, thbButtons);
            if(S_OK != hr)
                msg_Err( p_intf, "ThumbBarAddButtons failed with error %08lx", hr );
        }
        CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, changeThumbbarButtons( int ) );
    }
static HCURSOR create32BitCursor(const QPixmap &pixmap, int hx, int hy)
{
    HCURSOR cur = 0;
#if !defined(Q_WS_WINCE)
    QBitmap mask = pixmap.mask();
    if (mask.isNull()) {
        mask = QBitmap(pixmap.size());
        mask.fill(Qt::color1);
    }

    HBITMAP ic = pixmap.toWinHBITMAP(QPixmap::Alpha);
    HBITMAP im = qt_createIconMask(mask);

    ICONINFO ii;
    ii.fIcon     = 0;
    ii.xHotspot  = hx;
    ii.yHotspot  = hy;
    ii.hbmMask   = im;
    ii.hbmColor  = ic;

    cur = CreateIconIndirect(&ii);

    DeleteObject(ic);
    DeleteObject(im);
#elif defined(GWES_ICONCURS)
    QImage bbits, mbits;
    bool invb, invm;
    bbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
    mbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
    invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1));
    invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1));

    int sysW = GetSystemMetrics(SM_CXCURSOR);
    int sysH = GetSystemMetrics(SM_CYCURSOR);
    int sysN = qMax(1, sysW / 8);
    int n = qMax(1, bbits.width() / 8);
    int h = bbits.height();

    uchar* xBits = new uchar[sysH * sysN];
    uchar* xMask = new uchar[sysH * sysN];
    int x = 0;
    for (int i = 0; i < sysH; ++i) {
        if (i >= h) {
            memset(&xBits[x] , 255, sysN);
            memset(&xMask[x] ,   0, sysN);
            x += sysN;
        } else {
            int fillWidth = n > sysN ? sysN : n;
            uchar *bits = bbits.scanLine(i);
            uchar *mask = mbits.scanLine(i);
            for (int j = 0; j < fillWidth; ++j) {
                uchar b = bits[j];
                uchar m = mask[j];
                if (invb)
                    b ^= 0xFF;
                if (invm)
                    m ^= 0xFF;
                xBits[x] = ~m;
                xMask[x] = b ^ m;
                ++x;
            }
            for (int j = fillWidth; j < sysN; ++j ) {
                xBits[x] = 255;
                xMask[x] = 0;
                ++x;
            }
        }
    }

    cur = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH,
        xBits, xMask);
#else
    Q_UNUSED(pixmap);
    Q_UNUSED(hx);
    Q_UNUSED(hy);
#endif
    return cur;
}
static HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0)
{
    return p.toWinHBITMAP((enum QBitmap::HBitmapFormat)hbitmapFormat);
}