PDA

View Full Version : QTextImageFormat HTML not write <img width= height>



patrik08
7th February 2007, 11:37
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?












void Edit::Image_mod_Setting()
{
/* QTextImageFormat nowimage; */
if (nowimage.isValid()) {
Edit_Image::self( this )->SetFormat(nowimage);
Edit_Image::self( this )->exec();
QTextImageFormat newforminepic = Edit_Image::self( this )->GetFormat();
if (newforminepic.isValid()) {
nowimage = newforminepic;
qDebug() << "### Draw image h ... " << nowimage.height();
qDebug() << "### Draw image w... " << nowimage.width();
}
}

}






void Edit::RContext( const QPoint & pos )
{
////////////////qDebug() << "### contextMenuEvent " << pos;
Eframe = false;
Eimage = false;
Etable = false;

QTextCursor findercursor(wtext->textCursor());
Eframe = findercursor.currentFrame();
nowimage = findercursor.charFormat().toImageFormat();
nowtable = findercursor.currentTable();
Eimage = nowimage.isValid();
Etable = findercursor.currentTable();
qDebug() << "### Eframe " << Eframe;
qDebug() << "### Eimage " << Eimage;
qDebug() << "### Etable " << Etable;
TContext = new QMenu(this);
if (editrun) {
TContext->addAction(tr( "View Modus" ), this , SLOT( ShowModusPanelView() ) );
TtableContext = new QMenu(tr("Table edit or new "),TContext);
TtableContext->addAction(tr( "Insert Table here" ), this , SLOT( CreateanewTable() ) );
if (findercursor.currentTable()) {
TtableContext->addAction(tr( "Table (this) Propriety BackgroundColor, Padding, Spacing" ), this , SLOT( TableSetting() ) );
TtableContext->addAction(tr( "Merge selected cell (if select)" ), this , SLOT( MergeCellByCursorPosition() ) );
TtableContext->addAction(tr( "Append Row on this table" ), this , SLOT( AppendTableRows() ) );
TtableContext->addAction(tr( "Append Cools on this table" ), this , SLOT( AppendTableCools() ) );
TtableContext->addAction(tr( "Remove this row" ), this , SLOT( RemoveRowByCursorPosition() ) );
TtableContext->addAction(tr( "Remove this cool" ), this , SLOT( RemoveCoolByCursorPosition() ) );
}
TContext->addAction(TtableContext->menuAction());
TimageContext = new QMenu(tr("Image edit or new "),TContext);
TimageContext->addAction(tr( "Insert new image" ), this , SLOT( CreateanewImage() ) );
if (Eimage) {
QString picname = nowimage.name();
QFileInfo locinfo(picname);
TimageContext->addAction(tr( "Image edit \"%1\" width - height" ).arg(locinfo.fileName()), this , SLOT( Image_mod_Setting() ) );
}
TContext->addAction(TimageContext->menuAction());
} else {
TContext->addAction(tr( "Edit Modus" ), this , SLOT( ShowModusPanelEdit() ) );
}


/* ..cute past & source view ecc........ */

jacek
7th February 2007, 14:38
What does Edit_Image::self( this )->GetFormat() do?

patrik08
7th February 2007, 23:35
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 ....




#include "edit_image.h"
//
/* Save file as edit_image.cpp */
/* incomming class name Edit_Image */
//
#include <QCloseEvent>
//
QPointer<Edit_Image> Edit_Image::_self = 0L;
//
Edit_Image* Edit_Image::self( QWidget* parent )
{
if ( !_self )
_self = new Edit_Image( parent );
return _self;
}
//
Edit_Image::Edit_Image( QWidget* parent )
: QDialog( parent )
{
setupUi( this );
Load_Connector();
}
//
void Edit_Image::Load_Connector()
{
/* to nothing */
/*connect(buttonx, SIGNAL(clicked()), this , SLOT(Make()));*/
onwi = false;
}


void Edit_Image::SetFormat( QTextImageFormat e )
{
nowimage = e;
imagefullpath = nowimage.name();
////////////qDebug() << "### imagefullpath " << imagefullpath;

fileName = imagefullpath;
if (!fileName.isEmpty()) {
image.load(fileName);
if (image.isNull()) {
QMessageBox::warning(this, tr("Error:"), tr("Unable to load image file %1.").arg(fileName));
close();
return;
}
} else {
QMessageBox::warning(this, tr("Error:"), tr("Unable to load image file %1.").arg(fileName));
close();
return;
}

connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(Modpicsw(int)));
connect(horizontalSlider_2, SIGNAL(valueChanged(int)), this, SLOT(Modpicsh(int)));
picco->setPixmap(QPixmap::fromImage(image));
int serial = image.serialNumber();
////////////qDebug() << "### Draw image... " << serial;
picco->adjustSize();
actual = picco->pixmap()->size();
wi = actual.width();
largestart = wi;
hi = actual.height();
spinBox->setValue(wi);
spinBox_2->setValue(hi);



////////QFileInfo locinfo(picname);
}


void Edit_Image::SavePicimage()
{
int large = spinBox->value();

if (largestart != large) {

QString saveto = imagefullpath;
QFileInfo ImageInfo(saveto);
QString ext = ImageInfo.completeSuffix();
QByteArray ba = ext.toAscii();
if (!imagefullpath.isEmpty()) {

if (large > 19) {
QPixmap picsa(imagefullpath);
QPixmap resized = picsa.scaledToWidth(large);
resized.save(saveto,ba.data(),80);
return;
}
}
}
}

QTextImageFormat Edit_Image::GetFormat()
{
int swi = spinBox->value();
int shi = spinBox_2->value();
nowimage.setHeight(shi);
nowimage.setWidth(swi);
SavePicimage();
return nowimage;
}

void Edit_Image::Modpicsw( int w )
{
if (!onwi) {
ModpicsChangedWI(w,1);
}
}
void Edit_Image::Modpicsh( int w )
{
if (!onwi) {
ModpicsChangedWI(w,0);
}
}

void Edit_Image::ModpicsChangedWI(int newvalue_w , int modus ) /* int from QSlider 20px steeps miniumu 150 max pics width() */
{
QPixmap scaled;
onwi = true;
QPixmap pic(imagefullpath);
if (modus == 1) {
scaled = pic.scaledToWidth(newvalue_w);
} else {
scaled = pic.scaledToHeight(newvalue_w);
}
picco->setPixmap(scaled); /* label */
picco->adjustSize(); /* label */
actual = picco->pixmap()->size();
wi = actual.width();
hi = actual.height();

if (modus == 1) {
spinBox_2->setValue(hi);
} else {
spinBox->setValue(wi);
}
onwi = false;

}

void Edit_Image::closeEvent( QCloseEvent* e )
{
e->accept();
}

jacek
7th February 2007, 23:57
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?

patrik08
8th February 2007, 00:09
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 ...


QTextImageFormat newforminepic = Edit_Image::self( this )->GetFormat();
if (newforminepic.isValid()) {
nowimage = newforminepic;
qDebug() << "### Draw image h ... " << nowimage.height();
qDebug() << "### Draw image w... " << nowimage.width();



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...

patrik08
8th February 2007, 00:37
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...

jacek
8th February 2007, 01:08
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?

patrik08
8th February 2007, 01:40
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(imposi)) );

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?

jacek
8th February 2007, 02:09
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".

patrik08
8th February 2007, 02:59
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....



void Edit::TableSetting()
{
QTextCursor findercursor(wtext->textCursor());
Etable = findercursor.currentTable();
if (Etable) {
Table_Setting::self( this )->SetFormat(nowtable);
Table_Setting::self( this )->exec();
QTextTableFormat newformine = Table_Setting::self( this )->GetNewFormats(); /* incomming other attribute by table .... from dialog */
if (newformine.isValid()) {
nowtable->setFormat(newformine); /* nowtable = QTextTable */
}
}

}



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/task-tracker/index_html?method=entry&id=149069


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

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





void Edit::Image_mod_Setting()
{
/* QTextImageFormat nowimage; */
if (nowimage.isValid()) {
Edit_Image::self( this )->SetFormat(nowimage);
Edit_Image::self( this )->exec();
QTextImageFormat newforminepic = Edit_Image::self( this )->GetFormat();
if (newforminepic.isValid()) {
////////////nowimage = newforminepic;
/* QTextCursor lastcursor; ( last cursor from action ) */
lastcursor.setCharFormat(newforminepic);
qDebug() << "### Draw image h ... " << nowimage.height();
qDebug() << "### Draw image w... " << nowimage.width();
Reload_Editor(); /* repaint new size from image and go back to last QScrollBar *wysiwyg_sroll; int value setvalue(int)*/
/* http://www.qtcentre.org/forum/f-qt-programming-2/t-loading-images-in-qtextbrowser-5046.html/?highlight=QTextImageFormat */
}
}

}