class TextFrame
: public QFrame
{
protected:
private:
bool erase;
int CounterOfPoint ;
Point Points [MaxPoint];
public:
~TextFrame();
};
//********************************
// Definition of Destructor
//********************************
TextFrame::~TextFrame()
{
}
//********************************
// Definition of Constructor
//********************************
{
_buffer = a ;
CounterOfPoint = 0 ;
}
void TextFrame :: EraseAll()
{
CounterOfPoint = 0 ;
// this solve problem only when I erase all things in frame, but
// if I erase some thing problem still there ..
_buffer
= * (QWidget::erasePixmap()) ;
QWidget::setErasePixmap( _buffer
) ;
}
{
bitBlt(this , 0 , 0 , &_buffer) ;
}
//********************************
// Definition of mousePressEvent
//********************************
{
// write on frame :
if ( erase == false )
{
_last = e->pos();
// Add point to array of points
Points [CounterOfPoint].x = _last.x() ;
Points [CounterOfPoint].y = _last.y() ;
CounterOfPoint++;
pen.setWidth ( _currentSize) ;
pen.setColor (_currentColor);
windowpainter.begin (this) ;
bufferpainter.begin(& _buffer) ;
windowpainter.setPen (pen);
bufferpainter.setPen (pen);
windowpainter.drawPoint(_last);
windowpainter.end() ;
bufferpainter.end () ;
}
// erase from frame :
else
CheckEraseSize(e);
} //end if
//********************************
// Definition of mouseMoveEvent
//********************************
{
// write on frame :
if ( erase == false )
{
// set size and color
pen.setWidth ( _currentSize) ;
pen.setColor (_currentColor);
// begin writing in buffer and in frame
windowpainter.begin (this) ;
bufferpainter.begin(& _buffer) ;
// pass pen to painter
windowpainter.setPen (pen);
bufferpainter.setPen (pen);
//draw line
windowpainter.drawLine(_last,e->pos());
bufferpainter.drawLine(_last,e->pos()) ;
//end buffer and painter
windowpainter.end() ;
bufferpainter.end () ;
// refresh the last point
_last= e->pos();
// Add point to array of points
Points [CounterOfPoint].x = _last.x() ;
Points [CounterOfPoint].y = _last.y() ;
CounterOfPoint++;
}
// erase from frame :
else
CheckEraseSize(e);
}
{
_buffer.resize ( event -> size () ) ;
bitBlt ( &_buffer , 0, 0 , &save ) ;
{
int x = e-> x() ;
int y = e-> y() ;
const QRegion Re
(x
-sizeErase,y
-sizeErase,sizeErase
*2,sizeErase
*2,
QRegion::Ellipse);
class TextFrame : public QFrame
{
protected:
void paintEvent(QPaintEvent *e);
void mousePressEvent( QMouseEvent *e );
void mouseMoveEvent( QMouseEvent *e );
void resizeEvent ( QResizeEvent * event) ;
private:
QPainter windowpainter;
QPainter bufferpainter;
QPen pen ;
QPoint _last;
QPixmap _buffer ;
QPixmap _erase ;
bool erase;
int CounterOfPoint ;
Point Points [MaxPoint];
public:
TextFrame(QWidget *parent);
~TextFrame();
void CheckEraseSize(QMouseEvent *e);
};
//********************************
// Definition of Destructor
//********************************
TextFrame::~TextFrame()
{
}
//********************************
// Definition of Constructor
//********************************
TextFrame::TextFrame(QWidget *parent) : QFrame(parent)
{
QPixmap a ( QPixmap("T.jpg") ) ;
_buffer = a ;
CounterOfPoint = 0 ;
}
void TextFrame :: EraseAll()
{
CounterOfPoint = 0 ;
QWidget::erase();
// this solve problem only when I erase all things in frame, but
// if I erase some thing problem still there ..
_buffer = * (QWidget::erasePixmap()) ;
QWidget::setErasePixmap( _buffer ) ;
}
void TextFrame :: paintEvent(QPaintEvent*)
{
bitBlt(this , 0 , 0 , &_buffer) ;
}
//********************************
// Definition of mousePressEvent
//********************************
void TextFrame::mousePressEvent( QMouseEvent * e )
{
// write on frame :
if ( erase == false )
{
_last = e->pos();
// Add point to array of points
Points [CounterOfPoint].x = _last.x() ;
Points [CounterOfPoint].y = _last.y() ;
CounterOfPoint++;
pen.setWidth ( _currentSize) ;
pen.setColor (_currentColor);
windowpainter.begin (this) ;
bufferpainter.begin(& _buffer) ;
windowpainter.setPen (pen);
bufferpainter.setPen (pen);
windowpainter.drawPoint(_last);
windowpainter.end() ;
bufferpainter.end () ;
}
// erase from frame :
else
CheckEraseSize(e);
} //end if
//********************************
// Definition of mouseMoveEvent
//********************************
void TextFrame::mouseMoveEvent( QMouseEvent *e )
{
// write on frame :
if ( erase == false )
{
// set size and color
pen.setWidth ( _currentSize) ;
pen.setColor (_currentColor);
// begin writing in buffer and in frame
windowpainter.begin (this) ;
bufferpainter.begin(& _buffer) ;
// pass pen to painter
windowpainter.setPen (pen);
bufferpainter.setPen (pen);
//draw line
windowpainter.drawLine(_last,e->pos());
bufferpainter.drawLine(_last,e->pos()) ;
//end buffer and painter
windowpainter.end() ;
bufferpainter.end () ;
// refresh the last point
_last= e->pos();
// Add point to array of points
Points [CounterOfPoint].x = _last.x() ;
Points [CounterOfPoint].y = _last.y() ;
CounterOfPoint++;
}
// erase from frame :
else
CheckEraseSize(e);
}
void TextFrame :: resizeEvent ( QResizeEvent * event)
{
QPixmap save ( _buffer ) ;
_buffer.resize ( event -> size () ) ;
bitBlt ( &_buffer , 0, 0 , &save ) ;
}void TextFrame :: CheckEraseSize(QMouseEvent *e)
{
int x = e-> x() ;
int y = e-> y() ;
const QRegion Re(x-sizeErase,y-sizeErase,sizeErase*2,sizeErase*2,QRegion::Ellipse);
QWidget::erase(Re);
To copy to clipboard, switch view to plain text mode
Bookmarks