예제 #1
0
void ImageViewer::myMouseMove(QMouseEvent * event)
{
    QPoint change = event->globalPos() - startPos;

    if(event->modifiers() == Qt::ControlModifier){
        emit siteChange(change);
    }else{
        //if widget smaller than widget, allow to move image.
        //! + SIZE_ADJUST
        if(hasPicture() && !(rect().size() + Config::SizeAdjusted - image.size()*scale).isValid()){
            shift += change;
            updateShift();


            QPoint delta = event->pos() - pressPos;
            if(justPressed){
                if (delta.x() > threshold || delta.x() < -threshold ||
                        delta.y() > threshold || delta.y() < -threshold) {
                    timeStamp = QTime::currentTime(); //start calculate
                    justPressed = false; ///
                    this->delta = QPoint(0, 0);
                    pressPos = event->pos();
                }
            }else{
                if (timeStamp.elapsed() > 100) {
                    timeStamp = QTime::currentTime();   //restart calculate
                    speed = delta - this->delta;    ///
                    this->delta = delta;
                }
            }
        }
    }

    startPos = event->globalPos();    //
}
예제 #2
0
void ImageViewer::scrollContent(int deltaX, int deltaY)
{
    // if widget smaller than widget, allow to move image.
    if(hasPicture() && scaleLargeThanWidget()){
        shift.setX(shift.x() + deltaX);
        shift.setY(shift.y() + deltaY);
        updateShift();
    }
}
예제 #3
0
void ImageViewer::resizeEvent(QResizeEvent *e)
{
    if(noPicture()) return;

    if(hasUserZoom){
        updateTopLeft();
        updateShift();
    }else{
        initToFitWidget();
    }
    QWidget::resizeEvent(e);
}
예제 #4
0
void ImageViewer::resizeEvent(QResizeEvent *e)
{
    if(noPicture()) return;

    if(hasUserZoom){
        calcTopLeft();
        updateShift();
        updateCursor();
    }else{
        layoutImage(); //! FIXME: if user drag and move image content (when AlignCenter is hasUserZoom and shift != (0,0)) , this will reset the shift if align mode isn't AlignCenterCenter.
    }
    QWidget::resizeEvent(e);
}
예제 #5
0
void ImageViewer::zoomIn(double factor, const QPoint &pivot)
{
    if(noPicture() || !rect().contains(pivot)) // pivot must inner widget
        return;

    qreal scale_old = scale;
    zoomIn(factor);

    QPointF distance(rect().center() - pivot);
    QPointF change(distance / scale_old * scale - distance);
    shift += change;    // to keep the pivot position, must after scale.
    updateShift();
}
예제 #6
0
void ImageViewer::myTimerEvent()
{
    speed = deaccelerate(speed);

    QPointF shiftOld = shift;
    shift += speed;
    updateShift();

    if(shift == shiftOld)
        speed = QPoint(0, 0);
    if (speed == QPoint(0, 0))
        timer.stop();
}
void DistanceFieldShiftedStyleTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
{
    DistanceFieldStyledTextMaterialShader::updateState(state, newEffect, oldEffect);

    QSGDistanceFieldShiftedStyleTextMaterial *material = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(newEffect);
    QSGDistanceFieldShiftedStyleTextMaterial *oldMaterial = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(oldEffect);

    if (oldMaterial == 0
            || oldMaterial->fontScale() != material->fontScale()
            || oldMaterial->shift() != material->shift()
            || oldMaterial->textureSize() != material->textureSize()) {
        updateShift(material->fontScale(), material->shift());
    }
}
예제 #8
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);
}
예제 #9
0
void ImageViewer::wheelEvent(QWheelEvent *e)
{
    if(noPicture() || !rect().contains(e->pos())) //cursor is not in widget
        return;

    qreal scale_old = scale;

    switch(e->modifiers()){
    case Qt::ShiftModifier:
        zoomIn(e->delta() / qreal(2400)); //e->delta() is +120 or -120
        break;
    case Qt::ControlModifier:
        zoomIn(e->delta() / qreal(600));
        break;
    default:
        zoomIn(e->delta() / qreal(1200));
        break;
    }

    QPointF distance(rect().center() - e->pos());
    QPointF change(distance / scale_old * scale - distance);
    shift += change;    //to keep the cursor position, must after scale.
    updateShift();
}
예제 #10
0
 void ShiftButton::updateSelection(const sf::Vector2f& mousePosition, const sf::Time& delta)
 {
     if(bound.contains(mousePosition))
     {
         if(_shiftMax != _currentShift)
         {
             _currentShift.x += _shiftMax.x * (delta.asSeconds() / _shiftDuration);
             _currentShift.y += _shiftMax.y * (delta.asSeconds() / _shiftDuration);
             if(_shiftMax.x > 0)
             {
                 if(_currentShift.x > _shiftMax.x)
                 {
                     _currentShift.x = _shiftMax.x;
                 }
             }
             else if(_shiftMax.x < 0)
             {
                 if(_currentShift.x < _shiftMax.x)
                 {
                     _currentShift.x = _shiftMax.x;
                 }
             }
             if(_shiftMax.y > 0)
             {
                 if(_currentShift.y > _shiftMax.y)
                 {
                     _currentShift.y = _shiftMax.y;
                 }
             }
             else if(_shiftMax.y < 0)
             {
                 if(_currentShift.y < _shiftMax.y)
                 {
                     _currentShift.y = _shiftMax.y;
                 }
             }
         }
     } 
     else
     {
         if(_currentShift != sf::Vector2f(0,0))
         {
             _currentShift.x -= _shiftMax.x * (delta.asSeconds() / _shiftDuration);
             _currentShift.y -= _shiftMax.y * (delta.asSeconds() / _shiftDuration);
             if(_shiftMax.x > 0)
             {
                 if(_currentShift.x < 0)
                 {
                     _currentShift.x = 0;
                 }
             }
             else if(_shiftMax.x < 0)
             {
                 if(_currentShift.x > 0 )
                 {
                     _currentShift.x = 0;
                 }
             }
             if(_shiftMax.y > 0)
             {
                 if(_currentShift.y < 0)
                 {
                     _currentShift.y = 0;
                 }
             }
             else if(_shiftMax.y < 0)
             {
                 if(_currentShift.y > 0)
                 {
                     _currentShift.y = 0;
                 }
             }
         }
     }
     updateShift();
 }
예제 #11
0
 void ShiftButton::setPosition(sf::Vector2f position)
 {
     // set the actual position
     _actualPosition = position;
     updateShift();
 }
예제 #12
0
 ShiftButton::ShiftButton(sf::Sprite buttonSprite, sf::Vector2f shiftMax, float shiftDuration)
     : bound(_bound), _sprite(buttonSprite), _actualPosition(0,0), _currentPosition(0,0), _shiftMax(shiftMax)
     , _shiftDuration(shiftDuration)
 {
     updateShift();
 }