23#include <tqgroupbox.h>
24#include <tqpushbutton.h>
25#include <tqfileinfo.h>
31#include <tdelistbox.h>
32#include <kiconloader.h>
34#include "vgradientwidget.h"
35#include "vgradienttabwidget.h"
36#include "karbon_resourceserver.h"
37#include "vkopainter.h"
40VGradientListItem::VGradientListItem(
const VGradient& gradient, TQString filename )
41 : TQListBoxItem( 0L ), m_filename( filename )
43 m_gradient =
new VGradient( gradient );
45 m_pixmap.resize( 200, 16 );
46 VKoPainter gp( &m_pixmap, m_pixmap.width(), m_pixmap.height() );
47 gp.setRasterOp( TQt::XorROP );
49 VGradient grad( *m_gradient );
50 grad.setOrigin( KoPoint( 0, 0 ) );
51 grad.setVector( KoPoint( m_pixmap.width() - 1, 0 ) );
52 grad.setType( VGradient::linear );
54 fill.gradient() = grad;
57 gp.moveTo( KoPoint( 0, 0 ) );
58 gp.lineTo( KoPoint( 0, m_pixmap.height() - 1 ) );
59 gp.lineTo( KoPoint( m_pixmap.width() - 1, m_pixmap.height() - 1 ) );
60 gp.lineTo( KoPoint( m_pixmap.width() - 1, 0 ) );
61 gp.lineTo( KoPoint( 0, 0 ) );
65 m_delete = TQFileInfo( filename ).isWritable();
68VGradientListItem::VGradientListItem(
const VGradientListItem& gradient )
71 m_pixmap = gradient.m_pixmap;
72 m_delete = gradient.m_delete;
73 m_gradient =
new VGradient( *gradient.gradient() );
74 m_filename = gradient.m_filename;
77VGradientListItem::~VGradientListItem()
82int VGradientListItem::width(
const TQListBox* lb )
const
84 return lb->width() - 25;
87void VGradientListItem::paint( TQPainter* painter )
90 painter->setRasterOp( TQt::CopyROP );
91 TQRect r ( 0, 0, width( listBox() ), height( listBox() ) );
92 painter->scale( ( (
float)( width( listBox() ) ) ) / 200., 1. );
93 painter->drawPixmap( 0, 0, m_pixmap );
96 painter->setPen( listBox()->colorGroup().highlightedText() );
98 painter->setPen( listBox()->colorGroup().base() );
99 painter->drawRect( r );
103VGradientPreview::VGradientPreview( VGradient& gradient,
double& opacity, TQWidget* parent,
const char* name )
104 : TQWidget( parent, name ), m_gradient( &gradient ), m_opacity( &opacity )
106 setBackgroundMode( TQt::NoBackground );
107 setMinimumSize( 70, 70 );
110VGradientPreview::~VGradientPreview()
114void VGradientPreview::paintEvent( TQPaintEvent* )
116 TQPixmap pixmap( width(), height() );
117 VKoPainter gp( &pixmap, width(), height() );
118 gp.setRasterOp( TQt::XorROP );
120 VGradient gradient( *m_gradient );
121 if( gradient.type() == VGradient::radial || gradient.type() == VGradient::conic )
123 gradient.setOrigin( KoPoint( width() / 2, height() / 2 ) );
124 gradient.setFocalPoint( KoPoint( width() / 2, height() / 2 ) );
125 gradient.setVector( KoPoint( width() / 4, height() / 4 ) );
129 gradient.setOrigin( KoPoint( width() / 3, 2 * ( height() / 3 ) ) );
130 gradient.setVector( KoPoint( 2 * ( width() / 3 ), height() / 3 ) );
134 fill.pattern() = VPattern( il.iconPath(
"karbon.png", TDEIcon::Small ) );
138 fill.gradient() = gradient;
140 VColor c = fill.color();
142 fill.setColor( c,
false );
144 gp.moveTo( KoPoint( 2, 2 ) );
145 gp.lineTo( KoPoint( 2, height() - 2 ) );
146 gp.lineTo( KoPoint( width() - 2, height() - 2 ) );
147 gp.lineTo( KoPoint( width() - 2, 2 ) );
148 gp.lineTo( KoPoint( 2, 2 ) );
152 TQPainter p( &pixmap );
154 p.setPen( colorGroup().light() );
155 p.moveTo( 1, height() - 1 );
157 p.lineTo( width() - 1, 1 );
158 p.lineTo( width() - 1, height() - 1 );
159 p.lineTo( 1, height() - 1 );
160 p.setPen( colorGroup().dark() );
161 p.moveTo( 0, height() - 1 );
163 p.lineTo( width() - 1, 0 );
164 p.moveTo( width() - 2, 2 );
165 p.lineTo( width() - 2, height() - 2 );
166 p.lineTo( 2, height() - 2 );
167 bitBlt(
this, 0, 0, &pixmap, 0, 0, width(), height() );
170VGradientTabWidget::VGradientTabWidget( VGradient& gradient, KarbonResourceServer* server, TQWidget* parent,
const char* name )
171 : TQTabWidget( parent, name ), m_gradient( gradient ), m_resourceServer( server )
178VGradientTabWidget::~VGradientTabWidget()
182void VGradientTabWidget::setupUI()
184 m_editGroup =
new TQGroupBox( i18n(
"Edit Gradient" ) );
185 TQGridLayout* editLayout =
new TQGridLayout( m_editGroup, 7, 3 );
186 editLayout->setSpacing( 3 );
187 editLayout->setMargin( 6 );
188 editLayout->addRowSpacing( 0, 12 );
189 editLayout->addMultiCellWidget( m_gradientPreview =
new VGradientPreview( m_gradient, m_gradOpacity, m_editGroup ), 1, 3, 0, 0 );
190 editLayout->addWidget(
new TQLabel( i18n(
"Type:" ), m_editGroup ), 1, 1 );
191 editLayout->addWidget(
new TQLabel( i18n(
"Repeat:" ), m_editGroup ), 2, 1 );
192 editLayout->addWidget(
new TQLabel( i18n(
"Target:" ), m_editGroup ), 3, 1 );
193 editLayout->addWidget( m_gradientType =
new KComboBox(
false, m_editGroup ), 1, 2 );
194 m_gradientType->insertItem( i18n(
"Linear" ), 0 );
195 m_gradientType->insertItem( i18n(
"Radial" ), 1 );
196 m_gradientType->insertItem( i18n(
"Conical" ), 2 );
197 editLayout->addWidget( m_gradientRepeat =
new KComboBox(
false, m_editGroup ), 2, 2 );
198 m_gradientRepeat->insertItem( i18n(
"None" ), 0 );
199 m_gradientRepeat->insertItem( i18n(
"Reflect" ), 1 );
200 m_gradientRepeat->insertItem( i18n(
"Repeat" ), 2 );
201 editLayout->addWidget( m_gradientTarget =
new KComboBox(
false, m_editGroup ), 3, 2 );
202 m_gradientTarget->insertItem( i18n(
"Stroke" ), 0 );
203 m_gradientTarget->insertItem( i18n(
"Fill" ), 1 );
204 editLayout->addMultiCellWidget( m_addToPredefs =
new TQPushButton( i18n(
"&Add to Predefined Gradients" ), m_editGroup ), 6, 6, 0, 2 );
205 editLayout->addMultiCellWidget( m_gradientWidget =
new VGradientWidget( m_gradient, m_editGroup ), 4, 4, 0, 2 );
206 editLayout->addWidget(
new TQLabel( i18n(
"Overall opacity:" ), m_editGroup ), 5, 0 );
207 m_opacity =
new KIntNumInput( 100, m_editGroup );
208 m_opacity->setRange( 0, 100, 1,
true );
209 m_opacity->setValue( 100 );
210 editLayout->addMultiCellWidget( m_opacity, 5, 5, 1, 2 );
211 addTab( m_editGroup, i18n(
"Edit" ) );
213 TQGroupBox* predefGroup =
new TQGroupBox( i18n(
"Predefined Gradients" ) );
214 TQGridLayout* predefLayout =
new TQGridLayout( predefGroup, 3, 2 );
215 predefLayout->setSpacing( 3 );
216 predefLayout->setMargin( 6 );
217 predefLayout->addRowSpacing( 0, 12 );
218 predefLayout->addMultiCellWidget( m_predefGradientsView =
new TDEListBox( predefGroup ), 1, 1, 0, 2 );
219 predefLayout->addWidget( m_predefDelete =
new TQPushButton( i18n(
"&Delete" ), predefGroup ), 2, 0 );
220 predefLayout->addWidget( m_predefImport =
new TQPushButton( i18n(
"&Import" ), predefGroup ), 2, 1 );
221 m_predefImport->setEnabled(
false );
222 addTab( predefGroup, i18n(
"Predefined" ) );
225void VGradientTabWidget::setupConnections()
227 connect( m_gradientType, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( combosChange(
int ) ) );
228 connect( m_gradientRepeat, TQ_SIGNAL( activated(
int ) ),
this, TQ_SLOT( combosChange(
int ) ) );
229 connect( m_gradientWidget, TQ_SIGNAL( changed() ), m_gradientPreview, TQ_SLOT( update() ) );
230 connect( m_addToPredefs, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( addGradientToPredefs() ) );
231 connect( m_predefGradientsView, TQ_SIGNAL( doubleClicked( TQListBoxItem *,
const TQPoint & ) ),
this, TQ_SLOT( changeToPredef( TQListBoxItem* ) ) );
232 connect( m_predefDelete, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( deletePredef() ) );
233 connect( m_opacity, TQ_SIGNAL( valueChanged(
int ) ),
this, TQ_SLOT( opacityChanged(
int ) ) );
236void VGradientTabWidget::initUI()
238 m_gradientType->setCurrentItem( m_gradient.type() );
239 m_gradientRepeat->setCurrentItem( m_gradient.repeatMethod() );
240 m_gradientTarget->setCurrentItem( FILL );
241 m_opacity->setValue( 100 );
243 m_predefGradientsView->clear();
244 TQPtrList<VGradientListItem>* gradientList = m_resourceServer->gradients();
245 if( gradientList->count() > 0 )
246 for( VGradientListItem* g = gradientList->first(); g != NULL; g = gradientList->next() )
247 m_predefGradientsView->insertItem(
new VGradientListItem( *g ) );
251VGradientTabWidget::opacity()
const
253 return m_opacity->value() / 100.0;
257VGradientTabWidget::setOpacity(
double opacity )
259 if( opacity < 0.0 || opacity > 1.0 )
262 m_gradOpacity = opacity;
263 m_opacity->setValue(
int(opacity*100.0) );
267VGradientTabWidget::gradient()
272void VGradientTabWidget::setGradient( VGradient& gradient )
274 m_gradient = gradient;
279VGradientTabWidget::VGradientTarget VGradientTabWidget::target()
281 return (VGradientTarget)m_gradientTarget->currentItem();
284void VGradientTabWidget::setTarget( VGradientTarget target )
286 m_gradientTarget->setCurrentItem( target );
289void VGradientTabWidget::combosChange(
int )
291 m_gradient.setType( (VGradient::VGradientType)m_gradientType->currentItem() );
292 m_gradient.setRepeatMethod( (VGradient::VGradientRepeatMethod)m_gradientRepeat->currentItem() );
294 m_gradientPreview->update();
297void VGradientTabWidget::opacityChanged(
int value )
299 m_gradOpacity = value / 100.0;
300 m_gradientPreview->update();
303void VGradientTabWidget::addGradientToPredefs()
305 VGradientListItem* item = m_resourceServer->addGradient(
new VGradient( m_gradient ) );
306 m_predefGradientsView->insertItem( item );
309void VGradientTabWidget::predefSelected( TQListBoxItem* item )
313 VGradientListItem* gradientItem = (VGradientListItem*)item;
314 m_predefDelete->setEnabled( gradientItem->canDelete() );
318void VGradientTabWidget::changeToPredef( TQListBoxItem* item )
322 VGradientListItem* gradientItem = (VGradientListItem*)item;
323 m_gradient = *gradientItem->gradient();
324 m_gradientType->setCurrentItem( m_gradient.type() );
325 m_gradientRepeat->setCurrentItem( m_gradient.repeatMethod() );
326 m_opacity->setValue( 100 );
327 m_gradientPreview->update();
328 m_gradientWidget->update();
329 showPage( m_editGroup );
333void VGradientTabWidget::deletePredef()
335 int i = m_predefGradientsView->currentItem();
336 if( !m_predefGradientsView->item( i ) )
338 m_resourceServer->removeGradient( (VGradientListItem*)m_predefGradientsView->item( i ) );
339 m_predefGradientsView->removeItem( i );
342#include "vgradienttabwidget.moc"
void setOpacity(float opacity)
Sets the color opacity.
Manages the fill of shapes.