]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiHyperlink.cpp
Make the InsetInfo dialog a bit less esoteric.
[lyx.git] / src / frontends / qt4 / GuiHyperlink.cpp
index 8323b65ff3d3f1f625f602fbfa9f53bbfcc5bdca..c063ca236260789badf89e16a8178c55e010e019 100644 (file)
 #include "GuiHyperlink.h"
 
 #include "qt_helpers.h"
-#include "FuncRequest.h"
-#include "insets/InsetCommand.h"
 
-#include <QCheckBox>
-#include <QLineEdit>
-#include <QPushButton>
+#include "insets/InsetHyperlink.h"
+
+#if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
+// GCC couldn't find operator==
+namespace lyx {
+       bool operator==(lyx::docstring const & d, char const * c);
+       namespace frontend {
+               bool operator==(lyx::docstring const & d, char const * c)
+                 { return lyx::operator ==(d, c); }
+       } // namespace frontend
+} // namespace lyx
+#endif
 
 
 namespace lyx {
 namespace frontend {
 
-GuiHyperlink::GuiHyperlink(GuiView & lv)
-       : GuiDialog(lv, "href", qt_("Hyperlink")),
-    params_(insetCode("href"))
+GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
 {
        setupUi(this);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
        connect(targetED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(changed_adaptor()));
+               this, SIGNAL(changed()));
        connect(nameED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(changed_adaptor()));
+               this, SIGNAL(changed()));
+       connect(literalCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
        connect(webRB, SIGNAL(clicked()),
-               this, SLOT(changed_adaptor()));
+               this, SIGNAL(changed()));
        connect(emailRB, SIGNAL(clicked()),
-               this, SLOT(changed_adaptor()));
+               this, SIGNAL(changed()));
        connect(fileRB, SIGNAL(clicked()),
-               this, SLOT(changed_adaptor()));
+               this, SIGNAL(changed()));
 
        setFocusProxy(targetED);
-
-       bc().setPolicy(ButtonPolicy::OkCancelReadOnlyPolicy);
-
-       bc().setOK(okPB);
-       bc().setCancel(closePB);
-       bc().addReadOnly(targetED);
-       bc().addReadOnly(nameED);
-       bc().addReadOnly(webRB);
-       bc().addReadOnly(emailRB);
-       bc().addReadOnly(fileRB);
 }
 
 
-void GuiHyperlink::changed_adaptor()
+void GuiHyperlink::paramsToDialog(Inset const * inset)
 {
-       changed();
+       InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
+       InsetCommandParams const & params = hlink->params();
+
+       targetED->setText(toqstr(params["target"]));
+       nameED->setText(toqstr(params["name"]));
+       literalCB->setChecked(params["literal"] == "true");
+       docstring const & type = params["type"];
+       if (type.empty())
+               webRB->setChecked(true);
+       else if (type == "mailto:")
+               emailRB->setChecked(true);
+       else if (type == "file:")
+               fileRB->setChecked(true);
 }
 
 
-void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/)
+bool GuiHyperlink::initialiseParams(std::string const & sdata)
 {
-       targetED->setText(toqstr(params_["target"]));
-       nameED->setText(toqstr(params_["name"]));
-       if (params_["type"] == "")
-               webRB->setChecked(true);
-       else if (params_["type"] == "mailto:")
+       InsetCommandParams params(insetCode());
+       if (!InsetCommand::string2params(sdata, params))
+               return false;
+       targetED->setText(toqstr(params["target"]));
+       nameED->setText(toqstr(params["name"]));
+       literalCB->setChecked(params["literal"] == "true");
+       if (params["type"] == from_utf8("mailto:"))
                emailRB->setChecked(true);
-       else if (params_["type"] == "file:")
+       else if (params["type"] == from_utf8("file:"))
                fileRB->setChecked(true);
-       bc().setValid(isValid());
+       else
+               webRB->setChecked(true);
+       return true;
 }
 
 
-void GuiHyperlink::applyView()
+docstring GuiHyperlink::dialogToParams() const
 {
-       params_["target"] = qstring_to_ucs4(targetED->text());
-       params_["name"] = qstring_to_ucs4(nameED->text());
+       InsetCommandParams params(insetCode());
+
+       params["target"] = qstring_to_ucs4(targetED->text());
+       params["name"] = qstring_to_ucs4(nameED->text());
        if (webRB->isChecked())
-               params_["type"] = qstring_to_ucs4("");
+               params["type"] = from_utf8("");
        else if (emailRB->isChecked())
-               params_["type"] = qstring_to_ucs4("mailto:");
+               params["type"] = from_utf8("mailto:");
        else if (fileRB->isChecked())
-               params_["type"] = qstring_to_ucs4("file:");
-       params_.setCmdName("href");
+               params["type"] = from_utf8("file:");
+       params["literal"] = literalCB->isChecked()
+                       ? from_ascii("true") : from_ascii("false");
+       params.setCmdName("href");
+       return from_utf8(InsetHyperlink::params2string(params));
 }
 
 
-bool GuiHyperlink::isValid()
+bool GuiHyperlink::checkWidgets(bool readonly) const
 {
+       targetED->setReadOnly(readonly);
+       nameED->setReadOnly(readonly);
+       typeGB->setEnabled(!readonly);
+       if (!InsetParamsWidget::checkWidgets())
+               return false;
        return !targetED->text().isEmpty() || !nameED->text().isEmpty();
 }
 
 
-bool GuiHyperlink::initialiseParams(std::string const & data)
-{
-       // The name passed with LFUN_INSET_APPLY is also the name
-       // used to identify the mailer.
-       InsetCommand::string2params("href", data, params_);
-       paramsToDialog(params_);
-       return true;
-}
-
-
-void GuiHyperlink::dispatchParams()
-{
-       std::string const lfun = InsetCommand::params2string("href", params_);
-       dispatch(FuncRequest(getLfun(), lfun));
-}
-
-
-Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); }
-
-
 } // namespace frontend
 } // namespace lyx