2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-10-13 19:06:09 +00:00
|
|
|
* \file GuiHyperlink.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2007-10-07 14:19:14 +00:00
|
|
|
* \author Angus Leeming
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-10-13 19:06:09 +00:00
|
|
|
#include "GuiHyperlink.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-10-27 17:02:42 +00:00
|
|
|
#include "insets/InsetHyperlink.h"
|
2007-08-31 22:16:11 +00:00
|
|
|
|
2010-07-18 21:23:26 +00:00
|
|
|
#if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
|
2010-01-30 11:34:28 +00:00
|
|
|
// GCC couldn't find operator==
|
|
|
|
namespace lyx {
|
2010-04-23 13:20:28 +00:00
|
|
|
bool operator==(lyx::docstring const & d, char const * c);
|
2010-01-30 11:34:28 +00:00
|
|
|
namespace frontend {
|
2010-10-27 17:02:42 +00:00
|
|
|
bool operator==(lyx::docstring const & d, char const * c)
|
2010-04-23 12:58:17 +00:00
|
|
|
{ return lyx::operator ==(d, c); }
|
2010-01-30 11:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2010-10-27 17:02:42 +00:00
|
|
|
GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-11-01 17:49:17 +00:00
|
|
|
connect(targetED, SIGNAL(textChanged(const QString &)),
|
2010-10-27 17:02:42 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-08-12 12:40:11 +00:00
|
|
|
connect(nameED, SIGNAL(textChanged(const QString &)),
|
2010-10-27 17:02:42 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-11-01 17:49:17 +00:00
|
|
|
connect(webRB, SIGNAL(clicked()),
|
2010-10-27 17:02:42 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-11-01 17:49:17 +00:00
|
|
|
connect(emailRB, SIGNAL(clicked()),
|
2010-10-27 17:02:42 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-11-01 17:49:17 +00:00
|
|
|
connect(fileRB, SIGNAL(clicked()),
|
2010-10-27 17:02:42 +00:00
|
|
|
this, SIGNAL(changed()));
|
2007-03-28 20:14:50 +00:00
|
|
|
|
2007-11-01 17:49:17 +00:00
|
|
|
setFocusProxy(targetED);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-27 17:02:42 +00:00
|
|
|
void GuiHyperlink::paramsToDialog(Inset const * inset)
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2010-10-27 17:02:42 +00:00
|
|
|
InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
|
|
|
|
InsetCommandParams const & params = hlink->params();
|
2007-08-31 22:16:11 +00:00
|
|
|
|
2010-10-27 17:02:42 +00:00
|
|
|
targetED->setText(toqstr(params["target"]));
|
|
|
|
nameED->setText(toqstr(params["name"]));
|
|
|
|
docstring const & type = params["type"];
|
|
|
|
if (type.empty())
|
2007-11-01 17:49:17 +00:00
|
|
|
webRB->setChecked(true);
|
2010-10-27 17:02:42 +00:00
|
|
|
else if (type == "mailto:")
|
2007-11-01 17:49:17 +00:00
|
|
|
emailRB->setChecked(true);
|
2010-10-27 17:02:42 +00:00
|
|
|
else if (type == "file:")
|
2007-11-01 17:49:17 +00:00
|
|
|
fileRB->setChecked(true);
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-23 16:20:47 +00:00
|
|
|
bool GuiHyperlink::initialiseParams(std::string const & data)
|
|
|
|
{
|
|
|
|
InsetCommandParams params(insetCode());
|
|
|
|
if (!InsetCommand::string2params(data, params))
|
|
|
|
return false;
|
|
|
|
targetED->setText(toqstr(params["target"]));
|
|
|
|
nameED->setText(toqstr(params["name"]));
|
|
|
|
if (params["type"] == from_utf8("mailto:"))
|
|
|
|
emailRB->setChecked(true);
|
|
|
|
else if (params["type"] == from_utf8("file:"))
|
|
|
|
fileRB->setChecked(true);
|
|
|
|
else
|
|
|
|
webRB->setChecked(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-27 17:02:42 +00:00
|
|
|
docstring GuiHyperlink::dialogToParams() const
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2010-10-27 17:02:42 +00:00
|
|
|
InsetCommandParams params(insetCode());
|
|
|
|
|
|
|
|
params["target"] = qstring_to_ucs4(targetED->text());
|
|
|
|
params["name"] = qstring_to_ucs4(nameED->text());
|
2007-11-01 17:49:17 +00:00
|
|
|
if (webRB->isChecked())
|
2014-02-23 16:20:47 +00:00
|
|
|
params["type"] = from_utf8("");
|
2007-11-01 17:49:17 +00:00
|
|
|
else if (emailRB->isChecked())
|
2014-02-23 16:20:47 +00:00
|
|
|
params["type"] = from_utf8("mailto:");
|
2007-11-01 17:49:17 +00:00
|
|
|
else if (fileRB->isChecked())
|
2014-02-23 16:20:47 +00:00
|
|
|
params["type"] = from_utf8("file:");
|
2010-10-27 17:02:42 +00:00
|
|
|
params.setCmdName("href");
|
2010-11-07 17:38:39 +00:00
|
|
|
return from_utf8(InsetHyperlink::params2string(params));
|
2008-04-20 09:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-30 12:44:11 +00:00
|
|
|
bool GuiHyperlink::checkWidgets(bool readonly) const
|
2008-04-20 09:24:14 +00:00
|
|
|
{
|
2015-03-30 12:44:11 +00:00
|
|
|
targetED->setReadOnly(readonly);
|
|
|
|
nameED->setReadOnly(readonly);
|
|
|
|
typeGB->setEnabled(!readonly);
|
2010-10-27 17:02:42 +00:00
|
|
|
if (!InsetParamsWidget::checkWidgets())
|
|
|
|
return false;
|
|
|
|
return !targetED->text().isEmpty() || !nameED->text().isEmpty();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 14:19:14 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2007-08-31 22:37:05 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiHyperlink.cpp"
|