1 /* Copyright (C) 2013 Thomas Lübking <thomas.luebking@gmail.com>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * @short A generic Spinner, ie an overlay displaying some rotating stuff to indicate:
32 * Hold on, slow action in process...
33 * The Spinner fades in and out and automatically positions itself in the visible area of its
34 * parent with 2/3 of the smaller dimension of the visible parent rect.
36 class Spinner
: public QWidget
{
39 enum Type
{ Aperture
= 0, Scythe
, Elastic
, Sun
};
40 enum Context
{ Overlay
= 0, Throbber
};
41 /** Providing a @p parent that is NOT Null is mandatory! */
42 explicit Spinner(QWidget
*parent
);
44 * Set the context. Throbber suits the needs of a small icon with opaque foreground.
45 * You might recall that browsers used to have such when loading webpages took minutes.
46 * Throbbers have the optional text as tooltip.
47 * The default context is "Overlay"
49 void setContext(const Context c
);
50 Context
context() const;
51 /** The optional text */
53 /** Set a type to control the look a bit */
54 void setType(const Type t
);
58 * Set an optional text in the center of the rotating stuff
59 * the text of course does not rotate ;-)
61 void setText(const QString
&text
);
63 * You can start the spinner as much as you want. If it's still visible, this will just keep it
64 * alive (or do nothing)
65 * The optional @p delay in milliseconds can be used if you've no idea when you'll stop the
66 * spinner and want to avoid it if your stop condition triggers in eg. less then 250ms
67 * Ie. if you call m_spinner->start(250); QTimer::singleShot(100, m_spinner, SLOT(stop()));
68 * the spinner will never actually start (because the stop call arrives before the delay times
71 void start(uint delay
);
73 /** Stop the spinner, the spinner will fade out for around a second before it's really hidden */
77 bool event(QEvent
*e
);
78 bool eventFilter(QObject
*o
, QEvent
*e
);
79 void paintEvent(QPaintEvent
*e
);
80 void timerEvent(QTimerEvent
*e
);
82 void updateAncestors();
83 void updateGeometry();
89 QList
<QWidget
*> m_ancestors
;