Back to index

salome-gui  6.5.0
ViewerTools_FontWidgetBase.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "ViewerTools_FontWidgetBase.h"
00024 
00025 #include <QToolButton>
00026 #include <QComboBox>
00027 #include <QColorDialog>
00028 #include <QCheckBox>
00029 #include <QHBoxLayout>
00030 
00039 ViewerTools_FontWidgetBase::ViewerTools_FontWidgetBase( QWidget* theParent )
00040 : QWidget( theParent )
00041 {
00042 }
00043 
00047 ViewerTools_FontWidgetBase::~ViewerTools_FontWidgetBase()
00048 {
00049 }
00050 
00051 void ViewerTools_FontWidgetBase::Initialize()
00052 {
00053   myColorBtn = new QToolButton( this );
00054   myColorBtn->setMinimumWidth( 20 );
00055 
00056   myFamily = new QComboBox( this );
00057   InitializeFamilies();
00058 
00059   myBold = new QCheckBox( tr( "BOLD" ), this );
00060   myItalic = new QCheckBox( tr( "ITALIC" ), this );
00061   myShadow = new QCheckBox( tr( "SHADOW" ), this );
00062 
00063   QHBoxLayout* aHBLayout = new QHBoxLayout;
00064   aHBLayout->setMargin( 0 );
00065   aHBLayout->setSpacing( 5 );
00066   aHBLayout->addWidget(myColorBtn);
00067   aHBLayout->addWidget(myFamily);
00068   aHBLayout->addWidget(myBold);
00069   aHBLayout->addWidget(myItalic);
00070   aHBLayout->addWidget(myShadow);
00071   aHBLayout->addStretch();
00072   this->setLayout(aHBLayout);
00073 
00074   connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) );
00075 
00076   if( myFamily->count() == 0 )
00077   {
00078     myFamily->hide();
00079     myBold->hide();
00080     myItalic->hide();
00081     myShadow->hide();
00082   }
00083 }
00084 
00085 void ViewerTools_FontWidgetBase::SetColor( const QColor& theColor )
00086 {
00087   QPalette palette;
00088   palette.setColor(myColorBtn->backgroundRole(), theColor);
00089   myColorBtn->setPalette(palette);
00090 }
00091 
00092 QColor ViewerTools_FontWidgetBase::GetColor() const
00093 {
00094   return myColorBtn->palette().color( myColorBtn->backgroundRole() );
00095 }
00096 
00097 void ViewerTools_FontWidgetBase::onColor()
00098 {
00099   QColor aColor = QColorDialog::getColor( GetColor(), this );
00100   if ( aColor.isValid() )
00101     SetColor( aColor );
00102 }
00103 
00104 void ViewerTools_FontWidgetBase::SetData( const QColor& theColor,
00105                                           const int theFamily,
00106                                           const bool theBold,
00107                                           const bool theItalic,
00108                                           const bool theShadow )
00109 {
00110   SetColor( theColor );
00111 
00112   myBold->setChecked( theBold );
00113   myItalic->setChecked( theItalic );
00114   myShadow->setChecked( theShadow );
00115 }
00116 
00117 void ViewerTools_FontWidgetBase::GetData( QColor& theColor,
00118                                           int& theFamily,
00119                                           bool& theBold,
00120                                           bool& theItalic,
00121                                           bool& theShadow ) const
00122 {
00123   theColor = GetColor();
00124 
00125   theBold = myBold->isChecked();
00126   theItalic = myItalic->isChecked();
00127   theShadow = myShadow->isChecked();
00128 }