systemtray.h 4.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/**
 * 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/>.
 */
18

19 20
#ifndef JUK_SYSTEMTRAY_H
#define JUK_SYSTEMTRAY_H
21

Michael Pyne's avatar
Michael Pyne committed
22
#include <KStatusNotifierItem>
23

24
#include <QVector>
25
#include <QColor>
Laurent Montel's avatar
Laurent Montel committed
26
#include <QPixmap>
Stephan Kulow's avatar
Stephan Kulow committed
27
#include <QIcon>
28
#include <QFrame>
29
#include <QVBoxLayout>
30

31
class SystemTray;
32
class PlayerManager;
33
class QLabel;
34
class QTimer;
35 36 37
class FileHandle;

/**
38
 * Workalike of KPassivePopup intended to more easily support JuK's particular
39 40
 * usage pattern, including things like staying open while under the mouse.
 *
41
 * @author Michael Pyne <mpyne@kde.org>
42
 */
43
class PassiveInfo final : public QFrame
44 45 46
{
    Q_OBJECT
public:
47
    PassiveInfo();
48 49 50 51 52 53 54

    // 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;
55 56

public slots:
57 58 59
    // Starts a timer to show the popup.  The popup will not automatically delete itself
    // once hidden.
    void startTimer(int delay);
60 61 62 63 64
    virtual void show();

signals:
    void mouseEntered();
    void timeExpired();
65 66
    void previousSong();
    void nextSong();
67 68

protected:
69 70 71 72
    virtual void enterEvent(QEvent *) override;
    virtual void leaveEvent(QEvent *) override;
    virtual void hideEvent(QHideEvent *) override;
    virtual void wheelEvent(QWheelEvent *) override;
73 74

private:
75
    // Move us near the required position.
76
    void positionSelf();
77 78 79 80 81 82

private slots:
    void timerExpired();

private:
    QTimer *m_timer;
83
    QVBoxLayout *m_layout;
84 85
    bool m_justDie;
};
86

87
class SystemTray final : public KStatusNotifierItem
88 89 90
{
    Q_OBJECT

91
public:
92
    explicit SystemTray(PlayerManager *player, QWidget *parent = 0);
93

94 95 96 97
signals:
    // Emitted when the fade process is complete.
    void fadeDone();

98
private:
99 100
    static const int STEPS = 20; ///< Number of intermediate steps for fading.

101
    void createPopup();
102
    void setToolTip(const QString &tip = QString(), const QPixmap &cover = QPixmap());
103

104
    // Creates the widget layout for the popup, returning the QWidget that
105 106
    // holds the text labels.

107 108 109 110
    QWidget *createInfoBox(QBoxLayout *parentLayout, const FileHandle &file);
    void addSeparatorLine(QBoxLayout *parentLayout);
    void addCoverButton(QBoxLayout *parentLayout, const QPixmap &cover);
    void createButtonBox(QBoxLayout *parentLayout);
111

112 113 114
    // Interpolates from start color to end color.  If @p step == 0, then
    // m_startColor is returned, while @p step == @steps returns
    // m_endColor.
115

116 117
    QColor interpolateColor(int step, int steps = STEPS);

118
private slots:
119
    void slotPlay();
120
    void slotPause();
121
    void slotStop();
122
    void slotPopupDestroyed();
123
    void slotNextStep(); ///< This is the fading routine.
124
    void slotPopupLargeCover();
125 126 127 128
    void slotForward();
    void slotBack();
    void slotFadeOut(); ///< Fades out the text
    void slotMouseInPopup(); ///< Forces the text back to its normal color.
129
    void scrollEvent(int delta, Qt::Orientation orientation);
130 131

private:
132 133
    QIcon m_backPix;
    QIcon m_forwardPix;
134
    QColor m_startColor, m_endColor;
135

136
    PassiveInfo *m_popup;
137
    PlayerManager *m_player;
138
    QVector<QLabel *> m_labels;
139
    QTimer *m_fadeTimer;
140
    int m_step;
141
    bool m_fade;
142 143 144

    /// Used to choose between manual fade and windowOpacity
    bool m_hasCompositionManager;
145 146
};

147
#endif // JUK_SYSTEMTRAY_H
148 149

// vim: set et sw=4 tw=0 sta: