Migrate GuiLabel to InsetParamsDialog.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35868 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-10-27 17:25:55 +00:00
parent 26dc500557
commit 585f8b9fda
5 changed files with 54 additions and 168 deletions

View File

@ -12,11 +12,9 @@
#include "GuiLabel.h"
#include "FuncRequest.h"
#include "qt_helpers.h"
#include "support/debug.h"
#include "insets/InsetCommand.h"
#include "insets/InsetLabel.h"
#include <QLabel>
#include <QPushButton>
@ -33,82 +31,40 @@ namespace frontend {
//
/////////////////////////////////////////////////////////////////
GuiLabel::GuiLabel(GuiView & lv)
: GuiDialog(lv, "label", qt_("Label")),
params_(insetCode("label"))
GuiLabel::GuiLabel(QWidget * parent) : InsetParamsWidget(parent)
{
setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(keywordED, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
this, SIGNAL(changed()));
setFocusProxy(keywordED);
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setOK(okPB);
bc().setCancel(closePB);
bc().addReadOnly(keywordED);
}
void GuiLabel::change_adaptor()
void GuiLabel::paramsToDialog(Inset const * inset)
{
changed();
InsetLabel const * label = static_cast<InsetLabel const *>(inset);
InsetCommandParams const & params = label->params();
keywordED->setText(toqstr(params["name"]));
}
void GuiLabel::reject()
docstring GuiLabel::dialogToParams() const
{
slotClose();
InsetCommandParams params(insetCode());
params["name"] = qstring_to_ucs4(keywordED->text());
return from_ascii(InsetLabel::params2string("label", params));
}
void GuiLabel::updateContents()
{
docstring const contents = params_["name"];
keywordED->setText(toqstr(contents));
bc().setValid(!contents.empty());
}
void GuiLabel::applyView()
{
params_["name"] = qstring_to_ucs4(keywordED->text());
}
void GuiLabel::enableView(bool enable)
{
keywordED->setEnabled(enable);
}
bool GuiLabel::isValid()
bool GuiLabel::checkWidgets() const
{
if (!InsetParamsWidget::checkWidgets())
return false;
return !keywordED->text().isEmpty();
}
bool GuiLabel::initialiseParams(std::string const & data)
{
InsetCommand::string2params("label", data, params_);
return true;
}
void GuiLabel::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("label", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiLabel(GuiView & lv) { return new GuiLabel(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -13,48 +13,29 @@
#ifndef GUILABEL_H
#define GUILABEL_H
#include "GuiDialog.h"
#include "ui_LabelUi.h"
#include "insets/InsetCommandParams.h"
#include "InsetParamsWidget.h"
namespace lyx {
namespace frontend {
class GuiLabel : public GuiDialog, public Ui::LabelUi
class GuiLabel : public InsetParamsWidget, public Ui::LabelUi
{
Q_OBJECT
public:
GuiLabel(GuiView & lv);
private Q_SLOTS:
void change_adaptor();
void reject();
GuiLabel(QWidget * parent = 0);
private:
///
bool isValid();
/// Apply changes
void applyView();
/// update
void updateContents();
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
void enableView(bool enable);
///
bool canApply() const { return true; }
private:
///
InsetCommandParams params_;
/// \name InsetParamsWidget inherited methods
//@{
InsetCode insetCode() const { return LABEL_CODE; }
FuncCode creationCode() const { return LFUN_INSET_INSERT; }
void paramsToDialog(Inset const *);
docstring dialogToParams() const;
bool checkWidgets() const;
//@}
};
} // namespace frontend

View File

@ -3771,7 +3771,6 @@ Dialog * createGuiExternal(GuiView & lv);
Dialog * createGuiGraphics(GuiView & lv);
Dialog * createGuiInclude(GuiView & lv);
Dialog * createGuiIndex(GuiView & lv);
Dialog * createGuiLabel(GuiView & lv);
Dialog * createGuiListings(GuiView & lv);
Dialog * createGuiLog(GuiView & lv);
Dialog * createGuiMathMatrix(GuiView & lv);
@ -3794,7 +3793,6 @@ Dialog * createGuiTabularCreate(GuiView & lv);
Dialog * createGuiTexInfo(GuiView & lv);
Dialog * createGuiToc(GuiView & lv);
Dialog * createGuiThesaurus(GuiView & lv);
Dialog * createGuiHyperlink(GuiView & lv);
Dialog * createGuiViewSource(GuiView & lv);
Dialog * createGuiWrap(GuiView & lv);
Dialog * createGuiProgressView(GuiView & lv);
@ -3843,8 +3841,6 @@ Dialog * GuiView::build(string const & name)
return createGuiIndex(*this);
if (name == "index_print")
return createGuiPrintindex(*this);
if (name == "label")
return createGuiLabel(*this);
if (name == "listings")
return createGuiListings(*this);
if (name == "log")

View File

@ -18,6 +18,7 @@
#include "GuiERT.h"
#include "GuiHyperlink.h"
#include "GuiInfo.h"
#include "GuiLabel.h"
#include "GuiLine.h"
#include "GuiHSpace.h"
#include "GuiTabular.h"
@ -239,6 +240,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
case INFO_CODE:
widget = new GuiInfo;
break;
case LABEL_CODE:
widget = new GuiLabel;
break;
case LINE_CODE:
widget = new GuiLine;
break;

View File

@ -1,101 +1,50 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LabelUi</class>
<widget class="QDialog" name="LabelUi" >
<property name="geometry" >
<widget class="QWidget" name="LabelUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>82</height>
<height>71</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string/>
</property>
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>11</number>
</property>
<property name="spacing" >
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>11</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="keywordLA" >
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>&amp;Label:</string>
</property>
<property name="buddy" >
<cstring>keywordED</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="keywordED" >
<property name="toolTip" >
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<property name="margin">
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
<widget class="QLabel" name="keywordLA">
<property name="toolTip">
<string/>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="sizeHint" >
<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="default" >
<bool>true</bool>
<property name="buddy">
<cstring>keywordED</cstring>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>Cancel</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default" >
<bool>false</bool>
<widget class="QLineEdit" name="keywordED">
<property name="toolTip">
<string/>
</property>
</widget>
</item>
@ -104,7 +53,7 @@
</layout>
</widget>
<includes>
<include location="local" >qt_i18n.h</include>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>