Attached is a patch fixing bug 1550. It pre-empts my previous effort, using radio buttons, as suggested by Abdel and JMarc, among others, rather than a combo box, as previously.
This patch makes the dialog modal, for the present. This is not the ideal solution, but the ideal solution is still not known, the issue being that, if left up, the dialog does not get updated if the user moves the cursor with the keyboard or mouse and hence may still offer invalid options, as well as (say) presenting a disabled Label Width field even though the cursor is in an itemized list. One question: I would have preferred to make QParagraph::radioMap const but couldn't, because it can only be populated after the dialog is created. Any other ideas? rh -- ================================================================== Richard G Heck, Jr Professor of Philosophy Brown University http://frege.brown.edu/heck/ ================================================================== Get my public key from http://sks.keyserver.penguin.de Hash: 0x1DE91F1E66FFBDEC Learn how to sign your email using Thunderbird and GnuPG at: http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto
Index: qt4/QParagraphDialog.C =================================================================== --- qt4/QParagraphDialog.C (revision 17770) +++ qt4/QParagraphDialog.C (working copy) @@ -5,6 +5,7 @@ * * \author John Levon * \author Edwin Leuven + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -21,7 +22,10 @@ #include <QCloseEvent> #include "qt_helpers.h" +#include "frontends/controllers/ControlParagraph.h" +#include <map> + namespace lyx { namespace frontend { @@ -36,8 +40,18 @@ 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() ) ); connect(linespacing, SIGNAL( activated(int) ), @@ -84,6 +98,37 @@ linespacingValue->setEnabled(enable); } + +void QParagraphDialog::checkAlignmentRadioButtons() { + if (alignDefaultCB->isChecked()) { + for ( + QPRadioMap::iterator it = form_->radioMap.begin(); + it != form_->radioMap.end(); + ++it) + { + it->second->setDisabled(true); + } + } else { + LyXAlignment alignPossible = form_->controller().alignPossible(); + for ( + QPRadioMap::iterator it = form_->radioMap.begin(); + it != form_->radioMap.end(); + ++it) + { + it->second->setEnabled(it->first & alignPossible); + } + } +} + + + +void QParagraphDialog::on_alignDefaultCB_toggled(bool) +{ + checkAlignmentRadioButtons(); + form_->alignmentToRadioButtons(); +} + + } // namespace frontend } // namespace lyx Index: qt4/QParagraphDialog.h =================================================================== --- qt4/QParagraphDialog.h (revision 17770) +++ qt4/QParagraphDialog.h (working copy) @@ -6,6 +6,7 @@ * * \author John Levon * \author Edwin Leuven + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -17,16 +18,20 @@ #include <QDialog> #include <QCloseEvent> +#include "layout.h" namespace lyx { namespace frontend { +typedef std::map<LyXAlignment, QRadioButton *> QPRadioMap; + class QParagraph; class QParagraphDialog : public QDialog, public Ui::QParagraphUi { Q_OBJECT public: QParagraphDialog(QParagraph * form); + void checkAlignmentRadioButtons(); protected: void closeEvent (QCloseEvent * e); private: @@ -34,6 +39,7 @@ protected Q_SLOTS: void change_adaptor(); void enableLinespacingValue(int); + void on_alignDefaultCB_toggled(bool); }; } // namespace frontend Index: qt4/QParagraph.C =================================================================== --- qt4/QParagraph.C (revision 17770) +++ qt4/QParagraph.C (working copy) @@ -4,11 +4,13 @@ * Licence details can be found in the file COPYING. * * \author Edwin Leuven + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ #include <config.h> +#include "debug.h" #include "QParagraph.h" #include "QParagraphDialog.h" @@ -17,6 +19,7 @@ #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 { @@ -49,6 +53,11 @@ bcview().setApply(dialog_->applyPB); bcview().setCancel(dialog_->closePB); bcview().setRestore(dialog_->restorePB); + + radioMap[LYX_ALIGN_BLOCK] = dialog_->alignJustRB; + radioMap[LYX_ALIGN_LEFT] = dialog_->alignLeftRB; + radioMap[LYX_ALIGN_RIGHT] = dialog_->alignRightRB; + radioMap[LYX_ALIGN_CENTER] = dialog_->alignCenterRB; } @@ -56,25 +65,7 @@ { 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(getAlignmentFromDialog()); // get spacing Spacing::Space linespacing = Spacing::Default; @@ -110,6 +101,8 @@ void QParagraph::update_contents() { + //updateAlignmentCombo(); + ParagraphParameters const & params = controller().params(); // label width @@ -124,26 +117,15 @@ } // 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 newAlignment = params.align(); + LyXAlignment defaultAlignment = controller().alignDefault(); + bool alignmentIsDefault = + newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment; + dialog_->alignDefaultCB->setChecked(alignmentIsDefault); + dialog_->checkAlignmentRadioButtons(); + alignmentToRadioButtons(newAlignment); - - //LyXAlignment alignpos = controller().alignPossible(); - + //indentation dialog_->indentCB->setChecked(!params.noindent()); // linespacing @@ -176,5 +158,48 @@ } } + +LyXAlignment QParagraph::getAlignmentFromDialog() +{ + if (dialog_->alignDefaultCB->isChecked()) + return LYX_ALIGN_LAYOUT; + LyXAlignment alignment = LYX_ALIGN_NONE; + for ( + QPRadioMap::iterator it = radioMap.begin(); + it != radioMap.end(); + ++it + ) + { + if (it->second->isChecked()) { + alignment = it->first; + break; + } + } + if (alignment == controller().alignDefault()) + return LYX_ALIGN_LAYOUT; + else return alignment; +} + + +void QParagraph::alignmentToRadioButtons(LyXAlignment align) +{ + if (align == LYX_ALIGN_LAYOUT) + align = controller().alignDefault(); + for ( + QPRadioMap::iterator it = radioMap.begin(); + it != radioMap.end(); + ++it + ) + { + if (align == it->first) { + it->second->setChecked(true); + return; + } + } + lyxerr << "Unknown alignment " << controller().lyxAlignmentAsString(align) << + " passed to QParagraph::alignmentToRadioButtons" << endl; +} + + } // namespace frontend } // namespace lyx Index: qt4/ui/QParagraphUi.ui =================================================================== --- qt4/ui/QParagraphUi.ui (revision 17770) +++ qt4/ui/QParagraphUi.ui (working copy) @@ -1,300 +1,369 @@ <ui version="4.0" > - <author></author> - <comment></comment> - <exportmacro></exportmacro> <class>QParagraphUi</class> <widget class="QDialog" name="QParagraphUi" > + <property name="windowModality" > + <enum>Qt::ApplicationModal</enum> + </property> <property name="geometry" > <rect> <x>0</x> <y>0</y> - <width>396</width> - <height>237</height> + <width>493</width> + <height>334</height> </rect> </property> + <property name="focusPolicy" > + <enum>Qt::NoFocus</enum> + </property> <property name="windowTitle" > <string/> </property> <property name="sizeGripEnabled" > <bool>true</bool> </property> - <layout class="QGridLayout" > - <property name="margin" > - <number>11</number> + <widget class="QWidget" name="layoutWidget" > + <property name="geometry" > + <rect> + <x>10</x> + <y>10</y> + <width>468</width> + <height>301</height> + </rect> </property> - <property name="spacing" > - <number>6</number> - </property> - <item row="1" column="1" > - <widget class="QComboBox" name="linespacing" > - <item> - <property name="text" > - <string>Default</string> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> </property> - </item> - <item> - <property name="text" > - <string>Single</string> + <property name="spacing" > + <number>6</number> </property> - </item> - <item> - <property name="text" > - <string>1.5</string> - </property> - </item> - <item> - <property name="text" > - <string>Double</string> - </property> - </item> - <item> - <property name="text" > - <string>Custom</string> - </property> - </item> - </widget> - </item> - <item row="1" column="0" > - <widget class="QLabel" name="linespacingL" > - <property name="text" > - <string>L&ine spacing:</string> - </property> - <property name="buddy" > - <cstring>linespacing</cstring> - </property> - </widget> - </item> - <item row="0" column="1" > - <widget class="QComboBox" name="align" > - <item> - <property name="text" > - <string>Justified</string> - </property> - </item> - <item> - <property name="text" > - <string>Left</string> - </property> - </item> - <item> - <property name="text" > - <string>Right</string> - </property> - </item> - <item> - <property name="text" > - <string>Center</string> - </property> - </item> - </widget> - </item> - <item row="0" column="0" > - <widget class="QLabel" name="alignL" > - <property name="text" > - <string>Alig&nment:</string> - </property> - <property name="buddy" > - <cstring>align</cstring> - </property> - </widget> - </item> - <item rowspan="2" row="0" column="2" > - <layout class="QVBoxLayout" > - <property name="margin" > - <number>0</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item> - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QLineEdit" name="linespacingValue" > - <property name="enabled" > - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </item> - <item row="2" column="0" colspan="3" > - <layout class="QHBoxLayout" > - <property name="margin" > - <number>0</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item> - <widget class="QCheckBox" name="indentCB" > - <property name="text" > - <string>In&dent paragraph</string> - </property> - </widget> - </item> - <item> - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="3" column="0" colspan="3" > - <widget class="QGroupBox" name="labelwidthGB" > - <property name="enabled" > - <bool>false</bool> - </property> - <property name="title" > - <string>Label Width</string> - </property> - <layout class="QGridLayout" > + <item> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QGroupBox" name="aligmentGB" > + <property name="title" > + <string>Alignment</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QCheckBox" name="alignDefaultCB" > + <property name="font" > + <font> + <weight>50</weight> + <italic>true</italic> + <bold>false</bold> + <kerning>true</kerning> + </font> + </property> + <property name="text" > + <string>&Default</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="alignJustRB" > + <property name="text" > + <string>&Justified</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="alignLeftRB" > + <property name="text" > + <string>&Left</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="alignRightRB" > + <property name="text" > + <string>&Right</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="alignCenterRB" > + <property name="text" > + <string>&Center</string> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QLabel" name="linespacingL" > + <property name="text" > + <string>L&ine spacing:</string> + </property> + <property name="buddy" > + <cstring>linespacing</cstring> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="linespacing" > + <item> + <property name="text" > + <string>Default</string> + </property> + </item> + <item> + <property name="text" > + <string>Single</string> + </property> + </item> + <item> + <property name="text" > + <string>1.5</string> + </property> + </item> + <item> + <property name="text" > + <string>Double</string> + </property> + </item> + <item> + <property name="text" > + <string>Custom</string> + </property> + </item> + </widget> + </item> + <item> + <widget class="QLineEdit" name="linespacingValue" > + <property name="enabled" > + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QCheckBox" name="indentCB" > + <property name="text" > + <string>Indent &Paragraph</string> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="labelwidthGB" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="title" > + <string>Label Width</string> + </property> + <layout class="QGridLayout" > + <property name="margin" > + <number>11</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="1" > + <widget class="QLineEdit" name="labelWidth" > + <property name="toolTip" > + <string>This text defines the width of the paragraph label</string> + </property> + </widget> + </item> + <item row="0" column="0" > + <widget class="QLabel" name="TextLabel2" > + <property name="toolTip" > + <string>This text defines the width of the paragraph label</string> + </property> + <property name="text" > + <string>&Longest label</string> + </property> + <property name="buddy" > + <cstring>labelWidth</cstring> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > <property name="margin" > - <number>11</number> + <number>0</number> </property> <property name="spacing" > <number>6</number> </property> - <item row="0" column="1" > - <widget class="QLineEdit" name="labelWidth" > - <property name="toolTip" > - <string>This text defines the width of the paragraph label</string> + <item> + <widget class="QPushButton" name="restorePB" > + <property name="text" > + <string>&Restore</string> </property> + <property name="autoDefault" > + <bool>false</bool> + </property> </widget> </item> - <item row="0" column="0" > - <widget class="QLabel" name="TextLabel2" > - <property name="toolTip" > - <string>This text defines the width of the paragraph label</string> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> </property> + <property name="sizeType" > + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="okPB" > <property name="text" > - <string>&Longest label</string> + <string>&OK</string> </property> - <property name="buddy" > - <cstring>labelWidth</cstring> + <property name="autoDefault" > + <bool>false</bool> </property> + <property name="default" > + <bool>true</bool> + </property> </widget> </item> + <item> + <widget class="QPushButton" name="applyPB" > + <property name="text" > + <string>&Apply</string> + </property> + <property name="autoDefault" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="closePB" > + <property name="text" > + <string>&Close</string> + </property> + <property name="autoDefault" > + <bool>false</bool> + </property> + </widget> + </item> </layout> - </widget> - </item> - <item row="4" column="2" > - <spacer> - <property name="orientation" > - <enum>Qt::Vertical</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="5" column="0" colspan="3" > - <layout class="QHBoxLayout" > - <property name="margin" > - <number>0</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item> - <widget class="QPushButton" name="restorePB" > - <property name="text" > - <string>&Restore</string> - </property> - <property name="autoDefault" > - <bool>false</bool> - </property> - </widget> - </item> - <item> - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType" > - <enum>QSizePolicy::Expanding</enum> - </property> - <property name="sizeHint" > - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="okPB" > - <property name="text" > - <string>&OK</string> - </property> - <property name="autoDefault" > - <bool>false</bool> - </property> - <property name="default" > - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="applyPB" > - <property name="text" > - <string>&Apply</string> - </property> - <property name="autoDefault" > - <bool>false</bool> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="closePB" > - <property name="text" > - <string>&Close</string> - </property> - <property name="autoDefault" > - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </item> - </layout> + </item> + </layout> + </widget> </widget> - <pixmapfunction></pixmapfunction> - <includes> - <include location="local" >qt_helpers.h</include> - </includes> <tabstops> - <tabstop>align</tabstop> <tabstop>linespacing</tabstop> <tabstop>linespacingValue</tabstop> <tabstop>indentCB</tabstop> @@ -304,6 +373,9 @@ <tabstop>applyPB</tabstop> <tabstop>closePB</tabstop> </tabstops> + <includes> + <include location="local" >qt_helpers.h</include> + </includes> <resources/> <connections/> </ui> Index: qt4/QParagraph.h =================================================================== --- qt4/QParagraph.h (revision 17770) +++ qt4/QParagraph.h (working copy) @@ -6,6 +6,7 @@ * * \author Edwin Leuven * \author John Levon + * \author Richard Heck * * Full author contact details are available in file CREDITS. */ @@ -15,6 +16,8 @@ #include "QDialogView.h" #include "QParagraphDialog.h" +#include "layout.h" +#include <map> namespace lyx { namespace frontend { @@ -26,8 +29,8 @@ { public: friend class QParagraphDialog; - QParagraph(Dialog &); + private: /// Apply changes virtual void apply(); @@ -35,8 +38,15 @@ virtual void update_contents(); /// build the dialog virtual void build_dialog(); + /// + LyXAlignment getAlignmentFromDialog(); + /// + void alignmentToRadioButtons(LyXAlignment align = LYX_ALIGN_LAYOUT); + /// + QPRadioMap radioMap; }; + } // namespace frontend } // namespace lyx Index: controllers/ControlParagraph.C =================================================================== --- controllers/ControlParagraph.C (revision 17770) +++ controllers/ControlParagraph.C (working copy) @@ -17,12 +17,15 @@ #include "lyxlex.h" #include "paragraph.h" #include "ParagraphParameters.h" +#include "layout.h" +#include "debug.h" #include <sstream> using std::istringstream; using std::ostringstream; using std::string; +using std::endl; namespace lyx { namespace frontend { @@ -165,5 +168,23 @@ return aligndefault_; } + +string ControlParagraph::lyxAlignmentAsString(LyXAlignment const align) +{ + switch (align) { + case LYX_ALIGN_NONE: return "None"; + case LYX_ALIGN_BLOCK: return "Justified"; + case LYX_ALIGN_LEFT: return "Left"; + case LYX_ALIGN_RIGHT: return "Right"; + case LYX_ALIGN_CENTER: return "Center"; + case LYX_ALIGN_LAYOUT: return "Default"; + case LYX_ALIGN_SPECIAL: return "Special"; + } + //Should never get here. + lyxerr << "Invalid alignment passed to ControlParagraph::lyxAlignmentAsString()" <<endl; + return ""; +} + + } // namespace frontend } // namespace lyx Index: controllers/ControlParagraph.h =================================================================== --- controllers/ControlParagraph.h (revision 17770) +++ controllers/ControlParagraph.h (working copy) @@ -15,6 +15,8 @@ #include "Dialog.h" #include "layout.h" // for LyXAlignment +using std::string; + namespace lyx { class ParagraphParameters; @@ -43,6 +45,9 @@ LyXAlignment alignPossible() const; /// LyXAlignment alignDefault() const; + /// + string lyxAlignmentAsString(LyXAlignment const align); + private: ///