]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiHyperlink.cpp
Fix the tab ordering of GuiDocument components.
[lyx.git] / src / frontends / qt4 / GuiHyperlink.cpp
index 680aceba03513b4e5448a87dcc08809b97a41d4e..7cb9cc61d4ad7f5c4791eb3416fd9708c5137d96 100644 (file)
 #include "GuiHyperlink.h"
 
 #include "qt_helpers.h"
-#include "FuncRequest.h"
-#include "insets/InsetCommand.h"
 
-#include <QCheckBox>
-#include <QCloseEvent>
-#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); }
+       }
+}
+#endif
 
 
 namespace lyx {
 namespace frontend {
 
-GuiHyperlink::GuiHyperlink(LyXView & lv)
-       : GuiCommand(lv, "href")
+GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
 {
        setupUi(this);
-       setViewTitle( _("Hyperlink"));
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-       connect(urlED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(changed_adaptor()));
+       connect(targetED, SIGNAL(textChanged(const QString &)),
+               this, SIGNAL(changed()));
        connect(nameED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(changed_adaptor()));
-
-       setFocusProxy(urlED);
-
-       bc().setOK(okPB);
-       bc().setCancel(closePB);
-       bc().addReadOnly(urlED);
-       bc().addReadOnly(nameED);
-}
-
-
-void GuiHyperlink::changed_adaptor()
-{
-       changed();
-}
-
-
-void GuiHyperlink::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       e->accept();
+               this, SIGNAL(changed()));
+       connect(webRB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(emailRB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(fileRB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+
+       setFocusProxy(targetED);
 }
 
 
-void GuiHyperlink::updateContents()
+void GuiHyperlink::paramsToDialog(Inset const * inset)
 {
-       urlED->setText(toqstr(params_["target"]));
-       nameED->setText(toqstr(params_["name"]));
-       bc().setValid(isValid());
+       InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
+       InsetCommandParams const & params = hlink->params();
+
+       targetED->setText(toqstr(params["target"]));
+       nameED->setText(toqstr(params["name"]));
+       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::applyView()
+docstring GuiHyperlink::dialogToParams() const
 {
-       params_["target"] = qstring_to_ucs4(urlED->text());
-       params_["name"] = qstring_to_ucs4(nameED->text());
-       params_.setCmdName("href");
+       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("");
+       else if (emailRB->isChecked())
+               params["type"] = qstring_to_ucs4("mailto:");
+       else if (fileRB->isChecked())
+               params["type"] = qstring_to_ucs4("file:");
+       params.setCmdName("href");
+       return from_utf8(InsetHyperlink::params2string(params));
 }
 
 
-bool GuiHyperlink::isValid()
+bool GuiHyperlink::checkWidgets() const
 {
-       QString const u = urlED->text();
-       QString const n = nameED->text();
-
-       return !u.isEmpty() || !n.isEmpty();
+       if (!InsetParamsWidget::checkWidgets())
+               return false;
+       return !targetED->text().isEmpty() || !nameED->text().isEmpty();
 }
 
 
-Dialog * createGuiHyperlink(LyXView & lv) { return new GuiHyperlink(lv); }
-
-
 } // namespace frontend
 } // namespace lyx
 
 
-#include "GuiHyperlink_moc.cpp"
+#include "moc_GuiHyperlink.cpp"