diff --git a/src/frontends/qt4/QParagraph.C b/src/frontends/qt4/QParagraph.C index 1c0db613b2..eddbb3169f 100644 --- a/src/frontends/qt4/QParagraph.C +++ b/src/frontends/qt4/QParagraph.C @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Edwin Leuven + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -15,8 +16,10 @@ #include "Qt2BC.h" #include "qt_helpers.h" +#include "debug.h" #include "ParagraphParameters.h" #include "Spacing.h" +#include "layout.h" #include "controllers/ControlParagraph.h" #include "controllers/helper_funcs.h" @@ -27,6 +30,7 @@ using std::string; +using std::endl; namespace lyx { namespace frontend { @@ -56,25 +60,7 @@ void QParagraph::apply() { ParagraphParameters & params = controller().params(); - // alignment - LyXAlignment align; - switch (dialog_->align->currentIndex()) { - case 0: - align = LYX_ALIGN_BLOCK; - break; - case 1: - align = LYX_ALIGN_LEFT; - break; - case 2: - align = LYX_ALIGN_RIGHT; - break; - case 3: - align = LYX_ALIGN_CENTER; - break; - default: - align = LYX_ALIGN_BLOCK; - } - params.align(align); + params.align(dialog_->getAlignmentFromDialog()); // get spacing Spacing::Space linespacing = Spacing::Default; @@ -124,26 +110,15 @@ void QParagraph::update_contents() } // alignment - int i; - switch (params.align()) { - case LYX_ALIGN_LEFT: - i = 1; - break; - case LYX_ALIGN_RIGHT: - i = 2; - break; - case LYX_ALIGN_CENTER: - i = 3; - break; - default: - i = 0; - break; - } - dialog_->align->setCurrentIndex(i); - - - //LyXAlignment alignpos = controller().alignPossible(); + LyXAlignment newAlignment = params.align(); + LyXAlignment defaultAlignment = controller().alignDefault(); + bool alignmentIsDefault = + newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment; + dialog_->alignDefaultCB->setChecked(alignmentIsDefault); + dialog_->checkAlignmentRadioButtons(); + dialog_->alignmentToRadioButtons(newAlignment); + //indentation dialog_->indentCB->setChecked(!params.noindent()); // linespacing diff --git a/src/frontends/qt4/QParagraphDialog.C b/src/frontends/qt4/QParagraphDialog.C index bf4f2fdc48..bbc1452dde 100644 --- a/src/frontends/qt4/QParagraphDialog.C +++ b/src/frontends/qt4/QParagraphDialog.C @@ -5,6 +5,7 @@ * * \author John Levon * \author Edwin Leuven + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -21,6 +22,11 @@ #include #include "qt_helpers.h" +#include "frontends/controllers/ControlParagraph.h" + +#include "debug.h" + +#include namespace lyx { namespace frontend { @@ -36,7 +42,17 @@ QParagraphDialog::QParagraphDialog(QParagraph * form) form_, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); - connect(align, SIGNAL( activated(int) ), + connect(restorePB, SIGNAL(clicked()), + form_, SLOT(slotRestore())); + connect(alignDefaultCB, SIGNAL( clicked() ), + this, SLOT( change_adaptor() ) ); + connect(alignJustRB, SIGNAL( clicked() ), + this, SLOT( change_adaptor() ) ); + connect(alignLeftRB, SIGNAL( clicked() ), + this, SLOT( change_adaptor() ) ); + connect(alignRightRB, SIGNAL( clicked() ), + this, SLOT( change_adaptor() ) ); + connect(alignCenterRB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) ); connect(linespacing, SIGNAL( activated(int) ), this, SLOT( change_adaptor() ) ); @@ -62,6 +78,11 @@ QParagraphDialog::QParagraphDialog(QParagraph * form) " items is used. But if you need to, you can" " change it here." )); + + radioMap[LYX_ALIGN_BLOCK] = alignJustRB; + radioMap[LYX_ALIGN_LEFT] = alignLeftRB; + radioMap[LYX_ALIGN_RIGHT] = alignRightRB; + radioMap[LYX_ALIGN_CENTER] = alignCenterRB; } @@ -84,6 +105,64 @@ void QParagraphDialog::enableLinespacingValue(int) linespacingValue->setEnabled(enable); } + +void QParagraphDialog::checkAlignmentRadioButtons() { + if (alignDefaultCB->isChecked()) { + QPRadioMap::const_iterator it = radioMap.begin(); + for (; it != radioMap.end(); ++it) + it->second->setDisabled(true); + } else { + LyXAlignment alignPossible = form_->controller().alignPossible(); + QPRadioMap::const_iterator it = radioMap.begin(); + for (; it != radioMap.end(); ++it) + it->second->setEnabled(it->first & alignPossible); + } +} + + +void QParagraphDialog::on_alignDefaultCB_toggled(bool) +{ + checkAlignmentRadioButtons(); + alignmentToRadioButtons(); +} + + +void QParagraphDialog::alignmentToRadioButtons(LyXAlignment align) +{ + if (align == LYX_ALIGN_LAYOUT) + align = form_->controller().alignDefault(); + + QPRadioMap::const_iterator it = radioMap.begin(); + for (;it != radioMap.end(); ++it) { + if (align == it->first) { + it->second->setChecked(true); + return; + } + } + + lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment " + << align << std::endl; +} + + +LyXAlignment QParagraphDialog::getAlignmentFromDialog() +{ + if (alignDefaultCB->isChecked()) + return LYX_ALIGN_LAYOUT; + LyXAlignment alignment = LYX_ALIGN_NONE; + QPRadioMap::const_iterator it = radioMap.begin(); + for (; it != radioMap.end(); ++it) { + if (it->second->isChecked()) { + alignment = it->first; + break; + } + } + if (alignment == form_->controller().alignDefault()) + return LYX_ALIGN_LAYOUT; + else return alignment; +} + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/QParagraphDialog.h b/src/frontends/qt4/QParagraphDialog.h index 48c7a694ff..fefcedd960 100644 --- a/src/frontends/qt4/QParagraphDialog.h +++ b/src/frontends/qt4/QParagraphDialog.h @@ -6,6 +6,7 @@ * * \author John Levon * \author Edwin Leuven + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -17,23 +18,36 @@ #include #include +#include "layout.h" namespace lyx { namespace frontend { - + class QParagraph; class QParagraphDialog : public QDialog, public Ui::QParagraphUi { Q_OBJECT public: QParagraphDialog(QParagraph * form); + /// + void checkAlignmentRadioButtons(); + /// + void alignmentToRadioButtons(LyXAlignment align = LYX_ALIGN_LAYOUT); + /// + LyXAlignment getAlignmentFromDialog(); protected: void closeEvent (QCloseEvent * e); private: QParagraph * form_; + typedef std::map QPRadioMap; + QPRadioMap radioMap; protected Q_SLOTS: + /// void change_adaptor(); + /// void enableLinespacingValue(int); + /// + void on_alignDefaultCB_toggled(bool); }; } // namespace frontend diff --git a/src/frontends/qt4/ui/QParagraphUi.ui b/src/frontends/qt4/ui/QParagraphUi.ui index 8689d55156..1d18b9f033 100644 --- a/src/frontends/qt4/ui/QParagraphUi.ui +++ b/src/frontends/qt4/ui/QParagraphUi.ui @@ -1,300 +1,369 @@ - - - QParagraphUi + + Qt::ApplicationModal + 0 0 - 396 - 237 + 493 + 334 + + Qt::NoFocus + true - - - 11 + + + + 10 + 10 + 468 + 301 + - - 6 - - - - - - Default - - - - - Single - - - - - 1.5 - - - - - Double - - - - - Custom - - - - - - - - L&ine spacing: - - - linespacing - - - - - - - - Justified - - - - - Left - - - - - Right - - - - - Center - - - - - - - - Alig&nment: - - - align - - - - - - - 0 - - - 6 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - false - - - - - - - - - 0 - - - 6 - - - - - In&dent paragraph - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - - - false - - - Label Width - - + + + 0 + + + 6 + + + - 11 + 0 6 - - - - This text defines the width of the paragraph label + + + + 0 + + + 6 + + + + + Alignment + + + + 9 + + + 6 + + + + + + 50 + true + false + true + + + + &Default + + + + + + + &Justified + + + + + + + &Left + + + + + + + &Right + + + + + + + &Center + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 0 + + + 6 + + + + + 0 + + + 6 + + + + + L&ine spacing: + + + linespacing + + + + + + + + Default + + + + + Single + + + + + 1.5 + + + + + Double + + + + + Custom + + + + + + + + false + + + + + + + + + 0 + + + 6 + + + + + Indent &Paragraph + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + + + false + + + Label Width + + + + 11 + + + 6 + + + + + This text defines the width of the paragraph label + + + + + + + This text defines the width of the paragraph label + + + &Longest label + + + labelWidth + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + 0 + + + 6 + + + + + &Restore + + + false - - - - This text defines the width of the paragraph label + + + + Qt::Horizontal + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + - &Longest label + &OK - - labelWidth + + false + + + true + + + + + + + &Apply + + + false + + + + + + + &Close + + + false - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - 0 - - - 6 - - - - - &Restore - - - false - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - &OK - - - false - - - true - - - - - - - &Apply - - - false - - - - - - - &Close - - - false - - - - - - + + + - - - qt_helpers.h - - align linespacing linespacingValue indentCB @@ -304,6 +373,9 @@ applyPB closePB + + qt_helpers.h +