kpresenter

KPrPBPreview.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2004 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KPrPBPreview.h"
00022 
00023 #include <qpainter.h>
00024 
00025 #include <KoTextZoomHandler.h>
00026 #include "KPrUtils.h"
00027 
00028 KPrPBPreview::KPrPBPreview( QWidget* parent, const char* name, PaintType _paintType )
00029     : QFrame( parent, name )
00030 {
00031     //FIXME zoom
00032     _zoomHandler=new KoTextZoomHandler();
00033     paintType = _paintType;
00034     pen = KoPen( black, 1, SolidLine );
00035     brush = QBrush( white, SolidPattern );
00036     gradient = new KPrGradient( Qt::red, Qt::green, BCT_GHORZ, false, 100, 100 );
00037     savedGradient = gradient;
00038 
00039     setFrameStyle( WinPanel | Sunken );
00040 
00041     switch ( paintType ) {
00042     case Pen:
00043         setFixedHeight( 40 );
00044         break;
00045     default:
00046         setMinimumWidth( 230 );
00047         break;
00048     }
00049 }
00050 
00051 void KPrPBPreview::resizeEvent( QResizeEvent *e )
00052 {
00053     QFrame::resizeEvent( e );
00054     if ( gradient )
00055     {
00056 #if 1
00057         gradient->setSize( contentsRect().size() );
00058         repaint();
00059 #endif
00060     }
00061 }
00062 
00063 void KPrPBPreview::drawContents( QPainter *painter )
00064 {
00065     painter->save();
00066     painter->translate( contentsRect().x(), contentsRect().y() );
00067 
00068     if ( paintType == Pen ) {
00069         painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(),
00070                            colorGroup().base() );
00071         KoSize diff1( 0, 0 ), diff2( 0, 0 );
00072         int _w = int( pen.pointWidth() );
00073 
00074         if ( lineBegin != L_NORMAL )
00075             diff1 = getOffset( lineBegin, _w, + 180.0 );
00076 
00077         if ( lineEnd != L_NORMAL )
00078             diff2 = getOffset( lineEnd, _w, 0 );
00079 
00080         if ( lineBegin != L_NORMAL )
00081             drawFigure( lineBegin, painter, KoPoint( 5, _zoomHandler->unzoomItY( contentsRect().height() ) / 2 ),
00082                         pen.color(), _w, 180.0, _zoomHandler );
00083 
00084         if ( lineEnd != L_NORMAL )
00085             drawFigure( lineEnd, painter, KoPoint( _zoomHandler->unzoomItX( contentsRect().width() - 7 ) ,
00086                                                    _zoomHandler->unzoomItY( contentsRect().height() ) / 2 ),
00087                         pen.color(), _w, 0.0, _zoomHandler );
00088 
00089         painter->setPen( pen.zoomedPen( _zoomHandler ) );
00090         painter->drawLine( - (int)diff1.width() + 8,
00091                            contentsRect().height() / 2,
00092                            contentsRect().width() - (int)diff2.width() - 7,
00093                            contentsRect().height() / 2 );
00094 
00095     } else if ( paintType == Brush ) {
00096         painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(),
00097                            colorGroup().base() );
00098         painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(), brush );
00099     } else if ( paintType == Gradient )
00100         painter->drawPixmap( 0, 0, gradient->pixmap());
00101 
00102     painter->restore();
00103 }
00104 
00105 KPrPBPreview::~KPrPBPreview()
00106 {
00107     delete _zoomHandler;
00108     delete savedGradient;
00109 }
00110 
00111 
00112 void KPrPBPreview::setGradient( const QColor &_c1, const QColor &_c2, BCType _t,
00113                              bool _unbalanced, int _xfactor, int _yfactor )
00114 {
00115     gradient->setColor1( _c1 );
00116     gradient->setColor2( _c2 );
00117     gradient->setBackColorType( _t );
00118     gradient->setUnbalanced( _unbalanced );
00119     gradient->setXFactor( _xfactor );
00120     gradient->setYFactor( _yfactor );
00121     repaint( false );
00122 }
00123 
00124 
00125 #include "KPrPBPreview.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys