~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to part/view/kateanimation.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE and the Kate project
2
 
 *
3
 
 *   Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
4
 
 *
5
 
 *  This library is free software; you can redistribute it and/or
6
 
 *  modify it under the terms of the GNU Library General Public
7
 
 *  License as published by the Free Software Foundation; either
8
 
 *  version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 *  This library is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 *  Library General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU Library General Public License
16
 
 *  along with this library; see the file COPYING.LIB.  If not, write to
17
 
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 *  Boston, MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
#include "kateanimation.h"
22
 
#include "kateanimation.moc"
23
 
#include <katefadeeffect.h>
24
 
 
25
 
#include <KMessageWidget>
26
 
#include <QTimer>
27
 
#include <kglobalsettings.h>
28
 
 
29
 
KateAnimation::KateAnimation(KMessageWidget* widget, EffectType effect)
30
 
  : QObject(widget)
31
 
  , m_widget(widget)
32
 
  , m_fadeEffect(0)
33
 
{
34
 
  Q_ASSERT(m_widget != 0);
35
 
 
36
 
  // create wanted effect
37
 
  if (effect == FadeEffect) {
38
 
    m_fadeEffect = new KateFadeEffect(widget);
39
 
  }
40
 
 
41
 
  // create tracking timer for hiding the widget
42
 
  m_hideTimer = new QTimer(this);
43
 
  m_hideTimer->setInterval(550); // 500 from KMessageWidget + 50 to make sure the hide animation is really finished
44
 
  m_hideTimer->setSingleShot(true);
45
 
  connect(m_hideTimer, SIGNAL(timeout()), this, SIGNAL(widgetHidden()));
46
 
 
47
 
  // create tracking timer for showing the widget
48
 
  m_showTimer = new QTimer(this);
49
 
  m_showTimer->setInterval(550); // 500 from KMessageWidget + 50 to make sure the show animation is really finished
50
 
  m_showTimer->setSingleShot(true);
51
 
  connect(m_showTimer, SIGNAL(timeout()), this, SIGNAL(widgetShown()));
52
 
}
53
 
 
54
 
bool KateAnimation::hideAnimationActive() const
55
 
{
56
 
  return m_hideTimer->isActive();
57
 
}
58
 
 
59
 
bool KateAnimation::showAnimationActive() const
60
 
{
61
 
  return m_showTimer->isActive();
62
 
}
63
 
 
64
 
void KateAnimation::show()
65
 
{
66
 
  Q_ASSERT(m_widget != 0);
67
 
 
68
 
  // stop hide timer if needed
69
 
  if (m_hideTimer->isActive()) {
70
 
    m_hideTimer->stop();
71
 
  }
72
 
 
73
 
  // show according to effects config
74
 
  if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
75
 
    m_widget->show();
76
 
    emit widgetShown();
77
 
  } else {
78
 
    // launch show effect
79
 
    // NOTE: use a singleShot timer to avoid resizing issues when showing the message widget the first time (bug #316666)
80
 
    if (m_fadeEffect) {
81
 
      QTimer::singleShot(0, m_fadeEffect, SLOT(fadeIn()));
82
 
    } else {
83
 
      QTimer::singleShot(0, m_widget, SLOT(animatedShow()));
84
 
    }
85
 
 
86
 
    // start timer in order to track when showing is done (this effectively works
87
 
    // around the fact, that KMessageWidget does not have a hidden signal)
88
 
    m_showTimer->start();
89
 
  }
90
 
}
91
 
 
92
 
void KateAnimation::hide()
93
 
{
94
 
  Q_ASSERT(m_widget != 0);
95
 
 
96
 
  // stop show timer if needed
97
 
  if (m_showTimer->isActive()) {
98
 
    m_showTimer->stop();
99
 
  }
100
 
  
101
 
  // hide according to effects config
102
 
  if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
103
 
    m_widget->hide();
104
 
    emit widgetHidden();
105
 
  } else {
106
 
    // hide depending on effect
107
 
    if (m_fadeEffect) {
108
 
      m_fadeEffect->fadeOut();
109
 
    } else {
110
 
      m_widget->animatedHide();
111
 
    }
112
 
 
113
 
    // start timer in order to track when hiding is done (this effectively works
114
 
    // around the fact, that KMessageWidget does not have a hidden signal)
115
 
    m_hideTimer->start();
116
 
  }
117
 
}
118
 
 
119
 
// kate: space-indent on; indent-width 2; replace-tabs on;