]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiListings.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiListings.cpp
index fbd6ac373a07db17e64b24fdb247390f390757bb..9bb8f05dba0cef6f8f7df61ee45ec5722ff725e4 100644 (file)
@@ -4,7 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Bo Peng
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 #include "GuiListings.h"
 
 #include "qt_helpers.h"
+
 #include "FuncRequest.h"
+
 #include "insets/InsetListings.h"
 #include "insets/InsetListingsParams.h"
-#include "debug.h"
 
+#include "support/convert.h"
+#include "support/debug.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
 #include <QLineEdit>
-#include <QCloseEvent>
 #include <QPushButton>
 #include <QValidator>
 #include <QRegExpValidator>
 
-
-using std::string;
-using std::vector;
-using lyx::support::findToken;
-using lyx::support::getVectorFromString;
-using lyx::support::getStringFromVector;
-using lyx::support::prefixIs;
-using lyx::support::suffixIs;
-using lyx::support::contains;
-
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
@@ -166,10 +161,9 @@ char const * font_styles_gui[] =
 
 
 GuiListings::GuiListings(GuiView & lv)
-       : GuiDialog(lv, "listings")
+       : GuiDialog(lv, "listings", qt_("Program Listing Settings"))
 {
        setupUi(this);
-       setViewTitle(_("Program Listing Settings"));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
        connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
@@ -205,17 +199,19 @@ GuiListings::GuiListings(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(spaceInStringCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
+       connect(tabsizeSB, SIGNAL(valueChanged(int)),
+               this, SLOT(change_adaptor()));
        connect(extendedcharsCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
        connect(listingsED,  SIGNAL(textChanged()),
                this, SLOT(change_adaptor()));
        connect(listingsED,  SIGNAL(textChanged()),
-               this, SLOT(set_listings_msg()));
+               this, SLOT(setListingsMsg()));
        connect(bypassCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
        connect(bypassCB, SIGNAL(clicked()),
-               this, SLOT(set_listings_msg()));
+               this, SLOT(setListingsMsg()));
 
        for (int n = 0; languages[n][0]; ++n)
                languageCO->addItem(qt_(languages_gui[n]));
@@ -235,6 +231,7 @@ GuiListings::GuiListings(GuiView & lv)
        lastlineLE->setValidator(new QIntValidator(0, 1000000, this));
        placementLE->setValidator(new QRegExpValidator(QRegExp("[\\*tbph]*"), this));
 
+       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
        bc().setOK(okPB);
        bc().setApply(applyPB);
        bc().setCancel(closePB);
@@ -246,13 +243,6 @@ GuiListings::GuiListings(GuiView & lv)
 }
 
 
-void GuiListings::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       e->accept();
-}
-
-
 void GuiListings::change_adaptor()
 {
        changed();
@@ -261,7 +251,7 @@ void GuiListings::change_adaptor()
 
 string GuiListings::construct_params()
 {
-       string language = languages[languageCO->currentIndex()];
+       string language = languages[qMax(0, languageCO->currentIndex())];
        string dialect;
        string const dialect_gui = fromqstr(dialectCO->currentText());
        if (dialectCO->currentIndex() > 0) {
@@ -281,7 +271,7 @@ string GuiListings::construct_params()
                placement = fromqstr(placementLE->text());
 
        string numberSide;
-       switch (numberSideCO->currentIndex()) {
+       switch (qMax(0, numberSideCO->currentIndex())) {
        case 0:
                numberSide = "none";
                break;
@@ -296,12 +286,12 @@ string GuiListings::construct_params()
                break;
        }
        string stepnumber = fromqstr(numberStepLE->text());
-       string numberfontsize = font_sizes[numberFontSizeCO->currentIndex()];
+       string numberfontsize = font_sizes[qMax(0, numberFontSizeCO->currentIndex())];
        string firstline = fromqstr(firstlineLE->text());
        string lastline = fromqstr(lastlineLE->text());
 
-       string fontsize = font_sizes[fontsizeCO->currentIndex()];
-       string fontstyle = font_styles[fontstyleCO->currentIndex()];
+       string fontsize = font_sizes[qMax(0, fontsizeCO->currentIndex())];
+       string fontstyle = font_styles[qMax(0, fontstyleCO->currentIndex())];
        string basicstyle;
        if (fontsize != "default")
                basicstyle = "\\" + fontsize;
@@ -309,6 +299,7 @@ string GuiListings::construct_params()
                basicstyle += "\\" + fontstyle;
        bool breakline = breaklinesCB->isChecked();
        bool space = spaceCB->isChecked();
+       int tabsize = tabsizeSB->value();
        bool spaceInString = spaceInStringCB->isChecked();
        bool extendedchars = extendedcharsCB->isChecked();
        string extra = fromqstr(listingsED->toPlainText());
@@ -344,6 +335,8 @@ string GuiListings::construct_params()
                par.addParam("showspaces", "true");
        if (!spaceInString)
                par.addParam("showstringspaces", "false");
+       if (tabsize != 8)
+               par.addParam("tabsize", convert<string>(tabsize));
        if (extendedchars)
                par.addParam("extendedchars", "true");
        par.addParams(extra);
@@ -370,7 +363,7 @@ docstring GuiListings::validate_listings_params()
 }
 
 
-void GuiListings::set_listings_msg()
+void GuiListings::setListingsMsg()
 {
        static bool isOK = true;
        docstring msg = validate_listings_params();
@@ -441,7 +434,7 @@ void GuiListings::applyView()
 }
 
 
-static string plainParam(std::string const & par)
+static string plainParam(string const & par)
 {
        // remove enclosing braces
        if (prefixIs(par, "{") && suffixIs(par, "}"))
@@ -469,6 +462,7 @@ void GuiListings::updateContents()
        breaklinesCB->setChecked(false);
        spaceCB->setChecked(false);
        spaceInStringCB->setChecked(true);
+       tabsizeSB->setValue(8);
        extendedcharsCB->setChecked(false);
 
        // set values from param string
@@ -489,11 +483,12 @@ void GuiListings::updateContents()
                        string dialect;
                        bool in_gui = false;
                        if (prefixIs(arg, "[") && contains(arg, "]")) {
-                               string::size_type end_dialect = arg.find("]");
+                               size_t end_dialect = arg.find("]");
                                dialect = arg.substr(1, end_dialect - 1);
                                language = arg.substr(end_dialect + 1);
-                       } else
+                       } else {
                                language = arg;
+                       }
                        int n = findToken(languages, language);
                        if (n >= 0) {
                                languageCO->setCurrentIndex(n);
@@ -595,6 +590,9 @@ void GuiListings::updateContents()
                } else if (prefixIs(*it, "showstringspaces=")) {
                        spaceInStringCB->setChecked(contains(*it, "true"));
                        *it = "";
+               } else if (prefixIs(*it, "tabsize=")) {
+                       tabsizeSB->setValue(convert<int>(plainParam(it->substr(8))));
+                       *it = "";
                } else if (prefixIs(*it, "extendedchars=")) {
                        extendedcharsCB->setChecked(contains(*it, "true"));
                        *it = "";
@@ -618,7 +616,7 @@ bool GuiListings::isValid()
 
 bool GuiListings::initialiseParams(string const & data)
 {
-       InsetListingsMailer::string2params(data, params_);
+       InsetListings::string2params(data, params_);
        return true;
 }
 
@@ -631,7 +629,7 @@ void GuiListings::clearParams()
 
 void GuiListings::dispatchParams()
 {
-       string const lfun = InsetListingsMailer::params2string(params_);
+       string const lfun = InsetListings::params2string(params_);
        dispatch(FuncRequest(getLfun(), lfun));
 }
 
@@ -649,4 +647,4 @@ Dialog * createGuiListings(GuiView & lv) { return new GuiListings(lv); }
 } // namespace lyx
 
 
-#include "GuiListings_moc.cpp"
+#include "moc_GuiListings.cpp"