]> git.lyx.org Git - features.git/commitdiff
Make the Qt Alert boxes recognize their parent.
authorAngus Leeming <leeming@lyx.org>
Thu, 12 May 2005 22:37:43 +0000 (22:37 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 12 May 2005 22:37:43 +0000 (22:37 +0000)
Lots of gratuitous changes that should not alter Lyx's behaviour.

**************************************************************************
You're all going to get failure on link. Please "rm -f lengthvalidator.*".
**************************************************************************

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9940 a592a061-630c-0410-9148-cb99ea01b6c8

19 files changed:
po/POTFILES.in
src/frontends/controllers/ChangeLog
src/frontends/controllers/Kernel.C
src/frontends/controllers/Kernel.h
src/frontends/qt2/Alert_pimpl.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/Makefile.dialogs
src/frontends/qt2/QBoxDialog.C
src/frontends/qt2/QDocumentDialog.C
src/frontends/qt2/QExternalDialog.C
src/frontends/qt2/QGraphicsDialog.C
src/frontends/qt2/QRef.C
src/frontends/qt2/QTabularDialog.C
src/frontends/qt2/QVSpaceDialog.C
src/frontends/qt2/lengthvalidator.C [deleted file]
src/frontends/qt2/lengthvalidator.h [deleted file]
src/frontends/qt2/validators.C [new file with mode: 0644]
src/frontends/qt2/validators.h [new file with mode: 0644]
src/frontends/xforms/FormRef.C

index 162e37752bcc4b351c15ad80701bfcefa1f3a602..081a5307189f5a88051cbd7152dd6cf6b7fe2c19 100644 (file)
@@ -107,6 +107,7 @@ src/frontends/qt2/QWrap.C
 src/frontends/qt2/Qt2BC.h
 src/frontends/qt2/QtView.C
 src/frontends/qt2/floatplacement.C
+src/frontends/qt2/validators.C
 src/frontends/xforms/Alert_pimpl.C
 src/frontends/xforms/ColorHandler.C
 src/frontends/xforms/Dialogs.C
index c0308b48b83eb1d0b6bc14b8d2b78f4bfbbde238..ae17a736fa5efaeed6ae65dc8250e587908cd0d6 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-08  Angus Leeming  <leeming@lyx.org>
+
+       * Kernel.h (KernelDocType): wrapper class for the Kernel::DocTypes
+       enum.
+
 2005-05-07  Michael Schmitt  <michael.schmitt@teststep.org>
 
        * ControlRef.C: rename LFUN_REF_GOTO to LFUN_LABEL_GOTO
index 327ede82f3c03e221284264af98aea820eb0602e..b4a0e57c1fc43a198f7ae7f6027826b400e11e6b 100644 (file)
@@ -69,7 +69,7 @@ string const Kernel::bufferFilepath() const
 }
 
 
-Kernel::DocTypes Kernel::docType() const
+Kernel::DocType Kernel::docType() const
 {
        if (buffer().isLatex())
                return LATEX;
index 1bc7461f89e60d0a5fff9b4747defc181c380a03..f046c7f1509785478a4402783f9f22f2703a23f1 100644 (file)
@@ -64,18 +64,18 @@ public:
        std::string const bufferFilepath() const;
        //@}
 
-       /** \enum DocTypes used to flag the different kinds of buffer
+       /** \enum DocType used to flag the different kinds of buffer
         *  without making the kernel header files available to the
         *  dialog's Controller or View.
         */
-       enum DocTypes {
+       enum DocType {
                LATEX,
                LITERATE,
                LINUXDOC,
                DOCBOOK
        };
        /// The type of the current buffer.
-       DocTypes docType() const;
+       DocType docType() const;
 
        /** A request that the GUI be redrawn,
         *  e.g. because the colors have been remapped.
@@ -101,6 +101,19 @@ private:
        LyXView & lyxview_;
 };
 
+
+/** \c KernelDocType is a wrapper for Kernel::DocType.
+ *  It can be forward-declared and passed as a function argument without
+ *  having to expose Kernel.h.
+ */
+class KernelDocType {
+public:
+       KernelDocType(Kernel::DocType val) : val_(val) {}
+       operator Kernel::DocType() const { return val_; }
+private:
+       Kernel::DocType val_;
+};
+
 } // namespace frontend
 } // namespace lyx
 
index 10197ea63fee9e9234c39059b18e4c996956cc5b..3dadee0320995872bd754a449c962d22744e27c1 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "gettext.h"
 
+#include <qapplication.h>
 #include <qmessagebox.h>
 #include <qlabel.h>
 #include <qlineedit.h>
@@ -37,9 +38,16 @@ int prompt_pimpl(string const & tit, string const & question,
 {
        string const title = bformat(_("LyX: %1$s"), tit);
 
-       int res = QMessageBox::information(0, toqstr(title), toqstr(formatted(question)),
-               toqstr(b1), toqstr(b2), b3.empty() ? QString::null : toqstr(b3),
-               default_button, cancel_button);
+       QWidget * const parent = qApp->focusWidget() ?
+               qApp->focusWidget() : qApp->mainWidget();
+
+       int res = QMessageBox::information(parent,
+                                          toqstr(title),
+                                          toqstr(formatted(question)),
+                                          toqstr(b1),
+                                          toqstr(b2),
+                                          b3.empty() ? QString::null : toqstr(b3),
+                                          default_button, cancel_button);
 
        // Qt bug: can return -1 on cancel or WM close, despite the docs.
        if (res == -1)
@@ -50,30 +58,48 @@ int prompt_pimpl(string const & tit, string const & question,
 
 void warning_pimpl(string const & tit, string const & message)
 {
+       QWidget * const parent = qApp->focusWidget() ?
+               qApp->focusWidget() : qApp->mainWidget();
+
        string const title = bformat(_("LyX: %1$s"), tit);
-       QMessageBox::warning(0, toqstr(title), toqstr(formatted(message)));
+       QMessageBox::warning(parent,
+                            toqstr(title),
+                            toqstr(formatted(message)));
 }
 
 
 void error_pimpl(string const & tit, string const & message)
 {
+       QWidget * const parent = qApp->focusWidget() ?
+               qApp->focusWidget() : qApp->mainWidget();
+
        string const title = bformat(_("LyX: %1$s"), tit);
-       QMessageBox::critical(0, toqstr(title), toqstr(formatted(message)));
+       QMessageBox::critical(parent,
+                             toqstr(title),
+                             toqstr(formatted(message)));
 }
 
 
 void information_pimpl(string const & tit, string const & message)
 {
+       QWidget * const parent = qApp->focusWidget() ?
+               qApp->focusWidget() : qApp->mainWidget();
+
        string const title = bformat(_("LyX: %1$s"), tit);
-       QMessageBox::information(0, toqstr(title), toqstr(formatted(message)));
+       QMessageBox::information(parent,
+                                toqstr(title),
+                                toqstr(formatted(message)));
 }
 
 
 pair<bool, string> const
 askForText_pimpl(string const & msg, string const & dflt)
 {
+       QWidget * const parent = qApp->focusWidget() ?
+               qApp->focusWidget() : qApp->mainWidget();
+
        string const title = bformat(_("LyX: %1$s"), msg);
-       QAskForTextDialog d(0, toqstr(title), true);
+       QAskForTextDialog d(parent, toqstr(title), true);
        // less than ideal !
        d.askLA->setText(toqstr('&' + msg));
        d.askLE->setText(toqstr(dflt));
index 152374fca5ea76defe3940d1d75979f13d966d4a..4138277ac14ef21ee7217354f3065ce058ccbc68 100644 (file)
@@ -1,3 +1,22 @@
+2005-05-07  Angus Leeming  <leeming@lyx.org>
+
+       * Alert_pimpl.C (prompt_pimpl, warning_pimpl, error_pimpl) 
+       (information_pimpl, askForText_pimpl): make these warning dialogs
+       modal with respect to the calling dialog, rather than with respect
+       to the main window.
+
+       * lengthvalidator.[Ch]: removed.
+       * validators.[Ch]: added.
+       * Makefile.dialogs: remove lengthvalidator.[Ch]. Add validators.[Ch].
+
+       * QBoxDialog.C (unsignedLengthValidator):
+       * QDocumentDialog.C (unsignedLengthValidator):
+       * QExternalDialog.C (unsignedLengthValidator):
+       * QGraphicsDialog.C (unsignedLengthValidator):
+       * QTabularDialog.C (unsignedLengthValidator):
+       * QVSpaceDialog.C (unsignedLengthValidator):
+       removed. Use the version in validators.C.
+
 2005-05-12  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * QLPopupMenu.C (fire): use lyx_gui::sync_events.
@@ -47,7 +66,7 @@
 
 2005-05-02  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
-       * QTabularDialog.C: correcht handling of the LFUN_UNSET_*
+       * QTabularDialog.C: correct handling of the LFUN_UNSET_*
        functions within longtabular.
        
        * ui/QTabularDialogBase.ui: add tooltips to longtabular tab.
index 6fc0c196ccd998d49bf4facdf25ec56adf8dcd25..a0f1bb3d99ee25249c4e415ea056e6b21a09d1d1 100644 (file)
@@ -126,5 +126,5 @@ MOCFILES = \
        QVSpaceDialog.C QVSpaceDialog.h \
        QWrapDialog.C QWrapDialog.h \
        QLToolbar.C QLToolbar.h \
-       lengthvalidator.C lengthvalidator.h \
-       socket_callback.C socket_callback.h
+       socket_callback.C socket_callback.h \
+       validators.C validators.h
index 6cb449572c6cece01d24d9d5bfe2e15bede2c765..6bd909759aa3552961b19efca70e2cf897e0a29a 100644 (file)
@@ -13,7 +13,7 @@
 #include "QBoxDialog.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "QBox.h"
 #include "qt_helpers.h"
 
 namespace lyx {
 namespace frontend {
 
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-       LengthValidator * v = new LengthValidator(ed);
-       v->setBottom(LyXLength());
-       return v;
-}
-
-} // namespace anon
-
-
 QBoxDialog::QBoxDialog(QBox * form)
        : QBoxDialogBase(0, 0, false, 0),
        form_(form)
index daad83f66a7062c2fc5ec0ec6fdf8b45e24d7576..bcb30bad2e559368df2d999e50567a7e8f4fa462 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "floatplacement.h"
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "panelstack.h"
 #include "qt_helpers.h"
 
@@ -48,18 +48,6 @@ namespace lyx {
 namespace frontend {
 
 
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-       LengthValidator * v = new LengthValidator(ed);
-       v->setBottom(LyXLength());
-       return v;
-}
-
-} // namespace anon
-
-
 QDocumentDialog::QDocumentDialog(QDocument * form)
        : QDocumentDialogBase(0, 0, false, 0), form_(form)
 {
index 39f3fa8367a637bf5a5600db5dfa75537ed67618..c951728856514b43e557a2d74be0055e8c8c2952 100644 (file)
@@ -25,7 +25,7 @@
 #include "QExternalDialog.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 #include "QExternal.h"
 
@@ -35,7 +35,7 @@
 #include <qfiledialog.h>
 #include <qtextview.h>
 #include <qlineedit.h>
-#include <qvalidator.h>
+
 
 using lyx::support::float_equal;
 using lyx::support::isStrDbl;
@@ -44,18 +44,6 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-       LengthValidator * v = new LengthValidator(ed);
-       v->setBottom(LyXLength());
-       return v;
-}
-
-} // namespace anon
-
-
 QExternalDialog::QExternalDialog(QExternal * form)
        : QExternalDialogBase(0, 0, false, 0),
          form_(form)
index 09b598ef744ef496e941671ad710b6cc2ff51cb3..efc2c99d33222d73567cbb308e7a0b5d9978f21a 100644 (file)
@@ -15,7 +15,7 @@
 #include "QGraphics.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 
 #include "debug.h"
@@ -33,18 +33,6 @@ namespace lyx {
 namespace frontend {
 
 
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-       LengthValidator * v = new LengthValidator(ed);
-       v->setBottom(LyXLength());
-       return v;
-}
-
-} // namespace anon
-
-
 QGraphicsDialog::QGraphicsDialog(QGraphics * form)
        : QGraphicsDialogBase(0, 0, false, 0),
        form_(form)
index 0093a498228a581caa1459a9bd02aa7109b84f3a..0b6deff123fc0718fa720364e899ba3d2c8388ea 100644 (file)
@@ -116,7 +116,7 @@ void QRef::apply()
 
 bool QRef::nameAllowed()
 {
-       Kernel::DocTypes doc_type = kernel().docType();
+       Kernel::DocType const doc_type = kernel().docType();
        return doc_type != Kernel::LATEX &&
                doc_type != Kernel::LITERATE;
 }
@@ -124,7 +124,7 @@ bool QRef::nameAllowed()
 
 bool QRef::typeAllowed()
 {
-       Kernel::DocTypes doc_type = kernel().docType();
+       Kernel::DocType const doc_type = kernel().docType();
        return doc_type != Kernel::LINUXDOC &&
                doc_type != Kernel::DOCBOOK;
 }
index 9f081b68ad24f85f16dd2d9817c8f1fc334835ef..b1fafff8bb445482170f1a01c5b216fdae43b8c1 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "QTabularDialog.h"
 #include "QTabular.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 
 #include "controllers/ControlTabular.h"
@@ -29,18 +29,6 @@ namespace lyx {
 namespace frontend {
 
 
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-       LengthValidator * v = new LengthValidator(ed);
-       v->setBottom(LyXLength());
-       return v;
-}
-
-} // namespace anon
-
-
 QTabularDialog::QTabularDialog(QTabular * form)
        : QTabularDialogBase(0, 0, false, 0),
        form_(form)
index 39daee67c9a0014588ed198c006324a53a1236c0..ab1feede1c6300f600f46dd2d1723198c83e7117 100644 (file)
@@ -16,7 +16,7 @@
 #include "QVSpace.h"
 
 #include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
 #include "qt_helpers.h"
 
 #include <qcombobox.h>
@@ -29,18 +29,6 @@ namespace lyx {
 namespace frontend {
 
 
-namespace {
-
-LengthValidator * unsignedLengthValidator(QLineEdit * ed)
-{
-       LengthValidator * v = new LengthValidator(ed);
-       v->setBottom(LyXGlueLength());
-       return v;
-}
-
-} // namespace anon
-
-
 QVSpaceDialog::QVSpaceDialog(QVSpace * form)
        : QVSpaceDialogBase(0, 0, false, 0),
        form_(form)
diff --git a/src/frontends/qt2/lengthvalidator.C b/src/frontends/qt2/lengthvalidator.C
deleted file mode 100644 (file)
index c7625b4..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * \file lengthvalidator.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-
-#include <config.h>
-
-#include "lengthvalidator.h"
-#include "qt_helpers.h"
-
-#include "support/lstrings.h"
-
-#include <qwidget.h>
-
-
-using lyx::support::isStrDbl;
-using std::string;
-
-
-LengthValidator::LengthValidator(QWidget * parent, const char * name)
-       : QValidator(parent, name),
-         no_bottom_(true), glue_length_(false)
-{}
-
-
-QValidator::State LengthValidator::validate(QString & qtext, int &) const
-{
-       string const text = fromqstr(qtext);
-       if (text.empty() || isStrDbl(text))
-               return QValidator::Acceptable;
-
-       if (glue_length_) {
-               LyXGlueLength gl;
-               return (isValidGlueLength(text, &gl)) ?
-                       QValidator::Acceptable : QValidator::Intermediate;
-               }
-
-       LyXLength l;
-       bool const valid_length = isValidLength(text, &l);
-       if (!valid_length)
-               return QValidator::Intermediate;
-
-       if (no_bottom_)
-               return QValidator::Acceptable;
-
-       return b_.inPixels(100) <= l.inPixels(100) ?
-               QValidator::Acceptable : QValidator::Intermediate;
-}
-
-
-void LengthValidator::setBottom(LyXLength const & b)
-{
-       b_ = b;
-       no_bottom_ = false;
-}
-
-
-void LengthValidator::setBottom(LyXGlueLength const & g)
-{
-       g_ = g;
-       no_bottom_ = false;
-       glue_length_ = true;
-}
diff --git a/src/frontends/qt2/lengthvalidator.h b/src/frontends/qt2/lengthvalidator.h
deleted file mode 100644 (file)
index 9f60b98..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// -*- C++ -*-
-/**
- * \file lengthvalidator.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LENGTHVALIDATOR_H
-#define LENGTHVALIDATOR_H
-
-#include "lyxlength.h"
-#include "lyxgluelength.h"
-#include <qvalidator.h>
-
-class QWidget;
-
-
-class LengthValidator : public QValidator
-{
-       Q_OBJECT
-public:
-       LengthValidator(QWidget * parent, const char *name = 0);
-
-       QValidator::State validate(QString &, int &) const;
-
-       void setBottom(LyXLength const &);
-       void setBottom(LyXGlueLength const &);
-       LyXLength bottom() const { return b_; }
-
-private:
-#if defined(Q_DISABLE_COPY)
-       LengthValidator( const LengthValidator & );
-       LengthValidator& operator=( const LengthValidator & );
-#endif
-
-       LyXLength b_;
-       LyXGlueLength g_;
-       bool no_bottom_;
-       bool glue_length_;
-};
-
-# endif // NOT LENGTHVALIDATOR_H
diff --git a/src/frontends/qt2/validators.C b/src/frontends/qt2/validators.C
new file mode 100644 (file)
index 0000000..87c4775
--- /dev/null
@@ -0,0 +1,169 @@
+/**
+ * \file validators.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+
+#include <config.h>
+
+#include "validators.h"
+#include "qt_helpers.h"
+
+#include "gettext.h"
+#include "lyxrc.h"
+
+#include "frontends/Alert.h"
+
+#include "frontends/controllers/Dialog.h"
+
+#include "support/lstrings.h"
+#include "support/std_ostream.h"
+
+#include <qlineedit.h>
+#include <qwidget.h>
+
+#include <sstream>
+
+using lyx::support::isStrDbl;
+using std::string;
+
+
+LengthValidator::LengthValidator(QWidget * parent, const char * name)
+       : QValidator(parent, name),
+         no_bottom_(true), glue_length_(false)
+{}
+
+
+QValidator::State LengthValidator::validate(QString & qtext, int &) const
+{
+       string const text = fromqstr(qtext);
+       if (text.empty() || isStrDbl(text))
+               return QValidator::Acceptable;
+
+       if (glue_length_) {
+               LyXGlueLength gl;
+               return (isValidGlueLength(text, &gl)) ?
+                       QValidator::Acceptable : QValidator::Intermediate;
+               }
+
+       LyXLength l;
+       bool const valid_length = isValidLength(text, &l);
+       if (!valid_length)
+               return QValidator::Intermediate;
+
+       if (no_bottom_)
+               return QValidator::Acceptable;
+
+       return b_.inPixels(100) <= l.inPixels(100) ?
+               QValidator::Acceptable : QValidator::Intermediate;
+}
+
+
+void LengthValidator::setBottom(LyXLength const & b)
+{
+       b_ = b;
+       no_bottom_ = false;
+}
+
+
+void LengthValidator::setBottom(LyXGlueLength const & g)
+{
+       g_ = g;
+       no_bottom_ = false;
+       glue_length_ = true;
+}
+
+
+LengthValidator * unsignedLengthValidator(QLineEdit * ed)
+{
+       LengthValidator * v = new LengthValidator(ed);
+       v->setBottom(LyXLength());
+       return v;
+}
+
+
+PathValidator::PathValidator(bool acceptable_if_empty,
+                            QWidget * parent, const char * name)
+       : QValidator(parent, name),
+         acceptable_if_empty_(acceptable_if_empty),
+         latex_doc_(false),
+         tex_allows_spaces_(false)
+{}
+
+
+namespace {
+
+string const printable_list(string const & invalid_chars)
+{
+       std::ostringstream ss;
+       string::const_iterator const begin = invalid_chars.begin();
+       string::const_iterator const end = invalid_chars.end();
+       string::const_iterator it = begin;
+
+       for (; it != end; ++it) {
+               if (it != begin)
+                       ss << ", ";
+               if (*it == ' ')
+                       ss << _("space");
+               else
+                       ss << *it;
+       }
+
+       return ss.str();
+}
+
+} // namespace anon
+
+
+QValidator::State PathValidator::validate(QString & qtext, int &) const
+{
+       if (!latex_doc_)
+               return QValidator::Acceptable;
+
+       string const text = lyx::support::trim(fromqstr(qtext));
+       if (text.empty())
+               return  acceptable_if_empty_ ?
+                       QValidator::Acceptable : QValidator::Intermediate;
+
+       string invalid_chars("#$%{}()[]:\"^");
+       if (!tex_allows_spaces_)
+               invalid_chars += ' ';
+
+       if (text.find_first_of(invalid_chars) != string::npos) {
+
+               static int counter = 0;
+               if (counter == 0) {
+                       Alert::error(_("Invalid filename"),
+                                    _("LyX does not provide LateX support for file names containing any of these characters:\n") +
+                                    printable_list(invalid_chars));
+               }
+               ++counter;
+               return QValidator::Intermediate;
+       }
+
+       return QValidator::Acceptable;
+}
+
+
+void PathValidator::setChecker(lyx::frontend::KernelDocType const & type,
+                              LyXRC const & lyxrc)
+{
+       latex_doc_ = type == lyx::frontend::Kernel::LATEX;
+       tex_allows_spaces_ = lyxrc.tex_allows_spaces;
+}
+
+
+PathValidator * getPathValidator(QLineEdit * ed)
+{
+       if (!ed)
+               return 0;
+       QValidator * validator = const_cast<QValidator *>(ed->validator());
+       if (!validator)
+               return 0;
+       return dynamic_cast<PathValidator *>(validator);
+}
diff --git a/src/frontends/qt2/validators.h b/src/frontends/qt2/validators.h
new file mode 100644 (file)
index 0000000..56bcc77
--- /dev/null
@@ -0,0 +1,132 @@
+// -*- C++ -*-
+/**
+ * \file validators.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * Validators are used to decide upon the legality of some input action.
+ * For example, a "line edit" widget might be used to input a "glue length".
+ * The correct syntax for such a length is "2em + 0.5em". The LengthValidator
+ * below will report whether the input text conforms to this syntax.
+ *
+ * This information is used in LyX primarily to give the user some
+ * feedback on the validity of the input data using the "checked_widget"
+ * concept. For example, if the data is invalid then the label of
+ * a "line edit" widget is changed in colour and the dialog's "Ok"
+ * and "Apply" buttons are disabled. See checked_widgets.[Ch] for
+ * further details.
+ */
+
+#ifndef VALIDATORS_H
+#define VALIDATORS_H
+
+#include "lyxlength.h"
+#include "lyxgluelength.h"
+#include <qvalidator.h>
+
+class QWidget;
+class QLineEdit;
+
+
+/** A class to ascertain whether the data passed to the @c validate()
+ *  member function can be interpretted as a LyXGlueLength.
+ */
+class LengthValidator : public QValidator
+{
+       Q_OBJECT
+public:
+       /// Define a validator for widget @c parent.
+       LengthValidator(QWidget * parent, const char *name = 0);
+
+       /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
+        *  If not, returns QValidator::Intermediate.
+        */
+       QValidator::State validate(QString & data, int &) const;
+
+       /** @name Bottom
+        *  Set and retrieve the minimum allowed LyXLength value.
+        */
+       //@{
+       void setBottom(LyXLength const &);
+       void setBottom(LyXGlueLength const &);
+       LyXLength bottom() const { return b_; }
+       //@}
+
+private:
+#if defined(Q_DISABLE_COPY)
+       LengthValidator( const LengthValidator & );
+       LengthValidator& operator=( const LengthValidator & );
+#endif
+
+       LyXLength b_;
+       LyXGlueLength g_;
+       bool no_bottom_;
+       bool glue_length_;
+};
+
+
+/// @returns a new @c LengthValidator that does not accept negative lengths.
+LengthValidator * unsignedLengthValidator(QLineEdit *);
+
+
+// Forward declarations
+class LyXRC;
+
+namespace lyx {
+namespace frontend {
+
+class KernelDocType;
+
+} // namespace frontend
+} // namespace lyx
+
+
+/** A class to ascertain whether the data passed to the @c validate()
+ *  member function is a valid file path.
+ *  The test is active only when the path is to be stored in a LaTeX
+ *  file, LaTeX being quite picky about legal names.
+ */
+class PathValidator : public QValidator
+{
+       Q_OBJECT
+public:
+       /** Define a validator for widget @c parent.
+        *  If @c acceptable_if_empty is @c true then an empty path
+        *  is regarded as acceptable.
+        */
+       PathValidator(bool acceptable_if_empty,
+                     QWidget * parent, const char *name = 0);
+
+       /** @returns QValidator::Acceptable if @c data is a valid path.
+        *  If not, returns QValidator::Intermediate.
+        */
+       QValidator::State validate(QString &, int &) const;
+
+       /** Define what checks that @c validate() will perform.
+        *  @param doc_type checks are activated only for @c LATEX docs.
+        *  @param lyxrc contains a @c tex_allows_spaces member that
+        *  is used to define what is legal.
+        */
+       void setChecker(lyx::frontend::KernelDocType const & doc_type,
+                       LyXRC const & lyxrc);
+
+private:
+#if defined(Q_DISABLE_COPY)
+       PathValidator( const PathValidator & );
+       PathValidator& operator=( const PathValidator & );
+#endif
+
+       bool acceptable_if_empty_;
+       bool latex_doc_;
+       bool tex_allows_spaces_;
+};
+
+
+/// @returns the PathValidator attached to the widget, or 0.
+PathValidator * getPathValidator(QLineEdit *);
+
+# endif // NOT VALIDATORS_H
index 70ab49238ffb47de78f6313bfadfbb3559880df0..43dce8a34c297ab86b4d07b328f2890b2f6421ba 100644 (file)
@@ -98,7 +98,7 @@ void FormRef::update()
        switch_go_button();
 
        // Name is irrelevant to LaTeX/Literate documents
-       Kernel::DocTypes doctype = kernel().docType();
+       Kernel::DocType const doctype = kernel().docType();
        if (doctype == Kernel::LATEX || doctype == Kernel::LITERATE) {
                setEnabled(dialog_->input_name, false);
        } else {