[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdemultimedia/kmix
From:       Christian Esken <esken () kde ! org>
Date:       2011-07-21 23:15:24
Message-ID: 20110721231524.AF982AC88B () svn ! kde ! org
[Download RAW message or body]

SVN commit 1242599 by esken:

Playback controls and MPRIS2 impementation. 70% done

 M  +1 -2      backends/mixer_mpris2.cpp  
 M  +78 -43    gui/mdwslider.cpp  
 M  +7 -1      gui/mdwslider.h  


--- trunk/KDE/kdemultimedia/kmix/backends/mixer_mpris2.cpp #1242598:1242599
@@ -226,8 +226,7 @@
 	// MPRIS2 doesn't support an actual mute switch. Mute is defined as volume = 0.0
 	// Thus we won't add the playback switch
 	Volume* vol = new Volume( 100, 0, false, false);
-	vol->addVolumeChannel(VolumeChannel(Volume::LEFT));
-	vol->addVolumeChannel(VolumeChannel(Volume::RIGHT));
+	vol->addVolumeChannel(VolumeChannel(Volume::LEFT)); // MPRIS is only one control \
("Mono")  md->addMediaPlayControl();
 	md->addMediaNextControl();
 	md->addMediaPrevControl();
--- trunk/KDE/kdemultimedia/kmix/gui/mdwslider.cpp #1242598:1242599
@@ -71,7 +71,7 @@
 //	MixDeviceWidget(md,true,orientation,parent,view, par_ctl),
 	m_linked(true),	muteButtonSpacer(0), captureSpacer(0), labelSpacer(0),
 	m_iconLabelSimple(0), m_qcb(0), m_muteText(0),
-	m_extraCaptureLabel( 0 ), m_label( 0 ), /*m_captureLED( 0 ),*/
+	m_label( 0 ), /*m_captureLED( 0 ),*/
 	m_captureCheckbox(0), m_captureText(0), labelSpacing(0),
 	muteButtonSpacing(false), captureLEDSpacing(false), _mdwMoveActions(new \
KActionCollection(this)), m_moveMenu(0)  {
@@ -280,10 +280,7 @@
       bool bothCaptureANDPlaybackExist = wantsPlaybackSliders && \
wantsCaptureSliders;  
       bool wantsMediaControls = ( m_mixdevice->hasMediaNextControl() || \
                m_mixdevice->hasMediaPlayControl() || \
                m_mixdevice->hasMediaPrevControl() );
-      if ( wantsMediaControls )
-      {
-	kDebug() << "Bla";
-      }
+
       // case of vertical sliders:
 	if ( _orientation == Qt::Vertical )
 	{
@@ -339,7 +336,7 @@
 			if ( wantsCaptureSliders )
 				addSliders( volLayout, 'c', bothCaptureANDPlaybackExist );
 			if ( wantsMediaControls )
-				addMediaControls( volLayout );
+				addMediaControls( volLayout ); // Please note that the addmediaControls() is in \
the hasVolumeSliders check onyl because it was easier to integrate  \
controlLayout->addSpacing( 3 );  } else {
 			controlLayout->addStretch(1);
@@ -397,8 +394,6 @@
 		row1->addWidget( m_label );
 		row1->setAlignment(m_label, Qt::AlignVCenter);
 
-		//row1->addStretch();
-
 		if ( showCaptureLED && includeCapture && m_mixdevice->captureVolume().hasSwitch() \
)  {
 			m_captureCheckbox = new QCheckBox( i18n("capture") , this);
@@ -486,82 +481,105 @@
 
       if ( mixDevice()->hasMediaPlayControl())
       {
-        QLabel* prev = 0; //new QLabel("<", this);
-	setIcon("media-skip-backward", &prev);
-	mediaLayout->addWidget(prev);
+	QToolButton *lbl = addMediaButton("media-skip-backward", mediaLayout);
+	connect(lbl, SIGNAL( clicked(bool) ), this, SLOT( mediaPrev(bool) ) ); 
       }
       if ( mixDevice()->hasMediaPlayControl())
       {
-	QLabel* play = 0; //new QLabel("P", this);
-	setIcon("media-playback-start", &play);
-	mediaLayout->addWidget(play);
+	QToolButton *lbl = addMediaButton("media-playback-start", mediaLayout);
+	connect(lbl, SIGNAL( clicked(bool) ), this, SLOT( mediaPlay(bool) ) ); 
       }
       if ( mixDevice()->hasMediaPlayControl())
       {
-        QLabel* next = 0; //new QLabel(">, this");
-	setIcon("media-skip-forward", &next);
-	mediaLayout->addWidget(next);
+	QToolButton *lbl = addMediaButton("media-skip-forward", mediaLayout);
+	connect(lbl, SIGNAL( clicked(bool) ), this, SLOT( mediaNext(bool) ) ); 
       }
       volLayout->addLayout(mediaLayout);
     }
 
+
+QToolButton* MDWSlider::addMediaButton(QString iconName, QLayout* layout)
+{
+	QToolButton *lbl = new QToolButton(this);
+	lbl->setIconSize(QSize(22,22));
+	lbl->setAutoRaise(true);
+	lbl->setCheckable(false);
+	
+	setIcon(iconName, lbl);
+	layout->addWidget(lbl);
+
+	return lbl;
+}
+
+void MDWSlider::mediaPrev(bool)
+{
+  kDebug() << "ZZZZZZZ";
+}
+
+void MDWSlider::mediaNext(bool)
+{
+  kDebug() << "ZZZZZZZ";
+}
+
+void MDWSlider::mediaPlay(bool)
+{
+  kDebug() << "ZZZZZZZ";
+}
+
 void MDWSlider::addSliders( QBoxLayout *volLayout, char type, bool addLabel)
 {
 	Volume* volP;
-// 	QList<Volume::ChannelID>* ref_slidersChidsP;
 	QList<QAbstractSlider *>* ref_slidersP;
 	QList<QWidget *>* ref_labelsP;
 
 	if ( type == 'c' ) { // capture
 		volP              = &m_mixdevice->captureVolume();
-// 		ref_slidersChidsP = &_slidersChidsCapture;
 		ref_slidersP      = &m_slidersCapture;
 		ref_labelsP       = &m_labelsCapture;
 	}
 	else { // playback
 	  
 		volP              = &m_mixdevice->playbackVolume();
-// 		ref_slidersChidsP = &_slidersChidsPlayback;
 		ref_slidersP      = &m_slidersPlayback;
 		ref_labelsP       = &m_labelsPlayback;
 	}
 
 	Volume& vol = *volP;
-// 	QList<Volume::ChannelID>& ref_slidersChids = *ref_slidersChidsP;
 	QList<QAbstractSlider *>& ref_sliders = *ref_slidersP;
 	QList<QWidget *>& ref_labels = *ref_labelsP;
 
-
+	LabelType labelType = LT_NONE;
 	if (addLabel && type == 'c')
 	{
-		static QString capture = i18n("capture");
-		m_extraCaptureLabel = createLabel(this, capture, volLayout, false);
+	  labelType = LT_FIRST_CAPTURE;
 	}
+	if ( vol.count() > 2 && ! isStereoLinked())
+	{
+	  labelType = LT_ALL;
+	}
 
 
-//	vol._volumes.
-
 	const int minSliderSize = fontMetrics().height() * 10;
 	long minvol = vol.minVolume();
 	long maxvol = vol.maxVolume();
 
 	bool first = true;
 	QMap<Volume::ChannelID, VolumeChannel> vols = vol.getVolumes();
-	bool suppressAllSubcontrolLables = (vols.count() < 2);
+
 	foreach (VolumeChannel vc, vols )
 	{
 			  kDebug(67100) << "Add label to " << vc.chid << ": " <<  \
                Volume::ChannelNameReadable[vc.chid];
 			    QString subcontrolTranslation = Volume::ChannelNameReadable[vc.chid]; \
                //Volume::getSubcontrolTranslation(chid);
 			    QWidget *subcontrolLabel = createLabel(this, subcontrolTranslation, \
volLayout, true);  ref_labels.append ( subcontrolLabel ); // add to list
-			if( suppressAllSubcontrolLables || (!first && isStereoLinked())  ) {
-				// show only one (the first) slider, when the user wants it so
-				subcontrolLabel->hide();
-			}			  
-// 			}
 
+		if( labelType == LT_NONE ) subcontrolLabel->hide();
+		else if ( labelType == LT_FIRST_CAPTURE && !first ) subcontrolLabel->hide();
+		else subcontrolLabel->show();
+		
 			QAbstractSlider* slider;
-			if ( m_small ) {
+		if ( m_small )
+		{
 				slider = new KSmallSlider( minvol, maxvol, (maxvol-minvol)/10, // @todo !! User \
                definable steps
 				                           vol.getVolume( vc.chid ), _orientation, this );
 			} // small
@@ -663,7 +681,11 @@
 		*label = new QLabel(this);
 		installEventFilter( *label );
 	}
+	setIcon(filename, *label);
+}
 
+void MDWSlider::setIcon( QString filename, QWidget* label )
+{
 	QPixmap miniDevPM = loadIcon( filename );
 	if ( !miniDevPM.isNull() )
 	{
@@ -672,17 +694,32 @@
 			// scale icon
 			QMatrix t;
 			t = t.scale( 10.0/miniDevPM.width(), 10.0/miniDevPM.height() );
-			(*label)->setPixmap( miniDevPM.transformed( t ) );
-			(*label)->resize( 10, 10 );
+			miniDevPM = miniDevPM.transformed( t );
+			label->resize( 10, 10 );
 		} // small size
+		label->setMinimumSize(22,22);
+		
+		QLabel* lbl = qobject_cast<QLabel*>(label);
+		if ( lbl != 0 )
+		{
+		  lbl->setPixmap( miniDevPM );
+		  lbl->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
+		} // QLabel
 		else
 		{
-			(*label)->setPixmap( miniDevPM );
-		} // normal size
-
-		(*label)->setMinimumSize(22,22);
-		(*label)->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
+		  QToolButton* tbt = qobject_cast<QToolButton*>(label);
+		  if ( tbt != 0 )
+		  {
+/*		  QIcon ic(miniDevPM);
+		  lbl->setIcon(ic);*/
+		    tbt->setIcon( miniDevPM );
+//		    tbt->setAlignment(Qt::AlignHCenter | Qt::AlignCenter);
+		  } // QToolButton 
+		  else {
+		    kError() << "Invalid widget type ... cannot set icon";
 	}
+		}
+	}
 	else
 	{
 		kError(67100) << "Pixmap missing." << endl;
@@ -742,18 +779,16 @@
 void
 MDWSlider::setLabeled(bool value)
 {
-	if ( m_label == 0  && m_extraCaptureLabel == 0 )
+	if ( m_label == 0  )
 		return;
 
 	if (value ) {
 		if ( m_label != 0) m_label->show();
-		if ( m_extraCaptureLabel != 0) m_extraCaptureLabel->show();
 		if ( m_muteText != 0) m_muteText->show();
 		if ( m_captureText != 0) m_captureText->show();
 	}
 	else {
 		if ( m_label != 0) m_label->hide();
-		if ( m_extraCaptureLabel != 0) m_extraCaptureLabel->hide();
 		if ( m_muteText != 0) m_muteText->hide();
 		if ( m_captureText != 0) m_captureText->hide();
 	}
--- trunk/KDE/kdemultimedia/kmix/gui/mdwslider.h #1242598:1242599
@@ -58,6 +58,7 @@
 	       QWidget* parent, ViewBase* view, ProfControl *pctl);
     ~MDWSlider() { }
 
+    enum LabelType { LT_ALL, LT_FIRST_CAPTURE, LT_NONE };
     void addActionToPopup( KAction *action );
     void createActions();
     void createShortcutActions();
@@ -69,6 +70,8 @@
     void setTicks( bool ticks );
     void setIcons( bool value );
     void setIcon( QString filename, QLabel** label );
+    void setIcon( QString filename, QWidget* label );
+    QToolButton* addMediaButton(QString iconName, QLayout* layout);
     void setColors( QColor high, QColor low, QColor back );
     void setMutedColors( QColor high, QColor low, QColor back );
     
@@ -117,6 +120,10 @@
     void moveStreamAutomatic();
     void moveStream( QString destId );
 
+    void mediaPlay(bool);
+    void mediaNext(bool);
+    void mediaPrev(bool);
+
 private:
     KShortcut dummyShortcut;
     void setIcon( QString iconname );
@@ -144,7 +151,6 @@
 	QToolButton* m_qcb;
 	QLabel* m_muteText;
         
-    QWidget *m_extraCaptureLabel; // extra capture label (if you got playback AND \
capture on the same control)  QLabel *m_label; // is either QLabel or VerticalText
     
 	QCheckBox* m_captureCheckbox;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic