Changeset View
Changeset View
Standalone View
Standalone View
kdecoration/breezedecoration.cpp
Show All 39 Lines | |||||
40 | #include <KConfigGroup> | 40 | #include <KConfigGroup> | ||
41 | #include <KColorUtils> | 41 | #include <KColorUtils> | ||
42 | #include <KSharedConfig> | 42 | #include <KSharedConfig> | ||
43 | #include <KPluginFactory> | 43 | #include <KPluginFactory> | ||
44 | 44 | | |||
45 | #include <QPainter> | 45 | #include <QPainter> | ||
46 | #include <QTextStream> | 46 | #include <QTextStream> | ||
47 | #include <QTimer> | 47 | #include <QTimer> | ||
48 | #include <QVariantAnimation> | ||||
48 | 49 | | |||
49 | #if BREEZE_HAVE_X11 | 50 | #if BREEZE_HAVE_X11 | ||
50 | #include <QX11Info> | 51 | #include <QX11Info> | ||
51 | #endif | 52 | #endif | ||
52 | 53 | | |||
53 | #include <cmath> | 54 | #include <cmath> | ||
54 | 55 | | |||
55 | K_PLUGIN_FACTORY_WITH_JSON( | 56 | K_PLUGIN_FACTORY_WITH_JSON( | ||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 148 | { | |||
154 | static int g_shadowSizeEnum = InternalSettings::ShadowLarge; | 155 | static int g_shadowSizeEnum = InternalSettings::ShadowLarge; | ||
155 | static int g_shadowStrength = 255; | 156 | static int g_shadowStrength = 255; | ||
156 | static QColor g_shadowColor = Qt::black; | 157 | static QColor g_shadowColor = Qt::black; | ||
157 | static QSharedPointer<KDecoration2::DecorationShadow> g_sShadow; | 158 | static QSharedPointer<KDecoration2::DecorationShadow> g_sShadow; | ||
158 | 159 | | |||
159 | //________________________________________________________________ | 160 | //________________________________________________________________ | ||
160 | Decoration::Decoration(QObject *parent, const QVariantList &args) | 161 | Decoration::Decoration(QObject *parent, const QVariantList &args) | ||
161 | : KDecoration2::Decoration(parent, args) | 162 | : KDecoration2::Decoration(parent, args) | ||
162 | , m_animation( new QPropertyAnimation( this ) ) | 163 | , m_animation( new QVariantAnimation( this ) ) | ||
163 | { | 164 | { | ||
164 | g_sDecoCount++; | 165 | g_sDecoCount++; | ||
165 | } | 166 | } | ||
166 | 167 | | |||
167 | //________________________________________________________________ | 168 | //________________________________________________________________ | ||
168 | Decoration::~Decoration() | 169 | Decoration::~Decoration() | ||
169 | { | 170 | { | ||
170 | g_sDecoCount--; | 171 | g_sDecoCount--; | ||
Show All 17 Lines | |||||
188 | } | 189 | } | ||
189 | 190 | | |||
190 | //________________________________________________________________ | 191 | //________________________________________________________________ | ||
191 | QColor Decoration::titleBarColor() const | 192 | QColor Decoration::titleBarColor() const | ||
192 | { | 193 | { | ||
193 | 194 | | |||
194 | auto c = client().data(); | 195 | auto c = client().data(); | ||
195 | if( hideTitleBar() ) return c->color( ColorGroup::Inactive, ColorRole::TitleBar ); | 196 | if( hideTitleBar() ) return c->color( ColorGroup::Inactive, ColorRole::TitleBar ); | ||
196 | else if( m_animation->state() == QPropertyAnimation::Running ) | 197 | else if( m_animation->state() == QAbstractAnimation::Running ) | ||
197 | { | 198 | { | ||
198 | return KColorUtils::mix( | 199 | return KColorUtils::mix( | ||
199 | c->color( ColorGroup::Inactive, ColorRole::TitleBar ), | 200 | c->color( ColorGroup::Inactive, ColorRole::TitleBar ), | ||
200 | c->color( ColorGroup::Active, ColorRole::TitleBar ), | 201 | c->color( ColorGroup::Active, ColorRole::TitleBar ), | ||
201 | m_opacity ); | 202 | m_opacity ); | ||
202 | } else return c->color( c->isActive() ? ColorGroup::Active : ColorGroup::Inactive, ColorRole::TitleBar ); | 203 | } else return c->color( c->isActive() ? ColorGroup::Active : ColorGroup::Inactive, ColorRole::TitleBar ); | ||
203 | 204 | | |||
204 | } | 205 | } | ||
205 | 206 | | |||
206 | //________________________________________________________________ | 207 | //________________________________________________________________ | ||
207 | QColor Decoration::outlineColor() const | 208 | QColor Decoration::outlineColor() const | ||
208 | { | 209 | { | ||
209 | 210 | | |||
210 | auto c( client().data() ); | 211 | auto c( client().data() ); | ||
211 | if( !m_internalSettings->drawTitleBarSeparator() ) return QColor(); | 212 | if( !m_internalSettings->drawTitleBarSeparator() ) return QColor(); | ||
212 | if( m_animation->state() == QPropertyAnimation::Running ) | 213 | if( m_animation->state() == QAbstractAnimation::Running ) | ||
213 | { | 214 | { | ||
214 | QColor color( c->palette().color( QPalette::Highlight ) ); | 215 | QColor color( c->palette().color( QPalette::Highlight ) ); | ||
215 | color.setAlpha( color.alpha()*m_opacity ); | 216 | color.setAlpha( color.alpha()*m_opacity ); | ||
216 | return color; | 217 | return color; | ||
217 | } else if( c->isActive() ) return c->palette().color( QPalette::Highlight ); | 218 | } else if( c->isActive() ) return c->palette().color( QPalette::Highlight ); | ||
218 | else return QColor(); | 219 | else return QColor(); | ||
219 | } | 220 | } | ||
220 | 221 | | |||
221 | //________________________________________________________________ | 222 | //________________________________________________________________ | ||
222 | QColor Decoration::fontColor() const | 223 | QColor Decoration::fontColor() const | ||
223 | { | 224 | { | ||
224 | 225 | | |||
225 | auto c = client().data(); | 226 | auto c = client().data(); | ||
226 | if( m_animation->state() == QPropertyAnimation::Running ) | 227 | if( m_animation->state() == QAbstractAnimation::Running ) | ||
227 | { | 228 | { | ||
228 | return KColorUtils::mix( | 229 | return KColorUtils::mix( | ||
229 | c->color( ColorGroup::Inactive, ColorRole::Foreground ), | 230 | c->color( ColorGroup::Inactive, ColorRole::Foreground ), | ||
230 | c->color( ColorGroup::Active, ColorRole::Foreground ), | 231 | c->color( ColorGroup::Active, ColorRole::Foreground ), | ||
231 | m_opacity ); | 232 | m_opacity ); | ||
232 | } else return c->color( c->isActive() ? ColorGroup::Active : ColorGroup::Inactive, ColorRole::Foreground ); | 233 | } else return c->color( c->isActive() ? ColorGroup::Active : ColorGroup::Inactive, ColorRole::Foreground ); | ||
233 | 234 | | |||
234 | } | 235 | } | ||
235 | 236 | | |||
236 | //________________________________________________________________ | 237 | //________________________________________________________________ | ||
237 | void Decoration::init() | 238 | void Decoration::init() | ||
238 | { | 239 | { | ||
239 | auto c = client().data(); | 240 | auto c = client().data(); | ||
240 | 241 | | |||
241 | // active state change animation | 242 | // active state change animation | ||
242 | m_animation->setStartValue( 0 ); | 243 | // It is important start and end value are of the same type, hence 0.0 and not just 0 | ||
244 | m_animation->setStartValue( 0.0 ); | ||||
243 | m_animation->setEndValue( 1.0 ); | 245 | m_animation->setEndValue( 1.0 ); | ||
244 | m_animation->setTargetObject( this ); | | |||
245 | m_animation->setPropertyName( "opacity" ); | | |||
246 | m_animation->setEasingCurve( QEasingCurve::InOutQuad ); | 246 | m_animation->setEasingCurve( QEasingCurve::InOutQuad ); | ||
247 | connect(m_animation, &QVariantAnimation::valueChanged, this, [this](const QVariant &value) { | ||||
248 | setOpacity(value.toReal()); | ||||
249 | }); | ||||
247 | 250 | | |||
248 | reconfigure(); | 251 | reconfigure(); | ||
249 | updateTitleBar(); | 252 | updateTitleBar(); | ||
250 | auto s = settings(); | 253 | auto s = settings(); | ||
251 | connect(s.data(), &KDecoration2::DecorationSettings::borderSizeChanged, this, &Decoration::recalculateBorders); | 254 | connect(s.data(), &KDecoration2::DecorationSettings::borderSizeChanged, this, &Decoration::recalculateBorders); | ||
252 | 255 | | |||
253 | // a change in font might cause the borders to change | 256 | // a change in font might cause the borders to change | ||
254 | connect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &Decoration::recalculateBorders); | 257 | connect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &Decoration::recalculateBorders); | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
305 | 308 | | |||
306 | //________________________________________________________________ | 309 | //________________________________________________________________ | ||
307 | void Decoration::updateAnimationState() | 310 | void Decoration::updateAnimationState() | ||
308 | { | 311 | { | ||
309 | if( m_internalSettings->animationsEnabled() ) | 312 | if( m_internalSettings->animationsEnabled() ) | ||
310 | { | 313 | { | ||
311 | 314 | | |||
312 | auto c = client().data(); | 315 | auto c = client().data(); | ||
313 | m_animation->setDirection( c->isActive() ? QPropertyAnimation::Forward : QPropertyAnimation::Backward ); | 316 | m_animation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward ); | ||
314 | if( m_animation->state() != QPropertyAnimation::Running ) m_animation->start(); | 317 | if( m_animation->state() != QAbstractAnimation::Running ) m_animation->start(); | ||
315 | 318 | | |||
316 | } else { | 319 | } else { | ||
317 | 320 | | |||
318 | update(); | 321 | update(); | ||
319 | 322 | | |||
320 | } | 323 | } | ||
321 | } | 324 | } | ||
322 | 325 | | |||
▲ Show 20 Lines • Show All 509 Lines • Show Last 20 Lines |