Migrate GuiPrintNomencl to InsetParamsDialog.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35938 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-10-30 20:14:57 +00:00
parent 4b57639ad0
commit 766e300f42
5 changed files with 39 additions and 158 deletions

View File

@ -25,44 +25,24 @@
#include "support/gettext.h" #include "support/gettext.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include <QLineEdit>
#include <QPushButton>
#include <QValidator>
using namespace std; using namespace std;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
GuiPrintNomencl::GuiPrintNomencl(GuiView & lv) GuiPrintNomencl::GuiPrintNomencl(QWidget * parent) : InsetParamsWidget(parent)
: GuiDialog(lv, "nomencl_print", qt_("Nomenclature settings")),
params_(insetCode("nomencl_print"))
{ {
setupUi(this); setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(valueLE, SIGNAL(textChanged(QString)), connect(valueLE, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor())); this, SIGNAL(changed()));
connect(unitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), connect(unitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor())); this, SIGNAL(changed()));
valueLE->setValidator(unsignedLengthValidator(valueLE)); valueLE->setValidator(unsignedLengthValidator(valueLE));
// Manage the ok, apply, restore and cancel/close buttons
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
bc().setOK(okPB);
bc().setApply(applyPB);
bc().setCancel(closePB);
// disable for read-only documents
bc().addReadOnly(valueLE);
bc().addReadOnly(unitLC);
// initialize the length validator // initialize the length validator
bc().addCheckedLineEdit(valueLE, valueLA); addCheckedWidget(valueLE, valueLA);
setWidthCO->addItem(qt_("Default"), setWidthCO->addItem(qt_("Default"),
QVariant(toqstr("none"))); QVariant(toqstr("none")));
@ -73,12 +53,6 @@ GuiPrintNomencl::GuiPrintNomencl(GuiView & lv)
} }
void GuiPrintNomencl::change_adaptor()
{
changed();
}
void GuiPrintNomencl::on_setWidthCO_activated(int i) void GuiPrintNomencl::on_setWidthCO_activated(int i)
{ {
bool const custom = bool const custom =
@ -91,73 +65,48 @@ void GuiPrintNomencl::on_setWidthCO_activated(int i)
} }
void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & /*icp*/) void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & params)
{ {
setWidthCO->setCurrentIndex( setWidthCO->setCurrentIndex(
setWidthCO->findData(toqstr(params_["set_width"]))); setWidthCO->findData(toqstr(params["set_width"])));
lengthToWidgets(valueLE, lengthToWidgets(valueLE,
unitLC, unitLC,
params_["width"], params["width"],
Length::defaultUnit()); Length::defaultUnit());
bc().setValid(isValid());
} }
void GuiPrintNomencl::updateContents() void GuiPrintNomencl::paramsToDialog(Inset const * inset)
{ {
bool const custom = (setWidthCO->itemData( InsetNomencl const * nomencl = static_cast<InsetNomencl const *>(inset);
setWidthCO->currentIndex()).toString() paramsToDialog(nomencl->params());
== "custom");
valueLE->setEnabled(custom);
unitLC->setEnabled(custom);
valueLA->setEnabled(custom);
} }
void GuiPrintNomencl::applyView() docstring GuiPrintNomencl::dialogToParams() const
{ {
InsetCommandParams params(insetCode());
docstring const set_width = qstring_to_ucs4(setWidthCO->itemData( docstring const set_width = qstring_to_ucs4(setWidthCO->itemData(
setWidthCO->currentIndex()).toString()); setWidthCO->currentIndex()).toString());
params_["set_width"] = set_width; params["set_width"] = set_width;
docstring width; docstring width;
if (set_width == from_ascii("custom")) if (set_width == from_ascii("custom"))
width = from_utf8(widgetsToLength(valueLE, unitLC)); width = from_utf8(widgetsToLength(valueLE, unitLC));
params_["width"] = width; params["width"] = width;
return from_ascii(InsetNomencl::params2string(params));
} }
bool GuiPrintNomencl::isValid() const bool GuiPrintNomencl::checkWidgets() const
{ {
if (!InsetParamsWidget::checkWidgets())
return false;
return setWidthCO->itemData( return setWidthCO->itemData(
setWidthCO->currentIndex()).toString() != "custom" setWidthCO->currentIndex()).toString() != "custom"
|| !valueLE->text().isEmpty(); || !valueLE->text().isEmpty();
} }
bool GuiPrintNomencl::initialiseParams(std::string const & data)
{
InsetCommand::string2params(data, params_);
paramsToDialog(params_);
return true;
}
void GuiPrintNomencl::dispatchParams()
{
std::string const lfun = InsetCommand::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiPrintNomencl(GuiView & lv)
{
return new GuiPrintNomencl(lv);
}
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -13,46 +13,32 @@
#ifndef GUIPRINTNOMENCL_H #ifndef GUIPRINTNOMENCL_H
#define GUIPRINTNOMENCL_H #define GUIPRINTNOMENCL_H
#include "GuiDialog.h" #include "InsetParamsWidget.h"
#include "ui_PrintNomenclUi.h" #include "ui_PrintNomenclUi.h"
#include "insets/InsetCommandParams.h"
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class GuiPrintNomencl : public GuiDialog, public Ui::PrintNomenclUi class GuiPrintNomencl : public InsetParamsWidget, public Ui::PrintNomenclUi
{ {
Q_OBJECT Q_OBJECT
public: public:
GuiPrintNomencl(GuiView & lv); GuiPrintNomencl(QWidget * parent = 0);
private Q_SLOTS: private Q_SLOTS:
void change_adaptor();
void on_setWidthCO_activated(int); void on_setWidthCO_activated(int);
private: private:
/// Apply changes /// \name InsetParamsWidget inherited methods
void applyView(); //@{
/// Update dialog before showing it InsetCode insetCode() const { return NOMENCL_PRINT_CODE; }
void updateContents(); FuncCode creationCode() const { return LFUN_INSET_INSERT; }
/// void paramsToDialog(Inset const *);
bool initialiseParams(std::string const & data); void paramsToDialog(InsetCommandParams const &);
/// docstring dialogToParams() const;
void paramsToDialog(InsetCommandParams const & icp); bool checkWidgets() const;
/// //@}
void clearParams() { params_.clear(); }
///
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
bool isValid() const;
///
InsetCommandParams params_;
}; };
} // namespace frontend } // namespace frontend

View File

@ -3754,7 +3754,6 @@ Dialog * createGuiPhantom(GuiView & lv);
Dialog * createGuiPreferences(GuiView & lv); Dialog * createGuiPreferences(GuiView & lv);
Dialog * createGuiPrint(GuiView & lv); Dialog * createGuiPrint(GuiView & lv);
Dialog * createGuiPrintindex(GuiView & lv); Dialog * createGuiPrintindex(GuiView & lv);
Dialog * createGuiPrintNomencl(GuiView & lv);
Dialog * createGuiRef(GuiView & lv); Dialog * createGuiRef(GuiView & lv);
Dialog * createGuiSearch(GuiView & lv); Dialog * createGuiSearch(GuiView & lv);
Dialog * createGuiSearchAdv(GuiView & lv); Dialog * createGuiSearchAdv(GuiView & lv);
@ -3822,8 +3821,6 @@ Dialog * GuiView::build(string const & name)
return createGuiDelimiter(*this); return createGuiDelimiter(*this);
if (name == "mathmatrix") if (name == "mathmatrix")
return createGuiMathMatrix(*this); return createGuiMathMatrix(*this);
if (name == "nomencl_print")
return createGuiPrintNomencl(*this);
if (name == "note") if (name == "note")
return createGuiNote(*this); return createGuiNote(*this);
if (name == "paragraph") if (name == "paragraph")

View File

@ -22,6 +22,7 @@
#include "GuiLabel.h" #include "GuiLabel.h"
#include "GuiLine.h" #include "GuiLine.h"
#include "GuiNomenclature.h" #include "GuiNomenclature.h"
#include "GuiPrintNomencl.h"
#include "GuiTabular.h" #include "GuiTabular.h"
#include "GuiVSpace.h" #include "GuiVSpace.h"
#include "FloatPlacement.h" #include "FloatPlacement.h"
@ -255,6 +256,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
case NOMENCL_CODE: case NOMENCL_CODE:
widget = new GuiNomenclature; widget = new GuiNomenclature;
break; break;
case NOMENCL_PRINT_CODE:
widget = new GuiPrintNomencl;
break;
case SPACE_CODE: case SPACE_CODE:
widget = new GuiHSpace(false); widget = new GuiHSpace(false);
break; break;

View File

@ -1,19 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>PrintNomenclUi</class> <class>PrintNomenclUi</class>
<widget class="QDialog" name="PrintNomenclUi"> <widget class="QWidget" name="PrintNomenclUi">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>280</width> <width>336</width>
<height>119</height> <height>80</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string/> <string>&quot;Nomenclature settings&quot;</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
@ -59,56 +57,6 @@
<item row="1" column="3"> <item row="1" column="3">
<widget class="LengthCombo" name="unitLC"/> <widget class="LengthCombo" name="unitLC"/>
</item> </item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>74</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="okPB">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB">
<property name="text">
<string>&amp;Apply</string>
</property>
<property name="autoDefault">
<bool>false</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>
<customwidgets> <customwidgets>
@ -120,9 +68,6 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>valueLE</tabstop> <tabstop>valueLE</tabstop>
<tabstop>okPB</tabstop>
<tabstop>applyPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops> </tabstops>
<includes> <includes>
<include location="local">qt_i18n.h</include> <include location="local">qt_i18n.h</include>