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,19 +14,15 @@
#include "GuiHyperlink.h" #include "GuiHyperlink.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "FuncRequest.h"
#include "insets/InsetCommand.h"
#include <QCheckBox> #include "insets/InsetHyperlink.h"
#include <QLineEdit>
#include <QPushButton>
#if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC) #if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
// GCC couldn't find operator== // GCC couldn't find operator==
namespace lyx { namespace lyx {
bool operator==(lyx::docstring const & d, char const * c); bool operator==(lyx::docstring const & d, char const * c);
namespace frontend { namespace frontend {
bool operator==(lyx::docstring const & d, char const * c) bool operator==(lyx::docstring const & d, char const * c)
{ return lyx::operator ==(d, c); } { return lyx::operator ==(d, c); }
} }
} }
@ -36,99 +32,68 @@ namespace lyx {
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
GuiHyperlink::GuiHyperlink(GuiView & lv) GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
: GuiDialog(lv, "href", qt_("Hyperlink")),
params_(insetCode("href"))
{ {
setupUi(this); setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(targetED, SIGNAL(textChanged(const QString &)), connect(targetED, SIGNAL(textChanged(const QString &)),
this, SLOT(changed_adaptor())); this, SIGNAL(changed()));
connect(nameED, SIGNAL(textChanged(const QString &)), connect(nameED, SIGNAL(textChanged(const QString &)),
this, SLOT(changed_adaptor())); this, SIGNAL(changed()));
connect(webRB, SIGNAL(clicked()), connect(webRB, SIGNAL(clicked()),
this, SLOT(changed_adaptor())); this, SIGNAL(changed()));
connect(emailRB, SIGNAL(clicked()), connect(emailRB, SIGNAL(clicked()),
this, SLOT(changed_adaptor())); this, SIGNAL(changed()));
connect(fileRB, SIGNAL(clicked()), connect(fileRB, SIGNAL(clicked()),
this, SLOT(changed_adaptor())); this, SIGNAL(changed()));
setFocusProxy(targetED); 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"]));
void GuiHyperlink::paramsToDialog(InsetCommandParams const & /*icp*/) nameED->setText(toqstr(params["name"]));
{ docstring const & type = params["type"];
targetED->setText(toqstr(params_["target"])); if (type.empty())
nameED->setText(toqstr(params_["name"]));
if (params_["type"] == "")
webRB->setChecked(true); webRB->setChecked(true);
else if (params_["type"] == "mailto:") else if (type == "mailto:")
emailRB->setChecked(true); emailRB->setChecked(true);
else if (params_["type"] == "file:") else if (type == "file:")
fileRB->setChecked(true); fileRB->setChecked(true);
bc().setValid(isValid());
} }
void GuiHyperlink::applyView() docstring GuiHyperlink::dialogToParams() const
{ {
params_["target"] = qstring_to_ucs4(targetED->text()); InsetCommandParams params(insetCode());
params_["name"] = qstring_to_ucs4(nameED->text());
params["target"] = qstring_to_ucs4(targetED->text());
params["name"] = qstring_to_ucs4(nameED->text());
if (webRB->isChecked()) if (webRB->isChecked())
params_["type"] = qstring_to_ucs4(""); params["type"] = qstring_to_ucs4("");
else if (emailRB->isChecked()) else if (emailRB->isChecked())
params_["type"] = qstring_to_ucs4("mailto:"); params["type"] = qstring_to_ucs4("mailto:");
else if (fileRB->isChecked()) else if (fileRB->isChecked())
params_["type"] = qstring_to_ucs4("file:"); params["type"] = qstring_to_ucs4("file:");
params_.setCmdName("href"); 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(); 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 frontend
} // namespace lyx } // namespace lyx

View File

@ -13,46 +13,29 @@
#ifndef GUIHYPERLINK_H #ifndef GUIHYPERLINK_H
#define GUIHYPERLINK_H #define GUIHYPERLINK_H
#include "GuiDialog.h" #include "InsetParamsWidget.h"
#include "ui_HyperlinkUi.h" #include "ui_HyperlinkUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class GuiHyperlink : public GuiDialog, public Ui::HyperlinkUi class GuiHyperlink : public InsetParamsWidget, public Ui::HyperlinkUi
{ {
Q_OBJECT Q_OBJECT
public: public:
/// Constructor ///
GuiHyperlink(GuiView & lv); GuiHyperlink(QWidget * parent = 0);
public Q_SLOTS:
void changed_adaptor();
private: private:
/// /// \name InsetParamsWidget inherited methods
bool isValid(); //@{
/// apply dialog InsetCode insetCode() const { return HYPERLINK_CODE; }
void applyView(); FuncCode creationCode() const { return LFUN_INSET_INSERT; }
/// update dialog void paramsToDialog(Inset const *);
void updateContents() {} docstring dialogToParams() const;
/// bool checkWidgets() const;
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_;
}; };
} // namespace frontend } // namespace frontend

View File

@ -287,7 +287,7 @@ struct GuiView::GuiViewPrivate
{ {
return splitter_->count(); return splitter_->count();
} }
TabWorkArea * tabWorkArea(int i) TabWorkArea * tabWorkArea(int i)
{ {
return dynamic_cast<TabWorkArea *>(splitter_->widget(i)); return dynamic_cast<TabWorkArea *>(splitter_->widget(i));
@ -378,14 +378,14 @@ public:
template<class T> template<class T>
static docstring runAndDestroy(const T& func, Buffer const * orig, Buffer * buffer, string const & format, string const & msg); static docstring runAndDestroy(const T& func, Buffer const * orig, Buffer * buffer, string const & format, string const & msg);
// TODO syncFunc/previewFunc: use bind // TODO syncFunc/previewFunc: use bind
bool asyncBufferProcessing(string const & argument, bool asyncBufferProcessing(string const & argument,
Buffer const * used_buffer, Buffer const * used_buffer,
docstring const & msg, docstring const & msg,
docstring (*asyncFunc)(Buffer const *, Buffer *, string const &), docstring (*asyncFunc)(Buffer const *, Buffer *, string const &),
bool (Buffer::*syncFunc)(string const &, bool, bool) const, bool (Buffer::*syncFunc)(string const &, bool, bool) const,
bool (Buffer::*previewFunc)(string const &, bool) const); bool (Buffer::*previewFunc)(string const &, bool) const);
QTimer processing_cursor_timer_; QTimer processing_cursor_timer_;
bool indicates_processing_; bool indicates_processing_;
@ -2932,12 +2932,12 @@ docstring GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer
bool GuiView::GuiViewPrivate::asyncBufferProcessing( bool GuiView::GuiViewPrivate::asyncBufferProcessing(
string const & argument, string const & argument,
Buffer const * used_buffer, Buffer const * used_buffer,
docstring const & msg, docstring const & msg,
docstring (*asyncFunc)(Buffer const *, Buffer *, string const &), docstring (*asyncFunc)(Buffer const *, Buffer *, string const &),
bool (Buffer::*syncFunc)(string const &, bool, bool) const, bool (Buffer::*syncFunc)(string const &, bool, bool) const,
bool (Buffer::*previewFunc)(string const &, bool) const) bool (Buffer::*previewFunc)(string const &, bool) const)
{ {
if (!used_buffer) { if (!used_buffer) {
return false; return false;
@ -3024,13 +3024,13 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
} }
#else #else
/* TODO/Review: Is it a problem to also export the children? /* TODO/Review: Is it a problem to also export the children?
See the update_unincluded flag */ See the update_unincluded flag */
d.asyncBufferProcessing(argument, d.asyncBufferProcessing(argument,
doc_buffer, doc_buffer,
_("Exporting ..."), _("Exporting ..."),
&GuiViewPrivate::exportAndDestroy, &GuiViewPrivate::exportAndDestroy,
&Buffer::doExport, &Buffer::doExport,
0); 0);
// TODO Inform user about success // TODO Inform user about success
#endif #endif
break; break;
@ -3038,37 +3038,37 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
case LFUN_BUFFER_UPDATE: { case LFUN_BUFFER_UPDATE: {
d.asyncBufferProcessing(argument, d.asyncBufferProcessing(argument,
doc_buffer, doc_buffer,
_("Exporting ..."), _("Exporting ..."),
&GuiViewPrivate::compileAndDestroy, &GuiViewPrivate::compileAndDestroy,
&Buffer::doExport, &Buffer::doExport,
0); 0);
break; break;
} }
case LFUN_BUFFER_VIEW: { case LFUN_BUFFER_VIEW: {
d.asyncBufferProcessing(argument, d.asyncBufferProcessing(argument,
doc_buffer, doc_buffer,
_("Previewing ..."), _("Previewing ..."),
&GuiViewPrivate::previewAndDestroy, &GuiViewPrivate::previewAndDestroy,
0, 0,
&Buffer::preview); &Buffer::preview);
break; break;
} }
case LFUN_MASTER_BUFFER_UPDATE: { case LFUN_MASTER_BUFFER_UPDATE: {
d.asyncBufferProcessing(argument, d.asyncBufferProcessing(argument,
(doc_buffer ? doc_buffer->masterBuffer() : 0), (doc_buffer ? doc_buffer->masterBuffer() : 0),
docstring(), docstring(),
&GuiViewPrivate::compileAndDestroy, &GuiViewPrivate::compileAndDestroy,
&Buffer::doExport, &Buffer::doExport,
0); 0);
break; break;
} }
case LFUN_MASTER_BUFFER_VIEW: { case LFUN_MASTER_BUFFER_VIEW: {
d.asyncBufferProcessing(argument, d.asyncBufferProcessing(argument,
(doc_buffer ? doc_buffer->masterBuffer() : 0), (doc_buffer ? doc_buffer->masterBuffer() : 0),
docstring(), docstring(),
&GuiViewPrivate::previewAndDestroy, &GuiViewPrivate::previewAndDestroy,
0, &Buffer::preview); 0, &Buffer::preview);
break; break;
} }
case LFUN_BUFFER_SWITCH: { case LFUN_BUFFER_SWITCH: {
@ -3158,7 +3158,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
int ret = 0; int ret = 0;
if (!doc_buffer->isClean()) { if (!doc_buffer->isClean()) {
docstring const file = docstring const file =
makeDisplayPath(doc_buffer->absFileName(), 20); makeDisplayPath(doc_buffer->absFileName(), 20);
docstring text = bformat(_("Any changes will be lost. " docstring text = bformat(_("Any changes will be lost. "
"Are you sure you want to revert to the saved version " "Are you sure you want to revert to the saved version "
@ -3234,7 +3234,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
//FIXME: pass DispatchResult here? //FIXME: pass DispatchResult here?
inset->dispatch(currentBufferView()->cursor(), fr); inset->dispatch(currentBufferView()->cursor(), fr);
} }
} }
break; break;
} }
@ -3837,8 +3837,6 @@ Dialog * GuiView::build(string const & name)
return createGuiSearchAdv(*this); return createGuiSearchAdv(*this);
if (name == "graphics") if (name == "graphics")
return createGuiGraphics(*this); return createGuiGraphics(*this);
if (name == "href")
return createGuiHyperlink(*this);
if (name == "include") if (name == "include")
return createGuiInclude(*this); return createGuiInclude(*this);
if (name == "index") if (name == "index")

View File

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

View File

@ -1,20 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>HyperlinkUi</class> <class>HyperlinkUi</class>
<widget class="QDialog" name="HyperlinkUi"> <widget class="QWidget" name="HyperlinkUi">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>302</width> <width>343</width>
<height>151</height> <height>130</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string/> <string/>
</property> </property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="targetLA"> <widget class="QLabel" name="targetLA">
@ -104,55 +102,6 @@
</layout> </layout>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<tabstops> <tabstops>
@ -161,8 +110,6 @@
<tabstop>webRB</tabstop> <tabstop>webRB</tabstop>
<tabstop>emailRB</tabstop> <tabstop>emailRB</tabstop>
<tabstop>fileRB</tabstop> <tabstop>fileRB</tabstop>
<tabstop>okPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops> </tabstops>
<includes> <includes>
<include location="local">qt_i18n.h</include> <include location="local">qt_i18n.h</include>