* \author Edwin Leuven
* \author Richard Heck
* \author Abdelrazak Younes
+ * \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "GuiParagraph.h"
-#include "qt_helpers.h"
-#include "ControlParagraph.h"
+#include "qt_helpers.h"
-#include "debug.h"
-#include "frontend_helpers.h"
-#include "gettext.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "BufferView.h"
+#include "Cursor.h"
+#include "FuncRequest.h"
+#include "GuiView.h"
+#include "Lexer.h"
+#include "Paragraph.h"
#include "ParagraphParameters.h"
#include "Spacing.h"
+#include "support/debug.h"
+#include "support/gettext.h"
+
#include <QCheckBox>
-#include <QCloseEvent>
#include <QLineEdit>
#include <QPushButton>
-#include <boost/current_function.hpp>
+#include <sstream>
-using std::string;
-using std::endl;
+using namespace std;
namespace lyx {
namespace frontend {
-GuiParagraph::GuiParagraph(ControlParagraph & controller, QWidget * parent)
- : QWidget(parent), controller_(controller)
+GuiParagraph::GuiParagraph(GuiView & lv)
+ : DialogView(lv, "paragraph", qt_("Paragraph Settings"))
{
setupUi(this);
- setWindowTitle(qt_("Paragraph Settings"));
connect(alignDefaultRB, SIGNAL(clicked()), this, SLOT(changed()));
connect(alignJustRB, SIGNAL(clicked()), this, SLOT(changed()));
connect(alignRightRB, SIGNAL(clicked()), this, SLOT(changed()));
connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(changed()));
connect(linespacing, SIGNAL(activated(int)), this, SLOT(changed()));
- connect(linespacingValue, SIGNAL(textChanged(const QString &)),
+ connect(linespacingValue, SIGNAL(textChanged(QString)),
this, SLOT(changed()));
connect(indentCB, SIGNAL(clicked()), this, SLOT(changed()));
- connect(labelWidth, SIGNAL(textChanged(const QString &)),
+ connect(labelWidth, SIGNAL(textChanged(QString)),
this, SLOT(changed()));
-
+#ifdef Q_WS_MACX
+ // On Mac it's common to have tool windows which are always in the
+ // foreground and are hidden when the main window is not focused.
+ setWindowFlags(Qt::Tool);
synchronizedViewCB->setChecked(true);
+#else
+ synchronizedViewCB->setChecked(false);
+#endif
+
on_synchronizedViewCB_toggled();
linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
+ labelMap[LYX_ALIGN_BLOCK] = _("Justified");
+ labelMap[LYX_ALIGN_LEFT] = _("Left");
+ labelMap[LYX_ALIGN_RIGHT] = _("Right");
+ labelMap[LYX_ALIGN_CENTER] = _("Center");
+
const_cast<QString &>(alignDefaultLabel) = alignDefaultRB->text();
}
}
-void GuiParagraph::checkAlignmentRadioButtons() {
- LyXAlignment const alignPossible = controller_.alignPossible();
-
+void GuiParagraph::checkAlignmentRadioButtons()
+{
RadioMap::iterator it = radioMap.begin();
for (; it != radioMap.end(); ++it) {
LyXAlignment const align = it->first;
- it->second->setEnabled(align & alignPossible);
+ it->second->setEnabled(align & alignPossible());
}
- if (controller_.haveMulitParSelection())
+ if (haveMultiParSelection())
alignDefaultRB->setText(alignDefaultLabel);
else
- alignDefaultRB->setText(alignDefaultLabel + " ("
- + radioMap[controller_.alignDefault()]->text() + ")");
+ alignDefaultRB->setText(alignDefaultLabel + " ("
+ + toqstr(labelMap[alignDefault()]) + ")");
}
{
RadioMap::const_iterator it = radioMap.begin();
for (;it != radioMap.end(); ++it) {
- if (!it->second->isEnabled())
- continue;
it->second->blockSignals(true);
it->second->setChecked(align == it->first);
it->second->blockSignals(false);
void GuiParagraph::on_applyPB_clicked()
{
- ParagraphParameters & params = controller_.params();
+ ParagraphParameters & pp = params();
- params.align(getAlignmentFromDialog());
+ pp.align(getAlignmentFromDialog());
// get spacing
Spacing::Space ls = Spacing::Default;
}
Spacing const spacing(ls, other);
- params.spacing(spacing);
+ pp.spacing(spacing);
// label width
- params.labelWidthString(qstring_to_ucs4(labelWidth->text()));
+ pp.labelWidthString(qstring_to_ucs4(labelWidth->text()));
// indendation
- params.noindent(!indentCB->isChecked());
+ pp.noindent(!indentCB->isChecked());
- controller_.dispatchParams();
+ dispatchParams();
}
{
on_synchronizedViewCB_toggled();
- ParagraphParameters const & params = controller_.params();
+ ParagraphParameters const & pp = params();
// label width
- docstring const & labelwidth = params.labelWidthString();
+ docstring const & labelwidth = pp.labelWidthString();
// FIXME We should not compare translated strings
if (labelwidth != _("Senseless with this layout!")) {
labelwidthGB->setEnabled(true);
// alignment
checkAlignmentRadioButtons();
- alignmentToRadioButtons(params.align());
+ alignmentToRadioButtons(pp.align());
//indentation
- bool const canindent = controller_.canIndent();
+ bool const canindent = canIndent();
indentCB->setEnabled(canindent);
- indentCB->setChecked(canindent && !params.noindent());
+ indentCB->setChecked(canindent && !pp.noindent());
// linespacing
int ls;
- Spacing const & space = params.spacing();
+ Spacing const & space = pp.spacing();
switch (space.getSpace()) {
case Spacing::Single:
ls = 1;
}
}
+
+void GuiParagraph::enableView(bool enable)
+{
+ indentCB->setEnabled(enable);
+ linespacing->setEnabled(enable);
+ labelWidth->setEnabled(enable);
+ synchronizedViewCB->setEnabled(enable);
+ applyPB->setEnabled(enable);
+ restorePB->setEnabled(enable);
+ if (!enable)
+ synchronizedViewCB->setChecked(true);
+ RadioMap::const_iterator it = radioMap.begin();
+ for (; it != radioMap.end(); ++it)
+ it->second->setEnabled(enable);
+}
+
+
+ParagraphParameters & GuiParagraph::params()
+{
+ if (haveMultiParSelection()) {
+ multiparsel_ = ParagraphParameters();
+ // FIXME: It would be nice to initialise the parameters that
+ // are common to all paragraphs.
+ return multiparsel_;
+ }
+
+ return bufferview()->cursor().innerParagraph().params();
+}
+
+
+ParagraphParameters const & GuiParagraph::params() const
+{
+ return bufferview()->cursor().innerParagraph().params();
+}
+
+
+void GuiParagraph::dispatchParams()
+{
+ if (haveMultiParSelection()) {
+ ostringstream data;
+ multiparsel_.write(data);
+ FuncRequest const fr(getLfun(), data.str());
+ dispatch(fr);
+ return;
+ }
+
+ bufferview()->updateMetrics();
+ bufferview()->buffer().changed();
+}
+
+
+bool GuiParagraph::haveMultiParSelection()
+{
+ Cursor cur = bufferview()->cursor();
+ return cur.selection() && cur.selBegin().pit() != cur.selEnd().pit();
+}
+
+
+bool GuiParagraph::canIndent() const
+{
+ return buffer().params().paragraph_separation ==
+ BufferParams::PARSEP_INDENT;
+}
+
+
+LyXAlignment GuiParagraph::alignPossible() const
+{
+ return bufferview()->cursor().innerParagraph().layout()->alignpossible;
+}
+
+
+LyXAlignment GuiParagraph::alignDefault() const
+{
+ return bufferview()->cursor().innerParagraph().layout()->align;
+}
+
+
+Dialog * createGuiParagraph(GuiView & lv)
+{
+ return new GuiParagraph(lv);
+}
+
+
} // namespace frontend
} // namespace lyx