Changeset View
Changeset View
Standalone View
Standalone View
kdecoration/breezebutton.cpp
Show All 18 Lines | |||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | 20 | */ | ||
21 | #include "breezebutton.h" | 21 | #include "breezebutton.h" | ||
22 | 22 | | |||
23 | #include <KDecoration2/DecoratedClient> | 23 | #include <KDecoration2/DecoratedClient> | ||
24 | #include <KColorUtils> | 24 | #include <KColorUtils> | ||
25 | 25 | | |||
26 | #include <QPainter> | 26 | #include <QPainter> | ||
27 | #include <QVariantAnimation> | ||||
27 | 28 | | |||
28 | namespace Breeze | 29 | namespace Breeze | ||
29 | { | 30 | { | ||
30 | 31 | | |||
31 | using KDecoration2::ColorRole; | 32 | using KDecoration2::ColorRole; | ||
32 | using KDecoration2::ColorGroup; | 33 | using KDecoration2::ColorGroup; | ||
33 | using KDecoration2::DecorationButtonType; | 34 | using KDecoration2::DecorationButtonType; | ||
34 | 35 | | |||
35 | 36 | | |||
36 | //__________________________________________________________________ | 37 | //__________________________________________________________________ | ||
37 | Button::Button(DecorationButtonType type, Decoration* decoration, QObject* parent) | 38 | Button::Button(DecorationButtonType type, Decoration* decoration, QObject* parent) | ||
38 | : DecorationButton(type, decoration, parent) | 39 | : DecorationButton(type, decoration, parent) | ||
39 | , m_animation( new QPropertyAnimation( this ) ) | 40 | , m_animation( new QVariantAnimation( this ) ) | ||
40 | { | 41 | { | ||
41 | 42 | | |||
42 | // setup animation | 43 | // setup animation | ||
43 | m_animation->setStartValue( 0 ); | 44 | // It is important start and end value are of the same type, hence 0.0 and not just 0 | ||
45 | m_animation->setStartValue( 0.0 ); | ||||
44 | m_animation->setEndValue( 1.0 ); | 46 | m_animation->setEndValue( 1.0 ); | ||
45 | m_animation->setTargetObject( this ); | | |||
46 | m_animation->setPropertyName( "opacity" ); | | |||
47 | m_animation->setEasingCurve( QEasingCurve::InOutQuad ); | 47 | m_animation->setEasingCurve( QEasingCurve::InOutQuad ); | ||
48 | connect(m_animation, &QVariantAnimation::valueChanged, this, [this](const QVariant &value) { | ||||
49 | setOpacity(value.toReal()); | ||||
50 | }); | ||||
48 | 51 | | |||
49 | // setup default geometry | 52 | // setup default geometry | ||
50 | const int height = decoration->buttonHeight(); | 53 | const int height = decoration->buttonHeight(); | ||
51 | setGeometry(QRect(0, 0, height, height)); | 54 | setGeometry(QRect(0, 0, height, height)); | ||
52 | setIconSize(QSize( height, height )); | 55 | setIconSize(QSize( height, height )); | ||
53 | 56 | | |||
54 | // connections | 57 | // connections | ||
55 | connect(decoration->client().data(), SIGNAL(iconChanged(QIcon)), this, SLOT(update())); | 58 | connect(decoration->client().data(), SIGNAL(iconChanged(QIcon)), this, SLOT(update())); | ||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Line(s) | 363 | { | |||
370 | } else if( type() == DecorationButtonType::Close && d->internalSettings()->outlineCloseButton() ) { | 373 | } else if( type() == DecorationButtonType::Close && d->internalSettings()->outlineCloseButton() ) { | ||
371 | 374 | | |||
372 | return d->titleBarColor(); | 375 | return d->titleBarColor(); | ||
373 | 376 | | |||
374 | } else if( ( type() == DecorationButtonType::KeepBelow || type() == DecorationButtonType::KeepAbove || type() == DecorationButtonType::Shade ) && isChecked() ) { | 377 | } else if( ( type() == DecorationButtonType::KeepBelow || type() == DecorationButtonType::KeepAbove || type() == DecorationButtonType::Shade ) && isChecked() ) { | ||
375 | 378 | | |||
376 | return d->titleBarColor(); | 379 | return d->titleBarColor(); | ||
377 | 380 | | |||
378 | } else if( m_animation->state() == QPropertyAnimation::Running ) { | 381 | } else if( m_animation->state() == QAbstractAnimation::Running ) { | ||
379 | 382 | | |||
380 | return KColorUtils::mix( d->fontColor(), d->titleBarColor(), m_opacity ); | 383 | return KColorUtils::mix( d->fontColor(), d->titleBarColor(), m_opacity ); | ||
381 | 384 | | |||
382 | } else if( isHovered() ) { | 385 | } else if( isHovered() ) { | ||
383 | 386 | | |||
384 | return d->titleBarColor(); | 387 | return d->titleBarColor(); | ||
385 | 388 | | |||
386 | } else { | 389 | } else { | ||
Show All 19 Lines | 408 | if( isPressed() ) { | |||
406 | 409 | | |||
407 | if( type() == DecorationButtonType::Close ) return c->color( ColorGroup::Warning, ColorRole::Foreground ); | 410 | if( type() == DecorationButtonType::Close ) return c->color( ColorGroup::Warning, ColorRole::Foreground ); | ||
408 | else return KColorUtils::mix( d->titleBarColor(), d->fontColor(), 0.3 ); | 411 | else return KColorUtils::mix( d->titleBarColor(), d->fontColor(), 0.3 ); | ||
409 | 412 | | |||
410 | } else if( ( type() == DecorationButtonType::KeepBelow || type() == DecorationButtonType::KeepAbove || type() == DecorationButtonType::Shade ) && isChecked() ) { | 413 | } else if( ( type() == DecorationButtonType::KeepBelow || type() == DecorationButtonType::KeepAbove || type() == DecorationButtonType::Shade ) && isChecked() ) { | ||
411 | 414 | | |||
412 | return d->fontColor(); | 415 | return d->fontColor(); | ||
413 | 416 | | |||
414 | } else if( m_animation->state() == QPropertyAnimation::Running ) { | 417 | } else if( m_animation->state() == QAbstractAnimation::Running ) { | ||
415 | 418 | | |||
416 | if( type() == DecorationButtonType::Close ) | 419 | if( type() == DecorationButtonType::Close ) | ||
417 | { | 420 | { | ||
418 | if( d->internalSettings()->outlineCloseButton() ) | 421 | if( d->internalSettings()->outlineCloseButton() ) | ||
419 | { | 422 | { | ||
420 | 423 | | |||
421 | return KColorUtils::mix( d->fontColor(), c->color( ColorGroup::Warning, ColorRole::Foreground ).lighter(), m_opacity ); | 424 | return KColorUtils::mix( d->fontColor(), c->color( ColorGroup::Warning, ColorRole::Foreground ).lighter(), m_opacity ); | ||
422 | 425 | | |||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
465 | 468 | | |||
466 | //__________________________________________________________________ | 469 | //__________________________________________________________________ | ||
467 | void Button::updateAnimationState( bool hovered ) | 470 | void Button::updateAnimationState( bool hovered ) | ||
468 | { | 471 | { | ||
469 | 472 | | |||
470 | auto d = qobject_cast<Decoration*>(decoration()); | 473 | auto d = qobject_cast<Decoration*>(decoration()); | ||
471 | if( !(d && d->internalSettings()->animationsEnabled() ) ) return; | 474 | if( !(d && d->internalSettings()->animationsEnabled() ) ) return; | ||
472 | 475 | | |||
473 | m_animation->setDirection( hovered ? QPropertyAnimation::Forward : QPropertyAnimation::Backward ); | 476 | m_animation->setDirection( hovered ? QAbstractAnimation::Forward : QAbstractAnimation::Backward ); | ||
474 | if( m_animation->state() != QPropertyAnimation::Running ) m_animation->start(); | 477 | if( m_animation->state() != QAbstractAnimation::Running ) m_animation->start(); | ||
475 | 478 | | |||
476 | } | 479 | } | ||
477 | 480 | | |||
478 | } // namespace | 481 | } // namespace |