panel_dock_widget.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <QChildEvent>
00031 #include <QHBoxLayout>
00032 #include <QLabel>
00033 #include <QToolButton>
00034 #include <QCloseEvent>
00035 
00036 #include "rviz/panel_dock_widget.h"
00037 
00038 namespace rviz
00039 {
00040 
00041 PanelDockWidget::PanelDockWidget( const QString& name )
00042   : QDockWidget( name )
00043   , collapsed_(false)
00044 {
00045   QWidget *title_bar = new QWidget(this);
00046 
00047   QPalette pal(palette());
00048   pal.setColor(QPalette::Background, QColor( 200,200,200 ) );
00049   title_bar->setAutoFillBackground(true);
00050   title_bar->setPalette(pal);
00051   title_bar->setContentsMargins(0,0,0,0);
00052 
00053   QToolButton *close_button = new QToolButton();
00054   close_button->setIcon(QIcon::fromTheme("window-close"));
00055   close_button->setIconSize( QSize(10,10) );
00056 
00057   connect( close_button, SIGNAL( clicked() ), this, SLOT(close()) );
00058 
00059   title_label_ = new QLabel( name, this );
00060 
00061   icon_label_ = new QLabel( this );
00062   icon_label_->setContentsMargins(2,2,0,0);
00063   setIcon( QIcon() );
00064 
00065   QHBoxLayout *title_layout = new QHBoxLayout();
00066   title_layout->setContentsMargins(2,2,2,2);
00067   title_layout->addWidget( icon_label_, 0 );
00068   title_layout->addWidget( title_label_, 1 );
00069   title_layout->addWidget( close_button, 0 );
00070   title_bar->setLayout(title_layout);
00071   setTitleBarWidget( title_bar );
00072 }
00073 
00074 void PanelDockWidget::setWindowTitle( QString title )
00075 {
00076   QDockWidget::setWindowTitle( title );
00077   title_label_->setText( title );
00078 }
00079 
00080 
00081 void PanelDockWidget::setIcon( QIcon icon )
00082 {
00083   if ( icon.isNull() )
00084   {
00085     icon_label_->setVisible( false );
00086   }
00087   else
00088   {
00089     icon_label_->setVisible( true );
00090     icon_label_->setPixmap( icon.pixmap(16,16) );
00091   }
00092 }
00093 
00094 void PanelDockWidget::setCollapsed( bool collapse )
00095 {
00096   if ( collapsed_ == collapse || isFloating() ) return;
00097 
00098 
00099   if ( collapse )
00100   {
00101     if ( isVisible() )
00102     {
00103       QDockWidget::setVisible( false );
00104       collapsed_ = collapse;
00105     }
00106   }
00107   else
00108   {
00109     QDockWidget::setVisible( true );
00110     collapsed_ = collapse;
00111   }
00112 }
00113 
00114 void PanelDockWidget::setContentWidget( QWidget* child )
00115 {
00116   if( widget() )
00117   {
00118     disconnect( widget(), SIGNAL( destroyed( QObject* )), this, SLOT( onChildDestroyed( QObject* )));
00119   }
00120   setWidget( child );
00121   if( child )
00122   {
00123     connect( child, SIGNAL( destroyed( QObject* )), this, SLOT( onChildDestroyed( QObject* )));
00124   }
00125 }
00126 
00127 void PanelDockWidget::closeEvent ( QCloseEvent * event )
00128 {
00129   Q_EMIT closed();
00130 }
00131 
00132 void PanelDockWidget::onChildDestroyed( QObject* )
00133 {
00134   deleteLater();
00135 }
00136 
00137 void PanelDockWidget::save( Config config )
00138 {
00139   config.mapSetValue( "collapsed", collapsed_ );
00140 }
00141 
00142 void PanelDockWidget::load( Config config )
00143 {
00144   config.mapGetBool( "collapsed", &collapsed_ );
00145 }
00146 
00147 } // end namespace rviz


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Aug 27 2015 15:02:27