A UI for document-local layout information. LyX has supported this for a

while, but without any UI for it. (There has been local layout in the
Customization manual for a long time, in fact.)

Yes, this is an advanced feature. But, absent a layout editor, it is the
one thing that will make it easier, and possible, for "normal users" to
experiment with layout without having to go through reconfiguration,
etc, etc. To keep too many people from shooting themselves, we validate
the layout information before allowing the user to apply it.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35061 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-08-05 22:47:42 +00:00
parent e1fa4c9eb3
commit 64f979cb06
3 changed files with 129 additions and 14 deletions

View File

@ -46,6 +46,7 @@
#include "PDFOptions.h"
#include "qt_helpers.h"
#include "Spacing.h"
#include "TextClass.h"
#include "insets/InsetListingsParams.h"
@ -525,6 +526,79 @@ void PreambleModule::closeEvent(QCloseEvent * e)
}
/////////////////////////////////////////////////////////////////////
//
// LocalLayout
//
/////////////////////////////////////////////////////////////////////
LocalLayout::LocalLayout() : current_id_(0), is_valid_(false)
{
connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
}
void LocalLayout::update(BufferParams const & params, BufferId id)
{
QString layout = toqstr(params.local_layout);
// Nothing to do if the params and preamble are unchanged.
if (id == current_id_
&& layout == locallayoutTE->document()->toPlainText())
return;
// Save the params address for further use.
current_id_ = id;
locallayoutTE->document()->setPlainText(layout);
validate();
}
void LocalLayout::apply(BufferParams & params)
{
string const layout = fromqstr(locallayoutTE->document()->toPlainText());
params.local_layout = layout;
}
void LocalLayout::textChanged()
{
static const QString unknown = qt_("Press button to check validity...");
is_valid_ = false;
infoLB->setText(unknown);
validatePB->setEnabled(true);
changed();
}
void LocalLayout::validate() {
static const QString valid = qt_("Layout is valid!");
static const QString vtext =
toqstr("<p style=\"font-weight: bold; \">")
+ valid + toqstr("</p>");
static const QString invalid = qt_("Layout is invalid!");
static const QString ivtext =
toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
+ invalid + toqstr("</p>");
string const layout = fromqstr(locallayoutTE->document()->toPlainText());
if (layout.empty())
is_valid_ = true;
else
is_valid_ = TextClass::validate(layout);
infoLB->setText(is_valid_ ? vtext : ivtext);
validatePB->setEnabled(false);
}
void LocalLayout::validatePressed() {
validate();
changed();
}
/////////////////////////////////////////////////////////////////////
//
// DocumentDialog
@ -1071,6 +1145,10 @@ GuiDocument::GuiDocument(GuiView & lv)
preambleModule = new PreambleModule;
connect(preambleModule, SIGNAL(changed()),
this, SLOT(change_adaptor()));
localLayout = new LocalLayout;
connect(localLayout, SIGNAL(changed()),
this, SLOT(change_adaptor()));
// bullets
@ -1176,6 +1254,7 @@ GuiDocument::GuiDocument(GuiView & lv)
docPS->addPanel(branchesModule, qt_("Branches"));
docPS->addPanel(outputModule, qt_("Output"));
docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
docPS->addPanel(localLayout, qt_("Local Layout"));
docPS->setCurrentPanel(qt_("Document Class"));
// FIXME: hack to work around resizing bug in Qt >= 4.2
// bug verified with Qt 4.2.{0-3} (JSpitzm)
@ -1185,12 +1264,6 @@ GuiDocument::GuiDocument(GuiView & lv)
}
void GuiDocument::showPreamble()
{
docPS->setCurrentPanel(qt_("LaTeX Preamble"));
}
void GuiDocument::saveDefaultClicked()
{
saveDocDefault();
@ -2020,6 +2093,7 @@ void GuiDocument::applyView()
{
// preamble
preambleModule->apply(bp_);
localLayout->apply(bp_);
// date
bp_.suppress_date = latexModule->suppressDateCB->isChecked();
@ -2436,6 +2510,7 @@ void GuiDocument::paramsToDialog()
// preamble
preambleModule->update(bp_, id());
localLayout->update(bp_, id());
// date
latexModule->suppressDateCB->setChecked(bp_.suppress_date);
@ -3025,13 +3100,25 @@ void GuiDocument::setLayoutComboByIDString(string const & idString)
bool GuiDocument::isValid()
{
return validateListingsParameters().isEmpty()
&& (textLayoutModule->skipCO->currentIndex() != 3
|| !textLayoutModule->skipLE->text().isEmpty()
|| textLayoutModule->indentRB->isChecked())
&& (textLayoutModule->indentCO->currentIndex() != 1
|| !textLayoutModule->indentLE->text().isEmpty()
|| textLayoutModule->skipRB->isChecked());
return
validateListingsParameters().isEmpty() &&
localLayout->isValid() &&
(
// if we're asking for skips between paragraphs
!textLayoutModule->skipRB->isChecked() ||
// then either we haven't chosen custom
textLayoutModule->skipCO->currentIndex() != 3 ||
// or else a length has been given
!textLayoutModule->skipLE->text().isEmpty()
) &&
(
// if we're asking for indentation
!textLayoutModule->indentRB->isChecked() ||
// then either we haven't chosen custom
textLayoutModule->indentCO->currentIndex() != 1 ||
// or else a length has been given
!textLayoutModule->indentLE->text().isEmpty()
);
}

View File

@ -27,6 +27,7 @@
#include "ui_LanguageUi.h"
#include "ui_LaTeXUi.h"
#include "ui_ListingsSettingsUi.h"
#include "ui_LocalLayoutUi.h"
#include "ui_MarginsUi.h"
#include "ui_MasterChildUi.h"
#include "ui_MathsUi.h"
@ -51,6 +52,7 @@ class GuiBranches;
class GuiIndices;
class ModuleSelectionManager;
class PreambleModule;
class LocalLayout;
///
typedef void const * BufferId;
@ -76,7 +78,6 @@ public:
void updatePagestyle(std::string const &, std::string const &);
bool isChildIncluded(std::string const &);
void showPreamble();
///
BufferParams const & params() const { return bp_; }
@ -136,6 +137,7 @@ private:
UiWidget<Ui::OutputUi> *outputModule;
UiWidget<Ui::ListingsSettingsUi> *listingsModule;
PreambleModule * preambleModule;
LocalLayout * localLayout;
GuiBranches * branchesModule;
GuiIndices * indicesModule;
@ -271,6 +273,31 @@ private:
};
class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
{
Q_OBJECT
public:
LocalLayout();
void update(BufferParams const & params, BufferId id);
void apply(BufferParams & params);
bool isValid() const { return is_valid_; }
Q_SIGNALS:
/// signal that something's changed in the Widget.
void changed();
private:
void validate();
private Q_SLOTS:
void textChanged();
void validatePressed();
private:
BufferId current_id_;
bool is_valid_;
};
} // namespace frontend
} // namespace lyx

View File

@ -282,6 +282,7 @@ UIFILES = \
LaTeXUi.ui \
ListingsUi.ui \
ListingsSettingsUi.ui \
LocalLayoutUi.ui \
LogUi.ui \
MarginsUi.ui \
MasterChildUi.ui \