karbon

vstrokedlg.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, The Karbon Developers
00003    Copyright (C) 2002, The Karbon Developers
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qcombobox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qtabwidget.h>
00025 #include <qradiobutton.h>
00026 #include <qvbuttongroup.h>
00027 
00028 #include <kiconloader.h>
00029 #include <klocale.h>
00030 #include <kstandarddirs.h>
00031 
00032 #include "KoUnitWidgets.h"
00033 
00034 #include "karbon_part.h"
00035 #include "vcolor.h"
00036 #include "vselection.h"
00037 #include "vstrokecmd.h"
00038 #include "vstroke.h"
00039 #include "vstrokedlg.h"
00040 #include "vcolortab.h"
00041 
00042 VStrokeDlg::VStrokeDlg( KarbonPart* part, QWidget* parent, const char* name )
00043     : KDialogBase ( parent, name, true, i18n( "Stroke" ), Ok | Cancel ), m_part( part )
00044 {
00045     enableButtonSeparator( true );
00046     QTabWidget *mainWidget = new QTabWidget( this, "strokemain" );
00047     QHBoxLayout *mainLayout = new QHBoxLayout (mainWidget, 3);
00048 
00049     QVBoxLayout *leftLayout = new QVBoxLayout( mainLayout, 4 );
00050 
00051     QLabel* widthLabel = new QLabel( i18n ( "stroke width", "Width:" ), mainWidget );
00052     leftLayout->addWidget ( widthLabel );
00053     m_setLineWidth = new KoUnitDoubleSpinBox( mainWidget, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 1 );
00054     leftLayout->addWidget ( m_setLineWidth );
00055 
00056     //Dashing ->
00057     QLabel* styleLabel = new QLabel( i18n ( "Style:" ), mainWidget );
00058     leftLayout->addWidget ( styleLabel );
00059     m_styleCombo = new QComboBox( mainWidget );
00060     m_styleCombo->setEnabled ( false );
00061     leftLayout->addWidget ( m_styleCombo );
00062     // <- Dashing - reserved for later
00063 
00064     QRadioButton* button;
00065     m_typeOption = new QVButtonGroup ( mainWidget );
00066     button = new QRadioButton ( i18n( "None" ), m_typeOption );
00067     m_typeOption->insert( button );
00068     button = new QRadioButton ( i18n( "Stroke" ), m_typeOption );
00069     m_typeOption->insert( button );
00070     button = new QRadioButton ( i18n( "Gradient" ), m_typeOption );
00071     m_typeOption->insert( button );
00072     m_typeOption->setTitle( i18n( "Type" ) );
00073     mainLayout->addWidget( m_typeOption );
00074     connect( m_typeOption, SIGNAL( clicked( int ) ), this, SLOT( slotTypeChanged( int ) ) );
00075 
00076     m_capOption = new QVButtonGroup ( mainWidget );
00077     //button = new QRadioButton ( i18n( "Butt" ), m_capOption );                                                              
00078     button = new QRadioButton ( m_capOption );
00079     button->setPixmap( DesktopIcon( "cap_butt" ) );
00080     m_capOption->insert( button );
00081     button = new QRadioButton ( m_capOption );
00082     button->setPixmap( DesktopIcon( "cap_round" ) );
00083     m_capOption->insert( button );
00084     button = new QRadioButton ( m_capOption );
00085     button->setPixmap( DesktopIcon( "cap_square" ) );
00086     m_capOption->insert( button );
00087     m_capOption->setTitle( i18n( "Cap" ) );
00088     mainLayout->addWidget( m_capOption );
00089     connect( m_capOption, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
00090 
00091     m_joinOption = new QVButtonGroup ( mainWidget );
00092     button = new QRadioButton ( m_joinOption );
00093     button->setPixmap( DesktopIcon( "join_miter" ) );
00094     m_joinOption->insert( button );
00095     button = new QRadioButton ( m_joinOption );
00096     button->setPixmap( DesktopIcon( "join_round" ) );
00097     m_joinOption->insert( button );
00098     button = new QRadioButton ( m_joinOption );
00099     button->setPixmap( DesktopIcon( "join_bevel" ) );
00100     m_joinOption->insert( button );
00101     m_joinOption->setTitle( i18n( "Join" ) );
00102     mainLayout->addWidget( m_joinOption );
00103     connect( m_joinOption, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
00104 
00105     VSelection *sel = part->document().selection();
00106     if( sel && sel->objects().count() > 0 ) // there is a selection, so take the stroke of first selected object
00107     {
00108         m_stroke.setType ( sel->objects().getFirst()->stroke()->type() );
00109         m_stroke.setColor ( sel->objects().getFirst()->stroke()->color() );
00110         m_stroke.setLineWidth ( sel->objects().getFirst()->stroke()->lineWidth() );
00111         m_stroke.setLineCap ( sel->objects().getFirst()->stroke()->lineCap() );   
00112         m_stroke.setLineJoin ( sel->objects().getFirst()->stroke()->lineJoin() );
00113         m_stroke.setMiterLimit ( sel->objects().getFirst()->stroke()->miterLimit() );
00114     }
00115 
00116     slotUpdateDialog(); //Put the values of selected objects (or default)
00117     mainLayout->activate();
00118 
00119     //setMainWidget( mainWidget );
00120 
00121     m_colortab = new VColorTab( sel->objects().count() == 0 ? sel->stroke()->color() :
00122                                 sel->objects().getFirst()->stroke()->color(), this);
00123     m_colortab->insertTab( mainWidget, i18n("Stroke"), 0 );
00124     m_colortab->setCurrentPage( 0 );
00125 
00126     setMainWidget( m_colortab );
00127 
00128     disableResize();
00129     connect (this, SIGNAL( okClicked( void ) ), this, SLOT( slotOKClicked ( void ) ) );
00130 }
00131 
00132 void VStrokeDlg::slotTypeChanged( int ID )
00133 {
00134     switch ( ID ) {
00135         case 1:
00136             m_stroke.setType ( VStroke::solid ); break;
00137         case 2:
00138             m_stroke.setType ( VStroke::grad ); break;
00139         default:
00140             m_stroke.setType ( VStroke::none );
00141     }
00142 }
00143 
00144 void VStrokeDlg::slotCapChanged( int ID )
00145 {
00146     switch ( ID ) {
00147         case 1:
00148             m_stroke.setLineCap ( VStroke::capRound ); break;
00149         case 2:
00150             m_stroke.setLineCap ( VStroke::capSquare ); break;
00151         default:
00152             m_stroke.setLineCap ( VStroke::capButt );
00153     }
00154 }
00155 
00156 void VStrokeDlg::slotJoinChanged( int ID )
00157 {
00158     switch ( ID ) {
00159         case 1:
00160             m_stroke.setLineJoin ( VStroke::joinRound ); break;
00161         case 2:
00162             m_stroke.setLineJoin ( VStroke::joinBevel ); break;
00163         default:
00164             m_stroke.setLineJoin ( VStroke::joinMiter );
00165     }
00166 }
00167 
00168 void VStrokeDlg::slotOKClicked()
00169 {
00170     m_stroke.setLineWidth ( m_setLineWidth->value() );
00171 
00172     m_stroke.setColor( m_colortab->Color() );
00173 
00174     if( m_part && m_part->document().selection()->objects().count() > 0 )
00175         m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
00176 
00177     emit strokeChanged( VStroke( m_stroke ) );
00178 }
00179 
00180 void VStrokeDlg::slotUpdateDialog()
00181 {
00182     switch( m_stroke.type() )
00183     {
00184         case VStroke::solid:
00185             m_typeOption->setButton( 1 ); break;
00186         case VStroke::grad:
00187             m_typeOption->setButton( 2 ); break;
00188         default:
00189             m_typeOption->setButton( 0 );
00190     }
00191 
00192     switch( m_stroke.lineCap() )
00193     {
00194         case VStroke::capRound:
00195             m_capOption->setButton( 1 ); break;
00196         case VStroke::capSquare:
00197             m_capOption->setButton( 2 ); break;
00198         default:
00199             m_capOption->setButton( 0 );
00200     }
00201 
00202     switch( m_stroke.lineJoin() )
00203     {
00204         case VStroke::joinRound:
00205             m_joinOption->setButton( 1 ); break;
00206         case VStroke::joinBevel:
00207             m_joinOption->setButton( 2 ); break;
00208         default:
00209             m_joinOption->setButton( 0 );
00210     }
00211     
00212     m_setLineWidth->setValue( m_stroke.lineWidth() );
00213 }
00214 
00215 #include "vstrokedlg.moc"
00216 
KDE Home | KDE Accessibility Home | Description of Access Keys