00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qcolor.h>
00023 #include <qframe.h>
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qpixmap.h>
00027
00028 #include <klocale.h>
00029 #include <KoPoint.h>
00030
00031 #include "vcolor.h"
00032 #include "vfill.h"
00033 #include "vgradient.h"
00034 #include "vkopainter.h"
00035 #include "vpattern.h"
00036 #include "vstroke.h"
00037
00038 #include "vsmallpreview.h"
00039
00040 #define FRAMEWIDTH 40
00041
00042 VSmallPreview::VSmallPreview( QWidget* parent, const char* name )
00043 : QWidget( parent, name )
00044 {
00045
00046 QHBoxLayout *layout = new QHBoxLayout( this, 4 );
00047 m_strokeLabel = new QLabel( i18n( "Stroke: None" ), this );
00048 layout->addWidget( m_strokeLabel );
00049 m_strokeFrame = new QFrame( this );
00050 m_strokeFrame->setFixedWidth ( FRAMEWIDTH );
00051 m_strokeFrame->setFrameStyle( QFrame::GroupBoxPanel | QFrame::Plain );
00052 layout->addWidget( m_strokeFrame );
00053 m_fillLabel = new QLabel( i18n( "Fill: None" ), this );
00054 layout->addWidget( m_fillLabel );
00055 m_fillFrame = new QFrame( this );
00056 m_fillFrame->setFixedWidth ( FRAMEWIDTH );
00057 m_fillFrame->setFrameStyle( QFrame::GroupBoxPanel | QFrame::Plain );
00058 layout->addWidget( m_fillFrame );
00059 layout->activate();
00060
00061 m_fill = VFill();
00062 m_stroke = VStroke();
00063 }
00064
00065 VSmallPreview::~VSmallPreview()
00066 {
00067 }
00068
00069 void
00070 VSmallPreview::update( const VStroke &s, const VFill &f )
00071 {
00072 m_fill = f;
00073 m_stroke = s;
00074
00075 drawStroke( s );
00076 drawFill( f );
00077 }
00078
00079 void
00080 VSmallPreview::paintEvent( QPaintEvent* )
00081 {
00082 drawStroke( m_stroke );
00083 drawFill( m_fill );
00084 }
00085
00086 void
00087 VSmallPreview::drawFill( const VFill &f )
00088 {
00089 VFill fill;
00090 VStroke stroke;
00091
00092 QPixmap m_pixmap;
00093 m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() );
00094 VKoPainter* m_painter = new VKoPainter( &m_pixmap, m_fillFrame->width(), m_fillFrame->height() );
00095
00096 m_painter->begin();
00097 m_painter->setPen( Qt::NoPen );
00098 fill.setColor( Qt::white );
00099 m_painter->setBrush( fill );
00100 m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) );
00101
00102 switch ( f.type() )
00103 {
00104 case VFill::solid:
00105 {
00106 switch ( f.color().colorSpace() )
00107 {
00108 case VColor::rgb:
00109 m_fillLabel->setText( i18n( "Fill: RGB") ); break;
00110 case VColor::cmyk:
00111 m_fillLabel->setText( i18n( "Fill: CMYK") ); break;
00112 case VColor::hsb:
00113 m_fillLabel->setText( i18n( "Fill: HSB") ); break;
00114 case VColor::gray:
00115 m_fillLabel->setText( i18n( "Fill: Grayscale") ); break;
00116 default:
00117 m_fillLabel->setText( i18n( "Fill: Color") );
00118 }
00119 fill.setColor( f.color() );
00120 break;
00121 }
00122 case VFill::grad:
00123 {
00124 fill.gradient() = f.gradient();
00125 fill.setType( VFill::grad );
00126 m_fillLabel->setText( i18n( "Fill: Gradient") );
00127 if( f.gradient().type() == VGradient::linear )
00128 {
00129 fill.gradient().setOrigin( KoPoint( m_fillFrame->width() * 0.5, 0 ) );
00130 fill.gradient().setVector( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() ) );
00131 }
00132 else if( f.gradient().type() == VGradient::radial ||
00133 f.gradient().type() == VGradient::conic )
00134 {
00135 fill.gradient().setOrigin( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() * 0.5 ) );
00136 fill.gradient().setFocalPoint( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() * 0.5 ) );
00137 fill.gradient().setVector( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() ) );
00138 }
00139 break;
00140
00141 }
00142 case VFill::patt:
00143 {
00144 fill.pattern() = f.pattern();
00145 fill.pattern().setOrigin( KoPoint( 0, 0 ) );
00146 fill.pattern().setVector( KoPoint( m_fillFrame->width() * 0.5, 0 ) );
00147 fill.setType( VFill::patt );
00148 m_fillLabel->setText( i18n( "Fill: Pattern") );
00149 break;
00150 }
00151 default:
00152 {
00153 m_fillLabel->setText( i18n( "Fill: None") );
00154 fill.setColor( Qt::white );
00155 m_painter->setBrush( fill );
00156 m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) );
00157 stroke.setColor( Qt::red );
00158 stroke.setLineWidth( 2.0 );
00159 m_painter->setPen( stroke );
00160 m_painter->newPath();
00161 m_painter->moveTo( KoPoint( 4, m_fillFrame->height() - 4 ) );
00162 m_painter->lineTo( KoPoint( m_fillFrame->width() - 4, 4 ) );
00163 m_painter->strokePath();
00164 }
00165 }
00166
00167 if( f.type() != VFill::none )
00168 {
00169 m_painter->setPen( stroke );
00170 m_painter->setBrush( fill );
00171 m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) );
00172 }
00173
00174 m_painter->end();
00175
00176 bitBlt( m_fillFrame, m_fillFrame->frameWidth(), m_fillFrame->frameWidth(), &m_pixmap, m_fillFrame->frameWidth(), m_fillFrame->frameWidth(), m_fillFrame->width() - m_fillFrame->frameWidth(), m_fillFrame->height() - m_fillFrame->frameWidth(), CopyROP );
00177
00178 delete ( m_painter );
00179 }
00180
00181 void
00182 VSmallPreview::drawStroke( const VStroke &s )
00183 {
00184 VFill fill;
00185 VStroke stroke;
00186
00187 QPixmap m_pixmap;
00188 m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() );
00189 VKoPainter* m_painter = new VKoPainter( &m_pixmap, m_fillFrame->width(), m_fillFrame->height() );
00190
00191 m_painter->begin();
00192 m_painter->setPen( Qt::NoPen );
00193 fill.setColor( Qt::white );
00194 m_painter->setBrush( fill );
00195 m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) );
00196
00197
00198 switch ( s.type() )
00199 {
00200 case VStroke::solid:
00201 {
00202 switch ( s.color().colorSpace() )
00203 {
00204 case VColor::rgb:
00205 m_strokeLabel->setText( i18n( "Stroke: RGB") ); break;
00206 case VColor::cmyk:
00207 m_strokeLabel->setText( i18n( "Stroke: CMYK") ); break;
00208 case VColor::hsb:
00209 m_strokeLabel->setText( i18n( "Stroke: HSB") ); break;
00210 case VColor::gray:
00211 m_strokeLabel->setText( i18n( "Stroke: Grayscale") ); break;
00212 default:
00213 m_strokeLabel->setText( i18n( "Stroke: Color") );
00214 }
00215 fill.setColor( s.color() );
00216 break;
00217 }
00218 case VStroke::grad:
00219 {
00220 fill.gradient() = s.gradient();
00221 fill.setType( VFill::grad );
00222 m_strokeLabel->setText( i18n( "Stroke: Gradient") );
00223 if( s.gradient().type() == VGradient::linear )
00224 {
00225 fill.gradient().setOrigin( KoPoint( m_strokeFrame->width() * 0.5, 0 ) );
00226 fill.gradient().setVector( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() ) );
00227 }
00228 else if( s.gradient().type() == VGradient::radial ||
00229 s.gradient().type() == VGradient::conic )
00230 {
00231 fill.gradient().setOrigin( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() * 0.5 ) );
00232 fill.gradient().setFocalPoint( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() * 0.5 ) );
00233 fill.gradient().setVector( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() ) );
00234 }
00235 break;
00236 }
00237 case VStroke::patt:
00238 {
00239 fill.pattern() = s.pattern();
00240 fill.pattern().setOrigin( KoPoint( 0, 0 ) );
00241 fill.pattern().setVector( KoPoint( m_strokeFrame->width() * 0.5, 0 ) );
00242 fill.setType( VFill::patt );
00243 m_strokeLabel->setText( i18n( "Stroke: Pattern") );
00244 break;
00245 }
00246 default:
00247 {
00248 m_strokeLabel->setText( i18n( "Stroke: None") );
00249 fill.setColor( Qt::white );
00250 m_painter->setBrush( fill );
00251 m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) );
00252 stroke.setColor( Qt::red );
00253 stroke.setLineWidth( 2.0 );
00254 m_painter->setPen( stroke );
00255 m_painter->newPath();
00256 m_painter->moveTo( KoPoint( 4, m_strokeFrame->height() - 4 ) );
00257 m_painter->lineTo( KoPoint( m_strokeFrame->width() - 4, 4 ) );
00258 m_painter->strokePath();
00259 }
00260 }
00261
00262 if( s.type() != VStroke::none )
00263 {
00264 m_painter->setPen( stroke );
00265 m_painter->setBrush( fill );
00266 m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) );
00267 }
00268
00269 m_painter->end();
00270
00271 bitBlt( m_strokeFrame, m_strokeFrame->frameWidth(), m_strokeFrame->frameWidth(), &m_pixmap, m_strokeFrame->frameWidth(), m_strokeFrame->frameWidth(), m_strokeFrame->width() - m_strokeFrame->frameWidth(), m_strokeFrame->height() - m_strokeFrame->frameWidth(), CopyROP );
00272
00273 delete ( m_painter );
00274 }
00275
00276 #include "vsmallpreview.moc"
00277