File indexing completed on 2022-08-04 15:34:52

0001 /**
0002  * Copyright (C) 2002 Daniel Molkentin <molkentin@kde.org>
0003  * Copyright (C) 2002-2004 Scott Wheeler <wheeler@kde.org>
0004  * Copyright (C) 2007, 2008, 2009 Michael Pyne <mpyne@kde.org>
0005  *
0006  * This program is free software; you can redistribute it and/or modify it under
0007  * the terms of the GNU General Public License as published by the Free Software
0008  * Foundation; either version 2 of the License, or (at your option) any later
0009  * version.
0010  *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License along with
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #ifndef JUK_SYSTEMTRAY_H
0020 #define JUK_SYSTEMTRAY_H
0021 
0022 #include <KStatusNotifierItem>
0023 
0024 #include <QVector>
0025 #include <QColor>
0026 #include <QPixmap>
0027 #include <QIcon>
0028 #include <QFrame>
0029 #include <QVBoxLayout>
0030 
0031 class SystemTray;
0032 class PlayerManager;
0033 class QLabel;
0034 class QTimer;
0035 class FileHandle;
0036 
0037 /**
0038  * Workalike of KPassivePopup intended to more easily support JuK's particular
0039  * usage pattern, including things like staying open while under the mouse.
0040  *
0041  * @author Michael Pyne <mpyne@kde.org>
0042  */
0043 class PassiveInfo final : public QFrame
0044 {
0045     Q_OBJECT
0046 public:
0047     PassiveInfo();
0048 
0049     // Sets view as a child widget to show in the popup window.
0050     // This widget does not take ownership of the widget.  If you want it auto-deleted,
0051     // either re-parent it or create it using this widget as its parent.
0052     void setView(QWidget *view);
0053 
0054     QWidget *view() const;
0055 
0056 public slots:
0057     virtual void show();
0058 
0059 signals:
0060     void mouseEntered();
0061     void timeExpired();
0062     void previousSong();
0063     void nextSong();
0064 
0065 protected:
0066 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0067     void enterEvent (QEnterEvent *e) override;
0068 #else
0069     void enterEvent (QEvent *e) override;
0070 #endif
0071     void leaveEvent(QEvent *) override;
0072     void wheelEvent(QWheelEvent *) override;
0073 
0074 private:
0075     // Move us near the required position.
0076     void positionSelf();
0077 
0078 private slots:
0079     void timerExpired();
0080 
0081 private:
0082     QTimer *m_startFadeTimer;
0083     QVBoxLayout *m_layout;
0084     bool m_justDie;
0085 };
0086 
0087 class SystemTray final : public KStatusNotifierItem
0088 {
0089     Q_OBJECT
0090 
0091 public:
0092     explicit SystemTray(PlayerManager *player, QWidget *parent = nullptr);
0093 
0094 signals:
0095     // Emitted when the fade process is complete.
0096     void fadeDone();
0097 
0098 private:
0099     static const int STEPS = 40; ///< Number of intermediate steps for fading.
0100 
0101     void createPopup();
0102     void setToolTip(const QString &tip = QString(), const QPixmap &cover = QPixmap());
0103 
0104     // Creates the widget layout for the popup, returning the QWidget that
0105     // holds the text labels.
0106 
0107     QWidget *createInfoBox(QBoxLayout *parentLayout, const FileHandle &file);
0108     void addSeparatorLine(QBoxLayout *parentLayout);
0109     void addCoverButton(QBoxLayout *parentLayout, const QPixmap &cover);
0110     void createButtonBox(QBoxLayout *parentLayout);
0111 
0112     // Interpolates from start color to end color.  If @p step == 0, then
0113     // m_startColor is returned, while @p step == @steps returns
0114     // m_endColor.
0115 
0116     QColor interpolateColor(int step, int steps = STEPS);
0117 
0118 private slots:
0119     void slotPlay();
0120     void slotPause();
0121     void slotStop();
0122     void slotPopupDestroyed();
0123     void slotNextStep(); ///< This is the fading routine.
0124     void slotPopupLargeCover();
0125     void slotForward();
0126     void slotBack();
0127     void slotFadeOut(); ///< Fades out the text
0128     void slotMouseInPopup(); ///< Forces the text back to its normal color.
0129     void scrollEvent(int delta, Qt::Orientation orientation);
0130 
0131 private:
0132     PassiveInfo *m_popup = nullptr;
0133     PlayerManager *m_player;
0134 
0135     QIcon m_backPix;
0136     QIcon m_forwardPix;
0137 
0138     QVector<QLabel *> m_labels;
0139 
0140     QTimer *m_fadeStepTimer = nullptr;
0141     QColor m_startColor, m_endColor;
0142     int m_step = 0;
0143     bool m_fade = true;
0144 
0145     /// Used to choose between manual fade and windowOpacity
0146     bool m_hasCompositionManager = false;
0147 };
0148 
0149 #endif // JUK_SYSTEMTRAY_H
0150 
0151 // vim: set et sw=4 tw=0 sta: