From 8b78a8791bc539bcffe7159f9d9714d577cb3d7d Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 23 May 2021 20:48:35 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- karbon/widgets/Makefile.am | 34 +-- karbon/widgets/vcanvas.cc | 380 ----------------------------- karbon/widgets/vcanvas.cpp | 380 +++++++++++++++++++++++++++++ karbon/widgets/vcolorslider.cc | 149 ------------ karbon/widgets/vcolorslider.cpp | 149 ++++++++++++ karbon/widgets/vgradienttabwidget.cc | 343 -------------------------- karbon/widgets/vgradienttabwidget.cpp | 343 ++++++++++++++++++++++++++ karbon/widgets/vgradientwidget.cc | 309 ----------------------- karbon/widgets/vgradientwidget.cpp | 309 +++++++++++++++++++++++ karbon/widgets/vreference.cc | 74 ------ karbon/widgets/vreference.cpp | 74 ++++++ karbon/widgets/vruler.cc | 332 ------------------------- karbon/widgets/vruler.cpp | 332 +++++++++++++++++++++++++ karbon/widgets/vselecttoolbar.cc | 124 ---------- karbon/widgets/vselecttoolbar.cpp | 124 ++++++++++ karbon/widgets/vsmallpreview.cc | 282 --------------------- karbon/widgets/vsmallpreview.cpp | 282 +++++++++++++++++++++ karbon/widgets/vstatebutton.cc | 49 ---- karbon/widgets/vstatebutton.cpp | 49 ++++ karbon/widgets/vstrokefillpreview.cc | 447 ---------------------------------- karbon/widgets/vstrokefillpreview.cpp | 447 ++++++++++++++++++++++++++++++++++ karbon/widgets/vtoolbox.cc | 42 ---- karbon/widgets/vtoolbox.cpp | 42 ++++ karbon/widgets/vtranslate.cc | 84 ------- karbon/widgets/vtranslate.cpp | 84 +++++++ karbon/widgets/vtypebuttonbox.cc | 330 ------------------------- karbon/widgets/vtypebuttonbox.cpp | 330 +++++++++++++++++++++++++ 27 files changed, 2962 insertions(+), 2962 deletions(-) delete mode 100644 karbon/widgets/vcanvas.cc create mode 100644 karbon/widgets/vcanvas.cpp delete mode 100644 karbon/widgets/vcolorslider.cc create mode 100644 karbon/widgets/vcolorslider.cpp delete mode 100644 karbon/widgets/vgradienttabwidget.cc create mode 100644 karbon/widgets/vgradienttabwidget.cpp delete mode 100644 karbon/widgets/vgradientwidget.cc create mode 100644 karbon/widgets/vgradientwidget.cpp delete mode 100644 karbon/widgets/vreference.cc create mode 100644 karbon/widgets/vreference.cpp delete mode 100644 karbon/widgets/vruler.cc create mode 100644 karbon/widgets/vruler.cpp delete mode 100644 karbon/widgets/vselecttoolbar.cc create mode 100644 karbon/widgets/vselecttoolbar.cpp delete mode 100644 karbon/widgets/vsmallpreview.cc create mode 100644 karbon/widgets/vsmallpreview.cpp delete mode 100644 karbon/widgets/vstatebutton.cc create mode 100644 karbon/widgets/vstatebutton.cpp delete mode 100644 karbon/widgets/vstrokefillpreview.cc create mode 100644 karbon/widgets/vstrokefillpreview.cpp delete mode 100644 karbon/widgets/vtoolbox.cc create mode 100644 karbon/widgets/vtoolbox.cpp delete mode 100644 karbon/widgets/vtranslate.cc create mode 100644 karbon/widgets/vtranslate.cpp delete mode 100644 karbon/widgets/vtypebuttonbox.cc create mode 100644 karbon/widgets/vtypebuttonbox.cpp (limited to 'karbon/widgets') diff --git a/karbon/widgets/Makefile.am b/karbon/widgets/Makefile.am index c78d166c..35828299 100644 --- a/karbon/widgets/Makefile.am +++ b/karbon/widgets/Makefile.am @@ -27,27 +27,27 @@ noinst_HEADERS = \ 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 + dummy.cpp \ + vcanvas.cpp \ + vcolorslider.cpp \ + vgradientwidget.cpp \ + vgradienttabwidget.cpp \ + vreference.cpp \ + vstrokefillpreview.cpp \ + vtranslate.cpp \ + vselecttoolbar.cpp \ + vsmallpreview.cpp \ + vstatebutton.cpp \ + vtoolbox.cpp \ + vtypebuttonbox.cpp \ + vruler.cpp libkarbonwidgets_la_METASOURCES = \ AUTO DISTCLEANFILES = \ - dummy.cc + dummy.cpp -dummy.cc: - echo > dummy.cc +dummy.cpp: + echo > dummy.cpp diff --git a/karbon/widgets/vcanvas.cc b/karbon/widgets/vcanvas.cc deleted file mode 100644 index d4cd6497..00000000 --- a/karbon/widgets/vcanvas.cc +++ /dev/null @@ -1,380 +0,0 @@ -/* 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 -#include -#include - -#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 -#include -#include - -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 = tqRound( p.x() / dxy.width() ); - int dy = tqRound( p.y() / dxy.height() ); - - float distx = TQMIN( TQABS( p.x() - dxy.width() * dx ), TQABS( p.x() - dxy.width() * ( dx + 1 ) ) ); - float disty = TQMIN( TQABS( p.y() - dxy.height() * dy ), TQABS( p.y() - dxy.height() * ( dy + 1 ) ) ); - - if( distx < dist.width() ) - { - if( TQABS(p.x() - dxy.width() * dx ) < TQABS( p.x() - dxy.width() * ( dx + 1 ) ) ) - p.rx() = dxy.width() * dx; - else - p.rx() = dxy.width() * ( dx + 1 ); - } - - if( disty < dist.height() ) - { - if( TQABS( p.y() - dxy.height() * dy ) < TQABS( p.y() - dxy.height() * ( dy + 1 ) ) ) - p.ry() = dxy.height() * dy; - else - p.ry() = dxy.height() * ( dy + 1 ); - } - - return p; -} - - -VCanvas::VCanvas( TQWidget *parent, KarbonView* view, KarbonPart* part ) - : TQScrollView( parent, "canvas", WStaticContents/*WNorthWestGravity*/ | WResizeNoErase | - WRepaintNoErase ), m_part( part ), m_view( view ) -{ - connect(this, TQT_SIGNAL( contentsMoving( int, int ) ), this, TQT_SLOT( slotContentsMoving( int, int ) ) ); - viewport()->setFocusPolicy( TQ_StrongFocus ); - - viewport()->setMouseTracking( true ); - setMouseTracking( true ); - - viewport()->setBackgroundColor( TQt::white ); - viewport()->setBackgroundMode( TQWidget::NoBackground ); - viewport()->installEventFilter( this ); - - resizeContents( 800, 600 ); - m_pixmap = new TQPixmap( 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 ); - TQCursor::setPos( mapToGlobal( TQPoint( int(p2.x()), int(p2.y()) ) ) ); -} - -bool -VCanvas::eventFilter( TQObject* object, TQEvent* event ) -{ - TQScrollView::eventFilter( object, event ); - - if( event->type() == TQEvent::AccelOverride || event->type() == TQEvent::Accel ) - return TQScrollView::eventFilter( object, event ); - - if( event->type() == TQEvent::KeyPress || event->type() == TQEvent::KeyRelease ) - return m_view->keyEvent( event ); - - TQMouseEvent* mouseEvent = dynamic_cast( 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( TQFocusEvent * ) -{ -} - -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 ) -{ - TQWMatrix 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( TQPaintEvent *e ) -{ - TQRect eventRect = e->rect(); - KoRect rect = KoRect::fromTQRect( eventRect ); - - setYMirroring( m_view->painterFactory()->editpainter() ); - viewport()->setUpdatesEnabled( false ); - VPainter *p = m_view->painterFactory()->painter(); - - // TODO : only update ROIs - p->begin(); - p->clear( rect, TQColor( 195, 194, 193 ) ); - p->setZoomFactor( m_view->zoom() ); - setYMirroring( p ); - - // TRICK : slightly adjust the matrix so libart AA looks better - TQWMatrix 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: - VTQPainter 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( TQPainter* painter, int clipx, int clipy, - int clipw, int cliph ) -{ - drawDocument( painter, KoRect( clipx, clipy, clipw, cliph ) ); -} - -void -VCanvas::drawDocument( TQPainter* /*painter*/, const KoRect&, bool drawVObjects ) -{ - setYMirroring( m_view->painterFactory()->editpainter() ); - - VPainter* p = m_view->painterFactory()->painter(); - if( drawVObjects ) - { - p->begin(); - p->clear( TQColor( 195, 194, 193 ) ); - p->setZoomFactor( m_view->zoom() ); - setYMirroring( p ); - // TRICK : slightly adjust the matrix so libart AA looks better - TQWMatrix 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: - VTQPainter 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( TQResizeEvent* event ) -{ - double centerX = double( contentsX() + 0.5 * visibleWidth() ) / double( contentsWidth() ); - double centerY = double( contentsY() + 0.5 * visibleHeight() ) / double( contentsHeight() ); - - TQScrollView::resizeEvent( event ); - if( !m_pixmap ) - m_pixmap = new TQPixmap( width(), height() ); - else - m_pixmap->resize( width(), height() ); - - VPainter *p = m_view->painterFactory()->painter(); - p->resize( width(), height() ); - p->clear( TQColor( 195, 194, 193 ) ); - setViewport( centerX, centerY ); -} - -void -VCanvas::slotContentsMoving( int /*x*/, int /*y*/ ) -{ - emit viewportChanged(); -} - -void -VCanvas::dragEnterEvent( TQDragEnterEvent *e ) -{ - e->accept( KarbonDrag::canDecode( e ) || KColorDrag::canDecode( e ) ); -} - -void -VCanvas::dropEvent( TQDropEvent *e ) -{ - m_view->dropEvent( e ); -} - -#include "vcanvas.moc" - diff --git a/karbon/widgets/vcanvas.cpp b/karbon/widgets/vcanvas.cpp new file mode 100644 index 00000000..d4cd6497 --- /dev/null +++ b/karbon/widgets/vcanvas.cpp @@ -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 +#include +#include + +#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 +#include +#include + +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 = tqRound( p.x() / dxy.width() ); + int dy = tqRound( p.y() / dxy.height() ); + + float distx = TQMIN( TQABS( p.x() - dxy.width() * dx ), TQABS( p.x() - dxy.width() * ( dx + 1 ) ) ); + float disty = TQMIN( TQABS( p.y() - dxy.height() * dy ), TQABS( p.y() - dxy.height() * ( dy + 1 ) ) ); + + if( distx < dist.width() ) + { + if( TQABS(p.x() - dxy.width() * dx ) < TQABS( p.x() - dxy.width() * ( dx + 1 ) ) ) + p.rx() = dxy.width() * dx; + else + p.rx() = dxy.width() * ( dx + 1 ); + } + + if( disty < dist.height() ) + { + if( TQABS( p.y() - dxy.height() * dy ) < TQABS( p.y() - dxy.height() * ( dy + 1 ) ) ) + p.ry() = dxy.height() * dy; + else + p.ry() = dxy.height() * ( dy + 1 ); + } + + return p; +} + + +VCanvas::VCanvas( TQWidget *parent, KarbonView* view, KarbonPart* part ) + : TQScrollView( parent, "canvas", WStaticContents/*WNorthWestGravity*/ | WResizeNoErase | + WRepaintNoErase ), m_part( part ), m_view( view ) +{ + connect(this, TQT_SIGNAL( contentsMoving( int, int ) ), this, TQT_SLOT( slotContentsMoving( int, int ) ) ); + viewport()->setFocusPolicy( TQ_StrongFocus ); + + viewport()->setMouseTracking( true ); + setMouseTracking( true ); + + viewport()->setBackgroundColor( TQt::white ); + viewport()->setBackgroundMode( TQWidget::NoBackground ); + viewport()->installEventFilter( this ); + + resizeContents( 800, 600 ); + m_pixmap = new TQPixmap( 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 ); + TQCursor::setPos( mapToGlobal( TQPoint( int(p2.x()), int(p2.y()) ) ) ); +} + +bool +VCanvas::eventFilter( TQObject* object, TQEvent* event ) +{ + TQScrollView::eventFilter( object, event ); + + if( event->type() == TQEvent::AccelOverride || event->type() == TQEvent::Accel ) + return TQScrollView::eventFilter( object, event ); + + if( event->type() == TQEvent::KeyPress || event->type() == TQEvent::KeyRelease ) + return m_view->keyEvent( event ); + + TQMouseEvent* mouseEvent = dynamic_cast( 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( TQFocusEvent * ) +{ +} + +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 ) +{ + TQWMatrix 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( TQPaintEvent *e ) +{ + TQRect eventRect = e->rect(); + KoRect rect = KoRect::fromTQRect( eventRect ); + + setYMirroring( m_view->painterFactory()->editpainter() ); + viewport()->setUpdatesEnabled( false ); + VPainter *p = m_view->painterFactory()->painter(); + + // TODO : only update ROIs + p->begin(); + p->clear( rect, TQColor( 195, 194, 193 ) ); + p->setZoomFactor( m_view->zoom() ); + setYMirroring( p ); + + // TRICK : slightly adjust the matrix so libart AA looks better + TQWMatrix 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: + VTQPainter 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( TQPainter* painter, int clipx, int clipy, + int clipw, int cliph ) +{ + drawDocument( painter, KoRect( clipx, clipy, clipw, cliph ) ); +} + +void +VCanvas::drawDocument( TQPainter* /*painter*/, const KoRect&, bool drawVObjects ) +{ + setYMirroring( m_view->painterFactory()->editpainter() ); + + VPainter* p = m_view->painterFactory()->painter(); + if( drawVObjects ) + { + p->begin(); + p->clear( TQColor( 195, 194, 193 ) ); + p->setZoomFactor( m_view->zoom() ); + setYMirroring( p ); + // TRICK : slightly adjust the matrix so libart AA looks better + TQWMatrix 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: + VTQPainter 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( TQResizeEvent* event ) +{ + double centerX = double( contentsX() + 0.5 * visibleWidth() ) / double( contentsWidth() ); + double centerY = double( contentsY() + 0.5 * visibleHeight() ) / double( contentsHeight() ); + + TQScrollView::resizeEvent( event ); + if( !m_pixmap ) + m_pixmap = new TQPixmap( width(), height() ); + else + m_pixmap->resize( width(), height() ); + + VPainter *p = m_view->painterFactory()->painter(); + p->resize( width(), height() ); + p->clear( TQColor( 195, 194, 193 ) ); + setViewport( centerX, centerY ); +} + +void +VCanvas::slotContentsMoving( int /*x*/, int /*y*/ ) +{ + emit viewportChanged(); +} + +void +VCanvas::dragEnterEvent( TQDragEnterEvent *e ) +{ + e->accept( KarbonDrag::canDecode( e ) || KColorDrag::canDecode( e ) ); +} + +void +VCanvas::dropEvent( TQDropEvent *e ) +{ + m_view->dropEvent( e ); +} + +#include "vcanvas.moc" + diff --git a/karbon/widgets/vcolorslider.cc b/karbon/widgets/vcolorslider.cc deleted file mode 100644 index 42c4f058..00000000 --- a/karbon/widgets/vcolorslider.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* 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 -#include -#include -#include - -#include "vcolorslider.h" - -VColorSlider::VColorSlider( TQWidget* parent, const char* name ) - : TQWidget( parent, name ) -{ - init(); -} - -// Label, left color, right color, min, max, value ... -VColorSlider::VColorSlider( const TQString& label, const TQColor& col1, - const TQColor& col2, int min, int max, int value, TQWidget* parent, const char* name ) - : TQWidget( parent, name ) -{ - init(); - setLabel( label ); - setColors( col1, col2 ); - setMinValue( min ); - setMaxValue( max ); - setValue( value ); -} - -VColorSlider::~VColorSlider() -{ -} - -void VColorSlider::init() -{ - m_isDragging = false; - TQHBoxLayout *layout = new TQHBoxLayout( this, 3 ); - - m_label = new TQLabel( this ); - m_gradientSelect = new KGradientSelector( Qt::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, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_spinBox( int ) ) ); - connect( m_gradientSelect, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_gradientSelect( int ) ) ); - - m_gradientSelect->installEventFilter( this ); - - layout->activate(); -} - -void VColorSlider::setLabel( const TQString& label ) -{ - m_label->setText( label ); -} - -void VColorSlider::setColors( const TQColor& color1, const TQColor& 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, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_gradientSelect( int ) ) ); - m_gradientSelect->setValue( (m_maxValue - value) + m_minValue ); - connect( m_gradientSelect, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_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, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_spinBox( int ) ) ); - m_spinBox->setValue( value ); - connect( m_spinBox, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_spinBox( int ) ) ); - emit valueChanged( value ); - } -} - -bool VColorSlider::eventFilter( TQObject *obj, TQEvent *ev ) -{ - if( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(m_gradientSelect) ) - { - if ( ev->type() == TQEvent::MouseButtonPress ) - m_isDragging = true; - else if( ev->type() == TQEvent::MouseButtonRelease ) - m_isDragging = false; - } - return FALSE; -} - -#include "vcolorslider.moc" - diff --git a/karbon/widgets/vcolorslider.cpp b/karbon/widgets/vcolorslider.cpp new file mode 100644 index 00000000..d2d0a0ab --- /dev/null +++ b/karbon/widgets/vcolorslider.cpp @@ -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.cpp */ + +#include +#include +#include +#include + +#include "vcolorslider.h" + +VColorSlider::VColorSlider( TQWidget* parent, const char* name ) + : TQWidget( parent, name ) +{ + init(); +} + +// Label, left color, right color, min, max, value ... +VColorSlider::VColorSlider( const TQString& label, const TQColor& col1, + const TQColor& col2, int min, int max, int value, TQWidget* parent, const char* name ) + : TQWidget( parent, name ) +{ + init(); + setLabel( label ); + setColors( col1, col2 ); + setMinValue( min ); + setMaxValue( max ); + setValue( value ); +} + +VColorSlider::~VColorSlider() +{ +} + +void VColorSlider::init() +{ + m_isDragging = false; + TQHBoxLayout *layout = new TQHBoxLayout( this, 3 ); + + m_label = new TQLabel( this ); + m_gradientSelect = new KGradientSelector( Qt::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, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_spinBox( int ) ) ); + connect( m_gradientSelect, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_gradientSelect( int ) ) ); + + m_gradientSelect->installEventFilter( this ); + + layout->activate(); +} + +void VColorSlider::setLabel( const TQString& label ) +{ + m_label->setText( label ); +} + +void VColorSlider::setColors( const TQColor& color1, const TQColor& 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, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_gradientSelect( int ) ) ); + m_gradientSelect->setValue( (m_maxValue - value) + m_minValue ); + connect( m_gradientSelect, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_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, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_spinBox( int ) ) ); + m_spinBox->setValue( value ); + connect( m_spinBox, TQT_SIGNAL( valueChanged ( int ) ), this, TQT_SLOT( updateFrom_spinBox( int ) ) ); + emit valueChanged( value ); + } +} + +bool VColorSlider::eventFilter( TQObject *obj, TQEvent *ev ) +{ + if( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(m_gradientSelect) ) + { + if ( ev->type() == TQEvent::MouseButtonPress ) + m_isDragging = true; + else if( ev->type() == TQEvent::MouseButtonRelease ) + m_isDragging = false; + } + return FALSE; +} + +#include "vcolorslider.moc" + diff --git a/karbon/widgets/vgradienttabwidget.cc b/karbon/widgets/vgradienttabwidget.cc deleted file mode 100644 index 5c57efab..00000000 --- a/karbon/widgets/vgradienttabwidget.cc +++ /dev/null @@ -1,343 +0,0 @@ -/* 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 -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "vgradientwidget.h" -#include "vgradienttabwidget.h" -#include "karbon_resourceserver.h" -#include "vkopainter.h" -#include "vfill.h" - -VGradientListItem::VGradientListItem( const VGradient& gradient, TQString filename ) - : TQListBoxItem( 0L ), m_filename( filename ) -{ - m_gradient = new VGradient( gradient ); - - m_pixmap.resize( 200, 16 ); - VKoPainter gp( TQT_TQPAINTDEVICE(&m_pixmap), m_pixmap.width(), m_pixmap.height() ); - gp.setRasterOp( TQt::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 = TQFileInfo( filename ).isWritable(); -} // VGradientListItem::VGradientListItem - -VGradientListItem::VGradientListItem( const VGradientListItem& gradient ) - : TQListBoxItem( 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 TQListBox* lb ) const -{ - return lb->width() - 25; -} // VGradientListItem::width - -void VGradientListItem::paint( TQPainter* painter ) -{ - painter->save(); - painter->setRasterOp( TQt::CopyROP ); - TQRect 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, TQWidget* parent, const char* name ) - : TQWidget( parent, name ), m_gradient( &gradient ), m_opacity( &opacity ) -{ - setBackgroundMode( TQt::NoBackground ); - setMinimumSize( 70, 70 ); -} // VGradientPreview::VGradientPreview - -VGradientPreview::~VGradientPreview() -{ -} // VGradientPreview::~VGradientPreview - -void VGradientPreview::paintEvent( TQPaintEvent* ) -{ - TQPixmap pixmap( width(), height() ); - VKoPainter gp( TQT_TQPAINTDEVICE(&pixmap), width(), height() ); - gp.setRasterOp( TQt::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; - TDEIconLoader il; - fill.pattern() = VPattern( il.iconPath( "karbon.png", TDEIcon::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(); - - TQPainter 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, TQWidget* parent, const char* name ) - : TQTabWidget( parent, name ), m_gradient( gradient ), m_resourceServer( server ) -{ - setupUI(); - setupConnections(); - initUI(); -} // VGradientTabWidget::VGradientTabWidget - -VGradientTabWidget::~VGradientTabWidget() -{ -} // VGradientTabWidget::~VGradientTabWidget - -void VGradientTabWidget::setupUI() -{ - m_editGroup = new TQGroupBox( i18n( "Edit Gradient" ) ); - TQGridLayout* editLayout = new TQGridLayout( 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 TQLabel( i18n( "Type:" ), m_editGroup ), 1, 1 ); - editLayout->addWidget( new TQLabel( i18n( "Repeat:" ), m_editGroup ), 2, 1 ); - editLayout->addWidget( new TQLabel( 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 TQPushButton( 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 TQLabel( 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" ) ); - - TQGroupBox* predefGroup = new TQGroupBox( i18n( "Predefined Gradients" ) ); - TQGridLayout* predefLayout = new TQGridLayout( predefGroup, 3, 2 ); - predefLayout->setSpacing( 3 ); - predefLayout->setMargin( 6 ); - predefLayout->addRowSpacing( 0, 12 ); - predefLayout->addMultiCellWidget( m_predefGradientsView = new TDEListBox( predefGroup ), 1, 1, 0, 2 ); - predefLayout->addWidget( m_predefDelete = new TQPushButton( i18n( "&Delete" ), predefGroup ), 2, 0 ); - predefLayout->addWidget( m_predefImport = new TQPushButton( i18n( "&Import" ), predefGroup ), 2, 1 ); - m_predefImport->setEnabled( false ); - addTab( predefGroup, i18n( "Predefined" ) ); -} // VGradientTabWidget::setupUI - -void VGradientTabWidget::setupConnections() -{ - connect( m_gradientType, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( combosChange( int ) ) ); - connect( m_gradientRepeat, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( combosChange( int ) ) ); - connect( m_gradientWidget, TQT_SIGNAL( changed() ), m_gradientPreview, TQT_SLOT( update() ) ); - connect( m_addToPredefs, TQT_SIGNAL( clicked() ), this, TQT_SLOT( addGradientToPredefs() ) ); - connect( m_predefGradientsView, TQT_SIGNAL( doubleClicked( TQListBoxItem *, const TQPoint & ) ), this, TQT_SLOT( changeToPredef( TQListBoxItem* ) ) ); - connect( m_predefDelete, TQT_SIGNAL( clicked() ), this, TQT_SLOT( deletePredef() ) ); - connect( m_opacity, TQT_SIGNAL( valueChanged( int ) ), this, TQT_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(); - TQPtrList* 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( TQListBoxItem* item ) -{ - if( item ) - { - VGradientListItem* gradientItem = (VGradientListItem*)item; - m_predefDelete->setEnabled( gradientItem->canDelete() ); - } -} // VGradientTabWidget::predefSelected - -void VGradientTabWidget::changeToPredef( TQListBoxItem* 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.cpp b/karbon/widgets/vgradienttabwidget.cpp new file mode 100644 index 00000000..5c57efab --- /dev/null +++ b/karbon/widgets/vgradienttabwidget.cpp @@ -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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "vgradientwidget.h" +#include "vgradienttabwidget.h" +#include "karbon_resourceserver.h" +#include "vkopainter.h" +#include "vfill.h" + +VGradientListItem::VGradientListItem( const VGradient& gradient, TQString filename ) + : TQListBoxItem( 0L ), m_filename( filename ) +{ + m_gradient = new VGradient( gradient ); + + m_pixmap.resize( 200, 16 ); + VKoPainter gp( TQT_TQPAINTDEVICE(&m_pixmap), m_pixmap.width(), m_pixmap.height() ); + gp.setRasterOp( TQt::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 = TQFileInfo( filename ).isWritable(); +} // VGradientListItem::VGradientListItem + +VGradientListItem::VGradientListItem( const VGradientListItem& gradient ) + : TQListBoxItem( 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 TQListBox* lb ) const +{ + return lb->width() - 25; +} // VGradientListItem::width + +void VGradientListItem::paint( TQPainter* painter ) +{ + painter->save(); + painter->setRasterOp( TQt::CopyROP ); + TQRect 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, TQWidget* parent, const char* name ) + : TQWidget( parent, name ), m_gradient( &gradient ), m_opacity( &opacity ) +{ + setBackgroundMode( TQt::NoBackground ); + setMinimumSize( 70, 70 ); +} // VGradientPreview::VGradientPreview + +VGradientPreview::~VGradientPreview() +{ +} // VGradientPreview::~VGradientPreview + +void VGradientPreview::paintEvent( TQPaintEvent* ) +{ + TQPixmap pixmap( width(), height() ); + VKoPainter gp( TQT_TQPAINTDEVICE(&pixmap), width(), height() ); + gp.setRasterOp( TQt::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; + TDEIconLoader il; + fill.pattern() = VPattern( il.iconPath( "karbon.png", TDEIcon::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(); + + TQPainter 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, TQWidget* parent, const char* name ) + : TQTabWidget( parent, name ), m_gradient( gradient ), m_resourceServer( server ) +{ + setupUI(); + setupConnections(); + initUI(); +} // VGradientTabWidget::VGradientTabWidget + +VGradientTabWidget::~VGradientTabWidget() +{ +} // VGradientTabWidget::~VGradientTabWidget + +void VGradientTabWidget::setupUI() +{ + m_editGroup = new TQGroupBox( i18n( "Edit Gradient" ) ); + TQGridLayout* editLayout = new TQGridLayout( 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 TQLabel( i18n( "Type:" ), m_editGroup ), 1, 1 ); + editLayout->addWidget( new TQLabel( i18n( "Repeat:" ), m_editGroup ), 2, 1 ); + editLayout->addWidget( new TQLabel( 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 TQPushButton( 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 TQLabel( 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" ) ); + + TQGroupBox* predefGroup = new TQGroupBox( i18n( "Predefined Gradients" ) ); + TQGridLayout* predefLayout = new TQGridLayout( predefGroup, 3, 2 ); + predefLayout->setSpacing( 3 ); + predefLayout->setMargin( 6 ); + predefLayout->addRowSpacing( 0, 12 ); + predefLayout->addMultiCellWidget( m_predefGradientsView = new TDEListBox( predefGroup ), 1, 1, 0, 2 ); + predefLayout->addWidget( m_predefDelete = new TQPushButton( i18n( "&Delete" ), predefGroup ), 2, 0 ); + predefLayout->addWidget( m_predefImport = new TQPushButton( i18n( "&Import" ), predefGroup ), 2, 1 ); + m_predefImport->setEnabled( false ); + addTab( predefGroup, i18n( "Predefined" ) ); +} // VGradientTabWidget::setupUI + +void VGradientTabWidget::setupConnections() +{ + connect( m_gradientType, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( combosChange( int ) ) ); + connect( m_gradientRepeat, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( combosChange( int ) ) ); + connect( m_gradientWidget, TQT_SIGNAL( changed() ), m_gradientPreview, TQT_SLOT( update() ) ); + connect( m_addToPredefs, TQT_SIGNAL( clicked() ), this, TQT_SLOT( addGradientToPredefs() ) ); + connect( m_predefGradientsView, TQT_SIGNAL( doubleClicked( TQListBoxItem *, const TQPoint & ) ), this, TQT_SLOT( changeToPredef( TQListBoxItem* ) ) ); + connect( m_predefDelete, TQT_SIGNAL( clicked() ), this, TQT_SLOT( deletePredef() ) ); + connect( m_opacity, TQT_SIGNAL( valueChanged( int ) ), this, TQT_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(); + TQPtrList* 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( TQListBoxItem* item ) +{ + if( item ) + { + VGradientListItem* gradientItem = (VGradientListItem*)item; + m_predefDelete->setEnabled( gradientItem->canDelete() ); + } +} // VGradientTabWidget::predefSelected + +void VGradientTabWidget::changeToPredef( TQListBoxItem* 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/vgradientwidget.cc b/karbon/widgets/vgradientwidget.cc deleted file mode 100644 index 64cbf373..00000000 --- a/karbon/widgets/vgradientwidget.cc +++ /dev/null @@ -1,309 +0,0 @@ -/* 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 -#include -#include - -#include -#include -#include -#include -#include - -#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, TQWidget* parent, const char* name ) - : TQWidget( parent, name ), m_gradient( &gradient ) -{ - setBackgroundMode( TQt::NoBackground ); - setMinimumSize( 105, 35 ); -} // VGradientWidget::VGradientWidget - -VGradientWidget::~VGradientWidget() -{ -} // VGradientWidget::~VGradientWidget - -void VGradientWidget::paintColorStop( TQPainter& p, int x, VColor& color ) -{ - TQBitmap bitmap; - - bitmap = TQBitmap( colorStop_width, colorStop_height, colorStop_bits, true ); - bitmap.setMask( bitmap ); - p.setPen( color ); - p.drawPixmap( x - 4, 1, bitmap ); - - bitmap = TQBitmap( colorStopBorder_width, colorStopBorder_height, colorStopBorder_bits, true ); - bitmap.setMask( bitmap ); - p.setPen( TQt::black ); - p.drawPixmap( x - 5, 1, bitmap ); -} // VGradientWidget::paintColorStop - -void VGradientWidget::paintMidPoint( TQPainter& p, int x ) -{ - TQBitmap bitmap( midPoint_width, midPoint_height, midPoint_bits, true ); - bitmap.setMask( bitmap ); - p.setPen( TQt::black ); - p.drawPixmap( x - 3, 1, bitmap ); -} // VGradientWidget::paintMidPoint - -void VGradientWidget::paintEvent( TQPaintEvent* ) -{ - 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 - - TQPixmap pixmap( width(), height() ); - VKoPainter gp( TQT_TQPAINTDEVICE(&pixmap), width(), height() ); - gp.setRasterOp( TQt::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; - TDEIconLoader il; - fill.pattern() = VPattern( il.iconPath( "karbon.png", TDEIcon::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(); - - TQPainter 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() ); - - TQPtrList& 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( TQMouseEvent* e ) -{ - if( ! m_pntArea.contains( e->x(), e->y() ) ) - return; - - TQPtrList& 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( TQMouseEvent* 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( TQCursor( TQt::ArrowCursor ) ); -} // VGradientWidget::mouseReleaseEvent - -void VGradientWidget::mouseDoubleClickEvent( TQMouseEvent* 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() == TQDialog::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() == TQDialog::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( TQMouseEvent* e ) -{ - if( e->state() & Qt::RightButton ) - return; - - TQPtrList& 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.cpp b/karbon/widgets/vgradientwidget.cpp new file mode 100644 index 00000000..64cbf373 --- /dev/null +++ b/karbon/widgets/vgradientwidget.cpp @@ -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 +#include +#include + +#include +#include +#include +#include +#include + +#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, TQWidget* parent, const char* name ) + : TQWidget( parent, name ), m_gradient( &gradient ) +{ + setBackgroundMode( TQt::NoBackground ); + setMinimumSize( 105, 35 ); +} // VGradientWidget::VGradientWidget + +VGradientWidget::~VGradientWidget() +{ +} // VGradientWidget::~VGradientWidget + +void VGradientWidget::paintColorStop( TQPainter& p, int x, VColor& color ) +{ + TQBitmap bitmap; + + bitmap = TQBitmap( colorStop_width, colorStop_height, colorStop_bits, true ); + bitmap.setMask( bitmap ); + p.setPen( color ); + p.drawPixmap( x - 4, 1, bitmap ); + + bitmap = TQBitmap( colorStopBorder_width, colorStopBorder_height, colorStopBorder_bits, true ); + bitmap.setMask( bitmap ); + p.setPen( TQt::black ); + p.drawPixmap( x - 5, 1, bitmap ); +} // VGradientWidget::paintColorStop + +void VGradientWidget::paintMidPoint( TQPainter& p, int x ) +{ + TQBitmap bitmap( midPoint_width, midPoint_height, midPoint_bits, true ); + bitmap.setMask( bitmap ); + p.setPen( TQt::black ); + p.drawPixmap( x - 3, 1, bitmap ); +} // VGradientWidget::paintMidPoint + +void VGradientWidget::paintEvent( TQPaintEvent* ) +{ + 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 + + TQPixmap pixmap( width(), height() ); + VKoPainter gp( TQT_TQPAINTDEVICE(&pixmap), width(), height() ); + gp.setRasterOp( TQt::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; + TDEIconLoader il; + fill.pattern() = VPattern( il.iconPath( "karbon.png", TDEIcon::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(); + + TQPainter 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() ); + + TQPtrList& 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( TQMouseEvent* e ) +{ + if( ! m_pntArea.contains( e->x(), e->y() ) ) + return; + + TQPtrList& 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( TQMouseEvent* 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( TQCursor( TQt::ArrowCursor ) ); +} // VGradientWidget::mouseReleaseEvent + +void VGradientWidget::mouseDoubleClickEvent( TQMouseEvent* 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() == TQDialog::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() == TQDialog::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( TQMouseEvent* e ) +{ + if( e->state() & Qt::RightButton ) + return; + + TQPtrList& 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/vreference.cc b/karbon/widgets/vreference.cc deleted file mode 100644 index c8580000..00000000 --- a/karbon/widgets/vreference.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* 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 -#include -#include - -#include "vreference.h" - -VReference::VReference( TQWidget *parent, const char *name ) : TQFrame ( parent, name ) -{ - TQVBoxLayout* layout = new TQVBoxLayout( this ); - mButtonGroup = new TQButtonGroup (3,Qt::Vertical, this ); - TQRadioButton* radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, TopLeft ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, Left ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, BottomLeft ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, Top ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, Center ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, Bottom ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, TopRight ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, Right ); - radio = new TQRadioButton ( mButtonGroup ); - mButtonGroup->insert( radio, BottomRight ); - - connect( - mButtonGroup, TQT_SIGNAL( clicked( int ) ), - this, TQT_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.cpp b/karbon/widgets/vreference.cpp new file mode 100644 index 00000000..c4e96ddf --- /dev/null +++ b/karbon/widgets/vreference.cpp @@ -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.cpp */ + +#include +#include +#include + +#include "vreference.h" + +VReference::VReference( TQWidget *parent, const char *name ) : TQFrame ( parent, name ) +{ + TQVBoxLayout* layout = new TQVBoxLayout( this ); + mButtonGroup = new TQButtonGroup (3,Qt::Vertical, this ); + TQRadioButton* radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, TopLeft ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Left ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, BottomLeft ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Top ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Center ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Bottom ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, TopRight ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, Right ); + radio = new TQRadioButton ( mButtonGroup ); + mButtonGroup->insert( radio, BottomRight ); + + connect( + mButtonGroup, TQT_SIGNAL( clicked( int ) ), + this, TQT_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/vruler.cc b/karbon/widgets/vruler.cc deleted file mode 100644 index c0ff0a20..00000000 --- a/karbon/widgets/vruler.cc +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Kivio - Visual Modelling and Flowcharting - * Copyright (C) 2000-2001 theKompany.com & Dave Marotti - * Copyright (C) 2002 Patrick Julien - * - * 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 - -#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, TQWidget *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(TQ_INT32 w, TQ_INT32 h) -{ - TQPainter 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() -{ - TQ_INT32 w; - TQ_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 TQPixmap(w, h); - TQ_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(TQ_INT32 x, TQ_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(TQ_INT32 xpos, TQ_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(TQPaintEvent *e) -{ - if (m_pixmapBuffer) { - const TQRect& rect = e -> rect(); - - bitBlt(this, rect.topLeft(), m_pixmapBuffer, rect); - super::paintEvent(e); - } -} - -void VRuler::drawRuler() -{ - TQPainter p; - TQString buf; - TQ_INT32 st1 = 0; - TQ_INT32 st2 = 0; - TQ_INT32 st3 = 0; - TQ_INT32 st4 = 0; - TQ_INT32 stt = 0; - - if (!m_pixmapBuffer) - return; - - p.begin(m_pixmapBuffer); - p.setPen(TQColor(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; - } - - TQ_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; - TQ_INT32 step = tqRound(cx);//((TQ_INT32)(cx / (float)stt) + 1) * stt; - TQ_INT32 start = (TQ_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom); - - do { - pos = (TQ_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(TQABS(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; - TQ_INT32 height = m_pixmapBuffer -> height() - 1; - TQ_INT32 step = tqRound(cx); - TQ_INT32 start = (TQ_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom); - - do { - pos = height - (TQ_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(TQABS(start)); - drawNums(&p, 4, pos, buf, false); - } - - start++; - } while (pos > 0); - } - - p.end(); -} - -void VRuler::resizeEvent(TQResizeEvent *) -{ - 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(TQPainter *p, TQ_INT32 x, TQ_INT32 y, TQString& num, bool orientationHoriz) -{ - if (orientationHoriz) - x -= 7; - else - y -= 8; - - for (TQ_UINT32 k = 0; k < num.length(); k++) { - TQ_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.cpp b/karbon/widgets/vruler.cpp new file mode 100644 index 00000000..c0ff0a20 --- /dev/null +++ b/karbon/widgets/vruler.cpp @@ -0,0 +1,332 @@ +/* + * Kivio - Visual Modelling and Flowcharting + * Copyright (C) 2000-2001 theKompany.com & Dave Marotti + * Copyright (C) 2002 Patrick Julien + * + * 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 + +#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, TQWidget *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(TQ_INT32 w, TQ_INT32 h) +{ + TQPainter 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() +{ + TQ_INT32 w; + TQ_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 TQPixmap(w, h); + TQ_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(TQ_INT32 x, TQ_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(TQ_INT32 xpos, TQ_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(TQPaintEvent *e) +{ + if (m_pixmapBuffer) { + const TQRect& rect = e -> rect(); + + bitBlt(this, rect.topLeft(), m_pixmapBuffer, rect); + super::paintEvent(e); + } +} + +void VRuler::drawRuler() +{ + TQPainter p; + TQString buf; + TQ_INT32 st1 = 0; + TQ_INT32 st2 = 0; + TQ_INT32 st3 = 0; + TQ_INT32 st4 = 0; + TQ_INT32 stt = 0; + + if (!m_pixmapBuffer) + return; + + p.begin(m_pixmapBuffer); + p.setPen(TQColor(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; + } + + TQ_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; + TQ_INT32 step = tqRound(cx);//((TQ_INT32)(cx / (float)stt) + 1) * stt; + TQ_INT32 start = (TQ_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom); + + do { + pos = (TQ_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(TQABS(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; + TQ_INT32 height = m_pixmapBuffer -> height() - 1; + TQ_INT32 step = tqRound(cx); + TQ_INT32 start = (TQ_INT32)(KoUnit::toUserValue(m_firstVisible, m_unit) / m_zoom); + + do { + pos = height - (TQ_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(TQABS(start)); + drawNums(&p, 4, pos, buf, false); + } + + start++; + } while (pos > 0); + } + + p.end(); +} + +void VRuler::resizeEvent(TQResizeEvent *) +{ + 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(TQPainter *p, TQ_INT32 x, TQ_INT32 y, TQString& num, bool orientationHoriz) +{ + if (orientationHoriz) + x -= 7; + else + y -= 8; + + for (TQ_UINT32 k = 0; k < num.length(); k++) { + TQ_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/vselecttoolbar.cc b/karbon/widgets/vselecttoolbar.cc deleted file mode 100644 index 2e32a677..00000000 --- a/karbon/widgets/vselecttoolbar.cc +++ /dev/null @@ -1,124 +0,0 @@ -/* 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 - -#include -#include - -#include "KoUnitWidgets.h" -#include "vselecttoolbar.h" -#include "karbon_view.h" -#include "karbon_part.h" -#include "vselection.h" -#include "vtransformcmd.h" -#include - -VSelectToolBar::VSelectToolBar( KarbonView *view, const char* name ) : TDEToolBar( view, name ), m_view( view ) -{ - setCaption( i18n( "Object Properties" ) ); - TQLabel *x_label = new TQLabel( i18n( "X:" ), this, "tde toolbar widget" ); - insertWidget( 0, x_label->width(), x_label ); - m_x = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); - connect( m_x, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotXChanged( double ) ) ); - insertWidget( 1, m_x->width(), m_x ); - TQLabel *y_label = new TQLabel( i18n( "Y:" ), this, "tde toolbar widget" ); - insertWidget( 2, y_label->width(), y_label ); - m_y = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); - connect( m_y, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotYChanged( double ) ) ); - insertWidget( 3, m_y->width(), m_y ); - - insertSeparator( 4 ); - TQLabel *w_label = new TQLabel( i18n( "selection width", "Width:" ), this, "tde toolbar widget" ); - insertWidget( 5, w_label->width(), w_label ); - m_width = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); - connect( m_width, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotWidthChanged( double ) ) ); - insertWidget( 6, m_width->width(), m_width ); - TQLabel *h_label = new TQLabel( i18n( "Height:" ), this, "tde toolbar widget" ); - insertWidget( 7, h_label->width(), h_label ); - m_height = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); - connect( m_height, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotHeightChanged( double ) ) ); - insertWidget( 8, m_height->width(), m_height ); - - connect( m_view, TQT_SIGNAL( selectionChange() ), this, TQT_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.cpp b/karbon/widgets/vselecttoolbar.cpp new file mode 100644 index 00000000..b0dc9a7c --- /dev/null +++ b/karbon/widgets/vselecttoolbar.cpp @@ -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.cpp */ + +#include + +#include +#include + +#include "KoUnitWidgets.h" +#include "vselecttoolbar.h" +#include "karbon_view.h" +#include "karbon_part.h" +#include "vselection.h" +#include "vtransformcmd.h" +#include + +VSelectToolBar::VSelectToolBar( KarbonView *view, const char* name ) : TDEToolBar( view, name ), m_view( view ) +{ + setCaption( i18n( "Object Properties" ) ); + TQLabel *x_label = new TQLabel( i18n( "X:" ), this, "tde toolbar widget" ); + insertWidget( 0, x_label->width(), x_label ); + m_x = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_x, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotXChanged( double ) ) ); + insertWidget( 1, m_x->width(), m_x ); + TQLabel *y_label = new TQLabel( i18n( "Y:" ), this, "tde toolbar widget" ); + insertWidget( 2, y_label->width(), y_label ); + m_y = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_y, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotYChanged( double ) ) ); + insertWidget( 3, m_y->width(), m_y ); + + insertSeparator( 4 ); + TQLabel *w_label = new TQLabel( i18n( "selection width", "Width:" ), this, "tde toolbar widget" ); + insertWidget( 5, w_label->width(), w_label ); + m_width = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_width, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotWidthChanged( double ) ) ); + insertWidget( 6, m_width->width(), m_width ); + TQLabel *h_label = new TQLabel( i18n( "Height:" ), this, "tde toolbar widget" ); + insertWidget( 7, h_label->width(), h_label ); + m_height = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5 ); + connect( m_height, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( slotHeightChanged( double ) ) ); + insertWidget( 8, m_height->width(), m_height ); + + connect( m_view, TQT_SIGNAL( selectionChange() ), this, TQT_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/vsmallpreview.cc b/karbon/widgets/vsmallpreview.cc deleted file mode 100644 index 28a8dd27..00000000 --- a/karbon/widgets/vsmallpreview.cc +++ /dev/null @@ -1,282 +0,0 @@ -/* 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 -#include -#include -#include -#include - -#include -#include - -#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( TQWidget* parent, const char* name ) - : TQWidget( parent, name ) -{ - /* Create widget layout */ - TQHBoxLayout *layout = new TQHBoxLayout( this, 4 ); - m_strokeLabel = new TQLabel( i18n( "Stroke: None" ), this ); - layout->addWidget( m_strokeLabel ); - m_strokeFrame = new TQFrame( this ); - m_strokeFrame->setFixedWidth ( FRAMEWIDTH ); - m_strokeFrame->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Plain ); - layout->addWidget( m_strokeFrame ); - m_fillLabel = new TQLabel( i18n( "Fill: None" ), this ); - layout->addWidget( m_fillLabel ); - m_fillFrame = new TQFrame( this ); - m_fillFrame->setFixedWidth ( FRAMEWIDTH ); - m_fillFrame->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::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( TQPaintEvent* /*event*/ ) -{ - drawStroke( m_stroke ); - drawFill( m_fill ); -} - -void -VSmallPreview::drawFill( const VFill &f ) -{ - VFill fill; - VStroke stroke; - - TQPixmap m_pixmap; - m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() ); - VKoPainter* m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), m_fillFrame->width(), m_fillFrame->height() ); - - m_painter->begin(); - m_painter->setPen( TQt::NoPen ); - fill.setColor( TQt::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( TQt::white ); - m_painter->setBrush( fill ); - m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) ); - stroke.setColor( TQt::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; - - TQPixmap m_pixmap; - m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() ); - VKoPainter* m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), m_fillFrame->width(), m_fillFrame->height() ); - - m_painter->begin(); - m_painter->setPen( TQt::NoPen ); - fill.setColor( TQt::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( TQt::white ); - m_painter->setBrush( fill ); - m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) ); - stroke.setColor( TQt::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.cpp b/karbon/widgets/vsmallpreview.cpp new file mode 100644 index 00000000..c422104e --- /dev/null +++ b/karbon/widgets/vsmallpreview.cpp @@ -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.cpp */ +#include +#include +#include +#include +#include + +#include +#include + +#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( TQWidget* parent, const char* name ) + : TQWidget( parent, name ) +{ + /* Create widget layout */ + TQHBoxLayout *layout = new TQHBoxLayout( this, 4 ); + m_strokeLabel = new TQLabel( i18n( "Stroke: None" ), this ); + layout->addWidget( m_strokeLabel ); + m_strokeFrame = new TQFrame( this ); + m_strokeFrame->setFixedWidth ( FRAMEWIDTH ); + m_strokeFrame->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Plain ); + layout->addWidget( m_strokeFrame ); + m_fillLabel = new TQLabel( i18n( "Fill: None" ), this ); + layout->addWidget( m_fillLabel ); + m_fillFrame = new TQFrame( this ); + m_fillFrame->setFixedWidth ( FRAMEWIDTH ); + m_fillFrame->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::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( TQPaintEvent* /*event*/ ) +{ + drawStroke( m_stroke ); + drawFill( m_fill ); +} + +void +VSmallPreview::drawFill( const VFill &f ) +{ + VFill fill; + VStroke stroke; + + TQPixmap m_pixmap; + m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() ); + VKoPainter* m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), m_fillFrame->width(), m_fillFrame->height() ); + + m_painter->begin(); + m_painter->setPen( TQt::NoPen ); + fill.setColor( TQt::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( TQt::white ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) ); + stroke.setColor( TQt::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; + + TQPixmap m_pixmap; + m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() ); + VKoPainter* m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), m_fillFrame->width(), m_fillFrame->height() ); + + m_painter->begin(); + m_painter->setPen( TQt::NoPen ); + fill.setColor( TQt::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( TQt::white ); + m_painter->setBrush( fill ); + m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) ); + stroke.setColor( TQt::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/vstatebutton.cc b/karbon/widgets/vstatebutton.cc deleted file mode 100644 index 1ea8e27a..00000000 --- a/karbon/widgets/vstatebutton.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* 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( TQWidget* parent, const char* name ) - : TQPushButton( parent, name ) -{ - m_index = 0; - m_pixmaps.setAutoDelete( true ); -} - -VStateButton::~VStateButton() -{ -} - -void -VStateButton::mouseReleaseEvent( TQMouseEvent *e ) -{ - TQPushButton::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.cpp b/karbon/widgets/vstatebutton.cpp new file mode 100644 index 00000000..1ea8e27a --- /dev/null +++ b/karbon/widgets/vstatebutton.cpp @@ -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( TQWidget* parent, const char* name ) + : TQPushButton( parent, name ) +{ + m_index = 0; + m_pixmaps.setAutoDelete( true ); +} + +VStateButton::~VStateButton() +{ +} + +void +VStateButton::mouseReleaseEvent( TQMouseEvent *e ) +{ + TQPushButton::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/vstrokefillpreview.cc b/karbon/widgets/vstrokefillpreview.cc deleted file mode 100644 index f69d5d85..00000000 --- a/karbon/widgets/vstrokefillpreview.cc +++ /dev/null @@ -1,447 +0,0 @@ -/* 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 - -#include -#include - -#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, TQWidget* parent, const char* name ) - : TQFrame( parent, name ), m_part( part ) -{ - m_strokeWidget = false; - setFocusPolicy( TQ_NoFocus ); - - setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Sunken ); - - installEventFilter( this ); - m_pixmap.resize( int( PANEL_SIZEX ), int( PANEL_SIZEY ) ); - m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), uint( PANEL_SIZEX ), uint( PANEL_SIZEY ) ); -} - -VStrokeFillPreview::~VStrokeFillPreview() -{ - delete( m_painter ); -} - -void -VStrokeFillPreview::paintEvent( TQPaintEvent* event ) -{ - bitBlt( this, - (int)( width() - PANEL_SIZEX ) / 2, (int)( height() - PANEL_SIZEY ) / 2, - &m_pixmap, - 0, 0, (int)PANEL_SIZEX, (int)PANEL_SIZEY ); - - TQFrame::paintEvent( event ); -} - -bool -VStrokeFillPreview::eventFilter( TQObject *, TQEvent *event ) -{ - TQMouseEvent* e = TQT_TQMOUSEEVENT( event ); - - int ex = e->x() - int( ( width() - PANEL_SIZEX ) / 2 ); - int ey = e->y() - int( ( height() - PANEL_SIZEY ) / 2 ); - - if( event && event->type() == TQEvent::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() == TQEvent::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() == TQDialog::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() == TQDialog::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( TQt::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 ) ? TQColor( 180, 180, 180 ) : TQColor( 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( TQt::NoPen ); - m_painter->drawRect( KoRect( FILL_TOPX, FILL_TOPY, FILL_BOTTOMX - FILL_TOPX, FILL_BOTTOMY - FILL_TOPY ) ); - } - else - { - VFill fill; - fill.setColor( TQt::white ); - m_painter->setBrush( fill ); - m_painter->setPen( TQt::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( TQt::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( TQt::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( TQt::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( TQt::white ); - - m_painter->setBrush( fill ); - m_painter->setPen( TQt::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( TQt::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( TQt::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( TQt::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.cpp b/karbon/widgets/vstrokefillpreview.cpp new file mode 100644 index 00000000..f69d5d85 --- /dev/null +++ b/karbon/widgets/vstrokefillpreview.cpp @@ -0,0 +1,447 @@ +/* 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 + +#include +#include + +#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, TQWidget* parent, const char* name ) + : TQFrame( parent, name ), m_part( part ) +{ + m_strokeWidget = false; + setFocusPolicy( TQ_NoFocus ); + + setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Sunken ); + + installEventFilter( this ); + m_pixmap.resize( int( PANEL_SIZEX ), int( PANEL_SIZEY ) ); + m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), uint( PANEL_SIZEX ), uint( PANEL_SIZEY ) ); +} + +VStrokeFillPreview::~VStrokeFillPreview() +{ + delete( m_painter ); +} + +void +VStrokeFillPreview::paintEvent( TQPaintEvent* event ) +{ + bitBlt( this, + (int)( width() - PANEL_SIZEX ) / 2, (int)( height() - PANEL_SIZEY ) / 2, + &m_pixmap, + 0, 0, (int)PANEL_SIZEX, (int)PANEL_SIZEY ); + + TQFrame::paintEvent( event ); +} + +bool +VStrokeFillPreview::eventFilter( TQObject *, TQEvent *event ) +{ + TQMouseEvent* e = TQT_TQMOUSEEVENT( event ); + + int ex = e->x() - int( ( width() - PANEL_SIZEX ) / 2 ); + int ey = e->y() - int( ( height() - PANEL_SIZEY ) / 2 ); + + if( event && event->type() == TQEvent::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() == TQEvent::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() == TQDialog::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() == TQDialog::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( TQt::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 ) ? TQColor( 180, 180, 180 ) : TQColor( 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( TQt::NoPen ); + m_painter->drawRect( KoRect( FILL_TOPX, FILL_TOPY, FILL_BOTTOMX - FILL_TOPX, FILL_BOTTOMY - FILL_TOPY ) ); + } + else + { + VFill fill; + fill.setColor( TQt::white ); + m_painter->setBrush( fill ); + m_painter->setPen( TQt::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( TQt::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( TQt::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( TQt::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( TQt::white ); + + m_painter->setBrush( fill ); + m_painter->setPen( TQt::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( TQt::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( TQt::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( TQt::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/vtoolbox.cc b/karbon/widgets/vtoolbox.cc deleted file mode 100644 index e048555c..00000000 --- a/karbon/widgets/vtoolbox.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* 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( TDEMainWindow *mainWin, const char* name, TDEInstance* 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.cpp b/karbon/widgets/vtoolbox.cpp new file mode 100644 index 00000000..e048555c --- /dev/null +++ b/karbon/widgets/vtoolbox.cpp @@ -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( TDEMainWindow *mainWin, const char* name, TDEInstance* 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/vtranslate.cc b/karbon/widgets/vtranslate.cc deleted file mode 100644 index 35a25a71..00000000 --- a/karbon/widgets/vtranslate.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* 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 -#include -#include -#include -#include -#include -#include -#include - -#include "vtranslate.h" - -VTranslate::VTranslate( TQWidget* parent, const char* name ) - : TQWidget( parent, name ) -{ - setCaption( i18n( "Translate" ) ); - - TQVBoxLayout *mainlayout = new TQVBoxLayout(this, 7); - mainlayout->addSpacing(5); - - TQGridLayout *inputlayout = new TQGridLayout(this, 5, 3); - mainlayout->addLayout(inputlayout); - m_labelX = new TQLabel(i18n("X:"), this); - inputlayout->addWidget(m_labelX, 0, 0); - labely = new TQLabel(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 TQLabel("", this); - inputlayout->addWidget(m_labelUnit1, 0, 4); - m_labelUnit2 = new TQLabel("", this); - inputlayout->addWidget(m_labelUnit2, 1, 4); - mainlayout->addSpacing(5); - m_checkBoxPosition = new TQCheckBox(i18n("Relative &position"), this); - mainlayout->addWidget(m_checkBoxPosition); - mainlayout->addSpacing(5); - m_buttonDuplicate = new TQPushButton(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 TQString& units ) -{ - m_labelUnit1->setText( units ); - m_labelUnit2->setText( units ); -} - -#include "vtranslate.moc" - diff --git a/karbon/widgets/vtranslate.cpp b/karbon/widgets/vtranslate.cpp new file mode 100644 index 00000000..35a25a71 --- /dev/null +++ b/karbon/widgets/vtranslate.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include + +#include "vtranslate.h" + +VTranslate::VTranslate( TQWidget* parent, const char* name ) + : TQWidget( parent, name ) +{ + setCaption( i18n( "Translate" ) ); + + TQVBoxLayout *mainlayout = new TQVBoxLayout(this, 7); + mainlayout->addSpacing(5); + + TQGridLayout *inputlayout = new TQGridLayout(this, 5, 3); + mainlayout->addLayout(inputlayout); + m_labelX = new TQLabel(i18n("X:"), this); + inputlayout->addWidget(m_labelX, 0, 0); + labely = new TQLabel(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 TQLabel("", this); + inputlayout->addWidget(m_labelUnit1, 0, 4); + m_labelUnit2 = new TQLabel("", this); + inputlayout->addWidget(m_labelUnit2, 1, 4); + mainlayout->addSpacing(5); + m_checkBoxPosition = new TQCheckBox(i18n("Relative &position"), this); + mainlayout->addWidget(m_checkBoxPosition); + mainlayout->addSpacing(5); + m_buttonDuplicate = new TQPushButton(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 TQString& units ) +{ + m_labelUnit1->setText( units ); + m_labelUnit2->setText( units ); +} + +#include "vtranslate.moc" + diff --git a/karbon/widgets/vtypebuttonbox.cc b/karbon/widgets/vtypebuttonbox.cc deleted file mode 100644 index 9a98a125..00000000 --- a/karbon/widgets/vtypebuttonbox.cc +++ /dev/null @@ -1,330 +0,0 @@ -/* 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 -#include -#include - -#include - -#include "karbon_part.h" -#include "vfillcmd.h" -#include "vselection.h" -#include "vstrokecmd.h" - -#include "vtypebuttonbox.h" - -VTypeButtonBox::VTypeButtonBox( KarbonPart *part, - TQWidget* parent, const char* name ) - : TQHButtonGroup( parent, name ), - m_part( part ), m_isStrokeManipulator( false ) -{ - setMaximumWidth( parent->width() - 2 ); - - // The button for no fill - TQToolButton* button = new TQToolButton( this ); - button->setPixmap( TQPixmap( (const char **) buttonnone ) ); - button->setMaximumWidth( 14 ); - button->setMaximumHeight( 14 ); - TQToolTip::add( button, i18n( "None" ) ); - insert( button, none ); - - // The button for solid fill - button = new TQToolButton( this ); - button->setPixmap( TQPixmap( (const char **) buttonsolid ) ); - button->setMaximumWidth( 14 ); - button->setMaximumHeight( 14 ); - TQToolTip::add( button, i18n( "Solid" ) ); - insert( button, solid ); - - // The button for gradient fill - button = new TQToolButton( this ); - button->setPixmap( TQPixmap( (const char **) buttongradient ) ); - button->setMaximumWidth( 14 ); - button->setMaximumHeight( 14 ); - TQToolTip::add( button, i18n( "Gradient" ) ); - insert( button, gradient ); - - // The button for pattern fill - button = new TQToolButton( this ); - button->setPixmap( TQPixmap( (const char **) buttonpattern ) ); - button->setMaximumWidth( 14 ); - button->setMaximumHeight( 14 ); - TQToolTip::add( button, i18n( "Pattern" ) ); - insert( button, pattern ); - - setInsideMargin( 1 ); - setInsideSpacing( 1 ); - connect( this, TQT_SIGNAL( clicked( int ) ), - this, TQT_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.cpp b/karbon/widgets/vtypebuttonbox.cpp new file mode 100644 index 00000000..9a98a125 --- /dev/null +++ b/karbon/widgets/vtypebuttonbox.cpp @@ -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 +#include +#include + +#include + +#include "karbon_part.h" +#include "vfillcmd.h" +#include "vselection.h" +#include "vstrokecmd.h" + +#include "vtypebuttonbox.h" + +VTypeButtonBox::VTypeButtonBox( KarbonPart *part, + TQWidget* parent, const char* name ) + : TQHButtonGroup( parent, name ), + m_part( part ), m_isStrokeManipulator( false ) +{ + setMaximumWidth( parent->width() - 2 ); + + // The button for no fill + TQToolButton* button = new TQToolButton( this ); + button->setPixmap( TQPixmap( (const char **) buttonnone ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + TQToolTip::add( button, i18n( "None" ) ); + insert( button, none ); + + // The button for solid fill + button = new TQToolButton( this ); + button->setPixmap( TQPixmap( (const char **) buttonsolid ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + TQToolTip::add( button, i18n( "Solid" ) ); + insert( button, solid ); + + // The button for gradient fill + button = new TQToolButton( this ); + button->setPixmap( TQPixmap( (const char **) buttongradient ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + TQToolTip::add( button, i18n( "Gradient" ) ); + insert( button, gradient ); + + // The button for pattern fill + button = new TQToolButton( this ); + button->setPixmap( TQPixmap( (const char **) buttonpattern ) ); + button->setMaximumWidth( 14 ); + button->setMaximumHeight( 14 ); + TQToolTip::add( button, i18n( "Pattern" ) ); + insert( button, pattern ); + + setInsideMargin( 1 ); + setInsideSpacing( 1 ); + connect( this, TQT_SIGNAL( clicked( int ) ), + this, TQT_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" + -- cgit v1.2.1