Git commit 1ef6eb8e6c06bed8d7d9381dc7fcef8c04d0c6f1 by Andreas Cord-Landweh= r. Committed on 28/02/2015 at 15:50. Pushed by cordlandwehr into branch 'frameworks'. Finish KF5 port of include graphics dialog. Finish porting tasks, update to new slot mechanism and cleanup class. M +94 -155 src/dialogs/includegraphicsdialog.cpp M +40 -41 src/dialogs/includegraphicsdialog.h http://commits.kde.org/kile/1ef6eb8e6c06bed8d7d9381dc7fcef8c04d0c6f1 diff --git a/src/dialogs/includegraphicsdialog.cpp b/src/dialogs/includegra= phicsdialog.cpp index 1c940b0..39ef481 100644 --- a/src/dialogs/includegraphicsdialog.cpp +++ b/src/dialogs/includegraphicsdialog.cpp @@ -1,6 +1,7 @@ /*************************************************************************= ************************* - Copyright (C) 2004-2005 by Holger Danielsson (holger.danielsson@t-onlin= e.de) - 2004 by Jeroen Wijnhout + Copyright (C) 2004-2005 Holger Danielsson + 2004 Jeroen Wijnhout + 2015 Andreas Cord-Landwehr *************************************************************************= *************************/ = /*************************************************************************= ** @@ -13,58 +14,44 @@ *************************************************************************= **/ = #include "dialogs/includegraphicsdialog.h" - -#include -#include -#include - -#include -#include -#include -#include -#include +#include "editorextension.h" +#include "errorhandler.h" +#include "kileactions.h" +#include "kileconfig.h" +#include "kiledebug.h" +#include "kileinfo.h" +#include "kiletool_enums.h" = #include -#include #include #include -#include #include = -#include "errorhandler.h" -#include "kiledebug.h" -#include "kileconfig.h" -#include "kileinfo.h" -#include "editorextension.h" -#include "kileactions.h" -#include "kiletool_enums.h" +#include +#include +#include +#include +#include +#include = namespace KileDialog { = -IncludeGraphics::IncludeGraphics(QWidget *parent, const QString &startdir,= KileInfo *ki) : - QDialog(parent), - m_startdir(startdir), - m_width(0), - m_height(0), - m_ki(ki), - m_proc(NULL) +IncludeGraphics::IncludeGraphics(QWidget *parent, const QString &startdir,= KileInfo *ki) + : QDialog(parent) + , m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox:= :Cancel)) + , m_startdir(startdir) + , m_width(0) + , m_height(0) + , m_ki(ki) + , m_proc(Q_NULLPTR) { setWindowTitle(i18n("Include Graphics")); setModal(true); - QDialogButtonBox *buttonBox =3D new QDialogButtonBox(QDialogButtonBox::Ok= |QDialogButtonBox::Cancel); QWidget *mainWidget =3D new QWidget(this); QVBoxLayout *mainLayout =3D new QVBoxLayout; setLayout(mainLayout); mainLayout->addWidget(mainWidget); - QPushButton *okButton =3D buttonBox->button(QDialogButtonBox::Ok); - okButton->setDefault(true); - okButton->setShortcut(Qt::CTRL | Qt::Key_Return); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - //PORTING SCRIPT: WARNING mainLayout->addWidget(buttonBox) must be last i= tem in layout. Please move it. - mainLayout->addWidget(buttonBox); - okButton->setDefault(true); = QWidget *page =3D new QWidget(this); m_widget.setupUi(page); @@ -72,29 +59,27 @@ IncludeGraphics::IncludeGraphics(QWidget *parent, const= QString &startdir, KileI = // read configuration readConfig(); - - slotChooseFilter(); - -//TODO KF5 -// #if KDE_IS_VERSION(4,2,90) -// m_widget.edit_file->setStartDir(QUrl::fromLocalFile(m_startdir)); -// #else -// m_widget.edit_file->setUrl(QUrl::fromLocalFile(m_startdir)); -// #endif + onChooseFilter(); = setFocusProxy(m_widget.edit_file); + m_widget.edit_file->setUrl(QUrl::fromLocalFile(m_startdir)); m_widget.edit_file->setFocus(); = - connect(m_widget.cb_bb, SIGNAL(toggled(bool)), - this, SLOT(slotChooseFilter())); - connect(m_widget.edit_file, SIGNAL(urlSelected(const QUrl&)), - this, SLOT(slotUrlSelected(const QUrl&))); - connect(m_widget.edit_file, SIGNAL(textChanged(const QString&)), - this, SLOT(slotTextChanged(const QString&))); - connect(m_widget.cb_figure, SIGNAL(toggled(bool)), - this, SLOT(slotFigureSelected(bool))); - connect(m_widget.cb_wrapfigure, SIGNAL(toggled(bool)), - this, SLOT(slotWrapFigureSelected(bool))); + connect(m_widget.cb_bb, &QCheckBox::toggled, this, &IncludeGraphics::onCh= ooseFilter); + connect(m_widget.edit_file, &KUrlRequester::urlSelected, this, &IncludeGr= aphics::onUrlSelected); + connect(m_widget.edit_file, &KUrlRequester::textChanged, this, &IncludeGr= aphics::onTextChanged); + connect(m_widget.cb_figure, &QGroupBox::toggled, this, &IncludeGraphics::= onFigureSelected); + connect(m_widget.cb_wrapfigure, &QGroupBox::toggled, this, &IncludeGraphi= cs::onWrapFigureSelected); + + QPushButton *okButton =3D m_buttonBox->button(QDialogButtonBox::Ok); + okButton->setDefault(true); + okButton->setShortcut(Qt::CTRL | Qt::Key_Return); + okButton->setEnabled(false); + mainLayout->addWidget(m_buttonBox); + + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + connect(this, &QDialog::accepted, this, &IncludeGraphics::onAccepted); } = IncludeGraphics::~IncludeGraphics() @@ -185,14 +170,12 @@ QString IncludeGraphics::getTemplate() p +=3D ']'; } = - // add start of figure environment s +=3D "\\begin{figure}" + p + '\n'; } = // build tags for start of wrapfigure environment if (wrapfigure) { - s +=3D "\\begin{wrapfigure}"; = // number of lines in length @@ -202,20 +185,20 @@ QString IncludeGraphics::getTemplate() = // positioning for wrapfigure environment bool wrapfloat; - wrapfloat =3D m_widget.cb_wrapfloat->isChecked(); - if (m_widget.cb_wrapright->isChecked()){ + wrapfloat =3D m_widget.cb_wrapfloat->isChecked(); + if (m_widget.cb_wrapright->isChecked()) { if (wrapfloat) s +=3D "{R}"; else s +=3D "{r}"; } - if (m_widget.cb_wrapleft->isChecked()){ + if (m_widget.cb_wrapleft->isChecked()) { if (wrapfloat) s +=3D "{L}"; else s +=3D "{l}"; } - if (m_widget.cb_wrapinside->isChecked()){ + if (m_widget.cb_wrapinside->isChecked()) { if (wrapfloat) s +=3D "{I}"; else s +=3D "{i}"; } - if (m_widget.cb_wrapoutside->isChecked()){ + if (m_widget.cb_wrapoutside->isChecked()) { if (wrapfloat) s +=3D "{O}"; else s +=3D "{i}"; } @@ -250,8 +233,7 @@ QString IncludeGraphics::getTemplate() if (center) { if (figure || wrapfigure) { s +=3D indent + "\\centering\n"; - } - else { + } else { s +=3D "\\begin{center}\n"; } } @@ -265,13 +247,13 @@ QString IncludeGraphics::getTemplate() s +=3D '[' + options + ']'; } = -//TODO KF5 -// // add name of picture -// // either take the filename or try to take the relative part of the na= me -// QString filename =3D (m_widget.cb_graphicspath->isChecked()) -// ? QFileInfo(m_widget.edit_file->lineEdit()->text()).fileName() -// : QUrl::relativePath(QFileInfo(m_ki->getCompileName()).path(), m_wi= dget.edit_file->lineEdit()->text()); -// s +=3D '{' + filename + "}\n"; + // add name of picture + // either take the filename or try to take the relative part of the name + const QString relativeUrl =3D QDir(QFileInfo(m_ki->getCompileName()).path= ()).relativeFilePath(m_widget.edit_file->lineEdit()->text()); + QString filename =3D (m_widget.cb_graphicspath->isChecked()) + ? QFileInfo(m_widget.edit_file->lineEdit()->text()).fileName() + : relativeUrl; + s +=3D '{' + filename + "}\n"; = // add some comments (depending of given resolution, this may be wrong!) QString info =3D getInfo(); @@ -285,8 +267,7 @@ QString IncludeGraphics::getTemplate() } = // close figure environment ? - if (figure) - { + if (figure) { QString caption =3D m_widget.edit_caption->text().trimmed(); if (!caption.isEmpty()) { s +=3D indent + "\\caption{" + caption + "}\n"; @@ -298,8 +279,7 @@ QString IncludeGraphics::getTemplate() s +=3D "\\end{figure}\n"; } = - if (wrapfigure) - { + if (wrapfigure) { QString caption =3D m_widget.edit_wrapcaption->text().trimmed(); if (!caption.isEmpty()) { s +=3D indent + "\\caption{" + caption + "}\n"; @@ -323,17 +303,17 @@ QString IncludeGraphics::getFilename() = QString IncludeGraphics::getOptions() { - QString s =3D ""; + QString s =3D QString(); = - if (! m_widget.edit_width->text().isEmpty()) { + if (!m_widget.edit_width->text().isEmpty()) { s +=3D ",width=3D" + m_widget.edit_width->text(); } = - if (! m_widget.edit_height->text().isEmpty()) { + if (!m_widget.edit_height->text().isEmpty()) { s +=3D ",height=3D" + m_widget.edit_height->text(); } = - if (! m_widget.edit_angle->text().isEmpty()) { + if (!m_widget.edit_angle->text().isEmpty()) { s +=3D ",angle=3D" + m_widget.edit_angle->text(); } = @@ -370,8 +350,7 @@ QString IncludeGraphics::getOptions() = if (s.left(1) =3D=3D ",") { return s.right(s.length() - 1); - } - else { + } else { return s; } } @@ -380,14 +359,13 @@ QString IncludeGraphics::getOptions() = QString IncludeGraphics::getInfo() { - QString wcm,hcm,dpi; - int wpx=3D0,hpx=3D0; + QString wcm, hcm, dpi; + int wpx =3D 0, hpx =3D 0; = bool ok =3D getPictureSize(wpx, hpx, dpi, wcm, hcm); - if (! ok) - return ""; - else - { + if (!ok) { + return QString(); + } else { QFileInfo fi(m_widget.edit_file->lineEdit()->text()); = return "% " + fi.baseName() + '.' + fi.completeSuffix() @@ -404,16 +382,15 @@ void IncludeGraphics::setInfo() QString wcm, hcm, dpi; int wpx, hpx; = - if (!m_widget.edit_file->lineEdit()->text().isEmpty() && getPictureSize(w= px, hpx, dpi, wcm, hcm)) - { + if (!m_widget.edit_file->lineEdit()->text().isEmpty() && getPictureSize(w= px, hpx, dpi, wcm, hcm)) { text =3D QString("%1x%2 pixel").arg(wpx).arg(hpx) + " / " + wcm + 'x' + hcm + " cm" + " (" + dpi + "dpi)"; - } - else + } else { text =3D "---"; + } = -// insert text + // insert text m_widget.infolabel->setText(text); } = @@ -433,7 +410,7 @@ bool IncludeGraphics::getPictureSize(int &wpx, int &hpx= , QString &dpi, QString & return true; } = -void IncludeGraphics::slotChooseFilter() +void IncludeGraphics::onChooseFilter() { QString filter =3D (!m_widget.cb_bb->isChecked()) ? i18n("*.png *.jpg *.pdf *.ps *.eps|Graphics\n") @@ -451,62 +428,62 @@ void IncludeGraphics::slotChooseFilter() m_widget.edit_file->setFilter(filter); } = -void IncludeGraphics::slotUrlSelected(const QUrl &url) +void IncludeGraphics::onUrlSelected(const QUrl &url) { QFileInfo fi(url.toLocalFile()); = // could we accept the picture? - if (!url.toLocalFile().isEmpty() && fi.exists() && fi.isReadable()) - { + if (!url.toLocalFile().isEmpty() && fi.exists() && fi.isReadable()) { // execute the command and filter the result: // eps|eps.gz --> %%BoundingBox: 0 0 123 456 // bitmaps --> w=3D123 h=3D456 dpi=3D789 QString grep =3D " | grep -m1 \"^%%BoundingBox:\""; QString ext =3D fi.completeSuffix(); - if (ext =3D=3D "eps"){ + if (ext =3D=3D "eps") { execute("cat " + url.toLocalFile() + grep); } - else if (ext =3D=3D "eps.gz"){ + else if (ext =3D=3D "eps.gz") { execute("gunzip -c " + url.toLocalFile() + grep); } - else{ + else { execute("identify -format \"w=3D%w h=3D%h dpi=3D%x\" \"" + url.toLocalF= ile() + "\""); } + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } else { KILE_DEBUG_MAIN << "=3D=3D=3D IncludeGraphics::error =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"; KILE_DEBUG_MAIN << " filename: '" << url.toLocalFile() << "'"; = m_widget.infolabel->setText("---"); m_widget.edit_bb->setText(""); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } } = -void IncludeGraphics::slotTextChanged(const QString& string) +void IncludeGraphics::onTextChanged(const QString &string) { - slotUrlSelected(QUrl(string)); + onUrlSelected(QUrl::fromLocalFile(string.trimmed())); } = void IncludeGraphics::execute(const QString &command) { - if (!m_boundingbox || (!m_imagemagick && command.left(8) =3D=3D "identify= ")) + if (!m_boundingbox || (!m_imagemagick && command.left(8) =3D=3D "identify= ")) { return; + } = - if (m_proc) + if (m_proc) { delete m_proc; + } = m_proc =3D new KProcess(this); m_proc->setShellCommand(command); m_proc->setOutputChannelMode(KProcess::MergedChannels); m_proc->setReadChannel(QProcess::StandardOutput); = - connect(m_proc, SIGNAL(readyReadStandardOutput()), - this, SLOT(slotProcessOutput())); - connect(m_proc, SIGNAL(readyReadStandardError()), - this, SLOT(slotProcessOutput())); - connect(m_proc, SIGNAL(finished(int, QProcess::ExitStatus)), - this, SLOT(slotProcessExited(int, QProcess::ExitStatus))); + connect(m_proc, &KProcess::readyReadStandardOutput, this, &IncludeGraphic= s::onProcessOutput); + connect(m_proc, &KProcess::readyReadStandardError, this, &IncludeGraphics= ::onProcessOutput); + connect(m_proc, static_cast(&KProcess::finished), this, &IncludeGraphics::onProcessExited); = - m_output =3D ""; + m_output =3D QString(); KILE_DEBUG_MAIN << "=3D=3D=3D IncludeGraphics::execute =3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"; KILE_DEBUG_MAIN << " execute '" << command << "'"; = @@ -515,14 +492,14 @@ void IncludeGraphics::execute(const QString &command) = // get all output of identify = -void IncludeGraphics::slotProcessOutput() +void IncludeGraphics::onProcessOutput() { m_output +=3D m_proc->readAll(); } = // identify was called = -void IncludeGraphics::slotProcessExited(int /* exitCode */, QProcess::Exit= Status exitStatus) +void IncludeGraphics::onProcessExited(int /* exitCode */, QProcess::ExitSt= atus exitStatus) { if (exitStatus =3D=3D QProcess::NormalExit) { KILE_DEBUG_MAIN << " result: " << m_output; @@ -589,24 +566,12 @@ void IncludeGraphics::slotProcessExited(int /* exitCo= de */, QProcess::ExitStatus } } = -//Adapt code and connect okbutton or other to new slot. It doesn't exist i= n qdialog -//Adapt code and connect okbutton or other to new slot. It doesn't exist i= n qdialog -void IncludeGraphics::slotButtonClicked(int button) +void IncludeGraphics::onAccepted() { -// if(button =3D=3D QDialog::Ok){ -// if(checkParameter()){ -// writeConfig(); -// accept(); -// } -// } -// else{ -// //Adapt code and connect okbutton or other to new slot. It doesn't exis= t in qdialog -// //Adapt code and connect okbutton or other to new slot. It doesn't exis= t in qdialog -// QDialog::slotButtonClicked(button); -// } + writeConfig(); } = -void IncludeGraphics::slotWrapFigureSelected(bool state) { +void IncludeGraphics::onWrapFigureSelected(bool state) { if (m_widget.cb_figure->isChecked() && state) { m_widget.cb_figure->setChecked(false); } @@ -617,35 +582,9 @@ void IncludeGraphics::slotWrapFigureSelected(bool stat= e) { } } = -void IncludeGraphics::slotFigureSelected(bool state) { +void IncludeGraphics::onFigureSelected(bool state) { if (m_widget.cb_wrapfigure->isChecked() && state) { m_widget.cb_wrapfigure->setChecked(false); } } - -bool IncludeGraphics::checkParameter() -{ - QString filename =3D m_widget.edit_file->lineEdit()->text().trimmed(); - m_widget.edit_file->lineEdit()->setText(filename); - - if (filename.isEmpty()) - { - if (KMessageBox::warningYesNo(this, i18n("No graphics file was given. Pr= oceed any way?")) =3D=3D KMessageBox::No) - return false; - } - else - { - QFileInfo fi(filename); - if (! fi.exists()) - { - if (KMessageBox::warningYesNo(this, i18n("The graphics file does not ex= ist. Proceed any way?")) =3D=3D KMessageBox::No) - return false; - } - } - - return true; -} - } - -#include "includegraphicsdialog.moc" diff --git a/src/dialogs/includegraphicsdialog.h b/src/dialogs/includegraph= icsdialog.h index 67c03b5..be6def8 100644 --- a/src/dialogs/includegraphicsdialog.h +++ b/src/dialogs/includegraphicsdialog.h @@ -1,8 +1,9 @@ /*************************************************************************= ** date : Nov 02 2005 version : 0.23 - copyright : (C) 2004-2005 by Holger Danielsson, 2004 Jeroen= Wijnhout - email : holger.danielsson@t-online.de + copyright : 2004-2005 Holger Danielsson + 2004 Jeroen Wijnhout + 2015 Andreas Cord-Landwehr *************************************************************************= **/ = /*************************************************************************= ** @@ -18,11 +19,11 @@ #define INCLUDEGRAPHICSDIALOG_H = #include - #include = #include "ui_includegraphicsdialog_base.h" = +class QDialogButtonBox; class KProcess; class KileInfo; = @@ -34,55 +35,53 @@ namespace KileDialog = class IncludeGraphics : public QDialog { - Q_OBJECT - - public: - IncludeGraphics(QWidget *parent, const QString &startdir, KileInfo *ki); - ~IncludeGraphics(); + Q_OBJECT = - QString getTemplate(); - QString getFilename(); +public: + IncludeGraphics(QWidget *parent, const QString &startdir, KileInfo *ki); + virtual ~IncludeGraphics(); = - private Q_SLOTS: - void slotChooseFilter(); - void slotUrlSelected(const QUrl &url); - void slotTextChanged(const QString& string); - void slotProcessOutput(); - void slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus); + QString getTemplate(); + QString getFilename(); = - void slotWrapFigureSelected(bool state); - void slotFigureSelected(bool state); +private Q_SLOTS: + void onChooseFilter(); + void onUrlSelected(const QUrl &url); + void onTextChanged(const QString& string); + void onProcessOutput(); + void onProcessExited(int exitCode, QProcess::ExitStatus exitStatus); = - protected Q_SLOTS: - virtual void slotButtonClicked(int button); + void onWrapFigureSelected(bool state); + void onFigureSelected(bool state); + void onAccepted(); = - private: - void readConfig(); - void writeConfig(); - bool checkParameter(); - QString getOptions(); - QString getInfo(); - bool getPictureSize(int &wpx, int &hpx, QString &dpi, QString &wcm, QStr= ing &hcm); - void setInfo(); +private: + void readConfig(); + void writeConfig(); + QString getOptions(); + QString getInfo(); + bool getPictureSize(int &wpx, int &hpx, QString &dpi, QString &wcm, QStri= ng &hcm); + void setInfo(); = - Ui::IncludeGraphicsWidget m_widget; + QDialogButtonBox *m_buttonBox; + Ui::IncludeGraphicsWidget m_widget; = - QString m_startdir; - QString m_output; + QString m_startdir; + QString m_output; = - // current picture - int m_width, m_height; - float m_resolution; + // current picture + int m_width, m_height; + float m_resolution; = - // default - bool m_imagemagick; - bool m_boundingbox; - float m_defaultresolution; + // default + bool m_imagemagick; + bool m_boundingbox; + float m_defaultresolution; = - void execute(const QString &command); + void execute(const QString &command); = - KileInfo *m_ki; - KProcess* m_proc; + KileInfo *m_ki; + KProcess* m_proc; }; = }