Migrate Branch dialog to InsetParamsWidget

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33521 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-02-19 20:57:25 +00:00
parent bebd53821a
commit 4db2685cbe
8 changed files with 43 additions and 174 deletions

View File

@ -19,7 +19,6 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "BranchList.h"
#include "FuncRequest.h"
#include "insets/InsetBranch.h"
@ -30,36 +29,21 @@ using namespace std;
namespace lyx {
namespace frontend {
GuiBranch::GuiBranch(GuiView & lv)
: GuiDialog(lv, "branch", qt_("Branch Settings"))
GuiBranch::GuiBranch(QWidget * parent) : InsetParamsWidget(parent)
{
setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(branchCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setOK(okPB);
bc().setCancel(closePB);
connect(branchCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
}
void GuiBranch::change_adaptor()
{
changed();
}
void GuiBranch::updateContents()
void GuiBranch::paramsToDialog(Inset const * inset)
{
InsetBranch const * ib = static_cast<InsetBranch const *>(inset);
typedef BranchList::const_iterator const_iterator;
BranchList const & branchlist = buffer().params().branchlist();
docstring const cur_branch = params_.branch;
BranchList const & branchlist = ib->buffer().params().branchlist();
docstring const cur_branch = ib->branch();
branchCO->clear();
const_iterator const begin = branchlist.begin();
const_iterator const end = branchlist.end();
int id = 0;
@ -67,7 +51,6 @@ void GuiBranch::updateContents()
for (const_iterator it = begin; it != end; ++it, ++count) {
docstring const & branch = it->branch();
branchCO->addItem(toqstr(branch));
if (cur_branch == branch)
id = count;
}
@ -75,34 +58,12 @@ void GuiBranch::updateContents()
}
void GuiBranch::applyView()
docstring GuiBranch::dialogToParams() const
{
params_.branch = qstring_to_ucs4(branchCO->currentText());
InsetBranchParams params(qstring_to_ucs4(branchCO->currentText()));
return from_utf8(InsetBranch::params2string(params));
}
bool GuiBranch::initialiseParams(string const & data)
{
InsetBranch::string2params(data, params_);
return true;
}
void GuiBranch::clearParams()
{
params_ = InsetBranchParams();
}
void GuiBranch::dispatchParams()
{
dispatch(FuncRequest(getLfun(), InsetBranch::params2string(params_)));
}
Dialog * createGuiBranch(GuiView & lv) { return new GuiBranch(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -14,40 +14,27 @@
#ifndef GUIBRANCH_H
#define GUIBRANCH_H
#include "GuiDialog.h"
#include "InsetParamsWidget.h"
#include "ui_BranchUi.h"
#include "insets/InsetBranch.h"
namespace lyx {
namespace frontend {
class GuiBranch : public GuiDialog, public Ui::BranchUi
class GuiBranch : public InsetParamsWidget, public Ui::BranchUi
{
Q_OBJECT
public:
GuiBranch(GuiView & lv);
private Q_SLOTS:
void change_adaptor();
GuiBranch(QWidget * parent = 0);
private:
/// Apply changes
void applyView();
/// Update dialog before showing it
void updateContents();
///
bool initialiseParams(std::string const & data);
///
void clearParams();
///
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
InsetBranchParams params_;
/// \name DialogView inherited methods
//@{
InsetCode insetCode() const { return BRANCH_CODE; }
FuncCode creationCode() const { return LFUN_BRANCH_INSERT; }
void paramsToDialog(Inset const *);
docstring dialogToParams() const;
//@}
};
} // namespace frontend

View File

@ -3443,7 +3443,6 @@ Dialog * createDialog(GuiView & lv, string const & name);
Dialog * createGuiAbout(GuiView & lv);
Dialog * createGuiBibitem(GuiView & lv);
Dialog * createGuiBibtex(GuiView & lv);
Dialog * createGuiBranch(GuiView & lv);
Dialog * createGuiChanges(GuiView & lv);
Dialog * createGuiCharacter(GuiView & lv);
Dialog * createGuiCitation(GuiView & lv);
@ -3501,8 +3500,6 @@ Dialog * GuiView::build(string const & name)
return createGuiBibitem(*this);
if (name == "bibtex")
return createGuiBibtex(*this);
if (name == "branch")
return createGuiBranch(*this);
if (name == "changes")
return createGuiChanges(*this);
if (name == "character")

View File

@ -13,6 +13,7 @@
#include "InsetParamsDialog.h"
#include "GuiBox.h"
#include "GuiBranch.h"
#include "GuiERT.h"
#include "GuiInfo.h"
#include "GuiTabular.h"
@ -204,6 +205,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
case FLOAT_CODE:
widget = new FloatPlacement(true);
break;
case BRANCH_CODE:
widget = new GuiBranch;
break;
case BOX_CODE:
widget = new GuiBox;
break;

View File

@ -1,84 +1,32 @@
<ui version="4.0" >
<ui version="4.0">
<class>BranchUi</class>
<widget class="QDialog" name="BranchUi" >
<property name="geometry" >
<widget class="QWidget" name="BranchUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>219</width>
<height>99</height>
<width>259</width>
<height>38</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string/>
</property>
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" colspan="3" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="branchLA">
<property name="text">
<string>&amp;Available branches:</string>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="branchLA" >
<property name="text" >
<string>&amp;Available branches:</string>
</property>
<property name="buddy" >
<cstring>branchCO</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="branchCO" >
<property name="toolTip" >
<string>Select your branch</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>31</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="default" >
<bool>true</bool>
<property name="buddy">
<cstring>branchCO</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="default" >
<bool>false</bool>
<item row="0" column="1">
<widget class="QComboBox" name="branchCO">
<property name="toolTip">
<string>Select your branch</string>
</property>
</widget>
</item>
@ -86,11 +34,9 @@
</widget>
<tabstops>
<tabstop>branchCO</tabstop>
<tabstop>okPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops>
<includes>
<include location="local" >qt_i18n.h</include>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>

View File

@ -100,7 +100,7 @@ static void build_translator()
insetnames[OPTARG_CODE] = InsetName("optarg");
insetnames[NEWLINE_CODE] = InsetName("newline");
insetnames[LINE_CODE] = InsetName("line");
insetnames[BRANCH_CODE] = InsetName("branch");
insetnames[BRANCH_CODE] = InsetName("branch", _("Branch"));
insetnames[BOX_CODE] = InsetName("box", _("Box"));
insetnames[FLEX_CODE] = InsetName("flex");
insetnames[SPACE_CODE] = InsetName("space");
@ -296,8 +296,8 @@ bool Inset::showInsetDialog(BufferView * bv) const
case ERT_CODE:
case FLOAT_CODE:
case BOX_CODE:
case BRANCH_CODE:
case INFO_CODE:
//FIXME: not ready yet.
case TABULAR_CODE:
case VSPACE_CODE:
bv->showDialog(insetName(code));

View File

@ -46,12 +46,6 @@ InsetBranch::InsetBranch(Buffer * buf, InsetBranchParams const & params)
{}
InsetBranch::~InsetBranch()
{
hideDialogs("branch", this);
}
void InsetBranch::write(ostream & os) const
{
params_.write(os);
@ -116,14 +110,6 @@ ColorCode InsetBranch::backgroundColor(PainterInfo const & pi) const
}
bool InsetBranch::showInsetDialog(BufferView * bv) const
{
bv->showDialog("branch", params2string(params()),
const_cast<InsetBranch *>(this));
return true;
}
void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
@ -133,11 +119,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
params_.branch = params.branch;
break;
}
case LFUN_INSET_DIALOG_UPDATE:
cur.bv().updateDialog("branch", params2string(params()));
break;
case LFUN_BRANCH_ACTIVATE:
case LFUN_BRANCH_DEACTIVATE: {
// FIXME: I do not like this cast, but have no other idea...
@ -153,7 +134,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
our_branch->setSelected(cmd.action == LFUN_BRANCH_ACTIVATE);
break;
}
case LFUN_INSET_TOGGLE:
if (cmd.argument() == "assign")
setStatus(cur, isBranchSelected() ? Open : Collapsed);
@ -173,7 +153,6 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
{
switch (cmd.action) {
case LFUN_INSET_MODIFY:
case LFUN_INSET_DIALOG_UPDATE:
flag.setEnabled(true);
break;

View File

@ -14,7 +14,6 @@
#include "InsetCollapsable.h"
namespace lyx {
class InsetBranchParams {
@ -44,8 +43,6 @@ class InsetBranch : public InsetCollapsable
public:
///
InsetBranch(Buffer *, InsetBranchParams const &);
///
~InsetBranch();
///
static std::string params2string(InsetBranchParams const &);
@ -68,8 +65,6 @@ private:
///
ColorCode backgroundColor(PainterInfo const &) const;
///
bool showInsetDialog(BufferView *) const;
///
int latex(odocstream &, OutputParams const &) const;
///
int plaintext(odocstream &, OutputParams const &) const;