Results 1 to 9 of 9

Thread: Paint Rect visible on Drag to crop image coordinate

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Paint Rect visible on Drag to crop image coordinate

    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 :-(



    Or must i attach other event on drag???

    I wand this rect visible on drag mesure to select crop image ....

    Qt Code:
    1. void Image_Operator::paintEvent(QPaintEvent *e)
    2. {
    3.  
    4. if (display.isNull()) {
    5. qDebug() << "### display pixmap broken!!!! " << display.isNull();
    6. return;
    7. }
    8. qDebug() << "### paintEvent go starter...... ";
    9. Load_Actual_Desktop(); /* widget size setting e resolution X11 */
    10. int hi_now = widgetSize.height();
    11. int wi_now = widgetSize.width();
    12. picscaled = display.scaled(wi_now,hi_now,Qt::KeepAspectRatio); /* scaled to widget displayer */
    13. QSize actual_result = picscaled.size(); /* get */
    14. Ratio_On_Work(actual_result);
    15. QPainter painter(this);
    16. painter.drawPixmap(0,0,picscaled);
    17. QString selectionText;
    18. selectionText = QString("Image %1 x %2").arg(actual_result.width()).arg(actual_result.height());
    19.  
    20. QFontMetrics fm( this->font() );
    21. int stringWidth = fm.width(selectionText);
    22. int stringHeight = fm.ascent();
    23. const int TEXT_MARGIN = 4;
    24.  
    25. /* color to pen */
    26. QColor textColor = Qt::black;
    27. QColor fillrectcolor = Qt::red;
    28.  
    29. int textX = 0;
    30. int textY = 0;
    31.  
    32. /* display rect mesure image crop !!! */
    33. QPoint topLeft( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
    34. QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
    35. QPoint bottomRight( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
    36. QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
    37. QRect selectionIMAGE( topLeft, bottomRight );
    38. /* display rect mesure image crop !!! */
    39. /* display rect mesure text crop !!! */
    40. QPoint topLeftT( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
    41. QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
    42. QPoint bottomRightT( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
    43. QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
    44. QRect selectionTEXT( topLeftT, bottomRightT );
    45. /* display rect mesure text crop !!! */
    46.  
    47. QPen pen;
    48. pen.setStyle( Qt::SolidLine );
    49. pen.setCapStyle( Qt::RoundCap );
    50. pen.setColor( fillrectcolor );
    51. pen.setWidth( 2 );
    52. /* display rect to crop image !!! */
    53. painter.setPen( pen);
    54. painter.drawRect(selectionIMAGE);
    55. /* display rect to crop image !!! */
    56. /* display text image ratio text on crop image !!! */
    57. pen.setColor( textColor );
    58. painter.setPen( pen);
    59. /* display text image ratio text on crop image !!! */
    60. painter.drawText(selectionTEXT,selectionText);
    61. //////// Show_Actual_Params(); /* debug display coordinate all */
    62. }
    63.  
    64. void Image_Operator::mousePressEvent(QMouseEvent *e)
    65. {
    66. qDebug() << "### mousePressEvent -> " << e->x() << "x" << e->y();
    67. mousePRESSPoint = e->pos();
    68. }
    69. void Image_Operator::mouseReleaseEvent(QMouseEvent *e)
    70. {
    71. qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
    72. mouseRELEASEPoint = e->pos();
    73. }
    74.  
    75. void Image_Operator::mouseMoveEvent(QMouseEvent *e)
    76. {
    77. qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
    78. mouseMOVEPoint = e->pos();
    79. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 16th March 2007 at 15:56.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Paint Rect visible on Drag to crop image coordinate

    What exactly is the question? Could you prepare a minimal compilable example reproducing the problem?

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Paint Rect visible on Drag to crop image coordinate

    Quote Originally Posted by wysota View Post
    What exactly is the question? Could you prepare a minimal compilable example reproducing the problem?
    Here is a example wo reproducing .... the display widged to work on operation crop image...
    main.h
    main.cpp
    image_operator.h
    image_operator.cpp
    test.png
    qt profile

    http://ppk.ciz.ch/qt_c++/imagegrop.zip 300kb (one image 280kb inside)

    I found so mach sample from paint on qt wiki book or other .... never found a sample to simply crop or cut a part of a image....

    I wand to paint the red rectange on the drag process to display live on the selected rect to crop.... (same as gimp)
    not only on release mouse.....


    The target from this widged is only to find ...
    QImage* cropImage( QString filename, QPoint topLeft, QPoint bottomRight )

    I take sample base from http://albumshaper.sourceforge.net/

    http://ppk.ciz.ch/qt_c++/image_crop/ selectionInterface.cpp

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Paint Rect visible on Drag to crop image coordinate

    If you want to cut out part of an image (I assume this is your goal), just create a new image and paint a section of the previous one on the new one.

    Take a look at QPainter::drawImage that takes the source rectangle as its argument.

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Paint Rect visible on Drag to crop image coordinate

    Quote Originally Posted by wysota View Post
    If you want to cut out part of an image (I assume this is your goal), just create a new image and paint a section of the previous one on the new one.
    Take a look at QPainter::drawImage that takes the source rectangle as its argument.
    Yes the final target is Crop the image....

    ..... before i Want to display the -> painter.drawRect(selectionIMAGE);

    on event Move Mouse pull down rectangle the action to select the Crop ...

    Now my script display only the rectangle on resize .... mouse Out.....
    mouseReleaseEvent(QMouseEvent *e)

    Not on drag move action ... is here other event?

    Qt Code:
    1. //==============================================
    2. QImage* cropImage( QString filename, QPoint topLeft, QPoint bottomRight )
    3. {
    4. //load original image
    5. QImage origImage( filename );
    6.  
    7. //convert to 32-bit depth if necessary
    8. if( origImage.depth() < 32 ) { origImage = origImage.convertDepth( 32, Qt::AutoColor ); }
    9.  
    10. //construct cropped image
    11. QImage* croppedImage = new QImage(bottomRight.x() - topLeft.x() + 1,
    12. bottomRight.y() - topLeft.y() + 1,
    13. origImage.depth());
    14.  
    15. //iterate over each selected scanline
    16. int xOrig, yOrig;
    17. int xCropped, yCropped;
    18. uchar *origScanLine, *croppedScanLine;
    19.  
    20. for( yOrig=topLeft.y(),yCropped=0; yOrig<=bottomRight.y(); yOrig++, yCropped++)
    21. {
    22. //iterate over each selected pixel in scanline
    23. origScanLine = origImage.scanLine(yOrig);
    24. croppedScanLine = croppedImage->scanLine(yCropped);
    25.  
    26. for( xOrig=topLeft.x(),xCropped=0; xOrig<=bottomRight.x(); xOrig++,xCropped++)
    27. {
    28. //copy pixel color from original image to cropped image
    29. *((QRgb*)croppedScanLine+xCropped) = *((QRgb*)origScanLine+xOrig);
    30. }
    31. }
    32.  
    33. //return pointer to cropped image
    34. return croppedImage;
    35. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Paint Rect visible on Drag to crop image coordinate

    Maybe it will be easier if you use QRubberBand?

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Paint Rect visible on Drag to crop image coordinate

    Quote Originally Posted by jacek View Post
    Maybe it will be easier if you use QRubberBand?
    Crasch app maybe QRubberBand and paintEvent is not able to live together....
    && i wand to display text pixel size to crop.... on top of rectange

    i test now to split action & switch paint mode...

    && QWidget:aintEngine ()


    typedef enum
    {
    DRAW_SELECTION,
    MOVE_SELECTION,
    MOVE_TOP_LEFT_CORNER,
    MOVE_TOP_RIGHT_CORNER,
    MOVE_BOTTOM_LEFT_CORNER,
    MOVE_BOTTOM_RIGHT_CORNER,
    MOVE_LEFT_SIDE,
    MOVE_RIGHT_SIDE,
    MOVE_TOP_SIDE,
    MOVE_BOTTOM_SIDE,
    SCALE_SELECTION,
    DRAW_LINE,
    KEYBOARD_CTRL,
    NO_EFFECT
    } DRAG_MODE;

  8. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Paint Rect visible on Drag to crop image coordinate

    I have it .... the solution is only repaint on mouseMoveEvent && define each DRAG_MODE
    on widged....

    Qt Code:
    1. typedef enum
    2. {
    3. DRAW_SELECTION,
    4. SCALE_SELECTION,
    5. DRAW_LINE,
    6. DRAW_START,
    7. NO_EFFECT
    8. } DRAG_MODE;
    9.  
    10.  
    11.  
    12. void Image_Operator::mouseMoveEvent(QMouseEvent *e)
    13. {
    14. currentDragMode = DRAW_LINE;
    15. mouseRELEASEPoint = e->pos();
    16. if (display.isNull()) {
    17. return;
    18. }
    19.  
    20. /* remove draw lines */
    21. Load_Actual_Desktop(); /* widget size setting e resolution X11 */
    22. int hi_now = widgetSize.height();
    23. int wi_now = widgetSize.width();
    24.  
    25. QPoint topLeft( 0 , 0 );
    26. QPoint bottomRight( widgetSize.width() , widgetSize.height() );
    27. QRect areanow( topLeft, bottomRight );
    28. repaint(areanow);
    29. }
    30.  
    31. if ( currentDragMode == DRAW_SELECTION || currentDragMode == DRAW_LINE ) {
    32. OneWorkImage = selectionIMAGE;
    33. pen.setWidth( bordershade );
    34. pen.setColor( shapepicture );
    35. painter.setPen( pen);
    36. painter.drawRect(selectionOutIMAGE);
    37. /* ................... draw rectangle or only image display on the Zoom Widged && resizable ....*/
    To copy to clipboard, switch view to plain text mode 

    source & PrtScn avaiable....

    http://www.qtforum.de/forum/viewtopic.php?t=3885

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Paint Rect visible on Drag to crop image coordinate

    Please try to express yourself with simple and full sentences, without "...", abreviations, images or code that distract the reader from the topic of your post - especially if you're not sure of your English language skills. Using such constructions makes your post barely readable and hardly understandable. So does including a large amount of code that doesn't add anything to the conversation. If you have to paste some of your code, please remove parts that are not important.

    I have to say that after reading this thread a few times I still don't know what the problem was. The thread title suggests problems with cropping an image, but the thread content implies something completely different.

  10. The following user says thank you to wysota for this useful post:

    patrik08 (17th March 2007)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.