00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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
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 )
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();
00117 mainLayout->activate();
00118
00119
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