summaryrefslogtreecommitdiffstats
path: root/kpresenter/KPrPBPreview.cpp
blob: cec920e0308e17ed4291415b95eedbf00e60f6ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* This file is part of the KDE project
   Copyright (C) 2004 Thorsten Zachmann <[email protected]>

   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 "KPrPBPreview.h"

#include <tqpainter.h>

#include <KoTextZoomHandler.h>
#include "KPrUtils.h"

KPrPBPreview::KPrPBPreview( TQWidget* parent, const char* name, PaintType _paintType )
    : TQFrame( parent, name )
{
    //FIXME zoom
    _zoomHandler=new KoTextZoomHandler();
    paintType = _paintType;
    pen = KoPen( black, 1, Qt::SolidLine );
    brush = TQBrush( white, SolidPattern );
    gradient = new KPrGradient( TQt::red, TQt::green, BCT_GHORZ, false, 100, 100 );
    savedGradient = gradient;

    setFrameStyle( WinPanel | Sunken );

    switch ( paintType ) {
    case Pen:
        setFixedHeight( 40 );
        break;
    default:
        setMinimumWidth( 230 );
        break;
    }
}

void KPrPBPreview::resizeEvent( TQResizeEvent *e )
{
    TQFrame::resizeEvent( e );
    if ( gradient )
    {
#if 1
        gradient->setSize( contentsRect().size() );
        repaint();
#endif
    }
}

void KPrPBPreview::drawContents( TQPainter *painter )
{
    painter->save();
    painter->translate( contentsRect().x(), contentsRect().y() );

    if ( paintType == Pen ) {
        painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(),
                           colorGroup().base() );
        KoSize diff1( 0, 0 ), diff2( 0, 0 );
        int _w = int( pen.pointWidth() );

        if ( lineBegin != L_NORMAL )
            diff1 = getOffset( lineBegin, _w, + 180.0 );

        if ( lineEnd != L_NORMAL )
            diff2 = getOffset( lineEnd, _w, 0 );

        if ( lineBegin != L_NORMAL )
            drawFigure( lineBegin, painter, KoPoint( 5, _zoomHandler->unzoomItY( contentsRect().height() ) / 2 ),
                        pen.color(), _w, 180.0, _zoomHandler );

        if ( lineEnd != L_NORMAL )
            drawFigure( lineEnd, painter, KoPoint( _zoomHandler->unzoomItX( contentsRect().width() - 7 ) ,
                                                   _zoomHandler->unzoomItY( contentsRect().height() ) / 2 ),
                        pen.color(), _w, 0.0, _zoomHandler );

        painter->setPen( pen.zoomedPen( _zoomHandler ) );
        painter->drawLine( - (int)diff1.width() + 8,
                           contentsRect().height() / 2,
                           contentsRect().width() - (int)diff2.width() - 7,
                           contentsRect().height() / 2 );

    } else if ( paintType == Brush ) {
        painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(),
                           colorGroup().base() );
        painter->fillRect( 0, 0, contentsRect().width(), contentsRect().height(), brush );
    } else if ( paintType == Gradient )
        painter->drawPixmap( 0, 0, gradient->pixmap());

    painter->restore();
}

KPrPBPreview::~KPrPBPreview()
{
    delete _zoomHandler;
    delete savedGradient;
}


void KPrPBPreview::setGradient( const TQColor &_c1, const TQColor &_c2, BCType _t,
                             bool _unbalanced, int _xfactor, int _yfactor )
{
    gradient->setColor1( _c1 );
    gradient->setColor2( _c2 );
    gradient->setBackColorType( _t );
    gradient->setUnbalanced( _unbalanced );
    gradient->setXFactor( _xfactor );
    gradient->setYFactor( _yfactor );
    repaint( false );
}


#include "KPrPBPreview.moc"