Not crap after all...
[amarok.git] / src / osd.h
blob65fafbf21f3c8548ae63bab4d56c50faa2e62985
1 /*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6 */
8 /*
9 osd.h - Provides an interface to a plain QWidget, which is independent of KDE (bypassed to X11)
10 begin: Fre Sep 26 2003
11 copyright: (C) 2003 by Christian Muehlhaeuser
12 email: chris@chris.de
15 #ifndef AMAROK_OSD_H
16 #define AMAROK_OSD_H
18 #include "metabundle.h"
20 #include <QPixmap>
21 #include <QImage>
22 #include <QWidget> //baseclass
25 class OSDWidget : public QWidget
27 Q_OBJECT
29 public:
30 enum Alignment { Left, Middle, Center, Right };
32 explicit OSDWidget( QWidget *parent, const char *name = "osd" );
34 /** resets the colours to defaults */
35 void unsetColors();
37 public slots:
38 /** calls setText() then show(), after setting image if needed */
39 void show( const QString &text, QImage newImage = QImage::QImage() );
40 void ratingChanged( const short rating );
41 void volChanged( unsigned char volume );
43 /** reimplemented, shows the OSD */
44 virtual void show();
46 /**
47 * For the sake of simplicity, when these settings are
48 * changed they do not take effect until the next time
49 * the OSD is shown!
51 * To force an update call show();
53 void setDuration( int ms ) { m_duration = ms; }
54 void setTextColor( const QColor &color ) {
55 QPalette palette;
56 palette.setColor(foregroundRole(), color);
57 setPalette(palette);
59 void setOffset( int y ) { m_y = y; }
60 void setAlignment( Alignment alignment ) { m_alignment = alignment; }
61 void setImage( const QImage &image ) { m_cover = image; }
62 void setScreen( int screen );
63 void setText( const QString &text ) { m_text = text; }
64 void setDrawShadow( const bool b ) { m_drawShadow = b; }
65 void setRating( const short rating ) { if ( isEnabled() ) m_rating = rating; }
66 void setMoodbar( void ) { m_moodbarBundle = MetaBundle(); }
67 void setMoodbar( const MetaBundle &bundle )
68 { m_moodbarBundle = bundle; m_moodbarBundle.moodbar().load(); }
70 protected:
71 /** determine new size and position */
72 QRect determineMetrics( const uint marginMetric );
74 /** reimplemented */
75 virtual void paintEvent( QPaintEvent* );
76 virtual void mousePressEvent( QMouseEvent* );
77 virtual bool event( QEvent* );
79 bool useMoodbar( void );
81 /** distance from screen edge */
82 static const int MARGIN = 15;
84 uint m_m;
85 QSize m_size;
86 int m_duration;
87 QTimer *m_timer;
88 Alignment m_alignment;
89 int m_screen;
90 uint m_y;
91 bool m_drawShadow;
92 short m_rating;
93 unsigned char m_newvolume;
94 bool m_volume;
95 QString m_text;
96 QImage m_cover;
97 // need a whole MetaBundle to draw the moodbar on the fly
98 MetaBundle m_moodbarBundle;
99 QPixmap m_scaledCover;
104 class OSDPreviewWidget : public OSDWidget
106 Q_OBJECT
108 public:
109 OSDPreviewWidget( QWidget *parent );
111 int screen() { return m_screen; }
112 int alignment() { return m_alignment; }
113 int y() { return m_y; }
115 public slots:
116 void setTextColor( const QColor &color ) { OSDWidget::setTextColor( color ); doUpdate(); }
117 void setDrawShadow( bool b ) { OSDWidget::setDrawShadow( b ); doUpdate(); }
118 void setFont( const QFont &font ) { OSDWidget::setFont( font ); doUpdate(); }
119 void setScreen( int screen ) { OSDWidget::setScreen( screen ); doUpdate(); }
120 void setUseCustomColors( const bool use, const QColor &fg, const QColor &/*bg*/ )
122 if( use ) {
123 OSDWidget::setTextColor( fg );
124 } else
125 unsetColors();
126 doUpdate();
129 private:
130 inline void doUpdate() { if( !isHidden() ) show(); }
132 signals:
133 void positionChanged();
135 protected:
136 void mousePressEvent( QMouseEvent * );
137 void mouseReleaseEvent( QMouseEvent * );
138 void mouseMoveEvent( QMouseEvent * );
140 private:
141 bool m_dragging;
142 QPoint m_dragOffset;
147 namespace Amarok
149 class OSD : public OSDWidget
151 Q_OBJECT
153 public:
154 static OSD *instance()
156 static OSD *s_instance = new OSD;
157 return s_instance;
160 void applySettings();
161 void show( const MetaBundle &bundle );
163 public slots:
165 * When user pushs global shortcut or uses DCOP OSD is toggle
166 * even if it is disabled()
168 void forceToggleOSD();
170 private:
171 OSD();
173 private slots:
174 void slotCoverChanged( const QString &artist, const QString &album );
175 void slotImageChanged( const QString &remoteURL );
179 #endif /*AMAROK_OSD_H*/