QQuickItemGrabResult *QQuickItemGrabResultPrivate::create(QQuickItem *item, const QSize &targetSize)
{
    QSize size = targetSize;
    if (size.isEmpty())
        size = QSize(item->width(), item->height());

    if (size.width() < 1 || size.height() < 1) {
        qWarning("Item::grabToImage: item has invalid dimensions");
        return 0;
    }

    if (!item->window()) {
        qWarning("Item::grabToImage: item is not attached to a window");
        return 0;
    }

    if (!item->window()->isVisible()) {
        qWarning("Item::grabToImage: item's window is not visible");
        return 0;
    }

    QQuickItemGrabResult *result = new QQuickItemGrabResult();
    QQuickItemGrabResultPrivate *d = result->d_func();
    d->item = item;
    d->window = item->window();
    d->textureSize = size;

    QQuickItemPrivate::get(item)->refFromEffectItem(false);

    // trigger sync & render
    item->window()->update();

    return result;
}
Exemple #2
0
QWKPage::ViewportAttributes QWKPage::viewportAttributesForSize(const QSize& availableSize) const
{
    static int desktopWidth = 980;
    static int deviceDPI = 160;

    ViewportAttributes result;

    if (availableSize.isEmpty())
        return result; // Returns an invalid instance.

    // FIXME: Add a way to get these data via the platform plugin and fall back
    // to the size of the view.
    int deviceWidth = 480;
    int deviceHeight = 864;

    WebCore::ViewportAttributes conf = WebCore::computeViewportAttributes(d->viewportArguments, desktopWidth, deviceWidth, deviceHeight, deviceDPI, availableSize);

    result.m_isValid = true;
    result.m_size = conf.layoutSize;
    result.m_initialScaleFactor = conf.initialScale;
    result.m_minimumScaleFactor = conf.minimumScale;
    result.m_maximumScaleFactor = conf.maximumScale;
    result.m_devicePixelRatio = conf.devicePixelRatio;
    result.m_isUserScalable = static_cast<bool>(conf.userScalable);

    return result;
}
//virtual
void PixmapFilmstripObject::createFrames(const QSize& frameSize,quint32 numFrames,FrameDirection::Enum direction,const QPoint& startOffset)
{
	if ((numFrames == 0) || (direction == FrameDirection::INVALID) || frameSize.isEmpty() || (!frameSize.isValid()))
	{
		return;
	}
	QPoint adder;
	switch (direction)
	{
	case FrameDirection::North:
		adder = QPoint(0,-frameSize.height());
		break;
	case FrameDirection::South:
		adder = QPoint(0,frameSize.height());
		break;
	case FrameDirection::East:
		adder = QPoint(-frameSize.width(),0);
		break;
	case FrameDirection::West:
		adder = QPoint(frameSize.width(),0);
	default:
		break;
	}
	QPoint currentOrigin = startOffset;
	QList<QRect> frameCoordinates;
	for (quint32 i = 0;i<numFrames;++i,currentOrigin+=adder)
	{
		frameCoordinates << QRect(currentOrigin,frameSize);
	}
	createFrames(frameCoordinates);
}
Exemple #4
0
int main(int argc, char **argv)
{
    LXQt::SingleApplication app(argc, argv);
    app.setOrganizationName(QStringLiteral("lxqt"));
    app.setApplicationName(QStringLiteral("lxqt-config"));
    app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);

    QCommandLineParser parser;
    parser.setApplicationDescription(QStringLiteral("LXQt Config"));
    const QString VERINFO = QStringLiteral(LXQT_CONFIG_VERSION
                                           "\nliblxqt   " LXQT_VERSION
                                           "\nQt        " QT_VERSION_STR);
    app.setApplicationVersion(VERINFO);
    parser.addVersionOption();
    parser.addHelpOption();
    parser.process(app);

    // ensure that we use lxqt-config.menu file.
    qputenv("XDG_MENU_PREFIX", "lxqt-");

    LXQtConfig::MainWindow w;
    app.setActivationWindow(&w);
    QSize s = QSettings{}.value("size").toSize();
    if (!s.isEmpty())
        w.resize(s);
    w.show();

    int ret = app.exec();

    QSettings{}.setValue("size", w.size());

    return ret;
}
/******************************************************************************
* Return the minimum size for the tab, adjusted if necessary to a height that
* fits the screen.
* In order to make the QStackedWidget containing the tabs take the correct
* size, the value returned is actually the minimum size of the largest tab.
* Otherwise, only the currently visible tab would be taken into account with
* the result that the dialog would initially be displayed too small.
*/
QSize StackedScrollGroup::minimumSizeHint() const
{
    QSize s = maxMinimumSizeHint();
    if (!s.isEmpty()  &&  mMinHeight > 0  &&  mMinHeight < s.height())
        return QSize(s.width() + mWidgets[0]->style()->pixelMetric(QStyle::PM_ScrollBarExtent), mMinHeight);
    return s;
}
Exemple #6
0
/** Restores the last size and location of the window. */
void
VidaliaWindow::restoreWindowState()
{
#if QT_VERSION >= 0x040200
  QByteArray geometry = getSetting("Geometry", QByteArray()).toByteArray();
  if (geometry.isEmpty())
    adjustSize();
  else
    restoreGeometry(geometry);
#else
  QRect screen = QDesktopWidget().availableGeometry();

  /* Restore the window size. */
  QSize size = getSetting("Size", QSize()).toSize();
  if (!size.isEmpty()) {
    size = size.boundedTo(screen.size());
    resize(size);
  }

  /* Restore the window position. */
  QPoint pos = getSetting("Position", QPoint()).toPoint();
  if (!pos.isNull() && screen.contains(pos)) {
    move(pos);
  }
#endif
}
bool WebPage::render(const QString &fileName, const QSize &minimumSize) {
  QFileInfo fileInfo(fileName);
  QDir dir;
  dir.mkpath(fileInfo.absolutePath());

  QSize viewportSize = this->viewportSize();
  this->setViewportSize(minimumSize);
  QSize pageSize = this->mainFrame()->contentsSize();
  if (pageSize.isEmpty()) {
    return false;
  }

  QImage buffer(pageSize, QImage::Format_ARGB32);
  buffer.fill(qRgba(255, 255, 255, 0));

  QPainter p(&buffer);
  p.setRenderHint( QPainter::Antialiasing,          true);
  p.setRenderHint( QPainter::TextAntialiasing,      true);
  p.setRenderHint( QPainter::SmoothPixmapTransform, true);

  this->setViewportSize(pageSize);
  this->mainFrame()->render(&p);

  QImage pointer = QImage(":/pointer.png");
  p.drawImage(m_mousePosition, pointer);

  p.end();
  this->setViewportSize(viewportSize);

  return buffer.save(fileName);
}
QImageLoadThreadPool::PATH_STATUS QImageLoadThreadPool::load(QString path, int &bytesLoaded) {
    PATH_STATUS status = PATH_NULL;
    controlInternal.lock();
    if (workers.length() < 3) {
        bool gtg = true;
        for (LoadThread &lt : workers) {
            if (lt.first == path) gtg = false;
        }
        if (gtg) {
            QImageReader imgTest(path);
            QSize tSize = imgTest.size();
            if (tSize.isEmpty()) {
                status = PATH_FAILURE;
            } else {
                int bytesToLoad = tSize.width() * tSize.height() * 4;
                if (bytesLoaded + bytesToLoad > maxBytes) {
                    status = PATH_INSUFFICIENT_MEMORY;
                } else {
                    bytesLoaded += bytesToLoad;
                    workers.append(LoadThread(path, new std::thread(std::bind(&QImageLoadThreadPool::internalThreadRun, this, path))));
                    status = PATH_SUCCESS;
                }
            }
        } else {
            status = PATH_ALREADY_LOADING;
        }
    } else {
        status = PATH_MAX_WORKERS;
    }
    controlInternal.unlock();
    return status;
}
Exemple #9
0
QPixmap QDeclarativeTextPrivate::wrappedTextImage(bool drawStyle)
{
    //do layout
    QSize size = cachedLayoutSize;

    int x = 0;
    for (int i = 0; i < layout.lineCount(); ++i) {
        QTextLine line = layout.lineAt(i);
        if (hAlign == QDeclarativeText::AlignLeft) {
            x = 0;
        } else if (hAlign == QDeclarativeText::AlignRight) {
            x = size.width() - (int)line.naturalTextWidth();
        } else if (hAlign == QDeclarativeText::AlignHCenter) {
            x = (size.width() - (int)line.naturalTextWidth()) / 2;
        }
        line.setPosition(QPoint(x, (int)line.y()));
    }

    //paint text
    QPixmap img(size);
    if (!size.isEmpty()) {
        img.fill(Qt::transparent);
        QPainter p(&img);
        drawWrappedText(&p, QPointF(0,0), drawStyle);
    }
    return img;
}
Exemple #10
0
QSize QtDNDTabBar::sizeHint() const {
	QSize hint = QTabBar::sizeHint();
	if (hint.isEmpty()) {
		hint = QSize(parentWidget()->width(), defaultTabHeight);
	}
	return hint;
}
Exemple #11
0
void DkCompressDialog::updateFileSizeLabel(float bufferSize, QSize bufferImgSize, float factor) {

	if (bufferImgSize.isEmpty())
		bufferImgSize = mNewImg.size();

	if (mImg.isNull() || bufferSize == -1 || bufferImgSize.isNull()) {
		mPreviewSizeLabel->setText(tr("File Size: --"));
		mPreviewSizeLabel->setEnabled(false);
		return;
	}
	mPreviewSizeLabel->setEnabled(true);

	if (factor == -1.0f)
		factor = 1.0f;

	float depth = (mDialogMode == jpg_dialog || mDialogMode == j2k_dialog || (mDialogMode == web_dialog && mHasAlpha)) ? 24.0f : (float)mImg.depth();	// jpg uses always 24 bit
	
	float rawBufferSize = bufferImgSize.width()*bufferImgSize.height()*depth/8.0f;
	float rawImgSize = factor*(mImg.width()*mImg.height()*depth/8.0f);

	//qDebug() << "I need: " << rawImgSize*bufferSize/rawBufferSize << " bytes because buffer size: " << bufferSize;
	//qDebug() << "new image: " << newImg.size() << " full image: " << img->size() << " depth: " << depth;

	mPreviewSizeLabel->setText(tr("File Size: ~%1").arg(DkUtils::readableByte(rawImgSize*bufferSize/rawBufferSize)));
}
Exemple #12
0
bool QCefWebView::CreateBrowser(const QSize& size) {
    //qDebug() << __FUNCTION__ << __LINE__;
    if (browser_state_ != kNone || size.isEmpty()) {
        return false;
    }
    mutex_.lock();
    if (browser_state_ != kNone) {
        mutex_.unlock();
        return false;
    }
    //qDebug() << __FUNCTION__ << __LINE__;
    RECT rect;
    rect.left = 0;
    rect.top = 0;
    rect.right = size.width();
    rect.bottom = size.height();
    CefWindowInfo info;
    CefBrowserSettings settings;
    info.SetAsChild((HWND) this->winId(), rect);
    qcef_client_handler->set_listener(this);
    QString url = url_.isEmpty() ? kUrlBlank : url_.toString();
    CefBrowserHost::CreateBrowser(info,
                                  qcef_client_handler.get(),
                                  CefString(url.toStdWString()),
                                  settings,
                                  NULL);

    browser_state_ = kCreating;
    mutex_.unlock();
    return true;
}
Exemple #13
0
void
E6Irc::run (const QSize & desktopSize)
{
  CertStore::IF().Init();
  control->fillContext(isProbablyPhone);
  setSource (QUrl ("qrc:///qml/Main.qml"));
  channelGroup->Start();
  control->Run ();
  QObject * qmlRoot = rootObject();
  QDeclarativeItem * qmlItem = qobject_cast<QDeclarativeItem*> (qmlRoot);
  if (qmlItem) {
    qDebug () << __PRETTY_FUNCTION__ << " phone ? " << isProbablyPhone;
    QMetaObject::invokeMethod (qmlItem, "phoneSettings",
      Q_ARG (QVariant, isProbablyPhone));
  }
  if (!isFullScreen()) {
    QSize defaultSize = size();
    QSize newsize = Settings().value ("sizes/e6irc", defaultSize).toSize();
    if (newsize.isEmpty()) {
      showMaximized();
      newsize = desktopSize;
      resize (newsize);
    } else {
      resize (newsize);
    }
    qDebug () << __PRETTY_FUNCTION__ << " resize to " << newsize
              << " result is " << size();
  }
  show ();
  Settings().sync ();
  objectCount = 0;
  fixCaps (qmlRoot);
  qDebug () << objectCount << " objects";
}
Exemple #14
0
void QWSSharedMemSurface::setGeometry(const QRect &rect)
{
    const QSize size = rect.size();
    if (img.size() != size) {
        if (size.isEmpty()) {
            mem.detach();
            img = QImage();
        } else {
            mem.detach();

            QWidget *win = window();
            const QImage::Format format = preferredImageFormat(win);
            const int bpl = nextMulOf4(bytesPerPixel(format) * size.width());
#ifdef QT_QWS_CLIENTBLIT
            const int imagesize = bpl * size.height() + sizeof(uint);
#else
            const int imagesize = bpl * size.height();
#endif
            if (!mem.create(imagesize)) {
                perror("QWSSharedMemSurface::setGeometry allocating shared memory");
                qFatal("Error creating shared memory of size %d", imagesize);
            }
#ifdef QT_QWS_CLIENTBLIT
            *((uint *)mem.address()) = 0;
            uchar *base = static_cast<uchar*>(mem.address()) + sizeof(uint);
#else
            uchar *base = static_cast<uchar*>(mem.address());
#endif
            img = QImage(base, size.width(), size.height(), bpl, format);
            setImageMetrics(img, win);
        }
    }

    QWSWindowSurface::setGeometry(rect);
}
bool QGLPixmapData::fromFile(const QString &filename, const char *format,
                             Qt::ImageConversionFlags flags)
{
    if (pixelType() == QPixmapData::BitmapType)
        return QPixmapData::fromFile(filename, format, flags);
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly))
        return false;
    QByteArray data = file.peek(64);
    bool alpha;
    if (m_texture.canBindCompressedTexture
            (data.constData(), data.size(), format, &alpha)) {
        resize(0, 0);
        data = file.readAll();
        file.close();
        QGLShareContextScope ctx(qt_gl_share_widget()->context());
        QSize size = m_texture.bindCompressedTexture
            (data.constData(), data.size(), format);
        if (!size.isEmpty()) {
            w = size.width();
            h = size.height();
            is_null = false;
            d = 32;
            m_hasAlpha = alpha;
            m_source = QImage();
            m_dirty = isValid();
            return true;
        }
        return false;
    }
    fromImage(QImageReader(&file, format).read(), flags);
    return !isNull();
}
Exemple #16
0
void QQnxWindow::setBufferSize(const QSize &size)
{
    qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "size =" << size;

    // Set window buffer size
    errno = 0;

    // libscreen fails when creating empty buffers
    const QSize nonEmptySize = size.isEmpty() ? QSize(1, 1) : size;

    int val[2] = { nonEmptySize.width(), nonEmptySize.height() };
    int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val);
    if (result != 0)
        qFatal("QQnxWindow: failed to set window buffer size, errno=%d", errno);

    // Create window buffers if they do not exist
    if (m_bufferSize.isEmpty()) {
        val[0] = m_screen->nativeFormat();
#if !defined(QT_NO_OPENGL)
        // Get pixel format from EGL config if using OpenGL;
        // otherwise inherit pixel format of window's screen
        if (m_platformOpenGLContext != 0)
            val[0] = platformWindowFormatToNativeFormat(m_platformOpenGLContext->format());
#endif

        errno = 0;
        result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val);
        if (result != 0)
            qFatal("QQnxWindow: failed to set window pixel format, errno=%d", errno);

        errno = 0;
        result = screen_create_window_buffers(m_window, MAX_BUFFER_COUNT);
        if (result != 0)
            qWarning() << "QQnxWindow: Buffer size was" << size;
        qFatal("QQnxWindow: failed to create window buffers, errno=%d", errno);

        // check if there are any buffers available
        int bufferCount = 0;
        result = screen_get_window_property_iv(m_window, SCREEN_PROPERTY_RENDER_BUFFER_COUNT, &bufferCount);

        if (result != 0)
            qFatal("QQnxWindow: failed to query window buffer count, errno=%d", errno);

        if (bufferCount != MAX_BUFFER_COUNT) {
            qFatal("QQnxWindow: invalid buffer count. Expected = %d, got = %d. You might experience problems.",
                   MAX_BUFFER_COUNT, bufferCount);
        }
    }

    // Cache new buffer size
    m_bufferSize = nonEmptySize;

    // Buffers were destroyed; reacquire them
    m_currentBufferIndex = -1;
    m_previousDirty = QRegion();
    m_scrolled = QRegion();

    const QMutexLocker locker(&m_mutex);
    m_requestedBufferSize = QSize();
}
Exemple #17
0
bool QGLPixmapData::fromData(const uchar *buffer, uint len, const char *format,
                             Qt::ImageConversionFlags flags)
{
    bool alpha;
    const char *buf = reinterpret_cast<const char *>(buffer);
    if (m_texture.canBindCompressedTexture(buf, int(len), format, &alpha)) {
        resize(0, 0);
        QGLShareContextScope ctx(qt_gl_share_widget()->context());
        QSize size = m_texture.bindCompressedTexture(buf, int(len), format);
        if (!size.isEmpty()) {
            w = size.width();
            h = size.height();
            is_null = false;
            d = 32;
            m_hasAlpha = alpha;
            m_source = QVolatileImage();
            m_dirty = isValid();
            return true;
        }
    }

    QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len);
    QBuffer b(&a);
    b.open(QIODevice::ReadOnly);
    QImage image = QImageReader(&b, format).read();
    if (image.isNull())
        return false;

    createPixmapForImage(image, flags, true);

    return !isNull();
}
Exemple #18
0
static inline void qwtDrawPixmapSymbols( QPainter *painter,
    const QPointF *points, int numPoints, const QwtSymbol &symbol )
{
    QSize size = symbol.size();
    if ( size.isEmpty() )
        size = symbol.pixmap().size();

    const QTransform transform = painter->transform();
    if ( transform.isScaling() )
    {
        const QRect r( 0, 0, size.width(), size.height() );
        size = transform.mapRect( r ).size();
    }

    QPixmap pm = symbol.pixmap();
    if ( pm.size() != size )
        pm = pm.scaled( size );
    
    QPointF pinPoint( 0.5 * size.width(), 0.5 * size.height() );
    if ( symbol.isPinPointEnabled() )
        pinPoint = symbol.pinPoint();

    painter->resetTransform();

    for ( int i = 0; i < numPoints; i++ )
    {
        const QPointF pos = transform.map( points[i] ) - pinPoint;

        QwtPainter::drawPixmap( painter, 
            QRect( pos.toPoint(), pm.size() ), pm );
    }
}
Exemple #19
0
void MainWindow::resizeToVideo(MediaWidget::ResizeFactor resizeFactor)
{
	if (!isFullScreen() && !mediaWidget->sizeHint().isEmpty()) {
		if (isMaximized()) {
			setWindowState(windowState() & ~Qt::WindowMaximized);
		}

		QSize videoSize;

		switch (resizeFactor) {
		case MediaWidget::ResizeOff:
			break;
		case MediaWidget::OriginalSize:
			videoSize = mediaWidget->sizeHint();
			break;
		case MediaWidget::DoubleSize:
			videoSize = (2 * mediaWidget->sizeHint());
			break;
		}

		if (!videoSize.isEmpty()) {
			resize(size() - centralWidget()->size() + videoSize);
		}
	}
}
Exemple #20
0
QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
    QImage image(id);
    QImage ret;

    if (requestedSize.isEmpty()) {
        ret = image;
    } else {
        // Load the requested image, scalling to the
        // requested size
        QSize scaleSize = requestedSize;
        if (scaleSize.height() == 0) {
            scaleSize.setHeight(scaleSize.width());
        } else if (scaleSize.width() == 0) {
            scaleSize.setWidth(scaleSize.height());
        }

        ret = image.scaled(scaleSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    }

    if (size) {
        *size = QSize(image.width(), image.height());
    }

    KExiv2Iface::KExiv2	exiv(id);
    exiv.rotateExifQImage(ret, exiv.getImageOrientation());

    return ret;
}
void LfmDelegate::paint( QPainter* p, const QStyleOptionViewItem& opt, const QModelIndex& index ) const
{
    QIcon icon;

    if( index.data(Qt::DecorationRole).type() == QVariant::Icon )
    {
        icon = index.data(Qt::DecorationRole).value<QIcon>();

        if ( icon.isNull() )
            //icon = QIcon( m_defaultImage );
            icon = QIcon( ":/default_user.png" );

        QRect iconRect = opt.rect.translated( 3, 3 );
        iconRect.setSize( QSize( 34, 34 ));
        icon.paint( p, iconRect );
        QSize iconSize = icon.actualSize( iconRect.size());

        if( iconSize.isEmpty()) iconSize = QSize( 34, 34 );

        iconRect.translate( ( iconRect.width() - iconSize.width()) / 2.0f,
                            ( iconRect.height() - iconSize.height()) /2.0f );
        iconRect.setSize( iconSize );
        p->drawRect( iconRect );
    }

    QFontMetrics fm( p->font() );
    QString elidedText = fm.elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 50 );
    p->drawText( opt.rect.adjusted( 46, 3, -5, -5 ), elidedText );
}
NumberPiece::NumberPiece(int number, QColor color, QSize pieceSize) :
    num(number),
    color(color),
    pixmap(pieceSize)
{
    if (!pieceSize.isEmpty())
        init();
}
Exemple #23
0
//***************************************************************************
QSize Kwave::AboutContainer::sizeHint(void) const
{
    //
    // The size is computed by adding the sizeHint().height() of all
    // widget children and taking the width of the widest child and adding
    // layout()->margin() and layout()->spacing()
    //

    QSize total_size;

    int numChild = 0;
    const QList<QObject*> l = children(); // silence please
    foreach (QObject *o, l) {
	if (o->isWidgetType()) {
	    ++numChild;
	    QWidget * const w = static_cast<QWidget *>(o);

	    QSize s = w->minimumSize();
	    if (s.isEmpty()) {
		s = w->minimumSizeHint();
		if (s.isEmpty()) {
		    s = w->sizeHint();
		    if (s.isEmpty())
			s = QSize(100, 100); // Default size
		}
	    }
	    total_size.setHeight(total_size.height() + s.height());
	    if (s.width() > total_size.width()) {
		total_size.setWidth(s.width());
	    }
	}
    }

    if (numChild > 0) {
	//
	// Seems I have to add 1 to the height to properly show the border
	// of the last entry if layout()->margin() is 0
	//
	total_size.setHeight(total_size.height() +
	    layout()->spacing() * (numChild - 1));
	total_size += QSize(layout()->margin()*2, layout()->margin()*2 + 1);
    } else {
	total_size = QSize(1, 1);
    }
    return total_size;
}
void GeoSceneTileDataset::setTileSize( const QSize &tileSize )
{
    if ( tileSize.isEmpty() ) {
        mDebug() << "Ignoring invalid tile size " << tileSize;
    } else {
        m_tileSize = tileSize;
    }
}
Exemple #25
0
/**
 * @brief Sets the resolution text
 * @param resolution Resolution (QSize) to set
 * @param hint Hint
 */
void ImageLabel::setHint(QSize resolution, QString hint)
{
    QString text;
    if (!resolution.isNull() && !resolution.isEmpty() && resolution.isValid())
        text = QString("%1 x %2").arg(resolution.width()).arg(resolution.height());
    text.append(hint);
    ui->resolution->setText(text);
}
Exemple #26
0
bool VideoWidgetSurface::isFormatSupported(const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const
{
    Q_UNUSED(similar);

    const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
    const QSize size = format.frameSize();

    return imageFormat != QImage::Format_Invalid && !size.isEmpty() && format.handleType() == QAbstractVideoBuffer::NoHandle;
}
Exemple #27
0
QPixmap
Album::cover( const QSize& size, bool forceLoad ) const
{
    if ( !m_infoLoaded && !m_infoLoading )
    {
        if ( !forceLoad )
            return QPixmap();

        m_uuid = uuid();

        Tomahawk::InfoSystem::InfoStringHash trackInfo;
        trackInfo["artist"] = artist()->name();
        trackInfo["album"] = name();

        Tomahawk::InfoSystem::InfoRequestData requestData;
        requestData.caller = m_uuid;
        requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
        requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
        requestData.customData = QVariantMap();

        connect( Tomahawk::InfoSystem::InfoSystem::instance(),
                SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
                SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );

        connect( Tomahawk::InfoSystem::InfoSystem::instance(),
                SIGNAL( finished( QString ) ),
                SLOT( infoSystemFinished( QString ) ) );

        Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );

        m_infoLoading = true;
    }

    if ( !m_cover && !m_coverBuffer.isEmpty() )
    {
        m_cover = new QPixmap();
        m_cover->loadFromData( m_coverBuffer );
    }

    if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
    {
        if ( m_coverCache.contains( size.width() ) )
        {
            return m_coverCache.value( size.width() );
        }

        QPixmap scaledCover;
        scaledCover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
        m_coverCache.insert( size.width(), scaledCover );
        return scaledCover;
    }

    if ( m_cover )
        return *m_cover;
    else
        return QPixmap();
}
Exemple #28
0
void TilesetEditor::restoreState()
{
    QSettings *settings = Preferences::instance()->settings();
    QSize size = settings->value(QLatin1String(SIZE_KEY)).toSize();
    if (!size.isEmpty()) {
        mMainWindow->resize(size.width(), size.height());
        mMainWindow->restoreState(settings->value(QLatin1String(STATE_KEY)).toByteArray());
    }
}
Exemple #29
0
void
KTreemapView::rebuildTreemap( KFileInfo *	newRoot,
			      const QSize &	newSz )
{
    // kdDebug() << k_funcinfo << endl;

    QSize newSize = newSz;

    if ( newSz.isEmpty() )
	newSize = visibleSize();


    // Delete all old stuff.
    clear();

    // Re-create a new canvas

    if ( ! canvas() )
    {
	QCanvas * canv = new QCanvas( this );
	CHECK_PTR( canv );
	setCanvas( canv );
    }

    canvas()->resize( newSize.width(), newSize.height() );

    if ( newSize.width() >= UpdateMinSize && newSize.height() >= UpdateMinSize )
    {
	// The treemap contents is displayed if larger than a certain minimum
	// visible size. This is an easy way for the user to avoid
	// time-consuming delays when deleting a lot of files: Simply make the
	// treemap (sub-) window very small.

	// Fill the new canvas

	if ( newRoot )
	{
	    _rootTile = new KTreemapTile( this,		// parentView
					  0,		// parentTile
					  newRoot,	// orig
					  QRect( QPoint( 0, 0), newSize ),
					  KTreemapAuto );
	}


	// Synchronize selection with the tree

	if ( _tree->selection() )
	    selectTile( _tree->selection() );
    }
    else
    {
	// kdDebug() << "Too small - suppressing treemap contents" << endl;
    }

    emit treemapChanged();
}
void QGstreamerPlayerSession::updateVideoResolutionTag()
{
    QSize size;
    QSize aspectRatio;

    GstPad *pad = gst_element_get_static_pad(m_videoIdentity, "src");
    GstCaps *caps = gst_pad_get_negotiated_caps(pad);

    if (caps) {
        const GstStructure *structure = gst_caps_get_structure(caps, 0);
        gst_structure_get_int(structure, "width", &size.rwidth());
        gst_structure_get_int(structure, "height", &size.rheight());

        gint aspectNum = 0;
        gint aspectDenum = 0;
        if (!size.isEmpty() && gst_structure_get_fraction(
                    structure, "pixel-aspect-ratio", &aspectNum, &aspectDenum)) {
            if (aspectDenum > 0)
                aspectRatio = QSize(aspectNum, aspectDenum);
        }
        gst_caps_unref(caps);
    }

    gst_object_unref(GST_OBJECT(pad));

    QSize currentSize = m_tags.value("resolution").toSize();
    QSize currentAspectRatio = m_tags.value("pixel-aspect-ratio").toSize();

    if (currentSize != size || currentAspectRatio != aspectRatio) {
        if (aspectRatio.isEmpty())
            m_tags.remove("pixel-aspect-ratio");

        if (size.isEmpty()) {
            m_tags.remove("resolution");
        } else {
            m_tags.insert("resolution", QVariant(size));
            if (!aspectRatio.isEmpty())
                m_tags.insert("pixel-aspect-ratio", QVariant(aspectRatio));
        }

        emit tagsChanged();
    }
}