Exemple #1
0
void ImageViewer::fitWidth() {
    if(mIsDisplaying) {
        float scale = (float)width() * devicePixelRatioF() / mSourceSize.width();
        if(!expandImage && scale > 1.0f) {
            fitNormal();
        } else {
            setScale(scale);
            centerImage();
            if(drawingRect.height() > height()*devicePixelRatioF())
                drawingRect.moveTop(0);
            update();
        }
    } else {
        centerImage();
    }
}
Exemple #2
0
void PreviewWidget::previewLatex(const QPixmap& previewImage){
	preViewer->setPixmap(previewImage);
	preViewer->adjustSize();
	pvscaleFactor=1.0;
	if (mFit) fitImage(true);
	if (mCenter) centerImage(true);
}
Exemple #3
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();
}
Exemple #4
0
void PiqslImageView::keyPressEvent(QKeyEvent* event)
{
    if(event->key() == Qt::Key_H)
        centerImage();
    else
        event->ignore();
}
Exemple #5
0
/**
 * Resizes the image so that the resulting sheet has a new size and the image
 * content is zoomed to fit best into the sheet, while keeping it's aspect ration.
 *
 * @param w the new width to resize to
 * @param h the new height to resize to
 */
void resize(int w, int h, struct IMAGE* image) {
    struct IMAGE newimage;
    int ww;
    int hh;
    float wRat;
    float hRat;
    
    if (verbose >= VERBOSE_NORMAL) {
        printf("resizing %dx%d -> %dx%d\n", image->width, image->height, w, h);
    }

    wRat = (float)w / image->width;
    hRat = (float)h / image->height;
    if (wRat < hRat) { // horizontally more shrinking/less enlarging is needed: fill width fully, adjust height
        ww = w;
        hh = image->height * w / image->width;
    } else if (hRat < wRat) {
        ww = image->width * h / image->height;
        hh = h;
    } else { // wRat == hRat
        ww = w;
        hh = h;
    }
    stretch(ww, hh, image);
    initImage(&newimage, w, h, image->bitdepth, image->color, image->background);
    centerImage(image, 0, 0, w, h, &newimage);
    replaceImage(image, &newimage);
}
Exemple #6
0
void ImageViewer::fitWindow() {
    if(mIsDisplaying) {
        bool h = mSourceSize.height() <= height() * devicePixelRatioF();
        bool w = mSourceSize.width()  <= width()  * devicePixelRatioF();
        // source image fits entirely
        if(h && w && !expandImage) {
            fitNormal();
            return;
        } else { // doesnt fit
            setScale(expandImage?fitWindowScale:minScale);
            centerImage();
            update();
        }
    } else {
        centerImage();
    }
}
Exemple #7
0
void ImageViewer::fitNormal() {
    if(!mIsDisplaying) {
        return;
    }
    setScale(1.0);
    centerImage();
    if(drawingRect.height() > height() * devicePixelRatioF()) {
        drawingRect.moveTop(0);
    }
    update();
}
bool TribotsTools::ScrollImageWidget::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: setImage((const Image&)*((const Image*)static_QUType_ptr.get(_o+1))); break;
    case 1: setImage((const ImageBuffer&)*((const ImageBuffer*)static_QUType_ptr.get(_o+1))); break;
    case 2: centerImage(); break;
    case 3: mousePressEvent((QMouseEvent*)static_QUType_ptr.get(_o+1)); break;
    case 4: mouseMoveEvent((QMouseEvent*)static_QUType_ptr.get(_o+1)); break;
    case 5: keyPressEvent((QKeyEvent*)static_QUType_ptr.get(_o+1)); break;
    default:
	return QScrollView::qt_invoke( _id, _o );
    }
    return TRUE;
}
Exemple #9
0
void ImageView::resizeImage()
{
	static bool busy = false;
	if (busy || (!imageLabel->pixmap() && !anim))
		return;
	busy = true;

	imageLabel->setVisible(false);
	QSize imgSize = isAnimation? anim->currentPixmap().size() : imageLabel->pixmap()->size();

	if (tempDisableResize) {
		imgSize.scale(calcZoom(imgSize.width()), calcZoom(imgSize.height()), Qt::KeepAspectRatio);
	} else {
		switch(GData::zoomInFlags) {
			case Disable:
				if (imgSize.width() < size().width() && imgSize.height() < size().height())
					imgSize.scale(calcZoom(imgSize.width()), calcZoom(imgSize.height()),
																					Qt::KeepAspectRatio);
				break;
				
			case WidthNHeight:
				if (imgSize.width() < size().width() && imgSize.height() < size().height())
					imgSize.scale(calcZoom(size().width()), calcZoom(size().height()),
																					Qt::KeepAspectRatio);
				break;

			case Width:
				if (imgSize.width() < size().width())
					imgSize.scale(calcZoom(size().width()), 
						calcZoom(getHeightByWidth(imgSize.width(), imgSize.height(), size().width())),
						Qt::KeepAspectRatio);
				break;
				
			case Height:
				if (imgSize.height() < size().height())
					imgSize.scale(calcZoom(getWidthByHeight(imgSize.height(), imgSize.width(),
									size().height())), calcZoom(size().height()), Qt::KeepAspectRatio);
				break;

			case Disprop:
				int newWidth = imgSize.width(), newHeight = imgSize.height();
				if (newWidth < size().width())
					newWidth = size().width();
				if (newHeight < size().height())
					newHeight = size().height();
				imgSize.scale(calcZoom(newWidth), calcZoom(newHeight), Qt::IgnoreAspectRatio);
				break;
		}

		switch(GData::zoomOutFlags) {
			case Disable:
				if (imgSize.width() >= size().width() || imgSize.height() >= size().height())
					imgSize.scale(calcZoom(imgSize.width()), calcZoom(imgSize.height()),
																					Qt::KeepAspectRatio);
				break;
		
			case WidthNHeight:
				if (imgSize.width() >= size().width() || imgSize.height() >= size().height())
					imgSize.scale(calcZoom(size().width()), calcZoom(size().height()),
																					Qt::KeepAspectRatio);
				break;

			case Width:
				if (imgSize.width() > size().width())
					imgSize.scale(calcZoom(size().width()), 
						calcZoom(getHeightByWidth(imgSize.width(), imgSize.height(), size().width())),
																					Qt::KeepAspectRatio);
				break;
				
			case Height:
				if (imgSize.height() > size().height())
					imgSize.scale(calcZoom(getWidthByHeight(imgSize.height(), imgSize.width(), 
																					size().height())),
						calcZoom(size().height()), Qt::KeepAspectRatio);
			
				break;

			case Disprop:
				int newWidth = imgSize.width(), newHeight = imgSize.height();
				if (newWidth > size().width())
					newWidth = size().width();
				if (newHeight > size().height())
					newHeight = size().height();
				imgSize.scale(calcZoom(newWidth), calcZoom(newHeight), Qt::IgnoreAspectRatio);
				break;
		}
	}

	imageLabel->setFixedSize(imgSize);
	imageLabel->setVisible(true);
	centerImage(imgSize);
	busy = false;
}
Exemple #10
0
void PiqslImageView::imageResized()
{
    centerImage();
}