kpresenter
KPrPolygonPreview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "KPrPolygonPreview.h"
00025
00026 #include <qpainter.h>
00027
00028 #include <math.h>
00029
00030 KPrPolygonPreview::KPrPolygonPreview( QWidget* parent, const char* name)
00031 : QFrame( parent, name )
00032 {
00033 setFrameStyle( WinPanel | Sunken );
00034 setBackgroundColor( white );
00035
00036 setMinimumSize( 200, 100 );
00037 }
00038
00039
00040 void KPrPolygonPreview::drawContents( QPainter *painter )
00041 {
00042 double angle = 2 * M_PI / nCorners;
00043 double diameter = static_cast<double>( QMAX( width(), height() ) - 10 );
00044 double radius = diameter * 0.5;
00045
00046 painter->setWindow( qRound( -radius ), qRound( -radius ), qRound( diameter ), qRound( diameter ) );
00047 painter->setViewport( 5, 5, width() - 10, height() - 10 );
00048 painter->setPen( pen );
00049 painter->setBrush( brush );
00050
00051 QPointArray points( isConcave ? nCorners * 2 : nCorners );
00052 points.setPoint( 0, 0, qRound( -radius ) );
00053
00054 if ( isConcave ) {
00055 angle = angle / 2.0;
00056 double a = angle;
00057 double r = radius - ( sharpness / 100.0 * radius );
00058 for ( int i = 1; i < nCorners * 2; ++i ) {
00059 double xp, yp;
00060 if ( i % 2 ) {
00061 xp = r * sin( a );
00062 yp = -r * cos( a );
00063 }
00064 else {
00065 xp = radius * sin( a );
00066 yp = -radius * cos( a );
00067 }
00068 a += angle;
00069 points.setPoint( i, (int)xp, (int)yp );
00070 }
00071 }
00072 else {
00073 double a = angle;
00074 for ( int i = 1; i < nCorners; ++i ) {
00075 double xp = radius * sin( a );
00076 double yp = -radius * cos( a );
00077 a += angle;
00078 points.setPoint( i, (int)xp, (int)yp );
00079 }
00080 }
00081 painter->drawPolygon( points );
00082 }
00083
00084
00085 void KPrPolygonPreview::slotConvexConcave( bool convexConcave )
00086 {
00087 isConcave = convexConcave;
00088 repaint();
00089 }
00090
00091
00092 void KPrPolygonPreview::slotConvexPolygon()
00093 {
00094 isConcave = false;
00095 repaint();
00096 }
00097
00098
00099 void KPrPolygonPreview::slotConcavePolygon()
00100 {
00101 isConcave = true;
00102 repaint();
00103 }
00104
00105
00106 void KPrPolygonPreview::slotCornersValue( int value )
00107 {
00108 nCorners = value;
00109 repaint();
00110 }
00111
00112
00113 void KPrPolygonPreview::slotSharpnessValue( int value )
00114 {
00115 sharpness = value;
00116 repaint();
00117 }
00118
00119
00120 #include "KPrPolygonPreview.moc"
|