git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20775 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-06 10:23:51 +00:00
parent 5629673a88
commit 7a32331ab2
6 changed files with 128 additions and 205 deletions

View File

@ -1,83 +0,0 @@
/**
* \file ControlBox.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Martin Vermeer (with useful hints from Angus Leeming)
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "ControlBox.h"
#include "FuncRequest.h"
#include "gettext.h"
using std::string;
using std::vector;
namespace lyx {
namespace frontend {
ControlBox::ControlBox(Dialog & parent)
: Controller(parent), params_("")
{}
bool ControlBox::initialiseParams(string const & data)
{
InsetBoxMailer::string2params(data, params_);
return true;
}
void ControlBox::clearParams()
{
params_ = InsetBoxParams("");
}
void ControlBox::dispatchParams()
{
string const lfun = InsetBoxMailer::params2string(params());
dispatch(FuncRequest(getLfun(), lfun));
}
void box_gui_tokens(vector<string> & ids, vector<docstring> & gui_names)
{
char const * const ids_[] = {
"Frameless", "Boxed", "ovalbox",
"Ovalbox", "Shadowbox", "Doublebox"};
size_t const ids_size = sizeof(ids_) / sizeof(char *);
ids = vector<string>(ids_, ids_ + ids_size);
gui_names.clear();
gui_names.push_back(_("No frame drawn"));
gui_names.push_back(_("Rectangular box"));
gui_names.push_back(_("Oval box, thin"));
gui_names.push_back(_("Oval box, thick"));
gui_names.push_back(_("Shadow box"));
gui_names.push_back(_("Double box"));
}
void box_gui_tokens_special_length(vector<string> & ids,
vector<docstring> & gui_names)
{
char const * const ids_[] = {
"none", "height", "depth",
"totalheight", "width"};
size_t const ids_size = sizeof(ids_) / sizeof(char *);
ids = vector<string>(ids_, ids_ + ids_size);
gui_names.clear();
gui_names.push_back(_("None"));
gui_names.push_back(_("Height"));
gui_names.push_back(_("Depth"));
gui_names.push_back(_("Total Height"));
gui_names.push_back(_("Width"));
}
} // namespace frontend
} // namespace lyx

View File

@ -1,54 +0,0 @@
// -*- C++ -*-
/**
* \file ControlBox.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Martin Vermeer (with useful hints from Angus Leeming)
*
* Full author contact details are available in file CREDITS.
*/
#ifndef CONTROLBOX_H
#define CONTROLBOX_H
#include "Dialog.h"
#include "insets/InsetBox.h"
#include <vector>
namespace lyx {
namespace frontend {
class ControlBox : public Controller {
public:
///
ControlBox(Dialog &);
///
virtual bool initialiseParams(std::string const & data);
///
virtual void clearParams();
///
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
InsetBoxParams & params() { return params_; }
///
InsetBoxParams const & params() const { return params_; }
///
private:
///
InsetBoxParams params_;
};
///
void box_gui_tokens(std::vector<std::string> &, std::vector<docstring> &);
///
void box_gui_tokens_special_length(std::vector<std::string> &,
std::vector<docstring> &);
} // namespace frontend
} // namespace lyx
#endif // CONTROLBOX_H

View File

@ -9,7 +9,6 @@ noinst_LTLIBRARIES = liblyxcontrollers.la
SOURCEFILES = \
Dialog.cpp \
ButtonPolicy.cpp \
ControlBox.cpp \
ControlCharacter.cpp \
ControlChanges.cpp \
ControlCitation.cpp \
@ -36,7 +35,6 @@ SOURCEFILES = \
HEADERFILES = \
ButtonPolicy.h \
ControlBox.h \
ControlCharacter.h \
ControlChanges.h \
ControlCitation.h \

View File

@ -17,7 +17,6 @@
#include "DialogView.h"
#include "DockView.h"
#include "GuiBibitem.h"
#include "GuiBox.h"
#include "GuiChanges.h"
#include "GuiCharacter.h"
#include "GuiCitation.h"
@ -158,7 +157,7 @@ Dialog * Dialogs::build(string const & name)
} else if (name == "bibtex") {
dialog = createGuiBibtex(lyxview_);
} else if (name == "box") {
dialog = new GuiBoxDialog(lyxview_);
dialog = createGuiBox(lyxview_);
} else if (name == "branch") {
dialog = createGuiBranch(lyxview_);
} else if (name == "changes") {

View File

@ -14,6 +14,9 @@
#include "GuiBox.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "LengthCombo.h"
#include "qt_helpers.h"
#include "lengthcommon.h"
@ -28,18 +31,54 @@
#include <QLineEdit>
#include <QCloseEvent>
using std::string;
using std::vector;
namespace lyx {
namespace frontend {
GuiBoxDialog::GuiBoxDialog(LyXView & lv)
: GuiDialog(lv, "box")
void box_gui_tokens(vector<string> & ids, vector<docstring> & gui_names)
{
char const * const ids_[] = {
"Frameless", "Boxed", "ovalbox",
"Ovalbox", "Shadowbox", "Doublebox"};
size_t const ids_size = sizeof(ids_) / sizeof(char *);
ids = vector<string>(ids_, ids_ + ids_size);
gui_names.clear();
gui_names.push_back(_("No frame drawn"));
gui_names.push_back(_("Rectangular box"));
gui_names.push_back(_("Oval box, thin"));
gui_names.push_back(_("Oval box, thick"));
gui_names.push_back(_("Shadow box"));
gui_names.push_back(_("Double box"));
}
void box_gui_tokens_special_length(vector<string> & ids,
vector<docstring> & gui_names)
{
char const * const ids_[] = {
"none", "height", "depth",
"totalheight", "width"};
size_t const ids_size = sizeof(ids_) / sizeof(char *);
ids = vector<string>(ids_, ids_ + ids_size);
gui_names.clear();
gui_names.push_back(_("None"));
gui_names.push_back(_("Height"));
gui_names.push_back(_("Depth"));
gui_names.push_back(_("Total Height"));
gui_names.push_back(_("Width"));
}
GuiBox::GuiBox(LyXView & lv)
: GuiDialog(lv, "box"), Controller(this), params_("")
{
setupUi(this);
setViewTitle(_("Box Settings"));
setController(new ControlBox(*this));
setController(this, false);
// fill the box type choice
box_gui_tokens(ids_, gui_names_);
@ -57,11 +96,11 @@ GuiBoxDialog::GuiBoxDialog(LyXView & lv)
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(widthED, SIGNAL(textChanged(const QString &)),
connect(widthED, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor()));
connect(widthUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
connect(valignCO, SIGNAL(highlighted(const QString &)),
connect(valignCO, SIGNAL(highlighted(QString)),
this, SLOT(change_adaptor()));
connect(heightCB, SIGNAL(stateChanged(int)),
this, SLOT(change_adaptor()));
@ -105,26 +144,20 @@ GuiBoxDialog::GuiBoxDialog(LyXView & lv)
}
ControlBox & GuiBoxDialog::controller()
{
return static_cast<ControlBox &>(GuiDialog::controller());
}
void GuiBoxDialog::closeEvent(QCloseEvent * e)
void GuiBox::closeEvent(QCloseEvent * e)
{
slotClose();
e->accept();
}
void GuiBoxDialog::change_adaptor()
void GuiBox::change_adaptor()
{
changed();
}
void GuiBoxDialog::innerBoxChanged(const QString & str)
void GuiBox::innerBoxChanged(const QString & str)
{
bool const ibox = (str != qt_("None"));
valignCO->setEnabled(ibox);
@ -139,7 +172,7 @@ void GuiBoxDialog::innerBoxChanged(const QString & str)
}
void GuiBoxDialog::typeChanged(int index)
void GuiBox::typeChanged(int index)
{
bool const frameless = (index == 0);
if (frameless) {
@ -156,7 +189,7 @@ void GuiBoxDialog::typeChanged(int index)
}
void GuiBoxDialog::restoreClicked()
void GuiBox::restoreClicked()
{
setInnerType(true, 2);
widthED->setText("100");
@ -170,9 +203,9 @@ void GuiBoxDialog::restoreClicked()
}
void GuiBoxDialog::updateContents()
void GuiBox::updateContents()
{
string type(controller().params().type);
string type = params_.type;
for (unsigned int i = 0; i < gui_names_.size(); ++i) {
if (type == ids_[i])
typeCO->setCurrentIndex(i);
@ -180,23 +213,23 @@ void GuiBoxDialog::updateContents()
// default: minipage
unsigned int inner_type = 2;
if (!controller().params().inner_box)
if (!params_.inner_box)
// none
inner_type = 0;
if (controller().params().use_parbox)
if (params_.use_parbox)
// parbox
inner_type = 1;
bool frameless = (controller().params().type == "Frameless");
bool frameless = (params_.type == "Frameless");
setInnerType(frameless, inner_type);
char c = controller().params().pos;
char c = params_.pos;
valignCO->setCurrentIndex(string("tcb").find(c, 0));
c = controller().params().inner_pos;
c = params_.inner_pos;
ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
c = controller().params().hor_pos;
c = params_.hor_pos;
halignCO->setCurrentIndex(string("lcrs").find(c, 0));
bool ibox = controller().params().inner_box;
bool ibox = params_.inner_box;
valignCO->setEnabled(ibox);
ialignCO->setEnabled(ibox);
halignCO->setEnabled(!ibox);
@ -206,9 +239,9 @@ void GuiBoxDialog::updateContents()
(lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
lengthToWidgets(widthED, widthUnitsLC,
(controller().params().width).asString(), default_unit);
(params_.width).asString(), default_unit);
string const special = controller().params().special;
string const special = params_.special;
if (!special.empty() && special != "none") {
QString spc;
for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
@ -222,26 +255,24 @@ void GuiBoxDialog::updateContents()
}
lengthToWidgets(heightED, heightUnitsLC,
(controller().params().height).asString(), default_unit);
(params_.height).asString(), default_unit);
string const height_special = controller().params().height_special;
string const height_special = params_.height_special;
if (!height_special.empty() && height_special != "none") {
QString hspc;
for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
if (height_special == ids_spec_[i]) {
for (unsigned int i = 0; i != gui_names_spec_.size(); i++) {
if (height_special == ids_spec_[i])
hspc = toqstr(gui_names_spec_[i].c_str());
}
}
for (int j = 0; j < heightUnitsLC->count(); j++) {
if (heightUnitsLC->itemText(j) == hspc) {
for (int j = 0; j != heightUnitsLC->count(); j++) {
if (heightUnitsLC->itemText(j) == hspc)
heightUnitsLC->setCurrentIndex(j);
}
}
}
// set no optional height when the value is the default "1\height"
// (special units like \height are handled as "in",
if (height_special == "totalheight" &&
controller().params().height == Length("1in"))
params_.height == Length("1in"))
heightCB->setCheckState(Qt::Unchecked);
else
heightCB->setCheckState(Qt::Checked);
@ -250,22 +281,16 @@ void GuiBoxDialog::updateContents()
}
void GuiBoxDialog::applyView()
void GuiBox::applyView()
{
controller().params().type =
ids_[typeCO->currentIndex()];
params_.type = ids_[typeCO->currentIndex()];
controller().params().inner_box =
innerBoxCO->currentText() != qt_("None");
controller().params().use_parbox =
innerBoxCO->currentText() == qt_("Parbox");
params_.inner_box = innerBoxCO->currentText() != qt_("None");
params_.use_parbox = innerBoxCO->currentText() == qt_("Parbox");
controller().params().pos =
"tcb"[valignCO->currentIndex()];
controller().params().inner_pos =
"tcbs"[ialignCO->currentIndex()];
controller().params().hor_pos =
"lcrs"[halignCO->currentIndex()];
params_.pos = "tcb"[valignCO->currentIndex()];
params_.inner_pos = "tcbs"[ialignCO->currentIndex()];
params_.hor_pos = "lcrs"[halignCO->currentIndex()];
int i = 0;
bool spec = false;
@ -289,17 +314,18 @@ void GuiBoxDialog::applyView()
i = 0;
spec = false;
}
controller().params().special = ids_spec_[i];
params_.special = ids_spec_[i];
string width;
if (spec) {
width = fromqstr(value);
// beware: bogosity! the unit is simply ignored in this case
width += "in";
} else
} else {
width = widgetsToLength(widthED, widthUnitsLC);
}
controller().params().width = Length(width);
params_.width = Length(width);
i = 0;
spec = false;
@ -323,7 +349,7 @@ void GuiBoxDialog::applyView()
i = 0;
spec = false;
}
controller().params().height_special = ids_spec_[i];
params_.height_special = ids_spec_[i];
string height;
if (spec && !isValidLength(fromqstr(heightED->text()))) {
@ -338,15 +364,15 @@ void GuiBoxDialog::applyView()
// 1in + "Total Height" means "1\height" which is the LaTeX default when
// no height is given
if (heightCB->checkState() == Qt::Checked)
controller().params().height = Length(height);
params_.height = Length(height);
else {
controller().params().height = Length("1in");
controller().params().height_special = ids_spec_[3];
params_.height = Length("1in");
params_.height_special = ids_spec_[3];
}
}
void GuiBoxDialog::setSpecial(bool ibox)
void GuiBox::setSpecial(bool ibox)
{
box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
// check if the widget contains the special units
@ -368,7 +394,7 @@ void GuiBoxDialog::setSpecial(bool ibox)
}
void GuiBoxDialog::setInnerType(bool frameless, int i)
void GuiBox::setInnerType(bool frameless, int i)
{
// with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
// we have to remove "none" then and adjust the combo
@ -391,6 +417,29 @@ void GuiBoxDialog::setInnerType(bool frameless, int i)
}
}
bool GuiBox::initialiseParams(string const & data)
{
InsetBoxMailer::string2params(data, params_);
return true;
}
void GuiBox::clearParams()
{
params_ = InsetBoxParams("");
}
void GuiBox::dispatchParams()
{
dispatch(FuncRequest(getLfun(), InsetBoxMailer::params2string(params_)));
}
Dialog * createGuiBox(LyXView & lv) { return new GuiBox(lv); }
} // namespace frontend
} // namespace lyx

View File

@ -5,7 +5,7 @@
* Licence details can be found in the file COPYING.
*
* \author Jürgen Spitzmüller
* \ author Martin Vermeer
* \author Martin Vermeer (with useful hints from Angus Leeming)
*
* Full author contact details are available in file CREDITS.
*/
@ -14,20 +14,21 @@
#define GUIBOX_H
#include "GuiDialog.h"
#include "ControlBox.h"
#include "ui_BoxUi.h"
#include "insets/InsetBox.h"
#include <vector>
namespace lyx {
namespace frontend {
class GuiBoxDialog : public GuiDialog, public Ui::BoxUi
class GuiBox : public GuiDialog, public Ui::BoxUi, public Controller
{
Q_OBJECT
public:
GuiBoxDialog(LyXView & lv);
GuiBox(LyXView & lv);
private Q_SLOTS:
void change_adaptor();
@ -36,10 +37,11 @@ private Q_SLOTS:
void restoreClicked();
private:
///
void closeEvent(QCloseEvent * e);
/// parent controller
ControlBox & controller();
Controller & controller() { return *this; }
/// add and remove special lengths
void setSpecial(bool ibox);
/// only show valid inner box items
@ -50,6 +52,15 @@ private:
/// update
void updateContents();
///
bool initialiseParams(std::string const & data);
///
void clearParams();
///
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
std::vector<std::string> ids_;
///
@ -58,6 +69,9 @@ private:
std::vector<std::string> ids_spec_;
///
std::vector<docstring> gui_names_spec_;
///
InsetBoxParams params_;
};
} // namespace frontend