예제 #1
0
        void EtherMenu::ScaleObjectBasedOnPriority(int index, int priority)
        {
            qreal scalevalue;
            InfoCard* obj = objects_.at(index);


            if(priority==0 && card_max_size_.height() > boundaries_.height())
            {
                scalevalue =  current_card_max_size_.height() / (card_max_size_.height());

                //A hacky adjust so that bottom of the bottom card doesn't go below the scene border
                //scalevalue *= 0.95;

            }
            else
            {
                qreal scalemultiplier = (priority+1)/2;
                scalevalue = pow(current_scale_factor_, scalemultiplier);
                //scalevalue *= 0.9;
            }


            QPropertyAnimation* anim = dynamic_cast<QPropertyAnimation*>(dynamic_cast<QParallelAnimationGroup*>(animations_->animationAt(index))->animationAt(1));
            if (anim)
            {
                anim->stop();
                anim->setStartValue(obj->scale());
                anim->setEndValue(scalevalue);
                anim->start();
            }
        }
예제 #2
0
void KItemListViewAnimation::setScrollOffset(qreal offset)
{
    const qreal diff = m_scrollOffset - offset;
    m_scrollOffset = offset;

    // The change of the offset requires that the position of all
    // animated QGraphicsWidgets get adjusted. An exception is made
    // for the delete animation that should just fade away on the
    // existing position.
    for (int type = 0; type < AnimationTypeCount; ++type) {
        if (type == DeleteAnimation) {
            continue;
        }

        QHashIterator<QGraphicsWidget*, QPropertyAnimation*>  it(m_animation[type]);
        while (it.hasNext()) {
            it.next();

            QGraphicsWidget* widget = it.key();
            QPropertyAnimation* propertyAnim = it.value();

            QPointF currentPos = widget->pos();
            if (m_scrollOrientation == Qt::Vertical) {
                currentPos.ry() += diff;
            } else {
                currentPos.rx() += diff;
            }

            if (type == MovingAnimation) {
                // Stop the animation, calculate the moved start- and end-value
                // and restart the animation for the remaining duration.
                const int remainingDuration = propertyAnim->duration()
                                              - propertyAnim->currentTime();

                const bool block = propertyAnim->signalsBlocked();
                propertyAnim->blockSignals(true);
                propertyAnim->stop();

                QPointF endPos = propertyAnim->endValue().toPointF();
                if (m_scrollOrientation == Qt::Vertical) {
                    endPos.ry() += diff;
                } else {
                    endPos.rx() += diff;
                }

                propertyAnim->setDuration(remainingDuration);
                propertyAnim->setStartValue(currentPos);
                propertyAnim->setEndValue(endPos);
                propertyAnim->start();
                propertyAnim->blockSignals(block);
            } else {
                widget->setPos(currentPos);
            }
        }
    }
}
예제 #3
0
 void EtherMenu::MoveObjectToPosition(int index,const QPointF& point)
 {
     InfoCard* obj = objects_.at(index);
     QPropertyAnimation* anim = dynamic_cast<QPropertyAnimation*>(dynamic_cast<QParallelAnimationGroup*>(animations_->animationAt(index))->animationAt(0));
     if(anim)
     {
         anim->stop();
         anim->setStartValue(obj->pos());
         anim->setEndValue(point);
         anim->start();
     }
 }
예제 #4
0
 void EtherMenu::ShowCardAtIndex(int index)
 {
     InfoCard* obj = objects_.at(index);
     QPropertyAnimation* animopa = dynamic_cast<QPropertyAnimation*>(dynamic_cast<QParallelAnimationGroup*>(animations_->animationAt(index))->animationAt(2));
     if(animopa)
     {
         animopa->stop();
         animopa->setStartValue(obj->opacity());
         animopa->setEndValue(visible_);
         animopa->start();
     }
 }
예제 #5
0
        void EtherMenu::HideCardAtIndex(int index)
        {
            InfoCard* obj = objects_.at(index);
            //all visible objects have higher Z order
            ZOrderObjectBasedOnPriority(index, max_visible_objects_ + 1, true);

            QPropertyAnimation* animpos = dynamic_cast<QPropertyAnimation*>(dynamic_cast<QParallelAnimationGroup*>(animations_->animationAt(index))->animationAt(0));
            if(animpos)
            {
                animpos->stop();
                animpos->setStartValue(obj->pos());
                animpos->setEndValue(hide_point_);
                animpos->start();
            }

            QPropertyAnimation* animopa = dynamic_cast<QPropertyAnimation*>(dynamic_cast<QParallelAnimationGroup*>(animations_->animationAt(index))->animationAt(2));
            if(animopa)
            {
                animopa->stop();
                animopa->setStartValue(obj->opacity());
                animopa->setEndValue(invisible_);
                animopa->start();
            }
        }
예제 #6
0
void QWidgetAnimator::abort(QWidget *w)
{
#ifndef QT_NO_ANIMATION
    AnimationMap::iterator it = m_animation_map.find(w);
    if (it == m_animation_map.end())
        return;
    QPropertyAnimation *anim = *it;
    m_animation_map.erase(it);
    anim->stop();
#ifndef QT_NO_MAINWINDOW
    m_mainWindowLayout->animationFinished(w);
#endif
#else
    Q_UNUSED(w); //there is no animation to abort
#endif //QT_NO_ANIMATION
}
예제 #7
0
 void EtherMenu::ChangeObjectOpacityBasedOnPriority(int index,int priority)
 {
     if(opacity_factor_>0)
     {
         InfoCard* obj = objects_.at(index);
         int opacity_level = (priority+1)/2;
         QPropertyAnimation* anim = dynamic_cast<QPropertyAnimation*>(dynamic_cast<QParallelAnimationGroup*>(animations_->animationAt(index))->animationAt(2));
         if (anim)
         {
             anim->stop();
             anim->setStartValue(obj->opacity());
             anim->setEndValue(1- opacity_level*opacity_factor_);
             anim->start();
         }
     }
 }
예제 #8
0
 void EtherMenu::ZOrderObjectBasedOnPriority(int index, int priority, bool animated)
 {
     InfoCard* obj = objects_.at(index);
     if (animated)
     {
         QPropertyAnimation* anim = dynamic_cast<QPropertyAnimation*>(dynamic_cast<QParallelAnimationGroup*>(animations_->animationAt(index))->animationAt(3));
         if (anim)
         {
             anim->stop();
             anim->setStartValue(obj->scale());
             anim->setEndValue(max_visible_objects_- priority);
             anim->start();
         }
     }
     else
     {
         obj->setZValue(max_visible_objects_- priority);
     }
 }
예제 #9
0
파일: Applet.cpp 프로젝트: cancamilo/amarok
void
Context::Applet::collapse( bool on )
{
    qreal finalHeight = ( on ) ? m_heightCollapseOn : m_heightCollapseOff;
    const qreal maxHeight = containment()->size().height();
    if( (finalHeight > maxHeight) || (finalHeight < 0) )
        finalHeight = maxHeight;

    prepareGeometryChange();
    // warning: view() currently can return pointer to ToolbarView, not the ContextView
    ContextView *v = ContextView::self(); // may return null
    // Plasma::Applet::view() might return 0, if the widget is not yet constructed, etc.
    // \sa https://bugs.kde.org/show_bug.cgi?id=258741. If view is not available
    // yet, regardless of the animation setting the preferred size is set
    // straight away.
    if( !v || !AmarokConfig::animateAppletCollapse() )
    {
        setPreferredHeight( finalHeight );
        emit sizeHintChanged( Qt::PreferredSize );
        updateGeometry();
        return;
    }

    if( finalHeight == size().height() )
        return;

    // debug() << pluginName() << (on ? "collapsing to" : "uncollapsing to") << finalHeight;
    QPropertyAnimation *pan = m_animation.data();
    if( !pan )
        pan = new QPropertyAnimation( this, "preferredSize" );
    if( pan->state() == QAbstractAnimation::Running )
        pan->stop();
    pan->setDuration( 600 );
    pan->setEasingCurve( QEasingCurve::InQuad );
    pan->setStartValue( size() );
    pan->setEndValue( QSizeF(size().width(), finalHeight) );
    connect( pan, SIGNAL(finished()), SLOT(collapseAnimationFinished()) );
    m_animation = pan;
    pan->setDirection( QAbstractAnimation::Forward );

    v->addCollapseAnimation( pan );
}
예제 #10
0
void KItemListViewAnimation::stop(QGraphicsWidget* widget, AnimationType type)
{
    QPropertyAnimation* propertyAnim = m_animation[type].value(widget);
    if (propertyAnim) {
        propertyAnim->stop();

        switch (type) {
        case MovingAnimation: break;
        case CreateAnimation: widget->setOpacity(1.0); break;
        case DeleteAnimation: widget->setOpacity(0.0); break;
        case ResizeAnimation: break;
        default: break;
        }

        m_animation[type].remove(widget);
        delete propertyAnim;

        emit finished(widget, type);
    }
}
예제 #11
0
void FancyTabProxyStyle::drawControl(
    ControlElement element, const QStyleOption* option,
    QPainter* p, const QWidget* widget) const
{

    const QStyleOptionTab* v_opt = qstyleoption_cast<const QStyleOptionTab*>(option);

    if (element != CE_TabBarTab || !v_opt) {
        QProxyStyle::drawControl(element, option, p, widget);
        return;
    }

    const QRect rect = v_opt->rect;
    const bool selected = v_opt->state & State_Selected;
    const bool vertical_tabs = v_opt->shape == QTabBar::RoundedWest;
    const QString text = v_opt->text;

    if (selected) {
        //background
        p->save();
        QLinearGradient grad(rect.topLeft(), rect.topRight());
        grad.setColorAt(0, QColor(255, 255, 255, 140));
        grad.setColorAt(1, QColor(255, 255, 255, 210));
        p->fillRect(rect.adjusted(0, 0, 0, -1), grad);
        p->restore();

        //shadows
        p->setPen(QColor(0, 0, 0, 110));
        p->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1));
        p->drawLine(rect.bottomLeft(), rect.bottomRight());
        p->setPen(QColor(0, 0, 0, 40));
        p->drawLine(rect.topLeft(), rect.bottomLeft());

        //highlights
        p->setPen(QColor(255, 255, 255, 50));
        p->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2));
        p->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1));
        p->setPen(QColor(255, 255, 255, 40));
        p->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight());
        p->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1));
        p->drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1));
    }

    QTransform m;
    if (vertical_tabs) {
        m = QTransform::fromTranslate(rect.left(), rect.bottom());
        m.rotate(-90);
    }
    else {
        m = QTransform::fromTranslate(rect.left(), rect.top());
    }

    const QRect draw_rect(QPoint(0, 0), m.mapRect(rect).size());

    p->save();
    p->setTransform(m);

    QRect icon_rect(QPoint(8, 0), v_opt->iconSize);
    QRect text_rect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size());
    text_rect.setRight(draw_rect.width());
    icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2);

    QFont boldFont(p->font());
    boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
    boldFont.setBold(true);
    p->setFont(boldFont);
    p->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
    int textFlags = Qt::AlignHCenter | Qt::AlignVCenter;
    p->drawText(text_rect, textFlags, text);
    p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
    if (widget) {
        const QString fader_key = "tab_" + text + "_fader";
        const QString animation_key = "tab_" + text + "_animation";

        const QString tab_hover = widget->property("tab_hover").toString();
        int fader = widget->property(fader_key.toUtf8().constData()).toInt();
        QPropertyAnimation* animation = widget->property(animation_key.toUtf8().constData()).value<QPropertyAnimation*>();

        if (!animation) {
            QWidget* mut_widget = const_cast<QWidget*>(widget);
            fader = 0;
            mut_widget->setProperty(fader_key.toUtf8().constData(), fader);
            animation = new QPropertyAnimation(mut_widget, fader_key.toUtf8(), mut_widget);
            connect(animation, SIGNAL(valueChanged(QVariant)), mut_widget, SLOT(update()));
            mut_widget->setProperty(animation_key.toUtf8().constData(), QVariant::fromValue(animation));
        }

        if (text == tab_hover) {
            if (animation->state() != QAbstractAnimation::Running && fader != 40) {
                animation->stop();
                animation->setDuration(80);
                animation->setEndValue(40);
                animation->start();
            }
        }
        else {
            if (animation->state() != QAbstractAnimation::Running && fader != 0) {
                animation->stop();
                animation->setDuration(160);
                animation->setEndValue(0);
                animation->start();
            }
        }

        if (!selected) {
            p->save();
            p->fillRect(draw_rect, QColor(255, 255, 255, fader));
            p->setPen(QPen(QColor(255, 255, 255, fader), 1.0));
            p->drawLine(draw_rect.topLeft(), vertical_tabs ? draw_rect.bottomLeft() : draw_rect.topRight());
            p->drawLine(draw_rect.bottomRight(), vertical_tabs ? draw_rect.topRight() : draw_rect.bottomLeft());
            p->restore();
        }
    }

    Utils::StyleHelper::drawIconWithShadow(v_opt->icon, icon_rect, p, selected ? QIcon::Selected : QIcon::Normal);

    p->drawText(text_rect.translated(0, -1), textFlags, text);

    p->restore();
}
예제 #12
0
void FancyTabProxyStyle::drawControl(
    ControlElement element, const QStyleOption* option,
    QPainter* p, const QWidget* widget) const {

  const QStyleOptionTabV3* v_opt = qstyleoption_cast<const QStyleOptionTabV3*>(option);

  if (element != CE_TabBarTab || !v_opt) {
    QProxyStyle::drawControl(element, option, p, widget);
    return;
  }

  const QRect rect = v_opt->rect;
  const bool selected = v_opt->state & State_Selected;
  const bool vertical_tabs = v_opt->shape == QTabBar::RoundedWest;
  const QString text = v_opt->text;

  QTransform m;
  if (vertical_tabs) {
    m = QTransform::fromTranslate(rect.left(), rect.bottom());
    m.rotate(-90);
  } else {
    m = QTransform::fromTranslate(rect.left(), rect.top());
  }

  const QRect draw_rect(QPoint(0, 0), m.mapRect(rect).size());

  if (!selected && GtkStyle::isActive()) {
      p->fillRect(option->rect, option->palette.background());
  }

  p->save();
  p->setTransform(m);

  QRect icon_rect(QPoint(8, 0), v_opt->iconSize);
  QRect text_rect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size());
  text_rect.setRight(draw_rect.width());
  icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2);

    QStyleOptionViewItemV4 styleOpt;
    styleOpt.palette=option->palette;
    styleOpt.rect=draw_rect;
    if (QStyleOptionTab::Beginning==v_opt->position) {
        styleOpt.rect.adjust(0, 0, -1, 0);
    }
    styleOpt.state=option->state;
    styleOpt.state&=~(QStyle::State_Selected|QStyle::State_MouseOver);
    styleOpt.state|=QStyle::State_Selected|QStyle::State_Enabled;
    styleOpt.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
    styleOpt.showDecorationSelected=true;
    bool drawBgnd=true;
    int fader = 1;

    if (!selected && drawBgnd) {
        const QString fader_key = "tab_" + text + "_fader";
        const QString animation_key = "tab_" + text + "_animation";

        const QString tab_hover = widget->property("tab_hover").toString();
        fader=widget->property(fader_key.toUtf8().constData()).toInt();
        QPropertyAnimation* animation = widget->property(animation_key.toUtf8().constData()).value<QPropertyAnimation*>();

        if (!animation) {
            QWidget* mut_widget = const_cast<QWidget*>(widget);
            fader = 0;
            mut_widget->setProperty(fader_key.toUtf8().constData(), fader);
            animation = new QPropertyAnimation(mut_widget, fader_key.toUtf8(), mut_widget);
            connect(animation, SIGNAL(valueChanged(QVariant)), mut_widget, SLOT(update()));
            mut_widget->setProperty(animation_key.toUtf8().constData(), QVariant::fromValue(animation));
        }

        if (text == tab_hover) {
            if (animation->state() != QAbstractAnimation::Running && fader != 40) {
                animation->stop();
                animation->setDuration(80);
                animation->setEndValue(50);
                animation->start();
            }
        } else {
            if (animation->state() != QAbstractAnimation::Running && fader != 0) {
                animation->stop();
                animation->setDuration(160);
                animation->setEndValue(0);
                animation->start();
            }
        }

        if (fader<1) {
            drawBgnd=false;
        } else {
            QColor col(styleOpt.palette.highlight().color());
            col.setAlpha(fader);
            styleOpt.palette.setColor(styleOpt.palette.currentColorGroup(), QPalette::Highlight, col);
        }
    }

    if (drawBgnd) {
        if (!selected && GtkStyle::isActive()) {
            GtkStyle::drawSelection(styleOpt, p, (fader*1.0)/150.0);
        } else {
            QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &styleOpt, p, 0);
        }
    }
//     drawRoundedRect(p, draw_rect, 3, col);


//   QFont boldFont(p->font());
//   boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
// //   boldFont.setBold(true);
//   p->setFont(boldFont);
//   p->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
  int textFlags = Qt::AlignTop | Qt::AlignVCenter;
//   p->drawText(text_rect, textFlags, text);
//   p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor());
    p->setPen(selected && option->state&State_Active
              ? QApplication::palette().highlightedText().color() : QApplication::palette().foreground().color());

  drawIcon(v_opt->icon, icon_rect, p, v_opt->iconSize,
           selected && option->state&State_Active);

  QString txt=text;
  txt.replace("&", "");
  txt=p->fontMetrics().elidedText(txt, elideMode(), text_rect.width());

  p->drawText(text_rect.translated(0, -1), textFlags, txt);

  p->restore();
}