Results 1 to 10 of 10

Thread: QTextImageFormat HTML not write <img width= height>

  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 QTextImageFormat HTML not write <img width= height>

    I have build a small html editor (to append on a CMS - CRM ) that load automatic image remote or local in to local Cache
    and i enable drag in image or text/html text/plain and to edit all text attribute also table ...... but now i have problem on
    image attribute width="xxx" height="xxx" ..

    On Edit::RContext( const QPoint & pos ) (Contex menu) i grab QTextImageFormat from image i open Image_mod_Setting() on a
    dialog and i edit image large height and save image and i send back QTextImageFormat and my problem ....

    QTextImageFormat not write the new width="xxx" height="xxx" !!

    On QTextTableFormat runn all ok and set all attribute correct padding bgcolor spacing ecc... and QTextImageFormat no! why?







    Qt Code:
    1. void Edit::Image_mod_Setting()
    2. {
    3. /* QTextImageFormat nowimage; */
    4. if (nowimage.isValid()) {
    5. Edit_Image::self( this )->SetFormat(nowimage);
    6. Edit_Image::self( this )->exec();
    7. QTextImageFormat newforminepic = Edit_Image::self( this )->GetFormat();
    8. if (newforminepic.isValid()) {
    9. nowimage = newforminepic;
    10. qDebug() << "### Draw image h ... " << nowimage.height();
    11. qDebug() << "### Draw image w... " << nowimage.width();
    12. }
    13. }
    14.  
    15. }
    16.  
    17.  
    18.  
    19.  
    20.  
    21.  
    22. void Edit::RContext( const QPoint & pos )
    23. {
    24. ////////////////qDebug() << "### contextMenuEvent " << pos;
    25. Eframe = false;
    26. Eimage = false;
    27. Etable = false;
    28.  
    29. QTextCursor findercursor(wtext->textCursor());
    30. Eframe = findercursor.currentFrame();
    31. nowimage = findercursor.charFormat().toImageFormat();
    32. nowtable = findercursor.currentTable();
    33. Eimage = nowimage.isValid();
    34. Etable = findercursor.currentTable();
    35. qDebug() << "### Eframe " << Eframe;
    36. qDebug() << "### Eimage " << Eimage;
    37. qDebug() << "### Etable " << Etable;
    38. TContext = new QMenu(this);
    39. if (editrun) {
    40. TContext->addAction(tr( "View Modus" ), this , SLOT( ShowModusPanelView() ) );
    41. TtableContext = new QMenu(tr("Table edit or new "),TContext);
    42. TtableContext->addAction(tr( "Insert Table here" ), this , SLOT( CreateanewTable() ) );
    43. if (findercursor.currentTable()) {
    44. TtableContext->addAction(tr( "Table (this) Propriety BackgroundColor, Padding, Spacing" ), this , SLOT( TableSetting() ) );
    45. TtableContext->addAction(tr( "Merge selected cell (if select)" ), this , SLOT( MergeCellByCursorPosition() ) );
    46. TtableContext->addAction(tr( "Append Row on this table" ), this , SLOT( AppendTableRows() ) );
    47. TtableContext->addAction(tr( "Append Cools on this table" ), this , SLOT( AppendTableCools() ) );
    48. TtableContext->addAction(tr( "Remove this row" ), this , SLOT( RemoveRowByCursorPosition() ) );
    49. TtableContext->addAction(tr( "Remove this cool" ), this , SLOT( RemoveCoolByCursorPosition() ) );
    50. }
    51. TContext->addAction(TtableContext->menuAction());
    52. TimageContext = new QMenu(tr("Image edit or new "),TContext);
    53. TimageContext->addAction(tr( "Insert new image" ), this , SLOT( CreateanewImage() ) );
    54. if (Eimage) {
    55. QString picname = nowimage.name();
    56. QFileInfo locinfo(picname);
    57. TimageContext->addAction(tr( "Image edit \"%1\" width - height" ).arg(locinfo.fileName()), this , SLOT( Image_mod_Setting() ) );
    58. }
    59. TContext->addAction(TimageContext->menuAction());
    60. } else {
    61. TContext->addAction(tr( "Edit Modus" ), this , SLOT( ShowModusPanelEdit() ) );
    62. }
    63.  
    64.  
    65. /* ..cute past & source view ecc........ */
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 7th February 2007 at 13:41. Reason: reformatted to look better

  2. #2
    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: QTextImageFormat HTML not write <img width= height>

    What does Edit_Image::self( this )->GetFormat() do?

  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: QTextImageFormat HTML not write <img width= height>

    Quote Originally Posted by jacek View Post
    What does Edit_Image::self( this )->GetFormat() do?
    is return the old QTextImageFormat .... + new height() width() name stay same....

    here is dialog ... on qtexttable format its work wonderfull on same way ....
    i put QTextTableFormat to dialog modify attribute and get return ... in one way
    no signal or emit ....

    Qt Code:
    1. #include "edit_image.h"
    2. //
    3. /* Save file as edit_image.cpp */
    4. /* incomming class name Edit_Image */
    5. //
    6. #include <QCloseEvent>
    7. //
    8. QPointer<Edit_Image> Edit_Image::_self = 0L;
    9. //
    10. Edit_Image* Edit_Image::self( QWidget* parent )
    11. {
    12. if ( !_self )
    13. _self = new Edit_Image( parent );
    14. return _self;
    15. }
    16. //
    17. Edit_Image::Edit_Image( QWidget* parent )
    18. : QDialog( parent )
    19. {
    20. setupUi( this );
    21. Load_Connector();
    22. }
    23. //
    24. void Edit_Image::Load_Connector()
    25. {
    26. /* to nothing */
    27. /*connect(buttonx, SIGNAL(clicked()), this , SLOT(Make()));*/
    28. onwi = false;
    29. }
    30.  
    31.  
    32. void Edit_Image::SetFormat( QTextImageFormat e )
    33. {
    34. nowimage = e;
    35. imagefullpath = nowimage.name();
    36. ////////////qDebug() << "### imagefullpath " << imagefullpath;
    37.  
    38. fileName = imagefullpath;
    39. if (!fileName.isEmpty()) {
    40. image.load(fileName);
    41. if (image.isNull()) {
    42. QMessageBox::warning(this, tr("Error:"), tr("Unable to load image file %1.").arg(fileName));
    43. close();
    44. return;
    45. }
    46. } else {
    47. QMessageBox::warning(this, tr("Error:"), tr("Unable to load image file %1.").arg(fileName));
    48. close();
    49. return;
    50. }
    51.  
    52. connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(Modpicsw(int)));
    53. connect(horizontalSlider_2, SIGNAL(valueChanged(int)), this, SLOT(Modpicsh(int)));
    54. picco->setPixmap(QPixmap::fromImage(image));
    55. int serial = image.serialNumber();
    56. ////////////qDebug() << "### Draw image... " << serial;
    57. picco->adjustSize();
    58. actual = picco->pixmap()->size();
    59. wi = actual.width();
    60. largestart = wi;
    61. hi = actual.height();
    62. spinBox->setValue(wi);
    63. spinBox_2->setValue(hi);
    64.  
    65.  
    66.  
    67. ////////QFileInfo locinfo(picname);
    68. }
    69.  
    70.  
    71. void Edit_Image::SavePicimage()
    72. {
    73. int large = spinBox->value();
    74.  
    75. if (largestart != large) {
    76.  
    77. QString saveto = imagefullpath;
    78. QFileInfo ImageInfo(saveto);
    79. QString ext = ImageInfo.completeSuffix();
    80. QByteArray ba = ext.toAscii();
    81. if (!imagefullpath.isEmpty()) {
    82.  
    83. if (large > 19) {
    84. QPixmap picsa(imagefullpath);
    85. QPixmap resized = picsa.scaledToWidth(large);
    86. resized.save(saveto,ba.data(),80);
    87. return;
    88. }
    89. }
    90. }
    91. }
    92.  
    93. QTextImageFormat Edit_Image::GetFormat()
    94. {
    95. int swi = spinBox->value();
    96. int shi = spinBox_2->value();
    97. nowimage.setHeight(shi);
    98. nowimage.setWidth(swi);
    99. SavePicimage();
    100. return nowimage;
    101. }
    102.  
    103. void Edit_Image::Modpicsw( int w )
    104. {
    105. if (!onwi) {
    106. ModpicsChangedWI(w,1);
    107. }
    108. }
    109. void Edit_Image::Modpicsh( int w )
    110. {
    111. if (!onwi) {
    112. ModpicsChangedWI(w,0);
    113. }
    114. }
    115.  
    116. void Edit_Image::ModpicsChangedWI(int newvalue_w , int modus ) /* int from QSlider 20px steeps miniumu 150 max pics width() */
    117. {
    118. QPixmap scaled;
    119. onwi = true;
    120. QPixmap pic(imagefullpath);
    121. if (modus == 1) {
    122. scaled = pic.scaledToWidth(newvalue_w);
    123. } else {
    124. scaled = pic.scaledToHeight(newvalue_w);
    125. }
    126. picco->setPixmap(scaled); /* label */
    127. picco->adjustSize(); /* label */
    128. actual = picco->pixmap()->size();
    129. wi = actual.width();
    130. hi = actual.height();
    131.  
    132. if (modus == 1) {
    133. spinBox_2->setValue(hi);
    134. } else {
    135. spinBox->setValue(wi);
    136. }
    137. onwi = false;
    138.  
    139. }
    140.  
    141. void Edit_Image::closeEvent( QCloseEvent* e )
    142. {
    143. e->accept();
    144. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: QTextImageFormat HTML not write <img width= height>

    Quote Originally Posted by patrik08 View Post
    QTextImageFormat Edit_Image::GetFormat()
    {
    int swi = spinBox->value();
    int shi = spinBox_2->value();
    nowimage.setHeight(shi);
    nowimage.setWidth(swi);
    SavePicimage();
    return nowimage;
    }
    What are the values of swi and shi in this method?

  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: QTextImageFormat HTML not write <img width= height>

    Quote Originally Posted by jacek View Post
    What are the values of swi and shi in this method?

    int swi = spinBox->value(); /* width spinbox & qsliderhorrizzonat */
    int shi = spinBox_2->value(); /* height spinbox & qsliderhorrizzonat */

    swi white in pixel int
    shi height in pixel int

    from qpixmap resize operation and QSize actual;

    on mainwindow ...

    Qt Code:
    1. QTextImageFormat newforminepic = Edit_Image::self( this )->GetFormat();
    2. if (newforminepic.isValid()) {
    3. nowimage = newforminepic;
    4. qDebug() << "### Draw image h ... " << nowimage.height();
    5. qDebug() << "### Draw image w... " << nowimage.width();
    To copy to clipboard, switch view to plain text mode 

    debug out console is correct value new value is valid ....but on tag is only <img src="path...">


    void QTextImageFormat::setHeight ( qreal height ) i put int not qreal and work ok...

  6. #6
    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: QTextImageFormat HTML not write <img width= height>

    Quote Originally Posted by jacek View Post
    What are the values of swi and shi in this method?
    on ubuntu linux is running but not the img tag and drag image in render other mime...???.
    on window if i drag a image from firefox to apps is work .+ html .. not on linux.... && img....

    ## 65KB
    wget http://ppk.ciz.ch/qt_c++/html_edit.tar.gz
    ## curl -O http://ppk.ciz.ch/qt_c++/html_edit.tar.gz
    tar -zxvf html_edit.tar.gz
    cd html_edit && qmake && make

    ## pro file app destdir is ./ not desktop...
    Last edited by patrik08; 7th February 2007 at 23:42.

  7. #7
    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: QTextImageFormat HTML not write <img width= height>

    Quote Originally Posted by patrik08 View Post
    debug out console is correct value new value is valid ....but on tag is only <img src="path...">.
    Where do you actually use "nowimage" as the format for your image?

  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: QTextImageFormat HTML not write <img width= height>

    Quote Originally Posted by jacek View Post
    Where do you actually use "nowimage" as the format for your image?

    QTextImageFormat nowimage;

    Contain all image data can extract and reinsert ....
    1 - NAME *** path
    2 - name from resource
    3 - can save height
    4 -weight

    + info from
    doc->addResource( QTextDocument::ImageResource, QUrl(filename), QPixmap(QString("%1%_%2").arg(registername).arg(im posi)) );

    on load html i RegExp

    QRegExp expression( "src=[\"\'](.*)[\"\']", Qt::CaseInsensitive );
    expression.setMinimal(true);

    all image list and download remote image to cache and local image go to cache ....
    why? i prepare all image to same dir to zip & upload after on remote cms dir ...
    and i must only replace cache dir with the remote dir path.....
    to edit or reedit i get the remote zip to cache image....

    How You chance wieth height attribute on img tag? all img to QRegExp

    Why #include "table_setting.h" run so clean and chance all table attribute? + cell row ecc...

    QTextTableFormat & QTextImageFormat have different Target .. to usage?

  9. #9
    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: QTextImageFormat HTML not write <img width= height>

    Where do you change the format of an image that is already in the document? Because it seems that you never use the information stored in "nowimage".

  10. #10
    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: QTextImageFormat HTML not write <img width= height>

    Quote Originally Posted by jacek View Post
    Where do you change the format of an image that is already in the document? "nowimage".
    Yes i reformat .... image inside qtextbrowser .... & not open other apps photoshop or so... the image must stay on html size ... and not waist time to other photoshop or gimp action...

    table i reformat so ... is run OK super....

    Qt Code:
    1. void Edit::TableSetting()
    2. {
    3. QTextCursor findercursor(wtext->textCursor());
    4. Etable = findercursor.currentTable();
    5. if (Etable) {
    6. Table_Setting::self( this )->SetFormat(nowtable);
    7. Table_Setting::self( this )->exec();
    8. QTextTableFormat newformine = Table_Setting::self( this )->GetNewFormats(); /* incomming other attribute by table .... from dialog */
    9. if (newformine.isValid()) {
    10. nowtable->setFormat(newformine); /* nowtable = QTextTable */
    11. }
    12. }
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    Image i reformat so .... and run image have new size small or bigger is ok.....

    &&& <img src="tanzbaer.gif" width="368" height="383" >
    only width="368" height not write .....

    If i put on tidy lib only alt can append..... ... i hope the problem or bug is solved on
    http://www.trolltech.com/developer/t...ntry&id=149069


    QTextTable -> setformat ( QTextTableFormat ) run ok....

    QTextImage -> setformat (QTextImageFormat ) class QTextImage not present on qt4.2 .
    && lastcursor.setCharFormat(newforminepic); run only 1/2


    Qt Code:
    1. void Edit::Image_mod_Setting()
    2. {
    3. /* QTextImageFormat nowimage; */
    4. if (nowimage.isValid()) {
    5. Edit_Image::self( this )->SetFormat(nowimage);
    6. Edit_Image::self( this )->exec();
    7. QTextImageFormat newforminepic = Edit_Image::self( this )->GetFormat();
    8. if (newforminepic.isValid()) {
    9. ////////////nowimage = newforminepic;
    10. /* QTextCursor lastcursor; ( last cursor from action ) */
    11. lastcursor.setCharFormat(newforminepic);
    12. qDebug() << "### Draw image h ... " << nowimage.height();
    13. qDebug() << "### Draw image w... " << nowimage.width();
    14. Reload_Editor(); /* repaint new size from image and go back to last QScrollBar *wysiwyg_sroll; int value setvalue(int)*/
    15. /* http://www.qtcentre.org/forum/f-qt-programming-2/t-loading-images-in-qtextbrowser-5046.html/?highlight=QTextImageFormat */
    16. }
    17. }
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 8th February 2007 at 02:05.

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.