From 26dc500557c7126afe6e0c8d71a4a0306f21226d Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Wed, 27 Oct 2010 17:02:42 +0000 Subject: [PATCH] Migrate GuiHyperlink to InsetParamsDialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35867 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiHyperlink.cpp | 97 ++++++++----------------- src/frontends/qt4/GuiHyperlink.h | 39 +++------- src/frontends/qt4/GuiView.cpp | 82 ++++++++++----------- src/frontends/qt4/InsetParamsDialog.cpp | 4 + src/frontends/qt4/ui/HyperlinkUi.ui | 61 +--------------- 5 files changed, 90 insertions(+), 193 deletions(-) diff --git a/src/frontends/qt4/GuiHyperlink.cpp b/src/frontends/qt4/GuiHyperlink.cpp index 28a77ecb0c..f51a30b6c9 100644 --- a/src/frontends/qt4/GuiHyperlink.cpp +++ b/src/frontends/qt4/GuiHyperlink.cpp @@ -14,19 +14,15 @@ #include "GuiHyperlink.h" #include "qt_helpers.h" -#include "FuncRequest.h" -#include "insets/InsetCommand.h" -#include -#include -#include +#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) + bool operator==(lyx::docstring const & d, char const * c) { return lyx::operator ==(d, c); } } } @@ -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(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"); - -bool GuiHyperlink::isValid() -{ - 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; + return from_ascii(InsetHyperlink::params2string("href", params)); } -void GuiHyperlink::dispatchParams() +bool GuiHyperlink::checkWidgets() const { - std::string const lfun = InsetCommand::params2string("href", params_); - dispatch(FuncRequest(getLfun(), lfun)); + if (!InsetParamsWidget::checkWidgets()) + return false; + return !targetED->text().isEmpty() || !nameED->text().isEmpty(); } -Dialog * createGuiHyperlink(GuiView & lv) { return new GuiHyperlink(lv); } - - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiHyperlink.h b/src/frontends/qt4/GuiHyperlink.h index 6c02ad23c9..2134ca8a19 100644 --- a/src/frontends/qt4/GuiHyperlink.h +++ b/src/frontends/qt4/GuiHyperlink.h @@ -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(); - -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; } + GuiHyperlink(QWidget * parent = 0); 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 diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 3de3d48480..4cc75d365e 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -287,7 +287,7 @@ struct GuiView::GuiViewPrivate { return splitter_->count(); } - + TabWorkArea * tabWorkArea(int i) { return dynamic_cast(splitter_->widget(i)); @@ -378,14 +378,14 @@ public: template static docstring runAndDestroy(const T& func, Buffer const * orig, Buffer * buffer, string const & format, string const & msg); - + // TODO syncFunc/previewFunc: use bind bool asyncBufferProcessing(string const & argument, - Buffer const * used_buffer, - docstring const & msg, - docstring (*asyncFunc)(Buffer const *, Buffer *, string const &), - bool (Buffer::*syncFunc)(string const &, bool, bool) const, - bool (Buffer::*previewFunc)(string const &, bool) const); + Buffer const * used_buffer, + docstring const & msg, + docstring (*asyncFunc)(Buffer const *, Buffer *, string const &), + bool (Buffer::*syncFunc)(string const &, bool, bool) const, + bool (Buffer::*previewFunc)(string const &, bool) const); QTimer processing_cursor_timer_; bool indicates_processing_; @@ -2932,12 +2932,12 @@ docstring GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer bool GuiView::GuiViewPrivate::asyncBufferProcessing( - string const & argument, - Buffer const * used_buffer, - docstring const & msg, - docstring (*asyncFunc)(Buffer const *, Buffer *, string const &), - bool (Buffer::*syncFunc)(string const &, bool, bool) const, - bool (Buffer::*previewFunc)(string const &, bool) const) + string const & argument, + Buffer const * used_buffer, + docstring const & msg, + docstring (*asyncFunc)(Buffer const *, Buffer *, string const &), + bool (Buffer::*syncFunc)(string const &, bool, bool) const, + bool (Buffer::*previewFunc)(string const &, bool) const) { if (!used_buffer) { return false; @@ -3024,13 +3024,13 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } #else /* TODO/Review: Is it a problem to also export the children? - See the update_unincluded flag */ + See the update_unincluded flag */ d.asyncBufferProcessing(argument, - doc_buffer, - _("Exporting ..."), - &GuiViewPrivate::exportAndDestroy, - &Buffer::doExport, - 0); + doc_buffer, + _("Exporting ..."), + &GuiViewPrivate::exportAndDestroy, + &Buffer::doExport, + 0); // TODO Inform user about success #endif break; @@ -3038,37 +3038,37 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_BUFFER_UPDATE: { d.asyncBufferProcessing(argument, - doc_buffer, - _("Exporting ..."), - &GuiViewPrivate::compileAndDestroy, - &Buffer::doExport, - 0); + doc_buffer, + _("Exporting ..."), + &GuiViewPrivate::compileAndDestroy, + &Buffer::doExport, + 0); break; } case LFUN_BUFFER_VIEW: { d.asyncBufferProcessing(argument, - doc_buffer, - _("Previewing ..."), - &GuiViewPrivate::previewAndDestroy, - 0, - &Buffer::preview); + doc_buffer, + _("Previewing ..."), + &GuiViewPrivate::previewAndDestroy, + 0, + &Buffer::preview); break; } case LFUN_MASTER_BUFFER_UPDATE: { d.asyncBufferProcessing(argument, - (doc_buffer ? doc_buffer->masterBuffer() : 0), - docstring(), - &GuiViewPrivate::compileAndDestroy, - &Buffer::doExport, - 0); + (doc_buffer ? doc_buffer->masterBuffer() : 0), + docstring(), + &GuiViewPrivate::compileAndDestroy, + &Buffer::doExport, + 0); break; } case LFUN_MASTER_BUFFER_VIEW: { d.asyncBufferProcessing(argument, - (doc_buffer ? doc_buffer->masterBuffer() : 0), - docstring(), - &GuiViewPrivate::previewAndDestroy, - 0, &Buffer::preview); + (doc_buffer ? doc_buffer->masterBuffer() : 0), + docstring(), + &GuiViewPrivate::previewAndDestroy, + 0, &Buffer::preview); break; } case LFUN_BUFFER_SWITCH: { @@ -3158,7 +3158,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) int ret = 0; if (!doc_buffer->isClean()) { - docstring const file = + docstring const file = makeDisplayPath(doc_buffer->absFileName(), 20); docstring text = bformat(_("Any changes will be lost. " "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? inset->dispatch(currentBufferView()->cursor(), fr); } - } + } break; } @@ -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") diff --git a/src/frontends/qt4/InsetParamsDialog.cpp b/src/frontends/qt4/InsetParamsDialog.cpp index 4db2d21938..bd7251bdd5 100644 --- a/src/frontends/qt4/InsetParamsDialog.cpp +++ b/src/frontends/qt4/InsetParamsDialog.cpp @@ -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; diff --git a/src/frontends/qt4/ui/HyperlinkUi.ui b/src/frontends/qt4/ui/HyperlinkUi.ui index 4a33ecf248..bd9a061bfe 100644 --- a/src/frontends/qt4/ui/HyperlinkUi.ui +++ b/src/frontends/qt4/ui/HyperlinkUi.ui @@ -1,20 +1,18 @@ + HyperlinkUi - + 0 0 - 302 - 151 + 343 + 130 - - true - @@ -104,55 +102,6 @@ - - - - 6 - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - &OK - - - true - - - true - - - - - - - &Close - - - false - - - - - @@ -161,8 +110,6 @@ webRB emailRB fileRB - okPB - closePB qt_i18n.h -- 2.39.5