diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /karbon/widgets | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'karbon/widgets')
27 files changed, 3960 insertions, 0 deletions
diff --git a/karbon/widgets/Makefile.am b/karbon/widgets/Makefile.am new file mode 100644 index 00000000..c78d166c --- /dev/null +++ b/karbon/widgets/Makefile.am @@ -0,0 +1,53 @@ +INCLUDES = $(KOFFICE_INCLUDES) $(KOPAINTER_INCLUDES) \ + -I$(srcdir)/.. \ + -I$(srcdir)/../core \ + -I$(srcdir)/../commands \ + -I$(srcdir)/../render \ + -I$(srcdir)/../dialogs \ + -I$(srcdir)/../dockers \ + -I$(srcdir)/../tools \ + $(all_includes) + +noinst_LTLIBRARIES = \ + libkarbonwidgets.la + +noinst_HEADERS = \ + vcanvas.h \ + vcolorslider.h \ + vgradientwidget.h \ + vgradienttabwidget.h \ + vreference.h \ + vstrokefillpreview.h \ + vtranslate.h \ + vselecttoolbar.h \ + vsmallpreview.h \ + vstatebutton.h \ + vtoolbox.h \ + vtypebuttonbox.h \ + vruler.h + +libkarbonwidgets_la_SOURCES = \ + dummy.cc \ + vcanvas.cc \ + vcolorslider.cc \ + vgradientwidget.cc \ + vgradienttabwidget.cc \ + vreference.cc \ + vstrokefillpreview.cc \ + vtranslate.cc \ + vselecttoolbar.cc \ + vsmallpreview.cc \ + vstatebutton.cc \ + vtoolbox.cc \ + vtypebuttonbox.cc \ + vruler.cc + +libkarbonwidgets_la_METASOURCES = \ + AUTO + +DISTCLEANFILES = \ + dummy.cc + +dummy.cc: + echo > dummy.cc + diff --git a/karbon/widgets/vcanvas.cc b/karbon/widgets/vcanvas.cc new file mode 100644 index 00000000..c3c91670 --- /dev/null +++ b/karbon/widgets/vcanvas.cc @@ -0,0 +1,380 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include <qcursor.h> +#include <qpainter.h> +#include <qpixmap.h> + +#include "karbon_view.h" +#include "karbon_part.h" +#include "karbon_drag.h" +#include "vcanvas.h" +#include "vdocument.h" +#include "vpainter.h" +#include "vqpainter.h" +#include "vpainterfactory.h" +#include "vselection.h" +#include "vtoolcontroller.h" +#include "vtool.h" + +#include <kdebug.h> +#include <klocale.h> +#include <kcolordrag.h> + +int +VCanvas::pageOffsetX() const +{ + double zoomedWidth = m_part->document().width() * m_view->zoom(); + if( contentsWidth() < visibleWidth() ) + return int( 0.5 * ( visibleWidth() - zoomedWidth ) ); + else + return int( 0.5 * ( contentsWidth() - zoomedWidth ) ); +} + +int +VCanvas::pageOffsetY() const +{ + double zoomedHeight = m_part->document().height() * m_view->zoom(); + if( contentsHeight() < visibleHeight() ) + return int( 0.5 * ( visibleHeight() - zoomedHeight ) ); + else + return int( 0.5 * ( contentsHeight() - zoomedHeight ) ); +} + +KoPoint VCanvas::snapToGrid( const KoPoint &point ) +{ + if( !m_part->document().grid().isSnap ) + return point; + + KoPoint p = point; + + KoSize dist = m_part->document().grid().snap; + KoSize dxy = m_part->document().grid().freq; + + int dx = qRound( p.x() / dxy.width() ); + int dy = qRound( p.y() / dxy.height() ); + + float distx = QMIN( QABS( p.x() - dxy.width() * dx ), QABS( p.x() - dxy.width() * ( dx + 1 ) ) ); + float disty = QMIN( QABS( p.y() - dxy.height() * dy ), QABS( p.y() - dxy.height() * ( dy + 1 ) ) ); + + if( distx < dist.width() ) + { + if( QABS(p.x() - dxy.width() * dx ) < QABS( p.x() - dxy.width() * ( dx + 1 ) ) ) + p.rx() = dxy.width() * dx; + else + p.rx() = dxy.width() * ( dx + 1 ); + } + + if( disty < dist.height() ) + { + if( QABS( p.y() - dxy.height() * dy ) < QABS( p.y() - dxy.height() * ( dy + 1 ) ) ) + p.ry() = dxy.height() * dy; + else + p.ry() = dxy.height() * ( dy + 1 ); + } + + return p; +} + + +VCanvas::VCanvas( QWidget *parent, KarbonView* view, KarbonPart* part ) + : QScrollView( parent, "canvas", WStaticContents/*WNorthWestGravity*/ | WResizeNoErase | + WRepaintNoErase ), m_part( part ), m_view( view ) +{ + connect(this, SIGNAL( contentsMoving( int, int ) ), this, SLOT( slotContentsMoving( int, int ) ) ); + viewport()->setFocusPolicy( QWidget::StrongFocus ); + + viewport()->setMouseTracking( true ); + setMouseTracking( true ); + + viewport()->setBackgroundColor( Qt::white ); + viewport()->setBackgroundMode( QWidget::NoBackground ); + viewport()->installEventFilter( this ); + + resizeContents( 800, 600 ); + m_pixmap = new QPixmap( 800, 600 ); + + setFocus(); + + setAcceptDrops( true ); +} + +VCanvas::~VCanvas() +{ + delete m_pixmap; + m_view = 0L; + m_part = 0L; +} + +void +VCanvas::setPos( const KoPoint& p ) +{ + KoPoint p2 = toViewport( p ); + QCursor::setPos( mapToGlobal( QPoint( int(p2.x()), int(p2.y()) ) ) ); +} + +bool +VCanvas::eventFilter( QObject* object, QEvent* event ) +{ + QScrollView::eventFilter( object, event ); + + if( event->type() == QEvent::AccelOverride || event->type() == QEvent::Accel ) + return QScrollView::eventFilter( object, event ); + + if( event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease ) + return m_view->keyEvent( event ); + + QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>( event ); + + if( mouseEvent && m_view ) + { + KoPoint canvasCoordinate = toContents( KoPoint( mouseEvent->pos() ) ); + return m_view->mouseEvent( mouseEvent, canvasCoordinate ); + } + + return false; +} + + +// This causes a repaint normally, so just overwriting it omits the repainting +void +VCanvas::focusInEvent( QFocusEvent * ) +{ +} + +KoPoint +VCanvas::toViewport( const KoPoint &p ) const +{ + KoPoint p2 = p; + p2.setX( ( p.x() * m_view->zoom() ) - contentsX() + pageOffsetX() ); + if( contentsHeight() > height() ) + p2.setY( ( contentsHeight() - ( p.y() * m_view->zoom() + contentsY() + pageOffsetY() ) ) ); + else + p2.setY( ( height() - p.y() * m_view->zoom() + pageOffsetY() ) ); + return p2; +} + +KoPoint +VCanvas::toContents( const KoPoint &p ) const +{ + KoPoint p2 = p; + p2.setX( ( p.x() + contentsX() - pageOffsetX() ) / m_view->zoom() ); + if( contentsHeight() > height() ) + p2.setY( ( contentsHeight() - ( p.y() + contentsY() + pageOffsetY()) ) / m_view->zoom() ); + else + p2.setY( ( height() - p.y() - pageOffsetY() ) / m_view->zoom() ); + return p2; +} + +KoRect +VCanvas::boundingBox() const +{ + KoPoint p1( 0, 0 ); + KoPoint p2( width(), height() ); + if( !m_view->documentDeleted() ) + { + p1 = toContents( p1 ); + p2 = toContents( p2 ); + } + return KoRect( p1, p2 ).normalize(); +} + +void +VCanvas::setYMirroring( VPainter *p ) +{ + QWMatrix mat; + + mat.scale( 1, -1 ); + mat.translate( pageOffsetX(), pageOffsetY() ); + + if( contentsHeight() > visibleHeight() ) + mat.translate( -contentsX(), contentsY() - contentsHeight() ); + else + mat.translate( 0, -visibleHeight() ); + + p->setWorldMatrix( mat ); +} + +void +VCanvas::viewportPaintEvent( QPaintEvent *e ) +{ + QRect eventRect = e->rect(); + KoRect rect = KoRect::fromQRect( eventRect ); + + setYMirroring( m_view->painterFactory()->editpainter() ); + viewport()->setUpdatesEnabled( false ); + VPainter *p = m_view->painterFactory()->painter(); + + // TODO : only update ROIs + p->begin(); + p->clear( rect, QColor( 195, 194, 193 ) ); + p->setZoomFactor( m_view->zoom() ); + setYMirroring( p ); + + // TRICK : slightly adjust the matrix so libart AA looks better + QWMatrix mat = p->worldMatrix(); + p->setWorldMatrix( mat.translate( -.5, -.5 ) ); + + // set up clippath + p->newPath(); + p->moveTo( rect.topLeft() ); + p->lineTo( rect.topRight() ); + p->lineTo( rect.bottomRight() ); + p->lineTo( rect.bottomLeft() ); + p->lineTo( rect.topLeft() ); + p->setClipPath(); + + m_part->document().drawPage( p, m_part->pageLayout(), m_view->showPageMargins() ); + KoRect bbox = boundingBox(); + m_part->document().draw( p, &bbox ); + + p->resetClipPath(); + p->end(); + + // draw handle: + VQPainter qpainter( p->device() ); + setYMirroring( &qpainter ); + qpainter.setZoomFactor( m_view->zoom() ); + m_part->document().selection()->draw( &qpainter, m_view->zoom() ); + + if( m_view->toolController()->currentTool() ) + m_view->toolController()->currentTool()->draw( &qpainter ); + + bitBlt( viewport(), eventRect.topLeft(), p->device(), eventRect ); + viewport()->setUpdatesEnabled( true ); +} + +void +VCanvas::setViewport( double centerX, double centerY ) +{ + setContentsPos( int( centerX * contentsWidth() - 0.5 * visibleWidth() ), + int( centerY * contentsHeight() - 0.5 * visibleHeight() ) ); +} + +void +VCanvas::setViewportRect( const KoRect &r ) +{ + viewport()->setUpdatesEnabled( false ); + double zoomX = m_view->zoom() * ( ( visibleWidth() / m_view->zoom() ) / r.width() ); + double zoomY = m_view->zoom() * ( ( visibleHeight() / m_view->zoom() ) / r.height() ); + double pageOffX = ( contentsWidth() - ( m_part->document().width() * m_view->zoom() ) ) / 2.0; + double centerX = double( ( r.center().x() ) * m_view->zoom() + pageOffX ) / double( contentsWidth() ); + double pageOffY = ( contentsHeight() - ( m_part->document().height() * m_view->zoom() ) ) / 2.0; + double centerY = double( ( r.center().y() ) * m_view->zoom() + pageOffY ) / double( contentsHeight() ); + double zoom = zoomX < zoomY ? zoomX : zoomY; + resizeContents( int( ( zoom / m_view->zoom() ) * contentsWidth() ), + int( ( zoom / m_view->zoom() ) * contentsHeight() ) ); + setViewport( centerX, 1.0 - centerY ); + m_view->setZoomAt( zoom ); + viewport()->setUpdatesEnabled( true ); +} + +void +VCanvas::drawContents( QPainter* painter, int clipx, int clipy, + int clipw, int cliph ) +{ + drawDocument( painter, KoRect( clipx, clipy, clipw, cliph ) ); +} + +void +VCanvas::drawDocument( QPainter* /*painter*/, const KoRect&, bool drawVObjects ) +{ + setYMirroring( m_view->painterFactory()->editpainter() ); + + VPainter* p = m_view->painterFactory()->painter(); + if( drawVObjects ) + { + p->begin(); + p->clear( QColor( 195, 194, 193 ) ); + p->setZoomFactor( m_view->zoom() ); + setYMirroring( p ); + // TRICK : slightly adjust the matrix so libart AA looks better + QWMatrix mat = p->worldMatrix(); + p->setWorldMatrix( mat.translate( -.5, -.5 ) ); + + m_part->document().drawPage( p, m_part->pageLayout(), m_view->showPageMargins() ); + KoRect r2 = boundingBox(); + m_part->document().draw( p, &r2 ); + + p->end(); + } + + // draw handle: + VQPainter qpainter( p->device() ); + setYMirroring( &qpainter ); + qpainter.setZoomFactor( m_view->zoom() ); + m_part->document().selection()->draw( &qpainter, m_view->zoom() ); + + if( m_view->toolController()->currentTool() ) + m_view->toolController()->currentTool()->draw( &qpainter ); + + bitBlt( viewport(), 0, 0, p->device(), 0, 0, width(), height() ); +} + +void +VCanvas::repaintAll( bool drawVObjects ) +{ + drawDocument( 0, KoRect( 0, 0, width(), height() ), drawVObjects ); +} + +/// repaints just a rect area (no scrolling) +void +VCanvas::repaintAll( const KoRect &r ) +{ + drawDocument( 0, r ); +} + +void +VCanvas::resizeEvent( QResizeEvent* event ) +{ + double centerX = double( contentsX() + 0.5 * visibleWidth() ) / double( contentsWidth() ); + double centerY = double( contentsY() + 0.5 * visibleHeight() ) / double( contentsHeight() ); + + QScrollView::resizeEvent( event ); + if( !m_pixmap ) + m_pixmap = new QPixmap( width(), height() ); + else + m_pixmap->resize( width(), height() ); + + VPainter *p = m_view->painterFactory()->painter(); + p->resize( width(), height() ); + p->clear( QColor( 195, 194, 193 ) ); + setViewport( centerX, centerY ); +} + +void +VCanvas::slotContentsMoving( int /*x*/, int /*y*/ ) +{ + emit viewportChanged(); +} + +void +VCanvas::dragEnterEvent( QDragEnterEvent *e ) +{ + e->accept( KarbonDrag::canDecode( e ) || KColorDrag::canDecode( e ) ); +} + +void +VCanvas::dropEvent( QDropEvent *e ) +{ + m_view->dropEvent( e ); +} + +#include "vcanvas.moc" + diff --git a/karbon/widgets/vcanvas.h b/karbon/widgets/vcanvas.h new file mode 100644 index 00000000..d0446087 --- /dev/null +++ b/karbon/widgets/vcanvas.h @@ -0,0 +1,101 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef __VCANVAS_H__ +#define __VCANVAS_H__ + + +#include <qscrollview.h> +#include <koffice_export.h> +class KarbonPart; +class KarbonView; +class KoRect; +class KoPoint; +class VPainter; + +// The canvas is a QScrollView. + +class KARBONCOMMON_EXPORT VCanvas : public QScrollView +{ + Q_OBJECT +public: + VCanvas( QWidget *parent, KarbonView* view, KarbonPart* part ); + virtual ~VCanvas(); + + void repaintAll( const KoRect & ); + void repaintAll( bool drawVObjects = true ); + + QPixmap *pixmap() { return m_pixmap; } + + /** + * Sets mouse position to point p. + */ + void setPos( const KoPoint& p ); + + KoPoint toViewport( const KoPoint & ) const; + KoPoint toContents( const KoPoint & ) const; + KoRect boundingBox() const; + + /** + * Adjusts the viewport top-left position. This doesn't change the zoom level. + * Note that centerX and centerY is a value between 0.0 and 1.0, indicating a + * percentage of the total width/height. Thus centerX/centerY indicates the + * center of the viewport. + */ + void setViewport( double centerX, double centerY ); + + /** + * Sets the canvas viewport rectangle to rect. The zoom level is adjusted for this, if + * needed. + */ + void setViewportRect( const KoRect &rect ); + + int pageOffsetX() const; + int pageOffsetY() const; + + KoPoint snapToGrid( const KoPoint & ); + +protected: + virtual void dragEnterEvent( QDragEnterEvent * ); + virtual void dropEvent( QDropEvent * ); + virtual void focusInEvent( QFocusEvent * ); + virtual void viewportPaintEvent( QPaintEvent* ); + virtual void drawContents( QPainter* painter, int clipx, int clipy, + int clipw, int cliph ); + void drawDocument( QPainter* painter, const KoRect& rect, bool drawVObjects = true ); + + virtual void resizeEvent( QResizeEvent* event ); + + virtual bool eventFilter( QObject* object, QEvent* event ); + + void setYMirroring( VPainter * ); + +private slots: + void slotContentsMoving( int , int ); + +signals: + void viewportChanged(); + +private: + QPixmap *m_pixmap; + KarbonPart* m_part; + KarbonView* m_view; +}; + +#endif diff --git a/karbon/widgets/vcolorslider.cc b/karbon/widgets/vcolorslider.cc new file mode 100644 index 00000000..cd11951b --- /dev/null +++ b/karbon/widgets/vcolorslider.cc @@ -0,0 +1,149 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* vcolorslider.cc */ + +#include <qlayout.h> +#include <qlabel.h> +#include <knuminput.h> +#include <kselect.h> + +#include "vcolorslider.h" + +VColorSlider::VColorSlider( QWidget* parent, const char* name ) + : QWidget( parent, name ) +{ + init(); +} + +// Label, left color, right color, min, max, value ... +VColorSlider::VColorSlider( const QString& label, const QColor& col1, + const QColor& col2, int min, int max, int value, QWidget* parent, const char* name ) + : QWidget( parent, name ) +{ + init(); + setLabel( label ); + setColors( col1, col2 ); + setMinValue( min ); + setMaxValue( max ); + setValue( value ); +} + +VColorSlider::~VColorSlider() +{ +} + +void VColorSlider::init() +{ + m_isDragging = false; + QHBoxLayout *layout = new QHBoxLayout( this, 3 ); + + m_label = new QLabel( this ); + m_gradientSelect = new KGradientSelector( KSelector::Horizontal, this ); + m_spinBox = new KIntSpinBox( this ); + + layout->addWidget( m_label ); + layout->addWidget( m_gradientSelect, 2 ); + layout->addWidget( m_spinBox ); + + setValue( 0 ); + setMinValue( 0 ); + setMaxValue( 255 ); + + connect( m_spinBox, SIGNAL( valueChanged ( int ) ), this, SLOT( updateFrom_spinBox( int ) ) ); + connect( m_gradientSelect, SIGNAL( valueChanged ( int ) ), this, SLOT( updateFrom_gradientSelect( int ) ) ); + + m_gradientSelect->installEventFilter( this ); + + layout->activate(); +} + +void VColorSlider::setLabel( const QString& label ) +{ + m_label->setText( label ); +} + +void VColorSlider::setColors( const QColor& color1, const QColor& color2 ) +{ + m_gradientSelect->setColors( color1, color2 ); +} + +void VColorSlider::setValue( int value ) +{ + m_spinBox->setValue( value ); + m_gradientSelect->setValue( (m_maxValue - value) + m_minValue ); +} + +void VColorSlider::setMinValue( int value ) +{ + m_minValue = value; + m_spinBox->setMinValue( value ); + m_gradientSelect->setMinValue( value ); +} + +void VColorSlider::setMaxValue( int value ) +{ + m_maxValue = value; + m_spinBox->setMaxValue( value ); + m_gradientSelect->setMaxValue( value ); +} + +int VColorSlider::value() +{ + return( m_spinBox->value() ); +} + +void VColorSlider::updateFrom_spinBox( int value ) +{ + if ( value != m_gradientSelect->value() ) + { + disconnect( m_gradientSelect, SIGNAL( valueChanged ( int ) ), this, SLOT( updateFrom_gradientSelect( int ) ) ); + m_gradientSelect->setValue( (m_maxValue - value) + m_minValue ); + connect( m_gradientSelect, SIGNAL( valueChanged ( int ) ), this, SLOT( updateFrom_gradientSelect( int ) ) ); + emit valueChanged( value ); + } +} + +void VColorSlider::updateFrom_gradientSelect( int value ) +{ + value = (m_maxValue - value) + m_minValue; + if ( value != m_spinBox->value() ) + { + disconnect( m_spinBox, SIGNAL( valueChanged ( int ) ), this, SLOT( updateFrom_spinBox( int ) ) ); + m_spinBox->setValue( value ); + connect( m_spinBox, SIGNAL( valueChanged ( int ) ), this, SLOT( updateFrom_spinBox( int ) ) ); + emit valueChanged( value ); + } +} + +bool VColorSlider::eventFilter( QObject *obj, QEvent *ev ) +{ + if( obj == m_gradientSelect ) + { + if ( ev->type() == QEvent::MouseButtonPress ) + m_isDragging = true; + else if( ev->type() == QEvent::MouseButtonRelease ) + m_isDragging = false; + } + return FALSE; +} + +#include "vcolorslider.moc" + diff --git a/karbon/widgets/vcolorslider.h b/karbon/widgets/vcolorslider.h new file mode 100644 index 00000000..82c7f6ec --- /dev/null +++ b/karbon/widgets/vcolorslider.h @@ -0,0 +1,141 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* vcolorslider.h */ +#ifndef VCOLORSLIDER_H +#define VCOLORSLIDER_H + +#include <qwidget.h> + +class QLabel; +class KIntSpinBox; +class KGradientSelector; + +/** + * This is the color slider widget that is used to select color or color components. + * It combines a label, a gradient selector and a spinbox. + */ +class VColorSlider : public QWidget +{ + Q_OBJECT +public: + /** + * Constructs a new color slider. + * + * @param parent the parent widget + * @param name the slider's name + */ + VColorSlider( QWidget* parent = 0L, const char* name = 0L ); + + /** + * Constructs a new color slider. + * + * @param label the label text + * @param col1 the left color + * @param col2 the right color + * @param min the minimum value + * @param max the maximum value + * @param value the actual value + * @param parent the parent widget + * @param name the slider's name + */ + VColorSlider( const QString& label, const QColor& col1, const QColor& col2, + int min, int max, int value, QWidget* parent = 0L, const char* name = 0L ); + + /** Destroys the color slider */ + ~VColorSlider(); + + /** + * Reflects if the slider is still being dragged while the color changes + * + * @return true if slider is still dragged, else false + */ + bool isDragging() { return m_isDragging; } +public slots: + + /** + * Sets the description of the slider + * + * @param label the new label text + */ + virtual void setLabel( const QString& label ); + + /** + * Sets the colors for the slider. + * + * @param color1 the new left color + * @param color2 the new right color + */ + virtual void setColors( const QColor& color1, const QColor& color2 ); + + /** + * Sets the value of the spinbox (and the value of the vcolorslider). + * + * @param value the new value + */ + virtual void setValue( int value ); + + /** + * Sets the minimum value of the spinbox and slider. + * + * @param value the new minimum value + */ + virtual void setMinValue( int value ); + + /** + * Sets the maximum value of the spinbox and slider. + * + * @param value the new maximum value + */ + virtual void setMaxValue( int value ); + + /** + * Retrieves the actual value of the spinbox and slider. + * + * @return the actual value + */ + int value(); + +private: + void init(); + bool eventFilter( QObject *obj, QEvent *ev ); + QLabel* m_label; + KIntSpinBox* m_spinBox; + KGradientSelector* m_gradientSelect; + bool m_isDragging; + int m_minValue; + int m_maxValue; + +signals: + /** + * Is emitted whenever the slider or spinbox value has changed. + * Use @ref isDragging to know if the slider is still being dragged. + * + * @param value the actual value + */ + void valueChanged( int value ); + +private slots: + void updateFrom_spinBox( int ); + void updateFrom_gradientSelect( int ); +}; + +#endif + diff --git a/karbon/widgets/vgradienttabwidget.cc b/karbon/widgets/vgradienttabwidget.cc new file mode 100644 index 00000000..44bb53bc --- /dev/null +++ b/karbon/widgets/vgradienttabwidget.cc @@ -0,0 +1,343 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include <qlabel.h> +#include <qpainter.h> +#include <qlayout.h> +#include <qgroupbox.h> +#include <qpushbutton.h> +#include <qfileinfo.h> +#include <qpixmap.h> + +#include <knuminput.h> +#include <kcombobox.h> +#include <klocale.h> +#include <klistbox.h> +#include <kiconloader.h> + +#include "vgradientwidget.h" +#include "vgradienttabwidget.h" +#include "karbon_resourceserver.h" +#include "vkopainter.h" +#include "vfill.h" + +VGradientListItem::VGradientListItem( const VGradient& gradient, QString filename ) + : QListBoxItem( 0L ), m_filename( filename ) +{ + m_gradient = new VGradient( gradient ); + + m_pixmap.resize( 200, 16 ); + VKoPainter gp( &m_pixmap, m_pixmap.width(), m_pixmap.height() ); + gp.setRasterOp( Qt::XorROP ); + gp.newPath(); + VGradient grad( *m_gradient ); + grad.setOrigin( KoPoint( 0, 0 ) ); + grad.setVector( KoPoint( m_pixmap.width() - 1, 0 ) ); + grad.setType( VGradient::linear ); + VFill fill; + fill.gradient() = grad; + fill.setType( VFill::grad ); + gp.setBrush( fill ); + gp.moveTo( KoPoint( 0, 0 ) ); + gp.lineTo( KoPoint( 0, m_pixmap.height() - 1 ) ); + gp.lineTo( KoPoint( m_pixmap.width() - 1, m_pixmap.height() - 1 ) ); + gp.lineTo( KoPoint( m_pixmap.width() - 1, 0 ) ); + gp.lineTo( KoPoint( 0, 0 ) ); + gp.fillPath(); + gp.end(); + + m_delete = QFileInfo( filename ).isWritable(); +} // VGradientListItem::VGradientListItem + +VGradientListItem::VGradientListItem( const VGradientListItem& gradient ) + : QListBoxItem( 0L ) +{ + m_pixmap = gradient.m_pixmap; + m_delete = gradient.m_delete; + m_gradient = new VGradient( *gradient.gradient() ); + m_filename = gradient.m_filename; +} // VGradientListItem::VGradientListItem + +VGradientListItem::~VGradientListItem() +{ + delete m_gradient; +} // VGradientListItem::~VGradientListItem + +int VGradientListItem::width( const QListBox* lb ) const +{ + return lb->width() - 25; +} // VGradientListItem::width + +void VGradientListItem::paint( QPainter* painter ) +{ + painter->save(); + painter->setRasterOp( Qt::CopyROP ); + QRect r ( 0, 0, width( listBox() ), height( listBox() ) ); + painter->scale( ( (float)( width( listBox() ) ) ) / 200., 1. ); + painter->drawPixmap( 0, 0, m_pixmap ); + painter->restore(); + if ( isSelected() ) + painter->setPen( listBox()->colorGroup().highlightedText() ); + else + painter->setPen( listBox()->colorGroup().base() ); + painter->drawRect( r ); + painter->flush(); +} // VGradientListItem::paint + +VGradientPreview::VGradientPreview( VGradient& gradient, double& opacity, QWidget* parent, const char* name ) + : QWidget( parent, name ), m_gradient( &gradient ), m_opacity( &opacity ) +{ + setBackgroundMode( Qt::NoBackground ); + setMinimumSize( 70, 70 ); +} // VGradientPreview::VGradientPreview + +VGradientPreview::~VGradientPreview() +{ +} // VGradientPreview::~VGradientPreview + +void VGradientPreview::paintEvent( QPaintEvent* ) +{ + QPixmap pixmap( width(), height() ); + VKoPainter gp( &pixmap, width(), height() ); + gp.setRasterOp( Qt::XorROP ); + gp.newPath(); + VGradient gradient( *m_gradient ); + if( gradient.type() == VGradient::radial || gradient.type() == VGradient::conic ) + { + gradient.setOrigin( KoPoint( width() / 2, height() / 2 ) ); + gradient.setFocalPoint( KoPoint( width() / 2, height() / 2 ) ); + gradient.setVector( KoPoint( width() / 4, height() / 4 ) ); + } + else + { + gradient.setOrigin( KoPoint( width() / 3, 2 * ( height() / 3 ) ) ); + gradient.setVector( KoPoint( 2 * ( width() / 3 ), height() / 3 ) ); + } + VFill fill; + KIconLoader il; + fill.pattern() = VPattern( il.iconPath( "karbon.png", KIcon::Small ) ); + fill.setType( VFill::patt ); + gp.setBrush( fill ); + gp.fillPath(); + fill.gradient() = gradient; + fill.setType( VFill::grad ); + VColor c = fill.color(); + c.setOpacity( *m_opacity ); + fill.setColor( c, false ); + gp.setBrush( fill ); + gp.moveTo( KoPoint( 2, 2 ) ); + gp.lineTo( KoPoint( 2, height() - 2 ) ); + gp.lineTo( KoPoint( width() - 2, height() - 2 ) ); + gp.lineTo( KoPoint( width() - 2, 2 ) ); + gp.lineTo( KoPoint( 2, 2 ) ); + gp.fillPath(); + gp.end(); + + QPainter p( &pixmap ); + + p.setPen( colorGroup().light() ); + p.moveTo( 1, height() - 1 ); + p.lineTo( 1, 1 ); + p.lineTo( width() - 1, 1 ); + p.lineTo( width() - 1, height() - 1 ); + p.lineTo( 1, height() - 1 ); + p.setPen( colorGroup().dark() ); + p.moveTo( 0, height() - 1 ); + p.lineTo( 0, 0 ); + p.lineTo( width() - 1, 0 ); + p.moveTo( width() - 2, 2 ); + p.lineTo( width() - 2, height() - 2 ); + p.lineTo( 2, height() - 2 ); + bitBlt( this, 0, 0, &pixmap, 0, 0, width(), height() ); +} // VGradientPreview::paintEvent + +VGradientTabWidget::VGradientTabWidget( VGradient& gradient, KarbonResourceServer* server, QWidget* parent, const char* name ) + : QTabWidget( parent, name ), m_gradient( gradient ), m_resourceServer( server ) +{ + setupUI(); + setupConnections(); + initUI(); +} // VGradientTabWidget::VGradientTabWidget + +VGradientTabWidget::~VGradientTabWidget() +{ +} // VGradientTabWidget::~VGradientTabWidget + +void VGradientTabWidget::setupUI() +{ + m_editGroup = new QGroupBox( i18n( "Edit Gradient" ) ); + QGridLayout* editLayout = new QGridLayout( m_editGroup, 7, 3 ); + editLayout->setSpacing( 3 ); + editLayout->setMargin( 6 ); + editLayout->addRowSpacing( 0, 12 ); + editLayout->addMultiCellWidget( m_gradientPreview = new VGradientPreview( m_gradient, m_gradOpacity, m_editGroup ), 1, 3, 0, 0 ); + editLayout->addWidget( new QLabel( i18n( "Type:" ), m_editGroup ), 1, 1 ); + editLayout->addWidget( new QLabel( i18n( "Repeat:" ), m_editGroup ), 2, 1 ); + editLayout->addWidget( new QLabel( i18n( "Target:" ), m_editGroup ), 3, 1 ); + editLayout->addWidget( m_gradientType = new KComboBox( false, m_editGroup ), 1, 2 ); + m_gradientType->insertItem( i18n( "Linear" ), 0 ); + m_gradientType->insertItem( i18n( "Radial" ), 1 ); + m_gradientType->insertItem( i18n( "Conical" ), 2 ); + editLayout->addWidget( m_gradientRepeat = new KComboBox( false, m_editGroup ), 2, 2 ); + m_gradientRepeat->insertItem( i18n( "None" ), 0 ); + m_gradientRepeat->insertItem( i18n( "Reflect" ), 1 ); + m_gradientRepeat->insertItem( i18n( "Repeat" ), 2 ); + editLayout->addWidget( m_gradientTarget = new KComboBox( false, m_editGroup ), 3, 2 ); + m_gradientTarget->insertItem( i18n( "Stroke" ), 0 ); + m_gradientTarget->insertItem( i18n( "Fill" ), 1 ); + editLayout->addMultiCellWidget( m_addToPredefs = new QPushButton( i18n( "&Add to Predefined Gradients" ), m_editGroup ), 6, 6, 0, 2 ); + editLayout->addMultiCellWidget( m_gradientWidget = new VGradientWidget( m_gradient, m_editGroup ), 4, 4, 0, 2 ); + editLayout->addWidget( new QLabel( i18n( "Overall opacity:" ), m_editGroup ), 5, 0 ); + m_opacity = new KIntNumInput( 100, m_editGroup ); + m_opacity->setRange( 0, 100, 1, true ); + m_opacity->setValue( 100 ); + editLayout->addMultiCellWidget( m_opacity, 5, 5, 1, 2 ); + addTab( m_editGroup, i18n( "Edit" ) ); + + QGroupBox* predefGroup = new QGroupBox( i18n( "Predefined Gradients" ) ); + QGridLayout* predefLayout = new QGridLayout( predefGroup, 3, 2 ); + predefLayout->setSpacing( 3 ); + predefLayout->setMargin( 6 ); + predefLayout->addRowSpacing( 0, 12 ); + predefLayout->addMultiCellWidget( m_predefGradientsView = new KListBox( predefGroup ), 1, 1, 0, 2 ); + predefLayout->addWidget( m_predefDelete = new QPushButton( i18n( "&Delete" ), predefGroup ), 2, 0 ); + predefLayout->addWidget( m_predefImport = new QPushButton( i18n( "&Import" ), predefGroup ), 2, 1 ); + m_predefImport->setEnabled( false ); + addTab( predefGroup, i18n( "Predefined" ) ); +} // VGradientTabWidget::setupUI + +void VGradientTabWidget::setupConnections() +{ + connect( m_gradientType, SIGNAL( activated( int ) ), this, SLOT( combosChange( int ) ) ); + connect( m_gradientRepeat, SIGNAL( activated( int ) ), this, SLOT( combosChange( int ) ) ); + connect( m_gradientWidget, SIGNAL( changed() ), m_gradientPreview, SLOT( update() ) ); + connect( m_addToPredefs, SIGNAL( clicked() ), this, SLOT( addGradientToPredefs() ) ); + connect( m_predefGradientsView, SIGNAL( doubleClicked( QListBoxItem *, const QPoint & ) ), this, SLOT( changeToPredef( QListBoxItem* ) ) ); + connect( m_predefDelete, SIGNAL( clicked() ), this, SLOT( deletePredef() ) ); + connect( m_opacity, SIGNAL( valueChanged( int ) ), this, SLOT( opacityChanged( int ) ) ); +} // VGradientTabWidget::setupConnection + +void VGradientTabWidget::initUI() +{ + m_gradientType->setCurrentItem( m_gradient.type() ); + m_gradientRepeat->setCurrentItem( m_gradient.repeatMethod() ); + m_gradientTarget->setCurrentItem( FILL ); + m_opacity->setValue( 100 ); + + m_predefGradientsView->clear(); + QPtrList<VGradientListItem>* gradientList = m_resourceServer->gradients(); + if( gradientList->count() > 0 ) + for( VGradientListItem* g = gradientList->first(); g != NULL; g = gradientList->next() ) + m_predefGradientsView->insertItem( new VGradientListItem( *g ) ); +} // VGradientTabWidget::initUI + +double +VGradientTabWidget::opacity() const +{ + return m_opacity->value() / 100.0; +} + +void +VGradientTabWidget::setOpacity( double opacity ) +{ + if( opacity < 0.0 || opacity > 1.0 ) + return; + + m_gradOpacity = opacity; + m_opacity->setValue( int(opacity*100.0) ); +} + +const VGradient& +VGradientTabWidget::gradient() +{ + return m_gradient; +} // VGradientTabWidget::gradient + +void VGradientTabWidget::setGradient( VGradient& gradient ) +{ + m_gradient = gradient; + + initUI(); +} // VGradientTabWidget::setGradient + +VGradientTabWidget::VGradientTarget VGradientTabWidget::target() +{ + return (VGradientTarget)m_gradientTarget->currentItem(); +} // VGradientTabWidget::target + +void VGradientTabWidget::setTarget( VGradientTarget target ) +{ + m_gradientTarget->setCurrentItem( target ); +} // VGradientTabWidget::setTarget + +void VGradientTabWidget::combosChange( int ) +{ + m_gradient.setType( (VGradient::VGradientType)m_gradientType->currentItem() ); + m_gradient.setRepeatMethod( (VGradient::VGradientRepeatMethod)m_gradientRepeat->currentItem() ); + + m_gradientPreview->update(); +} // VGradientTabWidget::combosChange + +void VGradientTabWidget::opacityChanged( int value ) +{ + m_gradOpacity = value / 100.0; + m_gradientPreview->update(); +} + +void VGradientTabWidget::addGradientToPredefs() +{ + VGradientListItem* item = m_resourceServer->addGradient( new VGradient( m_gradient ) ); + m_predefGradientsView->insertItem( item ); +} // VGradientTabWidget::addGradientToPredefs() + +void VGradientTabWidget::predefSelected( QListBoxItem* item ) +{ + if( item ) + { + VGradientListItem* gradientItem = (VGradientListItem*)item; + m_predefDelete->setEnabled( gradientItem->canDelete() ); + } +} // VGradientTabWidget::predefSelected + +void VGradientTabWidget::changeToPredef( QListBoxItem* item ) +{ + if( item ) + { + VGradientListItem* gradientItem = (VGradientListItem*)item; + m_gradient = *gradientItem->gradient(); + m_gradientType->setCurrentItem( m_gradient.type() ); + m_gradientRepeat->setCurrentItem( m_gradient.repeatMethod() ); + m_opacity->setValue( 100 ); + m_gradientPreview->update(); + m_gradientWidget->update(); + showPage( m_editGroup ); + } +} // VGradientTabWidget::changeToPredef + +void VGradientTabWidget::deletePredef() +{ + int i = m_predefGradientsView->currentItem(); + if( !m_predefGradientsView->item( i ) ) + return; + m_resourceServer->removeGradient( (VGradientListItem*)m_predefGradientsView->item( i ) ); + m_predefGradientsView->removeItem( i ); +} // VGradientTabWidget::deletePredef + +#include "vgradienttabwidget.moc" + diff --git a/karbon/widgets/vgradienttabwidget.h b/karbon/widgets/vgradienttabwidget.h new file mode 100644 index 00000000..2c60cee3 --- /dev/null +++ b/karbon/widgets/vgradienttabwidget.h @@ -0,0 +1,131 @@ +/* This file is part of the KDE project + Copyright (C) 2001, The Karbon Developers + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef _VGRADIENTTABWIDGET_H_ +#define _VGRADIENTTABWIDGET_H_ + +#include <qwidget.h> +#include <qtabwidget.h> +#include <qlistbox.h> +#include <koffice_export.h> +#include "vgradient.h" + +class KComboBox; +class VGradientWidget; +class KListBox; +class KIntNumInput; +class QPushButton; +class QGroupBox; +class KarbonResourceServer; + + +class VGradientListItem : public QListBoxItem +{ +public: + VGradientListItem( const VGradient& gradient, QString filename ); + VGradientListItem( const VGradientListItem& ); + ~VGradientListItem(); + + QPixmap& pixmap() { return m_pixmap; } + const VGradient* gradient() const { return m_gradient; } + QString filename() { return m_filename; } + bool canDelete() { return m_delete; } + + virtual int height( const QListBox* ) const { return 16; } + virtual int width( const QListBox* lb ) const; + +protected: + virtual void paint( QPainter* p ); + +private: + VGradient *m_gradient; + QPixmap m_pixmap; + QString m_filename; + bool m_delete; +}; // VGradientListItem + +class VGradientPreview : public QWidget +{ + public: + VGradientPreview( VGradient& gradient, double& opacity, QWidget* parent = 0L, const char* name = 0L ); + ~VGradientPreview(); + + virtual void paintEvent( QPaintEvent* ); + + protected: + VGradient* m_gradient; + double* m_opacity; +}; // VGradientPreview + +class KARBONBASE_EXPORT VGradientTabWidget : public QTabWidget +{ + Q_OBJECT + + public: + enum VGradientTarget { + STROKE, + FILL + }; + + VGradientTabWidget( VGradient& gradient, KarbonResourceServer* server, QWidget* parent = 0L, const char* name = 0L ); + ~VGradientTabWidget(); + + const VGradient& gradient(); + void setGradient( VGradient& gradient ); + + VGradientTarget target(); + void setTarget( VGradientTarget target ); + + double opacity() const; + void setOpacity( double opacity ); + + public slots: + void combosChange( int ); + void addGradientToPredefs(); + void changeToPredef( QListBoxItem* ); + void predefSelected( QListBoxItem* ); + void deletePredef(); + void opacityChanged( int ); + + protected: + void setupUI(); + void initUI(); + void setupConnections(); + + private: + QGroupBox *m_editGroup; + VGradientWidget *m_gradientWidget; + KComboBox *m_gradientTarget; + KComboBox *m_gradientRepeat; + KComboBox *m_gradientType; + VGradientPreview *m_gradientPreview; + KListBox *m_predefGradientsView; + QPushButton *m_predefDelete; + QPushButton *m_predefImport; + QPushButton *m_addToPredefs; + KIntNumInput *m_opacity; + + VGradient m_gradient; + /** The predefined gradients list. */ + KarbonResourceServer* m_resourceServer; + double m_gradOpacity; +}; // VGradientTabWidget + +#endif /* _VGRADIENTTABWIDGET_H_ */ diff --git a/karbon/widgets/vgradientwidget.cc b/karbon/widgets/vgradientwidget.cc new file mode 100644 index 00000000..25e29cd7 --- /dev/null +++ b/karbon/widgets/vgradientwidget.cc @@ -0,0 +1,309 @@ +/* This file is part of the KDE project + Copyright (C) 2001, The Karbon Developers + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include <qlabel.h> +#include <qframe.h> +#include <qbitmap.h> + +#include <kcolorbutton.h> +#include <kcombobox.h> +#include <klocale.h> +#include <qpainter.h> +#include <kiconloader.h> + +#include "vgradientwidget.h" +#include "vcolordlg.h" +#include "vfill.h" +#include "vkopainter.h" +#include "vcursor.h" + +#define midPoint_width 7 +#define midPoint_height 10 +static unsigned char midPoint_bits[] = { + 0x08, 0x08, 0x1c, 0x1c, 0x2a, 0x2a, 0x08, 0x08, 0x08, 0x08 +}; + +#define colorStopBorder_width 11 +#define colorStopBorder_height 11 +static unsigned char colorStopBorder_bits[] = { + 0x20, 0x00, 0x50, 0x00, 0x50, 0x00, 0x88, 0x00, 0x88, 0x00, 0x04, 0x01, + 0x04, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x04, 0xff, 0x07 +}; + +#define colorStop_width 9 +#define colorStop_height 10 +static unsigned char colorStop_bits[] = { + 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x38, 0x00, 0x38, 0x00, 0x7c, 0x00, + 0x7c, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xff, 0x01 +}; + +VGradientWidget::VGradientWidget( VGradient& gradient, QWidget* parent, const char* name ) + : QWidget( parent, name ), m_gradient( &gradient ) +{ + setBackgroundMode( Qt::NoBackground ); + setMinimumSize( 105, 35 ); +} // VGradientWidget::VGradientWidget + +VGradientWidget::~VGradientWidget() +{ +} // VGradientWidget::~VGradientWidget + +void VGradientWidget::paintColorStop( QPainter& p, int x, VColor& color ) +{ + QBitmap bitmap; + + bitmap = QBitmap( colorStop_width, colorStop_height, colorStop_bits, true ); + bitmap.setMask( bitmap ); + p.setPen( color ); + p.drawPixmap( x - 4, 1, bitmap ); + + bitmap = QBitmap( colorStopBorder_width, colorStopBorder_height, colorStopBorder_bits, true ); + bitmap.setMask( bitmap ); + p.setPen( Qt::black ); + p.drawPixmap( x - 5, 1, bitmap ); +} // VGradientWidget::paintColorStop + +void VGradientWidget::paintMidPoint( QPainter& p, int x ) +{ + QBitmap bitmap( midPoint_width, midPoint_height, midPoint_bits, true ); + bitmap.setMask( bitmap ); + p.setPen( Qt::black ); + p.drawPixmap( x - 3, 1, bitmap ); +} // VGradientWidget::paintMidPoint + +void VGradientWidget::paintEvent( QPaintEvent* ) +{ + int w = width() - 4; // available width for gradient and points + int h = height() - 7; // available height for gradient and points + int ph = colorStopBorder_height + 2; // point marker height + int gh = h - ph; // gradient area height + + QPixmap pixmap( width(), height() ); + VKoPainter gp( &pixmap, width(), height() ); + gp.setRasterOp( Qt::XorROP ); + VGradient gradient( *m_gradient ); + gradient.setType( VGradient::linear ); + gradient.setOrigin( KoPoint( 2, 2 ) ); + gradient.setFocalPoint( KoPoint( 2, 2 ) ); + gradient.setVector( KoPoint( 2 + w, 2 ) ); + VFill fill; + KIconLoader il; + fill.pattern() = VPattern( il.iconPath( "karbon.png", KIcon::Small ) ); + fill.setType( VFill::patt ); + gp.setBrush( fill ); + gp.drawRect( KoRect( 2, 2, w, gh ) ); + fill.gradient() = gradient; + fill.setType( VFill::grad ); + gp.setBrush( fill ); + gp.drawRect( KoRect( 2, 2, w, gh ) ); + gp.end(); + + QPainter p( &pixmap ); + + p.setPen( colorGroup().light() ); + // light frame around widget + p.moveTo( 1, height() - 1 ); + p.lineTo( 1, 1 ); + p.lineTo( width() - 1, 1 ); + p.lineTo( width() - 1, height() - 1 ); + p.lineTo( 1, height() - 1 ); + + // light line between gradient and point area + p.moveTo( 1, 3 + gh ); + p.lineTo( width() - 1, 3 + gh ); + + p.setPen( colorGroup().dark() ); + // left-top frame around widget + p.moveTo( 0, height() - 1 ); + p.lineTo( 0, 0 ); + p.lineTo( width() - 1, 0 ); + + // right-bottom from around gradient + p.moveTo( width() - 2, 2 ); + p.lineTo( width() - 2, 2 + gh ); + p.lineTo( 2, 2 + gh ); + + // upper line around point area + p.moveTo( 1, height() - 3 - ph ); + p.lineTo( width() - 1, height() - 3 - ph ); + + // right-bottom line around point area + p.moveTo( width() - 2, height() - ph - 1 ); + p.lineTo( width() - 2, height() - 2 ); + p.lineTo( 2, height() - 2 ); + + m_pntArea.setRect( 2, height() - ph - 2, w, ph ); + // clear point area + p.fillRect( m_pntArea.x(), m_pntArea.y(), m_pntArea.width(), m_pntArea.height(), colorGroup().background() ); + + p.setClipRect( m_pntArea.x(), m_pntArea.y(), m_pntArea.width(), m_pntArea.height() ); + p.translate( m_pntArea.x(), m_pntArea.y() ); + + QPtrList<VColorStop>& colorStops = m_gradient->m_colorStops; + if( colorStops.count() > 1 ) + { + VColorStop* stop, *nextstop; + for( stop = colorStops.first(), nextstop = colorStops.next(); + nextstop; stop = nextstop, nextstop = colorStops.next() ) + { + paintColorStop( p, (int)( stop->rampPoint * m_pntArea.width() ), stop->color ); + paintMidPoint( p, (int)(( stop->rampPoint + ( nextstop->rampPoint - stop->rampPoint ) * stop->midPoint ) * m_pntArea.width() ) ); + } + paintColorStop( p, int( stop->rampPoint * w ), stop->color ); + } + p.end(); + bitBlt( this, 0, 0, &pixmap, 0, 0, width(), height() ); +} // VGradientWidget::paintEvent + +void VGradientWidget::mousePressEvent( QMouseEvent* e ) +{ + if( ! m_pntArea.contains( e->x(), e->y() ) ) + return; + + QPtrList<VColorStop>& colorStops = m_gradient->m_colorStops; + + currentPoint = 0; + + int x = e->x() - m_pntArea.left(); + + int i = colorStops.count() - 1; + VColorStop *stop, *nextstop = 0; + for( stop = colorStops.last(); i >= 0; i--, stop = colorStops.prev() ) + { + int r = int( stop->rampPoint * m_pntArea.width() ); + if( nextstop ) + { + int m = int( ( stop->rampPoint + ( nextstop->rampPoint - stop->rampPoint ) * stop->midPoint ) * m_pntArea.width() ); + if( ( x > m - 5 ) && ( x < m + 5 ) ) + { + // found mid point at position + currentPoint = 2 * i + 2; + if( e->button() == Qt::LeftButton ) + setCursor( VCursor::horzMove() ); + return; + } + } + if( ( x > r - 5 ) && ( x < r + 5 ) ) + { + // found ramp point at position + currentPoint = 2 * i + 1; + if( e->button() == Qt::LeftButton ) + setCursor( VCursor::horzMove() ); + return; + } + + nextstop = stop; + } +} // VGradientWidget::mousePressEvent + +void VGradientWidget::mouseReleaseEvent( QMouseEvent* e ) +{ + if( e->button() == Qt::RightButton && currentPoint ) + { + if( m_pntArea.contains( e->x(), e->y() ) && ( currentPoint % 2 == 1 ) ) + { + int x = e->x() - m_pntArea.left(); + // check if we are still above the actual ramp point + int r = int( m_gradient->m_colorStops.at( int(0.5 * currentPoint) )->rampPoint * m_pntArea.width() ); + if( ( x > r - 5 ) && ( x < r + 5 ) ) + { + m_gradient->m_colorStops.remove( int(0.5 * currentPoint) ); + update(); + emit changed(); + } + } + } + setCursor( QCursor( Qt::ArrowCursor ) ); +} // VGradientWidget::mouseReleaseEvent + +void VGradientWidget::mouseDoubleClickEvent( QMouseEvent* e ) +{ + if( ! m_pntArea.contains( e->x(), e->y() ) ) + return; + + if( e->button() != Qt::LeftButton ) + return; + + if( currentPoint % 2 == 1 ) + { + // ramp point hit -> change color + VColorDlg* d = new VColorDlg( m_gradient->m_colorStops.at( currentPoint / 2 )->color, this->topLevelWidget() ); + if( d->exec() == QDialog::Accepted ) + { + m_gradient->m_colorStops.at( currentPoint / 2 )->color = d->Color(); + update(); + emit changed(); + } + delete d; + } + else if( currentPoint == 0 ) + { + // now point hit -> create new color stop + VColorDlg* d = new VColorDlg( m_gradient->m_colorStops.at( 0 )->color, this->topLevelWidget() ); + if( d->exec() == QDialog::Accepted ) + { + m_gradient->addStop( d->Color(), (float)( e->x() - 2 ) / ( m_pntArea.width() ), 0.5 ); + update(); + emit changed(); + } + delete d; + } +} // VGradientWidget::mouseDoubleClickEvent + +void VGradientWidget::mouseMoveEvent( QMouseEvent* e ) +{ + if( e->state() & Qt::RightButton ) + return; + + QPtrList<VColorStop>& colorStops = m_gradient->m_colorStops; + + if( currentPoint >= colorStops.count() * 2 ) + return; + + int x = e->x() - m_pntArea.left(); + + if( currentPoint % 2 == 1 ) + { + // move ramp point + int actRP = int( 0.5 * ( currentPoint - 1 ) ); + int prevRP = actRP - 1; + int nextRP = int( 0.5 * ( currentPoint + 1 ) ); + // Clip the color stop between to others. + x = kMin( x, ( actRP < int( colorStops.count() - 1 ) ) ? int( colorStops.at( nextRP )->rampPoint * m_pntArea.width() ) : m_pntArea.width() ); + x = kMax( x, ( actRP > 0 ) ? int( colorStops.at( prevRP )->rampPoint * m_pntArea.width() ) : 0 ); + colorStops.at( actRP )->rampPoint = (float)( x ) / m_pntArea.width(); + update(); + emit changed(); + } + else if( currentPoint > 0 ) + { + // move mid point + int prevRP = int( 0.5 * ( currentPoint - 1 ) ); + int nextRP = int( 0.5 * ( currentPoint + 1 ) ); + // Clip the mid point between to ramp points. + x = kMin( x, int( colorStops.at( nextRP )->rampPoint * m_pntArea.width() ) ); + x = kMax( x, int( colorStops.at( prevRP )->rampPoint * m_pntArea.width() ) ); + colorStops.at( prevRP )->midPoint = ( (float)( x ) / m_pntArea.width() - ( colorStops.at( prevRP )->rampPoint ) ) / ( colorStops.at( nextRP )->rampPoint - colorStops.at( prevRP )->rampPoint ); + update(); + emit changed(); + } +} // VGradientWidget::mouseMoveEvent + +#include "vgradientwidget.moc" diff --git a/karbon/widgets/vgradientwidget.h b/karbon/widgets/vgradientwidget.h new file mode 100644 index 00000000..76f7472d --- /dev/null +++ b/karbon/widgets/vgradientwidget.h @@ -0,0 +1,60 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef _VGRADIENTWIDGET_H_ +#define _VGRADIENTWIDGET_H_ + +#include <qwidget.h> +#include <koffice_export.h> +class VGradient; +class QPainter; +class VColor; + +class KARBONBASE_EXPORT VGradientWidget : public QWidget +{ + Q_OBJECT + +public: + VGradientWidget( VGradient& gradient, QWidget* parent = 0L, const char* name = 0L ); + ~VGradientWidget(); + + virtual void paintEvent( QPaintEvent* ); + +signals: + void changed(); + +protected: + /** mouse events... For color stops manipulation */ + void mousePressEvent( QMouseEvent* ); + void mouseReleaseEvent( QMouseEvent* ); + void mouseDoubleClickEvent( QMouseEvent* ); + void mouseMoveEvent( QMouseEvent* ); + + void paintColorStop( QPainter& p, int x, VColor& color ); + void paintMidPoint( QPainter& p, int x ); + + /** The gradient to modify. */ + VGradient* m_gradient; + /** The point to modify. */ + unsigned int currentPoint; + + QRect m_pntArea; +}; // VGradientWidget + +#endif /* _VGRADIENTWIDGET_H_ */ diff --git a/karbon/widgets/vreference.cc b/karbon/widgets/vreference.cc new file mode 100644 index 00000000..43b0e8b2 --- /dev/null +++ b/karbon/widgets/vreference.cc @@ -0,0 +1,74 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* vreference.cc */ + +#include <qbuttongroup.h> +#include <qlayout.h> +#include <qradiobutton.h> + +#include "vreference.h" + +VReference::VReference( QWidget *parent, const char *name ) : QFrame ( parent, name ) +{ + QVBoxLayout* layout = new QVBoxLayout( this ); + mButtonGroup = new QButtonGroup (3, Vertical, this ); + QRadioButton* radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, TopLeft ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Left ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, BottomLeft ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Top ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Center ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Bottom ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, TopRight ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Right ); + radio = new QRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, BottomRight ); + + connect( + mButtonGroup, SIGNAL( clicked( int ) ), + this, SLOT( setReferencePoint( int ) ) ); + + mButtonGroup->setButton( Center ); + layout->addWidget( mButtonGroup ); + layout->activate(); + setReferencePoint( Center ); +} + +void VReference::setReferencePoint ( int i ) +{ + m_referencePoint = i; + emit referencePointChanged( m_referencePoint ); +} + +int VReference::referencePoint() +{ + return( m_referencePoint ); +} + +#include "vreference.moc" + diff --git a/karbon/widgets/vreference.h b/karbon/widgets/vreference.h new file mode 100644 index 00000000..3c6c1a9f --- /dev/null +++ b/karbon/widgets/vreference.h @@ -0,0 +1,61 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* This is the color slider widget that is used to select color or color components */ + +/* vreference.h */ +#ifndef VREFERENCE_H +#define VREFERENCE_H + +#include <qframe.h> + +class QButtonGroup; + +enum Choice +{ + TopLeft, + Left, + BottomLeft, + Top, + Center, + Bottom, + TopRight, + Right, + BottomRight +}; + +class VReference : public QFrame +{ + Q_OBJECT +public: + VReference( QWidget *parent = 0L, const char *name = 0L ); + int referencePoint(); +public slots: + virtual void setReferencePoint ( int ); + +private: + int m_referencePoint; + QButtonGroup* mButtonGroup; +signals: + void referencePointChanged( int referencePoint ); +}; + +#endif + diff --git a/karbon/widgets/vruler.cc b/karbon/widgets/vruler.cc new file mode 100644 index 00000000..0f7c2f62 --- /dev/null +++ b/karbon/widgets/vruler.cc @@ -0,0 +1,332 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * Copyright (C) 2002 Patrick Julien <freak@codepimps.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include <qpainter.h> + +#include "kdebug.h" + +#include "vruler.h" + +#define MARKER_WIDTH 1 +#define MARKER_HEIGHT 20 +#define RULER_SIZE 20 + +const char *VRuler::m_nums[] = { + "70 7 2 1", + " c Black", + "X c None", + "XX XXXXXX XXXX XXXX XXXXXX XXX XXXX XXX XXX XXXX XX", + "X XXX XXXX XXX XXX XX XXX XXXX XXX XXXXXXX XXXXXXXXX XX XXX XX XXX X", + "X XXX XXXXX XXXXXXX XXXXXX XXX X XXX XXXXXX XXXXXXXXX XXX XXX XX XXX X", + "X XXX XXXXX XXXXX XXXXX XXX XX XXX XXX XXXXXX XXXX XXXX X", + "X XXX XXXXX XXXX XXXXXXXXX XX XXXXXX XX XXX XXXX XXXX XXX XXXXXX X", + "X XXX XXXXX XXX XXXXXX XXX XXXXX XXXXXXX XX XXX XXXX XXXX XXX XXXXX XX", + "XX XXXXXX XXX XXX XXXXXX XXX XXXX XXXXX XXXXX XXXX XXX" +}; + +VRuler::VRuler(Qt::Orientation o, QWidget *parent, const char *name) : super(parent, name, WRepaintNoErase | WResizeNoErase), m_pixmapNums(m_nums) +{ + setBackgroundMode(NoBackground); + setFrameStyle(Box | Sunken); + setLineWidth(1); + setMidLineWidth(0); + m_orientation = o; + m_unit = KoUnit::U_PT; + m_zoom = 1.0; + m_firstVisible = 0; + m_pixmapBuffer = 0; + m_currentPosition = -1; + + if (m_orientation == Qt::Horizontal) { + setFixedHeight(RULER_SIZE); + initMarker(MARKER_WIDTH, MARKER_HEIGHT); + } else { + setFixedWidth(RULER_SIZE); + initMarker(MARKER_HEIGHT, MARKER_WIDTH); + } +} + +VRuler::~VRuler() +{ + delete m_pixmapBuffer; +} + +void VRuler::initMarker(Q_INT32 w, Q_INT32 h) +{ + QPainter p; + + m_pixmapMarker.resize(w, h); + p.begin(&m_pixmapMarker); + p.setPen(blue); + p.eraseRect(0, 0, w, h); + p.drawLine(0, 0, w - 1, h - 1); + p.end(); +} + +void VRuler::recalculateSize() +{ + Q_INT32 w; + Q_INT32 h; + + if (m_pixmapBuffer) { + delete m_pixmapBuffer; + m_pixmapBuffer = 0; + } + + if (m_orientation == Qt::Horizontal) { + w = width(); + h = RULER_SIZE; + } else { + w = RULER_SIZE; + h = height(); + } + + m_pixmapBuffer = new QPixmap(w, h); + Q_CHECK_PTR(m_pixmapBuffer); + + drawRuler(); + updatePointer(m_currentPosition, m_currentPosition); +} + +KoUnit::Unit VRuler::unit() const +{ + return m_unit; +} + +void VRuler::setUnit(KoUnit::Unit u) +{ + m_unit = u; + drawRuler(); + updatePointer(m_currentPosition, m_currentPosition); + repaint(); +} + +void VRuler::setZoom(double zoom) +{ + m_zoom = zoom; + recalculateSize(); + drawRuler(); + updatePointer(m_currentPosition, m_currentPosition); + repaint(); +} + +void VRuler::updatePointer(Q_INT32 x, Q_INT32 y) +{ + if (m_pixmapBuffer) { + if (m_orientation == Qt::Horizontal) { + if (m_currentPosition != -1) + repaint(m_currentPosition, 1, MARKER_WIDTH, MARKER_HEIGHT); + + if (x != -1) { + bitBlt(this, x, 1, &m_pixmapMarker, 0, 0, MARKER_WIDTH, MARKER_HEIGHT); + m_currentPosition = x; + } + } else { + if (m_currentPosition != -1) + repaint(1, m_currentPosition, MARKER_HEIGHT, MARKER_WIDTH); + + if (y != -1) { + bitBlt(this, 1, y, &m_pixmapMarker, 0, 0, MARKER_HEIGHT, MARKER_WIDTH); + m_currentPosition = y; + } + } + } +} + +void VRuler::updateVisibleArea(Q_INT32 xpos, Q_INT32 ypos) +{ + if (m_orientation == Qt::Horizontal) + m_firstVisible = xpos; + else + m_firstVisible = ypos; + + //kdDebug() << "--###-- VRuler::updateVisibleArea(" << xpos << ", " << ypos << ")" << endl; + drawRuler(); + repaint(); + updatePointer(m_currentPosition, m_currentPosition); + //kdDebug() << "--###-- VRuler::updatePointer(" << m_currentPosition << ", " << m_currentPosition << ")" << endl; +} + +void VRuler::paintEvent(QPaintEvent *e) +{ + if (m_pixmapBuffer) { + const QRect& rect = e -> rect(); + + bitBlt(this, rect.topLeft(), m_pixmapBuffer, rect); + super::paintEvent(e); + } +} + +void VRuler::drawRuler() +{ + QPainter p; + QString buf; + Q_INT32 st1 = 0; + Q_INT32 st2 = 0; + Q_INT32 st3 = 0; + Q_INT32 st4 = 0; + Q_INT32 stt = 0; + + if (!m_pixmapBuffer) + return; + + p.begin(m_pixmapBuffer); + p.setPen(QColor(0x70, 0x70, 0x70)); + p.setBackgroundColor(colorGroup().background()); + p.eraseRect(0, 0, m_pixmapBuffer -> width(), m_pixmapBuffer -> height()); + + switch (m_unit) { + case KoUnit::U_PT: + case KoUnit::U_MM: + case KoUnit::U_DD: + case KoUnit::U_CC: + st1 = 1; + st2 = 5; + st3 = 10; + st4 = 25; + stt = 100; + break; + case KoUnit::U_CM: + case KoUnit::U_PI: + case KoUnit::U_INCH: + st1 = 1; + st2 = 2; + st3 = 5; + st4 = 10; + stt = 1; + break; + default: + break; + } + + Q_INT32 pos = 0; + bool s1 = KoUnit::fromUserValue(st1, m_unit) * m_zoom > 3.0; + bool s2 = KoUnit::fromUserValue(st2, m_unit) * m_zoom > 3.0; + bool s3 = KoUnit::fromUserValue(st3, m_unit) * m_zoom > 3.0; + bool s4 = KoUnit::fromUserValue(st4, m_unit) * m_zoom > 3.0; + + if (m_orientation == Qt::Horizontal) { + // XXX: This was 7 * 4 -- why? what was the idea about having 30 point intervals? + float cx = KoUnit::fromUserValue(100, m_unit) / m_zoom; + Q_INT32 step = qRound(cx);//((Q_INT32)(cx / (float)stt) + 1) * stt; + Q_INT32 start = (Q_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom); + + do { + pos = (Q_INT32)(KoUnit::fromUserValue(start, m_unit) * m_zoom - m_firstVisible); + + if (!s3 && s4 && start % st4 == 0) + p.drawLine(pos, RULER_SIZE - 9, pos, RULER_SIZE); + + if (s3 && start % st3 == 0) + p.drawLine(pos, RULER_SIZE - 9, pos, RULER_SIZE); + + if (s2 && start % st2 == 0) + p.drawLine(pos, RULER_SIZE - 7, pos, RULER_SIZE); + + if (s1 && start % st1 == 0) + p.drawLine(pos, RULER_SIZE - 5, pos, RULER_SIZE); + + if (step && start % step == 0) { + buf.setNum(QABS(start)); + drawNums(&p, pos, 4, buf, true); + } + + start++; + } while (pos < m_pixmapBuffer -> width()); + } else { + m_firstVisible = 0; + float cx = KoUnit::fromUserValue(100, m_unit) / m_zoom; + Q_INT32 height = m_pixmapBuffer -> height() - 1; + Q_INT32 step = qRound(cx); + Q_INT32 start = (Q_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom); + + do { + pos = height - (Q_INT32)(KoUnit::fromUserValue(start, m_unit) * m_zoom - m_firstVisible); + + if (!s3 && s4 && start % st4 == 0) + p.drawLine(RULER_SIZE - 9, pos, RULER_SIZE, pos); + + if (s3 && start % st3 == 0) + p.drawLine(RULER_SIZE - 9, pos, RULER_SIZE, pos); + + if (s2 && start % st2 == 0) + p.drawLine(RULER_SIZE - 7, pos, RULER_SIZE, pos); + + if (s1 && start % st1 == 0) + p.drawLine(RULER_SIZE - 5, pos, RULER_SIZE, pos); + + if (step && start % step == 0) { + buf.setNum(QABS(start)); + drawNums(&p, 4, pos, buf, false); + } + + start++; + } while (pos > 0); + } + + p.end(); +} + +void VRuler::resizeEvent(QResizeEvent *) +{ + recalculateSize(); +} + +void VRuler::show() +{ + if (m_orientation == Qt::Horizontal) { + setFixedHeight(RULER_SIZE); + initMarker(MARKER_WIDTH, MARKER_HEIGHT); + } else { + setFixedWidth(RULER_SIZE); + initMarker(MARKER_HEIGHT, MARKER_WIDTH); + } + + super::show(); +} + +void VRuler::hide() +{ + if (m_orientation == Qt::Horizontal) + setFixedHeight(1); + else + setFixedWidth(1); +} + +void VRuler::drawNums(QPainter *p, Q_INT32 x, Q_INT32 y, QString& num, bool orientationHoriz) +{ + if (orientationHoriz) + x -= 7; + else + y -= 8; + + for (Q_UINT32 k = 0; k < num.length(); k++) { + Q_INT32 st = num.at(k).digitValue() * 7; + + p -> drawPixmap(x, y, m_pixmapNums, st, 0, 7, 7); + + if (orientationHoriz) + x += 7; + else + y += 8; + } +} + +#include "vruler.moc" + diff --git a/karbon/widgets/vruler.h b/karbon/widgets/vruler.h new file mode 100644 index 00000000..c03de9a2 --- /dev/null +++ b/karbon/widgets/vruler.h @@ -0,0 +1,77 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * Copyright (C) 2002 Patrick Julien <freak@codepimps.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef VRULER_H_ +#define VRULER_H_ + +#include <qframe.h> +#include <qpixmap.h> +#include <KoUnit.h> + +// XXX: Make this look more like the KOffice ruler -- the KOffice +// ruler is not quite suited to Krita. Also: start units with 0, +// print every 100 units. + +class QPainter; + +class VRuler : public QFrame { + Q_OBJECT + typedef QFrame super; + +public: + VRuler(Qt::Orientation, QWidget *parent = 0, const char *name = 0); + virtual ~VRuler(); + +public: + KoUnit::Unit unit() const; + +public slots: + void setZoom(double zoom); + void updatePointer(Q_INT32 x, Q_INT32 y); + void updateVisibleArea(Q_INT32 xpos, Q_INT32 ypos); + void setUnit(KoUnit::Unit u); + void hide(); + void show(); + +public: + virtual void paintEvent(QPaintEvent *e); + virtual void resizeEvent(QResizeEvent *e); + +protected: + void recalculateSize(); + void drawRuler(); + void initMarker(Q_INT32 w, Q_INT32 h); + void drawNums(QPainter *gc, Q_INT32 x, Q_INT32 y, QString& num, bool orientationHoriz); + +private: + KoUnit::Unit m_unit; + Qt::Orientation m_orientation; + Q_INT32 m_firstVisible; + Q_INT32 m_currentPosition; + QPixmap *m_pixmapBuffer; + QPixmap m_pixmapMarker; + QPixmap m_pixmapNums; + double m_zoom; + +private: + static const char *m_nums[]; +}; + +#endif // VRULER_H_ + diff --git a/karbon/widgets/vselecttoolbar.cc b/karbon/widgets/vselecttoolbar.cc new file mode 100644 index 00000000..a39650d8 --- /dev/null +++ b/karbon/widgets/vselecttoolbar.cc @@ -0,0 +1,124 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* vselecttoolbar.cc */ + +#include <qlabel.h> + +#include <klocale.h> +#include <kdebug.h> + +#include "KoUnitWidgets.h" +#include "vselecttoolbar.h" +#include "karbon_view.h" +#include "karbon_part.h" +#include "vselection.h" +#include "vtransformcmd.h" +#include <KoRect.h> + +VSelectToolBar::VSelectToolBar( KarbonView *view, const char* name ) : KToolBar( view, name ), m_view( view ) +{ + setCaption( i18n( "Object Properties" ) ); + QLabel *x_label = new QLabel( i18n( "X:" ), this, "kde toolbar widget" ); + insertWidget( 0, x_label->width(), x_label ); + m_x = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_x, SIGNAL( valueChanged( double ) ), this, SLOT( slotXChanged( double ) ) ); + insertWidget( 1, m_x->width(), m_x ); + QLabel *y_label = new QLabel( i18n( "Y:" ), this, "kde toolbar widget" ); + insertWidget( 2, y_label->width(), y_label ); + m_y = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_y, SIGNAL( valueChanged( double ) ), this, SLOT( slotYChanged( double ) ) ); + insertWidget( 3, m_y->width(), m_y ); + + insertSeparator( 4 ); + QLabel *w_label = new QLabel( i18n( "selection width", "Width:" ), this, "kde toolbar widget" ); + insertWidget( 5, w_label->width(), w_label ); + m_width = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_width, SIGNAL( valueChanged( double ) ), this, SLOT( slotWidthChanged( double ) ) ); + insertWidget( 6, m_width->width(), m_width ); + QLabel *h_label = new QLabel( i18n( "Height:" ), this, "kde toolbar widget" ); + insertWidget( 7, h_label->width(), h_label ); + m_height = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_height, SIGNAL( valueChanged( double ) ), this, SLOT( slotHeightChanged( double ) ) ); + insertWidget( 8, m_height->width(), m_height ); + + connect( m_view, SIGNAL( selectionChange() ), this, SLOT( slotSelectionChanged() ) ); +} + +VSelectToolBar::~VSelectToolBar() +{ +} + +void +VSelectToolBar::slotXChanged( double newval ) +{ + double dx = newval - m_view->part()->document().selection()->boundingBox().topLeft().x(); + m_view->part()->addCommand( new VTranslateCmd( &m_view->part()->document(), dx, 0.0 ), true ); +} + +void +VSelectToolBar::slotYChanged( double newval ) +{ + double dy = newval - m_view->part()->document().selection()->boundingBox().topLeft().y(); + m_view->part()->addCommand( new VTranslateCmd( &m_view->part()->document(), 0.0, dy ), true ); +} + +void +VSelectToolBar::slotWidthChanged( double newval ) +{ + if( newval != 0.0 ) + { + double sx = newval / m_view->part()->document().selection()->boundingBox().width(); + KoPoint sp = m_view->part()->document().selection()->boundingBox().topLeft(); + m_view->part()->addCommand( new VScaleCmd( &m_view->part()->document(), sp, sx, 1.0 ), true ); + } +} + +void +VSelectToolBar::slotHeightChanged( double newval ) +{ + if( newval != 0.0 ) + { + double sy = newval / m_view->part()->document().selection()->boundingBox().height(); + KoPoint sp = m_view->part()->document().selection()->boundingBox().bottomLeft(); + m_view->part()->addCommand( new VScaleCmd( &m_view->part()->document(), sp, 1.0, sy ), true ); + } +} + +void +VSelectToolBar::slotSelectionChanged() +{ + m_x->blockSignals( true ); + m_y->blockSignals( true ); + m_width->blockSignals( true ); + m_height->blockSignals( true ); + KoRect rect = m_view->part()->document().selection()->boundingBox(); + m_x->setValue( rect.topLeft().x() ); + m_y->setValue( rect.topLeft().y() ); + m_width->setValue( rect.width() ); + m_height->setValue( rect.height() ); + m_x->blockSignals( false ); + m_y->blockSignals( false ); + m_width->blockSignals( false ); + m_height->blockSignals( false ); +} + +#include "vselecttoolbar.moc" + diff --git a/karbon/widgets/vselecttoolbar.h b/karbon/widgets/vselecttoolbar.h new file mode 100644 index 00000000..376ca134 --- /dev/null +++ b/karbon/widgets/vselecttoolbar.h @@ -0,0 +1,53 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* vselecttoolbar.h */ +#ifndef VSELECTTOOLBAR_H +#define VSELECTTOOLBAR_H + +#include <ktoolbar.h> + +class KoUnitDoubleSpinBox; +class KarbonView; + +class VSelectToolBar : public KToolBar +{ + Q_OBJECT +public: + VSelectToolBar( KarbonView *view, const char* name = 0L ); + ~VSelectToolBar(); + +public slots: + void slotSelectionChanged(); + void slotXChanged( double ); + void slotYChanged( double ); + void slotWidthChanged( double ); + void slotHeightChanged( double ); + +private: + KoUnitDoubleSpinBox *m_x; + KoUnitDoubleSpinBox *m_y; + KoUnitDoubleSpinBox *m_width; + KoUnitDoubleSpinBox *m_height; + KarbonView *m_view; +}; + +#endif + diff --git a/karbon/widgets/vsmallpreview.cc b/karbon/widgets/vsmallpreview.cc new file mode 100644 index 00000000..7766f6e9 --- /dev/null +++ b/karbon/widgets/vsmallpreview.cc @@ -0,0 +1,282 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.t-com.hr) + Copyright (C) 2005, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* vsmallpreview.cc */ +#include <qcolor.h> +#include <qframe.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpixmap.h> + +#include <klocale.h> +#include <KoPoint.h> + +#include "vcolor.h" +#include "vfill.h" +#include "vgradient.h" +#include "vkopainter.h" +#include "vpattern.h" +#include "vstroke.h" + +#include "vsmallpreview.h" + +#define FRAMEWIDTH 40 + +VSmallPreview::VSmallPreview( QWidget* parent, const char* name ) + : QWidget( parent, name ) +{ + /* Create widget layout */ + QHBoxLayout *layout = new QHBoxLayout( this, 4 ); + m_strokeLabel = new QLabel( i18n( "Stroke: None" ), this ); + layout->addWidget( m_strokeLabel ); + m_strokeFrame = new QFrame( this ); + m_strokeFrame->setFixedWidth ( FRAMEWIDTH ); + m_strokeFrame->setFrameStyle( QFrame::GroupBoxPanel | QFrame::Plain ); + layout->addWidget( m_strokeFrame ); + m_fillLabel = new QLabel( i18n( "Fill: None" ), this ); + layout->addWidget( m_fillLabel ); + m_fillFrame = new QFrame( this ); + m_fillFrame->setFixedWidth ( FRAMEWIDTH ); + m_fillFrame->setFrameStyle( QFrame::GroupBoxPanel | QFrame::Plain ); + layout->addWidget( m_fillFrame ); + layout->activate(); + + m_fill = VFill(); + m_stroke = VStroke(); +} + +VSmallPreview::~VSmallPreview() +{ +} + +void +VSmallPreview::update( const VStroke &s, const VFill &f ) +{ + if( &f ) + m_fill = f; + else + m_fill = VFill(); + if( &s ) + m_stroke = s; + else + m_stroke = VStroke(); + + drawStroke( m_stroke ); + drawFill( m_fill ); +} + +void +VSmallPreview::paintEvent( QPaintEvent* /*event*/ ) +{ + drawStroke( m_stroke ); + drawFill( m_fill ); +} + +void +VSmallPreview::drawFill( const VFill &f ) +{ + VFill fill; + VStroke stroke; + + QPixmap m_pixmap; + m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() ); + VKoPainter* m_painter = new VKoPainter( &m_pixmap, m_fillFrame->width(), m_fillFrame->height() ); + + m_painter->begin(); + m_painter->setPen( Qt::NoPen ); + fill.setColor( Qt::white ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) ); + + switch ( f.type() ) + { + case VFill::solid: + { + switch ( f.color().colorSpace() ) + { + case VColor::rgb: + m_fillLabel->setText( i18n( "Fill: RGB") ); break; + case VColor::cmyk: + m_fillLabel->setText( i18n( "Fill: CMYK") ); break; + case VColor::hsb: + m_fillLabel->setText( i18n( "Fill: HSB") ); break; + case VColor::gray: + m_fillLabel->setText( i18n( "Fill: Grayscale") ); break; + default: + m_fillLabel->setText( i18n( "Fill: Color") ); + } + fill.setColor( f.color() ); + break; + } + case VFill::grad: + { + fill.gradient() = f.gradient(); + fill.setType( VFill::grad ); + m_fillLabel->setText( i18n( "Fill: Gradient") ); + if( f.gradient().type() == VGradient::linear ) + { + fill.gradient().setOrigin( KoPoint( m_fillFrame->width() * 0.5, 0 ) ); + fill.gradient().setVector( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() ) ); + } + else if( f.gradient().type() == VGradient::radial || + f.gradient().type() == VGradient::conic ) + { + fill.gradient().setOrigin( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() * 0.5 ) ); + fill.gradient().setFocalPoint( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() * 0.5 ) ); + fill.gradient().setVector( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() ) ); + } + break; + + } + case VFill::patt: + { + fill.pattern() = f.pattern(); + fill.pattern().setOrigin( KoPoint( 0, 0 ) ); + fill.pattern().setVector( KoPoint( m_fillFrame->width() * 0.5, 0 ) ); + fill.setType( VFill::patt ); + m_fillLabel->setText( i18n( "Fill: Pattern") ); + break; + } + default: //None or unknown + { + m_fillLabel->setText( i18n( "Fill: None") ); + fill.setColor( Qt::white ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) ); + stroke.setColor( Qt::red ); + stroke.setLineWidth( 2.0 ); + m_painter->setPen( stroke ); + m_painter->newPath(); + m_painter->moveTo( KoPoint( 4, m_fillFrame->height() - 4 ) ); + m_painter->lineTo( KoPoint( m_fillFrame->width() - 4, 4 ) ); + m_painter->strokePath(); + } + } + + if( f.type() != VFill::none ) + { + m_painter->setPen( stroke ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) ); + } + + m_painter->end(); + + 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 ); + + delete ( m_painter ); +} + +void +VSmallPreview::drawStroke( const VStroke &s ) +{ + VFill fill; + VStroke stroke; + + QPixmap m_pixmap; + m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() ); + VKoPainter* m_painter = new VKoPainter( &m_pixmap, m_fillFrame->width(), m_fillFrame->height() ); + + m_painter->begin(); + m_painter->setPen( Qt::NoPen ); + fill.setColor( Qt::white ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) ); + + switch ( s.type() ) + { + case VStroke::solid: + { + switch ( s.color().colorSpace() ) + { + case VColor::rgb: + m_strokeLabel->setText( i18n( "Stroke: RGB") ); break; + case VColor::cmyk: + m_strokeLabel->setText( i18n( "Stroke: CMYK") ); break; + case VColor::hsb: + m_strokeLabel->setText( i18n( "Stroke: HSB") ); break; + case VColor::gray: + m_strokeLabel->setText( i18n( "Stroke: Grayscale") ); break; + default: + m_strokeLabel->setText( i18n( "Stroke: Color") ); + } + fill.setColor( s.color() ); + break; + } + case VStroke::grad: + { + fill.gradient() = s.gradient(); + fill.setType( VFill::grad ); + m_strokeLabel->setText( i18n( "Stroke: Gradient") ); + if( s.gradient().type() == VGradient::linear ) + { + fill.gradient().setOrigin( KoPoint( m_strokeFrame->width() * 0.5, 0 ) ); + fill.gradient().setVector( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() ) ); + } + else if( s.gradient().type() == VGradient::radial || + s.gradient().type() == VGradient::conic ) + { + fill.gradient().setOrigin( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() * 0.5 ) ); + fill.gradient().setFocalPoint( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() * 0.5 ) ); + fill.gradient().setVector( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() ) ); + } + break; + } + case VStroke::patt: + { + fill.pattern() = s.pattern(); + fill.pattern().setOrigin( KoPoint( 0, 0 ) ); + fill.pattern().setVector( KoPoint( m_strokeFrame->width() * 0.5, 0 ) ); + fill.setType( VFill::patt ); + m_strokeLabel->setText( i18n( "Stroke: Pattern") ); + break; + } + default: //None or unknown + { + m_strokeLabel->setText( i18n( "Stroke: None") ); + fill.setColor( Qt::white ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) ); + stroke.setColor( Qt::red ); + stroke.setLineWidth( 2.0 ); + m_painter->setPen( stroke ); + m_painter->newPath(); + m_painter->moveTo( KoPoint( 4, m_strokeFrame->height() - 4 ) ); + m_painter->lineTo( KoPoint( m_strokeFrame->width() - 4, 4 ) ); + m_painter->strokePath(); + } + } + + if( s.type() != VStroke::none ) + { + m_painter->setPen( stroke ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) ); + } + + m_painter->end(); + + 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 ); + + delete ( m_painter ); +} + +#include "vsmallpreview.moc" + diff --git a/karbon/widgets/vsmallpreview.h b/karbon/widgets/vsmallpreview.h new file mode 100644 index 00000000..7b1abb15 --- /dev/null +++ b/karbon/widgets/vsmallpreview.h @@ -0,0 +1,58 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.t-com.hr) + Copyright (C) 2005, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* This is a small widget used on the statusbar, to display fill/stroke colors etc. */ + +/* vsmallpreview.h */ +#ifndef VSMALLPREVIEW_H +#define VSMALLPREVIEW_H + +#include <qwidget.h> + +class QFrame; +class QLabel; +class VFill; +class VStroke; + +class VSmallPreview : public QWidget +{ + Q_OBJECT +public: + VSmallPreview( QWidget* parent = 0L, const char* name = 0L ); + ~VSmallPreview(); + + void update( const VStroke &, const VFill & ); + +protected: + virtual void paintEvent( QPaintEvent* event ); + +private: + void drawFill( const VFill & ); + void drawStroke( const VStroke & ); + QFrame *m_fillFrame; + QFrame *m_strokeFrame; + QLabel *m_fillLabel; + QLabel *m_strokeLabel; + VFill m_fill; + VStroke m_stroke; +}; + +#endif + diff --git a/karbon/widgets/vstatebutton.cc b/karbon/widgets/vstatebutton.cc new file mode 100644 index 00000000..635d3de7 --- /dev/null +++ b/karbon/widgets/vstatebutton.cc @@ -0,0 +1,49 @@ +/* This file is part of the KDE project + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "vstatebutton.h" + +VStateButton::VStateButton( QWidget* parent, const char* name ) + : QPushButton( parent, name ) +{ + m_index = 0; + m_pixmaps.setAutoDelete( true ); +} + +VStateButton::~VStateButton() +{ +} + +void +VStateButton::mouseReleaseEvent( QMouseEvent *e ) +{ + QPushButton::mouseReleaseEvent( e ); + if( m_pixmaps.count() > 0 ) + { + m_index = ++m_index % m_pixmaps.count(); + setPixmap( *( m_pixmaps.at( m_index ) ) ); + } +} + +void +VStateButton::setState( unsigned int /*index*/ ) +{ + if( m_pixmaps.count() > 0 ) + setPixmap( *( m_pixmaps.at( m_index ) ) ); +} diff --git a/karbon/widgets/vstatebutton.h b/karbon/widgets/vstatebutton.h new file mode 100644 index 00000000..6273adcc --- /dev/null +++ b/karbon/widgets/vstatebutton.h @@ -0,0 +1,45 @@ +/* This file is part of the KDE project + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef __VSTATEBUTTON_H__ +#define __VSTATEBUTTON_H__ + +#include <qpushbutton.h> +#include <qpixmap.h> +#include <qptrlist.h> + +class VStateButton : public QPushButton +{ +public: + VStateButton( QWidget* parent = 0L, const char* name = 0L ); + ~VStateButton(); + + void addState( QPixmap *state ) { m_pixmaps.append( state ); } + void setState( unsigned int index ); + unsigned int getState() const { return m_index; } + +private: + void mouseReleaseEvent( QMouseEvent * ); + + QPtrList<QPixmap> m_pixmaps; + unsigned int m_index; +}; + +#endif + diff --git a/karbon/widgets/vstrokefillpreview.cc b/karbon/widgets/vstrokefillpreview.cc new file mode 100644 index 00000000..40dbe4d6 --- /dev/null +++ b/karbon/widgets/vstrokefillpreview.cc @@ -0,0 +1,451 @@ +/* This file is part of the KDE project + Copyright (C) 2002 - 2005, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include <qcolor.h> + +#include <kdebug.h> +#include <KoPoint.h> + +#include "karbon_part.h" +#include "vcolordlg.h" +#include "vfill.h" +#include "vfillcmd.h" +#include "vkopainter.h" +#include "vselection.h" +#include "vstroke.h" +#include "vstrokecmd.h" +#include "vstrokefillpreview.h" + +#define PANEL_SIZEX 50.0 +#define PANEL_SIZEY 50.0 + +#define FILL_TOPX 15.0 +#define FILL_TOPY 15.0 +#define FILL_BOTTOMX 45.0 +#define FILL_BOTTOMY 45.0 + +#define STROKE_TOPX 5.0 +#define STROKE_TOPY 5.0 +#define STROKE_BOTTOMX 35.0 +#define STROKE_BOTTOMY 35.0 + +#define STROKE_TOPX_INNER STROKE_TOPX + 4 +#define STROKE_TOPY_INNER STROKE_TOPY + 4 +#define STROKE_BOTTOMX_INNER STROKE_BOTTOMX - 4 +#define STROKE_BOTTOMY_INNER STROKE_BOTTOMY - 4 + + +VStrokeFillPreview::VStrokeFillPreview( + KarbonPart *part, QWidget* parent, const char* name ) + : QFrame( parent, name ), m_part( part ) +{ + m_strokeWidget = false; + setFocusPolicy( QWidget::NoFocus ); + +#if QT_VERSION < 0x030100 + setFrameStyle( QFrame::Panel | QFrame::Sunken ); +#else + setFrameStyle( QFrame::GroupBoxPanel | QFrame::Sunken ); +#endif + + installEventFilter( this ); + m_pixmap.resize( int( PANEL_SIZEX ), int( PANEL_SIZEY ) ); + m_painter = new VKoPainter( &m_pixmap, uint( PANEL_SIZEX ), uint( PANEL_SIZEY ) ); +} + +VStrokeFillPreview::~VStrokeFillPreview() +{ + delete( m_painter ); +} + +void +VStrokeFillPreview::paintEvent( QPaintEvent* event ) +{ + bitBlt( this, + (int)( width() - PANEL_SIZEX ) / 2, (int)( height() - PANEL_SIZEY ) / 2, + &m_pixmap, + 0, 0, (int)PANEL_SIZEX, (int)PANEL_SIZEY ); + + QFrame::paintEvent( event ); +} + +bool +VStrokeFillPreview::eventFilter( QObject *, QEvent *event ) +{ + QMouseEvent* e = static_cast<QMouseEvent *>( event ); + + int ex = e->x() - int( ( width() - PANEL_SIZEX ) / 2 ); + int ey = e->y() - int( ( height() - PANEL_SIZEY ) / 2 ); + + if( event && event->type() == QEvent::MouseButtonPress ) + { + if ( m_strokeWidget ) + { + if( + ex >= STROKE_TOPX && ex <= STROKE_BOTTOMX && + ey >= STROKE_TOPY && ey <= STROKE_BOTTOMY ) + { + m_strokeWidget = true; + emit strokeSelected(); + } + else if( + ex >= FILL_TOPX && ex <= FILL_BOTTOMX && + ey >= FILL_TOPY && ey <= FILL_BOTTOMY ) + { + m_strokeWidget = false; + emit fillSelected(); + } + } + else + { + if( + ex >= FILL_TOPX && ex <= FILL_BOTTOMX && + ey >= FILL_TOPY && ey <= FILL_BOTTOMY ) + { + m_strokeWidget = false; + emit fillSelected(); + } + else if( + ex >= STROKE_TOPX && ex <= STROKE_BOTTOMX && + ey >= STROKE_TOPY && ey <= STROKE_BOTTOMY ) + { + m_strokeWidget = true; + emit strokeSelected(); + } + } + update( m_stroke, m_fill ); + } + + if( event && event->type() == QEvent::MouseButtonDblClick ) + { + if( + ex >= FILL_TOPX && ex <= FILL_BOTTOMX && + ey >= FILL_TOPY && ey <= FILL_BOTTOMY ) + { + VColorDlg* dialog = new VColorDlg( m_fill.color(), this ); + if( dialog->exec() == QDialog::Accepted ) + { + if( m_part && m_part->document().selection() ) m_part->addCommand( new VFillCmd( &m_part->document(), VFill( dialog->Color() ) ), true ); + } + delete dialog; + } + else if( + ex >= STROKE_TOPX && ex <= STROKE_BOTTOMX + && ey >= STROKE_TOPY && ey <= STROKE_BOTTOMY ) + { + VColorDlg* dialog = new VColorDlg( m_stroke.color(), this ); + if( dialog->exec() == QDialog::Accepted ) + { + if( m_part && m_part->document().selection() ) m_part->addCommand( new VStrokeCmd( &m_part->document(), dialog->Color() ), true ); + } + delete dialog; + } + } + return false; +} + +void +VStrokeFillPreview::update( const VStroke &s, const VFill &f ) +{ + m_painter->begin(); + + if( &f ) + m_fill = f; + else + m_fill = VFill(); + if( &s ) + m_stroke = s; + else + m_stroke = VStroke(); + + // draw checkerboard + VFill fill; + m_painter->setPen( Qt::NoPen ); + + for( unsigned char y = 0; y < PANEL_SIZEY; y += 10 ) + for( unsigned char x = 0; x < PANEL_SIZEX; x += 10 ) + { + fill.setColor( ( ( ( x + y ) % 20 ) == 0 ) ? QColor( 180, 180, 180 ) : QColor( 100, 100, 100 ) ); + m_painter->setBrush( fill ); + m_painter->drawRect( x, y, 10, 10 ); + } + + if ( m_strokeWidget ) + { + drawFill( m_fill ); + drawStroke( m_stroke ); + } + else + { + drawStroke( m_stroke ); + drawFill( m_fill ); + } + + m_painter->end(); + + repaint(); +} + +void +VStrokeFillPreview::drawFill( const VFill &f ) +{ + VStroke stroke; + + if( f.type() != VFill::none ) + { + if( f.type() != VFill::solid ) + { + VFill fill; + fill = f; + + if( f.type() == VFill::grad ) + { + if( f.gradient().type() == VGradient::linear ) + { + fill.gradient().setOrigin( KoPoint( 30, 20 ) ); + fill.gradient().setVector( KoPoint( 30, 50 ) ); + } + else if( f.gradient().type() == VGradient::radial || + f.gradient().type() == VGradient::conic ) + { + fill.gradient().setOrigin( KoPoint( 30, 35 ) ); + fill.gradient().setFocalPoint( KoPoint( 30, 35 ) ); + fill.gradient().setVector( KoPoint( 30, 50 ) ); + } + } + if( f.type() == VFill::patt ) + { + fill.pattern() = f.pattern(); + fill.pattern().setOrigin( KoPoint( 20, 10 ) ); + fill.pattern().setVector( KoPoint( 30, 10 ) ); + fill.setType( VFill::patt ); + } + + m_painter->setBrush( fill ); + } + else + m_painter->setBrush( f ); + m_painter->setPen( Qt::NoPen ); + m_painter->drawRect( KoRect( FILL_TOPX, FILL_TOPY, FILL_BOTTOMX - FILL_TOPX, FILL_BOTTOMY - FILL_TOPY ) ); + } + else + { + VFill fill; + fill.setColor( Qt::white ); + m_painter->setBrush( fill ); + m_painter->setPen( Qt::NoPen ); + + m_painter->drawRect( KoRect( FILL_TOPX, FILL_TOPY, + FILL_BOTTOMX - FILL_TOPX, + FILL_BOTTOMY - FILL_TOPY ) ); + } + + // show 3D outline of fill part + VColor color; + + m_painter->setBrush( Qt::NoBrush ); + color.set( 1.0, 1.0, 1.0 ); + stroke.setColor( color ); + m_painter->setPen( stroke ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( FILL_BOTTOMX, FILL_TOPY ) ); + m_painter->lineTo( KoPoint( FILL_TOPX, FILL_TOPY ) ); + m_painter->lineTo( KoPoint( FILL_TOPX, FILL_BOTTOMY ) ); + m_painter->strokePath(); + + color.set( 0.5, 0.5, 0.5 ); + stroke.setColor( color ); + m_painter->setPen( stroke ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( FILL_BOTTOMX, FILL_TOPY ) ); + m_painter->lineTo( KoPoint( FILL_BOTTOMX, FILL_BOTTOMY ) ); + m_painter->lineTo( KoPoint( FILL_TOPX, FILL_BOTTOMY ) ); + m_painter->strokePath(); + + if( f.type() == VFill::none ) + { + stroke.setColor( Qt::red ); + m_painter->setPen( stroke ); + m_painter->newPath(); + m_painter->moveTo( KoPoint( FILL_BOTTOMX, FILL_TOPY ) ); + m_painter->lineTo( KoPoint( FILL_TOPX, FILL_BOTTOMY ) ); + m_painter->strokePath(); + } +} + +void +VStrokeFillPreview::drawStroke( const VStroke &s ) +{ + VStroke stroke; + stroke.setLineWidth( 2.0 ); + + m_painter->setPen( Qt::NoPen ); + + if( s.type() != VStroke::none ) + { + VFill fill; + + if( s.type() != VStroke::solid ) + { + if( s.type() == VStroke::grad ) + { + fill.gradient() = s.gradient(); + + if( s.gradient().type() == VGradient::linear ) + { + fill.gradient().setOrigin( KoPoint( FILL_TOPX, 10 ) ); + fill.gradient().setVector( KoPoint( FILL_TOPX, 40 ) ); + } + else if( s.gradient().type() == VGradient::radial || + s.gradient().type() == VGradient::conic ) + { + fill.gradient().setOrigin( KoPoint( FILL_TOPX, 25 ) ); + fill.gradient().setFocalPoint( KoPoint( FILL_TOPX, 25 ) ); + fill.gradient().setVector( KoPoint( FILL_TOPX, 40 ) ); + } + + fill.setType( VFill::grad ); + } + if( s.type() == VStroke::patt ) + { + fill.pattern() = s.pattern(); + fill.pattern().setOrigin( KoPoint( FILL_TOPX, 10 ) ); + fill.pattern().setVector( KoPoint( FILL_TOPX, 40 ) ); + fill.setType( VFill::patt ); + } + } + else + fill.setColor( s.color() ); + + m_painter->setFillRule( evenOdd ); + + m_painter->setBrush( fill ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( STROKE_TOPX, STROKE_TOPY ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX, STROKE_TOPY ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX, STROKE_BOTTOMY ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX, STROKE_BOTTOMY ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX, STROKE_TOPY ) ); + + m_painter->moveTo( KoPoint( STROKE_TOPX_INNER, STROKE_TOPY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX_INNER, STROKE_TOPY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX_INNER, STROKE_BOTTOMY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX_INNER, STROKE_BOTTOMY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX_INNER, STROKE_TOPY_INNER ) ); + m_painter->fillPath(); + } + else + { + VFill fill; + m_painter->setFillRule( evenOdd ); + fill.setColor( Qt::white ); + + m_painter->setBrush( fill ); + m_painter->setPen( Qt::NoPen ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( STROKE_TOPX, STROKE_TOPY ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX, STROKE_TOPY ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX, STROKE_BOTTOMY ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX, STROKE_BOTTOMY ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX, STROKE_TOPY ) ); + + m_painter->moveTo( KoPoint( STROKE_TOPX_INNER, STROKE_TOPY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX_INNER, STROKE_TOPY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX_INNER, STROKE_BOTTOMY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX_INNER, STROKE_BOTTOMY_INNER ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX_INNER, STROKE_TOPY_INNER ) ); + m_painter->fillPath(); + } + + // show 3D outline of stroke part + VColor color; + + color.set( 1.0, 1.0, 1.0 ); + stroke.setColor( color ); + m_painter->setBrush( Qt::NoBrush ); + m_painter->setPen( stroke ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( STROKE_BOTTOMX + 1, STROKE_TOPY - 1 ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX - 1, STROKE_TOPY - 1 ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX - 1, STROKE_BOTTOMY + 1 ) ); + m_painter->strokePath(); + + color.set( 0.5, 0.5, 0.5 ); + stroke.setColor( color ); + m_painter->setPen( stroke ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( STROKE_BOTTOMX + 1, STROKE_TOPY - 1 ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX + 1, STROKE_BOTTOMY + 1 ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX - 1, STROKE_BOTTOMY + 1 ) ); + m_painter->strokePath(); + + //stroke.setColor( Qt::black.rgb() ); + //m_painter->setPen( stroke ); + m_painter->newPath(); + m_painter->moveTo( KoPoint( STROKE_BOTTOMX_INNER - 1, STROKE_TOPY_INNER + 1 ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX_INNER + 1, STROKE_TOPY_INNER + 1 ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX_INNER + 1, STROKE_BOTTOMY_INNER - 1 ) ); + m_painter->strokePath(); + + color.set( 1.0, 1.0, 1.0 ); + stroke.setColor( color ); + m_painter->setPen( stroke ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( STROKE_BOTTOMX_INNER - 1, STROKE_TOPY_INNER + 1 ) ); + m_painter->lineTo( KoPoint( STROKE_BOTTOMX_INNER - 1, STROKE_BOTTOMY_INNER - 1 ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX_INNER + 1, STROKE_BOTTOMY_INNER - 1 ) ); + m_painter->strokePath(); + + if( s.type() == VStroke::none ) + { + stroke.setColor( Qt::red ); + m_painter->setPen( stroke ); + + m_painter->newPath(); + m_painter->moveTo( KoPoint( STROKE_BOTTOMX, STROKE_TOPY ) ); + m_painter->lineTo( KoPoint( STROKE_TOPX, STROKE_BOTTOMY ) ); + m_painter->strokePath(); + } +} + +void +VStrokeFillPreview::setFillSelected() +{ + m_strokeWidget = false; + update( m_stroke, m_fill ); + emit fillSelected(); +} + +void +VStrokeFillPreview::setStrokeSelected() +{ + m_strokeWidget = true; + update( m_stroke, m_fill ); + emit strokeSelected(); +} + +#include "vstrokefillpreview.moc" + diff --git a/karbon/widgets/vstrokefillpreview.h b/karbon/widgets/vstrokefillpreview.h new file mode 100644 index 00000000..20b0acbd --- /dev/null +++ b/karbon/widgets/vstrokefillpreview.h @@ -0,0 +1,74 @@ +/* This file is part of the KDE project + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef __VSTROKEFILLPREVIEW_H__ +#define __VSTROKEFILLPREVIEW_H__ + +#include <qframe.h> +#include <qpixmap.h> + +class VKoPainter; +class VFill; +class VStroke; +class KarbonPart; + +class VStrokeFillPreview : public QFrame +{ + Q_OBJECT + +public: + VStrokeFillPreview( KarbonPart *part, QWidget* parent = 0L, const char* name = 0L ); + ~VStrokeFillPreview(); + + virtual QSize sizeHint() const + { return QSize( 50, 50 ); } + virtual QSize minimumSizeHint() const + { return QSize( 20, 20 ); } + virtual QSizePolicy sizePolicy() const + { return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); } + + void update( const VStroke &, const VFill & ); + + virtual bool eventFilter( QObject* object, QEvent* event ); + + bool strokeIsSelected() const { return m_strokeWidget; } + void setFillSelected(); + void setStrokeSelected(); +signals: + void strokeChanged( const VStroke & ); + void fillChanged( const VFill& ); + void fillSelected(); + void strokeSelected(); + +protected: + virtual void paintEvent( QPaintEvent* event ); + +private: + VKoPainter* m_painter; + void drawFill( const VFill & ); + void drawStroke( const VStroke & ); + QPixmap m_pixmap; + KarbonPart *m_part; + bool m_strokeWidget; + VFill m_fill; + VStroke m_stroke; +}; + +#endif + diff --git a/karbon/widgets/vtoolbox.cc b/karbon/widgets/vtoolbox.cc new file mode 100644 index 00000000..6146ae93 --- /dev/null +++ b/karbon/widgets/vtoolbox.cc @@ -0,0 +1,42 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "vtoolbox.h" +#include "vtool.h" + +VToolBox::VToolBox( KMainWindow *mainWin, const char* name, KInstance* instance ) : KoToolBox( mainWin, name, instance, 5 ) +{ +} + +void +VToolBox::registerTool( VTool *tool ) +{ + kdDebug(38000) << "VToolBox::registerTool : " << tool->name() << endl; + KoToolBox::registerTool( tool->action(), tool->toolType(), tool->priority() ); +} + +void +VToolBox::setupTools() +{ + kdDebug(38000) << k_funcinfo << endl; + KoToolBox::setupTools(); +} + +#include "vtoolbox.moc" diff --git a/karbon/widgets/vtoolbox.h b/karbon/widgets/vtoolbox.h new file mode 100644 index 00000000..28c53f97 --- /dev/null +++ b/karbon/widgets/vtoolbox.h @@ -0,0 +1,44 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef __VTOOLBOX_H__ +#define __VTOOLBOX_H__ +#include <KoToolBox.h> +class VTool; + +/// This class... + +class VToolBox : public KoToolBox +{ + Q_OBJECT + +public: + VToolBox( KMainWindow *mainWin, const char* name, KInstance* instance ); + virtual ~VToolBox() {} + + void registerTool( VTool * ); + void setupTools(); + +signals: + void activeToolChanged( VTool * ); +}; + +#endif + diff --git a/karbon/widgets/vtranslate.cc b/karbon/widgets/vtranslate.cc new file mode 100644 index 00000000..1eaf81ed --- /dev/null +++ b/karbon/widgets/vtranslate.cc @@ -0,0 +1,84 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include <qcheckbox.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qstring.h> +#include <klocale.h> +#include <knuminput.h> +#include <kstdguiitem.h> +#include <kpushbutton.h> + +#include "vtranslate.h" + +VTranslate::VTranslate( QWidget* parent, const char* name ) + : QWidget( parent, name ) +{ + setCaption( i18n( "Translate" ) ); + + QVBoxLayout *mainlayout = new QVBoxLayout(this, 7); + mainlayout->addSpacing(5); + + QGridLayout *inputlayout = new QGridLayout(this, 5, 3); + mainlayout->addLayout(inputlayout); + m_labelX = new QLabel(i18n("X:"), this); + inputlayout->addWidget(m_labelX, 0, 0); + labely = new QLabel(i18n("Y:"), this); + inputlayout->addWidget(labely, 1, 0); + inputlayout->addColSpacing(1, 1); + inputlayout->addColSpacing(3, 5); + m_inputX = new KDoubleNumInput( this ); + m_inputX->setRange(-10000.00, 10000.00, 1.00, false); //range is just for example - for now :-) + inputlayout->addWidget(m_inputX, 0, 2); + m_inputY = new KDoubleNumInput( this ); + m_inputY->setRange(-10000.00, 10000.00, 1.00, false); + inputlayout->addWidget(m_inputY, 1, 2); + m_labelUnit1 = new QLabel("", this); + inputlayout->addWidget(m_labelUnit1, 0, 4); + m_labelUnit2 = new QLabel("", this); + inputlayout->addWidget(m_labelUnit2, 1, 4); + mainlayout->addSpacing(5); + m_checkBoxPosition = new QCheckBox(i18n("Relative &position"), this); + mainlayout->addWidget(m_checkBoxPosition); + mainlayout->addSpacing(5); + m_buttonDuplicate = new QPushButton(i18n("&Duplicate"), this); + mainlayout->addWidget(m_buttonDuplicate); + mainlayout->addSpacing(1); + m_buttonApply = new KPushButton(KStdGuiItem::apply(), this); + mainlayout->addWidget(m_buttonApply); + + mainlayout->activate(); + + setFixedSize(baseSize()); //Set the size tp fixed values +} + +VTranslate::~VTranslate() +{ +} + +void VTranslate::setUnits( const QString& units ) +{ + m_labelUnit1->setText( units ); + m_labelUnit2->setText( units ); +} + +#include "vtranslate.moc" + diff --git a/karbon/widgets/vtranslate.h b/karbon/widgets/vtranslate.h new file mode 100644 index 00000000..23fd1325 --- /dev/null +++ b/karbon/widgets/vtranslate.h @@ -0,0 +1,57 @@ +/* This file is part of the KDE project + Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) + Copyright (C) 2002, The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef __VTRANSLATE_H__ +#define __VTRANSLATE_H__ + +#include <qwidget.h> + +class QCheckBox; +class QLabel; +class QPushButton; +class QString; +class KDoubleNumInput; + +class VTranslate : public QWidget +{ + Q_OBJECT + +public: + VTranslate( QWidget* parent = 0L, const char* name = 0L ); + ~VTranslate(); + +public slots: + //sets the unit labels do display correct text (mm, cm, pixels etc): + void setUnits( const QString& units ); + +private: + QLabel* m_labelX; + KDoubleNumInput* m_inputX; //X coordinate + QLabel* labely; + KDoubleNumInput* m_inputY; //Y coordinate + QLabel* m_labelUnit1; + QLabel* m_labelUnit2; + QCheckBox* m_checkBoxPosition; //If checked, displays coordinates of selected object + QPushButton* m_buttonDuplicate; //duplicate (makes a copy of selected object(s) with a new position) + QPushButton* m_buttonApply; //apply new position +}; + +#endif + diff --git a/karbon/widgets/vtypebuttonbox.cc b/karbon/widgets/vtypebuttonbox.cc new file mode 100644 index 00000000..4a23d6dd --- /dev/null +++ b/karbon/widgets/vtypebuttonbox.cc @@ -0,0 +1,330 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#if 0 + +// 8x8 pixels + +static const char* const buttonnone[]={ +"8 8 7 1", +"c c #0a0000", +". c #0a0a0a", +"b c #330000", +"a c #331f1f", +"# c #333333", +"e c #ff0000", +"d c #ffffff", +".####abc", +"#ddddeeb", +"#dddeeea", +"#ddeeed#", +"#deeedd#", +"aeeeddd#", +"beedddd#", +"cba####."}; + +static const char* const buttonsolid[]={ +"8 8 1 1", +". c #000000", +"........", +"........", +"........", +"........", +"........", +"........", +"........", +"........"}; + +static const char* const buttongradient[]={ +"8 8 14 1", +"f c #000000", +"e c #040404", +". c #0a0a0a", +"d c #0f0f0f", +"c c #181818", +"b c #212121", +"a c #292929", +"# c #303030", +"g c #333333", +"l c #484848", +"k c #787878", +"j c #a7a7a7", +"i c #cdcdcd", +"h c #f1f1f1", +".#abcdef", +"ghijkl#f", +"ghijkl#f", +"ghijkl#f", +"ghijkl#f", +"ghijkl#f", +"ghijkl#f", +".#abcdef"}; + +static const char* const buttonpattern[]={ +"8 8 4 1", +". c #0a0a0a", +"# c #333333", +"a c #a0a0a0", +"b c #ffffff", +".######.", +"#aabbaa#", +"#aabbaa#", +"#bbaabb#", +"#bbaabb#", +"#aabbaa#", +"#aabbaa#", +".######."}; + +#else + +// 16x16 pixels + +static const char* const buttonnone[]={ +"16 16 7 1", +"c c #0a0000", +". c #0a0a0a", +"b c #330000", +"a c #331f1f", +"# c #333333", +"e c #ff0000", +"d c #ffffff", +"..########aabbcc", +"..########aabbcc", +"##dddddddddeeebb", +"##ddddddddeeeebb", +"##dddddddeeeeeaa", +"##ddddddeeeeedaa", +"##dddddeeeeedd##", +"##ddddeeeeeddd##", +"##dddeeeeedddd##", +"##ddeeeeeddddd##", +"aaeeeeeedddddd##", +"aaeeeeeddddddd##", +"bbeeeedddddddd##", +"bbeeeddddddddd##", +"ccbbaa########..", +"ccbbaa########.."}; + +static const char* const buttonsolid[]={ +"16 16 1 1", +". c #000000", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................", +"................"}; + + +// FIXME: Smoother gradient button. + +static const char* const buttongradient[]={ +"16 16 14 1", +"f c #000000", +"e c #040404", +". c #0a0a0a", +"d c #0f0f0f", +"c c #181818", +"b c #212121", +"a c #292929", +"# c #303030", +"g c #333333", +"l c #484848", +"k c #787878", +"j c #a7a7a7", +"i c #cdcdcd", +"h c #f1f1f1", +"..##aabbccddeeff", +"..##aabbccddeeff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"gghhiijjkkll##ff", +"..##aabbccddeeff", +"..##aabbccddeeff"}; + +static const char* const buttonpattern[]={ +"16 16 4 1", +". c #0a0a0a", +"# c #333333", +"a c #a0a0a0", +"b c #ffffffff", +"..############..", +"..############..", +"##aaaabbbbaaaa##", +"##aaaabbbbaaaa##", +"##aaaabbbbaaaa##", +"##aaaabbbbaaaa##", +"##bbbbaaaabbbb##", +"##bbbbaaaabbbb##", +"##bbbbaaaabbbb##", +"##bbbbaaaabbbb##", +"##aaaabbbbaaaa##", +"##aaaabbbbaaaa##", +"##aaaabbbbaaaa##", +"##aaaabbbbaaaa##", +"..############..", +"..############.."}; + +#endif + + +#include <qpixmap.h> +#include <qtoolbutton.h> +#include <qtooltip.h> + +#include <klocale.h> + +#include "karbon_part.h" +#include "vfillcmd.h" +#include "vselection.h" +#include "vstrokecmd.h" + +#include "vtypebuttonbox.h" + +VTypeButtonBox::VTypeButtonBox( KarbonPart *part, + QWidget* parent, const char* name ) + : QHButtonGroup( parent, name ), + m_part( part ), m_isStrokeManipulator( false ) +{ + setMaximumWidth( parent->width() - 2 ); + + // The button for no fill + QToolButton* button = new QToolButton( this ); + button->setPixmap( QPixmap( (const char **) buttonnone ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + QToolTip::add( button, i18n( "None" ) ); + insert( button, none ); + + // The button for solid fill + button = new QToolButton( this ); + button->setPixmap( QPixmap( (const char **) buttonsolid ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + QToolTip::add( button, i18n( "Solid" ) ); + insert( button, solid ); + + // The button for gradient fill + button = new QToolButton( this ); + button->setPixmap( QPixmap( (const char **) buttongradient ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + QToolTip::add( button, i18n( "Gradient" ) ); + insert( button, gradient ); + + // The button for pattern fill + button = new QToolButton( this ); + button->setPixmap( QPixmap( (const char **) buttonpattern ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + QToolTip::add( button, i18n( "Pattern" ) ); + insert( button, pattern ); + + setInsideMargin( 1 ); + setInsideSpacing( 1 ); + connect( this, SIGNAL( clicked( int ) ), + this, SLOT( slotButtonPressed( int ) ) ); +} + +void +VTypeButtonBox::slotButtonPressed( int id ) +{ + if( m_part && m_part->document().selection()->objects().count() > 0 ) { + if ( m_isStrokeManipulator ) + manipulateStrokes( id ); + else + manipulateFills( id ); + } +} + +void +VTypeButtonBox::setStroke() +{ + m_isStrokeManipulator = true; +} + +void +VTypeButtonBox::setFill() +{ + m_isStrokeManipulator = false; +} + +void +VTypeButtonBox::manipulateFills( int id ) +{ + VFill m_fill; + m_fill = *m_part->document().selection()->objects().getFirst()->fill(); + switch( id ){ + case none: + m_fill.setType( VFill::none ); + break; + case solid: + m_fill.setType( VFill::solid ); + break; + case gradient: + m_fill.setType( VFill::grad ); + break; + case pattern: + m_fill.setType( VFill::patt ); + } + m_part->addCommand( new VFillCmd( &m_part->document(), m_fill ), true ); +} + +void +VTypeButtonBox::manipulateStrokes( int id ) +{ + VStroke m_stroke; + m_stroke = *m_part->document().selection()->objects().getFirst()->stroke(); + switch( id ){ + case none: + m_stroke.setType( VStroke::none ); + break; + case solid: + m_stroke.setType( VStroke::solid ); + break; + case gradient: + m_stroke.setType( VStroke::grad ); + break; + case pattern: + m_stroke.setType( VStroke::patt ); + } + m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true ); +} + +#include "vtypebuttonbox.moc" + diff --git a/karbon/widgets/vtypebuttonbox.h b/karbon/widgets/vtypebuttonbox.h new file mode 100644 index 00000000..ab624c04 --- /dev/null +++ b/karbon/widgets/vtypebuttonbox.h @@ -0,0 +1,56 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 The Karbon Developers + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef __VTYPEBUTTONBOX_H__ +#define __VTYPEBUTTONBOX_H__ + +#include <qhbuttongroup.h> + +class KarbonPart; + +class VTypeButtonBox : public QHButtonGroup +{ + Q_OBJECT + +public: + enum buttonType { + none = 0, + solid = 1, + gradient = 2, + pattern = 3 + }; + + VTypeButtonBox( KarbonPart *part, QWidget* parent = 0L, const char* name = 0L ); + bool isStrokeManipulator() { return m_isStrokeManipulator; } + +public slots: + void slotButtonPressed( int id ); + void setFill(); + void setStroke(); + +private: + KarbonPart *m_part; + bool m_isStrokeManipulator; + + void manipulateFills( int id ); + void manipulateStrokes( int id ); +}; + +#endif + |