PageRenderTime 123ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 73ms app.codeStats 0ms

/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
 19#include "ReadOrWriteWidget.h"
 20
 21#include <QLabel>
 22#include <QStackedLayout>
 23
 24#include "utils/Logger.h"
 25
 26
 27ReadOrWriteWidget::ReadOrWriteWidget( QWidget* writableWidget, bool writable, QWidget* parent)
 28    : QWidget( parent )
 29    , m_writableWidget( writableWidget )
 30    , m_label( 0 )
 31    , m_layout( 0 )
 32    , m_writable( writable )
 33{
 34    m_label = new QLabel( QString(), this );
 35
 36    m_layout = new QStackedLayout( this );
 37    if( writableWidget )
 38        m_layout->addWidget( writableWidget );
 39
 40    m_layout->addWidget( m_label );
 41
 42    setWritable( m_writable );
 43
 44    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
 45    setContentsMargins( 0, 0, 0, 0 );
 46    m_layout->setContentsMargins( 0, 0, 0, 0 );
 47    m_layout->setSpacing( 0 );
 48}
 49
 50
 51void
 52ReadOrWriteWidget::setWritable( bool write )
 53{
 54    m_writable = write;
 55    if( m_writableWidget && write )
 56        m_layout->setCurrentWidget( m_writableWidget );
 57    else
 58        m_layout->setCurrentWidget( m_label );
 59}
 60
 61
 62void
 63ReadOrWriteWidget::setWritableWidget( QWidget* w )
 64{
 65    if( m_writableWidget ) {
 66        m_layout->removeWidget( m_writableWidget );
 67    }
 68
 69    m_writableWidget = w;
 70    m_layout->insertWidget( 0, m_writableWidget );
 71}
 72
 73
 74bool
 75ReadOrWriteWidget::writable() const
 76{
 77    return m_writable;
 78}
 79
 80
 81QWidget*
 82ReadOrWriteWidget::writableWidget() const
 83{
 84    return m_writableWidget;
 85}
 86
 87
 88QString
 89ReadOrWriteWidget::label() const
 90{
 91    return m_label->text();
 92}
 93
 94
 95void
 96ReadOrWriteWidget::setLabel( const QString& label )
 97{
 98    m_label->setText( label );
 99}
100
101
102QSize
103ReadOrWriteWidget::sizeHint() const
104{
105    if( m_writableWidget ) {
106        return m_writableWidget->sizeHint();
107    } else {
108        return m_label->sizeHint();
109    }
110}
111