File indexing completed on 2024-05-05 17:15:10

0001 /**************************************************************************************************
0002    Copyright (C) 2004-2005  Holger Danielsson <holger.danielsson@t-online.de>
0003                  2004       Jeroen Wijnhout
0004                  2015       Andreas Cord-Landwehr <cordlandwehr@kde.org>
0005  **************************************************************************************************/
0006 
0007 /***************************************************************************
0008  *                                                                         *
0009  *   This program is free software; you can redistribute it and/or modify  *
0010  *   it under the terms of the GNU General Public License as published by  *
0011  *   the Free Software Foundation; either version 2 of the License, or     *
0012  *   (at your option) any later version.                                   *
0013  *                                                                         *
0014  ***************************************************************************/
0015 
0016 #include "dialogs/includegraphicsdialog.h"
0017 #include "editorextension.h"
0018 #include "errorhandler.h"
0019 #include "kileactions.h"
0020 #include "kileconfig.h"
0021 #include "kiledebug.h"
0022 #include "kileinfo.h"
0023 #include "kiletool_enums.h"
0024 
0025 #include <KConfigGroup>
0026 #include <KLineEdit>
0027 #include <KLocalizedString>
0028 #include <KProcess>
0029 
0030 #include <QDialogButtonBox>
0031 #include <QFileInfo>
0032 #include <QLineEdit>
0033 #include <QPushButton>
0034 #include <QRegExp>
0035 #include <QVBoxLayout>
0036 
0037 namespace KileDialog
0038 {
0039 
0040 IncludeGraphics::IncludeGraphics(QWidget *parent, const QString &startdir, KileInfo *ki)
0041     : QDialog(parent)
0042     , m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel))
0043     , m_startdir(startdir)
0044     , m_width(0)
0045     , m_height(0)
0046     , m_ki(ki)
0047     , m_proc(Q_NULLPTR)
0048 {
0049     setWindowTitle(i18n("Include Graphics"));
0050     setModal(true);
0051     QWidget *mainWidget = new QWidget(this);
0052     QVBoxLayout *mainLayout = new QVBoxLayout;
0053     setLayout(mainLayout);
0054     mainLayout->addWidget(mainWidget);
0055 
0056     QWidget *page = new QWidget(this);
0057     m_widget.setupUi(page);
0058     mainLayout->addWidget(page);
0059 
0060     // read configuration
0061     readConfig();
0062     onChooseFilter();
0063 
0064     setFocusProxy(m_widget.edit_file);
0065     m_widget.edit_file->setMode(KFile::File | KFile::LocalOnly);
0066     m_widget.edit_file->setStartDir(QUrl::fromLocalFile(m_startdir));
0067     m_widget.edit_file->setFocus();
0068 
0069     connect(m_widget.cb_bb, &QCheckBox::toggled, this, &IncludeGraphics::onChooseFilter);
0070     connect(m_widget.edit_file, &KUrlRequester::urlSelected, this, &IncludeGraphics::onUrlSelected);
0071     connect(m_widget.edit_file, &KUrlRequester::textChanged, this, &IncludeGraphics::onTextChanged);
0072     connect(m_widget.cb_figure, &QGroupBox::toggled, this, &IncludeGraphics::onFigureSelected);
0073     connect(m_widget.cb_wrapfigure, &QGroupBox::toggled, this, &IncludeGraphics::onWrapFigureSelected);
0074 
0075     QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok);
0076     okButton->setDefault(true);
0077     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0078     okButton->setEnabled(false);
0079     mainLayout->addWidget(m_buttonBox);
0080 
0081     connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0082     connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0083     connect(this, &QDialog::accepted, this, &IncludeGraphics::onAccepted);
0084 }
0085 
0086 IncludeGraphics::~IncludeGraphics()
0087 {
0088     delete m_proc;
0089 }
0090 
0091 ////////////////////////////// configuration data //////////////////////////////
0092 
0093 void IncludeGraphics::readConfig()
0094 {
0095     m_widget.cb_center->setChecked(KileConfig::igCenter());
0096     m_widget.cb_bb->setChecked(KileConfig::igBoundingBox());
0097     m_widget.cb_graphicspath->setChecked(KileConfig::igGraphicspath());
0098 
0099     m_widget.cb_figure->setChecked(KileConfig::igFigure());
0100     m_widget.cb_Bottom->setChecked(KileConfig::igBottom());
0101     m_widget.cb_Force->setChecked(KileConfig::igForce());
0102     m_widget.cb_Here->setChecked(KileConfig::igHere());
0103     m_widget.cb_Page->setChecked(KileConfig::igPage());
0104     m_widget.cb_Top->setChecked(KileConfig::igTop());
0105 
0106     m_widget.cb_wrapfigure->setChecked(KileConfig::igWrapFigure());
0107     m_widget.cb_wrapright->setChecked(KileConfig::igWrapRight());
0108     m_widget.cb_wrapleft->setChecked(KileConfig::igWrapLeft());
0109     m_widget.cb_wrapinside->setChecked(KileConfig::igWrapInside());
0110     m_widget.cb_wrapoutside->setChecked(KileConfig::igWrapOutside());
0111     m_widget.cb_wrapfloat->setChecked(KileConfig::igWrapFloat());
0112 
0113     m_imagemagick = KileConfig::imagemagick();
0114     m_boundingbox = KileConfig::boundingbox();
0115     m_defaultresolution = KileConfig::resolution();
0116 }
0117 
0118 void IncludeGraphics::writeConfig()
0119 {
0120     KileConfig::setIgCenter(m_widget.cb_center->isChecked());
0121     KileConfig::setIgBoundingBox(m_widget.cb_bb->isChecked());
0122     KileConfig::setIgGraphicspath(m_widget.cb_graphicspath->isChecked());
0123 
0124     KileConfig::setIgFigure(m_widget.cb_figure->isChecked());
0125     KileConfig::setIgBottom(m_widget.cb_Bottom->isChecked());
0126     KileConfig::setIgHere(m_widget.cb_Here->isChecked());
0127     KileConfig::setIgPage(m_widget.cb_Page->isChecked());
0128     KileConfig::setIgTop(m_widget.cb_Top->isChecked());
0129     KileConfig::setIgForce(m_widget.cb_Force->isChecked());
0130 
0131     KileConfig::setIgWrapFigure(m_widget.cb_wrapfigure->isChecked());
0132     KileConfig::setIgWrapRight(m_widget.cb_wrapright->isChecked());
0133     KileConfig::setIgWrapLeft(m_widget.cb_wrapleft->isChecked());
0134     KileConfig::setIgWrapInside(m_widget.cb_wrapinside->isChecked());
0135     KileConfig::setIgWrapOutside(m_widget.cb_wrapoutside->isChecked());
0136     KileConfig::setIgWrapFloat(m_widget.cb_wrapfloat->isChecked());
0137 }
0138 
0139 ////////////////////////////// determine the whole tag //////////////////////////////
0140 
0141 QString IncludeGraphics::getTemplate()
0142 {
0143     QString s;
0144 
0145     // state of figure, wrapfigure, and center checkbox
0146     bool figure = m_widget.cb_figure->isChecked();
0147     bool wrapfigure = m_widget.cb_wrapfigure->isChecked();
0148     bool center = m_widget.cb_center->isChecked();
0149     const QString indent = (figure || center) ? m_ki->editorExtension()->autoIndentEnvironment() : QString();
0150 
0151     // build tags for start of figure environment
0152     if (figure) {
0153         // positioning for figure environment
0154         QString p;
0155         bool here   = m_widget.cb_Here->isChecked();
0156         bool top    = m_widget.cb_Top->isChecked();
0157         bool bottom     = m_widget.cb_Bottom->isChecked();
0158         bool page   = m_widget.cb_Page->isChecked();
0159         bool force  = m_widget.cb_Force->isChecked();
0160         bool custom     = m_widget.cb_custom->isChecked();
0161 
0162         // build position string
0163         if (here||top||bottom||page||custom) { // Don't check for force -- if it is the only selection, just skip the position tag
0164             p += '[';
0165             if (here)   p+= 'h';
0166             if (top)    p+= 't';
0167             if (bottom) p+= 'b';
0168             if (page)   p+= 'p';
0169             if (force)      p+= '!';
0170             if (custom) p+= m_widget.edit_custom->text();
0171             p += ']';
0172         }
0173 
0174         // add start of figure environment
0175         s += "\\begin{figure}" + p + '\n';
0176     }
0177 
0178     // build tags for start of wrapfigure environment
0179     if (wrapfigure) {
0180         s += "\\begin{wrapfigure}";
0181 
0182         // number of lines in length
0183         if (!m_widget.edit_wraplines->text().isEmpty()) {
0184             s += '[' + m_widget.edit_wraplines->text() + ']';
0185         }
0186 
0187         // positioning for wrapfigure environment
0188         bool wrapfloat;
0189         wrapfloat = m_widget.cb_wrapfloat->isChecked();
0190         if (m_widget.cb_wrapright->isChecked()) {
0191             if (wrapfloat)  s += "{R}";
0192             else        s += "{r}";
0193         }
0194         if (m_widget.cb_wrapleft->isChecked()) {
0195             if (wrapfloat)  s += "{L}";
0196             else        s += "{l}";
0197         }
0198         if (m_widget.cb_wrapinside->isChecked()) {
0199             if (wrapfloat)  s += "{I}";
0200             else        s += "{i}";
0201         }
0202         if (m_widget.cb_wrapoutside->isChecked()) {
0203             if (wrapfloat)  s += "{O}";
0204             else        s += "{i}";
0205         }
0206 
0207         // overhang into margin
0208         if (!m_widget.edit_wrapoverhang->text().isEmpty()) {
0209             s += '[' + m_widget.edit_wrapoverhang->text() + ']';
0210         }
0211 
0212         // width of figure
0213         if (!m_widget.edit_wrapwidth->text().isEmpty()) {
0214             s += '{' + m_widget.edit_wrapwidth->text() + '}';
0215         }
0216 
0217         // end of wrapfigure options
0218         s += '\n';
0219 
0220         // Include warning in comment if wrapfig is not loaded.
0221         // Sending a warning to the log here would be good, but
0222         // the log seems to get cleared before user could catch
0223         // the warning.
0224         QStringList packagelist = m_ki->allPackages();
0225         if (!packagelist.contains("wrapfig")) {
0226             s += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
0227             s += "%%% You will need to add \\usepackage{wrapfig} to your preamble to use textwrapping %%%\n";
0228             s += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
0229         }
0230     }
0231 
0232 
0233     // add start of center environment ?
0234     if (center) {
0235         if (figure || wrapfigure) {
0236             s += indent + "\\centering\n";
0237         } else {
0238             s += "\\begin{center}\n";
0239         }
0240     }
0241 
0242     // add includegraphics command
0243     s += indent + "\\includegraphics";
0244 
0245     // add some options
0246     QString options = getOptions();
0247     if (!options.isEmpty()) {
0248         s += '[' + options + ']';
0249     }
0250 
0251     // add name of picture
0252     // either take the filename or try to take the relative part of the name
0253     const QString relativeUrl = QDir(QFileInfo(m_ki->getCompileName()).path()).relativeFilePath(m_widget.edit_file->lineEdit()->text());
0254     QString filename = (m_widget.cb_graphicspath->isChecked())
0255                        ? QFileInfo(m_widget.edit_file->lineEdit()->text()).fileName()
0256                        : relativeUrl;
0257     s += '{' + filename + "}\n";
0258 
0259     // add some comments (depending of given resolution, this may be wrong!)
0260     QString info = getInfo();
0261     if (info.length() > 0) {
0262         s += indent + info + '\n';
0263     }
0264 
0265     // close center environment ?
0266     if (center && !figure && !wrapfigure) {
0267         s += "\\end{center}\n";
0268     }
0269 
0270     // close figure environment ?
0271     if (figure) {
0272         QString caption = m_widget.edit_caption->text().trimmed();
0273         if (!caption.isEmpty()) {
0274             s +=  indent + "\\caption{" + caption + "}\n";
0275         }
0276         QString label = m_widget.edit_label->text().trimmed();
0277         if (!label.isEmpty() && label != "fig:") {
0278             s +=  indent + "\\label{" + label + "}\n";
0279         }
0280         s += "\\end{figure}\n";
0281     }
0282 
0283     if (wrapfigure) {
0284         QString caption = m_widget.edit_wrapcaption->text().trimmed();
0285         if (!caption.isEmpty()) {
0286             s +=  indent + "\\caption{" + caption + "}\n";
0287         }
0288         QString label = m_widget.edit_wraplabel->text().trimmed();
0289         if (!label.isEmpty() && label != "fig:") {
0290             s +=  indent + "\\label{" + label + "}\n";
0291         }
0292         s += "\\end{wrapfigure}\n";
0293     }
0294 
0295     return s;
0296 }
0297 
0298 QString IncludeGraphics::getFilename()
0299 {
0300     return m_widget.edit_file->lineEdit()->text();
0301 }
0302 
0303 ////////////////////////////// some calculations //////////////////////////////
0304 
0305 QString IncludeGraphics::getOptions()
0306 {
0307     QString s = QString();
0308 
0309     if (!m_widget.edit_width->text().isEmpty()) {
0310         s += ",width=" + m_widget.edit_width->text();
0311     }
0312 
0313     if (!m_widget.edit_height->text().isEmpty()) {
0314         s += ",height=" + m_widget.edit_height->text();
0315     }
0316 
0317     if (!m_widget.edit_angle->text().isEmpty()) {
0318         s += ",angle=" + m_widget.edit_angle->text();
0319     }
0320 
0321     // Only dvips needs the bounding box, not pdftex/pdflatex.
0322     // But it will be always inserted as a comment.
0323     if (!m_widget.edit_bb->text().isEmpty() && m_widget.cb_bb->isChecked()) {
0324         s += ",bb=" + m_widget.edit_bb->text();
0325     }
0326 
0327     if (!m_widget.edit_scale->text().isEmpty()) {
0328         s += ",scale=" + m_widget.edit_scale->text();
0329     }
0330 
0331     if (m_widget.cb_keepAspect->isChecked()) {
0332         s+= ",keepaspectratio=true";
0333     }
0334 
0335     if (m_widget.cb_clip->isChecked()) {
0336         QString l="0pt", b="0pt", r="0pt", t="0pt";
0337         if (!m_widget.edit_trimLeft->text().isEmpty()) {
0338             l = m_widget.edit_trimLeft->text();
0339         }
0340         if (!m_widget.edit_trimBottom->text().isEmpty()) {
0341             b = m_widget.edit_trimBottom->text();
0342         }
0343         if (!m_widget.edit_trimRight->text().isEmpty()) {
0344             r = m_widget.edit_trimRight->text();
0345         }
0346         if (!m_widget.edit_trimTop->text().isEmpty()) {
0347             t = m_widget.edit_trimTop->text();
0348         }
0349         s += ",clip=true,trim=" + l + ' ' + b + ' ' + r + ' ' + t;
0350     }
0351 
0352     if (s.left(1) == ",") {
0353         return s.right(s.length() - 1);
0354     } else {
0355         return s;
0356     }
0357 }
0358 
0359 ////////////////////////////// graphics info //////////////////////////////
0360 
0361 QString IncludeGraphics::getInfo()
0362 {
0363     QString wcm, hcm, dpi;
0364     int wpx = 0, hpx = 0;
0365 
0366     bool ok = getPictureSize(wpx, hpx, dpi, wcm, hcm);
0367     if (!ok) {
0368         return QString();
0369     } else {
0370         QFileInfo fi(m_widget.edit_file->lineEdit()->text());
0371 
0372         return "% " + fi.baseName() + '.' + fi.completeSuffix()
0373                + QString(": %1x%2 px").arg(wpx).arg(hpx)
0374                + ", " + dpi + "dpi"
0375                + ", " + wcm + 'x' + hcm + " cm"
0376                + ", bb=" + m_widget.edit_bb->text();
0377     }
0378 }
0379 
0380 void IncludeGraphics::setInfo()
0381 {
0382     QString text;
0383     QString wcm, hcm, dpi;
0384     int wpx, hpx;
0385 
0386     if (!m_widget.edit_file->lineEdit()->text().isEmpty() && getPictureSize(wpx, hpx, dpi, wcm, hcm)) {
0387         text = QString("%1x%2 px").arg(wpx).arg(hpx)
0388                + " / " + wcm + 'x' + hcm + " cm"
0389                + "  (" + dpi + "dpi)";
0390     } else {
0391         text = "---";
0392     }
0393 
0394     // insert text
0395     m_widget.infolabel->setText(text);
0396 }
0397 
0398 bool IncludeGraphics::getPictureSize(int &wpx, int &hpx, QString &dpi, QString &wcm, QString &hcm)
0399 {
0400     wpx = m_width;
0401     hpx = m_height;
0402 
0403     dpi = QString::number((int)(m_resolution + 0.5));
0404 
0405     // convert from inch to cm
0406     float w = (float)m_width / m_resolution * 2.54;
0407     wcm = wcm.setNum(w, 'f', 2);
0408 
0409     float h = (float)m_height / m_resolution * 2.54;
0410     hcm = hcm.setNum(h, 'f', 2);
0411     return true;
0412 }
0413 
0414 void IncludeGraphics::onChooseFilter()
0415 {
0416     QStringList filters;
0417     if (!m_widget.cb_bb->isChecked()) {
0418         filters.append(i18n("Graphics (*.png *.jpg *.pdf *.ps *.eps)"));
0419         filters.append(i18n("PNG Files (*.png)"));
0420         filters.append(i18n("JPG Files (*.jpg)"));
0421         filters.append(i18n("PDF Files (*.pdf)"));
0422         filters.append(i18n("Postscript Files (*.eps *ps)"));
0423     }
0424     else {
0425         filters.append(i18n("Graphics (*.png *.jpg *.eps.gz *.eps)"));
0426         filters.append(i18n("PNG Files (*.png)"));
0427         filters.append(i18n("JPG Files (*.jpg)"));
0428         filters.append(i18n("Zipped EPS Files (*.eps.gz)"));
0429         filters.append(i18n("EPS Files (*.eps)"));
0430     }
0431     filters.append(i18n("All Files (*)"));
0432     m_widget.edit_file->setNameFilters(filters);
0433 }
0434 
0435 void IncludeGraphics::onUrlSelected(const QUrl &url)
0436 {
0437     QFileInfo fi(url.toLocalFile());
0438 
0439     // could we accept the picture?
0440     if (!url.toLocalFile().isEmpty() && fi.exists() && fi.isReadable()) {
0441         // execute the command and filter the result:
0442         // eps|eps.gz --> %%BoundingBox: 0 0 123 456
0443         // bitmaps    --> w=123 h=456 dpi=789
0444         QString grep = " | grep -m1 \"^%%BoundingBox:\"";
0445         QString ext = fi.completeSuffix();
0446         if (ext == "eps") {
0447             execute("cat " + url.toLocalFile() + grep);
0448         }
0449         else if (ext == "eps.gz") {
0450             execute("gunzip -c " + url.toLocalFile() + grep);
0451         }
0452         else {
0453             execute("identify -format \"w=%w h=%h dpi=%x %U\" \"" + url.toLocalFile() + "\"");
0454         }
0455         m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
0456     } else {
0457         KILE_DEBUG_MAIN << "=== IncludeGraphics::error ====================";
0458         KILE_DEBUG_MAIN << "   filename: '" << url.toLocalFile() << "'";
0459 
0460         m_widget.infolabel->setText("---");
0461         m_widget.edit_bb->setText("");
0462         m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
0463     }
0464 }
0465 
0466 void IncludeGraphics::onTextChanged(const QString &string)
0467 {
0468     onUrlSelected(QUrl::fromLocalFile(string.trimmed()));
0469 }
0470 
0471 void IncludeGraphics::execute(const QString &command)
0472 {
0473     if (!m_boundingbox || (!m_imagemagick && command.left(8) == "identify")) {
0474         return;
0475     }
0476 
0477     if (m_proc) {
0478         delete m_proc;
0479     }
0480 
0481     m_proc = new KProcess(this);
0482     m_proc->setShellCommand(command);
0483     m_proc->setOutputChannelMode(KProcess::MergedChannels);
0484     m_proc->setReadChannel(QProcess::StandardOutput);
0485 
0486     connect(m_proc, &KProcess::readyReadStandardOutput, this, &IncludeGraphics::onProcessOutput);
0487     connect(m_proc, &KProcess::readyReadStandardError, this, &IncludeGraphics::onProcessOutput);
0488     connect(m_proc, static_cast<void (KProcess::*)(int, QProcess::ExitStatus)>(&KProcess::finished), this, &IncludeGraphics::onProcessExited);
0489 
0490     m_output = QString();
0491     KILE_DEBUG_MAIN << "=== IncludeGraphics::execute ====================";
0492     KILE_DEBUG_MAIN << "   execute '" << command << "'";
0493 
0494     m_proc->start();
0495 }
0496 
0497 // get all output of identify
0498 
0499 void IncludeGraphics::onProcessOutput()
0500 {
0501     m_output += m_proc->readAll();
0502 }
0503 
0504 // identify was called
0505 
0506 void IncludeGraphics::onProcessExited(int /* exitCode */, QProcess::ExitStatus exitStatus)
0507 {
0508     if (exitStatus == QProcess::NormalExit) {
0509         KILE_DEBUG_MAIN << "   result: " << m_output;
0510 
0511         // set the default resolution
0512         m_resolution = m_defaultresolution;
0513 
0514         // analyze the result
0515         if (m_output.left(14) == "%%BoundingBox:") {
0516             m_widget.edit_bb->setText(m_output.trimmed().mid(15, m_output.length() - 15));
0517 
0518             // this regexp will extract width and height from the bounding box
0519             QRegExp reg("(\\d+) (\\d+) (\\d+) (\\d+)");
0520             if(reg.indexIn(m_output) == -1) {
0521                 return;
0522             }
0523 
0524             // determine lower-left-x (llx), lower-left-y (lly), upper-right-x (urx) and upper-right-y (ury)
0525             bool ok;
0526             int llx = (int)reg.cap(1).toInt(&ok);
0527             if (!ok) {
0528                 return;
0529             }
0530 
0531             int lly = (int)reg.cap(2).toInt(&ok);
0532             if (!ok) {
0533                 return;
0534             }
0535 
0536             int urx = (int)reg.cap(3).toInt(&ok);
0537             if (!ok) {
0538                 return;
0539             }
0540 
0541             int ury = (int)reg.cap(4).toInt(&ok);
0542             if (!ok) {
0543                 return;
0544             }
0545 
0546             // calculate width and height from 72 dpi of eps graphics to the default resolution
0547             m_width = ((urx-llx)*m_resolution) / 72;
0548             m_height = ((ury-lly)*m_resolution) / 72;
0549 
0550             // show information
0551             setInfo();
0552         }
0553         else {
0554             if (m_output.left(2) == "w=") {
0555                 // dani  31.7.2004
0556                 // older version of imagemagick (pre 6.0):
0557                 //  - doesn't care of PixelsPerCentimeter, but always works with PixelsPerInch
0558                 //  - doesn't use floating numbers as resolution
0559                 // so the bounding box has to be calculated in a different way
0560 
0561                 // this regexp will accept floating point numbers as resolution
0562                 QRegExp reg("w=(\\d+)\\s+h=(\\d+)\\s+dpi=([0-9.]+) (.*)");
0563                 if(reg.indexIn(m_output) == -1) {
0564                     return;
0565                 }
0566 
0567                 // get bounding box and resolution
0568                 bool ok;
0569                 m_width = (int)reg.cap(1).toInt(&ok);
0570                 if (!ok) {
0571                     return;
0572                 }
0573 
0574                 m_height = (int)reg.cap(2).toInt(&ok);
0575                 if (!ok) {
0576                     return;
0577                 }
0578 
0579                 float res = (float)reg.cap(3).toFloat(&ok);
0580                 if (!ok) {
0581                     return;
0582                 }
0583                 if (res > 0.0) {
0584                     m_resolution = res;
0585                 }
0586 
0587                 // look, if resolution is in PixelsPerCentimeter
0588                 if (reg.cap(4).trimmed() == "PixelsPerCentimeter") {
0589                     m_resolution *= 2.54f;
0590                 }
0591 
0592                 // calc the bounding box
0593                 int bbw = (int)((float)m_width * 72.0 / m_resolution + 0.5);
0594                 int bbh = (int)((float)m_height * 72.0 / m_resolution + 0.5);
0595 
0596                 // take width and height as parameters for the bounding box
0597                 m_widget.edit_bb->setText(QString("0 0 ") + QString::number(bbw)
0598                                           + ' '
0599                                           + QString::number(bbh));
0600 
0601                 // show information
0602                 setInfo();
0603 
0604             }
0605         }
0606     }
0607 }
0608 
0609 void IncludeGraphics::onAccepted()
0610 {
0611     writeConfig();
0612 }
0613 
0614 void IncludeGraphics::onWrapFigureSelected(bool state) {
0615     if (m_widget.cb_figure->isChecked() && state) {
0616         m_widget.cb_figure->setChecked(false);
0617     }
0618     // Adds warning to log if wrapfig isn't in the preamble
0619     QStringList packagelist = m_ki->allPackages();
0620     if (!packagelist.contains("wrapfig")) {
0621         m_ki->errorHandler()->printMessage(KileTool::Error, i18n("You must include the wrapfig package to use the text wrapping options"), i18n("Missing Package"));
0622     }
0623 }
0624 
0625 void IncludeGraphics::onFigureSelected(bool state) {
0626     if (m_widget.cb_wrapfigure->isChecked() && state) {
0627         m_widget.cb_wrapfigure->setChecked(false);
0628     }
0629 }
0630 }