Please test this listings dialog, which looks more like Herbert's original one. I would appreciate it if someone can show me how to call this dialog from Include dialog and TextLayout dialog.
I plan to add it before beta3. Cheers, Bo
Index: src/frontends/qt4/QListings.h =================================================================== --- src/frontends/qt4/QListings.h (revision 18278) +++ src/frontends/qt4/QListings.h (working copy) @@ -27,6 +27,8 @@ Q_OBJECT public: QListingsDialog(QListings * form); + /// get values from all the widgets and form a string + std::string construct_params(); protected Q_SLOTS: virtual void change_adaptor(); /// AFAIK, QValidator only works for QLineEdit so Index: src/frontends/qt4/ui/ListingsUi.ui =================================================================== --- src/frontends/qt4/ui/ListingsUi.ui (revision 18278) +++ src/frontends/qt4/ui/ListingsUi.ui (working copy) @@ -8,8 +8,8 @@ <rect> <x>0</x> <y>0</y> - <width>239</width> - <height>382</height> + <width>548</width> + <height>462</height> </rect> </property> <property name="windowTitle" > @@ -26,73 +26,758 @@ <number>6</number> </property> <item> - <widget class="QCheckBox" name="inlineCB" > - <property name="text" > - <string>Inline listing</string> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> </property> - </widget> - </item> - <item> - <widget class="QGroupBox" name="listingsGB" > - <property name="sizePolicy" > - <sizepolicy> - <hsizetype>7</hsizetype> - <vsizetype>7</vsizetype> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <property name="spacing" > + <number>6</number> </property> - <property name="title" > - <string>Parameters</string> - </property> - <layout class="QVBoxLayout" > - <property name="margin" > - <number>9</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item> - <widget class="QTextBrowser" name="listingsTB" > - <property name="sizePolicy" > - <sizepolicy> - <hsizetype>7</hsizetype> - <vsizetype>0</vsizetype> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <item> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QGroupBox" name="groupBox" > + <property name="title" > + <string>Language</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QComboBox" name="languageCO" /> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2" > + <property name="title" > + <string>Placement</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QCheckBox" name="inlineCB" > + <property name="text" > + <string>Inline listing</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="floatCB" > + <property name="text" > + <string>Float</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" > + <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="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> + <widget class="QLabel" name="captionL_5" > + <property name="text" > + <string>Placement</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>captionLE</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="placementLE" /> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QGroupBox" name="numberstyleGB" > + <property name="title" > + <string>Number style</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> </property> - <property name="maximumSize" > - <size> - <width>16777215</width> - <height>50</height> - </size> + <property name="spacing" > + <number>6</number> </property> - <property name="cursor" > - <cursor>0</cursor> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QCheckBox" name="numberLeftCB" > + <property name="toolTip" > + <string>enable for numbers on the leftside</string> + </property> + <property name="text" > + <string>&Left</string> + </property> + <property name="checked" > + <bool>false</bool> + </property> + <property name="autoRepeat" > + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="numberRightCB" > + <property name="toolTip" > + <string>enable for numbers on the right side</string> + </property> + <property name="text" > + <string>&Right</string> + </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="QLabel" name="stepnumberL" > + <property name="toolTip" > + <string>File name of image</string> + </property> + <property name="text" > + <string>Step</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>numberStepLE</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="numberStepLE" > + <property name="toolTip" > + <string>Differenz between two numbered lines</string> + </property> + <property name="text" > + <string/> + </property> + <property name="alignment" > + <set>Qt::AlignLeading</set> + </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="QLabel" name="numberfontsizeL" > + <property name="text" > + <string>Font size</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>numberFontSizeCO</cstring> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="numberFontSizeCO" > + <property name="toolTip" > + <string>Choose the Font Size</string> + </property> + <property name="editable" > + <bool>true</bool> + </property> + <property name="autoCompletion" > + <bool>true</bool> + </property> + <property name="duplicatesEnabled" > + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>142</width> + <height>31</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QLabel" name="numberfontsizeL_3" > + <property name="text" > + <string>First line</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>numberFontSizeCO</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="firstlineLE" > + <property name="toolTip" > + <string>Differenz between two numbered lines</string> + </property> + <property name="text" > + <string/> + </property> + <property name="alignment" > + <set>Qt::AlignLeading</set> + </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="QLabel" name="numberfontsizeL_2" > + <property name="text" > + <string>Last line</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>numberFontSizeCO</cstring> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lastlineLE" > + <property name="toolTip" > + <string>Differenz between two numbered lines</string> + </property> + <property name="text" > + <string/> + </property> + <property name="alignment" > + <set>Qt::AlignLeading</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>142</width> + <height>31</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QGroupBox" name="basicstyleGB" > + <property name="font" > + <font> + <pointsize>10</pointsize> + </font> + </property> + <property name="title" > + <string>Style</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> </property> - <property name="acceptDrops" > - <bool>false</bool> + <property name="spacing" > + <number>6</number> </property> - <property name="frameShape" > - <enum>QFrame::NoFrame</enum> + <item> + <widget class="QLabel" name="label_6" > + <property name="text" > + <string>Basic style</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QLabel" name="fontsize_label_3" > + <property name="text" > + <string>Font size</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>fontsizeCO</cstring> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="fontsizeCO" > + <property name="toolTip" > + <string>Choose the Font Size</string> + </property> + <property name="editable" > + <bool>true</bool> + </property> + <property name="autoCompletion" > + <bool>true</bool> + </property> + <property name="duplicatesEnabled" > + <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="QLabel" name="fontstyle_label_3" > + <property name="text" > + <string>Font style</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>fontstyleCO</cstring> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="fontstyleCO" > + <property name="toolTip" > + <string>Choose the Font Style</string> + </property> + <property name="editable" > + <bool>true</bool> + </property> + <property name="autoCompletion" > + <bool>true</bool> + </property> + <property name="duplicatesEnabled" > + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>158</width> + <height>21</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="breaklinesCB" > + <property name="toolTip" > + <string>Breaking lines longer than the linewidth</string> + </property> + <property name="text" > + <string>&Break long lines</string> + </property> + <property name="shortcut" > + <number>276824130</number> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="spaceCB" > + <property name="toolTip" > + <string>Insert a special symbol for a space</string> + </property> + <property name="text" > + <string>&Space as Symbol</string> + </property> + <property name="shortcut" > + <number>276824147</number> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="extendedcharsCB" > + <property name="enabled" > + <bool>true</bool> + </property> + <property name="toolTip" > + <string>Use extended character table</string> + </property> + <property name="text" > + <string>&Extended Chars</string> + </property> + <property name="shortcut" > + <number>276824133</number> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>158</width> + <height>21</height> + </size> + </property> + </spacer> + </item> + </layout> + </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="QGroupBox" name="captionGB_3" > + <property name="title" > + <string>Display</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> </property> - <property name="frameShadow" > - <enum>QFrame::Plain</enum> + <property name="spacing" > + <number>6</number> </property> - <property name="lineWidth" > - <number>0</number> + <item> + <widget class="QLabel" name="captionL_4" > + <property name="text" > + <string>&Caption</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>captionLE</cstring> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QLineEdit" name="captionLE" > + <property name="minimumSize" > + <size> + <width>150</width> + <height>0</height> + </size> + </property> + <property name="toolTip" > + <string>A caption for the List of Listings</string> + </property> + <property name="text" > + <string/> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QLabel" name="labelL_4" > + <property name="text" > + <string>&Label</string> + </property> + <property name="wordWrap" > + <bool>false</bool> + </property> + <property name="buddy" > + <cstring>labelLE</cstring> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> + <widget class="QLineEdit" name="labelLE" > + <property name="minimumSize" > + <size> + <width>150</width> + <height>0</height> + </size> + </property> + <property name="toolTip" > + <string>A Label for the caption</string> + </property> + <property name="text" > + <string/> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>20</width> + <height>21</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QGroupBox" name="listingsGB" > + <property name="sizePolicy" > + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title" > + <string>More Parameters</string> + </property> + <layout class="QVBoxLayout" > + <property name="margin" > + <number>9</number> </property> - <property name="acceptRichText" > - <bool>false</bool> + <property name="spacing" > + <number>6</number> </property> - </widget> - </item> - <item> - <widget class="QTextEdit" name="listingsED" /> - </item> - </layout> - </widget> + <item> + <widget class="QSplitter" name="splitter" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <widget class="QTextBrowser" name="listingsTB" > + <property name="maximumSize" > + <size> + <width>16777215</width> + <height>16777215</height> + </size> + </property> + <property name="cursor" > + <cursor>0</cursor> + </property> + <property name="acceptDrops" > + <bool>false</bool> + </property> + <property name="frameShape" > + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow" > + <enum>QFrame::Plain</enum> + </property> + <property name="lineWidth" > + <number>0</number> + </property> + <property name="acceptRichText" > + <bool>false</bool> + </property> + </widget> + <widget class="QTextEdit" name="listingsED" /> + </widget> + </item> + </layout> + </widget> + </item> + </layout> </item> <item> <layout class="QHBoxLayout" > @@ -142,7 +827,23 @@ <tabstops> <tabstop>okPB</tabstop> <tabstop>closePB</tabstop> + <tabstop>languageCO</tabstop> <tabstop>inlineCB</tabstop> + <tabstop>floatCB</tabstop> + <tabstop>placementLE</tabstop> + <tabstop>numberLeftCB</tabstop> + <tabstop>numberRightCB</tabstop> + <tabstop>numberStepLE</tabstop> + <tabstop>numberFontSizeCO</tabstop> + <tabstop>firstlineLE</tabstop> + <tabstop>lastlineLE</tabstop> + <tabstop>fontsizeCO</tabstop> + <tabstop>fontstyleCO</tabstop> + <tabstop>breaklinesCB</tabstop> + <tabstop>spaceCB</tabstop> + <tabstop>extendedcharsCB</tabstop> + <tabstop>captionLE</tabstop> + <tabstop>labelLE</tabstop> <tabstop>listingsTB</tabstop> <tabstop>listingsED</tabstop> </tabstops> Index: src/frontends/qt4/QListings.cpp =================================================================== --- src/frontends/qt4/QListings.cpp (revision 18278) +++ src/frontends/qt4/QListings.cpp (working copy) @@ -23,9 +23,16 @@ #include <QLineEdit> #include <QCloseEvent> #include <QPushButton> +#include <QValidator> +#include <QRegExpValidator> using std::string; +using std::vector; +using lyx::support::getVectorFromString; +using lyx::support::getStringFromVector; +using lyx::support::prefixIs; +using lyx::support::contains; namespace lyx { namespace frontend { @@ -37,6 +44,17 @@ ///////////////////////////////////////////////////////////////////// +string const allowed_languages = + "no language\nBAP\nACSL\nAda\nALGOL\nC\nC++\nCaml\nClean\nCobol\n" + "Comal 80\ncsh\nDelphi\nEiffel\nElan\nEuphoria\nFortran\nHaskell\n" + "HTML\nIDL\nJava\nLisp\nLogo\nmake\nMathematica\nMatlab\nMercury\n" + "Miranda\nML\nModula-2\nOberon-2\nOCL\nPascal\nPerl\nPHP\nPL/I\nPOV\n" + "Python\nProlog\nR\nS\nSAS\nSHELXL\nSimula\ntcl\nSQL\nTeX\nVBScript\n" + "VHDL\nXML"; +string const allowed_fontsizes = "default\ntiny\nscriptsize\nfootnotesize\nsmall\n" + "normalsize\nlarge\nLarge"; +string const allowed_fontstyles = "default\nrmfamily\nttfamily\nsffamily"; + QListingsDialog::QListingsDialog(QListings * form) : form_(form) { @@ -44,7 +62,25 @@ connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK())); connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + + connect(languageCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); connect(inlineCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(floatCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(placementLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); + connect(numberLeftCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(numberRightCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(numberStepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); + connect(numberFontSizeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); + connect(firstlineLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); + connect(lastlineLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); + connect(fontsizeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); + connect(fontstyleCO, SIGNAL(currentIndexChanged(int)), this, SLOT(change_adaptor())); + connect(breaklinesCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(spaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); + connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); + connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor())); connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params())); } @@ -63,11 +99,79 @@ } +string QListingsDialog::construct_params() +{ + string language = fromqstr(languageCO->currentText()); + + bool float_ = floatCB->checkState() == Qt::Checked; + string placement = fromqstr(placementLE->text()); + + bool left = numberLeftCB->checkState() == Qt::Checked; + bool right = numberRightCB->checkState() == Qt::Checked; + string step = fromqstr(numberStepLE->text()); + string numberfontsize = fromqstr(numberFontSizeCO->currentText()); + string firstline = fromqstr(firstlineLE->text()); + string lastline = fromqstr(lastlineLE->text()); + + string fontsize = fromqstr(fontsizeCO->currentText()); + string fontstyle = fromqstr(fontstyleCO->currentText()); + string basicstyle; + if (fontsize != "default") + basicstyle = "\\" + fontsize; + if (fontstyle != "default") + basicstyle += "\\" + fontstyle; + bool breakline = breaklinesCB->checkState() == Qt::Checked; + bool space = spaceCB->checkState() == Qt::Checked; + bool extendedchar = extendedcharsCB->checkState() == Qt::Checked; + + string caption = fromqstr(captionLE->text()); + string label = fromqstr(labelLE->text()); + + string extra = fromqstr(listingsED->toPlainText()); + + // compose a string + InsetListingsParams par; + if (language != "no language") + par.addParam("language", language); + if (float_) + par.addParam("float", ""); + try { + if (!placement.empty()) + par.addParam("floatplacement", placement); + } catch (invalidParam & e) { + } + if (left) + par.addParam("numbers", "left"); + else if (right) + par.addParam("numbers", "right"); + if (numberfontsize != "default") + par.addParam("numberstyle", "\\" + numberfontsize); + if (!firstline.empty()) + par.addParam("firstline", firstline); + if (!lastline.empty()) + par.addParam("lastline", lastline); + if (basicstyle != "") + par.addParam("basicstyle", basicstyle); + if (breakline) + par.addParam("breaklines", "true"); + if (space) + par.addParam("showspaces", "true"); + if (extendedchar) + par.addParam("extendedchars", "true"); + if (!caption.empty()) + par.addParam("caption", "{" + caption + "}"); + if (!label.empty()) + par.addParam("label", "{" + label + "}"); + par.addParams(extra); + return par.params(); +} + + void QListingsDialog::validate_listings_params() { static bool isOK = true; try { - InsetListingsParams par(fromqstr(listingsED->toPlainText())); + InsetListingsParams par(construct_params()); if (!isOK) { isOK = true; // listingsTB->setTextColor("black"); @@ -102,8 +206,6 @@ bcview().setOK(dialog_->okPB); bcview().setCancel(dialog_->closePB); - dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters."); - update_contents(); } @@ -113,20 +215,158 @@ { InsetListingsParams & params = controller().params(); params.setInline(dialog_->inlineCB->isChecked()); - params.setParams(fromqstr(dialog_->listingsED->toPlainText())); + params.setParams(dialog_->construct_params()); controller().setParams(params); } void QListings::update_contents() { + + // first prepare all choices + vector<string> const languages = + getVectorFromString(allowed_languages, "\n"); + vector<string> const fontstyles = + getVectorFromString(allowed_fontstyles, "\n"); + vector<string> const fontsizes = + getVectorFromString(allowed_fontsizes, "\n"); + + dialog_->languageCO->clear(); + for (vector<string>::const_iterator it = languages.begin(); + it != languages.end(); ++it) { + dialog_->languageCO->addItem(toqstr(*it)); + } + dialog_->fontstyleCO->clear(); + dialog_->fontstyleCO->setEditable(false); + for (vector<string>::const_iterator it = fontstyles.begin(); + it != fontstyles.end(); ++it) { + dialog_->fontstyleCO->addItem(toqstr(*it)); + } + dialog_->fontsizeCO->clear(); + dialog_->fontsizeCO->setEditable(false); + dialog_->numberFontSizeCO->clear(); + dialog_->numberFontSizeCO->setEditable(false); + for (vector<string>::const_iterator it = fontsizes.begin(); + it != fontsizes.end(); ++it) { + dialog_->fontsizeCO->addItem(toqstr(*it)); + dialog_->numberFontSizeCO->addItem(toqstr(*it)); + } + + // set validators + dialog_->numberStepLE->setValidator(new QIntValidator(0, 1000000, this)); + dialog_->firstlineLE->setValidator(new QIntValidator(0, 1000000, this)); + dialog_->lastlineLE->setValidator(new QIntValidator(0, 1000000, this)); + dialog_->placementLE->setValidator(new QRegExpValidator(QRegExp("[tbph]*"), this)); + + // + dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters."); + + // set values from param string InsetListingsParams & params = controller().params(); - dialog_->listingsED->setPlainText(toqstr(params.separatedParams())); - if (params.isInline()) dialog_->inlineCB->setChecked(true); else dialog_->inlineCB->setChecked(false); + // break other parameters and set values + vector<string> pars = getVectorFromString(params.separatedParams(), "\n"); + // process each of them + for (vector<string>::iterator it = pars.begin(); + it != pars.end(); ++it) { + if (prefixIs(*it, "language=")) { + for (vector<string>::const_iterator st = languages.begin(); + st != languages.end(); ++st) { + if (*it == "language=" + *st) { + dialog_->languageCO->setCurrentIndex( + dialog_->languageCO->findText(toqstr(*st))); + *it = ""; + } + } + } else if (prefixIs(*it, "float")) { + if (prefixIs(*it, "float=")) + dialog_->placementLE->setText(toqstr(it->substr(6))); + else + dialog_->floatCB->setChecked(true); + *it = ""; + } else if (prefixIs(*it, "floatplacement=")) { + dialog_->placementLE->setText(toqstr(it->substr(15))); + *it = ""; + } else if (prefixIs(*it, "numbers=")) { + if (contains(*it, "left") != string::npos) + dialog_->numberLeftCB->setChecked(true); + else if (contains(*it, "right") != string::npos) + dialog_->numberRightCB->setChecked(true); + *it = ""; + } else if (prefixIs(*it, "stepnumber=")) { + dialog_->numberStepLE->setText(toqstr(it->substr(11))); + *it = ""; + } else if (prefixIs(*it, "numberstyle=")) { + for (vector<string>::const_iterator st = fontsizes.begin(); + st != fontsizes.end(); ++st) { + if (*it == "numberstyle=\\" + *st) { + dialog_->numberFontSizeCO->setCurrentIndex( + dialog_->numberFontSizeCO->findText(toqstr(*st))); + *it = ""; + } + } + } else if (prefixIs(*it, "firstline=")) { + dialog_->firstlineLE->setText(toqstr(it->substr(10))); + *it = ""; + } else if (prefixIs(*it, "lastline=")) { + dialog_->lastlineLE->setText(toqstr(it->substr(9))); + *it = ""; + } else if (prefixIs(*it, "basicstyle=")) { + string style; + string size; + for (vector<string>::const_iterator st = fontstyles.begin(); + st != fontstyles.end(); ++st) + if (contains(*it, "\\" + *st)) { + style = "\\" + *st; + break; + } + for (vector<string>::const_iterator st = fontsizes.begin(); + st != fontsizes.end(); ++st) + if (contains(*it, "\\" + *st)) { + size = "\\" + *st; + break; + } + if (it->substr(11) == style + size || it->substr(11) == size + style) { + if (!style.empty()) + dialog_->fontstyleCO->setCurrentIndex( + dialog_->fontstyleCO->findText(toqstr(style.substr(1)))); + if (!size.empty()) + dialog_->fontsizeCO->setCurrentIndex( + dialog_->fontsizeCO->findText(toqstr(size.substr(1)))); + *it = ""; + } + } else if (prefixIs(*it, "breaklines=")) { + dialog_->breaklinesCB->setChecked(prefixIs(*it, "true") != string::npos); + *it = ""; + } else if (prefixIs(*it, "showspaces=")) { + dialog_->spaceCB->setChecked(prefixIs(*it, "true") != string::npos); + *it = ""; + } else if (prefixIs(*it, "extendedchars=")) { + dialog_->extendedcharsCB->setChecked(prefixIs(*it, "true") != string::npos); + *it = ""; + } else if (prefixIs(*it, "caption=")) { + string cap = it->substr(8); + if ((cap[0] == '{' && cap[cap.size()-1] == '}') || + (cap[0] == '"' && cap[cap.size()-1] == '"') ) + dialog_->captionLE->setText(toqstr(cap.substr(1, cap.size()-2))); + else + dialog_->captionLE->setText(toqstr(cap)); + *it = ""; + } else if (prefixIs(*it, "label=")) { + string lbl = it->substr(6); + if ((lbl[0] == '{' && lbl[lbl.size()-1] == '}') || + (lbl[0] == '"' && lbl[lbl.size()-1] == '"') ) + dialog_->labelLE->setText(toqstr(lbl.substr(1, lbl.size()-2))); + else + dialog_->labelLE->setText(toqstr(lbl)); + *it = ""; + } + } + string extra = getStringFromVector(pars); + dialog_->listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams())); }