add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / osd.h
blobf102c317fe337e0f4ccc0283d7a24df0297a20e1
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 ratingChanged( const QString& path, int rating );
42 void volChanged( unsigned char volume );
44 /** reimplemented, shows the OSD */
45 virtual void show();
47 /**
48 * For the sake of simplicity, when these settings are
49 * changed they do not take effect until the next time
50 * the OSD is shown!
52 * To force an update call show();
54 void setDuration( int ms ) { m_duration = ms; }
55 void setTextColor( const QColor &color ) {
56 QPalette palette;
57 palette.setColor(foregroundRole(), color);
58 setPalette(palette);
60 void setOffset( int y ) { m_y = y; }
61 void setAlignment( Alignment alignment ) { m_alignment = alignment; }
62 void setImage( const QImage &image ) { m_cover = image; }
63 void setScreen( int screen );
64 void setText( const QString &text ) { m_text = text; }
65 void setDrawShadow( const bool b ) { m_drawShadow = b; }
66 void setRating( const short rating ) { if ( isEnabled() ) m_rating = rating; }
67 void setMoodbar( void ) { m_moodbarBundle = MetaBundle(); }
68 void setMoodbar( const MetaBundle &bundle )
69 { m_moodbarBundle = bundle; m_moodbarBundle.moodbar().load(); }
71 protected:
72 /** determine new size and position */
73 QRect determineMetrics( const uint marginMetric );
75 /** reimplemented */
76 virtual void paintEvent( QPaintEvent* );
77 virtual void mousePressEvent( QMouseEvent* );
78 virtual bool event( QEvent* );
80 bool useMoodbar( void );
82 /** distance from screen edge */
83 static const int MARGIN = 15;
85 uint m_m;
86 QSize m_size;
87 int m_duration;
88 QTimer *m_timer;
89 Alignment m_alignment;
90 int m_screen;
91 uint m_y;
92 bool m_drawShadow;
93 short m_rating;
94 unsigned char m_newvolume;
95 bool m_volume;
96 QString m_text;
97 QImage m_cover;
98 // need a whole MetaBundle to draw the moodbar on the fly
99 MetaBundle m_moodbarBundle;
100 QPixmap m_scaledCover;
105 class OSDPreviewWidget : public OSDWidget
107 Q_OBJECT
109 public:
110 OSDPreviewWidget( QWidget *parent );
112 int screen() { return m_screen; }
113 int alignment() { return m_alignment; }
114 int y() { return m_y; }
116 public slots:
117 void setTextColor( const QColor &color ) { OSDWidget::setTextColor( color ); doUpdate(); }
118 void setDrawShadow( bool b ) { OSDWidget::setDrawShadow( b ); doUpdate(); }
119 void setFont( const QFont &font ) { OSDWidget::setFont( font ); doUpdate(); }
120 void setScreen( int screen ) { OSDWidget::setScreen( screen ); doUpdate(); }
121 void setUseCustomColors( const bool use, const QColor &fg, const QColor &/*bg*/ )
123 if( use ) {
124 OSDWidget::setTextColor( fg );
125 } else
126 unsetColors();
127 doUpdate();
130 private:
131 inline void doUpdate() { if( !isHidden() ) show(); }
133 signals:
134 void positionChanged();
136 protected:
137 void mousePressEvent( QMouseEvent * );
138 void mouseReleaseEvent( QMouseEvent * );
139 void mouseMoveEvent( QMouseEvent * );
141 private:
142 bool m_dragging;
143 QPoint m_dragOffset;
148 namespace Amarok
150 class OSD : public OSDWidget
152 Q_OBJECT
154 public:
155 static OSD *instance()
157 static OSD *s_instance = new OSD;
158 return s_instance;
161 void applySettings();
162 void show( const MetaBundle &bundle );
164 public slots:
166 * When user pushs global shortcut or uses DCOP OSD is toggle
167 * even if it is disabled()
169 void forceToggleOSD();
171 private:
172 OSD();
174 private slots:
175 void slotCoverChanged( const QString &artist, const QString &album );
176 void slotImageChanged( const QString &remoteURL );
180 #endif /*AMAROK_OSD_H*/