mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
shorter code..
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23558 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
6e807d67ec
commit
621e1b50a9
@ -26,48 +26,48 @@
|
|||||||
#include "insets/InsetBox.h"
|
#include "insets/InsetBox.h"
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
#include "support/foreach.h"
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
|
static QStringList boxGuiIds()
|
||||||
void box_gui_tokens(vector<string> & ids, vector<docstring> & gui_names)
|
|
||||||
{
|
{
|
||||||
char const * const ids_[] = {
|
return QStringList()
|
||||||
"Frameless", "Boxed", "ovalbox",
|
<< "Frameless" << "Boxed"
|
||||||
"Ovalbox", "Shadowbox", "Shaded", "Doublebox"};
|
<< "ovalbox" << "Ovalbox"
|
||||||
size_t const ids_size = sizeof(ids_) / sizeof(char *);
|
<< "Shadowbox" << "Shaded"
|
||||||
ids = vector<string>(ids_, ids_ + ids_size);
|
<< "Doublebox";
|
||||||
gui_names.clear();
|
|
||||||
gui_names.push_back(_("No frame"));
|
|
||||||
gui_names.push_back(_("Simple rectangular frame"));
|
|
||||||
gui_names.push_back(_("Oval frame, thin"));
|
|
||||||
gui_names.push_back(_("Oval frame, thick"));
|
|
||||||
gui_names.push_back(_("Drop shadow"));
|
|
||||||
gui_names.push_back(_("Shaded background"));
|
|
||||||
gui_names.push_back(_("Double rectangular frame"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void box_gui_tokens_special_length(vector<string> & ids,
|
static QStringList boxGuiNames()
|
||||||
vector<docstring> & gui_names)
|
|
||||||
{
|
{
|
||||||
char const * const ids_[] = {
|
return QStringList()
|
||||||
"none", "height", "depth",
|
<< qt_("No frame") << qt_("Simple rectangular frame")
|
||||||
"totalheight", "width"};
|
<< qt_("Oval frame, thin") << qt_("Oval frame, thick")
|
||||||
size_t const ids_size = sizeof(ids_) / sizeof(char *);
|
<< qt_("Drop shadow") << qt_("Shaded background")
|
||||||
ids = vector<string>(ids_, ids_ + ids_size);
|
<< qt_("Double rectangular frame");
|
||||||
gui_names.clear();
|
}
|
||||||
gui_names.push_back(_("None"));
|
|
||||||
gui_names.push_back(_("Height"));
|
|
||||||
gui_names.push_back(_("Depth"));
|
static QStringList boxGuiSpecialLengthIds()
|
||||||
gui_names.push_back(_("Total Height"));
|
{
|
||||||
gui_names.push_back(_("Width"));
|
return QStringList() << "none" << "height" << "depth"
|
||||||
|
<< "totalheight" << "width";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static QStringList boxGuiSpecialLengthNames()
|
||||||
|
{
|
||||||
|
return QStringList() << qt_("None") << qt_("Height") << qt_("Depth")
|
||||||
|
<< qt_("Total Height") << qt_("Width");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -77,15 +77,17 @@ GuiBox::GuiBox(GuiView & lv)
|
|||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
// fill the box type choice
|
// fill the box type choice
|
||||||
box_gui_tokens(ids_, gui_names_);
|
ids_ = boxGuiIds();
|
||||||
for (unsigned int i = 0; i < gui_names_.size(); ++i)
|
gui_names_ = boxGuiNames();
|
||||||
typeCO->addItem(toqstr(gui_names_[i]));
|
foreach (QString const & str, gui_names_)
|
||||||
|
typeCO->addItem(str);
|
||||||
|
|
||||||
// add the special units to the height choice
|
// add the special units to the height choice
|
||||||
// width needs different handling
|
// width needs different handling
|
||||||
box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
|
ids_spec_ = boxGuiSpecialLengthIds();
|
||||||
for (unsigned int i = 1; i < gui_names_spec_.size(); ++i)
|
gui_names_spec_ = boxGuiSpecialLengthNames();
|
||||||
heightUnitsLC->addItem(toqstr(gui_names_spec_[i]));
|
foreach (QString const & str, gui_names_spec_)
|
||||||
|
heightUnitsLC->addItem(str);
|
||||||
|
|
||||||
connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
|
connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
|
||||||
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
||||||
@ -100,7 +102,7 @@ GuiBox::GuiBox(GuiView & lv)
|
|||||||
this, SLOT(change_adaptor()));
|
this, SLOT(change_adaptor()));
|
||||||
connect(heightCB, SIGNAL(stateChanged(int)),
|
connect(heightCB, SIGNAL(stateChanged(int)),
|
||||||
this, SLOT(change_adaptor()));
|
this, SLOT(change_adaptor()));
|
||||||
connect(heightED, SIGNAL(textChanged(const QString &)),
|
connect(heightED, SIGNAL(textChanged(QString)),
|
||||||
this, SLOT(change_adaptor()));
|
this, SLOT(change_adaptor()));
|
||||||
connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
connect(heightUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
||||||
this, SLOT(change_adaptor()));
|
this, SLOT(change_adaptor()));
|
||||||
@ -109,8 +111,8 @@ GuiBox::GuiBox(GuiView & lv)
|
|||||||
connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
|
connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
|
||||||
connect(halignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
connect(halignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
||||||
connect(ialignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
connect(ialignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
||||||
connect(innerBoxCO, SIGNAL(activated(const QString&)),
|
connect(innerBoxCO, SIGNAL(activated(QString)),
|
||||||
this, SLOT(innerBoxChanged(const QString &)));
|
this, SLOT(innerBoxChanged(QString)));
|
||||||
connect(innerBoxCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
connect(innerBoxCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
||||||
connect(pagebreakCB, SIGNAL(stateChanged(int)),
|
connect(pagebreakCB, SIGNAL(stateChanged(int)),
|
||||||
this, SLOT(pagebreakClicked()));
|
this, SLOT(pagebreakClicked()));
|
||||||
@ -149,7 +151,7 @@ void GuiBox::change_adaptor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiBox::innerBoxChanged(const QString & str)
|
void GuiBox::innerBoxChanged(QString const & str)
|
||||||
{
|
{
|
||||||
bool const ibox = (str != qt_("None"));
|
bool const ibox = (str != qt_("None"));
|
||||||
valignCO->setEnabled(ibox);
|
valignCO->setEnabled(ibox);
|
||||||
@ -191,9 +193,9 @@ void GuiBox::restoreClicked()
|
|||||||
widthUnitsLC->setCurrentItem(Length::PCW);
|
widthUnitsLC->setCurrentItem(Length::PCW);
|
||||||
heightCB->setCheckState(Qt::Checked);
|
heightCB->setCheckState(Qt::Checked);
|
||||||
heightED->setText("1");
|
heightED->setText("1");
|
||||||
for (int j = 0; j < heightUnitsLC->count(); j++) {
|
for (int i = 0; i != heightUnitsLC->count(); ++i) {
|
||||||
if (heightUnitsLC->itemText(j) == qt_("Total Height"))
|
if (heightUnitsLC->itemText(i) == qt_("Total Height"))
|
||||||
heightUnitsLC->setCurrentItem(j);
|
heightUnitsLC->setCurrentItem(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,29 +212,32 @@ void GuiBox::pagebreakClicked()
|
|||||||
heightED->setEnabled(false);
|
heightED->setEnabled(false);
|
||||||
heightUnitsLC->setEnabled(false);
|
heightUnitsLC->setEnabled(false);
|
||||||
setSpecial(false);
|
setSpecial(false);
|
||||||
} else
|
} else {
|
||||||
typeChanged(typeCO->currentIndex());
|
typeChanged(typeCO->currentIndex());
|
||||||
|
}
|
||||||
change_adaptor();
|
change_adaptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiBox::updateContents()
|
void GuiBox::updateContents()
|
||||||
{
|
{
|
||||||
string type = params_.type;
|
QString type = toqstr(params_.type);
|
||||||
if (type == "Framed") {
|
if (type == "Framed") {
|
||||||
pagebreakCB->setChecked(true);
|
pagebreakCB->setChecked(true);
|
||||||
type = "Boxed";
|
type = "Boxed";
|
||||||
} else
|
} else {
|
||||||
pagebreakCB->setChecked(false);
|
pagebreakCB->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
pagebreakCB->setEnabled(type == "Boxed");
|
pagebreakCB->setEnabled(type == "Boxed");
|
||||||
|
|
||||||
for (unsigned int i = 0; i < gui_names_.size(); ++i) {
|
for (int i = 0; i != gui_names_.size(); ++i) {
|
||||||
if (type == ids_[i])
|
if (type == ids_[i])
|
||||||
typeCO->setCurrentIndex(i);
|
typeCO->setCurrentIndex(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default: minipage
|
// default: minipage
|
||||||
unsigned int inner_type = 2;
|
int inner_type = 2;
|
||||||
if (!params_.inner_box)
|
if (!params_.inner_box)
|
||||||
// none
|
// none
|
||||||
inner_type = 0;
|
inner_type = 0;
|
||||||
@ -261,38 +266,37 @@ void GuiBox::updateContents()
|
|||||||
lengthToWidgets(widthED, widthUnitsLC,
|
lengthToWidgets(widthED, widthUnitsLC,
|
||||||
(params_.width).asString(), default_unit);
|
(params_.width).asString(), default_unit);
|
||||||
|
|
||||||
string const special = params_.special;
|
QString const special = toqstr(params_.special);
|
||||||
if (!special.empty() && special != "none") {
|
if (!special.isEmpty() && special != "none") {
|
||||||
QString spc;
|
QString spc;
|
||||||
for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
|
for (int i = 0; i != gui_names_spec_.size(); ++i) {
|
||||||
if (special == ids_spec_[i])
|
if (special == ids_spec_[i])
|
||||||
spc = toqstr(gui_names_spec_[i].c_str());
|
spc = gui_names_spec_[i];
|
||||||
}
|
}
|
||||||
for (int j = 0; j < widthUnitsLC->count(); j++) {
|
for (int i = 0; i != widthUnitsLC->count(); ++i) {
|
||||||
if (widthUnitsLC->itemText(j) == spc)
|
if (widthUnitsLC->itemText(i) == spc)
|
||||||
widthUnitsLC->setCurrentIndex(j);
|
widthUnitsLC->setCurrentIndex(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lengthToWidgets(heightED, heightUnitsLC,
|
lengthToWidgets(heightED, heightUnitsLC,
|
||||||
(params_.height).asString(), default_unit);
|
(params_.height).asString(), default_unit);
|
||||||
|
|
||||||
string const height_special = params_.height_special;
|
QString const height_special = toqstr(params_.height_special);
|
||||||
if (!height_special.empty() && height_special != "none") {
|
if (!height_special.isEmpty() && height_special != "none") {
|
||||||
QString hspc;
|
QString hspc;
|
||||||
for (unsigned int i = 0; i != gui_names_spec_.size(); i++) {
|
for (int i = 0; i != gui_names_spec_.size(); ++i) {
|
||||||
if (height_special == ids_spec_[i])
|
if (height_special == ids_spec_[i])
|
||||||
hspc = toqstr(gui_names_spec_[i].c_str());
|
hspc = gui_names_spec_[i];
|
||||||
}
|
}
|
||||||
for (int j = 0; j != heightUnitsLC->count(); j++) {
|
for (int i = 0; i != heightUnitsLC->count(); ++i) {
|
||||||
if (heightUnitsLC->itemText(j) == hspc)
|
if (heightUnitsLC->itemText(i) == hspc)
|
||||||
heightUnitsLC->setCurrentIndex(j);
|
heightUnitsLC->setCurrentIndex(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set no optional height when the value is the default "1\height"
|
// set no optional height when the value is the default "1\height"
|
||||||
// (special units like \height are handled as "in",
|
// (special units like \height are handled as "in",
|
||||||
if (height_special == "totalheight" &&
|
if (height_special == "totalheight" && params_.height == Length("1in"))
|
||||||
params_.height == Length("1in"))
|
|
||||||
heightCB->setCheckState(Qt::Unchecked);
|
heightCB->setCheckState(Qt::Unchecked);
|
||||||
else
|
else
|
||||||
heightCB->setCheckState(Qt::Checked);
|
heightCB->setCheckState(Qt::Checked);
|
||||||
@ -307,7 +311,7 @@ void GuiBox::applyView()
|
|||||||
if (pagebreak)
|
if (pagebreak)
|
||||||
params_.type = "Framed";
|
params_.type = "Framed";
|
||||||
else
|
else
|
||||||
params_.type = ids_[typeCO->currentIndex()];
|
params_.type = fromqstr(ids_[typeCO->currentIndex()]);
|
||||||
|
|
||||||
params_.inner_box = (!pagebreak && innerBoxCO->currentText() != qt_("None"));
|
params_.inner_box = (!pagebreak && innerBoxCO->currentText() != qt_("None"));
|
||||||
params_.use_parbox = (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
|
params_.use_parbox = (!pagebreak && innerBoxCO->currentText() == qt_("Parbox"));
|
||||||
@ -338,7 +342,7 @@ void GuiBox::applyView()
|
|||||||
i = 0;
|
i = 0;
|
||||||
spec = false;
|
spec = false;
|
||||||
}
|
}
|
||||||
params_.special = ids_spec_[i];
|
params_.special = fromqstr(ids_spec_[i]);
|
||||||
|
|
||||||
string width;
|
string width;
|
||||||
if (spec) {
|
if (spec) {
|
||||||
@ -373,7 +377,7 @@ void GuiBox::applyView()
|
|||||||
i = 0;
|
i = 0;
|
||||||
spec = false;
|
spec = false;
|
||||||
}
|
}
|
||||||
params_.height_special = ids_spec_[i];
|
params_.height_special = fromqstr(ids_spec_[i]);
|
||||||
|
|
||||||
string height;
|
string height;
|
||||||
if (spec && !isValidLength(fromqstr(heightED->text()))) {
|
if (spec && !isValidLength(fromqstr(heightED->text()))) {
|
||||||
@ -391,28 +395,31 @@ void GuiBox::applyView()
|
|||||||
params_.height = Length(height);
|
params_.height = Length(height);
|
||||||
else {
|
else {
|
||||||
params_.height = Length("1in");
|
params_.height = Length("1in");
|
||||||
params_.height_special = ids_spec_[3];
|
params_.height_special = fromqstr(ids_spec_[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiBox::setSpecial(bool ibox)
|
void GuiBox::setSpecial(bool ibox)
|
||||||
{
|
{
|
||||||
box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
|
// FIXME: Needed? Already done in the constructor
|
||||||
|
ids_spec_ = boxGuiSpecialLengthIds();
|
||||||
|
gui_names_spec_ = boxGuiSpecialLengthNames();
|
||||||
|
|
||||||
// check if the widget contains the special units
|
// check if the widget contains the special units
|
||||||
int count = widthUnitsLC->count();
|
int count = widthUnitsLC->count();
|
||||||
bool has_special = false;
|
bool has_special = false;
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i != count; ++i)
|
||||||
if (widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0)
|
if (widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0)
|
||||||
has_special = true;
|
has_special = true;
|
||||||
// insert 'em if needed...
|
// insert 'em if needed...
|
||||||
if (!ibox && !has_special) {
|
if (!ibox && !has_special) {
|
||||||
for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
|
for (int i = 1; i < gui_names_spec_.size(); ++i)
|
||||||
widthUnitsLC->addItem(toqstr(gui_names_spec_[i]));
|
widthUnitsLC->addItem(gui_names_spec_[i]);
|
||||||
// ... or remove 'em if needed
|
// ... or remove 'em if needed
|
||||||
} else if (ibox && has_special) {
|
} else if (ibox && has_special) {
|
||||||
widthUnitsLC->clear();
|
widthUnitsLC->clear();
|
||||||
for (int i = 0; i < num_units; i++)
|
for (int i = 0; i != num_units; ++i)
|
||||||
widthUnitsLC->addItem(qt_(unit_name_gui[i]));
|
widthUnitsLC->addItem(qt_(unit_name_gui[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void change_adaptor();
|
void change_adaptor();
|
||||||
void innerBoxChanged(const QString &);
|
void innerBoxChanged(QString const &);
|
||||||
void typeChanged(int);
|
void typeChanged(int);
|
||||||
void restoreClicked();
|
void restoreClicked();
|
||||||
void pagebreakClicked();
|
void pagebreakClicked();
|
||||||
@ -58,13 +58,13 @@ private:
|
|||||||
bool isBufferDependent() const { return true; }
|
bool isBufferDependent() const { return true; }
|
||||||
|
|
||||||
///
|
///
|
||||||
std::vector<std::string> ids_;
|
QStringList ids_;
|
||||||
///
|
///
|
||||||
std::vector<docstring> gui_names_;
|
QStringList gui_names_;
|
||||||
///
|
///
|
||||||
std::vector<std::string> ids_spec_;
|
QStringList ids_spec_;
|
||||||
///
|
///
|
||||||
std::vector<docstring> gui_names_spec_;
|
QStringList gui_names_spec_;
|
||||||
|
|
||||||
///
|
///
|
||||||
InsetBoxParams params_;
|
InsetBoxParams params_;
|
||||||
|
Loading…
Reference in New Issue
Block a user