+/////////////////////////////////////////////////////////////////////
+//
+// 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().trimmed());
+ if (layout.empty()) {
+ is_valid_ = true;
+ infoLB->setText("");
+ } else {
+ is_valid_ = TextClass::validate(layout);
+ infoLB->setText(is_valid_ ? vtext : ivtext);
+ }
+ validatePB->setEnabled(false);
+}
+
+
+void LocalLayout::validatePressed() {
+ validate();
+ changed();
+}
+
+