/src/libtomahawk/playlist/dynamic/widgets/ReadOrWriteWidget.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 111 lines · 69 code · 25 blank · 17 comment · 6 complexity · 3101e1db28cf1f56ad78ca112a5649df MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "ReadOrWriteWidget.h"
  19. #include <QLabel>
  20. #include <QStackedLayout>
  21. #include "utils/Logger.h"
  22. ReadOrWriteWidget::ReadOrWriteWidget( QWidget* writableWidget, bool writable, QWidget* parent)
  23. : QWidget( parent )
  24. , m_writableWidget( writableWidget )
  25. , m_label( 0 )
  26. , m_layout( 0 )
  27. , m_writable( writable )
  28. {
  29. m_label = new QLabel( QString(), this );
  30. m_layout = new QStackedLayout( this );
  31. if( writableWidget )
  32. m_layout->addWidget( writableWidget );
  33. m_layout->addWidget( m_label );
  34. setWritable( m_writable );
  35. setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
  36. setContentsMargins( 0, 0, 0, 0 );
  37. m_layout->setContentsMargins( 0, 0, 0, 0 );
  38. m_layout->setSpacing( 0 );
  39. }
  40. void
  41. ReadOrWriteWidget::setWritable( bool write )
  42. {
  43. m_writable = write;
  44. if( m_writableWidget && write )
  45. m_layout->setCurrentWidget( m_writableWidget );
  46. else
  47. m_layout->setCurrentWidget( m_label );
  48. }
  49. void
  50. ReadOrWriteWidget::setWritableWidget( QWidget* w )
  51. {
  52. if( m_writableWidget ) {
  53. m_layout->removeWidget( m_writableWidget );
  54. }
  55. m_writableWidget = w;
  56. m_layout->insertWidget( 0, m_writableWidget );
  57. }
  58. bool
  59. ReadOrWriteWidget::writable() const
  60. {
  61. return m_writable;
  62. }
  63. QWidget*
  64. ReadOrWriteWidget::writableWidget() const
  65. {
  66. return m_writableWidget;
  67. }
  68. QString
  69. ReadOrWriteWidget::label() const
  70. {
  71. return m_label->text();
  72. }
  73. void
  74. ReadOrWriteWidget::setLabel( const QString& label )
  75. {
  76. m_label->setText( label );
  77. }
  78. QSize
  79. ReadOrWriteWidget::sizeHint() const
  80. {
  81. if( m_writableWidget ) {
  82. return m_writableWidget->sizeHint();
  83. } else {
  84. return m_label->sizeHint();
  85. }
  86. }