Migrate GuiHyperlink to InsetParamsDialog.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35867 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-10-27 17:02:42 +00:00
parent 77713af558
commit 26dc500557
5 changed files with 91 additions and 194 deletions

View File

@ -14,12 +14,8 @@
#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==
@ -36,99 +32,68 @@ namespace lyx {
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(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();
void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/)
{
targetED->setText(toqstr(params_["target"]));
nameED->setText(toqstr(params_["name"]));
if (params_["type"] == "")
targetED->setText(toqstr(params["target"]));
nameED->setText(toqstr(params["name"]));
docstring const & type = params["type"];
if (type.empty())
webRB->setChecked(true);
else if (params_["type"] == "mailto:")
else if (type == "mailto:")
emailRB->setChecked(true);
else if (params_["type"] == "file:")
else if (type == "file:")
fileRB->setChecked(true);
bc().setValid(isValid());
}
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"] = qstring_to_ucs4("");
else if (emailRB->isChecked())
params_["type"] = qstring_to_ucs4("mailto:");
params["type"] = qstring_to_ucs4("mailto:");
else if (fileRB->isChecked())
params_["type"] = qstring_to_ucs4("file:");
params_.setCmdName("href");
params["type"] = qstring_to_ucs4("file:");
params.setCmdName("href");
return from_ascii(InsetHyperlink::params2string("href", params));
}
bool GuiHyperlink::isValid()
bool GuiHyperlink::checkWidgets() const
{
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

View File

@ -13,46 +13,29 @@
#ifndef GUIHYPERLINK_H
#define GUIHYPERLINK_H
#include "GuiDialog.h"
#include "InsetParamsWidget.h"
#include "ui_HyperlinkUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx {
namespace frontend {
class GuiHyperlink : public GuiDialog, public Ui::HyperlinkUi
class GuiHyperlink : public InsetParamsWidget, public Ui::HyperlinkUi
{
Q_OBJECT
public:
/// Constructor
GuiHyperlink(GuiView & lv);
public Q_SLOTS:
void changed_adaptor();
///
GuiHyperlink(QWidget * parent = 0);
private:
///
bool isValid();
/// apply dialog
void applyView();
/// update dialog
void updateContents() {}
///
bool initialiseParams(std::string const & data);
///
void paramsToDialog(InsetCommandParams const & icp);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
/// \name InsetParamsWidget inherited methods
//@{
InsetCode insetCode() const { return HYPERLINK_CODE; }
FuncCode creationCode() const { return LFUN_INSET_INSERT; }
void paramsToDialog(Inset const *);
docstring dialogToParams() const;
bool checkWidgets() const;
//@}
};
} // namespace frontend

View File

@ -3837,8 +3837,6 @@ Dialog * GuiView::build(string const & name)
return createGuiSearchAdv(*this);
if (name == "graphics")
return createGuiGraphics(*this);
if (name == "href")
return createGuiHyperlink(*this);
if (name == "include")
return createGuiInclude(*this);
if (name == "index")

View File

@ -16,6 +16,7 @@
#include "GuiBranch.h"
#include "GuiBibitem.h"
#include "GuiERT.h"
#include "GuiHyperlink.h"
#include "GuiInfo.h"
#include "GuiLine.h"
#include "GuiHSpace.h"
@ -232,6 +233,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
case BOX_CODE:
widget = new GuiBox;
break;
case HYPERLINK_CODE:
widget = new GuiHyperlink;
break;
case INFO_CODE:
widget = new GuiInfo;
break;

View File

@ -1,20 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HyperlinkUi</class>
<widget class="QDialog" name="HyperlinkUi">
<widget class="QWidget" name="HyperlinkUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>302</width>
<height>151</height>
<width>343</width>
<height>130</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="targetLA">
@ -104,55 +102,6 @@
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB">
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
@ -161,8 +110,6 @@
<tabstop>webRB</tabstop>
<tabstop>emailRB</tabstop>
<tabstop>fileRB</tabstop>
<tabstop>okPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops>
<includes>
<include location="local">qt_i18n.h</include>