1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/**
* Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
* Copyright (C) 2002-2004 Scott Wheeler <wheeler@kde.org>
* Copyright (C) 2007, 2008, 2009 Michael Pyne <mpyne@kde.org>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JUK_SYSTEMTRAY_H
#define JUK_SYSTEMTRAY_H
#include <kstatusnotifieritem.h>
#include <QVector>
#include <QColor>
#include <QPixmap>
#include <QIcon>
#include <QFrame>
class SystemTray;
class PlayerManager;
class QLabel;
class QTimer;
class KVBox;
class FileHandle;
class QVBoxLayout;
/**
* Workalike of KPassivePopup intended to more easily support JuK's particular
* usage pattern, including things like staying open while under the mouse.
*
* @author Michael Pyne <mpyne@kde.org>
*/
class PassiveInfo : public QFrame
{
Q_OBJECT
public:
PassiveInfo();
// Sets view as a child widget to show in the popup window.
// This widget does not take ownership of the widget. If you want it auto-deleted,
// either re-parent it or create it using this widget as its parent.
void setView(QWidget *view);
QWidget *view() const;
public slots:
// Starts a timer to show the popup. The popup will not automatically delete itself
// once hidden.
void startTimer(int delay);
virtual void show();
signals:
void mouseEntered();
void timeExpired();
void previousSong();
void nextSong();
protected:
virtual void enterEvent(QEvent *);
virtual void leaveEvent(QEvent *);
virtual void hideEvent(QHideEvent *);
virtual void wheelEvent(QWheelEvent *);
private:
// Move us near the required position.
void positionSelf();
private slots:
void timerExpired();
private:
QTimer *m_timer;
QVBoxLayout *m_layout;
bool m_justDie;
};
class SystemTray : public KStatusNotifierItem
{
Q_OBJECT
public:
explicit SystemTray(PlayerManager *player, QWidget *parent = 0);
signals:
// Emitted when the fade process is complete.
void fadeDone();
private:
static const int STEPS = 20; ///< Number of intermediate steps for fading.
void createPopup();
void setToolTip(const QString &tip = QString(), const QPixmap &cover = QPixmap());
void createButtonBox(QWidget *parent);
// Creates the widget layout for the popup, returning the QVBox that
// holds the text labels.
KVBox *createPopupLayout(QWidget *parent, const FileHandle &file);
void addSeparatorLine(QWidget *parent);
void addCoverButton(QWidget *parent, const QPixmap &cover);
// Interpolates from start color to end color. If @p step == 0, then
// m_startColor is returned, while @p step == @steps returns
// m_endColor.
QColor interpolateColor(int step, int steps = STEPS);
private slots:
void slotPlay();
void slotPause();
void slotStop();
void slotPopupDestroyed();
void slotNextStep(); ///< This is the fading routine.
void slotPopupLargeCover();
void slotForward();
void slotBack();
void slotFadeOut(); ///< Fades out the text
void slotMouseInPopup(); ///< Forces the text back to its normal color.
void scrollEvent(int delta, Qt::Orientation orientation);
private:
QPixmap m_backPix;
QPixmap m_forwardPix;
QColor m_startColor, m_endColor;
PassiveInfo *m_popup;
PlayerManager *m_player;
QVector<QLabel *> m_labels;
QTimer *m_fadeTimer;
int m_step;
bool m_fade;
/// Used to choose between manual fade and windowOpacity
bool m_hasCompositionManager;
};
#endif // JUK_SYSTEMTRAY_H
// vim: set et sw=4 tw=0 sta:
|