mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-16 07:55:41 +00:00
e15a8f3551
File format change. This allows for the relevant InsetCommand-based dialogs (such as citation text before/after, Bibitem label, hyperlink name etc.) to provide both the input of verbatim code or text that is transformed to proper LaTeX code. Some dialogs (Nomencl, Href) already had some methods (although they could not be toggled), which are now centralized and streamlined. The initial work of this patch has been done by Georg Baum (see http://www.lyx.org/trac/attachment/ticket/2751/x.diff) Fixes: #2751, #8227.
127 lines
3.2 KiB
C++
127 lines
3.2 KiB
C++
/**
|
|
* \file GuiHyperlink.cpp
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author Angus Leeming
|
|
* \author John Levon
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "GuiHyperlink.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
#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(QWidget * parent) : InsetParamsWidget(parent)
|
|
{
|
|
setupUi(this);
|
|
|
|
connect(targetED, SIGNAL(textChanged(const QString &)),
|
|
this, SIGNAL(changed()));
|
|
connect(nameED, SIGNAL(textChanged(const QString &)),
|
|
this, SIGNAL(changed()));
|
|
connect(literalCB, SIGNAL(clicked()),
|
|
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::paramsToDialog(Inset const * inset)
|
|
{
|
|
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);
|
|
}
|
|
|
|
|
|
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"]));
|
|
literalCB->setChecked(params["literal"] == "true");
|
|
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;
|
|
}
|
|
|
|
|
|
docstring GuiHyperlink::dialogToParams() const
|
|
{
|
|
InsetCommandParams params(insetCode());
|
|
|
|
params["target"] = qstring_to_ucs4(targetED->text());
|
|
params["name"] = qstring_to_ucs4(nameED->text());
|
|
if (webRB->isChecked())
|
|
params["type"] = from_utf8("");
|
|
else if (emailRB->isChecked())
|
|
params["type"] = from_utf8("mailto:");
|
|
else if (fileRB->isChecked())
|
|
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::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();
|
|
}
|
|
|
|
|
|
} // namespace frontend
|
|
} // namespace lyx
|
|
|
|
|
|
#include "moc_GuiHyperlink.cpp"
|