.h:
int startx,starty,endx,endy,addable,printed;
QPixmap originalPixmap;
//image where i draw QPixmap copyPixmap;
//temporary image QPixmap savePixmap;
//original image
.cpp:
{
startx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
starty=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
addable=1;
}
{
if(addable==1){
if(printed==1){
originalPixmap
=copyPixmap.
copy(QRect());
ui->label->setPixmap(originalPixmap);
}
painter.
setPen(QPen(Qt
::gray,
1, Qt
::DashLine, Qt
::RoundCap, Qt
::RoundJoin));
painter.drawRect(startx,
starty,
event->globalPos().x()-startx-offsetx+ui->scrollArea->horizontalScrollBar()->value(),
event->globalPos().y()-starty-offsety+ui->scrollArea->verticalScrollBar()->value() );
painter.end();
ui->label->setPixmap(originalPixmap);
printed=1;
}
}
{
printed=0;
originalPixmap
=copyPixmap.
copy(QRect());
ui->label->setPixmap(originalPixmap);
if(addable==1){
endx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
endy=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
addable=2;
connect(ui
->lineEdit,
SIGNAL(textChanged
(QString)),
this,
SLOT(checkText
(QString)));
}
}
.h:
int startx,starty,endx,endy,addable,printed;
QPixmap originalPixmap;//image where i draw
QPixmap copyPixmap;//temporary image
QPixmap savePixmap;//original image
QPen pen;
.cpp:
void Widget::mousePressEvent(QMouseEvent *event)
{
startx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
starty=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
addable=1;
QObject::disconnect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(checkText(QString)));
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
if(addable==1){
if(printed==1){
originalPixmap=copyPixmap.copy(QRect());
ui->label->setPixmap(originalPixmap);
}
QPainter painter(&originalPixmap);
painter.setPen(QPen(Qt::gray, 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin));
painter.drawRect(startx,
starty,
event->globalPos().x()-startx-offsetx+ui->scrollArea->horizontalScrollBar()->value(),
event->globalPos().y()-starty-offsety+ui->scrollArea->verticalScrollBar()->value() );
painter.end();
ui->label->setPixmap(originalPixmap);
printed=1;
}
}
void Widget::mouseReleaseEvent(QMouseEvent *event)
{
printed=0;
originalPixmap=copyPixmap.copy(QRect());
ui->label->setPixmap(originalPixmap);
if(addable==1){
endx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
endy=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
addable=2;
connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(checkText(QString)));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks