git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20772 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-06 09:19:53 +00:00
parent 5ac488927c
commit 06fe2c019f
9 changed files with 479 additions and 555 deletions

View File

@ -25,7 +25,7 @@ public:
///
ControlParagraph(Dialog &);
///
virtual bool initialiseParams(std::string const & data) { return true; }
virtual bool initialiseParams(std::string const & /*data*/) { return true; }
/// clean-up on hide.
virtual void clearParams() {}
///

View File

@ -1,259 +0,0 @@
/**
* \file ControlTabular.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "BufferView.h"
#include "ControlTabular.h"
#include "Cursor.h"
#include "FuncRequest.h"
#include "LyXRC.h"
#include "insets/InsetTabular.h"
using std::string;
namespace lyx {
namespace frontend {
ControlTabular::ControlTabular(Dialog & parent)
: Controller(parent), active_cell_(Tabular::npos), params_(0)
{}
ControlTabular::~ControlTabular()
{
delete params_;
}
bool ControlTabular::initialiseParams(string const & data)
{
// try to get the current cell
BufferView const * const bv = bufferview();
InsetTabular const * current_inset = 0;
if (bv) {
Cursor const & cur = bv->cursor();
// get the innermost tabular inset;
// assume that it is "ours"
for (int i = cur.depth() - 1; i >= 0; --i)
if (cur[i].inset().lyxCode() == Inset::TABULAR_CODE) {
current_inset = static_cast<InsetTabular const *>(&cur[i].inset());
active_cell_ = cur[i].idx();
break;
}
}
if (current_inset && data.empty()) {
delete params_;
params_ = new Tabular(current_inset->tabular);
return true;
}
InsetTabular tmp(buffer());
InsetTabularMailer::string2params(data, tmp);
delete params_;
params_ = new Tabular(tmp.tabular);
return true;
}
void ControlTabular::clearParams()
{
delete params_;
params_ = 0;
active_cell_ = Tabular::npos;
}
Tabular::idx_type ControlTabular::getActiveCell() const
{
return active_cell_;
}
Tabular const & ControlTabular::tabular() const
{
BOOST_ASSERT(params_);
return *params_;
}
void ControlTabular::set(Tabular::Feature f, string const & arg)
{
string const data = featureAsString(f) + ' ' + arg;
dispatch(FuncRequest(getLfun(), data));
}
bool ControlTabular::useMetricUnits() const
{
return lyxrc.default_papersize > PAPER_USEXECUTIVE;
}
void ControlTabular::toggleTopLine()
{
if (tabular().isMultiColumn(getActiveCell()))
set(Tabular::M_TOGGLE_LINE_TOP);
else
set(Tabular::TOGGLE_LINE_TOP);
}
void ControlTabular::toggleBottomLine()
{
if (tabular().isMultiColumn(getActiveCell()))
set(Tabular::M_TOGGLE_LINE_BOTTOM);
else
set(Tabular::TOGGLE_LINE_BOTTOM);
}
void ControlTabular::toggleLeftLine()
{
if (tabular().isMultiColumn(getActiveCell()))
set(Tabular::M_TOGGLE_LINE_LEFT);
else
set(Tabular::TOGGLE_LINE_LEFT);
}
void ControlTabular::toggleRightLine()
{
if (tabular().isMultiColumn(getActiveCell()))
set(Tabular::M_TOGGLE_LINE_RIGHT);
else
set(Tabular::TOGGLE_LINE_RIGHT);
}
void ControlTabular::setSpecial(string const & special)
{
if (tabular().isMultiColumn(getActiveCell()))
set(Tabular::SET_SPECIAL_MULTI, special);
else
set(Tabular::SET_SPECIAL_COLUMN, special);
}
void ControlTabular::setWidth(string const & width)
{
if (tabular().isMultiColumn(getActiveCell()))
set(Tabular::SET_MPWIDTH, width);
else
set(Tabular::SET_PWIDTH, width);
dialog().updateView();
}
void ControlTabular::toggleMultiColumn()
{
set(Tabular::MULTICOLUMN);
dialog().updateView();
}
void ControlTabular::rotateTabular(bool yes)
{
if (yes)
set(Tabular::SET_ROTATE_TABULAR);
else
set(Tabular::UNSET_ROTATE_TABULAR);
}
void ControlTabular::rotateCell(bool yes)
{
if (yes)
set(Tabular::SET_ROTATE_CELL);
else
set(Tabular::UNSET_ROTATE_CELL);
}
void ControlTabular::halign(ControlTabular::HALIGN h)
{
Tabular::Feature num = Tabular::ALIGN_LEFT;
Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
switch (h) {
case LEFT:
num = Tabular::ALIGN_LEFT;
multi_num = Tabular::M_ALIGN_LEFT;
break;
case CENTER:
num = Tabular::ALIGN_CENTER;
multi_num = Tabular::M_ALIGN_CENTER;
break;
case RIGHT:
num = Tabular::ALIGN_RIGHT;
multi_num = Tabular::M_ALIGN_RIGHT;
break;
case BLOCK:
num = Tabular::ALIGN_BLOCK;
//multi_num: no equivalent
break;
}
if (tabular().isMultiColumn(getActiveCell()))
set(multi_num);
else
set(num);
}
void ControlTabular::valign(ControlTabular::VALIGN v)
{
Tabular::Feature num = Tabular::VALIGN_MIDDLE;
Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
switch (v) {
case TOP:
num = Tabular::VALIGN_TOP;
multi_num = Tabular::M_VALIGN_TOP;
break;
case MIDDLE:
num = Tabular::VALIGN_MIDDLE;
multi_num = Tabular::M_VALIGN_MIDDLE;
break;
case BOTTOM:
num = Tabular::VALIGN_BOTTOM;
multi_num = Tabular::M_VALIGN_BOTTOM;
break;
}
if (tabular().isMultiColumn(getActiveCell()))
set(multi_num);
else
set(num);
}
void ControlTabular::booktabs(bool yes)
{
if (yes)
set(Tabular::SET_BOOKTABS);
else
set(Tabular::UNSET_BOOKTABS);
}
void ControlTabular::longTabular(bool yes)
{
if (yes)
set(Tabular::SET_LONGTABULAR);
else
set(Tabular::UNSET_LONGTABULAR);
}
} // namespace frontend
} // namespace lyx

View File

@ -1,89 +0,0 @@
// -*- C++ -*-
/**
* \file ControlTabular.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
*
* Full author contact details are available in file CREDITS.
*
* This is pretty icky, we should really be able to use
* ControlInset. We can't because there are no params for
* tabular inset.
*/
#ifndef CONTROLTABULAR_H
#define CONTROLTABULAR_H
#include "Dialog.h"
#include "insets/InsetTabular.h"
namespace lyx {
namespace frontend {
class ControlTabular : public Controller
{
public:
///
ControlTabular(Dialog &);
///
~ControlTabular();
///
virtual bool initialiseParams(std::string const & data);
/// clean-up on hide.
virtual void clearParams();
/// We use set() instead.
virtual void dispatchParams() {};
///
virtual bool isBufferDependent() const { return true; }
///
virtual kb_action getLfun() const { return LFUN_TABULAR_FEATURE; }
///
Tabular::idx_type getActiveCell() const;
/// get the contained tabular
Tabular const & tabular() const;
/// return true if units should default to metric
bool useMetricUnits() const;
/// set a parameter
void set(Tabular::Feature, std::string const & arg = std::string());
/// borders
void toggleTopLine();
void toggleBottomLine();
void toggleLeftLine();
void toggleRightLine();
void setSpecial(std::string const & special);
void setWidth(std::string const & width);
void toggleMultiColumn();
void rotateTabular(bool yes);
void rotateCell(bool yes);
enum HALIGN { LEFT, RIGHT, CENTER, BLOCK };
void halign(HALIGN h);
enum VALIGN { TOP, MIDDLE, BOTTOM };
void valign(VALIGN h);
void booktabs(bool yes);
void longTabular(bool yes);
private:
///
Tabular::idx_type active_cell_;
///
Tabular * params_;
};
} // namespace frontend
} // namespace lyx
#endif // CONTROLTABULAR_H

View File

@ -31,7 +31,6 @@ SOURCEFILES = \
ControlSearch.cpp \
ControlSendto.cpp \
ControlSpellchecker.cpp \
ControlTabular.cpp \
ControlTabularCreate.cpp \
ControlThesaurus.cpp \
ControlToc.cpp \
@ -61,7 +60,6 @@ HEADERFILES = \
ControlSearch.h \
ControlSendto.h \
ControlSpellchecker.h \
ControlTabular.h \
ControlTabularCreate.h \
ControlThesaurus.h \
ControlToc.h \

View File

@ -230,7 +230,7 @@ Dialog * Dialogs::build(string const & name)
} else if (name == "spellchecker") {
dialog = new GuiSpellcheckerDialog(lyxview_);
} else if (name == "tabular") {
dialog = new GuiTabularDialog(lyxview_);
dialog = createGuiTabular(lyxview_);
} else if (name == "tabularcreate") {
dialog = new GuiTabularCreateDialog(lyxview_);
} else if (name == "texinfo") {

File diff suppressed because it is too large Load Diff

View File

@ -16,18 +16,19 @@
#define GUITABULAR_H
#include "GuiDialog.h"
#include "ControlTabular.h"
#include "ui_TabularUi.h"
#include "insets/InsetTabular.h"
namespace lyx {
namespace frontend {
class GuiTabularDialog : public GuiDialog, public Ui::TabularUi
class GuiTabular : public GuiDialog, public Ui::TabularUi, public Controller
{
Q_OBJECT
public:
GuiTabularDialog(LyXView & lv);
GuiTabular(LyXView & lv);
~GuiTabular();
private Q_SLOTS:
void change_adaptor();
@ -71,7 +72,7 @@ private:
///
void closeEvent(QCloseEvent * e);
/// parent controller
ControlTabular & controller();
Controller & controller() { return *this; }
///
bool isValid() { return true; }
/// update borders
@ -80,6 +81,55 @@ private:
void updateContents();
/// save some values before closing the gui
void closeGUI();
///
bool initialiseParams(std::string const & data);
/// clean-up on hide.
void clearParams();
/// We use set() instead.
void dispatchParams() {};
///
bool isBufferDependent() const { return true; }
///
kb_action getLfun() const { return LFUN_TABULAR_FEATURE; }
///
Tabular::idx_type getActiveCell() const;
/// return true if units should default to metric
bool useMetricUnits() const;
/// set a parameter
void set(Tabular::Feature, std::string const & arg = std::string());
/// borders
void toggleTopLine();
void toggleBottomLine();
void toggleLeftLine();
void toggleRightLine();
void setSpecial(std::string const & special);
void setWidth(std::string const & width);
void toggleMultiColumn();
void rotateTabular(bool yes);
void rotateCell(bool yes);
enum HALIGN { LEFT, RIGHT, CENTER, BLOCK };
void halign(HALIGN h);
enum VALIGN { TOP, MIDDLE, BOTTOM };
void valign(VALIGN h);
void booktabs(bool yes);
void longTabular(bool yes);
///
Tabular::idx_type active_cell_;
///
Tabular tabular_;
};
} // namespace frontend

View File

@ -576,6 +576,12 @@ Tabular::ltType::ltType()
{}
Tabular::Tabular()
{
// unusable now!
}
Tabular::Tabular(BufferParams const & bp, row_type rows_arg,
col_type columns_arg)
{

View File

@ -238,6 +238,8 @@ public:
/// index indicating an invalid position
static const idx_type npos = static_cast<idx_type>(-1);
/// constructor
Tabular();
/// constructor
Tabular(BufferParams const &, col_type columns_arg,
row_type rows_arg);