]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiGraphics.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiGraphics.cpp
index 404df3c9d1282ae43771e75a1e15d7b6d0384ad2..b6bbaeac3fb13860c7a7049a4b0b01ec7c378af7 100644 (file)
@@ -24,7 +24,6 @@
 #include "LengthCombo.h"
 #include "Length.h"
 #include "LyXRC.h"
-#include "Format.h"
 
 #include "graphics/epstools.h"
 #include "graphics/GraphicsCache.h"
@@ -43,7 +42,6 @@
 #include "support/types.h"
 
 #include <QCheckBox>
-#include <QFileDialog>
 #include <QLabel>
 #include <QLineEdit>
 #include <QPushButton>
@@ -79,7 +77,7 @@ size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
 
 static string const autostr = N_("automatically");
 
-} // namespace anon
+} // namespace
 
 
 namespace lyx {
@@ -115,12 +113,10 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        : GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false)
 {
        setupUi(this);
-       
+
        //main buttons
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+                       this, SLOT(slotButtonBox(QAbstractButton *)));
 
        //graphics pane
        connect(filename, SIGNAL(textChanged(const QString &)),
@@ -157,7 +153,7 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        filename->setValidator(new PathValidator(true, filename));
        setFocusProxy(filename);
 
-       QDoubleValidator * scaleValidator = 
+       QDoubleValidator * scaleValidator =
                new DoubleAutoValidator(Scale, qt_(autostr));
        scaleValidator->setBottom(0);
        scaleValidator->setDecimals(256); //I guess that will do
@@ -169,19 +165,19 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        //clipping pane
        connect(clip, SIGNAL(stateChanged(int)),
                this, SLOT(change_adaptor()));
-       connect(lbY, SIGNAL(textChanged(const QString&)),
+       connect(lbY, SIGNAL(textChanged(const QString &)),
                this, SLOT(changeBB()));
        connect(lbYunit, SIGNAL(activated(int)),
                this, SLOT(changeBB()));
-       connect(rtY, SIGNAL(textChanged(const QString&)),
+       connect(rtY, SIGNAL(textChanged(const QString &)),
                this, SLOT(changeBB()));
        connect(rtYunit, SIGNAL(activated(int)),
                this, SLOT(changeBB()));
-       connect(lbX, SIGNAL(textChanged(const QString&)),
+       connect(lbX, SIGNAL(textChanged(const QString &)),
                this, SLOT(changeBB()));
        connect(lbXunit, SIGNAL(activated(int)),
                this, SLOT(changeBB()));
-       connect(rtX, SIGNAL(textChanged(const QString&)),
+       connect(rtX, SIGNAL(textChanged(const QString &)),
                this, SLOT(changeBB()));
        connect(rtXunit, SIGNAL(activated(int)),
                this, SLOT(changeBB()));
@@ -194,7 +190,7 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        rtY->setValidator(new QDoubleValidator(rtY));
 
        //extra options pane
-       connect(latexoptions, SIGNAL(textChanged(const QString&)),
+       connect(latexoptions, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
        connect(draftCB, SIGNAL(stateChanged(int)),
                this, SLOT(change_adaptor()));
@@ -206,7 +202,7 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        // is clicked, even right clicked (I think), not just whenever it is
        // toggled.
        connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
-       connect(displayscale, SIGNAL(textChanged(const QString&)),
+       connect(displayscale, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
        connect(groupCO, SIGNAL(currentIndexChanged(int)),
                this, SLOT(changeGroup(int)));
@@ -214,10 +210,10 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        displayscale->setValidator(new QIntValidator(displayscale));
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setApply(applyPB);
-       bc().setRestore(restorePB);
-       bc().setCancel(closePB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
+       bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
 
        bc().addReadOnly(latexoptions);
        bc().addReadOnly(filenameL);
@@ -250,13 +246,6 @@ GuiGraphics::GuiGraphics(GuiView & lv)
 void GuiGraphics::change_adaptor()
 {
        changed();
-       string const fname = fromqstr(filename->text());
-       FileName dest_fname(FileName(fromqstr(bufferFilePath())), fname);
-       Format const * fmt = theFormats().getFormat(theFormats().getFormatFromFile(dest_fname));
-       LYXERR(Debug::GRAPHICS, "fmt: " << fmt
-               << ", fmt_name: " << theFormats().getFormatFromFile(dest_fname));
-       editPB->setEnabled(!fname.empty() && !dest_fname.isDirectory() && dest_fname.exists());
-       chooseSamplePB->setEnabled(!fname.empty() && !dest_fname.isDirectory());
 }
 
 
@@ -264,12 +253,12 @@ void GuiGraphics::changeGroup(int /* index */)
 {
        QString const new_group = groupCO->itemData(
                groupCO->currentIndex()).toString();
-       
+
        // check if the old group consisted only of this member
        if (current_group_ != fromqstr(new_group)
            && graphics::countGroupMembers(buffer(), current_group_) == 1) {
                if (!new_group.isEmpty()) {
-                       if (Alert::prompt(_("Dissolve previous group?"), 
+                       if (Alert::prompt(_("Dissolve previous group?"),
                                bformat(_("If you assign this graphic to group '%2$s',\n"
                                          "the previously assigned group '%1$s' will be dissolved,\n"
                                          "because this graphic was its only member.\n"
@@ -285,7 +274,7 @@ void GuiGraphics::changeGroup(int /* index */)
                                return;
                        }
                } else {
-                       if (Alert::prompt(_("Dissolve previous group?"), 
+                       if (Alert::prompt(_("Dissolve previous group?"),
                        bformat(_("If you sign off this graphic from group '%1$s',\n"
                                  "the group will be dissolved,\n"
                                  "because this graphic was its only member.\n"
@@ -301,7 +290,7 @@ void GuiGraphics::changeGroup(int /* index */)
                        return;
                        }
                }
-       } 
+       }
 
        if (new_group.isEmpty()) {
                changed();
@@ -314,7 +303,7 @@ void GuiGraphics::changeGroup(int /* index */)
                changed();
                return;
        }
-       
+
        // filename might have been changed
        QString current_filename = filename->text();
 
@@ -323,7 +312,7 @@ void GuiGraphics::changeGroup(int /* index */)
        InsetGraphics::string2params(grp, buffer(), params_);
        paramsToDialog(params_);
        groupCO->blockSignals(false);
-       
+
        // reset filename
        filename->setText(current_filename);
 
@@ -339,7 +328,7 @@ void GuiGraphics::on_newGroupPB_clicked()
        if (newgroup.empty())
                return;
        if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
-               Alert::warning(_("Group already defined!"), 
+               Alert::warning(_("Group already defined!"),
                        bformat(_("A graphics group with the name '%1$s' already exists."),
                                newgroup));
                return;
@@ -368,91 +357,6 @@ void GuiGraphics::on_browsePB_clicked()
 }
 
 
-bool GuiGraphics::checkFileExists()
-{
-       string const fname = fromqstr(filename->text());
-       FileName dest_fname(FileName(fromqstr(bufferFilePath())), fname);
-       if (fname.empty() || !dest_fname.exists()) {
-               return frontend::Alert::prompt(
-                       _("Continue?"), bformat(_("File '%1$s' does not exist. Continue?"), from_utf8(dest_fname.absFileName())),
-                       0, 1, _("&Yes"), _("&No")) == 0;
-       }
-       return true;
-}
-
-
-void GuiGraphics::on_chooseSamplePB_clicked()
-{
-       string fname = fromqstr(filename->text());
-       FileName dest_fname(FileName(fromqstr(bufferFilePath())), fname);
-       string fmt_name = theFormats().getFormatFromFile(FileName(fname));
-       string filter("Any file (*.*)");
-       if (!fmt_name.empty()) {
-               Format const *fmt = theFormats().getFormat(fmt_name);
-               filter = to_utf8(fmt->prettyname()) + " Files (*." + dest_fname.extension() + ")";
-       }
-       if (fname.empty() || dest_fname.isDirectory()) {
-               frontend::Alert::warning(_("Invalid destination file name!"), _("Invalid destination file name!"));
-               return;
-       }
-
-       QString const samplesDir = toqstr(addPath(package().user_support().absFileName(), "samples"));
-       string sample_name = fromqstr(QFileDialog::getOpenFileName(this, toqstr("Please, select sample template"), samplesDir, toqstr(filter)));
-       if (sample_name.empty())
-               // User pressed Cancel
-               return;
-       FileName sample_fname = FileName(sample_name);
-
-       //FileName sample_fname = libFileSearch(toqstr("samples"), toqstr(sample_name));
-       if (sample_fname.isDirectory() || !sample_fname.exists()) {
-               frontend::Alert::warning(_("Invalid sample file name"), _("Invalid sample file name"));
-               return;
-       }
-
-       string sample_fmt_name = theFormats().getFormatFromFile(sample_fname);
-       if (fmt_name.empty() && !sample_fmt_name.empty()) {
-               fmt_name = sample_fmt_name;
-               string ext = theFormats().getFormat(fmt_name)->extension();
-               if (!ext.empty()) {
-                       fname = fname + "." + ext;
-                       dest_fname.set(FileName(fromqstr(bufferFilePath())), fname);
-                       filename->setText(toqstr(fname));
-               }
-       }
-
-       if (fname.empty() || dest_fname.isDirectory()) {
-               frontend::Alert::warning(_("Invalid destination file name!"), _("Cannot copy sample file on an invalid destination file!"));
-               return;
-       }
-
-       if (!dest_fname.exists() || (dest_fname.exists() &&
-               frontend::Alert::prompt(
-                       _("Overwrite?"), bformat(_("File '%1$s' already exists. Overwrite with sample from template?"), from_utf8(dest_fname.absFileName())),
-                       0, 1, _("&Yes"), _("&No")) == 0)) {
-               sample_fname.copyTo(dest_fname);
-               dest_fname.refresh();
-               change_adaptor();
-       }
-}
-
-
-void GuiGraphics::on_editPB_clicked()
-{
-       string const fname = fromqstr(filename->text());
-       FileName dest_fname(FileName(fromqstr(bufferFilePath())), fname);
-       string fmt_name = theFormats().getFormatFromFile(FileName(fname));
-       if (checkFileExists())
-               theFormats().edit(buffer(), dest_fname, fmt_name);
-}
-
-
-void GuiGraphics::on_okPB_clicked()
-{
-       if (checkFileExists())
-               applyView();
-}
-
-
 void GuiGraphics::on_getPB_clicked()
 {
        getBB();
@@ -563,9 +467,9 @@ void GuiGraphics::updateAspectRatioStatus()
 }
 
 
-void GuiGraphics::on_aspectratio_toggled(bool aspectratio)
+void GuiGraphics::on_aspectratio_toggled(bool aspect_ratio)
 {
-       if (aspectratio) {
+       if (aspect_ratio) {
                WidthCB->setText(qt_("Set max. &width:"));
                HeightCB->setText(qt_("Set max. &height:"));
                Width->setToolTip(qt_("Maximal width of image in output"));
@@ -579,12 +483,12 @@ void GuiGraphics::on_aspectratio_toggled(bool aspectratio)
 }
 
 
-void GuiGraphics::on_angle_textChanged(const QString & filename)
+void GuiGraphics::on_angle_textChanged(const QString & file_name)
 {
        rotateOrderCB->setEnabled((WidthCB->isChecked() ||
                                 HeightCB->isChecked() ||
                                 scaleCB->isChecked()) &&
-                                (filename != "0"));
+                                (file_name != "0"));
 }
 
 
@@ -598,7 +502,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
        lbYunit->clear();
        rtXunit->clear();
        rtYunit->clear();
-       
+
        for (size_t i = 0; i < bb_size; i++) {
                lbXunit->addItem(qt_(bb_units_gui[i]),
                        toqstr(bb_units[i]));
@@ -609,7 +513,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
                rtYunit->addItem(qt_(bb_units_gui[i]),
                        toqstr(bb_units[i]));
        }
-       
+
        // set the right default unit
        Length::UNIT const defaultUnit = Length::defaultUnit();
 
@@ -846,9 +750,9 @@ bool GuiGraphics::isValid()
 }
 
 
-bool GuiGraphics::initialiseParams(string const & data)
+bool GuiGraphics::initialiseParams(string const & sdata)
 {
-       InsetGraphics::string2params(data, buffer(), params_);
+       InsetGraphics::string2params(sdata, buffer(), params_);
        paramsToDialog(params_);
        current_group_ = params_.groupId;
        return true;
@@ -875,16 +779,16 @@ QString GuiGraphics::browse(QString const & in_name) const
 
        // Does user clipart directory exist?
        string clipdir = addName(package().user_support().absFileName(), "clipart");
-       FileName clip(clipdir);
+       FileName fclip(clipdir);
 
        // bail out to system clipart directory
-       if (!clip.isDirectory())
+       if (!fclip.isDirectory())
                clipdir = addName(package().system_support().absFileName(), "clipart");
 
        return browseRelToParent(in_name, bufferFilePath(),
-               title, fileFilters(QString()), false, 
-               qt_("Clipart|#C#c"), toqstr(clipdir),
-               qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+               title, fileFilters(QString()), false,
+               qt_("&Clipart"), toqstr(clipdir),
+               qt_("D&ocuments"), toqstr(lyxrc.document_path));
 }