patrik08
16th March 2007, 14:39
PS: my first QPainter not run...
I made a extra QWidget scaled on ratio image... to display a red rect to crop a simple image....
but now this paint is visible only if i resize the widged :-(
http://ppk.ciz.ch/qt_c++/crop_selecter.png
Or must i attach other event on drag???
I wand this rect visible on drag mesure to select crop image ....
void Image_Operator::paintEvent(QPaintEvent *e)
{
if (display.isNull()) {
qDebug() << "### display pixmap broken!!!! " << display.isNull();
return;
}
qDebug() << "### paintEvent go starter...... ";
Load_Actual_Desktop(); /* widget size setting e resolution X11 */
int hi_now = widgetSize.height();
int wi_now = widgetSize.width();
picscaled = display.scaled(wi_now,hi_now,Qt::KeepAspectRatio); /* scaled to widget displayer */
QSize actual_result = picscaled.size(); /* get */
Ratio_On_Work(actual_result);
QPainter painter(this);
painter.drawPixmap(0,0,picscaled);
QString selectionText;
selectionText = QString("Image %1 x %2").arg(actual_result.width()).arg(actual_result.hei ght());
QFontMetrics fm( this->font() );
int stringWidth = fm.width(selectionText);
int stringHeight = fm.ascent();
const int TEXT_MARGIN = 4;
/* color to pen */
QColor textColor = Qt::black;
QColor fillrectcolor = Qt::red;
int textX = 0;
int textY = 0;
/* display rect mesure image crop !!! */
QPoint topLeft( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
QPoint bottomRight( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
QRect selectionIMAGE( topLeft, bottomRight );
/* display rect mesure image crop !!! */
/* display rect mesure text crop !!! */
QPoint topLeftT( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
QPoint bottomRightT( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
QRect selectionTEXT( topLeftT, bottomRightT );
/* display rect mesure text crop !!! */
QPen pen;
pen.setStyle( Qt::SolidLine );
pen.setCapStyle( Qt::RoundCap );
pen.setColor( fillrectcolor );
pen.setWidth( 2 );
/* display rect to crop image !!! */
painter.setPen( pen);
painter.drawRect(selectionIMAGE);
/* display rect to crop image !!! */
/* display text image ratio text on crop image !!! */
pen.setColor( textColor );
painter.setPen( pen);
/* display text image ratio text on crop image !!! */
painter.drawText(selectionTEXT,selectionText);
//////// Show_Actual_Params(); /* debug display coordinate all */
}
void Image_Operator::mousePressEvent(QMouseEvent *e)
{
qDebug() << "### mousePressEvent -> " << e->x() << "x" << e->y();
mousePRESSPoint = e->pos();
}
void Image_Operator::mouseReleaseEvent(QMouseEvent *e)
{
qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
mouseRELEASEPoint = e->pos();
}
void Image_Operator::mouseMoveEvent(QMouseEvent *e)
{
qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
mouseMOVEPoint = e->pos();
}
I made a extra QWidget scaled on ratio image... to display a red rect to crop a simple image....
but now this paint is visible only if i resize the widged :-(
http://ppk.ciz.ch/qt_c++/crop_selecter.png
Or must i attach other event on drag???
I wand this rect visible on drag mesure to select crop image ....
void Image_Operator::paintEvent(QPaintEvent *e)
{
if (display.isNull()) {
qDebug() << "### display pixmap broken!!!! " << display.isNull();
return;
}
qDebug() << "### paintEvent go starter...... ";
Load_Actual_Desktop(); /* widget size setting e resolution X11 */
int hi_now = widgetSize.height();
int wi_now = widgetSize.width();
picscaled = display.scaled(wi_now,hi_now,Qt::KeepAspectRatio); /* scaled to widget displayer */
QSize actual_result = picscaled.size(); /* get */
Ratio_On_Work(actual_result);
QPainter painter(this);
painter.drawPixmap(0,0,picscaled);
QString selectionText;
selectionText = QString("Image %1 x %2").arg(actual_result.width()).arg(actual_result.hei ght());
QFontMetrics fm( this->font() );
int stringWidth = fm.width(selectionText);
int stringHeight = fm.ascent();
const int TEXT_MARGIN = 4;
/* color to pen */
QColor textColor = Qt::black;
QColor fillrectcolor = Qt::red;
int textX = 0;
int textY = 0;
/* display rect mesure image crop !!! */
QPoint topLeft( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
QPoint bottomRight( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
QRect selectionIMAGE( topLeft, bottomRight );
/* display rect mesure image crop !!! */
/* display rect mesure text crop !!! */
QPoint topLeftT( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
QPoint bottomRightT( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
QRect selectionTEXT( topLeftT, bottomRightT );
/* display rect mesure text crop !!! */
QPen pen;
pen.setStyle( Qt::SolidLine );
pen.setCapStyle( Qt::RoundCap );
pen.setColor( fillrectcolor );
pen.setWidth( 2 );
/* display rect to crop image !!! */
painter.setPen( pen);
painter.drawRect(selectionIMAGE);
/* display rect to crop image !!! */
/* display text image ratio text on crop image !!! */
pen.setColor( textColor );
painter.setPen( pen);
/* display text image ratio text on crop image !!! */
painter.drawText(selectionTEXT,selectionText);
//////// Show_Actual_Params(); /* debug display coordinate all */
}
void Image_Operator::mousePressEvent(QMouseEvent *e)
{
qDebug() << "### mousePressEvent -> " << e->x() << "x" << e->y();
mousePRESSPoint = e->pos();
}
void Image_Operator::mouseReleaseEvent(QMouseEvent *e)
{
qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
mouseRELEASEPoint = e->pos();
}
void Image_Operator::mouseMoveEvent(QMouseEvent *e)
{
qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
mouseMOVEPoint = e->pos();
}