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/lstrings.h"
#include <QLineEdit>
#include <QPushButton>
#include <QValidator>
using namespace std;
namespace lyx {
namespace frontend {
GuiPrintNomencl::GuiPrintNomencl(GuiView & lv)
: GuiDialog(lv, "nomencl_print", qt_("Nomenclature settings")),
params_(insetCode("nomencl_print"))
GuiPrintNomencl::GuiPrintNomencl(QWidget * parent) : InsetParamsWidget(parent)
{
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)),
this, SLOT(change_adaptor()));
this, SIGNAL(changed()));
connect(unitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
this, SIGNAL(changed()));
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
bc().addCheckedLineEdit(valueLE, valueLA);
addCheckedWidget(valueLE, valueLA);
setWidthCO->addItem(qt_("Default"),
QVariant(toqstr("none")));
@ -73,12 +53,6 @@ GuiPrintNomencl::GuiPrintNomencl(GuiView & lv)
}
void GuiPrintNomencl::change_adaptor()
{
changed();
}
void GuiPrintNomencl::on_setWidthCO_activated(int i)
{
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->findData(toqstr(params_["set_width"])));
setWidthCO->findData(toqstr(params["set_width"])));
lengthToWidgets(valueLE,
unitLC,
params_["width"],
params["width"],
Length::defaultUnit());
bc().setValid(isValid());
}
void GuiPrintNomencl::updateContents()
void GuiPrintNomencl::paramsToDialog(Inset const * inset)
{
bool const custom = (setWidthCO->itemData(
setWidthCO->currentIndex()).toString()
== "custom");
valueLE->setEnabled(custom);
unitLC->setEnabled(custom);
valueLA->setEnabled(custom);
InsetNomencl const * nomencl = static_cast<InsetNomencl const *>(inset);
paramsToDialog(nomencl->params());
}
void GuiPrintNomencl::applyView()
docstring GuiPrintNomencl::dialogToParams() const
{
InsetCommandParams params(insetCode());
docstring const set_width = qstring_to_ucs4(setWidthCO->itemData(
setWidthCO->currentIndex()).toString());
params_["set_width"] = set_width;
params["set_width"] = set_width;
docstring width;
if (set_width == from_ascii("custom"))
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(
setWidthCO->currentIndex()).toString() != "custom"
|| !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 lyx

View File

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

View File

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

View File

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

View File

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