Exemple #1
0
void PiqslImageView::setSelectedImage(const QModelIndexList& indexes)
{
    if(m_image)
        disconnect(m_image.data(), 0, this, 0);
    if(indexes.empty())
    {
      //        m_image.reset();
        update();
        return;
    }
    int prevWidth = 0;
    int prevHeight = 0;
    if(m_image)
    {
        prevWidth = m_image->frameWidth();
        prevHeight = m_image->frameHeight();
    }
    m_image = indexes[0].data().value<QSharedPointer<CqImage> >();
    if(prevWidth > 0 && m_image->frameWidth() > 0)
    {
        // Keep the center of the image in the same place when switching to an
        // image of different dimensions.
        m_tlPos += 0.5f*QPointF(prevWidth - m_image->frameWidth(),
                                prevHeight - m_image->frameHeight());
    }
    else
        centerImage();
    connect(m_image.data(), SIGNAL(updated(int,int,int,int)),
            this, SLOT(imageUpdated(int,int,int,int)));
    connect(m_image.data(), SIGNAL(resized()), this, SLOT(imageResized()));
    update();
}
void rescalethread::scaleImage(const QString &imageFileName, const int &currentIndex)
{

    QImage image, result;

    //construct the sting for the filename of the resized image
    targetFileName = QFileInfo(imageFileName).path() + QDir::separator() +"resized" + QDir::separator() + QFileInfo(imageFileName).baseName()+ "_resized" +".jpg";

    //if image was loaded succesfully, then scale it
    if(image.load(imageFileName))
    {
        //resize to this width/height and save to target file location
        result = image.scaled(resizeWidth, resizeHeight, Qt::KeepAspectRatio, Qt::FastTransformation);

        //try saving the image
        if(result.save(targetFileName, "JPG"))
        {
            //this signal is required to communicate the progress status on the main GUI thread
            emit imageResized(currentIndex);
        }

        else
        {
            //there was a problem with saving the image
            emit imageSaveErrorSIGNAL(imageFileName);
        }
    }

    else
    {
        //there was a problem with loading the image
        emit imageLoadErrorSIGNAL(imageFileName);
    }


}