karbon

vstrokedocker.cc

00001 /* This file is part of the KDE project
00002    Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr)
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 <qhbuttongroup.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qpushbutton.h>
00025 #include <qwidget.h>
00026 #include <qtooltip.h>
00027 
00028 #include <kiconloader.h>
00029 #include <klocale.h>
00030 #include <KoMainWindow.h>
00031 
00032 #include "KoUnitWidgets.h"
00033 
00034 #include "karbon_part.h"
00035 #include "karbon_view.h"
00036 #include "vstroke.h"
00037 #include "vselection.h"
00038 #include "vstrokecmd.h"
00039 
00040 #include "vstrokedocker.h"
00041 
00042 VStrokeDocker::VStrokeDocker( KarbonPart* part, KarbonView* parent, const char* /*name*/ )
00043     : QWidget(), m_part ( part ), m_view( parent )
00044 {
00045     setCaption( i18n( "Stroke Properties" ) );
00046 
00047     QPushButton *button;
00048 
00049     QGridLayout *mainLayout = new QGridLayout( this, 4, 2 );
00050     
00051     QLabel* widthLabel = new QLabel( i18n ( "Width:" ), this );
00052     mainLayout->addWidget( widthLabel, 0, 0 );
00053     // set min/max/step and value in points, then set actual unit
00054     m_setLineWidth = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 2 );
00055     m_setLineWidth->setUnit( part->unit() );
00056     QToolTip::add( m_setLineWidth, i18n( "Set line width of actual selection" ) );
00057     mainLayout->addWidget ( m_setLineWidth, 0, 1 );
00058     connect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
00059     
00060     QLabel* capLabel = new QLabel( i18n ( "Cap:" ), this );
00061     mainLayout->addWidget( capLabel, 1, 0 );
00062     m_capGroup = new QHButtonGroup( this );
00063     m_capGroup->setFrameShape( QFrame::NoFrame );
00064     m_capGroup->setInsideMargin( 1 );
00065     m_capGroup->setExclusive( true );
00066     button = new QPushButton( "", m_capGroup );
00067     button->setPixmap( SmallIcon( "cap_butt" ) );
00068     button->setToggleButton( true );
00069     QToolTip::add( button, i18n( "Butt cap" ) );
00070     m_capGroup->insert( button );
00071     button = new QPushButton( "", m_capGroup );
00072     button->setPixmap( SmallIcon( "cap_round" ) );
00073     button->setToggleButton( true );
00074     QToolTip::add( button, i18n( "Round cap" ) );
00075     m_capGroup->insert( button );
00076     button = new QPushButton( "", m_capGroup );
00077     button->setPixmap( SmallIcon( "cap_square" ) );
00078     button->setToggleButton( true );
00079     QToolTip::add( button, i18n( "Square cap" ) );
00080     m_capGroup->insert( button );
00081     mainLayout->addWidget( m_capGroup, 1, 1 );
00082     connect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
00083     
00084     QLabel* joinLabel = new QLabel( i18n ( "Join:" ), this );
00085     mainLayout->addWidget( joinLabel, 2, 0 );
00086     
00087     m_joinGroup = new QHButtonGroup( this );
00088     m_joinGroup->setFrameShape( QFrame::NoFrame );
00089     m_joinGroup->setInsideMargin( 1 );
00090     m_joinGroup->setExclusive( true );
00091     button = new QPushButton( "", m_joinGroup );
00092     button->setPixmap( SmallIcon( "join_miter" ) );
00093     button->setToggleButton( true );
00094     QToolTip::add( button, i18n( "Miter join" ) );
00095     m_joinGroup->insert( button );
00096     button = new QPushButton( "", m_joinGroup );
00097     button->setPixmap( SmallIcon( "join_round" ) );
00098     button->setToggleButton( true );
00099     QToolTip::add( button, i18n( "Round join" ) );
00100     m_joinGroup->insert( button );
00101     button = new QPushButton( "", m_joinGroup );
00102     button->setPixmap( SmallIcon( "join_bevel" ) );
00103     button->setToggleButton( true );
00104     QToolTip::add( button, i18n( "Bevel join" ) );
00105     m_joinGroup->insert( button );
00106     mainLayout->addWidget( m_joinGroup, 2, 1 );
00107     connect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
00108 
00109     mainLayout->setRowStretch( 3, 1 );
00110     mainLayout->setColStretch( 1, 1 );
00111     mainLayout->activate();
00112 
00113     updateDocker();
00114 }
00115 
00116 void VStrokeDocker::updateCanvas()
00117 {
00118     if( m_part && m_part->document().selection()->objects().count() > 0 )
00119         m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
00120 }
00121 
00122 void VStrokeDocker::slotCapChanged( int ID )
00123 {
00124     switch( ID )
00125     {
00126         case 1:
00127             m_stroke.setLineCap( VStroke::capRound ); break;
00128         case 2:
00129             m_stroke.setLineCap( VStroke::capSquare ); break;
00130         default:
00131             m_stroke.setLineCap( VStroke::capButt );
00132     }
00133     updateCanvas();
00134 }
00135 
00136 void VStrokeDocker::slotJoinChanged( int ID )
00137 {
00138     switch( ID )
00139     {
00140         case 1:
00141             m_stroke.setLineJoin( VStroke::joinRound ); break;
00142         case 2:
00143             m_stroke.setLineJoin( VStroke::joinBevel ); break;
00144         default:
00145             m_stroke.setLineJoin( VStroke::joinMiter );
00146     }
00147     updateCanvas();
00148 }
00149 
00150 void VStrokeDocker::updateDocker()
00151 {
00152     disconnect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
00153     disconnect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
00154     disconnect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
00155 
00156     switch( m_stroke.lineCap() )
00157     {
00158         case VStroke::capRound:
00159             m_capGroup->setButton( 1 ); break;
00160         case VStroke::capSquare:
00161             m_capGroup->setButton( 2 ); break;
00162         default:
00163             m_capGroup->setButton( 0 );
00164     }
00165 
00166     switch( m_stroke.lineJoin() )
00167     {
00168         case VStroke::joinRound:
00169             m_joinGroup->setButton( 1 ); break;
00170         case VStroke::joinBevel:
00171             m_joinGroup->setButton( 2 ); break;
00172         default:
00173             m_joinGroup->setButton( 0 );
00174     }
00175     
00176     m_setLineWidth->changeValue( m_stroke.lineWidth() );
00177     
00178     connect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
00179     connect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
00180     connect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
00181 }
00182 
00183 void VStrokeDocker::widthChanged()
00184 {
00185     m_stroke.setLineWidth( m_setLineWidth->value() );
00186     updateCanvas();
00187 }
00188 
00189 void VStrokeDocker::setStroke( const VStroke &stroke )
00190 {
00191     m_stroke = stroke;
00192     updateDocker();
00193 }
00194 
00195 void VStrokeDocker::setUnit( KoUnit::Unit unit )
00196 {
00197     disconnect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
00198     disconnect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
00199     disconnect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
00200 
00201     m_setLineWidth->setUnit( unit );
00202 
00203     connect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
00204     connect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
00205     connect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
00206 }
00207 #include "vstrokedocker.moc"
00208 
KDE Home | KDE Accessibility Home | Description of Access Keys