From: Bo Peng Date: Sun, 13 May 2007 04:06:37 +0000 (+0000) Subject: InsetListings: Enhanced listings dialog, more than 10 widgets are added to handle... X-Git-Tag: 1.6.10~9805 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0bbdc3ffeb4dea7b99f08338afc361df6ec8f125;p=features.git InsetListings: Enhanced listings dialog, more than 10 widgets are added to handle common listings parameters. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18282 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/QListings.cpp b/src/frontends/qt4/QListings.cpp index 55ec960713..66cc323557 100644 --- a/src/frontends/qt4/QListings.cpp +++ b/src/frontends/qt4/QListings.cpp @@ -23,9 +23,16 @@ #include #include #include +#include +#include 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 @@ namespace frontend { ///////////////////////////////////////////////////////////////////// +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 @@ QListingsDialog::QListingsDialog(QListings * form) 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,76 @@ void QListingsDialog::change_adaptor() } +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", ""); + if (!placement.empty()) + par.addParam("floatplacement", placement); + 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"); @@ -113,20 +214,159 @@ void QListings::apply() { 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 const languages = + getVectorFromString(allowed_languages, "\n"); + vector const fontstyles = + getVectorFromString(allowed_fontstyles, "\n"); + vector const fontsizes = + getVectorFromString(allowed_fontsizes, "\n"); + + dialog_->languageCO->clear(); + for (vector::const_iterator it = languages.begin(); + it != languages.end(); ++it) { + dialog_->languageCO->addItem(toqstr(*it)); + } + dialog_->fontstyleCO->clear(); + dialog_->fontstyleCO->setEditable(false); + for (vector::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::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 pars = getVectorFromString(params.separatedParams(), "\n"); + // process each of them + for (vector::iterator it = pars.begin(); + it != pars.end(); ++it) { + if (prefixIs(*it, "language=")) { + for (vector::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::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::const_iterator st = fontstyles.begin(); + st != fontstyles.end(); ++st) + if (contains(*it, "\\" + *st)) { + style = "\\" + *st; + break; + } + for (vector::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 = ""; + } + } + // parameters that can be handled by widgets are cleared + // the rest is put to the extra edit box. + string extra = getStringFromVector(pars); + dialog_->listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams())); } diff --git a/src/frontends/qt4/QListings.h b/src/frontends/qt4/QListings.h index 6d0edfcc1b..e3a0966f18 100644 --- a/src/frontends/qt4/QListings.h +++ b/src/frontends/qt4/QListings.h @@ -27,6 +27,8 @@ class QListingsDialog : public QDialog, public Ui::QListingsUi { 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 diff --git a/src/frontends/qt4/ui/ListingsUi.ui b/src/frontends/qt4/ui/ListingsUi.ui index 6a9a36477a..584e49b829 100644 --- a/src/frontends/qt4/ui/ListingsUi.ui +++ b/src/frontends/qt4/ui/ListingsUi.ui @@ -8,8 +8,8 @@ 0 0 - 239 - 382 + 548 + 462 @@ -26,73 +26,758 @@ 6 - - - Inline listing - - - - - - - - 7 - 7 - 0 - 0 - + + + 0 - - Parameters + + 6 - - - 9 - - - 6 - - - - - - 7 - 0 - 0 - 0 - + + + + 0 + + + 6 + + + + + Language + + + + 9 + + + 6 + + + + + + + + + + + Placement + + + + 9 + + + 6 + + + + + Inline listing + + + + + + + Float + + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 0 + + + 6 + + + + + Placement + + + false + + + captionLE + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 16 + 20 + + + + + + + + Number style + + + + 9 - - - 16777215 - 50 - + + 6 - - 0 + + + + 0 + + + 6 + + + + + enable for numbers on the leftside + + + &Left + + + false + + + false + + + + + + + enable for numbers on the right side + + + &Right + + + + + + + + + 0 + + + 6 + + + + + File name of image + + + Step + + + false + + + numberStepLE + + + + + + + Differenz between two numbered lines + + + + + + Qt::AlignLeading + + + + + + + + + 0 + + + 6 + + + + + Font size + + + false + + + numberFontSizeCO + + + + + + + Choose the Font Size + + + true + + + true + + + false + + + + + + + + + Qt::Vertical + + + + 142 + 31 + + + + + + + + 0 + + + 6 + + + + + First line + + + false + + + numberFontSizeCO + + + + + + + Differenz between two numbered lines + + + + + + Qt::AlignLeading + + + + + + + + + 0 + + + 6 + + + + + Last line + + + false + + + numberFontSizeCO + + + + + + + Differenz between two numbered lines + + + + + + Qt::AlignLeading + + + + + + + + + Qt::Vertical + + + + 142 + 31 + + + + + + + + + + + Qt::Horizontal + + + + 16 + 20 + + + + + + + + + 10 + + + + Style + + + + 9 - - false + + 6 - - QFrame::NoFrame + + + + Basic style + + + + + + + 0 + + + 6 + + + + + Font size + + + false + + + fontsizeCO + + + + + + + Choose the Font Size + + + true + + + true + + + false + + + + + + + + + 0 + + + 6 + + + + + Font style + + + false + + + fontstyleCO + + + + + + + Choose the Font Style + + + true + + + true + + + false + + + + + + + + + Qt::Vertical + + + + 158 + 21 + + + + + + + + Breaking lines longer than the linewidth + + + &Break long lines + + + 276824130 + + + + + + + Insert a special symbol for a space + + + &Space as Symbol + + + 276824147 + + + + + + + true + + + Use extended character table + + + &Extended Chars + + + 276824133 + + + + + + + Qt::Vertical + + + + 158 + 21 + + + + + + + + + + + + + 0 + + + 6 + + + + + Display + + + + 9 - - QFrame::Plain + + 6 - - 0 + + + + &Caption + + + false + + + captionLE + + + + + + + 0 + + + 6 + + + + + + 150 + 0 + + + + A caption for the List of Listings + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + &Label + + + false + + + labelLE + + + + + + + 0 + + + 6 + + + + + + 150 + 0 + + + + A Label for the caption + + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 21 + + + + + + + + + + + Qt::Horizontal + + + + 16 + 20 + + + + + + + + + 7 + 7 + 0 + 0 + + + + More Parameters + + + + 9 - - false + + 6 - - - - - - - + + + + Qt::Horizontal + + + + + 16777215 + 16777215 + + + + 0 + + + false + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + false + + + + + + + + + @@ -142,7 +827,23 @@ okPB closePB + languageCO inlineCB + floatCB + placementLE + numberLeftCB + numberRightCB + numberStepLE + numberFontSizeCO + firstlineLE + lastlineLE + fontsizeCO + fontstyleCO + breaklinesCB + spaceCB + extendedcharsCB + captionLE + labelLE listingsTB listingsED