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 ); }
void Widget::reverseStart() { //If last message, play hide animation. if (m_messageQueue.size() <= 1) { QPropertyAnimation* bounceAnim = qobject_cast<QPropertyAnimation*>(m_animation.animationAt(1)); if(bounceAnim) { if(bounceAnim->state() == QAbstractAnimation::Running){ return; } } if (!m_messageQueue.isEmpty()){ if(m_animation.animationAt(1)){ doneBounce(); } m_messageQueue.pop_front(); } unsigned int duration = m_settings.get("gui/out_animation_duration").toInt(); QPropertyAnimation* anim = qobject_cast<QPropertyAnimation*>(m_animation.animationAt(0)); if (!anim) { return; } disconnect(anim, SIGNAL(valueChanged(QVariant)), this, m_activePositionSlot.c_str()); anim->setDirection(QAnimationGroup::Backward); anim->setEasingCurve(QEasingCurve::Type(m_settings.get("gui/out_animation").toInt())); anim->setDuration(duration); anim->setCurrentTime(duration); connect(anim, SIGNAL(valueChanged(QVariant)), this, m_activePositionSlot.c_str()); anim->start(); //m_shortcutGrabber.disableShortcuts(); } else { autoNext(); } }
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(); }
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(); }