Amarok – versatile and easy to use audio player
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
5.0KB

  1. /* NMM - Network-Integrated Multimedia Middleware
  2. *
  3. * Copyright (C) 2006
  4. * NMM work group,
  5. * Computer Graphics Lab,
  6. * Saarland University, Germany
  7. * http://www.networkmultimedia.org
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301
  22. * USA
  23. */
  24. #include "HostList.h"
  25. #include <tqcursor.h>
  26. #include <tqheader.h>
  27. #include <tdelocale.h>
  28. #include "debug.h"
  29. #include "HostListItem.h"
  30. HostList::HostList( TQWidget *parent, const char *name )
  31. : TDEListView( parent, name ),
  32. m_read_only( false ),
  33. m_hoveredVolume(0)
  34. {
  35. // TODO: item should be activated on mouse click
  36. setMouseTracking( true );
  37. setAllColumnsShowFocus( true );
  38. addColumn( i18n("Hostname") );
  39. addColumn( i18n("Video" ) );
  40. addColumn( i18n("Audio" ) );
  41. addColumn( i18n("Volume" ), 113 );
  42. header()->setResizeEnabled(false, 3);
  43. addColumn( i18n("Status" ) );
  44. addColumn( i18n("Playback" ) );
  45. setColumnAlignment( HostListItem::Hostname, TQt::AlignCenter );
  46. setColumnAlignment( HostListItem::Video, TQt::AlignCenter );
  47. setColumnAlignment( HostListItem::Audio, TQt::AlignCenter );
  48. setColumnAlignment( HostListItem::Volume, TQt::AlignCenter );
  49. setColumnAlignment( HostListItem::Status, TQt::AlignLeft );
  50. }
  51. HostList::~HostList()
  52. {}
  53. void HostList::notifyHostError( TQString hostname, int error)
  54. {
  55. TQListViewItemIterator it( this );
  56. HostListItem *host;
  57. while( it.current() ) {
  58. host = static_cast<HostListItem*>( it.current() );
  59. if( host->text(HostListItem::Hostname) == hostname )
  60. {
  61. host->setText( HostListItem::Hostname, hostname );
  62. host->setStatus( error );
  63. host->repaint();
  64. return;
  65. }
  66. ++it;
  67. }
  68. }
  69. void HostList::contentsMousePressEvent( TQMouseEvent *e)
  70. {
  71. HostListItem *item = static_cast<HostListItem*>( itemAt( contentsToViewport( e->pos() ) ) );
  72. if( !( e->state() & TQt::ControlButton || e->state() & TQt::ShiftButton ) && ( e->button() & TQt::LeftButton ) && item)
  73. {
  74. // video column
  75. if( !m_read_only &&
  76. e->pos().x() > header()->sectionPos( HostListItem::Video ) &&
  77. e->pos().x() < header()->sectionPos( HostListItem::Video ) + header()->sectionSize( HostListItem::Video ) )
  78. {
  79. item->toggleVideo();
  80. item->updateColumn( HostListItem::Video );
  81. emit viewChanged();
  82. }
  83. // audio column
  84. else
  85. if( !m_read_only &&
  86. e->pos().x() > header()->sectionPos( HostListItem::Audio ) &&
  87. e->pos().x() < header()->sectionPos( HostListItem::Audio ) + header()->sectionSize( HostListItem::Audio ) )
  88. {
  89. item->toggleAudio();
  90. item->updateColumn( HostListItem::Audio );
  91. emit viewChanged();
  92. }
  93. // status column
  94. else
  95. if( e->pos().x() > header()->sectionPos( HostListItem::Status ) &&
  96. e->pos().x() < header()->sectionPos( HostListItem::Status ) + header()->sectionSize( HostListItem::Status ) )
  97. {
  98. item->statusToolTip();
  99. }
  100. else // set new volume for item
  101. if( e->pos().x() > header()->sectionPos( HostListItem::Volume ) &&
  102. e->pos().x() < header()->sectionPos( HostListItem::Volume ) + header()->sectionSize( HostListItem::Volume ) )
  103. {
  104. int vol = e->pos().x();
  105. vol -= header()->sectionPos( HostListItem::Volume );
  106. item->setVolume( item->volumeAtPosition( vol ) );
  107. }
  108. else
  109. TDEListView::contentsMousePressEvent( e );
  110. }
  111. else
  112. TDEListView::contentsMousePressEvent( e );
  113. }
  114. void HostList::contentsMouseMoveEvent( TQMouseEvent *e )
  115. {
  116. if( e )
  117. TDEListView::contentsMouseMoveEvent( e );
  118. HostListItem *prev = m_hoveredVolume;
  119. const TQPoint pos = e ? e->pos() : viewportToContents( viewport()->mapFromGlobal( TQCursor::pos() ) );
  120. HostListItem *item = static_cast<HostListItem*>( itemAt( contentsToViewport( pos ) ) );
  121. if( item && pos.x() > header()->sectionPos( HostListItem::Volume ) &&
  122. pos.x() < header()->sectionPos( HostListItem::Volume ) + header()->sectionSize( HostListItem::Volume ) )
  123. {
  124. m_hoveredVolume = item;
  125. m_hoveredVolume->updateColumn( HostListItem::Volume );
  126. }
  127. else
  128. m_hoveredVolume = 0;
  129. if( prev )
  130. prev->updateColumn( HostListItem::Volume );
  131. }
  132. void HostList::leaveEvent( TQEvent *e )
  133. {
  134. TDEListView::leaveEvent( e );
  135. HostListItem *prev = m_hoveredVolume;
  136. m_hoveredVolume = 0;
  137. if( prev )
  138. prev->updateColumn( HostListItem::Volume );
  139. }
  140. #include "HostList.moc"