示例#1
0
void QXcbNativeBackingStore::resize(const QSize &size, const QRegion &staticContents)
{
    if (size == m_pixmap.size())
        return;

    QPixmap newPixmap(size);

#if QT_CONFIG(xrender)
    if (m_translucentBackground && newPixmap.depth() != 32)
        qt_x11Pixmap(newPixmap)->convertToARGB32();
#endif

    if (!m_pixmap.isNull()) {
        Pixmap from = qt_x11PixmapHandle(m_pixmap);
        Pixmap to = qt_x11PixmapHandle(newPixmap);
        QRect br = staticContents.boundingRect().intersected(QRect(QPoint(0, 0), size));

        if (!br.isEmpty()) {
            GC gc = XCreateGC(display(), to, 0, Q_NULLPTR);
            XCopyArea(display(), from, to, gc, br.x(), br.y(), br.width(), br.height(), br.x(), br.y());
            XFreeGC(display(), gc);
        }
    }

    m_pixmap = newPixmap;
}
QThemedImageButton::QThemedImageButton(const QString& iconPath, QWidget *parent)
    : QPushButton(parent), resizeImageValue(false)
{
    if (QFile::exists(iconPath)) {
        QPixmap iconPixmap(iconPath);
        auto iconMask = iconPixmap.createMaskFromColor(Qt::transparent, Qt::MaskInColor);

        QPixmap newPixmap(iconPixmap.size());
        newPixmap.fill(this->palette().foreground().color());
        newPixmap.setMask(iconMask);

        this->setIcon(newPixmap);
    }

    else {
        qDebug() << "QThemedImageButton(Could not load icon: " << iconPath << ")";
    }
}
示例#3
0
文件: QVideo.cpp 项目: dtbinh/dviz
void QVideo::displayFrame()
{
	//qDebug("    END frame: %d",m_frame_counter);
        
        if(status() != Running)
	{
		//qDebug("Not running, not showing frame");
		return;
	}
        //qDebug("Done sleeping, showing next frame");

        int xflag = 0;
	if(m_expectedDelay == 0)
		m_expectedDelay = 10;
        if(m_frameDebug.elapsed() > m_expectedDelay * 3)
        {
            //qDebug(" * * * %s: elapsed: %d, expected: %d", qPrintable(m_filename), m_frameDebug.elapsed(), m_expectedDelay);
            xflag ++;
        }

//         if(m_frame_counter - m_last_frame_shown > 1)
//         {
//             qDebug("*************** DROPED %d",m_frame_counter - m_last_frame_shown);
//         }

        m_last_frame_shown = m_frame_counter;
/*        if(m_curImage)
        {*/
// 		qDebug() << "m_current_frame.frame:"<<m_current_frame.frame;
// 		QImage img = *m_current_frame.frame;
		if(m_curImage.height() > 0 && m_curImage.width() > 0)
		{
			emit newPixmap(QPixmap::fromImage(m_curImage));
		}
	
		//delete m_current_frame.frame;
		//m_current_frame.frame = 0;
	
		//consumeFrame();
// 	}
	//resume playing
	if(status() == Running)
		m_play_timer = startTimer(1);
}
示例#4
0
void RedirectedXCompositeWindow::createNewPixampAndPixampSurface()
{
    // This should never be called with an empty size (not in Accelerated Compositing mode).
    ASSERT(!m_size.isEmpty());
    XUniquePixmap newPixmap(XCompositeNameWindowPixmap(m_display, m_window.get()));
    if (!newPixmap) {
        cleanupPixmapAndPixmapSurface();
        return;
    }

    XWindowAttributes windowAttributes;
    if (!XGetWindowAttributes(m_display, m_window.get(), &windowAttributes)) {
        cleanupPixmapAndPixmapSurface();
        return;
    }

    RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap.get(), windowAttributes.visual, m_size.width(), m_size.height()));
    cairoSurfaceSetDeviceScale(newSurface.get(), m_webPage.deviceScaleFactor(), m_webPage.deviceScaleFactor());

    RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get()));
    if (!m_webPage.drawsBackground())
        cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR);
    else
        setSourceRGBAFromColor(cr.get(), m_webPage.backgroundColor());
    cairo_paint(cr.get());

    // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions
    // of a second after each resize, while doing continuous resizing (which constantly destroys and creates
    // pixmap window-backings), the pixmap memory is uninitialized. To work around this issue, paint the old
    // pixmap to the new one to properly initialize it.
    if (m_surface) {
        cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER);
        cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0);
        cairo_paint(cr.get());
    }

    cleanupPixmapAndPixmapSurface();
    m_pixmap = WTFMove(newPixmap);
    m_surface = WTFMove(newSurface);
}
示例#5
0
void VideoProvider::connectInput(int iIdx, QObject * receiver, const char * method)
{
    // safety check
    if (iIdx < 0 || iIdx >= m_inputs.size() || !receiver || !method) {
        qWarning("VideoProvider::connectInput: fail");
        return;
    }

    // connect input
    VideoInput * input = m_inputs[iIdx];
    if (!connect(input, SIGNAL(newPixmap(QPixmap)), receiver, method)) {
        qWarning("VideoProvider::connectInput: error connecting input %d to %s", iIdx, method);
        return;
    }

    // add it to the receivers list (for ref. counting only)
    input->receivers.append(receiver);

    // start the video if we're the first
    if (!input->active) {
        // start the video
#if defined(HAS_VIDEOCAPTURE)
        input->device->setSize(input->device->maxWidth(), input->device->maxHeight());
        input->device->startCapturing();
#else
        // TODO
#endif

        // mark as active
        input->active = true;
    }

    // start the capture timer if needed
    if (!m_snapTimer) {
        m_snapTimer = new QTimer(this);
        connect(m_snapTimer, SIGNAL(timeout()), this, SLOT(slotCaptureVideoFrames()));
        m_snapTimer->start(50);
    }
}
示例#6
0
void ColorPicker::changeColorWheel(ELayoutColorPicker oldLayout, ELayoutColorPicker newLayout, bool skipAnimation) {

    //------------------
    // get resources
    //------------------

    // get paths to resources for two color wheels
    QString oldLayoutResource = getWheelPixmapPath(oldLayout);
    QString newLayoutResource = getWheelPixmapPath(newLayout);

    // get pixmaps for two color wheels
    QPixmap oldPixmap(oldLayoutResource);
    QPixmap newPixmap(newLayoutResource);

    //------------------
    // resize and set pixmaps
    //------------------
    int wheelSize = int(this->size().height() * 0.55f);
    if (wheelSize > this->size().width() * 0.85f) {
        wheelSize = int(this->size().width() * 0.85f);
    }
    mTempWheel->setPixmap(oldPixmap.scaled(wheelSize,
                                           wheelSize,
                                           Qt::KeepAspectRatio,
                                           Qt::SmoothTransformation));
    mColorWheel->setPixmap(newPixmap.scaled(wheelSize,
                                            wheelSize,
                                            Qt::KeepAspectRatio,
                                            Qt::SmoothTransformation));


    const int animationMsec = 250;

    //------------------
    // Animate if needed
    //------------------

    if (!skipAnimation) {
        // check if a new color wheel is being added. if the two resources don't match
        // do a fade in/fade out between the color wheels.
        if (oldLayoutResource.compare(newLayoutResource) != 0) {
            // make temp wheel visible and overlapping the color wheel
            mTempWheel->setVisible(true);
            mTempWheel->setGeometry(mColorWheel->geometry());

            auto fadeOutEffect = new QGraphicsOpacityEffect(mTempWheel);
            mTempWheel->setGraphicsEffect(fadeOutEffect);
            auto fadeOutAnimation = new QPropertyAnimation(fadeOutEffect, "opacity");
            fadeOutAnimation->setDuration(animationMsec);
            fadeOutAnimation->setStartValue(mWheelOpacity);
            fadeOutAnimation->setEndValue(0.0f);
            connect(fadeOutAnimation, SIGNAL(finished()), this, SLOT(hideTempWheel()));

            auto fadeInEffect = new QGraphicsOpacityEffect(mColorWheel);
            mColorWheel->setGraphicsEffect(fadeInEffect);
            auto fadeInAnimation = new QPropertyAnimation(fadeInEffect, "opacity");
            fadeInAnimation->setDuration(animationMsec);
            fadeInAnimation->setStartValue(0.0f);
            mWheelOpacity = 1.0;
            // catch edge case wehre multi color picker is sometimes disabled by default
            if (newLayout == ELayoutColorPicker::multiColorLayout
                    && (mCustomColorPicker->palette()->selectedCount() == 0)) {
                mWheelOpacity = 0.333;
            }
            fadeInAnimation->setEndValue(mWheelOpacity);

            auto group = new QParallelAnimationGroup;
            group->addAnimation(fadeInAnimation);
            group->addAnimation(fadeOutAnimation);
            group->start(QAbstractAnimation::DeleteWhenStopped);
        } else if (mCustomColorPicker->palette()->selectedCount() == 0
                       && (newLayout == ELayoutColorPicker::multiColorLayout
                           || oldLayout == ELayoutColorPicker::multiColorLayout)
                       && (newLayout != oldLayout)) {
            mTempWheel->setVisible(false);

            // If the resources match but its either changing from or changing to a multi layout
            // and no indices are selected so the multi layout should be opaque.
            float startOpacity;
            // don't need two animations, just do one.
            if (newLayout == ELayoutColorPicker::multiColorLayout) {
                startOpacity = 1.0f;
                mWheelOpacity = 0.333;
            } else if (oldLayout == ELayoutColorPicker::multiColorLayout) {
                startOpacity = 0.333f;
                mWheelOpacity = 1.0;
            } else {
                startOpacity = 0.0f;
                mWheelOpacity = 0.0;
                qDebug() << "WARNING: shouldn't get here...";
            }

            if (oldLayout == ELayoutColorPicker::multiColorLayout) {
                // just set opacity here immediately cause of weird bug...
                mWheelOpacity = 1.0;
                // un-fade out the wheel
                auto effect = new QGraphicsOpacityEffect(mColorWheel);
                effect->setOpacity(mWheelOpacity);
                mColorWheel->setGraphicsEffect(effect);
            } else {
                auto fadeEffect = new QGraphicsOpacityEffect(mColorWheel);
                mColorWheel->setGraphicsEffect(fadeEffect);
                auto fadeAnimation = new QPropertyAnimation(fadeEffect, "opacity");
                fadeAnimation->setDuration(animationMsec);
                fadeAnimation->setStartValue(startOpacity);
                fadeAnimation->setEndValue(mWheelOpacity);
                fadeAnimation->start();
            }

        }
    } else {
        mTempWheel->setVisible(false);
    }

}