#ifndef MYDRAWINGFRAME_H
#define MYDRAWINGFRAME_H
#include "baseform.h"
#include <qframe.h>
#include <qpainter.h>
class MyDrawingFrame
: public QFrame{
Q_OBJECT
public:
public slots:
protected:
protected slots:
private:
double pi;
int activeLevel;
int functionNumber;
int dwgScaleFactor;
int count;
int num;
int n;
int o1;
bool ok;
private slots:
signals:
};
{
double angle;
int n, xs, xe, ys, ye, xc, yc;
bool ok;
if ( paintSupportLines.count () > 0 )
{
f.setFamily ( "Courier" );
f.setPointSize ( dwgScaleFactor );
p.setFont ( f );
pen.setBrush ( Qt::blue );
p.setPen ( pen );
p.setViewport ( viewportRect );
p.setWindow ( windowRect );
if ( clearWindow == "erase" ) { p.eraseRect ( windowRect ); clearWindow = "cancel erase"; }
else
{
for ( n = 0; n < paintSupportLines.count(); ++n )
{
//teErrorMessages->setText("F5 key clicked");
p.setClipRect ( clippingRect );
k = paintSupportLines[n];
tempList = k.split ( "," );
xs = tempList[0].toInt ( &ok );
ys = tempList[1].toInt ( &ok );
xe = tempList[2].toInt ( &ok );
ye = tempList[3].toInt ( &ok );
p.drawLine ( 10, 10 * n, 200, 200 );
p.drawLine ( xs, ys, xe, ye );
/// start of labeling.
if ( tempList[4] == "true" )
{
p.setClipRect ( windowRect );
xc = ( xs + xe ) / 2;
yc = ( ys + ye ) / 2;
if ( xs == xe ) angle = pi/2.0;
else if ( ys == ye ) angle = 0.0;
else
{
// angle = atan((double)(ye-ys)/(xe-xs)); /// Why did Qt 4 drop trig functions????
angle = ( double ) ( ye-ys ) / ( xe-xs ); /// hope this works!!!
angle /= 2.0 * pi ;
}
angle = ( angle * 180.0 ) / pi;
p.save();
p.translate ( xc, yc );
p.rotate ( angle ); //teErrorMessages->setText("F5 key clicked");
p.scale ( 1, -1 );
k = "S" + h.setNum ( n + 1 );
p.drawText ( 0, 0, k );
p.restore();
}
}
}
if ( paintColumns.count() > 0 )
{
p.setViewport ( viewportRect );
p.setWindow ( windowRect );
p.setClipRect ( windowRect );
for ( n = 0; n < paintColumns.count(); ++n )
{
k = paintColumns[n];
tempList = k.split ( "," );
xs = tempList[0].toInt ( &ok );
ys = tempList[1].toInt ( &ok );
xe = tempList[2].toInt ( &ok );
ye = tempList[3].toInt ( &ok );
angle = tempList[4].toInt ( &ok );
p.save();
p.translate ( xs, ys );
p.rotate ( angle );
p.fillRect ( -xe/2, -ye/2, xe, ye, Qt::black );
if ( tempList[5] == "true" )
{
f.setFamily ( "Courier" );
f.setPointSize ( ( int ) ( .8 * dwgScaleFactor ) );
p.setFont ( f );
pen.setBrush ( Qt::black );
p.setPen ( pen );
p.rotate ( -angle + 25 );
p.scale ( 1, -1 );
k = "---C" + h.setNum ( n + 1 );
p.drawText ( 0, 0, k );
}
p.restore();
}
}
}
}
#endif // MYDRAWINGFRAME_H
#ifndef MYDRAWINGFRAME_H
#define MYDRAWINGFRAME_H
#include "baseform.h"
#include <qframe.h>
#include <qpainter.h>
class MyDrawingFrame : public QFrame
{
Q_OBJECT
public:
public slots:
protected:
void paintEvent(QPaintEvent * event);
protected slots:
private:
QStringList tempList;
QStringList paintSupportLines;
QStringList paintColumns;
QString clearWindow;
QRect viewportRect;
QRect windowRect;
QRect clippingRect;
double pi;
int activeLevel;
int functionNumber;
int dwgScaleFactor;
int count;
int num;
int n;
int o1;
bool ok;
private slots:
signals:
};
void MyDrawingFrame::paintEvent(QPaintEvent * event)
{
QString k, h;
double angle;
int n, xs, xe, ys, ye, xc, yc;
bool ok;
QPainter p(this);
QPen pen;
QFont f;
if ( paintSupportLines.count () > 0 )
{
f.setFamily ( "Courier" );
f.setPointSize ( dwgScaleFactor );
p.setFont ( f );
pen.setBrush ( Qt::blue );
p.setPen ( pen );
p.setViewport ( viewportRect );
p.setWindow ( windowRect );
if ( clearWindow == "erase" ) { p.eraseRect ( windowRect ); clearWindow = "cancel erase"; }
else
{
for ( n = 0; n < paintSupportLines.count(); ++n )
{
//teErrorMessages->setText("F5 key clicked");
p.setClipRect ( clippingRect );
k = paintSupportLines[n];
tempList = k.split ( "," );
xs = tempList[0].toInt ( &ok );
ys = tempList[1].toInt ( &ok );
xe = tempList[2].toInt ( &ok );
ye = tempList[3].toInt ( &ok );
p.drawLine ( 10, 10 * n, 200, 200 );
p.drawLine ( xs, ys, xe, ye );
/// start of labeling.
if ( tempList[4] == "true" )
{
p.setClipRect ( windowRect );
xc = ( xs + xe ) / 2;
yc = ( ys + ye ) / 2;
if ( xs == xe ) angle = pi/2.0;
else if ( ys == ye ) angle = 0.0;
else
{
// angle = atan((double)(ye-ys)/(xe-xs)); /// Why did Qt 4 drop trig functions????
angle = ( double ) ( ye-ys ) / ( xe-xs ); /// hope this works!!!
angle /= 2.0 * pi ;
}
angle = ( angle * 180.0 ) / pi;
p.save();
p.translate ( xc, yc );
p.rotate ( angle ); //teErrorMessages->setText("F5 key clicked");
p.scale ( 1, -1 );
k = "S" + h.setNum ( n + 1 );
p.drawText ( 0, 0, k );
p.restore();
}
}
}
if ( paintColumns.count() > 0 )
{
p.setViewport ( viewportRect );
p.setWindow ( windowRect );
p.setClipRect ( windowRect );
for ( n = 0; n < paintColumns.count(); ++n )
{
k = paintColumns[n];
tempList = k.split ( "," );
xs = tempList[0].toInt ( &ok );
ys = tempList[1].toInt ( &ok );
xe = tempList[2].toInt ( &ok );
ye = tempList[3].toInt ( &ok );
angle = tempList[4].toInt ( &ok );
p.save();
p.translate ( xs, ys );
p.rotate ( angle );
p.fillRect ( -xe/2, -ye/2, xe, ye, Qt::black );
if ( tempList[5] == "true" )
{
f.setFamily ( "Courier" );
f.setPointSize ( ( int ) ( .8 * dwgScaleFactor ) );
p.setFont ( f );
pen.setBrush ( Qt::black );
p.setPen ( pen );
p.rotate ( -angle + 25 );
p.scale ( 1, -1 );
k = "---C" + h.setNum ( n + 1 );
p.drawText ( 0, 0, k );
}
p.restore();
}
}
}
}
#endif // MYDRAWINGFRAME_H
To copy to clipboard, switch view to plain text mode
Great, but how do I access it to set the values of the variables and activate the paint event itself??. If I "#include "mydrawingframe.h" in my "baseframe.cpp" or anyplace else for that matter I get an
Bookmarks