The attached patch tries to clear the confusion people have when trying to add a new converter with the qt frontend. Cf. http://bugzilla.lyx.org/show_bug.cgi?id=1488 The ui was just horrible. I think the xforms ui is much more intuitive in this case. I adapted it for the qt frontend. (the problem also occurs in 1.3.6, though)
While doing this, I have also fixed the crash when adding a new file format, as described in bug 1692: http://bugzilla.lyx.org/show_bug.cgi?id=1692 The crash was cured by adding converters().update() calls in new_format() and remove_format(). OK to apply? Jürgen
Index: QPrefsDialog.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QPrefsDialog.C,v retrieving revision 1.41 diff -p -u -r1.41 QPrefsDialog.C --- QPrefsDialog.C 26 Oct 2004 18:39:10 -0000 1.41 +++ QPrefsDialog.C 7 Nov 2004 18:53:30 -0000 @@ -48,6 +48,7 @@ #include <qlineedit.h> #include <qpushbutton.h> #include <qspinbox.h> +#include <qstring.h> using std::string; @@ -173,6 +174,10 @@ QPrefsDialog::QPrefsDialog(QPrefs * form connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(remove_converter())); connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(modify_converter())); connect(convertersModule->convertersLB, SIGNAL(highlighted(int)), this, SLOT(switch_converter(int))); + connect(convertersModule->converterFromCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed())); + connect(convertersModule->converterToCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed())); + connect(convertersModule->converterED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed())); + connect(convertersModule->converterFlagED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed())); // Qt really sucks. This is as ugly as it looks, but the alternative // means having to derive every module == bloat @@ -311,13 +316,15 @@ void QPrefsDialog::updateConverters() Converters::const_iterator ccit = form_->converters().begin(); Converters::const_iterator cend = form_->converters().end(); for (; ccit != cend; ++ccit) { - string const name(ccit->From->prettyname() + " -> " + - ccit->To->prettyname()); + std::string const name(ccit->From->prettyname() + " -> " + + ccit->To->prettyname()); convertmod->convertersLB->insertItem(toqstr(name)); } if (convertmod->convertersLB->currentItem() == -1) convertmod->convertersLB->setCurrentItem(0); + + updateConverterButtons(); } @@ -328,6 +335,40 @@ void QPrefsDialog::switch_converter(int convertersModule->converterToCO->setCurrentItem(form_->formats().getNumber(c.to)); convertersModule->converterED->setText(toqstr(c.command)); convertersModule->converterFlagED->setText(toqstr(c.flags)); + + updateConverterButtons(); +} + + +void QPrefsDialog::converter_changed() +{ + updateConverterButtons(); +} + + +void QPrefsDialog::updateConverterButtons() +{ + Format const & from(form_->formats().get( + convertersModule->converterFromCO->currentItem())); + Format const & to(form_->formats().get( + convertersModule->converterToCO->currentItem())); + int const sel = form_->converters().getNumber(from.name(), to.name()); + bool const known = !(sel < 0); + bool const valid = !(convertersModule->converterED->text().isEmpty() + || from.name() == to.name()); + + Converter const & c(form_->converters().get( + convertersModule->convertersLB->currentItem())); + string const old_command = c.command; + string const old_flag = c.flags; + string const new_command(fromqstr(convertersModule->converterED->text())); + string const new_flag(fromqstr(convertersModule->converterFlagED->text())); + + bool modified = ((old_command != new_command) || (old_flag != new_flag)); + + convertersModule->converterModifyPB->setEnabled(valid && known && modified); + convertersModule->converterNewPB->setEnabled(valid && !known); + convertersModule->converterRemovePB->setEnabled(known); } @@ -337,12 +378,15 @@ void QPrefsDialog::new_converter() { Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem())); Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem())); + string const command(fromqstr(convertersModule->converterED->text())); + string const flags(fromqstr(convertersModule->converterFlagED->text())); Converter const * old = form_->converters().getConverter(from.name(), to.name()); - form_->converters().add(from.name(), to.name(), "", ""); + form_->converters().add(from.name(), to.name(), command, flags); if (!old) { form_->converters().updateLast(form_->formats()); } + updateConverters(); convertersModule->convertersLB->setCurrentItem(convertersModule->convertersLB->count() - 1); } @@ -360,6 +404,7 @@ void QPrefsDialog::modify_converter() if (!old) { form_->converters().updateLast(form_->formats()); } + updateConverters(); } @@ -589,6 +634,7 @@ void QPrefsDialog::new_format() form_->formats().sort(); updateFormats(); fileformatsModule->formatsLB->setCurrentItem(form_->formats().getNumber(_("New"))); + form_->converters().update(form_->formats()); updateConverters(); } @@ -624,7 +670,9 @@ void QPrefsDialog::remove_format() if (nr < 0) return; form_->formats().erase(form_->formats().get(nr).name()); + updateFormats(); + form_->converters().update(form_->formats()); updateConverters(); } Index: QPrefsDialog.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QPrefsDialog.h,v retrieving revision 1.20 diff -p -u -r1.20 QPrefsDialog.h --- QPrefsDialog.h 26 Oct 2004 18:39:11 -0000 1.20 +++ QPrefsDialog.h 7 Nov 2004 18:53:30 -0000 @@ -49,6 +49,7 @@ public: ~QPrefsDialog(); void updateConverters(); + void updateConverterButtons(); void updateCopiers(); void updateFormats(); @@ -61,6 +62,7 @@ public slots: void remove_format(); void switch_converter(int); + void converter_changed(); void new_converter(); void modify_converter(); void remove_converter(); Index: ui/QPrefConvertersModule.ui =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ui/QPrefConvertersModule.ui,v retrieving revision 1.7 diff -p -u -r1.7 QPrefConvertersModule.ui --- ui/QPrefConvertersModule.ui 19 Oct 2004 09:11:01 -0000 1.7 +++ ui/QPrefConvertersModule.ui 7 Nov 2004 18:53:31 -0000 @@ -13,15 +13,15 @@ <rect> <x>0</x> <y>0</y> - <width>384</width> - <height>261</height> + <width>470</width> + <height>265</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>File Conversion</string> </property> - <hbox> + <grid> <property stdset="1"> <name>margin</name> <number>11</number> @@ -30,13 +30,13 @@ <name>spacing</name> <number>6</number> </property> - <widget> + <widget row="0" column="0" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout4</cstring> + <cstring>Layout13</cstring> </property> - <vbox> + <grid> <property stdset="1"> <name>margin</name> <number>0</number> @@ -45,28 +45,41 @@ <name>spacing</name> <number>6</number> </property> - <widget> - <class>QLabel</class> + <widget row="1" column="0" > + <class>QListBox</class> + <item> + <property> + <name>text</name> + <string>New Item</string> + </property> + </item> <property stdset="1"> <name>name</name> - <cstring>formatsLA_2</cstring> + <cstring>convertersLB</cstring> </property> <property stdset="1"> - <name>text</name> - <string>&Converters</string> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>7</vsizetype> + </sizepolicy> </property> - <property> - <name>buddy</name> - <cstring>convertersLB</cstring> + <property stdset="1"> + <name>vScrollBarMode</name> + <enum>AlwaysOn</enum> + </property> + <property stdset="1"> + <name>hScrollBarMode</name> + <enum>AlwaysOff</enum> </property> </widget> - <widget> + <widget row="2" column="0" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout1</cstring> + <cstring>Layout12</cstring> </property> - <grid> + <hbox> <property stdset="1"> <name>margin</name> <number>0</number> @@ -75,67 +88,64 @@ <name>spacing</name> <number>6</number> </property> - <widget row="0" column="0" rowspan="1" colspan="2" > - <class>QListBox</class> - <item> - <property> - <name>text</name> - <string>New Item</string> - </property> - </item> + <widget> + <class>QPushButton</class> <property stdset="1"> <name>name</name> - <cstring>convertersLB</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>3</hsizetype> - <vsizetype>7</vsizetype> - </sizepolicy> - </property> - <property stdset="1"> - <name>vScrollBarMode</name> - <enum>AlwaysOn</enum> + <cstring>converterRemovePB</cstring> </property> <property stdset="1"> - <name>hScrollBarMode</name> - <enum>AlwaysOff</enum> + <name>text</name> + <string>&Remove</string> </property> </widget> - <widget row="1" column="0" > - <class>QPushButton</class> - <property stdset="1"> + <spacer> + <property> <name>name</name> - <cstring>converterNewPB</cstring> + <cstring>Spacer8</cstring> </property> <property stdset="1"> - <name>text</name> - <string>&New</string> + <name>orientation</name> + <enum>Horizontal</enum> </property> - </widget> - <widget row="1" column="1" > - <class>QPushButton</class> <property stdset="1"> - <name>name</name> - <cstring>converterRemovePB</cstring> + <name>sizeType</name> + <enum>Expanding</enum> </property> - <property stdset="1"> - <name>text</name> - <string>&Remove</string> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> </property> - </widget> - </grid> + </spacer> + </hbox> + </widget> + <widget row="0" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>formatsLA_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>&Converters</string> + </property> + <property> + <name>buddy</name> + <cstring>convertersLB</cstring> + </property> </widget> - </vbox> + </grid> </widget> - <widget> + <widget row="0" column="1" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout6</cstring> + <cstring>Layout16</cstring> </property> - <vbox> + <grid> <property stdset="1"> <name>margin</name> <number>0</number> @@ -144,7 +154,7 @@ <name>spacing</name> <number>6</number> </property> - <widget> + <widget row="0" column="0" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> @@ -263,11 +273,32 @@ </widget> </grid> </widget> - <widget> + <spacer row="2" column="0" > + <property> + <name>name</name> + <cstring>Spacer28</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget row="1" column="0" > <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout5</cstring> + <cstring>Layout14</cstring> </property> <hbox> <property stdset="1"> @@ -282,6 +313,17 @@ <class>QPushButton</class> <property stdset="1"> <name>name</name> + <cstring>converterNewPB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>A&dd</string> + </property> + </widget> + <widget> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> <cstring>converterModifyPB</cstring> </property> <property stdset="1"> @@ -292,7 +334,7 @@ <spacer> <property> <name>name</name> - <cstring>Spacer2</cstring> + <cstring>Spacer3</cstring> </property> <property stdset="1"> <name>orientation</name> @@ -312,30 +354,9 @@ </spacer> </hbox> </widget> - <spacer> - <property> - <name>name</name> - <cstring>Spacer28</cstring> - </property> - <property stdset="1"> - <name>orientation</name> - <enum>Vertical</enum> - </property> - <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </vbox> + </grid> </widget> - </hbox> + </grid> </widget> <tabstops> <tabstop>convertersLB</tabstop>