Beispiel #1
0
void ImageViewer::resizeEvent(QResizeEvent *e)
{
    if(noPicture()) return;

    if(hasUserZoom){
        updateTopLeft();
        updateShift();
    }else{
        initToFitWidget();
    }
    QWidget::resizeEvent(e);
}
Beispiel #2
0
void ImageViewer::initToFitWidget()//no change the value of rotate
{
    //restore the cursor even if the image cannot load.
    setCursor(QCursor(Qt::ArrowCursor));

    if(noPicture()) return;

    QSize pixSize(image.size());
    //if image large than widget, will scale image to fit widget.
    if(!(rect().size() - pixSize).isValid())//! SIZE_ADJUST !!!
        pixSize.scale(rect().size() + Config::SizeAdjusted, Qt::KeepAspectRatio);
    if(image.width() == 0)
        scale = 1.0;
    else
        scale = qreal(pixSize.width()) / image.width();
    scaleMin = qMin(Config::ScaleMin, scale);

    updateTopLeft();
    shift = Config::OriginPoint;
}
Beispiel #3
0
void ImageViewer::zoomIn(double factor)
{
    if(noPicture()) return;

    qreal scale_old = scale;
    scale += factor;
    scale = qMax(scaleMin, qMin(Config::ScaleMax, scale));
    if(scale == scale_old)//scale no changed
        return;

    /*! topLeft must determined before shift,
     * otherwise will impact updateShift()
     */
    updateTopLeft();
    shift /= scale_old;
    shift *= scale;
    updateShift();
    hasUserZoom = true;

    ToolTip::showText(mapToGlobal(rect().center()),
                      QString("<font size='7'><b>%1%</b></font>").arg(scale * 100, 0, 'g', 4),
                      true, 0.7, 800);
}
AbstractGraphicsRectItem::AbstractGraphicsRectItem(QAbstractGraphicsShapeItem *shapeItem,
                                                   QGraphicsItem *parent)
    : KaptionGraphicsItem(shapeItem, parent),
      m_hTL(new HandleGraphicsItem(0, shapeItem)),
      m_hTR(new HandleGraphicsItem(0, shapeItem)),
      m_hBL(new HandleGraphicsItem(0, shapeItem)),
      m_hBR(new HandleGraphicsItem(0, shapeItem)),
      m_startingPoint(0)
{
    connect(m_hTL, SIGNAL(moved(QPointF)),
            this, SLOT(updateTopLeft(QPointF)));
    connect(m_hTR, SIGNAL(moved(QPointF)),
            this, SLOT(updateTopRight(QPointF)));
    connect(m_hBL, SIGNAL(moved(QPointF)),
            this, SLOT(updateBottomLeft(QPointF)));
    connect(m_hBR, SIGNAL(moved(QPointF)),
            this, SLOT(updateBottomRight(QPointF)));

    m_handles << m_hTL << m_hTR << m_hBL << m_hBR;

    hideHandles();

    dropShadowEffect()->setOffset(dropShadowEffect()->offset() - QPoint(5, 5));
}