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.
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
18 #include "metabundle.h"
22 #include <QWidget> //baseclass
25 class OSDWidget
: public QWidget
30 enum Alignment
{ Left
, Middle
, Center
, Right
};
32 explicit OSDWidget( QWidget
*parent
, const char *name
= "osd" );
34 /** resets the colours to defaults */
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 */
47 * For the sake of simplicity, when these settings are
48 * changed they do not take effect until the next time
51 * To force an update call show();
53 void setDuration( int ms
) { m_duration
= ms
; }
54 void setTextColor( const QColor
&color
) {
56 palette
.setColor(foregroundRole(), color
);
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(); }
71 /** determine new size and position */
72 QRect
determineMetrics( const uint marginMetric
);
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;
88 Alignment m_alignment
;
93 unsigned char m_newvolume
;
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
109 OSDPreviewWidget( QWidget
*parent
);
111 int screen() { return m_screen
; }
112 int alignment() { return m_alignment
; }
113 int y() { return m_y
; }
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*/ )
123 OSDWidget::setTextColor( fg
);
130 inline void doUpdate() { if( !isHidden() ) show(); }
133 void positionChanged();
136 void mousePressEvent( QMouseEvent
* );
137 void mouseReleaseEvent( QMouseEvent
* );
138 void mouseMoveEvent( QMouseEvent
* );
149 class OSD
: public OSDWidget
154 static OSD
*instance()
156 static OSD
*s_instance
= new OSD
;
160 void applySettings();
161 void show( const MetaBundle
&bundle
);
165 * When user pushs global shortcut or uses DCOP OSD is toggle
166 * even if it is disabled()
168 void forceToggleOSD();
174 void slotCoverChanged( const QString
&artist
, const QString
&album
);
175 void slotImageChanged( const QString
&remoteURL
);
179 #endif /*AMAROK_OSD_H*/