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
+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
}
-Kernel::DocTypes Kernel::docType() const
+Kernel::DocType Kernel::docType() const
{
if (buffer().isLatex())
return LATEX;
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.
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
#include "gettext.h"
+#include <qapplication.h>
#include <qmessagebox.h>
#include <qlabel.h>
#include <qlineedit.h>
{
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)
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));
+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.
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.
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
#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)
#include "floatplacement.h"
#include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
#include "panelstack.h"
#include "qt_helpers.h"
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)
{
#include "QExternalDialog.h"
#include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
#include "qt_helpers.h"
#include "QExternal.h"
#include <qfiledialog.h>
#include <qtextview.h>
#include <qlineedit.h>
-#include <qvalidator.h>
+
using lyx::support::float_equal;
using lyx::support::isStrDbl;
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)
#include "QGraphics.h"
#include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
#include "qt_helpers.h"
#include "debug.h"
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)
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;
}
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;
}
#include "QTabularDialog.h"
#include "QTabular.h"
-#include "lengthvalidator.h"
+#include "validators.h"
#include "qt_helpers.h"
#include "controllers/ControlTabular.h"
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)
#include "QVSpace.h"
#include "lengthcombo.h"
-#include "lengthvalidator.h"
+#include "validators.h"
#include "qt_helpers.h"
#include <qcombobox.h>
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)
+++ /dev/null
-/**
- * \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;
-}
+++ /dev/null
-// -*- 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
--- /dev/null
+/**
+ * \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);
+}
--- /dev/null
+// -*- 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
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 {