]> git.lyx.org Git - features.git/commitdiff
Rename .C ==> .cpp for files in src/frontends/qt4, part two
authorBo Peng <bpeng@lyx.org>
Thu, 26 Apr 2007 03:53:51 +0000 (03:53 +0000)
committerBo Peng <bpeng@lyx.org>
Thu, 26 Apr 2007 03:53:51 +0000 (03:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18015 a592a061-630c-0410-9148-cb99ea01b6c8

188 files changed:
src/frontends/qt4/Action.C [deleted file]
src/frontends/qt4/Action.cpp [new file with mode: 0644]
src/frontends/qt4/Alert_pimpl.C [deleted file]
src/frontends/qt4/Alert_pimpl.cpp [new file with mode: 0644]
src/frontends/qt4/BulletsModule.C [deleted file]
src/frontends/qt4/BulletsModule.cpp [new file with mode: 0644]
src/frontends/qt4/CheckedLineEdit.cpp [new file with mode: 0644]
src/frontends/qt4/CheckedLineEdit.h [new file with mode: 0644]
src/frontends/qt4/ColorCache.C [deleted file]
src/frontends/qt4/ColorCache.cpp [new file with mode: 0644]
src/frontends/qt4/Dialogs.C [deleted file]
src/frontends/qt4/Dialogs.cpp [new file with mode: 0644]
src/frontends/qt4/EmptyTable.cpp [new file with mode: 0644]
src/frontends/qt4/EmptyTable.h [new file with mode: 0644]
src/frontends/qt4/FileDialog.C [deleted file]
src/frontends/qt4/FileDialog.cpp [new file with mode: 0644]
src/frontends/qt4/FileDialog_private.C [deleted file]
src/frontends/qt4/FileDialog_private.h [deleted file]
src/frontends/qt4/FloatPlacement.C [deleted file]
src/frontends/qt4/FloatPlacement.cpp [new file with mode: 0644]
src/frontends/qt4/GuiApplication.C [deleted file]
src/frontends/qt4/GuiApplication.cpp [new file with mode: 0644]
src/frontends/qt4/GuiClipboard.C [deleted file]
src/frontends/qt4/GuiClipboard.cpp [new file with mode: 0644]
src/frontends/qt4/GuiFontLoader.C [deleted file]
src/frontends/qt4/GuiFontLoader.cpp [new file with mode: 0644]
src/frontends/qt4/GuiFontMetrics.C [deleted file]
src/frontends/qt4/GuiFontMetrics.cpp [new file with mode: 0644]
src/frontends/qt4/GuiImplementation.C [deleted file]
src/frontends/qt4/GuiImplementation.cpp [new file with mode: 0644]
src/frontends/qt4/GuiSelection.C [deleted file]
src/frontends/qt4/GuiSelection.cpp [new file with mode: 0644]
src/frontends/qt4/GuiView.C [deleted file]
src/frontends/qt4/GuiView.cpp [new file with mode: 0644]
src/frontends/qt4/GuiWorkArea.C [deleted file]
src/frontends/qt4/GuiWorkArea.cpp [new file with mode: 0644]
src/frontends/qt4/IconPalette.cpp [new file with mode: 0644]
src/frontends/qt4/IconPalette.h [new file with mode: 0644]
src/frontends/qt4/InsertTableWidget.C [deleted file]
src/frontends/qt4/InsertTableWidget.cpp [new file with mode: 0644]
src/frontends/qt4/LengthCombo.cpp [new file with mode: 0644]
src/frontends/qt4/LengthCombo.h [new file with mode: 0644]
src/frontends/qt4/LyXFileDialog.cpp [new file with mode: 0644]
src/frontends/qt4/LyXFileDialog.h [new file with mode: 0644]
src/frontends/qt4/LyXKeySymFactory.C [deleted file]
src/frontends/qt4/LyXKeySymFactory.cpp [new file with mode: 0644]
src/frontends/qt4/PanelStack.cpp [new file with mode: 0644]
src/frontends/qt4/PanelStack.h [new file with mode: 0644]
src/frontends/qt4/QAbout.C [deleted file]
src/frontends/qt4/QAbout.cpp [new file with mode: 0644]
src/frontends/qt4/QBibitem.C [deleted file]
src/frontends/qt4/QBibitem.cpp [new file with mode: 0644]
src/frontends/qt4/QBibtex.C [deleted file]
src/frontends/qt4/QBibtex.cpp [new file with mode: 0644]
src/frontends/qt4/QBox.C [deleted file]
src/frontends/qt4/QBox.cpp [new file with mode: 0644]
src/frontends/qt4/QBranch.C [deleted file]
src/frontends/qt4/QBranch.cpp [new file with mode: 0644]
src/frontends/qt4/QBranches.C [deleted file]
src/frontends/qt4/QBranches.cpp [new file with mode: 0644]
src/frontends/qt4/QChanges.C [deleted file]
src/frontends/qt4/QChanges.cpp [new file with mode: 0644]
src/frontends/qt4/QCharacter.C [deleted file]
src/frontends/qt4/QCharacter.cpp [new file with mode: 0644]
src/frontends/qt4/QCitation.C [deleted file]
src/frontends/qt4/QCitation.cpp [new file with mode: 0644]
src/frontends/qt4/QCitationDialog.C [deleted file]
src/frontends/qt4/QCitationDialog.cpp [new file with mode: 0644]
src/frontends/qt4/QCommandBuffer.C [deleted file]
src/frontends/qt4/QCommandBuffer.cpp [new file with mode: 0644]
src/frontends/qt4/QCommandEdit.C [deleted file]
src/frontends/qt4/QCommandEdit.cpp [new file with mode: 0644]
src/frontends/qt4/QDelimiterDialog.C [deleted file]
src/frontends/qt4/QDelimiterDialog.cpp [new file with mode: 0644]
src/frontends/qt4/QDialogView.C [deleted file]
src/frontends/qt4/QDialogView.cpp [new file with mode: 0644]
src/frontends/qt4/QDocument.C [deleted file]
src/frontends/qt4/QDocument.cpp [new file with mode: 0644]
src/frontends/qt4/QERT.C [deleted file]
src/frontends/qt4/QERT.cpp [new file with mode: 0644]
src/frontends/qt4/QErrorList.C [deleted file]
src/frontends/qt4/QErrorList.cpp [new file with mode: 0644]
src/frontends/qt4/QExternal.C [deleted file]
src/frontends/qt4/QExternal.cpp [new file with mode: 0644]
src/frontends/qt4/QFloat.C [deleted file]
src/frontends/qt4/QFloat.cpp [new file with mode: 0644]
src/frontends/qt4/QFloatDialog.C [deleted file]
src/frontends/qt4/QFloatDialog.cpp [new file with mode: 0644]
src/frontends/qt4/QFontExample.cpp [new file with mode: 0644]
src/frontends/qt4/QFontExample.h [new file with mode: 0644]
src/frontends/qt4/QGraphics.C [deleted file]
src/frontends/qt4/QGraphics.cpp [new file with mode: 0644]
src/frontends/qt4/QGraphicsDialog.C [deleted file]
src/frontends/qt4/QGraphicsDialog.cpp [new file with mode: 0644]
src/frontends/qt4/QInclude.C [deleted file]
src/frontends/qt4/QInclude.cpp [new file with mode: 0644]
src/frontends/qt4/QIndex.C [deleted file]
src/frontends/qt4/QIndex.cpp [new file with mode: 0644]
src/frontends/qt4/QLImage.C [deleted file]
src/frontends/qt4/QLImage.cpp [new file with mode: 0644]
src/frontends/qt4/QLMenubar.C [deleted file]
src/frontends/qt4/QLMenubar.cpp [new file with mode: 0644]
src/frontends/qt4/QLPainter.C [deleted file]
src/frontends/qt4/QLPainter.cpp [new file with mode: 0644]
src/frontends/qt4/QLPopupMenu.C [deleted file]
src/frontends/qt4/QLPopupMenu.cpp [new file with mode: 0644]
src/frontends/qt4/QLPrintDialog.C [deleted file]
src/frontends/qt4/QLPrintDialog.cpp [new file with mode: 0644]
src/frontends/qt4/QLToolbar.C [deleted file]
src/frontends/qt4/QLToolbar.cpp [new file with mode: 0644]
src/frontends/qt4/QLog.C [deleted file]
src/frontends/qt4/QLog.cpp [new file with mode: 0644]
src/frontends/qt4/QLyXKeySym.C [deleted file]
src/frontends/qt4/QLyXKeySym.cpp [new file with mode: 0644]
src/frontends/qt4/QMathMatrixDialog.C [deleted file]
src/frontends/qt4/QMathMatrixDialog.cpp [new file with mode: 0644]
src/frontends/qt4/QNomencl.C [deleted file]
src/frontends/qt4/QNomencl.cpp [new file with mode: 0644]
src/frontends/qt4/QNote.C [deleted file]
src/frontends/qt4/QNote.cpp [new file with mode: 0644]
src/frontends/qt4/QParagraph.C [deleted file]
src/frontends/qt4/QParagraph.cpp [new file with mode: 0644]
src/frontends/qt4/QPrefs.C [deleted file]
src/frontends/qt4/QPrefs.cpp [new file with mode: 0644]
src/frontends/qt4/QPrint.C [deleted file]
src/frontends/qt4/QPrint.cpp [new file with mode: 0644]
src/frontends/qt4/QRef.C [deleted file]
src/frontends/qt4/QRef.cpp [new file with mode: 0644]
src/frontends/qt4/QSearch.C [deleted file]
src/frontends/qt4/QSearch.cpp [new file with mode: 0644]
src/frontends/qt4/QSendto.C [deleted file]
src/frontends/qt4/QSendto.cpp [new file with mode: 0644]
src/frontends/qt4/QSetBorder.cpp [new file with mode: 0644]
src/frontends/qt4/QSetBorder.h [new file with mode: 0644]
src/frontends/qt4/QShowFile.C [deleted file]
src/frontends/qt4/QShowFile.cpp [new file with mode: 0644]
src/frontends/qt4/QSpellchecker.C [deleted file]
src/frontends/qt4/QSpellchecker.cpp [new file with mode: 0644]
src/frontends/qt4/QTabular.C [deleted file]
src/frontends/qt4/QTabular.cpp [new file with mode: 0644]
src/frontends/qt4/QTabularCreate.C [deleted file]
src/frontends/qt4/QTabularCreate.cpp [new file with mode: 0644]
src/frontends/qt4/QTexinfo.C [deleted file]
src/frontends/qt4/QTexinfo.cpp [new file with mode: 0644]
src/frontends/qt4/QThesaurus.C [deleted file]
src/frontends/qt4/QThesaurus.cpp [new file with mode: 0644]
src/frontends/qt4/QToc.C [deleted file]
src/frontends/qt4/QToc.cpp [new file with mode: 0644]
src/frontends/qt4/QURLDialog.C [deleted file]
src/frontends/qt4/QURLDialog.cpp [new file with mode: 0644]
src/frontends/qt4/QVSpace.C [deleted file]
src/frontends/qt4/QVSpace.cpp [new file with mode: 0644]
src/frontends/qt4/QViewSource.C [deleted file]
src/frontends/qt4/QViewSource.cpp [new file with mode: 0644]
src/frontends/qt4/QWrap.C [deleted file]
src/frontends/qt4/QWrap.cpp [new file with mode: 0644]
src/frontends/qt4/Qt2BC.C [deleted file]
src/frontends/qt4/Qt2BC.cpp [new file with mode: 0644]
src/frontends/qt4/TocModel.C [deleted file]
src/frontends/qt4/TocModel.cpp [new file with mode: 0644]
src/frontends/qt4/TocWidget.C [deleted file]
src/frontends/qt4/TocWidget.cpp [new file with mode: 0644]
src/frontends/qt4/UrlView.C [deleted file]
src/frontends/qt4/UrlView.cpp [new file with mode: 0644]
src/frontends/qt4/Validator.cpp [new file with mode: 0644]
src/frontends/qt4/Validator.h [new file with mode: 0644]
src/frontends/qt4/checkedwidgets.C [deleted file]
src/frontends/qt4/checkedwidgets.h [deleted file]
src/frontends/qt4/emptytable.C [deleted file]
src/frontends/qt4/emptytable.h [deleted file]
src/frontends/qt4/iconpalette.C [deleted file]
src/frontends/qt4/iconpalette.h [deleted file]
src/frontends/qt4/lengthcombo.C [deleted file]
src/frontends/qt4/lengthcombo.h [deleted file]
src/frontends/qt4/panelstack.C [deleted file]
src/frontends/qt4/panelstack.h [deleted file]
src/frontends/qt4/qfontexample.C [deleted file]
src/frontends/qt4/qfontexample.h [deleted file]
src/frontends/qt4/qsetborder.C [deleted file]
src/frontends/qt4/qsetborder.h [deleted file]
src/frontends/qt4/qtTimeout.C [deleted file]
src/frontends/qt4/qtTimeout.cpp [new file with mode: 0644]
src/frontends/qt4/qt_helpers.C [deleted file]
src/frontends/qt4/qt_helpers.cpp [new file with mode: 0644]
src/frontends/qt4/socket_callback.C [deleted file]
src/frontends/qt4/socket_callback.cpp [new file with mode: 0644]
src/frontends/qt4/validators.C [deleted file]
src/frontends/qt4/validators.h [deleted file]

diff --git a/src/frontends/qt4/Action.C b/src/frontends/qt4/Action.C
deleted file mode 100644 (file)
index 66d8dc4..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * \file Action.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "Action.h"
-
-#include "GuiView.h"
-#include "qt_helpers.h"
-
-#include "lyx_cb.h"
-#include "lyxfunc.h"
-#include "FuncStatus.h"
-#include "debug.h"
-
-#include "support/lstrings.h"
-
-#include <boost/bind.hpp>
-
-using std::string;
-using std::endl;
-
-namespace lyx {
-namespace frontend {
-
-
-Action::Action(GuiView & lyxView, docstring const & text,
-               FuncRequest const & func, docstring const & tooltip)
-       : QAction(&lyxView), func_(func), lyxView_(lyxView)
-{
-#if QT_VERSION >= 0x040200
-       // only Qt/Mac handles that
-       setMenuRole(NoRole);
-#endif
-       setText(toqstr(text));
-       setToolTip(toqstr(tooltip));
-       setStatusTip(toqstr(tooltip));
-       connect(this, SIGNAL(triggered()), this, SLOT(action()));
-       update();
-}
-
-Action::Action(GuiView & lyxView, string const & icon, docstring const & text,
-               FuncRequest const & func, docstring const & tooltip)
-               : QAction(&lyxView), func_(func), lyxView_(lyxView)
-{
-       setIcon(QPixmap(icon.c_str()));
-       setText(toqstr(text));
-       setToolTip(toqstr(tooltip));
-       setStatusTip(toqstr(tooltip));
-       connect(this, SIGNAL(triggered()), this, SLOT(action()));
-       update();
-}
-
-/*
-void Action::setAction(FuncRequest const & func)
-{
-       func_=func;
-}
-*/
-
-void Action::update()
-{
-       FuncStatus const status = getStatus(func_);
-
-       if (status.onoff(true)) {
-               setCheckable(true);
-               setChecked(true);
-       } else if (status.onoff(false)) {
-               setCheckable(true);
-               setChecked(false);
-       } else {
-               setCheckable(false);
-       }
-
-       setEnabled(status.enabled());
-}
-
-
-void Action::action()
-{
-//     LYXERR(Debug::ACTION) << "calling LyXFunc::dispatch: func_: " << func_ << endl;
-
-       lyxView_.dispatch(func_);
-       triggered(this);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "Action_moc.cpp"
diff --git a/src/frontends/qt4/Action.cpp b/src/frontends/qt4/Action.cpp
new file mode 100644 (file)
index 0000000..66d8dc4
--- /dev/null
@@ -0,0 +1,97 @@
+/**
+ * \file Action.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "Action.h"
+
+#include "GuiView.h"
+#include "qt_helpers.h"
+
+#include "lyx_cb.h"
+#include "lyxfunc.h"
+#include "FuncStatus.h"
+#include "debug.h"
+
+#include "support/lstrings.h"
+
+#include <boost/bind.hpp>
+
+using std::string;
+using std::endl;
+
+namespace lyx {
+namespace frontend {
+
+
+Action::Action(GuiView & lyxView, docstring const & text,
+               FuncRequest const & func, docstring const & tooltip)
+       : QAction(&lyxView), func_(func), lyxView_(lyxView)
+{
+#if QT_VERSION >= 0x040200
+       // only Qt/Mac handles that
+       setMenuRole(NoRole);
+#endif
+       setText(toqstr(text));
+       setToolTip(toqstr(tooltip));
+       setStatusTip(toqstr(tooltip));
+       connect(this, SIGNAL(triggered()), this, SLOT(action()));
+       update();
+}
+
+Action::Action(GuiView & lyxView, string const & icon, docstring const & text,
+               FuncRequest const & func, docstring const & tooltip)
+               : QAction(&lyxView), func_(func), lyxView_(lyxView)
+{
+       setIcon(QPixmap(icon.c_str()));
+       setText(toqstr(text));
+       setToolTip(toqstr(tooltip));
+       setStatusTip(toqstr(tooltip));
+       connect(this, SIGNAL(triggered()), this, SLOT(action()));
+       update();
+}
+
+/*
+void Action::setAction(FuncRequest const & func)
+{
+       func_=func;
+}
+*/
+
+void Action::update()
+{
+       FuncStatus const status = getStatus(func_);
+
+       if (status.onoff(true)) {
+               setCheckable(true);
+               setChecked(true);
+       } else if (status.onoff(false)) {
+               setCheckable(true);
+               setChecked(false);
+       } else {
+               setCheckable(false);
+       }
+
+       setEnabled(status.enabled());
+}
+
+
+void Action::action()
+{
+//     LYXERR(Debug::ACTION) << "calling LyXFunc::dispatch: func_: " << func_ << endl;
+
+       lyxView_.dispatch(func_);
+       triggered(this);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "Action_moc.cpp"
diff --git a/src/frontends/qt4/Alert_pimpl.C b/src/frontends/qt4/Alert_pimpl.C
deleted file mode 100644 (file)
index 6bf50fc..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * \file qt4/Alert_pimpl.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "Alert_pimpl.h"
-#include "Alert.h"
-
-#include "ui/AskForTextUi.h"
-#include "qt_helpers.h"
-
-#include "frontends/Application.h"
-
-#include "gettext.h"
-
-#include <QApplication>
-#include <QMessageBox>
-#include <QLabel>
-#include <QLineEdit>
-#include <QDialog>
-#include <QInputDialog>
-
-#include <algorithm>
-
-using std::pair;
-using std::make_pair;
-using lyx::support::bformat;
-
-namespace lyx {
-
-namespace {
-
-class MessageBox: public QMessageBox
-{
-public:
-       MessageBox(QWidget * parent = 0) : QMessageBox(parent)
-       {
-               setAttribute(Qt::WA_DeleteOnClose, true);
-               setAttribute(Qt::WA_QuitOnClose, false);
-       }
-};
-
-} // anonymous namespace
-
-
-int prompt_pimpl(docstring const & tit, docstring const & question,
-                int default_button, int cancel_button,
-                docstring const & b1, docstring const & b2, docstring const & b3)
-{
-       docstring const title = bformat(_("LyX: %1$s"), tit);
-
-       MessageBox mb;
-
-       // For some reason, sometimes Qt uses an hourglass or watch cursor when
-       // displaying the alert. Hence, we ask for the standard cursor shape.
-       // This call has no effect if the cursor has not been overridden.
-       qApp->changeOverrideCursor(Qt::ArrowCursor);
-
-       // FIXME replace that with theApp->gui()->currentView()
-       int res = mb.information(qApp->focusWidget(),
-                                          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)
-               res = cancel_button;
-       return res;
-}
-
-
-void warning_pimpl(docstring const & tit, docstring const & message)
-{
-       docstring const title = bformat(_("LyX: %1$s"), tit);
-
-       if (theApp() == 0) {
-               int argc = 1;
-               char * argv[1];
-               QApplication app(argc, argv);
-               QMessageBox::warning(0,
-                       toqstr(title),
-                       toqstr(formatted(message)));
-               return;
-       }
-       MessageBox mb;
-       mb.warning(qApp->focusWidget(),
-                            toqstr(title),
-                            toqstr(formatted(message)));
-}
-
-
-void error_pimpl(docstring const & tit, docstring const & message)
-{
-       docstring const title = bformat(_("LyX: %1$s"), tit);
-       if (theApp() == 0) {
-               int argc = 1;
-               char * argv[1];
-               QApplication app(argc, argv);
-               QMessageBox::critical(0,
-                       toqstr(title),
-                       toqstr(formatted(message)));
-               return;
-       }
-       MessageBox mb;
-       mb.critical(qApp->focusWidget(),
-                             toqstr(title),
-                             toqstr(formatted(message)));
-}
-
-
-void information_pimpl(docstring const & tit, docstring const & message)
-{
-       docstring const title = bformat(_("LyX: %1$s"), tit);
-       MessageBox mb;
-       mb.information(qApp->focusWidget(),
-                                toqstr(title),
-                                toqstr(formatted(message)));
-}
-
-
-pair<bool, docstring> const
-askForText_pimpl(docstring const & msg, docstring const & dflt)
-{
-       docstring const title = bformat(_("LyX: %1$s"), msg);
-
-       bool ok;
-       QString text = QInputDialog::getText(qApp->focusWidget(),
-               toqstr(title),
-               toqstr(char_type('&') + msg),
-               QLineEdit::Normal,
-               toqstr(dflt), &ok);
-
-       if (ok && !text.isEmpty())
-               return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
-       else
-               return make_pair<bool, docstring>(false, docstring());
-}
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/Alert_pimpl.cpp b/src/frontends/qt4/Alert_pimpl.cpp
new file mode 100644 (file)
index 0000000..6bf50fc
--- /dev/null
@@ -0,0 +1,151 @@
+/**
+ * \file qt4/Alert_pimpl.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "Alert_pimpl.h"
+#include "Alert.h"
+
+#include "ui/AskForTextUi.h"
+#include "qt_helpers.h"
+
+#include "frontends/Application.h"
+
+#include "gettext.h"
+
+#include <QApplication>
+#include <QMessageBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QDialog>
+#include <QInputDialog>
+
+#include <algorithm>
+
+using std::pair;
+using std::make_pair;
+using lyx::support::bformat;
+
+namespace lyx {
+
+namespace {
+
+class MessageBox: public QMessageBox
+{
+public:
+       MessageBox(QWidget * parent = 0) : QMessageBox(parent)
+       {
+               setAttribute(Qt::WA_DeleteOnClose, true);
+               setAttribute(Qt::WA_QuitOnClose, false);
+       }
+};
+
+} // anonymous namespace
+
+
+int prompt_pimpl(docstring const & tit, docstring const & question,
+                int default_button, int cancel_button,
+                docstring const & b1, docstring const & b2, docstring const & b3)
+{
+       docstring const title = bformat(_("LyX: %1$s"), tit);
+
+       MessageBox mb;
+
+       // For some reason, sometimes Qt uses an hourglass or watch cursor when
+       // displaying the alert. Hence, we ask for the standard cursor shape.
+       // This call has no effect if the cursor has not been overridden.
+       qApp->changeOverrideCursor(Qt::ArrowCursor);
+
+       // FIXME replace that with theApp->gui()->currentView()
+       int res = mb.information(qApp->focusWidget(),
+                                          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)
+               res = cancel_button;
+       return res;
+}
+
+
+void warning_pimpl(docstring const & tit, docstring const & message)
+{
+       docstring const title = bformat(_("LyX: %1$s"), tit);
+
+       if (theApp() == 0) {
+               int argc = 1;
+               char * argv[1];
+               QApplication app(argc, argv);
+               QMessageBox::warning(0,
+                       toqstr(title),
+                       toqstr(formatted(message)));
+               return;
+       }
+       MessageBox mb;
+       mb.warning(qApp->focusWidget(),
+                            toqstr(title),
+                            toqstr(formatted(message)));
+}
+
+
+void error_pimpl(docstring const & tit, docstring const & message)
+{
+       docstring const title = bformat(_("LyX: %1$s"), tit);
+       if (theApp() == 0) {
+               int argc = 1;
+               char * argv[1];
+               QApplication app(argc, argv);
+               QMessageBox::critical(0,
+                       toqstr(title),
+                       toqstr(formatted(message)));
+               return;
+       }
+       MessageBox mb;
+       mb.critical(qApp->focusWidget(),
+                             toqstr(title),
+                             toqstr(formatted(message)));
+}
+
+
+void information_pimpl(docstring const & tit, docstring const & message)
+{
+       docstring const title = bformat(_("LyX: %1$s"), tit);
+       MessageBox mb;
+       mb.information(qApp->focusWidget(),
+                                toqstr(title),
+                                toqstr(formatted(message)));
+}
+
+
+pair<bool, docstring> const
+askForText_pimpl(docstring const & msg, docstring const & dflt)
+{
+       docstring const title = bformat(_("LyX: %1$s"), msg);
+
+       bool ok;
+       QString text = QInputDialog::getText(qApp->focusWidget(),
+               toqstr(title),
+               toqstr(char_type('&') + msg),
+               QLineEdit::Normal,
+               toqstr(dflt), &ok);
+
+       if (ok && !text.isEmpty())
+               return make_pair<bool, docstring>(true, qstring_to_ucs4(text));
+       else
+               return make_pair<bool, docstring>(false, docstring());
+}
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/BulletsModule.C b/src/frontends/qt4/BulletsModule.C
deleted file mode 100644 (file)
index 46cf50d..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/**
- * \file BulletsModule.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "BulletsModule.h"
-#include "qt_helpers.h"
-
-#include "support/filetools.h"
-
-#include <QPixmap>
-#include <QPainter>
-
-#include <boost/assert.hpp>
-
-namespace lyx {
-
-using support::libFileSearch;
-
-using std::string;
-
-BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
-{
-       setupUi(this);
-
-       for (int iter = 0; iter < 4; ++iter)
-               bullets_[iter] = ITEMIZE_DEFAULTS[iter];
-
-       current_font_ = -1;
-       current_char_ = 0;
-
-       // add levels
-       levelLW->addItem("1");
-       levelLW->addItem("2");
-       levelLW->addItem("3");
-       levelLW->addItem("4");
-
-       // insert pixmaps
-       setupPanel(new QListWidget(bulletpaneSW), qt_("Standard"), "standard");
-       setupPanel(new QListWidget(bulletpaneSW), qt_("Maths"), "amssymb");
-       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 1"), "psnfss1");
-       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 2"), "psnfss2");
-       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3");
-       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4");
-
-       connect(levelLW, SIGNAL(currentRowChanged(int)),
-               this, SLOT(showLevel(int)));
-       connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
-               SLOT(setCurrentIndex(int)));
-}
-
-
-void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
-       std::string const & fname)
-{
-       connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
-               this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
-
-       // add panelname to combox
-       bulletpaneCO->addItem(panelname);
-
-       // get pixmap with bullets
-       QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm").absFilename()));
-
-       int const w = pixmap.width() / 6;
-       int const h = pixmap.height() / 6;
-
-       // apply setting to listwidget
-       lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-       lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-       lw->setViewMode(QListView::IconMode);
-       lw->setFlow(QListView::LeftToRight);
-       lw->setMovement(QListView::Static);
-       lw->setUniformItemSizes(true);
-       lw->setGridSize(QSize(w, h));
-       // the widening by 21 is needed to avoid wrapping
-       lw->resize(6 * w + 21, 6 * h);
-       bulletpaneSW->setMinimumSize(6 * w, 6 * h + 6);
-
-       // get individual bullets from pixmap
-       for (int row = 0; row < 6; ++row) {
-               for (int col = 0; col < 6; ++col) {
-                       QPixmap small(w, h);
-                       small.fill();
-                       QPainter painter(&small);
-                       painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
-                       new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
-               }
-       }
-
-       // add bulletpanel to stackedwidget
-       bulletpaneSW->addWidget(lw);
-}
-
-
-void BulletsModule::showLevel(int level)
-{
-       // unselect previous item
-       selectItem(current_font_, current_char_, false);
-
-       current_font_ = bullets_[level].getFont();
-
-       if (bullets_[level].getFont() < 0) {
-               customCB->setCheckState(Qt::Checked);
-               customLE->setText(toqstr(bullets_[level].getText()));
-       } else {
-               customCB->setCheckState(Qt::Unchecked);
-               customLE->clear();
-               current_char_ = bullets_[level].getCharacter();
-               selectItem(current_font_, current_char_, true);
-               bulletpaneCO->setCurrentIndex(current_font_);
-               bulletpaneSW->setCurrentIndex(current_font_);
-       }
-       bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
-}
-
-
-void BulletsModule::init()
-{
-       levelLW->setCurrentRow(0);
-       showLevel(0);
-}
-
-
-void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
-{
-       // unselect previous item
-       selectItem(current_font_, current_char_, false);
-
-       int const level = levelLW->currentRow();
-       bullets_[level].setCharacter(item->type());
-       bullets_[level].setFont(bulletpaneCO->currentIndex());
-       current_font_ = bulletpaneCO->currentIndex();
-       current_char_ = item->type();
-       changed();
-}
-
-
-void BulletsModule::on_customCB_clicked(bool custom)
-{
-       if (!custom) {
-               if (current_font_ < 0)
-                       current_font_ = bulletpaneCO->currentIndex();
-               return;
-       }
-               
-       // unselect previous item
-       selectItem(current_font_, current_char_, false);
-       current_font_ = -1;
-       changed();
-}
-
-
-void BulletsModule::selectItem(int font, int character, bool select)
-{
-       if (font < 0)
-               return;
-
-       QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
-       lw->setItemSelected(lw->item(character), select);
-}
-
-
-void BulletsModule::on_customLE_textEdited(const QString & text)
-{
-       if (customCB->checkState() == Qt::Unchecked)
-               return;
-
-       bullets_[levelLW->currentRow()].setFont(current_font_);
-       bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
-       changed();
-}
-
-
-void BulletsModule::on_bulletsizeCO_activated(int size)
-{
-       // -1 apparently means default...
-       bullets_[levelLW->currentRow()].setSize(size - 1);
-}
-
-
-void BulletsModule::setBullet(int level, Bullet const & bullet)
-{
-       bullets_[level] = bullet;
-}
-
-
-Bullet const & BulletsModule::getBullet(int level) const
-{
-       return bullets_[level];
-}
-
-} // namespace lyx
-
-
-#include "BulletsModule_moc.cpp"
diff --git a/src/frontends/qt4/BulletsModule.cpp b/src/frontends/qt4/BulletsModule.cpp
new file mode 100644 (file)
index 0000000..46cf50d
--- /dev/null
@@ -0,0 +1,203 @@
+/**
+ * \file BulletsModule.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "BulletsModule.h"
+#include "qt_helpers.h"
+
+#include "support/filetools.h"
+
+#include <QPixmap>
+#include <QPainter>
+
+#include <boost/assert.hpp>
+
+namespace lyx {
+
+using support::libFileSearch;
+
+using std::string;
+
+BulletsModule::BulletsModule(QWidget * , char const * , Qt::WFlags)
+{
+       setupUi(this);
+
+       for (int iter = 0; iter < 4; ++iter)
+               bullets_[iter] = ITEMIZE_DEFAULTS[iter];
+
+       current_font_ = -1;
+       current_char_ = 0;
+
+       // add levels
+       levelLW->addItem("1");
+       levelLW->addItem("2");
+       levelLW->addItem("3");
+       levelLW->addItem("4");
+
+       // insert pixmaps
+       setupPanel(new QListWidget(bulletpaneSW), qt_("Standard"), "standard");
+       setupPanel(new QListWidget(bulletpaneSW), qt_("Maths"), "amssymb");
+       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 1"), "psnfss1");
+       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 2"), "psnfss2");
+       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 3"), "psnfss3");
+       setupPanel(new QListWidget(bulletpaneSW), qt_("Dings 4"), "psnfss4");
+
+       connect(levelLW, SIGNAL(currentRowChanged(int)),
+               this, SLOT(showLevel(int)));
+       connect(bulletpaneCO, SIGNAL(activated(int)), bulletpaneSW,
+               SLOT(setCurrentIndex(int)));
+}
+
+
+void BulletsModule::setupPanel(QListWidget * lw, QString const & panelname,
+       std::string const & fname)
+{
+       connect(lw, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
+               this, SLOT(bulletSelected(QListWidgetItem *, QListWidgetItem*)));
+
+       // add panelname to combox
+       bulletpaneCO->addItem(panelname);
+
+       // get pixmap with bullets
+       QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm").absFilename()));
+
+       int const w = pixmap.width() / 6;
+       int const h = pixmap.height() / 6;
+
+       // apply setting to listwidget
+       lw->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+       lw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+       lw->setViewMode(QListView::IconMode);
+       lw->setFlow(QListView::LeftToRight);
+       lw->setMovement(QListView::Static);
+       lw->setUniformItemSizes(true);
+       lw->setGridSize(QSize(w, h));
+       // the widening by 21 is needed to avoid wrapping
+       lw->resize(6 * w + 21, 6 * h);
+       bulletpaneSW->setMinimumSize(6 * w, 6 * h + 6);
+
+       // get individual bullets from pixmap
+       for (int row = 0; row < 6; ++row) {
+               for (int col = 0; col < 6; ++col) {
+                       QPixmap small(w, h);
+                       small.fill();
+                       QPainter painter(&small);
+                       painter.drawPixmap(small.rect(), pixmap, QRect(col * w, row * h, w, h));
+                       new QListWidgetItem(QIcon(small), "" , lw, (6 * row + col));
+               }
+       }
+
+       // add bulletpanel to stackedwidget
+       bulletpaneSW->addWidget(lw);
+}
+
+
+void BulletsModule::showLevel(int level)
+{
+       // unselect previous item
+       selectItem(current_font_, current_char_, false);
+
+       current_font_ = bullets_[level].getFont();
+
+       if (bullets_[level].getFont() < 0) {
+               customCB->setCheckState(Qt::Checked);
+               customLE->setText(toqstr(bullets_[level].getText()));
+       } else {
+               customCB->setCheckState(Qt::Unchecked);
+               customLE->clear();
+               current_char_ = bullets_[level].getCharacter();
+               selectItem(current_font_, current_char_, true);
+               bulletpaneCO->setCurrentIndex(current_font_);
+               bulletpaneSW->setCurrentIndex(current_font_);
+       }
+       bulletsizeCO->setCurrentIndex(bullets_[level].getSize() + 1);
+}
+
+
+void BulletsModule::init()
+{
+       levelLW->setCurrentRow(0);
+       showLevel(0);
+}
+
+
+void BulletsModule::bulletSelected(QListWidgetItem * item, QListWidgetItem *)
+{
+       // unselect previous item
+       selectItem(current_font_, current_char_, false);
+
+       int const level = levelLW->currentRow();
+       bullets_[level].setCharacter(item->type());
+       bullets_[level].setFont(bulletpaneCO->currentIndex());
+       current_font_ = bulletpaneCO->currentIndex();
+       current_char_ = item->type();
+       changed();
+}
+
+
+void BulletsModule::on_customCB_clicked(bool custom)
+{
+       if (!custom) {
+               if (current_font_ < 0)
+                       current_font_ = bulletpaneCO->currentIndex();
+               return;
+       }
+               
+       // unselect previous item
+       selectItem(current_font_, current_char_, false);
+       current_font_ = -1;
+       changed();
+}
+
+
+void BulletsModule::selectItem(int font, int character, bool select)
+{
+       if (font < 0)
+               return;
+
+       QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
+       lw->setItemSelected(lw->item(character), select);
+}
+
+
+void BulletsModule::on_customLE_textEdited(const QString & text)
+{
+       if (customCB->checkState() == Qt::Unchecked)
+               return;
+
+       bullets_[levelLW->currentRow()].setFont(current_font_);
+       bullets_[levelLW->currentRow()].setText(qstring_to_ucs4(text));
+       changed();
+}
+
+
+void BulletsModule::on_bulletsizeCO_activated(int size)
+{
+       // -1 apparently means default...
+       bullets_[levelLW->currentRow()].setSize(size - 1);
+}
+
+
+void BulletsModule::setBullet(int level, Bullet const & bullet)
+{
+       bullets_[level] = bullet;
+}
+
+
+Bullet const & BulletsModule::getBullet(int level) const
+{
+       return bullets_[level];
+}
+
+} // namespace lyx
+
+
+#include "BulletsModule_moc.cpp"
diff --git a/src/frontends/qt4/CheckedLineEdit.cpp b/src/frontends/qt4/CheckedLineEdit.cpp
new file mode 100644 (file)
index 0000000..348bdef
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * \file qt4/CheckedLineEdit.cpp
+ * 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 "CheckedLineEdit.h"
+
+#include <QLabel>
+#include <QLineEdit>
+#include <QValidator>
+
+namespace lyx {
+namespace frontend {
+
+void addCheckedLineEdit(BCView & bcview,
+                       QLineEdit * input, QWidget * label)
+{
+       bcview.addCheckedWidget(new CheckedLineEdit(input, label));
+}
+
+
+namespace {
+
+void setWarningColor(QWidget * widget)
+{
+       // Qt 2.3 does not have
+       // widget->setPaletteForegroundColor(QColor(255, 0, 0));
+       // So copy the appropriate parts of the function here:
+       QPalette pal = widget->palette();
+       pal.setColor(QPalette::Active,
+                    QPalette::Foreground,
+                    QColor(255, 0, 0));
+       widget->setPalette(pal);
+}
+
+
+void setWidget(bool valid, QLineEdit * input, QWidget * label)
+{
+       if (valid)
+               input->setPalette(QPalette());
+       else
+               setWarningColor(input);
+
+       if (!label)
+               return;
+
+       if (valid)
+               label->setPalette(QPalette());
+       else
+               setWarningColor(label);
+}
+
+} // namespace anon
+
+
+CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label)
+       : input_(input), label_(label)
+{}
+
+
+bool CheckedLineEdit::check() const
+{
+       QValidator const * validator = input_->validator();
+       if (!validator)
+               return true;
+
+       QString t = input_->text();
+       int p = 0;
+       bool const valid = validator->validate(t, p) == QValidator::Acceptable;
+
+       // Visual feedback.
+       setWidget(valid, input_, label_);
+
+       return valid;
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/CheckedLineEdit.h b/src/frontends/qt4/CheckedLineEdit.h
new file mode 100644 (file)
index 0000000..823e095
--- /dev/null
@@ -0,0 +1,42 @@
+// -*- C++ -*-
+/**
+ * \file qt4/CheckedLineEdit.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 CHECKEDLINEEDIT_H
+#define CHECKEDLINEEDIT_H
+
+#include "BCView.h"
+
+class QWidget;
+class QLineEdit;
+
+namespace lyx {
+namespace frontend {
+
+void addCheckedLineEdit(BCView & bcview,
+       QLineEdit * input, QWidget * label = 0);
+
+class CheckedLineEdit : public CheckedWidget {
+public:
+       CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
+
+private:
+       ///
+       virtual bool check() const;
+
+       ///
+       QLineEdit * input_;
+       QWidget * label_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // CHECKEDLINEEDIT_H
diff --git a/src/frontends/qt4/ColorCache.C b/src/frontends/qt4/ColorCache.C
deleted file mode 100644 (file)
index 56994fd..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * \file ColorCache.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "Color.h"
-#include "ColorCache.h"
-
-#include "LColor.h"
-
-
-namespace lyx {
-
-const QColor grey40(0x66, 0x66, 0x66);
-const QColor grey60(0x99, 0x99, 0x99);
-const QColor grey80(0xcc, 0xcc, 0xcc);
-const QColor grey90(0xe5, 0xe5, 0xe5);
-const QColor none = Qt::black;
-
-QColor const & ColorCache::get(LColor_color col) const
-{
-       lcolor_map::const_iterator cit = colormap.find(col);
-       if (cit != colormap.end())
-               return cit->second;
-
-       if (lcolor.getX11Name(col) == "grey40")
-               colormap[col] = grey40;
-       else if (lcolor.getX11Name(col) == "grey60")
-               colormap[col] = grey60;
-       else if (lcolor.getX11Name(col) == "grey80")
-               colormap[col] = grey80;
-       else if (lcolor.getX11Name(col) == "grey90")
-               colormap[col] = grey90;
-       else if (lcolor.getX11Name(col) == "none")
-               colormap[col] = none;
-       else
-               colormap[col] = QColor(lcolor.getX11Name(col).c_str());
-
-       return colormap[col];
-}
-
-
-void ColorCache::clear()
-{
-       colormap.clear();
-}
-
-
-QColor const rgb2qcolor(RGBColor const & rgb)
-{
-       return QColor(rgb.r, rgb.g, rgb.b);
-}
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/ColorCache.cpp b/src/frontends/qt4/ColorCache.cpp
new file mode 100644 (file)
index 0000000..56994fd
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * \file ColorCache.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "Color.h"
+#include "ColorCache.h"
+
+#include "LColor.h"
+
+
+namespace lyx {
+
+const QColor grey40(0x66, 0x66, 0x66);
+const QColor grey60(0x99, 0x99, 0x99);
+const QColor grey80(0xcc, 0xcc, 0xcc);
+const QColor grey90(0xe5, 0xe5, 0xe5);
+const QColor none = Qt::black;
+
+QColor const & ColorCache::get(LColor_color col) const
+{
+       lcolor_map::const_iterator cit = colormap.find(col);
+       if (cit != colormap.end())
+               return cit->second;
+
+       if (lcolor.getX11Name(col) == "grey40")
+               colormap[col] = grey40;
+       else if (lcolor.getX11Name(col) == "grey60")
+               colormap[col] = grey60;
+       else if (lcolor.getX11Name(col) == "grey80")
+               colormap[col] = grey80;
+       else if (lcolor.getX11Name(col) == "grey90")
+               colormap[col] = grey90;
+       else if (lcolor.getX11Name(col) == "none")
+               colormap[col] = none;
+       else
+               colormap[col] = QColor(lcolor.getX11Name(col).c_str());
+
+       return colormap[col];
+}
+
+
+void ColorCache::clear()
+{
+       colormap.clear();
+}
+
+
+QColor const rgb2qcolor(RGBColor const & rgb)
+{
+       return QColor(rgb.r, rgb.g, rgb.b);
+}
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/Dialogs.C b/src/frontends/qt4/Dialogs.C
deleted file mode 100644 (file)
index 0735eab..0000000
+++ /dev/null
@@ -1,334 +0,0 @@
-/**
- * \file qt4/Dialogs.cpp
- * 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 "Dialogs.h"
-
-#include "ControlAboutlyx.h"
-#include "ControlBibtex.h"
-#include "ControlBox.h"
-#include "ControlBranch.h"
-#include "ControlChanges.h"
-#include "ControlCharacter.h"
-#include "ControlDocument.h"
-#include "ControlErrorList.h"
-#include "ControlERT.h"
-#include "ControlExternal.h"
-#include "ControlFloat.h"
-#include "ControlGraphics.h"
-#include "ControlInclude.h"
-#include "ControlLog.h"
-#include "ControlViewSource.h"
-#include "ControlMath.h"
-#include "ControlNote.h"
-#include "ControlParagraph.h"
-#include "ControlPrefs.h"
-#include "ControlPrint.h"
-#include "ControlRef.h"
-#include "ControlSearch.h"
-#include "ControlSendto.h"
-#include "ControlShowFile.h"
-#include "ControlSpellchecker.h"
-#include "ControlTabular.h"
-#include "ControlTabularCreate.h"
-#include "ControlVSpace.h"
-#include "ControlWrap.h"
-
-#include "Qt2BC.h"
-#include "ButtonController.h"
-#include "DockView.h"
-#include "GuiView.h"
-#include "QAbout.h"
-#include "QBibitem.h"
-#include "QBibtex.h"
-#include "QBox.h"
-#include "QBranch.h"
-#include "QChanges.h"
-#include "QCharacter.h"
-#include "QCitation.h"
-#include "QCitationDialog.h"
-#include "QDelimiterDialog.h"
-#include "QDocument.h"
-#include "QErrorList.h"
-#include "QERT.h"
-#include "QExternal.h"
-#include "QFloat.h"
-#include "QGraphics.h"
-#include "QInclude.h"
-#include "QIndex.h"
-#include "QMathMatrixDialog.h"
-#include "QNomencl.h"
-#include "QLog.h"
-#include "QViewSource.h"
-#include "QNote.h"
-#include "QParagraph.h"
-#include "QPrefs.h"
-#include "QPrint.h"
-#include "QRef.h"
-#include "QSearch.h"
-#include "QSendto.h"
-#include "QShowFile.h"
-#include "QSpellchecker.h"
-#include "QTabular.h"
-#include "QTabularCreate.h"
-#include "QTexinfo.h"
-#include "QToc.h"
-#include "TocWidget.h"
-#include "UrlView.h"
-#include "QVSpace.h"
-#include "QWrap.h"
-
-#ifdef HAVE_LIBAIKSAURUS
-#include "ControlThesaurus.h"
-#include "QThesaurus.h"
-#endif
-
-#include "qt_helpers.h"
-
-#include <boost/assert.hpp>
-
-using std::string;
-
-using namespace lyx::frontend;
-
-namespace {
-
-char const * const dialognames[] = {
-"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
-"citation", "document", "errorlist", "ert", "external", "file",
-"findreplace", "float", "graphics", "include", "index", "nomenclature", "label", "log",
-"mathdelimiter", "mathmatrix", "note", "paragraph",
-"prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate",
-
-#ifdef HAVE_LIBAIKSAURUS
-"thesaurus",
-#endif
-
-"texinfo", "toc", "url", "view-source", "vspace", "wrap" };
-
-char const * const * const end_dialognames =
-       dialognames + (sizeof(dialognames) / sizeof(char *));
-
-class cmpCStr {
-public:
-       cmpCStr(char const * name) : name_(name) {}
-       bool operator()(char const * other) {
-               return strcmp(other, name_) == 0;
-       }
-private:
-       char const * name_;
-};
-
-
-} // namespace anon
-
-
-namespace lyx {
-
-
-bool Dialogs::isValidName(string const & name) const
-{
-       return std::find_if(dialognames, end_dialognames,
-                           cmpCStr(name.c_str())) != end_dialognames;
-}
-
-
-Dialogs::DialogPtr Dialogs::build(string const & name)
-{
-       BOOST_ASSERT(isValidName(name));
-
-       DialogPtr dialog(new Dialog(lyxview_, name));
-       dialog->bc().view(new Qt2BC(dialog->bc()));
-
-       if (name == "aboutlyx") {
-               dialog->setController(new ControlAboutlyx(*dialog));
-               dialog->setView(new QAbout(*dialog));
-               dialog->bc().bp(new OkCancelPolicy);
-       } else if (name == "bibitem") {
-               dialog->setController(new ControlCommand(*dialog, name, name));
-               dialog->setView(new QBibitem(*dialog));
-               dialog->bc().bp(new OkCancelReadOnlyPolicy);
-       } else if (name == "bibtex") {
-               dialog->setController(new ControlBibtex(*dialog));
-               dialog->setView(new QBibtex(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "box") {
-               dialog->setController(new ControlBox(*dialog));
-               dialog->setView(new QBox(*dialog));
-               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
-       } else if (name == "branch") {
-               dialog->setController(new ControlBranch(*dialog));
-               dialog->setView(new QBranch(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "changes") {
-               dialog->setController(new ControlChanges(*dialog));
-               dialog->setView(new QChanges(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "character") {
-               dialog->setController(new ControlCharacter(*dialog));
-               dialog->setView(new QCharacter(*dialog));
-               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
-       } else if (name == "citation") {
-               QCitation * ci = new QCitation(*dialog);
-               dialog->setController(ci);
-               dialog->setView(new QCitationDialog(*dialog, ci));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "document") {
-               dialog->setController(new ControlDocument(*dialog));
-               dialog->setView(new QDocument(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "errorlist") {
-               dialog->setController(new ControlErrorList(*dialog));
-               dialog->setView(new QErrorList(*dialog));
-               dialog->bc().bp(new OkCancelPolicy);
-       } else if (name == "ert") {
-               dialog->setController(new ControlERT(*dialog));
-               dialog->setView(new QERT(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "external") {
-               dialog->setController(new ControlExternal(*dialog));
-               dialog->setView(new QExternal(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "file") {
-               dialog->setController(new ControlShowFile(*dialog));
-               dialog->setView(new QShowFile(*dialog));
-               dialog->bc().bp(new OkCancelPolicy);
-       } else if (name == "findreplace") {
-               dialog->setController(new ControlSearch(*dialog));
-               dialog->setView(new QSearch(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "float") {
-               dialog->setController(new ControlFloat(*dialog));
-               dialog->setView(new QFloat(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "graphics") {
-               dialog->setController(new ControlGraphics(*dialog));
-               dialog->setView(new QGraphics(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "include") {
-               dialog->setController(new ControlInclude(*dialog));
-               dialog->setView(new QInclude(*dialog));
-               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
-       } else if (name == "index") {
-               dialog->setController(new ControlCommand(*dialog, name, name));
-               dialog->setView(new QIndex(*dialog,
-                                          _("Index Entry"),
-                                          qt_("&Keyword:")));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "nomenclature") {
-               dialog->setController(new ControlCommand(*dialog, name, name));
-               dialog->setView(new QNomencl(*dialog, _("Glossary Entry")));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "label") {
-               dialog->setController(new ControlCommand(*dialog, name, name));
-               dialog->setView(new QIndex(*dialog,
-                                          _("Label"),
-                                          qt_("&Label:")));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "log") {
-               dialog->setController(new ControlLog(*dialog));
-               dialog->setView(new QLog(*dialog));
-               dialog->bc().bp(new OkCancelPolicy);
-       } else if (name == "view-source") {
-               QViewSource * qvs = new QViewSource(*dialog);
-               dialog->setController(qvs);
-               GuiView & gui_view = static_cast<GuiView &>(lyxview_);
-               dialog->setView(new DockView<QViewSource, QViewSourceDialog>(
-                       *dialog, qvs, &gui_view, _("LaTeX Source"), Qt::BottomDockWidgetArea));
-               dialog->bc().bp(new OkCancelPolicy);
-       } else if (name == "mathdelimiter") {
-               dialog->setController(new ControlMath(*dialog));
-               dialog->setView(new QMathDelimiter(*dialog));
-               dialog->bc().bp(new IgnorantPolicy);
-       } else if (name == "mathmatrix") {
-               dialog->setController(new ControlMath(*dialog));
-               dialog->setView(new QMathMatrix(*dialog));
-               dialog->bc().bp(new IgnorantPolicy);
-       } else if (name == "note") {
-               dialog->setController(new ControlNote(*dialog));
-               dialog->setView(new QNote(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "paragraph") {
-               dialog->setController(new ControlParagraph(*dialog));
-               dialog->setView(new QParagraph(*dialog));
-               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
-       } else if (name == "prefs") {
-               dialog->setController(new ControlPrefs(*dialog));
-               dialog->setView(new QPrefs(*dialog));
-               dialog->bc().bp(new PreferencesPolicy);
-       } else if (name == "print") {
-               dialog->setController(new ControlPrint(*dialog));
-               dialog->setView(new QPrint(*dialog));
-               dialog->bc().bp(new OkApplyCancelPolicy);
-       } else if (name == "ref") {
-               // full qualification because qt4 has also a ControlRef type
-               dialog->setController(new lyx::frontend::ControlRef(*dialog));
-               dialog->setView(new QRef(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "sendto") {
-               dialog->setController(new ControlSendto(*dialog));
-               dialog->setView(new QSendto(*dialog));
-               dialog->bc().bp(new OkApplyCancelPolicy);
-       } else if (name == "spellchecker") {
-               dialog->setController(new ControlSpellchecker(*dialog));
-               dialog->setView(new QSpellchecker(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "tabular") {
-               dialog->setController(new ControlTabular(*dialog));
-               dialog->setView(new QTabular(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "tabularcreate") {
-               dialog->setController(new ControlTabularCreate(*dialog));
-               dialog->setView(new QTabularCreate(*dialog));
-               dialog->bc().bp(new IgnorantPolicy);
-       } else if (name == "texinfo") {
-               dialog->setController(new ControlTexinfo(*dialog));
-               dialog->setView(new QTexinfo(*dialog));
-               dialog->bc().bp(new OkCancelPolicy);
-#ifdef HAVE_LIBAIKSAURUS
-       } else if (name == "thesaurus") {
-               dialog->setController(new ControlThesaurus(*dialog));
-               dialog->setView(new QThesaurus(*dialog));
-               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
-#endif
-       } else if (name == "toc") {
-               GuiView & gui_view = static_cast<GuiView &>(lyxview_);
-               QToc * qtoc = new QToc(*dialog, &gui_view);
-               dialog->setController(qtoc);
-               dialog->setView(new DockView<QToc, TocWidget>(
-                       *dialog, qtoc, &gui_view, _("Toc")));
-               dialog->bc().bp(new OkCancelPolicy);
-       } else if (name == "url") {
-               dialog->setController(new ControlCommand(*dialog, name, name));
-               dialog->setView(new UrlView(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       } else if (name == "vspace") {
-               dialog->setController(new ControlVSpace(*dialog));
-               dialog->setView(new QVSpace(*dialog));
-               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
-       } else if (name == "wrap") {
-               dialog->setController(new ControlWrap(*dialog));
-               dialog->setView(new QWrap(*dialog));
-               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
-       }
-
-       return dialog;
-}
-
-
-/// Are the tooltips on or off?
-bool Dialogs::tooltipsEnabled()
-{
-       return false;
-}
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp
new file mode 100644 (file)
index 0000000..0735eab
--- /dev/null
@@ -0,0 +1,334 @@
+/**
+ * \file qt4/Dialogs.cpp
+ * 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 "Dialogs.h"
+
+#include "ControlAboutlyx.h"
+#include "ControlBibtex.h"
+#include "ControlBox.h"
+#include "ControlBranch.h"
+#include "ControlChanges.h"
+#include "ControlCharacter.h"
+#include "ControlDocument.h"
+#include "ControlErrorList.h"
+#include "ControlERT.h"
+#include "ControlExternal.h"
+#include "ControlFloat.h"
+#include "ControlGraphics.h"
+#include "ControlInclude.h"
+#include "ControlLog.h"
+#include "ControlViewSource.h"
+#include "ControlMath.h"
+#include "ControlNote.h"
+#include "ControlParagraph.h"
+#include "ControlPrefs.h"
+#include "ControlPrint.h"
+#include "ControlRef.h"
+#include "ControlSearch.h"
+#include "ControlSendto.h"
+#include "ControlShowFile.h"
+#include "ControlSpellchecker.h"
+#include "ControlTabular.h"
+#include "ControlTabularCreate.h"
+#include "ControlVSpace.h"
+#include "ControlWrap.h"
+
+#include "Qt2BC.h"
+#include "ButtonController.h"
+#include "DockView.h"
+#include "GuiView.h"
+#include "QAbout.h"
+#include "QBibitem.h"
+#include "QBibtex.h"
+#include "QBox.h"
+#include "QBranch.h"
+#include "QChanges.h"
+#include "QCharacter.h"
+#include "QCitation.h"
+#include "QCitationDialog.h"
+#include "QDelimiterDialog.h"
+#include "QDocument.h"
+#include "QErrorList.h"
+#include "QERT.h"
+#include "QExternal.h"
+#include "QFloat.h"
+#include "QGraphics.h"
+#include "QInclude.h"
+#include "QIndex.h"
+#include "QMathMatrixDialog.h"
+#include "QNomencl.h"
+#include "QLog.h"
+#include "QViewSource.h"
+#include "QNote.h"
+#include "QParagraph.h"
+#include "QPrefs.h"
+#include "QPrint.h"
+#include "QRef.h"
+#include "QSearch.h"
+#include "QSendto.h"
+#include "QShowFile.h"
+#include "QSpellchecker.h"
+#include "QTabular.h"
+#include "QTabularCreate.h"
+#include "QTexinfo.h"
+#include "QToc.h"
+#include "TocWidget.h"
+#include "UrlView.h"
+#include "QVSpace.h"
+#include "QWrap.h"
+
+#ifdef HAVE_LIBAIKSAURUS
+#include "ControlThesaurus.h"
+#include "QThesaurus.h"
+#endif
+
+#include "qt_helpers.h"
+
+#include <boost/assert.hpp>
+
+using std::string;
+
+using namespace lyx::frontend;
+
+namespace {
+
+char const * const dialognames[] = {
+"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
+"citation", "document", "errorlist", "ert", "external", "file",
+"findreplace", "float", "graphics", "include", "index", "nomenclature", "label", "log",
+"mathdelimiter", "mathmatrix", "note", "paragraph",
+"prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate",
+
+#ifdef HAVE_LIBAIKSAURUS
+"thesaurus",
+#endif
+
+"texinfo", "toc", "url", "view-source", "vspace", "wrap" };
+
+char const * const * const end_dialognames =
+       dialognames + (sizeof(dialognames) / sizeof(char *));
+
+class cmpCStr {
+public:
+       cmpCStr(char const * name) : name_(name) {}
+       bool operator()(char const * other) {
+               return strcmp(other, name_) == 0;
+       }
+private:
+       char const * name_;
+};
+
+
+} // namespace anon
+
+
+namespace lyx {
+
+
+bool Dialogs::isValidName(string const & name) const
+{
+       return std::find_if(dialognames, end_dialognames,
+                           cmpCStr(name.c_str())) != end_dialognames;
+}
+
+
+Dialogs::DialogPtr Dialogs::build(string const & name)
+{
+       BOOST_ASSERT(isValidName(name));
+
+       DialogPtr dialog(new Dialog(lyxview_, name));
+       dialog->bc().view(new Qt2BC(dialog->bc()));
+
+       if (name == "aboutlyx") {
+               dialog->setController(new ControlAboutlyx(*dialog));
+               dialog->setView(new QAbout(*dialog));
+               dialog->bc().bp(new OkCancelPolicy);
+       } else if (name == "bibitem") {
+               dialog->setController(new ControlCommand(*dialog, name, name));
+               dialog->setView(new QBibitem(*dialog));
+               dialog->bc().bp(new OkCancelReadOnlyPolicy);
+       } else if (name == "bibtex") {
+               dialog->setController(new ControlBibtex(*dialog));
+               dialog->setView(new QBibtex(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "box") {
+               dialog->setController(new ControlBox(*dialog));
+               dialog->setView(new QBox(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
+       } else if (name == "branch") {
+               dialog->setController(new ControlBranch(*dialog));
+               dialog->setView(new QBranch(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "changes") {
+               dialog->setController(new ControlChanges(*dialog));
+               dialog->setView(new QChanges(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "character") {
+               dialog->setController(new ControlCharacter(*dialog));
+               dialog->setView(new QCharacter(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
+       } else if (name == "citation") {
+               QCitation * ci = new QCitation(*dialog);
+               dialog->setController(ci);
+               dialog->setView(new QCitationDialog(*dialog, ci));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "document") {
+               dialog->setController(new ControlDocument(*dialog));
+               dialog->setView(new QDocument(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "errorlist") {
+               dialog->setController(new ControlErrorList(*dialog));
+               dialog->setView(new QErrorList(*dialog));
+               dialog->bc().bp(new OkCancelPolicy);
+       } else if (name == "ert") {
+               dialog->setController(new ControlERT(*dialog));
+               dialog->setView(new QERT(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "external") {
+               dialog->setController(new ControlExternal(*dialog));
+               dialog->setView(new QExternal(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "file") {
+               dialog->setController(new ControlShowFile(*dialog));
+               dialog->setView(new QShowFile(*dialog));
+               dialog->bc().bp(new OkCancelPolicy);
+       } else if (name == "findreplace") {
+               dialog->setController(new ControlSearch(*dialog));
+               dialog->setView(new QSearch(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "float") {
+               dialog->setController(new ControlFloat(*dialog));
+               dialog->setView(new QFloat(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "graphics") {
+               dialog->setController(new ControlGraphics(*dialog));
+               dialog->setView(new QGraphics(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "include") {
+               dialog->setController(new ControlInclude(*dialog));
+               dialog->setView(new QInclude(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
+       } else if (name == "index") {
+               dialog->setController(new ControlCommand(*dialog, name, name));
+               dialog->setView(new QIndex(*dialog,
+                                          _("Index Entry"),
+                                          qt_("&Keyword:")));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "nomenclature") {
+               dialog->setController(new ControlCommand(*dialog, name, name));
+               dialog->setView(new QNomencl(*dialog, _("Glossary Entry")));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "label") {
+               dialog->setController(new ControlCommand(*dialog, name, name));
+               dialog->setView(new QIndex(*dialog,
+                                          _("Label"),
+                                          qt_("&Label:")));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "log") {
+               dialog->setController(new ControlLog(*dialog));
+               dialog->setView(new QLog(*dialog));
+               dialog->bc().bp(new OkCancelPolicy);
+       } else if (name == "view-source") {
+               QViewSource * qvs = new QViewSource(*dialog);
+               dialog->setController(qvs);
+               GuiView & gui_view = static_cast<GuiView &>(lyxview_);
+               dialog->setView(new DockView<QViewSource, QViewSourceDialog>(
+                       *dialog, qvs, &gui_view, _("LaTeX Source"), Qt::BottomDockWidgetArea));
+               dialog->bc().bp(new OkCancelPolicy);
+       } else if (name == "mathdelimiter") {
+               dialog->setController(new ControlMath(*dialog));
+               dialog->setView(new QMathDelimiter(*dialog));
+               dialog->bc().bp(new IgnorantPolicy);
+       } else if (name == "mathmatrix") {
+               dialog->setController(new ControlMath(*dialog));
+               dialog->setView(new QMathMatrix(*dialog));
+               dialog->bc().bp(new IgnorantPolicy);
+       } else if (name == "note") {
+               dialog->setController(new ControlNote(*dialog));
+               dialog->setView(new QNote(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "paragraph") {
+               dialog->setController(new ControlParagraph(*dialog));
+               dialog->setView(new QParagraph(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
+       } else if (name == "prefs") {
+               dialog->setController(new ControlPrefs(*dialog));
+               dialog->setView(new QPrefs(*dialog));
+               dialog->bc().bp(new PreferencesPolicy);
+       } else if (name == "print") {
+               dialog->setController(new ControlPrint(*dialog));
+               dialog->setView(new QPrint(*dialog));
+               dialog->bc().bp(new OkApplyCancelPolicy);
+       } else if (name == "ref") {
+               // full qualification because qt4 has also a ControlRef type
+               dialog->setController(new lyx::frontend::ControlRef(*dialog));
+               dialog->setView(new QRef(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "sendto") {
+               dialog->setController(new ControlSendto(*dialog));
+               dialog->setView(new QSendto(*dialog));
+               dialog->bc().bp(new OkApplyCancelPolicy);
+       } else if (name == "spellchecker") {
+               dialog->setController(new ControlSpellchecker(*dialog));
+               dialog->setView(new QSpellchecker(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "tabular") {
+               dialog->setController(new ControlTabular(*dialog));
+               dialog->setView(new QTabular(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "tabularcreate") {
+               dialog->setController(new ControlTabularCreate(*dialog));
+               dialog->setView(new QTabularCreate(*dialog));
+               dialog->bc().bp(new IgnorantPolicy);
+       } else if (name == "texinfo") {
+               dialog->setController(new ControlTexinfo(*dialog));
+               dialog->setView(new QTexinfo(*dialog));
+               dialog->bc().bp(new OkCancelPolicy);
+#ifdef HAVE_LIBAIKSAURUS
+       } else if (name == "thesaurus") {
+               dialog->setController(new ControlThesaurus(*dialog));
+               dialog->setView(new QThesaurus(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
+#endif
+       } else if (name == "toc") {
+               GuiView & gui_view = static_cast<GuiView &>(lyxview_);
+               QToc * qtoc = new QToc(*dialog, &gui_view);
+               dialog->setController(qtoc);
+               dialog->setView(new DockView<QToc, TocWidget>(
+                       *dialog, qtoc, &gui_view, _("Toc")));
+               dialog->bc().bp(new OkCancelPolicy);
+       } else if (name == "url") {
+               dialog->setController(new ControlCommand(*dialog, name, name));
+               dialog->setView(new UrlView(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       } else if (name == "vspace") {
+               dialog->setController(new ControlVSpace(*dialog));
+               dialog->setView(new QVSpace(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
+       } else if (name == "wrap") {
+               dialog->setController(new ControlWrap(*dialog));
+               dialog->setView(new QWrap(*dialog));
+               dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+       }
+
+       return dialog;
+}
+
+
+/// Are the tooltips on or off?
+bool Dialogs::tooltipsEnabled()
+{
+       return false;
+}
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/EmptyTable.cpp b/src/frontends/qt4/EmptyTable.cpp
new file mode 100644 (file)
index 0000000..bc233cb
--- /dev/null
@@ -0,0 +1,122 @@
+/**
+ * \file EmptyTable.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "EmptyTable.h"
+
+#include <QPainter>
+#include <QMouseEvent>
+
+/**
+ * A simple widget for a quick "preview" in TabularCreateDialog
+ */
+
+unsigned int const cellsize = 20;
+
+
+EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
+       : QTableWidget(rows, columns, parent)
+{
+       resetCellSize();
+       setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+       setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+       viewport()->resize(cellsize*rows,cellsize*columns);
+}
+
+
+QSize EmptyTable::sizeHint() const
+{
+       return QSize(cellsize * (2+columnCount()), cellsize * (2+rowCount()));
+}
+
+void EmptyTable::resetCellSize()
+{
+       for(int i=0; i<rowCount(); ++i)
+               setRowHeight(i, cellsize);
+       for(int i=0; i<columnCount(); ++i)
+               setColumnWidth(i, cellsize);
+}
+
+void EmptyTable::paintCell(QPainter * p, int row, int col)
+{
+       int const x2 = columnWidth(col) - 1;
+       int const y2 = rowHeight(row) - 1;
+
+       p->fillRect(0, 0, x2, y2, QColor("white"));
+       p->drawLine(x2, 0, x2, y2);
+       p->drawLine(0, y2, x2, y2);
+
+       if (row + 1 != rowCount() || col + 1 != columnCount())
+               return;
+
+       // draw handle
+       int const step = cellsize / 5;
+       int const space = 4;
+       int x = cellsize - step;
+       int const y = cellsize - space;
+       int const ex = cellsize - space;
+       int ey = cellsize - step;
+       while (x > space) {
+               p->drawLine(x, y, ex, ey);
+               x -= step;
+               ey -= step;
+       }
+}
+
+
+void EmptyTable::setNumberColumns(int nr_cols)
+{
+       if (nr_cols < 1)
+               return;
+       if (nr_cols == columnCount())
+               return;
+       setColumnCount(nr_cols);
+       resetCellSize();
+       updateGeometry();
+        // emit signal
+       colsChanged(nr_cols);
+}
+
+
+void EmptyTable::setNumberRows(int nr_rows)
+{
+       if (nr_rows < 1)
+               return;
+       if (nr_rows == rowCount())
+               return;
+       setRowCount(nr_rows);
+       resetCellSize();
+       updateGeometry();
+        // emit signal
+       rowsChanged(nr_rows);
+}
+
+/*
+void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
+{
+       int const x = ev->pos().x();
+       int const y = ev->pos().y();
+
+       if (x > 0)
+               setNumberColumns(x / cellsize + columnCount()-1);
+
+       if (y > 0)
+               setNumberRows(y / cellsize + rowCount()-1);
+}
+*/
+
+#include "EmptyTable_moc.cpp"
+
+
+namespace lyx {
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/EmptyTable.h b/src/frontends/qt4/EmptyTable.h
new file mode 100644 (file)
index 0000000..518ea1c
--- /dev/null
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+/**
+ * \file EmptyTable.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef EMPTYTABLE_H
+#define EMPTYTABLE_H
+
+#include <QTableWidget>
+
+
+class QMouseEvent;
+
+//namespace lyx {
+
+/**
+ * A simple widget for a quick "preview" in TabularCreateDialog.
+ * The user can drag on the widget to change the table dimensions.
+ */
+class EmptyTable : public QTableWidget {
+       Q_OBJECT
+public:
+       EmptyTable(QWidget * parent = 0, int rows = 5, int columns = 5);
+
+       virtual QSize sizeHint() const;
+public Q_SLOTS:
+       /// set the number of columns in the table and emit colsChanged() signal
+       void setNumberColumns(int nr_cols);
+       /// set the number of rows in the table and emit rowsChanged() signal
+       void setNumberRows(int nr_rows);
+Q_SIGNALS:
+       /// the number of columns changed
+       void colsChanged(int);
+       /// the number of rows changed
+       void rowsChanged(int);
+protected:
+       /// fill in a cell
+       virtual void paintCell(class QPainter *, int, int);
+//     virtual void mouseMoveEvent(QMouseEvent *);
+
+       /// Reset all the cell size to default
+       virtual void resetCellSize();
+
+private:
+       /// number of current columns
+       unsigned int cols;
+       /// number of current rows
+       unsigned int rows;
+
+};
+
+
+//} // namespace lyx
+
+#endif
diff --git a/src/frontends/qt4/FileDialog.C b/src/frontends/qt4/FileDialog.C
deleted file mode 100644 (file)
index bee4e6a..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/**
- * \file qt4/FileDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Jean-Marc Lasgouttes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/FileDialog.h"
-
-#include "LyXFileDialog.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-#include "gettext.h"
-
-#include "support/filefilterlist.h"
-#include "support/os.h"
-
-/** when this is defined, the code will use
- * QFileDialog::getOpenFileName and friends to create filedialogs.
- * Effects:
- * - the dialog does not use the quick directory buttons (Button
- *   parameters);
- * - with Qt/Mac or Qt/Win, the dialogs native to the environment are used.
- *
- * Therefore there is a tradeoff in enabling or disabling this (JMarc)
- */
-#ifdef Q_WS_MACX
-#define USE_NATIVE_FILEDIALOG 1
-#endif
-
-#ifdef USE_NATIVE_FILEDIALOG
-#include <qapplication.h>
-#include "support/filetools.h"
-
-using lyx::support::makeAbsPath;
-#endif
-
-namespace lyx {
-
-using support::FileFilterList;
-using support::os::internal_path;
-using std::endl;
-
-
-class FileDialog::Private {
-public:
-       Button b1;
-       Button b2;
-};
-
-
-FileDialog::FileDialog(docstring const & t,
-                      kb_action s, Button b1, Button b2)
-       : private_(new FileDialog::Private), title_(t), success_(s)
-{
-       private_->b1 = b1;
-       private_->b2 = b2;
-}
-
-
-FileDialog::~FileDialog()
-{
-       delete private_;
-}
-
-
-FileDialog::Result const FileDialog::save(docstring const & path,
-                                         FileFilterList const & filters,
-                                         docstring const & suggested)
-{
-       LYXERR(Debug::GUI) << "Select with path \"" << to_utf8(path)
-                          << "\", mask \"" << to_utf8(filters.as_string())
-                          << "\", suggested \"" << to_utf8(suggested) << '"' << endl;
-       FileDialog::Result result;
-       result.first = FileDialog::Chosen;
-
-#ifdef USE_NATIVE_FILEDIALOG
-       docstring const startsWith = from_utf8(
-               makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
-       result.second = from_utf8(internal_path(fromqstr(
-               QFileDialog::getSaveFileName(qApp->focusWidget(),
-               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ))));
-#else
-       LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
-#if QT_VERSION != 0x040203
-       dlg.setFileMode(QFileDialog::AnyFile);
-#endif
-       dlg.setAcceptMode(QFileDialog::AcceptSave);
-       dlg.setConfirmOverwrite(false);
-
-       if (!suggested.empty())
-               dlg.selectFile(toqstr(suggested));
-
-       LYXERR(Debug::GUI) << "Synchronous FileDialog: " << endl;
-       int res = dlg.exec();
-       LYXERR(Debug::GUI) << "result " << res << endl;
-       if (res == QDialog::Accepted)
-               result.second = from_utf8(internal_path(
-                                       fromqstr(dlg.selectedFiles()[0])));
-       dlg.hide();
-#endif
-       return result;
-}
-
-
-FileDialog::Result const FileDialog::open(docstring const & path,
-                                         FileFilterList const & filters,
-                                         docstring const & suggested)
-{
-       LYXERR(Debug::GUI) << "Select with path \"" << to_utf8(path)
-                          << "\", mask \"" << to_utf8(filters.as_string())
-                          << "\", suggested \"" << to_utf8(suggested) << '"' << endl;
-       FileDialog::Result result;
-       result.first = FileDialog::Chosen;
-
-#ifdef USE_NATIVE_FILEDIALOG
-       docstring const startsWith = from_utf8(
-               makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
-       result.second = from_utf8(internal_path(fromqstr(
-               QFileDialog::getOpenFileName(qApp->focusWidget(), 
-               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ))));
-#else
-       LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
-
-       if (!suggested.empty())
-               dlg.selectFile(toqstr(suggested));
-
-       LYXERR(Debug::GUI) << "Synchronous FileDialog: " << endl;
-       int res = dlg.exec();
-       LYXERR(Debug::GUI) << "result " << res << endl;
-       if (res == QDialog::Accepted)
-               result.second = from_utf8(internal_path(
-                                       fromqstr(dlg.selectedFiles()[0])));
-       dlg.hide();
-#endif
-       return result;
-}
-
-
-FileDialog::Result const FileDialog::opendir(docstring const & path,
-                                           docstring const & suggested)
-{
-       LYXERR(Debug::GUI) << "Select with path \"" << to_utf8(path)
-                          << "\", suggested \"" << to_utf8(suggested) << '"' << endl;
-       FileDialog::Result result;
-       result.first = FileDialog::Chosen;
-
-#ifdef USE_NATIVE_FILEDIALOG
-       docstring const startsWith = from_utf8(
-               makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
-       result.second = from_utf8(internal_path(fromqstr(
-               QFileDialog::getExistingDirectory(qApp->focusWidget(),
-               toqstr(title_),toqstr(startsWith)))));
-#else
-       FileFilterList const filter(_("Directories"));
-
-       LyXFileDialog dlg(title_, path, filter, private_->b1, private_->b2);
-
-       dlg.setFileMode(QFileDialog::DirectoryOnly);
-
-       if (!suggested.empty())
-               dlg.selectFile(toqstr(suggested));
-
-       LYXERR(Debug::GUI) << "Synchronous FileDialog: " << endl;
-       int res = dlg.exec();
-       LYXERR(Debug::GUI) << "result " << res << endl;
-       if (res == QDialog::Accepted)
-               result.second = from_utf8(internal_path(
-                                       fromqstr(dlg.selectedFiles()[0])));
-       dlg.hide();
-#endif
-       return result;
-}
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/FileDialog.cpp b/src/frontends/qt4/FileDialog.cpp
new file mode 100644 (file)
index 0000000..bee4e6a
--- /dev/null
@@ -0,0 +1,183 @@
+/**
+ * \file qt4/FileDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "frontends/FileDialog.h"
+
+#include "LyXFileDialog.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+#include "gettext.h"
+
+#include "support/filefilterlist.h"
+#include "support/os.h"
+
+/** when this is defined, the code will use
+ * QFileDialog::getOpenFileName and friends to create filedialogs.
+ * Effects:
+ * - the dialog does not use the quick directory buttons (Button
+ *   parameters);
+ * - with Qt/Mac or Qt/Win, the dialogs native to the environment are used.
+ *
+ * Therefore there is a tradeoff in enabling or disabling this (JMarc)
+ */
+#ifdef Q_WS_MACX
+#define USE_NATIVE_FILEDIALOG 1
+#endif
+
+#ifdef USE_NATIVE_FILEDIALOG
+#include <qapplication.h>
+#include "support/filetools.h"
+
+using lyx::support::makeAbsPath;
+#endif
+
+namespace lyx {
+
+using support::FileFilterList;
+using support::os::internal_path;
+using std::endl;
+
+
+class FileDialog::Private {
+public:
+       Button b1;
+       Button b2;
+};
+
+
+FileDialog::FileDialog(docstring const & t,
+                      kb_action s, Button b1, Button b2)
+       : private_(new FileDialog::Private), title_(t), success_(s)
+{
+       private_->b1 = b1;
+       private_->b2 = b2;
+}
+
+
+FileDialog::~FileDialog()
+{
+       delete private_;
+}
+
+
+FileDialog::Result const FileDialog::save(docstring const & path,
+                                         FileFilterList const & filters,
+                                         docstring const & suggested)
+{
+       LYXERR(Debug::GUI) << "Select with path \"" << to_utf8(path)
+                          << "\", mask \"" << to_utf8(filters.as_string())
+                          << "\", suggested \"" << to_utf8(suggested) << '"' << endl;
+       FileDialog::Result result;
+       result.first = FileDialog::Chosen;
+
+#ifdef USE_NATIVE_FILEDIALOG
+       docstring const startsWith = from_utf8(
+               makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
+       result.second = from_utf8(internal_path(fromqstr(
+               QFileDialog::getSaveFileName(qApp->focusWidget(),
+               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ))));
+#else
+       LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
+#if QT_VERSION != 0x040203
+       dlg.setFileMode(QFileDialog::AnyFile);
+#endif
+       dlg.setAcceptMode(QFileDialog::AcceptSave);
+       dlg.setConfirmOverwrite(false);
+
+       if (!suggested.empty())
+               dlg.selectFile(toqstr(suggested));
+
+       LYXERR(Debug::GUI) << "Synchronous FileDialog: " << endl;
+       int res = dlg.exec();
+       LYXERR(Debug::GUI) << "result " << res << endl;
+       if (res == QDialog::Accepted)
+               result.second = from_utf8(internal_path(
+                                       fromqstr(dlg.selectedFiles()[0])));
+       dlg.hide();
+#endif
+       return result;
+}
+
+
+FileDialog::Result const FileDialog::open(docstring const & path,
+                                         FileFilterList const & filters,
+                                         docstring const & suggested)
+{
+       LYXERR(Debug::GUI) << "Select with path \"" << to_utf8(path)
+                          << "\", mask \"" << to_utf8(filters.as_string())
+                          << "\", suggested \"" << to_utf8(suggested) << '"' << endl;
+       FileDialog::Result result;
+       result.first = FileDialog::Chosen;
+
+#ifdef USE_NATIVE_FILEDIALOG
+       docstring const startsWith = from_utf8(
+               makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
+       result.second = from_utf8(internal_path(fromqstr(
+               QFileDialog::getOpenFileName(qApp->focusWidget(), 
+               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ))));
+#else
+       LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
+
+       if (!suggested.empty())
+               dlg.selectFile(toqstr(suggested));
+
+       LYXERR(Debug::GUI) << "Synchronous FileDialog: " << endl;
+       int res = dlg.exec();
+       LYXERR(Debug::GUI) << "result " << res << endl;
+       if (res == QDialog::Accepted)
+               result.second = from_utf8(internal_path(
+                                       fromqstr(dlg.selectedFiles()[0])));
+       dlg.hide();
+#endif
+       return result;
+}
+
+
+FileDialog::Result const FileDialog::opendir(docstring const & path,
+                                           docstring const & suggested)
+{
+       LYXERR(Debug::GUI) << "Select with path \"" << to_utf8(path)
+                          << "\", suggested \"" << to_utf8(suggested) << '"' << endl;
+       FileDialog::Result result;
+       result.first = FileDialog::Chosen;
+
+#ifdef USE_NATIVE_FILEDIALOG
+       docstring const startsWith = from_utf8(
+               makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
+       result.second = from_utf8(internal_path(fromqstr(
+               QFileDialog::getExistingDirectory(qApp->focusWidget(),
+               toqstr(title_),toqstr(startsWith)))));
+#else
+       FileFilterList const filter(_("Directories"));
+
+       LyXFileDialog dlg(title_, path, filter, private_->b1, private_->b2);
+
+       dlg.setFileMode(QFileDialog::DirectoryOnly);
+
+       if (!suggested.empty())
+               dlg.selectFile(toqstr(suggested));
+
+       LYXERR(Debug::GUI) << "Synchronous FileDialog: " << endl;
+       int res = dlg.exec();
+       LYXERR(Debug::GUI) << "result " << res << endl;
+       if (res == QDialog::Accepted)
+               result.second = from_utf8(internal_path(
+                                       fromqstr(dlg.selectedFiles()[0])));
+       dlg.hide();
+#endif
+       return result;
+}
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/FileDialog_private.C b/src/frontends/qt4/FileDialog_private.C
deleted file mode 100644 (file)
index 0d6652c..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * \file LyXFileDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "LyXFileDialog.h"
-
-#include "qt_helpers.h"
-
-#include "support/filefilterlist.h"
-#include "support/lstrings.h"
-
-#include <QApplication>
-#include <QToolButton>
-#include <QHBoxLayout>
-
-using lyx::support::split;
-using std::string;
-
-namespace lyx {
-
-/// return the Qt form of the label
-static docstring const getLabel(docstring const & ucs4str) {
-       // FIXME UNICODE
-       string str = to_utf8(ucs4str);
-       string label;
-       string sc(split(str, label, '|'));
-       if (sc.length() < 2)
-               return from_utf8(label);
-       string::size_type pos = label.find(sc[1]);
-       if (pos == string::npos)
-               return from_utf8(label);
-       label.insert(pos, 1, '&');
-       return from_utf8(label);
-}
-
-
-LyXFileDialog::LyXFileDialog(docstring const & t,
-                            docstring const & p,
-                            support::FileFilterList const & filters,
-                            FileDialog::Button const & b1,
-                            FileDialog::Button const & b2)
-                                // FIXME replace that with theApp->gui()->currentView()
-       : QFileDialog(qApp->focusWidget(),
-                     toqstr(t), toqstr(p), toqstr(filters.as_string())),
-                     b1_(0), b2_(0)
-{
-       setWindowTitle(toqstr(t));
-
-       QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
-
-       if (!b1.first.empty()) {
-               b1_dir_ = b1.second;
-               b1_ = new QToolButton(this);
-               connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
-               b1_->setText(toqstr(getLabel(b1.first)));
-               layout.at(0)->addWidget(b1_);
-       }
-
-       if (!b2.first.empty()) {
-               b2_dir_ = b2.second;
-               b2_ = new QToolButton(this);
-               connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
-               b2_->setText(toqstr(getLabel(b2.first)));
-               layout.at(0)->addWidget(b2_);
-       }
-}
-
-
-void LyXFileDialog::buttonClicked()
-{
-       if (sender() == b1_)
-               setDirectory(toqstr(b1_dir_));
-       else if (sender() == b2_)
-               setDirectory(toqstr(b2_dir_));
-}
-
-} // namespace lyx
-
-#include "LyXFileDialog_moc.cpp"
-
diff --git a/src/frontends/qt4/FileDialog_private.h b/src/frontends/qt4/FileDialog_private.h
deleted file mode 100644 (file)
index 65e2dd4..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// -*- C++ -*-
-/**
- * \file LyXFileDialog.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LYXFILEDIALOG_H
-#define LYXFILEDIALOG_H
-
-#include "frontends/FileDialog.h"
-
-#include <QFileDialog>
-
-class QToolButton;
-
-namespace lyx {
-
-namespace support { class FileFilterList; }
-
-class LyXFileDialog : public QFileDialog
-{
-       Q_OBJECT
-public:
-       LyXFileDialog(docstring const & title,
-                     docstring const & path,
-                     support::FileFilterList const & filters,
-                     FileDialog::Button const & b1,
-                     FileDialog::Button const & b2);
-public Q_SLOTS:
-       void buttonClicked();
-private:
-       QToolButton * b1_;
-       docstring b1_dir_;
-
-       QToolButton * b2_;
-       docstring b2_dir_;
-};
-
-} // namespace lyx
-
-
-#endif // LYXFILEDIALOG_H
diff --git a/src/frontends/qt4/FloatPlacement.C b/src/frontends/qt4/FloatPlacement.C
deleted file mode 100644 (file)
index fdb1a34..0000000
+++ /dev/null
@@ -1,242 +0,0 @@
-/**
- * \file floatplacement.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "FloatPlacement.h"
-#include "qt_helpers.h"
-
-#include "insets/InsetFloat.h"
-#include "support/lstrings.h"
-
-using lyx::support::contains;
-using std::string;
-
-//namespace lyx {
-
-FloatPlacement::FloatPlacement(QWidget *)
-{
-       setupUi(this);
-
-       connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(defaultsCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-
-       spanCB->hide();
-       sidewaysCB->hide();
-}
-
-
-void FloatPlacement::useWide()
-{
-       spanCB->show();
-}
-
-
-void FloatPlacement::useSideways()
-{
-       sidewaysCB->show();
-}
-
-
-void FloatPlacement::changedSlot()
-{
-       // emit signal
-       changed();
-}
-
-
-void FloatPlacement::set(string const & placement)
-{
-       bool def_placement = false;
-       bool top = false;
-       bool bottom = false;
-       bool page = false;
-       bool here = false;
-       bool force = false;
-       bool here_definitely = false;
-
-       if (placement.empty()) {
-               def_placement = true;
-       } else if (contains(placement, 'H')) {
-               here_definitely = true;
-       } else {
-               if (contains(placement, '!')) {
-                       force = true;
-               }
-               if (contains(placement, 't')) {
-                       top = true;
-               }
-               if (contains(placement, 'b')) {
-                       bottom = true;
-               }
-               if (contains(placement, 'p')) {
-                       page = true;
-               }
-               if (contains(placement, 'h')) {
-                       here = true;
-               }
-       }
-
-       defaultsCB->setChecked(def_placement);
-       topCB->setChecked(top);
-       bottomCB->setChecked(bottom);
-       pageCB->setChecked(page);
-       herepossiblyCB->setChecked(here);
-       ignoreCB->setChecked(force);
-       ignoreCB->setEnabled(top || bottom || page || here);
-       heredefinitelyCB->setChecked(here_definitely);
-       checkAllowed();
-}
-
-
-void FloatPlacement::set(lyx::InsetFloatParams const & params)
-{
-       set(params.placement);
-
-       if (params.wide) {
-               herepossiblyCB->setChecked(false);
-               heredefinitelyCB->setChecked(false);
-               bottomCB->setChecked(false);
-       }
-
-       spanCB->setChecked(params.wide);
-       sidewaysCB->setChecked(params.sideways);
-       sidewaysCB->setEnabled(params.type == "figure"
-               || params.type == "table");
-       checkAllowed();
-}
-
-
-string const FloatPlacement::get(bool & wide, bool & sideways) const
-{
-       wide = spanCB->isChecked();
-       sideways = sidewaysCB->isChecked();
-
-       return get();
-}
-
-
-string const FloatPlacement::get() const
-{
-       string placement;
-
-       if (defaultsCB->isChecked())
-               return placement;
-
-       if (heredefinitelyCB->isChecked()) {
-               placement += 'H';
-       } else {
-               if (ignoreCB->isChecked()) {
-                       placement += '!';
-               }
-               if (topCB->isChecked()) {
-                       placement += 't';
-               }
-               if (bottomCB->isChecked()) {
-                       placement += 'b';
-               }
-               if (pageCB->isChecked()) {
-                       placement += 'p';
-               }
-               if (herepossiblyCB->isChecked()) {
-                       placement += 'h';
-               }
-       }
-       return placement;
-}
-
-
-void FloatPlacement::tbhpClicked()
-{
-       heredefinitelyCB->setChecked(false);
-       checkAllowed();
-}
-
-
-void FloatPlacement::on_heredefinitelyCB_clicked()
-{
-       if (heredefinitelyCB->isChecked())
-               ignoreCB->setEnabled(false);
-
-       topCB->setChecked(false);
-       bottomCB->setChecked(false);
-       pageCB->setChecked(false);
-       herepossiblyCB->setChecked(false);
-       ignoreCB->setChecked(false);
-}
-
-
-void FloatPlacement::on_spanCB_clicked()
-{
-       checkAllowed();
-       changed();
-
-       if (!spanCB->isChecked())
-               return;
-
-       herepossiblyCB->setChecked(false);
-       heredefinitelyCB->setChecked(false);
-       bottomCB->setChecked(false);
-}
-
-
-void FloatPlacement::on_sidewaysCB_clicked()
-{
-       checkAllowed();
-       changed();
-}
-
-
-void FloatPlacement::checkAllowed()
-{
-       bool const defaults = defaultsCB->isChecked();
-       bool ignore = topCB->isChecked();
-       ignore |= bottomCB->isChecked();
-       ignore |= pageCB->isChecked();
-       ignore |= herepossiblyCB->isChecked();
-
-       // float or document dialog?
-       if (spanCB->isVisible()) {
-               bool const span = spanCB->isChecked();
-               bool const sideways = sidewaysCB->isChecked();
-               defaultsCB->setEnabled(!sideways);
-               topCB->setEnabled(!sideways && !defaults);
-               bottomCB->setEnabled(!sideways && !defaults && !span);
-               pageCB->setEnabled(!sideways && !defaults);
-               ignoreCB->setEnabled(!sideways && !defaults && ignore);
-               herepossiblyCB->setEnabled(!sideways && !defaults && !span);
-               heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
-               spanCB->setEnabled(!sideways);
-       } else {
-               topCB->setEnabled(!defaults);
-               bottomCB->setEnabled(!defaults);
-               pageCB->setEnabled(!defaults);
-               ignoreCB->setEnabled(!defaults && ignore);
-               herepossiblyCB->setEnabled(!defaults);
-               heredefinitelyCB->setEnabled(!defaults);
-       }
-}
-
-//} // namespace lyx
-
-#include "FloatPlacement_moc.cpp"
-
-
diff --git a/src/frontends/qt4/FloatPlacement.cpp b/src/frontends/qt4/FloatPlacement.cpp
new file mode 100644 (file)
index 0000000..fdb1a34
--- /dev/null
@@ -0,0 +1,242 @@
+/**
+ * \file floatplacement.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "FloatPlacement.h"
+#include "qt_helpers.h"
+
+#include "insets/InsetFloat.h"
+#include "support/lstrings.h"
+
+using lyx::support::contains;
+using std::string;
+
+//namespace lyx {
+
+FloatPlacement::FloatPlacement(QWidget *)
+{
+       setupUi(this);
+
+       connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
+       connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
+       connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
+       connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
+       connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
+       connect(defaultsCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+
+       spanCB->hide();
+       sidewaysCB->hide();
+}
+
+
+void FloatPlacement::useWide()
+{
+       spanCB->show();
+}
+
+
+void FloatPlacement::useSideways()
+{
+       sidewaysCB->show();
+}
+
+
+void FloatPlacement::changedSlot()
+{
+       // emit signal
+       changed();
+}
+
+
+void FloatPlacement::set(string const & placement)
+{
+       bool def_placement = false;
+       bool top = false;
+       bool bottom = false;
+       bool page = false;
+       bool here = false;
+       bool force = false;
+       bool here_definitely = false;
+
+       if (placement.empty()) {
+               def_placement = true;
+       } else if (contains(placement, 'H')) {
+               here_definitely = true;
+       } else {
+               if (contains(placement, '!')) {
+                       force = true;
+               }
+               if (contains(placement, 't')) {
+                       top = true;
+               }
+               if (contains(placement, 'b')) {
+                       bottom = true;
+               }
+               if (contains(placement, 'p')) {
+                       page = true;
+               }
+               if (contains(placement, 'h')) {
+                       here = true;
+               }
+       }
+
+       defaultsCB->setChecked(def_placement);
+       topCB->setChecked(top);
+       bottomCB->setChecked(bottom);
+       pageCB->setChecked(page);
+       herepossiblyCB->setChecked(here);
+       ignoreCB->setChecked(force);
+       ignoreCB->setEnabled(top || bottom || page || here);
+       heredefinitelyCB->setChecked(here_definitely);
+       checkAllowed();
+}
+
+
+void FloatPlacement::set(lyx::InsetFloatParams const & params)
+{
+       set(params.placement);
+
+       if (params.wide) {
+               herepossiblyCB->setChecked(false);
+               heredefinitelyCB->setChecked(false);
+               bottomCB->setChecked(false);
+       }
+
+       spanCB->setChecked(params.wide);
+       sidewaysCB->setChecked(params.sideways);
+       sidewaysCB->setEnabled(params.type == "figure"
+               || params.type == "table");
+       checkAllowed();
+}
+
+
+string const FloatPlacement::get(bool & wide, bool & sideways) const
+{
+       wide = spanCB->isChecked();
+       sideways = sidewaysCB->isChecked();
+
+       return get();
+}
+
+
+string const FloatPlacement::get() const
+{
+       string placement;
+
+       if (defaultsCB->isChecked())
+               return placement;
+
+       if (heredefinitelyCB->isChecked()) {
+               placement += 'H';
+       } else {
+               if (ignoreCB->isChecked()) {
+                       placement += '!';
+               }
+               if (topCB->isChecked()) {
+                       placement += 't';
+               }
+               if (bottomCB->isChecked()) {
+                       placement += 'b';
+               }
+               if (pageCB->isChecked()) {
+                       placement += 'p';
+               }
+               if (herepossiblyCB->isChecked()) {
+                       placement += 'h';
+               }
+       }
+       return placement;
+}
+
+
+void FloatPlacement::tbhpClicked()
+{
+       heredefinitelyCB->setChecked(false);
+       checkAllowed();
+}
+
+
+void FloatPlacement::on_heredefinitelyCB_clicked()
+{
+       if (heredefinitelyCB->isChecked())
+               ignoreCB->setEnabled(false);
+
+       topCB->setChecked(false);
+       bottomCB->setChecked(false);
+       pageCB->setChecked(false);
+       herepossiblyCB->setChecked(false);
+       ignoreCB->setChecked(false);
+}
+
+
+void FloatPlacement::on_spanCB_clicked()
+{
+       checkAllowed();
+       changed();
+
+       if (!spanCB->isChecked())
+               return;
+
+       herepossiblyCB->setChecked(false);
+       heredefinitelyCB->setChecked(false);
+       bottomCB->setChecked(false);
+}
+
+
+void FloatPlacement::on_sidewaysCB_clicked()
+{
+       checkAllowed();
+       changed();
+}
+
+
+void FloatPlacement::checkAllowed()
+{
+       bool const defaults = defaultsCB->isChecked();
+       bool ignore = topCB->isChecked();
+       ignore |= bottomCB->isChecked();
+       ignore |= pageCB->isChecked();
+       ignore |= herepossiblyCB->isChecked();
+
+       // float or document dialog?
+       if (spanCB->isVisible()) {
+               bool const span = spanCB->isChecked();
+               bool const sideways = sidewaysCB->isChecked();
+               defaultsCB->setEnabled(!sideways);
+               topCB->setEnabled(!sideways && !defaults);
+               bottomCB->setEnabled(!sideways && !defaults && !span);
+               pageCB->setEnabled(!sideways && !defaults);
+               ignoreCB->setEnabled(!sideways && !defaults && ignore);
+               herepossiblyCB->setEnabled(!sideways && !defaults && !span);
+               heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
+               spanCB->setEnabled(!sideways);
+       } else {
+               topCB->setEnabled(!defaults);
+               bottomCB->setEnabled(!defaults);
+               pageCB->setEnabled(!defaults);
+               ignoreCB->setEnabled(!defaults && ignore);
+               herepossiblyCB->setEnabled(!defaults);
+               heredefinitelyCB->setEnabled(!defaults);
+       }
+}
+
+//} // namespace lyx
+
+#include "FloatPlacement_moc.cpp"
+
+
diff --git a/src/frontends/qt4/GuiApplication.C b/src/frontends/qt4/GuiApplication.C
deleted file mode 100644 (file)
index b8011a8..0000000
+++ /dev/null
@@ -1,332 +0,0 @@
-/**
- * \file qt4/GuiApplication.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "GuiApplication.h"
-
-#include "qt_helpers.h"
-#include "QLImage.h"
-#include "socket_callback.h"
-
-#include "frontends/LyXView.h"
-
-#include "graphics/LoaderQueue.h"
-
-#include "support/lstrings.h"
-#include "support/os.h"
-#include "support/package.h"
-
-#include "BufferView.h"
-#include "Color.h"
-#include "debug.h"
-#include "funcrequest.h"
-#include "lyx_main.h"
-#include "lyxfunc.h"
-#include "lyxrc.h"
-
-#include <QApplication>
-#include <QClipboard>
-#include <QEventLoop>
-#include <QFileOpenEvent>
-#include <QLocale>
-#include <QLibraryInfo>
-#include <QTextCodec>
-#include <QTimer>
-#include <QTranslator>
-#include <QWidget>
-
-#ifdef Q_WS_X11
-#include <X11/Xatom.h>
-#include <X11/Xlib.h>
-#endif
-
-#include <boost/bind.hpp>
-
-#include <exception>
-
-using std::string;
-using std::endl;
-
-///////////////////////////////////////////////////////////////
-// You can find other X11 specific stuff
-// at the end of this file...
-///////////////////////////////////////////////////////////////
-
-namespace {
-
-int getDPI()
-{
-       QWidget w;
-       return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
-}
-
-} // namespace anon
-
-
-namespace lyx {
-
-frontend::Application * createApplication(int & argc, char * argv[])
-{
-       return new frontend::GuiApplication(argc, argv);
-}
-
-
-namespace frontend {
-
-GuiApplication * guiApp;
-
-
-GuiApplication::~GuiApplication()
-{
-       socket_callbacks_.clear();
-}
-
-
-GuiApplication::GuiApplication(int & argc, char ** argv)
-       : QApplication(argc, argv), Application(argc, argv)
-{
-       // Qt bug? setQuitOnLastWindowClosed(true); does not work
-       setQuitOnLastWindowClosed(false);
-
-#ifdef Q_WS_X11
-       // doubleClickInterval() is 400 ms on X11 which is just too long.
-       // On Windows and Mac OS X, the operating system's value is used.
-       // On Microsoft Windows, calling this function sets the double
-       // click interval for all applications. So we don't!
-       QApplication::setDoubleClickInterval(300);
-#endif
-
-       // install translation file for Qt built-in dialogs
-       QString language_name = QString("qt_") + QLocale::system().name();
-       language_name.truncate(5);
-       if (qt_trans_.load(language_name,
-               QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
-       {
-               qApp->installTranslator(&qt_trans_);
-               // even if the language calls for RtL, don't do that
-               qApp->setLayoutDirection(Qt::LeftToRight);
-               LYXERR(Debug::GUI)
-                       << "Successfully installed Qt translations for locale "
-                       << fromqstr(language_name) << std::endl;
-       } else
-               LYXERR(Debug::GUI)
-                       << "Could not find  Qt translations for locale "
-                       << fromqstr(language_name) << std::endl;
-
-       using namespace lyx::graphics;
-
-       Image::newImage = boost::bind(&QLImage::newImage);
-       Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
-
-       // needs to be done before reading lyxrc
-       lyxrc.dpi = getDPI();
-
-       LoaderQueue::setPriority(10,100);
-
-       guiApp = this;
-}
-
-
-Clipboard& GuiApplication::clipboard()
-{
-       return clipboard_;
-}
-
-
-Selection& GuiApplication::selection()
-{
-       return selection_;
-}
-
-
-int const GuiApplication::exec()
-{
-       QTimer::singleShot(1, this, SLOT(execBatchCommands()));
-       return QApplication::exec();
-}
-
-
-void GuiApplication::exit(int status)
-{
-       QApplication::exit(status);
-}
-
-
-void GuiApplication::execBatchCommands()
-{
-       LyX::ref().execBatchCommands();
-}
-
-
-string const GuiApplication::romanFontName()
-{
-       QFont font;
-       font.setKerning(false);
-       font.setStyleHint(QFont::Serif);
-       font.setFamily("serif");
-
-       return fromqstr(QFontInfo(font).family());
-}
-
-
-string const GuiApplication::sansFontName()
-{
-       QFont font;
-       font.setKerning(false);
-       font.setStyleHint(QFont::SansSerif);
-       font.setFamily("sans");
-
-       return fromqstr(QFontInfo(font).family());
-}
-
-
-string const GuiApplication::typewriterFontName()
-{
-       QFont font;
-       font.setKerning(false);
-       font.setStyleHint(QFont::TypeWriter);
-       font.setFamily("monospace");
-
-       return fromqstr(QFontInfo(font).family());
-}
-
-
-bool GuiApplication::event(QEvent * e)
-{
-       switch(e->type()) {
-       case QEvent::FileOpen: {
-               // Open a file; this happens only on Mac OS X for now
-               QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
-               lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
-                                         fromqstr(foe->file())));
-               return true;
-       }
-       default:
-               return QApplication::event(e);
-       }
-}
-
-
-bool GuiApplication::notify(QObject * receiver, QEvent * event)
-{
-       bool return_value;
-       try {
-               return_value = QApplication::notify(receiver, event);
-       }
-       catch (std::exception  const & e) {
-               lyxerr << "Caught \"normal\" exception: " << e.what() << endl;
-               LyX::cref().emergencyCleanup();
-               abort();
-       }
-       catch (...) {
-               lyxerr << "Caught some really weird exception..." << endl;
-               LyX::cref().emergencyCleanup();
-               abort();
-       }
-
-       return return_value;
-}
-
-
-void GuiApplication::syncEvents()
-{
-       // This is the ONLY place where processEvents may be called.
-       // During screen update/ redraw, this method is disabled to
-       // prevent keyboard events being handed to the LyX core, where
-       // they could cause re-entrant calls to screen update.
-       processEvents(QEventLoop::ExcludeUserInputEvents);
-}
-
-
-bool GuiApplication::getRgbColor(LColor_color col,
-       RGBColor & rgbcol)
-{
-       QColor const & qcol = color_cache_.get(col);
-       if (!qcol.isValid()) {
-               rgbcol.r = 0;
-               rgbcol.g = 0;
-               rgbcol.b = 0;
-               return false;
-       }
-       rgbcol.r = qcol.red();
-       rgbcol.g = qcol.green();
-       rgbcol.b = qcol.blue();
-       return true;
-}
-
-
-string const GuiApplication::hexName(LColor_color col)
-{
-       return lyx::support::ltrim(fromqstr(color_cache_.get(col).name()), "#");
-}
-
-
-void GuiApplication::updateColor(LColor_color)
-{
-       // FIXME: Bleh, can't we just clear them all at once ?
-       color_cache_.clear();
-}
-
-
-void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
-{
-       socket_callbacks_[fd] =
-               boost::shared_ptr<socket_callback>(new socket_callback(fd, func));
-}
-
-
-void GuiApplication::unregisterSocketCallback(int fd)
-{
-       socket_callbacks_.erase(fd);
-}
-
-////////////////////////////////////////////////////////////////////////
-// X11 specific stuff goes here...
-#ifdef Q_WS_X11
-bool GuiApplication::x11EventFilter(XEvent * xev)
-{
-       if (!currentView())
-               return false;
-
-       switch (xev->type) {
-       case SelectionRequest: {
-               if (xev->xselectionrequest.selection != XA_PRIMARY)
-                       break;
-               LYXERR(Debug::GUI) << "X requested selection." << endl;
-               BufferView * bv = currentView()->view();
-               if (bv) {
-                       docstring const sel = bv->requestSelection();
-                       if (!sel.empty())
-                               selection_.put(sel);
-               }
-               break;
-       }
-       case SelectionClear: {
-               if (xev->xselectionclear.selection != XA_PRIMARY)
-                       break;
-               LYXERR(Debug::GUI) << "Lost selection." << endl;
-               BufferView * bv = currentView()->view();
-               if (bv)
-                       bv->clearSelection();
-               break;
-       }
-       }
-       return false;
-}
-#endif
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "GuiApplication_moc.cpp"
diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp
new file mode 100644 (file)
index 0000000..b8011a8
--- /dev/null
@@ -0,0 +1,332 @@
+/**
+ * \file qt4/GuiApplication.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiApplication.h"
+
+#include "qt_helpers.h"
+#include "QLImage.h"
+#include "socket_callback.h"
+
+#include "frontends/LyXView.h"
+
+#include "graphics/LoaderQueue.h"
+
+#include "support/lstrings.h"
+#include "support/os.h"
+#include "support/package.h"
+
+#include "BufferView.h"
+#include "Color.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "lyx_main.h"
+#include "lyxfunc.h"
+#include "lyxrc.h"
+
+#include <QApplication>
+#include <QClipboard>
+#include <QEventLoop>
+#include <QFileOpenEvent>
+#include <QLocale>
+#include <QLibraryInfo>
+#include <QTextCodec>
+#include <QTimer>
+#include <QTranslator>
+#include <QWidget>
+
+#ifdef Q_WS_X11
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#endif
+
+#include <boost/bind.hpp>
+
+#include <exception>
+
+using std::string;
+using std::endl;
+
+///////////////////////////////////////////////////////////////
+// You can find other X11 specific stuff
+// at the end of this file...
+///////////////////////////////////////////////////////////////
+
+namespace {
+
+int getDPI()
+{
+       QWidget w;
+       return int(0.5 * (w.logicalDpiX() + w.logicalDpiY()));
+}
+
+} // namespace anon
+
+
+namespace lyx {
+
+frontend::Application * createApplication(int & argc, char * argv[])
+{
+       return new frontend::GuiApplication(argc, argv);
+}
+
+
+namespace frontend {
+
+GuiApplication * guiApp;
+
+
+GuiApplication::~GuiApplication()
+{
+       socket_callbacks_.clear();
+}
+
+
+GuiApplication::GuiApplication(int & argc, char ** argv)
+       : QApplication(argc, argv), Application(argc, argv)
+{
+       // Qt bug? setQuitOnLastWindowClosed(true); does not work
+       setQuitOnLastWindowClosed(false);
+
+#ifdef Q_WS_X11
+       // doubleClickInterval() is 400 ms on X11 which is just too long.
+       // On Windows and Mac OS X, the operating system's value is used.
+       // On Microsoft Windows, calling this function sets the double
+       // click interval for all applications. So we don't!
+       QApplication::setDoubleClickInterval(300);
+#endif
+
+       // install translation file for Qt built-in dialogs
+       QString language_name = QString("qt_") + QLocale::system().name();
+       language_name.truncate(5);
+       if (qt_trans_.load(language_name,
+               QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+       {
+               qApp->installTranslator(&qt_trans_);
+               // even if the language calls for RtL, don't do that
+               qApp->setLayoutDirection(Qt::LeftToRight);
+               LYXERR(Debug::GUI)
+                       << "Successfully installed Qt translations for locale "
+                       << fromqstr(language_name) << std::endl;
+       } else
+               LYXERR(Debug::GUI)
+                       << "Could not find  Qt translations for locale "
+                       << fromqstr(language_name) << std::endl;
+
+       using namespace lyx::graphics;
+
+       Image::newImage = boost::bind(&QLImage::newImage);
+       Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
+
+       // needs to be done before reading lyxrc
+       lyxrc.dpi = getDPI();
+
+       LoaderQueue::setPriority(10,100);
+
+       guiApp = this;
+}
+
+
+Clipboard& GuiApplication::clipboard()
+{
+       return clipboard_;
+}
+
+
+Selection& GuiApplication::selection()
+{
+       return selection_;
+}
+
+
+int const GuiApplication::exec()
+{
+       QTimer::singleShot(1, this, SLOT(execBatchCommands()));
+       return QApplication::exec();
+}
+
+
+void GuiApplication::exit(int status)
+{
+       QApplication::exit(status);
+}
+
+
+void GuiApplication::execBatchCommands()
+{
+       LyX::ref().execBatchCommands();
+}
+
+
+string const GuiApplication::romanFontName()
+{
+       QFont font;
+       font.setKerning(false);
+       font.setStyleHint(QFont::Serif);
+       font.setFamily("serif");
+
+       return fromqstr(QFontInfo(font).family());
+}
+
+
+string const GuiApplication::sansFontName()
+{
+       QFont font;
+       font.setKerning(false);
+       font.setStyleHint(QFont::SansSerif);
+       font.setFamily("sans");
+
+       return fromqstr(QFontInfo(font).family());
+}
+
+
+string const GuiApplication::typewriterFontName()
+{
+       QFont font;
+       font.setKerning(false);
+       font.setStyleHint(QFont::TypeWriter);
+       font.setFamily("monospace");
+
+       return fromqstr(QFontInfo(font).family());
+}
+
+
+bool GuiApplication::event(QEvent * e)
+{
+       switch(e->type()) {
+       case QEvent::FileOpen: {
+               // Open a file; this happens only on Mac OS X for now
+               QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
+               lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
+                                         fromqstr(foe->file())));
+               return true;
+       }
+       default:
+               return QApplication::event(e);
+       }
+}
+
+
+bool GuiApplication::notify(QObject * receiver, QEvent * event)
+{
+       bool return_value;
+       try {
+               return_value = QApplication::notify(receiver, event);
+       }
+       catch (std::exception  const & e) {
+               lyxerr << "Caught \"normal\" exception: " << e.what() << endl;
+               LyX::cref().emergencyCleanup();
+               abort();
+       }
+       catch (...) {
+               lyxerr << "Caught some really weird exception..." << endl;
+               LyX::cref().emergencyCleanup();
+               abort();
+       }
+
+       return return_value;
+}
+
+
+void GuiApplication::syncEvents()
+{
+       // This is the ONLY place where processEvents may be called.
+       // During screen update/ redraw, this method is disabled to
+       // prevent keyboard events being handed to the LyX core, where
+       // they could cause re-entrant calls to screen update.
+       processEvents(QEventLoop::ExcludeUserInputEvents);
+}
+
+
+bool GuiApplication::getRgbColor(LColor_color col,
+       RGBColor & rgbcol)
+{
+       QColor const & qcol = color_cache_.get(col);
+       if (!qcol.isValid()) {
+               rgbcol.r = 0;
+               rgbcol.g = 0;
+               rgbcol.b = 0;
+               return false;
+       }
+       rgbcol.r = qcol.red();
+       rgbcol.g = qcol.green();
+       rgbcol.b = qcol.blue();
+       return true;
+}
+
+
+string const GuiApplication::hexName(LColor_color col)
+{
+       return lyx::support::ltrim(fromqstr(color_cache_.get(col).name()), "#");
+}
+
+
+void GuiApplication::updateColor(LColor_color)
+{
+       // FIXME: Bleh, can't we just clear them all at once ?
+       color_cache_.clear();
+}
+
+
+void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
+{
+       socket_callbacks_[fd] =
+               boost::shared_ptr<socket_callback>(new socket_callback(fd, func));
+}
+
+
+void GuiApplication::unregisterSocketCallback(int fd)
+{
+       socket_callbacks_.erase(fd);
+}
+
+////////////////////////////////////////////////////////////////////////
+// X11 specific stuff goes here...
+#ifdef Q_WS_X11
+bool GuiApplication::x11EventFilter(XEvent * xev)
+{
+       if (!currentView())
+               return false;
+
+       switch (xev->type) {
+       case SelectionRequest: {
+               if (xev->xselectionrequest.selection != XA_PRIMARY)
+                       break;
+               LYXERR(Debug::GUI) << "X requested selection." << endl;
+               BufferView * bv = currentView()->view();
+               if (bv) {
+                       docstring const sel = bv->requestSelection();
+                       if (!sel.empty())
+                               selection_.put(sel);
+               }
+               break;
+       }
+       case SelectionClear: {
+               if (xev->xselectionclear.selection != XA_PRIMARY)
+                       break;
+               LYXERR(Debug::GUI) << "Lost selection." << endl;
+               BufferView * bv = currentView()->view();
+               if (bv)
+                       bv->clearSelection();
+               break;
+       }
+       }
+       return false;
+}
+#endif
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "GuiApplication_moc.cpp"
diff --git a/src/frontends/qt4/GuiClipboard.C b/src/frontends/qt4/GuiClipboard.C
deleted file mode 100644 (file)
index dfb4665..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-// -*- C++ -*-
-/**
- * \file qt4/GuiClipboard.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "GuiClipboard.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-
-#include <QApplication>
-#include <QClipboard>
-#include <QMimeData>
-#include <QString>
-
-#include "support/lstrings.h"
-using lyx::support::internalLineEnding;
-using lyx::support::externalLineEnding;
-
-using std::endl;
-using std::string;
-
-static char const * const mime_type = "application/x-lyx";
-
-
-namespace lyx {
-namespace frontend {
-
-string const GuiClipboard::getAsLyX() const
-{
-       LYXERR(Debug::ACTION) << "GuiClipboard::getAsLyX(): `";
-       // We don't convert encodings here since the encoding of the
-       // clipboard contents is specified in the data itself
-       QMimeData const * source =
-               qApp->clipboard()->mimeData(QClipboard::Clipboard);
-       if (!source) {
-               LYXERR(Debug::ACTION) << "' (no QMimeData)" << endl;
-               return string();
-       }
-       if (source->hasFormat(mime_type)) {
-               // data from ourself or some other LyX instance
-               QByteArray const ar = source->data(mime_type);
-               string const s(ar.data(), ar.count());
-               LYXERR(Debug::ACTION) << s << "'" << endl;
-               return s;
-       }
-       LYXERR(Debug::ACTION) << "'" << endl;
-       return string();
-}
-
-
-docstring const GuiClipboard::getAsText() const
-{
-       // text data from other applications
-       QString const str = qApp->clipboard()->text(QClipboard::Clipboard)
-                               .normalized(QString::NormalizationForm_KC);
-       LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `"
-                             << fromqstr(str) << "'" << endl;
-       if (str.isNull())
-               return docstring();
-
-       return internalLineEnding(qstring_to_ucs4(str));
-}
-
-
-void GuiClipboard::put(string const & lyx, docstring const & text)
-{
-       LYXERR(Debug::ACTION) << "GuiClipboard::put(`" << lyx << "' `"
-                             << to_utf8(text) << "')" << endl;
-       // We don't convert the encoding of lyx since the encoding of the
-       // clipboard contents is specified in the data itself
-       QMimeData * data = new QMimeData;
-       if (!lyx.empty()) {
-               QByteArray const qlyx(lyx.c_str(), lyx.size());
-               data->setData(mime_type, qlyx);
-       }
-       // Don't test for text.empty() since we want to be able to clear the
-       // clipboard.
-       QString const qtext = toqstr(text);
-       data->setText(qtext);
-       qApp->clipboard()->setMimeData(data, QClipboard::Clipboard);
-}
-
-
-bool GuiClipboard::hasLyXContents() const
-{
-       QMimeData const * const source =
-               qApp->clipboard()->mimeData(QClipboard::Clipboard);
-       return source && source->hasFormat(mime_type);
-}
-
-
-bool GuiClipboard::isInternal() const
-{
-       // ownsClipboard() is also true for stuff coming from dialogs, e.g.
-       // the preamble dialog
-       // FIXME: This does only work on X11, since ownsClipboard() is
-       // hardwired to return false on Windows and OS X.
-       return qApp->clipboard()->ownsClipboard() && hasLyXContents();
-}
-
-
-bool GuiClipboard::empty() const
-{
-       // We need to check both the plaintext and the LyX version of the
-       // clipboard. The plaintext version is empty if the LyX version
-       // contains only one inset, and the LyX version is empry if the
-       // clipboard does not come from LyX.
-       if (!qApp->clipboard()->text(QClipboard::Clipboard).isEmpty())
-               return false;
-       return !hasLyXContents();
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp
new file mode 100644 (file)
index 0000000..dfb4665
--- /dev/null
@@ -0,0 +1,124 @@
+// -*- C++ -*-
+/**
+ * \file qt4/GuiClipboard.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiClipboard.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include <QApplication>
+#include <QClipboard>
+#include <QMimeData>
+#include <QString>
+
+#include "support/lstrings.h"
+using lyx::support::internalLineEnding;
+using lyx::support::externalLineEnding;
+
+using std::endl;
+using std::string;
+
+static char const * const mime_type = "application/x-lyx";
+
+
+namespace lyx {
+namespace frontend {
+
+string const GuiClipboard::getAsLyX() const
+{
+       LYXERR(Debug::ACTION) << "GuiClipboard::getAsLyX(): `";
+       // We don't convert encodings here since the encoding of the
+       // clipboard contents is specified in the data itself
+       QMimeData const * source =
+               qApp->clipboard()->mimeData(QClipboard::Clipboard);
+       if (!source) {
+               LYXERR(Debug::ACTION) << "' (no QMimeData)" << endl;
+               return string();
+       }
+       if (source->hasFormat(mime_type)) {
+               // data from ourself or some other LyX instance
+               QByteArray const ar = source->data(mime_type);
+               string const s(ar.data(), ar.count());
+               LYXERR(Debug::ACTION) << s << "'" << endl;
+               return s;
+       }
+       LYXERR(Debug::ACTION) << "'" << endl;
+       return string();
+}
+
+
+docstring const GuiClipboard::getAsText() const
+{
+       // text data from other applications
+       QString const str = qApp->clipboard()->text(QClipboard::Clipboard)
+                               .normalized(QString::NormalizationForm_KC);
+       LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `"
+                             << fromqstr(str) << "'" << endl;
+       if (str.isNull())
+               return docstring();
+
+       return internalLineEnding(qstring_to_ucs4(str));
+}
+
+
+void GuiClipboard::put(string const & lyx, docstring const & text)
+{
+       LYXERR(Debug::ACTION) << "GuiClipboard::put(`" << lyx << "' `"
+                             << to_utf8(text) << "')" << endl;
+       // We don't convert the encoding of lyx since the encoding of the
+       // clipboard contents is specified in the data itself
+       QMimeData * data = new QMimeData;
+       if (!lyx.empty()) {
+               QByteArray const qlyx(lyx.c_str(), lyx.size());
+               data->setData(mime_type, qlyx);
+       }
+       // Don't test for text.empty() since we want to be able to clear the
+       // clipboard.
+       QString const qtext = toqstr(text);
+       data->setText(qtext);
+       qApp->clipboard()->setMimeData(data, QClipboard::Clipboard);
+}
+
+
+bool GuiClipboard::hasLyXContents() const
+{
+       QMimeData const * const source =
+               qApp->clipboard()->mimeData(QClipboard::Clipboard);
+       return source && source->hasFormat(mime_type);
+}
+
+
+bool GuiClipboard::isInternal() const
+{
+       // ownsClipboard() is also true for stuff coming from dialogs, e.g.
+       // the preamble dialog
+       // FIXME: This does only work on X11, since ownsClipboard() is
+       // hardwired to return false on Windows and OS X.
+       return qApp->clipboard()->ownsClipboard() && hasLyXContents();
+}
+
+
+bool GuiClipboard::empty() const
+{
+       // We need to check both the plaintext and the LyX version of the
+       // clipboard. The plaintext version is empty if the LyX version
+       // contains only one inset, and the LyX version is empry if the
+       // clipboard does not come from LyX.
+       if (!qApp->clipboard()->text(QClipboard::Clipboard).isEmpty())
+               return false;
+       return !hasLyXContents();
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/GuiFontLoader.C b/src/frontends/qt4/GuiFontLoader.C
deleted file mode 100644 (file)
index f5cc8c9..0000000
+++ /dev/null
@@ -1,321 +0,0 @@
-/**
- * \file GuiFontLoader.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Asger Alstrup
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "GuiFontLoader.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-#include "lyxrc.h"
-
-#include "support/convert.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
-#include "support/systemcall.h"
-
-#include <qfontinfo.h>
-
-#include <boost/tuple/tuple.hpp>
-
-#ifdef Q_WS_X11
-#include <qwidget.h>
-//#include <X11/Xlib.h>
-#include <algorithm>
-#endif
-
-using lyx::support::contains;
-
-using std::endl;
-using std::make_pair;
-
-using std::pair;
-using std::vector;
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-namespace {
-
-struct symbol_font {
-       LyXFont::FONT_FAMILY lyx_family;
-       string family;
-       string xlfd;
-};
-
-symbol_font symbol_fonts[] = {
-       { LyXFont::SYMBOL_FAMILY,
-               "symbol",
-               "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific" },
-
-       { LyXFont::CMR_FAMILY,
-               "cmr10",
-               "-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::CMSY_FAMILY,
-               "cmsy10",
-               "-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::CMM_FAMILY,
-               "cmmi10",
-               "-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::CMEX_FAMILY,
-               "cmex10",
-               "-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::MSA_FAMILY,
-               "msam10",
-               "-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::MSB_FAMILY,
-               "msbm10",
-               "-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::EUFRAK_FAMILY,
-               "eufm10",
-               "-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::WASY_FAMILY,
-               "wasy10",
-               "-*-wasy10-medium-*-*-*-*-*-*-*-*-*-*-*" },
-
-       { LyXFont::ESINT_FAMILY,
-               "esint10",
-               "-*-esint10-medium-*-*-*-*-*-*-*-*-*-*-*" }
-};
-
-size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_font);
-
-
-string getRawName(string const & family)
-{
-       for (size_t i = 0; i < nr_symbol_fonts; ++i)
-               if (family == symbol_fonts[i].family)
-                       return symbol_fonts[i].xlfd;
-
-       LYXERR(Debug::FONT) << "BUG: family not found !" << endl;
-       return string();
-}
-
-
-string const symbolFamily(LyXFont::FONT_FAMILY family)
-{
-       for (size_t i = 0; i < nr_symbol_fonts; ++i) {
-               if (family == symbol_fonts[i].lyx_family)
-                       return symbol_fonts[i].family;
-       }
-       return string();
-}
-
-
-bool isSymbolFamily(LyXFont::FONT_FAMILY family)
-{
-       return family >= LyXFont::SYMBOL_FAMILY &&
-              family <= LyXFont::ESINT_FAMILY;
-}
-
-
-bool isChosenFont(QFont & font, string const & family)
-{
-       // QFontInfo won't find a font that has only a few glyphs at unusual
-       // positions, e.g. the original esint10 font.
-       // The workaround is to add dummy glyphs at least at all ASCII
-       // positions.
-       QFontInfo fi(font);
-
-       LYXERR(Debug::FONT) << "got: " << fromqstr(fi.family()) << endl;
-
-       if (contains(fromqstr(fi.family()), family)) {
-               LYXERR(Debug::FONT) << " got it ";
-               return true;
-       }
-
-       return false;
-}
-
-
-pair<QFont, bool> const getSymbolFont(string const & family)
-{
-       LYXERR(Debug::FONT) << "Looking for font family "
-               << family << " ... ";
-       string upper = family;
-       upper[0] = toupper(family[0]);
-
-       QFont font;
-       font.setKerning(false);
-       font.setFamily(toqstr(family));
-
-       if (isChosenFont(font, family)) {
-               LYXERR(Debug::FONT) << "normal!" << endl;
-               return make_pair<QFont, bool>(font, true);
-       }
-
-       LYXERR(Debug::FONT) << "Trying " << upper << " ... ";
-       font.setFamily(toqstr(upper));
-
-       if (isChosenFont(font, upper)) {
-               LYXERR(Debug::FONT) << "upper!" << endl;
-               return make_pair<QFont, bool>(font, true);
-       }
-
-       // A simple setFamily() fails on Qt 2
-
-       string const rawName = getRawName(family);
-       LYXERR(Debug::FONT) << "Trying " << rawName << " ... ";
-       font.setRawName(toqstr(rawName));
-
-       if (isChosenFont(font, family)) {
-               LYXERR(Debug::FONT) << "raw version!" << endl;
-               return make_pair<QFont, bool>(font, true);
-       }
-
-       LYXERR(Debug::FONT) << " FAILED :-(" << endl;
-       return make_pair<QFont, bool>(font, false);
-}
-
-} // namespace anon
-
-
-GuiFontLoader::GuiFontLoader()
-{
-       for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
-               for (int i2 = 0; i2 < 2; ++i2)
-                       for (int i3 = 0; i3 < 4; ++i3)
-                               for (int i4 = 0; i4 < 10; ++i4)
-                                       fontinfo_[i1][i2][i3][i4] = 0;
-}
-
-
-void GuiFontLoader::update()
-{
-       for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
-               for (int i2 = 0; i2 < 2; ++i2)
-                       for (int i3 = 0; i3 < 4; ++i3)
-                               for (int i4 = 0; i4 < 10; ++i4) {
-                                       delete fontinfo_[i1][i2][i3][i4];
-                                       fontinfo_[i1][i2][i3][i4] = 0;
-                               }
-}
-
-
-/////////////////////////////////////////////////
-
-
-QLFontInfo::QLFontInfo(LyXFont const & f)
-{
-       font.setKerning(false);
-       string const pat = symbolFamily(f.family());
-       if (!pat.empty()) {
-               bool tmp;
-               boost::tie(font, tmp) = getSymbolFont(pat);
-       } else {
-               switch (f.family()) {
-               case LyXFont::ROMAN_FAMILY:
-                       font.setFamily(toqstr(makeFontName(lyxrc.roman_font_name,
-                                                   lyxrc.roman_font_foundry)));
-                       break;
-               case LyXFont::SANS_FAMILY:
-                       font.setFamily(toqstr(makeFontName(lyxrc.sans_font_name,
-                                                   lyxrc.sans_font_foundry)));
-                       break;
-               case LyXFont::TYPEWRITER_FAMILY:
-                       font.setFamily(toqstr(makeFontName(lyxrc.typewriter_font_name,
-                                                   lyxrc.typewriter_font_foundry)));
-                       break;
-               default:
-                       break;
-               }
-       }
-
-       switch (f.series()) {
-               case LyXFont::MEDIUM_SERIES:
-                       font.setWeight(QFont::Normal);
-                       break;
-               case LyXFont::BOLD_SERIES:
-                       font.setWeight(QFont::Bold);
-                       break;
-               default:
-                       break;
-       }
-
-       switch (f.realShape()) {
-               case LyXFont::ITALIC_SHAPE:
-               case LyXFont::SLANTED_SHAPE:
-                       font.setItalic(true);
-                       break;
-               default:
-                       break;
-       }
-
-       LYXERR(Debug::FONT) << "Font '" << to_utf8(f.stateText(0))
-               << "' matched by\n" << fromqstr(font.family()) << endl;
-
-       // Is this an exact match?
-       if (font.exactMatch())
-               LYXERR(Debug::FONT) << "This font is an exact match" << endl;
-       else
-               LYXERR(Debug::FONT) << "This font is NOT an exact match"
-                                   << endl;
-
-       LYXERR(Debug::FONT) << "XFLD: " << fromqstr(font.rawName()) << endl;
-
-       font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
-                              * lyxrc.zoom / 100.0);
-
-       LYXERR(Debug::FONT) << "The font has size: "
-                           << font.pointSizeF() << endl;
-
-       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               metrics.reset(new GuiFontMetrics(font));
-       }
-       else {  
-               // handle small caps ourselves ...
-               LyXFont smallfont = f;
-               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
-               QFont font2(font);
-               font2.setKerning(false);
-               font2.setPointSizeF(convert<double>(lyxrc.font_sizes[smallfont.size()])
-                              * lyxrc.zoom / 100.0);
-
-               metrics.reset(new GuiFontMetrics(font, font2));
-       }
-
-}
-
-
-bool GuiFontLoader::available(LyXFont const & f)
-{
-       static vector<int> cache_set(LyXFont::NUM_FAMILIES, false);
-       static vector<int> cache(LyXFont::NUM_FAMILIES, false);
-
-       LyXFont::FONT_FAMILY family = f.family();
-       if (cache_set[family])
-               return cache[family];
-       cache_set[family] = true;
-
-       string const pat = symbolFamily(family);
-       if (pat.empty())
-               // We don't care about non-symbol fonts
-               return false;
-
-       pair<QFont, bool> tmp = getSymbolFont(pat);
-       if (!tmp.second)
-               return false;
-
-       cache[family] = true;
-       return true;
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/GuiFontLoader.cpp b/src/frontends/qt4/GuiFontLoader.cpp
new file mode 100644 (file)
index 0000000..f5cc8c9
--- /dev/null
@@ -0,0 +1,321 @@
+/**
+ * \file GuiFontLoader.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Asger Alstrup
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiFontLoader.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+#include "lyxrc.h"
+
+#include "support/convert.h"
+#include "support/filetools.h"
+#include "support/lstrings.h"
+#include "support/systemcall.h"
+
+#include <qfontinfo.h>
+
+#include <boost/tuple/tuple.hpp>
+
+#ifdef Q_WS_X11
+#include <qwidget.h>
+//#include <X11/Xlib.h>
+#include <algorithm>
+#endif
+
+using lyx::support::contains;
+
+using std::endl;
+using std::make_pair;
+
+using std::pair;
+using std::vector;
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+namespace {
+
+struct symbol_font {
+       LyXFont::FONT_FAMILY lyx_family;
+       string family;
+       string xlfd;
+};
+
+symbol_font symbol_fonts[] = {
+       { LyXFont::SYMBOL_FAMILY,
+               "symbol",
+               "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific" },
+
+       { LyXFont::CMR_FAMILY,
+               "cmr10",
+               "-*-cmr10-medium-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::CMSY_FAMILY,
+               "cmsy10",
+               "-*-cmsy10-*-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::CMM_FAMILY,
+               "cmmi10",
+               "-*-cmmi10-medium-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::CMEX_FAMILY,
+               "cmex10",
+               "-*-cmex10-*-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::MSA_FAMILY,
+               "msam10",
+               "-*-msam10-*-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::MSB_FAMILY,
+               "msbm10",
+               "-*-msbm10-*-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::EUFRAK_FAMILY,
+               "eufm10",
+               "-*-eufm10-medium-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::WASY_FAMILY,
+               "wasy10",
+               "-*-wasy10-medium-*-*-*-*-*-*-*-*-*-*-*" },
+
+       { LyXFont::ESINT_FAMILY,
+               "esint10",
+               "-*-esint10-medium-*-*-*-*-*-*-*-*-*-*-*" }
+};
+
+size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_font);
+
+
+string getRawName(string const & family)
+{
+       for (size_t i = 0; i < nr_symbol_fonts; ++i)
+               if (family == symbol_fonts[i].family)
+                       return symbol_fonts[i].xlfd;
+
+       LYXERR(Debug::FONT) << "BUG: family not found !" << endl;
+       return string();
+}
+
+
+string const symbolFamily(LyXFont::FONT_FAMILY family)
+{
+       for (size_t i = 0; i < nr_symbol_fonts; ++i) {
+               if (family == symbol_fonts[i].lyx_family)
+                       return symbol_fonts[i].family;
+       }
+       return string();
+}
+
+
+bool isSymbolFamily(LyXFont::FONT_FAMILY family)
+{
+       return family >= LyXFont::SYMBOL_FAMILY &&
+              family <= LyXFont::ESINT_FAMILY;
+}
+
+
+bool isChosenFont(QFont & font, string const & family)
+{
+       // QFontInfo won't find a font that has only a few glyphs at unusual
+       // positions, e.g. the original esint10 font.
+       // The workaround is to add dummy glyphs at least at all ASCII
+       // positions.
+       QFontInfo fi(font);
+
+       LYXERR(Debug::FONT) << "got: " << fromqstr(fi.family()) << endl;
+
+       if (contains(fromqstr(fi.family()), family)) {
+               LYXERR(Debug::FONT) << " got it ";
+               return true;
+       }
+
+       return false;
+}
+
+
+pair<QFont, bool> const getSymbolFont(string const & family)
+{
+       LYXERR(Debug::FONT) << "Looking for font family "
+               << family << " ... ";
+       string upper = family;
+       upper[0] = toupper(family[0]);
+
+       QFont font;
+       font.setKerning(false);
+       font.setFamily(toqstr(family));
+
+       if (isChosenFont(font, family)) {
+               LYXERR(Debug::FONT) << "normal!" << endl;
+               return make_pair<QFont, bool>(font, true);
+       }
+
+       LYXERR(Debug::FONT) << "Trying " << upper << " ... ";
+       font.setFamily(toqstr(upper));
+
+       if (isChosenFont(font, upper)) {
+               LYXERR(Debug::FONT) << "upper!" << endl;
+               return make_pair<QFont, bool>(font, true);
+       }
+
+       // A simple setFamily() fails on Qt 2
+
+       string const rawName = getRawName(family);
+       LYXERR(Debug::FONT) << "Trying " << rawName << " ... ";
+       font.setRawName(toqstr(rawName));
+
+       if (isChosenFont(font, family)) {
+               LYXERR(Debug::FONT) << "raw version!" << endl;
+               return make_pair<QFont, bool>(font, true);
+       }
+
+       LYXERR(Debug::FONT) << " FAILED :-(" << endl;
+       return make_pair<QFont, bool>(font, false);
+}
+
+} // namespace anon
+
+
+GuiFontLoader::GuiFontLoader()
+{
+       for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
+               for (int i2 = 0; i2 < 2; ++i2)
+                       for (int i3 = 0; i3 < 4; ++i3)
+                               for (int i4 = 0; i4 < 10; ++i4)
+                                       fontinfo_[i1][i2][i3][i4] = 0;
+}
+
+
+void GuiFontLoader::update()
+{
+       for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
+               for (int i2 = 0; i2 < 2; ++i2)
+                       for (int i3 = 0; i3 < 4; ++i3)
+                               for (int i4 = 0; i4 < 10; ++i4) {
+                                       delete fontinfo_[i1][i2][i3][i4];
+                                       fontinfo_[i1][i2][i3][i4] = 0;
+                               }
+}
+
+
+/////////////////////////////////////////////////
+
+
+QLFontInfo::QLFontInfo(LyXFont const & f)
+{
+       font.setKerning(false);
+       string const pat = symbolFamily(f.family());
+       if (!pat.empty()) {
+               bool tmp;
+               boost::tie(font, tmp) = getSymbolFont(pat);
+       } else {
+               switch (f.family()) {
+               case LyXFont::ROMAN_FAMILY:
+                       font.setFamily(toqstr(makeFontName(lyxrc.roman_font_name,
+                                                   lyxrc.roman_font_foundry)));
+                       break;
+               case LyXFont::SANS_FAMILY:
+                       font.setFamily(toqstr(makeFontName(lyxrc.sans_font_name,
+                                                   lyxrc.sans_font_foundry)));
+                       break;
+               case LyXFont::TYPEWRITER_FAMILY:
+                       font.setFamily(toqstr(makeFontName(lyxrc.typewriter_font_name,
+                                                   lyxrc.typewriter_font_foundry)));
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       switch (f.series()) {
+               case LyXFont::MEDIUM_SERIES:
+                       font.setWeight(QFont::Normal);
+                       break;
+               case LyXFont::BOLD_SERIES:
+                       font.setWeight(QFont::Bold);
+                       break;
+               default:
+                       break;
+       }
+
+       switch (f.realShape()) {
+               case LyXFont::ITALIC_SHAPE:
+               case LyXFont::SLANTED_SHAPE:
+                       font.setItalic(true);
+                       break;
+               default:
+                       break;
+       }
+
+       LYXERR(Debug::FONT) << "Font '" << to_utf8(f.stateText(0))
+               << "' matched by\n" << fromqstr(font.family()) << endl;
+
+       // Is this an exact match?
+       if (font.exactMatch())
+               LYXERR(Debug::FONT) << "This font is an exact match" << endl;
+       else
+               LYXERR(Debug::FONT) << "This font is NOT an exact match"
+                                   << endl;
+
+       LYXERR(Debug::FONT) << "XFLD: " << fromqstr(font.rawName()) << endl;
+
+       font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
+                              * lyxrc.zoom / 100.0);
+
+       LYXERR(Debug::FONT) << "The font has size: "
+                           << font.pointSizeF() << endl;
+
+       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               metrics.reset(new GuiFontMetrics(font));
+       }
+       else {  
+               // handle small caps ourselves ...
+               LyXFont smallfont = f;
+               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
+               QFont font2(font);
+               font2.setKerning(false);
+               font2.setPointSizeF(convert<double>(lyxrc.font_sizes[smallfont.size()])
+                              * lyxrc.zoom / 100.0);
+
+               metrics.reset(new GuiFontMetrics(font, font2));
+       }
+
+}
+
+
+bool GuiFontLoader::available(LyXFont const & f)
+{
+       static vector<int> cache_set(LyXFont::NUM_FAMILIES, false);
+       static vector<int> cache(LyXFont::NUM_FAMILIES, false);
+
+       LyXFont::FONT_FAMILY family = f.family();
+       if (cache_set[family])
+               return cache[family];
+       cache_set[family] = true;
+
+       string const pat = symbolFamily(family);
+       if (pat.empty())
+               // We don't care about non-symbol fonts
+               return false;
+
+       pair<QFont, bool> tmp = getSymbolFont(pat);
+       if (!tmp.second)
+               return false;
+
+       cache[family] = true;
+       return true;
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C
deleted file mode 100644 (file)
index cf38d4d..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-/**
- * \file GuiFontMetrics.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "GuiFontMetrics.h"
-
-#include "qt_helpers.h"
-
-#include "language.h"
-#include "dimension.h"
-
-#include "support/unicode.h"
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-GuiFontMetrics::GuiFontMetrics(QFont const & font)
-: metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false)
-{
-}
-
-
-GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font)
-: metrics_(font), smallcaps_metrics_(smallcaps_font), smallcaps_shape_(true)
-{
-}
-
-
-int GuiFontMetrics::maxAscent() const
-{
-       return metrics_.ascent();
-}
-
-
-int GuiFontMetrics::maxDescent() const
-{
-       // We add 1 as the value returned by QT is different than X
-       // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
-       return metrics_.descent() + 1;
-}
-
-
-int GuiFontMetrics::lbearing(char_type c) const
-{
-       return metrics_.leftBearing(ucs4_to_qchar(c));
-}
-
-
-int GuiFontMetrics::rbearing(char_type c) const
-{
-       if (!rbearing_cache_.contains(c)) {
-               // Qt rbearing is from the right edge of the char's width().
-               QChar sc = ucs4_to_qchar(c);
-               int rb = metrics_.width(sc) - metrics_.rightBearing(sc);
-               rbearing_cache_.insert(c, rb);
-       }
-       return rbearing_cache_.value(c);
-}
-
-
-int GuiFontMetrics::smallcapsWidth(QString const & s) const
-{
-       int w = 0;
-       int const ls = s.size();
-
-       for (int i = 0; i < ls; ++i) {
-               QChar const & c = s[i];
-               QChar const uc = c.toUpper();
-               if (c != uc)
-                       w += smallcaps_metrics_.width(uc);
-               else
-                       w += metrics_.width(c);
-       }
-       return w;
-}
-
-
-int GuiFontMetrics::width(docstring const & s) const
-{
-       size_t ls = s.size();
-       if (ls == 0)
-               return 0;
-
-       if (ls == 1 && !smallcaps_shape_) {
-               return width(s[0]);
-       }
-
-       if (smallcaps_shape_)
-               // Caution: The following ucs4 to QString conversions work
-               // for symbol fonts only because they are no real conversions
-               // but simple casts in reality. See comment in QLPainter::text()
-               // for more explanation.
-               return smallcapsWidth(toqstr(s));
-
-       int w = 0;
-       for (unsigned int i = 0; i < ls; ++i)
-               w += width(s[i]);
-
-       return w;
-}
-
-
-int GuiFontMetrics::width(QString const & ucs2) const
-{
-       int const ls = ucs2.size();
-       if (ls == 1 && !smallcaps_shape_) {
-               return width(ucs2[0].unicode());
-       }
-
-       if (smallcaps_shape_)
-               return smallcapsWidth(ucs2);
-
-       int w = 0;
-       for (int i = 0; i < ls; ++i)
-               w += width(ucs2[i].unicode());
-
-       return w;
-}
-
-
-int GuiFontMetrics::signedWidth(docstring const & s) const
-{
-       if (s.empty())
-               return 0;
-
-       if (s[0] == '-')
-               return -width(s.substr(1, s.size() - 1));
-       else
-               return width(s);
-}
-
-
-void GuiFontMetrics::rectText(docstring const & str,
-       int & w, int & ascent, int & descent) const
-{
-       static int const d = 2;
-       w = width(str) + d * 2 + 2;
-       ascent = metrics_.ascent() + d;
-       descent = metrics_.descent() + d;
-}
-
-
-
-void GuiFontMetrics::buttonText(docstring const & str,
-       int & w, int & ascent, int & descent) const
-{
-       static int const d = 3;
-       w = width(str) + d * 2 + 2;
-       ascent = metrics_.ascent() + d;
-       descent = metrics_.descent() + d;
-}
-
-
-Dimension const GuiFontMetrics::defaultDimension() const
-{
-       return Dimension(0, maxAscent(), maxDescent());
-}
-
-
-Dimension const GuiFontMetrics::dimension(char_type c) const
-{
-       return Dimension(width(c), ascent(c), descent(c));
-}
-
-
-void GuiFontMetrics::fillMetricsCache(char_type c) const
-{
-       QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
-       AscendDescend ad = { -r.top(), r.bottom() + 1};
-       // We could as well compute the width but this is not really
-       // needed for now as it is done directly in width() below.
-       metrics_cache_.insert(c, ad);
-}
-
-
-int GuiFontMetrics::width(char_type c) const
-{
-       if (smallcaps_shape_)
-               return smallcapsWidth(ucs4_to_qchar(c));
-
-       if (!width_cache_.contains(c)) {
-               width_cache_.insert(c, metrics_.width(ucs4_to_qchar(c)));
-       }
-
-       return width_cache_.value(c);
-}
-
-
-int GuiFontMetrics::ascent(char_type c) const
-{
-       if (!metrics_cache_.contains(c))
-               fillMetricsCache(c);
-
-       return metrics_cache_.value(c).ascent;
-}
-
-
-int GuiFontMetrics::descent(char_type c) const
-{
-       if (!metrics_cache_.contains(c))
-               fillMetricsCache(c);
-
-       return metrics_cache_.value(c).descent;
-}
-
-} // frontend
-} // lyx
diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp
new file mode 100644 (file)
index 0000000..cf38d4d
--- /dev/null
@@ -0,0 +1,218 @@
+/**
+ * \file GuiFontMetrics.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiFontMetrics.h"
+
+#include "qt_helpers.h"
+
+#include "language.h"
+#include "dimension.h"
+
+#include "support/unicode.h"
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+GuiFontMetrics::GuiFontMetrics(QFont const & font)
+: metrics_(font), smallcaps_metrics_(font), smallcaps_shape_(false)
+{
+}
+
+
+GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font)
+: metrics_(font), smallcaps_metrics_(smallcaps_font), smallcaps_shape_(true)
+{
+}
+
+
+int GuiFontMetrics::maxAscent() const
+{
+       return metrics_.ascent();
+}
+
+
+int GuiFontMetrics::maxDescent() const
+{
+       // We add 1 as the value returned by QT is different than X
+       // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
+       return metrics_.descent() + 1;
+}
+
+
+int GuiFontMetrics::lbearing(char_type c) const
+{
+       return metrics_.leftBearing(ucs4_to_qchar(c));
+}
+
+
+int GuiFontMetrics::rbearing(char_type c) const
+{
+       if (!rbearing_cache_.contains(c)) {
+               // Qt rbearing is from the right edge of the char's width().
+               QChar sc = ucs4_to_qchar(c);
+               int rb = metrics_.width(sc) - metrics_.rightBearing(sc);
+               rbearing_cache_.insert(c, rb);
+       }
+       return rbearing_cache_.value(c);
+}
+
+
+int GuiFontMetrics::smallcapsWidth(QString const & s) const
+{
+       int w = 0;
+       int const ls = s.size();
+
+       for (int i = 0; i < ls; ++i) {
+               QChar const & c = s[i];
+               QChar const uc = c.toUpper();
+               if (c != uc)
+                       w += smallcaps_metrics_.width(uc);
+               else
+                       w += metrics_.width(c);
+       }
+       return w;
+}
+
+
+int GuiFontMetrics::width(docstring const & s) const
+{
+       size_t ls = s.size();
+       if (ls == 0)
+               return 0;
+
+       if (ls == 1 && !smallcaps_shape_) {
+               return width(s[0]);
+       }
+
+       if (smallcaps_shape_)
+               // Caution: The following ucs4 to QString conversions work
+               // for symbol fonts only because they are no real conversions
+               // but simple casts in reality. See comment in QLPainter::text()
+               // for more explanation.
+               return smallcapsWidth(toqstr(s));
+
+       int w = 0;
+       for (unsigned int i = 0; i < ls; ++i)
+               w += width(s[i]);
+
+       return w;
+}
+
+
+int GuiFontMetrics::width(QString const & ucs2) const
+{
+       int const ls = ucs2.size();
+       if (ls == 1 && !smallcaps_shape_) {
+               return width(ucs2[0].unicode());
+       }
+
+       if (smallcaps_shape_)
+               return smallcapsWidth(ucs2);
+
+       int w = 0;
+       for (int i = 0; i < ls; ++i)
+               w += width(ucs2[i].unicode());
+
+       return w;
+}
+
+
+int GuiFontMetrics::signedWidth(docstring const & s) const
+{
+       if (s.empty())
+               return 0;
+
+       if (s[0] == '-')
+               return -width(s.substr(1, s.size() - 1));
+       else
+               return width(s);
+}
+
+
+void GuiFontMetrics::rectText(docstring const & str,
+       int & w, int & ascent, int & descent) const
+{
+       static int const d = 2;
+       w = width(str) + d * 2 + 2;
+       ascent = metrics_.ascent() + d;
+       descent = metrics_.descent() + d;
+}
+
+
+
+void GuiFontMetrics::buttonText(docstring const & str,
+       int & w, int & ascent, int & descent) const
+{
+       static int const d = 3;
+       w = width(str) + d * 2 + 2;
+       ascent = metrics_.ascent() + d;
+       descent = metrics_.descent() + d;
+}
+
+
+Dimension const GuiFontMetrics::defaultDimension() const
+{
+       return Dimension(0, maxAscent(), maxDescent());
+}
+
+
+Dimension const GuiFontMetrics::dimension(char_type c) const
+{
+       return Dimension(width(c), ascent(c), descent(c));
+}
+
+
+void GuiFontMetrics::fillMetricsCache(char_type c) const
+{
+       QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
+       AscendDescend ad = { -r.top(), r.bottom() + 1};
+       // We could as well compute the width but this is not really
+       // needed for now as it is done directly in width() below.
+       metrics_cache_.insert(c, ad);
+}
+
+
+int GuiFontMetrics::width(char_type c) const
+{
+       if (smallcaps_shape_)
+               return smallcapsWidth(ucs4_to_qchar(c));
+
+       if (!width_cache_.contains(c)) {
+               width_cache_.insert(c, metrics_.width(ucs4_to_qchar(c)));
+       }
+
+       return width_cache_.value(c);
+}
+
+
+int GuiFontMetrics::ascent(char_type c) const
+{
+       if (!metrics_cache_.contains(c))
+               fillMetricsCache(c);
+
+       return metrics_cache_.value(c).ascent;
+}
+
+
+int GuiFontMetrics::descent(char_type c) const
+{
+       if (!metrics_cache_.contains(c))
+               fillMetricsCache(c);
+
+       return metrics_cache_.value(c).descent;
+}
+
+} // frontend
+} // lyx
diff --git a/src/frontends/qt4/GuiImplementation.C b/src/frontends/qt4/GuiImplementation.C
deleted file mode 100644 (file)
index 18ae534..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-// -*- C++ -*-
-/**
- * \file GuiImplementation.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-// This include must be declared before everything else because
-// of boost/Qt/LyX clash...
-#include "GuiView.h"
-
-#include "GuiImplementation.h"
-#include "GuiWorkArea.h"
-
-#include "BufferView.h"
-#include "bufferlist.h"
-#include "funcrequest.h"
-#include "lyxfunc.h"
-
-#include <QApplication>
-
-using boost::shared_ptr;
-
-
-namespace
-{
-       template<class T>
-       void updateIds(std::map<int, T*> const & stdmap, std::vector<int> & ids) 
-       {
-               ids.clear();
-               typename std::map<int, T*>::const_iterator it;
-               for (it = stdmap.begin(); it != stdmap.end(); ++it)
-                       ids.push_back(it->first);
-       }
-}
-
-
-namespace lyx {
-namespace frontend {
-
-
-GuiImplementation::GuiImplementation()
-{
-       view_ids_.clear();
-       work_area_ids_.clear();
-}
-
-
-LyXView& GuiImplementation::createRegisteredView()
-{
-       updateIds(views_, view_ids_);
-       int id = 0;
-       while (views_.find(id) != views_.end())
-               id++;
-       views_.insert(std::pair<int, GuiView *>(id, new GuiView(id)));
-       updateIds(views_, view_ids_);
-       return *views_[id];
-}
-
-
-bool GuiImplementation::unregisterView(int id)
-{
-       updateIds(views_, view_ids_);
-       BOOST_ASSERT(views_.find(id) != views_.end());
-       BOOST_ASSERT(views_[id]);
-
-       std::map<int, GuiView *>::iterator it;
-       for (it = views_.begin(); it != views_.end(); ++it) {
-               if (it->first == id) {
-                       std::vector<int> const & wa_ids = it->second->workAreaIds();
-                       for (size_t i = 0; i < wa_ids.size(); ++i)
-                               work_areas_.erase(wa_ids[i]);
-                       views_.erase(id);
-                       break;
-               }
-       }
-       updateIds(views_, view_ids_);
-       return true;
-}
-
-
-bool GuiImplementation::closeAllViews()
-{
-       updateIds(views_, view_ids_);
-       if (views_.empty())
-       {
-               // quit in CloseEvent will not be triggert
-               qApp->quit();
-               return true;
-       }
-
-       std::map<int, GuiView*> const cmap = views_;
-       std::map<int, GuiView*>::const_iterator it;
-       for (it = cmap.begin(); it != cmap.end(); ++it)
-       {
-               // TODO: return false when close event was ignored
-               //       e.g. quitWriteAll()->'Cancel'
-               //       maybe we need something like 'bool closeView()'
-               it->second->close(); 
-               // unregisterd by the CloseEvent
-       }
-
-       views_.clear();
-       work_areas_.clear();
-       view_ids_.clear();
-       work_area_ids_.clear();
-       return true;
-}
-
-
-LyXView& GuiImplementation::view(int id) const
-{
-       BOOST_ASSERT(views_.find(id) != views_.end());
-       return *views_.find(id)->second;
-}
-
-
-std::vector<int> const & GuiImplementation::workAreaIds()
-{
-       updateIds(work_areas_, work_area_ids_);
-       return work_area_ids_;
-}
-
-
-int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
-{
-       updateIds(views_, view_ids_);
-       int id = 0;
-       while (work_areas_.find(id) != work_areas_.end())
-               id++;
-
-       GuiView * view = views_[view_id];
-
-       work_areas_.insert(std::pair<int, GuiWorkArea *>
-                                       (id, new GuiWorkArea(w, h, id, *view)));
-
-       // FIXME BufferView creation should be independant of WorkArea creation
-       buffer_views_[id].reset(new BufferView);
-       work_areas_[id]->setBufferView(buffer_views_[id].get());
-
-       view->setWorkArea(work_areas_[id]);
-       view->initTab(work_areas_[id]);
-
-       return id;
-}
-
-
-WorkArea& GuiImplementation::workArea(int id)
-{
-       BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
-       return *work_areas_[id];
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "GuiImplementation_moc.cpp"
diff --git a/src/frontends/qt4/GuiImplementation.cpp b/src/frontends/qt4/GuiImplementation.cpp
new file mode 100644 (file)
index 0000000..18ae534
--- /dev/null
@@ -0,0 +1,165 @@
+// -*- C++ -*-
+/**
+ * \file GuiImplementation.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+// This include must be declared before everything else because
+// of boost/Qt/LyX clash...
+#include "GuiView.h"
+
+#include "GuiImplementation.h"
+#include "GuiWorkArea.h"
+
+#include "BufferView.h"
+#include "bufferlist.h"
+#include "funcrequest.h"
+#include "lyxfunc.h"
+
+#include <QApplication>
+
+using boost::shared_ptr;
+
+
+namespace
+{
+       template<class T>
+       void updateIds(std::map<int, T*> const & stdmap, std::vector<int> & ids) 
+       {
+               ids.clear();
+               typename std::map<int, T*>::const_iterator it;
+               for (it = stdmap.begin(); it != stdmap.end(); ++it)
+                       ids.push_back(it->first);
+       }
+}
+
+
+namespace lyx {
+namespace frontend {
+
+
+GuiImplementation::GuiImplementation()
+{
+       view_ids_.clear();
+       work_area_ids_.clear();
+}
+
+
+LyXView& GuiImplementation::createRegisteredView()
+{
+       updateIds(views_, view_ids_);
+       int id = 0;
+       while (views_.find(id) != views_.end())
+               id++;
+       views_.insert(std::pair<int, GuiView *>(id, new GuiView(id)));
+       updateIds(views_, view_ids_);
+       return *views_[id];
+}
+
+
+bool GuiImplementation::unregisterView(int id)
+{
+       updateIds(views_, view_ids_);
+       BOOST_ASSERT(views_.find(id) != views_.end());
+       BOOST_ASSERT(views_[id]);
+
+       std::map<int, GuiView *>::iterator it;
+       for (it = views_.begin(); it != views_.end(); ++it) {
+               if (it->first == id) {
+                       std::vector<int> const & wa_ids = it->second->workAreaIds();
+                       for (size_t i = 0; i < wa_ids.size(); ++i)
+                               work_areas_.erase(wa_ids[i]);
+                       views_.erase(id);
+                       break;
+               }
+       }
+       updateIds(views_, view_ids_);
+       return true;
+}
+
+
+bool GuiImplementation::closeAllViews()
+{
+       updateIds(views_, view_ids_);
+       if (views_.empty())
+       {
+               // quit in CloseEvent will not be triggert
+               qApp->quit();
+               return true;
+       }
+
+       std::map<int, GuiView*> const cmap = views_;
+       std::map<int, GuiView*>::const_iterator it;
+       for (it = cmap.begin(); it != cmap.end(); ++it)
+       {
+               // TODO: return false when close event was ignored
+               //       e.g. quitWriteAll()->'Cancel'
+               //       maybe we need something like 'bool closeView()'
+               it->second->close(); 
+               // unregisterd by the CloseEvent
+       }
+
+       views_.clear();
+       work_areas_.clear();
+       view_ids_.clear();
+       work_area_ids_.clear();
+       return true;
+}
+
+
+LyXView& GuiImplementation::view(int id) const
+{
+       BOOST_ASSERT(views_.find(id) != views_.end());
+       return *views_.find(id)->second;
+}
+
+
+std::vector<int> const & GuiImplementation::workAreaIds()
+{
+       updateIds(work_areas_, work_area_ids_);
+       return work_area_ids_;
+}
+
+
+int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
+{
+       updateIds(views_, view_ids_);
+       int id = 0;
+       while (work_areas_.find(id) != work_areas_.end())
+               id++;
+
+       GuiView * view = views_[view_id];
+
+       work_areas_.insert(std::pair<int, GuiWorkArea *>
+                                       (id, new GuiWorkArea(w, h, id, *view)));
+
+       // FIXME BufferView creation should be independant of WorkArea creation
+       buffer_views_[id].reset(new BufferView);
+       work_areas_[id]->setBufferView(buffer_views_[id].get());
+
+       view->setWorkArea(work_areas_[id]);
+       view->initTab(work_areas_[id]);
+
+       return id;
+}
+
+
+WorkArea& GuiImplementation::workArea(int id)
+{
+       BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
+       return *work_areas_[id];
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "GuiImplementation_moc.cpp"
diff --git a/src/frontends/qt4/GuiSelection.C b/src/frontends/qt4/GuiSelection.C
deleted file mode 100644 (file)
index 17c60b3..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-// -*- C++ -*-
-/**
- * \file qt4/GuiSelection.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "GuiSelection.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-
-#include <QApplication>
-#include <QClipboard>
-#include <QString>
-
-#include "support/lstrings.h"
-using lyx::support::internalLineEnding;
-using lyx::support::externalLineEnding;
-
-using std::endl;
-
-namespace lyx {
-namespace frontend {
-
-void GuiSelection::haveSelection(bool own)
-{
-       if (!qApp->clipboard()->supportsSelection())
-               return;
-
-       // Tell qt that we have a selection by setting a dummy selection.
-       // We don't use the interface provided by Qt for setting the
-       // selection for performance reasons (see documentation of
-       // Selection::put()). Instead we only tell here that we have a
-       // selection by setting the selection to the empty string.
-       // The real selection is set in GuiApplication::x11EventFilter when
-       // an application actually requests it.
-       // This way calling Selection::have() is cheap and we can do it as
-       // often as we want.
-       if (own)
-               qApp->clipboard()->setText(QString(), QClipboard::Selection);
-       // We don't need to do anything if own = false, as this case is
-       // handled by QT.
-       // FIXME (gb): This is wrong. What is missing here is rather a call of
-       //else
-       //      qApp->clipboard()->clear(QClipboard::Selection);
-       // Since we do not issue this call we rather implement
-       // "persistent selections" as far as X is concerned.
-}
-
-
-docstring const GuiSelection::get() const
-{
-       QString const str = qApp->clipboard()->text(QClipboard::Selection)
-                               .normalized(QString::NormalizationForm_KC);
-       LYXERR(Debug::ACTION) << "GuiSelection::get: " << fromqstr(str)
-                             << endl;
-       if (str.isNull())
-               return docstring();
-
-       return internalLineEnding(qstring_to_ucs4(str));
-}
-
-
-void GuiSelection::put(docstring const & str)
-{
-       LYXERR(Debug::ACTION) << "GuiSelection::put: " << to_utf8(str) << endl;
-
-       qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
-                                  QClipboard::Selection);
-}
-
-
-bool GuiSelection::empty() const
-{
-       if (!qApp->clipboard()->supportsSelection())
-               return true;
-
-       return qApp->clipboard()->text(QClipboard::Selection).isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/GuiSelection.cpp b/src/frontends/qt4/GuiSelection.cpp
new file mode 100644 (file)
index 0000000..17c60b3
--- /dev/null
@@ -0,0 +1,90 @@
+// -*- C++ -*-
+/**
+ * \file qt4/GuiSelection.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiSelection.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include <QApplication>
+#include <QClipboard>
+#include <QString>
+
+#include "support/lstrings.h"
+using lyx::support::internalLineEnding;
+using lyx::support::externalLineEnding;
+
+using std::endl;
+
+namespace lyx {
+namespace frontend {
+
+void GuiSelection::haveSelection(bool own)
+{
+       if (!qApp->clipboard()->supportsSelection())
+               return;
+
+       // Tell qt that we have a selection by setting a dummy selection.
+       // We don't use the interface provided by Qt for setting the
+       // selection for performance reasons (see documentation of
+       // Selection::put()). Instead we only tell here that we have a
+       // selection by setting the selection to the empty string.
+       // The real selection is set in GuiApplication::x11EventFilter when
+       // an application actually requests it.
+       // This way calling Selection::have() is cheap and we can do it as
+       // often as we want.
+       if (own)
+               qApp->clipboard()->setText(QString(), QClipboard::Selection);
+       // We don't need to do anything if own = false, as this case is
+       // handled by QT.
+       // FIXME (gb): This is wrong. What is missing here is rather a call of
+       //else
+       //      qApp->clipboard()->clear(QClipboard::Selection);
+       // Since we do not issue this call we rather implement
+       // "persistent selections" as far as X is concerned.
+}
+
+
+docstring const GuiSelection::get() const
+{
+       QString const str = qApp->clipboard()->text(QClipboard::Selection)
+                               .normalized(QString::NormalizationForm_KC);
+       LYXERR(Debug::ACTION) << "GuiSelection::get: " << fromqstr(str)
+                             << endl;
+       if (str.isNull())
+               return docstring();
+
+       return internalLineEnding(qstring_to_ucs4(str));
+}
+
+
+void GuiSelection::put(docstring const & str)
+{
+       LYXERR(Debug::ACTION) << "GuiSelection::put: " << to_utf8(str) << endl;
+
+       qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
+                                  QClipboard::Selection);
+}
+
+
+bool GuiSelection::empty() const
+{
+       if (!qApp->clipboard()->supportsSelection())
+               return true;
+
+       return qApp->clipboard()->text(QClipboard::Selection).isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C
deleted file mode 100644 (file)
index 113f143..0000000
+++ /dev/null
@@ -1,747 +0,0 @@
-/**
- * \file GuiView.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author John Levon
- * \author Abdelrazak Younes
- * \author Peter Kümmel
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "GuiView.h"
-
-#include "GuiImplementation.h"
-#include "GuiWorkArea.h"
-#include "QLyXKeySym.h"
-#include "QLMenubar.h"
-#include "QLToolbar.h"
-#include "QCommandBuffer.h"
-#include "qt_helpers.h"
-
-#include "frontends/Application.h"
-#include "frontends/Gui.h"
-#include "frontends/WorkArea.h"
-
-#include "support/filetools.h"
-#include "support/convert.h"
-#include "support/lstrings.h"
-
-#include "BufferView.h"
-#include "bufferlist.h"
-#include "debug.h"
-#include "funcrequest.h"
-#include "lyx_cb.h"
-#include "lyxrc.h"
-#include "lyx_main.h"
-#include "session.h"
-#include "lyxfunc.h"
-#include "MenuBackend.h"
-#include "buffer.h"
-#include "bufferlist.h"
-
-#include <QAction>
-#include <QApplication>
-#include <QCloseEvent>
-#include <QPixmap>
-#include <QStatusBar>
-#include <QToolBar>
-#include <QTabBar>
-#include <QDesktopWidget>
-#include <QVBoxLayout>
-
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
-
-using std::endl;
-using std::string;
-using std::vector;
-
-namespace lyx {
-
-using support::FileName;
-using support::libFileSearch;
-using support::makeDisplayPath;
-
-namespace frontend {
-
-namespace {
-
-int const statusbar_timer_value = 3000;
-
-class TabWidget : public QWidget
-{
-public:
-       QTabBar* tabbar;
-
-       TabWidget(QWidget* w, bool topTabBar)
-       {
-               tabbar = new QTabBar;
-               QVBoxLayout* layout = new QVBoxLayout;
-               if (topTabBar) {
-                       layout->addWidget(tabbar);
-                       layout->addWidget(w);
-               } else {
-                       tabbar->setShape(QTabBar::RoundedSouth);
-                       layout->addWidget(w);
-                       layout->addWidget(tabbar);
-               }
-               layout->setMargin(0);
-               setLayout(layout);
-       }
-
-       void clearTabbar()
-       {
-               for (int i = tabbar->count() - 1; i >= 0; --i) 
-                       tabbar->removeTab(i);
-       }
-};
-
-} // namespace anon
-
-
-struct GuiView::GuiViewPrivate
-{
-       vector<string> tabnames;
-       string cur_title;
-
-       TabWidget* tabWidget;
-
-       int posx_offset;
-       int posy_offset;
-
-       GuiViewPrivate() : tabWidget(0), posx_offset(0), posy_offset(0)
-       {}
-
-       unsigned int smallIconSize;
-       unsigned int normalIconSize;
-       unsigned int bigIconSize;
-       // static needed by "New Window"
-       static unsigned int lastIconSize;
-
-       QMenu* toolBarPopup(GuiView *parent)
-       {
-               // FIXME: translation 
-               QMenu* menu = new QMenu(parent);
-               QActionGroup *iconSizeGroup = new QActionGroup(parent);
-
-               QAction *smallIcons = new QAction(iconSizeGroup);
-               smallIcons->setText(qt_("Small-sized icons"));
-               smallIcons->setCheckable(true);
-               QObject::connect(smallIcons, SIGNAL(triggered()), parent, SLOT(smallSizedIcons()));
-               menu->addAction(smallIcons);
-
-               QAction *normalIcons = new QAction(iconSizeGroup);
-               normalIcons->setText(qt_("Normal-sized icons"));
-               normalIcons->setCheckable(true);
-               QObject::connect(normalIcons, SIGNAL(triggered()), parent, SLOT(normalSizedIcons()));
-               menu->addAction(normalIcons);
-
-
-               QAction *bigIcons = new QAction(iconSizeGroup);
-               bigIcons->setText(qt_("Big-sized icons"));
-               bigIcons->setCheckable(true);
-               QObject::connect(bigIcons, SIGNAL(triggered()), parent, SLOT(bigSizedIcons()));
-               menu->addAction(bigIcons);
-
-               unsigned int cur = parent->iconSize().width();
-               if ( cur == parent->d.smallIconSize)
-                       smallIcons->setChecked(true);
-               else if (cur == parent->d.normalIconSize)
-                       normalIcons->setChecked(true);
-               else if (cur == parent->d.bigIconSize)
-                       bigIcons->setChecked(true);
-
-               return menu;
-       }
-};
-
-
-unsigned int GuiView::GuiViewPrivate::lastIconSize = 0;
-
-
-GuiView::GuiView(int id)
-       : QMainWindow(), LyXView(id), commandbuffer_(0), quitting_by_menu_(false),
-         d(*new GuiViewPrivate)
-{
-       // Qt bug? signal lastWindowClosed does not work
-       setAttribute(Qt::WA_QuitOnClose, false);
-       setAttribute(Qt::WA_DeleteOnClose, true);
-
-       // hardcode here the platform specific icon size
-       d.smallIconSize = 14;   // scaling problems
-       d.normalIconSize = 20;  // ok, default
-       d.bigIconSize = 26;             // better for some math icons
-
-#ifndef Q_WS_MACX
-       //  assign an icon to main form. We do not do it under Qt/Mac,
-       //  since the icon is provided in the application bundle.
-       FileName const iconname = libFileSearch("images", "lyx", "xpm");
-       if (!iconname.empty())
-               setWindowIcon(QPixmap(toqstr(iconname.absFilename())));
-#endif
-}
-
-
-GuiView::~GuiView()
-{
-       menubar_.reset();
-       delete &d;
-}
-
-
-void GuiView::close()
-{
-       quitting_by_menu_ = true;
-       QMainWindow::close();
-       quitting_by_menu_ = false;
-}
-
-
-void GuiView::setFocus()
-{
-       BOOST_ASSERT(work_area_);
-       static_cast<GuiWorkArea *>(work_area_)->setFocus();
-}
-
-
-QMenu* GuiView::createPopupMenu()
-{
-       return d.toolBarPopup(this);
-}
-
-
-void GuiView::init()
-{
-       menubar_.reset(new QLMenubar(this, menubackend));
-       QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
-               this, SLOT(updateMenu(QAction *)));
-
-       getToolbars().init();
-
-       statusBar()->setSizeGripEnabled(true);
-
-       QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
-               this, SLOT(update_view_state_qt()));
-
-       BOOST_ASSERT(work_area_);
-       if (!work_area_->bufferView().buffer() && !theBufferList().empty())
-               setBuffer(theBufferList().first());
-
-       // make sure the buttons are disabled if needed
-       updateToolbars();
-       updateLayoutChoice();
-       updateMenubar();
-}
-
-
-void GuiView::closeEvent(QCloseEvent * close_event)
-{
-       // we may have been called through the close window button
-       // which bypasses the LFUN machinery.
-       if (!quitting_by_menu_ && theApp()->gui().viewIds().size() == 1) {
-               if (!theBufferList().quitWriteAll()) {
-                       close_event->ignore();
-                       return;
-               }
-       }
-
-       theApp()->gui().unregisterView(id());
-       if (!theApp()->gui().viewIds().empty()) {
-               // Just close the window and do nothing else if this is not the
-               // last window.
-               close_event->accept();
-               return;
-       }
-
-       if (view()->buffer()) {
-               // save cursor position for opened files to .lyx/session
-               // only bottom (whole doc) level pit and pos is saved.
-               LyX::ref().session().lastFilePos().save(
-                       FileName(buffer()->fileName()),
-                       boost::tie(view()->cursor().bottom().pit(),
-                       view()->cursor().bottom().pos()));
-       }
-
-       // this is the place where we leave the frontend.
-       // it is the only point at which we start quitting.
-       saveGeometry();
-       close_event->accept();
-       // quit the event loop
-       qApp->quit();
-}
-
-
-void GuiView::saveGeometry()
-{
-       static bool done = false;
-       if (done)
-               return;
-       else
-               done = true;
-
-       // FIXME:
-       // change the ifdef to 'geometry = normalGeometry();' only
-       // when Trolltech has fixed the broken normalGeometry on X11:
-       // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
-       // Then also the moveEvent, resizeEvent, and the
-       // code for floatingGeometry_ can be removed;
-       // adjust GuiView::setGeometry()
-       
-       QRect normal_geometry;
-       int maximized;
-#ifdef Q_WS_WIN
-       normal_geometry = normalGeometry();
-       if (isMaximized()) {
-               maximized = CompletelyMaximized;
-       } else {
-               maximized = NotMaximized;
-       }
-#else
-       normal_geometry = updateFloatingGeometry();
-
-       QDesktopWidget& dw = *qApp->desktop();
-       QRect desk = dw.availableGeometry(dw.primaryScreen());  
-       // Qt bug on Linux: load completely maximized, vert max. save-> frameGeometry().height() is wrong
-       if (isMaximized() && desk.width() <= frameGeometry().width() && desk.height() <= frameGeometry().height()) {
-               maximized = CompletelyMaximized;
-               // maximizing does not work when the window is allready hor. or vert. maximized
-               // Tested only on KDE
-               int dh = frameGeometry().height() - height(); 
-               if (desk.height() <= normal_geometry.height() + dh) 
-                       normal_geometry.setHeight(normal_geometry.height() - 1);
-               int dw = frameGeometry().width() - width();
-               if (desk.width() <= normal_geometry.width() + dw) 
-                       normal_geometry.setWidth(normal_geometry.width() - 1);
-       } else if (desk.height() <= frameGeometry().height()) {
-               maximized = VerticallyMaximized;                
-       } else if (desk.width() <= frameGeometry().width()) {
-               maximized = HorizontallyMaximized;
-       } else {
-               maximized = NotMaximized;
-       }
-
-
-#endif
-       // save windows size and position
-       Session & session = LyX::ref().session();
-       session.sessionInfo().save("WindowWidth", convert<string>(normal_geometry.width()));
-       session.sessionInfo().save("WindowHeight", convert<string>(normal_geometry.height()));
-       session.sessionInfo().save("WindowMaximized", convert<string>(maximized));
-       session.sessionInfo().save("IconSizeXY", convert<string>(iconSize().width()));
-       if (lyxrc.geometry_xysaved) {
-               session.sessionInfo().save("WindowPosX", convert<string>(normal_geometry.x() + d.posx_offset));
-               session.sessionInfo().save("WindowPosY", convert<string>(normal_geometry.y() + d.posy_offset));
-       }
-       getToolbars().saveToolbarInfo();
-}
-                                                 
-
-void GuiView::setGeometry(unsigned int width,
-                         unsigned int height,
-                         int posx, int posy,
-                         int maximized,
-                         unsigned int iconSizeXY,
-                         const string & geometryArg)
-{
-       // use last value (not at startup)
-       if (d.lastIconSize != 0)
-               setIconSize(d.lastIconSize);
-       else if (iconSizeXY != 0)
-               setIconSize(iconSizeXY);
-       else
-               setIconSize(d.normalIconSize);
-
-       // only true when the -geometry option was NOT used
-       if (width != 0 && height != 0) {
-               if (posx != -1 && posy != -1) {
-                       // if there are startup positioning problems:
-                       // http://doc.trolltech.com/4.2/qdesktopwidget.html 
-                       QDesktopWidget& dw = *qApp->desktop();
-                       if (dw.isVirtualDesktop()) {
-                               if(!dw.geometry().contains(posx, posy)) {
-                                       posx = 50;
-                                       posy = 50;
-                               }
-                       } else {
-                               // Which system doesn't use a virtual desktop?
-                               // TODO save also last screen number and check if it is still availabe.
-                       }
-#ifdef Q_WS_WIN
-                       // FIXME: use setGeometry only when Trolltech has fixed the qt4/X11 bug
-                       QWidget::setGeometry(posx, posy, width, height);
-#else
-                       resize(width, height);
-                       move(posx, posy);
-#endif
-               } else {
-                       resize(width, height);
-               }
-
-               // remember original size
-               floatingGeometry_ = QRect(posx, posy, width, height);
-
-               if (maximized != NotMaximized) {
-                       if (maximized == CompletelyMaximized) {
-                               setWindowState(Qt::WindowMaximized);
-                       } else {
-#ifndef Q_WS_WIN
-                               // TODO How to set by the window manager?
-                               //      setWindowState(Qt::WindowVerticallyMaximized); 
-                               //      is not possible
-                               QDesktopWidget& dw = *qApp->desktop();
-                               QRect desk = dw.availableGeometry(dw.primaryScreen());
-                               if (maximized == VerticallyMaximized) 
-                                       resize(width, desk.height());
-                               if (maximized == HorizontallyMaximized)
-                                       resize(desk.width(), height);
-#endif
-                       }
-               }
-       }
-       else
-       {
-               // FIXME: move this code into parse_geometry() (lyx_main.C)
-#ifdef Q_WS_WIN
-               int x, y;
-               int w, h;
-               QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
-               re.indexIn(toqstr(geometryArg.c_str()));
-               w = re.cap(1).toInt();
-               h = re.cap(2).toInt();
-               x = re.cap(3).toInt();
-               y = re.cap(4).toInt();
-               QWidget::setGeometry( x, y, w, h );
-#else
-               // silence warning
-               (void)geometryArg;
-#endif
-       }
-
-       show();
-
-       // For an unknown reason, the Window title update is not effective for
-       // the second windows up until it is shown on screen (Qt bug?).
-       updateWindowTitle();
-
-       // after show geometry() has changed (Qt bug?)
-       // we compensate the drift when storing the position
-       d.posx_offset = 0;
-       d.posy_offset = 0;
-       if (width != 0 && height != 0) 
-               if (posx != -1 && posy != -1) {
-#ifdef Q_WS_WIN
-                       d.posx_offset = posx - normalGeometry().x();
-                       d.posy_offset = posy - normalGeometry().y();
-#else
-#ifndef Q_WS_MACX
-                       if (maximized == NotMaximized) {
-                               d.posx_offset = posx - geometry().x();
-                               d.posy_offset = posy - geometry().y();
-                       }
-#endif
-#endif
-               }
-}
-
-
-void GuiView::updateMenu(QAction * /*action*/)
-{
-       menubar_->update();
-}
-
-
-void GuiView::setWindowTitle(docstring const & t, docstring const & it)
-{
-       QString title = windowTitle();
-       QString new_title = toqstr(t);
-       if (title != new_title) {
-               QMainWindow::setWindowTitle(new_title);
-               QMainWindow::setWindowIconText(toqstr(it));
-       }
-}
-
-
-void GuiView::addCommandBuffer(QToolBar * toolbar)
-{
-       commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
-       focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
-       toolbar->addWidget(commandbuffer_);
-}
-
-
-void GuiView::message(docstring const & str)
-{
-       statusBar()->showMessage(toqstr(str));
-       statusbar_timer_.stop();
-       statusbar_timer_.start(statusbar_timer_value);
-}
-
-
-void GuiView::clearMessage()
-{
-       update_view_state_qt();
-}
-
-
-void GuiView::setIconSize(unsigned int size)
-{
-       d.lastIconSize = size;
-       QMainWindow::setIconSize(QSize(size, size));
-}
-
-
-void GuiView::smallSizedIcons()
-{
-       setIconSize(d.smallIconSize);
-}
-
-
-void GuiView::normalSizedIcons()
-{
-       setIconSize(d.normalIconSize);
-}
-
-
-void GuiView::bigSizedIcons()
-{
-       setIconSize(d.bigIconSize);
-}
-
-
-void GuiView::focus_command_widget()
-{
-       if (commandbuffer_)
-               commandbuffer_->focus_command();
-}
-
-
-void GuiView::update_view_state_qt()
-{
-       statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
-       statusbar_timer_.stop();
-}
-
-
-void GuiView::initTab(QWidget* workarea)
-{
-       // construct the TabWidget with 'false' to have the tabbar at the bottom
-       d.tabWidget = new TabWidget(workarea, true);
-       setCentralWidget(d.tabWidget);
-       QObject::connect(d.tabWidget->tabbar, SIGNAL(currentChanged(int)),
-                       this, SLOT(currentTabChanged(int)));
-}
-
-
-void GuiView::updateTab()
-{
-       std::vector<string> const & names = theBufferList().getFileNames();
-
-       string cur_title;
-       if (view()->buffer()) {
-               cur_title = view()->buffer()->fileName();
-       }
-
-       // avoid unnecessary tabbar rebuild: 
-       // check if something has changed
-       if (d.tabnames == names && d.cur_title == cur_title) 
-               return;
-       d.tabnames = names;
-       d.cur_title = cur_title;
-
-       QTabBar & tabbar = *d.tabWidget->tabbar;
-
-       // update when all is done
-       tabbar.blockSignals(true);
-
-       // remove all tab bars
-       d.tabWidget->clearTabbar();
-
-       // rebuild tabbar and function map from scratch
-       if (names.size() > 1) {
-               for(size_t i = 0; i < names.size(); i++) {
-                       tabbar.addTab(toqstr(makeDisplayPath(names[i], 30))); 
-                       // set current tab
-                       if (names[i] == cur_title)
-                               tabbar.setCurrentIndex(i);
-               }
-       }
-       tabbar.blockSignals(false);
-}
-
-
-void GuiView::currentTabChanged(int i)
-{
-       BOOST_ASSERT(i >= 0 && size_type(i) < d.tabnames.size());
-       dispatch(FuncRequest(LFUN_BUFFER_SWITCH, d.tabnames[i]));
-}
-
-
-void GuiView::updateStatusBar()
-{
-       // let the user see the explicit message
-       if (statusbar_timer_.isActive())
-               return;
-
-       statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
-}
-
-
-void GuiView::activated(FuncRequest const & func)
-{
-       dispatch(func);
-}
-
-
-bool GuiView::hasFocus() const
-{
-       return qApp->activeWindow() == this;
-}
-
-
-QRect  GuiView::updateFloatingGeometry()
-{
-       QDesktopWidget& dw = *qApp->desktop();
-       QRect desk = dw.availableGeometry(dw.primaryScreen());
-       // remember only non-maximized sizes
-       if (!isMaximized() && desk.width() > frameGeometry().width() && desk.height() > frameGeometry().height()) {
-               floatingGeometry_ = QRect(x(), y(), width(), height());
-       }
-       return floatingGeometry_;
-}
-
-
-void GuiView::resizeEvent(QResizeEvent *)
-{
-       updateFloatingGeometry();
-}
-
-
-void GuiView::moveEvent(QMoveEvent *)
-{
-       updateFloatingGeometry();
-}
-
-
-bool GuiView::event(QEvent * e)
-{
-       // Useful debug code:
-       /*
-       switch (e->type())
-       {
-       case QEvent::WindowActivate:
-       case QEvent::ActivationChange:
-       case QEvent::WindowDeactivate:
-       case QEvent::Paint:
-       case QEvent::Enter:
-       case QEvent::Leave:
-       case QEvent::HoverEnter:
-       case QEvent::HoverLeave:
-       case QEvent::HoverMove:
-       case QEvent::StatusTip:
-               break;
-       default:
-       */
-
-       if (e->type() == QEvent::ShortcutOverride) {
-               QKeyEvent * ke = static_cast<QKeyEvent*>(e);
-               if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
-                       boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
-                       sym->set(ke);
-                       BOOST_ASSERT(work_area_);
-                       work_area_->processKeySym(sym, key_modifier::none);
-                       e->accept();
-                       return true;
-               }
-       }
-       //} for the debug switch above.
-
-       return QMainWindow::event(e);
-}
-
-
-bool GuiView::focusNextPrevChild(bool /*next*/)
-{
-       setFocus();
-       return true;
-}
-
-
-void GuiView::show()
-{
-       QMainWindow::setWindowTitle(qt_("LyX"));
-       QMainWindow::show();
-       updateFloatingGeometry();
-}
-
-
-void GuiView::busy(bool yes)
-{
-       BOOST_ASSERT(work_area_);
-       static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
-
-       if (yes) {
-               work_area_->stopBlinkingCursor();
-               QApplication::setOverrideCursor(Qt::WaitCursor);
-       }
-       else {
-               work_area_->startBlinkingCursor();
-               QApplication::restoreOverrideCursor();
-       }
-}
-
-
-Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
-{
-       QLToolbar * Tb = new QLToolbar(tbinfo, *this);
-
-       if (tbinfo.flags & ToolbarInfo::TOP) {
-               if (newline)
-                       addToolBarBreak(Qt::TopToolBarArea);
-               addToolBar(Qt::TopToolBarArea, Tb);
-       }
-
-       if (tbinfo.flags & ToolbarInfo::BOTTOM) {
-// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
-#if (QT_VERSION >= 0x040202)
-               if (newline)
-                       addToolBarBreak(Qt::BottomToolBarArea);
-#endif
-               addToolBar(Qt::BottomToolBarArea, Tb);
-       }
-
-       if (tbinfo.flags & ToolbarInfo::LEFT) {
-// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
-#if (QT_VERSION >= 0x040202)
-               if (newline)
-                       addToolBarBreak(Qt::LeftToolBarArea);
-#endif
-               addToolBar(Qt::LeftToolBarArea, Tb);
-       }
-
-       if (tbinfo.flags & ToolbarInfo::RIGHT) {
-// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
-#if (QT_VERSION >= 0x040202)
-               if (newline)
-                       addToolBarBreak(Qt::RightToolBarArea);
-#endif
-               addToolBar(Qt::RightToolBarArea, Tb);
-       }
-
-       // The following does not work so I cannot restore to exact toolbar location
-       /*
-       ToolbarSection::ToolbarInfo & tbinfo = LyX::ref().session().toolbars().load(tbinfo.name);
-       Tb->move(tbinfo.posx, tbinfo.posy);
-       */
-
-       return Toolbars::ToolbarPtr(Tb);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "GuiView_moc.cpp"
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
new file mode 100644 (file)
index 0000000..113f143
--- /dev/null
@@ -0,0 +1,747 @@
+/**
+ * \file GuiView.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ * \author Abdelrazak Younes
+ * \author Peter Kümmel
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiView.h"
+
+#include "GuiImplementation.h"
+#include "GuiWorkArea.h"
+#include "QLyXKeySym.h"
+#include "QLMenubar.h"
+#include "QLToolbar.h"
+#include "QCommandBuffer.h"
+#include "qt_helpers.h"
+
+#include "frontends/Application.h"
+#include "frontends/Gui.h"
+#include "frontends/WorkArea.h"
+
+#include "support/filetools.h"
+#include "support/convert.h"
+#include "support/lstrings.h"
+
+#include "BufferView.h"
+#include "bufferlist.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "lyx_cb.h"
+#include "lyxrc.h"
+#include "lyx_main.h"
+#include "session.h"
+#include "lyxfunc.h"
+#include "MenuBackend.h"
+#include "buffer.h"
+#include "bufferlist.h"
+
+#include <QAction>
+#include <QApplication>
+#include <QCloseEvent>
+#include <QPixmap>
+#include <QStatusBar>
+#include <QToolBar>
+#include <QTabBar>
+#include <QDesktopWidget>
+#include <QVBoxLayout>
+
+#include <boost/bind.hpp>
+#include <boost/shared_ptr.hpp>
+
+using std::endl;
+using std::string;
+using std::vector;
+
+namespace lyx {
+
+using support::FileName;
+using support::libFileSearch;
+using support::makeDisplayPath;
+
+namespace frontend {
+
+namespace {
+
+int const statusbar_timer_value = 3000;
+
+class TabWidget : public QWidget
+{
+public:
+       QTabBar* tabbar;
+
+       TabWidget(QWidget* w, bool topTabBar)
+       {
+               tabbar = new QTabBar;
+               QVBoxLayout* layout = new QVBoxLayout;
+               if (topTabBar) {
+                       layout->addWidget(tabbar);
+                       layout->addWidget(w);
+               } else {
+                       tabbar->setShape(QTabBar::RoundedSouth);
+                       layout->addWidget(w);
+                       layout->addWidget(tabbar);
+               }
+               layout->setMargin(0);
+               setLayout(layout);
+       }
+
+       void clearTabbar()
+       {
+               for (int i = tabbar->count() - 1; i >= 0; --i) 
+                       tabbar->removeTab(i);
+       }
+};
+
+} // namespace anon
+
+
+struct GuiView::GuiViewPrivate
+{
+       vector<string> tabnames;
+       string cur_title;
+
+       TabWidget* tabWidget;
+
+       int posx_offset;
+       int posy_offset;
+
+       GuiViewPrivate() : tabWidget(0), posx_offset(0), posy_offset(0)
+       {}
+
+       unsigned int smallIconSize;
+       unsigned int normalIconSize;
+       unsigned int bigIconSize;
+       // static needed by "New Window"
+       static unsigned int lastIconSize;
+
+       QMenu* toolBarPopup(GuiView *parent)
+       {
+               // FIXME: translation 
+               QMenu* menu = new QMenu(parent);
+               QActionGroup *iconSizeGroup = new QActionGroup(parent);
+
+               QAction *smallIcons = new QAction(iconSizeGroup);
+               smallIcons->setText(qt_("Small-sized icons"));
+               smallIcons->setCheckable(true);
+               QObject::connect(smallIcons, SIGNAL(triggered()), parent, SLOT(smallSizedIcons()));
+               menu->addAction(smallIcons);
+
+               QAction *normalIcons = new QAction(iconSizeGroup);
+               normalIcons->setText(qt_("Normal-sized icons"));
+               normalIcons->setCheckable(true);
+               QObject::connect(normalIcons, SIGNAL(triggered()), parent, SLOT(normalSizedIcons()));
+               menu->addAction(normalIcons);
+
+
+               QAction *bigIcons = new QAction(iconSizeGroup);
+               bigIcons->setText(qt_("Big-sized icons"));
+               bigIcons->setCheckable(true);
+               QObject::connect(bigIcons, SIGNAL(triggered()), parent, SLOT(bigSizedIcons()));
+               menu->addAction(bigIcons);
+
+               unsigned int cur = parent->iconSize().width();
+               if ( cur == parent->d.smallIconSize)
+                       smallIcons->setChecked(true);
+               else if (cur == parent->d.normalIconSize)
+                       normalIcons->setChecked(true);
+               else if (cur == parent->d.bigIconSize)
+                       bigIcons->setChecked(true);
+
+               return menu;
+       }
+};
+
+
+unsigned int GuiView::GuiViewPrivate::lastIconSize = 0;
+
+
+GuiView::GuiView(int id)
+       : QMainWindow(), LyXView(id), commandbuffer_(0), quitting_by_menu_(false),
+         d(*new GuiViewPrivate)
+{
+       // Qt bug? signal lastWindowClosed does not work
+       setAttribute(Qt::WA_QuitOnClose, false);
+       setAttribute(Qt::WA_DeleteOnClose, true);
+
+       // hardcode here the platform specific icon size
+       d.smallIconSize = 14;   // scaling problems
+       d.normalIconSize = 20;  // ok, default
+       d.bigIconSize = 26;             // better for some math icons
+
+#ifndef Q_WS_MACX
+       //  assign an icon to main form. We do not do it under Qt/Mac,
+       //  since the icon is provided in the application bundle.
+       FileName const iconname = libFileSearch("images", "lyx", "xpm");
+       if (!iconname.empty())
+               setWindowIcon(QPixmap(toqstr(iconname.absFilename())));
+#endif
+}
+
+
+GuiView::~GuiView()
+{
+       menubar_.reset();
+       delete &d;
+}
+
+
+void GuiView::close()
+{
+       quitting_by_menu_ = true;
+       QMainWindow::close();
+       quitting_by_menu_ = false;
+}
+
+
+void GuiView::setFocus()
+{
+       BOOST_ASSERT(work_area_);
+       static_cast<GuiWorkArea *>(work_area_)->setFocus();
+}
+
+
+QMenu* GuiView::createPopupMenu()
+{
+       return d.toolBarPopup(this);
+}
+
+
+void GuiView::init()
+{
+       menubar_.reset(new QLMenubar(this, menubackend));
+       QObject::connect(menuBar(), SIGNAL(triggered(QAction *)),
+               this, SLOT(updateMenu(QAction *)));
+
+       getToolbars().init();
+
+       statusBar()->setSizeGripEnabled(true);
+
+       QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
+               this, SLOT(update_view_state_qt()));
+
+       BOOST_ASSERT(work_area_);
+       if (!work_area_->bufferView().buffer() && !theBufferList().empty())
+               setBuffer(theBufferList().first());
+
+       // make sure the buttons are disabled if needed
+       updateToolbars();
+       updateLayoutChoice();
+       updateMenubar();
+}
+
+
+void GuiView::closeEvent(QCloseEvent * close_event)
+{
+       // we may have been called through the close window button
+       // which bypasses the LFUN machinery.
+       if (!quitting_by_menu_ && theApp()->gui().viewIds().size() == 1) {
+               if (!theBufferList().quitWriteAll()) {
+                       close_event->ignore();
+                       return;
+               }
+       }
+
+       theApp()->gui().unregisterView(id());
+       if (!theApp()->gui().viewIds().empty()) {
+               // Just close the window and do nothing else if this is not the
+               // last window.
+               close_event->accept();
+               return;
+       }
+
+       if (view()->buffer()) {
+               // save cursor position for opened files to .lyx/session
+               // only bottom (whole doc) level pit and pos is saved.
+               LyX::ref().session().lastFilePos().save(
+                       FileName(buffer()->fileName()),
+                       boost::tie(view()->cursor().bottom().pit(),
+                       view()->cursor().bottom().pos()));
+       }
+
+       // this is the place where we leave the frontend.
+       // it is the only point at which we start quitting.
+       saveGeometry();
+       close_event->accept();
+       // quit the event loop
+       qApp->quit();
+}
+
+
+void GuiView::saveGeometry()
+{
+       static bool done = false;
+       if (done)
+               return;
+       else
+               done = true;
+
+       // FIXME:
+       // change the ifdef to 'geometry = normalGeometry();' only
+       // when Trolltech has fixed the broken normalGeometry on X11:
+       // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
+       // Then also the moveEvent, resizeEvent, and the
+       // code for floatingGeometry_ can be removed;
+       // adjust GuiView::setGeometry()
+       
+       QRect normal_geometry;
+       int maximized;
+#ifdef Q_WS_WIN
+       normal_geometry = normalGeometry();
+       if (isMaximized()) {
+               maximized = CompletelyMaximized;
+       } else {
+               maximized = NotMaximized;
+       }
+#else
+       normal_geometry = updateFloatingGeometry();
+
+       QDesktopWidget& dw = *qApp->desktop();
+       QRect desk = dw.availableGeometry(dw.primaryScreen());  
+       // Qt bug on Linux: load completely maximized, vert max. save-> frameGeometry().height() is wrong
+       if (isMaximized() && desk.width() <= frameGeometry().width() && desk.height() <= frameGeometry().height()) {
+               maximized = CompletelyMaximized;
+               // maximizing does not work when the window is allready hor. or vert. maximized
+               // Tested only on KDE
+               int dh = frameGeometry().height() - height(); 
+               if (desk.height() <= normal_geometry.height() + dh) 
+                       normal_geometry.setHeight(normal_geometry.height() - 1);
+               int dw = frameGeometry().width() - width();
+               if (desk.width() <= normal_geometry.width() + dw) 
+                       normal_geometry.setWidth(normal_geometry.width() - 1);
+       } else if (desk.height() <= frameGeometry().height()) {
+               maximized = VerticallyMaximized;                
+       } else if (desk.width() <= frameGeometry().width()) {
+               maximized = HorizontallyMaximized;
+       } else {
+               maximized = NotMaximized;
+       }
+
+
+#endif
+       // save windows size and position
+       Session & session = LyX::ref().session();
+       session.sessionInfo().save("WindowWidth", convert<string>(normal_geometry.width()));
+       session.sessionInfo().save("WindowHeight", convert<string>(normal_geometry.height()));
+       session.sessionInfo().save("WindowMaximized", convert<string>(maximized));
+       session.sessionInfo().save("IconSizeXY", convert<string>(iconSize().width()));
+       if (lyxrc.geometry_xysaved) {
+               session.sessionInfo().save("WindowPosX", convert<string>(normal_geometry.x() + d.posx_offset));
+               session.sessionInfo().save("WindowPosY", convert<string>(normal_geometry.y() + d.posy_offset));
+       }
+       getToolbars().saveToolbarInfo();
+}
+                                                 
+
+void GuiView::setGeometry(unsigned int width,
+                         unsigned int height,
+                         int posx, int posy,
+                         int maximized,
+                         unsigned int iconSizeXY,
+                         const string & geometryArg)
+{
+       // use last value (not at startup)
+       if (d.lastIconSize != 0)
+               setIconSize(d.lastIconSize);
+       else if (iconSizeXY != 0)
+               setIconSize(iconSizeXY);
+       else
+               setIconSize(d.normalIconSize);
+
+       // only true when the -geometry option was NOT used
+       if (width != 0 && height != 0) {
+               if (posx != -1 && posy != -1) {
+                       // if there are startup positioning problems:
+                       // http://doc.trolltech.com/4.2/qdesktopwidget.html 
+                       QDesktopWidget& dw = *qApp->desktop();
+                       if (dw.isVirtualDesktop()) {
+                               if(!dw.geometry().contains(posx, posy)) {
+                                       posx = 50;
+                                       posy = 50;
+                               }
+                       } else {
+                               // Which system doesn't use a virtual desktop?
+                               // TODO save also last screen number and check if it is still availabe.
+                       }
+#ifdef Q_WS_WIN
+                       // FIXME: use setGeometry only when Trolltech has fixed the qt4/X11 bug
+                       QWidget::setGeometry(posx, posy, width, height);
+#else
+                       resize(width, height);
+                       move(posx, posy);
+#endif
+               } else {
+                       resize(width, height);
+               }
+
+               // remember original size
+               floatingGeometry_ = QRect(posx, posy, width, height);
+
+               if (maximized != NotMaximized) {
+                       if (maximized == CompletelyMaximized) {
+                               setWindowState(Qt::WindowMaximized);
+                       } else {
+#ifndef Q_WS_WIN
+                               // TODO How to set by the window manager?
+                               //      setWindowState(Qt::WindowVerticallyMaximized); 
+                               //      is not possible
+                               QDesktopWidget& dw = *qApp->desktop();
+                               QRect desk = dw.availableGeometry(dw.primaryScreen());
+                               if (maximized == VerticallyMaximized) 
+                                       resize(width, desk.height());
+                               if (maximized == HorizontallyMaximized)
+                                       resize(desk.width(), height);
+#endif
+                       }
+               }
+       }
+       else
+       {
+               // FIXME: move this code into parse_geometry() (lyx_main.C)
+#ifdef Q_WS_WIN
+               int x, y;
+               int w, h;
+               QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
+               re.indexIn(toqstr(geometryArg.c_str()));
+               w = re.cap(1).toInt();
+               h = re.cap(2).toInt();
+               x = re.cap(3).toInt();
+               y = re.cap(4).toInt();
+               QWidget::setGeometry( x, y, w, h );
+#else
+               // silence warning
+               (void)geometryArg;
+#endif
+       }
+
+       show();
+
+       // For an unknown reason, the Window title update is not effective for
+       // the second windows up until it is shown on screen (Qt bug?).
+       updateWindowTitle();
+
+       // after show geometry() has changed (Qt bug?)
+       // we compensate the drift when storing the position
+       d.posx_offset = 0;
+       d.posy_offset = 0;
+       if (width != 0 && height != 0) 
+               if (posx != -1 && posy != -1) {
+#ifdef Q_WS_WIN
+                       d.posx_offset = posx - normalGeometry().x();
+                       d.posy_offset = posy - normalGeometry().y();
+#else
+#ifndef Q_WS_MACX
+                       if (maximized == NotMaximized) {
+                               d.posx_offset = posx - geometry().x();
+                               d.posy_offset = posy - geometry().y();
+                       }
+#endif
+#endif
+               }
+}
+
+
+void GuiView::updateMenu(QAction * /*action*/)
+{
+       menubar_->update();
+}
+
+
+void GuiView::setWindowTitle(docstring const & t, docstring const & it)
+{
+       QString title = windowTitle();
+       QString new_title = toqstr(t);
+       if (title != new_title) {
+               QMainWindow::setWindowTitle(new_title);
+               QMainWindow::setWindowIconText(toqstr(it));
+       }
+}
+
+
+void GuiView::addCommandBuffer(QToolBar * toolbar)
+{
+       commandbuffer_ = new QCommandBuffer(this, *controlcommand_);
+       focus_command_buffer.connect(boost::bind(&GuiView::focus_command_widget, this));
+       toolbar->addWidget(commandbuffer_);
+}
+
+
+void GuiView::message(docstring const & str)
+{
+       statusBar()->showMessage(toqstr(str));
+       statusbar_timer_.stop();
+       statusbar_timer_.start(statusbar_timer_value);
+}
+
+
+void GuiView::clearMessage()
+{
+       update_view_state_qt();
+}
+
+
+void GuiView::setIconSize(unsigned int size)
+{
+       d.lastIconSize = size;
+       QMainWindow::setIconSize(QSize(size, size));
+}
+
+
+void GuiView::smallSizedIcons()
+{
+       setIconSize(d.smallIconSize);
+}
+
+
+void GuiView::normalSizedIcons()
+{
+       setIconSize(d.normalIconSize);
+}
+
+
+void GuiView::bigSizedIcons()
+{
+       setIconSize(d.bigIconSize);
+}
+
+
+void GuiView::focus_command_widget()
+{
+       if (commandbuffer_)
+               commandbuffer_->focus_command();
+}
+
+
+void GuiView::update_view_state_qt()
+{
+       statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
+       statusbar_timer_.stop();
+}
+
+
+void GuiView::initTab(QWidget* workarea)
+{
+       // construct the TabWidget with 'false' to have the tabbar at the bottom
+       d.tabWidget = new TabWidget(workarea, true);
+       setCentralWidget(d.tabWidget);
+       QObject::connect(d.tabWidget->tabbar, SIGNAL(currentChanged(int)),
+                       this, SLOT(currentTabChanged(int)));
+}
+
+
+void GuiView::updateTab()
+{
+       std::vector<string> const & names = theBufferList().getFileNames();
+
+       string cur_title;
+       if (view()->buffer()) {
+               cur_title = view()->buffer()->fileName();
+       }
+
+       // avoid unnecessary tabbar rebuild: 
+       // check if something has changed
+       if (d.tabnames == names && d.cur_title == cur_title) 
+               return;
+       d.tabnames = names;
+       d.cur_title = cur_title;
+
+       QTabBar & tabbar = *d.tabWidget->tabbar;
+
+       // update when all is done
+       tabbar.blockSignals(true);
+
+       // remove all tab bars
+       d.tabWidget->clearTabbar();
+
+       // rebuild tabbar and function map from scratch
+       if (names.size() > 1) {
+               for(size_t i = 0; i < names.size(); i++) {
+                       tabbar.addTab(toqstr(makeDisplayPath(names[i], 30))); 
+                       // set current tab
+                       if (names[i] == cur_title)
+                               tabbar.setCurrentIndex(i);
+               }
+       }
+       tabbar.blockSignals(false);
+}
+
+
+void GuiView::currentTabChanged(int i)
+{
+       BOOST_ASSERT(i >= 0 && size_type(i) < d.tabnames.size());
+       dispatch(FuncRequest(LFUN_BUFFER_SWITCH, d.tabnames[i]));
+}
+
+
+void GuiView::updateStatusBar()
+{
+       // let the user see the explicit message
+       if (statusbar_timer_.isActive())
+               return;
+
+       statusBar()->showMessage(toqstr(theLyXFunc().viewStatusMessage()));
+}
+
+
+void GuiView::activated(FuncRequest const & func)
+{
+       dispatch(func);
+}
+
+
+bool GuiView::hasFocus() const
+{
+       return qApp->activeWindow() == this;
+}
+
+
+QRect  GuiView::updateFloatingGeometry()
+{
+       QDesktopWidget& dw = *qApp->desktop();
+       QRect desk = dw.availableGeometry(dw.primaryScreen());
+       // remember only non-maximized sizes
+       if (!isMaximized() && desk.width() > frameGeometry().width() && desk.height() > frameGeometry().height()) {
+               floatingGeometry_ = QRect(x(), y(), width(), height());
+       }
+       return floatingGeometry_;
+}
+
+
+void GuiView::resizeEvent(QResizeEvent *)
+{
+       updateFloatingGeometry();
+}
+
+
+void GuiView::moveEvent(QMoveEvent *)
+{
+       updateFloatingGeometry();
+}
+
+
+bool GuiView::event(QEvent * e)
+{
+       // Useful debug code:
+       /*
+       switch (e->type())
+       {
+       case QEvent::WindowActivate:
+       case QEvent::ActivationChange:
+       case QEvent::WindowDeactivate:
+       case QEvent::Paint:
+       case QEvent::Enter:
+       case QEvent::Leave:
+       case QEvent::HoverEnter:
+       case QEvent::HoverLeave:
+       case QEvent::HoverMove:
+       case QEvent::StatusTip:
+               break;
+       default:
+       */
+
+       if (e->type() == QEvent::ShortcutOverride) {
+               QKeyEvent * ke = static_cast<QKeyEvent*>(e);
+               if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
+                       boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
+                       sym->set(ke);
+                       BOOST_ASSERT(work_area_);
+                       work_area_->processKeySym(sym, key_modifier::none);
+                       e->accept();
+                       return true;
+               }
+       }
+       //} for the debug switch above.
+
+       return QMainWindow::event(e);
+}
+
+
+bool GuiView::focusNextPrevChild(bool /*next*/)
+{
+       setFocus();
+       return true;
+}
+
+
+void GuiView::show()
+{
+       QMainWindow::setWindowTitle(qt_("LyX"));
+       QMainWindow::show();
+       updateFloatingGeometry();
+}
+
+
+void GuiView::busy(bool yes)
+{
+       BOOST_ASSERT(work_area_);
+       static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
+
+       if (yes) {
+               work_area_->stopBlinkingCursor();
+               QApplication::setOverrideCursor(Qt::WaitCursor);
+       }
+       else {
+               work_area_->startBlinkingCursor();
+               QApplication::restoreOverrideCursor();
+       }
+}
+
+
+Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
+{
+       QLToolbar * Tb = new QLToolbar(tbinfo, *this);
+
+       if (tbinfo.flags & ToolbarInfo::TOP) {
+               if (newline)
+                       addToolBarBreak(Qt::TopToolBarArea);
+               addToolBar(Qt::TopToolBarArea, Tb);
+       }
+
+       if (tbinfo.flags & ToolbarInfo::BOTTOM) {
+// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
+#if (QT_VERSION >= 0x040202)
+               if (newline)
+                       addToolBarBreak(Qt::BottomToolBarArea);
+#endif
+               addToolBar(Qt::BottomToolBarArea, Tb);
+       }
+
+       if (tbinfo.flags & ToolbarInfo::LEFT) {
+// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
+#if (QT_VERSION >= 0x040202)
+               if (newline)
+                       addToolBarBreak(Qt::LeftToolBarArea);
+#endif
+               addToolBar(Qt::LeftToolBarArea, Tb);
+       }
+
+       if (tbinfo.flags & ToolbarInfo::RIGHT) {
+// Qt < 4.2.2 cannot handle ToolBarBreak on non-TOP dock.
+#if (QT_VERSION >= 0x040202)
+               if (newline)
+                       addToolBarBreak(Qt::RightToolBarArea);
+#endif
+               addToolBar(Qt::RightToolBarArea, Tb);
+       }
+
+       // The following does not work so I cannot restore to exact toolbar location
+       /*
+       ToolbarSection::ToolbarInfo & tbinfo = LyX::ref().session().toolbars().load(tbinfo.name);
+       Tb->move(tbinfo.posx, tbinfo.posy);
+       */
+
+       return Toolbars::ToolbarPtr(Tb);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "GuiView_moc.cpp"
diff --git a/src/frontends/qt4/GuiWorkArea.C b/src/frontends/qt4/GuiWorkArea.C
deleted file mode 100644 (file)
index 436e7f1..0000000
+++ /dev/null
@@ -1,743 +0,0 @@
-/**
- * \file GuiWorkArea.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "GuiWorkArea.h"
-
-#include "GuiApplication.h"
-#include "QLPainter.h"
-#include "QLyXKeySym.h"
-#include "qt_helpers.h"
-
-#include "LyXView.h"
-
-#include "BufferView.h"
-#include "rowpainter.h"
-#include "debug.h"
-#include "funcrequest.h"
-#include "LColor.h"
-#include "version.h"
-#include "lyxrc.h"
-
-#include "support/filetools.h" // LibFileSearch
-#include "support/os.h"
-#include "support/convert.h"
-
-#include "graphics/GraphicsImage.h"
-#include "graphics/GraphicsLoader.h"
-
-#include <QLayout>
-#include <QMainWindow>
-#include <QMimeData>
-#include <QUrl>
-#include <QDragEnterEvent>
-#include <QPainter>
-#include <QScrollBar>
-#include <QTimer>
-#include <QInputContext>
-
-#include <boost/bind.hpp>
-#include <boost/current_function.hpp>
-
-#ifdef Q_WS_WIN
-int const CursorWidth = 2;
-#else
-int const CursorWidth = 1;
-#endif
-
-
-using std::endl;
-using std::string;
-
-namespace os = lyx::support::os;
-
-
-namespace lyx {
-
-using support::FileName;
-
-/// return the LyX key state from Qt's
-static key_modifier::state q_key_state(Qt::KeyboardModifiers state)
-{
-       key_modifier::state k = key_modifier::none;
-       if (state & Qt::ControlModifier)
-               k |= key_modifier::ctrl;
-       if (state & Qt::ShiftModifier)
-               k |= key_modifier::shift;
-       if (state & Qt::AltModifier || state & Qt::MetaModifier)
-               k |= key_modifier::alt;
-       return k;
-}
-
-
-/// return the LyX mouse button state from Qt's
-static mouse_button::state q_button_state(Qt::MouseButton button)
-{
-       mouse_button::state b = mouse_button::none;
-       switch (button) {
-               case Qt::LeftButton:
-                       b = mouse_button::button1;
-                       break;
-               case Qt::MidButton:
-                       b = mouse_button::button2;
-                       break;
-               case Qt::RightButton:
-                       b = mouse_button::button3;
-                       break;
-               default:
-                       break;
-       }
-       return b;
-}
-
-
-/// return the LyX mouse button state from Qt's
-mouse_button::state q_motion_state(Qt::MouseButtons state)
-{
-       mouse_button::state b = mouse_button::none;
-       if (state & Qt::LeftButton)
-               b |= mouse_button::button1;
-       if (state & Qt::MidButton)
-               b |= mouse_button::button2;
-       if (state & Qt::RightButton)
-               b |= mouse_button::button3;
-       return b;
-}
-
-
-namespace frontend {
-
-class CursorWidget {
-public:
-       CursorWidget() {}
-
-       void draw(QPainter & painter)
-       {
-               // FIXME: do something depending on the cursor shape.
-               if (show_ && rect_.isValid())
-                       painter.fillRect(rect_, color_);
-       }
-
-       void update(int x, int y, int h, CursorShape shape)
-       {
-               color_ = guiApp->colorCache().get(LColor::cursor);
-               rect_ = QRect(x, y, CursorWidth, h);
-               shape_ = shape;
-       }
-
-       void show(bool set_show = true) { show_ = set_show; }
-       void hide() { show_ = false; }
-
-       QRect const & rect() { return rect_; }
-
-private:
-       ///
-       CursorShape shape_;
-       ///
-       bool show_;
-       ///
-       QColor color_;
-       ///
-       QRect rect_;
-};
-
-
-// This is a 'heartbeat' generating synthetic mouse move events when the
-// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
-SyntheticMouseEvent::SyntheticMouseEvent()
-       : timeout(200), restart_timeout(true),
-         x_old(-1), y_old(-1), scrollbar_value_old(-1.0)
-{}
-
-
-GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view)
-       : WorkArea(id, lyx_view), need_resize_(false), schedule_redraw_(false),
-         preedit_lines_(1)
-{
-       screen_ = QPixmap(viewport()->width(), viewport()->height());
-       cursor_ = new frontend::CursorWidget();
-       cursor_->hide();
-
-       setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
-       setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-       setAcceptDrops(true);
-       setMouseTracking(true);
-       setMinimumSize(100, 70);
-
-       viewport()->setAutoFillBackground(false);
-       // We don't need double-buffering nor SystemBackground on
-       // the viewport because we have our own backing pixmap.
-       viewport()->setAttribute(Qt::WA_NoSystemBackground);
-
-       setFocusPolicy(Qt::WheelFocus);
-
-       viewport()->setCursor(Qt::IBeamCursor);
-
-       resize(w, h);
-
-       synthetic_mouse_event_.timeout.timeout.connect(
-               boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
-                           this));
-
-       // Initialize the vertical Scroll Bar
-       QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
-               this, SLOT(adjustViewWithScrollBar(int)));
-
-       // disable context menu for the scrollbar
-       verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
-
-       // PageStep only depends on the viewport height.
-       verticalScrollBar()->setPageStep(viewport()->height());
-
-       LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
-               << "\n Area width\t" << width()
-               << "\n Area height\t" << height()
-               << "\n viewport width\t" << viewport()->width()
-               << "\n viewport height\t" << viewport()->height()
-               << endl;
-
-       // Enables input methods for asian languages.
-       // Must be set when creating custom text editing widgets.
-       setAttribute(Qt::WA_InputMethodEnabled, true);
-}
-
-
-void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
-{
-       if (verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOn)
-               setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-
-       verticalScrollBar()->setTracking(false);
-
-       // do what cursor movement does (some grey)
-       h += height() / 4;
-       int scroll_max_ = std::max(0, h - height());
-
-       verticalScrollBar()->setRange(0, scroll_max_);
-       verticalScrollBar()->setSliderPosition(scroll_pos);
-       verticalScrollBar()->setSingleStep(scroll_line_step);
-       verticalScrollBar()->setValue(scroll_pos);
-
-       verticalScrollBar()->setTracking(true);
-}
-
-
-void GuiWorkArea::adjustViewWithScrollBar(int)
-{
-       scrollBufferView(verticalScrollBar()->sliderPosition());
-}
-
-
-void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event)
-{
-       if (event->mimeData()->hasUrls())
-               event->accept();
-       /// \todo Ask lyx-devel is this is enough:
-       /// if (event->mimeData()->hasFormat("text/plain"))
-       ///     event->acceptProposedAction();
-}
-
-
-void GuiWorkArea::dropEvent(QDropEvent* event)
-{
-       QList<QUrl> files = event->mimeData()->urls();
-       if (files.isEmpty())
-               return;
-
-       LYXERR(Debug::GUI) << "GuiWorkArea::dropEvent: got URIs!" << endl;
-       for (int i = 0; i!=files.size(); ++i) {
-               string const file = os::internal_path(fromqstr(files.at(i).toLocalFile()));
-               if (!file.empty())
-                       dispatch(FuncRequest(LFUN_FILE_OPEN, file));
-       }
-}
-
-
-void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
-{
-       // No need to do anything if we didn't change views...
-//     if (theApp() == 0 || &lyx_view_ == theApp()->currentView())
-//             return;
-
-       theApp()->setCurrentView(lyx_view_);
-
-       // Repaint the whole screen.
-       // Note: this is different from redraw() as only the backing pixmap
-       // will be redrawn, which is cheap.
-       viewport()->repaint();
-
-       // FIXME: it would be better to send a signal "newBuffer()"
-       // in BufferList that could be connected to the different tabbars.
-       lyx_view_.updateTab();
-
-       startBlinkingCursor();
-}
-
-
-void GuiWorkArea::focusOutEvent(QFocusEvent * /*event*/)
-{
-       stopBlinkingCursor();
-}
-
-
-void GuiWorkArea::mousePressEvent(QMouseEvent * e)
-{
-       if (dc_event_.active && dc_event_ == *e) {
-               dc_event_.active = false;
-               FuncRequest cmd(LFUN_MOUSE_TRIPLE,
-                       e->x(), e->y(),
-                       q_button_state(e->button()));
-               dispatch(cmd);
-               return;
-       }
-
-       inputContext()->reset();
-
-       FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
-               q_button_state(e->button()));
-       dispatch(cmd, q_key_state(e->modifiers()));
-}
-
-
-void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
-{
-       if (synthetic_mouse_event_.timeout.running())
-               synthetic_mouse_event_.timeout.stop();
-
-       FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
-                             q_button_state(e->button()));
-       dispatch(cmd);
-}
-
-
-void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
-{
-       // we kill the triple click if we move
-       doubleClickTimeout();
-       FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
-                             q_motion_state(e->buttons()));
-
-       // If we're above or below the work area...
-       if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
-               // Make sure only a synthetic event can cause a page scroll,
-               // so they come at a steady rate:
-               if (e->y() <= 20)
-                       // _Force_ a scroll up:
-                       cmd.y = -40;
-               else
-                       cmd.y = viewport()->height();
-               // Store the event, to be handled when the timeout expires.
-               synthetic_mouse_event_.cmd = cmd;
-
-               if (synthetic_mouse_event_.timeout.running())
-                       // Discard the event. Note that it _may_ be handled
-                       // when the timeout expires if
-                       // synthetic_mouse_event_.cmd has not been overwritten.
-                       // Ie, when the timeout expires, we handle the
-                       // most recent event but discard all others that
-                       // occurred after the one used to start the timeout
-                       // in the first place.
-                       return;
-               else {
-                       synthetic_mouse_event_.restart_timeout = true;
-                       synthetic_mouse_event_.timeout.start();
-                       // Fall through to handle this event...
-               }
-
-       } else if (synthetic_mouse_event_.timeout.running()) {
-               // Store the event, to be possibly handled when the timeout
-               // expires.
-               // Once the timeout has expired, normal control is returned
-               // to mouseMoveEvent (restart_timeout = false).
-               // This results in a much smoother 'feel' when moving the
-               // mouse back into the work area.
-               synthetic_mouse_event_.cmd = cmd;
-               synthetic_mouse_event_.restart_timeout = false;
-               return;
-       }
-
-       // Has anything changed on-screen since the last QMouseEvent
-       // was received?
-       double const scrollbar_value = verticalScrollBar()->value();
-       if (e->x() != synthetic_mouse_event_.x_old ||
-           e->y() != synthetic_mouse_event_.y_old ||
-           scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
-               // Yes it has. Store the params used to check this.
-               synthetic_mouse_event_.x_old = e->x();
-               synthetic_mouse_event_.y_old = e->y();
-               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
-
-               // ... and dispatch the event to the LyX core.
-               dispatch(cmd);
-       }
-}
-
-
-void GuiWorkArea::wheelEvent(QWheelEvent * e)
-{
-       // Wheel rotation by one notch results in a delta() of 120 (see
-       // documentation of QWheelEvent)
-       int const lines = qApp->wheelScrollLines() * e->delta() / 120;
-       verticalScrollBar()->setValue(verticalScrollBar()->value() -
-                       lines *  verticalScrollBar()->singleStep());
-       adjustViewWithScrollBar();
-}
-
-
-void GuiWorkArea::generateSyntheticMouseEvent()
-{
-// Set things off to generate the _next_ 'pseudo' event.
-       if (synthetic_mouse_event_.restart_timeout)
-               synthetic_mouse_event_.timeout.start();
-
-       // Has anything changed on-screen since the last timeout signal
-       // was received?
-       double const scrollbar_value = verticalScrollBar()->value();
-       if (scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
-               // Yes it has. Store the params used to check this.
-               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
-
-               // ... and dispatch the event to the LyX core.
-               dispatch(synthetic_mouse_event_.cmd);
-       }
-}
-
-
-void GuiWorkArea::keyPressEvent(QKeyEvent * e)
-{
-       LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
-               << " count=" << e->count()
-               << " text=" << fromqstr(e->text())
-               << " isAutoRepeat=" << e->isAutoRepeat()
-               << " key=" << e->key()
-               << endl;
-
-       boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
-       sym->set(e);
-       processKeySym(sym, q_key_state(e->modifiers()));
-}
-
-void GuiWorkArea::doubleClickTimeout() {
-       dc_event_.active = false;
-}
-
-void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
-{
-       dc_event_ = double_click(e);
-       QTimer::singleShot(QApplication::doubleClickInterval(), this,
-                          SLOT(doubleClickTimeout()));
-       FuncRequest cmd(LFUN_MOUSE_DOUBLE,
-                       e->x(), e->y(),
-                       q_button_state(e->button()));
-       dispatch(cmd);
-}
-
-
-void GuiWorkArea::resizeEvent(QResizeEvent * ev)
-{
-       QAbstractScrollArea::resizeEvent(ev);
-       need_resize_ = true;
-}
-
-
-void GuiWorkArea::update(int x, int y, int w, int h)
-{
-       viewport()->repaint(x, y, w, h);
-}
-
-
-void GuiWorkArea::doGreyOut(QLPainter & pain)
-{
-       pain.fillRectangle(0, 0, width(), height(),
-               LColor::bottomarea);
-
-       //if (!lyxrc.show_banner)
-       //      return;
-       LYXERR(Debug::GUI) << "show banner: " << lyxrc.show_banner << endl;
-       /// The text to be written on top of the pixmap
-       QString const text = lyx_version ? QString(lyx_version) : qt_("unknown version");
-       FileName const file = support::libFileSearch("images", "banner", "png");
-       if (file.empty())
-               return;
-
-       QPixmap pm(toqstr(file.absFilename()));
-       if (!pm) {
-               lyxerr << "could not load splash screen: '" << file << "'" << endl;
-               return;
-       }
-
-       QFont font;
-       // The font used to display the version info
-       font.setStyleHint(QFont::SansSerif);
-       font.setWeight(QFont::Bold);
-       font.setPointSize(convert<int>(lyxrc.font_sizes[LyXFont::SIZE_LARGE]));
-
-       int const w = pm.width();
-       int const h = pm.height();
-
-       int x = (width() - w) / 2;
-       int y = (height() - h) / 2;
-
-       pain.drawPixmap(x, y, pm);
-
-       x += 260;
-       y += 270;
-
-       pain.setPen(QColor(255, 255, 0));
-       pain.setFont(font);
-       pain.drawText(x, y, text);
-}
-
-
-void GuiWorkArea::paintEvent(QPaintEvent * ev)
-{
-       QRect const rc = ev->rect(); 
-       /*
-       LYXERR(Debug::PAINTING) << "paintEvent begin: x: " << rc.x()
-               << " y: " << rc.y()
-               << " w: " << rc.width()
-               << " h: " << rc.height() << endl;
-       */
-
-       if (need_resize_) {
-               verticalScrollBar()->setPageStep(viewport()->height());
-               screen_ = QPixmap(viewport()->width(), viewport()->height());
-               resizeBufferView();
-               updateScreen();
-               need_resize_ = false;
-       }
-
-       QPainter pain(viewport());
-       pain.drawPixmap(rc, screen_, rc);
-       cursor_->draw(pain);
-}
-
-
-void GuiWorkArea::expose(int x, int y, int w, int h)
-{
-       updateScreen();
-       update(x, y, w, h);
-}
-
-
-void GuiWorkArea::updateScreen()
-{
-       QLPainter pain(&screen_);
-
-       if (greyed_out_) {
-               LYXERR(Debug::GUI) << "splash screen requested" << endl;
-               verticalScrollBar()->hide();
-               doGreyOut(pain);
-               return;
-       }
-
-       verticalScrollBar()->show();
-       paintText(*buffer_view_, pain);
-}
-
-
-void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
-{
-       if (schedule_redraw_) {
-               if (buffer_view_ && buffer_view_->buffer()) {
-                       buffer_view_->update(Update::Force);
-                       updateScreen();
-                       viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
-               }
-               schedule_redraw_ = false;
-               // Show the cursor immediately after the update.
-               hideCursor();
-               toggleCursor();
-               return;
-       }
-
-       cursor_->update(x, y, h, shape);
-       cursor_->show();
-       viewport()->update(cursor_->rect());
-}
-
-
-void GuiWorkArea::removeCursor()
-{
-       cursor_->hide();
-       //if (!qApp->focusWidget())
-               viewport()->update(cursor_->rect());
-}
-
-
-void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
-{
-       QString const & commit_string = e->commitString();
-       docstring const & preedit_string
-               = qstring_to_ucs4(e->preeditString());
-
-       if(greyed_out_) {
-               e->ignore();
-               return;
-       }
-
-       if (!commit_string.isEmpty()) {
-
-               LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
-                       << " preeditString =" << fromqstr(e->preeditString())
-                       << " commitString  =" << fromqstr(e->commitString())
-                       << endl;
-
-               int key = 0;
-
-               // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
-               for (int i = 0; i < commit_string.size(); ++i) {
-                       QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
-                       keyPressEvent(&ev);
-               }
-       }
-
-       // Hide the cursor during the kana-kanji transformation. 
-       if (preedit_string.empty())
-               startBlinkingCursor();
-       else
-               stopBlinkingCursor();
-
-       // last_width : for checking if last preedit string was/wasn't empty.
-       static bool last_width = false;
-       if (!last_width && preedit_string.empty()) {
-               // if last_width is last length of preedit string. 
-               e->accept();
-               return;
-       }
-
-       QLPainter pain(&screen_);
-       buffer_view_->updateMetrics(false);
-       paintText(*buffer_view_, pain);
-       LyXFont font = buffer_view_->cursor().getFont();
-       FontMetrics const & fm = theFontMetrics(font);
-       int height = fm.maxHeight();
-       int cur_x = cursor_->rect().left();
-       int cur_y = cursor_->rect().bottom();
-
-       // redraw area of preedit string.
-       update(0, cur_y - height, GuiWorkArea::width(),
-               (height + 1) * preedit_lines_);
-
-       if (preedit_string.empty()) {
-               last_width = false;
-               preedit_lines_ = 1;
-               e->accept();
-               return;
-       }
-       last_width = true;
-
-       // att : stores an IM attribute.
-       QList<QInputMethodEvent::Attribute> const & att = e->attributes();
-
-       // get attributes of input method cursor.
-       // cursor_pos : cursor position in preedit string.
-       size_t cursor_pos = 0;
-       bool cursor_is_visible = false;
-       for (int i = 0; i < att.size(); ++i) {
-               if (att.at(i).type == QInputMethodEvent::Cursor) {
-                       cursor_pos = att.at(i).start;
-                       cursor_is_visible = att.at(i).length != 0;
-                       break;
-               }
-       }
-
-       size_t preedit_length = preedit_string.length();
-
-       // get position of selection in input method.
-       // FIXME: isn't there a way to do this simplier?
-       // rStart : cursor position in selected string in IM.
-       size_t rStart = 0;
-       // rLength : selected string length in IM.
-       size_t rLength = 0;
-       if (cursor_pos < preedit_length) {
-               for (int i = 0; i < att.size(); ++i) {
-                       if (att.at(i).type == QInputMethodEvent::TextFormat) {
-                               if (att.at(i).start <= int(cursor_pos)
-                                       && int(cursor_pos) < att.at(i).start + att.at(i).length) {
-                                               rStart = att.at(i).start;
-                                               rLength = att.at(i).length;
-                                               if (!cursor_is_visible)
-                                                       cursor_pos += rLength;
-                                               break;
-                               }
-                       }
-               }
-       }
-       else {
-               rStart = cursor_pos;
-               rLength = 0;
-       }
-
-       int const right_margin = rightMargin();
-       Painter::preedit_style ps;
-       // Most often there would be only one line:
-       preedit_lines_ = 1;
-       for (size_t pos = 0; pos != preedit_length; ++pos) {
-               char_type const typed_char = preedit_string[pos];
-               // reset preedit string style
-               ps = Painter::preedit_default;
-
-               // if we reached the right extremity of the screen, go to next line.
-               if (cur_x + fm.width(typed_char) > GuiWorkArea::width() - right_margin) {
-                       cur_x = right_margin;
-                       cur_y += height + 1;
-                       ++preedit_lines_;
-               }
-               // preedit strings are displayed with dashed underline
-               // and partial strings are displayed white on black indicating
-               // that we are in selecting mode in the input method.
-               // FIXME: rLength == preedit_length is not a changing condition
-               // FIXME: should be put out of the loop.
-               if (pos >= rStart 
-                       && pos < rStart + rLength
-                       && !(cursor_pos < rLength && rLength == preedit_length))
-                       ps = Painter::preedit_selecting;
-
-               if (pos == cursor_pos
-                       && (cursor_pos < rLength && rLength == preedit_length))
-                       ps = Painter::preedit_cursor;
-
-               // draw one character and update cur_x.
-               cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
-       }
-
-       // update the preedit string screen area.
-       update(0, cur_y - preedit_lines_*height, GuiWorkArea::width(),
-               (height + 1) * preedit_lines_);
-
-       // Don't forget to accept the event!
-       e->accept();
-}
-
-
-QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
-{
-       QRect cur_r(0,0,0,0);
-       switch (query) {
-               // this is the CJK-specific composition window position.
-               case Qt::ImMicroFocus:
-                       cur_r = cursor_->rect();
-                       if (preedit_lines_ != 1)
-                               cur_r.moveLeft(10);
-                       cur_r.moveBottom(cur_r.bottom() + cur_r.height() * preedit_lines_);
-                       // return lower right of cursor in LyX.
-                       return cur_r;
-               default:
-                       return QWidget::inputMethodQuery(query);
-       }
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "GuiWorkArea_moc.cpp"
diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp
new file mode 100644 (file)
index 0000000..436e7f1
--- /dev/null
@@ -0,0 +1,743 @@
+/**
+ * \file GuiWorkArea.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiWorkArea.h"
+
+#include "GuiApplication.h"
+#include "QLPainter.h"
+#include "QLyXKeySym.h"
+#include "qt_helpers.h"
+
+#include "LyXView.h"
+
+#include "BufferView.h"
+#include "rowpainter.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "LColor.h"
+#include "version.h"
+#include "lyxrc.h"
+
+#include "support/filetools.h" // LibFileSearch
+#include "support/os.h"
+#include "support/convert.h"
+
+#include "graphics/GraphicsImage.h"
+#include "graphics/GraphicsLoader.h"
+
+#include <QLayout>
+#include <QMainWindow>
+#include <QMimeData>
+#include <QUrl>
+#include <QDragEnterEvent>
+#include <QPainter>
+#include <QScrollBar>
+#include <QTimer>
+#include <QInputContext>
+
+#include <boost/bind.hpp>
+#include <boost/current_function.hpp>
+
+#ifdef Q_WS_WIN
+int const CursorWidth = 2;
+#else
+int const CursorWidth = 1;
+#endif
+
+
+using std::endl;
+using std::string;
+
+namespace os = lyx::support::os;
+
+
+namespace lyx {
+
+using support::FileName;
+
+/// return the LyX key state from Qt's
+static key_modifier::state q_key_state(Qt::KeyboardModifiers state)
+{
+       key_modifier::state k = key_modifier::none;
+       if (state & Qt::ControlModifier)
+               k |= key_modifier::ctrl;
+       if (state & Qt::ShiftModifier)
+               k |= key_modifier::shift;
+       if (state & Qt::AltModifier || state & Qt::MetaModifier)
+               k |= key_modifier::alt;
+       return k;
+}
+
+
+/// return the LyX mouse button state from Qt's
+static mouse_button::state q_button_state(Qt::MouseButton button)
+{
+       mouse_button::state b = mouse_button::none;
+       switch (button) {
+               case Qt::LeftButton:
+                       b = mouse_button::button1;
+                       break;
+               case Qt::MidButton:
+                       b = mouse_button::button2;
+                       break;
+               case Qt::RightButton:
+                       b = mouse_button::button3;
+                       break;
+               default:
+                       break;
+       }
+       return b;
+}
+
+
+/// return the LyX mouse button state from Qt's
+mouse_button::state q_motion_state(Qt::MouseButtons state)
+{
+       mouse_button::state b = mouse_button::none;
+       if (state & Qt::LeftButton)
+               b |= mouse_button::button1;
+       if (state & Qt::MidButton)
+               b |= mouse_button::button2;
+       if (state & Qt::RightButton)
+               b |= mouse_button::button3;
+       return b;
+}
+
+
+namespace frontend {
+
+class CursorWidget {
+public:
+       CursorWidget() {}
+
+       void draw(QPainter & painter)
+       {
+               // FIXME: do something depending on the cursor shape.
+               if (show_ && rect_.isValid())
+                       painter.fillRect(rect_, color_);
+       }
+
+       void update(int x, int y, int h, CursorShape shape)
+       {
+               color_ = guiApp->colorCache().get(LColor::cursor);
+               rect_ = QRect(x, y, CursorWidth, h);
+               shape_ = shape;
+       }
+
+       void show(bool set_show = true) { show_ = set_show; }
+       void hide() { show_ = false; }
+
+       QRect const & rect() { return rect_; }
+
+private:
+       ///
+       CursorShape shape_;
+       ///
+       bool show_;
+       ///
+       QColor color_;
+       ///
+       QRect rect_;
+};
+
+
+// This is a 'heartbeat' generating synthetic mouse move events when the
+// cursor is at the top or bottom edge of the viewport. One scroll per 0.2 s
+SyntheticMouseEvent::SyntheticMouseEvent()
+       : timeout(200), restart_timeout(true),
+         x_old(-1), y_old(-1), scrollbar_value_old(-1.0)
+{}
+
+
+GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view)
+       : WorkArea(id, lyx_view), need_resize_(false), schedule_redraw_(false),
+         preedit_lines_(1)
+{
+       screen_ = QPixmap(viewport()->width(), viewport()->height());
+       cursor_ = new frontend::CursorWidget();
+       cursor_->hide();
+
+       setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+       setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+       setAcceptDrops(true);
+       setMouseTracking(true);
+       setMinimumSize(100, 70);
+
+       viewport()->setAutoFillBackground(false);
+       // We don't need double-buffering nor SystemBackground on
+       // the viewport because we have our own backing pixmap.
+       viewport()->setAttribute(Qt::WA_NoSystemBackground);
+
+       setFocusPolicy(Qt::WheelFocus);
+
+       viewport()->setCursor(Qt::IBeamCursor);
+
+       resize(w, h);
+
+       synthetic_mouse_event_.timeout.timeout.connect(
+               boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
+                           this));
+
+       // Initialize the vertical Scroll Bar
+       QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
+               this, SLOT(adjustViewWithScrollBar(int)));
+
+       // disable context menu for the scrollbar
+       verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu);
+
+       // PageStep only depends on the viewport height.
+       verticalScrollBar()->setPageStep(viewport()->height());
+
+       LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
+               << "\n Area width\t" << width()
+               << "\n Area height\t" << height()
+               << "\n viewport width\t" << viewport()->width()
+               << "\n viewport height\t" << viewport()->height()
+               << endl;
+
+       // Enables input methods for asian languages.
+       // Must be set when creating custom text editing widgets.
+       setAttribute(Qt::WA_InputMethodEnabled, true);
+}
+
+
+void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
+{
+       if (verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOn)
+               setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+
+       verticalScrollBar()->setTracking(false);
+
+       // do what cursor movement does (some grey)
+       h += height() / 4;
+       int scroll_max_ = std::max(0, h - height());
+
+       verticalScrollBar()->setRange(0, scroll_max_);
+       verticalScrollBar()->setSliderPosition(scroll_pos);
+       verticalScrollBar()->setSingleStep(scroll_line_step);
+       verticalScrollBar()->setValue(scroll_pos);
+
+       verticalScrollBar()->setTracking(true);
+}
+
+
+void GuiWorkArea::adjustViewWithScrollBar(int)
+{
+       scrollBufferView(verticalScrollBar()->sliderPosition());
+}
+
+
+void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event)
+{
+       if (event->mimeData()->hasUrls())
+               event->accept();
+       /// \todo Ask lyx-devel is this is enough:
+       /// if (event->mimeData()->hasFormat("text/plain"))
+       ///     event->acceptProposedAction();
+}
+
+
+void GuiWorkArea::dropEvent(QDropEvent* event)
+{
+       QList<QUrl> files = event->mimeData()->urls();
+       if (files.isEmpty())
+               return;
+
+       LYXERR(Debug::GUI) << "GuiWorkArea::dropEvent: got URIs!" << endl;
+       for (int i = 0; i!=files.size(); ++i) {
+               string const file = os::internal_path(fromqstr(files.at(i).toLocalFile()));
+               if (!file.empty())
+                       dispatch(FuncRequest(LFUN_FILE_OPEN, file));
+       }
+}
+
+
+void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
+{
+       // No need to do anything if we didn't change views...
+//     if (theApp() == 0 || &lyx_view_ == theApp()->currentView())
+//             return;
+
+       theApp()->setCurrentView(lyx_view_);
+
+       // Repaint the whole screen.
+       // Note: this is different from redraw() as only the backing pixmap
+       // will be redrawn, which is cheap.
+       viewport()->repaint();
+
+       // FIXME: it would be better to send a signal "newBuffer()"
+       // in BufferList that could be connected to the different tabbars.
+       lyx_view_.updateTab();
+
+       startBlinkingCursor();
+}
+
+
+void GuiWorkArea::focusOutEvent(QFocusEvent * /*event*/)
+{
+       stopBlinkingCursor();
+}
+
+
+void GuiWorkArea::mousePressEvent(QMouseEvent * e)
+{
+       if (dc_event_.active && dc_event_ == *e) {
+               dc_event_.active = false;
+               FuncRequest cmd(LFUN_MOUSE_TRIPLE,
+                       e->x(), e->y(),
+                       q_button_state(e->button()));
+               dispatch(cmd);
+               return;
+       }
+
+       inputContext()->reset();
+
+       FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
+               q_button_state(e->button()));
+       dispatch(cmd, q_key_state(e->modifiers()));
+}
+
+
+void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
+{
+       if (synthetic_mouse_event_.timeout.running())
+               synthetic_mouse_event_.timeout.stop();
+
+       FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
+                             q_button_state(e->button()));
+       dispatch(cmd);
+}
+
+
+void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
+{
+       // we kill the triple click if we move
+       doubleClickTimeout();
+       FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
+                             q_motion_state(e->buttons()));
+
+       // If we're above or below the work area...
+       if (e->y() <= 20 || e->y() >= viewport()->height() - 20) {
+               // Make sure only a synthetic event can cause a page scroll,
+               // so they come at a steady rate:
+               if (e->y() <= 20)
+                       // _Force_ a scroll up:
+                       cmd.y = -40;
+               else
+                       cmd.y = viewport()->height();
+               // Store the event, to be handled when the timeout expires.
+               synthetic_mouse_event_.cmd = cmd;
+
+               if (synthetic_mouse_event_.timeout.running())
+                       // Discard the event. Note that it _may_ be handled
+                       // when the timeout expires if
+                       // synthetic_mouse_event_.cmd has not been overwritten.
+                       // Ie, when the timeout expires, we handle the
+                       // most recent event but discard all others that
+                       // occurred after the one used to start the timeout
+                       // in the first place.
+                       return;
+               else {
+                       synthetic_mouse_event_.restart_timeout = true;
+                       synthetic_mouse_event_.timeout.start();
+                       // Fall through to handle this event...
+               }
+
+       } else if (synthetic_mouse_event_.timeout.running()) {
+               // Store the event, to be possibly handled when the timeout
+               // expires.
+               // Once the timeout has expired, normal control is returned
+               // to mouseMoveEvent (restart_timeout = false).
+               // This results in a much smoother 'feel' when moving the
+               // mouse back into the work area.
+               synthetic_mouse_event_.cmd = cmd;
+               synthetic_mouse_event_.restart_timeout = false;
+               return;
+       }
+
+       // Has anything changed on-screen since the last QMouseEvent
+       // was received?
+       double const scrollbar_value = verticalScrollBar()->value();
+       if (e->x() != synthetic_mouse_event_.x_old ||
+           e->y() != synthetic_mouse_event_.y_old ||
+           scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
+               // Yes it has. Store the params used to check this.
+               synthetic_mouse_event_.x_old = e->x();
+               synthetic_mouse_event_.y_old = e->y();
+               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
+
+               // ... and dispatch the event to the LyX core.
+               dispatch(cmd);
+       }
+}
+
+
+void GuiWorkArea::wheelEvent(QWheelEvent * e)
+{
+       // Wheel rotation by one notch results in a delta() of 120 (see
+       // documentation of QWheelEvent)
+       int const lines = qApp->wheelScrollLines() * e->delta() / 120;
+       verticalScrollBar()->setValue(verticalScrollBar()->value() -
+                       lines *  verticalScrollBar()->singleStep());
+       adjustViewWithScrollBar();
+}
+
+
+void GuiWorkArea::generateSyntheticMouseEvent()
+{
+// Set things off to generate the _next_ 'pseudo' event.
+       if (synthetic_mouse_event_.restart_timeout)
+               synthetic_mouse_event_.timeout.start();
+
+       // Has anything changed on-screen since the last timeout signal
+       // was received?
+       double const scrollbar_value = verticalScrollBar()->value();
+       if (scrollbar_value != synthetic_mouse_event_.scrollbar_value_old) {
+               // Yes it has. Store the params used to check this.
+               synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
+
+               // ... and dispatch the event to the LyX core.
+               dispatch(synthetic_mouse_event_.cmd);
+       }
+}
+
+
+void GuiWorkArea::keyPressEvent(QKeyEvent * e)
+{
+       LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
+               << " count=" << e->count()
+               << " text=" << fromqstr(e->text())
+               << " isAutoRepeat=" << e->isAutoRepeat()
+               << " key=" << e->key()
+               << endl;
+
+       boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
+       sym->set(e);
+       processKeySym(sym, q_key_state(e->modifiers()));
+}
+
+void GuiWorkArea::doubleClickTimeout() {
+       dc_event_.active = false;
+}
+
+void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
+{
+       dc_event_ = double_click(e);
+       QTimer::singleShot(QApplication::doubleClickInterval(), this,
+                          SLOT(doubleClickTimeout()));
+       FuncRequest cmd(LFUN_MOUSE_DOUBLE,
+                       e->x(), e->y(),
+                       q_button_state(e->button()));
+       dispatch(cmd);
+}
+
+
+void GuiWorkArea::resizeEvent(QResizeEvent * ev)
+{
+       QAbstractScrollArea::resizeEvent(ev);
+       need_resize_ = true;
+}
+
+
+void GuiWorkArea::update(int x, int y, int w, int h)
+{
+       viewport()->repaint(x, y, w, h);
+}
+
+
+void GuiWorkArea::doGreyOut(QLPainter & pain)
+{
+       pain.fillRectangle(0, 0, width(), height(),
+               LColor::bottomarea);
+
+       //if (!lyxrc.show_banner)
+       //      return;
+       LYXERR(Debug::GUI) << "show banner: " << lyxrc.show_banner << endl;
+       /// The text to be written on top of the pixmap
+       QString const text = lyx_version ? QString(lyx_version) : qt_("unknown version");
+       FileName const file = support::libFileSearch("images", "banner", "png");
+       if (file.empty())
+               return;
+
+       QPixmap pm(toqstr(file.absFilename()));
+       if (!pm) {
+               lyxerr << "could not load splash screen: '" << file << "'" << endl;
+               return;
+       }
+
+       QFont font;
+       // The font used to display the version info
+       font.setStyleHint(QFont::SansSerif);
+       font.setWeight(QFont::Bold);
+       font.setPointSize(convert<int>(lyxrc.font_sizes[LyXFont::SIZE_LARGE]));
+
+       int const w = pm.width();
+       int const h = pm.height();
+
+       int x = (width() - w) / 2;
+       int y = (height() - h) / 2;
+
+       pain.drawPixmap(x, y, pm);
+
+       x += 260;
+       y += 270;
+
+       pain.setPen(QColor(255, 255, 0));
+       pain.setFont(font);
+       pain.drawText(x, y, text);
+}
+
+
+void GuiWorkArea::paintEvent(QPaintEvent * ev)
+{
+       QRect const rc = ev->rect(); 
+       /*
+       LYXERR(Debug::PAINTING) << "paintEvent begin: x: " << rc.x()
+               << " y: " << rc.y()
+               << " w: " << rc.width()
+               << " h: " << rc.height() << endl;
+       */
+
+       if (need_resize_) {
+               verticalScrollBar()->setPageStep(viewport()->height());
+               screen_ = QPixmap(viewport()->width(), viewport()->height());
+               resizeBufferView();
+               updateScreen();
+               need_resize_ = false;
+       }
+
+       QPainter pain(viewport());
+       pain.drawPixmap(rc, screen_, rc);
+       cursor_->draw(pain);
+}
+
+
+void GuiWorkArea::expose(int x, int y, int w, int h)
+{
+       updateScreen();
+       update(x, y, w, h);
+}
+
+
+void GuiWorkArea::updateScreen()
+{
+       QLPainter pain(&screen_);
+
+       if (greyed_out_) {
+               LYXERR(Debug::GUI) << "splash screen requested" << endl;
+               verticalScrollBar()->hide();
+               doGreyOut(pain);
+               return;
+       }
+
+       verticalScrollBar()->show();
+       paintText(*buffer_view_, pain);
+}
+
+
+void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
+{
+       if (schedule_redraw_) {
+               if (buffer_view_ && buffer_view_->buffer()) {
+                       buffer_view_->update(Update::Force);
+                       updateScreen();
+                       viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
+               }
+               schedule_redraw_ = false;
+               // Show the cursor immediately after the update.
+               hideCursor();
+               toggleCursor();
+               return;
+       }
+
+       cursor_->update(x, y, h, shape);
+       cursor_->show();
+       viewport()->update(cursor_->rect());
+}
+
+
+void GuiWorkArea::removeCursor()
+{
+       cursor_->hide();
+       //if (!qApp->focusWidget())
+               viewport()->update(cursor_->rect());
+}
+
+
+void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
+{
+       QString const & commit_string = e->commitString();
+       docstring const & preedit_string
+               = qstring_to_ucs4(e->preeditString());
+
+       if(greyed_out_) {
+               e->ignore();
+               return;
+       }
+
+       if (!commit_string.isEmpty()) {
+
+               LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
+                       << " preeditString =" << fromqstr(e->preeditString())
+                       << " commitString  =" << fromqstr(e->commitString())
+                       << endl;
+
+               int key = 0;
+
+               // FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
+               for (int i = 0; i < commit_string.size(); ++i) {
+                       QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
+                       keyPressEvent(&ev);
+               }
+       }
+
+       // Hide the cursor during the kana-kanji transformation. 
+       if (preedit_string.empty())
+               startBlinkingCursor();
+       else
+               stopBlinkingCursor();
+
+       // last_width : for checking if last preedit string was/wasn't empty.
+       static bool last_width = false;
+       if (!last_width && preedit_string.empty()) {
+               // if last_width is last length of preedit string. 
+               e->accept();
+               return;
+       }
+
+       QLPainter pain(&screen_);
+       buffer_view_->updateMetrics(false);
+       paintText(*buffer_view_, pain);
+       LyXFont font = buffer_view_->cursor().getFont();
+       FontMetrics const & fm = theFontMetrics(font);
+       int height = fm.maxHeight();
+       int cur_x = cursor_->rect().left();
+       int cur_y = cursor_->rect().bottom();
+
+       // redraw area of preedit string.
+       update(0, cur_y - height, GuiWorkArea::width(),
+               (height + 1) * preedit_lines_);
+
+       if (preedit_string.empty()) {
+               last_width = false;
+               preedit_lines_ = 1;
+               e->accept();
+               return;
+       }
+       last_width = true;
+
+       // att : stores an IM attribute.
+       QList<QInputMethodEvent::Attribute> const & att = e->attributes();
+
+       // get attributes of input method cursor.
+       // cursor_pos : cursor position in preedit string.
+       size_t cursor_pos = 0;
+       bool cursor_is_visible = false;
+       for (int i = 0; i < att.size(); ++i) {
+               if (att.at(i).type == QInputMethodEvent::Cursor) {
+                       cursor_pos = att.at(i).start;
+                       cursor_is_visible = att.at(i).length != 0;
+                       break;
+               }
+       }
+
+       size_t preedit_length = preedit_string.length();
+
+       // get position of selection in input method.
+       // FIXME: isn't there a way to do this simplier?
+       // rStart : cursor position in selected string in IM.
+       size_t rStart = 0;
+       // rLength : selected string length in IM.
+       size_t rLength = 0;
+       if (cursor_pos < preedit_length) {
+               for (int i = 0; i < att.size(); ++i) {
+                       if (att.at(i).type == QInputMethodEvent::TextFormat) {
+                               if (att.at(i).start <= int(cursor_pos)
+                                       && int(cursor_pos) < att.at(i).start + att.at(i).length) {
+                                               rStart = att.at(i).start;
+                                               rLength = att.at(i).length;
+                                               if (!cursor_is_visible)
+                                                       cursor_pos += rLength;
+                                               break;
+                               }
+                       }
+               }
+       }
+       else {
+               rStart = cursor_pos;
+               rLength = 0;
+       }
+
+       int const right_margin = rightMargin();
+       Painter::preedit_style ps;
+       // Most often there would be only one line:
+       preedit_lines_ = 1;
+       for (size_t pos = 0; pos != preedit_length; ++pos) {
+               char_type const typed_char = preedit_string[pos];
+               // reset preedit string style
+               ps = Painter::preedit_default;
+
+               // if we reached the right extremity of the screen, go to next line.
+               if (cur_x + fm.width(typed_char) > GuiWorkArea::width() - right_margin) {
+                       cur_x = right_margin;
+                       cur_y += height + 1;
+                       ++preedit_lines_;
+               }
+               // preedit strings are displayed with dashed underline
+               // and partial strings are displayed white on black indicating
+               // that we are in selecting mode in the input method.
+               // FIXME: rLength == preedit_length is not a changing condition
+               // FIXME: should be put out of the loop.
+               if (pos >= rStart 
+                       && pos < rStart + rLength
+                       && !(cursor_pos < rLength && rLength == preedit_length))
+                       ps = Painter::preedit_selecting;
+
+               if (pos == cursor_pos
+                       && (cursor_pos < rLength && rLength == preedit_length))
+                       ps = Painter::preedit_cursor;
+
+               // draw one character and update cur_x.
+               cur_x += pain.preeditText(cur_x, cur_y, typed_char, font, ps);
+       }
+
+       // update the preedit string screen area.
+       update(0, cur_y - preedit_lines_*height, GuiWorkArea::width(),
+               (height + 1) * preedit_lines_);
+
+       // Don't forget to accept the event!
+       e->accept();
+}
+
+
+QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
+{
+       QRect cur_r(0,0,0,0);
+       switch (query) {
+               // this is the CJK-specific composition window position.
+               case Qt::ImMicroFocus:
+                       cur_r = cursor_->rect();
+                       if (preedit_lines_ != 1)
+                               cur_r.moveLeft(10);
+                       cur_r.moveBottom(cur_r.bottom() + cur_r.height() * preedit_lines_);
+                       // return lower right of cursor in LyX.
+                       return cur_r;
+               default:
+                       return QWidget::inputMethodQuery(query);
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "GuiWorkArea_moc.cpp"
diff --git a/src/frontends/qt4/IconPalette.cpp b/src/frontends/qt4/IconPalette.cpp
new file mode 100644 (file)
index 0000000..e990846
--- /dev/null
@@ -0,0 +1,185 @@
+/**
+ * \file IconPalette.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "IconPalette.h"
+#include "qt_helpers.h"
+#include "controllers/ControlMath.h" // for find_xpm
+
+#include <QPixmap>
+#include <QGridLayout>
+#include <QToolButton>
+#include <QToolTip>
+#include <QToolBar>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QPainter>
+#include <QStyle>
+#include <QStyleOptionFrame>
+
+namespace lyx {
+namespace frontend {
+
+IconPalette::IconPalette(QWidget * parent)
+       : QWidget(parent, Qt::Popup)
+{
+       layout_ = new QGridLayout(this);
+       layout_->setSpacing(0);
+       layout_->setMargin(3);
+       setLayout(layout_);
+}
+
+
+void IconPalette::addButton(QAction * action)
+{
+       actions_.push_back(action);
+       QToolButton * tb = new QToolButton;
+       tb->setAutoRaise(true);
+       tb->setDefaultAction(action);
+       connect(tb, SIGNAL(triggered(QAction *)),
+               this, SLOT(clicked(QAction *)));
+       QToolBar * toolbar = qobject_cast<QToolBar *>(parentWidget()->parentWidget());
+       connect(toolbar, SIGNAL(iconSizeChanged(const QSize &)),
+               tb, SLOT(setIconSize(const QSize &)));
+
+       int const i = actions_.size();
+       int const ncols = qMin(6, i);
+       int const row = (i - 1)/ncols + 1;
+       int const col = qMax(1, i - (row - 1) * 6);
+       layout_->addWidget(tb, row, col);
+}
+
+
+void IconPalette::clicked(QAction * action)
+{
+       triggered(action);
+       setVisible(false);
+}
+
+
+void IconPalette::showEvent(QShowEvent * event)
+{
+       int hoffset = - parentWidget()->pos().x();
+       int voffset = - parentWidget()->pos().y();
+       int const parwidth = parentWidget()->geometry().width();
+       int const parheight = parentWidget()->geometry().height();
+
+       // vertical toolbar?
+       QToolBar * toolbar = qobject_cast<QToolBar *>(parentWidget()->parentWidget());
+       if (toolbar && toolbar->orientation() == Qt::Vertical) {
+               hoffset += parwidth;
+               voffset -= parheight;
+       }
+
+       QRect const screen = qApp->desktop()->availableGeometry(this);
+       QPoint const gpos = parentWidget()->mapToGlobal(
+               parentWidget()->geometry().bottomLeft());
+
+       // space to the right?
+       if (gpos.x() + hoffset + width() > screen.width()) {
+               hoffset -= width();
+               if (toolbar && toolbar->orientation() == Qt::Vertical)
+                       hoffset -= parwidth;
+               else
+                       hoffset += parwidth;
+       }
+       // space at the bottom?
+       if (gpos.y() + voffset + height() > screen.height()) {
+               voffset -= height();
+               if (toolbar && toolbar->orientation() == Qt::Horizontal)
+                       voffset -= parheight;
+               else
+                       voffset += parheight;
+       }
+
+       move(gpos.x() + hoffset, gpos.y() + voffset);
+       QWidget::showEvent(event);
+}
+
+
+void IconPalette::hideEvent(QHideEvent * event )
+{
+       visible(false);
+       QWidget::hideEvent(event);
+}
+
+
+void IconPalette::updateParent()
+{
+       bool enable = false;
+       for (int i = 0; i < actions_.size(); ++i)       
+               if (actions_.at(i)->isEnabled()) {
+                       enable = true;
+                       break;
+               }
+
+       parentWidget()->setEnabled(enable);
+}
+
+
+void IconPalette::paintEvent(QPaintEvent * event)
+{
+       // draw border
+       QPainter p(this);
+       QRegion emptyArea = QRegion(rect());
+       const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this);
+       if (fw) {
+               QRegion borderReg;
+               borderReg += QRect(0, 0, fw, height()); //left
+               borderReg += QRect(width()-fw, 0, fw, height()); //right
+               borderReg += QRect(0, 0, width(), fw); //top
+               borderReg += QRect(0, height()-fw, width(), fw); //bottom
+               p.setClipRegion(borderReg);
+               emptyArea -= borderReg;
+               QStyleOptionFrame frame;
+               frame.rect = rect();
+               frame.palette = palette();
+               frame.state = QStyle::State_None;
+               frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth);
+               frame.midLineWidth = 0;
+               style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, &p, this);
+       }
+       p.end();
+       // draw the rest (buttons)
+       QWidget::paintEvent(event);
+}
+
+
+ButtonMenu::ButtonMenu(const QString & title, QWidget * parent)
+       : QMenu(title, parent)
+{
+}
+
+
+void ButtonMenu::add(QAction * action)
+{
+       addAction(action);
+       actions_.push_back(action);
+}
+
+
+void ButtonMenu::updateParent()
+{
+       bool enable = false;
+       for (int i = 0; i < actions_.size(); ++i)       
+               if (actions_.at(i)->isEnabled()) {
+                       enable = true;
+                       break;
+               }
+
+       parentWidget()->setEnabled(enable);
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "IconPalette_moc.cpp"
diff --git a/src/frontends/qt4/IconPalette.h b/src/frontends/qt4/IconPalette.h
new file mode 100644 (file)
index 0000000..1f0f37c
--- /dev/null
@@ -0,0 +1,75 @@
+// -*- C++ -*-
+/**
+ * \file IconPalette.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef ICONPALETTE_H
+#define ICONPALETTE_H
+
+#include <QWidget>
+#include <QMenu>
+#include <QLayout>
+#include "Action.h"
+
+namespace lyx {
+namespace frontend {
+
+/**
+ * For holding an arbitrary set of icons.
+ */
+class IconPalette : public QWidget {
+       Q_OBJECT
+public:
+       IconPalette(QWidget * parent);
+       void addButton(QAction *);
+
+public Q_SLOTS:
+       void updateParent();
+
+Q_SIGNALS:
+       void triggered(QAction *);
+       void visible(bool);
+
+protected:
+       void showEvent(QShowEvent * event);
+       void hideEvent(QHideEvent * event);
+       void paintEvent(QPaintEvent * event);
+
+private Q_SLOTS:
+       virtual void clicked(QAction *);
+
+private:
+       QGridLayout * layout_;
+       QList<QAction *> actions_;
+};
+
+/**
+ * Popup menu for a toolbutton.
+ * We need this to keep track whether
+ * it is necessary to enable/disable
+ * the toolbutton
+ */
+class ButtonMenu : public QMenu {
+       Q_OBJECT
+public:
+       ButtonMenu(const QString & title, QWidget * parent = 0 );
+       void add(QAction *);
+
+public Q_SLOTS:
+       void updateParent();
+
+private:
+       QList<QAction *> actions_;
+};
+
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // ICONPALETTE_H
diff --git a/src/frontends/qt4/InsertTableWidget.C b/src/frontends/qt4/InsertTableWidget.C
deleted file mode 100644 (file)
index de8a317..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * \file InsertTableWidget.cpp
- *
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "lyxfunc.h"
-#include "FuncStatus.h"
-#include "funcrequest.h"
-#include "LyXView.h"
-
-#include "qt_helpers.h"
-
-#include "InsertTableWidget.h"
-#include <QMouseEvent>
-#include <QString>
-#include <QToolTip>
-#include <QPainter>
-
-
-namespace lyx {
-namespace frontend {
-
-InsertTableWidget::InsertTableWidget(LyXView & lyxView, QWidget * parent)
-       : QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12), lyxView_(lyxView)
-{
-       init();
-       setMouseTracking(true);
-}
-
-
-void InsertTableWidget::init()
-{
-       rows_ = 5;
-       cols_ = 5;
-       bottom_ = 0;
-       right_ = 0;
-       underMouse_ = false;
-}
-
-
-void InsertTableWidget::show(bool show)
-{
-       if (!show)
-               return;
-
-       init();
-       resetGeometry();
-       setVisible(true);
-       // emit signal
-       visible(true);
-}
-
-
-void InsertTableWidget::resetGeometry()
-{
-       QPoint p = parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft());
-       setGeometry(p.x() - parentWidget()->pos().x(),
-                               p.y() - parentWidget()->pos().y(),
-                               cols_ * colwidth_ + 1, rows_ * rowheight_ + 1);
-}
-
-
-void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
-{
-       // do this ourselves because when the mouse leaves the app
-       // we get an enter event (ie underMouse() is true)!!
-       underMouse_ = geometry().contains(event->globalPos());
-       if (!underMouse_) {
-               bottom_ = 0;
-               right_ = 0;
-               update();
-               return;
-       }
-
-       int const r0 = right_;
-       int const b0 = bottom_;
-       right_ = event->x() / colwidth_ + 1;
-       bottom_ = event->y() / rowheight_ + 1;
-
-       if (bottom_ == rows_) {
-               ++rows_;
-               resetGeometry();
-       }
-
-       if (right_ == cols_) {
-               ++cols_;
-               resetGeometry();
-       }
-
-       if (bottom_ != b0 || right_ != r0) {
-               update();
-               QString const status = QString("%1x%2").arg(bottom_).arg(right_);
-               QToolTip::showText(event->globalPos(), status , this);
-       }
-}
-
-
-void InsertTableWidget::mouseReleaseEvent(QMouseEvent * /*event*/)
-{
-       if (underMouse_) {
-               QString const data = QString("%1 %2").arg(bottom_).arg(right_);
-               lyxView_.dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data)));
-       }
-       // emit signal
-       visible(false);
-       close();
-}
-
-
-void InsertTableWidget::mousePressEvent(QMouseEvent * /*event*/)
-{
-       // swallow this one
-}
-
-
-void InsertTableWidget::paintEvent(QPaintEvent * /*event*/)
-{
-       drawGrid(rows_, cols_, Qt::white);
-       if (underMouse_)
-               drawGrid(bottom_, right_, Qt::darkBlue);
-}
-
-
-void InsertTableWidget::drawGrid(int const rows, int const cols, Qt::GlobalColor const color)
-{
-       QPainter painter(this);
-       painter.setPen(Qt::darkGray);
-       painter.setBrush(color);
-
-       for (int r = 0 ; r < rows ; ++r ) {
-               for (int c = 0 ; c < cols ; ++c ) {
-                       QRect rectangle(c * colwidth_, r * rowheight_, colwidth_, rowheight_);
-                       painter.drawRect(rectangle);
-               }
-       }
-}
-
-
-void InsertTableWidget::updateParent()
-{
-       bool status = getStatus(FuncRequest(LFUN_TABULAR_INSERT)).enabled();
-       parentWidget()->setEnabled(status);
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "InsertTableWidget_moc.cpp"
diff --git a/src/frontends/qt4/InsertTableWidget.cpp b/src/frontends/qt4/InsertTableWidget.cpp
new file mode 100644 (file)
index 0000000..de8a317
--- /dev/null
@@ -0,0 +1,157 @@
+/**
+ * \file InsertTableWidget.cpp
+ *
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "lyxfunc.h"
+#include "FuncStatus.h"
+#include "funcrequest.h"
+#include "LyXView.h"
+
+#include "qt_helpers.h"
+
+#include "InsertTableWidget.h"
+#include <QMouseEvent>
+#include <QString>
+#include <QToolTip>
+#include <QPainter>
+
+
+namespace lyx {
+namespace frontend {
+
+InsertTableWidget::InsertTableWidget(LyXView & lyxView, QWidget * parent)
+       : QWidget(parent, Qt::Popup), colwidth_(20), rowheight_(12), lyxView_(lyxView)
+{
+       init();
+       setMouseTracking(true);
+}
+
+
+void InsertTableWidget::init()
+{
+       rows_ = 5;
+       cols_ = 5;
+       bottom_ = 0;
+       right_ = 0;
+       underMouse_ = false;
+}
+
+
+void InsertTableWidget::show(bool show)
+{
+       if (!show)
+               return;
+
+       init();
+       resetGeometry();
+       setVisible(true);
+       // emit signal
+       visible(true);
+}
+
+
+void InsertTableWidget::resetGeometry()
+{
+       QPoint p = parentWidget()->mapToGlobal(parentWidget()->geometry().bottomLeft());
+       setGeometry(p.x() - parentWidget()->pos().x(),
+                               p.y() - parentWidget()->pos().y(),
+                               cols_ * colwidth_ + 1, rows_ * rowheight_ + 1);
+}
+
+
+void InsertTableWidget::mouseMoveEvent(QMouseEvent * event)
+{
+       // do this ourselves because when the mouse leaves the app
+       // we get an enter event (ie underMouse() is true)!!
+       underMouse_ = geometry().contains(event->globalPos());
+       if (!underMouse_) {
+               bottom_ = 0;
+               right_ = 0;
+               update();
+               return;
+       }
+
+       int const r0 = right_;
+       int const b0 = bottom_;
+       right_ = event->x() / colwidth_ + 1;
+       bottom_ = event->y() / rowheight_ + 1;
+
+       if (bottom_ == rows_) {
+               ++rows_;
+               resetGeometry();
+       }
+
+       if (right_ == cols_) {
+               ++cols_;
+               resetGeometry();
+       }
+
+       if (bottom_ != b0 || right_ != r0) {
+               update();
+               QString const status = QString("%1x%2").arg(bottom_).arg(right_);
+               QToolTip::showText(event->globalPos(), status , this);
+       }
+}
+
+
+void InsertTableWidget::mouseReleaseEvent(QMouseEvent * /*event*/)
+{
+       if (underMouse_) {
+               QString const data = QString("%1 %2").arg(bottom_).arg(right_);
+               lyxView_.dispatch(FuncRequest(LFUN_TABULAR_INSERT, fromqstr(data)));
+       }
+       // emit signal
+       visible(false);
+       close();
+}
+
+
+void InsertTableWidget::mousePressEvent(QMouseEvent * /*event*/)
+{
+       // swallow this one
+}
+
+
+void InsertTableWidget::paintEvent(QPaintEvent * /*event*/)
+{
+       drawGrid(rows_, cols_, Qt::white);
+       if (underMouse_)
+               drawGrid(bottom_, right_, Qt::darkBlue);
+}
+
+
+void InsertTableWidget::drawGrid(int const rows, int const cols, Qt::GlobalColor const color)
+{
+       QPainter painter(this);
+       painter.setPen(Qt::darkGray);
+       painter.setBrush(color);
+
+       for (int r = 0 ; r < rows ; ++r ) {
+               for (int c = 0 ; c < cols ; ++c ) {
+                       QRect rectangle(c * colwidth_, r * rowheight_, colwidth_, rowheight_);
+                       painter.drawRect(rectangle);
+               }
+       }
+}
+
+
+void InsertTableWidget::updateParent()
+{
+       bool status = getStatus(FuncRequest(LFUN_TABULAR_INSERT)).enabled();
+       parentWidget()->setEnabled(status);
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "InsertTableWidget_moc.cpp"
diff --git a/src/frontends/qt4/LengthCombo.cpp b/src/frontends/qt4/LengthCombo.cpp
new file mode 100644 (file)
index 0000000..ba7de38
--- /dev/null
@@ -0,0 +1,73 @@
+/**
+ * \file LengthCombo.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Herbert Voß
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "LengthCombo.h"
+#include "lengthcommon.h"
+#include "qt_helpers.h"
+
+
+LengthCombo::LengthCombo(QWidget * parent)
+       : QComboBox(parent)
+{
+       for (int i = 0; i < lyx::num_units; i++)
+               addItem(lyx::qt_(lyx::unit_name_gui[i]));
+
+       connect(this, SIGNAL(activated(int)),
+               this, SLOT(has_activated(int)));
+}
+
+
+lyx::LyXLength::UNIT LengthCombo::currentLengthItem() const
+{
+       return static_cast<lyx::LyXLength::UNIT>(currentIndex());
+}
+
+
+void LengthCombo::has_activated(int)
+{
+  // emit signal
+       selectionChanged(currentLengthItem());
+}
+
+
+void LengthCombo::setCurrentItem(lyx::LyXLength::UNIT unit)
+{
+       QComboBox::setCurrentIndex(int(unit));
+}
+
+
+void LengthCombo::setCurrentItem(int item)
+{
+       QComboBox::setCurrentIndex(item);
+}
+
+
+void LengthCombo::setEnabled(bool b)
+{
+       QComboBox::setEnabled(b);
+}
+
+
+void LengthCombo::noPercents()
+{
+       int num = QComboBox::count();
+       for (int i = 0; i < num; i++) {
+               if (QComboBox::itemText(i).contains('%') > 0) {
+                       QComboBox::removeItem(i);
+                       --i;
+                       --num;
+               }
+       }
+}
+
+#include "LengthCombo_moc.cpp"
diff --git a/src/frontends/qt4/LengthCombo.h b/src/frontends/qt4/LengthCombo.h
new file mode 100644 (file)
index 0000000..a0cebec
--- /dev/null
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+/**
+ * \file LengthCombo.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef LENGTHCOMBO_H
+#define LENGTHCOMBO_H
+
+#include <QComboBox>
+
+#include "vspace.h"
+
+
+//namespace lyx {
+
+/**
+ * A combo box for selecting LyXLength::UNIT types.
+ */
+class LengthCombo : public QComboBox {
+       Q_OBJECT
+
+public:
+       LengthCombo(QWidget * parent);
+
+       /// set the current item from unit
+       virtual void setCurrentItem(lyx::LyXLength::UNIT unit);
+       /// set the current item from int
+       virtual void setCurrentItem(int item);
+       /// get the current item
+       lyx::LyXLength::UNIT currentLengthItem() const;
+       /// enable the widget
+       virtual void setEnabled(bool b);
+       /// use the %-items?
+       virtual void noPercents();
+
+protected Q_SLOTS:
+       virtual void has_activated(int index);
+Q_SIGNALS:
+       /// the current selection has changed
+       void selectionChanged(lyx::LyXLength::UNIT unit);
+};
+
+
+//} // namespace lyx
+
+#endif // LENGTHCOMBO_H
diff --git a/src/frontends/qt4/LyXFileDialog.cpp b/src/frontends/qt4/LyXFileDialog.cpp
new file mode 100644 (file)
index 0000000..0d6652c
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * \file LyXFileDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "LyXFileDialog.h"
+
+#include "qt_helpers.h"
+
+#include "support/filefilterlist.h"
+#include "support/lstrings.h"
+
+#include <QApplication>
+#include <QToolButton>
+#include <QHBoxLayout>
+
+using lyx::support::split;
+using std::string;
+
+namespace lyx {
+
+/// return the Qt form of the label
+static docstring const getLabel(docstring const & ucs4str) {
+       // FIXME UNICODE
+       string str = to_utf8(ucs4str);
+       string label;
+       string sc(split(str, label, '|'));
+       if (sc.length() < 2)
+               return from_utf8(label);
+       string::size_type pos = label.find(sc[1]);
+       if (pos == string::npos)
+               return from_utf8(label);
+       label.insert(pos, 1, '&');
+       return from_utf8(label);
+}
+
+
+LyXFileDialog::LyXFileDialog(docstring const & t,
+                            docstring const & p,
+                            support::FileFilterList const & filters,
+                            FileDialog::Button const & b1,
+                            FileDialog::Button const & b2)
+                                // FIXME replace that with theApp->gui()->currentView()
+       : QFileDialog(qApp->focusWidget(),
+                     toqstr(t), toqstr(p), toqstr(filters.as_string())),
+                     b1_(0), b2_(0)
+{
+       setWindowTitle(toqstr(t));
+
+       QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
+
+       if (!b1.first.empty()) {
+               b1_dir_ = b1.second;
+               b1_ = new QToolButton(this);
+               connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
+               b1_->setText(toqstr(getLabel(b1.first)));
+               layout.at(0)->addWidget(b1_);
+       }
+
+       if (!b2.first.empty()) {
+               b2_dir_ = b2.second;
+               b2_ = new QToolButton(this);
+               connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
+               b2_->setText(toqstr(getLabel(b2.first)));
+               layout.at(0)->addWidget(b2_);
+       }
+}
+
+
+void LyXFileDialog::buttonClicked()
+{
+       if (sender() == b1_)
+               setDirectory(toqstr(b1_dir_));
+       else if (sender() == b2_)
+               setDirectory(toqstr(b2_dir_));
+}
+
+} // namespace lyx
+
+#include "LyXFileDialog_moc.cpp"
+
diff --git a/src/frontends/qt4/LyXFileDialog.h b/src/frontends/qt4/LyXFileDialog.h
new file mode 100644 (file)
index 0000000..65e2dd4
--- /dev/null
@@ -0,0 +1,47 @@
+// -*- C++ -*-
+/**
+ * \file LyXFileDialog.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef LYXFILEDIALOG_H
+#define LYXFILEDIALOG_H
+
+#include "frontends/FileDialog.h"
+
+#include <QFileDialog>
+
+class QToolButton;
+
+namespace lyx {
+
+namespace support { class FileFilterList; }
+
+class LyXFileDialog : public QFileDialog
+{
+       Q_OBJECT
+public:
+       LyXFileDialog(docstring const & title,
+                     docstring const & path,
+                     support::FileFilterList const & filters,
+                     FileDialog::Button const & b1,
+                     FileDialog::Button const & b2);
+public Q_SLOTS:
+       void buttonClicked();
+private:
+       QToolButton * b1_;
+       docstring b1_dir_;
+
+       QToolButton * b2_;
+       docstring b2_dir_;
+};
+
+} // namespace lyx
+
+
+#endif // LYXFILEDIALOG_H
diff --git a/src/frontends/qt4/LyXKeySymFactory.C b/src/frontends/qt4/LyXKeySymFactory.C
deleted file mode 100644 (file)
index abff60d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * \file qt4/LyXKeySymFactory.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Asger & Jürgen
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "frontends/LyXKeySymFactory.h"
-
-#include "QLyXKeySym.h"
-
-
-namespace lyx {
-
-namespace LyXKeySymFactory {
-
-LyXKeySym * create()
-{
-       return new QLyXKeySym;
-}
-
-} // namespace LyXKeySymFactory
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/LyXKeySymFactory.cpp b/src/frontends/qt4/LyXKeySymFactory.cpp
new file mode 100644 (file)
index 0000000..abff60d
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * \file qt4/LyXKeySymFactory.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Asger & Jürgen
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "frontends/LyXKeySymFactory.h"
+
+#include "QLyXKeySym.h"
+
+
+namespace lyx {
+
+namespace LyXKeySymFactory {
+
+LyXKeySym * create()
+{
+       return new QLyXKeySym;
+}
+
+} // namespace LyXKeySymFactory
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp
new file mode 100644 (file)
index 0000000..13e3100
--- /dev/null
@@ -0,0 +1,142 @@
+/**
+ * \file PanelStack.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "PanelStack.h"
+
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include <QFontMetrics>
+#include <QStackedWidget>
+#include <QTreeWidget>
+#include <QHBoxLayout>
+#include <QHeaderView>
+
+#include <boost/assert.hpp>
+
+#include <iostream>
+
+
+using std::endl;
+using std::cout;
+
+namespace lyx {
+namespace frontend {
+
+
+PanelStack::PanelStack(QWidget * parent)
+       : QWidget(parent)
+{
+       list_ = new QTreeWidget(this);
+       stack_ = new QStackedWidget(this);
+
+       list_->setColumnCount(1);
+       // Hide the pointless list header
+       list_->header()->hide();
+//     QStringList HeaderLabels;
+//     HeaderLabels << QString("Category");
+//     list_->setHeaderLabels(HeaderLabels);
+
+       connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
+               this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*)));
+
+       QHBoxLayout * layout = new QHBoxLayout(this);
+       layout->addWidget(list_, 0);
+       layout->addWidget(stack_, 1);
+}
+
+
+void PanelStack::addCategory(docstring const & n, docstring const & parent)
+{
+       QTreeWidgetItem * item = 0;
+       QString const name = toqstr(n);
+
+       LYXERR(Debug::GUI) << "addCategory n= " << to_utf8(n) << "   parent= " << endl;
+
+       int depth = 1;
+
+       if (parent.empty()) {
+               item = new QTreeWidgetItem(list_);
+               item->setText(0, name);
+       }
+       else {
+               PanelMap::iterator it = panel_map_.find(parent);
+               //BOOST_ASSERT(it != panel_map_.end());
+               if (it == panel_map_.end()) {
+                       addCategory(parent);
+                       it = panel_map_.find(parent);
+               }
+               BOOST_ASSERT(it != panel_map_.end());
+
+               item = new QTreeWidgetItem(it->second);
+               item->setText(0, name);
+               depth = 2;
+       }
+
+       panel_map_[n] = item;
+
+       QFontMetrics fm(list_->font());
+       // calculate the real size the current item needs in the listview
+       int itemsize = fm.width(name) + 10
+               + list_->indentation() * depth;
+       // adjust the listview width to the max. itemsize
+       if (itemsize > list_->minimumWidth())
+               list_->setMinimumWidth(itemsize);
+}
+
+
+void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent)
+{
+       addCategory(name, parent);
+       QTreeWidgetItem * item = panel_map_.find(name)->second;
+
+       widget_map_[item] = panel;
+       stack_->addWidget(panel);
+       stack_->setMinimumSize(panel->minimumSize());
+}
+
+
+void PanelStack::setCurrentPanel(docstring const & name)
+{
+       PanelMap::const_iterator cit = panel_map_.find(name);
+       BOOST_ASSERT(cit != panel_map_.end());
+
+       // force on first set
+       if (list_->currentItem() ==  cit->second)
+               switchPanel(cit->second);
+
+       list_->setCurrentItem(cit->second);
+}
+
+
+void PanelStack::switchPanel(QTreeWidgetItem * item,
+                            QTreeWidgetItem * /*previous*/)
+{
+       WidgetMap::const_iterator cit = widget_map_.find(item);
+       if (cit == widget_map_.end())
+               return;
+
+       stack_->setCurrentWidget(cit->second);
+}
+
+
+QSize PanelStack::sizeHint() const
+{
+       return QSize(list_->width() + stack_->width(),
+               qMax(list_->height(), stack_->height()));
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "PanelStack_moc.cpp"
diff --git a/src/frontends/qt4/PanelStack.h b/src/frontends/qt4/PanelStack.h
new file mode 100644 (file)
index 0000000..1e38043
--- /dev/null
@@ -0,0 +1,71 @@
+// -*- C++ -*-
+/**
+ * \file PanelStack.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+#ifndef PANELSTACK_H
+#define PANELSTACK_H
+
+#include "support/docstring.h"
+
+#include <QWidget>
+
+#include <map>
+
+class QTreeWidget;
+class QTreeWidgetItem;
+class QStackedWidget;
+
+namespace lyx {
+namespace frontend {
+
+
+class PanelStack : public QWidget
+{
+       Q_OBJECT
+public:
+       PanelStack(QWidget * parent = 0);
+
+       /// add a category with no associated panel
+       void addCategory(docstring const & name,
+               docstring const & parent = docstring());
+
+       /// add a widget panel with a given name, under the given parent
+       void addPanel(QWidget * panel, docstring const & name,
+               docstring const & parent = docstring());
+
+       /// set current panel by logical name
+       void setCurrentPanel(docstring const &);
+
+       virtual QSize sizeHint() const;
+
+public Q_SLOTS:
+       /// set current panel from an item
+       void switchPanel(QTreeWidgetItem * it, QTreeWidgetItem * previous = 0);
+
+private:
+       typedef std::map<docstring, QTreeWidgetItem *> PanelMap;
+
+       PanelMap panel_map_;
+
+       typedef std::map<QTreeWidgetItem *, QWidget *> WidgetMap;
+
+       WidgetMap widget_map_;
+
+       /// contains the items
+       QTreeWidget * list_;
+
+       /// contains the panes
+       QStackedWidget * stack_;
+};
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // PANELSTACK_H
diff --git a/src/frontends/qt4/QAbout.C b/src/frontends/qt4/QAbout.C
deleted file mode 100644 (file)
index 05901ec..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * \file QAbout.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Kalle Dalheimer
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QAbout.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ButtonController.h"
-#include "controllers/ControlAboutlyx.h"
-
-#include "support/lstrings.h"
-
-#include <sstream>
-
-#include <QLabel>
-#include <QPushButton>
-#include <QTextCodec>
-#include <QTextBrowser>
-
-using lyx::support::prefixIs;
-
-using std::getline;
-
-using std::istringstream;
-using std::ostringstream;
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-
-typedef QController<ControlAboutlyx, QView<QAboutDialog> > AboutBase;
-
-QAbout::QAbout(Dialog & parent)
-       : AboutBase(parent, _("About LyX"))
-{
-}
-
-
-void QAbout::build_dialog()
-{
-       dialog_.reset(new QAboutDialog);
-       connect(dialog_.get()->closePB, SIGNAL(clicked()),
-               this, SLOT(slotClose()));
-
-       dialog_->copyrightTB->setPlainText(toqstr(controller().getCopyright()));
-       dialog_->copyrightTB->append("");
-       dialog_->copyrightTB->append(toqstr(controller().getLicense()));
-       dialog_->copyrightTB->append("");
-       dialog_->copyrightTB->append(toqstr(controller().getDisclaimer()));
-
-       dialog_->versionLA->setText(toqstr(controller().getVersion()));
-
-       // The code below should depend on a autoconf test. (Lgb)
-#if 1
-       // There are a lot of buggy stringstream implementations..., but the
-       // code below will work on all of them (I hope). The drawback with
-       // this solutions os the extra copying. (Lgb)
-
-       ostringstream in;
-       controller().getCredits(in);
-
-       istringstream ss(in.str());
-
-       string s;
-       ostringstream out;
-
-       while (getline(ss, s)) {
-               if (prefixIs(s, "@b"))
-                       out << "<b>" << s.substr(2) << "</b>";
-               else if (prefixIs(s, "@i"))
-                       out << "<i>" << s.substr(2) << "</i>";
-               else
-                       out << s;
-               out << "<br>";
-       }
-#else
-       // Good stringstream implementations can handle this. It avoids
-       // some copying, and should thus be faster and use less memory. (Lgb)
-       // I'll make this the default for a short while to see if anyone
-       // see the error...
-       stringstream in;
-       controller().getCredits(in);
-       in.seekg(0);
-       string s;
-       ostringstream out;
-
-       while (getline(in, s)) {
-               if (prefixIs(s, "@b"))
-                       out << "<b>" << s.substr(2) << "</b>";
-               else if (prefixIs(s, "@i"))
-                       out << "<i>" << s.substr(2) << "</i>";
-               else
-                       out << s;
-               out << "<br>";
-       }
-#endif
-
-       dialog_->creditsTB->setHtml(toqstr(out.str()));
-
-       // try to resize to a good size
-       dialog_->copyrightTB->hide();
-       dialog_->setMinimumSize(dialog_->copyrightTB->sizeHint());
-       dialog_->copyrightTB->show();
-       dialog_->setMinimumSize(dialog_->sizeHint());
-
-       // Manage the cancel/close button
-       bcview().setCancel(dialog_->closePB);
-       bc().refresh();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QAbout_moc.cpp"
diff --git a/src/frontends/qt4/QAbout.cpp b/src/frontends/qt4/QAbout.cpp
new file mode 100644 (file)
index 0000000..05901ec
--- /dev/null
@@ -0,0 +1,124 @@
+/**
+ * \file QAbout.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Kalle Dalheimer
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QAbout.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ButtonController.h"
+#include "controllers/ControlAboutlyx.h"
+
+#include "support/lstrings.h"
+
+#include <sstream>
+
+#include <QLabel>
+#include <QPushButton>
+#include <QTextCodec>
+#include <QTextBrowser>
+
+using lyx::support::prefixIs;
+
+using std::getline;
+
+using std::istringstream;
+using std::ostringstream;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+
+typedef QController<ControlAboutlyx, QView<QAboutDialog> > AboutBase;
+
+QAbout::QAbout(Dialog & parent)
+       : AboutBase(parent, _("About LyX"))
+{
+}
+
+
+void QAbout::build_dialog()
+{
+       dialog_.reset(new QAboutDialog);
+       connect(dialog_.get()->closePB, SIGNAL(clicked()),
+               this, SLOT(slotClose()));
+
+       dialog_->copyrightTB->setPlainText(toqstr(controller().getCopyright()));
+       dialog_->copyrightTB->append("");
+       dialog_->copyrightTB->append(toqstr(controller().getLicense()));
+       dialog_->copyrightTB->append("");
+       dialog_->copyrightTB->append(toqstr(controller().getDisclaimer()));
+
+       dialog_->versionLA->setText(toqstr(controller().getVersion()));
+
+       // The code below should depend on a autoconf test. (Lgb)
+#if 1
+       // There are a lot of buggy stringstream implementations..., but the
+       // code below will work on all of them (I hope). The drawback with
+       // this solutions os the extra copying. (Lgb)
+
+       ostringstream in;
+       controller().getCredits(in);
+
+       istringstream ss(in.str());
+
+       string s;
+       ostringstream out;
+
+       while (getline(ss, s)) {
+               if (prefixIs(s, "@b"))
+                       out << "<b>" << s.substr(2) << "</b>";
+               else if (prefixIs(s, "@i"))
+                       out << "<i>" << s.substr(2) << "</i>";
+               else
+                       out << s;
+               out << "<br>";
+       }
+#else
+       // Good stringstream implementations can handle this. It avoids
+       // some copying, and should thus be faster and use less memory. (Lgb)
+       // I'll make this the default for a short while to see if anyone
+       // see the error...
+       stringstream in;
+       controller().getCredits(in);
+       in.seekg(0);
+       string s;
+       ostringstream out;
+
+       while (getline(in, s)) {
+               if (prefixIs(s, "@b"))
+                       out << "<b>" << s.substr(2) << "</b>";
+               else if (prefixIs(s, "@i"))
+                       out << "<i>" << s.substr(2) << "</i>";
+               else
+                       out << s;
+               out << "<br>";
+       }
+#endif
+
+       dialog_->creditsTB->setHtml(toqstr(out.str()));
+
+       // try to resize to a good size
+       dialog_->copyrightTB->hide();
+       dialog_->setMinimumSize(dialog_->copyrightTB->sizeHint());
+       dialog_->copyrightTB->show();
+       dialog_->setMinimumSize(dialog_->sizeHint());
+
+       // Manage the cancel/close button
+       bcview().setCancel(dialog_->closePB);
+       bc().refresh();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QAbout_moc.cpp"
diff --git a/src/frontends/qt4/QBibitem.C b/src/frontends/qt4/QBibitem.C
deleted file mode 100644 (file)
index 6e29d58..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * \file QBibitem.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QBibitem.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ControlCommand.h"
-
-#include <QLineEdit>
-#include <QPushButton>
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QBibItemDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QBibitemDialog::QBibitemDialog(QBibitem * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(keyED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(labelED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-}
-
-
-void QBibitemDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QBibitemDialog::closeEvent(QCloseEvent *e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QBibItem
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlCommand, QView<QBibitemDialog> > BibItemBase;
-
-
-QBibitem::QBibitem(Dialog & parent)
-       : BibItemBase(parent, _("Bibliography Entry Settings"))
-{
-}
-
-
-void QBibitem::build_dialog()
-{
-       dialog_.reset(new QBibitemDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->keyED);
-       bcview().addReadOnly(dialog_->labelED);
-}
-
-
-void QBibitem::update_contents()
-{
-       dialog_->keyED->setText(toqstr(controller().params()["key"]));
-       dialog_->labelED->setText(toqstr(controller().params()["label"]));
-}
-
-
-void QBibitem::apply()
-{
-       controller().params()["key"] = qstring_to_ucs4(dialog_->keyED->text());
-       controller().params()["label"] = qstring_to_ucs4(dialog_->labelED->text());
-}
-
-
-bool QBibitem::isValid()
-{
-       return !dialog_->keyED->text().isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QBibitem_moc.cpp"
diff --git a/src/frontends/qt4/QBibitem.cpp b/src/frontends/qt4/QBibitem.cpp
new file mode 100644 (file)
index 0000000..6e29d58
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * \file QBibitem.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QBibitem.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ControlCommand.h"
+
+#include <QLineEdit>
+#include <QPushButton>
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QBibItemDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QBibitemDialog::QBibitemDialog(QBibitem * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(keyED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(labelED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+}
+
+
+void QBibitemDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QBibitemDialog::closeEvent(QCloseEvent *e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QBibItem
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlCommand, QView<QBibitemDialog> > BibItemBase;
+
+
+QBibitem::QBibitem(Dialog & parent)
+       : BibItemBase(parent, _("Bibliography Entry Settings"))
+{
+}
+
+
+void QBibitem::build_dialog()
+{
+       dialog_.reset(new QBibitemDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->keyED);
+       bcview().addReadOnly(dialog_->labelED);
+}
+
+
+void QBibitem::update_contents()
+{
+       dialog_->keyED->setText(toqstr(controller().params()["key"]));
+       dialog_->labelED->setText(toqstr(controller().params()["label"]));
+}
+
+
+void QBibitem::apply()
+{
+       controller().params()["key"] = qstring_to_ucs4(dialog_->keyED->text());
+       controller().params()["label"] = qstring_to_ucs4(dialog_->labelED->text());
+}
+
+
+bool QBibitem::isValid()
+{
+       return !dialog_->keyED->text().isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QBibitem_moc.cpp"
diff --git a/src/frontends/qt4/QBibtex.C b/src/frontends/qt4/QBibtex.C
deleted file mode 100644 (file)
index 4d8ef8a..0000000
+++ /dev/null
@@ -1,411 +0,0 @@
-/**
- * \file QBibtex.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Herbert Voß
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QBibtex.h"
-
-#include "ui/BibtexAddUi.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-#include "Validator.h"
-#include "lyxrc.h"
-#include "CheckedLineEdit.h"
-
-#include "controllers/ControlBibtex.h"
-#include "controllers/ButtonPolicies.h"
-
-#include "controllers/ControlBibtex.h"
-
-#include "support/filetools.h" // changeExtension
-#include "support/lstrings.h"
-
-#include <QPushButton>
-#include <QListWidget>
-#include <QCheckBox>
-#include <QCloseEvent>
-#include <QLineEdit>
-
-using lyx::support::changeExtension;
-using lyx::support::split;
-using lyx::support::trim;
-
-using std::vector;
-using std::string;
-
-#include "debug.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
-
-
-namespace lyx {
-namespace frontend {
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QBibtexDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QBibtexDialog::QBibtexDialog(QBibtex * form)
-       : form_(form)
-{
-       setupUi(this);
-       QDialog::setModal(true);
-
-       connect(okPB, SIGNAL(clicked()),
-               form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-       connect(stylePB, SIGNAL(clicked()),
-               this, SLOT( browsePressed()));
-       connect(deletePB, SIGNAL(clicked()),
-               this, SLOT( deletePressed()));
-       connect(styleCB, SIGNAL(editTextChanged (const QString &)),
-               this, SLOT( change_adaptor()));
-       connect(databaseLW, SIGNAL(itemSelectionChanged()),
-               this, SLOT( databaseChanged()));
-       connect(bibtocCB, SIGNAL(clicked()),
-               this, SLOT( change_adaptor()));
-       connect(btPrintCO, SIGNAL(activated(int)),
-               this, SLOT( change_adaptor()));
-       connect(addBibPB, SIGNAL(clicked()),
-               this, SLOT( addPressed()));
-
-       add_ = new UiDialog<Ui::QBibtexAddUi>(this, true);
-
-       Qt2BC * bcview = new Qt2BC(add_bc_);
-       add_bc_.view(bcview);
-       add_bc_.bp(new OkCancelPolicy);
-
-       bcview->setOK(add_->addPB);
-       bcview->setCancel(add_->closePB);
-
-       add_->bibED->setValidator(new PathValidator(true, add_->bibED));
-       addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
-
-       connect(add_->bibED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(bibEDChanged()));
-       connect(add_->addPB, SIGNAL(clicked()),
-               this, SLOT(addDatabase()));
-       connect(add_->addPB, SIGNAL(clicked()),
-               add_, SLOT(accept()));
-       connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
-               this, SLOT(addDatabase()));
-       connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
-               add_, SLOT(accept()));
-       connect(add_->bibLW, SIGNAL(itemSelectionChanged()),
-               this, SLOT(availableChanged()));
-       connect(add_->browsePB, SIGNAL(clicked()),
-               this, SLOT(browseBibPressed()));
-       connect(add_->closePB, SIGNAL(clicked()),
-               add_, SLOT(reject()));
-
-}
-
-
-void QBibtexDialog::bibEDChanged()
-{
-       // Indicate to the button controller that the contents have
-       // changed. The actual test of validity is carried out by
-       // the checkedLineEdit.
-       add_bc_.valid(true);
-}
-
-
-void QBibtexDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QBibtexDialog::browsePressed()
-{
-       docstring const file = form_->controller().browseBst(docstring());
-
-       if (!file.empty()) {
-               // FIXME UNICODE
-               docstring const filen = from_utf8(changeExtension(to_utf8(file), ""));
-               bool present = false;
-               unsigned int pres = 0;
-
-               for (int i = 0; i != styleCB->count(); ++i) {
-                       if (qstring_to_ucs4(styleCB->itemText(i)) == filen) {
-                               present = true;
-                               pres = i;
-                       }
-               }
-
-               if (!present)
-                       styleCB->insertItem(0, toqstr(filen));
-
-               styleCB->setCurrentIndex(pres);
-               form_->changed();
-       }
-}
-
-
-void QBibtexDialog::browseBibPressed()
-{
-       docstring const file = trim(form_->controller().browseBib(docstring()));
-
-       if (!file.empty()) {
-               // FIXME UNICODE
-               QString const f = toqstr(changeExtension(to_utf8(file), ""));
-               bool present = false;
-
-               for (int i = 0; i < add_->bibLW->count(); ++i) {
-                       if (add_->bibLW->item(i)->text() == f)
-                               present = true;
-               }
-
-               if (!present) {
-                       add_->bibLW->addItem(f);
-                       form_->changed();
-               }
-
-               add_->bibED->setText(f);
-       }
-}
-
-
-void QBibtexDialog::addPressed()
-{
-       add_bc_.valid(false);
-       add_->exec();
-}
-
-
-void QBibtexDialog::addDatabase()
-{
-       int const sel = add_->bibLW->currentRow();
-       docstring const file = trim(qstring_to_ucs4(add_->bibED->text()));
-
-       if (sel < 0 && file.empty())
-               return;
-
-       // Add the selected browser_bib keys to browser_database
-       // multiple selections are possible
-       for (int i = 0; i != add_->bibLW->count(); ++i) {
-               QListWidgetItem * const item = add_->bibLW->item(i);
-               if (add_->bibLW->isItemSelected(item)) {
-                       add_->bibLW->setItemSelected(item, false);
-                       QList<QListWidgetItem *> matches =
-                               databaseLW->findItems(item->text(), Qt::MatchExactly);
-                       if (matches.empty())
-                               databaseLW->addItem(item->text());
-               }
-       }
-
-       if (!file.empty()) {
-               add_->bibED->clear();
-               QString const f = toqstr(from_utf8(changeExtension(to_utf8(file), "")));
-               QList<QListWidgetItem *> matches =
-                       databaseLW->findItems(f, Qt::MatchExactly);
-               if (matches.empty())
-                       databaseLW->addItem(f);
-       }
-
-       form_->changed();
-}
-
-
-void QBibtexDialog::deletePressed()
-{
-       databaseLW->takeItem(databaseLW->currentRow());
-       form_->changed();
-}
-
-
-
-void QBibtexDialog::databaseChanged()
-{
-       deletePB->setEnabled(!form_->readOnly() && databaseLW->currentRow() != -1);
-}
-
-
-void QBibtexDialog::availableChanged()
-{
-       add_bc_.valid(true);
-}
-
-
-void QBibtexDialog::closeEvent(QCloseEvent *e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QBibTex
-//
-/////////////////////////////////////////////////////////////////////
-
-
-typedef QController<ControlBibtex, QView<QBibtexDialog> > BibtexBase;
-
-QBibtex::QBibtex(Dialog & parent)
-       : BibtexBase(parent, _("BibTeX Bibliography"))
-{
-}
-
-
-void QBibtex::build_dialog()
-{
-       dialog_.reset(new QBibtexDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->databaseLW);
-       bcview().addReadOnly(dialog_->stylePB);
-       bcview().addReadOnly(dialog_->styleCB);
-       bcview().addReadOnly(dialog_->bibtocCB);
-       bcview().addReadOnly(dialog_->addBibPB);
-       bcview().addReadOnly(dialog_->deletePB);
-}
-
-
-void QBibtex::update_contents()
-{
-       PathValidator * path_validator =
-               getPathValidator(dialog_->add_->bibED);
-       if (path_validator)
-               path_validator->setChecker(kernel().docType(), lyxrc);
-
-       bool bibtopic = controller().usingBibtopic();
-
-       dialog_->databaseLW->clear();
-
-       docstring bibs(controller().params()["bibfiles"]);
-       docstring bib;
-
-       while (!bibs.empty()) {
-               bibs = split(bibs, bib, ',');
-               bib = trim(bib);
-               if (!bib.empty())
-                       dialog_->databaseLW->addItem(toqstr(bib));
-       }
-
-       dialog_->add_->bibLW->clear();
-
-       vector<string> bib_str;
-       controller().getBibFiles(bib_str);
-       for (vector<string>::const_iterator it = bib_str.begin();
-               it != bib_str.end(); ++it) {
-               string bibItem(changeExtension(*it, ""));
-               dialog_->add_->bibLW->addItem(toqstr(bibItem));
-       }
-
-       string bibstyle(controller().getStylefile());
-
-       dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
-       dialog_->bibtocCB->setEnabled(!bibtopic);
-
-       docstring btprint(controller().params()["btprint"]);
-       int btp = 0;
-       if (btprint == "btPrintNotCited")
-               btp = 1;
-       else if (btprint == "btPrintAll")
-               btp = 2;
-
-       dialog_->btPrintCO->setCurrentIndex(btp);
-       dialog_->btPrintCO->setEnabled(bibtopic);
-
-       dialog_->styleCB->clear();
-
-       int item_nr(-1);
-
-       vector<string> str;
-       controller().getBibStyles(str);
-       for (vector<string>::const_iterator it = str.begin();
-               it != str.end(); ++it) {
-               string item(changeExtension(*it, ""));
-               if (item == bibstyle)
-                       item_nr = int(it - str.begin());
-               dialog_->styleCB->addItem(toqstr(item));
-       }
-
-       if (item_nr == -1 && !bibstyle.empty()) {
-               dialog_->styleCB->addItem(toqstr(bibstyle));
-               item_nr = dialog_->styleCB->count() - 1;
-       }
-
-       if (item_nr != -1)
-               dialog_->styleCB->setCurrentIndex(item_nr);
-       else
-               dialog_->styleCB->clearEditText();
-}
-
-
-void QBibtex::apply()
-{
-       docstring dbs(qstring_to_ucs4(dialog_->databaseLW->item(0)->text()));
-
-       unsigned int maxCount = dialog_->databaseLW->count();
-       for (unsigned int i = 1; i < maxCount; i++) {
-               dbs += ',';
-               dbs += qstring_to_ucs4(dialog_->databaseLW->item(i)->text());
-       }
-
-       controller().params()["bibfiles"] = dbs;
-
-       docstring const bibstyle(qstring_to_ucs4(dialog_->styleCB->currentText()));
-       bool const bibtotoc(dialog_->bibtocCB->isChecked());
-
-       if (bibtotoc && (!bibstyle.empty())) {
-               // both bibtotoc and style
-               controller().params()["options"] = "bibtotoc," + bibstyle;
-       } else if (bibtotoc) {
-               // bibtotoc and no style
-               controller().params()["options"] = from_ascii("bibtotoc");
-       } else {
-               // only style. An empty one is valid, because some
-               // documentclasses have an own \bibliographystyle{}
-               // command!
-               controller().params()["options"] = bibstyle;
-       }
-
-       // bibtopic allows three kinds of sections:
-       // 1. sections that include all cited references of the database(s)
-       // 2. sections that include all uncited references of the database(s)
-       // 3. sections that include all references of the database(s), cited or not
-       int btp = dialog_->btPrintCO->currentIndex();
-
-       switch (btp) {
-       case 0:
-               controller().params()["btprint"] = from_ascii("btPrintCited");
-               break;
-       case 1:
-               controller().params()["btprint"] = from_ascii("btPrintNotCited");
-               break;
-       case 2:
-               controller().params()["btprint"] = from_ascii("btPrintAll");
-               break;
-       }
-
-       if (!controller().usingBibtopic())
-               controller().params()["btprint"] = docstring();
-}
-
-
-bool QBibtex::isValid()
-{
-       return dialog_->databaseLW->count() != 0;
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QBibtex_moc.cpp"
diff --git a/src/frontends/qt4/QBibtex.cpp b/src/frontends/qt4/QBibtex.cpp
new file mode 100644 (file)
index 0000000..4d8ef8a
--- /dev/null
@@ -0,0 +1,411 @@
+/**
+ * \file QBibtex.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Herbert Voß
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QBibtex.h"
+
+#include "ui/BibtexAddUi.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+#include "Validator.h"
+#include "lyxrc.h"
+#include "CheckedLineEdit.h"
+
+#include "controllers/ControlBibtex.h"
+#include "controllers/ButtonPolicies.h"
+
+#include "controllers/ControlBibtex.h"
+
+#include "support/filetools.h" // changeExtension
+#include "support/lstrings.h"
+
+#include <QPushButton>
+#include <QListWidget>
+#include <QCheckBox>
+#include <QCloseEvent>
+#include <QLineEdit>
+
+using lyx::support::changeExtension;
+using lyx::support::split;
+using lyx::support::trim;
+
+using std::vector;
+using std::string;
+
+#include "debug.h"
+#include "support/filetools.h"
+#include "support/lstrings.h"
+
+
+namespace lyx {
+namespace frontend {
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QBibtexDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QBibtexDialog::QBibtexDialog(QBibtex * form)
+       : form_(form)
+{
+       setupUi(this);
+       QDialog::setModal(true);
+
+       connect(okPB, SIGNAL(clicked()),
+               form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+       connect(stylePB, SIGNAL(clicked()),
+               this, SLOT( browsePressed()));
+       connect(deletePB, SIGNAL(clicked()),
+               this, SLOT( deletePressed()));
+       connect(styleCB, SIGNAL(editTextChanged (const QString &)),
+               this, SLOT( change_adaptor()));
+       connect(databaseLW, SIGNAL(itemSelectionChanged()),
+               this, SLOT( databaseChanged()));
+       connect(bibtocCB, SIGNAL(clicked()),
+               this, SLOT( change_adaptor()));
+       connect(btPrintCO, SIGNAL(activated(int)),
+               this, SLOT( change_adaptor()));
+       connect(addBibPB, SIGNAL(clicked()),
+               this, SLOT( addPressed()));
+
+       add_ = new UiDialog<Ui::QBibtexAddUi>(this, true);
+
+       Qt2BC * bcview = new Qt2BC(add_bc_);
+       add_bc_.view(bcview);
+       add_bc_.bp(new OkCancelPolicy);
+
+       bcview->setOK(add_->addPB);
+       bcview->setCancel(add_->closePB);
+
+       add_->bibED->setValidator(new PathValidator(true, add_->bibED));
+       addCheckedLineEdit(add_bc_.view(), add_->bibED, 0);
+
+       connect(add_->bibED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(bibEDChanged()));
+       connect(add_->addPB, SIGNAL(clicked()),
+               this, SLOT(addDatabase()));
+       connect(add_->addPB, SIGNAL(clicked()),
+               add_, SLOT(accept()));
+       connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
+               this, SLOT(addDatabase()));
+       connect(add_->bibLW, SIGNAL(itemActivated(QListWidgetItem *)),
+               add_, SLOT(accept()));
+       connect(add_->bibLW, SIGNAL(itemSelectionChanged()),
+               this, SLOT(availableChanged()));
+       connect(add_->browsePB, SIGNAL(clicked()),
+               this, SLOT(browseBibPressed()));
+       connect(add_->closePB, SIGNAL(clicked()),
+               add_, SLOT(reject()));
+
+}
+
+
+void QBibtexDialog::bibEDChanged()
+{
+       // Indicate to the button controller that the contents have
+       // changed. The actual test of validity is carried out by
+       // the checkedLineEdit.
+       add_bc_.valid(true);
+}
+
+
+void QBibtexDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QBibtexDialog::browsePressed()
+{
+       docstring const file = form_->controller().browseBst(docstring());
+
+       if (!file.empty()) {
+               // FIXME UNICODE
+               docstring const filen = from_utf8(changeExtension(to_utf8(file), ""));
+               bool present = false;
+               unsigned int pres = 0;
+
+               for (int i = 0; i != styleCB->count(); ++i) {
+                       if (qstring_to_ucs4(styleCB->itemText(i)) == filen) {
+                               present = true;
+                               pres = i;
+                       }
+               }
+
+               if (!present)
+                       styleCB->insertItem(0, toqstr(filen));
+
+               styleCB->setCurrentIndex(pres);
+               form_->changed();
+       }
+}
+
+
+void QBibtexDialog::browseBibPressed()
+{
+       docstring const file = trim(form_->controller().browseBib(docstring()));
+
+       if (!file.empty()) {
+               // FIXME UNICODE
+               QString const f = toqstr(changeExtension(to_utf8(file), ""));
+               bool present = false;
+
+               for (int i = 0; i < add_->bibLW->count(); ++i) {
+                       if (add_->bibLW->item(i)->text() == f)
+                               present = true;
+               }
+
+               if (!present) {
+                       add_->bibLW->addItem(f);
+                       form_->changed();
+               }
+
+               add_->bibED->setText(f);
+       }
+}
+
+
+void QBibtexDialog::addPressed()
+{
+       add_bc_.valid(false);
+       add_->exec();
+}
+
+
+void QBibtexDialog::addDatabase()
+{
+       int const sel = add_->bibLW->currentRow();
+       docstring const file = trim(qstring_to_ucs4(add_->bibED->text()));
+
+       if (sel < 0 && file.empty())
+               return;
+
+       // Add the selected browser_bib keys to browser_database
+       // multiple selections are possible
+       for (int i = 0; i != add_->bibLW->count(); ++i) {
+               QListWidgetItem * const item = add_->bibLW->item(i);
+               if (add_->bibLW->isItemSelected(item)) {
+                       add_->bibLW->setItemSelected(item, false);
+                       QList<QListWidgetItem *> matches =
+                               databaseLW->findItems(item->text(), Qt::MatchExactly);
+                       if (matches.empty())
+                               databaseLW->addItem(item->text());
+               }
+       }
+
+       if (!file.empty()) {
+               add_->bibED->clear();
+               QString const f = toqstr(from_utf8(changeExtension(to_utf8(file), "")));
+               QList<QListWidgetItem *> matches =
+                       databaseLW->findItems(f, Qt::MatchExactly);
+               if (matches.empty())
+                       databaseLW->addItem(f);
+       }
+
+       form_->changed();
+}
+
+
+void QBibtexDialog::deletePressed()
+{
+       databaseLW->takeItem(databaseLW->currentRow());
+       form_->changed();
+}
+
+
+
+void QBibtexDialog::databaseChanged()
+{
+       deletePB->setEnabled(!form_->readOnly() && databaseLW->currentRow() != -1);
+}
+
+
+void QBibtexDialog::availableChanged()
+{
+       add_bc_.valid(true);
+}
+
+
+void QBibtexDialog::closeEvent(QCloseEvent *e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QBibTex
+//
+/////////////////////////////////////////////////////////////////////
+
+
+typedef QController<ControlBibtex, QView<QBibtexDialog> > BibtexBase;
+
+QBibtex::QBibtex(Dialog & parent)
+       : BibtexBase(parent, _("BibTeX Bibliography"))
+{
+}
+
+
+void QBibtex::build_dialog()
+{
+       dialog_.reset(new QBibtexDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->databaseLW);
+       bcview().addReadOnly(dialog_->stylePB);
+       bcview().addReadOnly(dialog_->styleCB);
+       bcview().addReadOnly(dialog_->bibtocCB);
+       bcview().addReadOnly(dialog_->addBibPB);
+       bcview().addReadOnly(dialog_->deletePB);
+}
+
+
+void QBibtex::update_contents()
+{
+       PathValidator * path_validator =
+               getPathValidator(dialog_->add_->bibED);
+       if (path_validator)
+               path_validator->setChecker(kernel().docType(), lyxrc);
+
+       bool bibtopic = controller().usingBibtopic();
+
+       dialog_->databaseLW->clear();
+
+       docstring bibs(controller().params()["bibfiles"]);
+       docstring bib;
+
+       while (!bibs.empty()) {
+               bibs = split(bibs, bib, ',');
+               bib = trim(bib);
+               if (!bib.empty())
+                       dialog_->databaseLW->addItem(toqstr(bib));
+       }
+
+       dialog_->add_->bibLW->clear();
+
+       vector<string> bib_str;
+       controller().getBibFiles(bib_str);
+       for (vector<string>::const_iterator it = bib_str.begin();
+               it != bib_str.end(); ++it) {
+               string bibItem(changeExtension(*it, ""));
+               dialog_->add_->bibLW->addItem(toqstr(bibItem));
+       }
+
+       string bibstyle(controller().getStylefile());
+
+       dialog_->bibtocCB->setChecked(controller().bibtotoc() && !bibtopic);
+       dialog_->bibtocCB->setEnabled(!bibtopic);
+
+       docstring btprint(controller().params()["btprint"]);
+       int btp = 0;
+       if (btprint == "btPrintNotCited")
+               btp = 1;
+       else if (btprint == "btPrintAll")
+               btp = 2;
+
+       dialog_->btPrintCO->setCurrentIndex(btp);
+       dialog_->btPrintCO->setEnabled(bibtopic);
+
+       dialog_->styleCB->clear();
+
+       int item_nr(-1);
+
+       vector<string> str;
+       controller().getBibStyles(str);
+       for (vector<string>::const_iterator it = str.begin();
+               it != str.end(); ++it) {
+               string item(changeExtension(*it, ""));
+               if (item == bibstyle)
+                       item_nr = int(it - str.begin());
+               dialog_->styleCB->addItem(toqstr(item));
+       }
+
+       if (item_nr == -1 && !bibstyle.empty()) {
+               dialog_->styleCB->addItem(toqstr(bibstyle));
+               item_nr = dialog_->styleCB->count() - 1;
+       }
+
+       if (item_nr != -1)
+               dialog_->styleCB->setCurrentIndex(item_nr);
+       else
+               dialog_->styleCB->clearEditText();
+}
+
+
+void QBibtex::apply()
+{
+       docstring dbs(qstring_to_ucs4(dialog_->databaseLW->item(0)->text()));
+
+       unsigned int maxCount = dialog_->databaseLW->count();
+       for (unsigned int i = 1; i < maxCount; i++) {
+               dbs += ',';
+               dbs += qstring_to_ucs4(dialog_->databaseLW->item(i)->text());
+       }
+
+       controller().params()["bibfiles"] = dbs;
+
+       docstring const bibstyle(qstring_to_ucs4(dialog_->styleCB->currentText()));
+       bool const bibtotoc(dialog_->bibtocCB->isChecked());
+
+       if (bibtotoc && (!bibstyle.empty())) {
+               // both bibtotoc and style
+               controller().params()["options"] = "bibtotoc," + bibstyle;
+       } else if (bibtotoc) {
+               // bibtotoc and no style
+               controller().params()["options"] = from_ascii("bibtotoc");
+       } else {
+               // only style. An empty one is valid, because some
+               // documentclasses have an own \bibliographystyle{}
+               // command!
+               controller().params()["options"] = bibstyle;
+       }
+
+       // bibtopic allows three kinds of sections:
+       // 1. sections that include all cited references of the database(s)
+       // 2. sections that include all uncited references of the database(s)
+       // 3. sections that include all references of the database(s), cited or not
+       int btp = dialog_->btPrintCO->currentIndex();
+
+       switch (btp) {
+       case 0:
+               controller().params()["btprint"] = from_ascii("btPrintCited");
+               break;
+       case 1:
+               controller().params()["btprint"] = from_ascii("btPrintNotCited");
+               break;
+       case 2:
+               controller().params()["btprint"] = from_ascii("btPrintAll");
+               break;
+       }
+
+       if (!controller().usingBibtopic())
+               controller().params()["btprint"] = docstring();
+}
+
+
+bool QBibtex::isValid()
+{
+       return dialog_->databaseLW->count() != 0;
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QBibtex_moc.cpp"
diff --git a/src/frontends/qt4/QBox.C b/src/frontends/qt4/QBox.C
deleted file mode 100644 (file)
index d62c78e..0000000
+++ /dev/null
@@ -1,396 +0,0 @@
-/**
- * \file QBox.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Vigna (Minipage stuff)
- * \author Martin Vermeer
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QBox.h"
-
-#include "CheckedLineEdit.h"
-#include "LengthCombo.h"
-#include "qt_helpers.h"
-#include "Qt2BC.h"
-#include "lengthcommon.h"
-#include "lyxrc.h" // to set the default length values
-#include "Validator.h"
-
-#include "controllers/ControlBox.h"
-#include "controllers/frontend_helpers.h"
-
-#include "insets/InsetBox.h"
-
-#include "support/lstrings.h"
-
-#include <QPushButton>
-#include <QLineEdit>
-#include <QCloseEvent>
-
-
-using lyx::support::getStringFromVector;
-using lyx::support::isStrDbl;
-using lyx::support::subst;
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-//////////////////////////////////////////////////////////////////
-//
-// QBoxDialog
-//
-//////////////////////////////////////////////////////////////////
-
-QBoxDialog::QBoxDialog(QBox * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(widthED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(widthUnitsLC, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(change_adaptor()));
-       connect(valignCO, SIGNAL(highlighted(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(heightED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(heightUnitsLC, SIGNAL(selectionChanged(LyXLength::UNIT) ),
-               this, SLOT(change_adaptor()));
-       connect(restorePB, SIGNAL(clicked()), this, SLOT(restoreClicked()));
-       connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
-       connect(halignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(ialignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(innerBoxCO, SIGNAL(activated(const QString&)),
-               this, SLOT(innerBoxChanged(const QString &)));
-       connect(innerBoxCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-
-       heightED->setValidator(unsignedLengthValidator(heightED));
-       widthED->setValidator(unsignedLengthValidator(widthED));
-}
-
-
-void QBoxDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QBoxDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QBoxDialog::innerBoxChanged(const QString & str)
-{
-       bool const ibox = (str != qt_("None"));
-       valignCO->setEnabled(ibox);
-       ialignCO->setEnabled(ibox);
-       halignCO->setEnabled(!ibox);
-       heightED->setEnabled(ibox);
-       heightUnitsLC->setEnabled(ibox);
-       form_->setSpecial(ibox);
-}
-
-
-void QBoxDialog::typeChanged(int index)
-{
-       bool const frameless = (index == 0);
-       if (frameless) {
-               valignCO->setEnabled(true);
-               ialignCO->setEnabled(true);
-               halignCO->setEnabled(false);
-               heightED->setEnabled(true);
-               heightUnitsLC->setEnabled(true);
-               form_->setSpecial(true);
-       }
-       int itype = innerBoxCO->currentIndex();
-       form_->setInnerType(frameless, itype);
-}
-
-
-void QBoxDialog::restoreClicked()
-{
-       form_->setInnerType(true, 2);
-       widthED->setText("100");
-       widthUnitsLC->setCurrentItem(LyXLength::PCW);
-       heightED->setText("1");
-       for (int j = 0; j < heightUnitsLC->count(); j++) {
-               if (heightUnitsLC->itemText(j) == qt_("Total Height"))
-                       heightUnitsLC->setCurrentItem(j);
-       }
-}
-
-
-//////////////////////////////////////////////////////////////////
-//
-// QBox
-//
-//////////////////////////////////////////////////////////////////
-
-typedef QController<ControlBox, QView<QBoxDialog> > box_base_class;
-
-QBox::QBox(Dialog & parent)
-       : box_base_class(parent, _("Box Settings"))
-{}
-
-
-void QBox::build_dialog()
-{
-       dialog_.reset(new QBoxDialog(this));
-
-       // fill the box type choice
-       box_gui_tokens(ids_, gui_names_);
-       for (unsigned int i = 0; i < gui_names_.size(); ++i)
-               dialog_->typeCO->addItem(toqstr(gui_names_[i]));
-
-       // add the special units to the height choice
-       // width needs different handling
-       box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
-       for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) 
-               dialog_->heightUnitsLC->addItem(toqstr(gui_names_spec_[i]));
-
-       bcview().addReadOnly(dialog_->typeCO);
-       bcview().addReadOnly(dialog_->innerBoxCO);
-       bcview().addReadOnly(dialog_->valignCO);
-       bcview().addReadOnly(dialog_->ialignCO);
-       bcview().addReadOnly(dialog_->halignCO);
-       bcview().addReadOnly(dialog_->widthED);
-       bcview().addReadOnly(dialog_->heightED);
-       bcview().addReadOnly(dialog_->widthUnitsLC);
-       bcview().addReadOnly(dialog_->heightUnitsLC);
-
-       bcview().setRestore(dialog_->restorePB);
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-
-       // initialize the length validator
-       addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
-       addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
-}
-
-
-void QBox::update_contents()
-{
-       string type(controller().params().type);
-       for (unsigned int i = 0; i < gui_names_.size(); ++i) {
-               if (type == ids_[i])
-                       dialog_->typeCO->setCurrentIndex(i);
-       }
-
-       // default: minipage
-       unsigned int inner_type = 2;
-       if (!controller().params().inner_box)
-               // none
-               inner_type = 0;
-       if (controller().params().use_parbox)
-               // parbox
-               inner_type = 1;
-       bool frameless = (controller().params().type == "Frameless");
-       setInnerType(frameless, inner_type);
-
-       char c = controller().params().pos;
-       dialog_->valignCO->setCurrentIndex(string("tcb").find(c, 0));
-       c = controller().params().inner_pos;
-       dialog_->ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
-       c = controller().params().hor_pos;
-       dialog_->halignCO->setCurrentIndex(string("lcrs").find(c, 0));
-
-       bool ibox = controller().params().inner_box;
-       dialog_->valignCO->setEnabled(ibox);
-       dialog_->ialignCO->setEnabled(ibox);
-       dialog_->halignCO->setEnabled(!ibox);
-       setSpecial(ibox);
-
-       LyXLength::UNIT default_unit =
-               (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
-
-       lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC,
-               (controller().params().width).asString(), default_unit);
-
-       string const special(controller().params().special);
-       if (!special.empty() && special != "none") {
-               QString spc;
-               for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
-                       if (special == ids_spec_[i])
-                               spc = toqstr(gui_names_spec_[i].c_str());
-               }
-               for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) {
-                       if (dialog_->widthUnitsLC->itemText(j) == spc)
-                               dialog_->widthUnitsLC->setCurrentIndex(j);
-               }
-       }
-
-       lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC,
-               (controller().params().height).asString(), default_unit);
-
-       string const height_special(controller().params().height_special);
-       if (!height_special.empty() && height_special != "none") {
-               QString hspc;
-               for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
-                       if (height_special == ids_spec_[i]) {
-                               hspc = toqstr(gui_names_spec_[i].c_str());
-                       }
-               }
-               for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) {
-                       if (dialog_->heightUnitsLC->itemText(j) == hspc) {
-                               dialog_->heightUnitsLC->setCurrentIndex(j);
-                       }
-               }
-       }
-
-       dialog_->heightED->setEnabled(ibox);
-       dialog_->heightUnitsLC->setEnabled(ibox);
-}
-
-
-void QBox::apply()
-{
-       controller().params().type =
-               ids_[dialog_->typeCO->currentIndex()];
-
-       controller().params().inner_box =
-               dialog_->innerBoxCO->currentText() != qt_("None");
-       controller().params().use_parbox =
-               dialog_->innerBoxCO->currentText() ==  qt_("Parbox");
-
-       controller().params().pos =
-               "tcb"[dialog_->valignCO->currentIndex()];
-       controller().params().inner_pos =
-               "tcbs"[dialog_->ialignCO->currentIndex()];
-       controller().params().hor_pos =
-               "lcrs"[dialog_->halignCO->currentIndex()];
-
-       int i = 0;
-       bool spec = false;
-       QString special = dialog_->widthUnitsLC->currentText();
-       QString value = dialog_->widthED->text();
-       if (special == qt_("Height")) {
-               i = 1;
-               spec = true;
-       } else if (special == qt_("Depth")) {
-               i = 2;
-               spec = true;
-       } else if (special == qt_("Total Height")) {
-               i = 3;
-               spec = true;
-       } else if (special == qt_("Width")) {
-               i = 4;
-               spec = true;
-       }
-       // the user might insert a non-special value in the line edit
-       if (isValidLength(fromqstr(value))) {
-               i = 0;
-               spec = false;
-       }
-       controller().params().special = ids_spec_[i];
-
-       string width;
-       if (spec) {
-               width = fromqstr(value);
-               // beware: bogosity! the unit is simply ignored in this case
-               width += "in";
-       } else
-               width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC);
-
-       controller().params().width = LyXLength(width);
-
-       i = 0;
-       spec = false;
-       special = dialog_->heightUnitsLC->currentText();
-       value = dialog_->heightED->text();
-       if (special == qt_("Height")) {
-               i = 1;
-               spec = true;
-       } else if (special == qt_("Depth")) {
-               i = 2;
-               spec = true;
-       } else if (special == qt_("Total Height")) {
-               i = 3;
-               spec = true;
-       } else if (special == qt_("Width")) {
-               i = 4;
-               spec = true;
-       }
-       // the user might insert a non-special value in the line edit
-       if (isValidLength(fromqstr(value))) {
-               i = 0;
-               spec = false;
-       }
-       controller().params().height_special = ids_spec_[i];
-
-       string height;
-       if (spec  && !isValidLength(fromqstr(dialog_->heightED->text()))) {
-               height = fromqstr(value);
-               // beware: bogosity! the unit is simply ignored in this case
-               height += "in";
-       } else
-               height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC);
-
-       controller().params().height = LyXLength(height);
-}
-
-
-void QBox::setSpecial(bool ibox)
-{
-       box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
-       // check if the widget contains the special units
-       int count = dialog_->widthUnitsLC->count();
-       bool has_special = false;
-       for (int i = 0; i < count; i++)
-               if (dialog_->widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0)
-                       has_special = true;
-       // insert 'em if needed...
-       if (!ibox && !has_special) {
-               for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
-                       dialog_->widthUnitsLC->addItem(toqstr(gui_names_spec_[i]));
-       // ... or remove 'em if needed
-       } else if (ibox && has_special) {
-               dialog_->widthUnitsLC->clear();
-               for (int i = 0; i < num_units; i++)
-                       dialog_->widthUnitsLC->addItem(qt_(unit_name_gui[i]));
-       }
-}
-
-
-void QBox::setInnerType(bool frameless, int i)
-{
-       // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
-       // we have to remove "none" then and adjust the combo
-       if (frameless) {
-               dialog_->innerBoxCO->clear();
-               dialog_->innerBoxCO->addItem(qt_("Parbox"));
-               dialog_->innerBoxCO->addItem(qt_("Minipage"));
-               dialog_->innerBoxCO->setCurrentIndex(i - 1);
-       } else {
-               if (dialog_->innerBoxCO->count() == 2)
-                       i += 1;
-               dialog_->innerBoxCO->clear();
-               dialog_->innerBoxCO->addItem(qt_("None"));
-               dialog_->innerBoxCO->addItem(qt_("Parbox"));
-               dialog_->innerBoxCO->addItem(qt_("Minipage"));
-               dialog_->innerBoxCO->setCurrentIndex(i);
-       }
-}
-
-} // namespace frontend
-} // namespace lyx
-
-
-#include "QBox_moc.cpp"
-
diff --git a/src/frontends/qt4/QBox.cpp b/src/frontends/qt4/QBox.cpp
new file mode 100644 (file)
index 0000000..d62c78e
--- /dev/null
@@ -0,0 +1,396 @@
+/**
+ * \file QBox.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna (Minipage stuff)
+ * \author Martin Vermeer
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QBox.h"
+
+#include "CheckedLineEdit.h"
+#include "LengthCombo.h"
+#include "qt_helpers.h"
+#include "Qt2BC.h"
+#include "lengthcommon.h"
+#include "lyxrc.h" // to set the default length values
+#include "Validator.h"
+
+#include "controllers/ControlBox.h"
+#include "controllers/frontend_helpers.h"
+
+#include "insets/InsetBox.h"
+
+#include "support/lstrings.h"
+
+#include <QPushButton>
+#include <QLineEdit>
+#include <QCloseEvent>
+
+
+using lyx::support::getStringFromVector;
+using lyx::support::isStrDbl;
+using lyx::support::subst;
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+//////////////////////////////////////////////////////////////////
+//
+// QBoxDialog
+//
+//////////////////////////////////////////////////////////////////
+
+QBoxDialog::QBoxDialog(QBox * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(widthED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(widthUnitsLC, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(change_adaptor()));
+       connect(valignCO, SIGNAL(highlighted(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(heightED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(heightUnitsLC, SIGNAL(selectionChanged(LyXLength::UNIT) ),
+               this, SLOT(change_adaptor()));
+       connect(restorePB, SIGNAL(clicked()), this, SLOT(restoreClicked()));
+       connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
+       connect(halignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(ialignCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(innerBoxCO, SIGNAL(activated(const QString&)),
+               this, SLOT(innerBoxChanged(const QString &)));
+       connect(innerBoxCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+
+       heightED->setValidator(unsignedLengthValidator(heightED));
+       widthED->setValidator(unsignedLengthValidator(widthED));
+}
+
+
+void QBoxDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QBoxDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QBoxDialog::innerBoxChanged(const QString & str)
+{
+       bool const ibox = (str != qt_("None"));
+       valignCO->setEnabled(ibox);
+       ialignCO->setEnabled(ibox);
+       halignCO->setEnabled(!ibox);
+       heightED->setEnabled(ibox);
+       heightUnitsLC->setEnabled(ibox);
+       form_->setSpecial(ibox);
+}
+
+
+void QBoxDialog::typeChanged(int index)
+{
+       bool const frameless = (index == 0);
+       if (frameless) {
+               valignCO->setEnabled(true);
+               ialignCO->setEnabled(true);
+               halignCO->setEnabled(false);
+               heightED->setEnabled(true);
+               heightUnitsLC->setEnabled(true);
+               form_->setSpecial(true);
+       }
+       int itype = innerBoxCO->currentIndex();
+       form_->setInnerType(frameless, itype);
+}
+
+
+void QBoxDialog::restoreClicked()
+{
+       form_->setInnerType(true, 2);
+       widthED->setText("100");
+       widthUnitsLC->setCurrentItem(LyXLength::PCW);
+       heightED->setText("1");
+       for (int j = 0; j < heightUnitsLC->count(); j++) {
+               if (heightUnitsLC->itemText(j) == qt_("Total Height"))
+                       heightUnitsLC->setCurrentItem(j);
+       }
+}
+
+
+//////////////////////////////////////////////////////////////////
+//
+// QBox
+//
+//////////////////////////////////////////////////////////////////
+
+typedef QController<ControlBox, QView<QBoxDialog> > box_base_class;
+
+QBox::QBox(Dialog & parent)
+       : box_base_class(parent, _("Box Settings"))
+{}
+
+
+void QBox::build_dialog()
+{
+       dialog_.reset(new QBoxDialog(this));
+
+       // fill the box type choice
+       box_gui_tokens(ids_, gui_names_);
+       for (unsigned int i = 0; i < gui_names_.size(); ++i)
+               dialog_->typeCO->addItem(toqstr(gui_names_[i]));
+
+       // add the special units to the height choice
+       // width needs different handling
+       box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
+       for (unsigned int i = 1; i < gui_names_spec_.size(); ++i) 
+               dialog_->heightUnitsLC->addItem(toqstr(gui_names_spec_[i]));
+
+       bcview().addReadOnly(dialog_->typeCO);
+       bcview().addReadOnly(dialog_->innerBoxCO);
+       bcview().addReadOnly(dialog_->valignCO);
+       bcview().addReadOnly(dialog_->ialignCO);
+       bcview().addReadOnly(dialog_->halignCO);
+       bcview().addReadOnly(dialog_->widthED);
+       bcview().addReadOnly(dialog_->heightED);
+       bcview().addReadOnly(dialog_->widthUnitsLC);
+       bcview().addReadOnly(dialog_->heightUnitsLC);
+
+       bcview().setRestore(dialog_->restorePB);
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+
+       // initialize the length validator
+       addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
+       addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
+}
+
+
+void QBox::update_contents()
+{
+       string type(controller().params().type);
+       for (unsigned int i = 0; i < gui_names_.size(); ++i) {
+               if (type == ids_[i])
+                       dialog_->typeCO->setCurrentIndex(i);
+       }
+
+       // default: minipage
+       unsigned int inner_type = 2;
+       if (!controller().params().inner_box)
+               // none
+               inner_type = 0;
+       if (controller().params().use_parbox)
+               // parbox
+               inner_type = 1;
+       bool frameless = (controller().params().type == "Frameless");
+       setInnerType(frameless, inner_type);
+
+       char c = controller().params().pos;
+       dialog_->valignCO->setCurrentIndex(string("tcb").find(c, 0));
+       c = controller().params().inner_pos;
+       dialog_->ialignCO->setCurrentIndex(string("tcbs").find(c, 0));
+       c = controller().params().hor_pos;
+       dialog_->halignCO->setCurrentIndex(string("lcrs").find(c, 0));
+
+       bool ibox = controller().params().inner_box;
+       dialog_->valignCO->setEnabled(ibox);
+       dialog_->ialignCO->setEnabled(ibox);
+       dialog_->halignCO->setEnabled(!ibox);
+       setSpecial(ibox);
+
+       LyXLength::UNIT default_unit =
+               (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
+
+       lengthToWidgets(dialog_->widthED, dialog_->widthUnitsLC,
+               (controller().params().width).asString(), default_unit);
+
+       string const special(controller().params().special);
+       if (!special.empty() && special != "none") {
+               QString spc;
+               for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
+                       if (special == ids_spec_[i])
+                               spc = toqstr(gui_names_spec_[i].c_str());
+               }
+               for (int j = 0; j < dialog_->widthUnitsLC->count(); j++) {
+                       if (dialog_->widthUnitsLC->itemText(j) == spc)
+                               dialog_->widthUnitsLC->setCurrentIndex(j);
+               }
+       }
+
+       lengthToWidgets(dialog_->heightED, dialog_->heightUnitsLC,
+               (controller().params().height).asString(), default_unit);
+
+       string const height_special(controller().params().height_special);
+       if (!height_special.empty() && height_special != "none") {
+               QString hspc;
+               for (unsigned int i = 0; i < gui_names_spec_.size(); i++) {
+                       if (height_special == ids_spec_[i]) {
+                               hspc = toqstr(gui_names_spec_[i].c_str());
+                       }
+               }
+               for (int j = 0; j < dialog_->heightUnitsLC->count(); j++) {
+                       if (dialog_->heightUnitsLC->itemText(j) == hspc) {
+                               dialog_->heightUnitsLC->setCurrentIndex(j);
+                       }
+               }
+       }
+
+       dialog_->heightED->setEnabled(ibox);
+       dialog_->heightUnitsLC->setEnabled(ibox);
+}
+
+
+void QBox::apply()
+{
+       controller().params().type =
+               ids_[dialog_->typeCO->currentIndex()];
+
+       controller().params().inner_box =
+               dialog_->innerBoxCO->currentText() != qt_("None");
+       controller().params().use_parbox =
+               dialog_->innerBoxCO->currentText() ==  qt_("Parbox");
+
+       controller().params().pos =
+               "tcb"[dialog_->valignCO->currentIndex()];
+       controller().params().inner_pos =
+               "tcbs"[dialog_->ialignCO->currentIndex()];
+       controller().params().hor_pos =
+               "lcrs"[dialog_->halignCO->currentIndex()];
+
+       int i = 0;
+       bool spec = false;
+       QString special = dialog_->widthUnitsLC->currentText();
+       QString value = dialog_->widthED->text();
+       if (special == qt_("Height")) {
+               i = 1;
+               spec = true;
+       } else if (special == qt_("Depth")) {
+               i = 2;
+               spec = true;
+       } else if (special == qt_("Total Height")) {
+               i = 3;
+               spec = true;
+       } else if (special == qt_("Width")) {
+               i = 4;
+               spec = true;
+       }
+       // the user might insert a non-special value in the line edit
+       if (isValidLength(fromqstr(value))) {
+               i = 0;
+               spec = false;
+       }
+       controller().params().special = ids_spec_[i];
+
+       string width;
+       if (spec) {
+               width = fromqstr(value);
+               // beware: bogosity! the unit is simply ignored in this case
+               width += "in";
+       } else
+               width = widgetsToLength(dialog_->widthED, dialog_->widthUnitsLC);
+
+       controller().params().width = LyXLength(width);
+
+       i = 0;
+       spec = false;
+       special = dialog_->heightUnitsLC->currentText();
+       value = dialog_->heightED->text();
+       if (special == qt_("Height")) {
+               i = 1;
+               spec = true;
+       } else if (special == qt_("Depth")) {
+               i = 2;
+               spec = true;
+       } else if (special == qt_("Total Height")) {
+               i = 3;
+               spec = true;
+       } else if (special == qt_("Width")) {
+               i = 4;
+               spec = true;
+       }
+       // the user might insert a non-special value in the line edit
+       if (isValidLength(fromqstr(value))) {
+               i = 0;
+               spec = false;
+       }
+       controller().params().height_special = ids_spec_[i];
+
+       string height;
+       if (spec  && !isValidLength(fromqstr(dialog_->heightED->text()))) {
+               height = fromqstr(value);
+               // beware: bogosity! the unit is simply ignored in this case
+               height += "in";
+       } else
+               height = widgetsToLength(dialog_->heightED, dialog_->heightUnitsLC);
+
+       controller().params().height = LyXLength(height);
+}
+
+
+void QBox::setSpecial(bool ibox)
+{
+       box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
+       // check if the widget contains the special units
+       int count = dialog_->widthUnitsLC->count();
+       bool has_special = false;
+       for (int i = 0; i < count; i++)
+               if (dialog_->widthUnitsLC->itemText(i).contains(qt_("Total Height")) > 0)
+                       has_special = true;
+       // insert 'em if needed...
+       if (!ibox && !has_special) {
+               for (unsigned int i = 1; i < gui_names_spec_.size(); i++)
+                       dialog_->widthUnitsLC->addItem(toqstr(gui_names_spec_[i]));
+       // ... or remove 'em if needed
+       } else if (ibox && has_special) {
+               dialog_->widthUnitsLC->clear();
+               for (int i = 0; i < num_units; i++)
+                       dialog_->widthUnitsLC->addItem(qt_(unit_name_gui[i]));
+       }
+}
+
+
+void QBox::setInnerType(bool frameless, int i)
+{
+       // with "frameless" boxes, inner box is mandatory (i.e. is the actual box)
+       // we have to remove "none" then and adjust the combo
+       if (frameless) {
+               dialog_->innerBoxCO->clear();
+               dialog_->innerBoxCO->addItem(qt_("Parbox"));
+               dialog_->innerBoxCO->addItem(qt_("Minipage"));
+               dialog_->innerBoxCO->setCurrentIndex(i - 1);
+       } else {
+               if (dialog_->innerBoxCO->count() == 2)
+                       i += 1;
+               dialog_->innerBoxCO->clear();
+               dialog_->innerBoxCO->addItem(qt_("None"));
+               dialog_->innerBoxCO->addItem(qt_("Parbox"));
+               dialog_->innerBoxCO->addItem(qt_("Minipage"));
+               dialog_->innerBoxCO->setCurrentIndex(i);
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QBox_moc.cpp"
+
diff --git a/src/frontends/qt4/QBranch.C b/src/frontends/qt4/QBranch.C
deleted file mode 100644 (file)
index 757a69c..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * \file QBranch.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QBranch.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "BranchList.h"
-
-#include "controllers/ControlBranch.h"
-
-#include "insets/InsetBranch.h"
-
-#include <QPushButton>
-#include <QCloseEvent>
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QBranchDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QBranchDialog::QBranchDialog(QBranch * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(okPB, SIGNAL(clicked()),
-               form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-       connect(branchCO, SIGNAL( activated(int) ), 
-               this, SLOT( change_adaptor() ) );
-}
-
-
-void QBranchDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QBranchDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QBranch
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlBranch, QView<QBranchDialog> > branch_base_class;
-
-
-QBranch::QBranch(Dialog & parent)
-       : branch_base_class(parent, _("Branch Settings"))
-{}
-
-
-void QBranch::build_dialog()
-{
-       dialog_.reset(new QBranchDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QBranch::update_contents()
-{
-       typedef BranchList::const_iterator const_iterator;
-
-       BranchList const & branchlist = controller().branchlist();
-       docstring const cur_branch = controller().params().branch;
-
-       dialog_->branchCO->clear();
-
-       const_iterator const begin = branchlist.begin();
-       const_iterator const end = branchlist.end();
-       int id = 0;
-       int count = 0;
-       for (const_iterator it = begin; it != end; ++it, ++count) {
-               docstring const & branch = it->getBranch();
-               dialog_->branchCO->addItem(toqstr(branch));
-
-               if (cur_branch == branch)
-                       id = count;
-       }
-       dialog_->branchCO->setCurrentIndex(id);
-}
-
-
-void QBranch::apply()
-{
-       docstring const type = qstring_to_ucs4(dialog_->branchCO->currentText());
-       controller().params().branch = type;
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QBranch_moc.cpp"
diff --git a/src/frontends/qt4/QBranch.cpp b/src/frontends/qt4/QBranch.cpp
new file mode 100644 (file)
index 0000000..757a69c
--- /dev/null
@@ -0,0 +1,117 @@
+/**
+ * \file QBranch.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QBranch.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "BranchList.h"
+
+#include "controllers/ControlBranch.h"
+
+#include "insets/InsetBranch.h"
+
+#include <QPushButton>
+#include <QCloseEvent>
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QBranchDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QBranchDialog::QBranchDialog(QBranch * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(okPB, SIGNAL(clicked()),
+               form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+       connect(branchCO, SIGNAL( activated(int) ), 
+               this, SLOT( change_adaptor() ) );
+}
+
+
+void QBranchDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QBranchDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QBranch
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlBranch, QView<QBranchDialog> > branch_base_class;
+
+
+QBranch::QBranch(Dialog & parent)
+       : branch_base_class(parent, _("Branch Settings"))
+{}
+
+
+void QBranch::build_dialog()
+{
+       dialog_.reset(new QBranchDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QBranch::update_contents()
+{
+       typedef BranchList::const_iterator const_iterator;
+
+       BranchList const & branchlist = controller().branchlist();
+       docstring const cur_branch = controller().params().branch;
+
+       dialog_->branchCO->clear();
+
+       const_iterator const begin = branchlist.begin();
+       const_iterator const end = branchlist.end();
+       int id = 0;
+       int count = 0;
+       for (const_iterator it = begin; it != end; ++it, ++count) {
+               docstring const & branch = it->getBranch();
+               dialog_->branchCO->addItem(toqstr(branch));
+
+               if (cur_branch == branch)
+                       id = count;
+       }
+       dialog_->branchCO->setCurrentIndex(id);
+}
+
+
+void QBranch::apply()
+{
+       docstring const type = qstring_to_ucs4(dialog_->branchCO->currentText());
+       controller().params().branch = type;
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QBranch_moc.cpp"
diff --git a/src/frontends/qt4/QBranches.C b/src/frontends/qt4/QBranches.C
deleted file mode 100644 (file)
index 49a5682..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * \file QBranches.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QBranches.h"
-
-#include "GuiApplication.h"
-#include "Validator.h"
-#include "qt_helpers.h"
-
-#include "bufferparams.h"
-#include "controllers/ControlDocument.h"
-
-#include "support/lstrings.h"
-
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-#include <QPixmap>
-#include <QIcon>
-#include <QColor>
-#include <QColorDialog>
-
-
-namespace lyx {
-namespace frontend {
-
-
-QBranches::QBranches(QWidget * parent, Qt::WFlags f)
-       : QWidget(parent, f)
-{
-       setupUi(this);
-       branchesTW->setColumnCount(3);
-       branchesTW->headerItem()->setText(0, qt_("Branch"));
-       branchesTW->headerItem()->setText(1, qt_("Activated"));
-       branchesTW->headerItem()->setText(2, qt_("Color"));
-       branchesTW->setSortingEnabled(true);
-}
-
-void QBranches::update(BufferParams const & params)
-{
-       branchlist_ = params.branchlist();
-       update();
-}
-
-void QBranches::update()
-{
-       // store the selected branch
-       QTreeWidgetItem * item = branchesTW->currentItem();
-       QString sel_branch;
-       if (item != 0)
-               sel_branch = item->text(0);
-
-       branchesTW->clear();
-
-       BranchList::const_iterator it = branchlist_.begin();
-       BranchList::const_iterator const end = branchlist_.end();
-       for (; it != end; ++it) {
-               QTreeWidgetItem * newItem =
-                       new QTreeWidgetItem(branchesTW);
-
-               QString const bname = toqstr(it->getBranch());
-               newItem->setText(0, bname);
-
-               QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
-               newItem->setText(1, sel);
-
-               QColor const itemcolor = rgb2qcolor(it->getColor());
-               if (itemcolor.isValid()) {
-                       QPixmap coloritem(30, 10);
-                       coloritem.fill(itemcolor);
-                       newItem->setIcon(2, QIcon(coloritem));
-               }
-               // restore selected branch
-               if (bname == sel_branch) {
-                       branchesTW->setCurrentItem(newItem);
-                       branchesTW->setItemSelected(newItem, true);
-               }
-       }
-       // emit signal
-       changed();
-}
-
-void QBranches::apply(BufferParams & params) const
-{
-       params.branchlist() = branchlist_;
-}
-
-void QBranches::on_addBranchPB_pressed()
-{
-       QString const new_branch = newBranchLE->text();
-       if (!new_branch.isEmpty()) {
-               branchlist_.add(qstring_to_ucs4(new_branch));
-               newBranchLE->clear();
-               update();
-       }
-}
-
-
-void QBranches::on_removePB_pressed()
-{
-       QTreeWidgetItem * selItem =
-               branchesTW->currentItem();
-       QString sel_branch;
-       if (selItem != 0)
-               sel_branch = selItem->text(0);
-       if (!sel_branch.isEmpty()) {
-               branchlist_.remove(qstring_to_ucs4(sel_branch));
-               newBranchLE->clear();
-               update();
-       }
-}
-
-
-void QBranches::on_activatePB_pressed()
-{
-       toggleBranch(branchesTW->currentItem());
-}
-
-
-void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
-{
-       if (col < 2)
-               toggleBranch(item);
-       else
-               toggleColor(item);
-}
-
-
-void QBranches::toggleBranch(QTreeWidgetItem * item)
-{
-       if (item == 0)
-               return;
-
-       QString sel_branch = item->text(0);
-       if (!sel_branch.isEmpty()) {
-               bool const selected = item->text(1) == qt_("Yes");
-               Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
-               if (branch && branch->setSelected(!selected)) {
-                       newBranchLE->clear();
-                       update();
-               }
-       }
-}
-
-
-void QBranches::on_colorPB_clicked()
-{
-       toggleColor(branchesTW->currentItem());
-}
-
-
-void QBranches::toggleColor(QTreeWidgetItem * item)
-{
-       if (item == 0)
-               return;
-
-       QString sel_branch = item->text(0);
-       if (!sel_branch.isEmpty()) {
-               docstring current_branch = qstring_to_ucs4(sel_branch);
-               Branch * branch =
-                       branchlist_.find(current_branch);
-               if (!branch)
-                       return;
-
-               QColor const initial = rgb2qcolor(branch->getColor());
-               QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget()));
-               if (ncol.isValid()){
-                       // add the color to the branchlist
-                       branch->setColor(fromqstr(ncol.name()));
-                       newBranchLE->clear();
-                       update();
-               }
-       }
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QBranches_moc.cpp"
diff --git a/src/frontends/qt4/QBranches.cpp b/src/frontends/qt4/QBranches.cpp
new file mode 100644 (file)
index 0000000..49a5682
--- /dev/null
@@ -0,0 +1,188 @@
+/**
+ * \file QBranches.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QBranches.h"
+
+#include "GuiApplication.h"
+#include "Validator.h"
+#include "qt_helpers.h"
+
+#include "bufferparams.h"
+#include "controllers/ControlDocument.h"
+
+#include "support/lstrings.h"
+
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QPixmap>
+#include <QIcon>
+#include <QColor>
+#include <QColorDialog>
+
+
+namespace lyx {
+namespace frontend {
+
+
+QBranches::QBranches(QWidget * parent, Qt::WFlags f)
+       : QWidget(parent, f)
+{
+       setupUi(this);
+       branchesTW->setColumnCount(3);
+       branchesTW->headerItem()->setText(0, qt_("Branch"));
+       branchesTW->headerItem()->setText(1, qt_("Activated"));
+       branchesTW->headerItem()->setText(2, qt_("Color"));
+       branchesTW->setSortingEnabled(true);
+}
+
+void QBranches::update(BufferParams const & params)
+{
+       branchlist_ = params.branchlist();
+       update();
+}
+
+void QBranches::update()
+{
+       // store the selected branch
+       QTreeWidgetItem * item = branchesTW->currentItem();
+       QString sel_branch;
+       if (item != 0)
+               sel_branch = item->text(0);
+
+       branchesTW->clear();
+
+       BranchList::const_iterator it = branchlist_.begin();
+       BranchList::const_iterator const end = branchlist_.end();
+       for (; it != end; ++it) {
+               QTreeWidgetItem * newItem =
+                       new QTreeWidgetItem(branchesTW);
+
+               QString const bname = toqstr(it->getBranch());
+               newItem->setText(0, bname);
+
+               QString const sel = it->getSelected() ? qt_("Yes") : qt_("No");
+               newItem->setText(1, sel);
+
+               QColor const itemcolor = rgb2qcolor(it->getColor());
+               if (itemcolor.isValid()) {
+                       QPixmap coloritem(30, 10);
+                       coloritem.fill(itemcolor);
+                       newItem->setIcon(2, QIcon(coloritem));
+               }
+               // restore selected branch
+               if (bname == sel_branch) {
+                       branchesTW->setCurrentItem(newItem);
+                       branchesTW->setItemSelected(newItem, true);
+               }
+       }
+       // emit signal
+       changed();
+}
+
+void QBranches::apply(BufferParams & params) const
+{
+       params.branchlist() = branchlist_;
+}
+
+void QBranches::on_addBranchPB_pressed()
+{
+       QString const new_branch = newBranchLE->text();
+       if (!new_branch.isEmpty()) {
+               branchlist_.add(qstring_to_ucs4(new_branch));
+               newBranchLE->clear();
+               update();
+       }
+}
+
+
+void QBranches::on_removePB_pressed()
+{
+       QTreeWidgetItem * selItem =
+               branchesTW->currentItem();
+       QString sel_branch;
+       if (selItem != 0)
+               sel_branch = selItem->text(0);
+       if (!sel_branch.isEmpty()) {
+               branchlist_.remove(qstring_to_ucs4(sel_branch));
+               newBranchLE->clear();
+               update();
+       }
+}
+
+
+void QBranches::on_activatePB_pressed()
+{
+       toggleBranch(branchesTW->currentItem());
+}
+
+
+void QBranches::on_branchesTW_itemDoubleClicked(QTreeWidgetItem * item, int col)
+{
+       if (col < 2)
+               toggleBranch(item);
+       else
+               toggleColor(item);
+}
+
+
+void QBranches::toggleBranch(QTreeWidgetItem * item)
+{
+       if (item == 0)
+               return;
+
+       QString sel_branch = item->text(0);
+       if (!sel_branch.isEmpty()) {
+               bool const selected = item->text(1) == qt_("Yes");
+               Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
+               if (branch && branch->setSelected(!selected)) {
+                       newBranchLE->clear();
+                       update();
+               }
+       }
+}
+
+
+void QBranches::on_colorPB_clicked()
+{
+       toggleColor(branchesTW->currentItem());
+}
+
+
+void QBranches::toggleColor(QTreeWidgetItem * item)
+{
+       if (item == 0)
+               return;
+
+       QString sel_branch = item->text(0);
+       if (!sel_branch.isEmpty()) {
+               docstring current_branch = qstring_to_ucs4(sel_branch);
+               Branch * branch =
+                       branchlist_.find(current_branch);
+               if (!branch)
+                       return;
+
+               QColor const initial = rgb2qcolor(branch->getColor());
+               QColor ncol(QColorDialog::getColor(initial, qApp->focusWidget()));
+               if (ncol.isValid()){
+                       // add the color to the branchlist
+                       branch->setColor(fromqstr(ncol.name()));
+                       newBranchLE->clear();
+                       update();
+               }
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QBranches_moc.cpp"
diff --git a/src/frontends/qt4/QChanges.C b/src/frontends/qt4/QChanges.C
deleted file mode 100644 (file)
index e7613e0..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * \file QChanges.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Michael Gerz
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QChanges.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "support/lstrings.h"
-
-#include "controllers/ControlChanges.h"
-
-#include <QPushButton>
-#include <QCloseEvent>
-#include <QTextBrowser>
-
-using lyx::support::bformat;
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QChangesDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QChangesDialog::QChangesDialog(QChanges * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-       connect(nextPB, SIGNAL(clicked()), this, SLOT(nextPressed()));
-       connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectPressed()));
-       connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptPressed()));
-}
-
-
-void QChangesDialog::nextPressed()
-{
-       form_->next();
-}
-
-
-void QChangesDialog::acceptPressed()
-{
-       form_->accept();
-}
-
-
-void QChangesDialog::rejectPressed()
-{
-       form_->reject();
-}
-
-
-void QChangesDialog::closeEvent(QCloseEvent *e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QChanges
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlChanges, QView<QChangesDialog> > ChangesBase;
-
-
-QChanges::QChanges(Dialog & parent)
-       : ChangesBase(parent, _("Merge Changes"))
-{
-}
-
-
-void QChanges::build_dialog()
-{
-       dialog_.reset(new QChangesDialog(this));
-
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->acceptPB);
-       bcview().addReadOnly(dialog_->rejectPB);
-}
-
-
-void QChanges::update_contents()
-{
-       docstring text;
-       docstring author = controller().getChangeAuthor();
-       docstring date = controller().getChangeDate();
-
-       if (!author.empty())
-               text += bformat(_("Change by %1$s\n\n"), author);
-       if (!date.empty())
-               text += bformat(_("Change made at %1$s\n"), date);
-
-       dialog_->changeTB->setPlainText(toqstr(text));
-}
-
-
-void QChanges::next()
-{
-       controller().next();
-}
-
-
-void QChanges::accept()
-{
-       controller().accept();
-}
-
-
-void QChanges::reject()
-{
-       controller().reject();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QChanges_moc.cpp"
diff --git a/src/frontends/qt4/QChanges.cpp b/src/frontends/qt4/QChanges.cpp
new file mode 100644 (file)
index 0000000..e7613e0
--- /dev/null
@@ -0,0 +1,135 @@
+/**
+ * \file QChanges.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Michael Gerz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QChanges.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "support/lstrings.h"
+
+#include "controllers/ControlChanges.h"
+
+#include <QPushButton>
+#include <QCloseEvent>
+#include <QTextBrowser>
+
+using lyx::support::bformat;
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QChangesDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QChangesDialog::QChangesDialog(QChanges * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+       connect(nextPB, SIGNAL(clicked()), this, SLOT(nextPressed()));
+       connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectPressed()));
+       connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptPressed()));
+}
+
+
+void QChangesDialog::nextPressed()
+{
+       form_->next();
+}
+
+
+void QChangesDialog::acceptPressed()
+{
+       form_->accept();
+}
+
+
+void QChangesDialog::rejectPressed()
+{
+       form_->reject();
+}
+
+
+void QChangesDialog::closeEvent(QCloseEvent *e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QChanges
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlChanges, QView<QChangesDialog> > ChangesBase;
+
+
+QChanges::QChanges(Dialog & parent)
+       : ChangesBase(parent, _("Merge Changes"))
+{
+}
+
+
+void QChanges::build_dialog()
+{
+       dialog_.reset(new QChangesDialog(this));
+
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->acceptPB);
+       bcview().addReadOnly(dialog_->rejectPB);
+}
+
+
+void QChanges::update_contents()
+{
+       docstring text;
+       docstring author = controller().getChangeAuthor();
+       docstring date = controller().getChangeDate();
+
+       if (!author.empty())
+               text += bformat(_("Change by %1$s\n\n"), author);
+       if (!date.empty())
+               text += bformat(_("Change made at %1$s\n"), date);
+
+       dialog_->changeTB->setPlainText(toqstr(text));
+}
+
+
+void QChanges::next()
+{
+       controller().next();
+}
+
+
+void QChanges::accept()
+{
+       controller().accept();
+}
+
+
+void QChanges::reject()
+{
+       controller().reject();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QChanges_moc.cpp"
diff --git a/src/frontends/qt4/QCharacter.C b/src/frontends/qt4/QCharacter.C
deleted file mode 100644 (file)
index 86eb85f..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-/**
- * \file QCharacter.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QCharacter.h"
-#include "ControlCharacter.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "LColor.h"
-
-
-#include <QCloseEvent>
-
-using std::vector;
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QCharacterDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QCharacterDialog::QCharacterDialog(QCharacter * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
-
-       connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-}
-
-
-void QCharacterDialog::change_adaptor()
-{
-       form_->changed();
-
-       if (!autoapplyCB->isChecked())
-               return;
-
-       // to be really good here, we should set the combos to the values of
-       // the current text, and make it appear as "no change" if the values
-       // stay the same between applys. Might be difficult though wrt to a
-       // moved cursor - jbl
-       form_->slotApply();
-       familyCO->setCurrentIndex(0);
-       seriesCO->setCurrentIndex(0);
-       sizeCO->setCurrentIndex(0);
-       shapeCO->setCurrentIndex(0);
-       miscCO->setCurrentIndex(0);
-       langCO->setCurrentIndex(0);
-       colorCO->setCurrentIndex(0);
-}
-
-
-void QCharacterDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QCharacter
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlCharacter, QView<QCharacterDialog> > CharacterBase;
-
-QCharacter::QCharacter(Dialog & parent)
-       : CharacterBase(parent, _("Text Style"))
-{
-}
-
-
-void QCharacter::build_dialog()
-{
-       dialog_.reset(new QCharacterDialog(this));
-
-       family = getFamilyData();
-       series = getSeriesData();
-       shape  = getShapeData();
-       size   = getSizeData();
-       bar    = getBarData();
-       color  = getColorData();
-       language = getLanguageData(true);
-
-       for (vector<FamilyPair>::const_iterator cit = family.begin();
-               cit != family.end(); ++cit) {
-               dialog_->familyCO->addItem(toqstr(cit->first));
-       }
-
-       for (vector<SeriesPair>::const_iterator cit = series.begin();
-               cit != series.end(); ++cit) {
-               dialog_->seriesCO->addItem(toqstr(cit->first));
-       }
-       for (vector<ShapePair>::const_iterator cit = shape.begin();
-               cit != shape.end(); ++cit) {
-               dialog_->shapeCO->addItem(toqstr(cit->first));
-       }
-       for (vector<SizePair>::const_iterator cit = size.begin();
-               cit != size.end(); ++cit) {
-               dialog_->sizeCO->addItem(toqstr(cit->first));
-       }
-       for (vector<BarPair>::const_iterator cit = bar.begin();
-               cit != bar.end(); ++cit) {
-               dialog_->miscCO->addItem(toqstr(cit->first));
-       }
-       for (vector<ColorPair>::const_iterator cit = color.begin();
-               cit != color.end(); ++cit) {
-               dialog_->colorCO->addItem(toqstr(cit->first));
-       }
-       for (vector<LanguagePair>::const_iterator cit = language.begin();
-               cit != language.end(); ++cit) {
-               dialog_->langCO->addItem(toqstr(cit->first));
-       }
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->familyCO);
-       bcview().addReadOnly(dialog_->seriesCO);
-       bcview().addReadOnly(dialog_->sizeCO);
-       bcview().addReadOnly(dialog_->shapeCO);
-       bcview().addReadOnly(dialog_->miscCO);
-       bcview().addReadOnly(dialog_->langCO);
-       bcview().addReadOnly(dialog_->colorCO);
-       bcview().addReadOnly(dialog_->toggleallCB);
-       bcview().addReadOnly(dialog_->autoapplyCB);
-
-// FIXME: hack to work around resizing bug in Qt >= 4.2
-// bug verified with Qt 4.2.{0-3} (JSpitzm)
-#if QT_VERSION >= 0x040200
-       // qt resizes the comboboxes only after show(), so ...
-       dialog_->show();
-#endif
-}
-
-
-namespace {
-
-template<class A, class B>
-int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
-{
-       typedef typename vector<std::pair<A, B> >::const_iterator
-               const_iterator;
-
-       const_iterator cit = vec.begin();
-       for (; cit != vec.end(); ++cit) {
-               if (cit->second == val)
-                       return int(cit - vec.begin());
-       }
-       return 0;
-}
-
-} // namespace anon
-
-
-void QCharacter::update_contents()
-{
-       ControlCharacter const & ctrl = controller();
-
-       dialog_->familyCO->setCurrentIndex(findPos2nd(family,
-                                                    ctrl.getFamily()));
-       dialog_->seriesCO->setCurrentIndex(findPos2nd(series,
-                                                    ctrl.getSeries()));
-       dialog_->shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
-       dialog_->sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
-       dialog_->miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
-       dialog_->colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
-       dialog_->langCO->setCurrentIndex(findPos2nd(language,
-                                                  ctrl.getLanguage()));
-
-       dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
-}
-
-
-void QCharacter::apply()
-{
-       ControlCharacter & ctrl = controller();
-
-       ctrl.setFamily(family[dialog_->familyCO->currentIndex()].second);
-       ctrl.setSeries(series[dialog_->seriesCO->currentIndex()].second);
-       ctrl.setShape(shape[dialog_->shapeCO->currentIndex()].second);
-       ctrl.setSize(size[dialog_->sizeCO->currentIndex()].second);
-       ctrl.setBar(bar[dialog_->miscCO->currentIndex()].second);
-       ctrl.setColor(color[dialog_->colorCO->currentIndex()].second);
-       ctrl.setLanguage(language[dialog_->langCO->currentIndex()].second);
-
-       ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QCharacter_moc.cpp"
diff --git a/src/frontends/qt4/QCharacter.cpp b/src/frontends/qt4/QCharacter.cpp
new file mode 100644 (file)
index 0000000..86eb85f
--- /dev/null
@@ -0,0 +1,217 @@
+/**
+ * \file QCharacter.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QCharacter.h"
+#include "ControlCharacter.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "LColor.h"
+
+
+#include <QCloseEvent>
+
+using std::vector;
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QCharacterDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QCharacterDialog::QCharacterDialog(QCharacter * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+
+       connect(miscCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(sizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(familyCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(seriesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(shapeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(colorCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(langCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(toggleallCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+}
+
+
+void QCharacterDialog::change_adaptor()
+{
+       form_->changed();
+
+       if (!autoapplyCB->isChecked())
+               return;
+
+       // to be really good here, we should set the combos to the values of
+       // the current text, and make it appear as "no change" if the values
+       // stay the same between applys. Might be difficult though wrt to a
+       // moved cursor - jbl
+       form_->slotApply();
+       familyCO->setCurrentIndex(0);
+       seriesCO->setCurrentIndex(0);
+       sizeCO->setCurrentIndex(0);
+       shapeCO->setCurrentIndex(0);
+       miscCO->setCurrentIndex(0);
+       langCO->setCurrentIndex(0);
+       colorCO->setCurrentIndex(0);
+}
+
+
+void QCharacterDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QCharacter
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlCharacter, QView<QCharacterDialog> > CharacterBase;
+
+QCharacter::QCharacter(Dialog & parent)
+       : CharacterBase(parent, _("Text Style"))
+{
+}
+
+
+void QCharacter::build_dialog()
+{
+       dialog_.reset(new QCharacterDialog(this));
+
+       family = getFamilyData();
+       series = getSeriesData();
+       shape  = getShapeData();
+       size   = getSizeData();
+       bar    = getBarData();
+       color  = getColorData();
+       language = getLanguageData(true);
+
+       for (vector<FamilyPair>::const_iterator cit = family.begin();
+               cit != family.end(); ++cit) {
+               dialog_->familyCO->addItem(toqstr(cit->first));
+       }
+
+       for (vector<SeriesPair>::const_iterator cit = series.begin();
+               cit != series.end(); ++cit) {
+               dialog_->seriesCO->addItem(toqstr(cit->first));
+       }
+       for (vector<ShapePair>::const_iterator cit = shape.begin();
+               cit != shape.end(); ++cit) {
+               dialog_->shapeCO->addItem(toqstr(cit->first));
+       }
+       for (vector<SizePair>::const_iterator cit = size.begin();
+               cit != size.end(); ++cit) {
+               dialog_->sizeCO->addItem(toqstr(cit->first));
+       }
+       for (vector<BarPair>::const_iterator cit = bar.begin();
+               cit != bar.end(); ++cit) {
+               dialog_->miscCO->addItem(toqstr(cit->first));
+       }
+       for (vector<ColorPair>::const_iterator cit = color.begin();
+               cit != color.end(); ++cit) {
+               dialog_->colorCO->addItem(toqstr(cit->first));
+       }
+       for (vector<LanguagePair>::const_iterator cit = language.begin();
+               cit != language.end(); ++cit) {
+               dialog_->langCO->addItem(toqstr(cit->first));
+       }
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->familyCO);
+       bcview().addReadOnly(dialog_->seriesCO);
+       bcview().addReadOnly(dialog_->sizeCO);
+       bcview().addReadOnly(dialog_->shapeCO);
+       bcview().addReadOnly(dialog_->miscCO);
+       bcview().addReadOnly(dialog_->langCO);
+       bcview().addReadOnly(dialog_->colorCO);
+       bcview().addReadOnly(dialog_->toggleallCB);
+       bcview().addReadOnly(dialog_->autoapplyCB);
+
+// FIXME: hack to work around resizing bug in Qt >= 4.2
+// bug verified with Qt 4.2.{0-3} (JSpitzm)
+#if QT_VERSION >= 0x040200
+       // qt resizes the comboboxes only after show(), so ...
+       dialog_->show();
+#endif
+}
+
+
+namespace {
+
+template<class A, class B>
+int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
+{
+       typedef typename vector<std::pair<A, B> >::const_iterator
+               const_iterator;
+
+       const_iterator cit = vec.begin();
+       for (; cit != vec.end(); ++cit) {
+               if (cit->second == val)
+                       return int(cit - vec.begin());
+       }
+       return 0;
+}
+
+} // namespace anon
+
+
+void QCharacter::update_contents()
+{
+       ControlCharacter const & ctrl = controller();
+
+       dialog_->familyCO->setCurrentIndex(findPos2nd(family,
+                                                    ctrl.getFamily()));
+       dialog_->seriesCO->setCurrentIndex(findPos2nd(series,
+                                                    ctrl.getSeries()));
+       dialog_->shapeCO->setCurrentIndex(findPos2nd(shape, ctrl.getShape()));
+       dialog_->sizeCO->setCurrentIndex(findPos2nd(size, ctrl.getSize()));
+       dialog_->miscCO->setCurrentIndex(findPos2nd(bar, ctrl.getBar()));
+       dialog_->colorCO->setCurrentIndex(findPos2nd(color, ctrl.getColor()));
+       dialog_->langCO->setCurrentIndex(findPos2nd(language,
+                                                  ctrl.getLanguage()));
+
+       dialog_->toggleallCB->setChecked(ctrl.getToggleAll());
+}
+
+
+void QCharacter::apply()
+{
+       ControlCharacter & ctrl = controller();
+
+       ctrl.setFamily(family[dialog_->familyCO->currentIndex()].second);
+       ctrl.setSeries(series[dialog_->seriesCO->currentIndex()].second);
+       ctrl.setShape(shape[dialog_->shapeCO->currentIndex()].second);
+       ctrl.setSize(size[dialog_->sizeCO->currentIndex()].second);
+       ctrl.setBar(bar[dialog_->miscCO->currentIndex()].second);
+       ctrl.setColor(color[dialog_->colorCO->currentIndex()].second);
+       ctrl.setLanguage(language[dialog_->langCO->currentIndex()].second);
+
+       ctrl.setToggleAll(dialog_->toggleallCB->isChecked());
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QCharacter_moc.cpp"
diff --git a/src/frontends/qt4/QCitation.C b/src/frontends/qt4/QCitation.C
deleted file mode 100644 (file)
index a5c64fa..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * \file QCitation.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- * \author Kalle Dalheimer
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QCitation.h"
-
-#include "qt_helpers.h"
-
-#include "support/lstrings.h"
-
-#include "debug.h"
-
-#include <vector>
-#include <string>
-
-using std::vector;
-using std::string;
-
-
-template<typename String> static QStringList to_qstring_list(vector<String> const & v)
-{
-       QStringList qlist;
-
-       for (size_t i = 0; i != v.size(); ++i) {
-               if (v[i].empty())
-                       continue;
-               qlist.append(lyx::toqstr(v[i]));
-       }
-       return qlist;
-}
-
-
-static vector<string> const to_string_vector(QStringList const & qlist)
-{
-       vector<string> v;
-       for (int i = 0; i != qlist.size(); ++i) {
-               if (qlist[i].isEmpty())
-                       continue;
-               v.push_back(lyx::fromqstr(qlist[i]));
-       }
-       return v;
-}
-
-
-namespace lyx {
-namespace frontend {
-
-
-QCitation::QCitation(Dialog & parent)
-       : ControlCitation(parent)
-{
-}
-
-
-void QCitation::apply(int const choice, bool const full, bool const force,
-                      QString before, QString after)
-{
-       if (cited_keys_.isEmpty())
-               return;
-
-       vector<biblio::CiteStyle> const & styles =
-               ControlCitation::getCiteStyles();
-
-       string const command =
-               biblio::CitationStyle(styles[choice], full, force)
-               .asLatexStr();
-
-       params().setCmdName(command);
-       params()["key"] = qstring_to_ucs4(cited_keys_.join(","));
-       params()["before"] = qstring_to_ucs4(before);
-       params()["after"] = qstring_to_ucs4(after);
-       dispatchParams();
-}
-
-
-void QCitation::clearSelection()
-{
-       cited_keys_.clear();
-       selected_model_.setStringList(cited_keys_);
-}
-
-       
-QString QCitation::textBefore()
-{
-       return toqstr(params()["before"]);
-}
-
-
-QString QCitation::textAfter()
-{
-       return toqstr(params()["after"]);
-}
-
-
-bool QCitation::initialiseParams(std::string const & data)
-{
-       if (!ControlCitation::initialiseParams(data))
-               return false;
-       init();
-       return true;
-}
-
-
-void QCitation::init()
-{
-       // Make the list of all available bibliography keys
-       all_keys_ = to_qstring_list(availableKeys());
-       available_model_.setStringList(all_keys_);
-
-       // Ditto for the keys cited in this inset
-       QString str = toqstr(params()["key"]);
-       if (str.isEmpty())
-               cited_keys_.clear();
-       else
-               cited_keys_ = str.split(",");
-
-       selected_model_.setStringList(cited_keys_);
-}
-
-
-void QCitation::findKey(QString const & str, bool only_keys,
-               bool case_sensitive, bool reg_exp)
-{
-       if (str.isEmpty()) {
-               available_model_.setStringList(all_keys_);
-               return;
-       }
-
-       // Used for optimisation: store last searched string.
-       static QString last_searched_string;
-       // Used to disable the above optimisation.
-       static bool last_case_sensitive;
-       static bool last_reg_exp;
-       // Reset last_searched_string in case of changed option.
-       if (last_case_sensitive != case_sensitive
-               || last_reg_exp != reg_exp) {
-                       LYXERR(Debug::GUI) << "QCitation::findKey: optimisation disabled!" << std::endl;
-               last_searched_string.clear();
-       }
-       // save option for next search.
-       last_case_sensitive = case_sensitive;
-       last_reg_exp = reg_exp;
-
-       Qt::CaseSensitivity qtcase = case_sensitive?
-                       Qt::CaseSensitive: Qt::CaseInsensitive;
-       QStringList keys;
-       // If new string (str) contains the last searched one...
-       if (!last_searched_string.isEmpty() && str.size() > 1 
-               && str.contains(last_searched_string, qtcase))
-               // ... then only search within already found list.
-               keys = available_model_.stringList();
-       else
-               // ... else search all keys.
-               keys = all_keys_;
-       // save searched string for next search.
-       last_searched_string = str;
-
-       QStringList result;
-       if (only_keys)
-               // Search only within the matching keys:
-               result = keys.filter(str, qtcase);
-       else
-               // Search within matching keys and associated info.
-               result = to_qstring_list(searchKeys(to_string_vector(keys),
-                       qstring_to_ucs4(str), case_sensitive, reg_exp));
-
-       available_model_.setStringList(result);
-}
-
-
-void QCitation::addKey(QModelIndex const & index)
-{
-       cited_keys_.append(index.data().toString());
-       selected_model_.setStringList(cited_keys_);
-}
-
-
-void QCitation::deleteKey(QModelIndex const & index)
-{
-       cited_keys_.removeAt(index.row());
-       selected_model_.setStringList(cited_keys_);
-}
-
-
-void QCitation::upKey(QModelIndex const & index)
-{
-       int pos = index.row();
-       cited_keys_.swap(pos, pos - 1);
-       selected_model_.setStringList(cited_keys_);
-}
-
-
-void QCitation::downKey(QModelIndex const & index)
-{
-       int pos = index.row();
-       cited_keys_.swap(pos, pos + 1);
-       selected_model_.setStringList(cited_keys_);
-}
-
-
-QStringList QCitation::citationStyles(int sel)
-{
-       string const key = fromqstr(cited_keys_[sel]);
-       return to_qstring_list(getCiteStrings(key));
-}
-
-
-QString QCitation::getKeyInfo(QString const & sel)
-{
-       return toqstr(getInfo(fromqstr(sel)));
-}
-
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/QCitation.cpp b/src/frontends/qt4/QCitation.cpp
new file mode 100644 (file)
index 0000000..a5c64fa
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * \file QCitation.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ * \author Kalle Dalheimer
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QCitation.h"
+
+#include "qt_helpers.h"
+
+#include "support/lstrings.h"
+
+#include "debug.h"
+
+#include <vector>
+#include <string>
+
+using std::vector;
+using std::string;
+
+
+template<typename String> static QStringList to_qstring_list(vector<String> const & v)
+{
+       QStringList qlist;
+
+       for (size_t i = 0; i != v.size(); ++i) {
+               if (v[i].empty())
+                       continue;
+               qlist.append(lyx::toqstr(v[i]));
+       }
+       return qlist;
+}
+
+
+static vector<string> const to_string_vector(QStringList const & qlist)
+{
+       vector<string> v;
+       for (int i = 0; i != qlist.size(); ++i) {
+               if (qlist[i].isEmpty())
+                       continue;
+               v.push_back(lyx::fromqstr(qlist[i]));
+       }
+       return v;
+}
+
+
+namespace lyx {
+namespace frontend {
+
+
+QCitation::QCitation(Dialog & parent)
+       : ControlCitation(parent)
+{
+}
+
+
+void QCitation::apply(int const choice, bool const full, bool const force,
+                      QString before, QString after)
+{
+       if (cited_keys_.isEmpty())
+               return;
+
+       vector<biblio::CiteStyle> const & styles =
+               ControlCitation::getCiteStyles();
+
+       string const command =
+               biblio::CitationStyle(styles[choice], full, force)
+               .asLatexStr();
+
+       params().setCmdName(command);
+       params()["key"] = qstring_to_ucs4(cited_keys_.join(","));
+       params()["before"] = qstring_to_ucs4(before);
+       params()["after"] = qstring_to_ucs4(after);
+       dispatchParams();
+}
+
+
+void QCitation::clearSelection()
+{
+       cited_keys_.clear();
+       selected_model_.setStringList(cited_keys_);
+}
+
+       
+QString QCitation::textBefore()
+{
+       return toqstr(params()["before"]);
+}
+
+
+QString QCitation::textAfter()
+{
+       return toqstr(params()["after"]);
+}
+
+
+bool QCitation::initialiseParams(std::string const & data)
+{
+       if (!ControlCitation::initialiseParams(data))
+               return false;
+       init();
+       return true;
+}
+
+
+void QCitation::init()
+{
+       // Make the list of all available bibliography keys
+       all_keys_ = to_qstring_list(availableKeys());
+       available_model_.setStringList(all_keys_);
+
+       // Ditto for the keys cited in this inset
+       QString str = toqstr(params()["key"]);
+       if (str.isEmpty())
+               cited_keys_.clear();
+       else
+               cited_keys_ = str.split(",");
+
+       selected_model_.setStringList(cited_keys_);
+}
+
+
+void QCitation::findKey(QString const & str, bool only_keys,
+               bool case_sensitive, bool reg_exp)
+{
+       if (str.isEmpty()) {
+               available_model_.setStringList(all_keys_);
+               return;
+       }
+
+       // Used for optimisation: store last searched string.
+       static QString last_searched_string;
+       // Used to disable the above optimisation.
+       static bool last_case_sensitive;
+       static bool last_reg_exp;
+       // Reset last_searched_string in case of changed option.
+       if (last_case_sensitive != case_sensitive
+               || last_reg_exp != reg_exp) {
+                       LYXERR(Debug::GUI) << "QCitation::findKey: optimisation disabled!" << std::endl;
+               last_searched_string.clear();
+       }
+       // save option for next search.
+       last_case_sensitive = case_sensitive;
+       last_reg_exp = reg_exp;
+
+       Qt::CaseSensitivity qtcase = case_sensitive?
+                       Qt::CaseSensitive: Qt::CaseInsensitive;
+       QStringList keys;
+       // If new string (str) contains the last searched one...
+       if (!last_searched_string.isEmpty() && str.size() > 1 
+               && str.contains(last_searched_string, qtcase))
+               // ... then only search within already found list.
+               keys = available_model_.stringList();
+       else
+               // ... else search all keys.
+               keys = all_keys_;
+       // save searched string for next search.
+       last_searched_string = str;
+
+       QStringList result;
+       if (only_keys)
+               // Search only within the matching keys:
+               result = keys.filter(str, qtcase);
+       else
+               // Search within matching keys and associated info.
+               result = to_qstring_list(searchKeys(to_string_vector(keys),
+                       qstring_to_ucs4(str), case_sensitive, reg_exp));
+
+       available_model_.setStringList(result);
+}
+
+
+void QCitation::addKey(QModelIndex const & index)
+{
+       cited_keys_.append(index.data().toString());
+       selected_model_.setStringList(cited_keys_);
+}
+
+
+void QCitation::deleteKey(QModelIndex const & index)
+{
+       cited_keys_.removeAt(index.row());
+       selected_model_.setStringList(cited_keys_);
+}
+
+
+void QCitation::upKey(QModelIndex const & index)
+{
+       int pos = index.row();
+       cited_keys_.swap(pos, pos - 1);
+       selected_model_.setStringList(cited_keys_);
+}
+
+
+void QCitation::downKey(QModelIndex const & index)
+{
+       int pos = index.row();
+       cited_keys_.swap(pos, pos + 1);
+       selected_model_.setStringList(cited_keys_);
+}
+
+
+QStringList QCitation::citationStyles(int sel)
+{
+       string const key = fromqstr(cited_keys_[sel]);
+       return to_qstring_list(getCiteStrings(key));
+}
+
+
+QString QCitation::getKeyInfo(QString const & sel)
+{
+       return toqstr(getInfo(fromqstr(sel)));
+}
+
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/QCitationDialog.C b/src/frontends/qt4/QCitationDialog.C
deleted file mode 100644 (file)
index b7ace68..0000000
+++ /dev/null
@@ -1,431 +0,0 @@
-/**
- * \file QCitationDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Kalle Dalheimer
- * \author John Levon
- * \author Jürgen Spitzmüller
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QCitationDialog.h"
-
-#include "QCitation.h"
-
-#include "frontends/controllers/frontend_helpers.h"
-#include "frontends/controllers/ControlCitation.h"
-
-#include "debug.h"
-#include "gettext.h"
-
-#include <algorithm>
-#include <vector>
-#include <string>
-
-#include <QCloseEvent>
-#include <QKeyEvent>
-
-using std::vector;
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-
-QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form)
-       : Dialog::View(dialog, _("Citation")), form_(form)
-{
-       setupUi(this);
-
-       setWindowTitle(toqstr("LyX: " + getTitle()));
-
-       selectedLV->setModel(form_->selected());
-       availableLV->setModel(form_->available());
-
-       connect(citationStyleCO, SIGNAL(activated(int)),
-               this, SLOT(changed()));
-       connect(fulllistCB, SIGNAL(clicked()),
-               this, SLOT(changed()));
-       connect(forceuppercaseCB, SIGNAL(clicked()),
-               this, SLOT(changed()));
-       connect(textBeforeED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(changed()));
-       connect(textAfterED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(changed()));
-       connect(clearPB, SIGNAL(clicked()),
-               findLE, SLOT(clear()));
-       connect(availableLV->selectionModel(),
-               SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
-               this, SLOT(availableChanged(const QModelIndex &, const QModelIndex &)));
-       connect(selectedLV->selectionModel(),
-               SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
-               this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &)));
-}
-
-
-QCitationDialog::~QCitationDialog()
-{
-}
-
-
-void QCitationDialog::keyPressEvent(QKeyEvent * event)
-{
-       if (event->key() == Qt::Key_Escape) {
-               form_->clearSelection();
-               form_->clearParams();
-               event->accept();
-               close();
-       } else
-               event->ignore();
-}
-
-
-void QCitationDialog::closeEvent(QCloseEvent * e)
-{
-       form_->clearSelection();
-       form_->clearParams();
-       e->accept();
-}
-
-
-void QCitationDialog::apply()
-{
-       int  const choice = std::max(0, citationStyleCO->currentIndex());
-       style_ = choice;
-       bool const full  = fulllistCB->isChecked();
-       bool const force = forceuppercaseCB->isChecked();
-
-       QString const before = textBeforeED->text();
-       QString const after = textAfterED->text();
-
-       form_->apply(choice, full, force, before, after);
-}
-
-
-void QCitationDialog::hide()
-{
-       form_->clearParams();
-       accept();
-}
-
-
-void QCitationDialog::show()
-{
-       findLE->clear();
-       availableLV->setFocus();
-       QDialog::show();
-}
-
-
-bool QCitationDialog::isVisible() const
-{
-       return QDialog::isVisible();
-}
-
-void QCitationDialog::on_okPB_clicked()
-{
-       apply();
-       form_->clearSelection();
-       hide();
-}
-
-
-void QCitationDialog::on_cancelPB_clicked()
-{
-       form_->clearSelection();
-       hide();
-}
-
-
-void QCitationDialog::on_applyPB_clicked()
-{
-       apply();
-}
-
-
-void QCitationDialog::on_restorePB_clicked()
-{
-       form_->init();
-       update();
-}
-
-
-void QCitationDialog::update()
-{
-       if (selectedLV->selectionModel()->selectedIndexes().isEmpty()) {
-               if (availableLV->selectionModel()->selectedIndexes().isEmpty() 
-                       && availableLV->model()->rowCount() > 0)
-                               availableLV->setCurrentIndex(availableLV->model()->index(0,0));
-               updateInfo(availableLV->currentIndex());
-       } else
-               updateInfo(selectedLV->currentIndex());
-
-       setButtons();
-
-       textBeforeED->setText(form_->textBefore());
-       textAfterED->setText(form_->textAfter());
-
-       fillStyles();
-       updateStyle();
-}
-
-
-void QCitationDialog::updateStyle()
-{
-       biblio::CiteEngine const engine = form_->getEngine();
-       bool const natbib_engine =
-               engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
-               engine == biblio::ENGINE_NATBIB_NUMERICAL;
-       bool const basic_engine = engine == biblio::ENGINE_BASIC;
-
-       fulllistCB->setEnabled(natbib_engine);
-       forceuppercaseCB->setEnabled(natbib_engine);
-       textBeforeED->setEnabled(!basic_engine);
-       textBeforeLA->setEnabled(!basic_engine);
-
-       string const & command = form_->params().getCmdName();
-
-       // Find the style of the citekeys
-       vector<biblio::CiteStyle> const & styles =
-               ControlCitation::getCiteStyles();
-       biblio::CitationStyle const cs(command);
-
-       vector<biblio::CiteStyle>::const_iterator cit =
-               std::find(styles.begin(), styles.end(), cs.style);
-
-       // restore the latest natbib style
-       if (style_ >= 0 && style_ < citationStyleCO->count())
-               citationStyleCO->setCurrentIndex(style_);
-       else
-               citationStyleCO->setCurrentIndex(0);
-
-       fulllistCB->setChecked(false);
-       forceuppercaseCB->setChecked(false);
-
-       if (cit != styles.end()) {
-               int const i = int(cit - styles.begin());
-               citationStyleCO->setCurrentIndex(i);
-               fulllistCB->setChecked(cs.full);
-               forceuppercaseCB->setChecked(cs.forceUCase);
-       }
-}
-
-
-void QCitationDialog::fillStyles()
-{
-       int const orig = citationStyleCO->currentIndex();
-
-       citationStyleCO->clear();
-
-       QStringList selected_keys = form_->selected()->stringList();
-       if (selected_keys.empty()) {
-               citationStyleCO->setEnabled(false);
-               citationStyleLA->setEnabled(false);
-               return;
-       }
-
-       int curr = selectedLV->model()->rowCount() - 1;
-       if (curr < 0)
-               return;
-
-       if (!selectedLV->selectionModel()->selectedIndexes().empty())
-               curr = selectedLV->selectionModel()->selectedIndexes()[0].row();
-
-       QStringList sty = form_->citationStyles(curr);
-
-       bool const basic_engine = 
-               (form_->getEngine() == biblio::ENGINE_BASIC);
-
-       citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
-       citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
-
-       if (sty.isEmpty() || basic_engine)
-               return;
-
-       citationStyleCO->insertItems(0, sty);
-
-       if (orig != -1 && orig < citationStyleCO->count())
-               citationStyleCO->setCurrentIndex(orig);
-}
-
-
-bool QCitationDialog::isSelected(const QModelIndex & idx)
-{
-       QString const str = idx.data().toString();
-       return !form_->selected()->stringList().filter(str).isEmpty();
-}
-
-
-void QCitationDialog::setButtons()
-{
-       int const arows = availableLV->model()->rowCount();
-       addPB->setEnabled(arows>0 && !isSelected(availableLV->currentIndex()));
-
-       int const srows = selectedLV->model()->rowCount();
-       int const sel_nr = selectedLV->currentIndex().row();
-       deletePB->setEnabled(sel_nr >= 0);
-       upPB->setEnabled(sel_nr > 0);
-       downPB->setEnabled(sel_nr >= 0 && sel_nr < srows - 1);
-       applyPB->setEnabled(srows>0);
-       okPB->setEnabled(srows>0);
-}
-
-
-void QCitationDialog::updateInfo(const QModelIndex & idx)
-{
-       if (idx.isValid()) {
-               QString const keytxt = form_->getKeyInfo(idx.data().toString());
-               infoML->document()->setPlainText(keytxt);
-       } else
-               infoML->document()->clear();
-}
-
-
-void QCitationDialog::on_selectedLV_clicked(const QModelIndex &)
-{
-       availableLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::selectedChanged(const QModelIndex & idx, const QModelIndex &)
-{
-       if (!idx.isValid())
-               return;
-
-       availableLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::on_availableLV_clicked(const QModelIndex &)
-{
-       selectedLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::availableChanged(const QModelIndex & idx, const QModelIndex &)
-{
-       if (!idx.isValid())
-               return;
-               
-       selectedLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::on_availableLV_activated(const QModelIndex & idx)
-{
-       if (isSelected(idx))
-               return;
-
-       selectedLV->selectionModel()->reset();
-       on_addPB_clicked();
-       if (selectedLV->model()->rowCount() == 1)
-               on_okPB_clicked();
-}
-
-
-void QCitationDialog::on_availableLV_entered(const QModelIndex &)
-{
-}
-
-
-void QCitationDialog::on_addPB_clicked()
-{
-       QModelIndex idx = selectedLV->currentIndex();
-       form_->addKey(availableLV->currentIndex());
-       if (idx.isValid())
-               selectedLV->setCurrentIndex(idx);
-       selectedLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::on_deletePB_clicked()
-{
-       QModelIndex idx = selectedLV->currentIndex();
-       int nrows = selectedLV->model()->rowCount();
-       
-       form_->deleteKey(idx);
-
-       if (idx.row() == nrows - 1)     
-               idx = idx.sibling(idx.row() - 1, idx.column());
-
-       if (nrows>1)
-               selectedLV->setCurrentIndex(idx);
-
-       availableLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::on_upPB_clicked()
-{
-       QModelIndex idx = selectedLV->currentIndex();
-       form_->upKey(idx);
-       selectedLV->setCurrentIndex(idx.sibling(idx.row() - 1, idx.column()));
-       availableLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::on_downPB_clicked()
-{
-       QModelIndex idx = selectedLV->currentIndex();
-       form_->downKey(idx);
-       selectedLV->setCurrentIndex(idx.sibling(idx.row() + 1, idx.column()));
-       availableLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::findText(QString const & text)
-{
-       bool const case_sentitive = caseCB->checkState();
-       bool const reg_exp = regexCB->checkState();
-       form_->findKey(text, false, case_sentitive, reg_exp);
-       selectedLV->selectionModel()->reset();
-       update();
-}
-
-
-void QCitationDialog::on_findLE_textChanged(const QString & text)
-{
-       clearPB->setDisabled(text.isEmpty());
-       if (text.isEmpty())
-               findLE->setFocus();
-       findText(text);
-}
-
-
-void QCitationDialog::on_caseCB_stateChanged(int)
-{
-       findText(findLE->text());
-}
-
-
-void QCitationDialog::on_regexCB_stateChanged(int)
-{
-       findText(findLE->text());
-}
-
-
-void QCitationDialog::changed()
-{
-       fillStyles();
-       setButtons();
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QCitationDialog_moc.cpp"
diff --git a/src/frontends/qt4/QCitationDialog.cpp b/src/frontends/qt4/QCitationDialog.cpp
new file mode 100644 (file)
index 0000000..b7ace68
--- /dev/null
@@ -0,0 +1,431 @@
+/**
+ * \file QCitationDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Kalle Dalheimer
+ * \author John Levon
+ * \author Jürgen Spitzmüller
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QCitationDialog.h"
+
+#include "QCitation.h"
+
+#include "frontends/controllers/frontend_helpers.h"
+#include "frontends/controllers/ControlCitation.h"
+
+#include "debug.h"
+#include "gettext.h"
+
+#include <algorithm>
+#include <vector>
+#include <string>
+
+#include <QCloseEvent>
+#include <QKeyEvent>
+
+using std::vector;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+
+QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form)
+       : Dialog::View(dialog, _("Citation")), form_(form)
+{
+       setupUi(this);
+
+       setWindowTitle(toqstr("LyX: " + getTitle()));
+
+       selectedLV->setModel(form_->selected());
+       availableLV->setModel(form_->available());
+
+       connect(citationStyleCO, SIGNAL(activated(int)),
+               this, SLOT(changed()));
+       connect(fulllistCB, SIGNAL(clicked()),
+               this, SLOT(changed()));
+       connect(forceuppercaseCB, SIGNAL(clicked()),
+               this, SLOT(changed()));
+       connect(textBeforeED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(changed()));
+       connect(textAfterED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(changed()));
+       connect(clearPB, SIGNAL(clicked()),
+               findLE, SLOT(clear()));
+       connect(availableLV->selectionModel(),
+               SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+               this, SLOT(availableChanged(const QModelIndex &, const QModelIndex &)));
+       connect(selectedLV->selectionModel(),
+               SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+               this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &)));
+}
+
+
+QCitationDialog::~QCitationDialog()
+{
+}
+
+
+void QCitationDialog::keyPressEvent(QKeyEvent * event)
+{
+       if (event->key() == Qt::Key_Escape) {
+               form_->clearSelection();
+               form_->clearParams();
+               event->accept();
+               close();
+       } else
+               event->ignore();
+}
+
+
+void QCitationDialog::closeEvent(QCloseEvent * e)
+{
+       form_->clearSelection();
+       form_->clearParams();
+       e->accept();
+}
+
+
+void QCitationDialog::apply()
+{
+       int  const choice = std::max(0, citationStyleCO->currentIndex());
+       style_ = choice;
+       bool const full  = fulllistCB->isChecked();
+       bool const force = forceuppercaseCB->isChecked();
+
+       QString const before = textBeforeED->text();
+       QString const after = textAfterED->text();
+
+       form_->apply(choice, full, force, before, after);
+}
+
+
+void QCitationDialog::hide()
+{
+       form_->clearParams();
+       accept();
+}
+
+
+void QCitationDialog::show()
+{
+       findLE->clear();
+       availableLV->setFocus();
+       QDialog::show();
+}
+
+
+bool QCitationDialog::isVisible() const
+{
+       return QDialog::isVisible();
+}
+
+void QCitationDialog::on_okPB_clicked()
+{
+       apply();
+       form_->clearSelection();
+       hide();
+}
+
+
+void QCitationDialog::on_cancelPB_clicked()
+{
+       form_->clearSelection();
+       hide();
+}
+
+
+void QCitationDialog::on_applyPB_clicked()
+{
+       apply();
+}
+
+
+void QCitationDialog::on_restorePB_clicked()
+{
+       form_->init();
+       update();
+}
+
+
+void QCitationDialog::update()
+{
+       if (selectedLV->selectionModel()->selectedIndexes().isEmpty()) {
+               if (availableLV->selectionModel()->selectedIndexes().isEmpty() 
+                       && availableLV->model()->rowCount() > 0)
+                               availableLV->setCurrentIndex(availableLV->model()->index(0,0));
+               updateInfo(availableLV->currentIndex());
+       } else
+               updateInfo(selectedLV->currentIndex());
+
+       setButtons();
+
+       textBeforeED->setText(form_->textBefore());
+       textAfterED->setText(form_->textAfter());
+
+       fillStyles();
+       updateStyle();
+}
+
+
+void QCitationDialog::updateStyle()
+{
+       biblio::CiteEngine const engine = form_->getEngine();
+       bool const natbib_engine =
+               engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
+               engine == biblio::ENGINE_NATBIB_NUMERICAL;
+       bool const basic_engine = engine == biblio::ENGINE_BASIC;
+
+       fulllistCB->setEnabled(natbib_engine);
+       forceuppercaseCB->setEnabled(natbib_engine);
+       textBeforeED->setEnabled(!basic_engine);
+       textBeforeLA->setEnabled(!basic_engine);
+
+       string const & command = form_->params().getCmdName();
+
+       // Find the style of the citekeys
+       vector<biblio::CiteStyle> const & styles =
+               ControlCitation::getCiteStyles();
+       biblio::CitationStyle const cs(command);
+
+       vector<biblio::CiteStyle>::const_iterator cit =
+               std::find(styles.begin(), styles.end(), cs.style);
+
+       // restore the latest natbib style
+       if (style_ >= 0 && style_ < citationStyleCO->count())
+               citationStyleCO->setCurrentIndex(style_);
+       else
+               citationStyleCO->setCurrentIndex(0);
+
+       fulllistCB->setChecked(false);
+       forceuppercaseCB->setChecked(false);
+
+       if (cit != styles.end()) {
+               int const i = int(cit - styles.begin());
+               citationStyleCO->setCurrentIndex(i);
+               fulllistCB->setChecked(cs.full);
+               forceuppercaseCB->setChecked(cs.forceUCase);
+       }
+}
+
+
+void QCitationDialog::fillStyles()
+{
+       int const orig = citationStyleCO->currentIndex();
+
+       citationStyleCO->clear();
+
+       QStringList selected_keys = form_->selected()->stringList();
+       if (selected_keys.empty()) {
+               citationStyleCO->setEnabled(false);
+               citationStyleLA->setEnabled(false);
+               return;
+       }
+
+       int curr = selectedLV->model()->rowCount() - 1;
+       if (curr < 0)
+               return;
+
+       if (!selectedLV->selectionModel()->selectedIndexes().empty())
+               curr = selectedLV->selectionModel()->selectedIndexes()[0].row();
+
+       QStringList sty = form_->citationStyles(curr);
+
+       bool const basic_engine = 
+               (form_->getEngine() == biblio::ENGINE_BASIC);
+
+       citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
+       citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
+
+       if (sty.isEmpty() || basic_engine)
+               return;
+
+       citationStyleCO->insertItems(0, sty);
+
+       if (orig != -1 && orig < citationStyleCO->count())
+               citationStyleCO->setCurrentIndex(orig);
+}
+
+
+bool QCitationDialog::isSelected(const QModelIndex & idx)
+{
+       QString const str = idx.data().toString();
+       return !form_->selected()->stringList().filter(str).isEmpty();
+}
+
+
+void QCitationDialog::setButtons()
+{
+       int const arows = availableLV->model()->rowCount();
+       addPB->setEnabled(arows>0 && !isSelected(availableLV->currentIndex()));
+
+       int const srows = selectedLV->model()->rowCount();
+       int const sel_nr = selectedLV->currentIndex().row();
+       deletePB->setEnabled(sel_nr >= 0);
+       upPB->setEnabled(sel_nr > 0);
+       downPB->setEnabled(sel_nr >= 0 && sel_nr < srows - 1);
+       applyPB->setEnabled(srows>0);
+       okPB->setEnabled(srows>0);
+}
+
+
+void QCitationDialog::updateInfo(const QModelIndex & idx)
+{
+       if (idx.isValid()) {
+               QString const keytxt = form_->getKeyInfo(idx.data().toString());
+               infoML->document()->setPlainText(keytxt);
+       } else
+               infoML->document()->clear();
+}
+
+
+void QCitationDialog::on_selectedLV_clicked(const QModelIndex &)
+{
+       availableLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::selectedChanged(const QModelIndex & idx, const QModelIndex &)
+{
+       if (!idx.isValid())
+               return;
+
+       availableLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::on_availableLV_clicked(const QModelIndex &)
+{
+       selectedLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::availableChanged(const QModelIndex & idx, const QModelIndex &)
+{
+       if (!idx.isValid())
+               return;
+               
+       selectedLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::on_availableLV_activated(const QModelIndex & idx)
+{
+       if (isSelected(idx))
+               return;
+
+       selectedLV->selectionModel()->reset();
+       on_addPB_clicked();
+       if (selectedLV->model()->rowCount() == 1)
+               on_okPB_clicked();
+}
+
+
+void QCitationDialog::on_availableLV_entered(const QModelIndex &)
+{
+}
+
+
+void QCitationDialog::on_addPB_clicked()
+{
+       QModelIndex idx = selectedLV->currentIndex();
+       form_->addKey(availableLV->currentIndex());
+       if (idx.isValid())
+               selectedLV->setCurrentIndex(idx);
+       selectedLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::on_deletePB_clicked()
+{
+       QModelIndex idx = selectedLV->currentIndex();
+       int nrows = selectedLV->model()->rowCount();
+       
+       form_->deleteKey(idx);
+
+       if (idx.row() == nrows - 1)     
+               idx = idx.sibling(idx.row() - 1, idx.column());
+
+       if (nrows>1)
+               selectedLV->setCurrentIndex(idx);
+
+       availableLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::on_upPB_clicked()
+{
+       QModelIndex idx = selectedLV->currentIndex();
+       form_->upKey(idx);
+       selectedLV->setCurrentIndex(idx.sibling(idx.row() - 1, idx.column()));
+       availableLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::on_downPB_clicked()
+{
+       QModelIndex idx = selectedLV->currentIndex();
+       form_->downKey(idx);
+       selectedLV->setCurrentIndex(idx.sibling(idx.row() + 1, idx.column()));
+       availableLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::findText(QString const & text)
+{
+       bool const case_sentitive = caseCB->checkState();
+       bool const reg_exp = regexCB->checkState();
+       form_->findKey(text, false, case_sentitive, reg_exp);
+       selectedLV->selectionModel()->reset();
+       update();
+}
+
+
+void QCitationDialog::on_findLE_textChanged(const QString & text)
+{
+       clearPB->setDisabled(text.isEmpty());
+       if (text.isEmpty())
+               findLE->setFocus();
+       findText(text);
+}
+
+
+void QCitationDialog::on_caseCB_stateChanged(int)
+{
+       findText(findLE->text());
+}
+
+
+void QCitationDialog::on_regexCB_stateChanged(int)
+{
+       findText(findLE->text());
+}
+
+
+void QCitationDialog::changed()
+{
+       fillStyles();
+       setButtons();
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QCitationDialog_moc.cpp"
diff --git a/src/frontends/qt4/QCommandBuffer.C b/src/frontends/qt4/QCommandBuffer.C
deleted file mode 100644 (file)
index 5bc8c46..0000000
+++ /dev/null
@@ -1,238 +0,0 @@
-/**
- * \file QCommandBuffer.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-// Qt defines a macro 'signals' that clashes with a boost namespace.
-// All is well if the namespace is visible first.
-#include "GuiView.h"
-
-#include "QCommandBuffer.h"
-#include "QCommandEdit.h"
-#include "qt_helpers.h"
-
-#include "controllers/ControlCommandBuffer.h"
-
-#include "support/filetools.h"
-
-#include <QHBoxLayout>
-#include <QKeyEvent>
-#include <QLayout>
-#include <QListWidget>
-#include <QMouseEvent>
-#include <QPixmap>
-#include <QPushButton>
-#include <QToolTip>
-#include <QVBoxLayout>
-
-using lyx::support::libFileSearch;
-
-using std::vector;
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-namespace {
-
-class QTempListBox : public QListWidget {
-public:
-       QTempListBox() {
-               //setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-               setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-               setWindowModality(Qt::WindowModal);
-               setWindowFlags(Qt::Popup);
-               setAttribute(Qt::WA_DeleteOnClose);
-       }
-protected:
-       void mouseReleaseEvent(QMouseEvent * ev) {
-               if (ev->x() < 0 || ev->y() < 0
-                   || ev->x() > width() || ev->y() > height()) {
-                       hide();
-               } else {
-                       // emit signal
-                       itemPressed(currentItem());
-               }
-       }
-
-       void keyPressEvent(QKeyEvent * ev) {
-               if (ev->key() == Qt::Key_Escape) {
-                       hide();
-                       return;
-               }
-               QListWidget::keyPressEvent(ev);
-       }
-};
-
-} // end of anon
-
-
-QCommandBuffer::QCommandBuffer(GuiView * view, ControlCommandBuffer & control)
-       : view_(view), controller_(control)
-{
-       QPixmap qpup(toqstr(libFileSearch("images", "up", "xpm").absFilename()));
-       QPixmap qpdown(toqstr(libFileSearch("images", "down", "xpm").absFilename()));
-
-       QVBoxLayout * top = new QVBoxLayout(this);
-       QHBoxLayout * layout = new QHBoxLayout(0);
-
-       QPushButton * up = new QPushButton(qpup, "", this);
-       up->setMaximumSize(24, 24);
-       up->setToolTip(qt_("Previous command"));
-       connect(up, SIGNAL(clicked()), this, SLOT(up()));
-       QPushButton * down = new QPushButton(qpdown, "", this);
-       down->setToolTip(qt_("Next command"));
-       down->setMaximumSize(24, 24);
-       connect(down, SIGNAL(clicked()), this, SLOT(down()));
-
-       edit_ = new QCommandEdit(this);
-       edit_->setMinimumSize(edit_->sizeHint());
-       edit_->setFocusPolicy(Qt::ClickFocus);
-
-       connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
-       connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
-       connect(edit_, SIGNAL(tabPressed()), this, SLOT(complete()));
-       connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
-       connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
-
-       layout->addWidget(up, 0);
-       layout->addWidget(down, 0);
-       layout->addWidget(edit_, 10);
-       layout->setMargin(0);
-       top->addLayout(layout);
-       top->setMargin(0);
-}
-
-
-
-void QCommandBuffer::focus_command()
-{
-       edit_->setFocus();
-}
-
-
-void QCommandBuffer::cancel()
-{
-       view_->setFocus();
-       edit_->setText(QString());
-}
-
-
-void QCommandBuffer::dispatch()
-{
-       controller_.dispatch(fromqstr(edit_->text()));
-       view_->setFocus();
-       edit_->setText(QString());
-       edit_->clearFocus();
-}
-
-
-void QCommandBuffer::complete()
-{
-       string const input = fromqstr(edit_->text());
-       string new_input;
-       vector<string> comp = controller_.completions(input, new_input);
-
-       if (comp.empty() && new_input == input) {
-               // show_info_suffix(qt_("[no match]"), input);
-               return;
-       }
-
-       if (comp.empty()) {
-               edit_->setText(toqstr(new_input));
-       //      show_info_suffix(("[only completion]"), new_input + ' ');
-               return;
-       }
-
-       edit_->setText(toqstr(new_input));
-
-       QTempListBox * list = new QTempListBox;
-
-       // For some reason the scrollview's contents are larger
-       // than the number of actual items...
-       vector<string>::const_iterator cit = comp.begin();
-       vector<string>::const_iterator end = comp.end();
-       for (; cit != end; ++cit)
-               list->addItem(toqstr(*cit));
-
-       list->resize(list->sizeHint());
-       QPoint const pos = edit_->mapToGlobal(QPoint(0, 0));
-
-       int const y = std::max(0, pos.y() - list->height());
-
-       list->move(pos.x(), y);
-
-       connect(list, SIGNAL(itemPressed(QListWidgetItem *)),
-               this, SLOT(complete_selected(QListWidgetItem *)));
-       connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
-               this, SLOT(complete_selected(QListWidgetItem *)));
-
-       list->show();
-       list->setFocus();
-}
-
-
-void QCommandBuffer::complete_selected(QListWidgetItem * item)
-{
-       QWidget const * widget = static_cast<QWidget const *>(sender());
-       const_cast<QWidget *>(widget)->hide();
-       edit_->setText(item->text() + ' ');
-       edit_->setFocus();
-}
-
-
-void QCommandBuffer::up()
-{
-       string const input = fromqstr(edit_->text());
-       string const h = controller_.historyUp();
-
-       if (h.empty()) {
-       //      show_info_suffix(qt_("[Beginning of history]"), input);
-       } else {
-               edit_->setText(toqstr(h));
-       }
-}
-
-
-void QCommandBuffer::down()
-{
-       string const input = fromqstr(edit_->text());
-       string const h = controller_.historyDown();
-
-       if (h.empty()) {
-       //      show_info_suffix(qt_("[End of history]"), input);
-       } else {
-               edit_->setText(toqstr(h));
-       }
-}
-
-
-#if 0
-void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
-{
-       stored_input_ = input;
-       info_suffix_shown_ = true;
-       set_input(input + ' ' + suffix);
-       suffix_timer_->start();
-}
-
-
-void XMiniBuffer::suffix_timeout()
-{
-       info_suffix_shown_ = false;
-       set_input(stored_input_);
-}
-
-#endif
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QCommandBuffer_moc.cpp"
diff --git a/src/frontends/qt4/QCommandBuffer.cpp b/src/frontends/qt4/QCommandBuffer.cpp
new file mode 100644 (file)
index 0000000..5bc8c46
--- /dev/null
@@ -0,0 +1,238 @@
+/**
+ * \file QCommandBuffer.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+// Qt defines a macro 'signals' that clashes with a boost namespace.
+// All is well if the namespace is visible first.
+#include "GuiView.h"
+
+#include "QCommandBuffer.h"
+#include "QCommandEdit.h"
+#include "qt_helpers.h"
+
+#include "controllers/ControlCommandBuffer.h"
+
+#include "support/filetools.h"
+
+#include <QHBoxLayout>
+#include <QKeyEvent>
+#include <QLayout>
+#include <QListWidget>
+#include <QMouseEvent>
+#include <QPixmap>
+#include <QPushButton>
+#include <QToolTip>
+#include <QVBoxLayout>
+
+using lyx::support::libFileSearch;
+
+using std::vector;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+namespace {
+
+class QTempListBox : public QListWidget {
+public:
+       QTempListBox() {
+               //setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+               setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+               setWindowModality(Qt::WindowModal);
+               setWindowFlags(Qt::Popup);
+               setAttribute(Qt::WA_DeleteOnClose);
+       }
+protected:
+       void mouseReleaseEvent(QMouseEvent * ev) {
+               if (ev->x() < 0 || ev->y() < 0
+                   || ev->x() > width() || ev->y() > height()) {
+                       hide();
+               } else {
+                       // emit signal
+                       itemPressed(currentItem());
+               }
+       }
+
+       void keyPressEvent(QKeyEvent * ev) {
+               if (ev->key() == Qt::Key_Escape) {
+                       hide();
+                       return;
+               }
+               QListWidget::keyPressEvent(ev);
+       }
+};
+
+} // end of anon
+
+
+QCommandBuffer::QCommandBuffer(GuiView * view, ControlCommandBuffer & control)
+       : view_(view), controller_(control)
+{
+       QPixmap qpup(toqstr(libFileSearch("images", "up", "xpm").absFilename()));
+       QPixmap qpdown(toqstr(libFileSearch("images", "down", "xpm").absFilename()));
+
+       QVBoxLayout * top = new QVBoxLayout(this);
+       QHBoxLayout * layout = new QHBoxLayout(0);
+
+       QPushButton * up = new QPushButton(qpup, "", this);
+       up->setMaximumSize(24, 24);
+       up->setToolTip(qt_("Previous command"));
+       connect(up, SIGNAL(clicked()), this, SLOT(up()));
+       QPushButton * down = new QPushButton(qpdown, "", this);
+       down->setToolTip(qt_("Next command"));
+       down->setMaximumSize(24, 24);
+       connect(down, SIGNAL(clicked()), this, SLOT(down()));
+
+       edit_ = new QCommandEdit(this);
+       edit_->setMinimumSize(edit_->sizeHint());
+       edit_->setFocusPolicy(Qt::ClickFocus);
+
+       connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
+       connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
+       connect(edit_, SIGNAL(tabPressed()), this, SLOT(complete()));
+       connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
+       connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
+
+       layout->addWidget(up, 0);
+       layout->addWidget(down, 0);
+       layout->addWidget(edit_, 10);
+       layout->setMargin(0);
+       top->addLayout(layout);
+       top->setMargin(0);
+}
+
+
+
+void QCommandBuffer::focus_command()
+{
+       edit_->setFocus();
+}
+
+
+void QCommandBuffer::cancel()
+{
+       view_->setFocus();
+       edit_->setText(QString());
+}
+
+
+void QCommandBuffer::dispatch()
+{
+       controller_.dispatch(fromqstr(edit_->text()));
+       view_->setFocus();
+       edit_->setText(QString());
+       edit_->clearFocus();
+}
+
+
+void QCommandBuffer::complete()
+{
+       string const input = fromqstr(edit_->text());
+       string new_input;
+       vector<string> comp = controller_.completions(input, new_input);
+
+       if (comp.empty() && new_input == input) {
+               // show_info_suffix(qt_("[no match]"), input);
+               return;
+       }
+
+       if (comp.empty()) {
+               edit_->setText(toqstr(new_input));
+       //      show_info_suffix(("[only completion]"), new_input + ' ');
+               return;
+       }
+
+       edit_->setText(toqstr(new_input));
+
+       QTempListBox * list = new QTempListBox;
+
+       // For some reason the scrollview's contents are larger
+       // than the number of actual items...
+       vector<string>::const_iterator cit = comp.begin();
+       vector<string>::const_iterator end = comp.end();
+       for (; cit != end; ++cit)
+               list->addItem(toqstr(*cit));
+
+       list->resize(list->sizeHint());
+       QPoint const pos = edit_->mapToGlobal(QPoint(0, 0));
+
+       int const y = std::max(0, pos.y() - list->height());
+
+       list->move(pos.x(), y);
+
+       connect(list, SIGNAL(itemPressed(QListWidgetItem *)),
+               this, SLOT(complete_selected(QListWidgetItem *)));
+       connect(list, SIGNAL(itemActivated(QListWidgetItem *)),
+               this, SLOT(complete_selected(QListWidgetItem *)));
+
+       list->show();
+       list->setFocus();
+}
+
+
+void QCommandBuffer::complete_selected(QListWidgetItem * item)
+{
+       QWidget const * widget = static_cast<QWidget const *>(sender());
+       const_cast<QWidget *>(widget)->hide();
+       edit_->setText(item->text() + ' ');
+       edit_->setFocus();
+}
+
+
+void QCommandBuffer::up()
+{
+       string const input = fromqstr(edit_->text());
+       string const h = controller_.historyUp();
+
+       if (h.empty()) {
+       //      show_info_suffix(qt_("[Beginning of history]"), input);
+       } else {
+               edit_->setText(toqstr(h));
+       }
+}
+
+
+void QCommandBuffer::down()
+{
+       string const input = fromqstr(edit_->text());
+       string const h = controller_.historyDown();
+
+       if (h.empty()) {
+       //      show_info_suffix(qt_("[End of history]"), input);
+       } else {
+               edit_->setText(toqstr(h));
+       }
+}
+
+
+#if 0
+void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
+{
+       stored_input_ = input;
+       info_suffix_shown_ = true;
+       set_input(input + ' ' + suffix);
+       suffix_timer_->start();
+}
+
+
+void XMiniBuffer::suffix_timeout()
+{
+       info_suffix_shown_ = false;
+       set_input(stored_input_);
+}
+
+#endif
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QCommandBuffer_moc.cpp"
diff --git a/src/frontends/qt4/QCommandEdit.C b/src/frontends/qt4/QCommandEdit.C
deleted file mode 100644 (file)
index 3cd2c32..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * \file QCommandEdit.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QCommandEdit.h"
-
-#include <QKeyEvent>
-#include <QEvent>
-
-namespace lyx {
-namespace frontend {
-
-QCommandEdit::QCommandEdit(QWidget * parent)
-       : QLineEdit(parent)
-{
-       setFocusPolicy(Qt::ClickFocus);
-}
-
-
-void QCommandEdit::keyPressEvent(QKeyEvent * e)
-{
-       switch (e->key()) {
-       case Qt::Key_Escape:
-               // emit signal
-               escapePressed();
-               break;
-
-       case Qt::Key_Up:
-               // emit signal
-               upPressed();
-               break;
-
-       case Qt::Key_Down:
-               // emit signal
-               downPressed();
-               break;
-
-       default:
-               QLineEdit::keyPressEvent(e);
-               break;
-       }
-}
-
-
-bool QCommandEdit::event(QEvent * e)
-{
-       if (e->type() != QEvent::KeyPress)
-               return QLineEdit::event(e);
-
-       QKeyEvent * ev = (QKeyEvent *)e;
-
-       if (ev->key() != Qt::Key_Tab)
-               return QLineEdit::event(e);
-
-       // emit signal
-       tabPressed();
-       return true;
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QCommandEdit_moc.cpp"
diff --git a/src/frontends/qt4/QCommandEdit.cpp b/src/frontends/qt4/QCommandEdit.cpp
new file mode 100644 (file)
index 0000000..3cd2c32
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ * \file QCommandEdit.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QCommandEdit.h"
+
+#include <QKeyEvent>
+#include <QEvent>
+
+namespace lyx {
+namespace frontend {
+
+QCommandEdit::QCommandEdit(QWidget * parent)
+       : QLineEdit(parent)
+{
+       setFocusPolicy(Qt::ClickFocus);
+}
+
+
+void QCommandEdit::keyPressEvent(QKeyEvent * e)
+{
+       switch (e->key()) {
+       case Qt::Key_Escape:
+               // emit signal
+               escapePressed();
+               break;
+
+       case Qt::Key_Up:
+               // emit signal
+               upPressed();
+               break;
+
+       case Qt::Key_Down:
+               // emit signal
+               downPressed();
+               break;
+
+       default:
+               QLineEdit::keyPressEvent(e);
+               break;
+       }
+}
+
+
+bool QCommandEdit::event(QEvent * e)
+{
+       if (e->type() != QEvent::KeyPress)
+               return QLineEdit::event(e);
+
+       QKeyEvent * ev = (QKeyEvent *)e;
+
+       if (ev->key() != Qt::Key_Tab)
+               return QLineEdit::event(e);
+
+       // emit signal
+       tabPressed();
+       return true;
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QCommandEdit_moc.cpp"
diff --git a/src/frontends/qt4/QDelimiterDialog.C b/src/frontends/qt4/QDelimiterDialog.C
deleted file mode 100644 (file)
index e0d254a..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-/**
- * \file QDelimiterDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QDelimiterDialog.h"
-
-#include "GuiApplication.h"
-#include "GuiView.h"
-
-
-#include "qt_helpers.h"
-#include "controllers/ControlMath.h"
-
-#include "gettext.h"
-
-#include <QPixmap>
-#include <QCheckBox>
-#include <QListWidgetItem>
-
-#include <sstream>
-
-// Set to zero if unicode symbols are preferred.
-#define USE_PIXMAP 1
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-namespace {
-
-QString const bigleft[]  = {"", "bigl", "Bigl", "biggl", "Biggl"};
-
-
-QString const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"};
-
-
-char const * const biggui[]   = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"),
-       N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
-
-
-// FIXME: It might be better to fix the big delim LFUN to not require
-// additional '\' prefix.
-QString fix_name(QString const & str, bool big)
-{
-       if (str.isEmpty())
-               return ".";
-       if (!big || str == "(" || str == ")" || str == "[" || str == "]"
-           || str == "|" || str == "/")
-               return str;
-
-       return "\\" + str;
-}
-
-} // namespace anon
-
-
-typedef QController<ControlMath, QView<QDelimiterDialog> > delimiter_base;
-
-QMathDelimiter::QMathDelimiter(Dialog & parent)
-       : delimiter_base(parent, _("Math Delimiter"))
-{}
-
-
-void QMathDelimiter::build_dialog()
-{
-       dialog_.reset(new QDelimiterDialog(this,
-               static_cast<GuiView *>(controller().view())));
-}
-
-
-char_type QDelimiterDialog::doMatch(char_type const symbol) const
-{
-       string const & str = form_->controller().texName(symbol);
-       string match;
-       if (str == "(") match = ")";
-       else if (str == ")") match = "(";
-       else if (str == "[") match = "]";
-       else if (str == "]") match = "[";
-       else if (str == "{") match = "}";
-       else if (str == "}") match = "{";
-       else if (str == "l") match = "r";
-       else if (str == "rceil") match = "lceil";
-       else if (str == "lceil") match = "rceil";
-       else if (str == "rfloor") match = "lfloor";
-       else if (str == "lfloor") match = "rfloor";
-       else if (str == "rangle") match = "langle";
-       else if (str == "langle") match = "rangle";
-       else if (str == "backslash") match = "/";
-       else if (str == "/") match = "backslash";
-       else return symbol;
-
-       return form_->controller().mathSymbol(match).unicode;
-}
-
-
-QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form, QWidget * parent)
-       : QDialog(parent), form_(form)
-{
-       setupUi(this);
-
-       connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
-
-       setWindowTitle(qt_("LyX: Delimiters"));
-       setFocusProxy(leftLW);
-
-       leftLW->setViewMode(QListView::IconMode);
-       rightLW->setViewMode(QListView::IconMode);
-       
-       typedef std::map<char_type, QListWidgetItem *> ListItems;
-       ListItems list_items;
-       // The last element is the empty one.
-       int const end = nr_latex_delimiters - 1;
-       for (int i = 0; i < end; ++i) {
-               string const delim = latex_delimiters[i];
-               MathSymbol const & ms = form_->controller().mathSymbol(delim);
-               QString symbol(ms.fontcode?
-                       QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
-               QListWidgetItem * lwi = new QListWidgetItem(symbol);
-               lwi->setToolTip(toqstr(delim));
-               LyXFont lyxfont;
-               lyxfont.setFamily(ms.fontfamily);
-               QFont const & symbol_font = guiApp->guiFontLoader().get(lyxfont);
-               lwi->setFont(symbol_font);
-               list_items[ms.unicode] = lwi;
-               leftLW->addItem(lwi);
-       }
-
-       for (int i = 0; i != leftLW->count(); ++i) {
-               MathSymbol const & ms = form_->controller().mathSymbol(
-                       fromqstr(leftLW->item(i)->toolTip()));
-               rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
-       }
-
-       // The last element is the empty one.
-       leftLW->addItem(qt_("(None)"));
-       rightLW->addItem(qt_("(None)"));
-
-       sizeCO->addItem(qt_("Variable"));
-
-       for (int i = 0; *biggui[i]; ++i)
-               sizeCO->addItem(qt_(biggui[i]));
-
-       on_leftLW_currentRowChanged(0);
-}
-
-
-void QDelimiterDialog::updateTeXCode(int size)
-{
-       bool const bigsize = size != 0;
-
-       QString left_str = fix_name(leftLW->currentItem()->toolTip(), bigsize);
-       QString right_str = fix_name(rightLW->currentItem()->toolTip(), bigsize);
-
-       if (!bigsize)
-               tex_code_ = left_str + ' ' + right_str;
-       else {
-               tex_code_ = bigleft[size] + ' '
-                       + left_str + ' ' 
-                       + bigright[size] + ' '
-                       + right_str;
-       }
-
-       // Generate TeX-code for GUI display.
-       // FIXME: Instead of reconstructing the TeX code it would be nice to
-       // FIXME: retrieve the LateX code directly from mathed.
-       // In all cases, we want the '\' prefix if needed, so we pass 'true'
-       // to fix_name.
-       left_str = fix_name(leftLW->currentItem()->toolTip(), true);
-       right_str = fix_name(rightLW->currentItem()->toolTip(), true);
-       QString code_str;
-       if (!bigsize)
-               code_str = "\\left" + left_str + " \\right" + right_str;
-       else {
-               // There should be nothing in the TeX-code when the delimiter is "None".
-               if (left_str != ".")
-                       code_str = "\\" + bigleft[size] + left_str + ' ';
-               if (right_str != ".")
-                       code_str += "\\" + bigright[size] + right_str;
-       }
-
-       texCodeL->setText(qt_("TeX Code: ") + code_str);
-}
-
-
-void QDelimiterDialog::on_insertPB_clicked()
-{
-       if (sizeCO->currentIndex() == 0)
-               form_->controller().dispatchDelim(fromqstr(tex_code_));
-       else {
-               QString command = '"' + tex_code_ + '"';
-               command.replace(' ', "\" \"");
-               form_->controller().dispatchBigDelim(fromqstr(command));
-       }
- }
-
-void QDelimiterDialog::on_sizeCO_activated(int index)
-{
-       updateTeXCode(index);
-}
-
-
-void QDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
-{
-       on_insertPB_clicked();
-       accept();
-}
-
-
-void QDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *)
-{
-       on_insertPB_clicked();
-       accept();
-}
-
-
-void QDelimiterDialog::on_leftLW_currentRowChanged(int item)
-{
-       if (matchCB->isChecked())
-               rightLW->setCurrentRow(item);
-
-       updateTeXCode(sizeCO->currentIndex());
-}
-
-
-void QDelimiterDialog::on_rightLW_currentRowChanged(int item)
-{
-       if (matchCB->isChecked())
-               leftLW->setCurrentRow(item);
-
-       updateTeXCode(sizeCO->currentIndex());
-}
-
-
-void QDelimiterDialog::on_matchCB_stateChanged(int state)
-{
-       if (state == Qt::Checked)
-               on_leftLW_currentRowChanged(leftLW->currentRow());
-
-       updateTeXCode(sizeCO->currentIndex());
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QDelimiterDialog_moc.cpp"
diff --git a/src/frontends/qt4/QDelimiterDialog.cpp b/src/frontends/qt4/QDelimiterDialog.cpp
new file mode 100644 (file)
index 0000000..e0d254a
--- /dev/null
@@ -0,0 +1,256 @@
+/**
+ * \file QDelimiterDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QDelimiterDialog.h"
+
+#include "GuiApplication.h"
+#include "GuiView.h"
+
+
+#include "qt_helpers.h"
+#include "controllers/ControlMath.h"
+
+#include "gettext.h"
+
+#include <QPixmap>
+#include <QCheckBox>
+#include <QListWidgetItem>
+
+#include <sstream>
+
+// Set to zero if unicode symbols are preferred.
+#define USE_PIXMAP 1
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+namespace {
+
+QString const bigleft[]  = {"", "bigl", "Bigl", "biggl", "Biggl"};
+
+
+QString const bigright[] = {"", "bigr", "Bigr", "biggr", "Biggr"};
+
+
+char const * const biggui[]   = {N_("big[[delimiter size]]"), N_("Big[[delimiter size]]"),
+       N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
+
+
+// FIXME: It might be better to fix the big delim LFUN to not require
+// additional '\' prefix.
+QString fix_name(QString const & str, bool big)
+{
+       if (str.isEmpty())
+               return ".";
+       if (!big || str == "(" || str == ")" || str == "[" || str == "]"
+           || str == "|" || str == "/")
+               return str;
+
+       return "\\" + str;
+}
+
+} // namespace anon
+
+
+typedef QController<ControlMath, QView<QDelimiterDialog> > delimiter_base;
+
+QMathDelimiter::QMathDelimiter(Dialog & parent)
+       : delimiter_base(parent, _("Math Delimiter"))
+{}
+
+
+void QMathDelimiter::build_dialog()
+{
+       dialog_.reset(new QDelimiterDialog(this,
+               static_cast<GuiView *>(controller().view())));
+}
+
+
+char_type QDelimiterDialog::doMatch(char_type const symbol) const
+{
+       string const & str = form_->controller().texName(symbol);
+       string match;
+       if (str == "(") match = ")";
+       else if (str == ")") match = "(";
+       else if (str == "[") match = "]";
+       else if (str == "]") match = "[";
+       else if (str == "{") match = "}";
+       else if (str == "}") match = "{";
+       else if (str == "l") match = "r";
+       else if (str == "rceil") match = "lceil";
+       else if (str == "lceil") match = "rceil";
+       else if (str == "rfloor") match = "lfloor";
+       else if (str == "lfloor") match = "rfloor";
+       else if (str == "rangle") match = "langle";
+       else if (str == "langle") match = "rangle";
+       else if (str == "backslash") match = "/";
+       else if (str == "/") match = "backslash";
+       else return symbol;
+
+       return form_->controller().mathSymbol(match).unicode;
+}
+
+
+QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form, QWidget * parent)
+       : QDialog(parent), form_(form)
+{
+       setupUi(this);
+
+       connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
+
+       setWindowTitle(qt_("LyX: Delimiters"));
+       setFocusProxy(leftLW);
+
+       leftLW->setViewMode(QListView::IconMode);
+       rightLW->setViewMode(QListView::IconMode);
+       
+       typedef std::map<char_type, QListWidgetItem *> ListItems;
+       ListItems list_items;
+       // The last element is the empty one.
+       int const end = nr_latex_delimiters - 1;
+       for (int i = 0; i < end; ++i) {
+               string const delim = latex_delimiters[i];
+               MathSymbol const & ms = form_->controller().mathSymbol(delim);
+               QString symbol(ms.fontcode?
+                       QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
+               QListWidgetItem * lwi = new QListWidgetItem(symbol);
+               lwi->setToolTip(toqstr(delim));
+               LyXFont lyxfont;
+               lyxfont.setFamily(ms.fontfamily);
+               QFont const & symbol_font = guiApp->guiFontLoader().get(lyxfont);
+               lwi->setFont(symbol_font);
+               list_items[ms.unicode] = lwi;
+               leftLW->addItem(lwi);
+       }
+
+       for (int i = 0; i != leftLW->count(); ++i) {
+               MathSymbol const & ms = form_->controller().mathSymbol(
+                       fromqstr(leftLW->item(i)->toolTip()));
+               rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
+       }
+
+       // The last element is the empty one.
+       leftLW->addItem(qt_("(None)"));
+       rightLW->addItem(qt_("(None)"));
+
+       sizeCO->addItem(qt_("Variable"));
+
+       for (int i = 0; *biggui[i]; ++i)
+               sizeCO->addItem(qt_(biggui[i]));
+
+       on_leftLW_currentRowChanged(0);
+}
+
+
+void QDelimiterDialog::updateTeXCode(int size)
+{
+       bool const bigsize = size != 0;
+
+       QString left_str = fix_name(leftLW->currentItem()->toolTip(), bigsize);
+       QString right_str = fix_name(rightLW->currentItem()->toolTip(), bigsize);
+
+       if (!bigsize)
+               tex_code_ = left_str + ' ' + right_str;
+       else {
+               tex_code_ = bigleft[size] + ' '
+                       + left_str + ' ' 
+                       + bigright[size] + ' '
+                       + right_str;
+       }
+
+       // Generate TeX-code for GUI display.
+       // FIXME: Instead of reconstructing the TeX code it would be nice to
+       // FIXME: retrieve the LateX code directly from mathed.
+       // In all cases, we want the '\' prefix if needed, so we pass 'true'
+       // to fix_name.
+       left_str = fix_name(leftLW->currentItem()->toolTip(), true);
+       right_str = fix_name(rightLW->currentItem()->toolTip(), true);
+       QString code_str;
+       if (!bigsize)
+               code_str = "\\left" + left_str + " \\right" + right_str;
+       else {
+               // There should be nothing in the TeX-code when the delimiter is "None".
+               if (left_str != ".")
+                       code_str = "\\" + bigleft[size] + left_str + ' ';
+               if (right_str != ".")
+                       code_str += "\\" + bigright[size] + right_str;
+       }
+
+       texCodeL->setText(qt_("TeX Code: ") + code_str);
+}
+
+
+void QDelimiterDialog::on_insertPB_clicked()
+{
+       if (sizeCO->currentIndex() == 0)
+               form_->controller().dispatchDelim(fromqstr(tex_code_));
+       else {
+               QString command = '"' + tex_code_ + '"';
+               command.replace(' ', "\" \"");
+               form_->controller().dispatchBigDelim(fromqstr(command));
+       }
+ }
+
+void QDelimiterDialog::on_sizeCO_activated(int index)
+{
+       updateTeXCode(index);
+}
+
+
+void QDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
+{
+       on_insertPB_clicked();
+       accept();
+}
+
+
+void QDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *)
+{
+       on_insertPB_clicked();
+       accept();
+}
+
+
+void QDelimiterDialog::on_leftLW_currentRowChanged(int item)
+{
+       if (matchCB->isChecked())
+               rightLW->setCurrentRow(item);
+
+       updateTeXCode(sizeCO->currentIndex());
+}
+
+
+void QDelimiterDialog::on_rightLW_currentRowChanged(int item)
+{
+       if (matchCB->isChecked())
+               leftLW->setCurrentRow(item);
+
+       updateTeXCode(sizeCO->currentIndex());
+}
+
+
+void QDelimiterDialog::on_matchCB_stateChanged(int state)
+{
+       if (state == Qt::Checked)
+               on_leftLW_currentRowChanged(leftLW->currentRow());
+
+       updateTeXCode(sizeCO->currentIndex());
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QDelimiterDialog_moc.cpp"
diff --git a/src/frontends/qt4/QDialogView.C b/src/frontends/qt4/QDialogView.C
deleted file mode 100644 (file)
index 57cd673..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * \file QDialogView.cpp
- * 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 "QDialogView.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ButtonController.h"
-
-
-namespace lyx {
-namespace frontend {
-
-QDialogView::QDialogView(Dialog & parent, docstring const & t)
-       : Dialog::View(parent,t), updating_(false)
-{}
-
-
-Qt2BC & QDialogView::bcview()
-{
-       return static_cast<Qt2BC &>(dialog().bc().view());
-}
-
-
-bool QDialogView::isVisible() const
-{
-       return form() && form()->isVisible();
-}
-
-
-bool QDialogView::readOnly() const
-{
-       return kernel().isBufferReadonly();
-}
-
-
-void QDialogView::show()
-{
-       if (!form()) {
-               build();
-       }
-
-       QSize const sizeHint = form()->sizeHint();
-       if (sizeHint.height() >= 0 && sizeHint.width() >= 0)
-               form()->setMinimumSize(sizeHint);
-
-       update();  // make sure its up-to-date
-       if (dialog().controller().exitEarly())
-               return;
-
-       form()->setWindowTitle(toqstr("LyX: " + getTitle()));
-
-       if (form()->isVisible()) {
-               form()->raise();
-               form()->activateWindow();
-               form()->setFocus();
-       } else {
-               form()->show();
-               form()->setFocus();
-       }
-}
-
-
-void QDialogView::hide()
-{
-       if (form() && form()->isVisible())
-               form()->hide();
-}
-
-
-bool QDialogView::isValid()
-{
-       return true;
-}
-
-
-void QDialogView::changed()
-{
-       if (updating_)
-               return;
-       bc().valid(isValid());
-}
-
-
-void QDialogView::slotWMHide()
-{
-       dialog().CancelButton();
-}
-
-
-void QDialogView::slotApply()
-{
-       dialog().ApplyButton();
-}
-
-
-void QDialogView::slotOK()
-{
-       dialog().OKButton();
-}
-
-
-void QDialogView::slotClose()
-{
-       dialog().CancelButton();
-}
-
-
-void QDialogView::slotRestore()
-{
-       dialog().RestoreButton();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QDialogView_moc.cpp"
diff --git a/src/frontends/qt4/QDialogView.cpp b/src/frontends/qt4/QDialogView.cpp
new file mode 100644 (file)
index 0000000..57cd673
--- /dev/null
@@ -0,0 +1,126 @@
+/**
+ * \file QDialogView.cpp
+ * 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 "QDialogView.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ButtonController.h"
+
+
+namespace lyx {
+namespace frontend {
+
+QDialogView::QDialogView(Dialog & parent, docstring const & t)
+       : Dialog::View(parent,t), updating_(false)
+{}
+
+
+Qt2BC & QDialogView::bcview()
+{
+       return static_cast<Qt2BC &>(dialog().bc().view());
+}
+
+
+bool QDialogView::isVisible() const
+{
+       return form() && form()->isVisible();
+}
+
+
+bool QDialogView::readOnly() const
+{
+       return kernel().isBufferReadonly();
+}
+
+
+void QDialogView::show()
+{
+       if (!form()) {
+               build();
+       }
+
+       QSize const sizeHint = form()->sizeHint();
+       if (sizeHint.height() >= 0 && sizeHint.width() >= 0)
+               form()->setMinimumSize(sizeHint);
+
+       update();  // make sure its up-to-date
+       if (dialog().controller().exitEarly())
+               return;
+
+       form()->setWindowTitle(toqstr("LyX: " + getTitle()));
+
+       if (form()->isVisible()) {
+               form()->raise();
+               form()->activateWindow();
+               form()->setFocus();
+       } else {
+               form()->show();
+               form()->setFocus();
+       }
+}
+
+
+void QDialogView::hide()
+{
+       if (form() && form()->isVisible())
+               form()->hide();
+}
+
+
+bool QDialogView::isValid()
+{
+       return true;
+}
+
+
+void QDialogView::changed()
+{
+       if (updating_)
+               return;
+       bc().valid(isValid());
+}
+
+
+void QDialogView::slotWMHide()
+{
+       dialog().CancelButton();
+}
+
+
+void QDialogView::slotApply()
+{
+       dialog().ApplyButton();
+}
+
+
+void QDialogView::slotOK()
+{
+       dialog().OKButton();
+}
+
+
+void QDialogView::slotClose()
+{
+       dialog().CancelButton();
+}
+
+
+void QDialogView::slotRestore()
+{
+       dialog().RestoreButton();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QDialogView_moc.cpp"
diff --git a/src/frontends/qt4/QDocument.C b/src/frontends/qt4/QDocument.C
deleted file mode 100644 (file)
index 6ef51d7..0000000
+++ /dev/null
@@ -1,1292 +0,0 @@
-/**
- * \file QDocument.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QDocument.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-#include "QBranches.h"
-
-#include <QCloseEvent>
-
-#include "FloatPlacement.h"
-#include "LengthCombo.h"
-#include "Validator.h"
-#include "PanelStack.h"
-#include "Qt2BC.h"
-#include "CheckedLineEdit.h"
-
-// For latexHighlighter use in the preamble.
-#include "QViewSource.h"
-
-#include "bufferparams.h"
-#include "encoding.h"
-#include "gettext.h"
-#include "frontend_helpers.h" // getSecond()
-#include "language.h"
-#include "lyxrc.h" // defaultUnit
-#include "lyxtextclasslist.h"
-#include "tex-strings.h" // tex_graphics
-#include "Spacing.h"
-
-#include "controllers/ControlDocument.h"
-
-#include "support/lstrings.h"
-
-#include "controllers/ControlDocument.h"
-
-
-using lyx::support::token;
-using lyx::support::bformat;
-using lyx::support::findToken;
-using lyx::support::getVectorFromString;
-
-using std::distance;
-using std::vector;
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// DocumentDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QDocumentDialog::QDocumentDialog(QDocument * form)
-       : form_(form),
-       lang_(getSecond(getLanguageData(false)))
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
-
-       connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
-       connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
-
-       // Manage the restore, ok, apply, restore and cancel/close buttons
-       form_->bcview().setOK(okPB);
-       form_->bcview().setApply(applyPB);
-       form_->bcview().setCancel(closePB);
-       form_->bcview().setRestore(restorePB);
-
-
-       textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
-       // text layout
-       connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
-               this, SLOT(setLSpacing(int)));
-       connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->skipRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->indentRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
-               this, SLOT(setSkip(int)));
-       connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
-               this, SLOT(enableSkip(bool)));
-       connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
-               textLayoutModule->lspacingLE));
-       textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
-               textLayoutModule->skipLE));
-
-       textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
-       textLayoutModule->skipCO->addItem(qt_("MedSkip"));
-       textLayoutModule->skipCO->addItem(qt_("BigSkip"));
-       textLayoutModule->skipCO->addItem(qt_("Length"));
-       // remove the %-items from the unit choice
-       textLayoutModule->skipLengthCO->noPercents();
-       textLayoutModule->lspacingCO->insertItem(
-               Spacing::Single, qt_("Single"));
-       textLayoutModule->lspacingCO->insertItem(
-               Spacing::Onehalf, qt_("OneHalf"));
-       textLayoutModule->lspacingCO->insertItem(
-               Spacing::Double, qt_("Double"));
-       textLayoutModule->lspacingCO->insertItem(
-               Spacing::Other, qt_("Custom"));
-
-       // initialize the length validator
-       addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
-
-       fontModule = new UiWidget<Ui::FontUi>;
-       // fonts
-       connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
-               this, SLOT(romanChanged(int)));
-       connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
-               this, SLOT(sansChanged(int)));
-       connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
-               this, SLOT(ttChanged(int)));
-       connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->fontScCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->fontOsfCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-
-       for (int n = 0; tex_fonts_roman[n][0]; ++n) {
-               QString font = toqstr(tex_fonts_roman_gui[n]);
-               if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
-                       font += qt_(" (not installed)");
-               fontModule->fontsRomanCO->addItem(font);
-       }
-       for (int n = 0; tex_fonts_sans[n][0]; ++n) {
-               QString font = toqstr(tex_fonts_sans_gui[n]);
-               if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
-                       font += qt_(" (not installed)");
-               fontModule->fontsSansCO->addItem(font);
-       }
-       for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
-               QString font = toqstr(tex_fonts_monospaced_gui[n]);
-               if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
-                       font += qt_(" (not installed)");
-               fontModule->fontsTypewriterCO->addItem(font);
-       }
-
-       fontModule->fontsizeCO->addItem(qt_("default"));
-       fontModule->fontsizeCO->addItem(qt_("10"));
-       fontModule->fontsizeCO->addItem(qt_("11"));
-       fontModule->fontsizeCO->addItem(qt_("12"));
-
-       for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
-               fontModule->fontsDefaultCO->addItem(
-                       qt_(ControlDocument::fontfamilies_gui[n]));
-
-
-       pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
-       // page layout
-       connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
-               this, SLOT(setCustomPapersize(int)));
-       connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
-               this, SLOT(setCustomPapersize(int)));
-       connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
-               this, SLOT(portraitChanged()));
-       connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-
-       pageLayoutModule->pagestyleCO->addItem(qt_("default"));
-       pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
-       pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
-       pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
-       pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
-       addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
-               pageLayoutModule->paperheightL);
-       addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
-               pageLayoutModule->paperwidthL);
-
-       // paper
-       QComboBox * cb = pageLayoutModule->papersizeCO;
-       cb->addItem(qt_("Default"));
-       cb->addItem(qt_("Custom"));
-       cb->addItem(qt_("US letter"));
-       cb->addItem(qt_("US legal"));
-       cb->addItem(qt_("US executive"));
-       cb->addItem(qt_("A3"));
-       cb->addItem(qt_("A4"));
-       cb->addItem(qt_("A5"));
-       cb->addItem(qt_("B3"));
-       cb->addItem(qt_("B4"));
-       cb->addItem(qt_("B5"));
-       // remove the %-items from the unit choice
-       pageLayoutModule->paperwidthUnitCO->noPercents();
-       pageLayoutModule->paperheightUnitCO->noPercents();
-       pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
-               pageLayoutModule->paperheightLE));
-       pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
-               pageLayoutModule->paperwidthLE));
-
-
-
-
-       marginsModule = new UiWidget<Ui::MarginsUi>;
-       // margins
-       connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
-               this, SLOT(setCustomMargins(bool)));
-       connect(marginsModule->marginCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->topUnit, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->innerUnit, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->outerUnit, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       marginsModule->topLE->setValidator(unsignedLengthValidator(
-               marginsModule->topLE));
-       marginsModule->bottomLE->setValidator(unsignedLengthValidator(
-               marginsModule->bottomLE));
-       marginsModule->innerLE->setValidator(unsignedLengthValidator(
-               marginsModule->innerLE));
-       marginsModule->outerLE->setValidator(unsignedLengthValidator(
-               marginsModule->outerLE));
-       marginsModule->headsepLE->setValidator(unsignedLengthValidator(
-               marginsModule->headsepLE));
-       marginsModule->headheightLE->setValidator(unsignedLengthValidator(
-               marginsModule->headheightLE));
-       marginsModule->footskipLE->setValidator(unsignedLengthValidator(
-               marginsModule->footskipLE));
-
-       addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
-               marginsModule->topL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
-               marginsModule->bottomL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
-               marginsModule->innerL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
-               marginsModule->outerL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
-               marginsModule->headsepL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
-               marginsModule->headheightL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
-               marginsModule->footskipL);
-
-
-       langModule = new UiWidget<Ui::LanguageUi>;
-       connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)),
-               langModule->encodingL, SLOT(setDisabled(bool)));
-       connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)),
-               langModule->encodingCO, SLOT(setDisabled(bool)));
-       // language & quote
-       connect(langModule->languageCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->defaultencodingCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(langModule->encodingCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       // language & quotes
-       vector<LanguagePair> const langs = getLanguageData(false);
-       vector<LanguagePair>::const_iterator lit  = langs.begin();
-       vector<LanguagePair>::const_iterator lend = langs.end();
-       for (; lit != lend; ++lit) {
-               langModule->languageCO->addItem(
-                       toqstr(lit->first));
-       }
-
-       // Always put the default encoding in the first position.
-       // It is special because the displayed text is translated.
-       langModule->encodingCO->addItem(qt_("LaTeX default"));
-       Encodings::const_iterator it = encodings.begin();
-       Encodings::const_iterator const end = encodings.end();
-       for (; it != end; ++it)
-               langModule->encodingCO->addItem(toqstr(it->latexName()));
-
-       langModule->quoteStyleCO->addItem(qt_("``text''"));
-       langModule->quoteStyleCO->addItem(qt_("''text''"));
-       langModule->quoteStyleCO->addItem(qt_(",,text``"));
-       langModule->quoteStyleCO->addItem(qt_(",,text''"));
-       langModule->quoteStyleCO->addItem(qt_("<<text>>"));
-       langModule->quoteStyleCO->addItem(qt_(">>text<<"));
-
-
-
-       numberingModule = new UiWidget<Ui::NumberingUi>;
-       // numbering
-       connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
-               this, SLOT(updateNumbering()));
-       connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
-               this, SLOT(updateNumbering()));
-       numberingModule->tocTW->setColumnCount(3);
-       numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
-       numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
-       numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
-
-
-       biblioModule = new UiWidget<Ui::BiblioUi>;
-       connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
-               biblioModule->citationStyleL, SLOT(setEnabled(bool)));
-       connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
-               biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
-       // biblio
-       connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       // biblio
-       biblioModule->citeStyleCO->addItem(qt_("Author-year"));
-       biblioModule->citeStyleCO->addItem(qt_("Numerical"));
-       biblioModule->citeStyleCO->setCurrentIndex(0);
-
-
-
-       mathsModule = new UiWidget<Ui::MathsUi>;
-       connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
-               mathsModule->amsCB, SLOT(setDisabled(bool)));
-       connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
-               mathsModule->esintCB, SLOT(setDisabled(bool)));
-       // maths
-       connect(mathsModule->amsCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->amsautoCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->esintCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(mathsModule->esintautoCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-
-       latexModule = new UiWidget<Ui::LaTeXUi>;
-       // latex class
-       connect(latexModule->classCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(latexModule->psdriverCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(latexModule->classCO, SIGNAL(activated(int)),
-               this, SLOT(classChanged()));
-       // packages
-       for (int n = 0; tex_graphics[n][0]; ++n) {
-               QString enc = tex_graphics[n];
-               latexModule->psdriverCO->addItem(enc);
-       }
-       // latex
-       for (LyXTextClassList::const_iterator cit = textclasslist.begin();
-            cit != textclasslist.end(); ++cit) {
-               if (cit->isTeXClassAvailable()) {
-                       latexModule->classCO->addItem(toqstr(cit->description()));
-               } else {
-                       docstring item =
-                               bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
-                       latexModule->classCO->addItem(toqstr(item));
-               }
-       }
-
-       // branches
-       branchesModule = new QBranches;
-       connect(branchesModule, SIGNAL(changed()),
-               this, SLOT(change_adaptor()));
-
-       // preamble
-       preambleModule = new UiWidget<Ui::PreambleUi>;
-       connect(preambleModule->preambleTE, SIGNAL(textChanged()),
-               this, SLOT(change_adaptor()));
-       // This is not a memory leak. The object will be destroyed
-       // with preambleModule.
-       (void) new LaTeXHighlighter(preambleModule->preambleTE->document());
-
-
-       // bullets
-       bulletsModule = new BulletsModule;
-       connect(bulletsModule, SIGNAL(changed()),
-               this, SLOT(change_adaptor()));
-
-
-       // float
-       floatModule = new FloatPlacement;
-       connect(floatModule, SIGNAL(changed()),
-               this, SLOT(change_adaptor()));
-
-       docPS->addPanel(latexModule, _("Document Class"));
-       docPS->addPanel(fontModule, _("Fonts"));
-       docPS->addPanel(textLayoutModule, _("Text Layout"));
-       docPS->addPanel(pageLayoutModule, _("Page Layout"));
-       docPS->addPanel(marginsModule, _("Page Margins"));
-       docPS->addPanel(langModule, _("Language"));
-       docPS->addPanel(numberingModule, _("Numbering & TOC"));
-       docPS->addPanel(biblioModule, _("Bibliography"));
-       docPS->addPanel(mathsModule, _("Math Options"));
-       docPS->addPanel(floatModule, _("Float Placement"));
-       docPS->addPanel(bulletsModule, _("Bullets"));
-       docPS->addPanel(branchesModule, _("Branches"));
-       docPS->addPanel(preambleModule, _("LaTeX Preamble"));
-       docPS->setCurrentPanel(_("Document Class"));
-// FIXME: hack to work around resizing bug in Qt >= 4.2
-// bug verified with Qt 4.2.{0-3} (JSpitzm)
-#if QT_VERSION >= 0x040200
-       docPS->updateGeometry();
-#endif
-}
-
-
-void QDocumentDialog::showPreamble()
-{
-       docPS->setCurrentPanel(_("LaTeX Preamble"));
-}
-
-
-void QDocumentDialog::saveDefaultClicked()
-{
-       form_->saveDocDefault();
-}
-
-
-void QDocumentDialog::useDefaultsClicked()
-{
-       form_->useClassDefaults();
-}
-
-
-void QDocumentDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QDocumentDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QDocumentDialog::setLSpacing(int item)
-{
-       textLayoutModule->lspacingLE->setEnabled(item == 3);
-}
-
-
-void QDocumentDialog::setSkip(int item)
-{
-       bool const enable = (item == 3);
-       textLayoutModule->skipLE->setEnabled(enable);
-       textLayoutModule->skipLengthCO->setEnabled(enable);
-}
-
-
-void QDocumentDialog::enableSkip(bool skip)
-{
-       textLayoutModule->skipCO->setEnabled(skip);
-       textLayoutModule->skipLE->setEnabled(skip);
-       textLayoutModule->skipLengthCO->setEnabled(skip);
-       if (skip)
-               setSkip(textLayoutModule->skipCO->currentIndex());
-}
-
-void QDocumentDialog::portraitChanged()
-{
-       setMargins(pageLayoutModule->papersizeCO->currentIndex());
-}
-
-void QDocumentDialog::setMargins(bool custom)
-{
-       marginsModule->marginCB->setChecked(custom);
-       setCustomMargins(custom);
-}
-
-
-void QDocumentDialog::setCustomPapersize(int papersize)
-{
-       bool const custom = (papersize == 1);
-
-       pageLayoutModule->paperwidthL->setEnabled(custom);
-       pageLayoutModule->paperwidthLE->setEnabled(custom);
-       pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
-       pageLayoutModule->paperheightL->setEnabled(custom);
-       pageLayoutModule->paperheightLE->setEnabled(custom);
-       pageLayoutModule->paperheightLE->setFocus();
-       pageLayoutModule->paperheightUnitCO->setEnabled(custom);
-}
-
-
-void QDocumentDialog::setCustomMargins(bool custom)
-{
-       marginsModule->topL->setEnabled(!custom);
-       marginsModule->topLE->setEnabled(!custom);
-       marginsModule->topUnit->setEnabled(!custom);
-
-       marginsModule->bottomL->setEnabled(!custom);
-       marginsModule->bottomLE->setEnabled(!custom);
-       marginsModule->bottomUnit->setEnabled(!custom);
-
-       marginsModule->innerL->setEnabled(!custom);
-       marginsModule->innerLE->setEnabled(!custom);
-       marginsModule->innerUnit->setEnabled(!custom);
-
-       marginsModule->outerL->setEnabled(!custom);
-       marginsModule->outerLE->setEnabled(!custom);
-       marginsModule->outerUnit->setEnabled(!custom);
-
-       marginsModule->headheightL->setEnabled(!custom);
-       marginsModule->headheightLE->setEnabled(!custom);
-       marginsModule->headheightUnit->setEnabled(!custom);
-
-       marginsModule->headsepL->setEnabled(!custom);
-       marginsModule->headsepLE->setEnabled(!custom);
-       marginsModule->headsepUnit->setEnabled(!custom);
-
-       marginsModule->footskipL->setEnabled(!custom);
-       marginsModule->footskipLE->setEnabled(!custom);
-       marginsModule->footskipUnit->setEnabled(!custom);
-}
-
-
-void QDocumentDialog::updateFontsize(string const & items, string const & sel)
-{
-       fontModule->fontsizeCO->clear();
-       fontModule->fontsizeCO->addItem(qt_("default"));
-
-       for (int n = 0; !token(items,'|',n).empty(); ++n)
-               fontModule->fontsizeCO->
-                       addItem(toqstr(token(items,'|',n)));
-
-       for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
-               if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
-                       fontModule->fontsizeCO->setCurrentIndex(n);
-                       break;
-               }
-       }
-}
-
-
-void QDocumentDialog::romanChanged(int item)
-{
-       string const font = tex_fonts_roman[item];
-       
-       fontModule->fontScCB->setEnabled(
-               form_->controller().providesSC(font));
-       fontModule->fontOsfCB->setEnabled(
-               form_->controller().providesOSF(font));
-}
-
-
-void QDocumentDialog::sansChanged(int item)
-{
-       string const font = tex_fonts_sans[item];
-       bool scaleable = form_->controller().providesScale(font);
-       fontModule->scaleSansSB->setEnabled(scaleable);
-       fontModule->scaleSansLA->setEnabled(scaleable);
-}
-
-
-void QDocumentDialog::ttChanged(int item)
-{
-       string const font = tex_fonts_monospaced[item];
-       bool scaleable = form_->controller().providesScale(font);
-       fontModule->scaleTypewriterSB->setEnabled(scaleable);
-       fontModule->scaleTypewriterLA->setEnabled(scaleable);
-}
-
-
-void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
-{
-       pageLayoutModule->pagestyleCO->clear();
-       pageLayoutModule->pagestyleCO->addItem("default");
-
-       for (int n=0; !token(items,'|',n).empty(); ++n)
-               pageLayoutModule->pagestyleCO->
-                       addItem(toqstr(token(items,'|',n)));
-
-       for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
-               if (fromqstr(pageLayoutModule->pagestyleCO->itemText(n))==sel) {
-                       pageLayoutModule->pagestyleCO->setCurrentIndex(n);
-                       break;
-               }
-       }
-}
-
-
-void QDocumentDialog::classChanged()
-{
-       ControlDocument & cntrl = form_->controller();
-       BufferParams & params = cntrl.params();
-
-       textclass_type const tc = latexModule->classCO->currentIndex();
-
-       if (form_->controller().loadTextclass(tc)) {
-               params.textclass = tc;
-               if (lyxrc.auto_reset_options)
-                       params.useClassDefaults();
-               form_->update_contents();
-       } else {
-               latexModule->classCO->setCurrentIndex(params.textclass);
-       }
-}
-
-
-void QDocumentDialog::updateNumbering()
-{
-       LyXTextClass const & tclass =
-               form_->controller().params().getLyXTextClass();
-
-       numberingModule->tocTW->setUpdatesEnabled(false);
-       numberingModule->tocTW->clear();
-
-       int const depth = numberingModule->depthSL->value();
-       int const toc = numberingModule->tocSL->value();
-       QString const no = qt_("No");
-       QString const yes = qt_("Yes");
-       LyXTextClass::const_iterator end = tclass.end();
-       LyXTextClass::const_iterator cit = tclass.begin();
-       QTreeWidgetItem * item = 0;
-       for ( ; cit != end ; ++cit) {
-               int const toclevel = (*cit)->toclevel;
-               if (toclevel != LyXLayout::NOT_IN_TOC 
-                   && (*cit)->labeltype == LABEL_COUNTER) {
-                       item = new QTreeWidgetItem(numberingModule->tocTW);
-                       item->setText(0, qt_((*cit)->name()));
-                       item->setText(1, (toclevel <= depth) ? yes : no);
-                       item->setText(2, (toclevel <= toc) ? yes : no);
-               }
-       }
-
-       numberingModule->tocTW->setUpdatesEnabled(true);
-       numberingModule->tocTW->update();
-}
-
-void QDocumentDialog::apply(BufferParams & params)
-{
-       // preamble
-       params.preamble =
-               fromqstr(preambleModule->preambleTE->document()->toPlainText());
-
-       // biblio
-       params.setCiteEngine(biblio::ENGINE_BASIC);
-
-       if (biblioModule->citeNatbibRB->isChecked()) {
-               bool const use_numerical_citations =
-                       biblioModule->citeStyleCO->currentIndex();
-               if (use_numerical_citations)
-                       params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
-               else
-                       params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
-
-       } else if (biblioModule->citeJurabibRB->isChecked())
-               params.setCiteEngine(biblio::ENGINE_JURABIB);
-
-       params.use_bibtopic =
-               biblioModule->bibtopicCB->isChecked();
-
-       // language & quotes
-       if (langModule->defaultencodingCB->isChecked()) {
-               params.inputenc = "auto";
-       } else {
-               int i = langModule->encodingCO->currentIndex();
-               if (i == 0)
-                       params.inputenc = "default";
-               else
-                       params.inputenc =
-                               fromqstr(langModule->encodingCO->currentText());
-       }
-
-       InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
-       switch (langModule->quoteStyleCO->currentIndex()) {
-       case 0:
-               lga = InsetQuotes::EnglishQ;
-               break;
-       case 1:
-               lga = InsetQuotes::SwedishQ;
-               break;
-       case 2:
-               lga = InsetQuotes::GermanQ;
-               break;
-       case 3:
-               lga = InsetQuotes::PolishQ;
-               break;
-       case 4:
-               lga = InsetQuotes::FrenchQ;
-               break;
-       case 5:
-               lga = InsetQuotes::DanishQ;
-               break;
-       }
-       params.quotes_language = lga;
-
-       int const pos = langModule->languageCO->currentIndex();
-       params.language = languages.getLanguage(lang_[pos]);
-
-       // numbering
-       if (params.getLyXTextClass().hasTocLevels()) {
-               params.tocdepth = numberingModule->tocSL->value();
-               params.secnumdepth = numberingModule->depthSL->value();
-       }
-
-       // bullets
-       params.user_defined_bullet(0) = bulletsModule->getBullet(0);
-       params.user_defined_bullet(1) = bulletsModule->getBullet(1);
-       params.user_defined_bullet(2) = bulletsModule->getBullet(2);
-       params.user_defined_bullet(3) = bulletsModule->getBullet(3);
-
-       // packages
-       params.graphicsDriver =
-               fromqstr(latexModule->psdriverCO->currentText());
-
-       if (mathsModule->amsautoCB->isChecked()) {
-               params.use_amsmath = BufferParams::package_auto;
-       } else {
-               if (mathsModule->amsCB->isChecked())
-                       params.use_amsmath = BufferParams::package_on;
-               else
-                       params.use_amsmath = BufferParams::package_off;
-       }
-
-       if (mathsModule->esintautoCB->isChecked())
-               params.use_esint = BufferParams::package_auto;
-       else {
-               if (mathsModule->esintCB->isChecked())
-                       params.use_esint = BufferParams::package_on;
-               else
-                       params.use_esint = BufferParams::package_off;
-       }
-
-       // text layout
-       params.textclass =
-               latexModule->classCO->currentIndex();
-
-       params.pagestyle =
-               fromqstr(pageLayoutModule->pagestyleCO->currentText());
-
-       switch (textLayoutModule->lspacingCO->currentIndex()) {
-       case 0:
-               params.spacing().set(Spacing::Single);
-               break;
-       case 1:
-               params.spacing().set(Spacing::Onehalf);
-               break;
-       case 2:
-               params.spacing().set(Spacing::Double);
-               break;
-       case 3:
-               params.spacing().set(Spacing::Other,
-                       fromqstr(textLayoutModule->lspacingLE->text()));
-               break;
-       }
-
-       if (textLayoutModule->twoColumnCB->isChecked())
-               params.columns = 2;
-       else
-               params.columns = 1;
-
-       if (textLayoutModule->indentRB->isChecked())
-               params.paragraph_separation = BufferParams::PARSEP_INDENT;
-       else
-               params.paragraph_separation = BufferParams::PARSEP_SKIP;
-
-       switch (textLayoutModule->skipCO->currentIndex()) {
-       case 0:
-               params.setDefSkip(VSpace(VSpace::SMALLSKIP));
-               break;
-       case 1:
-               params.setDefSkip(VSpace(VSpace::MEDSKIP));
-               break;
-       case 2:
-               params.setDefSkip(VSpace(VSpace::BIGSKIP));
-               break;
-       case 3:
-       {
-               VSpace vs = VSpace(
-                       widgetsToLength(textLayoutModule->skipLE,
-                               textLayoutModule->skipLengthCO)
-                       );
-               params.setDefSkip(vs);
-               break;
-       }
-       default:
-               // DocumentDefskipCB assures that this never happens
-               // so Assert then !!!  - jbl
-               params.setDefSkip(VSpace(VSpace::MEDSKIP));
-               break;
-       }
-
-       params.options =
-               fromqstr(latexModule->optionsLE->text());
-
-       params.float_placement = floatModule->get();
-
-       // fonts
-       params.fontsRoman =
-               tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
-
-       params.fontsSans =
-               tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
-
-       params.fontsTypewriter =
-               tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
-
-       params.fontsSansScale = fontModule->scaleSansSB->value();
-
-       params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
-
-       params.fontsSC = fontModule->fontScCB->isChecked();
-
-       params.fontsOSF = fontModule->fontOsfCB->isChecked();
-
-       params.fontsDefaultFamily = ControlDocument::fontfamilies[
-               fontModule->fontsDefaultCO->currentIndex()];
-
-       if (fontModule->fontsizeCO->currentIndex() == 0)
-               params.fontsize = "default";
-       else
-               params.fontsize =
-                       fromqstr(fontModule->fontsizeCO->currentText());
-
-       // paper
-       params.papersize = PAPER_SIZE(
-               pageLayoutModule->papersizeCO->currentIndex());
-
-       // custom, A3, B3 and B4 paper sizes need geometry
-       int psize = pageLayoutModule->papersizeCO->currentIndex();
-       bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
-
-       params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
-               pageLayoutModule->paperwidthUnitCO);
-
-       params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
-               pageLayoutModule->paperheightUnitCO);
-
-       if (pageLayoutModule->facingPagesCB->isChecked())
-               params.sides = LyXTextClass::TwoSides;
-       else
-               params.sides = LyXTextClass::OneSide;
-
-       if (pageLayoutModule->landscapeRB->isChecked())
-               params.orientation = ORIENTATION_LANDSCAPE;
-       else
-               params.orientation = ORIENTATION_PORTRAIT;
-
-       // margins
-       params.use_geometry =
-               (!marginsModule->marginCB->isChecked()
-               || geom_papersize);
-
-       Ui::MarginsUi const * m(marginsModule);
-
-       params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
-
-       params.topmargin = widgetsToLength(m->topLE, m->topUnit);
-
-       params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
-
-       params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
-
-       params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
-
-       params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
-
-       params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
-
-       branchesModule->apply(params);
-}
-
-namespace {
-
-/** Return the position of val in the vector if found.
-    If not found, return 0.
- */
-template<class A>
-typename std::vector<A>::size_type
-findPos(std::vector<A> const & vec, A const & val)
-{
-       typename std::vector<A>::const_iterator it =
-               std::find(vec.begin(), vec.end(), val);
-       if (it == vec.end())
-               return 0;
-       return distance(vec.begin(), it);
-}
-
-} // namespace anom
-
-
-void QDocumentDialog::updateParams(BufferParams const & params)
-{
-       // set the default unit
-       // FIXME: move to controller
-       LyXLength::UNIT defaultUnit = LyXLength::CM;
-       switch (lyxrc.default_papersize) {
-               case PAPER_DEFAULT: break;
-
-               case PAPER_USLETTER:
-               case PAPER_USLEGAL:
-               case PAPER_USEXECUTIVE:
-                       defaultUnit = LyXLength::IN;
-                       break;
-
-               case PAPER_A3:
-               case PAPER_A4:
-               case PAPER_A5:
-               case PAPER_B3:
-               case PAPER_B4:
-               case PAPER_B5:
-                       defaultUnit = LyXLength::CM;
-                       break;
-               case PAPER_CUSTOM:
-                       break;
-       }
-
-       // preamble
-       QString preamble = toqstr(params.preamble);
-       preambleModule->preambleTE->document()->setPlainText(preamble);
-
-       // biblio
-       biblioModule->citeDefaultRB->setChecked(
-               params.getEngine() == biblio::ENGINE_BASIC);
-
-       biblioModule->citeNatbibRB->setChecked(
-               params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
-               params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
-
-       biblioModule->citeStyleCO->setCurrentIndex(
-               params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
-
-       biblioModule->citeJurabibRB->setChecked(
-               params.getEngine() == biblio::ENGINE_JURABIB);
-
-       biblioModule->bibtopicCB->setChecked(
-               params.use_bibtopic);
-
-       // language & quotes
-       int const pos = int(findPos(lang_,
-                                   params.language->lang()));
-       langModule->languageCO->setCurrentIndex(pos);
-
-       langModule->quoteStyleCO->setCurrentIndex(
-               params.quotes_language);
-
-       langModule->defaultencodingCB->setChecked(true);
-
-       if (params.inputenc != "auto") {
-               langModule->defaultencodingCB->setChecked(false);
-               if (params.inputenc == "default") {
-                       langModule->encodingCO->setCurrentIndex(0);
-               } else {
-                       int const i = langModule->encodingCO->findText(
-                                       toqstr(params.inputenc));
-                       if (i >= 0)
-                               langModule->encodingCO->setCurrentIndex(i);
-                       else
-                               // unknown encoding. Set to default.
-                               langModule->defaultencodingCB->setChecked(true);
-               }
-       }
-
-       // numbering
-       int const min_toclevel = form_->controller().textClass().min_toclevel();
-       int const max_toclevel = form_->controller().textClass().max_toclevel();
-       if (form_->controller().textClass().hasTocLevels()) {
-               numberingModule->setEnabled(true);
-               numberingModule->depthSL->setMinimum(min_toclevel - 1);
-               numberingModule->depthSL->setMaximum(max_toclevel);
-               numberingModule->depthSL->setValue(params.secnumdepth);
-               numberingModule->tocSL->setMaximum(min_toclevel - 1);
-               numberingModule->tocSL->setMaximum(max_toclevel);
-               numberingModule->tocSL->setValue(params.tocdepth);
-               updateNumbering();
-       } else {
-               numberingModule->setEnabled(false);
-               numberingModule->tocTW->clear();
-       }
-
-       // bullets
-       bulletsModule->setBullet(0, params.user_defined_bullet(0));
-       bulletsModule->setBullet(1, params.user_defined_bullet(1));
-       bulletsModule->setBullet(2, params.user_defined_bullet(2));
-       bulletsModule->setBullet(3, params.user_defined_bullet(3));
-       bulletsModule->init();
-
-       // packages
-       QString text = toqstr(params.graphicsDriver);
-       int nitem = latexModule->psdriverCO->count();
-       for (int n = 0; n < nitem ; ++n) {
-               QString enc = tex_graphics[n];
-               if (enc == text) {
-                       latexModule->psdriverCO->setCurrentIndex(n);
-               }
-       }
-
-
-       mathsModule->amsCB->setChecked(
-               params.use_amsmath == BufferParams::package_on);
-       mathsModule->amsautoCB->setChecked(
-               params.use_amsmath == BufferParams::package_auto);
-
-       mathsModule->esintCB->setChecked(
-               params.use_esint == BufferParams::package_on);
-       mathsModule->esintautoCB->setChecked(
-               params.use_esint == BufferParams::package_auto);
-
-       switch (params.spacing().getSpace()) {
-               case Spacing::Other: nitem = 3; break;
-               case Spacing::Double: nitem = 2; break;
-               case Spacing::Onehalf: nitem = 1; break;
-               case Spacing::Default: case Spacing::Single: nitem = 0; break;
-       }
-
-       // text layout
-       latexModule->classCO->setCurrentIndex(params.textclass);
-
-       updatePagestyle(form_->controller().textClass().opt_pagestyle(),
-                                params.pagestyle);
-
-       textLayoutModule->lspacingCO->setCurrentIndex(nitem);
-       if (params.spacing().getSpace() == Spacing::Other) {
-               textLayoutModule->lspacingLE->setText(
-                       toqstr(params.spacing().getValueAsString()));
-       }
-       setLSpacing(nitem);
-
-       if (params.paragraph_separation
-           == BufferParams::PARSEP_INDENT) {
-               textLayoutModule->indentRB->setChecked(true);
-       } else {
-               textLayoutModule->skipRB->setChecked(true);
-       }
-
-       int skip = 0;
-       switch (params.getDefSkip().kind()) {
-       case VSpace::SMALLSKIP:
-               skip = 0;
-               break;
-       case VSpace::MEDSKIP:
-               skip = 1;
-               break;
-       case VSpace::BIGSKIP:
-               skip = 2;
-               break;
-       case VSpace::LENGTH:
-       {
-               skip = 3;
-               string const length = params.getDefSkip().asLyXCommand();
-               lengthToWidgets(textLayoutModule->skipLE,
-                       textLayoutModule->skipLengthCO,
-                       length, defaultUnit);
-               break;
-       }
-       default:
-               skip = 0;
-               break;
-       }
-       textLayoutModule->skipCO->setCurrentIndex(skip);
-       setSkip(skip);
-
-       textLayoutModule->twoColumnCB->setChecked(
-               params.columns == 2);
-
-       if (!params.options.empty()) {
-               latexModule->optionsLE->setText(
-                       toqstr(params.options));
-       } else {
-               latexModule->optionsLE->setText("");
-       }
-
-       floatModule->set(params.float_placement);
-
-       //fonts
-       updateFontsize(form_->controller().textClass().opt_fontsize(),
-                       params.fontsize);
-
-       int n = findToken(tex_fonts_roman, params.fontsRoman);
-       if (n >= 0) {
-               fontModule->fontsRomanCO->setCurrentIndex(n);
-               romanChanged(n);
-       }
-
-       n = findToken(tex_fonts_sans, params.fontsSans);
-       if (n >= 0)     {
-               fontModule->fontsSansCO->setCurrentIndex(n);
-               sansChanged(n);
-       }
-
-       n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
-       if (n >= 0) {
-               fontModule->fontsTypewriterCO->setCurrentIndex(n);
-               ttChanged(n);
-       }
-
-       fontModule->fontScCB->setChecked(params.fontsSC);
-       fontModule->fontOsfCB->setChecked(params.fontsOSF);
-       fontModule->scaleSansSB->setValue(params.fontsSansScale);
-       fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
-       n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
-       if (n >= 0)
-               fontModule->fontsDefaultCO->setCurrentIndex(n);
-
-       // paper
-       int const psize = params.papersize;
-       pageLayoutModule->papersizeCO->setCurrentIndex(psize);
-       setCustomPapersize(psize);
-
-       bool const landscape =
-               params.orientation == ORIENTATION_LANDSCAPE;
-       pageLayoutModule->landscapeRB->setChecked(landscape);
-       pageLayoutModule->portraitRB->setChecked(!landscape);
-
-       pageLayoutModule->facingPagesCB->setChecked(
-               params.sides == LyXTextClass::TwoSides);
-
-
-       lengthToWidgets(pageLayoutModule->paperwidthLE,
-               pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
-
-       lengthToWidgets(pageLayoutModule->paperheightLE,
-               pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
-
-       // margins
-       Ui::MarginsUi * m = marginsModule;
-
-       setMargins(!params.use_geometry);
-
-       lengthToWidgets(m->topLE, m->topUnit,
-               params.topmargin, defaultUnit);
-
-       lengthToWidgets(m->bottomLE, m->bottomUnit,
-               params.bottommargin, defaultUnit);
-
-       lengthToWidgets(m->innerLE, m->innerUnit,
-               params.leftmargin, defaultUnit);
-
-       lengthToWidgets(m->outerLE, m->outerUnit,
-               params.rightmargin, defaultUnit);
-
-       lengthToWidgets(m->headheightLE, m->headheightUnit,
-               params.headheight, defaultUnit);
-
-       lengthToWidgets(m->headsepLE, m->headsepUnit,
-               params.headsep, defaultUnit);
-
-       lengthToWidgets(m->footskipLE, m->footskipUnit,
-               params.footskip, defaultUnit);
-
-       branchesModule->update(params);
-}
-
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// Document
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlDocument, QView<QDocumentDialog> >
-       DocumentBase;
-
-
-QDocument::QDocument(Dialog & parent)
-       : DocumentBase(parent, _("Document Settings"))
-{}
-
-
-void QDocument::build_dialog()
-{
-       dialog_.reset(new QDocumentDialog(this));
-}
-
-
-void QDocument::showPreamble()
-{
-       dialog_->showPreamble();
-}
-
-
-void QDocument::apply()
-{
-       if (!dialog_.get())
-               return;
-
-       dialog_->apply(controller().params());
-}
-
-
-void QDocument::update_contents()
-{
-       if (!dialog_.get())
-               return;
-
-       dialog_->updateParams(controller().params());
-}
-
-void QDocument::saveDocDefault()
-{
-       // we have to apply the params first
-       apply();
-       controller().saveAsDefault();
-}
-
-
-void QDocument::useClassDefaults()
-{
-       BufferParams & params = controller().params();
-
-       ///\todo verify the use of below with lyx-devel:
-       params.textclass = dialog_->latexModule->classCO->currentIndex();
-
-       params.useClassDefaults();
-       update_contents();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QDocument_moc.cpp"
diff --git a/src/frontends/qt4/QDocument.cpp b/src/frontends/qt4/QDocument.cpp
new file mode 100644 (file)
index 0000000..6ef51d7
--- /dev/null
@@ -0,0 +1,1292 @@
+/**
+ * \file QDocument.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QDocument.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+#include "QBranches.h"
+
+#include <QCloseEvent>
+
+#include "FloatPlacement.h"
+#include "LengthCombo.h"
+#include "Validator.h"
+#include "PanelStack.h"
+#include "Qt2BC.h"
+#include "CheckedLineEdit.h"
+
+// For latexHighlighter use in the preamble.
+#include "QViewSource.h"
+
+#include "bufferparams.h"
+#include "encoding.h"
+#include "gettext.h"
+#include "frontend_helpers.h" // getSecond()
+#include "language.h"
+#include "lyxrc.h" // defaultUnit
+#include "lyxtextclasslist.h"
+#include "tex-strings.h" // tex_graphics
+#include "Spacing.h"
+
+#include "controllers/ControlDocument.h"
+
+#include "support/lstrings.h"
+
+#include "controllers/ControlDocument.h"
+
+
+using lyx::support::token;
+using lyx::support::bformat;
+using lyx::support::findToken;
+using lyx::support::getVectorFromString;
+
+using std::distance;
+using std::vector;
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// DocumentDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QDocumentDialog::QDocumentDialog(QDocument * form)
+       : form_(form),
+       lang_(getSecond(getLanguageData(false)))
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
+
+       connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
+       connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
+
+       // Manage the restore, ok, apply, restore and cancel/close buttons
+       form_->bcview().setOK(okPB);
+       form_->bcview().setApply(applyPB);
+       form_->bcview().setCancel(closePB);
+       form_->bcview().setRestore(restorePB);
+
+
+       textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
+       // text layout
+       connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
+               this, SLOT(setLSpacing(int)));
+       connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->skipRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->indentRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
+               this, SLOT(setSkip(int)));
+       connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
+               this, SLOT(enableSkip(bool)));
+       connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
+               textLayoutModule->lspacingLE));
+       textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
+               textLayoutModule->skipLE));
+
+       textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
+       textLayoutModule->skipCO->addItem(qt_("MedSkip"));
+       textLayoutModule->skipCO->addItem(qt_("BigSkip"));
+       textLayoutModule->skipCO->addItem(qt_("Length"));
+       // remove the %-items from the unit choice
+       textLayoutModule->skipLengthCO->noPercents();
+       textLayoutModule->lspacingCO->insertItem(
+               Spacing::Single, qt_("Single"));
+       textLayoutModule->lspacingCO->insertItem(
+               Spacing::Onehalf, qt_("OneHalf"));
+       textLayoutModule->lspacingCO->insertItem(
+               Spacing::Double, qt_("Double"));
+       textLayoutModule->lspacingCO->insertItem(
+               Spacing::Other, qt_("Custom"));
+
+       // initialize the length validator
+       addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
+
+       fontModule = new UiWidget<Ui::FontUi>;
+       // fonts
+       connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
+               this, SLOT(romanChanged(int)));
+       connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
+               this, SLOT(sansChanged(int)));
+       connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
+               this, SLOT(ttChanged(int)));
+       connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->fontScCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(fontModule->fontOsfCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+
+       for (int n = 0; tex_fonts_roman[n][0]; ++n) {
+               QString font = toqstr(tex_fonts_roman_gui[n]);
+               if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
+                       font += qt_(" (not installed)");
+               fontModule->fontsRomanCO->addItem(font);
+       }
+       for (int n = 0; tex_fonts_sans[n][0]; ++n) {
+               QString font = toqstr(tex_fonts_sans_gui[n]);
+               if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
+                       font += qt_(" (not installed)");
+               fontModule->fontsSansCO->addItem(font);
+       }
+       for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
+               QString font = toqstr(tex_fonts_monospaced_gui[n]);
+               if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
+                       font += qt_(" (not installed)");
+               fontModule->fontsTypewriterCO->addItem(font);
+       }
+
+       fontModule->fontsizeCO->addItem(qt_("default"));
+       fontModule->fontsizeCO->addItem(qt_("10"));
+       fontModule->fontsizeCO->addItem(qt_("11"));
+       fontModule->fontsizeCO->addItem(qt_("12"));
+
+       for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
+               fontModule->fontsDefaultCO->addItem(
+                       qt_(ControlDocument::fontfamilies_gui[n]));
+
+
+       pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
+       // page layout
+       connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
+               this, SLOT(setCustomPapersize(int)));
+       connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
+               this, SLOT(setCustomPapersize(int)));
+       connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
+               this, SLOT(portraitChanged()));
+       connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+
+       pageLayoutModule->pagestyleCO->addItem(qt_("default"));
+       pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
+       pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
+       pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
+       pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
+       addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
+               pageLayoutModule->paperheightL);
+       addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
+               pageLayoutModule->paperwidthL);
+
+       // paper
+       QComboBox * cb = pageLayoutModule->papersizeCO;
+       cb->addItem(qt_("Default"));
+       cb->addItem(qt_("Custom"));
+       cb->addItem(qt_("US letter"));
+       cb->addItem(qt_("US legal"));
+       cb->addItem(qt_("US executive"));
+       cb->addItem(qt_("A3"));
+       cb->addItem(qt_("A4"));
+       cb->addItem(qt_("A5"));
+       cb->addItem(qt_("B3"));
+       cb->addItem(qt_("B4"));
+       cb->addItem(qt_("B5"));
+       // remove the %-items from the unit choice
+       pageLayoutModule->paperwidthUnitCO->noPercents();
+       pageLayoutModule->paperheightUnitCO->noPercents();
+       pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
+               pageLayoutModule->paperheightLE));
+       pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
+               pageLayoutModule->paperwidthLE));
+
+
+
+
+       marginsModule = new UiWidget<Ui::MarginsUi>;
+       // margins
+       connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
+               this, SLOT(setCustomMargins(bool)));
+       connect(marginsModule->marginCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->topUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->innerUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->outerUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       marginsModule->topLE->setValidator(unsignedLengthValidator(
+               marginsModule->topLE));
+       marginsModule->bottomLE->setValidator(unsignedLengthValidator(
+               marginsModule->bottomLE));
+       marginsModule->innerLE->setValidator(unsignedLengthValidator(
+               marginsModule->innerLE));
+       marginsModule->outerLE->setValidator(unsignedLengthValidator(
+               marginsModule->outerLE));
+       marginsModule->headsepLE->setValidator(unsignedLengthValidator(
+               marginsModule->headsepLE));
+       marginsModule->headheightLE->setValidator(unsignedLengthValidator(
+               marginsModule->headheightLE));
+       marginsModule->footskipLE->setValidator(unsignedLengthValidator(
+               marginsModule->footskipLE));
+
+       addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
+               marginsModule->topL);
+       addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
+               marginsModule->bottomL);
+       addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
+               marginsModule->innerL);
+       addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
+               marginsModule->outerL);
+       addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
+               marginsModule->headsepL);
+       addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
+               marginsModule->headheightL);
+       addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
+               marginsModule->footskipL);
+
+
+       langModule = new UiWidget<Ui::LanguageUi>;
+       connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)),
+               langModule->encodingL, SLOT(setDisabled(bool)));
+       connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)),
+               langModule->encodingCO, SLOT(setDisabled(bool)));
+       // language & quote
+       connect(langModule->languageCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->defaultencodingCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(langModule->encodingCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       // language & quotes
+       vector<LanguagePair> const langs = getLanguageData(false);
+       vector<LanguagePair>::const_iterator lit  = langs.begin();
+       vector<LanguagePair>::const_iterator lend = langs.end();
+       for (; lit != lend; ++lit) {
+               langModule->languageCO->addItem(
+                       toqstr(lit->first));
+       }
+
+       // Always put the default encoding in the first position.
+       // It is special because the displayed text is translated.
+       langModule->encodingCO->addItem(qt_("LaTeX default"));
+       Encodings::const_iterator it = encodings.begin();
+       Encodings::const_iterator const end = encodings.end();
+       for (; it != end; ++it)
+               langModule->encodingCO->addItem(toqstr(it->latexName()));
+
+       langModule->quoteStyleCO->addItem(qt_("``text''"));
+       langModule->quoteStyleCO->addItem(qt_("''text''"));
+       langModule->quoteStyleCO->addItem(qt_(",,text``"));
+       langModule->quoteStyleCO->addItem(qt_(",,text''"));
+       langModule->quoteStyleCO->addItem(qt_("<<text>>"));
+       langModule->quoteStyleCO->addItem(qt_(">>text<<"));
+
+
+
+       numberingModule = new UiWidget<Ui::NumberingUi>;
+       // numbering
+       connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
+               this, SLOT(updateNumbering()));
+       connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
+               this, SLOT(updateNumbering()));
+       numberingModule->tocTW->setColumnCount(3);
+       numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
+       numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
+       numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
+
+
+       biblioModule = new UiWidget<Ui::BiblioUi>;
+       connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
+               biblioModule->citationStyleL, SLOT(setEnabled(bool)));
+       connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
+               biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
+       // biblio
+       connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       // biblio
+       biblioModule->citeStyleCO->addItem(qt_("Author-year"));
+       biblioModule->citeStyleCO->addItem(qt_("Numerical"));
+       biblioModule->citeStyleCO->setCurrentIndex(0);
+
+
+
+       mathsModule = new UiWidget<Ui::MathsUi>;
+       connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
+               mathsModule->amsCB, SLOT(setDisabled(bool)));
+       connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
+               mathsModule->esintCB, SLOT(setDisabled(bool)));
+       // maths
+       connect(mathsModule->amsCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->amsautoCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->esintCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->esintautoCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+
+       latexModule = new UiWidget<Ui::LaTeXUi>;
+       // latex class
+       connect(latexModule->classCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(latexModule->psdriverCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(latexModule->classCO, SIGNAL(activated(int)),
+               this, SLOT(classChanged()));
+       // packages
+       for (int n = 0; tex_graphics[n][0]; ++n) {
+               QString enc = tex_graphics[n];
+               latexModule->psdriverCO->addItem(enc);
+       }
+       // latex
+       for (LyXTextClassList::const_iterator cit = textclasslist.begin();
+            cit != textclasslist.end(); ++cit) {
+               if (cit->isTeXClassAvailable()) {
+                       latexModule->classCO->addItem(toqstr(cit->description()));
+               } else {
+                       docstring item =
+                               bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
+                       latexModule->classCO->addItem(toqstr(item));
+               }
+       }
+
+       // branches
+       branchesModule = new QBranches;
+       connect(branchesModule, SIGNAL(changed()),
+               this, SLOT(change_adaptor()));
+
+       // preamble
+       preambleModule = new UiWidget<Ui::PreambleUi>;
+       connect(preambleModule->preambleTE, SIGNAL(textChanged()),
+               this, SLOT(change_adaptor()));
+       // This is not a memory leak. The object will be destroyed
+       // with preambleModule.
+       (void) new LaTeXHighlighter(preambleModule->preambleTE->document());
+
+
+       // bullets
+       bulletsModule = new BulletsModule;
+       connect(bulletsModule, SIGNAL(changed()),
+               this, SLOT(change_adaptor()));
+
+
+       // float
+       floatModule = new FloatPlacement;
+       connect(floatModule, SIGNAL(changed()),
+               this, SLOT(change_adaptor()));
+
+       docPS->addPanel(latexModule, _("Document Class"));
+       docPS->addPanel(fontModule, _("Fonts"));
+       docPS->addPanel(textLayoutModule, _("Text Layout"));
+       docPS->addPanel(pageLayoutModule, _("Page Layout"));
+       docPS->addPanel(marginsModule, _("Page Margins"));
+       docPS->addPanel(langModule, _("Language"));
+       docPS->addPanel(numberingModule, _("Numbering & TOC"));
+       docPS->addPanel(biblioModule, _("Bibliography"));
+       docPS->addPanel(mathsModule, _("Math Options"));
+       docPS->addPanel(floatModule, _("Float Placement"));
+       docPS->addPanel(bulletsModule, _("Bullets"));
+       docPS->addPanel(branchesModule, _("Branches"));
+       docPS->addPanel(preambleModule, _("LaTeX Preamble"));
+       docPS->setCurrentPanel(_("Document Class"));
+// FIXME: hack to work around resizing bug in Qt >= 4.2
+// bug verified with Qt 4.2.{0-3} (JSpitzm)
+#if QT_VERSION >= 0x040200
+       docPS->updateGeometry();
+#endif
+}
+
+
+void QDocumentDialog::showPreamble()
+{
+       docPS->setCurrentPanel(_("LaTeX Preamble"));
+}
+
+
+void QDocumentDialog::saveDefaultClicked()
+{
+       form_->saveDocDefault();
+}
+
+
+void QDocumentDialog::useDefaultsClicked()
+{
+       form_->useClassDefaults();
+}
+
+
+void QDocumentDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QDocumentDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QDocumentDialog::setLSpacing(int item)
+{
+       textLayoutModule->lspacingLE->setEnabled(item == 3);
+}
+
+
+void QDocumentDialog::setSkip(int item)
+{
+       bool const enable = (item == 3);
+       textLayoutModule->skipLE->setEnabled(enable);
+       textLayoutModule->skipLengthCO->setEnabled(enable);
+}
+
+
+void QDocumentDialog::enableSkip(bool skip)
+{
+       textLayoutModule->skipCO->setEnabled(skip);
+       textLayoutModule->skipLE->setEnabled(skip);
+       textLayoutModule->skipLengthCO->setEnabled(skip);
+       if (skip)
+               setSkip(textLayoutModule->skipCO->currentIndex());
+}
+
+void QDocumentDialog::portraitChanged()
+{
+       setMargins(pageLayoutModule->papersizeCO->currentIndex());
+}
+
+void QDocumentDialog::setMargins(bool custom)
+{
+       marginsModule->marginCB->setChecked(custom);
+       setCustomMargins(custom);
+}
+
+
+void QDocumentDialog::setCustomPapersize(int papersize)
+{
+       bool const custom = (papersize == 1);
+
+       pageLayoutModule->paperwidthL->setEnabled(custom);
+       pageLayoutModule->paperwidthLE->setEnabled(custom);
+       pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
+       pageLayoutModule->paperheightL->setEnabled(custom);
+       pageLayoutModule->paperheightLE->setEnabled(custom);
+       pageLayoutModule->paperheightLE->setFocus();
+       pageLayoutModule->paperheightUnitCO->setEnabled(custom);
+}
+
+
+void QDocumentDialog::setCustomMargins(bool custom)
+{
+       marginsModule->topL->setEnabled(!custom);
+       marginsModule->topLE->setEnabled(!custom);
+       marginsModule->topUnit->setEnabled(!custom);
+
+       marginsModule->bottomL->setEnabled(!custom);
+       marginsModule->bottomLE->setEnabled(!custom);
+       marginsModule->bottomUnit->setEnabled(!custom);
+
+       marginsModule->innerL->setEnabled(!custom);
+       marginsModule->innerLE->setEnabled(!custom);
+       marginsModule->innerUnit->setEnabled(!custom);
+
+       marginsModule->outerL->setEnabled(!custom);
+       marginsModule->outerLE->setEnabled(!custom);
+       marginsModule->outerUnit->setEnabled(!custom);
+
+       marginsModule->headheightL->setEnabled(!custom);
+       marginsModule->headheightLE->setEnabled(!custom);
+       marginsModule->headheightUnit->setEnabled(!custom);
+
+       marginsModule->headsepL->setEnabled(!custom);
+       marginsModule->headsepLE->setEnabled(!custom);
+       marginsModule->headsepUnit->setEnabled(!custom);
+
+       marginsModule->footskipL->setEnabled(!custom);
+       marginsModule->footskipLE->setEnabled(!custom);
+       marginsModule->footskipUnit->setEnabled(!custom);
+}
+
+
+void QDocumentDialog::updateFontsize(string const & items, string const & sel)
+{
+       fontModule->fontsizeCO->clear();
+       fontModule->fontsizeCO->addItem(qt_("default"));
+
+       for (int n = 0; !token(items,'|',n).empty(); ++n)
+               fontModule->fontsizeCO->
+                       addItem(toqstr(token(items,'|',n)));
+
+       for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
+               if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
+                       fontModule->fontsizeCO->setCurrentIndex(n);
+                       break;
+               }
+       }
+}
+
+
+void QDocumentDialog::romanChanged(int item)
+{
+       string const font = tex_fonts_roman[item];
+       
+       fontModule->fontScCB->setEnabled(
+               form_->controller().providesSC(font));
+       fontModule->fontOsfCB->setEnabled(
+               form_->controller().providesOSF(font));
+}
+
+
+void QDocumentDialog::sansChanged(int item)
+{
+       string const font = tex_fonts_sans[item];
+       bool scaleable = form_->controller().providesScale(font);
+       fontModule->scaleSansSB->setEnabled(scaleable);
+       fontModule->scaleSansLA->setEnabled(scaleable);
+}
+
+
+void QDocumentDialog::ttChanged(int item)
+{
+       string const font = tex_fonts_monospaced[item];
+       bool scaleable = form_->controller().providesScale(font);
+       fontModule->scaleTypewriterSB->setEnabled(scaleable);
+       fontModule->scaleTypewriterLA->setEnabled(scaleable);
+}
+
+
+void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
+{
+       pageLayoutModule->pagestyleCO->clear();
+       pageLayoutModule->pagestyleCO->addItem("default");
+
+       for (int n=0; !token(items,'|',n).empty(); ++n)
+               pageLayoutModule->pagestyleCO->
+                       addItem(toqstr(token(items,'|',n)));
+
+       for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
+               if (fromqstr(pageLayoutModule->pagestyleCO->itemText(n))==sel) {
+                       pageLayoutModule->pagestyleCO->setCurrentIndex(n);
+                       break;
+               }
+       }
+}
+
+
+void QDocumentDialog::classChanged()
+{
+       ControlDocument & cntrl = form_->controller();
+       BufferParams & params = cntrl.params();
+
+       textclass_type const tc = latexModule->classCO->currentIndex();
+
+       if (form_->controller().loadTextclass(tc)) {
+               params.textclass = tc;
+               if (lyxrc.auto_reset_options)
+                       params.useClassDefaults();
+               form_->update_contents();
+       } else {
+               latexModule->classCO->setCurrentIndex(params.textclass);
+       }
+}
+
+
+void QDocumentDialog::updateNumbering()
+{
+       LyXTextClass const & tclass =
+               form_->controller().params().getLyXTextClass();
+
+       numberingModule->tocTW->setUpdatesEnabled(false);
+       numberingModule->tocTW->clear();
+
+       int const depth = numberingModule->depthSL->value();
+       int const toc = numberingModule->tocSL->value();
+       QString const no = qt_("No");
+       QString const yes = qt_("Yes");
+       LyXTextClass::const_iterator end = tclass.end();
+       LyXTextClass::const_iterator cit = tclass.begin();
+       QTreeWidgetItem * item = 0;
+       for ( ; cit != end ; ++cit) {
+               int const toclevel = (*cit)->toclevel;
+               if (toclevel != LyXLayout::NOT_IN_TOC 
+                   && (*cit)->labeltype == LABEL_COUNTER) {
+                       item = new QTreeWidgetItem(numberingModule->tocTW);
+                       item->setText(0, qt_((*cit)->name()));
+                       item->setText(1, (toclevel <= depth) ? yes : no);
+                       item->setText(2, (toclevel <= toc) ? yes : no);
+               }
+       }
+
+       numberingModule->tocTW->setUpdatesEnabled(true);
+       numberingModule->tocTW->update();
+}
+
+void QDocumentDialog::apply(BufferParams & params)
+{
+       // preamble
+       params.preamble =
+               fromqstr(preambleModule->preambleTE->document()->toPlainText());
+
+       // biblio
+       params.setCiteEngine(biblio::ENGINE_BASIC);
+
+       if (biblioModule->citeNatbibRB->isChecked()) {
+               bool const use_numerical_citations =
+                       biblioModule->citeStyleCO->currentIndex();
+               if (use_numerical_citations)
+                       params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
+               else
+                       params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
+
+       } else if (biblioModule->citeJurabibRB->isChecked())
+               params.setCiteEngine(biblio::ENGINE_JURABIB);
+
+       params.use_bibtopic =
+               biblioModule->bibtopicCB->isChecked();
+
+       // language & quotes
+       if (langModule->defaultencodingCB->isChecked()) {
+               params.inputenc = "auto";
+       } else {
+               int i = langModule->encodingCO->currentIndex();
+               if (i == 0)
+                       params.inputenc = "default";
+               else
+                       params.inputenc =
+                               fromqstr(langModule->encodingCO->currentText());
+       }
+
+       InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
+       switch (langModule->quoteStyleCO->currentIndex()) {
+       case 0:
+               lga = InsetQuotes::EnglishQ;
+               break;
+       case 1:
+               lga = InsetQuotes::SwedishQ;
+               break;
+       case 2:
+               lga = InsetQuotes::GermanQ;
+               break;
+       case 3:
+               lga = InsetQuotes::PolishQ;
+               break;
+       case 4:
+               lga = InsetQuotes::FrenchQ;
+               break;
+       case 5:
+               lga = InsetQuotes::DanishQ;
+               break;
+       }
+       params.quotes_language = lga;
+
+       int const pos = langModule->languageCO->currentIndex();
+       params.language = languages.getLanguage(lang_[pos]);
+
+       // numbering
+       if (params.getLyXTextClass().hasTocLevels()) {
+               params.tocdepth = numberingModule->tocSL->value();
+               params.secnumdepth = numberingModule->depthSL->value();
+       }
+
+       // bullets
+       params.user_defined_bullet(0) = bulletsModule->getBullet(0);
+       params.user_defined_bullet(1) = bulletsModule->getBullet(1);
+       params.user_defined_bullet(2) = bulletsModule->getBullet(2);
+       params.user_defined_bullet(3) = bulletsModule->getBullet(3);
+
+       // packages
+       params.graphicsDriver =
+               fromqstr(latexModule->psdriverCO->currentText());
+
+       if (mathsModule->amsautoCB->isChecked()) {
+               params.use_amsmath = BufferParams::package_auto;
+       } else {
+               if (mathsModule->amsCB->isChecked())
+                       params.use_amsmath = BufferParams::package_on;
+               else
+                       params.use_amsmath = BufferParams::package_off;
+       }
+
+       if (mathsModule->esintautoCB->isChecked())
+               params.use_esint = BufferParams::package_auto;
+       else {
+               if (mathsModule->esintCB->isChecked())
+                       params.use_esint = BufferParams::package_on;
+               else
+                       params.use_esint = BufferParams::package_off;
+       }
+
+       // text layout
+       params.textclass =
+               latexModule->classCO->currentIndex();
+
+       params.pagestyle =
+               fromqstr(pageLayoutModule->pagestyleCO->currentText());
+
+       switch (textLayoutModule->lspacingCO->currentIndex()) {
+       case 0:
+               params.spacing().set(Spacing::Single);
+               break;
+       case 1:
+               params.spacing().set(Spacing::Onehalf);
+               break;
+       case 2:
+               params.spacing().set(Spacing::Double);
+               break;
+       case 3:
+               params.spacing().set(Spacing::Other,
+                       fromqstr(textLayoutModule->lspacingLE->text()));
+               break;
+       }
+
+       if (textLayoutModule->twoColumnCB->isChecked())
+               params.columns = 2;
+       else
+               params.columns = 1;
+
+       if (textLayoutModule->indentRB->isChecked())
+               params.paragraph_separation = BufferParams::PARSEP_INDENT;
+       else
+               params.paragraph_separation = BufferParams::PARSEP_SKIP;
+
+       switch (textLayoutModule->skipCO->currentIndex()) {
+       case 0:
+               params.setDefSkip(VSpace(VSpace::SMALLSKIP));
+               break;
+       case 1:
+               params.setDefSkip(VSpace(VSpace::MEDSKIP));
+               break;
+       case 2:
+               params.setDefSkip(VSpace(VSpace::BIGSKIP));
+               break;
+       case 3:
+       {
+               VSpace vs = VSpace(
+                       widgetsToLength(textLayoutModule->skipLE,
+                               textLayoutModule->skipLengthCO)
+                       );
+               params.setDefSkip(vs);
+               break;
+       }
+       default:
+               // DocumentDefskipCB assures that this never happens
+               // so Assert then !!!  - jbl
+               params.setDefSkip(VSpace(VSpace::MEDSKIP));
+               break;
+       }
+
+       params.options =
+               fromqstr(latexModule->optionsLE->text());
+
+       params.float_placement = floatModule->get();
+
+       // fonts
+       params.fontsRoman =
+               tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
+
+       params.fontsSans =
+               tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
+
+       params.fontsTypewriter =
+               tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
+
+       params.fontsSansScale = fontModule->scaleSansSB->value();
+
+       params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
+
+       params.fontsSC = fontModule->fontScCB->isChecked();
+
+       params.fontsOSF = fontModule->fontOsfCB->isChecked();
+
+       params.fontsDefaultFamily = ControlDocument::fontfamilies[
+               fontModule->fontsDefaultCO->currentIndex()];
+
+       if (fontModule->fontsizeCO->currentIndex() == 0)
+               params.fontsize = "default";
+       else
+               params.fontsize =
+                       fromqstr(fontModule->fontsizeCO->currentText());
+
+       // paper
+       params.papersize = PAPER_SIZE(
+               pageLayoutModule->papersizeCO->currentIndex());
+
+       // custom, A3, B3 and B4 paper sizes need geometry
+       int psize = pageLayoutModule->papersizeCO->currentIndex();
+       bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
+
+       params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
+               pageLayoutModule->paperwidthUnitCO);
+
+       params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
+               pageLayoutModule->paperheightUnitCO);
+
+       if (pageLayoutModule->facingPagesCB->isChecked())
+               params.sides = LyXTextClass::TwoSides;
+       else
+               params.sides = LyXTextClass::OneSide;
+
+       if (pageLayoutModule->landscapeRB->isChecked())
+               params.orientation = ORIENTATION_LANDSCAPE;
+       else
+               params.orientation = ORIENTATION_PORTRAIT;
+
+       // margins
+       params.use_geometry =
+               (!marginsModule->marginCB->isChecked()
+               || geom_papersize);
+
+       Ui::MarginsUi const * m(marginsModule);
+
+       params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
+
+       params.topmargin = widgetsToLength(m->topLE, m->topUnit);
+
+       params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
+
+       params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
+
+       params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
+
+       params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
+
+       params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
+
+       branchesModule->apply(params);
+}
+
+namespace {
+
+/** Return the position of val in the vector if found.
+    If not found, return 0.
+ */
+template<class A>
+typename std::vector<A>::size_type
+findPos(std::vector<A> const & vec, A const & val)
+{
+       typename std::vector<A>::const_iterator it =
+               std::find(vec.begin(), vec.end(), val);
+       if (it == vec.end())
+               return 0;
+       return distance(vec.begin(), it);
+}
+
+} // namespace anom
+
+
+void QDocumentDialog::updateParams(BufferParams const & params)
+{
+       // set the default unit
+       // FIXME: move to controller
+       LyXLength::UNIT defaultUnit = LyXLength::CM;
+       switch (lyxrc.default_papersize) {
+               case PAPER_DEFAULT: break;
+
+               case PAPER_USLETTER:
+               case PAPER_USLEGAL:
+               case PAPER_USEXECUTIVE:
+                       defaultUnit = LyXLength::IN;
+                       break;
+
+               case PAPER_A3:
+               case PAPER_A4:
+               case PAPER_A5:
+               case PAPER_B3:
+               case PAPER_B4:
+               case PAPER_B5:
+                       defaultUnit = LyXLength::CM;
+                       break;
+               case PAPER_CUSTOM:
+                       break;
+       }
+
+       // preamble
+       QString preamble = toqstr(params.preamble);
+       preambleModule->preambleTE->document()->setPlainText(preamble);
+
+       // biblio
+       biblioModule->citeDefaultRB->setChecked(
+               params.getEngine() == biblio::ENGINE_BASIC);
+
+       biblioModule->citeNatbibRB->setChecked(
+               params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
+               params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
+
+       biblioModule->citeStyleCO->setCurrentIndex(
+               params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
+
+       biblioModule->citeJurabibRB->setChecked(
+               params.getEngine() == biblio::ENGINE_JURABIB);
+
+       biblioModule->bibtopicCB->setChecked(
+               params.use_bibtopic);
+
+       // language & quotes
+       int const pos = int(findPos(lang_,
+                                   params.language->lang()));
+       langModule->languageCO->setCurrentIndex(pos);
+
+       langModule->quoteStyleCO->setCurrentIndex(
+               params.quotes_language);
+
+       langModule->defaultencodingCB->setChecked(true);
+
+       if (params.inputenc != "auto") {
+               langModule->defaultencodingCB->setChecked(false);
+               if (params.inputenc == "default") {
+                       langModule->encodingCO->setCurrentIndex(0);
+               } else {
+                       int const i = langModule->encodingCO->findText(
+                                       toqstr(params.inputenc));
+                       if (i >= 0)
+                               langModule->encodingCO->setCurrentIndex(i);
+                       else
+                               // unknown encoding. Set to default.
+                               langModule->defaultencodingCB->setChecked(true);
+               }
+       }
+
+       // numbering
+       int const min_toclevel = form_->controller().textClass().min_toclevel();
+       int const max_toclevel = form_->controller().textClass().max_toclevel();
+       if (form_->controller().textClass().hasTocLevels()) {
+               numberingModule->setEnabled(true);
+               numberingModule->depthSL->setMinimum(min_toclevel - 1);
+               numberingModule->depthSL->setMaximum(max_toclevel);
+               numberingModule->depthSL->setValue(params.secnumdepth);
+               numberingModule->tocSL->setMaximum(min_toclevel - 1);
+               numberingModule->tocSL->setMaximum(max_toclevel);
+               numberingModule->tocSL->setValue(params.tocdepth);
+               updateNumbering();
+       } else {
+               numberingModule->setEnabled(false);
+               numberingModule->tocTW->clear();
+       }
+
+       // bullets
+       bulletsModule->setBullet(0, params.user_defined_bullet(0));
+       bulletsModule->setBullet(1, params.user_defined_bullet(1));
+       bulletsModule->setBullet(2, params.user_defined_bullet(2));
+       bulletsModule->setBullet(3, params.user_defined_bullet(3));
+       bulletsModule->init();
+
+       // packages
+       QString text = toqstr(params.graphicsDriver);
+       int nitem = latexModule->psdriverCO->count();
+       for (int n = 0; n < nitem ; ++n) {
+               QString enc = tex_graphics[n];
+               if (enc == text) {
+                       latexModule->psdriverCO->setCurrentIndex(n);
+               }
+       }
+
+
+       mathsModule->amsCB->setChecked(
+               params.use_amsmath == BufferParams::package_on);
+       mathsModule->amsautoCB->setChecked(
+               params.use_amsmath == BufferParams::package_auto);
+
+       mathsModule->esintCB->setChecked(
+               params.use_esint == BufferParams::package_on);
+       mathsModule->esintautoCB->setChecked(
+               params.use_esint == BufferParams::package_auto);
+
+       switch (params.spacing().getSpace()) {
+               case Spacing::Other: nitem = 3; break;
+               case Spacing::Double: nitem = 2; break;
+               case Spacing::Onehalf: nitem = 1; break;
+               case Spacing::Default: case Spacing::Single: nitem = 0; break;
+       }
+
+       // text layout
+       latexModule->classCO->setCurrentIndex(params.textclass);
+
+       updatePagestyle(form_->controller().textClass().opt_pagestyle(),
+                                params.pagestyle);
+
+       textLayoutModule->lspacingCO->setCurrentIndex(nitem);
+       if (params.spacing().getSpace() == Spacing::Other) {
+               textLayoutModule->lspacingLE->setText(
+                       toqstr(params.spacing().getValueAsString()));
+       }
+       setLSpacing(nitem);
+
+       if (params.paragraph_separation
+           == BufferParams::PARSEP_INDENT) {
+               textLayoutModule->indentRB->setChecked(true);
+       } else {
+               textLayoutModule->skipRB->setChecked(true);
+       }
+
+       int skip = 0;
+       switch (params.getDefSkip().kind()) {
+       case VSpace::SMALLSKIP:
+               skip = 0;
+               break;
+       case VSpace::MEDSKIP:
+               skip = 1;
+               break;
+       case VSpace::BIGSKIP:
+               skip = 2;
+               break;
+       case VSpace::LENGTH:
+       {
+               skip = 3;
+               string const length = params.getDefSkip().asLyXCommand();
+               lengthToWidgets(textLayoutModule->skipLE,
+                       textLayoutModule->skipLengthCO,
+                       length, defaultUnit);
+               break;
+       }
+       default:
+               skip = 0;
+               break;
+       }
+       textLayoutModule->skipCO->setCurrentIndex(skip);
+       setSkip(skip);
+
+       textLayoutModule->twoColumnCB->setChecked(
+               params.columns == 2);
+
+       if (!params.options.empty()) {
+               latexModule->optionsLE->setText(
+                       toqstr(params.options));
+       } else {
+               latexModule->optionsLE->setText("");
+       }
+
+       floatModule->set(params.float_placement);
+
+       //fonts
+       updateFontsize(form_->controller().textClass().opt_fontsize(),
+                       params.fontsize);
+
+       int n = findToken(tex_fonts_roman, params.fontsRoman);
+       if (n >= 0) {
+               fontModule->fontsRomanCO->setCurrentIndex(n);
+               romanChanged(n);
+       }
+
+       n = findToken(tex_fonts_sans, params.fontsSans);
+       if (n >= 0)     {
+               fontModule->fontsSansCO->setCurrentIndex(n);
+               sansChanged(n);
+       }
+
+       n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
+       if (n >= 0) {
+               fontModule->fontsTypewriterCO->setCurrentIndex(n);
+               ttChanged(n);
+       }
+
+       fontModule->fontScCB->setChecked(params.fontsSC);
+       fontModule->fontOsfCB->setChecked(params.fontsOSF);
+       fontModule->scaleSansSB->setValue(params.fontsSansScale);
+       fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
+       n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
+       if (n >= 0)
+               fontModule->fontsDefaultCO->setCurrentIndex(n);
+
+       // paper
+       int const psize = params.papersize;
+       pageLayoutModule->papersizeCO->setCurrentIndex(psize);
+       setCustomPapersize(psize);
+
+       bool const landscape =
+               params.orientation == ORIENTATION_LANDSCAPE;
+       pageLayoutModule->landscapeRB->setChecked(landscape);
+       pageLayoutModule->portraitRB->setChecked(!landscape);
+
+       pageLayoutModule->facingPagesCB->setChecked(
+               params.sides == LyXTextClass::TwoSides);
+
+
+       lengthToWidgets(pageLayoutModule->paperwidthLE,
+               pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
+
+       lengthToWidgets(pageLayoutModule->paperheightLE,
+               pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
+
+       // margins
+       Ui::MarginsUi * m = marginsModule;
+
+       setMargins(!params.use_geometry);
+
+       lengthToWidgets(m->topLE, m->topUnit,
+               params.topmargin, defaultUnit);
+
+       lengthToWidgets(m->bottomLE, m->bottomUnit,
+               params.bottommargin, defaultUnit);
+
+       lengthToWidgets(m->innerLE, m->innerUnit,
+               params.leftmargin, defaultUnit);
+
+       lengthToWidgets(m->outerLE, m->outerUnit,
+               params.rightmargin, defaultUnit);
+
+       lengthToWidgets(m->headheightLE, m->headheightUnit,
+               params.headheight, defaultUnit);
+
+       lengthToWidgets(m->headsepLE, m->headsepUnit,
+               params.headsep, defaultUnit);
+
+       lengthToWidgets(m->footskipLE, m->footskipUnit,
+               params.footskip, defaultUnit);
+
+       branchesModule->update(params);
+}
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// Document
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlDocument, QView<QDocumentDialog> >
+       DocumentBase;
+
+
+QDocument::QDocument(Dialog & parent)
+       : DocumentBase(parent, _("Document Settings"))
+{}
+
+
+void QDocument::build_dialog()
+{
+       dialog_.reset(new QDocumentDialog(this));
+}
+
+
+void QDocument::showPreamble()
+{
+       dialog_->showPreamble();
+}
+
+
+void QDocument::apply()
+{
+       if (!dialog_.get())
+               return;
+
+       dialog_->apply(controller().params());
+}
+
+
+void QDocument::update_contents()
+{
+       if (!dialog_.get())
+               return;
+
+       dialog_->updateParams(controller().params());
+}
+
+void QDocument::saveDocDefault()
+{
+       // we have to apply the params first
+       apply();
+       controller().saveAsDefault();
+}
+
+
+void QDocument::useClassDefaults()
+{
+       BufferParams & params = controller().params();
+
+       ///\todo verify the use of below with lyx-devel:
+       params.textclass = dialog_->latexModule->classCO->currentIndex();
+
+       params.useClassDefaults();
+       update_contents();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QDocument_moc.cpp"
diff --git a/src/frontends/qt4/QERT.C b/src/frontends/qt4/QERT.C
deleted file mode 100644 (file)
index d1b0fce..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * \file QERT.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QERT.h"
-#include "Qt2BC.h"
-
-#include "controllers/ControlERT.h"
-
-#include <QRadioButton>
-#include <QPushButton>
-#include <QCloseEvent>
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QERTDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-QERTDialog::QERTDialog(QERT * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-       connect(inlineRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(collapsedRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(openRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-}
-
-
-void QERTDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QERTDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QERT
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlERT, QView<QERTDialog> > ERTBase;
-
-
-QERT::QERT(Dialog & parent)
-       : ERTBase(parent, _("TeX Code Settings"))
-{
-}
-
-
-void QERT::build_dialog()
-{
-       dialog_.reset(new QERTDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QERT::apply()
-{
-       if (dialog_->openRB->isChecked())
-               controller().setStatus(InsetERT::Open);
-       else if (dialog_->inlineRB->isChecked())
-               controller().setStatus(InsetERT::Inlined);
-       else
-               controller().setStatus(InsetERT::Collapsed);
-}
-
-
-void QERT::update_contents()
-{
-       QRadioButton * rb = 0;
-
-       switch (controller().status()) {
-               case InsetERT::Open: rb = dialog_->openRB; break;
-               case InsetERT::Inlined: rb = dialog_->inlineRB; break;
-               case InsetERT::Collapsed: rb = dialog_->collapsedRB; break;
-       }
-
-       rb->setChecked(true);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QERT_moc.cpp"
diff --git a/src/frontends/qt4/QERT.cpp b/src/frontends/qt4/QERT.cpp
new file mode 100644 (file)
index 0000000..d1b0fce
--- /dev/null
@@ -0,0 +1,109 @@
+/**
+ * \file QERT.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QERT.h"
+#include "Qt2BC.h"
+
+#include "controllers/ControlERT.h"
+
+#include <QRadioButton>
+#include <QPushButton>
+#include <QCloseEvent>
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QERTDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+QERTDialog::QERTDialog(QERT * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+       connect(inlineRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(collapsedRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(openRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+}
+
+
+void QERTDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QERTDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QERT
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlERT, QView<QERTDialog> > ERTBase;
+
+
+QERT::QERT(Dialog & parent)
+       : ERTBase(parent, _("TeX Code Settings"))
+{
+}
+
+
+void QERT::build_dialog()
+{
+       dialog_.reset(new QERTDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QERT::apply()
+{
+       if (dialog_->openRB->isChecked())
+               controller().setStatus(InsetERT::Open);
+       else if (dialog_->inlineRB->isChecked())
+               controller().setStatus(InsetERT::Inlined);
+       else
+               controller().setStatus(InsetERT::Collapsed);
+}
+
+
+void QERT::update_contents()
+{
+       QRadioButton * rb = 0;
+
+       switch (controller().status()) {
+               case InsetERT::Open: rb = dialog_->openRB; break;
+               case InsetERT::Inlined: rb = dialog_->inlineRB; break;
+               case InsetERT::Collapsed: rb = dialog_->collapsedRB; break;
+       }
+
+       rb->setChecked(true);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QERT_moc.cpp"
diff --git a/src/frontends/qt4/QErrorList.C b/src/frontends/qt4/QErrorList.C
deleted file mode 100644 (file)
index c4f73fb..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * \file QErrorList.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Alfredo Braunstein
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QErrorList.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ControlErrorList.h"
-
-#include <QListWidget>
-#include <QTextBrowser>
-#include <QPushButton>
-#include <QCloseEvent>
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QErrorListDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QErrorListDialog::QErrorListDialog(QErrorList * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-       connect(errorsLW, SIGNAL( itemActivated(QListWidgetItem *)),
-               form, SLOT(slotClose()));
-       connect( errorsLW, SIGNAL( itemClicked(QListWidgetItem *)), 
-               this, SLOT(select_adaptor(QListWidgetItem *)));
-}
-
-
-void QErrorListDialog::select_adaptor(QListWidgetItem * item)
-{
-       form_->select(item);
-}
-
-
-void QErrorListDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QErrorListDialog::showEvent(QShowEvent *e)
-{
-       errorsLW->setCurrentRow(0);
-       form_->select(errorsLW->item(0));
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QErrorList
-//
-/////////////////////////////////////////////////////////////////////
-
-
-typedef QController<ControlErrorList, QView<QErrorListDialog> >
-       ErrorListBase;
-
-QErrorList::QErrorList(Dialog & parent)
-       : ErrorListBase(parent, docstring())
-{}
-
-
-void QErrorList::build_dialog()
-{
-       dialog_.reset(new QErrorListDialog(this));
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QErrorList::select(QListWidgetItem * wi)
-{
-       int const item = dialog_->errorsLW->row(wi);
-       controller().goTo(item);
-       dialog_->descriptionTB->setPlainText(toqstr(controller().errorList()[item].description));
-}
-
-
-void QErrorList::update_contents()
-{
-       setTitle(from_utf8(controller().name()));
-       dialog_->errorsLW->clear();
-       dialog_->descriptionTB->setPlainText(QString());
-
-       ErrorList::const_iterator it = controller().errorList().begin();
-       ErrorList::const_iterator end = controller().errorList().end();
-       for(; it != end; ++it) {
-               dialog_->errorsLW->addItem(toqstr(it->error));
-       }
-}
-
-} // namespace frontend
-} // namespace lyx
-
-
-#include "QErrorList_moc.cpp"
diff --git a/src/frontends/qt4/QErrorList.cpp b/src/frontends/qt4/QErrorList.cpp
new file mode 100644 (file)
index 0000000..c4f73fb
--- /dev/null
@@ -0,0 +1,114 @@
+/**
+ * \file QErrorList.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Alfredo Braunstein
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QErrorList.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ControlErrorList.h"
+
+#include <QListWidget>
+#include <QTextBrowser>
+#include <QPushButton>
+#include <QCloseEvent>
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QErrorListDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QErrorListDialog::QErrorListDialog(QErrorList * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+       connect(errorsLW, SIGNAL( itemActivated(QListWidgetItem *)),
+               form, SLOT(slotClose()));
+       connect( errorsLW, SIGNAL( itemClicked(QListWidgetItem *)), 
+               this, SLOT(select_adaptor(QListWidgetItem *)));
+}
+
+
+void QErrorListDialog::select_adaptor(QListWidgetItem * item)
+{
+       form_->select(item);
+}
+
+
+void QErrorListDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QErrorListDialog::showEvent(QShowEvent *e)
+{
+       errorsLW->setCurrentRow(0);
+       form_->select(errorsLW->item(0));
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QErrorList
+//
+/////////////////////////////////////////////////////////////////////
+
+
+typedef QController<ControlErrorList, QView<QErrorListDialog> >
+       ErrorListBase;
+
+QErrorList::QErrorList(Dialog & parent)
+       : ErrorListBase(parent, docstring())
+{}
+
+
+void QErrorList::build_dialog()
+{
+       dialog_.reset(new QErrorListDialog(this));
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QErrorList::select(QListWidgetItem * wi)
+{
+       int const item = dialog_->errorsLW->row(wi);
+       controller().goTo(item);
+       dialog_->descriptionTB->setPlainText(toqstr(controller().errorList()[item].description));
+}
+
+
+void QErrorList::update_contents()
+{
+       setTitle(from_utf8(controller().name()));
+       dialog_->errorsLW->clear();
+       dialog_->descriptionTB->setPlainText(QString());
+
+       ErrorList::const_iterator it = controller().errorList().begin();
+       ErrorList::const_iterator end = controller().errorList().end();
+       for(; it != end; ++it) {
+               dialog_->errorsLW->addItem(toqstr(it->error));
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QErrorList_moc.cpp"
diff --git a/src/frontends/qt4/QExternal.C b/src/frontends/qt4/QExternal.C
deleted file mode 100644 (file)
index d33d91c..0000000
+++ /dev/null
@@ -1,737 +0,0 @@
-/**
- * \file QExternal.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-// Qt defines a macro 'signals' that clashes with a boost namespace.
-// All is well if the namespace is visible first.
-#include "lengthcommon.h"
-#include "lyxrc.h"
-
-#include "controllers/ControlExternal.h"
-#include "controllers/ButtonController.h"
-
-#include "insets/ExternalTemplate.h"
-#include "insets/InsetExternal.h"
-
-#include "support/lstrings.h"
-#include "support/convert.h"
-#include "support/os.h"
-#include "support/lyxlib.h"
-
-#include "QExternal.h"
-#include "Qt2BC.h"
-
-#include "CheckedLineEdit.h"
-#include "LengthCombo.h"
-#include "qt_helpers.h"
-#include "Validator.h"
-
-#include <QLineEdit>
-#include <QPushButton>
-#include <QCheckBox>
-#include <QTabWidget>
-#include <QTextBrowser>
-
-namespace external = lyx::external;
-
-using lyx::support::isStrDbl;
-using lyx::support::token;
-using lyx::support::trim;
-using lyx::support::float_equal;
-
-using lyx::support::os::internal_path;
-
-using std::string;
-using std::vector;
-using std::find;
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QExternalDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-QExternalDialog::QExternalDialog(QExternal * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(displayCB, SIGNAL(toggled(bool)),
-               showCO, SLOT(setEnabled(bool)));
-       connect(displayCB, SIGNAL(toggled(bool)),
-               displayscaleED, SLOT(setEnabled(bool)));
-       connect(showCO, SIGNAL(activated(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(originCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(aspectratioCB, SIGNAL(stateChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(browsePB, SIGNAL(clicked()),
-               this, SLOT(browseClicked()));
-       connect(editPB, SIGNAL(clicked()),
-               this, SLOT(editClicked()));
-       connect(externalCO, SIGNAL(activated(const QString&)),
-               this, SLOT(templateChanged()));
-       connect(extraED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(extraChanged(const QString&)));
-       connect(extraFormatCO, SIGNAL(activated(const QString&)),
-               this, SLOT(formatChanged(const QString&)));
-       connect(widthUnitCO, SIGNAL(activated(int)),
-               this, SLOT(widthUnitChanged()));
-       connect(heightUnitCO, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(change_adaptor()));
-       connect(displayCB, SIGNAL(stateChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(displayscaleED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(angleED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(widthED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(sizeChanged()));
-       connect(heightED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(sizeChanged()));
-       connect(fileED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(clipCB, SIGNAL(stateChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(getbbPB, SIGNAL(clicked()), this, SLOT(getbbClicked()));
-       connect(xrED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
-       connect(ytED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
-       connect(xlED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
-       connect(ybED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
-       connect(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-
-       QIntValidator * validator = new QIntValidator(displayscaleED);
-       validator->setBottom(1);
-       displayscaleED->setValidator(validator);
-
-       angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
-
-       xlED->setValidator(new QIntValidator(xlED));
-       ybED->setValidator(new QIntValidator(ybED));
-       xrED->setValidator(new QIntValidator(xrED));
-       ytED->setValidator(new QIntValidator(ytED));
-
-       widthED->setValidator(unsignedLengthValidator(widthED));
-       heightED->setValidator(unsignedLengthValidator(heightED));
-
-       fileED->setValidator(new PathValidator(true, fileED));
-       setFocusProxy(fileED);
-}
-
-
-void QExternalDialog::show()
-{
-       QDialog::show();
-}
-
-
-
-bool QExternalDialog::activateAspectratio() const
-{
-       if (widthUnitCO->currentIndex() == 0)
-               return false;
-
-       string const wstr = fromqstr(widthED->text());
-       if (wstr.empty())
-               return false;
-       bool const wIsDbl = isStrDbl(wstr);
-       if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
-               return false;
-       LyXLength l;
-       if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
-               return false;
-
-       string const hstr = fromqstr(heightED->text());
-       if (hstr.empty())
-               return false;
-       bool const hIsDbl = isStrDbl(hstr);
-       if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
-               return false;
-       if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
-               return false;
-
-       return true;
-}
-
-
-void QExternalDialog::bbChanged()
-{
-       form_->controller().bbChanged(true);
-       form_->changed();
-}
-
-
-void QExternalDialog::browseClicked()
-{
-       int const choice =  externalCO->currentIndex();
-       docstring const template_name = 
-               from_utf8(form_->controller().getTemplate(choice).lyxName);
-       docstring const str =
-               form_->controller().browse(qstring_to_ucs4(fileED->text()),
-                                          template_name);
-       fileED->setText(toqstr(str));
-       form_->changed();
-}
-
-
-void QExternalDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QExternalDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QExternalDialog::editClicked()
-{
-       form_->controller().editExternal();
-}
-
-
-
-void QExternalDialog::extraChanged(const QString& text)
-{
-       std::string const format = fromqstr(extraFormatCO->currentText());
-       form_->extra_[format] = text;
-       form_->changed();
-}
-
-
-void QExternalDialog::formatChanged(const QString& format)
-{
-       extraED->setText(form_->extra_[fromqstr(format)]);
-}
-
-
-void QExternalDialog::getbbClicked()
-{
-       form_->getBB();
-}
-
-
-void QExternalDialog::sizeChanged()
-{
-       aspectratioCB->setEnabled(activateAspectratio());
-       form_->changed();
-}
-
-
-void QExternalDialog::templateChanged()
-{
-       form_->updateTemplate();
-       form_->changed();
-}
-
-
-void QExternalDialog::widthUnitChanged()
-{
-       bool useHeight = (widthUnitCO->currentIndex() > 0);
-
-       if (useHeight)
-               widthED->setValidator(unsignedLengthValidator(widthED));
-       else
-               widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
-
-       heightED->setEnabled(useHeight);
-       heightUnitCO->setEnabled(useHeight);
-       form_->changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QExternal
-//
-/////////////////////////////////////////////////////////////////////
-
-namespace {
-
-LyXLength::UNIT defaultUnit()
-{
-       LyXLength::UNIT default_unit = LyXLength::CM;
-       switch (lyxrc.default_papersize) {
-       case PAPER_USLETTER:
-       case PAPER_USLEGAL:
-       case PAPER_USEXECUTIVE:
-               default_unit = LyXLength::IN;
-               break;
-       default:
-               break;
-       }
-       return default_unit;
-}
-
-
-void setDisplay(QCheckBox & displayCB, QComboBox & showCO, QLineEdit & scaleED,
-               external::DisplayType display, unsigned int scale,
-               bool read_only)
-{
-       int item = 0;
-       switch (display) {
-       case external::DefaultDisplay:
-               item = 0;
-               break;
-       case external::MonochromeDisplay:
-               item = 1;
-               break;
-       case external::GrayscaleDisplay:
-               item = 2;
-               break;
-       case external::ColorDisplay:
-               item = 3;
-               break;
-       case external::PreviewDisplay:
-               item = 4;
-               break;
-       case external::NoDisplay:
-               item = 0;
-               break;
-       }
-
-       showCO.setCurrentIndex(item);
-       bool const no_display = display == external::NoDisplay;
-       showCO.setEnabled(!no_display && !read_only);
-       displayCB.setChecked(!no_display);
-       scaleED.setEnabled(!no_display && !read_only);
-       scaleED.setText(toqstr(convert<string>(scale)));
-}
-
-
-void getDisplay(external::DisplayType & display,
-               unsigned int & scale,
-               QCheckBox const & displayCB,
-               QComboBox const & showCO,
-               QLineEdit const & scaleED)
-{
-       switch (showCO.currentIndex()) {
-       case 0:
-               display = external::DefaultDisplay;
-               break;
-       case 1:
-               display = external::MonochromeDisplay;
-               break;
-       case 2:
-               display = external::GrayscaleDisplay;
-               break;
-       case 3:
-               display = external::ColorDisplay;
-               break;
-       case 4:
-               display = external::PreviewDisplay;
-               break;
-       }
-
-       if (!displayCB.isChecked())
-               display = external::NoDisplay;
-
-       scale = convert<int>(fromqstr(scaleED.text()));
-}
-
-
-void setRotation(QLineEdit & angleED, QComboBox & originCO,
-                external::RotationData const & data)
-{
-       originCO.setCurrentIndex(int(data.origin()));
-       angleED.setText(toqstr(data.angle));
-}
-
-
-void getRotation(external::RotationData & data,
-                QLineEdit const & angleED, QComboBox const & originCO)
-{
-       typedef external::RotationData::OriginType OriginType;
-
-       data.origin(static_cast<OriginType>(originCO.currentIndex()));
-       data.angle = fromqstr(angleED.text());
-}
-
-
-void setSize(QLineEdit & widthED, QComboBox & widthUnitCO,
-            QLineEdit & heightED, LengthCombo & heightUnitCO,
-            QCheckBox & aspectratioCB,
-            external::ResizeData const & data)
-{
-       bool using_scale = data.usingScale();
-       std::string scale = data.scale;
-       if (data.no_resize()) {
-               // Everything is zero, so default to this!
-               using_scale = true;
-               scale = "100";
-       }
-
-       if (using_scale) {
-               widthED.setText(toqstr(scale));
-               widthUnitCO.setCurrentIndex(0);
-       } else {
-               widthED.setText(toqstr(convert<string>(data.width.value())));
-               // Because 'Scale' is position 0...
-               // Note also that width cannot be zero here, so
-               // we don't need to worry about the default unit.
-               widthUnitCO.setCurrentIndex(data.width.unit() + 1);
-       }
-
-       string const h = data.height.zero() ? string() : data.height.asString();
-       LyXLength::UNIT default_unit = data.width.zero() ?
-               defaultUnit() : data.width.unit();
-       lengthToWidgets(&heightED, &heightUnitCO, h, default_unit);
-
-       heightED.setEnabled(!using_scale);
-       heightUnitCO.setEnabled(!using_scale);
-
-       aspectratioCB.setChecked(data.keepAspectRatio);
-
-       bool const disable_aspectRatio = using_scale ||
-               data.width.zero() || data.height.zero();
-       aspectratioCB.setEnabled(!disable_aspectRatio);
-}
-
-
-void getSize(external::ResizeData & data,
-            QLineEdit const & widthED, QComboBox const & widthUnitCO,
-            QLineEdit const & heightED, LengthCombo const & heightUnitCO,
-            QCheckBox const & aspectratioCB)
-{
-       string const width = fromqstr(widthED.text());
-
-       if (widthUnitCO.currentIndex() > 0) {
-               // Subtract one, because scale is 0.
-               int const unit = widthUnitCO.currentIndex() - 1;
-
-               LyXLength w;
-               if (isValidLength(width, &w))
-                       data.width = w;
-               else if (isStrDbl(width))
-                       data.width = LyXLength(convert<double>(width),
-                                          static_cast<LyXLength::UNIT>(unit));
-               else
-                       data.width = LyXLength();
-
-               data.scale = string();
-
-       } else {
-               // scaling instead of a width
-               data.scale = width;
-               data.width = LyXLength();
-       }
-
-       data.height = LyXLength(widgetsToLength(&heightED, &heightUnitCO));
-
-       data.keepAspectRatio = aspectratioCB.isChecked();
-}
-
-
-void setCrop(QCheckBox & clipCB,
-            QLineEdit & xlED, QLineEdit & ybED,
-            QLineEdit & xrED, QLineEdit & ytED,
-            external::ClipData const & data)
-{
-       clipCB.setChecked(data.clip);
-       graphics::BoundingBox const & bbox = data.bbox;
-       xlED.setText(toqstr(convert<string>(bbox.xl)));
-       ybED.setText(toqstr(convert<string>(bbox.yb)));
-       xrED.setText(toqstr(convert<string>(bbox.xr)));
-       ytED.setText(toqstr(convert<string>(bbox.yt)));
-}
-
-
-void getCrop(external::ClipData & data,
-            QCheckBox const & clipCB,
-            QLineEdit const & xlED, QLineEdit const & ybED,
-            QLineEdit const & xrED, QLineEdit const & ytED,
-            bool bb_changed)
-{
-       data.clip = clipCB.isChecked();
-
-       if (!bb_changed)
-               return;
-
-       data.bbox.xl = convert<int>(fromqstr(xlED.text()));
-       data.bbox.yb = convert<int>(fromqstr(ybED.text()));
-       data.bbox.xr = convert<int>(fromqstr(xrED.text()));
-       data.bbox.yt = convert<int>(fromqstr(ytED.text()));
-}
-
-
-void getExtra(external::ExtraData & data,
-             QExternal::MapType const & extra)
-{
-       typedef QExternal::MapType MapType;
-       MapType::const_iterator it  = extra.begin();
-       MapType::const_iterator const end = extra.end();
-       for (; it != end; ++it)
-               data.set(it->first, trim(fromqstr(it->second)));
-}
-
-} // namespace anon
-
-
-typedef QController<ControlExternal, QView<QExternalDialog> >
-       ExternalBase;
-
-QExternal::QExternal(Dialog & parent)
-       : ExternalBase(parent, _("External Material"))
-{}
-
-
-void QExternal::build_dialog()
-{
-       dialog_.reset(new QExternalDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-
-       bcview().addReadOnly(dialog_->fileED);
-       bcview().addReadOnly(dialog_->browsePB);
-       bcview().addReadOnly(dialog_->editPB);
-       bcview().addReadOnly(dialog_->externalCO);
-       bcview().addReadOnly(dialog_->draftCB);
-       bcview().addReadOnly(dialog_->displayscaleED);
-       bcview().addReadOnly(dialog_->showCO);
-       bcview().addReadOnly(dialog_->displayCB);
-       bcview().addReadOnly(dialog_->angleED);
-       bcview().addReadOnly(dialog_->originCO);
-       bcview().addReadOnly(dialog_->heightUnitCO);
-       bcview().addReadOnly(dialog_->heightED);
-       bcview().addReadOnly(dialog_->aspectratioCB);
-       bcview().addReadOnly(dialog_->widthUnitCO);
-       bcview().addReadOnly(dialog_->widthED);
-       bcview().addReadOnly(dialog_->clipCB);
-       bcview().addReadOnly(dialog_->getbbPB);
-       bcview().addReadOnly(dialog_->ytED);
-       bcview().addReadOnly(dialog_->xlED);
-       bcview().addReadOnly(dialog_->xrED);
-       bcview().addReadOnly(dialog_->ybED);
-       bcview().addReadOnly(dialog_->extraFormatCO);
-       bcview().addReadOnly(dialog_->extraED);
-
-       addCheckedLineEdit(bcview(), dialog_->angleED, dialog_->angleLA);
-       addCheckedLineEdit(bcview(), dialog_->displayscaleED, dialog_->scaleLA);
-       addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
-       addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
-       addCheckedLineEdit(bcview(), dialog_->xlED, dialog_->lbLA);
-       addCheckedLineEdit(bcview(), dialog_->ybED, dialog_->lbLA);
-       addCheckedLineEdit(bcview(), dialog_->xrED, dialog_->rtLA);
-       addCheckedLineEdit(bcview(), dialog_->ytED, dialog_->rtLA);
-       addCheckedLineEdit(bcview(), dialog_->fileED, dialog_->fileLA);
-
-       std::vector<string> templates(controller().getTemplates());
-
-       for (std::vector<string>::const_iterator cit = templates.begin();
-               cit != templates.end(); ++cit) {
-               dialog_->externalCO->addItem(toqstr(*cit));
-       }
-
-       // Fill the origins combo
-       typedef vector<external::RotationDataType> Origins;
-       Origins const & all_origins = external::all_origins();
-       for (Origins::size_type i = 0; i != all_origins.size(); ++i)
-               dialog_->originCO->addItem(toqstr(external::origin_gui_str(i)));
-
-       // Fill the width combo
-       dialog_->widthUnitCO->addItem(qt_("Scale%"));
-       for (int i = 0; i < num_units; i++)
-               dialog_->widthUnitCO->addItem(qt_(unit_name_gui[i]));
-}
-
-
-void QExternal::update_contents()
-{
-       PathValidator * path_validator = getPathValidator(dialog_->fileED);
-       if (path_validator)
-               path_validator->setChecker(kernel().docType(), lyxrc);
-
-       dialog_->tab->setCurrentIndex(0);
-       InsetExternalParams const & params = controller().params();
-
-       string const name =
-               params.filename.outputFilename(kernel().bufferFilepath());
-       dialog_->fileED->setText(toqstr(name));
-
-       dialog_->externalCO->setCurrentIndex(
-               controller().getTemplateNumber(params.templatename()));
-       updateTemplate();
-
-       dialog_->draftCB->setChecked(params.draft);
-
-       setDisplay(*dialog_->displayCB, *dialog_->showCO,
-                  *dialog_->displayscaleED,
-                  params.display, params.lyxscale, readOnly());
-
-       setRotation(*dialog_->angleED, *dialog_->originCO, params.rotationdata);
-
-       setSize(*dialog_->widthED, *dialog_->widthUnitCO,
-               *dialog_->heightED, *dialog_->heightUnitCO,
-               *dialog_->aspectratioCB,
-               params.resizedata);
-
-       setCrop(*dialog_->clipCB,
-               *dialog_->xlED, *dialog_->ybED,
-               *dialog_->xrED, *dialog_->ytED,
-               params.clipdata);
-       controller().bbChanged(!params.clipdata.bbox.empty());
-
-       isValid();
-}
-
-
-void QExternal::updateTemplate()
-{
-       external::Template templ =
-               controller().getTemplate(dialog_->externalCO->currentIndex());
-       dialog_->externalTB->setPlainText(toqstr(templ.helpText));
-
-       // Ascertain which (if any) transformations the template supports
-       // and disable tabs hosting unsupported transforms.
-       typedef vector<external::TransformID> TransformIDs;
-       TransformIDs const transformIds = templ.transformIds;
-       TransformIDs::const_iterator tr_begin = transformIds.begin();
-       TransformIDs::const_iterator const tr_end = transformIds.end();
-
-       bool found = find(tr_begin, tr_end, external::Rotate) != tr_end;
-       dialog_->tab->setTabEnabled(
-               dialog_->tab->indexOf(dialog_->rotatetab), found);
-       found = find(tr_begin, tr_end, external::Resize) != tr_end;
-       dialog_->tab->setTabEnabled(
-               dialog_->tab->indexOf(dialog_->scaletab), found);
-
-       found = find(tr_begin, tr_end, external::Clip) != tr_end;
-       dialog_->tab->setTabEnabled(
-               dialog_->tab->indexOf(dialog_->croptab), found);
-
-       found = find(tr_begin, tr_end, external::Extra) != tr_end;
-       dialog_->tab->setTabEnabled(
-               dialog_->tab->indexOf(dialog_->optionstab), found);
-
-       if (!found)
-               return;
-
-       // Ascertain whether the template has any formats supporting
-       // the 'Extra' option
-       QLineEdit * const extraED = dialog_->extraED;
-       QComboBox * const extraCB = dialog_->extraFormatCO;
-
-       extra_.clear();
-       extraED->clear();
-       extraCB->clear();
-
-       external::Template::Formats::const_iterator it  = templ.formats.begin();
-       external::Template::Formats::const_iterator end = templ.formats.end();
-       for (; it != end; ++it) {
-               if (it->second.option_transformers.find(external::Extra) ==
-                   it->second.option_transformers.end())
-                       continue;
-               string const format = it->first;
-               string const opt = controller().params().extradata.get(format);
-               extraCB->addItem(toqstr(format));
-               extra_[format] = toqstr(opt);
-       }
-
-       bool const enabled = extraCB->count()  > 0;
-
-       dialog_->tab->setTabEnabled(
-               dialog_->tab->indexOf(dialog_->optionstab), enabled);
-       extraED->setEnabled(enabled && !kernel().isBufferReadonly());
-       extraCB->setEnabled(enabled);
-
-       if (enabled) {
-               extraCB->setCurrentIndex(0);
-               extraED->setText(extra_[fromqstr(extraCB->currentText())]);
-       }
-}
-
-
-void QExternal::apply()
-{
-       InsetExternalParams params = controller().params();
-
-       params.filename.set(internal_path(fromqstr(dialog_->fileED->text())),
-                           kernel().bufferFilepath());
-
-       params.settemplate(controller().getTemplate(
-                                  dialog_->externalCO->currentIndex()).lyxName);
-
-       params.draft = dialog_->draftCB->isChecked();
-
-       getDisplay(params.display, params.lyxscale,
-                  *dialog_->displayCB, *dialog_->showCO,
-                  *dialog_->displayscaleED);
-
-       if (dialog_->tab->isTabEnabled(
-               dialog_->tab->indexOf(dialog_->rotatetab)))
-               getRotation(params.rotationdata,
-                           *dialog_->angleED, *dialog_->originCO);
-
-       if (dialog_->tab->isTabEnabled(
-               dialog_->tab->indexOf(dialog_->scaletab)))
-               getSize(params.resizedata,
-                       *dialog_->widthED, *dialog_->widthUnitCO,
-                       *dialog_->heightED, *dialog_->heightUnitCO,
-                       *dialog_->aspectratioCB);
-
-       if (dialog_->tab->isTabEnabled(
-               dialog_->tab->indexOf(dialog_->croptab)))
-               getCrop(params.clipdata,
-                       *dialog_->clipCB,
-                       *dialog_->xlED, *dialog_->ybED,
-                       *dialog_->xrED, *dialog_->ytED,
-                       controller().bbChanged());
-
-       if (dialog_->tab->isTabEnabled(
-               dialog_->tab->indexOf(dialog_->optionstab)))
-               getExtra(params.extradata, extra_);
-
-       controller().setParams(params);
-}
-
-
-void QExternal::getBB()
-{
-       dialog_->xlED->setText("0");
-       dialog_->ybED->setText("0");
-       dialog_->xrED->setText("0");
-       dialog_->ytED->setText("0");
-
-       string const filename = fromqstr(dialog_->fileED->text());
-       if (filename.empty())
-               return;
-
-       string const bb = controller().readBB(filename);
-       if (bb.empty())
-               return;
-
-       dialog_->xlED->setText(toqstr(token(bb, ' ', 0)));
-       dialog_->ybED->setText(toqstr(token(bb, ' ', 1)));
-       dialog_->xrED->setText(toqstr(token(bb, ' ', 2)));
-       dialog_->ytED->setText(toqstr(token(bb, ' ', 3)));
-
-       controller().bbChanged(false);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QExternal_moc.cpp"
diff --git a/src/frontends/qt4/QExternal.cpp b/src/frontends/qt4/QExternal.cpp
new file mode 100644 (file)
index 0000000..d33d91c
--- /dev/null
@@ -0,0 +1,737 @@
+/**
+ * \file QExternal.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+// Qt defines a macro 'signals' that clashes with a boost namespace.
+// All is well if the namespace is visible first.
+#include "lengthcommon.h"
+#include "lyxrc.h"
+
+#include "controllers/ControlExternal.h"
+#include "controllers/ButtonController.h"
+
+#include "insets/ExternalTemplate.h"
+#include "insets/InsetExternal.h"
+
+#include "support/lstrings.h"
+#include "support/convert.h"
+#include "support/os.h"
+#include "support/lyxlib.h"
+
+#include "QExternal.h"
+#include "Qt2BC.h"
+
+#include "CheckedLineEdit.h"
+#include "LengthCombo.h"
+#include "qt_helpers.h"
+#include "Validator.h"
+
+#include <QLineEdit>
+#include <QPushButton>
+#include <QCheckBox>
+#include <QTabWidget>
+#include <QTextBrowser>
+
+namespace external = lyx::external;
+
+using lyx::support::isStrDbl;
+using lyx::support::token;
+using lyx::support::trim;
+using lyx::support::float_equal;
+
+using lyx::support::os::internal_path;
+
+using std::string;
+using std::vector;
+using std::find;
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QExternalDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+QExternalDialog::QExternalDialog(QExternal * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(displayCB, SIGNAL(toggled(bool)),
+               showCO, SLOT(setEnabled(bool)));
+       connect(displayCB, SIGNAL(toggled(bool)),
+               displayscaleED, SLOT(setEnabled(bool)));
+       connect(showCO, SIGNAL(activated(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(originCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(aspectratioCB, SIGNAL(stateChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(browsePB, SIGNAL(clicked()),
+               this, SLOT(browseClicked()));
+       connect(editPB, SIGNAL(clicked()),
+               this, SLOT(editClicked()));
+       connect(externalCO, SIGNAL(activated(const QString&)),
+               this, SLOT(templateChanged()));
+       connect(extraED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(extraChanged(const QString&)));
+       connect(extraFormatCO, SIGNAL(activated(const QString&)),
+               this, SLOT(formatChanged(const QString&)));
+       connect(widthUnitCO, SIGNAL(activated(int)),
+               this, SLOT(widthUnitChanged()));
+       connect(heightUnitCO, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(change_adaptor()));
+       connect(displayCB, SIGNAL(stateChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(displayscaleED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(angleED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(widthED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(sizeChanged()));
+       connect(heightED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(sizeChanged()));
+       connect(fileED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(clipCB, SIGNAL(stateChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(getbbPB, SIGNAL(clicked()), this, SLOT(getbbClicked()));
+       connect(xrED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
+       connect(ytED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
+       connect(xlED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
+       connect(ybED, SIGNAL(textChanged(const QString&)), this, SLOT(bbChanged()));
+       connect(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+
+       QIntValidator * validator = new QIntValidator(displayscaleED);
+       validator->setBottom(1);
+       displayscaleED->setValidator(validator);
+
+       angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
+
+       xlED->setValidator(new QIntValidator(xlED));
+       ybED->setValidator(new QIntValidator(ybED));
+       xrED->setValidator(new QIntValidator(xrED));
+       ytED->setValidator(new QIntValidator(ytED));
+
+       widthED->setValidator(unsignedLengthValidator(widthED));
+       heightED->setValidator(unsignedLengthValidator(heightED));
+
+       fileED->setValidator(new PathValidator(true, fileED));
+       setFocusProxy(fileED);
+}
+
+
+void QExternalDialog::show()
+{
+       QDialog::show();
+}
+
+
+
+bool QExternalDialog::activateAspectratio() const
+{
+       if (widthUnitCO->currentIndex() == 0)
+               return false;
+
+       string const wstr = fromqstr(widthED->text());
+       if (wstr.empty())
+               return false;
+       bool const wIsDbl = isStrDbl(wstr);
+       if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
+               return false;
+       LyXLength l;
+       if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
+               return false;
+
+       string const hstr = fromqstr(heightED->text());
+       if (hstr.empty())
+               return false;
+       bool const hIsDbl = isStrDbl(hstr);
+       if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
+               return false;
+       if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
+               return false;
+
+       return true;
+}
+
+
+void QExternalDialog::bbChanged()
+{
+       form_->controller().bbChanged(true);
+       form_->changed();
+}
+
+
+void QExternalDialog::browseClicked()
+{
+       int const choice =  externalCO->currentIndex();
+       docstring const template_name = 
+               from_utf8(form_->controller().getTemplate(choice).lyxName);
+       docstring const str =
+               form_->controller().browse(qstring_to_ucs4(fileED->text()),
+                                          template_name);
+       fileED->setText(toqstr(str));
+       form_->changed();
+}
+
+
+void QExternalDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QExternalDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QExternalDialog::editClicked()
+{
+       form_->controller().editExternal();
+}
+
+
+
+void QExternalDialog::extraChanged(const QString& text)
+{
+       std::string const format = fromqstr(extraFormatCO->currentText());
+       form_->extra_[format] = text;
+       form_->changed();
+}
+
+
+void QExternalDialog::formatChanged(const QString& format)
+{
+       extraED->setText(form_->extra_[fromqstr(format)]);
+}
+
+
+void QExternalDialog::getbbClicked()
+{
+       form_->getBB();
+}
+
+
+void QExternalDialog::sizeChanged()
+{
+       aspectratioCB->setEnabled(activateAspectratio());
+       form_->changed();
+}
+
+
+void QExternalDialog::templateChanged()
+{
+       form_->updateTemplate();
+       form_->changed();
+}
+
+
+void QExternalDialog::widthUnitChanged()
+{
+       bool useHeight = (widthUnitCO->currentIndex() > 0);
+
+       if (useHeight)
+               widthED->setValidator(unsignedLengthValidator(widthED));
+       else
+               widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
+
+       heightED->setEnabled(useHeight);
+       heightUnitCO->setEnabled(useHeight);
+       form_->changed();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QExternal
+//
+/////////////////////////////////////////////////////////////////////
+
+namespace {
+
+LyXLength::UNIT defaultUnit()
+{
+       LyXLength::UNIT default_unit = LyXLength::CM;
+       switch (lyxrc.default_papersize) {
+       case PAPER_USLETTER:
+       case PAPER_USLEGAL:
+       case PAPER_USEXECUTIVE:
+               default_unit = LyXLength::IN;
+               break;
+       default:
+               break;
+       }
+       return default_unit;
+}
+
+
+void setDisplay(QCheckBox & displayCB, QComboBox & showCO, QLineEdit & scaleED,
+               external::DisplayType display, unsigned int scale,
+               bool read_only)
+{
+       int item = 0;
+       switch (display) {
+       case external::DefaultDisplay:
+               item = 0;
+               break;
+       case external::MonochromeDisplay:
+               item = 1;
+               break;
+       case external::GrayscaleDisplay:
+               item = 2;
+               break;
+       case external::ColorDisplay:
+               item = 3;
+               break;
+       case external::PreviewDisplay:
+               item = 4;
+               break;
+       case external::NoDisplay:
+               item = 0;
+               break;
+       }
+
+       showCO.setCurrentIndex(item);
+       bool const no_display = display == external::NoDisplay;
+       showCO.setEnabled(!no_display && !read_only);
+       displayCB.setChecked(!no_display);
+       scaleED.setEnabled(!no_display && !read_only);
+       scaleED.setText(toqstr(convert<string>(scale)));
+}
+
+
+void getDisplay(external::DisplayType & display,
+               unsigned int & scale,
+               QCheckBox const & displayCB,
+               QComboBox const & showCO,
+               QLineEdit const & scaleED)
+{
+       switch (showCO.currentIndex()) {
+       case 0:
+               display = external::DefaultDisplay;
+               break;
+       case 1:
+               display = external::MonochromeDisplay;
+               break;
+       case 2:
+               display = external::GrayscaleDisplay;
+               break;
+       case 3:
+               display = external::ColorDisplay;
+               break;
+       case 4:
+               display = external::PreviewDisplay;
+               break;
+       }
+
+       if (!displayCB.isChecked())
+               display = external::NoDisplay;
+
+       scale = convert<int>(fromqstr(scaleED.text()));
+}
+
+
+void setRotation(QLineEdit & angleED, QComboBox & originCO,
+                external::RotationData const & data)
+{
+       originCO.setCurrentIndex(int(data.origin()));
+       angleED.setText(toqstr(data.angle));
+}
+
+
+void getRotation(external::RotationData & data,
+                QLineEdit const & angleED, QComboBox const & originCO)
+{
+       typedef external::RotationData::OriginType OriginType;
+
+       data.origin(static_cast<OriginType>(originCO.currentIndex()));
+       data.angle = fromqstr(angleED.text());
+}
+
+
+void setSize(QLineEdit & widthED, QComboBox & widthUnitCO,
+            QLineEdit & heightED, LengthCombo & heightUnitCO,
+            QCheckBox & aspectratioCB,
+            external::ResizeData const & data)
+{
+       bool using_scale = data.usingScale();
+       std::string scale = data.scale;
+       if (data.no_resize()) {
+               // Everything is zero, so default to this!
+               using_scale = true;
+               scale = "100";
+       }
+
+       if (using_scale) {
+               widthED.setText(toqstr(scale));
+               widthUnitCO.setCurrentIndex(0);
+       } else {
+               widthED.setText(toqstr(convert<string>(data.width.value())));
+               // Because 'Scale' is position 0...
+               // Note also that width cannot be zero here, so
+               // we don't need to worry about the default unit.
+               widthUnitCO.setCurrentIndex(data.width.unit() + 1);
+       }
+
+       string const h = data.height.zero() ? string() : data.height.asString();
+       LyXLength::UNIT default_unit = data.width.zero() ?
+               defaultUnit() : data.width.unit();
+       lengthToWidgets(&heightED, &heightUnitCO, h, default_unit);
+
+       heightED.setEnabled(!using_scale);
+       heightUnitCO.setEnabled(!using_scale);
+
+       aspectratioCB.setChecked(data.keepAspectRatio);
+
+       bool const disable_aspectRatio = using_scale ||
+               data.width.zero() || data.height.zero();
+       aspectratioCB.setEnabled(!disable_aspectRatio);
+}
+
+
+void getSize(external::ResizeData & data,
+            QLineEdit const & widthED, QComboBox const & widthUnitCO,
+            QLineEdit const & heightED, LengthCombo const & heightUnitCO,
+            QCheckBox const & aspectratioCB)
+{
+       string const width = fromqstr(widthED.text());
+
+       if (widthUnitCO.currentIndex() > 0) {
+               // Subtract one, because scale is 0.
+               int const unit = widthUnitCO.currentIndex() - 1;
+
+               LyXLength w;
+               if (isValidLength(width, &w))
+                       data.width = w;
+               else if (isStrDbl(width))
+                       data.width = LyXLength(convert<double>(width),
+                                          static_cast<LyXLength::UNIT>(unit));
+               else
+                       data.width = LyXLength();
+
+               data.scale = string();
+
+       } else {
+               // scaling instead of a width
+               data.scale = width;
+               data.width = LyXLength();
+       }
+
+       data.height = LyXLength(widgetsToLength(&heightED, &heightUnitCO));
+
+       data.keepAspectRatio = aspectratioCB.isChecked();
+}
+
+
+void setCrop(QCheckBox & clipCB,
+            QLineEdit & xlED, QLineEdit & ybED,
+            QLineEdit & xrED, QLineEdit & ytED,
+            external::ClipData const & data)
+{
+       clipCB.setChecked(data.clip);
+       graphics::BoundingBox const & bbox = data.bbox;
+       xlED.setText(toqstr(convert<string>(bbox.xl)));
+       ybED.setText(toqstr(convert<string>(bbox.yb)));
+       xrED.setText(toqstr(convert<string>(bbox.xr)));
+       ytED.setText(toqstr(convert<string>(bbox.yt)));
+}
+
+
+void getCrop(external::ClipData & data,
+            QCheckBox const & clipCB,
+            QLineEdit const & xlED, QLineEdit const & ybED,
+            QLineEdit const & xrED, QLineEdit const & ytED,
+            bool bb_changed)
+{
+       data.clip = clipCB.isChecked();
+
+       if (!bb_changed)
+               return;
+
+       data.bbox.xl = convert<int>(fromqstr(xlED.text()));
+       data.bbox.yb = convert<int>(fromqstr(ybED.text()));
+       data.bbox.xr = convert<int>(fromqstr(xrED.text()));
+       data.bbox.yt = convert<int>(fromqstr(ytED.text()));
+}
+
+
+void getExtra(external::ExtraData & data,
+             QExternal::MapType const & extra)
+{
+       typedef QExternal::MapType MapType;
+       MapType::const_iterator it  = extra.begin();
+       MapType::const_iterator const end = extra.end();
+       for (; it != end; ++it)
+               data.set(it->first, trim(fromqstr(it->second)));
+}
+
+} // namespace anon
+
+
+typedef QController<ControlExternal, QView<QExternalDialog> >
+       ExternalBase;
+
+QExternal::QExternal(Dialog & parent)
+       : ExternalBase(parent, _("External Material"))
+{}
+
+
+void QExternal::build_dialog()
+{
+       dialog_.reset(new QExternalDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+
+       bcview().addReadOnly(dialog_->fileED);
+       bcview().addReadOnly(dialog_->browsePB);
+       bcview().addReadOnly(dialog_->editPB);
+       bcview().addReadOnly(dialog_->externalCO);
+       bcview().addReadOnly(dialog_->draftCB);
+       bcview().addReadOnly(dialog_->displayscaleED);
+       bcview().addReadOnly(dialog_->showCO);
+       bcview().addReadOnly(dialog_->displayCB);
+       bcview().addReadOnly(dialog_->angleED);
+       bcview().addReadOnly(dialog_->originCO);
+       bcview().addReadOnly(dialog_->heightUnitCO);
+       bcview().addReadOnly(dialog_->heightED);
+       bcview().addReadOnly(dialog_->aspectratioCB);
+       bcview().addReadOnly(dialog_->widthUnitCO);
+       bcview().addReadOnly(dialog_->widthED);
+       bcview().addReadOnly(dialog_->clipCB);
+       bcview().addReadOnly(dialog_->getbbPB);
+       bcview().addReadOnly(dialog_->ytED);
+       bcview().addReadOnly(dialog_->xlED);
+       bcview().addReadOnly(dialog_->xrED);
+       bcview().addReadOnly(dialog_->ybED);
+       bcview().addReadOnly(dialog_->extraFormatCO);
+       bcview().addReadOnly(dialog_->extraED);
+
+       addCheckedLineEdit(bcview(), dialog_->angleED, dialog_->angleLA);
+       addCheckedLineEdit(bcview(), dialog_->displayscaleED, dialog_->scaleLA);
+       addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
+       addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
+       addCheckedLineEdit(bcview(), dialog_->xlED, dialog_->lbLA);
+       addCheckedLineEdit(bcview(), dialog_->ybED, dialog_->lbLA);
+       addCheckedLineEdit(bcview(), dialog_->xrED, dialog_->rtLA);
+       addCheckedLineEdit(bcview(), dialog_->ytED, dialog_->rtLA);
+       addCheckedLineEdit(bcview(), dialog_->fileED, dialog_->fileLA);
+
+       std::vector<string> templates(controller().getTemplates());
+
+       for (std::vector<string>::const_iterator cit = templates.begin();
+               cit != templates.end(); ++cit) {
+               dialog_->externalCO->addItem(toqstr(*cit));
+       }
+
+       // Fill the origins combo
+       typedef vector<external::RotationDataType> Origins;
+       Origins const & all_origins = external::all_origins();
+       for (Origins::size_type i = 0; i != all_origins.size(); ++i)
+               dialog_->originCO->addItem(toqstr(external::origin_gui_str(i)));
+
+       // Fill the width combo
+       dialog_->widthUnitCO->addItem(qt_("Scale%"));
+       for (int i = 0; i < num_units; i++)
+               dialog_->widthUnitCO->addItem(qt_(unit_name_gui[i]));
+}
+
+
+void QExternal::update_contents()
+{
+       PathValidator * path_validator = getPathValidator(dialog_->fileED);
+       if (path_validator)
+               path_validator->setChecker(kernel().docType(), lyxrc);
+
+       dialog_->tab->setCurrentIndex(0);
+       InsetExternalParams const & params = controller().params();
+
+       string const name =
+               params.filename.outputFilename(kernel().bufferFilepath());
+       dialog_->fileED->setText(toqstr(name));
+
+       dialog_->externalCO->setCurrentIndex(
+               controller().getTemplateNumber(params.templatename()));
+       updateTemplate();
+
+       dialog_->draftCB->setChecked(params.draft);
+
+       setDisplay(*dialog_->displayCB, *dialog_->showCO,
+                  *dialog_->displayscaleED,
+                  params.display, params.lyxscale, readOnly());
+
+       setRotation(*dialog_->angleED, *dialog_->originCO, params.rotationdata);
+
+       setSize(*dialog_->widthED, *dialog_->widthUnitCO,
+               *dialog_->heightED, *dialog_->heightUnitCO,
+               *dialog_->aspectratioCB,
+               params.resizedata);
+
+       setCrop(*dialog_->clipCB,
+               *dialog_->xlED, *dialog_->ybED,
+               *dialog_->xrED, *dialog_->ytED,
+               params.clipdata);
+       controller().bbChanged(!params.clipdata.bbox.empty());
+
+       isValid();
+}
+
+
+void QExternal::updateTemplate()
+{
+       external::Template templ =
+               controller().getTemplate(dialog_->externalCO->currentIndex());
+       dialog_->externalTB->setPlainText(toqstr(templ.helpText));
+
+       // Ascertain which (if any) transformations the template supports
+       // and disable tabs hosting unsupported transforms.
+       typedef vector<external::TransformID> TransformIDs;
+       TransformIDs const transformIds = templ.transformIds;
+       TransformIDs::const_iterator tr_begin = transformIds.begin();
+       TransformIDs::const_iterator const tr_end = transformIds.end();
+
+       bool found = find(tr_begin, tr_end, external::Rotate) != tr_end;
+       dialog_->tab->setTabEnabled(
+               dialog_->tab->indexOf(dialog_->rotatetab), found);
+       found = find(tr_begin, tr_end, external::Resize) != tr_end;
+       dialog_->tab->setTabEnabled(
+               dialog_->tab->indexOf(dialog_->scaletab), found);
+
+       found = find(tr_begin, tr_end, external::Clip) != tr_end;
+       dialog_->tab->setTabEnabled(
+               dialog_->tab->indexOf(dialog_->croptab), found);
+
+       found = find(tr_begin, tr_end, external::Extra) != tr_end;
+       dialog_->tab->setTabEnabled(
+               dialog_->tab->indexOf(dialog_->optionstab), found);
+
+       if (!found)
+               return;
+
+       // Ascertain whether the template has any formats supporting
+       // the 'Extra' option
+       QLineEdit * const extraED = dialog_->extraED;
+       QComboBox * const extraCB = dialog_->extraFormatCO;
+
+       extra_.clear();
+       extraED->clear();
+       extraCB->clear();
+
+       external::Template::Formats::const_iterator it  = templ.formats.begin();
+       external::Template::Formats::const_iterator end = templ.formats.end();
+       for (; it != end; ++it) {
+               if (it->second.option_transformers.find(external::Extra) ==
+                   it->second.option_transformers.end())
+                       continue;
+               string const format = it->first;
+               string const opt = controller().params().extradata.get(format);
+               extraCB->addItem(toqstr(format));
+               extra_[format] = toqstr(opt);
+       }
+
+       bool const enabled = extraCB->count()  > 0;
+
+       dialog_->tab->setTabEnabled(
+               dialog_->tab->indexOf(dialog_->optionstab), enabled);
+       extraED->setEnabled(enabled && !kernel().isBufferReadonly());
+       extraCB->setEnabled(enabled);
+
+       if (enabled) {
+               extraCB->setCurrentIndex(0);
+               extraED->setText(extra_[fromqstr(extraCB->currentText())]);
+       }
+}
+
+
+void QExternal::apply()
+{
+       InsetExternalParams params = controller().params();
+
+       params.filename.set(internal_path(fromqstr(dialog_->fileED->text())),
+                           kernel().bufferFilepath());
+
+       params.settemplate(controller().getTemplate(
+                                  dialog_->externalCO->currentIndex()).lyxName);
+
+       params.draft = dialog_->draftCB->isChecked();
+
+       getDisplay(params.display, params.lyxscale,
+                  *dialog_->displayCB, *dialog_->showCO,
+                  *dialog_->displayscaleED);
+
+       if (dialog_->tab->isTabEnabled(
+               dialog_->tab->indexOf(dialog_->rotatetab)))
+               getRotation(params.rotationdata,
+                           *dialog_->angleED, *dialog_->originCO);
+
+       if (dialog_->tab->isTabEnabled(
+               dialog_->tab->indexOf(dialog_->scaletab)))
+               getSize(params.resizedata,
+                       *dialog_->widthED, *dialog_->widthUnitCO,
+                       *dialog_->heightED, *dialog_->heightUnitCO,
+                       *dialog_->aspectratioCB);
+
+       if (dialog_->tab->isTabEnabled(
+               dialog_->tab->indexOf(dialog_->croptab)))
+               getCrop(params.clipdata,
+                       *dialog_->clipCB,
+                       *dialog_->xlED, *dialog_->ybED,
+                       *dialog_->xrED, *dialog_->ytED,
+                       controller().bbChanged());
+
+       if (dialog_->tab->isTabEnabled(
+               dialog_->tab->indexOf(dialog_->optionstab)))
+               getExtra(params.extradata, extra_);
+
+       controller().setParams(params);
+}
+
+
+void QExternal::getBB()
+{
+       dialog_->xlED->setText("0");
+       dialog_->ybED->setText("0");
+       dialog_->xrED->setText("0");
+       dialog_->ytED->setText("0");
+
+       string const filename = fromqstr(dialog_->fileED->text());
+       if (filename.empty())
+               return;
+
+       string const bb = controller().readBB(filename);
+       if (bb.empty())
+               return;
+
+       dialog_->xlED->setText(toqstr(token(bb, ' ', 0)));
+       dialog_->ybED->setText(toqstr(token(bb, ' ', 1)));
+       dialog_->xrED->setText(toqstr(token(bb, ' ', 2)));
+       dialog_->ytED->setText(toqstr(token(bb, ' ', 3)));
+
+       controller().bbChanged(false);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QExternal_moc.cpp"
diff --git a/src/frontends/qt4/QFloat.C b/src/frontends/qt4/QFloat.C
deleted file mode 100644 (file)
index c3e2c14..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * \file QFloat.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QFloat.h"
-#include "QFloatDialog.h"
-#include "Qt2BC.h"
-#include "FloatPlacement.h"
-
-#include "controllers/ControlFloat.h"
-
-#include "insets/InsetFloat.h"
-
-#include <QPushButton>
-
-namespace lyx {
-namespace frontend {
-
-typedef QController<ControlFloat, QView<QFloatDialog> > float_base_class;
-
-
-QFloat::QFloat(Dialog & parent)
-       : float_base_class(parent, _("Float Settings"))
-{
-}
-
-
-void QFloat::build_dialog()
-{
-       dialog_.reset(new QFloatDialog(this));
-
-       bcview().setCancel(dialog_->closePB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setOK(dialog_->okPB);
-       bcview().setRestore(dialog_->restorePB);
-
-       bcview().addReadOnly(dialog_->floatFP);
-}
-
-
-void QFloat::update_contents()
-{
-       dialog_->floatFP->set(controller().params());
-}
-
-
-void QFloat::apply()
-{
-       InsetFloatParams & params = controller().params();
-
-       params.placement = dialog_->floatFP->get(params.wide, params.sideways);
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/QFloat.cpp b/src/frontends/qt4/QFloat.cpp
new file mode 100644 (file)
index 0000000..c3e2c14
--- /dev/null
@@ -0,0 +1,63 @@
+/**
+ * \file QFloat.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QFloat.h"
+#include "QFloatDialog.h"
+#include "Qt2BC.h"
+#include "FloatPlacement.h"
+
+#include "controllers/ControlFloat.h"
+
+#include "insets/InsetFloat.h"
+
+#include <QPushButton>
+
+namespace lyx {
+namespace frontend {
+
+typedef QController<ControlFloat, QView<QFloatDialog> > float_base_class;
+
+
+QFloat::QFloat(Dialog & parent)
+       : float_base_class(parent, _("Float Settings"))
+{
+}
+
+
+void QFloat::build_dialog()
+{
+       dialog_.reset(new QFloatDialog(this));
+
+       bcview().setCancel(dialog_->closePB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setOK(dialog_->okPB);
+       bcview().setRestore(dialog_->restorePB);
+
+       bcview().addReadOnly(dialog_->floatFP);
+}
+
+
+void QFloat::update_contents()
+{
+       dialog_->floatFP->set(controller().params());
+}
+
+
+void QFloat::apply()
+{
+       InsetFloatParams & params = controller().params();
+
+       params.placement = dialog_->floatFP->get(params.wide, params.sideways);
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/QFloatDialog.C b/src/frontends/qt4/QFloatDialog.C
deleted file mode 100644 (file)
index c32ba45..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * \file QFloatDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QFloatDialog.h"
-#include "QFloat.h"
-
-#include <QCloseEvent>
-#include <QPushButton>
-
-#include "FloatPlacement.h"
-
-
-
-namespace lyx {
-namespace frontend {
-
-QFloatDialog::QFloatDialog(QFloat * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(restorePB, SIGNAL(clicked()),
-               form, SLOT(slotRestore()));
-       connect(okPB, SIGNAL(clicked()),
-               form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()),
-               form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-
-       // enable span columns checkbox
-       floatFP->useWide();
-
-       // enable sideways checkbox
-       floatFP->useSideways();
-
-       connect(floatFP, SIGNAL(changed()),
-               this, SLOT(change_adaptor()));
-}
-
-
-void QFloatDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QFloatDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QFloatDialog_moc.cpp"
diff --git a/src/frontends/qt4/QFloatDialog.cpp b/src/frontends/qt4/QFloatDialog.cpp
new file mode 100644 (file)
index 0000000..c32ba45
--- /dev/null
@@ -0,0 +1,65 @@
+/**
+ * \file QFloatDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QFloatDialog.h"
+#include "QFloat.h"
+
+#include <QCloseEvent>
+#include <QPushButton>
+
+#include "FloatPlacement.h"
+
+
+
+namespace lyx {
+namespace frontend {
+
+QFloatDialog::QFloatDialog(QFloat * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(restorePB, SIGNAL(clicked()),
+               form, SLOT(slotRestore()));
+       connect(okPB, SIGNAL(clicked()),
+               form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()),
+               form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+
+       // enable span columns checkbox
+       floatFP->useWide();
+
+       // enable sideways checkbox
+       floatFP->useSideways();
+
+       connect(floatFP, SIGNAL(changed()),
+               this, SLOT(change_adaptor()));
+}
+
+
+void QFloatDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QFloatDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QFloatDialog_moc.cpp"
diff --git a/src/frontends/qt4/QFontExample.cpp b/src/frontends/qt4/QFontExample.cpp
new file mode 100644 (file)
index 0000000..7ffffbd
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * \file QFontExample.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QFontExample.h"
+
+#include <QPainter>
+#include <QPaintEvent>
+
+
+//namespace lyx {
+
+void QFontExample::set(QFont const & font, QString const & text)
+{
+       font_ = font;
+       text_ = text;
+       update();
+}
+
+
+QSize QFontExample::sizeHint() const
+{
+       QFontMetrics m(font_);
+       return QSize(m.width(text_) + 10, m.ascent() + m.descent() + 6);
+}
+
+
+void QFontExample::paintEvent(QPaintEvent *)
+{
+       QPainter p;
+       QFontMetrics m(font_);
+
+       p.begin(this);
+       p.setFont(font_);
+       p.drawRect(0, 0, width() - 1, height() - 1);
+       p.drawText(5, 3 + m.ascent(), text_);
+       p.end();
+}
+
+
+//} // namespace lyx
diff --git a/src/frontends/qt4/QFontExample.h b/src/frontends/qt4/QFontExample.h
new file mode 100644 (file)
index 0000000..650c6fa
--- /dev/null
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+/**
+ * \file QFontExample.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef QT_QFONTEXAMPLE_H
+#define QT_QFONTEXAMPLE_H
+
+#include <QWidget>
+#include <QFont>
+#include <QString>
+
+class QPaintEvent;
+
+
+//namespace lyx {
+
+class QFontExample : public QWidget {
+
+public:
+       QFontExample(QWidget * parent)
+               : QWidget(parent) {}
+
+       void set(QFont const & font, QString const & text);
+
+       virtual QSize sizeHint() const;
+
+protected:
+       virtual void paintEvent(QPaintEvent * p);
+
+private:
+       QFont font_;
+       QString text_;
+};
+
+
+//} // namespace lyx
+
+#endif
diff --git a/src/frontends/qt4/QGraphics.C b/src/frontends/qt4/QGraphics.C
deleted file mode 100644 (file)
index 5e1e100..0000000
+++ /dev/null
@@ -1,418 +0,0 @@
-/**
- * \file QGraphics.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Edwin Leuven
- * \author Herbert Voß
- * \author Richard Heck
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QGraphics.h"
-
-#include "CheckedLineEdit.h"
-#include "LengthCombo.h"
-#include "QGraphicsDialog.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-#include "Validator.h"
-
-#include "lengthcommon.h"
-#include "lyxrc.h"
-
-#include "controllers/ControlGraphics.h"
-#include "controllers/frontend_helpers.h"
-
-#include "insets/InsetGraphicsParams.h"
-
-#include "support/convert.h"
-#include "support/lstrings.h"
-#include "support/lyxlib.h"
-#include "support/os.h"
-
-#include <QLineEdit>
-#include <QPushButton>
-#include <QCheckBox>
-#include <QLabel>
-
-#include <cmath>
-
-using lyx::support::float_equal;
-using lyx::support::token;
-
-using lyx::support::os::internal_path;
-
-#ifndef CXX_GLOBAL_CSTD
-using std::floor;
-#endif
-
-using std::vector;
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-typedef QController<ControlGraphics, QView<QGraphicsDialog> > graphics_base_class;
-
-QGraphics::QGraphics(Dialog & parent)
-       : graphics_base_class(parent, _("Graphics"))
-{
-}
-
-
-void QGraphics::build_dialog()
-{
-       dialog_.reset(new QGraphicsDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setRestore(dialog_->restorePB);
-       bcview().setCancel(dialog_->closePB);
-
-       bcview().addReadOnly(dialog_->latexoptions);
-       bcview().addReadOnly(dialog_->subfigure);
-       bcview().addReadOnly(dialog_->filenameL);
-       bcview().addReadOnly(dialog_->filename);
-       bcview().addReadOnly(dialog_->browsePB);
-       bcview().addReadOnly(dialog_->unzipCB);
-       bcview().addReadOnly(dialog_->bbFrame);
-       bcview().addReadOnly(dialog_->draftCB);
-       bcview().addReadOnly(dialog_->clip);
-       bcview().addReadOnly(dialog_->unzipCB);
-       bcview().addReadOnly(dialog_->displayGB);
-       bcview().addReadOnly(dialog_->sizeGB);
-       bcview().addReadOnly(dialog_->rotationGB);
-       bcview().addReadOnly(dialog_->latexoptions);
-       bcview().addReadOnly(dialog_->getPB);
-
-       // initialize the length validator
-       addCheckedLineEdit(bcview(), dialog_->Scale, dialog_->scaleCB);
-       addCheckedLineEdit(bcview(), dialog_->Width, dialog_->WidthCB);
-       addCheckedLineEdit(bcview(), dialog_->Height, dialog_->HeightCB);
-       addCheckedLineEdit(bcview(), dialog_->displayscale, dialog_->scaleLA);
-       addCheckedLineEdit(bcview(), dialog_->angle, dialog_->angleL);
-       addCheckedLineEdit(bcview(), dialog_->lbX, dialog_->xL);
-       addCheckedLineEdit(bcview(), dialog_->lbY, dialog_->yL);
-       addCheckedLineEdit(bcview(), dialog_->rtX, dialog_->xL_2);
-       addCheckedLineEdit(bcview(), dialog_->rtY, dialog_->yL_2);
-       addCheckedLineEdit(bcview(), dialog_->filename, dialog_->filenameL);
-}
-
-
-namespace {
-
-// returns the number of the string s in the vector v
-int getItemNo(vector<string> v, string const & s) {
-       vector<string>::const_iterator cit =
-                   find(v.begin(), v.end(), s);
-       return (cit != v.end()) ? int(cit - v.begin()) : 0;
-}
-
-}
-
-
-void QGraphics::update_contents()
-{
-       PathValidator * path_validator = getPathValidator(dialog_->filename);
-       if (path_validator)
-               path_validator->setChecker(kernel().docType(), lyxrc);
-
-       // clear and fill in the comboboxes
-       vector<string> const bb_units = frontend::getBBUnits();
-       dialog_->lbXunit->clear();
-       dialog_->lbYunit->clear();
-       dialog_->rtXunit->clear();
-       dialog_->rtYunit->clear();
-       for (vector<string>::const_iterator it = bb_units.begin();
-           it != bb_units.end(); ++it) {
-               dialog_->lbXunit->addItem(toqstr(*it));
-               dialog_->lbYunit->addItem(toqstr(*it));
-               dialog_->rtXunit->addItem(toqstr(*it));
-               dialog_->rtYunit->addItem(toqstr(*it));
-       }
-
-       InsetGraphicsParams & igp = controller().params();
-
-       // set the right default unit
-       LyXLength::UNIT unitDefault = LyXLength::CM;
-       switch (lyxrc.default_papersize) {
-               case PAPER_USLETTER:
-               case PAPER_USLEGAL:
-               case PAPER_USEXECUTIVE:
-                       unitDefault = LyXLength::IN;
-                       break;
-               default:
-                       break;
-       }
-
-       string const name =
-               igp.filename.outputFilename(kernel().bufferFilepath());
-       dialog_->filename->setText(toqstr(name));
-
-       // set the bounding box values
-       if (igp.bb.empty()) {
-               string const bb = controller().readBB(igp.filename.absFilename());
-               // the values from the file always have the bigpoint-unit bp
-               dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
-               dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
-               dialog_->rtX->setText(toqstr(token(bb, ' ', 2)));
-               dialog_->rtY->setText(toqstr(token(bb, ' ', 3)));
-               dialog_->lbXunit->setCurrentIndex(0);
-               dialog_->lbYunit->setCurrentIndex(0);
-               dialog_->rtXunit->setCurrentIndex(0);
-               dialog_->rtYunit->setCurrentIndex(0);
-               controller().bbChanged = false;
-       } else {
-               // get the values from the inset
-               LyXLength anyLength;
-               string const xl(token(igp.bb, ' ', 0));
-               string const yl(token(igp.bb, ' ', 1));
-               string const xr(token(igp.bb, ' ', 2));
-               string const yr(token(igp.bb, ' ', 3));
-               if (isValidLength(xl, &anyLength)) {
-                       dialog_->lbX->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       dialog_->lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
-               } else {
-                       dialog_->lbX->setText(toqstr(xl));
-               }
-               if (isValidLength(yl, &anyLength)) {
-                       dialog_->lbY->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       dialog_->lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
-               } else {
-                       dialog_->lbY->setText(toqstr(xl));
-               }
-               if (isValidLength(xr, &anyLength)) {
-                       dialog_->rtX->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       dialog_->rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
-               } else {
-                       dialog_->rtX->setText(toqstr(xl));
-               }
-               if (isValidLength(yr, &anyLength)) {
-                       dialog_->rtY->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       dialog_->rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
-               } else {
-                       dialog_->rtY->setText(toqstr(xl));
-               }
-               controller().bbChanged = true;
-       }
-
-       // Update the draft and clip mode
-       dialog_->draftCB->setChecked(igp.draft);
-       dialog_->clip->setChecked(igp.clip);
-       dialog_->unzipCB->setChecked(igp.noUnzip);
-
-       // Update the subcaption check button and input field
-       dialog_->subfigure->setChecked(igp.subcaption);
-       dialog_->subcaption->setText(toqstr(igp.subcaptionText));
-
-       int item = 0;
-       switch (igp.display) {
-               case graphics::DefaultDisplay: item = 0; break;
-               case graphics::MonochromeDisplay: item = 1; break;
-               case graphics::GrayscaleDisplay: item = 2; break;
-               case graphics::ColorDisplay: item = 3; break;
-               case graphics::NoDisplay: item = 0; break;
-       }
-       dialog_->showCB->setCurrentIndex(item);
-       dialog_->displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
-       dialog_->displayGB->setChecked(igp.display != graphics::NoDisplay);
-
-       // the output section (width/height)
-       
-       dialog_->Scale->setText(toqstr(igp.scale));
-       //igp.scale defaults to 100, so we treat it as empty
-       bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
-       dialog_->scaleCB->blockSignals(true);
-       dialog_->scaleCB->setChecked(scaleChecked);
-       dialog_->scaleCB->blockSignals(false);
-       dialog_->Scale->setEnabled(scaleChecked);
-       
-       lengthAutoToWidgets(dialog_->Width, dialog_->widthUnit, igp.width, 
-               unitDefault);
-       bool const widthChecked = !dialog_->Width->text().isEmpty() && 
-               dialog_->Width->text() != "auto";
-       dialog_->WidthCB->blockSignals(true);
-       dialog_->WidthCB->setChecked(widthChecked);
-       dialog_->WidthCB->blockSignals(false);
-       dialog_->Width->setEnabled(widthChecked);
-       dialog_->widthUnit->setEnabled(widthChecked);
-       
-       lengthAutoToWidgets(dialog_->Height, dialog_->heightUnit, igp.height, 
-               unitDefault);
-       bool const heightChecked = !dialog_->Height->text().isEmpty() 
-               && dialog_->Height->text() != "auto";
-       dialog_->HeightCB->blockSignals(true);
-       dialog_->HeightCB->setChecked(heightChecked);
-       dialog_->HeightCB->blockSignals(false);
-       dialog_->Height->setEnabled(heightChecked);
-       dialog_->heightUnit->setEnabled(heightChecked);
-       
-       dialog_->scaleCB->setEnabled(!widthChecked && !heightChecked);
-       dialog_->WidthCB->setEnabled(!scaleChecked);
-       dialog_->HeightCB->setEnabled(!scaleChecked);
-       dialog_->aspectratio->setEnabled(widthChecked && heightChecked);
-       
-       dialog_->setAutoText();
-
-       dialog_->angle->setText(toqstr(igp.rotateAngle));
-
-       dialog_->origin->clear();
-
-       vector<RotationOriginPair> origindata = getRotationOriginData();
-       vector<docstring> const origin_lang = getFirst(origindata);
-       QGraphics::origin_ltx = getSecond(origindata);
-
-       for (vector<docstring>::const_iterator it = origin_lang.begin();
-           it != origin_lang.end(); ++it)
-               dialog_->origin->addItem(toqstr(*it));
-
-       if (!igp.rotateOrigin.empty())
-               dialog_->origin->setCurrentIndex(
-                       getItemNo(origin_ltx, igp.rotateOrigin));
-       else
-               dialog_->origin->setCurrentIndex(0);
-
-       // disable edit button when no filename is present
-       dialog_->editPB->setDisabled(dialog_->filename->text().isEmpty());
-
-       //// latex section
-       dialog_->latexoptions->setText(toqstr(igp.special));
-}
-
-
-void QGraphics::apply()
-{
-       InsetGraphicsParams & igp = controller().params();
-
-       igp.filename.set(internal_path(fromqstr(dialog_->filename->text())),
-                        kernel().bufferFilepath());
-
-       // the bb section
-       igp.bb.erase();
-       if (controller().bbChanged) {
-               string bb;
-               string lbX(fromqstr(dialog_->lbX->text()));
-               string lbY(fromqstr(dialog_->lbY->text()));
-               string rtX(fromqstr(dialog_->rtX->text()));
-               string rtY(fromqstr(dialog_->rtY->text()));
-               int bb_sum =
-                       convert<int>(lbX) + convert<int>(lbY) +
-                       convert<int>(rtX) + convert<int>(rtX);
-               if (bb_sum) {
-                       if (lbX.empty())
-                               bb = "0 ";
-                       else
-                               bb = lbX + fromqstr(dialog_->lbXunit->currentText()) + ' ';
-                       if (lbY.empty())
-                               bb += "0 ";
-                       else
-                               bb += (lbY + fromqstr(dialog_->lbYunit->currentText()) + ' ');
-                       if (rtX.empty())
-                               bb += "0 ";
-                       else
-                               bb += (rtX + fromqstr(dialog_->rtXunit->currentText()) + ' ');
-                       if (rtY.empty())
-                               bb += '0';
-                       else
-                               bb += (rtY + fromqstr(dialog_->rtYunit->currentText()));
-                       igp.bb = bb;
-               }
-       }
-
-       igp.draft = dialog_->draftCB->isChecked();
-       igp.clip = dialog_->clip->isChecked();
-       igp.subcaption = dialog_->subfigure->isChecked();
-       igp.subcaptionText = fromqstr(dialog_->subcaption->text());
-
-       switch (dialog_->showCB->currentIndex()) {
-               case 0: igp.display = graphics::DefaultDisplay; break;
-               case 1: igp.display = graphics::MonochromeDisplay; break;
-               case 2: igp.display = graphics::GrayscaleDisplay; break;
-               case 3: igp.display = graphics::ColorDisplay; break;
-               default:;
-       }
-
-       if (!dialog_->displayGB->isChecked())
-               igp.display = graphics::NoDisplay;
-       
-       //the graphics section
-       if (dialog_->scaleCB->isChecked()       && !dialog_->Scale->text().isEmpty()) {
-               igp.scale = fromqstr(dialog_->Scale->text());
-               igp.width = LyXLength("0pt");
-               igp.height = LyXLength("0pt");
-               igp.keepAspectRatio = false;
-       } else {
-               igp.scale = string();
-               igp.width = dialog_->WidthCB->isChecked() ? 
-                       //Note that this works even if dialog_->Width is "auto", since in
-                       //that case we get "0pt".
-                       LyXLength(widgetsToLength(dialog_->Width, dialog_->widthUnit)): 
-                       LyXLength("0pt");
-               igp.height = dialog_->HeightCB->isChecked() ? 
-                       LyXLength(widgetsToLength(dialog_->Height, dialog_->heightUnit)) :
-                       LyXLength("0pt");
-               igp.keepAspectRatio = dialog_->aspectratio->isEnabled() &&
-                       dialog_->aspectratio->isChecked() &&
-                       igp.width.value() > 0 && igp.height.value() > 0;
-       }
-
-       igp.noUnzip = dialog_->unzipCB->isChecked();
-
-       igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text()));
-
-       igp.rotateAngle = fromqstr(dialog_->angle->text());
-
-       double rotAngle = convert<double>(igp.rotateAngle);
-       if (std::abs(rotAngle) > 360.0) {
-               rotAngle -= 360.0 * floor(rotAngle / 360.0);
-               igp.rotateAngle = convert<string>(rotAngle);
-       }
-
-       // save the latex name for the origin. If it is the default
-       // then origin_ltx returns ""
-       igp.rotateOrigin =
-               QGraphics::origin_ltx[dialog_->origin->currentIndex()];
-
-       // more latex options
-       igp.special = fromqstr(dialog_->latexoptions->text());
-}
-
-
-void QGraphics::getBB()
-{
-       string const filename(fromqstr(dialog_->filename->text()));
-       if (!filename.empty()) {
-               string const bb(controller().readBB(filename));
-               if (!bb.empty()) {
-                       dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
-                       dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
-                       dialog_->rtX->setText(toqstr(token(bb, ' ', 2)));
-                       dialog_->rtY->setText(toqstr(token(bb, ' ', 3)));
-                       // the default units for the bb values when reading
-                       // it from the file
-                       dialog_->lbXunit->setCurrentIndex(0);
-                       dialog_->lbYunit->setCurrentIndex(0);
-                       dialog_->rtXunit->setCurrentIndex(0);
-                       dialog_->rtYunit->setCurrentIndex(0);
-               }
-               controller().bbChanged = false;
-       }
-}
-
-
-bool QGraphics::isValid()
-{
-       return !dialog_->filename->text().isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/QGraphics.cpp b/src/frontends/qt4/QGraphics.cpp
new file mode 100644 (file)
index 0000000..5e1e100
--- /dev/null
@@ -0,0 +1,418 @@
+/**
+ * \file QGraphics.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Edwin Leuven
+ * \author Herbert Voß
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QGraphics.h"
+
+#include "CheckedLineEdit.h"
+#include "LengthCombo.h"
+#include "QGraphicsDialog.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+#include "Validator.h"
+
+#include "lengthcommon.h"
+#include "lyxrc.h"
+
+#include "controllers/ControlGraphics.h"
+#include "controllers/frontend_helpers.h"
+
+#include "insets/InsetGraphicsParams.h"
+
+#include "support/convert.h"
+#include "support/lstrings.h"
+#include "support/lyxlib.h"
+#include "support/os.h"
+
+#include <QLineEdit>
+#include <QPushButton>
+#include <QCheckBox>
+#include <QLabel>
+
+#include <cmath>
+
+using lyx::support::float_equal;
+using lyx::support::token;
+
+using lyx::support::os::internal_path;
+
+#ifndef CXX_GLOBAL_CSTD
+using std::floor;
+#endif
+
+using std::vector;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+typedef QController<ControlGraphics, QView<QGraphicsDialog> > graphics_base_class;
+
+QGraphics::QGraphics(Dialog & parent)
+       : graphics_base_class(parent, _("Graphics"))
+{
+}
+
+
+void QGraphics::build_dialog()
+{
+       dialog_.reset(new QGraphicsDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setRestore(dialog_->restorePB);
+       bcview().setCancel(dialog_->closePB);
+
+       bcview().addReadOnly(dialog_->latexoptions);
+       bcview().addReadOnly(dialog_->subfigure);
+       bcview().addReadOnly(dialog_->filenameL);
+       bcview().addReadOnly(dialog_->filename);
+       bcview().addReadOnly(dialog_->browsePB);
+       bcview().addReadOnly(dialog_->unzipCB);
+       bcview().addReadOnly(dialog_->bbFrame);
+       bcview().addReadOnly(dialog_->draftCB);
+       bcview().addReadOnly(dialog_->clip);
+       bcview().addReadOnly(dialog_->unzipCB);
+       bcview().addReadOnly(dialog_->displayGB);
+       bcview().addReadOnly(dialog_->sizeGB);
+       bcview().addReadOnly(dialog_->rotationGB);
+       bcview().addReadOnly(dialog_->latexoptions);
+       bcview().addReadOnly(dialog_->getPB);
+
+       // initialize the length validator
+       addCheckedLineEdit(bcview(), dialog_->Scale, dialog_->scaleCB);
+       addCheckedLineEdit(bcview(), dialog_->Width, dialog_->WidthCB);
+       addCheckedLineEdit(bcview(), dialog_->Height, dialog_->HeightCB);
+       addCheckedLineEdit(bcview(), dialog_->displayscale, dialog_->scaleLA);
+       addCheckedLineEdit(bcview(), dialog_->angle, dialog_->angleL);
+       addCheckedLineEdit(bcview(), dialog_->lbX, dialog_->xL);
+       addCheckedLineEdit(bcview(), dialog_->lbY, dialog_->yL);
+       addCheckedLineEdit(bcview(), dialog_->rtX, dialog_->xL_2);
+       addCheckedLineEdit(bcview(), dialog_->rtY, dialog_->yL_2);
+       addCheckedLineEdit(bcview(), dialog_->filename, dialog_->filenameL);
+}
+
+
+namespace {
+
+// returns the number of the string s in the vector v
+int getItemNo(vector<string> v, string const & s) {
+       vector<string>::const_iterator cit =
+                   find(v.begin(), v.end(), s);
+       return (cit != v.end()) ? int(cit - v.begin()) : 0;
+}
+
+}
+
+
+void QGraphics::update_contents()
+{
+       PathValidator * path_validator = getPathValidator(dialog_->filename);
+       if (path_validator)
+               path_validator->setChecker(kernel().docType(), lyxrc);
+
+       // clear and fill in the comboboxes
+       vector<string> const bb_units = frontend::getBBUnits();
+       dialog_->lbXunit->clear();
+       dialog_->lbYunit->clear();
+       dialog_->rtXunit->clear();
+       dialog_->rtYunit->clear();
+       for (vector<string>::const_iterator it = bb_units.begin();
+           it != bb_units.end(); ++it) {
+               dialog_->lbXunit->addItem(toqstr(*it));
+               dialog_->lbYunit->addItem(toqstr(*it));
+               dialog_->rtXunit->addItem(toqstr(*it));
+               dialog_->rtYunit->addItem(toqstr(*it));
+       }
+
+       InsetGraphicsParams & igp = controller().params();
+
+       // set the right default unit
+       LyXLength::UNIT unitDefault = LyXLength::CM;
+       switch (lyxrc.default_papersize) {
+               case PAPER_USLETTER:
+               case PAPER_USLEGAL:
+               case PAPER_USEXECUTIVE:
+                       unitDefault = LyXLength::IN;
+                       break;
+               default:
+                       break;
+       }
+
+       string const name =
+               igp.filename.outputFilename(kernel().bufferFilepath());
+       dialog_->filename->setText(toqstr(name));
+
+       // set the bounding box values
+       if (igp.bb.empty()) {
+               string const bb = controller().readBB(igp.filename.absFilename());
+               // the values from the file always have the bigpoint-unit bp
+               dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
+               dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
+               dialog_->rtX->setText(toqstr(token(bb, ' ', 2)));
+               dialog_->rtY->setText(toqstr(token(bb, ' ', 3)));
+               dialog_->lbXunit->setCurrentIndex(0);
+               dialog_->lbYunit->setCurrentIndex(0);
+               dialog_->rtXunit->setCurrentIndex(0);
+               dialog_->rtYunit->setCurrentIndex(0);
+               controller().bbChanged = false;
+       } else {
+               // get the values from the inset
+               LyXLength anyLength;
+               string const xl(token(igp.bb, ' ', 0));
+               string const yl(token(igp.bb, ' ', 1));
+               string const xr(token(igp.bb, ' ', 2));
+               string const yr(token(igp.bb, ' ', 3));
+               if (isValidLength(xl, &anyLength)) {
+                       dialog_->lbX->setText(toqstr(convert<string>(anyLength.value())));
+                       string const unit(unit_name[anyLength.unit()]);
+                       dialog_->lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
+               } else {
+                       dialog_->lbX->setText(toqstr(xl));
+               }
+               if (isValidLength(yl, &anyLength)) {
+                       dialog_->lbY->setText(toqstr(convert<string>(anyLength.value())));
+                       string const unit(unit_name[anyLength.unit()]);
+                       dialog_->lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
+               } else {
+                       dialog_->lbY->setText(toqstr(xl));
+               }
+               if (isValidLength(xr, &anyLength)) {
+                       dialog_->rtX->setText(toqstr(convert<string>(anyLength.value())));
+                       string const unit(unit_name[anyLength.unit()]);
+                       dialog_->rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
+               } else {
+                       dialog_->rtX->setText(toqstr(xl));
+               }
+               if (isValidLength(yr, &anyLength)) {
+                       dialog_->rtY->setText(toqstr(convert<string>(anyLength.value())));
+                       string const unit(unit_name[anyLength.unit()]);
+                       dialog_->rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
+               } else {
+                       dialog_->rtY->setText(toqstr(xl));
+               }
+               controller().bbChanged = true;
+       }
+
+       // Update the draft and clip mode
+       dialog_->draftCB->setChecked(igp.draft);
+       dialog_->clip->setChecked(igp.clip);
+       dialog_->unzipCB->setChecked(igp.noUnzip);
+
+       // Update the subcaption check button and input field
+       dialog_->subfigure->setChecked(igp.subcaption);
+       dialog_->subcaption->setText(toqstr(igp.subcaptionText));
+
+       int item = 0;
+       switch (igp.display) {
+               case graphics::DefaultDisplay: item = 0; break;
+               case graphics::MonochromeDisplay: item = 1; break;
+               case graphics::GrayscaleDisplay: item = 2; break;
+               case graphics::ColorDisplay: item = 3; break;
+               case graphics::NoDisplay: item = 0; break;
+       }
+       dialog_->showCB->setCurrentIndex(item);
+       dialog_->displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
+       dialog_->displayGB->setChecked(igp.display != graphics::NoDisplay);
+
+       // the output section (width/height)
+       
+       dialog_->Scale->setText(toqstr(igp.scale));
+       //igp.scale defaults to 100, so we treat it as empty
+       bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
+       dialog_->scaleCB->blockSignals(true);
+       dialog_->scaleCB->setChecked(scaleChecked);
+       dialog_->scaleCB->blockSignals(false);
+       dialog_->Scale->setEnabled(scaleChecked);
+       
+       lengthAutoToWidgets(dialog_->Width, dialog_->widthUnit, igp.width, 
+               unitDefault);
+       bool const widthChecked = !dialog_->Width->text().isEmpty() && 
+               dialog_->Width->text() != "auto";
+       dialog_->WidthCB->blockSignals(true);
+       dialog_->WidthCB->setChecked(widthChecked);
+       dialog_->WidthCB->blockSignals(false);
+       dialog_->Width->setEnabled(widthChecked);
+       dialog_->widthUnit->setEnabled(widthChecked);
+       
+       lengthAutoToWidgets(dialog_->Height, dialog_->heightUnit, igp.height, 
+               unitDefault);
+       bool const heightChecked = !dialog_->Height->text().isEmpty() 
+               && dialog_->Height->text() != "auto";
+       dialog_->HeightCB->blockSignals(true);
+       dialog_->HeightCB->setChecked(heightChecked);
+       dialog_->HeightCB->blockSignals(false);
+       dialog_->Height->setEnabled(heightChecked);
+       dialog_->heightUnit->setEnabled(heightChecked);
+       
+       dialog_->scaleCB->setEnabled(!widthChecked && !heightChecked);
+       dialog_->WidthCB->setEnabled(!scaleChecked);
+       dialog_->HeightCB->setEnabled(!scaleChecked);
+       dialog_->aspectratio->setEnabled(widthChecked && heightChecked);
+       
+       dialog_->setAutoText();
+
+       dialog_->angle->setText(toqstr(igp.rotateAngle));
+
+       dialog_->origin->clear();
+
+       vector<RotationOriginPair> origindata = getRotationOriginData();
+       vector<docstring> const origin_lang = getFirst(origindata);
+       QGraphics::origin_ltx = getSecond(origindata);
+
+       for (vector<docstring>::const_iterator it = origin_lang.begin();
+           it != origin_lang.end(); ++it)
+               dialog_->origin->addItem(toqstr(*it));
+
+       if (!igp.rotateOrigin.empty())
+               dialog_->origin->setCurrentIndex(
+                       getItemNo(origin_ltx, igp.rotateOrigin));
+       else
+               dialog_->origin->setCurrentIndex(0);
+
+       // disable edit button when no filename is present
+       dialog_->editPB->setDisabled(dialog_->filename->text().isEmpty());
+
+       //// latex section
+       dialog_->latexoptions->setText(toqstr(igp.special));
+}
+
+
+void QGraphics::apply()
+{
+       InsetGraphicsParams & igp = controller().params();
+
+       igp.filename.set(internal_path(fromqstr(dialog_->filename->text())),
+                        kernel().bufferFilepath());
+
+       // the bb section
+       igp.bb.erase();
+       if (controller().bbChanged) {
+               string bb;
+               string lbX(fromqstr(dialog_->lbX->text()));
+               string lbY(fromqstr(dialog_->lbY->text()));
+               string rtX(fromqstr(dialog_->rtX->text()));
+               string rtY(fromqstr(dialog_->rtY->text()));
+               int bb_sum =
+                       convert<int>(lbX) + convert<int>(lbY) +
+                       convert<int>(rtX) + convert<int>(rtX);
+               if (bb_sum) {
+                       if (lbX.empty())
+                               bb = "0 ";
+                       else
+                               bb = lbX + fromqstr(dialog_->lbXunit->currentText()) + ' ';
+                       if (lbY.empty())
+                               bb += "0 ";
+                       else
+                               bb += (lbY + fromqstr(dialog_->lbYunit->currentText()) + ' ');
+                       if (rtX.empty())
+                               bb += "0 ";
+                       else
+                               bb += (rtX + fromqstr(dialog_->rtXunit->currentText()) + ' ');
+                       if (rtY.empty())
+                               bb += '0';
+                       else
+                               bb += (rtY + fromqstr(dialog_->rtYunit->currentText()));
+                       igp.bb = bb;
+               }
+       }
+
+       igp.draft = dialog_->draftCB->isChecked();
+       igp.clip = dialog_->clip->isChecked();
+       igp.subcaption = dialog_->subfigure->isChecked();
+       igp.subcaptionText = fromqstr(dialog_->subcaption->text());
+
+       switch (dialog_->showCB->currentIndex()) {
+               case 0: igp.display = graphics::DefaultDisplay; break;
+               case 1: igp.display = graphics::MonochromeDisplay; break;
+               case 2: igp.display = graphics::GrayscaleDisplay; break;
+               case 3: igp.display = graphics::ColorDisplay; break;
+               default:;
+       }
+
+       if (!dialog_->displayGB->isChecked())
+               igp.display = graphics::NoDisplay;
+       
+       //the graphics section
+       if (dialog_->scaleCB->isChecked()       && !dialog_->Scale->text().isEmpty()) {
+               igp.scale = fromqstr(dialog_->Scale->text());
+               igp.width = LyXLength("0pt");
+               igp.height = LyXLength("0pt");
+               igp.keepAspectRatio = false;
+       } else {
+               igp.scale = string();
+               igp.width = dialog_->WidthCB->isChecked() ? 
+                       //Note that this works even if dialog_->Width is "auto", since in
+                       //that case we get "0pt".
+                       LyXLength(widgetsToLength(dialog_->Width, dialog_->widthUnit)): 
+                       LyXLength("0pt");
+               igp.height = dialog_->HeightCB->isChecked() ? 
+                       LyXLength(widgetsToLength(dialog_->Height, dialog_->heightUnit)) :
+                       LyXLength("0pt");
+               igp.keepAspectRatio = dialog_->aspectratio->isEnabled() &&
+                       dialog_->aspectratio->isChecked() &&
+                       igp.width.value() > 0 && igp.height.value() > 0;
+       }
+
+       igp.noUnzip = dialog_->unzipCB->isChecked();
+
+       igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text()));
+
+       igp.rotateAngle = fromqstr(dialog_->angle->text());
+
+       double rotAngle = convert<double>(igp.rotateAngle);
+       if (std::abs(rotAngle) > 360.0) {
+               rotAngle -= 360.0 * floor(rotAngle / 360.0);
+               igp.rotateAngle = convert<string>(rotAngle);
+       }
+
+       // save the latex name for the origin. If it is the default
+       // then origin_ltx returns ""
+       igp.rotateOrigin =
+               QGraphics::origin_ltx[dialog_->origin->currentIndex()];
+
+       // more latex options
+       igp.special = fromqstr(dialog_->latexoptions->text());
+}
+
+
+void QGraphics::getBB()
+{
+       string const filename(fromqstr(dialog_->filename->text()));
+       if (!filename.empty()) {
+               string const bb(controller().readBB(filename));
+               if (!bb.empty()) {
+                       dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
+                       dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
+                       dialog_->rtX->setText(toqstr(token(bb, ' ', 2)));
+                       dialog_->rtY->setText(toqstr(token(bb, ' ', 3)));
+                       // the default units for the bb values when reading
+                       // it from the file
+                       dialog_->lbXunit->setCurrentIndex(0);
+                       dialog_->lbYunit->setCurrentIndex(0);
+                       dialog_->rtXunit->setCurrentIndex(0);
+                       dialog_->rtYunit->setCurrentIndex(0);
+               }
+               controller().bbChanged = false;
+       }
+}
+
+
+bool QGraphics::isValid()
+{
+       return !dialog_->filename->text().isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/QGraphicsDialog.C b/src/frontends/qt4/QGraphicsDialog.C
deleted file mode 100644 (file)
index 3aaaebc..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/**
- * \file QGraphicsDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Herbert Voß
- * \author Abdelrazak Younes
- * \author Richard Heck
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QGraphicsDialog.h"
-#include "QGraphics.h"
-
-#include "LengthCombo.h"
-#include "Validator.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-
-#include "controllers/ControlGraphics.h"
-
-#include "insets/InsetGraphicsParams.h"
-
-#include <QCloseEvent>
-#include <QPushButton>
-#include <QLineEdit>
-#include <QValidator>
-
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-
-QGraphicsDialog::QGraphicsDialog(QGraphics * form)
-       : form_(form)
-{
-       setupUi(this);
-       //main buttons
-       connect(okPB, SIGNAL(clicked()),
-               form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()),
-               form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()),
-               form, SLOT(slotRestore()));
-       
-       //graphics pane
-       connect(filename, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(WidthCB, SIGNAL( clicked()),
-               this, SLOT(change_adaptor()));
-       connect(HeightCB, SIGNAL( clicked()),
-               this, SLOT(change_adaptor()));
-       connect(Width, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(Height, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(heightUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(change_adaptor()));
-       connect(widthUnit, SIGNAL(selectionChanged(lyx::LyXLength::UNIT)),
-               this, SLOT(change_adaptor()));
-       connect(aspectratio, SIGNAL(stateChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(angle, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(origin, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(scaleCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(Scale, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       
-       filename->setValidator(new PathValidator(true, filename));
-       setFocusProxy(filename);
-       
-       QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
-       scaleValidator->setBottom(0);
-       scaleValidator->setDecimals(256); //I guess that will do
-       Scale->setValidator(scaleValidator);
-       Height->setValidator(unsignedLengthAutoValidator(Height));
-       Width->setValidator(unsignedLengthAutoValidator(Width));
-       angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
-
-       //clipping pane
-       connect(clip, SIGNAL(stateChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(lbY, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
-       connect(lbYunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
-       connect(rtY, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
-       connect(rtYunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
-       connect(lbX, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
-       connect(lbXunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
-       connect(rtX, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
-       connect(rtXunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
-       connect(getPB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       
-       lbX->setValidator(new QDoubleValidator(lbX));
-       lbY->setValidator(new QDoubleValidator(lbY));
-       rtX->setValidator(new QDoubleValidator(rtX));
-       rtY->setValidator(new QDoubleValidator(rtY));
-
-       //extra options pane
-       connect(latexoptions, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(draftCB, SIGNAL(stateChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(unzipCB, SIGNAL(stateChanged(int)),
-               this, SLOT(change_adaptor()));
-       // FIXME: we should connect to clicked() when we move to Qt 4.2 because
-       // the toggled(bool) signal is also trigged when we update the widgets
-       // (rgh-4/07) this isn't as much or a problem as it was, because we're now
-       // using blockSignals() to keep from triggering that signal when we call
-       // setChecked(). Note, too, that clicked() would get called whenever it
-       // is clicked, even right clicked (I think), not just whenever it is
-       // toggled.
-       connect(subfigure, SIGNAL(toggled(bool)),
-               this, SLOT(change_adaptor()));
-       connect(subcaption, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(displayGB, SIGNAL(toggled(bool)),
-               this, SLOT(change_adaptor()));
-       connect(showCB, SIGNAL(currentIndexChanged(int)),
-               this, SLOT(change_adaptor()));
-       connect(displayscale, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       displayscale->setValidator(new QIntValidator(displayscale));
-}
-
-
-void QGraphicsDialog::show()
-{
-       QDialog::show();
-}
-
-
-void QGraphicsDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QGraphicsDialog::change_bb()
-{
-       form_->controller().bbChanged = true;
-       LYXERR(Debug::GRAPHICS)
-               << "[controller().bb_Changed set to true]\n";
-       form_->changed();
-}
-
-
-void QGraphicsDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QGraphicsDialog::on_browsePB_clicked()
-{
-       docstring const str =
-               form_->controller().browse(qstring_to_ucs4(filename->text()));
-       filename->setText(toqstr(str));
-       form_->changed();
-}
-
-
-void QGraphicsDialog::on_getPB_clicked()
-{
-       form_->getBB();
-}
-
-
-void QGraphicsDialog::on_editPB_clicked()
-{
-       form_->controller().editGraphics();
-}
-
-
-void QGraphicsDialog::on_filename_textChanged(const QString & filename)
-{
-       editPB->setDisabled(filename.isEmpty());
-}
-
-
-void QGraphicsDialog::setAutoText() {
-       if (scaleCB->isChecked()) return;
-       if (!Scale->isEnabled() && Scale->text() != "100") 
-               Scale->setText(QString("auto"));
-
-       setAutoTextCB(WidthCB, Width, widthUnit);
-       setAutoTextCB(HeightCB, Height, heightUnit);
-}
-
-
-void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
-{
-       Scale->setEnabled(setScale);
-       if (setScale) {
-               Scale->setText("100");
-               Scale->setFocus(Qt::OtherFocusReason);
-       }
-       
-       WidthCB->setDisabled(setScale);
-       WidthCB->blockSignals(true);
-       WidthCB->setChecked(false);
-       WidthCB->blockSignals(false);
-       Width->setEnabled(false);
-       widthUnit->setEnabled(false);
-       
-       HeightCB->setDisabled(setScale);
-       HeightCB->blockSignals(true);
-       HeightCB->setChecked(false);
-       HeightCB->blockSignals(false);
-       Height->setEnabled(false);
-       heightUnit->setEnabled(false);
-       
-       aspectratio->setDisabled(true);
-       aspectratio->setChecked(true);
-       
-       setAutoText();
-}
-
-void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
-{
-       Width->setEnabled(setWidth);
-       widthUnit->setEnabled(setWidth);
-       if (setWidth)
-               Width->setFocus(Qt::OtherFocusReason);
-       
-       bool const setHeight = HeightCB->isChecked();
-       aspectratio->setEnabled(setWidth && setHeight);
-       aspectratio->blockSignals(true);
-       aspectratio->setChecked(!(setWidth && setHeight));
-       aspectratio->blockSignals(false);
-       
-       scaleCB->setEnabled(!setWidth && !setHeight);
-       //already will be unchecked, so don't need to do that
-       Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled() 
-                       && scaleCB->isChecked()); //should be false, but let's check
-       
-       setAutoText();
-}
-
-void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
-{
-       Height->setEnabled(setHeight);
-       heightUnit->setEnabled(setHeight);
-       if (setHeight)
-               Height->setFocus(Qt::OtherFocusReason);
-       
-       bool const setWidth = WidthCB->isChecked();
-       aspectratio->setEnabled(setWidth && setHeight);
-       aspectratio->blockSignals(true);
-       aspectratio->setChecked(!(setWidth && setHeight));
-       aspectratio->blockSignals(false);
-       
-       scaleCB->setEnabled(!setWidth && !setHeight);
-       //already unchecked
-       Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled() 
-               && scaleCB->isChecked()); //should be false
-       
-       setAutoText();
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QGraphicsDialog_moc.cpp"
diff --git a/src/frontends/qt4/QGraphicsDialog.cpp b/src/frontends/qt4/QGraphicsDialog.cpp
new file mode 100644 (file)
index 0000000..3aaaebc
--- /dev/null
@@ -0,0 +1,286 @@
+/**
+ * \file QGraphicsDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Herbert Voß
+ * \author Abdelrazak Younes
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QGraphicsDialog.h"
+#include "QGraphics.h"
+
+#include "LengthCombo.h"
+#include "Validator.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include "controllers/ControlGraphics.h"
+
+#include "insets/InsetGraphicsParams.h"
+
+#include <QCloseEvent>
+#include <QPushButton>
+#include <QLineEdit>
+#include <QValidator>
+
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+
+QGraphicsDialog::QGraphicsDialog(QGraphics * form)
+       : form_(form)
+{
+       setupUi(this);
+       //main buttons
+       connect(okPB, SIGNAL(clicked()),
+               form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()),
+               form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+       connect(restorePB, SIGNAL(clicked()),
+               form, SLOT(slotRestore()));
+       
+       //graphics pane
+       connect(filename, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(WidthCB, SIGNAL( clicked()),
+               this, SLOT(change_adaptor()));
+       connect(HeightCB, SIGNAL( clicked()),
+               this, SLOT(change_adaptor()));
+       connect(Width, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(Height, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(heightUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(change_adaptor()));
+       connect(widthUnit, SIGNAL(selectionChanged(lyx::LyXLength::UNIT)),
+               this, SLOT(change_adaptor()));
+       connect(aspectratio, SIGNAL(stateChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(angle, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(origin, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(scaleCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(Scale, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       
+       filename->setValidator(new PathValidator(true, filename));
+       setFocusProxy(filename);
+       
+       QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
+       scaleValidator->setBottom(0);
+       scaleValidator->setDecimals(256); //I guess that will do
+       Scale->setValidator(scaleValidator);
+       Height->setValidator(unsignedLengthAutoValidator(Height));
+       Width->setValidator(unsignedLengthAutoValidator(Width));
+       angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
+
+       //clipping pane
+       connect(clip, SIGNAL(stateChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(lbY, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_bb()));
+       connect(lbYunit, SIGNAL(activated(int)),
+               this, SLOT(change_bb()));
+       connect(rtY, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_bb()));
+       connect(rtYunit, SIGNAL(activated(int)),
+               this, SLOT(change_bb()));
+       connect(lbX, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_bb()));
+       connect(lbXunit, SIGNAL(activated(int)),
+               this, SLOT(change_bb()));
+       connect(rtX, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_bb()));
+       connect(rtXunit, SIGNAL(activated(int)),
+               this, SLOT(change_bb()));
+       connect(getPB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       
+       lbX->setValidator(new QDoubleValidator(lbX));
+       lbY->setValidator(new QDoubleValidator(lbY));
+       rtX->setValidator(new QDoubleValidator(rtX));
+       rtY->setValidator(new QDoubleValidator(rtY));
+
+       //extra options pane
+       connect(latexoptions, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(draftCB, SIGNAL(stateChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(unzipCB, SIGNAL(stateChanged(int)),
+               this, SLOT(change_adaptor()));
+       // FIXME: we should connect to clicked() when we move to Qt 4.2 because
+       // the toggled(bool) signal is also trigged when we update the widgets
+       // (rgh-4/07) this isn't as much or a problem as it was, because we're now
+       // using blockSignals() to keep from triggering that signal when we call
+       // setChecked(). Note, too, that clicked() would get called whenever it
+       // is clicked, even right clicked (I think), not just whenever it is
+       // toggled.
+       connect(subfigure, SIGNAL(toggled(bool)),
+               this, SLOT(change_adaptor()));
+       connect(subcaption, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(displayGB, SIGNAL(toggled(bool)),
+               this, SLOT(change_adaptor()));
+       connect(showCB, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(change_adaptor()));
+       connect(displayscale, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       displayscale->setValidator(new QIntValidator(displayscale));
+}
+
+
+void QGraphicsDialog::show()
+{
+       QDialog::show();
+}
+
+
+void QGraphicsDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QGraphicsDialog::change_bb()
+{
+       form_->controller().bbChanged = true;
+       LYXERR(Debug::GRAPHICS)
+               << "[controller().bb_Changed set to true]\n";
+       form_->changed();
+}
+
+
+void QGraphicsDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QGraphicsDialog::on_browsePB_clicked()
+{
+       docstring const str =
+               form_->controller().browse(qstring_to_ucs4(filename->text()));
+       filename->setText(toqstr(str));
+       form_->changed();
+}
+
+
+void QGraphicsDialog::on_getPB_clicked()
+{
+       form_->getBB();
+}
+
+
+void QGraphicsDialog::on_editPB_clicked()
+{
+       form_->controller().editGraphics();
+}
+
+
+void QGraphicsDialog::on_filename_textChanged(const QString & filename)
+{
+       editPB->setDisabled(filename.isEmpty());
+}
+
+
+void QGraphicsDialog::setAutoText() {
+       if (scaleCB->isChecked()) return;
+       if (!Scale->isEnabled() && Scale->text() != "100") 
+               Scale->setText(QString("auto"));
+
+       setAutoTextCB(WidthCB, Width, widthUnit);
+       setAutoTextCB(HeightCB, Height, heightUnit);
+}
+
+
+void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
+{
+       Scale->setEnabled(setScale);
+       if (setScale) {
+               Scale->setText("100");
+               Scale->setFocus(Qt::OtherFocusReason);
+       }
+       
+       WidthCB->setDisabled(setScale);
+       WidthCB->blockSignals(true);
+       WidthCB->setChecked(false);
+       WidthCB->blockSignals(false);
+       Width->setEnabled(false);
+       widthUnit->setEnabled(false);
+       
+       HeightCB->setDisabled(setScale);
+       HeightCB->blockSignals(true);
+       HeightCB->setChecked(false);
+       HeightCB->blockSignals(false);
+       Height->setEnabled(false);
+       heightUnit->setEnabled(false);
+       
+       aspectratio->setDisabled(true);
+       aspectratio->setChecked(true);
+       
+       setAutoText();
+}
+
+void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
+{
+       Width->setEnabled(setWidth);
+       widthUnit->setEnabled(setWidth);
+       if (setWidth)
+               Width->setFocus(Qt::OtherFocusReason);
+       
+       bool const setHeight = HeightCB->isChecked();
+       aspectratio->setEnabled(setWidth && setHeight);
+       aspectratio->blockSignals(true);
+       aspectratio->setChecked(!(setWidth && setHeight));
+       aspectratio->blockSignals(false);
+       
+       scaleCB->setEnabled(!setWidth && !setHeight);
+       //already will be unchecked, so don't need to do that
+       Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled() 
+                       && scaleCB->isChecked()); //should be false, but let's check
+       
+       setAutoText();
+}
+
+void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
+{
+       Height->setEnabled(setHeight);
+       heightUnit->setEnabled(setHeight);
+       if (setHeight)
+               Height->setFocus(Qt::OtherFocusReason);
+       
+       bool const setWidth = WidthCB->isChecked();
+       aspectratio->setEnabled(setWidth && setHeight);
+       aspectratio->blockSignals(true);
+       aspectratio->setChecked(!(setWidth && setHeight));
+       aspectratio->blockSignals(false);
+       
+       scaleCB->setEnabled(!setWidth && !setHeight);
+       //already unchecked
+       Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled() 
+               && scaleCB->isChecked()); //should be false
+       
+       setAutoText();
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QGraphicsDialog_moc.cpp"
diff --git a/src/frontends/qt4/QInclude.C b/src/frontends/qt4/QInclude.C
deleted file mode 100644 (file)
index a701814..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-/**
- * \file QInclude.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "support/os.h"
-
-#include "QInclude.h"
-
-#include "CheckedLineEdit.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-#include "Validator.h"
-
-#include "lyxrc.h"
-
-#include "controllers/ControlInclude.h"
-
-#include <QPushButton>
-#include <QCheckBox>
-#include <QCloseEvent>
-#include <QLineEdit>
-
-using std::string;
-
-using lyx::support::os::internal_path;
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QIncludeDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QIncludeDialog::QIncludeDialog(QInclude * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(visiblespaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(filenameED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(loadPB, SIGNAL(clicked()), this, SLOT(loadClicked()));
-       connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
-       connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
-       connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-
-       filenameED->setValidator(new PathValidator(true, filenameED));
-       setFocusProxy(filenameED);
-}
-
-
-void QIncludeDialog::show()
-{
-       QDialog::show();
-}
-
-
-void QIncludeDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QIncludeDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QIncludeDialog::typeChanged(int v)
-{
-       switch (v) {
-               //case Include
-               case 0:
-                       visiblespaceCB->setEnabled(false);
-                       visiblespaceCB->setChecked(false);
-                       previewCB->setEnabled(false);
-                       previewCB->setChecked(false);
-                       break;
-               //case Input
-               case 1:
-                       visiblespaceCB->setEnabled(false);
-                       visiblespaceCB->setChecked(false);
-                       previewCB->setEnabled(true);
-                       break;
-               //case Verbatim
-               default:
-                       visiblespaceCB->setEnabled(true);
-                       previewCB->setEnabled(false);
-                       previewCB->setChecked(false);
-                       break;
-       }
-}
-
-
-void QIncludeDialog::loadClicked()
-{
-       form_->load();
-}
-
-
-void QIncludeDialog::browseClicked()
-{
-       form_->browse();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QInclude
-//
-/////////////////////////////////////////////////////////////////////
-
-
-typedef QController<ControlInclude, QView<QIncludeDialog> > IncludeBase;
-
-
-QInclude::QInclude(Dialog & parent)
-       : IncludeBase(parent, _("Child Document"))
-{}
-
-
-void QInclude::build_dialog()
-{
-       dialog_.reset(new QIncludeDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->filenameED);
-       bcview().addReadOnly(dialog_->browsePB);
-       bcview().addReadOnly(dialog_->visiblespaceCB);
-       bcview().addReadOnly(dialog_->typeCO);
-
-       addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
-}
-
-
-void QInclude::update_contents()
-{
-       PathValidator * path_validator = getPathValidator(dialog_->filenameED);
-       if (path_validator)
-               path_validator->setChecker(kernel().docType(), lyxrc);
-
-       InsetCommandParams const & params = controller().params();
-
-       dialog_->filenameED->setText(toqstr(params["filename"]));
-
-       dialog_->visiblespaceCB->setChecked(false);
-       dialog_->visiblespaceCB->setEnabled(false);
-       dialog_->previewCB->setChecked(false);
-       dialog_->previewCB->setEnabled(false);
-
-       string cmdname = controller().params().getCmdName();
-       if (cmdname != "include" &&
-           cmdname != "verbatiminput" &&
-           cmdname != "verbatiminput*")
-               cmdname = "input";
-
-       if (cmdname == "include") {
-               dialog_->typeCO->setCurrentIndex(0);
-
-       } else if (cmdname == "input") {
-               dialog_->typeCO->setCurrentIndex(1);
-               dialog_->previewCB->setEnabled(true);
-               dialog_->previewCB->setChecked(params.preview());
-
-       } else if (cmdname == "verbatiminput*") {
-               dialog_->typeCO->setCurrentIndex(2);
-               dialog_->visiblespaceCB->setEnabled(true);
-               dialog_->visiblespaceCB->setChecked(true);
-
-       } else if (cmdname == "verbatiminput") {
-               dialog_->typeCO->setCurrentIndex(2);
-               dialog_->visiblespaceCB->setEnabled(true);
-       }
-}
-
-
-void QInclude::apply()
-{
-       InsetCommandParams params = controller().params();
-
-       params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text())));
-       params.preview(dialog_->previewCB->isChecked());
-
-       int const item = dialog_->typeCO->currentIndex();
-       if (item == 0)
-               params.setCmdName("include");
-       else if (item == 1)
-               params.setCmdName("input");
-       else {
-               if (dialog_->visiblespaceCB->isChecked())
-                       params.setCmdName("verbatiminput*");
-               else
-                       params.setCmdName("verbatiminput");
-       }
-       controller().setParams(params);
-}
-
-
-void QInclude::browse()
-{
-       ControlInclude::Type type;
-
-       int const item = dialog_->typeCO->currentIndex();
-       if (item == 0)
-               type = ControlInclude::INCLUDE;
-       else if (item == 1)
-               type = ControlInclude::INPUT;
-       else
-               type = ControlInclude::VERBATIM;
-
-       docstring const & name =
-               controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type);
-       if (!name.empty())
-               dialog_->filenameED->setText(toqstr(name));
-}
-
-
-void QInclude::load()
-{
-       if (isValid()) {
-               string const file = fromqstr(dialog_->filenameED->text());
-               slotOK();
-               controller().load(file);
-       }
-}
-
-
-bool QInclude::isValid()
-{
-       return !dialog_->filenameED->text().isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QInclude_moc.cpp"
diff --git a/src/frontends/qt4/QInclude.cpp b/src/frontends/qt4/QInclude.cpp
new file mode 100644 (file)
index 0000000..a701814
--- /dev/null
@@ -0,0 +1,253 @@
+/**
+ * \file QInclude.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "support/os.h"
+
+#include "QInclude.h"
+
+#include "CheckedLineEdit.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+#include "Validator.h"
+
+#include "lyxrc.h"
+
+#include "controllers/ControlInclude.h"
+
+#include <QPushButton>
+#include <QCheckBox>
+#include <QCloseEvent>
+#include <QLineEdit>
+
+using std::string;
+
+using lyx::support::os::internal_path;
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QIncludeDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QIncludeDialog::QIncludeDialog(QInclude * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(visiblespaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(filenameED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(loadPB, SIGNAL(clicked()), this, SLOT(loadClicked()));
+       connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
+       connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
+       connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+
+       filenameED->setValidator(new PathValidator(true, filenameED));
+       setFocusProxy(filenameED);
+}
+
+
+void QIncludeDialog::show()
+{
+       QDialog::show();
+}
+
+
+void QIncludeDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QIncludeDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QIncludeDialog::typeChanged(int v)
+{
+       switch (v) {
+               //case Include
+               case 0:
+                       visiblespaceCB->setEnabled(false);
+                       visiblespaceCB->setChecked(false);
+                       previewCB->setEnabled(false);
+                       previewCB->setChecked(false);
+                       break;
+               //case Input
+               case 1:
+                       visiblespaceCB->setEnabled(false);
+                       visiblespaceCB->setChecked(false);
+                       previewCB->setEnabled(true);
+                       break;
+               //case Verbatim
+               default:
+                       visiblespaceCB->setEnabled(true);
+                       previewCB->setEnabled(false);
+                       previewCB->setChecked(false);
+                       break;
+       }
+}
+
+
+void QIncludeDialog::loadClicked()
+{
+       form_->load();
+}
+
+
+void QIncludeDialog::browseClicked()
+{
+       form_->browse();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QInclude
+//
+/////////////////////////////////////////////////////////////////////
+
+
+typedef QController<ControlInclude, QView<QIncludeDialog> > IncludeBase;
+
+
+QInclude::QInclude(Dialog & parent)
+       : IncludeBase(parent, _("Child Document"))
+{}
+
+
+void QInclude::build_dialog()
+{
+       dialog_.reset(new QIncludeDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->filenameED);
+       bcview().addReadOnly(dialog_->browsePB);
+       bcview().addReadOnly(dialog_->visiblespaceCB);
+       bcview().addReadOnly(dialog_->typeCO);
+
+       addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
+}
+
+
+void QInclude::update_contents()
+{
+       PathValidator * path_validator = getPathValidator(dialog_->filenameED);
+       if (path_validator)
+               path_validator->setChecker(kernel().docType(), lyxrc);
+
+       InsetCommandParams const & params = controller().params();
+
+       dialog_->filenameED->setText(toqstr(params["filename"]));
+
+       dialog_->visiblespaceCB->setChecked(false);
+       dialog_->visiblespaceCB->setEnabled(false);
+       dialog_->previewCB->setChecked(false);
+       dialog_->previewCB->setEnabled(false);
+
+       string cmdname = controller().params().getCmdName();
+       if (cmdname != "include" &&
+           cmdname != "verbatiminput" &&
+           cmdname != "verbatiminput*")
+               cmdname = "input";
+
+       if (cmdname == "include") {
+               dialog_->typeCO->setCurrentIndex(0);
+
+       } else if (cmdname == "input") {
+               dialog_->typeCO->setCurrentIndex(1);
+               dialog_->previewCB->setEnabled(true);
+               dialog_->previewCB->setChecked(params.preview());
+
+       } else if (cmdname == "verbatiminput*") {
+               dialog_->typeCO->setCurrentIndex(2);
+               dialog_->visiblespaceCB->setEnabled(true);
+               dialog_->visiblespaceCB->setChecked(true);
+
+       } else if (cmdname == "verbatiminput") {
+               dialog_->typeCO->setCurrentIndex(2);
+               dialog_->visiblespaceCB->setEnabled(true);
+       }
+}
+
+
+void QInclude::apply()
+{
+       InsetCommandParams params = controller().params();
+
+       params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text())));
+       params.preview(dialog_->previewCB->isChecked());
+
+       int const item = dialog_->typeCO->currentIndex();
+       if (item == 0)
+               params.setCmdName("include");
+       else if (item == 1)
+               params.setCmdName("input");
+       else {
+               if (dialog_->visiblespaceCB->isChecked())
+                       params.setCmdName("verbatiminput*");
+               else
+                       params.setCmdName("verbatiminput");
+       }
+       controller().setParams(params);
+}
+
+
+void QInclude::browse()
+{
+       ControlInclude::Type type;
+
+       int const item = dialog_->typeCO->currentIndex();
+       if (item == 0)
+               type = ControlInclude::INCLUDE;
+       else if (item == 1)
+               type = ControlInclude::INPUT;
+       else
+               type = ControlInclude::VERBATIM;
+
+       docstring const & name =
+               controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type);
+       if (!name.empty())
+               dialog_->filenameED->setText(toqstr(name));
+}
+
+
+void QInclude::load()
+{
+       if (isValid()) {
+               string const file = fromqstr(dialog_->filenameED->text());
+               slotOK();
+               controller().load(file);
+       }
+}
+
+
+bool QInclude::isValid()
+{
+       return !dialog_->filenameED->text().isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QInclude_moc.cpp"
diff --git a/src/frontends/qt4/QIndex.C b/src/frontends/qt4/QIndex.C
deleted file mode 100644 (file)
index 3eb8d1b..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * \file QIndex.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "debug.h"
-#include "ControlCommand.h"
-#include "qt_helpers.h"
-
-#include "QIndex.h"
-#include "Qt2BC.h"
-#include "ButtonController.h"
-
-#include <QLabel>
-#include <QPushButton>
-#include <QLineEdit>
-#include <QWhatsThis>
-#include <QCloseEvent>
-
-
-using std::string;
-
-/////////////////////////////////////////////////////////////////////
-//
-// QIndexDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-namespace lyx {
-namespace frontend {
-
-QIndexDialog::QIndexDialog(QIndex * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-       connect( keywordED, SIGNAL(textChanged(const QString &)), 
-               this, SLOT(change_adaptor()));
-
-       setFocusProxy(keywordED);
-
-       keywordED->setWhatsThis( qt_(
-               "The format of the entry in the index.\n"
-               "\n"
-               "An entry can be specified as a sub-entry of\n"
-               "another with \"!\":\n"
-               "\n"
-               "cars!mileage\n"
-               "\n"
-               "You can cross-refer to another entry like so:\n"
-               "\n"
-               "cars!mileage|see{economy}\n"
-               "\n"
-               "For further details refer to the local LaTeX\n"
-               "documentation.\n")
-       );
-}
-
-
-void QIndexDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QIndexDialog::reject()
-{
-       form_->slotClose();
-}
-
-
-void QIndexDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QIndex
-//
-/////////////////////////////////////////////////////////////////////
-
-
-typedef QController<ControlCommand, QView<QIndexDialog> > IndexBase;
-
-QIndex::QIndex(Dialog & parent, docstring const & title, QString const & label)
-       : IndexBase(parent, title), label_(label)
-{
-}
-
-
-void QIndex::build_dialog()
-{
-       dialog_.reset(new QIndexDialog(this));
-
-       dialog_->keywordLA->setText(label_);
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->keywordED);
-}
-
-
-void QIndex::update_contents()
-{
-       docstring const contents = controller().params()["name"];
-       dialog_->keywordED->setText(toqstr(contents));
-
-       bc().valid(!contents.empty());
-}
-
-
-void QIndex::apply()
-{
-       controller().params()["name"] = qstring_to_ucs4(dialog_->keywordED->text());
-}
-
-
-bool QIndex::isValid()
-{
-       return !dialog_->keywordED->text().isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QIndex_moc.cpp"
diff --git a/src/frontends/qt4/QIndex.cpp b/src/frontends/qt4/QIndex.cpp
new file mode 100644 (file)
index 0000000..3eb8d1b
--- /dev/null
@@ -0,0 +1,138 @@
+/**
+ * \file QIndex.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "debug.h"
+#include "ControlCommand.h"
+#include "qt_helpers.h"
+
+#include "QIndex.h"
+#include "Qt2BC.h"
+#include "ButtonController.h"
+
+#include <QLabel>
+#include <QPushButton>
+#include <QLineEdit>
+#include <QWhatsThis>
+#include <QCloseEvent>
+
+
+using std::string;
+
+/////////////////////////////////////////////////////////////////////
+//
+// QIndexDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+namespace lyx {
+namespace frontend {
+
+QIndexDialog::QIndexDialog(QIndex * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+       connect( keywordED, SIGNAL(textChanged(const QString &)), 
+               this, SLOT(change_adaptor()));
+
+       setFocusProxy(keywordED);
+
+       keywordED->setWhatsThis( qt_(
+               "The format of the entry in the index.\n"
+               "\n"
+               "An entry can be specified as a sub-entry of\n"
+               "another with \"!\":\n"
+               "\n"
+               "cars!mileage\n"
+               "\n"
+               "You can cross-refer to another entry like so:\n"
+               "\n"
+               "cars!mileage|see{economy}\n"
+               "\n"
+               "For further details refer to the local LaTeX\n"
+               "documentation.\n")
+       );
+}
+
+
+void QIndexDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QIndexDialog::reject()
+{
+       form_->slotClose();
+}
+
+
+void QIndexDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QIndex
+//
+/////////////////////////////////////////////////////////////////////
+
+
+typedef QController<ControlCommand, QView<QIndexDialog> > IndexBase;
+
+QIndex::QIndex(Dialog & parent, docstring const & title, QString const & label)
+       : IndexBase(parent, title), label_(label)
+{
+}
+
+
+void QIndex::build_dialog()
+{
+       dialog_.reset(new QIndexDialog(this));
+
+       dialog_->keywordLA->setText(label_);
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->keywordED);
+}
+
+
+void QIndex::update_contents()
+{
+       docstring const contents = controller().params()["name"];
+       dialog_->keywordED->setText(toqstr(contents));
+
+       bc().valid(!contents.empty());
+}
+
+
+void QIndex::apply()
+{
+       controller().params()["name"] = qstring_to_ucs4(dialog_->keywordED->text());
+}
+
+
+bool QIndex::isValid()
+{
+       return !dialog_->keywordED->text().isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QIndex_moc.cpp"
diff --git a/src/frontends/qt4/QLImage.C b/src/frontends/qt4/QLImage.C
deleted file mode 100644 (file)
index 6a6c39c..0000000
+++ /dev/null
@@ -1,290 +0,0 @@
-/**
- * \file QLImage.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QLImage.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-#include "format.h"
-
-#include "graphics/GraphicsParams.h"
-
-#include "support/filename.h"
-#include "support/lstrings.h"       // ascii_lowercase
-
-#include <QPainter>
-#include <QPictureIO>
-#include <QPicture>
-#include <QImage>
-#include <QImageReader>
-
-#include <boost/bind.hpp>
-#include <boost/tuple/tuple.hpp>
-
-using lyx::support::ascii_lowercase;
-
-using boost::bind;
-
-using std::endl;
-using std::equal_to;
-using std::find_if;
-using std::string;
-
-QPictureIO StaticPicture;
-
-namespace lyx {
-namespace graphics {
-
-/// Access to this class is through this static method.
-Image::ImagePtr QLImage::newImage()
-{
-       ImagePtr ptr;
-       ptr.reset(new QLImage);
-       return ptr;
-}
-
-
-/// Return the list of loadable formats.
-Image::FormatList QLImage::loadableFormats()
-{
-       static FormatList fmts;
-
-       if (!fmts.empty())
-               return fmts;
-
-       // The formats recognised by LyX
-       Formats::const_iterator begin = formats.begin();
-       Formats::const_iterator end   = formats.end();
-
-
-//     LYXERR(Debug::GRAPHICS)
-//             << "D:/msys/home/yns/src/lyx-devel/lib/images/banner.png mis of format: "
-//             << fromqstr(Pic.pictureFormat("D:/msys/home/yns/src/lyx-devel/lib/images/banner.png"))
-//             << endl;
-//     if (Pic.pictureFormat("D:/msys/home/yns/src/lyx-devel/lib/images/banner.png"))
-//             LYXERR(Debug::GRAPHICS)
-//                     << "pictureFormat not returned NULL\n" << endl;
-//                     << "Supported formats are: " << Pic.inputFormats() << endl;
-
-       QList<QByteArray> qt_formats = QImageReader::supportedImageFormats ();
-
-       LYXERR(Debug::GRAPHICS)
-               << "\nThe image loader can load the following directly:\n";
-
-       if (qt_formats.empty())
-               LYXERR(Debug::GRAPHICS)
-                       << "\nQt4 Problem: No Format available!" << endl;
-
-       for (QList<QByteArray>::const_iterator it =qt_formats.begin(); it != qt_formats.end(); ++it) {
-
-               LYXERR(Debug::GRAPHICS) << (const char *) *it << ", ";
-
-               string ext = ascii_lowercase((const char *) *it);
-
-               // special case
-               if (ext == "jpeg")
-                       ext = "jpg";
-
-               Formats::const_iterator fit =
-                       find_if(begin, end,
-                               bind(equal_to<string>(),
-                                    bind(&Format::extension, _1),
-                                    ext));
-               if (fit != end)
-                       fmts.push_back(fit->name());
-       }
-
-       if (lyxerr.debugging()) {
-               LYXERR(Debug::GRAPHICS)
-                       << "\nOf these, LyX recognises the following formats:\n";
-
-               FormatList::const_iterator fbegin = fmts.begin();
-               FormatList::const_iterator fend   = fmts.end();
-               for (FormatList::const_iterator fit = fbegin; fit != fend; ++fit) {
-                       if (fit != fbegin)
-                               LYXERR(Debug::GRAPHICS) << ", ";
-                       LYXERR(Debug::GRAPHICS) << *fit;
-               }
-               LYXERR(Debug::GRAPHICS) << '\n' << endl;
-       }
-
-       return fmts;
-}
-
-
-QLImage::QLImage()
-       : Image()
-{
-}
-
-
-QLImage::QLImage(QLImage const & other)
-       : Image(other), original_(other.original_),
-         transformed_(other.transformed_),
-         transformed_pixmap_(other.transformed_pixmap_)
-{}
-
-
-Image * QLImage::clone_impl() const
-{
-       return new QLImage(*this);
-}
-
-
-unsigned int QLImage::getWidth_impl() const
-{
-       return transformed_.width();
-}
-
-
-unsigned int QLImage::getHeight_impl() const
-{
-       return transformed_.height();
-}
-
-
-void QLImage::load_impl(support::FileName const & filename)
-{
-       if (!original_.isNull()) {
-               LYXERR(Debug::GRAPHICS)
-                       << "Image is loaded already!" << endl;
-               finishedLoading(false);
-               return;
-       }
-
-       if (!original_.load(toqstr(filename.absFilename()))) {
-               LYXERR(Debug::GRAPHICS)
-                       << "Unable to open image" << endl;
-               finishedLoading(false);
-               return;
-       }
-       transformed_ = original_;
-       finishedLoading(true);
-}
-
-
-namespace {
-
-// This code is taken from KImageEffect::toGray
-QImage & toGray(QImage & img)
-{
-       if (img.width() == 0 || img.height() == 0)
-               return img;
-
-       int const pixels = img.depth() > 8 ?
-               img.width() * img.height() : img.numColors();
-
-       unsigned int *data = img.depth() > 8 ? 
-               reinterpret_cast<unsigned int *>(img.bits()) :
-               reinterpret_cast<unsigned int *>(&img.colorTable()[0]);
-
-       for(int i = 0; i < pixels; ++i){
-               int const val = qGray(data[i]);
-               data[i] = qRgba(val, val, val, qAlpha(data[i]));
-       }
-       return img;
-}
-
-} // namespace anon
-
-
-bool QLImage::setPixmap_impl(Params const & params)
-{
-       if (original_.isNull() || params.display == NoDisplay)
-               return false;
-
-       switch (params.display) {
-       case GrayscaleDisplay: {
-               toGray(transformed_);
-               break;
-       }
-
-       case MonochromeDisplay: {
-               transformed_.convertToFormat(transformed_.format(), Qt::MonoOnly);
-               break;
-       }
-
-       default:
-               break;
-       }
-
-       transformed_pixmap_ = QPixmap::fromImage(transformed_);
-       return true;
-}
-
-
-void QLImage::clip_impl(Params const & params)
-{
-       if (transformed_.isNull())
-               return;
-
-       if (params.bb.empty())
-               // No clipping is necessary.
-               return;
-
-       int const new_width  = params.bb.xr - params.bb.xl;
-       int const new_height = params.bb.yt - params.bb.yb;
-
-       // No need to check if the width, height are > 0 because the
-       // Bounding Box would be empty() in this case.
-       if (new_width > original_.width() || new_height > original_.height()) {
-               // Bounds are invalid.
-               return;
-       }
-
-       if (new_width == original_.width() && new_height == original_.height())
-               return;
-
-       int const xoffset_l = params.bb.xl;
-       int const yoffset_t = (original_.height() > int(params.bb.yt) ?
-                              original_.height() - params.bb.yt : 0);
-
-       transformed_ = original_.copy(xoffset_l, yoffset_t,
-                                     new_width, new_height);
-}
-
-
-void QLImage::rotate_impl(Params const & params)
-{
-       if (transformed_.isNull())
-               return;
-
-       if (!params.angle)
-               return;
-
-       QMatrix m;
-       m.rotate(-params.angle);
-
-       transformed_ = transformed_.transformed(m);
-}
-
-
-void QLImage::scale_impl(Params const & params)
-{
-       if (transformed_.isNull())
-               return;
-
-       unsigned int width;
-       unsigned int height;
-       boost::tie(width, height) = getScaledDimensions(params);
-
-       if (width == getWidth() && height == getHeight())
-               return;
-
-       QMatrix m;
-       m.scale(double(width) / getWidth(), double(height) / getHeight());
-       transformed_ = transformed_.transformed(m);
-}
-
-} // namespace graphics
-} // lyx
diff --git a/src/frontends/qt4/QLImage.cpp b/src/frontends/qt4/QLImage.cpp
new file mode 100644 (file)
index 0000000..6a6c39c
--- /dev/null
@@ -0,0 +1,290 @@
+/**
+ * \file QLImage.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QLImage.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+#include "format.h"
+
+#include "graphics/GraphicsParams.h"
+
+#include "support/filename.h"
+#include "support/lstrings.h"       // ascii_lowercase
+
+#include <QPainter>
+#include <QPictureIO>
+#include <QPicture>
+#include <QImage>
+#include <QImageReader>
+
+#include <boost/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+
+using lyx::support::ascii_lowercase;
+
+using boost::bind;
+
+using std::endl;
+using std::equal_to;
+using std::find_if;
+using std::string;
+
+QPictureIO StaticPicture;
+
+namespace lyx {
+namespace graphics {
+
+/// Access to this class is through this static method.
+Image::ImagePtr QLImage::newImage()
+{
+       ImagePtr ptr;
+       ptr.reset(new QLImage);
+       return ptr;
+}
+
+
+/// Return the list of loadable formats.
+Image::FormatList QLImage::loadableFormats()
+{
+       static FormatList fmts;
+
+       if (!fmts.empty())
+               return fmts;
+
+       // The formats recognised by LyX
+       Formats::const_iterator begin = formats.begin();
+       Formats::const_iterator end   = formats.end();
+
+
+//     LYXERR(Debug::GRAPHICS)
+//             << "D:/msys/home/yns/src/lyx-devel/lib/images/banner.png mis of format: "
+//             << fromqstr(Pic.pictureFormat("D:/msys/home/yns/src/lyx-devel/lib/images/banner.png"))
+//             << endl;
+//     if (Pic.pictureFormat("D:/msys/home/yns/src/lyx-devel/lib/images/banner.png"))
+//             LYXERR(Debug::GRAPHICS)
+//                     << "pictureFormat not returned NULL\n" << endl;
+//                     << "Supported formats are: " << Pic.inputFormats() << endl;
+
+       QList<QByteArray> qt_formats = QImageReader::supportedImageFormats ();
+
+       LYXERR(Debug::GRAPHICS)
+               << "\nThe image loader can load the following directly:\n";
+
+       if (qt_formats.empty())
+               LYXERR(Debug::GRAPHICS)
+                       << "\nQt4 Problem: No Format available!" << endl;
+
+       for (QList<QByteArray>::const_iterator it =qt_formats.begin(); it != qt_formats.end(); ++it) {
+
+               LYXERR(Debug::GRAPHICS) << (const char *) *it << ", ";
+
+               string ext = ascii_lowercase((const char *) *it);
+
+               // special case
+               if (ext == "jpeg")
+                       ext = "jpg";
+
+               Formats::const_iterator fit =
+                       find_if(begin, end,
+                               bind(equal_to<string>(),
+                                    bind(&Format::extension, _1),
+                                    ext));
+               if (fit != end)
+                       fmts.push_back(fit->name());
+       }
+
+       if (lyxerr.debugging()) {
+               LYXERR(Debug::GRAPHICS)
+                       << "\nOf these, LyX recognises the following formats:\n";
+
+               FormatList::const_iterator fbegin = fmts.begin();
+               FormatList::const_iterator fend   = fmts.end();
+               for (FormatList::const_iterator fit = fbegin; fit != fend; ++fit) {
+                       if (fit != fbegin)
+                               LYXERR(Debug::GRAPHICS) << ", ";
+                       LYXERR(Debug::GRAPHICS) << *fit;
+               }
+               LYXERR(Debug::GRAPHICS) << '\n' << endl;
+       }
+
+       return fmts;
+}
+
+
+QLImage::QLImage()
+       : Image()
+{
+}
+
+
+QLImage::QLImage(QLImage const & other)
+       : Image(other), original_(other.original_),
+         transformed_(other.transformed_),
+         transformed_pixmap_(other.transformed_pixmap_)
+{}
+
+
+Image * QLImage::clone_impl() const
+{
+       return new QLImage(*this);
+}
+
+
+unsigned int QLImage::getWidth_impl() const
+{
+       return transformed_.width();
+}
+
+
+unsigned int QLImage::getHeight_impl() const
+{
+       return transformed_.height();
+}
+
+
+void QLImage::load_impl(support::FileName const & filename)
+{
+       if (!original_.isNull()) {
+               LYXERR(Debug::GRAPHICS)
+                       << "Image is loaded already!" << endl;
+               finishedLoading(false);
+               return;
+       }
+
+       if (!original_.load(toqstr(filename.absFilename()))) {
+               LYXERR(Debug::GRAPHICS)
+                       << "Unable to open image" << endl;
+               finishedLoading(false);
+               return;
+       }
+       transformed_ = original_;
+       finishedLoading(true);
+}
+
+
+namespace {
+
+// This code is taken from KImageEffect::toGray
+QImage & toGray(QImage & img)
+{
+       if (img.width() == 0 || img.height() == 0)
+               return img;
+
+       int const pixels = img.depth() > 8 ?
+               img.width() * img.height() : img.numColors();
+
+       unsigned int *data = img.depth() > 8 ? 
+               reinterpret_cast<unsigned int *>(img.bits()) :
+               reinterpret_cast<unsigned int *>(&img.colorTable()[0]);
+
+       for(int i = 0; i < pixels; ++i){
+               int const val = qGray(data[i]);
+               data[i] = qRgba(val, val, val, qAlpha(data[i]));
+       }
+       return img;
+}
+
+} // namespace anon
+
+
+bool QLImage::setPixmap_impl(Params const & params)
+{
+       if (original_.isNull() || params.display == NoDisplay)
+               return false;
+
+       switch (params.display) {
+       case GrayscaleDisplay: {
+               toGray(transformed_);
+               break;
+       }
+
+       case MonochromeDisplay: {
+               transformed_.convertToFormat(transformed_.format(), Qt::MonoOnly);
+               break;
+       }
+
+       default:
+               break;
+       }
+
+       transformed_pixmap_ = QPixmap::fromImage(transformed_);
+       return true;
+}
+
+
+void QLImage::clip_impl(Params const & params)
+{
+       if (transformed_.isNull())
+               return;
+
+       if (params.bb.empty())
+               // No clipping is necessary.
+               return;
+
+       int const new_width  = params.bb.xr - params.bb.xl;
+       int const new_height = params.bb.yt - params.bb.yb;
+
+       // No need to check if the width, height are > 0 because the
+       // Bounding Box would be empty() in this case.
+       if (new_width > original_.width() || new_height > original_.height()) {
+               // Bounds are invalid.
+               return;
+       }
+
+       if (new_width == original_.width() && new_height == original_.height())
+               return;
+
+       int const xoffset_l = params.bb.xl;
+       int const yoffset_t = (original_.height() > int(params.bb.yt) ?
+                              original_.height() - params.bb.yt : 0);
+
+       transformed_ = original_.copy(xoffset_l, yoffset_t,
+                                     new_width, new_height);
+}
+
+
+void QLImage::rotate_impl(Params const & params)
+{
+       if (transformed_.isNull())
+               return;
+
+       if (!params.angle)
+               return;
+
+       QMatrix m;
+       m.rotate(-params.angle);
+
+       transformed_ = transformed_.transformed(m);
+}
+
+
+void QLImage::scale_impl(Params const & params)
+{
+       if (transformed_.isNull())
+               return;
+
+       unsigned int width;
+       unsigned int height;
+       boost::tie(width, height) = getScaledDimensions(params);
+
+       if (width == getWidth() && height == getHeight())
+               return;
+
+       QMatrix m;
+       m.scale(double(width) / getWidth(), double(height) / getHeight());
+       transformed_ = transformed_.transformed(m);
+}
+
+} // namespace graphics
+} // lyx
diff --git a/src/frontends/qt4/QLMenubar.C b/src/frontends/qt4/QLMenubar.C
deleted file mode 100644 (file)
index 9c8b5ab..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/**
- * \file qt4/QLMenubar.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-// Qt defines a macro 'signals' that clashes with a boost namespace.
-// All is well if the namespace is visible first.
-#include "GuiView.h"
-
-#include "Action.h"
-#include "QLMenubar.h"
-#include "QLPopupMenu.h"
-
-#include "qt_helpers.h"
-#include "support/lstrings.h"
-
-#include "MenuBackend.h"
-
-#include "debug.h"
-
-#include <QCursor>
-#include <QMenuBar>
-
-using std::pair;
-using std::string;
-using std::endl;
-
-namespace lyx {
-namespace frontend {
-
-// MacOSX specific stuff is at the end.
-
-QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
-       : owner_(static_cast<GuiView*>(view)), menubackend_(mbe)
-{
-       macxMenuBarInit();
-
-       LYXERR(Debug::GUI) << "populating menu bar" << to_utf8(menubackend_.getMenubar().name()) << endl;
-
-       if (menubackend_.getMenubar().size() == 0) {
-               LYXERR(Debug::GUI) << "\tERROR: empty menu bar"
-                       << to_utf8(menubackend_.getMenubar().name()) << endl;
-               return;
-               //                      continue;
-       }
-       else {
-               LYXERR(Debug::GUI) << "menu bar entries "
-                       << menubackend_.getMenubar().size();
-       }
-
-       Menu menu;
-       menubackend_.expand(menubackend_.getMenubar(), menu, owner_->buffer());
-
-       Menu::const_iterator m = menu.begin();
-       Menu::const_iterator end = menu.end();
-
-       for (; m != end; ++m) {
-
-               if (m->kind() != MenuItem::Submenu) {
-                       LYXERR(Debug::GUI) << "\tERROR: not a submenu "
-                               << to_utf8(m->label()) << endl;
-                       continue;
-               }
-
-               LYXERR(Debug::GUI) << "menu bar item " << to_utf8(m->label())
-                       << " is a submenu named " << to_utf8(m->submenuname()) << endl;
-
-               docstring name = m->submenuname();
-               if (!menubackend_.hasMenu(name)) {
-                       LYXERR(Debug::GUI) << "\tERROR: " << to_utf8(name)
-                               << " submenu has no menu!" << endl;
-                       continue;
-               }
-
-               Menu menu;
-               menubackend_.expand(menubackend_.getMenubar(), menu, owner_->buffer());
-
-               QLPopupMenu * qMenu = new QLPopupMenu(this, *m, true);
-               owner_->menuBar()->addMenu(qMenu);
-
-               pair<NameMap::iterator, bool> I = name_map_.insert(make_pair(name, qMenu));
-               if (!I.second) {
-                       LYXERR(Debug::GUI) << "\tERROR: " << to_utf8(name)
-                               << " submenu is already there!" << endl;
-               }
-/*
-               QObject::connect(qMenu, SIGNAL(aboutToShow()), this, SLOT(update()));
-               QObject::connect(qMenu, SIGNAL(triggered(QAction *)), this, SLOT(update()));
-               QObject::connect(qMenu->menuAction(), SIGNAL(triggered()), this, SLOT(update()));
-*/
-       }
-       //QObject::connect(owner_->menuBar(), SIGNAL(triggered()), this, SLOT(update()));
-}
-
-void QLMenubar::openByName(docstring const & name)
-{
-       NameMap::const_iterator const cit = name_map_.find(name);
-       if (cit == name_map_.end())
-               return;
-
-       // I (Abdel) don't understand this comment:
-       // this will have to do I'm afraid.
-       cit->second->exec(QCursor::pos());
-}
-
-
-void QLMenubar::update()
-{ }
-
-GuiView * QLMenubar::view()
-{
-       return owner_;
-}
-
-
-MenuBackend const & QLMenubar::backend()
-{
-       return menubackend_;
-}
-
-
-/// Some special Qt/Mac support hacks
-
-/*
-  Here is what the Qt documentation says about how a menubar is chosen:
-
-     1) If the window has a QMenuBar then it is used. 2) If the window
-     is a modal then its menubar is used. If no menubar is specified
-     then a default menubar is used (as documented below) 3) If the
-     window has no parent then the default menubar is used (as
-     documented below).
-
-     The above 3 steps are applied all the way up the parent window
-     chain until one of the above are satisifed. If all else fails a
-     default menubar will be created, the default menubar on Qt/Mac is
-     an empty menubar, however you can create a different default
-     menubar by creating a parentless QMenuBar, the first one created
-     will thus be designated the default menubar, and will be used
-     whenever a default menubar is needed.
-
-  Thus, for Qt/Mac, we add the menus to a free standing menubar, so
-  that this menubar will be used also when one of LyX' dialogs has
-  focus. (JMarc)
-*/
-QMenuBar * QLMenubar::menuBar() const
-{
-#ifdef Q_WS_MACX
-       return mac_menubar_.get();
-#else
-       return owner_->menuBar();
-#endif
-}
-
-#ifdef Q_WS_MACX
-extern void qt_mac_set_menubar_merge(bool b);
-#endif
-
-void QLMenubar::macxMenuBarInit()
-{
-#ifdef Q_WS_MACX
-       mac_menubar_.reset(new QMenuBar);
-
-# if QT_VERSION >= 0x040200
-       /* Since Qt 4.2, the qt/mac menu code has special code for
-          specifying the role of a menu entry. However, it does not
-          work very well with our scheme of creating menus on demand,
-          and therefore we need to put these entries in a special
-          invisible menu. (JMarc)
-       */
-
-       /* The entries of our special mac menu. If we add support for
-        * special entries in MenuBackend, we could imagine something
-        * like
-        *    SpecialItem About " "About LyX" "dialog-show aboutlyx"
-        * and therefore avoid hardcoding. I am not sure it is worth
-        * the hassle, though. (JMarc)
-        */
-       struct MacMenuEntry {
-               kb_action action;
-               char const * arg;
-               char const * label;
-               QAction::MenuRole role;
-       };
-
-       MacMenuEntry entries[] = {
-               {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX", 
-                QAction::AboutRole},
-               {LFUN_DIALOG_SHOW, "prefs", "Preferences", 
-                QAction::PreferencesRole},
-               {LFUN_RECONFIGURE, "", "Reconfigure", 
-                QAction::ApplicationSpecificRole},
-               {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
-       };
-       const size_t num_entries = sizeof(entries) / sizeof(MacMenuEntry);
-
-       // the special menu for MenuBackend. 
-       Menu special;
-       for (size_t i = 0 ; i < num_entries ; ++i) {
-               FuncRequest const func(entries[i].action, 
-                                      from_utf8(entries[i].arg));
-               special.add(MenuItem(MenuItem::Command, 
-                                    from_utf8(entries[i].label), 
-                                    func));
-       }
-       menubackend_.specialMenu(special);
-
-       // add the entries to a QMenu that will eventually be empty
-       // and therefore invisible.
-       QMenu * qMenu = owner_->menuBar()->addMenu("special");
-
-       // we do not use 'special' because it is a temporary variable,
-       // whereas MenuBackend::specialMenu points to a persistent
-       // copy.
-       Menu::const_iterator cit = menubackend_.specialMenu().begin();
-       Menu::const_iterator end = menubackend_.specialMenu().end();
-       for (size_t i = 0 ; cit != end ; ++cit, ++i) {
-               Action * action = new Action(*owner_, cit->label(), 
-                                            cit->func());
-               action->setMenuRole(entries[i].role);
-               qMenu->addAction(action);
-
-       }
-# else
-       qt_mac_set_menubar_merge(false);
-# endif // QT_VERSION >= 0x040200
-#endif // Q_WS_MACX
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QLMenubar_moc.cpp"
diff --git a/src/frontends/qt4/QLMenubar.cpp b/src/frontends/qt4/QLMenubar.cpp
new file mode 100644 (file)
index 0000000..9c8b5ab
--- /dev/null
@@ -0,0 +1,239 @@
+/**
+ * \file qt4/QLMenubar.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+// Qt defines a macro 'signals' that clashes with a boost namespace.
+// All is well if the namespace is visible first.
+#include "GuiView.h"
+
+#include "Action.h"
+#include "QLMenubar.h"
+#include "QLPopupMenu.h"
+
+#include "qt_helpers.h"
+#include "support/lstrings.h"
+
+#include "MenuBackend.h"
+
+#include "debug.h"
+
+#include <QCursor>
+#include <QMenuBar>
+
+using std::pair;
+using std::string;
+using std::endl;
+
+namespace lyx {
+namespace frontend {
+
+// MacOSX specific stuff is at the end.
+
+QLMenubar::QLMenubar(LyXView * view, MenuBackend & mbe)
+       : owner_(static_cast<GuiView*>(view)), menubackend_(mbe)
+{
+       macxMenuBarInit();
+
+       LYXERR(Debug::GUI) << "populating menu bar" << to_utf8(menubackend_.getMenubar().name()) << endl;
+
+       if (menubackend_.getMenubar().size() == 0) {
+               LYXERR(Debug::GUI) << "\tERROR: empty menu bar"
+                       << to_utf8(menubackend_.getMenubar().name()) << endl;
+               return;
+               //                      continue;
+       }
+       else {
+               LYXERR(Debug::GUI) << "menu bar entries "
+                       << menubackend_.getMenubar().size();
+       }
+
+       Menu menu;
+       menubackend_.expand(menubackend_.getMenubar(), menu, owner_->buffer());
+
+       Menu::const_iterator m = menu.begin();
+       Menu::const_iterator end = menu.end();
+
+       for (; m != end; ++m) {
+
+               if (m->kind() != MenuItem::Submenu) {
+                       LYXERR(Debug::GUI) << "\tERROR: not a submenu "
+                               << to_utf8(m->label()) << endl;
+                       continue;
+               }
+
+               LYXERR(Debug::GUI) << "menu bar item " << to_utf8(m->label())
+                       << " is a submenu named " << to_utf8(m->submenuname()) << endl;
+
+               docstring name = m->submenuname();
+               if (!menubackend_.hasMenu(name)) {
+                       LYXERR(Debug::GUI) << "\tERROR: " << to_utf8(name)
+                               << " submenu has no menu!" << endl;
+                       continue;
+               }
+
+               Menu menu;
+               menubackend_.expand(menubackend_.getMenubar(), menu, owner_->buffer());
+
+               QLPopupMenu * qMenu = new QLPopupMenu(this, *m, true);
+               owner_->menuBar()->addMenu(qMenu);
+
+               pair<NameMap::iterator, bool> I = name_map_.insert(make_pair(name, qMenu));
+               if (!I.second) {
+                       LYXERR(Debug::GUI) << "\tERROR: " << to_utf8(name)
+                               << " submenu is already there!" << endl;
+               }
+/*
+               QObject::connect(qMenu, SIGNAL(aboutToShow()), this, SLOT(update()));
+               QObject::connect(qMenu, SIGNAL(triggered(QAction *)), this, SLOT(update()));
+               QObject::connect(qMenu->menuAction(), SIGNAL(triggered()), this, SLOT(update()));
+*/
+       }
+       //QObject::connect(owner_->menuBar(), SIGNAL(triggered()), this, SLOT(update()));
+}
+
+void QLMenubar::openByName(docstring const & name)
+{
+       NameMap::const_iterator const cit = name_map_.find(name);
+       if (cit == name_map_.end())
+               return;
+
+       // I (Abdel) don't understand this comment:
+       // this will have to do I'm afraid.
+       cit->second->exec(QCursor::pos());
+}
+
+
+void QLMenubar::update()
+{ }
+
+GuiView * QLMenubar::view()
+{
+       return owner_;
+}
+
+
+MenuBackend const & QLMenubar::backend()
+{
+       return menubackend_;
+}
+
+
+/// Some special Qt/Mac support hacks
+
+/*
+  Here is what the Qt documentation says about how a menubar is chosen:
+
+     1) If the window has a QMenuBar then it is used. 2) If the window
+     is a modal then its menubar is used. If no menubar is specified
+     then a default menubar is used (as documented below) 3) If the
+     window has no parent then the default menubar is used (as
+     documented below).
+
+     The above 3 steps are applied all the way up the parent window
+     chain until one of the above are satisifed. If all else fails a
+     default menubar will be created, the default menubar on Qt/Mac is
+     an empty menubar, however you can create a different default
+     menubar by creating a parentless QMenuBar, the first one created
+     will thus be designated the default menubar, and will be used
+     whenever a default menubar is needed.
+
+  Thus, for Qt/Mac, we add the menus to a free standing menubar, so
+  that this menubar will be used also when one of LyX' dialogs has
+  focus. (JMarc)
+*/
+QMenuBar * QLMenubar::menuBar() const
+{
+#ifdef Q_WS_MACX
+       return mac_menubar_.get();
+#else
+       return owner_->menuBar();
+#endif
+}
+
+#ifdef Q_WS_MACX
+extern void qt_mac_set_menubar_merge(bool b);
+#endif
+
+void QLMenubar::macxMenuBarInit()
+{
+#ifdef Q_WS_MACX
+       mac_menubar_.reset(new QMenuBar);
+
+# if QT_VERSION >= 0x040200
+       /* Since Qt 4.2, the qt/mac menu code has special code for
+          specifying the role of a menu entry. However, it does not
+          work very well with our scheme of creating menus on demand,
+          and therefore we need to put these entries in a special
+          invisible menu. (JMarc)
+       */
+
+       /* The entries of our special mac menu. If we add support for
+        * special entries in MenuBackend, we could imagine something
+        * like
+        *    SpecialItem About " "About LyX" "dialog-show aboutlyx"
+        * and therefore avoid hardcoding. I am not sure it is worth
+        * the hassle, though. (JMarc)
+        */
+       struct MacMenuEntry {
+               kb_action action;
+               char const * arg;
+               char const * label;
+               QAction::MenuRole role;
+       };
+
+       MacMenuEntry entries[] = {
+               {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX", 
+                QAction::AboutRole},
+               {LFUN_DIALOG_SHOW, "prefs", "Preferences", 
+                QAction::PreferencesRole},
+               {LFUN_RECONFIGURE, "", "Reconfigure", 
+                QAction::ApplicationSpecificRole},
+               {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
+       };
+       const size_t num_entries = sizeof(entries) / sizeof(MacMenuEntry);
+
+       // the special menu for MenuBackend. 
+       Menu special;
+       for (size_t i = 0 ; i < num_entries ; ++i) {
+               FuncRequest const func(entries[i].action, 
+                                      from_utf8(entries[i].arg));
+               special.add(MenuItem(MenuItem::Command, 
+                                    from_utf8(entries[i].label), 
+                                    func));
+       }
+       menubackend_.specialMenu(special);
+
+       // add the entries to a QMenu that will eventually be empty
+       // and therefore invisible.
+       QMenu * qMenu = owner_->menuBar()->addMenu("special");
+
+       // we do not use 'special' because it is a temporary variable,
+       // whereas MenuBackend::specialMenu points to a persistent
+       // copy.
+       Menu::const_iterator cit = menubackend_.specialMenu().begin();
+       Menu::const_iterator end = menubackend_.specialMenu().end();
+       for (size_t i = 0 ; cit != end ; ++cit, ++i) {
+               Action * action = new Action(*owner_, cit->label(), 
+                                            cit->func());
+               action->setMenuRole(entries[i].role);
+               qMenu->addAction(action);
+
+       }
+# else
+       qt_mac_set_menubar_merge(false);
+# endif // QT_VERSION >= 0x040200
+#endif // Q_WS_MACX
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QLMenubar_moc.cpp"
diff --git a/src/frontends/qt4/QLPainter.C b/src/frontends/qt4/QLPainter.C
deleted file mode 100644 (file)
index 8bec6ae..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/**
- * \file QLPainter.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include <QTextLayout>
-
-#include "QLPainter.h"
-
-#include "GuiApplication.h"
-#include "GuiFontMetrics.h"
-#include "QLImage.h"
-
-#include "GuiApplication.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-#include "language.h"
-#include "LColor.h"
-
-#include "support/unicode.h"
-
-using std::endl;
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-QLPainter::QLPainter(QPaintDevice * device)
-       : QPainter(device), Painter()
-{
-       // new QPainter has default QPen:
-       current_color_ = LColor::black;
-       current_ls_ = line_solid;
-       current_lw_ = line_thin;
-}
-
-
-QLPainter::~QLPainter()
-{
-       QPainter::end();
-       //lyxerr << "QLPainter::end()" << endl;
-}
-
-
-void QLPainter::setQPainterPen(LColor_color col,
-       Painter::line_style ls, Painter::line_width lw)
-{
-       if (col == current_color_ && ls == current_ls_ && lw == current_lw_)
-               return;
-
-       current_color_ = col;
-       current_ls_ = ls;
-       current_lw_ = lw;
-
-       QPen pen = QPainter::pen();
-
-       pen.setColor(guiApp->colorCache().get(col));
-
-       switch (ls) {
-               case line_solid: pen.setStyle(Qt::SolidLine); break;
-               case line_onoffdash: pen.setStyle(Qt::DotLine); break;
-       }
-
-       switch (lw) {
-               case line_thin: pen.setWidth(0); break;
-               case line_thick: pen.setWidth(3); break;
-       }
-
-       setPen(pen);
-}
-
-
-void QLPainter::point(int x, int y, LColor_color col)
-{
-       if (!isDrawingEnabled())
-               return;
-
-       setQPainterPen(col);
-       drawPoint(x, y);
-}
-
-
-void QLPainter::line(int x1, int y1, int x2, int y2,
-       LColor_color col,
-       line_style ls,
-       line_width lw)
-{
-       if (!isDrawingEnabled())
-               return;
-
-       setQPainterPen(col, ls, lw);
-       setRenderHint(Antialiasing, x1 != x2 && y1 != y2);
-       drawLine(x1, y1, x2, y2);
-       setRenderHint(Antialiasing, false);
-}
-
-
-void QLPainter::lines(int const * xp, int const * yp, int np,
-       LColor_color col,
-       line_style ls,
-       line_width lw)
-{
-       // FIXME ?
-
-       // Must use new as np is not known at compile time.
-       boost::scoped_array<QPoint> points(new QPoint[np]);
-
-       bool antialias = false;
-       for (int i = 0; i < np; ++i) {
-               points[i].setX(xp[i]);
-               points[i].setY(yp[i]);
-               if (i != 0) 
-                       antialias |= xp[i-1] != xp[i] && yp[i-1] != yp[i];
-       }
-
-       if (!isDrawingEnabled())
-               return;
-
-       setQPainterPen(col, ls, lw);
-       setRenderHint(Antialiasing, antialias);
-       drawPolyline(points.get(), np);
-       setRenderHint(Antialiasing, false);
-}
-
-
-void QLPainter::rectangle(int x, int y, int w, int h,
-       LColor_color col,
-       line_style ls,
-       line_width lw)
-{
-       if (!isDrawingEnabled())
-               return;
-
-       setQPainterPen(col, ls, lw);
-       drawRect(x, y, w, h);
-}
-
-
-void QLPainter::fillRectangle(int x, int y, int w, int h, LColor_color col)
-{
-       fillRect(x, y, w, h, guiApp->colorCache().get(col));
-}
-
-
-void QLPainter::arc(int x, int y, unsigned int w, unsigned int h,
-       int a1, int a2, LColor_color col)
-{
-       if (!isDrawingEnabled())
-               return;
-
-       // LyX usings 1/64ths degree, Qt usings 1/16th
-       setQPainterPen(col);
-       setRenderHint(Antialiasing, true);
-       drawArc(x, y, w, h, a1 / 4, a2 / 4);
-       setRenderHint(Antialiasing, false);
-}
-
-
-void QLPainter::image(int x, int y, int w, int h, graphics::Image const & i)
-{
-       graphics::QLImage const & qlimage =
-               static_cast<graphics::QLImage const &>(i);
-
-       fillRectangle(x, y, w, h, LColor::graphicsbg);
-
-       if (!isDrawingEnabled())
-               return;
-
-       drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
-}
-
-
-int QLPainter::text(int x, int y, char_type c, LyXFont const & f)
-{
-       docstring s(1, c);
-       return text(x, y, s, f);
-}
-
-
-int QLPainter::smallCapsText(int x, int y,
-       QString const & s, LyXFont const & f)
-{
-       LyXFont smallfont(f);
-       smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
-
-       QFont const & qfont = guiApp->guiFontLoader().get(f);
-       QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont);
-
-       setQPainterPen(f.realColor());
-       int textwidth = 0;
-       size_t const ls = s.length();
-       for (unsigned int i = 0; i < ls; ++i) {
-               QChar const c = s[i].toUpper();
-               if (c != s.at(i)) {
-                       setFont(qsmallfont);
-               } else {
-                       setFont(qfont);
-               }
-               if (isDrawingEnabled())
-                       drawText(x + textwidth, y, c);
-               textwidth += fontMetrics().width(c);
-       }
-       return textwidth;
-}
-
-
-int QLPainter::text(int x, int y, docstring const & s,
-               LyXFont const & f)
-{
-       /* Caution: The following ucs4 to QString conversions work for symbol fonts
-       only because they are no real conversions but simple casts in reality.
-       When we want to draw a symbol or calculate the metrics we pass the position
-       of the symbol in the font (as given in lib/symbols) as a char_type to the
-       frontend. This is just wrong, because the symbol is no UCS4 character at
-       all. You can think of this number as the code point of the symbol in a
-       custom symbol encoding. It works because this char_type is lateron again
-       interpreted as a position in the font again.
-       The correct solution would be to have extra functions for symbols, but that
-       would require to duplicate a lot of frontend and mathed support code.
-       */
-       QString str = toqstr(s);
-
-#if 0
-       // HACK: QT3 refuses to show single compose characters
-       //       Still needed with Qt4?
-       if (ls == 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2)
-               str = ' ' + str;
-#endif
-
-       QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
-
-       int textwidth;
-
-       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               setQPainterPen(f.realColor());
-               if (font() != fi.font)
-                       setFont(fi.font);
-               // We need to draw the text as LTR as we use our own bidi code.
-               setLayoutDirection(Qt::LeftToRight);
-               if (isDrawingEnabled()) {
-                       LYXERR(Debug::PAINTING) << "draw " << std::string(str.toUtf8())
-                               << " at " << x << "," << y << std::endl;
-                       // Qt4 does not display a glyph whose codepoint is the
-                       // same as that of a soft-hyphen (0x00ad), unless it
-                       // occurs at a line-break. As a kludge, we force Qt to
-                       // render this glyph using a one-column line.
-                       if (s.size() == 1 && str[0].unicode() == 0x00ad) {
-                               QTextLayout adsymbol(str);
-                               adsymbol.setFont(fi.font);
-                               adsymbol.beginLayout();
-                               QTextLine line = adsymbol.createLine();
-                               line.setNumColumns(1);
-                               line.setPosition(QPointF(0, -line.ascent()));
-                               adsymbol.endLayout();
-                               line.draw(this, QPointF(x, y));
-                       } else
-                               drawText(x, y, str);
-               }
-               // Here we use the font width cache instead of
-               //   textwidth = fontMetrics().width(str);
-               // because the above is awfully expensive on MacOSX
-               textwidth = fi.metrics->width(str);
-       } else {
-               textwidth = smallCapsText(x, y, str, f);
-       }
-
-       if (f.underbar() == LyXFont::ON) {
-               underline(f, x, y, textwidth);
-       }
-
-       return textwidth;
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
diff --git a/src/frontends/qt4/QLPainter.cpp b/src/frontends/qt4/QLPainter.cpp
new file mode 100644 (file)
index 0000000..8bec6ae
--- /dev/null
@@ -0,0 +1,286 @@
+/**
+ * \file QLPainter.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include <QTextLayout>
+
+#include "QLPainter.h"
+
+#include "GuiApplication.h"
+#include "GuiFontMetrics.h"
+#include "QLImage.h"
+
+#include "GuiApplication.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+#include "language.h"
+#include "LColor.h"
+
+#include "support/unicode.h"
+
+using std::endl;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+QLPainter::QLPainter(QPaintDevice * device)
+       : QPainter(device), Painter()
+{
+       // new QPainter has default QPen:
+       current_color_ = LColor::black;
+       current_ls_ = line_solid;
+       current_lw_ = line_thin;
+}
+
+
+QLPainter::~QLPainter()
+{
+       QPainter::end();
+       //lyxerr << "QLPainter::end()" << endl;
+}
+
+
+void QLPainter::setQPainterPen(LColor_color col,
+       Painter::line_style ls, Painter::line_width lw)
+{
+       if (col == current_color_ && ls == current_ls_ && lw == current_lw_)
+               return;
+
+       current_color_ = col;
+       current_ls_ = ls;
+       current_lw_ = lw;
+
+       QPen pen = QPainter::pen();
+
+       pen.setColor(guiApp->colorCache().get(col));
+
+       switch (ls) {
+               case line_solid: pen.setStyle(Qt::SolidLine); break;
+               case line_onoffdash: pen.setStyle(Qt::DotLine); break;
+       }
+
+       switch (lw) {
+               case line_thin: pen.setWidth(0); break;
+               case line_thick: pen.setWidth(3); break;
+       }
+
+       setPen(pen);
+}
+
+
+void QLPainter::point(int x, int y, LColor_color col)
+{
+       if (!isDrawingEnabled())
+               return;
+
+       setQPainterPen(col);
+       drawPoint(x, y);
+}
+
+
+void QLPainter::line(int x1, int y1, int x2, int y2,
+       LColor_color col,
+       line_style ls,
+       line_width lw)
+{
+       if (!isDrawingEnabled())
+               return;
+
+       setQPainterPen(col, ls, lw);
+       setRenderHint(Antialiasing, x1 != x2 && y1 != y2);
+       drawLine(x1, y1, x2, y2);
+       setRenderHint(Antialiasing, false);
+}
+
+
+void QLPainter::lines(int const * xp, int const * yp, int np,
+       LColor_color col,
+       line_style ls,
+       line_width lw)
+{
+       // FIXME ?
+
+       // Must use new as np is not known at compile time.
+       boost::scoped_array<QPoint> points(new QPoint[np]);
+
+       bool antialias = false;
+       for (int i = 0; i < np; ++i) {
+               points[i].setX(xp[i]);
+               points[i].setY(yp[i]);
+               if (i != 0) 
+                       antialias |= xp[i-1] != xp[i] && yp[i-1] != yp[i];
+       }
+
+       if (!isDrawingEnabled())
+               return;
+
+       setQPainterPen(col, ls, lw);
+       setRenderHint(Antialiasing, antialias);
+       drawPolyline(points.get(), np);
+       setRenderHint(Antialiasing, false);
+}
+
+
+void QLPainter::rectangle(int x, int y, int w, int h,
+       LColor_color col,
+       line_style ls,
+       line_width lw)
+{
+       if (!isDrawingEnabled())
+               return;
+
+       setQPainterPen(col, ls, lw);
+       drawRect(x, y, w, h);
+}
+
+
+void QLPainter::fillRectangle(int x, int y, int w, int h, LColor_color col)
+{
+       fillRect(x, y, w, h, guiApp->colorCache().get(col));
+}
+
+
+void QLPainter::arc(int x, int y, unsigned int w, unsigned int h,
+       int a1, int a2, LColor_color col)
+{
+       if (!isDrawingEnabled())
+               return;
+
+       // LyX usings 1/64ths degree, Qt usings 1/16th
+       setQPainterPen(col);
+       setRenderHint(Antialiasing, true);
+       drawArc(x, y, w, h, a1 / 4, a2 / 4);
+       setRenderHint(Antialiasing, false);
+}
+
+
+void QLPainter::image(int x, int y, int w, int h, graphics::Image const & i)
+{
+       graphics::QLImage const & qlimage =
+               static_cast<graphics::QLImage const &>(i);
+
+       fillRectangle(x, y, w, h, LColor::graphicsbg);
+
+       if (!isDrawingEnabled())
+               return;
+
+       drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
+}
+
+
+int QLPainter::text(int x, int y, char_type c, LyXFont const & f)
+{
+       docstring s(1, c);
+       return text(x, y, s, f);
+}
+
+
+int QLPainter::smallCapsText(int x, int y,
+       QString const & s, LyXFont const & f)
+{
+       LyXFont smallfont(f);
+       smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
+
+       QFont const & qfont = guiApp->guiFontLoader().get(f);
+       QFont const & qsmallfont = guiApp->guiFontLoader().get(smallfont);
+
+       setQPainterPen(f.realColor());
+       int textwidth = 0;
+       size_t const ls = s.length();
+       for (unsigned int i = 0; i < ls; ++i) {
+               QChar const c = s[i].toUpper();
+               if (c != s.at(i)) {
+                       setFont(qsmallfont);
+               } else {
+                       setFont(qfont);
+               }
+               if (isDrawingEnabled())
+                       drawText(x + textwidth, y, c);
+               textwidth += fontMetrics().width(c);
+       }
+       return textwidth;
+}
+
+
+int QLPainter::text(int x, int y, docstring const & s,
+               LyXFont const & f)
+{
+       /* Caution: The following ucs4 to QString conversions work for symbol fonts
+       only because they are no real conversions but simple casts in reality.
+       When we want to draw a symbol or calculate the metrics we pass the position
+       of the symbol in the font (as given in lib/symbols) as a char_type to the
+       frontend. This is just wrong, because the symbol is no UCS4 character at
+       all. You can think of this number as the code point of the symbol in a
+       custom symbol encoding. It works because this char_type is lateron again
+       interpreted as a position in the font again.
+       The correct solution would be to have extra functions for symbols, but that
+       would require to duplicate a lot of frontend and mathed support code.
+       */
+       QString str = toqstr(s);
+
+#if 0
+       // HACK: QT3 refuses to show single compose characters
+       //       Still needed with Qt4?
+       if (ls == 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2)
+               str = ' ' + str;
+#endif
+
+       QLFontInfo & fi = guiApp->guiFontLoader().fontinfo(f);
+
+       int textwidth;
+
+       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               setQPainterPen(f.realColor());
+               if (font() != fi.font)
+                       setFont(fi.font);
+               // We need to draw the text as LTR as we use our own bidi code.
+               setLayoutDirection(Qt::LeftToRight);
+               if (isDrawingEnabled()) {
+                       LYXERR(Debug::PAINTING) << "draw " << std::string(str.toUtf8())
+                               << " at " << x << "," << y << std::endl;
+                       // Qt4 does not display a glyph whose codepoint is the
+                       // same as that of a soft-hyphen (0x00ad), unless it
+                       // occurs at a line-break. As a kludge, we force Qt to
+                       // render this glyph using a one-column line.
+                       if (s.size() == 1 && str[0].unicode() == 0x00ad) {
+                               QTextLayout adsymbol(str);
+                               adsymbol.setFont(fi.font);
+                               adsymbol.beginLayout();
+                               QTextLine line = adsymbol.createLine();
+                               line.setNumColumns(1);
+                               line.setPosition(QPointF(0, -line.ascent()));
+                               adsymbol.endLayout();
+                               line.draw(this, QPointF(x, y));
+                       } else
+                               drawText(x, y, str);
+               }
+               // Here we use the font width cache instead of
+               //   textwidth = fontMetrics().width(str);
+               // because the above is awfully expensive on MacOSX
+               textwidth = fi.metrics->width(str);
+       } else {
+               textwidth = smallCapsText(x, y, str, f);
+       }
+
+       if (f.underbar() == LyXFont::ON) {
+               underline(f, x, y, textwidth);
+       }
+
+       return textwidth;
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
diff --git a/src/frontends/qt4/QLPopupMenu.C b/src/frontends/qt4/QLPopupMenu.C
deleted file mode 100644 (file)
index f583642..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * \file QLPopupMenu.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include <boost/current_function.hpp>
-
-// Qt defines a macro 'signals' that clashes with a boost namespace.
-// All is well if the namespace is visible first.
-#include "GuiView.h"
-
-#include "Action.h"
-#include "QLPopupMenu.h"
-#include "QLMenubar.h"
-#include "qt_helpers.h"
-#include "MenuBackend.h"
-
-#include "support/lstrings.h"
-#include "debug.h"
-
-
-using std::make_pair;
-using std::string;
-using std::pair;
-using std::endl;
-
-
-namespace lyx {
-namespace frontend {
-
-QLPopupMenu::QLPopupMenu(QLMenubar * owner,
-                                                MenuItem const & mi, bool topLevelMenu)
-       : owner_(owner)
-{
-       name_ = mi.submenuname();
-
-       setTitle(toqstr(getLabel(mi)));
-
-       if (topLevelMenu)
-               connect(this, SIGNAL(aboutToShow()), this, SLOT(update()));
-}
-
-
-void QLPopupMenu::update()
-{
-       LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION << endl;
-       LYXERR(Debug::GUI) << "\tTriggered menu: " << to_utf8(name_) << endl;
-
-       clear();
-
-       if (name_.empty())
-               return;
-
-       // Here, We make sure that theLyXFunc points to the correct LyXView.
-       theLyXFunc().setLyXView(owner_->view());
-
-       Menu const & fromLyxMenu = owner_->backend().getMenu(name_);
-       owner_->backend().expand(fromLyxMenu, topLevelMenu_, owner_->view()->buffer());
-
-       if (!owner_->backend().hasMenu(topLevelMenu_.name())) {
-               LYXERR(Debug::GUI) << "\tWARNING: menu seems empty"     
-                       << to_utf8(topLevelMenu_.name()) << endl;
-       }
-       populate(this, &topLevelMenu_);
-}
-
-void QLPopupMenu::populate(QMenu* qMenu, Menu * menu)
-{
-       LYXERR(Debug::GUI) << "populating menu " << to_utf8(menu->name()) ;
-       if (menu->size() == 0) {
-               LYXERR(Debug::GUI) << "\tERROR: empty menu "
-                       << to_utf8(menu->name()) << endl;
-               return;
-       }
-       else {
-               LYXERR(Debug::GUI) << " *****  menu entries " << menu->size() << endl;
-       }
-
-       Menu::const_iterator m = menu->begin();
-       Menu::const_iterator end = menu->end();
-
-       for (; m != end; ++m) {
-
-               if (m->kind() == MenuItem::Separator) {
-
-                       qMenu->addSeparator();
-                       LYXERR(Debug::GUI) << "adding Menubar Separator" << endl;
-
-               } else if (m->kind() == MenuItem::Submenu) {
-
-                       LYXERR(Debug::GUI) << "** creating New Sub-Menu "
-                               << to_utf8(getLabel(*m)) << endl;
-                       QMenu * subMenu = qMenu->addMenu(toqstr(getLabel(*m)));
-                       populate(subMenu, m->submenu());
-
-               } else { // we have a MenuItem::Command
-
-                       LYXERR(Debug::GUI) << "creating Menu Item "
-                               << to_utf8(m->label()) << endl;
-
-                       docstring label = getLabel(*m);
-                       addBinding(label, *m);
-
-                       Action * action = new Action(*(owner_->view()),
-                                                    label, m->func());
-                       qMenu->addAction(action);
-               }
-       }
-}
-
-
-docstring const QLPopupMenu::getLabel(MenuItem const & mi)
-{
-       docstring const shortcut = mi.shortcut();
-       docstring label = support::subst(mi.label(),
-       from_ascii("&"), from_ascii("&&"));
-
-       if (!shortcut.empty()) {
-               docstring::size_type pos = label.find(shortcut);
-               if (pos != docstring::npos)
-                       label.insert(pos, 1, char_type('&'));
-       }
-
-       return label;
-}
-
-void QLPopupMenu::addBinding(docstring & label, MenuItem const & mi)
-{
-#ifdef Q_WS_MACX
-       docstring const binding(mi.binding(false));
-#else
-       docstring const binding(mi.binding(true));
-#endif
-       if (!binding.empty()) {
-               label += '\t' + binding;
-       }
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QLPopupMenu_moc.cpp"
diff --git a/src/frontends/qt4/QLPopupMenu.cpp b/src/frontends/qt4/QLPopupMenu.cpp
new file mode 100644 (file)
index 0000000..f583642
--- /dev/null
@@ -0,0 +1,150 @@
+/**
+ * \file QLPopupMenu.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include <boost/current_function.hpp>
+
+// Qt defines a macro 'signals' that clashes with a boost namespace.
+// All is well if the namespace is visible first.
+#include "GuiView.h"
+
+#include "Action.h"
+#include "QLPopupMenu.h"
+#include "QLMenubar.h"
+#include "qt_helpers.h"
+#include "MenuBackend.h"
+
+#include "support/lstrings.h"
+#include "debug.h"
+
+
+using std::make_pair;
+using std::string;
+using std::pair;
+using std::endl;
+
+
+namespace lyx {
+namespace frontend {
+
+QLPopupMenu::QLPopupMenu(QLMenubar * owner,
+                                                MenuItem const & mi, bool topLevelMenu)
+       : owner_(owner)
+{
+       name_ = mi.submenuname();
+
+       setTitle(toqstr(getLabel(mi)));
+
+       if (topLevelMenu)
+               connect(this, SIGNAL(aboutToShow()), this, SLOT(update()));
+}
+
+
+void QLPopupMenu::update()
+{
+       LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION << endl;
+       LYXERR(Debug::GUI) << "\tTriggered menu: " << to_utf8(name_) << endl;
+
+       clear();
+
+       if (name_.empty())
+               return;
+
+       // Here, We make sure that theLyXFunc points to the correct LyXView.
+       theLyXFunc().setLyXView(owner_->view());
+
+       Menu const & fromLyxMenu = owner_->backend().getMenu(name_);
+       owner_->backend().expand(fromLyxMenu, topLevelMenu_, owner_->view()->buffer());
+
+       if (!owner_->backend().hasMenu(topLevelMenu_.name())) {
+               LYXERR(Debug::GUI) << "\tWARNING: menu seems empty"     
+                       << to_utf8(topLevelMenu_.name()) << endl;
+       }
+       populate(this, &topLevelMenu_);
+}
+
+void QLPopupMenu::populate(QMenu* qMenu, Menu * menu)
+{
+       LYXERR(Debug::GUI) << "populating menu " << to_utf8(menu->name()) ;
+       if (menu->size() == 0) {
+               LYXERR(Debug::GUI) << "\tERROR: empty menu "
+                       << to_utf8(menu->name()) << endl;
+               return;
+       }
+       else {
+               LYXERR(Debug::GUI) << " *****  menu entries " << menu->size() << endl;
+       }
+
+       Menu::const_iterator m = menu->begin();
+       Menu::const_iterator end = menu->end();
+
+       for (; m != end; ++m) {
+
+               if (m->kind() == MenuItem::Separator) {
+
+                       qMenu->addSeparator();
+                       LYXERR(Debug::GUI) << "adding Menubar Separator" << endl;
+
+               } else if (m->kind() == MenuItem::Submenu) {
+
+                       LYXERR(Debug::GUI) << "** creating New Sub-Menu "
+                               << to_utf8(getLabel(*m)) << endl;
+                       QMenu * subMenu = qMenu->addMenu(toqstr(getLabel(*m)));
+                       populate(subMenu, m->submenu());
+
+               } else { // we have a MenuItem::Command
+
+                       LYXERR(Debug::GUI) << "creating Menu Item "
+                               << to_utf8(m->label()) << endl;
+
+                       docstring label = getLabel(*m);
+                       addBinding(label, *m);
+
+                       Action * action = new Action(*(owner_->view()),
+                                                    label, m->func());
+                       qMenu->addAction(action);
+               }
+       }
+}
+
+
+docstring const QLPopupMenu::getLabel(MenuItem const & mi)
+{
+       docstring const shortcut = mi.shortcut();
+       docstring label = support::subst(mi.label(),
+       from_ascii("&"), from_ascii("&&"));
+
+       if (!shortcut.empty()) {
+               docstring::size_type pos = label.find(shortcut);
+               if (pos != docstring::npos)
+                       label.insert(pos, 1, char_type('&'));
+       }
+
+       return label;
+}
+
+void QLPopupMenu::addBinding(docstring & label, MenuItem const & mi)
+{
+#ifdef Q_WS_MACX
+       docstring const binding(mi.binding(false));
+#else
+       docstring const binding(mi.binding(true));
+#endif
+       if (!binding.empty()) {
+               label += '\t' + binding;
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QLPopupMenu_moc.cpp"
diff --git a/src/frontends/qt4/QLPrintDialog.C b/src/frontends/qt4/QLPrintDialog.C
deleted file mode 100644 (file)
index 85d8126..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * \file QLPrintDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "controllers/ControlPrint.h"
-#include "QLPrintDialog.h"
-#include "QPrint.h"
-#include "qt_helpers.h"
-
-#include <qcheckbox.h>
-#include <qlineedit.h>
-#include <qpushbutton.h>
-#include <qradiobutton.h>
-
-namespace lyx {
-namespace frontend {
-
-QLPrintDialog::QLPrintDialog(QPrint * f)
-       : form_(f)
-{
-       setupUi(this);
-
-       connect(printPB, SIGNAL(clicked()),
-               form_, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               form_, SLOT(slotClose()));
-
-    connect( copiesSB, SIGNAL( valueChanged(int) ), this, SLOT( copiesChanged(int) ) );
-    connect( printerED, SIGNAL( textChanged(const QString&) ), this, SLOT( printerChanged() ) );
-    connect( fileED, SIGNAL( textChanged(const QString&) ), this, SLOT( fileChanged() ) );
-    connect( browsePB, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
-    connect( allRB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
-    connect( reverseCB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
-    connect( collateCB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
-    connect( fromED, SIGNAL( textChanged(const QString&) ), this, SLOT( pagerangeChanged() ) );
-    connect( fromED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
-    connect( toED, SIGNAL( textChanged(const QString&) ), this, SLOT( pagerangeChanged() ) );
-    connect( toED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
-    connect( fileRB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
-    connect( printerRB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
-    connect( rangeRB, SIGNAL( toggled(bool) ), fromED, SLOT( setEnabled(bool) ) );
-    connect( rangeRB, SIGNAL( toggled(bool) ), toED, SLOT( setEnabled(bool) ) );
-}
-
-
-void QLPrintDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QLPrintDialog::browseClicked()
-{
-       QString file = toqstr(form_->controller().browse(docstring()));
-       if (!file.isNull()) {
-               fileED->setText(file);
-               form_->changed();
-       }
-}
-
-
-void QLPrintDialog::fileChanged()
-{
-       if (!fileED->text().isEmpty())
-               fileRB->setChecked(true);
-       form_->changed();
-}
-
-
-void QLPrintDialog::copiesChanged(int i)
-{
-       collateCB->setEnabled(i != 1);
-       form_->changed();
-}
-
-
-void QLPrintDialog::printerChanged()
-{
-       printerRB->setChecked(true);
-       form_->changed();
-}
-
-
-void QLPrintDialog::pagerangeChanged()
-{
-       form_->changed();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QLPrintDialog_moc.cpp"
diff --git a/src/frontends/qt4/QLPrintDialog.cpp b/src/frontends/qt4/QLPrintDialog.cpp
new file mode 100644 (file)
index 0000000..85d8126
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * \file QLPrintDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "controllers/ControlPrint.h"
+#include "QLPrintDialog.h"
+#include "QPrint.h"
+#include "qt_helpers.h"
+
+#include <qcheckbox.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+
+namespace lyx {
+namespace frontend {
+
+QLPrintDialog::QLPrintDialog(QPrint * f)
+       : form_(f)
+{
+       setupUi(this);
+
+       connect(printPB, SIGNAL(clicked()),
+               form_, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               form_, SLOT(slotClose()));
+
+    connect( copiesSB, SIGNAL( valueChanged(int) ), this, SLOT( copiesChanged(int) ) );
+    connect( printerED, SIGNAL( textChanged(const QString&) ), this, SLOT( printerChanged() ) );
+    connect( fileED, SIGNAL( textChanged(const QString&) ), this, SLOT( fileChanged() ) );
+    connect( browsePB, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
+    connect( allRB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
+    connect( reverseCB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
+    connect( collateCB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
+    connect( fromED, SIGNAL( textChanged(const QString&) ), this, SLOT( pagerangeChanged() ) );
+    connect( fromED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
+    connect( toED, SIGNAL( textChanged(const QString&) ), this, SLOT( pagerangeChanged() ) );
+    connect( toED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
+    connect( fileRB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
+    connect( printerRB, SIGNAL( clicked() ), this, SLOT( change_adaptor() ) );
+    connect( rangeRB, SIGNAL( toggled(bool) ), fromED, SLOT( setEnabled(bool) ) );
+    connect( rangeRB, SIGNAL( toggled(bool) ), toED, SLOT( setEnabled(bool) ) );
+}
+
+
+void QLPrintDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QLPrintDialog::browseClicked()
+{
+       QString file = toqstr(form_->controller().browse(docstring()));
+       if (!file.isNull()) {
+               fileED->setText(file);
+               form_->changed();
+       }
+}
+
+
+void QLPrintDialog::fileChanged()
+{
+       if (!fileED->text().isEmpty())
+               fileRB->setChecked(true);
+       form_->changed();
+}
+
+
+void QLPrintDialog::copiesChanged(int i)
+{
+       collateCB->setEnabled(i != 1);
+       form_->changed();
+}
+
+
+void QLPrintDialog::printerChanged()
+{
+       printerRB->setChecked(true);
+       form_->changed();
+}
+
+
+void QLPrintDialog::pagerangeChanged()
+{
+       form_->changed();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QLPrintDialog_moc.cpp"
diff --git a/src/frontends/qt4/QLToolbar.C b/src/frontends/qt4/QLToolbar.C
deleted file mode 100644 (file)
index 65af778..0000000
+++ /dev/null
@@ -1,392 +0,0 @@
-/**
- * \file qt4/QLToolbar.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author John Levon
- * \author Jean-Marc Lasgouttes
- * \author Angus Leeming
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "buffer.h"
-#include "bufferparams.h"
-#include "debug.h"
-#include "funcrequest.h"
-#include "FuncStatus.h"
-#include "gettext.h"
-#include "lyxfunc.h"
-#include "IconPalette.h"
-
-#include "GuiView.h"
-#include "QLToolbar.h"
-#include "LyXAction.h"
-#include "Action.h"
-#include "qt_helpers.h"
-#include "InsertTableWidget.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
-#include "controllers/ControlMath.h"
-#include "ToolbarBackend.h"
-
-#include <QComboBox>
-#include <QToolBar>
-#include <QToolButton>
-#include <QAction>
-#include <QPixmap>
-
-
-namespace lyx {
-
-using std::string;
-using std::endl;
-using support::FileName;
-using support::libFileSearch;
-using support::subst;
-
-
-using support::libFileSearch;
-using support::subst;
-
-namespace frontend {
-
-namespace {
-
-LyXTextClass const & getTextClass(LyXView const & lv)
-{
-       return lv.buffer()->params().getLyXTextClass();
-}
-
-
-} // namespace anon
-
-
-QLayoutBox::QLayoutBox(QToolBar * toolbar, GuiView & owner)
-       : owner_(owner)
-{
-       combo_ = new QComboBox;
-       combo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
-       combo_->setFocusPolicy(Qt::ClickFocus);
-       combo_->setMinimumWidth(combo_->sizeHint().width());
-       combo_->setMaxVisibleItems(100);
-
-       QObject::connect(combo_, SIGNAL(activated(const QString &)),
-                        this, SLOT(selected(const QString &)));
-
-       toolbar->addWidget(combo_);
-}
-
-
-void QLayoutBox::set(string const & layout)
-{
-       LyXTextClass const & tc = getTextClass(owner_);
-
-       QString const & name = qt_(tc[layout]->name());
-
-       int i = 0;
-       for (; i < combo_->count(); ++i) {
-               if (name == combo_->itemText(i))
-                       break;
-       }
-
-       if (i == combo_->count()) {
-               lyxerr << "Trying to select non existent layout type "
-                       << fromqstr(name) << endl;
-               return;
-       }
-
-       combo_->setCurrentIndex(i);
-}
-
-
-void QLayoutBox::update()
-{
-       LyXTextClass const & tc = getTextClass(owner_);
-
-       combo_->setUpdatesEnabled(false);
-
-       combo_->clear();
-
-       LyXTextClass::const_iterator it = tc.begin();
-       LyXTextClass::const_iterator const end = tc.end();
-       for (; it != end; ++it) {
-               // ignore obsolete entries
-               if ((*it)->obsoleted_by().empty())
-                       combo_->addItem(qt_((*it)->name()));
-       }
-
-       // needed to recalculate size hint
-       combo_->hide();
-       combo_->setMinimumWidth(combo_->sizeHint().width());
-       combo_->show();
-
-       combo_->setUpdatesEnabled(true);
-       combo_->update();
-}
-
-
-void QLayoutBox::clear()
-{
-       combo_->clear();
-}
-
-
-void QLayoutBox::open()
-{
-       combo_->showPopup();
-}
-
-
-void QLayoutBox::setEnabled(bool enable)
-{
-       // Workaround for Qt bug where setEnabled(true) closes
-       // the popup
-       if (enable != combo_->isEnabled())
-               combo_->setEnabled(enable);
-}
-
-
-void QLayoutBox::selected(const QString & str)
-{
-       string const sel = fromqstr(str);
-
-       owner_.setFocus();
-
-       layoutSelected(owner_, sel);
-}
-
-
-QLToolbar::QLToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
-       : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner)
-{
-       // give visual separation between adjacent toolbars
-       addSeparator();
-
-       // TODO: save toolbar position
-       setMovable(true);
-
-       ToolbarInfo::item_iterator it = tbinfo.items.begin();
-       ToolbarInfo::item_iterator end = tbinfo.items.end();
-       for (; it != end; ++it)
-               add(*it);
-}
-
-
-void QLToolbar::add(ToolbarItem const & item)
-{
-       switch (item.type_) {
-       case ToolbarItem::SEPARATOR:
-               addSeparator();
-               break;
-       case ToolbarItem::LAYOUTS:
-               layout_.reset(new QLayoutBox(this, owner_));
-               break;
-       case ToolbarItem::MINIBUFFER:
-               owner_.addCommandBuffer(this);
-               /// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
-               //setHorizontalStretchable(true);
-               break;
-       case ToolbarItem::TABLEINSERT: {
-               QToolButton * tb = new QToolButton;
-               tb->setCheckable(true);
-               tb->setIcon(QPixmap(toqstr(getIcon(FuncRequest(LFUN_TABULAR_INSERT)))));
-               tb->setToolTip(qt_(to_ascii(item.label_)));
-               tb->setStatusTip(qt_(to_ascii(item.label_)));
-               InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
-               connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
-               connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
-               connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
-               addWidget(tb);
-               break;
-               }
-       case ToolbarItem::ICONPALETTE: {
-               QToolButton * tb = new QToolButton(this);
-               tb->setCheckable(true);
-               tb->setToolTip(qt_(to_ascii(item.label_)));
-               tb->setStatusTip(qt_(to_ascii(item.label_)));
-               tb->setText(qt_(to_ascii(item.label_)));
-               connect(this, SIGNAL(iconSizeChanged(const QSize &)),
-                       tb, SLOT(setIconSize(const QSize &)));
-
-               IconPalette * panel = new IconPalette(tb);
-               connect(this, SIGNAL(updated()), panel, SLOT(updateParent()));
-               ToolbarInfo const & tbinfo = toolbarbackend.getToolbar(item.name_);
-               ToolbarInfo::item_iterator it = tbinfo.items.begin();
-               ToolbarInfo::item_iterator const end = tbinfo.items.end();
-               for (; it != end; ++it) 
-                       if (!getStatus(it->func_).unknown()) {
-                               Action * action = new Action(owner_,
-                                       getIcon(it->func_),
-                                       it->label_,
-                                       it->func_,
-                                       it->label_);
-                               panel->addButton(action);
-                               ActionVector.push_back(action);
-                               // use the icon of first action for the toolbar button
-                               if (it == tbinfo.items.begin())
-                                       tb->setIcon(QPixmap(getIcon(it->func_).c_str()));
-                       }
-               connect(tb, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
-               connect(panel, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
-               addWidget(tb);
-               break;
-               }
-       case ToolbarItem::POPUPMENU: {
-               QToolButton * tb = new QToolButton;
-               tb->setPopupMode(QToolButton::InstantPopup);
-               tb->setToolTip(qt_(to_ascii(item.label_)));
-               tb->setStatusTip(qt_(to_ascii(item.label_)));
-               tb->setText(qt_(to_ascii(item.label_)));
-               FileName icon_path = libFileSearch("images/math", item.name_, "xpm");
-               tb->setIcon(QIcon(toqstr(icon_path.absFilename())));
-               connect(this, SIGNAL(iconSizeChanged(const QSize &)),
-                       tb, SLOT(setIconSize(const QSize &)));
-
-               ButtonMenu * m = new ButtonMenu(qt_(to_ascii(item.label_)), tb);
-               connect(this, SIGNAL(updated()), m, SLOT(updateParent()));
-               ToolbarInfo const & tbinfo = toolbarbackend.getToolbar(item.name_);
-               ToolbarInfo::item_iterator it = tbinfo.items.begin();
-               ToolbarInfo::item_iterator const end = tbinfo.items.end();
-               for (; it != end; ++it)
-                       if (!getStatus(it->func_).unknown()) {
-                               Action * action = new Action(owner_,
-                                       getIcon(it->func_, false),
-                                       it->label_,
-                                       it->func_,
-                                       it->label_);
-                               m->add(action);
-                               ActionVector.push_back(action);
-                       }
-               tb->setMenu(m);
-               addWidget(tb);
-               break;
-               }
-       case ToolbarItem::COMMAND: {
-               if (getStatus(item.func_).unknown())
-                       break;
-
-               Action * action = new Action(owner_,
-                       getIcon(item.func_),
-                       item.label_,
-                       item.func_,
-                       item.label_);
-               addAction(action);
-               ActionVector.push_back(action);
-               break;
-               }
-       default:
-               break;
-       }
-}
-
-
-void QLToolbar::hide(bool)
-{
-       QToolBar::hide();
-}
-
-
-void QLToolbar::show(bool)
-{
-       QToolBar::show();
-}
-
-
-void QLToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
-{
-       // if tbinfo.state == auto *do not* set on/off
-       if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
-               if (QLToolbar::isVisible())
-                       tbinfo.state = ToolbarSection::ToolbarInfo::ON;
-               else
-                       tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
-       }
-       //      
-       // no need to save it here.
-       Qt::ToolBarArea loc = owner_.toolBarArea(this);
-
-       if (loc == Qt::TopToolBarArea)
-               tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
-       else if (loc == Qt::BottomToolBarArea)
-               tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
-       else if (loc == Qt::RightToolBarArea)
-               tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
-       else if (loc == Qt::LeftToolBarArea)
-               tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
-       else
-               tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
-       
-       // save toolbar position. They are not used to restore toolbar position 
-       // now because move(x,y) does not work for toolbar.
-       tbinfo.posx = pos().x();
-       tbinfo.posy = pos().y();
-}
-
-
-void QLToolbar::update()
-{
-       // This is a speed bottleneck because this is called on every keypress
-       // and update calls getStatus, which copies the cursor at least two times
-       for (size_t i = 0; i < ActionVector.size(); ++i)
-               ActionVector[i]->update();
-
-       // emit signal
-       updated();
-}
-
-
-string const getIcon(FuncRequest const & f, bool unknown)
-{
-       using frontend::find_xpm;
-
-       string fullname;
-
-       switch (f.action) {
-       case LFUN_MATH_INSERT:
-               if (!f.argument().empty())
-                       fullname = find_xpm(to_utf8(f.argument()).substr(1));
-               break;
-       case LFUN_MATH_DELIM:
-       case LFUN_MATH_BIGDELIM:
-               fullname = find_xpm(to_utf8(f.argument()));
-               break;
-       default:
-               string const name = lyxaction.getActionName(f.action);
-               string xpm_name(name);
-
-               if (!f.argument().empty())
-                       xpm_name = subst(name + ' ' + to_utf8(f.argument()), ' ', '_');
-
-               fullname = libFileSearch("images", xpm_name, "xpm").absFilename();
-
-               if (fullname.empty()) {
-                       // try without the argument
-                       fullname = libFileSearch("images", name, "xpm").absFilename();
-               }
-       }
-
-       if (!fullname.empty()) {
-               LYXERR(Debug::GUI) << "Full icon name is `"
-                                  << fullname << '\'' << endl;
-               return fullname;
-       }
-
-       LYXERR(Debug::GUI) << "Cannot find icon for command \""
-                          << lyxaction.getActionName(f.action)
-                          << '(' << to_utf8(f.argument()) << ")\"" << endl;
-       if (unknown)
-               return libFileSearch("images", "unknown", "xpm").absFilename();
-       else
-               return string();
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QLToolbar_moc.cpp"
diff --git a/src/frontends/qt4/QLToolbar.cpp b/src/frontends/qt4/QLToolbar.cpp
new file mode 100644 (file)
index 0000000..65af778
--- /dev/null
@@ -0,0 +1,392 @@
+/**
+ * \file qt4/QLToolbar.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ * \author Jean-Marc Lasgouttes
+ * \author Angus Leeming
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "buffer.h"
+#include "bufferparams.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "FuncStatus.h"
+#include "gettext.h"
+#include "lyxfunc.h"
+#include "IconPalette.h"
+
+#include "GuiView.h"
+#include "QLToolbar.h"
+#include "LyXAction.h"
+#include "Action.h"
+#include "qt_helpers.h"
+#include "InsertTableWidget.h"
+#include "support/filetools.h"
+#include "support/lstrings.h"
+#include "controllers/ControlMath.h"
+#include "ToolbarBackend.h"
+
+#include <QComboBox>
+#include <QToolBar>
+#include <QToolButton>
+#include <QAction>
+#include <QPixmap>
+
+
+namespace lyx {
+
+using std::string;
+using std::endl;
+using support::FileName;
+using support::libFileSearch;
+using support::subst;
+
+
+using support::libFileSearch;
+using support::subst;
+
+namespace frontend {
+
+namespace {
+
+LyXTextClass const & getTextClass(LyXView const & lv)
+{
+       return lv.buffer()->params().getLyXTextClass();
+}
+
+
+} // namespace anon
+
+
+QLayoutBox::QLayoutBox(QToolBar * toolbar, GuiView & owner)
+       : owner_(owner)
+{
+       combo_ = new QComboBox;
+       combo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+       combo_->setFocusPolicy(Qt::ClickFocus);
+       combo_->setMinimumWidth(combo_->sizeHint().width());
+       combo_->setMaxVisibleItems(100);
+
+       QObject::connect(combo_, SIGNAL(activated(const QString &)),
+                        this, SLOT(selected(const QString &)));
+
+       toolbar->addWidget(combo_);
+}
+
+
+void QLayoutBox::set(string const & layout)
+{
+       LyXTextClass const & tc = getTextClass(owner_);
+
+       QString const & name = qt_(tc[layout]->name());
+
+       int i = 0;
+       for (; i < combo_->count(); ++i) {
+               if (name == combo_->itemText(i))
+                       break;
+       }
+
+       if (i == combo_->count()) {
+               lyxerr << "Trying to select non existent layout type "
+                       << fromqstr(name) << endl;
+               return;
+       }
+
+       combo_->setCurrentIndex(i);
+}
+
+
+void QLayoutBox::update()
+{
+       LyXTextClass const & tc = getTextClass(owner_);
+
+       combo_->setUpdatesEnabled(false);
+
+       combo_->clear();
+
+       LyXTextClass::const_iterator it = tc.begin();
+       LyXTextClass::const_iterator const end = tc.end();
+       for (; it != end; ++it) {
+               // ignore obsolete entries
+               if ((*it)->obsoleted_by().empty())
+                       combo_->addItem(qt_((*it)->name()));
+       }
+
+       // needed to recalculate size hint
+       combo_->hide();
+       combo_->setMinimumWidth(combo_->sizeHint().width());
+       combo_->show();
+
+       combo_->setUpdatesEnabled(true);
+       combo_->update();
+}
+
+
+void QLayoutBox::clear()
+{
+       combo_->clear();
+}
+
+
+void QLayoutBox::open()
+{
+       combo_->showPopup();
+}
+
+
+void QLayoutBox::setEnabled(bool enable)
+{
+       // Workaround for Qt bug where setEnabled(true) closes
+       // the popup
+       if (enable != combo_->isEnabled())
+               combo_->setEnabled(enable);
+}
+
+
+void QLayoutBox::selected(const QString & str)
+{
+       string const sel = fromqstr(str);
+
+       owner_.setFocus();
+
+       layoutSelected(owner_, sel);
+}
+
+
+QLToolbar::QLToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
+       : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner)
+{
+       // give visual separation between adjacent toolbars
+       addSeparator();
+
+       // TODO: save toolbar position
+       setMovable(true);
+
+       ToolbarInfo::item_iterator it = tbinfo.items.begin();
+       ToolbarInfo::item_iterator end = tbinfo.items.end();
+       for (; it != end; ++it)
+               add(*it);
+}
+
+
+void QLToolbar::add(ToolbarItem const & item)
+{
+       switch (item.type_) {
+       case ToolbarItem::SEPARATOR:
+               addSeparator();
+               break;
+       case ToolbarItem::LAYOUTS:
+               layout_.reset(new QLayoutBox(this, owner_));
+               break;
+       case ToolbarItem::MINIBUFFER:
+               owner_.addCommandBuffer(this);
+               /// \todo find a Qt4 equivalent to setHorizontalStretchable(true);
+               //setHorizontalStretchable(true);
+               break;
+       case ToolbarItem::TABLEINSERT: {
+               QToolButton * tb = new QToolButton;
+               tb->setCheckable(true);
+               tb->setIcon(QPixmap(toqstr(getIcon(FuncRequest(LFUN_TABULAR_INSERT)))));
+               tb->setToolTip(qt_(to_ascii(item.label_)));
+               tb->setStatusTip(qt_(to_ascii(item.label_)));
+               InsertTableWidget * iv = new InsertTableWidget(owner_, tb);
+               connect(tb, SIGNAL(clicked(bool)), iv, SLOT(show(bool)));
+               connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
+               connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
+               addWidget(tb);
+               break;
+               }
+       case ToolbarItem::ICONPALETTE: {
+               QToolButton * tb = new QToolButton(this);
+               tb->setCheckable(true);
+               tb->setToolTip(qt_(to_ascii(item.label_)));
+               tb->setStatusTip(qt_(to_ascii(item.label_)));
+               tb->setText(qt_(to_ascii(item.label_)));
+               connect(this, SIGNAL(iconSizeChanged(const QSize &)),
+                       tb, SLOT(setIconSize(const QSize &)));
+
+               IconPalette * panel = new IconPalette(tb);
+               connect(this, SIGNAL(updated()), panel, SLOT(updateParent()));
+               ToolbarInfo const & tbinfo = toolbarbackend.getToolbar(item.name_);
+               ToolbarInfo::item_iterator it = tbinfo.items.begin();
+               ToolbarInfo::item_iterator const end = tbinfo.items.end();
+               for (; it != end; ++it) 
+                       if (!getStatus(it->func_).unknown()) {
+                               Action * action = new Action(owner_,
+                                       getIcon(it->func_),
+                                       it->label_,
+                                       it->func_,
+                                       it->label_);
+                               panel->addButton(action);
+                               ActionVector.push_back(action);
+                               // use the icon of first action for the toolbar button
+                               if (it == tbinfo.items.begin())
+                                       tb->setIcon(QPixmap(getIcon(it->func_).c_str()));
+                       }
+               connect(tb, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool)));
+               connect(panel, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
+               addWidget(tb);
+               break;
+               }
+       case ToolbarItem::POPUPMENU: {
+               QToolButton * tb = new QToolButton;
+               tb->setPopupMode(QToolButton::InstantPopup);
+               tb->setToolTip(qt_(to_ascii(item.label_)));
+               tb->setStatusTip(qt_(to_ascii(item.label_)));
+               tb->setText(qt_(to_ascii(item.label_)));
+               FileName icon_path = libFileSearch("images/math", item.name_, "xpm");
+               tb->setIcon(QIcon(toqstr(icon_path.absFilename())));
+               connect(this, SIGNAL(iconSizeChanged(const QSize &)),
+                       tb, SLOT(setIconSize(const QSize &)));
+
+               ButtonMenu * m = new ButtonMenu(qt_(to_ascii(item.label_)), tb);
+               connect(this, SIGNAL(updated()), m, SLOT(updateParent()));
+               ToolbarInfo const & tbinfo = toolbarbackend.getToolbar(item.name_);
+               ToolbarInfo::item_iterator it = tbinfo.items.begin();
+               ToolbarInfo::item_iterator const end = tbinfo.items.end();
+               for (; it != end; ++it)
+                       if (!getStatus(it->func_).unknown()) {
+                               Action * action = new Action(owner_,
+                                       getIcon(it->func_, false),
+                                       it->label_,
+                                       it->func_,
+                                       it->label_);
+                               m->add(action);
+                               ActionVector.push_back(action);
+                       }
+               tb->setMenu(m);
+               addWidget(tb);
+               break;
+               }
+       case ToolbarItem::COMMAND: {
+               if (getStatus(item.func_).unknown())
+                       break;
+
+               Action * action = new Action(owner_,
+                       getIcon(item.func_),
+                       item.label_,
+                       item.func_,
+                       item.label_);
+               addAction(action);
+               ActionVector.push_back(action);
+               break;
+               }
+       default:
+               break;
+       }
+}
+
+
+void QLToolbar::hide(bool)
+{
+       QToolBar::hide();
+}
+
+
+void QLToolbar::show(bool)
+{
+       QToolBar::show();
+}
+
+
+void QLToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
+{
+       // if tbinfo.state == auto *do not* set on/off
+       if (tbinfo.state != ToolbarSection::ToolbarInfo::AUTO) {
+               if (QLToolbar::isVisible())
+                       tbinfo.state = ToolbarSection::ToolbarInfo::ON;
+               else
+                       tbinfo.state = ToolbarSection::ToolbarInfo::OFF;
+       }
+       //      
+       // no need to save it here.
+       Qt::ToolBarArea loc = owner_.toolBarArea(this);
+
+       if (loc == Qt::TopToolBarArea)
+               tbinfo.location = ToolbarSection::ToolbarInfo::TOP;
+       else if (loc == Qt::BottomToolBarArea)
+               tbinfo.location = ToolbarSection::ToolbarInfo::BOTTOM;
+       else if (loc == Qt::RightToolBarArea)
+               tbinfo.location = ToolbarSection::ToolbarInfo::RIGHT;
+       else if (loc == Qt::LeftToolBarArea)
+               tbinfo.location = ToolbarSection::ToolbarInfo::LEFT;
+       else
+               tbinfo.location = ToolbarSection::ToolbarInfo::NOTSET;
+       
+       // save toolbar position. They are not used to restore toolbar position 
+       // now because move(x,y) does not work for toolbar.
+       tbinfo.posx = pos().x();
+       tbinfo.posy = pos().y();
+}
+
+
+void QLToolbar::update()
+{
+       // This is a speed bottleneck because this is called on every keypress
+       // and update calls getStatus, which copies the cursor at least two times
+       for (size_t i = 0; i < ActionVector.size(); ++i)
+               ActionVector[i]->update();
+
+       // emit signal
+       updated();
+}
+
+
+string const getIcon(FuncRequest const & f, bool unknown)
+{
+       using frontend::find_xpm;
+
+       string fullname;
+
+       switch (f.action) {
+       case LFUN_MATH_INSERT:
+               if (!f.argument().empty())
+                       fullname = find_xpm(to_utf8(f.argument()).substr(1));
+               break;
+       case LFUN_MATH_DELIM:
+       case LFUN_MATH_BIGDELIM:
+               fullname = find_xpm(to_utf8(f.argument()));
+               break;
+       default:
+               string const name = lyxaction.getActionName(f.action);
+               string xpm_name(name);
+
+               if (!f.argument().empty())
+                       xpm_name = subst(name + ' ' + to_utf8(f.argument()), ' ', '_');
+
+               fullname = libFileSearch("images", xpm_name, "xpm").absFilename();
+
+               if (fullname.empty()) {
+                       // try without the argument
+                       fullname = libFileSearch("images", name, "xpm").absFilename();
+               }
+       }
+
+       if (!fullname.empty()) {
+               LYXERR(Debug::GUI) << "Full icon name is `"
+                                  << fullname << '\'' << endl;
+               return fullname;
+       }
+
+       LYXERR(Debug::GUI) << "Cannot find icon for command \""
+                          << lyxaction.getActionName(f.action)
+                          << '(' << to_utf8(f.argument()) << ")\"" << endl;
+       if (unknown)
+               return libFileSearch("images", "unknown", "xpm").absFilename();
+       else
+               return string();
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QLToolbar_moc.cpp"
diff --git a/src/frontends/qt4/QLog.C b/src/frontends/qt4/QLog.C
deleted file mode 100644 (file)
index 4ca0adc..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * \file QLog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QLog.h"
-#include "qt_helpers.h"
-
-#include "frontends/Application.h"
-
-#include "controllers/ControlLog.h"
-
-#include <sstream>
-
-#include <QTextBrowser>
-#include <QPushButton>
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QLogDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-QLogDialog::QLogDialog(QLog * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-       connect( updatePB, SIGNAL( clicked() ), 
-               this, SLOT( updateClicked() ) );
-}
-
-
-void QLogDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QLogDialog::updateClicked()
-{
-       form_->update_contents();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// LogHighlighter
-//
-/////////////////////////////////////////////////////////////////////
-
-LogHighlighter::LogHighlighter(QTextDocument * parent)
-       : QSyntaxHighlighter(parent)
-{
-       infoFormat.setForeground(Qt::darkGray);
-       warningFormat.setForeground(Qt::darkBlue);
-       errorFormat.setForeground(Qt::red);
-}
-
-
-void LogHighlighter::highlightBlock(QString const & text)
-{
-       // Info
-       QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
-       int index = text.indexOf(exprInfo);
-       while (index >= 0) {
-               int length = exprInfo.matchedLength();
-               setFormat(index, length, infoFormat);
-               index = text.indexOf(exprInfo, index + length);
-       }
-       // LaTeX Warning:
-       QRegExp exprWarning("^LaTeX Warning.*$");
-       index = text.indexOf(exprWarning);
-       while (index >= 0) {
-               int length = exprWarning.matchedLength();
-               setFormat(index, length, warningFormat);
-               index = text.indexOf(exprWarning, index + length);
-       }
-       // ! error 
-       QRegExp exprError("^!.*$");
-       index = text.indexOf(exprError);
-       while (index >= 0) {
-               int length = exprError.matchedLength();
-               setFormat(index, length, errorFormat);
-               index = text.indexOf(exprError, index + length);
-       }
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QLog
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlLog, QView<QLogDialog> > LogBase;
-
-QLog::QLog(Dialog & parent)
-       : LogBase(parent, docstring())
-{}
-
-
-void QLog::build_dialog()
-{
-       dialog_.reset(new QLogDialog(this));
-       // set syntax highlighting
-       highlighter = new LogHighlighter(dialog_->logTB->document());
-       //
-       dialog_->logTB->setReadOnly(true);
-       QFont font(toqstr(theApp()->typewriterFontName()));
-       font.setKerning(false);
-       font.setFixedPitch(true);
-       font.setStyleHint(QFont::TypeWriter);
-       dialog_->logTB->setFont(font);
-}
-
-
-void QLog::update_contents()
-{
-       setTitle(controller().title());
-
-       std::ostringstream ss;
-       controller().getContents(ss);
-
-       dialog_->logTB->setPlainText(toqstr(ss.str()));
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QLog_moc.cpp"
diff --git a/src/frontends/qt4/QLog.cpp b/src/frontends/qt4/QLog.cpp
new file mode 100644 (file)
index 0000000..4ca0adc
--- /dev/null
@@ -0,0 +1,145 @@
+/**
+ * \file QLog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QLog.h"
+#include "qt_helpers.h"
+
+#include "frontends/Application.h"
+
+#include "controllers/ControlLog.h"
+
+#include <sstream>
+
+#include <QTextBrowser>
+#include <QPushButton>
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QLogDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+QLogDialog::QLogDialog(QLog * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+       connect( updatePB, SIGNAL( clicked() ), 
+               this, SLOT( updateClicked() ) );
+}
+
+
+void QLogDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QLogDialog::updateClicked()
+{
+       form_->update_contents();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// LogHighlighter
+//
+/////////////////////////////////////////////////////////////////////
+
+LogHighlighter::LogHighlighter(QTextDocument * parent)
+       : QSyntaxHighlighter(parent)
+{
+       infoFormat.setForeground(Qt::darkGray);
+       warningFormat.setForeground(Qt::darkBlue);
+       errorFormat.setForeground(Qt::red);
+}
+
+
+void LogHighlighter::highlightBlock(QString const & text)
+{
+       // Info
+       QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|\\(|\\\\).*$");
+       int index = text.indexOf(exprInfo);
+       while (index >= 0) {
+               int length = exprInfo.matchedLength();
+               setFormat(index, length, infoFormat);
+               index = text.indexOf(exprInfo, index + length);
+       }
+       // LaTeX Warning:
+       QRegExp exprWarning("^LaTeX Warning.*$");
+       index = text.indexOf(exprWarning);
+       while (index >= 0) {
+               int length = exprWarning.matchedLength();
+               setFormat(index, length, warningFormat);
+               index = text.indexOf(exprWarning, index + length);
+       }
+       // ! error 
+       QRegExp exprError("^!.*$");
+       index = text.indexOf(exprError);
+       while (index >= 0) {
+               int length = exprError.matchedLength();
+               setFormat(index, length, errorFormat);
+               index = text.indexOf(exprError, index + length);
+       }
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QLog
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlLog, QView<QLogDialog> > LogBase;
+
+QLog::QLog(Dialog & parent)
+       : LogBase(parent, docstring())
+{}
+
+
+void QLog::build_dialog()
+{
+       dialog_.reset(new QLogDialog(this));
+       // set syntax highlighting
+       highlighter = new LogHighlighter(dialog_->logTB->document());
+       //
+       dialog_->logTB->setReadOnly(true);
+       QFont font(toqstr(theApp()->typewriterFontName()));
+       font.setKerning(false);
+       font.setFixedPitch(true);
+       font.setStyleHint(QFont::TypeWriter);
+       dialog_->logTB->setFont(font);
+}
+
+
+void QLog::update_contents()
+{
+       setTitle(controller().title());
+
+       std::ostringstream ss;
+       controller().getContents(ss);
+
+       dialog_->logTB->setPlainText(toqstr(ss.str()));
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QLog_moc.cpp"
diff --git a/src/frontends/qt4/QLyXKeySym.C b/src/frontends/qt4/QLyXKeySym.C
deleted file mode 100644 (file)
index 524e1d1..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/**
- * \file QLyXKeySym.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Asger and Jürgen
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QLyXKeySym.h"
-#include "qlkey.h"
-#include "qt_helpers.h"
-
-
-#include "debug.h"
-
-#include <QKeyEvent>
-#include <QKeySequence>
-#include <QEvent>
-#include <QTextCodec>
-
-#include <map>
-#include "support/lstrings.h"
-#include "support/environment.h"
-#include "support/unicode.h"
-
-#include "encoding.h"
-#include "language.h"
-
-
-namespace lyx {
-
-using std::endl;
-using std::string;
-using std::map;
-using lyx::support::contains;
-using lyx::support::getEnv;
-
-
-namespace {
-
-typedef map<string, QTextCodec *> EncodingMap;
-EncodingMap encoding_map;
-
-char const encode(string const & encoding, QString const & str)
-{
-       QTextCodec * codec = 0;
-
-       EncodingMap::const_iterator cit = encoding_map.find(encoding);
-       if (cit == encoding_map.end()) {
-               LYXERR(Debug::KEY) << "Unrecognised encoding '" << encoding
-                                  << "'." << endl;
-               codec = encoding_map.find("")->second;
-       } else {
-               codec = cit->second;
-       }
-
-       if (!codec) {
-               LYXERR(Debug::KEY) << "No codec for encoding '" << encoding
-                                  << "' found." << endl;
-               return 0;
-       }
-
-       LYXERR(Debug::KEY) << "Using codec " << fromqstr(codec->name()) << endl;
-
-       if (!codec->canEncode(str)) {
-               LYXERR(Debug::KEY) << "Oof. Can't encode the text !" << endl;
-               return 0;
-       }
-
-       return codec->fromUnicode(str).data()[0];
-}
-
-}
-
-
-QLyXKeySym::QLyXKeySym()
-       : LyXKeySym(), key_(0)
-{
-}
-
-
-void QLyXKeySym::set(QKeyEvent * ev)
-{
-       key_ = ev->key();
-       if (ev->text().isNull()) {
-               LYXERR(Debug::KEY) << "keyevent has isNull() text !" << endl;
-               text_ = "";
-               return;
-       }
-       text_ = ev->text();
-       LYXERR(Debug::KEY) << "Setting key to " << key_ << ", " <<  fromqstr(text_) << endl;
-}
-
-
-void QLyXKeySym::init(string const & symbolname)
-{
-       key_ = string_to_qkey(symbolname);
-       text_ = toqstr(symbolname);
-       LYXERR(Debug::KEY) << "Init key to " << key_ << ", " << fromqstr(text_) << endl;
-}
-
-
-bool QLyXKeySym::isOK() const
-{
-       bool const ok(!(text_.isEmpty() && key_ == Qt::Key_unknown));
-       LYXERR(Debug::KEY) << "isOK is " << ok << endl;
-       return ok;
-}
-
-
-bool QLyXKeySym::isModifier() const
-{
-       bool const mod(q_is_modifier(key_));
-       LYXERR(Debug::KEY) << "isMod is " << mod << endl;
-       return mod;
-}
-
-
-string QLyXKeySym::getSymbolName() const
-{
-       string sym(qkey_to_string(key_));
-
-       // e.g. A-Za-z, and others
-       if (sym.empty())
-               sym = fromqstr(text_);
-
-       return sym;
-}
-
-
-char_type QLyXKeySym::getUCSEncoded() const
-{
-       if (text_.isEmpty())
-               return 0;
-
-       // UTF16 has a maximum of two characters.
-       BOOST_ASSERT(text_.size() <= 2);
-
-       if (lyxerr.debugging() && text_.size() > 1) {
-               // We don't know yet how well support the full ucs4 range.
-               LYXERR(Debug::KEY) << "QLyXKeySym::getUCSEncoded()" << endl;
-               for (int i = 0; i < text_.size(); ++i) {
-                       LYXERR(Debug::KEY) << "char " << i << ": "
-                               << text_[i].unicode() << endl;
-               }
-       }
-       
-       // Only one UCS4 character at the end.
-       docstring ucs4_text = qstring_to_ucs4(text_);
-       return ucs4_text[0];
-}
-
-
-docstring const QLyXKeySym::print(key_modifier::state mod, bool forgui) const
-{
-       int tmpkey = key_;
-
-       if (mod & key_modifier::shift)
-               tmpkey += Qt::SHIFT;
-       if (mod & key_modifier::ctrl)
-               tmpkey += Qt::CTRL;
-       if (mod & key_modifier::alt)
-               tmpkey += Qt::ALT;
-       
-       QKeySequence seq(tmpkey);
-
-       return qstring_to_ucs4(seq.toString(forgui ? QKeySequence::NativeText 
-                                           : QKeySequence::PortableText));
-}
-
-
-bool QLyXKeySym::isText() const
-{
-       if (text_.isEmpty()) {
-               LYXERR(Debug::KEY) << "text_ empty, isText() == false" << endl;
-               return false;
-       }
-
-       return true;
-}
-
-
-bool QLyXKeySym::operator==(LyXKeySym const & ks) const
-{
-       QLyXKeySym const & qks = static_cast<QLyXKeySym const &>(ks);
-
-       // we do not have enough info for a fair comparison, so return
-       // false. This works out OK because unknown text from Qt will
-       // get inserted anyway after the isText() check
-       if (key_ == Qt::Key_unknown || qks.key_ == Qt::Key_unknown)
-               return false;
-
-       return key_ == qks.key_;
-}
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/QLyXKeySym.cpp b/src/frontends/qt4/QLyXKeySym.cpp
new file mode 100644 (file)
index 0000000..524e1d1
--- /dev/null
@@ -0,0 +1,202 @@
+/**
+ * \file QLyXKeySym.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Asger and Jürgen
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QLyXKeySym.h"
+#include "qlkey.h"
+#include "qt_helpers.h"
+
+
+#include "debug.h"
+
+#include <QKeyEvent>
+#include <QKeySequence>
+#include <QEvent>
+#include <QTextCodec>
+
+#include <map>
+#include "support/lstrings.h"
+#include "support/environment.h"
+#include "support/unicode.h"
+
+#include "encoding.h"
+#include "language.h"
+
+
+namespace lyx {
+
+using std::endl;
+using std::string;
+using std::map;
+using lyx::support::contains;
+using lyx::support::getEnv;
+
+
+namespace {
+
+typedef map<string, QTextCodec *> EncodingMap;
+EncodingMap encoding_map;
+
+char const encode(string const & encoding, QString const & str)
+{
+       QTextCodec * codec = 0;
+
+       EncodingMap::const_iterator cit = encoding_map.find(encoding);
+       if (cit == encoding_map.end()) {
+               LYXERR(Debug::KEY) << "Unrecognised encoding '" << encoding
+                                  << "'." << endl;
+               codec = encoding_map.find("")->second;
+       } else {
+               codec = cit->second;
+       }
+
+       if (!codec) {
+               LYXERR(Debug::KEY) << "No codec for encoding '" << encoding
+                                  << "' found." << endl;
+               return 0;
+       }
+
+       LYXERR(Debug::KEY) << "Using codec " << fromqstr(codec->name()) << endl;
+
+       if (!codec->canEncode(str)) {
+               LYXERR(Debug::KEY) << "Oof. Can't encode the text !" << endl;
+               return 0;
+       }
+
+       return codec->fromUnicode(str).data()[0];
+}
+
+}
+
+
+QLyXKeySym::QLyXKeySym()
+       : LyXKeySym(), key_(0)
+{
+}
+
+
+void QLyXKeySym::set(QKeyEvent * ev)
+{
+       key_ = ev->key();
+       if (ev->text().isNull()) {
+               LYXERR(Debug::KEY) << "keyevent has isNull() text !" << endl;
+               text_ = "";
+               return;
+       }
+       text_ = ev->text();
+       LYXERR(Debug::KEY) << "Setting key to " << key_ << ", " <<  fromqstr(text_) << endl;
+}
+
+
+void QLyXKeySym::init(string const & symbolname)
+{
+       key_ = string_to_qkey(symbolname);
+       text_ = toqstr(symbolname);
+       LYXERR(Debug::KEY) << "Init key to " << key_ << ", " << fromqstr(text_) << endl;
+}
+
+
+bool QLyXKeySym::isOK() const
+{
+       bool const ok(!(text_.isEmpty() && key_ == Qt::Key_unknown));
+       LYXERR(Debug::KEY) << "isOK is " << ok << endl;
+       return ok;
+}
+
+
+bool QLyXKeySym::isModifier() const
+{
+       bool const mod(q_is_modifier(key_));
+       LYXERR(Debug::KEY) << "isMod is " << mod << endl;
+       return mod;
+}
+
+
+string QLyXKeySym::getSymbolName() const
+{
+       string sym(qkey_to_string(key_));
+
+       // e.g. A-Za-z, and others
+       if (sym.empty())
+               sym = fromqstr(text_);
+
+       return sym;
+}
+
+
+char_type QLyXKeySym::getUCSEncoded() const
+{
+       if (text_.isEmpty())
+               return 0;
+
+       // UTF16 has a maximum of two characters.
+       BOOST_ASSERT(text_.size() <= 2);
+
+       if (lyxerr.debugging() && text_.size() > 1) {
+               // We don't know yet how well support the full ucs4 range.
+               LYXERR(Debug::KEY) << "QLyXKeySym::getUCSEncoded()" << endl;
+               for (int i = 0; i < text_.size(); ++i) {
+                       LYXERR(Debug::KEY) << "char " << i << ": "
+                               << text_[i].unicode() << endl;
+               }
+       }
+       
+       // Only one UCS4 character at the end.
+       docstring ucs4_text = qstring_to_ucs4(text_);
+       return ucs4_text[0];
+}
+
+
+docstring const QLyXKeySym::print(key_modifier::state mod, bool forgui) const
+{
+       int tmpkey = key_;
+
+       if (mod & key_modifier::shift)
+               tmpkey += Qt::SHIFT;
+       if (mod & key_modifier::ctrl)
+               tmpkey += Qt::CTRL;
+       if (mod & key_modifier::alt)
+               tmpkey += Qt::ALT;
+       
+       QKeySequence seq(tmpkey);
+
+       return qstring_to_ucs4(seq.toString(forgui ? QKeySequence::NativeText 
+                                           : QKeySequence::PortableText));
+}
+
+
+bool QLyXKeySym::isText() const
+{
+       if (text_.isEmpty()) {
+               LYXERR(Debug::KEY) << "text_ empty, isText() == false" << endl;
+               return false;
+       }
+
+       return true;
+}
+
+
+bool QLyXKeySym::operator==(LyXKeySym const & ks) const
+{
+       QLyXKeySym const & qks = static_cast<QLyXKeySym const &>(ks);
+
+       // we do not have enough info for a fair comparison, so return
+       // false. This works out OK because unknown text from Qt will
+       // get inserted anyway after the isText() check
+       if (key_ == Qt::Key_unknown || qks.key_ == Qt::Key_unknown)
+               return false;
+
+       return key_ == qks.key_;
+}
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/QMathMatrixDialog.C b/src/frontends/qt4/QMathMatrixDialog.C
deleted file mode 100644 (file)
index da3f38f..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * \file QMathMatrixDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QMathMatrixDialog.h"
-
-#include "EmptyTable.h"
-#include "qt_helpers.h"
-
-#include "controllers/ControlMath.h"
-
-#include <sstream>
-
-#include <qlineedit.h>
-#include <qpushbutton.h>
-#include <qspinbox.h>
-
-#include "gettext.h"
-
-using std::ostringstream;
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-namespace {
-
-char h_align_str[80] = "c";
-char v_align_c[] = "tcb";
-
-} // namespace anon
-
-
-typedef QController<ControlMath, QView<QMathMatrixDialog> > matrix_base;
-
-
-QMathMatrix::QMathMatrix(Dialog & parent)
-       : matrix_base(parent, _("Math Matrix"))
-{}
-
-
-void QMathMatrix::build_dialog()
-{
-       dialog_.reset(new QMathMatrixDialog(this));
-}
-
-
-QMathMatrixDialog::QMathMatrixDialog(QMathMatrix * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       setWindowTitle(qt_("LyX: Insert Matrix"));
-
-       table->setMinimumSize(100, 100);
-       rowsSB->setValue(2);
-       columnsSB->setValue(2);
-       valignCO->setCurrentIndex(1);
-
-       connect(okPB, SIGNAL(clicked()),
-               this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               this, SLOT(slotClose()));
-
-    connect( table, SIGNAL( rowsChanged(int) ), rowsSB, SLOT( setValue(int) ) );
-    connect( table, SIGNAL( colsChanged(int) ), columnsSB, SLOT( setValue(int) ) );
-    connect( rowsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberRows(int) ) );
-    connect( columnsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberColumns(int) ) );
-    connect( rowsSB, SIGNAL( valueChanged(int) ), this, SLOT( rowsChanged(int) ) );
-    connect( columnsSB, SIGNAL( valueChanged(int) ), this, SLOT( columnsChanged(int) ) );
-    connect( valignCO, SIGNAL( highlighted(const QString&) ), this, SLOT( change_adaptor() ) );
-    connect( halignED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
-}
-
-
-void QMathMatrixDialog::columnsChanged(int)
-{
-       int const nx = int(columnsSB->value());
-       for (int i = 0; i < nx; ++i)
-               h_align_str[i] = 'c';
-
-       h_align_str[nx] = '\0';
-       halignED->setText(h_align_str);
-}
-
-
-void QMathMatrixDialog::rowsChanged(int)
-{
-}
-
-
-void QMathMatrixDialog::change_adaptor()
-{
-       // FIXME: We need a filter for the halign input
-}
-
-
-void QMathMatrixDialog::slotOK()
-{
-       char const c = v_align_c[valignCO->currentIndex()];
-       string const sh = fromqstr(halignED->text());
-       int const nx = int(columnsSB->value());
-       int const ny = int(rowsSB->value());
-
-       ostringstream os;
-       os << nx << ' ' << ny << ' ' << c << ' ' << sh;
-       form_->controller().dispatchMatrix(os.str().c_str());
-
-       // close the dialog
-       close();
-}
-
-
-void QMathMatrixDialog::slotClose()
-{
-       close();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QMathMatrixDialog_moc.cpp"
diff --git a/src/frontends/qt4/QMathMatrixDialog.cpp b/src/frontends/qt4/QMathMatrixDialog.cpp
new file mode 100644 (file)
index 0000000..da3f38f
--- /dev/null
@@ -0,0 +1,130 @@
+/**
+ * \file QMathMatrixDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QMathMatrixDialog.h"
+
+#include "EmptyTable.h"
+#include "qt_helpers.h"
+
+#include "controllers/ControlMath.h"
+
+#include <sstream>
+
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qspinbox.h>
+
+#include "gettext.h"
+
+using std::ostringstream;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+namespace {
+
+char h_align_str[80] = "c";
+char v_align_c[] = "tcb";
+
+} // namespace anon
+
+
+typedef QController<ControlMath, QView<QMathMatrixDialog> > matrix_base;
+
+
+QMathMatrix::QMathMatrix(Dialog & parent)
+       : matrix_base(parent, _("Math Matrix"))
+{}
+
+
+void QMathMatrix::build_dialog()
+{
+       dialog_.reset(new QMathMatrixDialog(this));
+}
+
+
+QMathMatrixDialog::QMathMatrixDialog(QMathMatrix * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       setWindowTitle(qt_("LyX: Insert Matrix"));
+
+       table->setMinimumSize(100, 100);
+       rowsSB->setValue(2);
+       columnsSB->setValue(2);
+       valignCO->setCurrentIndex(1);
+
+       connect(okPB, SIGNAL(clicked()),
+               this, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               this, SLOT(slotClose()));
+
+    connect( table, SIGNAL( rowsChanged(int) ), rowsSB, SLOT( setValue(int) ) );
+    connect( table, SIGNAL( colsChanged(int) ), columnsSB, SLOT( setValue(int) ) );
+    connect( rowsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberRows(int) ) );
+    connect( columnsSB, SIGNAL( valueChanged(int) ), table, SLOT( setNumberColumns(int) ) );
+    connect( rowsSB, SIGNAL( valueChanged(int) ), this, SLOT( rowsChanged(int) ) );
+    connect( columnsSB, SIGNAL( valueChanged(int) ), this, SLOT( columnsChanged(int) ) );
+    connect( valignCO, SIGNAL( highlighted(const QString&) ), this, SLOT( change_adaptor() ) );
+    connect( halignED, SIGNAL( textChanged(const QString&) ), this, SLOT( change_adaptor() ) );
+}
+
+
+void QMathMatrixDialog::columnsChanged(int)
+{
+       int const nx = int(columnsSB->value());
+       for (int i = 0; i < nx; ++i)
+               h_align_str[i] = 'c';
+
+       h_align_str[nx] = '\0';
+       halignED->setText(h_align_str);
+}
+
+
+void QMathMatrixDialog::rowsChanged(int)
+{
+}
+
+
+void QMathMatrixDialog::change_adaptor()
+{
+       // FIXME: We need a filter for the halign input
+}
+
+
+void QMathMatrixDialog::slotOK()
+{
+       char const c = v_align_c[valignCO->currentIndex()];
+       string const sh = fromqstr(halignED->text());
+       int const nx = int(columnsSB->value());
+       int const ny = int(rowsSB->value());
+
+       ostringstream os;
+       os << nx << ' ' << ny << ' ' << c << ' ' << sh;
+       form_->controller().dispatchMatrix(os.str().c_str());
+
+       // close the dialog
+       close();
+}
+
+
+void QMathMatrixDialog::slotClose()
+{
+       close();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QMathMatrixDialog_moc.cpp"
diff --git a/src/frontends/qt4/QNomencl.C b/src/frontends/qt4/QNomencl.C
deleted file mode 100644 (file)
index 6b4dd85..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * \file QNomencl.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author O. U. Baran
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "debug.h"
-#include "ControlCommand.h"
-#include "qt_helpers.h"
-
-#include "QNomencl.h"
-#include "Qt2BC.h"
-#include "ButtonController.h"
-#include <QLabel>
-#include <QLineEdit>
-#include <QPushButton>
-#include <QTextEdit>
-#include <QWhatsThis>
-#include <QCloseEvent>
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QNomenclDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QNomenclDialog::QNomenclDialog(QNomencl * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-       connect(symbolED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_adaptor()));
-       connect(descriptionTE, SIGNAL(textChanged()),
-               this, SLOT(change_adaptor()));
-
-       setFocusProxy(descriptionTE);
-}
-
-
-void QNomenclDialog::show()
-{
-       QDialog::show();
-}
-
-
-void QNomenclDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QNomenclDialog::reject()
-{
-       form_->slotClose();
-}
-
-
-void QNomenclDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QNomencl
-//
-/////////////////////////////////////////////////////////////////////
-
-
-typedef QController<ControlCommand, QView<QNomenclDialog> > NomenBase;
-
-
-QNomencl::QNomencl(Dialog & parent, docstring const & title)
-       : NomenBase(parent, title)
-{
-}
-
-
-void QNomencl::build_dialog()
-{
-       dialog_.reset(new QNomenclDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->symbolED);
-       bcview().addReadOnly(dialog_->descriptionTE);
-       bcview().addReadOnly(dialog_->prefixED);
-}
-
-
-void QNomencl::update_contents()
-{
-       dialog_->prefixED->setText(toqstr(controller().params()["prefix"]));
-       dialog_->symbolED->setText(toqstr(controller().params()["symbol"]));
-       QString description = toqstr(controller().params()["description"]);
-       description.replace("\\\\","\n");
-       dialog_->descriptionTE->setPlainText(description);
-
-       bc().valid(isValid());
-}
-
-
-void QNomencl::apply()
-{
-       controller().params()["prefix"] = qstring_to_ucs4(dialog_->prefixED->text());
-       controller().params()["symbol"] = qstring_to_ucs4(dialog_->symbolED->text());
-       QString description = dialog_->descriptionTE->toPlainText();
-       description.replace('\n',"\\\\");
-       controller().params()["description"] = qstring_to_ucs4(description);
-}
-
-
-bool QNomencl::isValid()
-{
-       QString const description = dialog_->descriptionTE->toPlainText();
-       return !dialog_->symbolED->text().isEmpty() && !description.isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QNomencl_moc.cpp"
diff --git a/src/frontends/qt4/QNomencl.cpp b/src/frontends/qt4/QNomencl.cpp
new file mode 100644 (file)
index 0000000..6b4dd85
--- /dev/null
@@ -0,0 +1,139 @@
+/**
+ * \file QNomencl.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author O. U. Baran
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "debug.h"
+#include "ControlCommand.h"
+#include "qt_helpers.h"
+
+#include "QNomencl.h"
+#include "Qt2BC.h"
+#include "ButtonController.h"
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QTextEdit>
+#include <QWhatsThis>
+#include <QCloseEvent>
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QNomenclDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QNomenclDialog::QNomenclDialog(QNomencl * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+       connect(symbolED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(descriptionTE, SIGNAL(textChanged()),
+               this, SLOT(change_adaptor()));
+
+       setFocusProxy(descriptionTE);
+}
+
+
+void QNomenclDialog::show()
+{
+       QDialog::show();
+}
+
+
+void QNomenclDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QNomenclDialog::reject()
+{
+       form_->slotClose();
+}
+
+
+void QNomenclDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QNomencl
+//
+/////////////////////////////////////////////////////////////////////
+
+
+typedef QController<ControlCommand, QView<QNomenclDialog> > NomenBase;
+
+
+QNomencl::QNomencl(Dialog & parent, docstring const & title)
+       : NomenBase(parent, title)
+{
+}
+
+
+void QNomencl::build_dialog()
+{
+       dialog_.reset(new QNomenclDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->symbolED);
+       bcview().addReadOnly(dialog_->descriptionTE);
+       bcview().addReadOnly(dialog_->prefixED);
+}
+
+
+void QNomencl::update_contents()
+{
+       dialog_->prefixED->setText(toqstr(controller().params()["prefix"]));
+       dialog_->symbolED->setText(toqstr(controller().params()["symbol"]));
+       QString description = toqstr(controller().params()["description"]);
+       description.replace("\\\\","\n");
+       dialog_->descriptionTE->setPlainText(description);
+
+       bc().valid(isValid());
+}
+
+
+void QNomencl::apply()
+{
+       controller().params()["prefix"] = qstring_to_ucs4(dialog_->prefixED->text());
+       controller().params()["symbol"] = qstring_to_ucs4(dialog_->symbolED->text());
+       QString description = dialog_->descriptionTE->toPlainText();
+       description.replace('\n',"\\\\");
+       controller().params()["description"] = qstring_to_ucs4(description);
+}
+
+
+bool QNomencl::isValid()
+{
+       QString const description = dialog_->descriptionTE->toPlainText();
+       return !dialog_->symbolED->text().isEmpty() && !description.isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QNomencl_moc.cpp"
diff --git a/src/frontends/qt4/QNote.C b/src/frontends/qt4/QNote.C
deleted file mode 100644 (file)
index 1751e61..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * \file QNote.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QNote.h"
-#include "Qt2BC.h"
-
-#include "controllers/ControlNote.h"
-
-#include "insets/InsetNote.h"
-
-#include <QCloseEvent>
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QNoteDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QNoteDialog::QNoteDialog(QNote * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(noteRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(greyedoutRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(commentRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(framedRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(shadedRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-}
-
-
-void QNoteDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QNoteDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QNote
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlNote, QView<QNoteDialog> > NoteBase;
-
-
-QNote::QNote(Dialog & parent)
-       : NoteBase(parent, _("Note Settings"))
-{}
-
-
-void QNote::build_dialog()
-{
-       dialog_.reset(new QNoteDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QNote::update_contents()
-{
-       QRadioButton * rb = 0;
-
-       switch (controller().params().type) {
-       case InsetNoteParams::Note:
-               rb = dialog_->noteRB;
-               break;
-       case InsetNoteParams::Comment:
-               rb = dialog_->commentRB;
-               break;
-       case InsetNoteParams::Greyedout:
-               rb = dialog_->greyedoutRB;
-               break;
-       case InsetNoteParams::Framed:
-               rb = dialog_->framedRB;
-               break;
-       case InsetNoteParams::Shaded:
-               rb = dialog_->shadedRB;
-               break;
-       }
-
-       rb->setChecked(true);
-}
-
-
-void QNote::apply()
-{
-       InsetNoteParams::Type type;
-
-       if (dialog_->greyedoutRB->isChecked())
-               type = InsetNoteParams::Greyedout;
-       else if (dialog_->commentRB->isChecked())
-               type = InsetNoteParams::Comment;
-       else if (dialog_->framedRB->isChecked())
-               type = InsetNoteParams::Framed;
-       else if (dialog_->shadedRB->isChecked())
-               type = InsetNoteParams::Shaded;
-       else
-               type = InsetNoteParams::Note;
-
-       controller().params().type = type;
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QNote_moc.cpp"
diff --git a/src/frontends/qt4/QNote.cpp b/src/frontends/qt4/QNote.cpp
new file mode 100644 (file)
index 0000000..1751e61
--- /dev/null
@@ -0,0 +1,130 @@
+/**
+ * \file QNote.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QNote.h"
+#include "Qt2BC.h"
+
+#include "controllers/ControlNote.h"
+
+#include "insets/InsetNote.h"
+
+#include <QCloseEvent>
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QNoteDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QNoteDialog::QNoteDialog(QNote * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(noteRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(greyedoutRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(commentRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(framedRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(shadedRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+}
+
+
+void QNoteDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QNoteDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QNote
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlNote, QView<QNoteDialog> > NoteBase;
+
+
+QNote::QNote(Dialog & parent)
+       : NoteBase(parent, _("Note Settings"))
+{}
+
+
+void QNote::build_dialog()
+{
+       dialog_.reset(new QNoteDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QNote::update_contents()
+{
+       QRadioButton * rb = 0;
+
+       switch (controller().params().type) {
+       case InsetNoteParams::Note:
+               rb = dialog_->noteRB;
+               break;
+       case InsetNoteParams::Comment:
+               rb = dialog_->commentRB;
+               break;
+       case InsetNoteParams::Greyedout:
+               rb = dialog_->greyedoutRB;
+               break;
+       case InsetNoteParams::Framed:
+               rb = dialog_->framedRB;
+               break;
+       case InsetNoteParams::Shaded:
+               rb = dialog_->shadedRB;
+               break;
+       }
+
+       rb->setChecked(true);
+}
+
+
+void QNote::apply()
+{
+       InsetNoteParams::Type type;
+
+       if (dialog_->greyedoutRB->isChecked())
+               type = InsetNoteParams::Greyedout;
+       else if (dialog_->commentRB->isChecked())
+               type = InsetNoteParams::Comment;
+       else if (dialog_->framedRB->isChecked())
+               type = InsetNoteParams::Framed;
+       else if (dialog_->shadedRB->isChecked())
+               type = InsetNoteParams::Shaded;
+       else
+               type = InsetNoteParams::Note;
+
+       controller().params().type = type;
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QNote_moc.cpp"
diff --git a/src/frontends/qt4/QParagraph.C b/src/frontends/qt4/QParagraph.C
deleted file mode 100644 (file)
index 00d8ee4..0000000
+++ /dev/null
@@ -1,294 +0,0 @@
-/**
- * \file QParagraph.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author Richard Heck
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QParagraph.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-#include "ParagraphParameters.h"
-#include "Spacing.h"
-#include "layout.h"
-
-#include "controllers/ControlParagraph.h"
-#include "controllers/frontend_helpers.h"
-
-#include <QCheckBox>
-#include <QLineEdit>
-#include <QPushButton>
-
-using std::string;
-using std::endl;
-
-/////////////////////////////////////////////////////////////////////
-//
-// QParagraphDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-#include <boost/current_function.hpp>
-
-namespace lyx {
-namespace frontend {
-
-QParagraphDialog::QParagraphDialog(QParagraph * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), form_, SLOT(slotRestore()));
-       connect(alignDefaultCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
-       connect(linespacing, SIGNAL(activated(int)), 
-               this, SLOT(enableLinespacingValue(int)));
-       connect(linespacingValue, SIGNAL(textChanged(const QString &)), 
-               this, SLOT(change_adaptor()));
-       connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(labelWidth, SIGNAL(textChanged(const QString &)), 
-               this, SLOT(change_adaptor()));
-
-       linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
-
-       labelWidth->setWhatsThis( qt_(
-               "As described in the User Guide, the length of"
-               " this text will determine how wide the label part"
-               " of each item is in environments like List and"
-               " Description.\n"
-               "\n"
-               " Normally you won't need to set this,"
-               " since the largest label width of all the"
-               " items is used. But if you need to, you can"
-               " change it here."
-       ));
-
-       radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
-       radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
-       radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
-       radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
-}
-
-
-void QParagraphDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QParagraphDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QParagraphDialog::enableLinespacingValue(int)
-{
-       bool const enable = linespacing->currentIndex() == 4;
-       linespacingValue->setEnabled(enable);
-}
-
-
-void QParagraphDialog::checkAlignmentRadioButtons() {
-       if (alignDefaultCB->isChecked()) {
-               QPRadioMap::const_iterator it = radioMap.begin();
-               for (; it != radioMap.end(); ++it)
-                       it->second->setDisabled(true);
-       } else {
-               LyXAlignment alignPossible = form_->controller().alignPossible();
-               QPRadioMap::const_iterator it = radioMap.begin();
-               for (; it != radioMap.end(); ++it)
-                       it->second->setEnabled(it->first & alignPossible);
-       }
-}
-
-
-void QParagraphDialog::on_alignDefaultCB_toggled(bool)
-{
-       checkAlignmentRadioButtons();
-       alignmentToRadioButtons();
-}
-
-
-void QParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
-{
-       if (align == LYX_ALIGN_LAYOUT)
-               align = form_->controller().alignDefault();
-
-       QPRadioMap::const_iterator it = radioMap.begin();
-       for (;it != radioMap.end(); ++it) {
-               if (align == it->first) {
-                       it->second->setChecked(true);
-                       return;
-               }
-       }
-
-       lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment " 
-               << align << std::endl;
-}
-
-
-LyXAlignment QParagraphDialog::getAlignmentFromDialog()
-{
-       if (alignDefaultCB->isChecked()) 
-               return LYX_ALIGN_LAYOUT;
-       LyXAlignment alignment = LYX_ALIGN_NONE;
-       QPRadioMap::const_iterator it = radioMap.begin();
-       for (; it != radioMap.end(); ++it) {
-               if (it->second->isChecked()) {
-                       alignment = it->first;
-                       break;
-               }
-       }
-       if (alignment == form_->controller().alignDefault())
-               return LYX_ALIGN_LAYOUT;
-       return alignment;
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QParagraph
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlParagraph, QView<QParagraphDialog> >
-       ParagraphBase;
-
-
-QParagraph::QParagraph(Dialog & parent)
-       : ParagraphBase(parent, _("Paragraph Settings"))
-{}
-
-
-void QParagraph::build_dialog()
-{
-       // the dialog
-       dialog_.reset(new QParagraphDialog(this));
-
-       // Manage the ok, apply, restore and cancel/close buttons
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().setRestore(dialog_->restorePB);
-}
-
-
-void QParagraph::apply()
-{
-       ParagraphParameters & params = controller().params();
-
-       params.align(dialog_->getAlignmentFromDialog());
-
-       // get spacing
-       Spacing::Space linespacing = Spacing::Default;
-       string other;
-       switch (dialog_->linespacing->currentIndex()) {
-       case 0:
-               linespacing = Spacing::Default;
-               break;
-       case 1:
-               linespacing = Spacing::Single;
-               break;
-       case 2:
-               linespacing = Spacing::Onehalf;
-               break;
-       case 3:
-               linespacing = Spacing::Double;
-               break;
-       case 4:
-               linespacing = Spacing::Other;
-               other = fromqstr(dialog_->linespacingValue->text());
-               break;
-       }
-
-       Spacing const spacing(linespacing, other);
-       params.spacing(spacing);
-
-       // label width
-       params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
-       // indendation
-       params.noindent(!dialog_->indentCB->isChecked());
-}
-
-
-void QParagraph::update_contents()
-{
-       ParagraphParameters const & params = controller().params();
-
-       // label width
-       docstring const & labelwidth = params.labelWidthString();
-       // FIXME We should not compare translated strings
-       if (labelwidth != _("Senseless with this layout!")) {
-               dialog_->labelwidthGB->setEnabled(true);
-               dialog_->labelWidth->setText(toqstr(labelwidth));
-       } else {
-               dialog_->labelwidthGB->setEnabled(false);
-               dialog_->labelWidth->setText("");
-       }
-
-       // alignment
-       LyXAlignment newAlignment = params.align();
-       LyXAlignment defaultAlignment = controller().alignDefault();
-       bool alignmentIsDefault = 
-               newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment;
-       dialog_->alignDefaultCB->blockSignals(true);
-       dialog_->alignDefaultCB->setChecked(alignmentIsDefault);
-       dialog_->alignDefaultCB->blockSignals(false);
-       dialog_->checkAlignmentRadioButtons();
-       dialog_->alignmentToRadioButtons(newAlignment);
-
-       //indentation
-       dialog_->indentCB->setChecked(!params.noindent());
-
-       // linespacing
-       int linespacing;
-       Spacing const & space = params.spacing();
-       switch (space.getSpace()) {
-       case Spacing::Single:
-               linespacing = 1;
-               break;
-       case Spacing::Onehalf:
-               linespacing = 2;
-               break;
-       case Spacing::Double:
-               linespacing = 3;
-               break;
-       case Spacing::Other:
-               linespacing = 4;
-               break;
-       default:
-               linespacing = 0;
-               break;
-       }
-       dialog_->linespacing->setCurrentIndex(linespacing);
-       if (space.getSpace() == Spacing::Other) {
-               dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
-               dialog_->linespacingValue->setEnabled(true);
-       } else {
-               dialog_->linespacingValue->setText("");
-               dialog_->linespacingValue->setEnabled(false);
-       }
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QParagraph_moc.cpp"
diff --git a/src/frontends/qt4/QParagraph.cpp b/src/frontends/qt4/QParagraph.cpp
new file mode 100644 (file)
index 0000000..00d8ee4
--- /dev/null
@@ -0,0 +1,294 @@
+/**
+ * \file QParagraph.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QParagraph.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+#include "ParagraphParameters.h"
+#include "Spacing.h"
+#include "layout.h"
+
+#include "controllers/ControlParagraph.h"
+#include "controllers/frontend_helpers.h"
+
+#include <QCheckBox>
+#include <QLineEdit>
+#include <QPushButton>
+
+using std::string;
+using std::endl;
+
+/////////////////////////////////////////////////////////////////////
+//
+// QParagraphDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+#include <boost/current_function.hpp>
+
+namespace lyx {
+namespace frontend {
+
+QParagraphDialog::QParagraphDialog(QParagraph * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+       connect(restorePB, SIGNAL(clicked()), form_, SLOT(slotRestore()));
+       connect(alignDefaultCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(alignJustRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(alignLeftRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(alignRightRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(alignCenterRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(linespacing, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
+       connect(linespacing, SIGNAL(activated(int)), 
+               this, SLOT(enableLinespacingValue(int)));
+       connect(linespacingValue, SIGNAL(textChanged(const QString &)), 
+               this, SLOT(change_adaptor()));
+       connect(indentCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(labelWidth, SIGNAL(textChanged(const QString &)), 
+               this, SLOT(change_adaptor()));
+
+       linespacingValue->setValidator(new QDoubleValidator(linespacingValue));
+
+       labelWidth->setWhatsThis( qt_(
+               "As described in the User Guide, the length of"
+               " this text will determine how wide the label part"
+               " of each item is in environments like List and"
+               " Description.\n"
+               "\n"
+               " Normally you won't need to set this,"
+               " since the largest label width of all the"
+               " items is used. But if you need to, you can"
+               " change it here."
+       ));
+
+       radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
+       radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
+       radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
+       radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
+}
+
+
+void QParagraphDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QParagraphDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QParagraphDialog::enableLinespacingValue(int)
+{
+       bool const enable = linespacing->currentIndex() == 4;
+       linespacingValue->setEnabled(enable);
+}
+
+
+void QParagraphDialog::checkAlignmentRadioButtons() {
+       if (alignDefaultCB->isChecked()) {
+               QPRadioMap::const_iterator it = radioMap.begin();
+               for (; it != radioMap.end(); ++it)
+                       it->second->setDisabled(true);
+       } else {
+               LyXAlignment alignPossible = form_->controller().alignPossible();
+               QPRadioMap::const_iterator it = radioMap.begin();
+               for (; it != radioMap.end(); ++it)
+                       it->second->setEnabled(it->first & alignPossible);
+       }
+}
+
+
+void QParagraphDialog::on_alignDefaultCB_toggled(bool)
+{
+       checkAlignmentRadioButtons();
+       alignmentToRadioButtons();
+}
+
+
+void QParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
+{
+       if (align == LYX_ALIGN_LAYOUT)
+               align = form_->controller().alignDefault();
+
+       QPRadioMap::const_iterator it = radioMap.begin();
+       for (;it != radioMap.end(); ++it) {
+               if (align == it->first) {
+                       it->second->setChecked(true);
+                       return;
+               }
+       }
+
+       lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment " 
+               << align << std::endl;
+}
+
+
+LyXAlignment QParagraphDialog::getAlignmentFromDialog()
+{
+       if (alignDefaultCB->isChecked()) 
+               return LYX_ALIGN_LAYOUT;
+       LyXAlignment alignment = LYX_ALIGN_NONE;
+       QPRadioMap::const_iterator it = radioMap.begin();
+       for (; it != radioMap.end(); ++it) {
+               if (it->second->isChecked()) {
+                       alignment = it->first;
+                       break;
+               }
+       }
+       if (alignment == form_->controller().alignDefault())
+               return LYX_ALIGN_LAYOUT;
+       return alignment;
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QParagraph
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlParagraph, QView<QParagraphDialog> >
+       ParagraphBase;
+
+
+QParagraph::QParagraph(Dialog & parent)
+       : ParagraphBase(parent, _("Paragraph Settings"))
+{}
+
+
+void QParagraph::build_dialog()
+{
+       // the dialog
+       dialog_.reset(new QParagraphDialog(this));
+
+       // Manage the ok, apply, restore and cancel/close buttons
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().setRestore(dialog_->restorePB);
+}
+
+
+void QParagraph::apply()
+{
+       ParagraphParameters & params = controller().params();
+
+       params.align(dialog_->getAlignmentFromDialog());
+
+       // get spacing
+       Spacing::Space linespacing = Spacing::Default;
+       string other;
+       switch (dialog_->linespacing->currentIndex()) {
+       case 0:
+               linespacing = Spacing::Default;
+               break;
+       case 1:
+               linespacing = Spacing::Single;
+               break;
+       case 2:
+               linespacing = Spacing::Onehalf;
+               break;
+       case 3:
+               linespacing = Spacing::Double;
+               break;
+       case 4:
+               linespacing = Spacing::Other;
+               other = fromqstr(dialog_->linespacingValue->text());
+               break;
+       }
+
+       Spacing const spacing(linespacing, other);
+       params.spacing(spacing);
+
+       // label width
+       params.labelWidthString(qstring_to_ucs4(dialog_->labelWidth->text()));
+       // indendation
+       params.noindent(!dialog_->indentCB->isChecked());
+}
+
+
+void QParagraph::update_contents()
+{
+       ParagraphParameters const & params = controller().params();
+
+       // label width
+       docstring const & labelwidth = params.labelWidthString();
+       // FIXME We should not compare translated strings
+       if (labelwidth != _("Senseless with this layout!")) {
+               dialog_->labelwidthGB->setEnabled(true);
+               dialog_->labelWidth->setText(toqstr(labelwidth));
+       } else {
+               dialog_->labelwidthGB->setEnabled(false);
+               dialog_->labelWidth->setText("");
+       }
+
+       // alignment
+       LyXAlignment newAlignment = params.align();
+       LyXAlignment defaultAlignment = controller().alignDefault();
+       bool alignmentIsDefault = 
+               newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment;
+       dialog_->alignDefaultCB->blockSignals(true);
+       dialog_->alignDefaultCB->setChecked(alignmentIsDefault);
+       dialog_->alignDefaultCB->blockSignals(false);
+       dialog_->checkAlignmentRadioButtons();
+       dialog_->alignmentToRadioButtons(newAlignment);
+
+       //indentation
+       dialog_->indentCB->setChecked(!params.noindent());
+
+       // linespacing
+       int linespacing;
+       Spacing const & space = params.spacing();
+       switch (space.getSpace()) {
+       case Spacing::Single:
+               linespacing = 1;
+               break;
+       case Spacing::Onehalf:
+               linespacing = 2;
+               break;
+       case Spacing::Double:
+               linespacing = 3;
+               break;
+       case Spacing::Other:
+               linespacing = 4;
+               break;
+       default:
+               linespacing = 0;
+               break;
+       }
+       dialog_->linespacing->setCurrentIndex(linespacing);
+       if (space.getSpace() == Spacing::Other) {
+               dialog_->linespacingValue->setText(toqstr(space.getValueAsString()));
+               dialog_->linespacingValue->setEnabled(true);
+       } else {
+               dialog_->linespacingValue->setText("");
+               dialog_->linespacingValue->setEnabled(false);
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QParagraph_moc.cpp"
diff --git a/src/frontends/qt4/QPrefs.C b/src/frontends/qt4/QPrefs.C
deleted file mode 100644 (file)
index b436782..0000000
+++ /dev/null
@@ -1,2044 +0,0 @@
-/**
- * \file QPrefs.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QPrefs.h"
-
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-#include "GuiApplication.h"
-
-#include "session.h"
-#include "debug.h"
-#include "LColor.h"
-#include "lyxfont.h"
-#include "PanelStack.h"
-#include "QFontExample.h"
-#include "gettext.h"
-
-#include "support/lstrings.h"
-#include "support/os.h"
-
-#include "controllers/ControlPrefs.h"
-#include "controllers/frontend_helpers.h"
-
-#include "frontends/Alert.h"
-#include "frontends/Application.h"
-
-#include <QCheckBox>
-#include <QColorDialog>
-#include <QFontDatabase>
-#include <QLineEdit>
-#include <QPushButton>
-#include <QSpinBox>
-#include <QString>
-#include <QValidator>
-#include <QCloseEvent>
-
-#include <boost/tuple/tuple.hpp>
-#include <iomanip>
-#include <sstream>
-
-using namespace Ui;
-
-using lyx::support::compare_ascii_no_case;
-using lyx::support::os::external_path;
-using lyx::support::os::external_path_list;
-using lyx::support::os::internal_path;
-using lyx::support::os::internal_path_list;
-
-using std::endl;
-using std::string;
-using std::pair;
-using std::vector;
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// Helpers
-//
-/////////////////////////////////////////////////////////////////////
-
-string const LookAndFeel = N_("Look and feel");
-string const LanguageSettings = N_("Language settings");
-string const Outputs = N_("Outputs");
-
-
-// FIXME: move to frontend_helpers.h
-
-template<class A>
-static size_t findPos_helper(std::vector<A> const & vec, A const & val)
-{
-       typedef typename std::vector<A>::const_iterator Cit;
-
-       Cit it = std::find(vec.begin(), vec.end(), val);
-       if (it == vec.end())
-               return 0;
-       return std::distance(vec.begin(), it);
-}
-
-
-static void setComboxFont(QComboBox * cb, string const & family,
-       string const & foundry)
-{
-       string const name = makeFontName(family, foundry);
-       for (int i = 0; i < cb->count(); ++i) {
-               if (fromqstr(cb->itemText(i)) == name) {
-                       cb->setCurrentIndex(i);
-                       return;
-               }
-       }
-
-       // Try matching without foundry name
-
-       // We count in reverse in order to prefer the Xft foundry
-       for (int i = cb->count() - 1; i >= 0; --i) {
-               pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
-               if (compare_ascii_no_case(tmp.first, family) == 0) {
-                       cb->setCurrentIndex(i);
-                       return;
-               }
-       }
-
-       // family alone can contain e.g. "Helvetica [Adobe]"
-       pair<string, string> tmpfam = parseFontName(family);
-
-       // We count in reverse in order to prefer the Xft foundry
-       for (int i = cb->count() - 1; i >= 0; --i) {
-               pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
-               if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
-                       cb->setCurrentIndex(i);
-                       return;
-               }
-       }
-
-       // Bleh, default fonts, and the names couldn't be found. Hack
-       // for bug 1063.
-
-       QFont font;
-       font.setKerning(false);
-
-       if (family == theApp()->romanFontName()) {
-               font.setStyleHint(QFont::Serif);
-               font.setFamily(family.c_str());
-       } else if (family == theApp()->sansFontName()) {
-               font.setStyleHint(QFont::SansSerif);
-               font.setFamily(family.c_str());
-       } else if (family == theApp()->typewriterFontName()) {
-               font.setStyleHint(QFont::TypeWriter);
-               font.setFamily(family.c_str());
-       } else {
-               lyxerr << "FAILED to find the default font: '"
-                      << foundry << "', '" << family << '\''<< endl;
-               return;
-       }
-
-       QFontInfo info(font);
-       pair<string, string> tmp = parseFontName(fromqstr(info.family()));
-       string const & default_font_name = tmp.first;
-       lyxerr << "Apparent font is " << default_font_name << endl;
-
-       for (int i = 0; i < cb->count(); ++i) {
-               lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
-               if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
-                                   default_font_name) == 0) {
-                       cb->setCurrentIndex(i);
-                       return;
-               }
-       }
-
-       lyxerr << "FAILED to find the font: '"
-              << foundry << "', '" << family << '\'' <<endl;
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefPlaintext
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefPlaintext::PrefPlaintext(QWidget * parent)
-       : PrefModule(_(Outputs), _("Plain text"), 0, parent)
-{
-       setupUi(this);
-       connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
-               this, SIGNAL(changed()));
-       connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefPlaintext::apply(LyXRC & rc) const
-{
-       rc.plaintext_linelen = plaintextLinelengthSB->value();
-       rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
-}
-
-
-void PrefPlaintext::update(LyXRC const & rc)
-{
-       plaintextLinelengthSB->setValue(rc.plaintext_linelen);
-       plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefDate
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefDate::PrefDate(QWidget * parent)
-       : PrefModule(_(Outputs), _("Date format"), 0, parent)
-{
-       setupUi(this);
-       connect(DateED, SIGNAL(textChanged(const QString &)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefDate::apply(LyXRC & rc) const
-{
-       rc.date_insert_format = fromqstr(DateED->text());
-}
-
-
-void PrefDate::update(LyXRC const & rc)
-{
-       DateED->setText(toqstr(rc.date_insert_format));
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefKeyboard
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
-       : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
-{
-       setupUi(this);
-
-       connect(keymapCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefKeyboard::apply(LyXRC & rc) const
-{
-       // FIXME: can derive CB from the two EDs
-       rc.use_kbmap = keymapCB->isChecked();
-       rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
-       rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
-}
-
-
-void PrefKeyboard::update(LyXRC const & rc)
-{
-       // FIXME: can derive CB from the two EDs
-       keymapCB->setChecked(rc.use_kbmap);
-       firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
-       secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
-}
-
-
-QString PrefKeyboard::testKeymap(QString keymap)
-{
-       return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
-}
-
-
-void PrefKeyboard::on_firstKeymapPB_clicked(bool)
-{
-       QString const file = testKeymap(firstKeymapED->text());
-       if (!file.isEmpty())
-               firstKeymapED->setText(file);
-}
-
-
-void PrefKeyboard::on_secondKeymapPB_clicked(bool)
-{
-       QString const file = testKeymap(secondKeymapED->text());
-       if (!file.isEmpty())
-               secondKeymapED->setText(file);
-}
-
-
-void PrefKeyboard::on_keymapCB_toggled(bool keymap)
-{
-       firstKeymapLA->setEnabled(keymap);
-       secondKeymapLA->setEnabled(keymap);
-       firstKeymapED->setEnabled(keymap);
-       secondKeymapED->setEnabled(keymap);
-       firstKeymapPB->setEnabled(keymap);
-       secondKeymapPB->setEnabled(keymap);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefLatex
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
-       : PrefModule(_(Outputs), _("LaTeX"), form, parent)
-{
-       setupUi(this);
-       connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(latexIndexED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(latexAutoresetCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(latexPaperSizeCO, SIGNAL(activated(int)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefLatex::apply(LyXRC & rc) const
-{
-       rc.fontenc = fromqstr(latexEncodingED->text());
-       rc.chktex_command = fromqstr(latexChecktexED->text());
-       rc.bibtex_command = fromqstr(latexBibtexED->text());
-       rc.index_command = fromqstr(latexIndexED->text());
-       rc.auto_reset_options = latexAutoresetCB->isChecked();
-       rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
-       rc.default_papersize =
-               form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
-}
-
-
-void PrefLatex::update(LyXRC const & rc)
-{
-       latexEncodingED->setText(toqstr(rc.fontenc));
-       latexChecktexED->setText(toqstr(rc.chktex_command));
-       latexBibtexED->setText(toqstr(rc.bibtex_command));
-       latexIndexED->setText(toqstr(rc.index_command));
-       latexAutoresetCB->setChecked(rc.auto_reset_options);
-       latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
-       latexPaperSizeCO->setCurrentIndex(
-               form_->controller().fromPaperSize(rc.default_papersize));
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefScreenFonts
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
-       : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
-{
-       setupUi(this);
-
-       connect(screenRomanCO, SIGNAL(activated(const QString&)),
-               this, SLOT(select_roman(const QString&)));
-       connect(screenSansCO, SIGNAL(activated(const QString&)),
-               this, SLOT(select_sans(const QString&)));
-       connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
-               this, SLOT(select_typewriter(const QString&)));
-
-       QFontDatabase fontdb;
-       QStringList families(fontdb.families());
-       for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
-               screenRomanCO->addItem(*it);
-               screenSansCO->addItem(*it);
-               screenTypewriterCO->addItem(*it);
-       }
-       connect(screenRomanCO, SIGNAL(activated(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenSansCO, SIGNAL(activated(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenZoomSB, SIGNAL(valueChanged(int)),
-               this, SIGNAL(changed()));
-       connect(screenDpiSB, SIGNAL(valueChanged(int)),
-               this, SIGNAL(changed()));
-       connect(screenTinyED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenSmallED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenNormalED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenLargeED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenLargerED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenLargestED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenHugeED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(screenHugerED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-
-       screenTinyED->setValidator(new QDoubleValidator(
-               screenTinyED));
-       screenSmallestED->setValidator(new QDoubleValidator(
-               screenSmallestED));
-       screenSmallerED->setValidator(new QDoubleValidator(
-               screenSmallerED));
-       screenSmallED->setValidator(new QDoubleValidator(
-               screenSmallED));
-       screenNormalED->setValidator(new QDoubleValidator(
-               screenNormalED));
-       screenLargeED->setValidator(new QDoubleValidator(
-               screenLargeED));
-       screenLargerED->setValidator(new QDoubleValidator(
-               screenLargerED));
-       screenLargestED->setValidator(new QDoubleValidator(
-               screenLargestED));
-       screenHugeED->setValidator(new QDoubleValidator(
-               screenHugeED));
-       screenHugerED->setValidator(new QDoubleValidator(
-               screenHugerED));
-}
-
-
-void PrefScreenFonts::apply(LyXRC & rc) const
-{
-       LyXRC const oldrc(rc);
-
-       boost::tie(rc.roman_font_name, rc.roman_font_foundry)
-               = parseFontName(fromqstr(screenRomanCO->currentText()));
-       boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
-               parseFontName(fromqstr(screenSansCO->currentText()));
-       boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
-               parseFontName(fromqstr(screenTypewriterCO->currentText()));
-
-       rc.zoom = screenZoomSB->value();
-       rc.dpi = screenDpiSB->value();
-       rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
-       rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
-       rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
-       rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
-       rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
-       rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
-       rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
-       rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
-       rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
-       rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
-
-       if (rc.font_sizes != oldrc.font_sizes
-               || rc.roman_font_name != oldrc.roman_font_name
-               || rc.sans_font_name != oldrc.sans_font_name
-               || rc.typewriter_font_name != oldrc.typewriter_font_name
-               || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
-               form_->controller().updateScreenFonts();
-       }
-}
-
-
-void PrefScreenFonts::update(LyXRC const & rc)
-{
-       setComboxFont(screenRomanCO, rc.roman_font_name,
-                       rc.roman_font_foundry);
-       setComboxFont(screenSansCO, rc.sans_font_name,
-                       rc.sans_font_foundry);
-       setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
-                       rc.typewriter_font_foundry);
-
-       select_roman(screenRomanCO->currentText());
-       select_sans(screenSansCO->currentText());
-       select_typewriter(screenTypewriterCO->currentText());
-
-       screenZoomSB->setValue(rc.zoom);
-       screenDpiSB->setValue(rc.dpi);
-       screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
-       screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
-       screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
-       screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
-       screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
-       screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
-       screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
-       screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
-       screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
-       screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
-}
-
-void PrefScreenFonts::select_roman(const QString& name)
-{
-       screenRomanFE->set(QFont(name), name);
-}
-
-
-void PrefScreenFonts::select_sans(const QString& name)
-{
-       screenSansFE->set(QFont(name), name);
-}
-
-
-void PrefScreenFonts::select_typewriter(const QString& name)
-{
-       screenTypewriterFE->set(QFont(name), name);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefColors
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefColors::PrefColors(QPrefs * form, QWidget * parent)
-       : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
-{
-       setupUi(this);
-
-       // FIXME: all of this initialization should be put into the controller.
-       // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
-       // for some discussion of why that is not trivial.
-       for (int i = 0; i < LColor::ignore; ++i) {
-               LColor::color lc = static_cast<LColor::color>(i);
-               if (lc == LColor::none
-                       || lc == LColor::black
-                       || lc == LColor::white
-                       || lc == LColor::red
-                       || lc == LColor::green
-                       || lc == LColor::blue
-                       || lc == LColor::cyan
-                       || lc == LColor::magenta
-                       || lc == LColor::yellow
-                       || lc == LColor::inherit
-                       || lc == LColor::ignore) continue;
-
-               lcolors_.push_back(lc);
-               QColor color = QColor(guiApp->colorCache().get(lc));
-               curcolors_.push_back(color.name());
-               QPixmap coloritem(32, 32);
-               coloritem.fill(color);
-               // This is not a memory leak:
-               /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
-                       toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
-       }
-       newcolors_ = curcolors_;
-       // End initialization
-
-       connect(colorChangePB, SIGNAL(clicked()),
-               this, SLOT(change_color()));
-       connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
-               this, SLOT(change_color()));
-}
-
-
-void PrefColors::apply(LyXRC & /*rc*/) const
-{
-       for (unsigned int i = 0; i < lcolors_.size(); ++i) {
-               if (curcolors_[i]!=newcolors_[i])
-                       form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
-       }
-       // HACK The following line is needed because the values are not 
-       // re-initialized in ControlPrefs::initialiseParams but are only 
-       // initialized in the constructor. But the constructor is only called 
-       // once, when the dialog if first created, and is not called again when 
-       // Tools > Preferences is selected a second time: It's just called up 
-       // from memory. [See QDialogView::show(): if (!form) { build(); }.]
-       curcolors_ = newcolors_;
-}
-
-
-// FIXME The fact that this method is empty is also a symptom of the
-// problem here.
-void PrefColors::update(LyXRC const & /*rc*/)
-{
-}
-
-void PrefColors::change_color()
-{
-       int const row = lyxObjectsLW->currentRow();
-       QString color = newcolors_[row];
-       QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
-
-       if (c.name() != color) {
-               newcolors_[row] = c.name();
-               QPixmap coloritem(32, 32);
-               coloritem.fill(c);
-               lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
-               // emit signal
-               changed();
-       }
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefCygwinPath
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefCygwinPath::PrefCygwinPath(QWidget * parent)
-       : PrefModule(_(Outputs), _("Paths"), 0, parent)
-{
-       setupUi(this);
-       connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
-}
-
-
-void PrefCygwinPath::apply(LyXRC & rc) const
-{
-       rc.windows_style_tex_paths = pathCB->isChecked();
-}
-
-
-void PrefCygwinPath::update(LyXRC const & rc)
-{
-       pathCB->setChecked(rc.windows_style_tex_paths);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefDisplay
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefDisplay::PrefDisplay(QWidget * parent)
-       : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
-{
-       setupUi(this);
-       connect(instantPreviewCO, SIGNAL(activated(int)),
-               this, SIGNAL(changed()));
-       connect(displayGraphicsCO, SIGNAL(activated(int)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefDisplay::apply(LyXRC & rc) const
-{
-       switch (instantPreviewCO->currentIndex()) {
-       case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
-       case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
-       case 2: rc.preview = LyXRC::PREVIEW_ON; break;
-       }
-
-       lyx::graphics::DisplayType dtype;
-       switch (displayGraphicsCO->currentIndex()) {
-       case 3: dtype = lyx::graphics::NoDisplay; break;
-       case 2: dtype = lyx::graphics::ColorDisplay; break;
-       case 1: dtype = lyx::graphics::GrayscaleDisplay;        break;
-       case 0: dtype = lyx::graphics::MonochromeDisplay; break;
-       default: dtype = lyx::graphics::GrayscaleDisplay;
-       }
-       rc.display_graphics = dtype;
-
-#ifdef WITH_WARNINGS
-#warning FIXME!! The graphics cache no longer has a changeDisplay method.
-#endif
-#if 0
-       if (old_value != rc.display_graphics) {
-               lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
-               gc.changeDisplay();
-       }
-#endif
-}
-
-
-void PrefDisplay::update(LyXRC const & rc)
-{
-       switch (rc.preview) {
-       case LyXRC::PREVIEW_OFF:
-               instantPreviewCO->setCurrentIndex(0);
-               break;
-       case LyXRC::PREVIEW_NO_MATH :
-               instantPreviewCO->setCurrentIndex(1);
-               break;
-       case LyXRC::PREVIEW_ON :
-               instantPreviewCO->setCurrentIndex(2);
-               break;
-       }
-
-       int item = 2;
-       switch (rc.display_graphics) {
-               case lyx::graphics::NoDisplay:          item = 3; break;
-               case lyx::graphics::ColorDisplay:       item = 2; break;
-               case lyx::graphics::GrayscaleDisplay:   item = 1; break;
-               case lyx::graphics::MonochromeDisplay:  item = 0; break;
-               default: break;
-       }
-       displayGraphicsCO->setCurrentIndex(item);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefPaths
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
-       : PrefModule(docstring(), _("Paths"), form, parent)
-{
-       setupUi(this);
-       connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
-       connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
-       connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
-       connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
-       connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
-       connect(workingDirED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(templateDirED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(backupDirED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(tempDirED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefPaths::apply(LyXRC & rc) const
-{
-       rc.document_path = internal_path(fromqstr(workingDirED->text()));
-       rc.template_path = internal_path(fromqstr(templateDirED->text()));
-       rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
-       rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
-       rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
-       // FIXME: should be a checkbox only
-       rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
-}
-
-
-void PrefPaths::update(LyXRC const & rc)
-{
-       workingDirED->setText(toqstr(external_path(rc.document_path)));
-       templateDirED->setText(toqstr(external_path(rc.template_path)));
-       backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
-       tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
-       pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
-       // FIXME: should be a checkbox only
-       lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
-}
-
-
-void PrefPaths::select_templatedir()
-{
-       docstring file(form_->controller().browsedir(
-               from_utf8(internal_path(fromqstr(templateDirED->text()))),
-               _("Select a document templates directory")));
-       if (!file.empty())
-               templateDirED->setText(toqstr(file));
-}
-
-
-void PrefPaths::select_tempdir()
-{
-       docstring file(form_->controller().browsedir(
-               from_utf8(internal_path(fromqstr(tempDirED->text()))),
-               _("Select a temporary directory")));
-       if (!file.empty())
-               tempDirED->setText(toqstr(file));
-}
-
-
-void PrefPaths::select_backupdir()
-{
-       docstring file(form_->controller().browsedir(
-               from_utf8(internal_path(fromqstr(backupDirED->text()))),
-               _("Select a backups directory")));
-       if (!file.empty())
-               backupDirED->setText(toqstr(file));
-}
-
-
-void PrefPaths::select_workingdir()
-{
-       docstring file(form_->controller().browsedir(
-               from_utf8(internal_path(fromqstr(workingDirED->text()))),
-               _("Select a document directory")));
-       if (!file.empty())
-               workingDirED->setText(toqstr(file));
-}
-
-
-void PrefPaths::select_lyxpipe()
-{
-       docstring file(form_->controller().browse(
-               from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
-               _("Give a filename for the LyX server pipe")));
-       if (!file.empty())
-               lyxserverDirED->setText(toqstr(file));
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefSpellchecker
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
-       : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
-{
-       setupUi(this);
-
-       connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
-#if defined (USE_ISPELL)
-       connect(spellCommandCO, SIGNAL(activated(int)),
-               this, SIGNAL(changed()));
-#else
-       spellCommandCO->setEnabled(false);
-#endif
-       connect(altLanguageED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(compoundWordCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(inputEncodingCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-
-       spellCommandCO->addItem(qt_("ispell"));
-       spellCommandCO->addItem(qt_("aspell"));
-       spellCommandCO->addItem(qt_("hspell"));
-#ifdef USE_PSPELL
-       spellCommandCO->addItem(qt_("pspell (library)"));
-#else
-#ifdef USE_ASPELL
-       spellCommandCO->addItem(qt_("aspell (library)"));
-#endif
-#endif
-}
-
-
-void PrefSpellchecker::apply(LyXRC & rc) const
-{
-       switch (spellCommandCO->currentIndex()) {
-               case 0:
-               case 1:
-               case 2:
-                       rc.use_spell_lib = false;
-                       rc.isp_command = fromqstr(spellCommandCO->currentText());
-                       break;
-               case 3:
-                       rc.use_spell_lib = true;
-                       break;
-       }
-
-       // FIXME: remove isp_use_alt_lang
-       rc.isp_alt_lang = fromqstr(altLanguageED->text());
-       rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
-       // FIXME: remove isp_use_esc_chars
-       rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
-       rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
-       // FIXME: remove isp_use_pers_dict
-       rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
-       rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
-       rc.isp_accept_compound = compoundWordCB->isChecked();
-       rc.isp_use_input_encoding = inputEncodingCB->isChecked();
-}
-
-
-void PrefSpellchecker::update(LyXRC const & rc)
-{
-       spellCommandCO->setCurrentIndex(0);
-
-       if (rc.isp_command == "ispell") {
-               spellCommandCO->setCurrentIndex(0);
-       } else if (rc.isp_command == "aspell") {
-               spellCommandCO->setCurrentIndex(1);
-       } else if (rc.isp_command == "hspell") {
-               spellCommandCO->setCurrentIndex(2);
-       }
-
-       if (rc.use_spell_lib) {
-#if defined(USE_ASPELL) || defined(USE_PSPELL)
-               spellCommandCO->setCurrentIndex(3);
-#endif
-       }
-
-       // FIXME: remove isp_use_alt_lang
-       altLanguageED->setText(toqstr(rc.isp_alt_lang));
-       // FIXME: remove isp_use_esc_chars
-       escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
-       // FIXME: remove isp_use_pers_dict
-       persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
-       compoundWordCB->setChecked(rc.isp_accept_compound);
-       inputEncodingCB->setChecked(rc.isp_use_input_encoding);
-}
-
-
-void PrefSpellchecker::select_dict()
-{
-       docstring file(form_->controller().browsedict(
-               from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
-       if (!file.empty())
-               persDictionaryED->setText(toqstr(file));
-}
-
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefConverters
-//
-/////////////////////////////////////////////////////////////////////
-
-
-PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
-       : PrefModule(docstring(), _("Converters"), form, parent)
-{
-       setupUi(this);
-
-       connect(converterNewPB, SIGNAL(clicked()),
-               this, SLOT(update_converter()));
-       connect(converterRemovePB, SIGNAL(clicked()),
-               this, SLOT(remove_converter()));
-       connect(converterModifyPB, SIGNAL(clicked()),
-               this, SLOT(update_converter()));
-       connect(convertersLW, SIGNAL(currentRowChanged(int)),
-               this, SLOT(switch_converter()));
-       connect(converterFromCO, SIGNAL(activated(const QString&)),
-               this, SLOT(converter_changed()));
-       connect(converterToCO, SIGNAL(activated(const QString&)),
-               this, SLOT(converter_changed()));
-       connect(converterED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(converter_changed()));
-       connect(converterFlagED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(converter_changed()));
-       connect(converterNewPB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(converterRemovePB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(converterModifyPB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-
-       maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
-       converterDefGB->setFocusProxy(convertersLW);
-}
-
-
-void PrefConverters::apply(LyXRC & rc) const
-{
-       rc.use_converter_cache = cacheCB->isChecked();
-       rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
-}
-
-
-void PrefConverters::update(LyXRC const & rc)
-{
-       cacheCB->setChecked(rc.use_converter_cache);
-       QString max_age;
-       max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
-       maxAgeLE->setText(max_age);
-       updateGui();
-}
-
-
-void PrefConverters::updateGui()
-{
-       // save current selection
-       QString current = converterFromCO->currentText()
-               + " -> " + converterToCO->currentText();
-
-       converterFromCO->clear();
-       converterToCO->clear();
-
-       Formats::const_iterator cit = form_->formats().begin();
-       Formats::const_iterator end = form_->formats().end();
-       for (; cit != end; ++cit) {
-               converterFromCO->addItem(toqstr(cit->prettyname()));
-               converterToCO->addItem(toqstr(cit->prettyname()));
-       }
-
-       // currentRowChanged(int) is also triggered when updating the listwidget
-       // block signals to avoid unnecessary calls to switch_converter()
-       convertersLW->blockSignals(true);
-       convertersLW->clear();
-
-       Converters::const_iterator ccit = form_->converters().begin();
-       Converters::const_iterator cend = form_->converters().end();
-       for (; ccit != cend; ++ccit) {
-               std::string const name =
-                       ccit->From->prettyname() + " -> " + ccit->To->prettyname();
-               int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
-               new QListWidgetItem(toqstr(name), convertersLW, type);
-       }
-       convertersLW->sortItems(Qt::AscendingOrder);
-       convertersLW->blockSignals(false);
-
-       // restore selection
-       if (!current.isEmpty()) {
-               QList<QListWidgetItem *> const item =
-                       convertersLW->findItems(current, Qt::MatchExactly);
-               if (item.size()>0)
-                       convertersLW->setCurrentItem(item.at(0));
-       }
-
-       // select first element if restoring failed
-       if (convertersLW->currentRow() == -1)
-               convertersLW->setCurrentRow(0);
-
-       updateButtons();
-}
-
-
-void PrefConverters::switch_converter()
-{
-       int const cnr = convertersLW->currentItem()->type();
-       Converter const & c(form_->converters().get(cnr));
-       converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
-       converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
-       converterED->setText(toqstr(c.command));
-       converterFlagED->setText(toqstr(c.flags));
-
-       updateButtons();
-}
-
-
-void PrefConverters::converter_changed()
-{
-       updateButtons();
-}
-
-
-void PrefConverters::updateButtons()
-{
-       Format const & from(form_->formats().get(converterFromCO->currentIndex()));
-       Format const & to(form_->formats().get(converterToCO->currentIndex()));
-       int const sel = form_->converters().getNumber(from.name(), to.name());
-       bool const known = !(sel < 0);
-       bool const valid = !(converterED->text().isEmpty()
-               || from.name() == to.name());
-
-       int const cnr = convertersLW->currentItem()->type();
-       Converter const & c(form_->converters().get(cnr));
-       string const old_command = c.command;
-       string const old_flag = c.flags;
-       string const new_command(fromqstr(converterED->text()));
-       string const new_flag(fromqstr(converterFlagED->text()));
-
-       bool modified = ((old_command != new_command) || (old_flag != new_flag));
-
-       converterModifyPB->setEnabled(valid && known && modified);
-       converterNewPB->setEnabled(valid && !known);
-       converterRemovePB->setEnabled(known);
-
-       maxAgeLE->setEnabled(cacheCB->isChecked());
-       maxAgeLA->setEnabled(cacheCB->isChecked());
-}
-
-
-// FIXME: user must
-// specify unique from/to or it doesn't appear. This is really bad UI
-// this is why we can use the same function for both new and modify
-void PrefConverters::update_converter()
-{
-       Format const & from(form_->formats().get(converterFromCO->currentIndex()));
-       Format const & to(form_->formats().get(converterToCO->currentIndex()));
-       string const flags = fromqstr(converterFlagED->text());
-       string const command = fromqstr(converterED->text());
-
-       Converter const * old = form_->converters().getConverter(from.name(), to.name());
-       form_->converters().add(from.name(), to.name(), command, flags);
-       if (!old) {
-               form_->converters().updateLast(form_->formats());
-       }
-
-       updateGui();
-}
-
-
-void PrefConverters::remove_converter()
-{
-       Format const & from(form_->formats().get(converterFromCO->currentIndex()));
-       Format const & to(form_->formats().get(converterToCO->currentIndex()));
-       form_->converters().erase(from.name(), to.name());
-
-       updateGui();
-}
-
-
-void PrefConverters::on_cacheCB_stateChanged(int state)
-{
-       maxAgeLE->setEnabled(state == Qt::Checked);
-       maxAgeLA->setEnabled(state == Qt::Checked);
-       changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefCopiers
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
-       : PrefModule(docstring(), _("Copiers"), form, parent)
-{
-       setupUi(this);
-
-       connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
-       connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
-       connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
-       connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
-               this, SLOT(switch_copierLB(int)));
-       connect(copierFormatCO, SIGNAL(activated(int)),
-               this, SLOT(switch_copierCO(int)));
-       connect(copierNewPB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(copierRemovePB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(copierModifyPB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(copierFormatCO, SIGNAL(activated(const QString &)),
-               this, SLOT(copiers_changed()));
-       connect(copierED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(copiers_changed()));
-}
-
-
-void PrefCopiers::apply(LyXRC & /*rc*/) const
-{
-}
-
-
-void PrefCopiers::update(LyXRC const & /*rc*/)
-{
-       update();
-}
-
-
-void PrefCopiers::update()
-{
-       // The choice widget
-       // save current selection
-       QString current = copierFormatCO->currentText();
-       copierFormatCO->clear();
-
-       for (Formats::const_iterator it = form_->formats().begin(),
-                    end = form_->formats().end();
-            it != end; ++it) {
-               copierFormatCO->addItem(toqstr(it->prettyname()));
-       }
-
-       // The browser widget
-       AllCopiersLW->clear();
-
-       for (Movers::const_iterator it = form_->movers().begin(),
-                    end = form_->movers().end();
-            it != end; ++it) {
-               std::string const & command = it->second.command();
-               if (command.empty())
-                       continue;
-               QString const pretty = toqstr(form_->formats().prettyName(it->first));
-               AllCopiersLW->addItem(pretty);
-       }
-       AllCopiersLW->sortItems(Qt::AscendingOrder);
-
-       // restore selection
-       if (!current.isEmpty()) {
-               QList<QListWidgetItem *> item =
-                       AllCopiersLW->findItems(current, Qt::MatchExactly);
-               if (item.size()>0)
-                       AllCopiersLW->setCurrentItem(item.at(0));
-       }
-       // select first element if restoring failed
-       if (AllCopiersLW->currentRow() == -1)
-               AllCopiersLW->setCurrentRow(0);
-}
-
-
-namespace {
-
-class SamePrettyName {
-public:
-       SamePrettyName(string const & n) : pretty_name_(n) {}
-
-       bool operator()(Format const & fmt) const {
-               return fmt.prettyname() == pretty_name_;
-       }
-
-private:
-       string const pretty_name_;
-};
-
-
-Format const * getFormat(std::string const & prettyname)
-{
-       Formats::const_iterator it = formats.begin();
-       Formats::const_iterator const end = formats.end();
-       it = std::find_if(it, end, SamePrettyName(prettyname));
-       return it == end ? 0 : &*it;
-}
-
-} // namespace anon
-
-
-void PrefCopiers::switch_copierLB(int row)
-{
-       if (row < 0)
-               return;
-
-       // FIXME UNICODE?
-       std::string const browser_text =
-               fromqstr(AllCopiersLW->currentItem()->text());
-       Format const * fmt = getFormat(browser_text);
-       if (fmt == 0)
-               return;
-
-       QString const gui_name = toqstr(fmt->prettyname());
-       QString const command = toqstr(form_->movers().command(fmt->name()));
-
-       copierED->clear();
-       int const combo_size = copierFormatCO->count();
-       for (int i = 0; i < combo_size; ++i) {
-               QString const text = copierFormatCO->itemText(i);
-               if (text == gui_name) {
-                       copierFormatCO->setCurrentIndex(i);
-                       copierED->setText(command);
-                       break;
-               }
-       }
-       updateButtons();
-}
-
-
-void PrefCopiers::switch_copierCO(int row)
-{
-       if (row<0)
-               return;
-
-       std::string const combo_text =
-               fromqstr(copierFormatCO->currentText());
-       Format const * fmt = getFormat(combo_text);
-       if (fmt == 0)
-               return;
-
-       QString const command = toqstr(form_->movers().command(fmt->name()));
-       copierED->setText(command);
-
-       QListWidgetItem * const index = AllCopiersLW->currentItem();
-       if (index >= 0)
-               AllCopiersLW->setItemSelected(index, false);
-
-       QString const gui_name = toqstr(fmt->prettyname());
-       int const browser_size = AllCopiersLW->count();
-       for (int i = 0; i < browser_size; ++i) {
-               QString const text = AllCopiersLW->item(i)->text();
-               if (text == gui_name) {
-                       QListWidgetItem * item = AllCopiersLW->item(i);
-                       AllCopiersLW->setItemSelected(item, true);
-                       break;
-               }
-       }
-}
-
-
-void PrefCopiers::copiers_changed()
-{
-       updateButtons();
-}
-
-
-void PrefCopiers::updateButtons()
-{
-       QString selected = copierFormatCO->currentText();
-
-       bool known = false;
-       for (int i = 0; i < AllCopiersLW->count(); ++i) {
-               if (AllCopiersLW->item(i)->text() == selected)
-                       known = true;
-       }
-
-       bool const valid = !copierED->text().isEmpty();
-
-       Format const * fmt = getFormat(fromqstr(selected));
-       string const old_command = form_->movers().command(fmt->name());
-       string const new_command(fromqstr(copierED->text()));
-
-       bool modified = (old_command != new_command);
-
-       copierModifyPB->setEnabled(valid && known && modified);
-       copierNewPB->setEnabled(valid && !known);
-       copierRemovePB->setEnabled(known);
-}
-
-
-void PrefCopiers::new_copier()
-{
-       std::string const combo_text =
-               fromqstr(copierFormatCO->currentText());
-       Format const * fmt = getFormat(combo_text);
-       if (fmt == 0)
-               return;
-
-       string const command = fromqstr(copierED->text());
-       if (command.empty())
-               return;
-
-       form_->movers().set(fmt->name(), command);
-
-       update();
-       int const last = AllCopiersLW->count() - 1;
-       AllCopiersLW->setCurrentRow(last);
-
-       updateButtons();
-}
-
-
-void PrefCopiers::modify_copier()
-{
-       std::string const combo_text =
-               fromqstr(copierFormatCO->currentText());
-       Format const * fmt = getFormat(combo_text);
-       if (fmt == 0)
-               return;
-
-       string const command = fromqstr(copierED->text());
-       form_->movers().set(fmt->name(), command);
-
-       update();
-       updateButtons();
-}
-
-
-void PrefCopiers::remove_copier()
-{
-       std::string const combo_text =
-               fromqstr(copierFormatCO->currentText());
-       Format const * fmt = getFormat(combo_text);
-       if (fmt == 0)
-               return;
-
-       string const & fmt_name = fmt->name();
-       form_->movers().set(fmt_name, string());
-
-       update();
-       updateButtons();
-}
-
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefFileformats
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
-       : PrefModule(docstring(), _("File formats"), form, parent)
-{
-       setupUi(this);
-
-       connect(formatNewPB, SIGNAL(clicked()),
-               this, SLOT(new_format()));
-       connect(formatRemovePB, SIGNAL(clicked()),
-               this, SLOT(remove_format()));
-       connect(formatModifyPB, SIGNAL(clicked()),
-               this, SLOT(modify_format()));
-       connect(formatsLW, SIGNAL(currentRowChanged(int)),
-               this, SLOT(switch_format(int)));
-       connect(formatED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(fileformat_changed()));
-       connect(guiNameED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(fileformat_changed()));
-       connect(shortcutED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(fileformat_changed()));
-       connect(extensionED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(fileformat_changed()));
-       connect(viewerED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(fileformat_changed()));
-       connect(editorED, SIGNAL(textChanged(const QString&)),
-               this, SLOT(fileformat_changed()));
-       connect(documentCB, SIGNAL(clicked()),
-               this, SLOT(fileformat_changed()));
-       connect(vectorCB, SIGNAL(clicked()),
-               this, SLOT(fileformat_changed()));
-       connect(formatNewPB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(formatRemovePB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(formatModifyPB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefFileformats::apply(LyXRC & /*rc*/) const
-{
-}
-
-
-void PrefFileformats::update(LyXRC const & /*rc*/)
-{
-       update();
-}
-
-
-void PrefFileformats::update()
-{
-       // save current selection
-       QString current = guiNameED->text();
-
-       // update listwidget with formats
-       formatsLW->blockSignals(true);
-       formatsLW->clear();
-       Formats::const_iterator cit = form_->formats().begin();
-       Formats::const_iterator end = form_->formats().end();
-       for (; cit != end; ++cit) {
-               new QListWidgetItem(toqstr(cit->prettyname()),
-                                                       formatsLW,
-                                                       form_->formats().getNumber(cit->name()) );
-       }
-       formatsLW->sortItems(Qt::AscendingOrder);
-       formatsLW->blockSignals(false);
-
-       // restore selection
-       if (!current.isEmpty()) {
-               QList<QListWidgetItem *>  item = formatsLW->findItems(current, Qt::MatchExactly);
-               if (item.size()>0)
-                       formatsLW->setCurrentItem(item.at(0));
-       }
-       // select first element if restoring failed
-       if (formatsLW->currentRow() == -1)
-               formatsLW->setCurrentRow(0);
-}
-
-
-void PrefFileformats::switch_format(int nr)
-{
-       int const ftype = formatsLW->item(nr)->type();
-       Format const f = form_->formats().get(ftype);
-
-       formatED->setText(toqstr(f.name()));
-       guiNameED->setText(toqstr(f.prettyname()));
-       extensionED->setText(toqstr(f.extension()));
-       shortcutED->setText(toqstr(f.shortcut()));
-       viewerED->setText(toqstr(f.viewer()));
-       editorED->setText(toqstr(f.editor()));
-       documentCB->setChecked((f.documentFormat()));
-       vectorCB->setChecked((f.vectorFormat()));
-
-       updateButtons();
-}
-
-
-void PrefFileformats::fileformat_changed()
-{
-       updateButtons();
-}
-
-
-void PrefFileformats::updateButtons()
-{
-       QString const format = formatED->text();
-       QString const gui_name = guiNameED->text();
-       int const sel = form_->formats().getNumber(fromqstr(format));
-       bool gui_name_known = false;
-       int where = sel;
-       for (int i = 0; i < formatsLW->count(); ++i) {
-               if (formatsLW->item(i)->text() == gui_name) {
-                       gui_name_known = true;
-                       where = formatsLW->item(i)->type();
-               }
-       }
-
-       // assure that a gui name cannot be chosen twice
-       bool const known_otherwise = gui_name_known && (where != sel);
-
-       bool const known = !(sel < 0);
-       bool const valid = (!formatED->text().isEmpty()
-               && !guiNameED->text().isEmpty());
-
-       int const ftype = formatsLW->currentItem()->type();
-       Format const & f(form_->formats().get(ftype));
-       string const old_pretty(f.prettyname());
-       string const old_shortcut(f.shortcut());
-       string const old_extension(f.extension());
-       string const old_viewer(f.viewer());
-       string const old_editor(f.editor());
-       bool const old_document(f.documentFormat());
-       bool const old_vector(f.vectorFormat());
-
-       string const new_pretty(fromqstr(gui_name));
-       string const new_shortcut(fromqstr(shortcutED->text()));
-       string const new_extension(fromqstr(extensionED->text()));
-       string const new_viewer(fromqstr(viewerED->text()));
-       string const new_editor(fromqstr(editorED->text()));
-       bool const new_document(documentCB->isChecked());
-       bool const new_vector(vectorCB->isChecked());
-
-       bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
-               || (old_extension != new_extension) || (old_viewer != new_viewer)
-               || old_editor != new_editor || old_document != new_document
-               || old_vector != new_vector);
-
-       formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
-       formatNewPB->setEnabled(valid && !known && !gui_name_known);
-       formatRemovePB->setEnabled(known);
-}
-
-
-void PrefFileformats::new_format()
-{
-       string const name = fromqstr(formatED->text());
-       string const prettyname = fromqstr(guiNameED->text());
-       string const extension = fromqstr(extensionED->text());
-       string const shortcut = fromqstr(shortcutED->text());
-       string const viewer = fromqstr(viewerED->text());
-       string const editor = fromqstr(editorED->text());
-       int flags = Format::none;
-       if (documentCB->isChecked())
-               flags |= Format::document;
-       if (vectorCB->isChecked())
-               flags |= Format::vector;
-
-       form_->formats().add(name, extension, prettyname, shortcut, viewer,
-                            editor, flags);
-       form_->formats().sort();
-       form_->converters().update(form_->formats());
-
-       update();
-       updateButtons();
-       formatsChanged();
-}
-
-
-void PrefFileformats::modify_format()
-{
-       int const current_item = formatsLW->currentItem()->type();
-       Format const & oldformat = form_->formats().get(current_item);
-       form_->formats().erase(oldformat.name());
-
-       new_format();
-}
-
-
-void PrefFileformats::remove_format()
-{
-       int const nr = formatsLW->currentItem()->type();
-       string const current_text = form_->formats().get(nr).name();
-       if (form_->converters().formatIsUsed(current_text)) {
-               Alert::error(_("Format in use"),
-                            _("Cannot remove a Format used by a Converter. "
-                                           "Remove the converter first."));
-               return;
-       }
-
-       form_->formats().erase(current_text);
-       form_->converters().update(form_->formats());
-
-       update();
-       updateButtons();
-       formatsChanged();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefLanguage
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefLanguage::PrefLanguage(QWidget * parent)
-       : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
-{
-       setupUi(this);
-
-       connect(rtlCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(markForeignCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(autoBeginCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(autoEndCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(useBabelCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(globalCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(languagePackageED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(startCommandED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(endCommandED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(defaultLanguageCO, SIGNAL(activated(int)),
-               this, SIGNAL(changed()));
-
-       defaultLanguageCO->clear();
-
-       // store the lang identifiers for later
-       std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
-       lang_ = getSecond(langs);
-
-       std::vector<LanguagePair>::const_iterator lit  = langs.begin();
-       std::vector<LanguagePair>::const_iterator lend = langs.end();
-       for (; lit != lend; ++lit) {
-               defaultLanguageCO->addItem(toqstr(lit->first));
-       }
-}
-
-
-void PrefLanguage::apply(LyXRC & rc) const
-{
-       // FIXME: remove rtl_support bool
-       rc.rtl_support = rtlCB->isChecked();
-       rc.mark_foreign_language = markForeignCB->isChecked();
-       rc.language_auto_begin = autoBeginCB->isChecked();
-       rc.language_auto_end = autoEndCB->isChecked();
-       rc.language_use_babel = useBabelCB->isChecked();
-       rc.language_global_options = globalCB->isChecked();
-       rc.language_package = fromqstr(languagePackageED->text());
-       rc.language_command_begin = fromqstr(startCommandED->text());
-       rc.language_command_end = fromqstr(endCommandED->text());
-       rc.default_language = lang_[defaultLanguageCO->currentIndex()];
-}
-
-
-void PrefLanguage::update(LyXRC const & rc)
-{
-       // FIXME: remove rtl_support bool
-       rtlCB->setChecked(rc.rtl_support);
-       markForeignCB->setChecked(rc.mark_foreign_language);
-       autoBeginCB->setChecked(rc.language_auto_begin);
-       autoEndCB->setChecked(rc.language_auto_end);
-       useBabelCB->setChecked(rc.language_use_babel);
-       globalCB->setChecked(rc.language_global_options);
-       languagePackageED->setText(toqstr(rc.language_package));
-       startCommandED->setText(toqstr(rc.language_command_begin));
-       endCommandED->setText(toqstr(rc.language_command_end));
-
-       int const pos = int(findPos_helper(lang_, rc.default_language));
-       defaultLanguageCO->setCurrentIndex(pos);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefPrinter
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefPrinter::PrefPrinter(QWidget * parent)
-       : PrefModule(_(Outputs), _("Printer"), 0, parent)
-{
-       setupUi(this);
-
-       connect(printerAdaptCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(printerCommandED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerNameED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerReverseED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerEvenED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerOddED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerToFileED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerExtraED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefPrinter::apply(LyXRC & rc) const
-{
-       rc.print_adapt_output = printerAdaptCB->isChecked();
-       rc.print_command = fromqstr(printerCommandED->text());
-       rc.printer = fromqstr(printerNameED->text());
-
-       rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
-       rc.print_copies_flag = fromqstr(printerCopiesED->text());
-       rc.print_reverse_flag = fromqstr(printerReverseED->text());
-       rc.print_to_printer = fromqstr(printerToPrinterED->text());
-       rc.print_file_extension = fromqstr(printerExtensionED->text());
-       rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
-       rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
-       rc.print_evenpage_flag = fromqstr(printerEvenED->text());
-       rc.print_oddpage_flag = fromqstr(printerOddED->text());
-       rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
-       rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
-       rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
-       rc.print_extra_options = fromqstr(printerExtraED->text());
-       rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
-       rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
-}
-
-
-void PrefPrinter::update(LyXRC const & rc)
-{
-       printerAdaptCB->setChecked(rc.print_adapt_output);
-       printerCommandED->setText(toqstr(rc.print_command));
-       printerNameED->setText(toqstr(rc.printer));
-
-       printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
-       printerCopiesED->setText(toqstr(rc.print_copies_flag));
-       printerReverseED->setText(toqstr(rc.print_reverse_flag));
-       printerToPrinterED->setText(toqstr(rc.print_to_printer));
-       printerExtensionED->setText(toqstr(rc.print_file_extension));
-       printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
-       printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
-       printerEvenED->setText(toqstr(rc.print_evenpage_flag));
-       printerOddED->setText(toqstr(rc.print_oddpage_flag));
-       printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
-       printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
-       printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
-       printerExtraED->setText(toqstr(rc.print_extra_options));
-       printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
-       printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// PrefUserInterface
-//
-/////////////////////////////////////////////////////////////////////
-
-PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
-       : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
-{
-       setupUi(this);
-
-       connect(autoSaveCB, SIGNAL(toggled(bool)),
-               autoSaveLA, SLOT(setEnabled(bool)));
-       connect(autoSaveCB, SIGNAL(toggled(bool)),
-               autoSaveSB, SLOT(setEnabled(bool)));
-       connect(autoSaveCB, SIGNAL(toggled(bool)),
-               TextLabel1, SLOT(setEnabled(bool)));
-       connect(uiFilePB, SIGNAL(clicked()),
-               this, SLOT(select_ui()));
-       connect(bindFilePB, SIGNAL(clicked()),
-               this, SLOT(select_bind()));
-       connect(uiFileED, SIGNAL(textChanged(const QString &)),
-               this, SIGNAL(changed()));
-       connect(bindFileED, SIGNAL(textChanged(const QString &)),
-               this, SIGNAL(changed()));
-       connect(restoreCursorCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(loadSessionCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(loadWindowSizeCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(loadWindowLocationCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(windowWidthSB, SIGNAL(valueChanged(int)),
-               this, SIGNAL(changed()));
-       connect(windowHeightSB, SIGNAL(valueChanged(int)),
-               this, SIGNAL(changed()));
-       connect(cursorFollowsCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(autoSaveSB, SIGNAL(valueChanged(int)),
-               this, SIGNAL(changed()));
-       connect(autoSaveCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(lastfilesSB, SIGNAL(valueChanged(int)),
-               this, SIGNAL(changed()));
-       lastfilesSB->setMaximum(maxlastfiles);
-}
-
-
-void PrefUserInterface::apply(LyXRC & rc) const
-{
-       rc.ui_file = internal_path(fromqstr(uiFileED->text()));
-       rc.bind_file = internal_path(fromqstr(bindFileED->text()));
-       rc.use_lastfilepos = restoreCursorCB->isChecked();
-       rc.load_session = loadSessionCB->isChecked();
-       if (loadWindowSizeCB->isChecked()) {
-               rc.geometry_width = 0;
-               rc.geometry_height = 0;
-       } else {
-               rc.geometry_width = windowWidthSB->value();
-               rc.geometry_height = windowHeightSB->value();
-       }
-       rc.geometry_xysaved = loadWindowLocationCB->isChecked();
-       rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
-       rc.autosave = autoSaveSB->value() * 60;
-       rc.make_backup = autoSaveCB->isChecked();
-       rc.num_lastfiles = lastfilesSB->value();
-}
-
-
-void PrefUserInterface::update(LyXRC const & rc)
-{
-       uiFileED->setText(toqstr(external_path(rc.ui_file)));
-       bindFileED->setText(toqstr(external_path(rc.bind_file)));
-       restoreCursorCB->setChecked(rc.use_lastfilepos);
-       loadSessionCB->setChecked(rc.load_session);
-       bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
-       loadWindowSizeCB->setChecked(loadWindowSize);
-       if (!loadWindowSize) {
-               windowWidthSB->setValue(rc.geometry_width);
-               windowHeightSB->setValue(rc.geometry_height);
-       }
-       loadWindowLocationCB->setChecked(rc.geometry_xysaved);
-       cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
-       // convert to minutes
-       int mins(rc.autosave / 60);
-       if (rc.autosave && !mins)
-               mins = 1;
-       autoSaveSB->setValue(mins);
-       autoSaveCB->setChecked(rc.make_backup);
-       lastfilesSB->setValue(rc.num_lastfiles);
-}
-
-
-
-void PrefUserInterface::select_ui()
-{
-       docstring const name =
-               from_utf8(internal_path(fromqstr(uiFileED->text())));
-       docstring file(form_->controller().browseUI(name));
-       if (!file.empty())
-               uiFileED->setText(toqstr(file));
-}
-
-
-void PrefUserInterface::select_bind()
-{
-       docstring const name =
-               from_utf8(internal_path(fromqstr(bindFileED->text())));
-       docstring file(form_->controller().browsebind(name));
-       if (!file.empty())
-               bindFileED->setText(toqstr(file));
-}
-
-
-void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
-{
-       windowWidthLA->setDisabled(loadwindowsize);
-       windowHeightLA->setDisabled(loadwindowsize);
-       windowWidthSB->setDisabled(loadwindowsize);
-       windowHeightSB->setDisabled(loadwindowsize);
-}
-
-
-PrefIdentity::PrefIdentity(QWidget * parent)
-: PrefModule(docstring(), _("Identity"), 0, parent)
-{
-       setupUi(this);
-
-       connect(nameED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-       connect(emailED, SIGNAL(textChanged(const QString&)),
-               this, SIGNAL(changed()));
-}
-
-
-void PrefIdentity::apply(LyXRC & rc) const
-{
-       rc.user_name = fromqstr(nameED->text());
-       rc.user_email = fromqstr(emailED->text());
-}
-
-
-void PrefIdentity::update(LyXRC const & rc)
-{
-       nameED->setText(toqstr(rc.user_name));
-       emailED->setText(toqstr(rc.user_email));
-}
-
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QPrefsDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QPrefsDialog::QPrefsDialog(QPrefs * form)
-       : form_(form)
-{
-       setupUi(this);
-       QDialog::setModal(false);
-
-       connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
-
-       add(new PrefUserInterface(form_));
-       add(new PrefScreenFonts(form_));
-       add(new PrefColors(form_));
-       add(new PrefDisplay);
-       add(new PrefKeyboard(form_));
-
-       add(new PrefPaths(form_));
-
-       add(new PrefIdentity);
-
-       add(new PrefLanguage);
-       add(new PrefSpellchecker(form_));
-
-       add(new PrefPrinter);
-       add(new PrefDate);
-       add(new PrefPlaintext);
-       add(new PrefLatex(form_));
-
-#if defined(__CYGWIN__) || defined(_WIN32)
-       add(new PrefCygwinPath);
-#endif
-
-
-       PrefConverters * converters = new PrefConverters(form_);
-       PrefFileformats * formats = new PrefFileformats(form_);
-       connect(formats, SIGNAL(formatsChanged()),
-                       converters, SLOT(updateGui()));
-       add(converters);
-       add(formats);
-
-       add(new PrefCopiers(form_));
-
-
-       prefsPS->setCurrentPanel(_("User interface"));
-// FIXME: hack to work around resizing bug in Qt >= 4.2
-// bug verified with Qt 4.2.{0-3} (JSpitzm)
-#if QT_VERSION >= 0x040200
-       prefsPS->updateGeometry();
-#endif
-
-       form_->bcview().setOK(savePB);
-       form_->bcview().setApply(applyPB);
-       form_->bcview().setCancel(closePB);
-       form_->bcview().setRestore(restorePB);
-}
-
-
-void QPrefsDialog::add(PrefModule * module)
-{
-       BOOST_ASSERT(module);
-
-//     if (module->category().empty())
-//             prefsPS->addPanel(module, module->title());
-//     else
-               prefsPS->addPanel(module, module->title(), module->category());
-
-       connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
-
-       modules_.push_back(module);
-}
-
-void QPrefsDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QPrefsDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QPrefsDialog::apply(LyXRC & rc) const
-{
-       size_t end = modules_.size();
-       for (size_t i = 0; i != end; ++i)
-               modules_[i]->apply(rc);
-}
-
-
-void QPrefsDialog::updateRc(LyXRC const & rc)
-{
-       size_t const end = modules_.size();
-       for (size_t i = 0; i != end; ++i)
-               modules_[i]->update(rc);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QPrefs
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
-
-QPrefs::QPrefs(Dialog & parent)
-       : PrefsBase(parent, _("Preferences"))
-{
-}
-
-Converters & QPrefs::converters()
-{
-       return controller().converters();
-}
-
-Formats & QPrefs::formats()
-{
-       return controller().formats();
-}
-
-Movers & QPrefs::movers()
-{
-       return controller().movers();
-}
-
-void QPrefs::build_dialog()
-{
-       dialog_.reset(new QPrefsDialog(this));
-}
-
-void QPrefs::apply()
-{
-       dialog_->apply(controller().rc());
-}
-
-void QPrefs::update_contents()
-{
-       dialog_->updateRc(controller().rc());
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QPrefs_moc.cpp"
diff --git a/src/frontends/qt4/QPrefs.cpp b/src/frontends/qt4/QPrefs.cpp
new file mode 100644 (file)
index 0000000..b436782
--- /dev/null
@@ -0,0 +1,2044 @@
+/**
+ * \file QPrefs.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QPrefs.h"
+
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+#include "GuiApplication.h"
+
+#include "session.h"
+#include "debug.h"
+#include "LColor.h"
+#include "lyxfont.h"
+#include "PanelStack.h"
+#include "QFontExample.h"
+#include "gettext.h"
+
+#include "support/lstrings.h"
+#include "support/os.h"
+
+#include "controllers/ControlPrefs.h"
+#include "controllers/frontend_helpers.h"
+
+#include "frontends/Alert.h"
+#include "frontends/Application.h"
+
+#include <QCheckBox>
+#include <QColorDialog>
+#include <QFontDatabase>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QString>
+#include <QValidator>
+#include <QCloseEvent>
+
+#include <boost/tuple/tuple.hpp>
+#include <iomanip>
+#include <sstream>
+
+using namespace Ui;
+
+using lyx::support::compare_ascii_no_case;
+using lyx::support::os::external_path;
+using lyx::support::os::external_path_list;
+using lyx::support::os::internal_path;
+using lyx::support::os::internal_path_list;
+
+using std::endl;
+using std::string;
+using std::pair;
+using std::vector;
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// Helpers
+//
+/////////////////////////////////////////////////////////////////////
+
+string const LookAndFeel = N_("Look and feel");
+string const LanguageSettings = N_("Language settings");
+string const Outputs = N_("Outputs");
+
+
+// FIXME: move to frontend_helpers.h
+
+template<class A>
+static size_t findPos_helper(std::vector<A> const & vec, A const & val)
+{
+       typedef typename std::vector<A>::const_iterator Cit;
+
+       Cit it = std::find(vec.begin(), vec.end(), val);
+       if (it == vec.end())
+               return 0;
+       return std::distance(vec.begin(), it);
+}
+
+
+static void setComboxFont(QComboBox * cb, string const & family,
+       string const & foundry)
+{
+       string const name = makeFontName(family, foundry);
+       for (int i = 0; i < cb->count(); ++i) {
+               if (fromqstr(cb->itemText(i)) == name) {
+                       cb->setCurrentIndex(i);
+                       return;
+               }
+       }
+
+       // Try matching without foundry name
+
+       // We count in reverse in order to prefer the Xft foundry
+       for (int i = cb->count() - 1; i >= 0; --i) {
+               pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
+               if (compare_ascii_no_case(tmp.first, family) == 0) {
+                       cb->setCurrentIndex(i);
+                       return;
+               }
+       }
+
+       // family alone can contain e.g. "Helvetica [Adobe]"
+       pair<string, string> tmpfam = parseFontName(family);
+
+       // We count in reverse in order to prefer the Xft foundry
+       for (int i = cb->count() - 1; i >= 0; --i) {
+               pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
+               if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
+                       cb->setCurrentIndex(i);
+                       return;
+               }
+       }
+
+       // Bleh, default fonts, and the names couldn't be found. Hack
+       // for bug 1063.
+
+       QFont font;
+       font.setKerning(false);
+
+       if (family == theApp()->romanFontName()) {
+               font.setStyleHint(QFont::Serif);
+               font.setFamily(family.c_str());
+       } else if (family == theApp()->sansFontName()) {
+               font.setStyleHint(QFont::SansSerif);
+               font.setFamily(family.c_str());
+       } else if (family == theApp()->typewriterFontName()) {
+               font.setStyleHint(QFont::TypeWriter);
+               font.setFamily(family.c_str());
+       } else {
+               lyxerr << "FAILED to find the default font: '"
+                      << foundry << "', '" << family << '\''<< endl;
+               return;
+       }
+
+       QFontInfo info(font);
+       pair<string, string> tmp = parseFontName(fromqstr(info.family()));
+       string const & default_font_name = tmp.first;
+       lyxerr << "Apparent font is " << default_font_name << endl;
+
+       for (int i = 0; i < cb->count(); ++i) {
+               lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
+               if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
+                                   default_font_name) == 0) {
+                       cb->setCurrentIndex(i);
+                       return;
+               }
+       }
+
+       lyxerr << "FAILED to find the font: '"
+              << foundry << "', '" << family << '\'' <<endl;
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefPlaintext
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefPlaintext::PrefPlaintext(QWidget * parent)
+       : PrefModule(_(Outputs), _("Plain text"), 0, parent)
+{
+       setupUi(this);
+       connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
+       connect(plaintextRoffED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefPlaintext::apply(LyXRC & rc) const
+{
+       rc.plaintext_linelen = plaintextLinelengthSB->value();
+       rc.plaintext_roff_command = fromqstr(plaintextRoffED->text());
+}
+
+
+void PrefPlaintext::update(LyXRC const & rc)
+{
+       plaintextLinelengthSB->setValue(rc.plaintext_linelen);
+       plaintextRoffED->setText(toqstr(rc.plaintext_roff_command));
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefDate
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefDate::PrefDate(QWidget * parent)
+       : PrefModule(_(Outputs), _("Date format"), 0, parent)
+{
+       setupUi(this);
+       connect(DateED, SIGNAL(textChanged(const QString &)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefDate::apply(LyXRC & rc) const
+{
+       rc.date_insert_format = fromqstr(DateED->text());
+}
+
+
+void PrefDate::update(LyXRC const & rc)
+{
+       DateED->setText(toqstr(rc.date_insert_format));
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefKeyboard
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefKeyboard::PrefKeyboard(QPrefs * form, QWidget * parent)
+       : PrefModule(_(LookAndFeel), _("Keyboard"), form, parent)
+{
+       setupUi(this);
+
+       connect(keymapCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(firstKeymapED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(secondKeymapED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefKeyboard::apply(LyXRC & rc) const
+{
+       // FIXME: can derive CB from the two EDs
+       rc.use_kbmap = keymapCB->isChecked();
+       rc.primary_kbmap = internal_path(fromqstr(firstKeymapED->text()));
+       rc.secondary_kbmap = internal_path(fromqstr(secondKeymapED->text()));
+}
+
+
+void PrefKeyboard::update(LyXRC const & rc)
+{
+       // FIXME: can derive CB from the two EDs
+       keymapCB->setChecked(rc.use_kbmap);
+       firstKeymapED->setText(toqstr(external_path(rc.primary_kbmap)));
+       secondKeymapED->setText(toqstr(external_path(rc.secondary_kbmap)));
+}
+
+
+QString PrefKeyboard::testKeymap(QString keymap)
+{
+       return toqstr(form_->controller().browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
+}
+
+
+void PrefKeyboard::on_firstKeymapPB_clicked(bool)
+{
+       QString const file = testKeymap(firstKeymapED->text());
+       if (!file.isEmpty())
+               firstKeymapED->setText(file);
+}
+
+
+void PrefKeyboard::on_secondKeymapPB_clicked(bool)
+{
+       QString const file = testKeymap(secondKeymapED->text());
+       if (!file.isEmpty())
+               secondKeymapED->setText(file);
+}
+
+
+void PrefKeyboard::on_keymapCB_toggled(bool keymap)
+{
+       firstKeymapLA->setEnabled(keymap);
+       secondKeymapLA->setEnabled(keymap);
+       firstKeymapED->setEnabled(keymap);
+       secondKeymapED->setEnabled(keymap);
+       firstKeymapPB->setEnabled(keymap);
+       secondKeymapPB->setEnabled(keymap);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefLatex
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefLatex::PrefLatex(QPrefs * form, QWidget * parent)
+       : PrefModule(_(Outputs), _("LaTeX"), form, parent)
+{
+       setupUi(this);
+       connect(latexEncodingED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(latexChecktexED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(latexBibtexED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(latexIndexED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(latexAutoresetCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(latexDviPaperED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(latexPaperSizeCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefLatex::apply(LyXRC & rc) const
+{
+       rc.fontenc = fromqstr(latexEncodingED->text());
+       rc.chktex_command = fromqstr(latexChecktexED->text());
+       rc.bibtex_command = fromqstr(latexBibtexED->text());
+       rc.index_command = fromqstr(latexIndexED->text());
+       rc.auto_reset_options = latexAutoresetCB->isChecked();
+       rc.view_dvi_paper_option = fromqstr(latexDviPaperED->text());
+       rc.default_papersize =
+               form_->controller().toPaperSize(latexPaperSizeCO->currentIndex());
+}
+
+
+void PrefLatex::update(LyXRC const & rc)
+{
+       latexEncodingED->setText(toqstr(rc.fontenc));
+       latexChecktexED->setText(toqstr(rc.chktex_command));
+       latexBibtexED->setText(toqstr(rc.bibtex_command));
+       latexIndexED->setText(toqstr(rc.index_command));
+       latexAutoresetCB->setChecked(rc.auto_reset_options);
+       latexDviPaperED->setText(toqstr(rc.view_dvi_paper_option));
+       latexPaperSizeCO->setCurrentIndex(
+               form_->controller().fromPaperSize(rc.default_papersize));
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefScreenFonts
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefScreenFonts::PrefScreenFonts(QPrefs * form, QWidget * parent)
+       : PrefModule(_(LookAndFeel), _("Screen fonts"), form, parent)
+{
+       setupUi(this);
+
+       connect(screenRomanCO, SIGNAL(activated(const QString&)),
+               this, SLOT(select_roman(const QString&)));
+       connect(screenSansCO, SIGNAL(activated(const QString&)),
+               this, SLOT(select_sans(const QString&)));
+       connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
+               this, SLOT(select_typewriter(const QString&)));
+
+       QFontDatabase fontdb;
+       QStringList families(fontdb.families());
+       for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
+               screenRomanCO->addItem(*it);
+               screenSansCO->addItem(*it);
+               screenTypewriterCO->addItem(*it);
+       }
+       connect(screenRomanCO, SIGNAL(activated(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenSansCO, SIGNAL(activated(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenTypewriterCO, SIGNAL(activated(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenZoomSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
+       connect(screenDpiSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
+       connect(screenTinyED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenSmallestED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenSmallerED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenSmallED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenNormalED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenLargeED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenLargerED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenLargestED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenHugeED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(screenHugerED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+
+       screenTinyED->setValidator(new QDoubleValidator(
+               screenTinyED));
+       screenSmallestED->setValidator(new QDoubleValidator(
+               screenSmallestED));
+       screenSmallerED->setValidator(new QDoubleValidator(
+               screenSmallerED));
+       screenSmallED->setValidator(new QDoubleValidator(
+               screenSmallED));
+       screenNormalED->setValidator(new QDoubleValidator(
+               screenNormalED));
+       screenLargeED->setValidator(new QDoubleValidator(
+               screenLargeED));
+       screenLargerED->setValidator(new QDoubleValidator(
+               screenLargerED));
+       screenLargestED->setValidator(new QDoubleValidator(
+               screenLargestED));
+       screenHugeED->setValidator(new QDoubleValidator(
+               screenHugeED));
+       screenHugerED->setValidator(new QDoubleValidator(
+               screenHugerED));
+}
+
+
+void PrefScreenFonts::apply(LyXRC & rc) const
+{
+       LyXRC const oldrc(rc);
+
+       boost::tie(rc.roman_font_name, rc.roman_font_foundry)
+               = parseFontName(fromqstr(screenRomanCO->currentText()));
+       boost::tie(rc.sans_font_name, rc.sans_font_foundry) =
+               parseFontName(fromqstr(screenSansCO->currentText()));
+       boost::tie(rc.typewriter_font_name, rc.typewriter_font_foundry) =
+               parseFontName(fromqstr(screenTypewriterCO->currentText()));
+
+       rc.zoom = screenZoomSB->value();
+       rc.dpi = screenDpiSB->value();
+       rc.font_sizes[LyXFont::SIZE_TINY] = fromqstr(screenTinyED->text());
+       rc.font_sizes[LyXFont::SIZE_SCRIPT] = fromqstr(screenSmallestED->text());
+       rc.font_sizes[LyXFont::SIZE_FOOTNOTE] = fromqstr(screenSmallerED->text());
+       rc.font_sizes[LyXFont::SIZE_SMALL] = fromqstr(screenSmallED->text());
+       rc.font_sizes[LyXFont::SIZE_NORMAL] = fromqstr(screenNormalED->text());
+       rc.font_sizes[LyXFont::SIZE_LARGE] = fromqstr(screenLargeED->text());
+       rc.font_sizes[LyXFont::SIZE_LARGER] = fromqstr(screenLargerED->text());
+       rc.font_sizes[LyXFont::SIZE_LARGEST] = fromqstr(screenLargestED->text());
+       rc.font_sizes[LyXFont::SIZE_HUGE] = fromqstr(screenHugeED->text());
+       rc.font_sizes[LyXFont::SIZE_HUGER] = fromqstr(screenHugerED->text());
+
+       if (rc.font_sizes != oldrc.font_sizes
+               || rc.roman_font_name != oldrc.roman_font_name
+               || rc.sans_font_name != oldrc.sans_font_name
+               || rc.typewriter_font_name != oldrc.typewriter_font_name
+               || rc.zoom != oldrc.zoom || rc.dpi != oldrc.dpi) {
+               form_->controller().updateScreenFonts();
+       }
+}
+
+
+void PrefScreenFonts::update(LyXRC const & rc)
+{
+       setComboxFont(screenRomanCO, rc.roman_font_name,
+                       rc.roman_font_foundry);
+       setComboxFont(screenSansCO, rc.sans_font_name,
+                       rc.sans_font_foundry);
+       setComboxFont(screenTypewriterCO, rc.typewriter_font_name,
+                       rc.typewriter_font_foundry);
+
+       select_roman(screenRomanCO->currentText());
+       select_sans(screenSansCO->currentText());
+       select_typewriter(screenTypewriterCO->currentText());
+
+       screenZoomSB->setValue(rc.zoom);
+       screenDpiSB->setValue(rc.dpi);
+       screenTinyED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_TINY]));
+       screenSmallestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SCRIPT]));
+       screenSmallerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_FOOTNOTE]));
+       screenSmallED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_SMALL]));
+       screenNormalED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_NORMAL]));
+       screenLargeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGE]));
+       screenLargerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGER]));
+       screenLargestED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_LARGEST]));
+       screenHugeED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGE]));
+       screenHugerED->setText(toqstr(rc.font_sizes[LyXFont::SIZE_HUGER]));
+}
+
+void PrefScreenFonts::select_roman(const QString& name)
+{
+       screenRomanFE->set(QFont(name), name);
+}
+
+
+void PrefScreenFonts::select_sans(const QString& name)
+{
+       screenSansFE->set(QFont(name), name);
+}
+
+
+void PrefScreenFonts::select_typewriter(const QString& name)
+{
+       screenTypewriterFE->set(QFont(name), name);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefColors
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefColors::PrefColors(QPrefs * form, QWidget * parent)
+       : PrefModule(_(LookAndFeel), _("Colors"), form, parent)
+{
+       setupUi(this);
+
+       // FIXME: all of this initialization should be put into the controller.
+       // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg113301.html
+       // for some discussion of why that is not trivial.
+       for (int i = 0; i < LColor::ignore; ++i) {
+               LColor::color lc = static_cast<LColor::color>(i);
+               if (lc == LColor::none
+                       || lc == LColor::black
+                       || lc == LColor::white
+                       || lc == LColor::red
+                       || lc == LColor::green
+                       || lc == LColor::blue
+                       || lc == LColor::cyan
+                       || lc == LColor::magenta
+                       || lc == LColor::yellow
+                       || lc == LColor::inherit
+                       || lc == LColor::ignore) continue;
+
+               lcolors_.push_back(lc);
+               QColor color = QColor(guiApp->colorCache().get(lc));
+               curcolors_.push_back(color.name());
+               QPixmap coloritem(32, 32);
+               coloritem.fill(color);
+               // This is not a memory leak:
+               /*QListWidgetItem * newItem =*/ new QListWidgetItem(QIcon(coloritem),
+                       toqstr(lcolor.getGUIName(lc)), lyxObjectsLW);
+       }
+       newcolors_ = curcolors_;
+       // End initialization
+
+       connect(colorChangePB, SIGNAL(clicked()),
+               this, SLOT(change_color()));
+       connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
+               this, SLOT(change_color()));
+}
+
+
+void PrefColors::apply(LyXRC & /*rc*/) const
+{
+       for (unsigned int i = 0; i < lcolors_.size(); ++i) {
+               if (curcolors_[i]!=newcolors_[i])
+                       form_->controller().setColor(lcolors_[i], fromqstr(newcolors_[i]));
+       }
+       // HACK The following line is needed because the values are not 
+       // re-initialized in ControlPrefs::initialiseParams but are only 
+       // initialized in the constructor. But the constructor is only called 
+       // once, when the dialog if first created, and is not called again when 
+       // Tools > Preferences is selected a second time: It's just called up 
+       // from memory. [See QDialogView::show(): if (!form) { build(); }.]
+       curcolors_ = newcolors_;
+}
+
+
+// FIXME The fact that this method is empty is also a symptom of the
+// problem here.
+void PrefColors::update(LyXRC const & /*rc*/)
+{
+}
+
+void PrefColors::change_color()
+{
+       int const row = lyxObjectsLW->currentRow();
+       QString color = newcolors_[row];
+       QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget()));
+
+       if (c.name() != color) {
+               newcolors_[row] = c.name();
+               QPixmap coloritem(32, 32);
+               coloritem.fill(c);
+               lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
+               // emit signal
+               changed();
+       }
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefCygwinPath
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefCygwinPath::PrefCygwinPath(QWidget * parent)
+       : PrefModule(_(Outputs), _("Paths"), 0, parent)
+{
+       setupUi(this);
+       connect(pathCB, SIGNAL(clicked()), this, SIGNAL(changed()));
+}
+
+
+void PrefCygwinPath::apply(LyXRC & rc) const
+{
+       rc.windows_style_tex_paths = pathCB->isChecked();
+}
+
+
+void PrefCygwinPath::update(LyXRC const & rc)
+{
+       pathCB->setChecked(rc.windows_style_tex_paths);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefDisplay
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefDisplay::PrefDisplay(QWidget * parent)
+       : PrefModule(_(LookAndFeel), _("Graphics"), 0, parent)
+{
+       setupUi(this);
+       connect(instantPreviewCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
+       connect(displayGraphicsCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefDisplay::apply(LyXRC & rc) const
+{
+       switch (instantPreviewCO->currentIndex()) {
+       case 0: rc.preview = LyXRC::PREVIEW_OFF; break;
+       case 1: rc.preview = LyXRC::PREVIEW_NO_MATH; break;
+       case 2: rc.preview = LyXRC::PREVIEW_ON; break;
+       }
+
+       lyx::graphics::DisplayType dtype;
+       switch (displayGraphicsCO->currentIndex()) {
+       case 3: dtype = lyx::graphics::NoDisplay; break;
+       case 2: dtype = lyx::graphics::ColorDisplay; break;
+       case 1: dtype = lyx::graphics::GrayscaleDisplay;        break;
+       case 0: dtype = lyx::graphics::MonochromeDisplay; break;
+       default: dtype = lyx::graphics::GrayscaleDisplay;
+       }
+       rc.display_graphics = dtype;
+
+#ifdef WITH_WARNINGS
+#warning FIXME!! The graphics cache no longer has a changeDisplay method.
+#endif
+#if 0
+       if (old_value != rc.display_graphics) {
+               lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
+               gc.changeDisplay();
+       }
+#endif
+}
+
+
+void PrefDisplay::update(LyXRC const & rc)
+{
+       switch (rc.preview) {
+       case LyXRC::PREVIEW_OFF:
+               instantPreviewCO->setCurrentIndex(0);
+               break;
+       case LyXRC::PREVIEW_NO_MATH :
+               instantPreviewCO->setCurrentIndex(1);
+               break;
+       case LyXRC::PREVIEW_ON :
+               instantPreviewCO->setCurrentIndex(2);
+               break;
+       }
+
+       int item = 2;
+       switch (rc.display_graphics) {
+               case lyx::graphics::NoDisplay:          item = 3; break;
+               case lyx::graphics::ColorDisplay:       item = 2; break;
+               case lyx::graphics::GrayscaleDisplay:   item = 1; break;
+               case lyx::graphics::MonochromeDisplay:  item = 0; break;
+               default: break;
+       }
+       displayGraphicsCO->setCurrentIndex(item);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefPaths
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefPaths::PrefPaths(QPrefs * form, QWidget * parent)
+       : PrefModule(docstring(), _("Paths"), form, parent)
+{
+       setupUi(this);
+       connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir()));
+       connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir()));
+       connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir()));
+       connect(workingDirPB, SIGNAL(clicked()), this, SLOT(select_workingdir()));
+       connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe()));
+       connect(workingDirED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(templateDirED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(backupDirED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(tempDirED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(lyxserverDirED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(pathPrefixED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefPaths::apply(LyXRC & rc) const
+{
+       rc.document_path = internal_path(fromqstr(workingDirED->text()));
+       rc.template_path = internal_path(fromqstr(templateDirED->text()));
+       rc.backupdir_path = internal_path(fromqstr(backupDirED->text()));
+       rc.tempdir_path = internal_path(fromqstr(tempDirED->text()));
+       rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
+       // FIXME: should be a checkbox only
+       rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
+}
+
+
+void PrefPaths::update(LyXRC const & rc)
+{
+       workingDirED->setText(toqstr(external_path(rc.document_path)));
+       templateDirED->setText(toqstr(external_path(rc.template_path)));
+       backupDirED->setText(toqstr(external_path(rc.backupdir_path)));
+       tempDirED->setText(toqstr(external_path(rc.tempdir_path)));
+       pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
+       // FIXME: should be a checkbox only
+       lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
+}
+
+
+void PrefPaths::select_templatedir()
+{
+       docstring file(form_->controller().browsedir(
+               from_utf8(internal_path(fromqstr(templateDirED->text()))),
+               _("Select a document templates directory")));
+       if (!file.empty())
+               templateDirED->setText(toqstr(file));
+}
+
+
+void PrefPaths::select_tempdir()
+{
+       docstring file(form_->controller().browsedir(
+               from_utf8(internal_path(fromqstr(tempDirED->text()))),
+               _("Select a temporary directory")));
+       if (!file.empty())
+               tempDirED->setText(toqstr(file));
+}
+
+
+void PrefPaths::select_backupdir()
+{
+       docstring file(form_->controller().browsedir(
+               from_utf8(internal_path(fromqstr(backupDirED->text()))),
+               _("Select a backups directory")));
+       if (!file.empty())
+               backupDirED->setText(toqstr(file));
+}
+
+
+void PrefPaths::select_workingdir()
+{
+       docstring file(form_->controller().browsedir(
+               from_utf8(internal_path(fromqstr(workingDirED->text()))),
+               _("Select a document directory")));
+       if (!file.empty())
+               workingDirED->setText(toqstr(file));
+}
+
+
+void PrefPaths::select_lyxpipe()
+{
+       docstring file(form_->controller().browse(
+               from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
+               _("Give a filename for the LyX server pipe")));
+       if (!file.empty())
+               lyxserverDirED->setText(toqstr(file));
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefSpellchecker
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefSpellchecker::PrefSpellchecker(QPrefs * form, QWidget * parent)
+       : PrefModule(_(LanguageSettings), _("Spellchecker"), form, parent)
+{
+       setupUi(this);
+
+       connect(persDictionaryPB, SIGNAL(clicked()), this, SLOT(select_dict()));
+#if defined (USE_ISPELL)
+       connect(spellCommandCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
+#else
+       spellCommandCO->setEnabled(false);
+#endif
+       connect(altLanguageED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(escapeCharactersED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(persDictionaryED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(compoundWordCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(inputEncodingCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+
+       spellCommandCO->addItem(qt_("ispell"));
+       spellCommandCO->addItem(qt_("aspell"));
+       spellCommandCO->addItem(qt_("hspell"));
+#ifdef USE_PSPELL
+       spellCommandCO->addItem(qt_("pspell (library)"));
+#else
+#ifdef USE_ASPELL
+       spellCommandCO->addItem(qt_("aspell (library)"));
+#endif
+#endif
+}
+
+
+void PrefSpellchecker::apply(LyXRC & rc) const
+{
+       switch (spellCommandCO->currentIndex()) {
+               case 0:
+               case 1:
+               case 2:
+                       rc.use_spell_lib = false;
+                       rc.isp_command = fromqstr(spellCommandCO->currentText());
+                       break;
+               case 3:
+                       rc.use_spell_lib = true;
+                       break;
+       }
+
+       // FIXME: remove isp_use_alt_lang
+       rc.isp_alt_lang = fromqstr(altLanguageED->text());
+       rc.isp_use_alt_lang = !rc.isp_alt_lang.empty();
+       // FIXME: remove isp_use_esc_chars
+       rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
+       rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
+       // FIXME: remove isp_use_pers_dict
+       rc.isp_pers_dict = internal_path(fromqstr(persDictionaryED->text()));
+       rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
+       rc.isp_accept_compound = compoundWordCB->isChecked();
+       rc.isp_use_input_encoding = inputEncodingCB->isChecked();
+}
+
+
+void PrefSpellchecker::update(LyXRC const & rc)
+{
+       spellCommandCO->setCurrentIndex(0);
+
+       if (rc.isp_command == "ispell") {
+               spellCommandCO->setCurrentIndex(0);
+       } else if (rc.isp_command == "aspell") {
+               spellCommandCO->setCurrentIndex(1);
+       } else if (rc.isp_command == "hspell") {
+               spellCommandCO->setCurrentIndex(2);
+       }
+
+       if (rc.use_spell_lib) {
+#if defined(USE_ASPELL) || defined(USE_PSPELL)
+               spellCommandCO->setCurrentIndex(3);
+#endif
+       }
+
+       // FIXME: remove isp_use_alt_lang
+       altLanguageED->setText(toqstr(rc.isp_alt_lang));
+       // FIXME: remove isp_use_esc_chars
+       escapeCharactersED->setText(toqstr(rc.isp_esc_chars));
+       // FIXME: remove isp_use_pers_dict
+       persDictionaryED->setText(toqstr(external_path(rc.isp_pers_dict)));
+       compoundWordCB->setChecked(rc.isp_accept_compound);
+       inputEncodingCB->setChecked(rc.isp_use_input_encoding);
+}
+
+
+void PrefSpellchecker::select_dict()
+{
+       docstring file(form_->controller().browsedict(
+               from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
+       if (!file.empty())
+               persDictionaryED->setText(toqstr(file));
+}
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefConverters
+//
+/////////////////////////////////////////////////////////////////////
+
+
+PrefConverters::PrefConverters(QPrefs * form, QWidget * parent)
+       : PrefModule(docstring(), _("Converters"), form, parent)
+{
+       setupUi(this);
+
+       connect(converterNewPB, SIGNAL(clicked()),
+               this, SLOT(update_converter()));
+       connect(converterRemovePB, SIGNAL(clicked()),
+               this, SLOT(remove_converter()));
+       connect(converterModifyPB, SIGNAL(clicked()),
+               this, SLOT(update_converter()));
+       connect(convertersLW, SIGNAL(currentRowChanged(int)),
+               this, SLOT(switch_converter()));
+       connect(converterFromCO, SIGNAL(activated(const QString&)),
+               this, SLOT(converter_changed()));
+       connect(converterToCO, SIGNAL(activated(const QString&)),
+               this, SLOT(converter_changed()));
+       connect(converterED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(converter_changed()));
+       connect(converterFlagED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(converter_changed()));
+       connect(converterNewPB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(converterRemovePB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(converterModifyPB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(maxAgeLE, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+
+       maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
+       converterDefGB->setFocusProxy(convertersLW);
+}
+
+
+void PrefConverters::apply(LyXRC & rc) const
+{
+       rc.use_converter_cache = cacheCB->isChecked();
+       rc.converter_cache_maxage = int(maxAgeLE->text().toDouble() * 86400.0);
+}
+
+
+void PrefConverters::update(LyXRC const & rc)
+{
+       cacheCB->setChecked(rc.use_converter_cache);
+       QString max_age;
+       max_age.setNum(double(rc.converter_cache_maxage) / 86400.0, 'g', 6);
+       maxAgeLE->setText(max_age);
+       updateGui();
+}
+
+
+void PrefConverters::updateGui()
+{
+       // save current selection
+       QString current = converterFromCO->currentText()
+               + " -> " + converterToCO->currentText();
+
+       converterFromCO->clear();
+       converterToCO->clear();
+
+       Formats::const_iterator cit = form_->formats().begin();
+       Formats::const_iterator end = form_->formats().end();
+       for (; cit != end; ++cit) {
+               converterFromCO->addItem(toqstr(cit->prettyname()));
+               converterToCO->addItem(toqstr(cit->prettyname()));
+       }
+
+       // currentRowChanged(int) is also triggered when updating the listwidget
+       // block signals to avoid unnecessary calls to switch_converter()
+       convertersLW->blockSignals(true);
+       convertersLW->clear();
+
+       Converters::const_iterator ccit = form_->converters().begin();
+       Converters::const_iterator cend = form_->converters().end();
+       for (; ccit != cend; ++ccit) {
+               std::string const name =
+                       ccit->From->prettyname() + " -> " + ccit->To->prettyname();
+               int type = form_->converters().getNumber(ccit->From->name(), ccit->To->name());
+               new QListWidgetItem(toqstr(name), convertersLW, type);
+       }
+       convertersLW->sortItems(Qt::AscendingOrder);
+       convertersLW->blockSignals(false);
+
+       // restore selection
+       if (!current.isEmpty()) {
+               QList<QListWidgetItem *> const item =
+                       convertersLW->findItems(current, Qt::MatchExactly);
+               if (item.size()>0)
+                       convertersLW->setCurrentItem(item.at(0));
+       }
+
+       // select first element if restoring failed
+       if (convertersLW->currentRow() == -1)
+               convertersLW->setCurrentRow(0);
+
+       updateButtons();
+}
+
+
+void PrefConverters::switch_converter()
+{
+       int const cnr = convertersLW->currentItem()->type();
+       Converter const & c(form_->converters().get(cnr));
+       converterFromCO->setCurrentIndex(form_->formats().getNumber(c.from));
+       converterToCO->setCurrentIndex(form_->formats().getNumber(c.to));
+       converterED->setText(toqstr(c.command));
+       converterFlagED->setText(toqstr(c.flags));
+
+       updateButtons();
+}
+
+
+void PrefConverters::converter_changed()
+{
+       updateButtons();
+}
+
+
+void PrefConverters::updateButtons()
+{
+       Format const & from(form_->formats().get(converterFromCO->currentIndex()));
+       Format const & to(form_->formats().get(converterToCO->currentIndex()));
+       int const sel = form_->converters().getNumber(from.name(), to.name());
+       bool const known = !(sel < 0);
+       bool const valid = !(converterED->text().isEmpty()
+               || from.name() == to.name());
+
+       int const cnr = convertersLW->currentItem()->type();
+       Converter const & c(form_->converters().get(cnr));
+       string const old_command = c.command;
+       string const old_flag = c.flags;
+       string const new_command(fromqstr(converterED->text()));
+       string const new_flag(fromqstr(converterFlagED->text()));
+
+       bool modified = ((old_command != new_command) || (old_flag != new_flag));
+
+       converterModifyPB->setEnabled(valid && known && modified);
+       converterNewPB->setEnabled(valid && !known);
+       converterRemovePB->setEnabled(known);
+
+       maxAgeLE->setEnabled(cacheCB->isChecked());
+       maxAgeLA->setEnabled(cacheCB->isChecked());
+}
+
+
+// FIXME: user must
+// specify unique from/to or it doesn't appear. This is really bad UI
+// this is why we can use the same function for both new and modify
+void PrefConverters::update_converter()
+{
+       Format const & from(form_->formats().get(converterFromCO->currentIndex()));
+       Format const & to(form_->formats().get(converterToCO->currentIndex()));
+       string const flags = fromqstr(converterFlagED->text());
+       string const command = fromqstr(converterED->text());
+
+       Converter const * old = form_->converters().getConverter(from.name(), to.name());
+       form_->converters().add(from.name(), to.name(), command, flags);
+       if (!old) {
+               form_->converters().updateLast(form_->formats());
+       }
+
+       updateGui();
+}
+
+
+void PrefConverters::remove_converter()
+{
+       Format const & from(form_->formats().get(converterFromCO->currentIndex()));
+       Format const & to(form_->formats().get(converterToCO->currentIndex()));
+       form_->converters().erase(from.name(), to.name());
+
+       updateGui();
+}
+
+
+void PrefConverters::on_cacheCB_stateChanged(int state)
+{
+       maxAgeLE->setEnabled(state == Qt::Checked);
+       maxAgeLA->setEnabled(state == Qt::Checked);
+       changed();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefCopiers
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefCopiers::PrefCopiers(QPrefs * form, QWidget * parent)
+       : PrefModule(docstring(), _("Copiers"), form, parent)
+{
+       setupUi(this);
+
+       connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
+       connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
+       connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
+       connect(AllCopiersLW, SIGNAL(currentRowChanged(int)),
+               this, SLOT(switch_copierLB(int)));
+       connect(copierFormatCO, SIGNAL(activated(int)),
+               this, SLOT(switch_copierCO(int)));
+       connect(copierNewPB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(copierRemovePB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(copierModifyPB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(copierFormatCO, SIGNAL(activated(const QString &)),
+               this, SLOT(copiers_changed()));
+       connect(copierED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(copiers_changed()));
+}
+
+
+void PrefCopiers::apply(LyXRC & /*rc*/) const
+{
+}
+
+
+void PrefCopiers::update(LyXRC const & /*rc*/)
+{
+       update();
+}
+
+
+void PrefCopiers::update()
+{
+       // The choice widget
+       // save current selection
+       QString current = copierFormatCO->currentText();
+       copierFormatCO->clear();
+
+       for (Formats::const_iterator it = form_->formats().begin(),
+                    end = form_->formats().end();
+            it != end; ++it) {
+               copierFormatCO->addItem(toqstr(it->prettyname()));
+       }
+
+       // The browser widget
+       AllCopiersLW->clear();
+
+       for (Movers::const_iterator it = form_->movers().begin(),
+                    end = form_->movers().end();
+            it != end; ++it) {
+               std::string const & command = it->second.command();
+               if (command.empty())
+                       continue;
+               QString const pretty = toqstr(form_->formats().prettyName(it->first));
+               AllCopiersLW->addItem(pretty);
+       }
+       AllCopiersLW->sortItems(Qt::AscendingOrder);
+
+       // restore selection
+       if (!current.isEmpty()) {
+               QList<QListWidgetItem *> item =
+                       AllCopiersLW->findItems(current, Qt::MatchExactly);
+               if (item.size()>0)
+                       AllCopiersLW->setCurrentItem(item.at(0));
+       }
+       // select first element if restoring failed
+       if (AllCopiersLW->currentRow() == -1)
+               AllCopiersLW->setCurrentRow(0);
+}
+
+
+namespace {
+
+class SamePrettyName {
+public:
+       SamePrettyName(string const & n) : pretty_name_(n) {}
+
+       bool operator()(Format const & fmt) const {
+               return fmt.prettyname() == pretty_name_;
+       }
+
+private:
+       string const pretty_name_;
+};
+
+
+Format const * getFormat(std::string const & prettyname)
+{
+       Formats::const_iterator it = formats.begin();
+       Formats::const_iterator const end = formats.end();
+       it = std::find_if(it, end, SamePrettyName(prettyname));
+       return it == end ? 0 : &*it;
+}
+
+} // namespace anon
+
+
+void PrefCopiers::switch_copierLB(int row)
+{
+       if (row < 0)
+               return;
+
+       // FIXME UNICODE?
+       std::string const browser_text =
+               fromqstr(AllCopiersLW->currentItem()->text());
+       Format const * fmt = getFormat(browser_text);
+       if (fmt == 0)
+               return;
+
+       QString const gui_name = toqstr(fmt->prettyname());
+       QString const command = toqstr(form_->movers().command(fmt->name()));
+
+       copierED->clear();
+       int const combo_size = copierFormatCO->count();
+       for (int i = 0; i < combo_size; ++i) {
+               QString const text = copierFormatCO->itemText(i);
+               if (text == gui_name) {
+                       copierFormatCO->setCurrentIndex(i);
+                       copierED->setText(command);
+                       break;
+               }
+       }
+       updateButtons();
+}
+
+
+void PrefCopiers::switch_copierCO(int row)
+{
+       if (row<0)
+               return;
+
+       std::string const combo_text =
+               fromqstr(copierFormatCO->currentText());
+       Format const * fmt = getFormat(combo_text);
+       if (fmt == 0)
+               return;
+
+       QString const command = toqstr(form_->movers().command(fmt->name()));
+       copierED->setText(command);
+
+       QListWidgetItem * const index = AllCopiersLW->currentItem();
+       if (index >= 0)
+               AllCopiersLW->setItemSelected(index, false);
+
+       QString const gui_name = toqstr(fmt->prettyname());
+       int const browser_size = AllCopiersLW->count();
+       for (int i = 0; i < browser_size; ++i) {
+               QString const text = AllCopiersLW->item(i)->text();
+               if (text == gui_name) {
+                       QListWidgetItem * item = AllCopiersLW->item(i);
+                       AllCopiersLW->setItemSelected(item, true);
+                       break;
+               }
+       }
+}
+
+
+void PrefCopiers::copiers_changed()
+{
+       updateButtons();
+}
+
+
+void PrefCopiers::updateButtons()
+{
+       QString selected = copierFormatCO->currentText();
+
+       bool known = false;
+       for (int i = 0; i < AllCopiersLW->count(); ++i) {
+               if (AllCopiersLW->item(i)->text() == selected)
+                       known = true;
+       }
+
+       bool const valid = !copierED->text().isEmpty();
+
+       Format const * fmt = getFormat(fromqstr(selected));
+       string const old_command = form_->movers().command(fmt->name());
+       string const new_command(fromqstr(copierED->text()));
+
+       bool modified = (old_command != new_command);
+
+       copierModifyPB->setEnabled(valid && known && modified);
+       copierNewPB->setEnabled(valid && !known);
+       copierRemovePB->setEnabled(known);
+}
+
+
+void PrefCopiers::new_copier()
+{
+       std::string const combo_text =
+               fromqstr(copierFormatCO->currentText());
+       Format const * fmt = getFormat(combo_text);
+       if (fmt == 0)
+               return;
+
+       string const command = fromqstr(copierED->text());
+       if (command.empty())
+               return;
+
+       form_->movers().set(fmt->name(), command);
+
+       update();
+       int const last = AllCopiersLW->count() - 1;
+       AllCopiersLW->setCurrentRow(last);
+
+       updateButtons();
+}
+
+
+void PrefCopiers::modify_copier()
+{
+       std::string const combo_text =
+               fromqstr(copierFormatCO->currentText());
+       Format const * fmt = getFormat(combo_text);
+       if (fmt == 0)
+               return;
+
+       string const command = fromqstr(copierED->text());
+       form_->movers().set(fmt->name(), command);
+
+       update();
+       updateButtons();
+}
+
+
+void PrefCopiers::remove_copier()
+{
+       std::string const combo_text =
+               fromqstr(copierFormatCO->currentText());
+       Format const * fmt = getFormat(combo_text);
+       if (fmt == 0)
+               return;
+
+       string const & fmt_name = fmt->name();
+       form_->movers().set(fmt_name, string());
+
+       update();
+       updateButtons();
+}
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefFileformats
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefFileformats::PrefFileformats(QPrefs * form, QWidget * parent)
+       : PrefModule(docstring(), _("File formats"), form, parent)
+{
+       setupUi(this);
+
+       connect(formatNewPB, SIGNAL(clicked()),
+               this, SLOT(new_format()));
+       connect(formatRemovePB, SIGNAL(clicked()),
+               this, SLOT(remove_format()));
+       connect(formatModifyPB, SIGNAL(clicked()),
+               this, SLOT(modify_format()));
+       connect(formatsLW, SIGNAL(currentRowChanged(int)),
+               this, SLOT(switch_format(int)));
+       connect(formatED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(fileformat_changed()));
+       connect(guiNameED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(fileformat_changed()));
+       connect(shortcutED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(fileformat_changed()));
+       connect(extensionED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(fileformat_changed()));
+       connect(viewerED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(fileformat_changed()));
+       connect(editorED, SIGNAL(textChanged(const QString&)),
+               this, SLOT(fileformat_changed()));
+       connect(documentCB, SIGNAL(clicked()),
+               this, SLOT(fileformat_changed()));
+       connect(vectorCB, SIGNAL(clicked()),
+               this, SLOT(fileformat_changed()));
+       connect(formatNewPB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(formatRemovePB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(formatModifyPB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefFileformats::apply(LyXRC & /*rc*/) const
+{
+}
+
+
+void PrefFileformats::update(LyXRC const & /*rc*/)
+{
+       update();
+}
+
+
+void PrefFileformats::update()
+{
+       // save current selection
+       QString current = guiNameED->text();
+
+       // update listwidget with formats
+       formatsLW->blockSignals(true);
+       formatsLW->clear();
+       Formats::const_iterator cit = form_->formats().begin();
+       Formats::const_iterator end = form_->formats().end();
+       for (; cit != end; ++cit) {
+               new QListWidgetItem(toqstr(cit->prettyname()),
+                                                       formatsLW,
+                                                       form_->formats().getNumber(cit->name()) );
+       }
+       formatsLW->sortItems(Qt::AscendingOrder);
+       formatsLW->blockSignals(false);
+
+       // restore selection
+       if (!current.isEmpty()) {
+               QList<QListWidgetItem *>  item = formatsLW->findItems(current, Qt::MatchExactly);
+               if (item.size()>0)
+                       formatsLW->setCurrentItem(item.at(0));
+       }
+       // select first element if restoring failed
+       if (formatsLW->currentRow() == -1)
+               formatsLW->setCurrentRow(0);
+}
+
+
+void PrefFileformats::switch_format(int nr)
+{
+       int const ftype = formatsLW->item(nr)->type();
+       Format const f = form_->formats().get(ftype);
+
+       formatED->setText(toqstr(f.name()));
+       guiNameED->setText(toqstr(f.prettyname()));
+       extensionED->setText(toqstr(f.extension()));
+       shortcutED->setText(toqstr(f.shortcut()));
+       viewerED->setText(toqstr(f.viewer()));
+       editorED->setText(toqstr(f.editor()));
+       documentCB->setChecked((f.documentFormat()));
+       vectorCB->setChecked((f.vectorFormat()));
+
+       updateButtons();
+}
+
+
+void PrefFileformats::fileformat_changed()
+{
+       updateButtons();
+}
+
+
+void PrefFileformats::updateButtons()
+{
+       QString const format = formatED->text();
+       QString const gui_name = guiNameED->text();
+       int const sel = form_->formats().getNumber(fromqstr(format));
+       bool gui_name_known = false;
+       int where = sel;
+       for (int i = 0; i < formatsLW->count(); ++i) {
+               if (formatsLW->item(i)->text() == gui_name) {
+                       gui_name_known = true;
+                       where = formatsLW->item(i)->type();
+               }
+       }
+
+       // assure that a gui name cannot be chosen twice
+       bool const known_otherwise = gui_name_known && (where != sel);
+
+       bool const known = !(sel < 0);
+       bool const valid = (!formatED->text().isEmpty()
+               && !guiNameED->text().isEmpty());
+
+       int const ftype = formatsLW->currentItem()->type();
+       Format const & f(form_->formats().get(ftype));
+       string const old_pretty(f.prettyname());
+       string const old_shortcut(f.shortcut());
+       string const old_extension(f.extension());
+       string const old_viewer(f.viewer());
+       string const old_editor(f.editor());
+       bool const old_document(f.documentFormat());
+       bool const old_vector(f.vectorFormat());
+
+       string const new_pretty(fromqstr(gui_name));
+       string const new_shortcut(fromqstr(shortcutED->text()));
+       string const new_extension(fromqstr(extensionED->text()));
+       string const new_viewer(fromqstr(viewerED->text()));
+       string const new_editor(fromqstr(editorED->text()));
+       bool const new_document(documentCB->isChecked());
+       bool const new_vector(vectorCB->isChecked());
+
+       bool modified = ((old_pretty != new_pretty) || (old_shortcut != new_shortcut)
+               || (old_extension != new_extension) || (old_viewer != new_viewer)
+               || old_editor != new_editor || old_document != new_document
+               || old_vector != new_vector);
+
+       formatModifyPB->setEnabled(valid && known && modified && !known_otherwise);
+       formatNewPB->setEnabled(valid && !known && !gui_name_known);
+       formatRemovePB->setEnabled(known);
+}
+
+
+void PrefFileformats::new_format()
+{
+       string const name = fromqstr(formatED->text());
+       string const prettyname = fromqstr(guiNameED->text());
+       string const extension = fromqstr(extensionED->text());
+       string const shortcut = fromqstr(shortcutED->text());
+       string const viewer = fromqstr(viewerED->text());
+       string const editor = fromqstr(editorED->text());
+       int flags = Format::none;
+       if (documentCB->isChecked())
+               flags |= Format::document;
+       if (vectorCB->isChecked())
+               flags |= Format::vector;
+
+       form_->formats().add(name, extension, prettyname, shortcut, viewer,
+                            editor, flags);
+       form_->formats().sort();
+       form_->converters().update(form_->formats());
+
+       update();
+       updateButtons();
+       formatsChanged();
+}
+
+
+void PrefFileformats::modify_format()
+{
+       int const current_item = formatsLW->currentItem()->type();
+       Format const & oldformat = form_->formats().get(current_item);
+       form_->formats().erase(oldformat.name());
+
+       new_format();
+}
+
+
+void PrefFileformats::remove_format()
+{
+       int const nr = formatsLW->currentItem()->type();
+       string const current_text = form_->formats().get(nr).name();
+       if (form_->converters().formatIsUsed(current_text)) {
+               Alert::error(_("Format in use"),
+                            _("Cannot remove a Format used by a Converter. "
+                                           "Remove the converter first."));
+               return;
+       }
+
+       form_->formats().erase(current_text);
+       form_->converters().update(form_->formats());
+
+       update();
+       updateButtons();
+       formatsChanged();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefLanguage
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefLanguage::PrefLanguage(QWidget * parent)
+       : PrefModule(_(LanguageSettings), _("Language"), 0, parent)
+{
+       setupUi(this);
+
+       connect(rtlCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(markForeignCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(autoBeginCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(autoEndCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(useBabelCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(globalCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(languagePackageED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(startCommandED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(endCommandED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(defaultLanguageCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
+
+       defaultLanguageCO->clear();
+
+       // store the lang identifiers for later
+       std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
+       lang_ = getSecond(langs);
+
+       std::vector<LanguagePair>::const_iterator lit  = langs.begin();
+       std::vector<LanguagePair>::const_iterator lend = langs.end();
+       for (; lit != lend; ++lit) {
+               defaultLanguageCO->addItem(toqstr(lit->first));
+       }
+}
+
+
+void PrefLanguage::apply(LyXRC & rc) const
+{
+       // FIXME: remove rtl_support bool
+       rc.rtl_support = rtlCB->isChecked();
+       rc.mark_foreign_language = markForeignCB->isChecked();
+       rc.language_auto_begin = autoBeginCB->isChecked();
+       rc.language_auto_end = autoEndCB->isChecked();
+       rc.language_use_babel = useBabelCB->isChecked();
+       rc.language_global_options = globalCB->isChecked();
+       rc.language_package = fromqstr(languagePackageED->text());
+       rc.language_command_begin = fromqstr(startCommandED->text());
+       rc.language_command_end = fromqstr(endCommandED->text());
+       rc.default_language = lang_[defaultLanguageCO->currentIndex()];
+}
+
+
+void PrefLanguage::update(LyXRC const & rc)
+{
+       // FIXME: remove rtl_support bool
+       rtlCB->setChecked(rc.rtl_support);
+       markForeignCB->setChecked(rc.mark_foreign_language);
+       autoBeginCB->setChecked(rc.language_auto_begin);
+       autoEndCB->setChecked(rc.language_auto_end);
+       useBabelCB->setChecked(rc.language_use_babel);
+       globalCB->setChecked(rc.language_global_options);
+       languagePackageED->setText(toqstr(rc.language_package));
+       startCommandED->setText(toqstr(rc.language_command_begin));
+       endCommandED->setText(toqstr(rc.language_command_end));
+
+       int const pos = int(findPos_helper(lang_, rc.default_language));
+       defaultLanguageCO->setCurrentIndex(pos);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefPrinter
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefPrinter::PrefPrinter(QWidget * parent)
+       : PrefModule(_(Outputs), _("Printer"), 0, parent)
+{
+       setupUi(this);
+
+       connect(printerAdaptCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(printerCommandED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerNameED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerPageRangeED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerCopiesED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerReverseED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerToPrinterED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerExtensionED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerSpoolCommandED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerPaperTypeED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerEvenED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerOddED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerCollatedED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerLandscapeED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerToFileED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerExtraED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerSpoolPrefixED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(printerPaperSizeED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefPrinter::apply(LyXRC & rc) const
+{
+       rc.print_adapt_output = printerAdaptCB->isChecked();
+       rc.print_command = fromqstr(printerCommandED->text());
+       rc.printer = fromqstr(printerNameED->text());
+
+       rc.print_pagerange_flag = fromqstr(printerPageRangeED->text());
+       rc.print_copies_flag = fromqstr(printerCopiesED->text());
+       rc.print_reverse_flag = fromqstr(printerReverseED->text());
+       rc.print_to_printer = fromqstr(printerToPrinterED->text());
+       rc.print_file_extension = fromqstr(printerExtensionED->text());
+       rc.print_spool_command = fromqstr(printerSpoolCommandED->text());
+       rc.print_paper_flag = fromqstr(printerPaperTypeED->text());
+       rc.print_evenpage_flag = fromqstr(printerEvenED->text());
+       rc.print_oddpage_flag = fromqstr(printerOddED->text());
+       rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
+       rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
+       rc.print_to_file = internal_path(fromqstr(printerToFileED->text()));
+       rc.print_extra_options = fromqstr(printerExtraED->text());
+       rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
+       rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
+}
+
+
+void PrefPrinter::update(LyXRC const & rc)
+{
+       printerAdaptCB->setChecked(rc.print_adapt_output);
+       printerCommandED->setText(toqstr(rc.print_command));
+       printerNameED->setText(toqstr(rc.printer));
+
+       printerPageRangeED->setText(toqstr(rc.print_pagerange_flag));
+       printerCopiesED->setText(toqstr(rc.print_copies_flag));
+       printerReverseED->setText(toqstr(rc.print_reverse_flag));
+       printerToPrinterED->setText(toqstr(rc.print_to_printer));
+       printerExtensionED->setText(toqstr(rc.print_file_extension));
+       printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
+       printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
+       printerEvenED->setText(toqstr(rc.print_evenpage_flag));
+       printerOddED->setText(toqstr(rc.print_oddpage_flag));
+       printerCollatedED->setText(toqstr(rc.print_collcopies_flag));
+       printerLandscapeED->setText(toqstr(rc.print_landscape_flag));
+       printerToFileED->setText(toqstr(external_path(rc.print_to_file)));
+       printerExtraED->setText(toqstr(rc.print_extra_options));
+       printerSpoolPrefixED->setText(toqstr(rc.print_spool_printerprefix));
+       printerPaperSizeED->setText(toqstr(rc.print_paper_dimension_flag));
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefUserInterface
+//
+/////////////////////////////////////////////////////////////////////
+
+PrefUserInterface::PrefUserInterface(QPrefs * form, QWidget * parent)
+       : PrefModule(_(LookAndFeel), _("User interface"), form, parent)
+{
+       setupUi(this);
+
+       connect(autoSaveCB, SIGNAL(toggled(bool)),
+               autoSaveLA, SLOT(setEnabled(bool)));
+       connect(autoSaveCB, SIGNAL(toggled(bool)),
+               autoSaveSB, SLOT(setEnabled(bool)));
+       connect(autoSaveCB, SIGNAL(toggled(bool)),
+               TextLabel1, SLOT(setEnabled(bool)));
+       connect(uiFilePB, SIGNAL(clicked()),
+               this, SLOT(select_ui()));
+       connect(bindFilePB, SIGNAL(clicked()),
+               this, SLOT(select_bind()));
+       connect(uiFileED, SIGNAL(textChanged(const QString &)),
+               this, SIGNAL(changed()));
+       connect(bindFileED, SIGNAL(textChanged(const QString &)),
+               this, SIGNAL(changed()));
+       connect(restoreCursorCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(loadSessionCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(loadWindowSizeCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(loadWindowLocationCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(windowWidthSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
+       connect(windowHeightSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
+       connect(cursorFollowsCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(autoSaveSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
+       connect(autoSaveCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
+       connect(lastfilesSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
+       lastfilesSB->setMaximum(maxlastfiles);
+}
+
+
+void PrefUserInterface::apply(LyXRC & rc) const
+{
+       rc.ui_file = internal_path(fromqstr(uiFileED->text()));
+       rc.bind_file = internal_path(fromqstr(bindFileED->text()));
+       rc.use_lastfilepos = restoreCursorCB->isChecked();
+       rc.load_session = loadSessionCB->isChecked();
+       if (loadWindowSizeCB->isChecked()) {
+               rc.geometry_width = 0;
+               rc.geometry_height = 0;
+       } else {
+               rc.geometry_width = windowWidthSB->value();
+               rc.geometry_height = windowHeightSB->value();
+       }
+       rc.geometry_xysaved = loadWindowLocationCB->isChecked();
+       rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
+       rc.autosave = autoSaveSB->value() * 60;
+       rc.make_backup = autoSaveCB->isChecked();
+       rc.num_lastfiles = lastfilesSB->value();
+}
+
+
+void PrefUserInterface::update(LyXRC const & rc)
+{
+       uiFileED->setText(toqstr(external_path(rc.ui_file)));
+       bindFileED->setText(toqstr(external_path(rc.bind_file)));
+       restoreCursorCB->setChecked(rc.use_lastfilepos);
+       loadSessionCB->setChecked(rc.load_session);
+       bool loadWindowSize = rc.geometry_width == 0 && rc.geometry_height == 0;
+       loadWindowSizeCB->setChecked(loadWindowSize);
+       if (!loadWindowSize) {
+               windowWidthSB->setValue(rc.geometry_width);
+               windowHeightSB->setValue(rc.geometry_height);
+       }
+       loadWindowLocationCB->setChecked(rc.geometry_xysaved);
+       cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
+       // convert to minutes
+       int mins(rc.autosave / 60);
+       if (rc.autosave && !mins)
+               mins = 1;
+       autoSaveSB->setValue(mins);
+       autoSaveCB->setChecked(rc.make_backup);
+       lastfilesSB->setValue(rc.num_lastfiles);
+}
+
+
+
+void PrefUserInterface::select_ui()
+{
+       docstring const name =
+               from_utf8(internal_path(fromqstr(uiFileED->text())));
+       docstring file(form_->controller().browseUI(name));
+       if (!file.empty())
+               uiFileED->setText(toqstr(file));
+}
+
+
+void PrefUserInterface::select_bind()
+{
+       docstring const name =
+               from_utf8(internal_path(fromqstr(bindFileED->text())));
+       docstring file(form_->controller().browsebind(name));
+       if (!file.empty())
+               bindFileED->setText(toqstr(file));
+}
+
+
+void PrefUserInterface::on_loadWindowSizeCB_toggled(bool loadwindowsize)
+{
+       windowWidthLA->setDisabled(loadwindowsize);
+       windowHeightLA->setDisabled(loadwindowsize);
+       windowWidthSB->setDisabled(loadwindowsize);
+       windowHeightSB->setDisabled(loadwindowsize);
+}
+
+
+PrefIdentity::PrefIdentity(QWidget * parent)
+: PrefModule(docstring(), _("Identity"), 0, parent)
+{
+       setupUi(this);
+
+       connect(nameED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+       connect(emailED, SIGNAL(textChanged(const QString&)),
+               this, SIGNAL(changed()));
+}
+
+
+void PrefIdentity::apply(LyXRC & rc) const
+{
+       rc.user_name = fromqstr(nameED->text());
+       rc.user_email = fromqstr(emailED->text());
+}
+
+
+void PrefIdentity::update(LyXRC const & rc)
+{
+       nameED->setText(toqstr(rc.user_name));
+       emailED->setText(toqstr(rc.user_email));
+}
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QPrefsDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QPrefsDialog::QPrefsDialog(QPrefs * form)
+       : form_(form)
+{
+       setupUi(this);
+       QDialog::setModal(false);
+
+       connect(savePB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
+
+       add(new PrefUserInterface(form_));
+       add(new PrefScreenFonts(form_));
+       add(new PrefColors(form_));
+       add(new PrefDisplay);
+       add(new PrefKeyboard(form_));
+
+       add(new PrefPaths(form_));
+
+       add(new PrefIdentity);
+
+       add(new PrefLanguage);
+       add(new PrefSpellchecker(form_));
+
+       add(new PrefPrinter);
+       add(new PrefDate);
+       add(new PrefPlaintext);
+       add(new PrefLatex(form_));
+
+#if defined(__CYGWIN__) || defined(_WIN32)
+       add(new PrefCygwinPath);
+#endif
+
+
+       PrefConverters * converters = new PrefConverters(form_);
+       PrefFileformats * formats = new PrefFileformats(form_);
+       connect(formats, SIGNAL(formatsChanged()),
+                       converters, SLOT(updateGui()));
+       add(converters);
+       add(formats);
+
+       add(new PrefCopiers(form_));
+
+
+       prefsPS->setCurrentPanel(_("User interface"));
+// FIXME: hack to work around resizing bug in Qt >= 4.2
+// bug verified with Qt 4.2.{0-3} (JSpitzm)
+#if QT_VERSION >= 0x040200
+       prefsPS->updateGeometry();
+#endif
+
+       form_->bcview().setOK(savePB);
+       form_->bcview().setApply(applyPB);
+       form_->bcview().setCancel(closePB);
+       form_->bcview().setRestore(restorePB);
+}
+
+
+void QPrefsDialog::add(PrefModule * module)
+{
+       BOOST_ASSERT(module);
+
+//     if (module->category().empty())
+//             prefsPS->addPanel(module, module->title());
+//     else
+               prefsPS->addPanel(module, module->title(), module->category());
+
+       connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
+
+       modules_.push_back(module);
+}
+
+void QPrefsDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QPrefsDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QPrefsDialog::apply(LyXRC & rc) const
+{
+       size_t end = modules_.size();
+       for (size_t i = 0; i != end; ++i)
+               modules_[i]->apply(rc);
+}
+
+
+void QPrefsDialog::updateRc(LyXRC const & rc)
+{
+       size_t const end = modules_.size();
+       for (size_t i = 0; i != end; ++i)
+               modules_[i]->update(rc);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QPrefs
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlPrefs, QView<QPrefsDialog> > PrefsBase;
+
+QPrefs::QPrefs(Dialog & parent)
+       : PrefsBase(parent, _("Preferences"))
+{
+}
+
+Converters & QPrefs::converters()
+{
+       return controller().converters();
+}
+
+Formats & QPrefs::formats()
+{
+       return controller().formats();
+}
+
+Movers & QPrefs::movers()
+{
+       return controller().movers();
+}
+
+void QPrefs::build_dialog()
+{
+       dialog_.reset(new QPrefsDialog(this));
+}
+
+void QPrefs::apply()
+{
+       dialog_->apply(controller().rc());
+}
+
+void QPrefs::update_contents()
+{
+       dialog_->updateRc(controller().rc());
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QPrefs_moc.cpp"
diff --git a/src/frontends/qt4/QPrint.C b/src/frontends/qt4/QPrint.C
deleted file mode 100644 (file)
index 47350a9..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * \file QPrint.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QPrint.h"
-#include "QLPrintDialog.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "PrinterParams.h"
-
-#include "controllers/ControlPrint.h"
-
-#include <qlineedit.h>
-#include <qcheckbox.h>
-#include <qradiobutton.h>
-#include <qspinbox.h>
-#include <qpushbutton.h>
-
-namespace lyx {
-namespace frontend {
-
-typedef QController<ControlPrint, QView<QLPrintDialog> > print_base_class;
-
-
-QPrint::QPrint(Dialog & parent)
-       : print_base_class(parent, _("Print Document"))
-{
-}
-
-
-void QPrint::build_dialog()
-{
-       dialog_.reset(new QLPrintDialog(this));
-
-       bcview().setOK(dialog_->printPB);
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QPrint::update_contents()
-{
-       PrinterParams & pp = controller().params();
-
-       // only reset params if a different buffer
-       if (!pp.file_name.empty() && pp.file_name == fromqstr(dialog_->fileED->text()))
-               return;
-
-       dialog_->printerED->setText(toqstr(pp.printer_name));
-       dialog_->fileED->setText(toqstr(pp.file_name));
-
-       dialog_->printerRB->setChecked(true);
-       if (pp.target == PrinterParams::FILE)
-               dialog_->fileRB->setChecked(true);
-
-       dialog_->reverseCB->setChecked(pp.reverse_order);
-
-       dialog_->copiesSB->setValue(pp.count_copies);
-
-       dialog_->oddCB->setChecked(pp.odd_pages);
-       dialog_->evenCB->setChecked(pp.even_pages);
-
-       dialog_->collateCB->setChecked(pp.sorted_copies);
-
-       if (pp.all_pages) {
-               dialog_->allRB->setChecked(true);
-               return;
-       }
-
-       dialog_->rangeRB->setChecked(true);
-
-       QString s;
-       s.setNum(pp.from_page);
-       dialog_->fromED->setText(s);
-       s.setNum(pp.to_page);
-       dialog_->toED->setText(s);
-}
-
-
-void QPrint::apply()
-{
-       PrinterParams::Target t = PrinterParams::PRINTER;
-       if (dialog_->fileRB->isChecked())
-               t = PrinterParams::FILE;
-
-       PrinterParams const pp(t,
-               fromqstr(dialog_->printerED->text()),
-               fromqstr(dialog_->fileED->text()),
-               dialog_->allRB->isChecked(),
-               dialog_->fromED->text().toUInt(),
-               dialog_->toED->text().toUInt(),
-               dialog_->oddCB->isChecked(),
-               dialog_->evenCB->isChecked(),
-               dialog_->copiesSB->text().toUInt(),
-               dialog_->collateCB->isChecked(),
-               dialog_->reverseCB->isChecked());
-
-       controller().params() = pp;
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/QPrint.cpp b/src/frontends/qt4/QPrint.cpp
new file mode 100644 (file)
index 0000000..47350a9
--- /dev/null
@@ -0,0 +1,111 @@
+/**
+ * \file QPrint.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QPrint.h"
+#include "QLPrintDialog.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "PrinterParams.h"
+
+#include "controllers/ControlPrint.h"
+
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qradiobutton.h>
+#include <qspinbox.h>
+#include <qpushbutton.h>
+
+namespace lyx {
+namespace frontend {
+
+typedef QController<ControlPrint, QView<QLPrintDialog> > print_base_class;
+
+
+QPrint::QPrint(Dialog & parent)
+       : print_base_class(parent, _("Print Document"))
+{
+}
+
+
+void QPrint::build_dialog()
+{
+       dialog_.reset(new QLPrintDialog(this));
+
+       bcview().setOK(dialog_->printPB);
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QPrint::update_contents()
+{
+       PrinterParams & pp = controller().params();
+
+       // only reset params if a different buffer
+       if (!pp.file_name.empty() && pp.file_name == fromqstr(dialog_->fileED->text()))
+               return;
+
+       dialog_->printerED->setText(toqstr(pp.printer_name));
+       dialog_->fileED->setText(toqstr(pp.file_name));
+
+       dialog_->printerRB->setChecked(true);
+       if (pp.target == PrinterParams::FILE)
+               dialog_->fileRB->setChecked(true);
+
+       dialog_->reverseCB->setChecked(pp.reverse_order);
+
+       dialog_->copiesSB->setValue(pp.count_copies);
+
+       dialog_->oddCB->setChecked(pp.odd_pages);
+       dialog_->evenCB->setChecked(pp.even_pages);
+
+       dialog_->collateCB->setChecked(pp.sorted_copies);
+
+       if (pp.all_pages) {
+               dialog_->allRB->setChecked(true);
+               return;
+       }
+
+       dialog_->rangeRB->setChecked(true);
+
+       QString s;
+       s.setNum(pp.from_page);
+       dialog_->fromED->setText(s);
+       s.setNum(pp.to_page);
+       dialog_->toED->setText(s);
+}
+
+
+void QPrint::apply()
+{
+       PrinterParams::Target t = PrinterParams::PRINTER;
+       if (dialog_->fileRB->isChecked())
+               t = PrinterParams::FILE;
+
+       PrinterParams const pp(t,
+               fromqstr(dialog_->printerED->text()),
+               fromqstr(dialog_->fileED->text()),
+               dialog_->allRB->isChecked(),
+               dialog_->fromED->text().toUInt(),
+               dialog_->toED->text().toUInt(),
+               dialog_->oddCB->isChecked(),
+               dialog_->evenCB->isChecked(),
+               dialog_->copiesSB->text().toUInt(),
+               dialog_->collateCB->isChecked(),
+               dialog_->reverseCB->isChecked());
+
+       controller().params() = pp;
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/QRef.C b/src/frontends/qt4/QRef.C
deleted file mode 100644 (file)
index c16e6ee..0000000
+++ /dev/null
@@ -1,387 +0,0 @@
-/**
- * \file QRef.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QRef.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ButtonController.h"
-#include "controllers/ControlRef.h"
-
-#include "insets/InsetRef.h"
-
-#include <QLineEdit>
-#include <QCheckBox>
-#include <QListWidget>
-#include <QListWidgetItem>
-#include <QPushButton>
-#include <QToolTip>
-#include <QCloseEvent>
-
-
-using std::vector;
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QRefDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QRefDialog::QRefDialog(QRef * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(reset_dialog()));
-
-       connect(typeCO, SIGNAL(activated(int)), 
-               this, SLOT(changed_adaptor()));
-       connect(referenceED, SIGNAL(textChanged(const QString &)), 
-               this, SLOT(changed_adaptor()));
-       connect(nameED, SIGNAL(textChanged(const QString &)), 
-               this, SLOT(changed_adaptor()));
-       connect(refsLW, SIGNAL(itemClicked(QListWidgetItem *)), 
-               this, SLOT(refHighlighted(QListWidgetItem *)));
-       connect(refsLW, SIGNAL(itemSelectionChanged()),
-               this, SLOT(selectionChanged()));
-       connect(refsLW, SIGNAL(itemActivated(QListWidgetItem *)), 
-               this, SLOT(refSelected(QListWidgetItem *)));
-       connect(sortCB, SIGNAL(clicked(bool)),
-               this, SLOT(sortToggled(bool)));
-       connect(gotoPB, SIGNAL(clicked()), 
-               this, SLOT(gotoClicked()));
-       connect(updatePB, SIGNAL(clicked()), 
-               this, SLOT(updateClicked()));
-       connect(bufferCO, SIGNAL(activated(int)), 
-               this, SLOT(updateClicked()));
-
-       setFocusProxy(refsLW);
-}
-
-void QRefDialog::show()
-{
-       QDialog::show();
-}
-
-
-void QRefDialog::changed_adaptor()
-{
-       form_->changed();
-}
-
-
-void QRefDialog::gotoClicked()
-{
-       form_->gotoRef();
-}
-
-void QRefDialog::selectionChanged()
-{
-       if (form_->readOnly())
-               return;
-       
-       QList<QListWidgetItem *> selections = refsLW->selectedItems();
-       if (selections.isEmpty())
-               return;
-       QListWidgetItem * sel = selections.first();
-       refHighlighted(sel);
-       return;
-}
-
-
-void QRefDialog::refHighlighted(QListWidgetItem * sel)
-{
-       if (form_->readOnly())
-               return;
-
-/*     int const cur_item = refsLW->currentRow();
-       bool const cur_item_selected = cur_item >= 0 ?
-               refsLB->isSelected(cur_item) : false;*/
-       bool const cur_item_selected = refsLW->isItemSelected(sel);
-
-       if (cur_item_selected)
-               referenceED->setText(sel->text());
-
-       if (form_->at_ref_)
-               form_->gotoRef();
-       gotoPB->setEnabled(true);
-       if (form_->typeAllowed())
-               typeCO->setEnabled(true);
-       if (form_->nameAllowed())
-               nameED->setEnabled(true);
-}
-
-
-void QRefDialog::refSelected(QListWidgetItem * sel)
-{
-       if (form_->readOnly())
-               return;
-
-/*     int const cur_item = refsLW->currentRow();
-       bool const cur_item_selected = cur_item >= 0 ?
-               refsLB->isSelected(cur_item) : false;*/
-       bool const cur_item_selected = refsLW->isItemSelected(sel);
-
-       if (cur_item_selected)
-               referenceED->setText(sel->text());
-       // <enter> or double click, inserts ref and closes dialog
-       form_->slotOK();
-}
-
-
-void QRefDialog::sortToggled(bool on)
-{
-       form_->sort_ = on;
-       form_->redoRefs();
-}
-
-
-void QRefDialog::updateClicked()
-{
-       form_->updateRefs();
-}
-
-
-void QRefDialog::reset_dialog() {
-       form_->at_ref_ = false;
-       form_->setGotoRef();
-}
-
-
-void QRefDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       reset_dialog();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QRef
-//
-/////////////////////////////////////////////////////////////////////
-
-// full qualification because qt4 has also a ControlRef type
-typedef QController<lyx::frontend::ControlRef, QView<QRefDialog> > RefBase;
-
-
-QRef::QRef(Dialog & parent)
-       : RefBase(parent, _("Cross-reference")),
-       sort_(false), at_ref_(false)
-{
-}
-
-
-void QRef::build_dialog()
-{
-       dialog_.reset(new QRefDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->refsLW);
-       bcview().addReadOnly(dialog_->sortCB);
-       bcview().addReadOnly(dialog_->nameED);
-       bcview().addReadOnly(dialog_->referenceED);
-       bcview().addReadOnly(dialog_->typeCO);
-       bcview().addReadOnly(dialog_->bufferCO);
-
-       restored_buffer_ = -1;
-}
-
-
-void QRef::update_contents()
-{
-       InsetCommandParams const & params = controller().params();
-
-       int orig_type = dialog_->typeCO->currentIndex();
-
-       dialog_->referenceED->setText(toqstr(params["reference"]));
-
-       dialog_->nameED->setText(toqstr(params["name"]));
-       dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
-
-       // restore type settings for new insets
-       if (params["reference"].empty())
-               dialog_->typeCO->setCurrentIndex(orig_type);
-       else
-               dialog_->typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
-       dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
-       if (!typeAllowed())
-               dialog_->typeCO->setCurrentIndex(0);
-
-       dialog_->sortCB->setChecked(sort_);
-
-       // insert buffer list
-       dialog_->bufferCO->clear();
-       vector<string> const buffers = controller().getBufferList();
-       for (vector<string>::const_iterator it = buffers.begin();
-               it != buffers.end(); ++it) {
-               dialog_->bufferCO->addItem(toqstr(*it));
-       }
-       // restore the buffer combo setting for new insets
-       if (params["reference"].empty() && restored_buffer_ != -1
-       && restored_buffer_ < dialog_->bufferCO->count())
-               dialog_->bufferCO->setCurrentIndex(restored_buffer_);
-       else
-               dialog_->bufferCO->setCurrentIndex(controller().getBufferNum());
-
-       updateRefs();
-       bc().valid(false);
-}
-
-
-void QRef::apply()
-{
-       InsetCommandParams & params = controller().params();
-       
-       last_reference_ = dialog_->referenceED->text();
-
-       params.setCmdName(InsetRef::getName(dialog_->typeCO->currentIndex()));
-       params["reference"] = qstring_to_ucs4(last_reference_);
-       params["name"] = qstring_to_ucs4(dialog_->nameED->text());
-
-       restored_buffer_ = dialog_->bufferCO->currentIndex();
-}
-
-
-bool QRef::nameAllowed()
-{
-       Kernel::DocType const doc_type = kernel().docType();
-       return doc_type != Kernel::LATEX &&
-               doc_type != Kernel::LITERATE;
-}
-
-
-bool QRef::typeAllowed()
-{
-       Kernel::DocType const doc_type = kernel().docType();
-       return doc_type != Kernel::DOCBOOK;
-}
-
-
-void QRef::setGoBack()
-{
-       dialog_->gotoPB->setText(qt_("&Go Back"));
-       dialog_->gotoPB->setToolTip("");
-       dialog_->gotoPB->setToolTip(qt_("Jump back"));
-}
-
-
-void QRef::setGotoRef()
-{
-       dialog_->gotoPB->setText(qt_("&Go to Label"));
-       dialog_->gotoPB->setToolTip("");
-       dialog_->gotoPB->setToolTip(qt_("Jump to label"));
-}
-
-
-void QRef::gotoRef()
-{
-       string ref(fromqstr(dialog_->referenceED->text()));
-
-       if (at_ref_) {
-               // go back
-               setGotoRef();
-               controller().gotoBookmark();
-       } else {
-               // go to the ref
-               setGoBack();
-               controller().gotoRef(ref);
-       }
-       at_ref_ = !at_ref_;
-}
-
-
-void QRef::redoRefs()
-{
-       // Prevent these widgets from emitting any signals whilst
-       // we modify their state.
-       dialog_->refsLW->blockSignals(true);
-       dialog_->referenceED->blockSignals(true);
-       dialog_->refsLW->setUpdatesEnabled(false);
-       
-       dialog_->refsLW->clear();
-
-       // need this because Qt will send a highlight() here for
-       // the first item inserted
-       QString const oldSelection(dialog_->referenceED->text());
-
-       for (std::vector<docstring>::const_iterator iter = refs_.begin();
-               iter != refs_.end(); ++iter) {
-               dialog_->refsLW->addItem(toqstr(*iter));
-       }
-
-       if (sort_)
-               dialog_->refsLW->sortItems();
-
-       dialog_->referenceED->setText(oldSelection);
-
-       // restore the last selection or, for new insets, highlight
-       // the previous selection
-       if (!oldSelection.isEmpty() || !last_reference_.isEmpty()) {
-               bool const newInset = oldSelection.isEmpty();
-               QString textToFind = newInset ? last_reference_ : oldSelection;
-               bool foundItem = false;
-               for (int i = 0; !foundItem && i < dialog_->refsLW->count(); ++i) {
-                       QListWidgetItem * item = dialog_->refsLW->item(i);
-                       if (textToFind == item->text()) {
-                               dialog_->refsLW->setCurrentItem(item);
-                               dialog_->refsLW->setItemSelected(item, !newInset);
-                               //Make sure selected item is visible
-                               dialog_->refsLW->scrollToItem(item);
-                               foundItem = true;
-                       }
-               }
-               if (foundItem)
-                       last_reference_ = textToFind;
-               else last_reference_ = "";
-       }
-       dialog_->refsLW->setUpdatesEnabled(true);
-       dialog_->refsLW->update();
-
-       // Re-activate the emission of signals by these widgets.
-       dialog_->refsLW->blockSignals(false);
-       dialog_->referenceED->blockSignals(false);
-}
-
-
-void QRef::updateRefs()
-{
-       refs_.clear();
-       string const name = controller().getBufferName(dialog_->bufferCO->currentIndex());
-       refs_ = controller().getLabelList(name);
-       dialog_->sortCB->setEnabled(!refs_.empty());
-       dialog_->refsLW->setEnabled(!refs_.empty());
-       dialog_->gotoPB->setEnabled(!refs_.empty());
-       redoRefs();
-}
-
-bool QRef::isValid()
-{
-       return !dialog_->referenceED->text().isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QRef_moc.cpp"
diff --git a/src/frontends/qt4/QRef.cpp b/src/frontends/qt4/QRef.cpp
new file mode 100644 (file)
index 0000000..c16e6ee
--- /dev/null
@@ -0,0 +1,387 @@
+/**
+ * \file QRef.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QRef.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ButtonController.h"
+#include "controllers/ControlRef.h"
+
+#include "insets/InsetRef.h"
+
+#include <QLineEdit>
+#include <QCheckBox>
+#include <QListWidget>
+#include <QListWidgetItem>
+#include <QPushButton>
+#include <QToolTip>
+#include <QCloseEvent>
+
+
+using std::vector;
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QRefDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QRefDialog::QRefDialog(QRef * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+       connect(closePB, SIGNAL(clicked()), this, SLOT(reset_dialog()));
+
+       connect(typeCO, SIGNAL(activated(int)), 
+               this, SLOT(changed_adaptor()));
+       connect(referenceED, SIGNAL(textChanged(const QString &)), 
+               this, SLOT(changed_adaptor()));
+       connect(nameED, SIGNAL(textChanged(const QString &)), 
+               this, SLOT(changed_adaptor()));
+       connect(refsLW, SIGNAL(itemClicked(QListWidgetItem *)), 
+               this, SLOT(refHighlighted(QListWidgetItem *)));
+       connect(refsLW, SIGNAL(itemSelectionChanged()),
+               this, SLOT(selectionChanged()));
+       connect(refsLW, SIGNAL(itemActivated(QListWidgetItem *)), 
+               this, SLOT(refSelected(QListWidgetItem *)));
+       connect(sortCB, SIGNAL(clicked(bool)),
+               this, SLOT(sortToggled(bool)));
+       connect(gotoPB, SIGNAL(clicked()), 
+               this, SLOT(gotoClicked()));
+       connect(updatePB, SIGNAL(clicked()), 
+               this, SLOT(updateClicked()));
+       connect(bufferCO, SIGNAL(activated(int)), 
+               this, SLOT(updateClicked()));
+
+       setFocusProxy(refsLW);
+}
+
+void QRefDialog::show()
+{
+       QDialog::show();
+}
+
+
+void QRefDialog::changed_adaptor()
+{
+       form_->changed();
+}
+
+
+void QRefDialog::gotoClicked()
+{
+       form_->gotoRef();
+}
+
+void QRefDialog::selectionChanged()
+{
+       if (form_->readOnly())
+               return;
+       
+       QList<QListWidgetItem *> selections = refsLW->selectedItems();
+       if (selections.isEmpty())
+               return;
+       QListWidgetItem * sel = selections.first();
+       refHighlighted(sel);
+       return;
+}
+
+
+void QRefDialog::refHighlighted(QListWidgetItem * sel)
+{
+       if (form_->readOnly())
+               return;
+
+/*     int const cur_item = refsLW->currentRow();
+       bool const cur_item_selected = cur_item >= 0 ?
+               refsLB->isSelected(cur_item) : false;*/
+       bool const cur_item_selected = refsLW->isItemSelected(sel);
+
+       if (cur_item_selected)
+               referenceED->setText(sel->text());
+
+       if (form_->at_ref_)
+               form_->gotoRef();
+       gotoPB->setEnabled(true);
+       if (form_->typeAllowed())
+               typeCO->setEnabled(true);
+       if (form_->nameAllowed())
+               nameED->setEnabled(true);
+}
+
+
+void QRefDialog::refSelected(QListWidgetItem * sel)
+{
+       if (form_->readOnly())
+               return;
+
+/*     int const cur_item = refsLW->currentRow();
+       bool const cur_item_selected = cur_item >= 0 ?
+               refsLB->isSelected(cur_item) : false;*/
+       bool const cur_item_selected = refsLW->isItemSelected(sel);
+
+       if (cur_item_selected)
+               referenceED->setText(sel->text());
+       // <enter> or double click, inserts ref and closes dialog
+       form_->slotOK();
+}
+
+
+void QRefDialog::sortToggled(bool on)
+{
+       form_->sort_ = on;
+       form_->redoRefs();
+}
+
+
+void QRefDialog::updateClicked()
+{
+       form_->updateRefs();
+}
+
+
+void QRefDialog::reset_dialog() {
+       form_->at_ref_ = false;
+       form_->setGotoRef();
+}
+
+
+void QRefDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       reset_dialog();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QRef
+//
+/////////////////////////////////////////////////////////////////////
+
+// full qualification because qt4 has also a ControlRef type
+typedef QController<lyx::frontend::ControlRef, QView<QRefDialog> > RefBase;
+
+
+QRef::QRef(Dialog & parent)
+       : RefBase(parent, _("Cross-reference")),
+       sort_(false), at_ref_(false)
+{
+}
+
+
+void QRef::build_dialog()
+{
+       dialog_.reset(new QRefDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->refsLW);
+       bcview().addReadOnly(dialog_->sortCB);
+       bcview().addReadOnly(dialog_->nameED);
+       bcview().addReadOnly(dialog_->referenceED);
+       bcview().addReadOnly(dialog_->typeCO);
+       bcview().addReadOnly(dialog_->bufferCO);
+
+       restored_buffer_ = -1;
+}
+
+
+void QRef::update_contents()
+{
+       InsetCommandParams const & params = controller().params();
+
+       int orig_type = dialog_->typeCO->currentIndex();
+
+       dialog_->referenceED->setText(toqstr(params["reference"]));
+
+       dialog_->nameED->setText(toqstr(params["name"]));
+       dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
+
+       // restore type settings for new insets
+       if (params["reference"].empty())
+               dialog_->typeCO->setCurrentIndex(orig_type);
+       else
+               dialog_->typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
+       dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
+       if (!typeAllowed())
+               dialog_->typeCO->setCurrentIndex(0);
+
+       dialog_->sortCB->setChecked(sort_);
+
+       // insert buffer list
+       dialog_->bufferCO->clear();
+       vector<string> const buffers = controller().getBufferList();
+       for (vector<string>::const_iterator it = buffers.begin();
+               it != buffers.end(); ++it) {
+               dialog_->bufferCO->addItem(toqstr(*it));
+       }
+       // restore the buffer combo setting for new insets
+       if (params["reference"].empty() && restored_buffer_ != -1
+       && restored_buffer_ < dialog_->bufferCO->count())
+               dialog_->bufferCO->setCurrentIndex(restored_buffer_);
+       else
+               dialog_->bufferCO->setCurrentIndex(controller().getBufferNum());
+
+       updateRefs();
+       bc().valid(false);
+}
+
+
+void QRef::apply()
+{
+       InsetCommandParams & params = controller().params();
+       
+       last_reference_ = dialog_->referenceED->text();
+
+       params.setCmdName(InsetRef::getName(dialog_->typeCO->currentIndex()));
+       params["reference"] = qstring_to_ucs4(last_reference_);
+       params["name"] = qstring_to_ucs4(dialog_->nameED->text());
+
+       restored_buffer_ = dialog_->bufferCO->currentIndex();
+}
+
+
+bool QRef::nameAllowed()
+{
+       Kernel::DocType const doc_type = kernel().docType();
+       return doc_type != Kernel::LATEX &&
+               doc_type != Kernel::LITERATE;
+}
+
+
+bool QRef::typeAllowed()
+{
+       Kernel::DocType const doc_type = kernel().docType();
+       return doc_type != Kernel::DOCBOOK;
+}
+
+
+void QRef::setGoBack()
+{
+       dialog_->gotoPB->setText(qt_("&Go Back"));
+       dialog_->gotoPB->setToolTip("");
+       dialog_->gotoPB->setToolTip(qt_("Jump back"));
+}
+
+
+void QRef::setGotoRef()
+{
+       dialog_->gotoPB->setText(qt_("&Go to Label"));
+       dialog_->gotoPB->setToolTip("");
+       dialog_->gotoPB->setToolTip(qt_("Jump to label"));
+}
+
+
+void QRef::gotoRef()
+{
+       string ref(fromqstr(dialog_->referenceED->text()));
+
+       if (at_ref_) {
+               // go back
+               setGotoRef();
+               controller().gotoBookmark();
+       } else {
+               // go to the ref
+               setGoBack();
+               controller().gotoRef(ref);
+       }
+       at_ref_ = !at_ref_;
+}
+
+
+void QRef::redoRefs()
+{
+       // Prevent these widgets from emitting any signals whilst
+       // we modify their state.
+       dialog_->refsLW->blockSignals(true);
+       dialog_->referenceED->blockSignals(true);
+       dialog_->refsLW->setUpdatesEnabled(false);
+       
+       dialog_->refsLW->clear();
+
+       // need this because Qt will send a highlight() here for
+       // the first item inserted
+       QString const oldSelection(dialog_->referenceED->text());
+
+       for (std::vector<docstring>::const_iterator iter = refs_.begin();
+               iter != refs_.end(); ++iter) {
+               dialog_->refsLW->addItem(toqstr(*iter));
+       }
+
+       if (sort_)
+               dialog_->refsLW->sortItems();
+
+       dialog_->referenceED->setText(oldSelection);
+
+       // restore the last selection or, for new insets, highlight
+       // the previous selection
+       if (!oldSelection.isEmpty() || !last_reference_.isEmpty()) {
+               bool const newInset = oldSelection.isEmpty();
+               QString textToFind = newInset ? last_reference_ : oldSelection;
+               bool foundItem = false;
+               for (int i = 0; !foundItem && i < dialog_->refsLW->count(); ++i) {
+                       QListWidgetItem * item = dialog_->refsLW->item(i);
+                       if (textToFind == item->text()) {
+                               dialog_->refsLW->setCurrentItem(item);
+                               dialog_->refsLW->setItemSelected(item, !newInset);
+                               //Make sure selected item is visible
+                               dialog_->refsLW->scrollToItem(item);
+                               foundItem = true;
+                       }
+               }
+               if (foundItem)
+                       last_reference_ = textToFind;
+               else last_reference_ = "";
+       }
+       dialog_->refsLW->setUpdatesEnabled(true);
+       dialog_->refsLW->update();
+
+       // Re-activate the emission of signals by these widgets.
+       dialog_->refsLW->blockSignals(false);
+       dialog_->referenceED->blockSignals(false);
+}
+
+
+void QRef::updateRefs()
+{
+       refs_.clear();
+       string const name = controller().getBufferName(dialog_->bufferCO->currentIndex());
+       refs_ = controller().getLabelList(name);
+       dialog_->sortCB->setEnabled(!refs_.empty());
+       dialog_->refsLW->setEnabled(!refs_.empty());
+       dialog_->gotoPB->setEnabled(!refs_.empty());
+       redoRefs();
+}
+
+bool QRef::isValid()
+{
+       return !dialog_->referenceED->text().isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QRef_moc.cpp"
diff --git a/src/frontends/qt4/QSearch.C b/src/frontends/qt4/QSearch.C
deleted file mode 100644 (file)
index 6bd22ee..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * \file QSearch.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QSearch.h"
-#include "qt_helpers.h"
-#include "Qt2BC.h"
-
-#include "controllers/ControlSearch.h"
-
-#include <QLineEdit>
-#include <QCloseEvent>
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QSearchDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-static void uniqueInsert(QComboBox * box, QString const & text)
-{
-       for (int i = 0; i < box->count(); ++i) {
-               if (box->itemText(i) == text)
-                       return;
-       }
-
-       box->addItem(text);
-}
-
-
-QSearchDialog::QSearchDialog(QSearch * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
-  connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
-  connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
-  connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
-  connect(findCO, SIGNAL(editTextChanged(const QString &)),
-               this, SLOT(findChanged()));
-
-       setFocusProxy(findCO);
-}
-
-
-void QSearchDialog::show()
-{
-       QDialog::show();
-       findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
-}
-
-
-void QSearchDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QSearchDialog::findChanged()
-{
-       if (findCO->currentText().isEmpty()) {
-               findPB->setEnabled(false);
-               replacePB->setEnabled(false);
-               replaceallPB->setEnabled(false);
-       } else {
-               findPB->setEnabled(true);
-               replacePB->setEnabled(!form_->readOnly());
-               replaceallPB->setEnabled(!form_->readOnly());
-       }
-}
-
-
-void QSearchDialog::findClicked()
-{
-       docstring const find = qstring_to_ucs4(findCO->currentText());
-       form_->find(find,
-               caseCB->isChecked(),
-               wordsCB->isChecked(),
-               backwardsCB->isChecked());
-       uniqueInsert(findCO, findCO->currentText());
-}
-
-
-void QSearchDialog::replaceClicked()
-{
-       docstring const find = qstring_to_ucs4(findCO->currentText());
-       docstring const replace = qstring_to_ucs4(replaceCO->currentText());
-       form_->replace(find, replace,
-               caseCB->isChecked(),
-               wordsCB->isChecked(),
-               backwardsCB->isChecked(), false);
-       uniqueInsert(findCO, findCO->currentText());
-       uniqueInsert(replaceCO, replaceCO->currentText());
-}
-
-
-void QSearchDialog::replaceallClicked()
-{
-       form_->replace(qstring_to_ucs4(findCO->currentText()),
-               qstring_to_ucs4(replaceCO->currentText()),
-               caseCB->isChecked(),
-               wordsCB->isChecked(),
-               false, true);
-       uniqueInsert(findCO, findCO->currentText());
-       uniqueInsert(replaceCO, replaceCO->currentText());
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QSearch
-//
-/////////////////////////////////////////////////////////////////////
-
-
-typedef QController<ControlSearch, QView<QSearchDialog> > SearchBase;
-
-
-QSearch::QSearch(Dialog & parent)
-       : SearchBase(parent, _("Find and Replace"))
-{
-}
-
-
-void QSearch::build_dialog()
-{
-       dialog_.reset(new QSearchDialog(this));
-
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->replaceCO);
-       bcview().addReadOnly(dialog_->replacePB);
-       bcview().addReadOnly(dialog_->replaceallPB);
-
-       dialog_->replacePB->setEnabled(false);
-       dialog_->replaceallPB->setEnabled(false);
-}
-
-
-void QSearch::find(docstring const & str, bool casesens,
-                  bool words, bool backwards)
-{
-       controller().find(str, casesens, words, !backwards);
-}
-
-
-void QSearch::replace(docstring const & findstr, docstring const & replacestr,
-       bool casesens, bool words, bool backwards, bool all)
-{
-       controller().replace(findstr, replacestr, casesens, words,
-                            !backwards, all);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-
-#include "QSearch_moc.cpp"
-
diff --git a/src/frontends/qt4/QSearch.cpp b/src/frontends/qt4/QSearch.cpp
new file mode 100644 (file)
index 0000000..6bd22ee
--- /dev/null
@@ -0,0 +1,176 @@
+/**
+ * \file QSearch.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QSearch.h"
+#include "qt_helpers.h"
+#include "Qt2BC.h"
+
+#include "controllers/ControlSearch.h"
+
+#include <QLineEdit>
+#include <QCloseEvent>
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QSearchDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+static void uniqueInsert(QComboBox * box, QString const & text)
+{
+       for (int i = 0; i < box->count(); ++i) {
+               if (box->itemText(i) == text)
+                       return;
+       }
+
+       box->addItem(text);
+}
+
+
+QSearchDialog::QSearchDialog(QSearch * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+  connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
+  connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
+  connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
+  connect(findCO, SIGNAL(editTextChanged(const QString &)),
+               this, SLOT(findChanged()));
+
+       setFocusProxy(findCO);
+}
+
+
+void QSearchDialog::show()
+{
+       QDialog::show();
+       findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
+}
+
+
+void QSearchDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QSearchDialog::findChanged()
+{
+       if (findCO->currentText().isEmpty()) {
+               findPB->setEnabled(false);
+               replacePB->setEnabled(false);
+               replaceallPB->setEnabled(false);
+       } else {
+               findPB->setEnabled(true);
+               replacePB->setEnabled(!form_->readOnly());
+               replaceallPB->setEnabled(!form_->readOnly());
+       }
+}
+
+
+void QSearchDialog::findClicked()
+{
+       docstring const find = qstring_to_ucs4(findCO->currentText());
+       form_->find(find,
+               caseCB->isChecked(),
+               wordsCB->isChecked(),
+               backwardsCB->isChecked());
+       uniqueInsert(findCO, findCO->currentText());
+}
+
+
+void QSearchDialog::replaceClicked()
+{
+       docstring const find = qstring_to_ucs4(findCO->currentText());
+       docstring const replace = qstring_to_ucs4(replaceCO->currentText());
+       form_->replace(find, replace,
+               caseCB->isChecked(),
+               wordsCB->isChecked(),
+               backwardsCB->isChecked(), false);
+       uniqueInsert(findCO, findCO->currentText());
+       uniqueInsert(replaceCO, replaceCO->currentText());
+}
+
+
+void QSearchDialog::replaceallClicked()
+{
+       form_->replace(qstring_to_ucs4(findCO->currentText()),
+               qstring_to_ucs4(replaceCO->currentText()),
+               caseCB->isChecked(),
+               wordsCB->isChecked(),
+               false, true);
+       uniqueInsert(findCO, findCO->currentText());
+       uniqueInsert(replaceCO, replaceCO->currentText());
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QSearch
+//
+/////////////////////////////////////////////////////////////////////
+
+
+typedef QController<ControlSearch, QView<QSearchDialog> > SearchBase;
+
+
+QSearch::QSearch(Dialog & parent)
+       : SearchBase(parent, _("Find and Replace"))
+{
+}
+
+
+void QSearch::build_dialog()
+{
+       dialog_.reset(new QSearchDialog(this));
+
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->replaceCO);
+       bcview().addReadOnly(dialog_->replacePB);
+       bcview().addReadOnly(dialog_->replaceallPB);
+
+       dialog_->replacePB->setEnabled(false);
+       dialog_->replaceallPB->setEnabled(false);
+}
+
+
+void QSearch::find(docstring const & str, bool casesens,
+                  bool words, bool backwards)
+{
+       controller().find(str, casesens, words, !backwards);
+}
+
+
+void QSearch::replace(docstring const & findstr, docstring const & replacestr,
+       bool casesens, bool words, bool backwards, bool all)
+{
+       controller().replace(findstr, replacestr, casesens, words,
+                            !backwards, all);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QSearch_moc.cpp"
+
diff --git a/src/frontends/qt4/QSendto.C b/src/frontends/qt4/QSendto.C
deleted file mode 100644 (file)
index 4efe0e3..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * \file QSendto.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QSendto.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "format.h"
-
-#include "controllers/ControlSendto.h"
-
-#include <QListWidget>
-#include <QPushButton>
-#include <QCloseEvent>
-
-using std::vector;
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QSendtoDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QSendtoDialog::QSendtoDialog(QSendto * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()),
-               form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()),
-               form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-
-       connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ), 
-               this, SLOT( slotFormatHighlighted(QListWidgetItem *) ) );
-       connect( formatLW, SIGNAL( itemActivated(QListWidgetItem *) ), 
-               this, SLOT( slotFormatSelected(QListWidgetItem *) ) );
-       connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ), 
-               this, SLOT( changed_adaptor() ) );
-       connect( commandCO, SIGNAL( textChanged(const QString&) ), 
-               this, SLOT( changed_adaptor() ) );
-}
-
-
-void QSendtoDialog::changed_adaptor()
-{
-       form_->changed();
-}
-
-
-void QSendtoDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QSendto
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlSendto, QView<QSendtoDialog> > SendtoBase;
-
-
-QSendto::QSendto(Dialog & parent)
-       : SendtoBase(parent, _("Send Document to Command"))
-{
-}
-
-
-void QSendto::build_dialog()
-{
-       dialog_.reset(new QSendtoDialog(this));
-
-       // Manage the ok, apply, restore and cancel/close buttons
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QSendto::update_contents()
-{
-       all_formats_ = controller().allFormats();
-
-       // Check whether the current contents of the browser will be
-       // changed by loading the contents of formats
-       vector<string> keys;
-       keys.resize(all_formats_.size());
-
-       vector<string>::iterator result = keys.begin();
-       vector<Format const *>::const_iterator it  = all_formats_.begin();
-       vector<Format const *>::const_iterator end = all_formats_.end();
-       for (; it != end; ++it, ++result) {
-               *result = (*it)->prettyname();
-       }
-
-       // Reload the browser
-       dialog_->formatLW->clear();
-
-       for (vector<string>::const_iterator it = keys.begin();
-            it < keys.end(); ++it) {
-               dialog_->formatLW->addItem(toqstr(*it));
-       }
-
-       dialog_->commandCO->addItem(toqstr(controller().getCommand()));
-}
-
-
-void QSendto::apply()
-{
-       int const line(dialog_->formatLW->currentRow());
-
-       if (line < 0 || line > int(dialog_->formatLW->count()))
-               return;
-
-       string const cmd(fromqstr(dialog_->commandCO->currentText()));
-
-       controller().setFormat(all_formats_[line]);
-       controller().setCommand(cmd);
-}
-
-
-bool QSendto::isValid()
-{
-       int const line(dialog_->formatLW->currentRow());
-
-       if (line < 0 || line > int(dialog_->formatLW->count()))
-               return false;
-
-       else return dialog_->formatLW->count() != 0 &&
-               !dialog_->commandCO->currentText().isEmpty();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QSendto_moc.cpp"
diff --git a/src/frontends/qt4/QSendto.cpp b/src/frontends/qt4/QSendto.cpp
new file mode 100644 (file)
index 0000000..4efe0e3
--- /dev/null
@@ -0,0 +1,156 @@
+/**
+ * \file QSendto.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QSendto.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "format.h"
+
+#include "controllers/ControlSendto.h"
+
+#include <QListWidget>
+#include <QPushButton>
+#include <QCloseEvent>
+
+using std::vector;
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QSendtoDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QSendtoDialog::QSendtoDialog(QSendto * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()),
+               form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()),
+               form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+
+       connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ), 
+               this, SLOT( slotFormatHighlighted(QListWidgetItem *) ) );
+       connect( formatLW, SIGNAL( itemActivated(QListWidgetItem *) ), 
+               this, SLOT( slotFormatSelected(QListWidgetItem *) ) );
+       connect( formatLW, SIGNAL( itemClicked(QListWidgetItem *) ), 
+               this, SLOT( changed_adaptor() ) );
+       connect( commandCO, SIGNAL( textChanged(const QString&) ), 
+               this, SLOT( changed_adaptor() ) );
+}
+
+
+void QSendtoDialog::changed_adaptor()
+{
+       form_->changed();
+}
+
+
+void QSendtoDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QSendto
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlSendto, QView<QSendtoDialog> > SendtoBase;
+
+
+QSendto::QSendto(Dialog & parent)
+       : SendtoBase(parent, _("Send Document to Command"))
+{
+}
+
+
+void QSendto::build_dialog()
+{
+       dialog_.reset(new QSendtoDialog(this));
+
+       // Manage the ok, apply, restore and cancel/close buttons
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QSendto::update_contents()
+{
+       all_formats_ = controller().allFormats();
+
+       // Check whether the current contents of the browser will be
+       // changed by loading the contents of formats
+       vector<string> keys;
+       keys.resize(all_formats_.size());
+
+       vector<string>::iterator result = keys.begin();
+       vector<Format const *>::const_iterator it  = all_formats_.begin();
+       vector<Format const *>::const_iterator end = all_formats_.end();
+       for (; it != end; ++it, ++result) {
+               *result = (*it)->prettyname();
+       }
+
+       // Reload the browser
+       dialog_->formatLW->clear();
+
+       for (vector<string>::const_iterator it = keys.begin();
+            it < keys.end(); ++it) {
+               dialog_->formatLW->addItem(toqstr(*it));
+       }
+
+       dialog_->commandCO->addItem(toqstr(controller().getCommand()));
+}
+
+
+void QSendto::apply()
+{
+       int const line(dialog_->formatLW->currentRow());
+
+       if (line < 0 || line > int(dialog_->formatLW->count()))
+               return;
+
+       string const cmd(fromqstr(dialog_->commandCO->currentText()));
+
+       controller().setFormat(all_formats_[line]);
+       controller().setCommand(cmd);
+}
+
+
+bool QSendto::isValid()
+{
+       int const line(dialog_->formatLW->currentRow());
+
+       if (line < 0 || line > int(dialog_->formatLW->count()))
+               return false;
+
+       else return dialog_->formatLW->count() != 0 &&
+               !dialog_->commandCO->currentText().isEmpty();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QSendto_moc.cpp"
diff --git a/src/frontends/qt4/QSetBorder.cpp b/src/frontends/qt4/QSetBorder.cpp
new file mode 100644 (file)
index 0000000..4a96ed6
--- /dev/null
@@ -0,0 +1,250 @@
+/**
+ * \file QSetBorder.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QSetBorder.h"
+
+#include <QPainter>
+
+//Added by qt3to4:
+#include <QMouseEvent>
+#include <QPaintEvent>
+
+
+QSetBorder::QSetBorder(QWidget * parent, Qt::WFlags fl)
+       : QWidget(parent, fl), buffer(75, 75)
+{
+       /* length of corner line */
+       l = buffer.width() / 10;
+       /* margin */
+       m = buffer.height() / 10;
+
+       w = buffer.width();
+       h = buffer.height();
+
+       init();
+
+       setMinimumSize(w,h);
+       setMaximumSize(w,h);
+}
+
+
+void QSetBorder::paintEvent(QPaintEvent * e)
+{
+       QWidget::paintEvent(e);
+       QPainter painter(this);
+       painter.drawPixmap(0, 0, buffer);
+}
+
+
+void QSetBorder::init()
+{
+       buffer.fill();
+       QPainter paint(&buffer);
+
+       paint.setPen(Qt::black);
+
+       // FIXME: wow, readable !! :)
+
+       paint.drawLine(m + l , m, m + l, m + l);
+       paint.drawLine(w - (m + l), m, w - (m + l), m + l);
+
+       paint.drawLine(m, m + l , m + l, m + l);
+       paint.drawLine(m, h - (m + l), m + l, h - (m + l));
+
+       paint.drawLine(m + l ,h - m, m + l ,h - (m + l));
+       paint.drawLine(w - (m + l), h - m, w - (m + l), h - (m + l));
+
+       paint.drawLine(h - m, m+l, h - (m + l), m + l);
+       paint.drawLine(h - m, h - (m + l), h - (m + l),h - (m + l));
+}
+
+
+void QSetBorder::mousePressEvent(QMouseEvent * e)
+{
+       if (e->y() > e->x()) {
+               if (e->y() < height() - e->x()) {
+                       if (left_.enabled) {
+                               setLeft(!left_.set);
+                                // emit signal
+                               leftSet(left_.set);
+                       }
+               } else {
+                       if (bottom_.enabled) {
+                               setBottom(!bottom_.set);
+                                // emit signal
+                               bottomSet(bottom_.set);
+                       }
+               }
+       } else {
+               if (e->y() < height() - e->x()) {
+                       if (top_.enabled) {
+                               setTop(!top_.set);
+                                // emit signal
+                               topSet(top_.set);
+                       }
+               } else {
+                       if (right_.enabled) {
+                               setRight(!right_.set);
+                                // emit signal
+                               rightSet(right_.set);
+                       }
+               }
+       }
+       update();
+        // emit signal
+       clicked();
+}
+
+
+void QSetBorder::drawLine(QColor const & col, int x, int y, int x2, int y2)
+{
+       QPainter paint(&buffer);
+       QPen p = paint.pen();
+       p.setWidth(2);
+       p.setColor(col);
+       paint.setPen(p);
+       paint.drawLine(x, y, x2, y2);
+}
+
+
+void QSetBorder::drawLeft(bool draw)
+{
+       QColor col(draw ? Qt::black : Qt::white);
+       if (!left_.enabled)
+               col = QColor("grey");
+       drawLine(col, m + l, m + l + 2, m + l, h - m - l - 1);
+}
+
+
+void QSetBorder::drawRight(bool draw)
+{
+       QColor col(draw ? Qt::black : Qt::white);
+       if (!right_.enabled)
+               col = QColor("grey");
+       drawLine(col, h - m - l + 1, m + l + 2, h - m - l + 1, h - m - l - 1);
+}
+
+
+void QSetBorder::drawTop(bool draw)
+{
+       QColor col(draw ? Qt::black : Qt::white);
+       if (!top_.enabled)
+               col = QColor("grey");
+       drawLine(col, m + l + 2, m + l, w - m - l - 1, m + l);
+}
+
+
+void QSetBorder::drawBottom(bool draw)
+{
+       QColor col(draw ? Qt::black : Qt::white);
+       if (!bottom_.enabled)
+               col = QColor("grey");
+       drawLine(col, m + l + 2, w - m - l + 1, w - m - l - 1, w - m - l + 1);
+}
+
+
+void QSetBorder::setLeftEnabled(bool border)
+{
+       left_.enabled = border;
+       drawLeft(border);
+}
+
+
+void QSetBorder::setRightEnabled(bool border)
+{
+       right_.enabled = border;
+       drawRight(border);
+}
+
+
+void QSetBorder::setTopEnabled(bool border)
+{
+       top_.enabled = border;
+       drawTop(border);
+}
+
+
+void QSetBorder::setBottomEnabled(bool border)
+{
+       bottom_.enabled = border;
+       drawBottom(border);
+}
+
+
+void QSetBorder::setLeft(bool border)
+{
+       left_.set = border;
+       drawLeft(border);
+}
+
+
+void QSetBorder::setRight(bool border)
+{
+       right_.set = border;
+       drawRight(border);
+}
+
+
+void QSetBorder::setTop(bool border)
+{
+       top_.set = border;
+       drawTop(border);
+}
+
+
+void QSetBorder::setBottom(bool border)
+{
+       bottom_.set = border;
+       drawBottom(border);
+}
+
+
+void QSetBorder::setAll(bool border)
+{
+       setLeft(border);
+       setRight(border);
+       setTop(border);
+       setBottom(border);
+}
+
+
+bool QSetBorder::getLeft()
+{
+       return left_.set;
+}
+
+
+bool QSetBorder::getRight()
+{
+       return right_.set;
+}
+
+
+bool QSetBorder::getTop()
+{
+       return top_.set;
+}
+
+
+bool QSetBorder::getBottom()
+{
+       return bottom_.set;
+}
+
+#include "QSetBorder_moc.cpp"
+
+
+namespace lyx {
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/QSetBorder.h b/src/frontends/qt4/QSetBorder.h
new file mode 100644 (file)
index 0000000..2c53bea
--- /dev/null
@@ -0,0 +1,90 @@
+// -*- C++ -*-
+/**
+ * \file QSetBorder.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+#ifndef QSETBORDER_H
+#define QSETBORDER_H
+
+#include <QWidget>
+#include <QPixmap>
+
+class QColor;
+class QMouseEvent;
+class QPaintEvent;
+
+//namespace lyx {
+
+class QSetBorder : public QWidget
+{
+       Q_OBJECT
+public:
+       QSetBorder(QWidget * parent = 0, Qt::WFlags fl = 0);
+
+       bool getLeft();
+       bool getRight();
+       bool getTop();
+       bool getBottom();
+
+Q_SIGNALS:
+       void rightSet(bool);
+       void leftSet(bool);
+       void topSet(bool);
+       void bottomSet(bool);
+       void clicked();
+
+public Q_SLOTS:
+       void setLeftEnabled(bool);
+       void setRightEnabled(bool);
+       void setTopEnabled(bool);
+       void setBottomEnabled(bool);
+       void setLeft(bool);
+       void setRight(bool);
+       void setTop(bool);
+       void setBottom(bool);
+       void setAll(bool);
+
+protected:
+       void mousePressEvent(QMouseEvent * e);
+       void paintEvent(QPaintEvent * e);
+
+private:
+       void init();
+
+       void drawLine(QColor const & col, int x, int y, int x2, int y2);
+
+       void drawLeft(bool);
+       void drawRight(bool);
+       void drawTop(bool);
+       void drawBottom(bool);
+
+       class Border {
+       public:
+               Border() : set(true), enabled(true) {}
+               bool set;
+               bool enabled;
+       };
+
+       Border left_;
+       Border right_;
+       Border top_;
+       Border bottom_;
+
+       int m;
+       int l;
+       int w;
+       int h;
+
+       QPixmap buffer;
+};
+
+
+//} // namespace lyx
+
+#endif // QSETBORDER_H
diff --git a/src/frontends/qt4/QShowFile.C b/src/frontends/qt4/QShowFile.C
deleted file mode 100644 (file)
index 5e97418..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * \file QShowFile.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QShowFile.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ControlShowFile.h"
-
-#include <QTextBrowser>
-#include <QPushButton>
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QShowFileDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QShowFileDialog::QShowFileDialog(QShowFile * form)
-       : form_(form)
-{
-       setupUi(this);
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-}
-
-
-void QShowFileDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QShowFile 
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlShowFile, QView<QShowFileDialog> >
-       ShowFileBase;
-
-
-QShowFile::QShowFile(Dialog & parent)
-       : ShowFileBase(parent, _("Show File"))
-{
-}
-
-
-void QShowFile::build_dialog()
-{
-       dialog_.reset(new QShowFileDialog(this));
-
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QShowFile::update_contents()
-{
-       dialog_->setWindowTitle(toqstr(controller().getFileName()));
-
-       std::string contents = controller().getFileContents();
-       if (contents.empty()) {
-               contents = "Error -> Cannot load file!";
-       }
-
-       dialog_->textTB->setPlainText(toqstr(contents));
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QShowFile_moc.cpp"
diff --git a/src/frontends/qt4/QShowFile.cpp b/src/frontends/qt4/QShowFile.cpp
new file mode 100644 (file)
index 0000000..5e97418
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * \file QShowFile.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QShowFile.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ControlShowFile.h"
+
+#include <QTextBrowser>
+#include <QPushButton>
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QShowFileDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QShowFileDialog::QShowFileDialog(QShowFile * form)
+       : form_(form)
+{
+       setupUi(this);
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+}
+
+
+void QShowFileDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QShowFile 
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlShowFile, QView<QShowFileDialog> >
+       ShowFileBase;
+
+
+QShowFile::QShowFile(Dialog & parent)
+       : ShowFileBase(parent, _("Show File"))
+{
+}
+
+
+void QShowFile::build_dialog()
+{
+       dialog_.reset(new QShowFileDialog(this));
+
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QShowFile::update_contents()
+{
+       dialog_->setWindowTitle(toqstr(controller().getFileName()));
+
+       std::string contents = controller().getFileContents();
+       if (contents.empty()) {
+               contents = "Error -> Cannot load file!";
+       }
+
+       dialog_->textTB->setPlainText(toqstr(contents));
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QShowFile_moc.cpp"
diff --git a/src/frontends/qt4/QSpellchecker.C b/src/frontends/qt4/QSpellchecker.C
deleted file mode 100644 (file)
index a09bc4e..0000000
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * \file QSpellchecker.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QSpellchecker.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ControlSpellchecker.h"
-
-#include <QProgressBar>
-#include <QLineEdit>
-#include <QPushButton>
-#include <QListWidget>
-#include <QListWidgetItem>
-#include <QCloseEvent>
-#include <QSyntaxHighlighter>
-#include <QTextCharFormat>
-#include <QTextDocument>
-
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QSpellCheckerDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-QSpellcheckerDialog::QSpellcheckerDialog(QSpellchecker * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(replaceCO, SIGNAL(highlighted(const QString &)),
-               this, SLOT(replaceChanged(const QString &)));
-       connect(replacePB, SIGNAL(clicked()),
-               this, SLOT(replaceClicked()));
-       connect(ignorePB, SIGNAL(clicked()),
-               this, SLOT(ignoreClicked()));
-       connect(replacePB_3, SIGNAL(clicked()),
-               this, SLOT(acceptClicked()));
-       connect(addPB, SIGNAL(clicked()),
-               this, SLOT(addClicked()));
-       connect(suggestionsLW, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
-               this, SLOT(replaceClicked() ) );
-       connect(suggestionsLW, SIGNAL(itemClicked(QListWidgetItem*)),
-               this, SLOT(suggestionChanged(QListWidgetItem*)));
-}
-
-
-void QSpellcheckerDialog::acceptClicked()
-{
-       form_->accept();
-}
-
-void QSpellcheckerDialog::addClicked()
-{
-       form_->add();
-}
-
-void QSpellcheckerDialog::replaceClicked()
-{
-       form_->replace();
-}
-
-void QSpellcheckerDialog::ignoreClicked()
-{
-       form_->ignore();
-}
-
-void QSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
-{
-       if (replaceCO->count() != 0)
-               replaceCO->setItemText(0, item->text());
-       else
-               replaceCO->addItem(item->text());
-
-       replaceCO->setCurrentIndex(0);
-}
-
-void QSpellcheckerDialog::replaceChanged(const QString & str)
-{
-       if (suggestionsLW->currentItem()->text() == str)
-               return;
-
-       for (int i = 0; i < suggestionsLW->count(); ++i) {
-               if (suggestionsLW->item(i)->text() == str) {
-                       suggestionsLW->setCurrentRow(i);
-                       break;
-               }
-       }
-}
-
-
-void QSpellcheckerDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QSpellcheckerDialog::reject()
-{
-       form_->slotWMHide();
-       QDialog::reject();
-}
-
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QSpellChecker
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlSpellchecker, QView<QSpellcheckerDialog> >
-       SpellcheckerBase;
-
-QSpellchecker::QSpellchecker(Dialog & parent)
-       : SpellcheckerBase(parent, _("Spellchecker"))
-{}
-
-
-void QSpellchecker::build_dialog()
-{
-       dialog_.reset(new QSpellcheckerDialog(this));
-
-       bcview().setCancel(dialog_->closePB);
-       dialog_->wordED->setReadOnly(true);
-}
-
-
-void QSpellchecker::update_contents()
-{
-       if (isVisible() || controller().exitEarly())
-               controller().check();
-}
-
-
-void QSpellchecker::accept()
-{
-       controller().ignoreAll();
-}
-
-
-void QSpellchecker::add()
-{
-       controller().insert();
-}
-
-
-void QSpellchecker::ignore()
-{
-       controller().check();
-}
-
-
-void QSpellchecker::replace()
-{
-       controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
-}
-
-
-void QSpellchecker::partialUpdate(int s)
-{
-       ControlSpellchecker::State const state =
-               static_cast<ControlSpellchecker::State>(s);
-
-       switch (state) {
-
-       case ControlSpellchecker::SPELL_PROGRESSED:
-               dialog_->spellcheckPR->setValue(controller().getProgress());
-               break;
-
-       case ControlSpellchecker::SPELL_FOUND_WORD: {
-               dialog_->wordED->setText(toqstr(controller().getWord()));
-               dialog_->suggestionsLW->clear();
-
-               docstring w;
-               while (!(w = controller().getSuggestion()).empty()) {
-                       dialog_->suggestionsLW->addItem(toqstr(w));
-               }
-
-               if (dialog_->suggestionsLW->count() == 0) {
-                       dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
-               } else {
-                       dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
-               }
-
-               dialog_->suggestionsLW->setCurrentRow(0);
-       }
-               break;
-
-       }
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QSpellchecker_moc.cpp"
diff --git a/src/frontends/qt4/QSpellchecker.cpp b/src/frontends/qt4/QSpellchecker.cpp
new file mode 100644 (file)
index 0000000..a09bc4e
--- /dev/null
@@ -0,0 +1,215 @@
+/**
+ * \file QSpellchecker.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QSpellchecker.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ControlSpellchecker.h"
+
+#include <QProgressBar>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QListWidget>
+#include <QListWidgetItem>
+#include <QCloseEvent>
+#include <QSyntaxHighlighter>
+#include <QTextCharFormat>
+#include <QTextDocument>
+
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QSpellCheckerDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+QSpellcheckerDialog::QSpellcheckerDialog(QSpellchecker * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(replaceCO, SIGNAL(highlighted(const QString &)),
+               this, SLOT(replaceChanged(const QString &)));
+       connect(replacePB, SIGNAL(clicked()),
+               this, SLOT(replaceClicked()));
+       connect(ignorePB, SIGNAL(clicked()),
+               this, SLOT(ignoreClicked()));
+       connect(replacePB_3, SIGNAL(clicked()),
+               this, SLOT(acceptClicked()));
+       connect(addPB, SIGNAL(clicked()),
+               this, SLOT(addClicked()));
+       connect(suggestionsLW, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
+               this, SLOT(replaceClicked() ) );
+       connect(suggestionsLW, SIGNAL(itemClicked(QListWidgetItem*)),
+               this, SLOT(suggestionChanged(QListWidgetItem*)));
+}
+
+
+void QSpellcheckerDialog::acceptClicked()
+{
+       form_->accept();
+}
+
+void QSpellcheckerDialog::addClicked()
+{
+       form_->add();
+}
+
+void QSpellcheckerDialog::replaceClicked()
+{
+       form_->replace();
+}
+
+void QSpellcheckerDialog::ignoreClicked()
+{
+       form_->ignore();
+}
+
+void QSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
+{
+       if (replaceCO->count() != 0)
+               replaceCO->setItemText(0, item->text());
+       else
+               replaceCO->addItem(item->text());
+
+       replaceCO->setCurrentIndex(0);
+}
+
+void QSpellcheckerDialog::replaceChanged(const QString & str)
+{
+       if (suggestionsLW->currentItem()->text() == str)
+               return;
+
+       for (int i = 0; i < suggestionsLW->count(); ++i) {
+               if (suggestionsLW->item(i)->text() == str) {
+                       suggestionsLW->setCurrentRow(i);
+                       break;
+               }
+       }
+}
+
+
+void QSpellcheckerDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QSpellcheckerDialog::reject()
+{
+       form_->slotWMHide();
+       QDialog::reject();
+}
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QSpellChecker
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlSpellchecker, QView<QSpellcheckerDialog> >
+       SpellcheckerBase;
+
+QSpellchecker::QSpellchecker(Dialog & parent)
+       : SpellcheckerBase(parent, _("Spellchecker"))
+{}
+
+
+void QSpellchecker::build_dialog()
+{
+       dialog_.reset(new QSpellcheckerDialog(this));
+
+       bcview().setCancel(dialog_->closePB);
+       dialog_->wordED->setReadOnly(true);
+}
+
+
+void QSpellchecker::update_contents()
+{
+       if (isVisible() || controller().exitEarly())
+               controller().check();
+}
+
+
+void QSpellchecker::accept()
+{
+       controller().ignoreAll();
+}
+
+
+void QSpellchecker::add()
+{
+       controller().insert();
+}
+
+
+void QSpellchecker::ignore()
+{
+       controller().check();
+}
+
+
+void QSpellchecker::replace()
+{
+       controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
+}
+
+
+void QSpellchecker::partialUpdate(int s)
+{
+       ControlSpellchecker::State const state =
+               static_cast<ControlSpellchecker::State>(s);
+
+       switch (state) {
+
+       case ControlSpellchecker::SPELL_PROGRESSED:
+               dialog_->spellcheckPR->setValue(controller().getProgress());
+               break;
+
+       case ControlSpellchecker::SPELL_FOUND_WORD: {
+               dialog_->wordED->setText(toqstr(controller().getWord()));
+               dialog_->suggestionsLW->clear();
+
+               docstring w;
+               while (!(w = controller().getSuggestion()).empty()) {
+                       dialog_->suggestionsLW->addItem(toqstr(w));
+               }
+
+               if (dialog_->suggestionsLW->count() == 0) {
+                       dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
+               } else {
+                       dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
+               }
+
+               dialog_->suggestionsLW->setCurrentRow(0);
+       }
+               break;
+
+       }
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QSpellchecker_moc.cpp"
diff --git a/src/frontends/qt4/QTabular.C b/src/frontends/qt4/QTabular.C
deleted file mode 100644 (file)
index 8ea0540..0000000
+++ /dev/null
@@ -1,979 +0,0 @@
-/**
- * \file QTabular.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Jürgen Spitzmüller
- * \author Herbert Voß
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "CheckedLineEdit.h"
-#include "QTabular.h"
-#include "Qt2BC.h"
-
-#include "LengthCombo.h"
-#include "Validator.h"
-#include "qt_helpers.h"
-
-#include "controllers/ButtonController.h"
-#include "controllers/ControlTabular.h"
-
-#include "support/convert.h"
-
-#include <QCloseEvent>
-#include <QCheckBox>
-#include <QPushButton>
-#include <QRadioButton>
-#include <QLineEdit>
-
-#include "QSetBorder.h"
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QTabularDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QTabularDialog::QTabularDialog(QTabular * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       widthED->setValidator(unsignedLengthValidator(widthED));
-       topspaceED->setValidator(new LengthValidator(topspaceED));
-       bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
-       interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
-
-       connect(topspaceED, SIGNAL(returnPressed()),
-               this, SLOT(topspace_changed()));
-       connect(topspaceUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(topspace_changed()));
-       connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed()));
-       connect(bottomspaceED, SIGNAL(returnPressed()),
-               this, SLOT(bottomspace_changed()));
-       connect(bottomspaceUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(bottomspace_changed()));
-       connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
-       connect(interlinespaceED, SIGNAL(returnPressed()),
-               this, SLOT(interlinespace_changed()));
-       connect(interlinespaceUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(interlinespace_changed()));
-       connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
-       connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
-       connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
-       connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
-       connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
-       connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
-       connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
-       connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
-       connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
-       connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
-       connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
-       connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
-       connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
-       connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
-       connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
-       connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
-       connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
-       connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
-       connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
-       connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
-       connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
-       connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
-       connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
-       connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
-       connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
-       connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
-       connect(widthED, SIGNAL(returnPressed()), this, SLOT(width_changed()));
-       connect(widthUnit, SIGNAL(selectionChanged(LyXLength::UNIT)), this, SLOT(width_changed()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
-       connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
-       connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
-       connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
-       connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
-       connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
-       connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
-       connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
-}
-
-
-void QTabularDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QTabularDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QTabularDialog::booktabsChanged(bool)
-{
-       form_->changed();
-       form_->controller().booktabs(booktabsRB->isChecked());
-       form_->update_borders();
-}
-
-
-void QTabularDialog::topspace_changed()
-{
-       switch(topspaceCO->currentIndex()) {
-               case 0: {
-                       form_->controller().set(LyXTabular::SET_TOP_SPACE, "");
-                               topspaceED->setEnabled(false);
-                               topspaceUnit->setEnabled(false);
-                       break;
-               }
-               case 1: {
-                       form_->controller().set(LyXTabular::SET_TOP_SPACE, "default");
-                       topspaceED->setEnabled(false);
-                       topspaceUnit->setEnabled(false);
-                       break;
-               }
-               case 2: {
-                       if (!topspaceED->text().isEmpty())
-                               form_->controller().set(LyXTabular::SET_TOP_SPACE,
-                                       widgetsToLength(topspaceED, topspaceUnit));
-                       if (!form_->bc().bp().isReadOnly()) {
-                               topspaceED->setEnabled(true);
-                               topspaceUnit->setEnabled(true);
-                       }
-                       break;
-               }
-       }
-       form_->changed();
-}
-
-
-void QTabularDialog::bottomspace_changed()
-{
-       switch(bottomspaceCO->currentIndex()) {
-               case 0: {
-                       form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "");
-                               bottomspaceED->setEnabled(false);
-                               bottomspaceUnit->setEnabled(false);
-                       break;
-               }
-               case 1: {
-                       form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "default");
-                       bottomspaceED->setEnabled(false);
-                       bottomspaceUnit->setEnabled(false);
-                       break;
-               }
-               case 2: {
-                       if (!bottomspaceED->text().isEmpty())
-                               form_->controller().set(LyXTabular::SET_BOTTOM_SPACE,
-                                       widgetsToLength(bottomspaceED, bottomspaceUnit));
-                       if (!form_->bc().bp().isReadOnly()) {
-                               bottomspaceED->setEnabled(true);
-                               bottomspaceUnit->setEnabled(true);
-                       }
-                       break;
-               }
-       }
-       form_->changed();
-}
-
-
-void QTabularDialog::interlinespace_changed()
-{
-       switch(interlinespaceCO->currentIndex()) {
-               case 0: {
-                       form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "");
-                               interlinespaceED->setEnabled(false);
-                               interlinespaceUnit->setEnabled(false);
-                       break;
-               }
-               case 1: {
-                       form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "default");
-                       interlinespaceED->setEnabled(false);
-                       interlinespaceUnit->setEnabled(false);
-                       break;
-               }
-               case 2: {
-                       if (!interlinespaceED->text().isEmpty())
-                               form_->controller().set(LyXTabular::SET_INTERLINE_SPACE,
-                                       widgetsToLength(interlinespaceED, interlinespaceUnit));
-                       if (!form_->bc().bp().isReadOnly()) {
-                               interlinespaceED->setEnabled(true);
-                               interlinespaceUnit->setEnabled(true);
-                       }
-                       break;
-               }
-       }
-       form_->changed();
-}
-
-
-void QTabularDialog::close_clicked()
-{
-       form_->closeGUI();
-       form_->slotClose();
-}
-
-
-void QTabularDialog::borderSet_clicked()
-{
-       form_->controller().set(LyXTabular::SET_ALL_LINES);
-       form_->update_borders();
-       form_->changed();
-}
-
-
-void QTabularDialog::borderUnset_clicked()
-{
-       form_->controller().set(LyXTabular::UNSET_ALL_LINES);
-       form_->update_borders();
-       form_->changed();
-}
-
-
-void QTabularDialog::leftBorder_changed()
-{
-       form_->controller().toggleLeftLine();
-       form_->changed();
-}
-
-
-void QTabularDialog::rightBorder_changed()
-{
-       form_->controller().toggleRightLine();
-       form_->changed();
-}
-
-
-void QTabularDialog::topBorder_changed()
-{
-       form_->controller().toggleTopLine();
-       form_->changed();
-}
-
-
-void QTabularDialog::bottomBorder_changed()
-{
-       form_->controller().toggleBottomLine();
-       form_->changed();
-}
-
-
-void QTabularDialog::specialAlignment_changed()
-{
-       string special = fromqstr(specialAlignmentED->text());
-       form_->controller().setSpecial(special);
-       form_->changed();
-}
-
-
-void QTabularDialog::width_changed()
-{
-       form_->changed();
-       string const width = widgetsToLength(widthED, widthUnit);
-       form_->controller().setWidth(width);
-}
-
-
-void QTabularDialog::multicolumn_clicked()
-{
-       form_->controller().toggleMultiColumn();
-       form_->changed();
-}
-
-
-void QTabularDialog::rotateTabular()
-{
-       form_->controller().rotateTabular(rotateTabularCB->isChecked());
-       form_->changed();
-}
-
-
-void QTabularDialog::rotateCell()
-{
-       form_->controller().rotateCell(rotateCellCB->isChecked());
-       form_->changed();
-}
-
-
-void QTabularDialog::hAlign_changed(int align)
-{
-       ControlTabular::HALIGN h = ControlTabular::LEFT;
-
-       switch (align) {
-               case 0: h = ControlTabular::LEFT; break;
-               case 1: h = ControlTabular::CENTER; break;
-               case 2: h = ControlTabular::RIGHT; break;
-               case 3: h = ControlTabular::BLOCK; break;
-       }
-
-       form_->controller().halign(h);
-}
-
-
-void QTabularDialog::vAlign_changed(int align)
-{
-       ControlTabular::VALIGN v = ControlTabular::TOP;
-
-       switch (align) {
-               case 0: v = ControlTabular::TOP; break;
-               case 1: v = ControlTabular::MIDDLE; break;
-               case 2: v = ControlTabular::BOTTOM; break;
-       }
-
-       form_->controller().valign(v);
-}
-
-
-void QTabularDialog::longTabular()
-{
-       form_->controller().longTabular(longTabularCB->isChecked());
-       form_->changed();
-}
-
-
-void QTabularDialog::ltNewpage_clicked()
-{
-       form_->controller().set(LyXTabular::SET_LTNEWPAGE);
-       form_->changed();
-}
-
-
-void QTabularDialog::ltHeaderStatus_clicked()
-{
-       bool enable(headerStatusCB->isChecked());
-       if (enable)
-               form_->controller().set(LyXTabular::SET_LTHEAD, "");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
-       headerBorderAboveCB->setEnabled(enable);
-       headerBorderBelowCB->setEnabled(enable);
-       firstheaderNoContentsCB->setEnabled(enable);
-       form_->changed();
-}
-
-
-void QTabularDialog::ltHeaderBorderAbove_clicked()
-{
-       if (headerBorderAboveCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_above");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltHeaderBorderBelow_clicked()
-{
-       if (headerBorderBelowCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_below");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
-{
-       if (firstheaderBorderAboveCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_above");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
-{
-       if (firstheaderBorderBelowCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_below");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltFirstHeaderStatus_clicked()
-{
-       bool enable(firstheaderStatusCB->isChecked());
-       if (enable)
-               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
-       firstheaderBorderAboveCB->setEnabled(enable);
-       firstheaderBorderBelowCB->setEnabled(enable);
-       form_->changed();
-}
-
-
-void QTabularDialog::ltFirstHeaderEmpty_clicked()
-{
-       bool enable(firstheaderNoContentsCB->isChecked());
-       if (enable)
-               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "empty");
-       firstheaderStatusCB->setEnabled(!enable);
-       firstheaderBorderAboveCB->setEnabled(!enable);
-       firstheaderBorderBelowCB->setEnabled(!enable);
-       form_->changed();
-}
-
-
-void QTabularDialog::ltFooterStatus_clicked()
-{
-       bool enable(footerStatusCB->isChecked());
-       if (enable)
-               form_->controller().set(LyXTabular::SET_LTFOOT, "");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
-       footerBorderAboveCB->setEnabled(enable);
-       footerBorderBelowCB->setEnabled(enable);
-       lastfooterNoContentsCB->setEnabled(enable);
-       form_->changed();
-}
-
-
-void QTabularDialog::ltFooterBorderAbove_clicked()
-{
-       if (footerBorderAboveCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_above");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltFooterBorderBelow_clicked()
-{
-       if (footerBorderBelowCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_below");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltLastFooterStatus_clicked()
-{
-       bool enable(lastfooterStatusCB->isChecked());
-       if (enable)
-               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
-       lastfooterBorderAboveCB->setEnabled(enable);
-       lastfooterBorderBelowCB->setEnabled(enable);
-       form_->changed();
-}
-
-
-void QTabularDialog::ltLastFooterBorderAbove_clicked()
-{
-       if (lastfooterBorderAboveCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_above");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltLastFooterBorderBelow_clicked()
-{
-       if (lastfooterBorderBelowCB->isChecked())
-               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_below");
-       form_->changed();
-}
-
-
-void QTabularDialog::ltLastFooterEmpty_clicked()
-{
-       bool enable(lastfooterNoContentsCB->isChecked());
-       if (enable)
-               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
-       else
-               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "empty");
-       lastfooterStatusCB->setEnabled(!enable);
-       lastfooterBorderAboveCB->setEnabled(!enable);
-       lastfooterBorderBelowCB->setEnabled(!enable);
-       form_->changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QTabular
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlTabular, QView<QTabularDialog> > tabular_base_class;
-
-QTabular::QTabular(Dialog & parent)
-       : tabular_base_class(parent, _("Table Settings"))
-{
-}
-
-
-void QTabular::build_dialog()
-{
-       dialog_.reset(new QTabularDialog(this));
-
-       bcview().setCancel(dialog_->closePB);
-
-       bcview().addReadOnly(dialog_->topspaceED);
-       bcview().addReadOnly(dialog_->topspaceUnit);
-       bcview().addReadOnly(dialog_->topspaceCO);
-       bcview().addReadOnly(dialog_->bottomspaceED);
-       bcview().addReadOnly(dialog_->bottomspaceUnit);
-       bcview().addReadOnly(dialog_->bottomspaceCO);
-       bcview().addReadOnly(dialog_->interlinespaceED);
-       bcview().addReadOnly(dialog_->interlinespaceUnit);
-       bcview().addReadOnly(dialog_->interlinespaceCO);
-       bcview().addReadOnly(dialog_->borderDefaultRB);
-       bcview().addReadOnly(dialog_->booktabsRB);
-
-       bcview().addReadOnly(dialog_->multicolumnCB);
-       bcview().addReadOnly(dialog_->rotateCellCB);
-       bcview().addReadOnly(dialog_->rotateTabularCB);
-       bcview().addReadOnly(dialog_->specialAlignmentED);
-       bcview().addReadOnly(dialog_->widthED);
-       bcview().addReadOnly(dialog_->widthUnit);
-       bcview().addReadOnly(dialog_->hAlignCB);
-       bcview().addReadOnly(dialog_->vAlignCB);
-       bcview().addReadOnly(dialog_->borderSetPB);
-       bcview().addReadOnly(dialog_->borderUnsetPB);
-       bcview().addReadOnly(dialog_->borders);
-       bcview().addReadOnly(dialog_->longTabularCB);
-       bcview().addReadOnly(dialog_->headerStatusCB);
-       bcview().addReadOnly(dialog_->headerBorderAboveCB);
-       bcview().addReadOnly(dialog_->headerBorderBelowCB);
-       bcview().addReadOnly(dialog_->firstheaderStatusCB);
-       bcview().addReadOnly(dialog_->firstheaderBorderAboveCB);
-       bcview().addReadOnly(dialog_->firstheaderBorderBelowCB);
-       bcview().addReadOnly(dialog_->firstheaderNoContentsCB);
-       bcview().addReadOnly(dialog_->footerStatusCB);
-       bcview().addReadOnly(dialog_->footerBorderAboveCB);
-       bcview().addReadOnly(dialog_->footerBorderBelowCB);
-       bcview().addReadOnly(dialog_->lastfooterStatusCB);
-       bcview().addReadOnly(dialog_->lastfooterBorderAboveCB);
-       bcview().addReadOnly(dialog_->lastfooterBorderBelowCB);
-       bcview().addReadOnly(dialog_->lastfooterNoContentsCB);
-       bcview().addReadOnly(dialog_->newpageCB);
-
-       // initialize the length validator
-       addCheckedLineEdit(bcview(), dialog_->widthED,
-               dialog_->fixedWidthColLA);
-       addCheckedLineEdit(bcview(), dialog_->topspaceED,
-               dialog_->topspaceLA);
-       addCheckedLineEdit(bcview(), dialog_->bottomspaceED,
-               dialog_->bottomspaceLA);
-       addCheckedLineEdit(bcview(), dialog_->interlinespaceED,
-               dialog_->interlinespaceLA);
-}
-
-
-bool QTabular::isValid()
-{
-       return true;
-}
-
-
-void QTabular::update_borders()
-{
-       LyXTabular const & tabular = controller().tabular();
-       LyXTabular::idx_type const cell = controller().getActiveCell();
-       bool const isMulticolumnCell = tabular.isMultiColumn(cell);
-
-       if (!isMulticolumnCell) {
-               dialog_->borders->setLeftEnabled(true);
-               dialog_->borders->setRightEnabled(true);
-               dialog_->borders->setTop(tabular.topLine(cell, true));
-               dialog_->borders->setBottom(tabular.bottomLine(cell, true));
-               dialog_->borders->setLeft(tabular.leftLine(cell, true));
-               dialog_->borders->setRight(tabular.rightLine(cell, true));
-               // repaint the setborder widget
-               dialog_->borders->update();
-               return;
-       }
-
-       dialog_->borders->setTop(tabular.topLine(cell));
-       dialog_->borders->setBottom(tabular.bottomLine(cell));
-       // pay attention to left/right lines: they are only allowed
-       // to set if we are in first/last cell of row or if the left/right
-       // cell is also a multicolumn.
-       if (tabular.isFirstCellInRow(cell) || tabular.isMultiColumn(cell - 1)) {
-               dialog_->borders->setLeftEnabled(true);
-               dialog_->borders->setLeft(tabular.leftLine(cell));
-       } else {
-               dialog_->borders->setLeft(false);
-               dialog_->borders->setLeftEnabled(false);
-       }
-       if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) {
-               dialog_->borders->setRightEnabled(true);
-               dialog_->borders->setRight(tabular.rightLine(cell));
-       } else {
-               dialog_->borders->setRight(false);
-               dialog_->borders->setRightEnabled(false);
-       }
-       // repaint the setborder widget
-       dialog_->borders->update();
-}
-
-
-void QTabular::update_contents()
-{
-       LyXTabular const & tabular(controller().tabular());
-       LyXTabular::idx_type const cell = controller().getActiveCell();
-
-       LyXTabular::row_type const row(tabular.row_of_cell(cell));
-       LyXTabular::col_type const col(tabular.column_of_cell(cell));
-
-       dialog_->tabularRowED->setText(toqstr(convert<string>(row + 1)));
-       dialog_->tabularColumnED->setText(toqstr(convert<string>(col + 1)));
-
-       bool const multicol(tabular.isMultiColumn(cell));
-
-       dialog_->multicolumnCB->setChecked(multicol);
-
-       dialog_->rotateCellCB->setChecked(tabular.getRotateCell(cell));
-       dialog_->rotateTabularCB->setChecked(tabular.getRotateTabular());
-
-       dialog_->longTabularCB->setChecked(tabular.isLongTabular());
-
-       update_borders();
-
-       LyXLength pwidth;
-       docstring special;
-
-       if (multicol) {
-               special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
-               pwidth = tabular.getMColumnPWidth(cell);
-       } else {
-               special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
-               pwidth = tabular.getColumnPWidth(cell);
-       }
-
-       dialog_->specialAlignmentED->setText(toqstr(special));
-
-       bool const isReadonly = bc().bp().isReadOnly();
-       dialog_->specialAlignmentED->setEnabled(!isReadonly);
-
-       LyXLength::UNIT default_unit = controller().useMetricUnits() ? LyXLength::CM : LyXLength::IN;
-
-       dialog_->borderDefaultRB->setChecked(!tabular.useBookTabs());
-       dialog_->booktabsRB->setChecked(tabular.useBookTabs());
-
-       if (tabular.row_info[row].top_space.empty()
-           && !tabular.row_info[row].top_space_default) {
-               dialog_->topspaceCO->setCurrentIndex(0);
-       } else if (tabular.row_info[row].top_space_default) {
-               dialog_->topspaceCO->setCurrentIndex(1);
-       } else {
-               dialog_->topspaceCO->setCurrentIndex(2);
-               lengthToWidgets(dialog_->topspaceED, 
-                               dialog_->topspaceUnit,
-                               tabular.row_info[row].top_space.asString(),
-                               default_unit);
-       }
-       dialog_->topspaceED->setEnabled(!isReadonly 
-               && (dialog_->topspaceCO->currentIndex() == 2));
-       dialog_->topspaceUnit->setEnabled(!isReadonly 
-               && (dialog_->topspaceCO->currentIndex() == 2));
-       dialog_->topspaceCO->setEnabled(!isReadonly);
-
-       if (tabular.row_info[row].bottom_space.empty()
-           && !tabular.row_info[row].bottom_space_default) {
-               dialog_->bottomspaceCO->setCurrentIndex(0);
-       } else if (tabular.row_info[row].bottom_space_default) {
-               dialog_->bottomspaceCO->setCurrentIndex(1);
-       } else {
-               dialog_->bottomspaceCO->setCurrentIndex(2);
-               lengthToWidgets(dialog_->bottomspaceED, 
-                               dialog_->bottomspaceUnit,
-                               tabular.row_info[row].bottom_space.asString(),
-                               default_unit);
-       }
-       dialog_->bottomspaceED->setEnabled(!isReadonly 
-               && (dialog_->bottomspaceCO->currentIndex() == 2));
-       dialog_->bottomspaceUnit->setEnabled(!isReadonly 
-               && (dialog_->bottomspaceCO->currentIndex() == 2));
-       dialog_->bottomspaceCO->setEnabled(!isReadonly);
-
-       if (tabular.row_info[row].interline_space.empty()
-           && !tabular.row_info[row].interline_space_default) {
-               dialog_->interlinespaceCO->setCurrentIndex(0);
-       } else if (tabular.row_info[row].interline_space_default) {
-               dialog_->interlinespaceCO->setCurrentIndex(1);
-       } else {
-               dialog_->interlinespaceCO->setCurrentIndex(2);
-               lengthToWidgets(dialog_->interlinespaceED, 
-                               dialog_->interlinespaceUnit,
-                               tabular.row_info[row].interline_space.asString(),
-                               default_unit);
-       }
-       dialog_->interlinespaceED->setEnabled(!isReadonly 
-               && (dialog_->interlinespaceCO->currentIndex() == 2));
-       dialog_->interlinespaceUnit->setEnabled(!isReadonly 
-               && (dialog_->interlinespaceCO->currentIndex() == 2));
-       dialog_->interlinespaceCO->setEnabled(!isReadonly);
-
-       string colwidth;
-       if (!pwidth.zero())
-               colwidth = pwidth.asString();
-       lengthToWidgets(dialog_->widthED, dialog_->widthUnit,
-               colwidth, default_unit);
-
-       dialog_->widthED->setEnabled(!isReadonly);
-       dialog_->widthUnit->setEnabled(!isReadonly);
-
-       dialog_->hAlignCB->clear();
-       dialog_->hAlignCB->addItem(qt_("Left"));
-       dialog_->hAlignCB->addItem(qt_("Center"));
-       dialog_->hAlignCB->addItem(qt_("Right"));
-       if (!multicol && !pwidth.zero())
-               dialog_->hAlignCB->addItem(qt_("Justified"));
-
-       int align = 0;
-       switch (tabular.getAlignment(cell)) {
-       case LYX_ALIGN_LEFT:
-               align = 0;
-               break;
-       case LYX_ALIGN_CENTER:
-               align = 1;
-               break;
-       case LYX_ALIGN_RIGHT:
-               align = 2;
-               break;
-       case LYX_ALIGN_BLOCK:
-       {
-               if (!multicol && !pwidth.zero())
-                       align = 3;
-               break;
-       }
-       default:
-               align = 0;
-               break;
-       }
-       dialog_->hAlignCB->setCurrentIndex(align);
-
-       int valign = 0;
-       switch (tabular.getVAlignment(cell)) {
-       case LyXTabular::LYX_VALIGN_TOP:
-               valign = 0;
-               break;
-       case LyXTabular::LYX_VALIGN_MIDDLE:
-               valign = 1;
-               break;
-       case LyXTabular::LYX_VALIGN_BOTTOM:
-               valign = 2;
-               break;
-       default:
-               valign = 1;
-               break;
-       }
-       if (pwidth.zero())
-               valign = 1;
-       dialog_->vAlignCB->setCurrentIndex(valign);
-
-       dialog_->hAlignCB->setEnabled(true);
-       dialog_->vAlignCB->setEnabled(!pwidth.zero());
-
-       if (!tabular.isLongTabular()) {
-               dialog_->headerStatusCB->setChecked(false);
-               dialog_->headerBorderAboveCB->setChecked(false);
-               dialog_->headerBorderBelowCB->setChecked(false);
-               dialog_->firstheaderStatusCB->setChecked(false);
-               dialog_->firstheaderBorderAboveCB->setChecked(false);
-               dialog_->firstheaderBorderBelowCB->setChecked(false);
-               dialog_->firstheaderNoContentsCB->setChecked(false);
-               dialog_->footerStatusCB->setChecked(false);
-               dialog_->footerBorderAboveCB->setChecked(false);
-               dialog_->footerBorderBelowCB->setChecked(false);
-               dialog_->lastfooterStatusCB->setChecked(false);
-               dialog_->lastfooterBorderAboveCB->setChecked(false);
-               dialog_->lastfooterBorderBelowCB->setChecked(false);
-               dialog_->lastfooterNoContentsCB->setChecked(false);
-               dialog_->newpageCB->setChecked(false);
-               dialog_->newpageCB->setEnabled(false);
-               return;
-       }
-
-       LyXTabular::ltType ltt;
-       bool use_empty;
-       bool row_set = tabular.getRowOfLTHead(row, ltt);
-       dialog_->headerStatusCB->setChecked(row_set);
-       if (ltt.set) {
-               dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
-               use_empty = true;
-       } else {
-               dialog_->headerBorderAboveCB->setChecked(false);
-               dialog_->headerBorderBelowCB->setChecked(false);
-               dialog_->headerBorderAboveCB->setEnabled(false);
-               dialog_->headerBorderBelowCB->setEnabled(false);
-               dialog_->firstheaderNoContentsCB->setChecked(false);
-               dialog_->firstheaderNoContentsCB->setEnabled(false);
-               use_empty = false;
-       }
-
-       row_set = tabular.getRowOfLTFirstHead(row, ltt);
-       dialog_->firstheaderStatusCB->setChecked(row_set);
-       if (ltt.set && (!ltt.empty || !use_empty)) {
-               dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
-       } else {
-               dialog_->firstheaderBorderAboveCB->setEnabled(false);
-               dialog_->firstheaderBorderBelowCB->setEnabled(false);
-               dialog_->firstheaderBorderAboveCB->setChecked(false);
-               dialog_->firstheaderBorderBelowCB->setChecked(false);
-               if (use_empty) {
-                       dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
-                       if (ltt.empty)
-                               dialog_->firstheaderStatusCB->setEnabled(false);
-               }
-       }
-
-       row_set = tabular.getRowOfLTFoot(row, ltt);
-       dialog_->footerStatusCB->setChecked(row_set);
-       if (ltt.set) {
-               dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
-               use_empty = true;
-       } else {
-               dialog_->footerBorderAboveCB->setChecked(false);
-               dialog_->footerBorderBelowCB->setChecked(false);
-               dialog_->footerBorderAboveCB->setEnabled(false);
-               dialog_->footerBorderBelowCB->setEnabled(false);
-               dialog_->lastfooterNoContentsCB->setChecked(false);
-               dialog_->lastfooterNoContentsCB->setEnabled(false);
-               use_empty = false;
-       }
-
-       row_set = tabular.getRowOfLTLastFoot(row, ltt);
-               dialog_->lastfooterStatusCB->setChecked(row_set);
-       if (ltt.set && (!ltt.empty || !use_empty)) {
-               dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
-               dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
-       } else {
-               dialog_->lastfooterBorderAboveCB->setEnabled(false);
-               dialog_->lastfooterBorderBelowCB->setEnabled(false);
-               dialog_->lastfooterBorderAboveCB->setChecked(false);
-               dialog_->lastfooterBorderBelowCB->setChecked(false);
-               if (use_empty) {
-                       dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
-                       if (ltt.empty)
-                               dialog_->lastfooterStatusCB->setEnabled(false);
-               }
-       }
-       dialog_->newpageCB->setChecked(tabular.getLTNewPage(row));
-}
-
-
-void QTabular::closeGUI()
-{
-       // ugly hack to auto-apply the stuff that hasn't been
-       // yet. don't let this continue to exist ...
-
-       // Subtle here, we must /not/ apply any changes and
-       // then refer to tabular, as it will have been freed
-       // since the changes update the actual controller().tabular()
-       LyXTabular const & tabular(controller().tabular());
-
-       // apply the fixed width values
-       LyXTabular::idx_type const cell = controller().getActiveCell();
-       bool const multicol = tabular.isMultiColumn(cell);
-       string width = widgetsToLength(dialog_->widthED, dialog_->widthUnit);
-       string width2;
-
-       LyXLength llen = tabular.getColumnPWidth(cell);
-       LyXLength llenMulti = tabular.getMColumnPWidth(cell);
-
-       if (multicol && !llenMulti.zero())
-                       width2 = llenMulti.asString();
-       else if (!multicol && !llen.zero())
-                       width2 = llen.asString();
-
-       // apply the special alignment
-       docstring const sa1 = qstring_to_ucs4(dialog_->specialAlignmentED->text());
-       docstring sa2;
-
-       if (multicol)
-               sa2 = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
-       else
-               sa2 = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
-
-       if (sa1 != sa2) {
-               if (multicol)
-                       controller().set(LyXTabular::SET_SPECIAL_MULTI, to_utf8(sa1));
-               else
-                       controller().set(LyXTabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
-       }
-
-       if (width != width2) {
-               if (multicol)
-                       controller().set(LyXTabular::SET_MPWIDTH, width);
-               else
-                       controller().set(LyXTabular::SET_PWIDTH, width);
-       }
-
-       /* DO WE NEED THIS?
-       switch (dialog_->topspaceCO->currentIndex()) {
-               case 0:
-                       controller().set(LyXTabular::SET_TOP_SPACE, "");
-                       break;
-               case 1:
-                       controller().set(LyXTabular::SET_TOP_SPACE, "default");
-                       break;
-               case 2:
-                       controller().set(LyXTabular::SET_TOP_SPACE,
-                               widgetsToLength(dialog_->topspaceED, 
-                                       dialog_->topspaceUnit));
-                       break;
-       }
-
-       switch (dialog_->bottomspaceCO->currentIndex()) {
-               case 0:
-                       controller().set(LyXTabular::SET_BOTTOM_SPACE, "");
-                       break;
-               case 1:
-                       controller().set(LyXTabular::SET_BOTTOM_SPACE, "default");
-                       break;
-               case 2:
-                       controller().set(LyXTabular::SET_BOTTOM_SPACE,
-                               widgetsToLength(dialog_->bottomspaceED, 
-                                       dialog_->bottomspaceUnit));
-                       break;
-       }
-
-       switch (dialog_->interlinespaceCO->currentIndex()) {
-               case 0:
-                       controller().set(LyXTabular::SET_INTERLINE_SPACE, "");
-                       break;
-               case 1:
-                       controller().set(LyXTabular::SET_INTERLINE_SPACE, "default");
-                       break;
-               case 2:
-                       controller().set(LyXTabular::SET_INTERLINE_SPACE,
-                               widgetsToLength(dialog_->interlinespaceED, 
-                                       dialog_->interlinespaceUnit));
-                       break;
-       }
-*/
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QTabular_moc.cpp"
-
diff --git a/src/frontends/qt4/QTabular.cpp b/src/frontends/qt4/QTabular.cpp
new file mode 100644 (file)
index 0000000..8ea0540
--- /dev/null
@@ -0,0 +1,979 @@
+/**
+ * \file QTabular.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Jürgen Spitzmüller
+ * \author Herbert Voß
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "CheckedLineEdit.h"
+#include "QTabular.h"
+#include "Qt2BC.h"
+
+#include "LengthCombo.h"
+#include "Validator.h"
+#include "qt_helpers.h"
+
+#include "controllers/ButtonController.h"
+#include "controllers/ControlTabular.h"
+
+#include "support/convert.h"
+
+#include <QCloseEvent>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QLineEdit>
+
+#include "QSetBorder.h"
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QTabularDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QTabularDialog::QTabularDialog(QTabular * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       widthED->setValidator(unsignedLengthValidator(widthED));
+       topspaceED->setValidator(new LengthValidator(topspaceED));
+       bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
+       interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
+
+       connect(topspaceED, SIGNAL(returnPressed()),
+               this, SLOT(topspace_changed()));
+       connect(topspaceUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(topspace_changed()));
+       connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed()));
+       connect(bottomspaceED, SIGNAL(returnPressed()),
+               this, SLOT(bottomspace_changed()));
+       connect(bottomspaceUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(bottomspace_changed()));
+       connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
+       connect(interlinespaceED, SIGNAL(returnPressed()),
+               this, SLOT(interlinespace_changed()));
+       connect(interlinespaceUnit, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(interlinespace_changed()));
+       connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
+       connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
+       connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
+       connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
+       connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
+       connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
+       connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
+       connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
+       connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
+       connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
+       connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
+       connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
+       connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
+       connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
+       connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
+       connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
+       connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
+       connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
+       connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
+       connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
+       connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
+       connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
+       connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
+       connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
+       connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
+       connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
+       connect(widthED, SIGNAL(returnPressed()), this, SLOT(width_changed()));
+       connect(widthUnit, SIGNAL(selectionChanged(LyXLength::UNIT)), this, SLOT(width_changed()));
+       connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
+       connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
+       connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
+       connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
+       connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
+       connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
+       connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
+       connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
+}
+
+
+void QTabularDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QTabularDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QTabularDialog::booktabsChanged(bool)
+{
+       form_->changed();
+       form_->controller().booktabs(booktabsRB->isChecked());
+       form_->update_borders();
+}
+
+
+void QTabularDialog::topspace_changed()
+{
+       switch(topspaceCO->currentIndex()) {
+               case 0: {
+                       form_->controller().set(LyXTabular::SET_TOP_SPACE, "");
+                               topspaceED->setEnabled(false);
+                               topspaceUnit->setEnabled(false);
+                       break;
+               }
+               case 1: {
+                       form_->controller().set(LyXTabular::SET_TOP_SPACE, "default");
+                       topspaceED->setEnabled(false);
+                       topspaceUnit->setEnabled(false);
+                       break;
+               }
+               case 2: {
+                       if (!topspaceED->text().isEmpty())
+                               form_->controller().set(LyXTabular::SET_TOP_SPACE,
+                                       widgetsToLength(topspaceED, topspaceUnit));
+                       if (!form_->bc().bp().isReadOnly()) {
+                               topspaceED->setEnabled(true);
+                               topspaceUnit->setEnabled(true);
+                       }
+                       break;
+               }
+       }
+       form_->changed();
+}
+
+
+void QTabularDialog::bottomspace_changed()
+{
+       switch(bottomspaceCO->currentIndex()) {
+               case 0: {
+                       form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "");
+                               bottomspaceED->setEnabled(false);
+                               bottomspaceUnit->setEnabled(false);
+                       break;
+               }
+               case 1: {
+                       form_->controller().set(LyXTabular::SET_BOTTOM_SPACE, "default");
+                       bottomspaceED->setEnabled(false);
+                       bottomspaceUnit->setEnabled(false);
+                       break;
+               }
+               case 2: {
+                       if (!bottomspaceED->text().isEmpty())
+                               form_->controller().set(LyXTabular::SET_BOTTOM_SPACE,
+                                       widgetsToLength(bottomspaceED, bottomspaceUnit));
+                       if (!form_->bc().bp().isReadOnly()) {
+                               bottomspaceED->setEnabled(true);
+                               bottomspaceUnit->setEnabled(true);
+                       }
+                       break;
+               }
+       }
+       form_->changed();
+}
+
+
+void QTabularDialog::interlinespace_changed()
+{
+       switch(interlinespaceCO->currentIndex()) {
+               case 0: {
+                       form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "");
+                               interlinespaceED->setEnabled(false);
+                               interlinespaceUnit->setEnabled(false);
+                       break;
+               }
+               case 1: {
+                       form_->controller().set(LyXTabular::SET_INTERLINE_SPACE, "default");
+                       interlinespaceED->setEnabled(false);
+                       interlinespaceUnit->setEnabled(false);
+                       break;
+               }
+               case 2: {
+                       if (!interlinespaceED->text().isEmpty())
+                               form_->controller().set(LyXTabular::SET_INTERLINE_SPACE,
+                                       widgetsToLength(interlinespaceED, interlinespaceUnit));
+                       if (!form_->bc().bp().isReadOnly()) {
+                               interlinespaceED->setEnabled(true);
+                               interlinespaceUnit->setEnabled(true);
+                       }
+                       break;
+               }
+       }
+       form_->changed();
+}
+
+
+void QTabularDialog::close_clicked()
+{
+       form_->closeGUI();
+       form_->slotClose();
+}
+
+
+void QTabularDialog::borderSet_clicked()
+{
+       form_->controller().set(LyXTabular::SET_ALL_LINES);
+       form_->update_borders();
+       form_->changed();
+}
+
+
+void QTabularDialog::borderUnset_clicked()
+{
+       form_->controller().set(LyXTabular::UNSET_ALL_LINES);
+       form_->update_borders();
+       form_->changed();
+}
+
+
+void QTabularDialog::leftBorder_changed()
+{
+       form_->controller().toggleLeftLine();
+       form_->changed();
+}
+
+
+void QTabularDialog::rightBorder_changed()
+{
+       form_->controller().toggleRightLine();
+       form_->changed();
+}
+
+
+void QTabularDialog::topBorder_changed()
+{
+       form_->controller().toggleTopLine();
+       form_->changed();
+}
+
+
+void QTabularDialog::bottomBorder_changed()
+{
+       form_->controller().toggleBottomLine();
+       form_->changed();
+}
+
+
+void QTabularDialog::specialAlignment_changed()
+{
+       string special = fromqstr(specialAlignmentED->text());
+       form_->controller().setSpecial(special);
+       form_->changed();
+}
+
+
+void QTabularDialog::width_changed()
+{
+       form_->changed();
+       string const width = widgetsToLength(widthED, widthUnit);
+       form_->controller().setWidth(width);
+}
+
+
+void QTabularDialog::multicolumn_clicked()
+{
+       form_->controller().toggleMultiColumn();
+       form_->changed();
+}
+
+
+void QTabularDialog::rotateTabular()
+{
+       form_->controller().rotateTabular(rotateTabularCB->isChecked());
+       form_->changed();
+}
+
+
+void QTabularDialog::rotateCell()
+{
+       form_->controller().rotateCell(rotateCellCB->isChecked());
+       form_->changed();
+}
+
+
+void QTabularDialog::hAlign_changed(int align)
+{
+       ControlTabular::HALIGN h = ControlTabular::LEFT;
+
+       switch (align) {
+               case 0: h = ControlTabular::LEFT; break;
+               case 1: h = ControlTabular::CENTER; break;
+               case 2: h = ControlTabular::RIGHT; break;
+               case 3: h = ControlTabular::BLOCK; break;
+       }
+
+       form_->controller().halign(h);
+}
+
+
+void QTabularDialog::vAlign_changed(int align)
+{
+       ControlTabular::VALIGN v = ControlTabular::TOP;
+
+       switch (align) {
+               case 0: v = ControlTabular::TOP; break;
+               case 1: v = ControlTabular::MIDDLE; break;
+               case 2: v = ControlTabular::BOTTOM; break;
+       }
+
+       form_->controller().valign(v);
+}
+
+
+void QTabularDialog::longTabular()
+{
+       form_->controller().longTabular(longTabularCB->isChecked());
+       form_->changed();
+}
+
+
+void QTabularDialog::ltNewpage_clicked()
+{
+       form_->controller().set(LyXTabular::SET_LTNEWPAGE);
+       form_->changed();
+}
+
+
+void QTabularDialog::ltHeaderStatus_clicked()
+{
+       bool enable(headerStatusCB->isChecked());
+       if (enable)
+               form_->controller().set(LyXTabular::SET_LTHEAD, "");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTHEAD, "");
+       headerBorderAboveCB->setEnabled(enable);
+       headerBorderBelowCB->setEnabled(enable);
+       firstheaderNoContentsCB->setEnabled(enable);
+       form_->changed();
+}
+
+
+void QTabularDialog::ltHeaderBorderAbove_clicked()
+{
+       if (headerBorderAboveCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTHEAD, "dl_above");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_above");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltHeaderBorderBelow_clicked()
+{
+       if (headerBorderBelowCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTHEAD, "dl_below");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTHEAD, "dl_below");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltFirstHeaderBorderAbove_clicked()
+{
+       if (firstheaderBorderAboveCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_above");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_above");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltFirstHeaderBorderBelow_clicked()
+{
+       if (firstheaderBorderBelowCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "dl_below");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "dl_below");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltFirstHeaderStatus_clicked()
+{
+       bool enable(firstheaderStatusCB->isChecked());
+       if (enable)
+               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "");
+       firstheaderBorderAboveCB->setEnabled(enable);
+       firstheaderBorderBelowCB->setEnabled(enable);
+       form_->changed();
+}
+
+
+void QTabularDialog::ltFirstHeaderEmpty_clicked()
+{
+       bool enable(firstheaderNoContentsCB->isChecked());
+       if (enable)
+               form_->controller().set(LyXTabular::SET_LTFIRSTHEAD, "empty");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTFIRSTHEAD, "empty");
+       firstheaderStatusCB->setEnabled(!enable);
+       firstheaderBorderAboveCB->setEnabled(!enable);
+       firstheaderBorderBelowCB->setEnabled(!enable);
+       form_->changed();
+}
+
+
+void QTabularDialog::ltFooterStatus_clicked()
+{
+       bool enable(footerStatusCB->isChecked());
+       if (enable)
+               form_->controller().set(LyXTabular::SET_LTFOOT, "");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTFOOT, "");
+       footerBorderAboveCB->setEnabled(enable);
+       footerBorderBelowCB->setEnabled(enable);
+       lastfooterNoContentsCB->setEnabled(enable);
+       form_->changed();
+}
+
+
+void QTabularDialog::ltFooterBorderAbove_clicked()
+{
+       if (footerBorderAboveCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTFOOT, "dl_above");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_above");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltFooterBorderBelow_clicked()
+{
+       if (footerBorderBelowCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTFOOT, "dl_below");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTFOOT, "dl_below");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltLastFooterStatus_clicked()
+{
+       bool enable(lastfooterStatusCB->isChecked());
+       if (enable)
+               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "");
+       lastfooterBorderAboveCB->setEnabled(enable);
+       lastfooterBorderBelowCB->setEnabled(enable);
+       form_->changed();
+}
+
+
+void QTabularDialog::ltLastFooterBorderAbove_clicked()
+{
+       if (lastfooterBorderAboveCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_above");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_above");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltLastFooterBorderBelow_clicked()
+{
+       if (lastfooterBorderBelowCB->isChecked())
+               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "dl_below");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "dl_below");
+       form_->changed();
+}
+
+
+void QTabularDialog::ltLastFooterEmpty_clicked()
+{
+       bool enable(lastfooterNoContentsCB->isChecked());
+       if (enable)
+               form_->controller().set(LyXTabular::SET_LTLASTFOOT, "empty");
+       else
+               form_->controller().set(LyXTabular::UNSET_LTLASTFOOT, "empty");
+       lastfooterStatusCB->setEnabled(!enable);
+       lastfooterBorderAboveCB->setEnabled(!enable);
+       lastfooterBorderBelowCB->setEnabled(!enable);
+       form_->changed();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QTabular
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlTabular, QView<QTabularDialog> > tabular_base_class;
+
+QTabular::QTabular(Dialog & parent)
+       : tabular_base_class(parent, _("Table Settings"))
+{
+}
+
+
+void QTabular::build_dialog()
+{
+       dialog_.reset(new QTabularDialog(this));
+
+       bcview().setCancel(dialog_->closePB);
+
+       bcview().addReadOnly(dialog_->topspaceED);
+       bcview().addReadOnly(dialog_->topspaceUnit);
+       bcview().addReadOnly(dialog_->topspaceCO);
+       bcview().addReadOnly(dialog_->bottomspaceED);
+       bcview().addReadOnly(dialog_->bottomspaceUnit);
+       bcview().addReadOnly(dialog_->bottomspaceCO);
+       bcview().addReadOnly(dialog_->interlinespaceED);
+       bcview().addReadOnly(dialog_->interlinespaceUnit);
+       bcview().addReadOnly(dialog_->interlinespaceCO);
+       bcview().addReadOnly(dialog_->borderDefaultRB);
+       bcview().addReadOnly(dialog_->booktabsRB);
+
+       bcview().addReadOnly(dialog_->multicolumnCB);
+       bcview().addReadOnly(dialog_->rotateCellCB);
+       bcview().addReadOnly(dialog_->rotateTabularCB);
+       bcview().addReadOnly(dialog_->specialAlignmentED);
+       bcview().addReadOnly(dialog_->widthED);
+       bcview().addReadOnly(dialog_->widthUnit);
+       bcview().addReadOnly(dialog_->hAlignCB);
+       bcview().addReadOnly(dialog_->vAlignCB);
+       bcview().addReadOnly(dialog_->borderSetPB);
+       bcview().addReadOnly(dialog_->borderUnsetPB);
+       bcview().addReadOnly(dialog_->borders);
+       bcview().addReadOnly(dialog_->longTabularCB);
+       bcview().addReadOnly(dialog_->headerStatusCB);
+       bcview().addReadOnly(dialog_->headerBorderAboveCB);
+       bcview().addReadOnly(dialog_->headerBorderBelowCB);
+       bcview().addReadOnly(dialog_->firstheaderStatusCB);
+       bcview().addReadOnly(dialog_->firstheaderBorderAboveCB);
+       bcview().addReadOnly(dialog_->firstheaderBorderBelowCB);
+       bcview().addReadOnly(dialog_->firstheaderNoContentsCB);
+       bcview().addReadOnly(dialog_->footerStatusCB);
+       bcview().addReadOnly(dialog_->footerBorderAboveCB);
+       bcview().addReadOnly(dialog_->footerBorderBelowCB);
+       bcview().addReadOnly(dialog_->lastfooterStatusCB);
+       bcview().addReadOnly(dialog_->lastfooterBorderAboveCB);
+       bcview().addReadOnly(dialog_->lastfooterBorderBelowCB);
+       bcview().addReadOnly(dialog_->lastfooterNoContentsCB);
+       bcview().addReadOnly(dialog_->newpageCB);
+
+       // initialize the length validator
+       addCheckedLineEdit(bcview(), dialog_->widthED,
+               dialog_->fixedWidthColLA);
+       addCheckedLineEdit(bcview(), dialog_->topspaceED,
+               dialog_->topspaceLA);
+       addCheckedLineEdit(bcview(), dialog_->bottomspaceED,
+               dialog_->bottomspaceLA);
+       addCheckedLineEdit(bcview(), dialog_->interlinespaceED,
+               dialog_->interlinespaceLA);
+}
+
+
+bool QTabular::isValid()
+{
+       return true;
+}
+
+
+void QTabular::update_borders()
+{
+       LyXTabular const & tabular = controller().tabular();
+       LyXTabular::idx_type const cell = controller().getActiveCell();
+       bool const isMulticolumnCell = tabular.isMultiColumn(cell);
+
+       if (!isMulticolumnCell) {
+               dialog_->borders->setLeftEnabled(true);
+               dialog_->borders->setRightEnabled(true);
+               dialog_->borders->setTop(tabular.topLine(cell, true));
+               dialog_->borders->setBottom(tabular.bottomLine(cell, true));
+               dialog_->borders->setLeft(tabular.leftLine(cell, true));
+               dialog_->borders->setRight(tabular.rightLine(cell, true));
+               // repaint the setborder widget
+               dialog_->borders->update();
+               return;
+       }
+
+       dialog_->borders->setTop(tabular.topLine(cell));
+       dialog_->borders->setBottom(tabular.bottomLine(cell));
+       // pay attention to left/right lines: they are only allowed
+       // to set if we are in first/last cell of row or if the left/right
+       // cell is also a multicolumn.
+       if (tabular.isFirstCellInRow(cell) || tabular.isMultiColumn(cell - 1)) {
+               dialog_->borders->setLeftEnabled(true);
+               dialog_->borders->setLeft(tabular.leftLine(cell));
+       } else {
+               dialog_->borders->setLeft(false);
+               dialog_->borders->setLeftEnabled(false);
+       }
+       if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) {
+               dialog_->borders->setRightEnabled(true);
+               dialog_->borders->setRight(tabular.rightLine(cell));
+       } else {
+               dialog_->borders->setRight(false);
+               dialog_->borders->setRightEnabled(false);
+       }
+       // repaint the setborder widget
+       dialog_->borders->update();
+}
+
+
+void QTabular::update_contents()
+{
+       LyXTabular const & tabular(controller().tabular());
+       LyXTabular::idx_type const cell = controller().getActiveCell();
+
+       LyXTabular::row_type const row(tabular.row_of_cell(cell));
+       LyXTabular::col_type const col(tabular.column_of_cell(cell));
+
+       dialog_->tabularRowED->setText(toqstr(convert<string>(row + 1)));
+       dialog_->tabularColumnED->setText(toqstr(convert<string>(col + 1)));
+
+       bool const multicol(tabular.isMultiColumn(cell));
+
+       dialog_->multicolumnCB->setChecked(multicol);
+
+       dialog_->rotateCellCB->setChecked(tabular.getRotateCell(cell));
+       dialog_->rotateTabularCB->setChecked(tabular.getRotateTabular());
+
+       dialog_->longTabularCB->setChecked(tabular.isLongTabular());
+
+       update_borders();
+
+       LyXLength pwidth;
+       docstring special;
+
+       if (multicol) {
+               special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
+               pwidth = tabular.getMColumnPWidth(cell);
+       } else {
+               special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
+               pwidth = tabular.getColumnPWidth(cell);
+       }
+
+       dialog_->specialAlignmentED->setText(toqstr(special));
+
+       bool const isReadonly = bc().bp().isReadOnly();
+       dialog_->specialAlignmentED->setEnabled(!isReadonly);
+
+       LyXLength::UNIT default_unit = controller().useMetricUnits() ? LyXLength::CM : LyXLength::IN;
+
+       dialog_->borderDefaultRB->setChecked(!tabular.useBookTabs());
+       dialog_->booktabsRB->setChecked(tabular.useBookTabs());
+
+       if (tabular.row_info[row].top_space.empty()
+           && !tabular.row_info[row].top_space_default) {
+               dialog_->topspaceCO->setCurrentIndex(0);
+       } else if (tabular.row_info[row].top_space_default) {
+               dialog_->topspaceCO->setCurrentIndex(1);
+       } else {
+               dialog_->topspaceCO->setCurrentIndex(2);
+               lengthToWidgets(dialog_->topspaceED, 
+                               dialog_->topspaceUnit,
+                               tabular.row_info[row].top_space.asString(),
+                               default_unit);
+       }
+       dialog_->topspaceED->setEnabled(!isReadonly 
+               && (dialog_->topspaceCO->currentIndex() == 2));
+       dialog_->topspaceUnit->setEnabled(!isReadonly 
+               && (dialog_->topspaceCO->currentIndex() == 2));
+       dialog_->topspaceCO->setEnabled(!isReadonly);
+
+       if (tabular.row_info[row].bottom_space.empty()
+           && !tabular.row_info[row].bottom_space_default) {
+               dialog_->bottomspaceCO->setCurrentIndex(0);
+       } else if (tabular.row_info[row].bottom_space_default) {
+               dialog_->bottomspaceCO->setCurrentIndex(1);
+       } else {
+               dialog_->bottomspaceCO->setCurrentIndex(2);
+               lengthToWidgets(dialog_->bottomspaceED, 
+                               dialog_->bottomspaceUnit,
+                               tabular.row_info[row].bottom_space.asString(),
+                               default_unit);
+       }
+       dialog_->bottomspaceED->setEnabled(!isReadonly 
+               && (dialog_->bottomspaceCO->currentIndex() == 2));
+       dialog_->bottomspaceUnit->setEnabled(!isReadonly 
+               && (dialog_->bottomspaceCO->currentIndex() == 2));
+       dialog_->bottomspaceCO->setEnabled(!isReadonly);
+
+       if (tabular.row_info[row].interline_space.empty()
+           && !tabular.row_info[row].interline_space_default) {
+               dialog_->interlinespaceCO->setCurrentIndex(0);
+       } else if (tabular.row_info[row].interline_space_default) {
+               dialog_->interlinespaceCO->setCurrentIndex(1);
+       } else {
+               dialog_->interlinespaceCO->setCurrentIndex(2);
+               lengthToWidgets(dialog_->interlinespaceED, 
+                               dialog_->interlinespaceUnit,
+                               tabular.row_info[row].interline_space.asString(),
+                               default_unit);
+       }
+       dialog_->interlinespaceED->setEnabled(!isReadonly 
+               && (dialog_->interlinespaceCO->currentIndex() == 2));
+       dialog_->interlinespaceUnit->setEnabled(!isReadonly 
+               && (dialog_->interlinespaceCO->currentIndex() == 2));
+       dialog_->interlinespaceCO->setEnabled(!isReadonly);
+
+       string colwidth;
+       if (!pwidth.zero())
+               colwidth = pwidth.asString();
+       lengthToWidgets(dialog_->widthED, dialog_->widthUnit,
+               colwidth, default_unit);
+
+       dialog_->widthED->setEnabled(!isReadonly);
+       dialog_->widthUnit->setEnabled(!isReadonly);
+
+       dialog_->hAlignCB->clear();
+       dialog_->hAlignCB->addItem(qt_("Left"));
+       dialog_->hAlignCB->addItem(qt_("Center"));
+       dialog_->hAlignCB->addItem(qt_("Right"));
+       if (!multicol && !pwidth.zero())
+               dialog_->hAlignCB->addItem(qt_("Justified"));
+
+       int align = 0;
+       switch (tabular.getAlignment(cell)) {
+       case LYX_ALIGN_LEFT:
+               align = 0;
+               break;
+       case LYX_ALIGN_CENTER:
+               align = 1;
+               break;
+       case LYX_ALIGN_RIGHT:
+               align = 2;
+               break;
+       case LYX_ALIGN_BLOCK:
+       {
+               if (!multicol && !pwidth.zero())
+                       align = 3;
+               break;
+       }
+       default:
+               align = 0;
+               break;
+       }
+       dialog_->hAlignCB->setCurrentIndex(align);
+
+       int valign = 0;
+       switch (tabular.getVAlignment(cell)) {
+       case LyXTabular::LYX_VALIGN_TOP:
+               valign = 0;
+               break;
+       case LyXTabular::LYX_VALIGN_MIDDLE:
+               valign = 1;
+               break;
+       case LyXTabular::LYX_VALIGN_BOTTOM:
+               valign = 2;
+               break;
+       default:
+               valign = 1;
+               break;
+       }
+       if (pwidth.zero())
+               valign = 1;
+       dialog_->vAlignCB->setCurrentIndex(valign);
+
+       dialog_->hAlignCB->setEnabled(true);
+       dialog_->vAlignCB->setEnabled(!pwidth.zero());
+
+       if (!tabular.isLongTabular()) {
+               dialog_->headerStatusCB->setChecked(false);
+               dialog_->headerBorderAboveCB->setChecked(false);
+               dialog_->headerBorderBelowCB->setChecked(false);
+               dialog_->firstheaderStatusCB->setChecked(false);
+               dialog_->firstheaderBorderAboveCB->setChecked(false);
+               dialog_->firstheaderBorderBelowCB->setChecked(false);
+               dialog_->firstheaderNoContentsCB->setChecked(false);
+               dialog_->footerStatusCB->setChecked(false);
+               dialog_->footerBorderAboveCB->setChecked(false);
+               dialog_->footerBorderBelowCB->setChecked(false);
+               dialog_->lastfooterStatusCB->setChecked(false);
+               dialog_->lastfooterBorderAboveCB->setChecked(false);
+               dialog_->lastfooterBorderBelowCB->setChecked(false);
+               dialog_->lastfooterNoContentsCB->setChecked(false);
+               dialog_->newpageCB->setChecked(false);
+               dialog_->newpageCB->setEnabled(false);
+               return;
+       }
+
+       LyXTabular::ltType ltt;
+       bool use_empty;
+       bool row_set = tabular.getRowOfLTHead(row, ltt);
+       dialog_->headerStatusCB->setChecked(row_set);
+       if (ltt.set) {
+               dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
+               dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
+               use_empty = true;
+       } else {
+               dialog_->headerBorderAboveCB->setChecked(false);
+               dialog_->headerBorderBelowCB->setChecked(false);
+               dialog_->headerBorderAboveCB->setEnabled(false);
+               dialog_->headerBorderBelowCB->setEnabled(false);
+               dialog_->firstheaderNoContentsCB->setChecked(false);
+               dialog_->firstheaderNoContentsCB->setEnabled(false);
+               use_empty = false;
+       }
+
+       row_set = tabular.getRowOfLTFirstHead(row, ltt);
+       dialog_->firstheaderStatusCB->setChecked(row_set);
+       if (ltt.set && (!ltt.empty || !use_empty)) {
+               dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
+               dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
+       } else {
+               dialog_->firstheaderBorderAboveCB->setEnabled(false);
+               dialog_->firstheaderBorderBelowCB->setEnabled(false);
+               dialog_->firstheaderBorderAboveCB->setChecked(false);
+               dialog_->firstheaderBorderBelowCB->setChecked(false);
+               if (use_empty) {
+                       dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
+                       if (ltt.empty)
+                               dialog_->firstheaderStatusCB->setEnabled(false);
+               }
+       }
+
+       row_set = tabular.getRowOfLTFoot(row, ltt);
+       dialog_->footerStatusCB->setChecked(row_set);
+       if (ltt.set) {
+               dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
+               dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
+               use_empty = true;
+       } else {
+               dialog_->footerBorderAboveCB->setChecked(false);
+               dialog_->footerBorderBelowCB->setChecked(false);
+               dialog_->footerBorderAboveCB->setEnabled(false);
+               dialog_->footerBorderBelowCB->setEnabled(false);
+               dialog_->lastfooterNoContentsCB->setChecked(false);
+               dialog_->lastfooterNoContentsCB->setEnabled(false);
+               use_empty = false;
+       }
+
+       row_set = tabular.getRowOfLTLastFoot(row, ltt);
+               dialog_->lastfooterStatusCB->setChecked(row_set);
+       if (ltt.set && (!ltt.empty || !use_empty)) {
+               dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
+               dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
+       } else {
+               dialog_->lastfooterBorderAboveCB->setEnabled(false);
+               dialog_->lastfooterBorderBelowCB->setEnabled(false);
+               dialog_->lastfooterBorderAboveCB->setChecked(false);
+               dialog_->lastfooterBorderBelowCB->setChecked(false);
+               if (use_empty) {
+                       dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
+                       if (ltt.empty)
+                               dialog_->lastfooterStatusCB->setEnabled(false);
+               }
+       }
+       dialog_->newpageCB->setChecked(tabular.getLTNewPage(row));
+}
+
+
+void QTabular::closeGUI()
+{
+       // ugly hack to auto-apply the stuff that hasn't been
+       // yet. don't let this continue to exist ...
+
+       // Subtle here, we must /not/ apply any changes and
+       // then refer to tabular, as it will have been freed
+       // since the changes update the actual controller().tabular()
+       LyXTabular const & tabular(controller().tabular());
+
+       // apply the fixed width values
+       LyXTabular::idx_type const cell = controller().getActiveCell();
+       bool const multicol = tabular.isMultiColumn(cell);
+       string width = widgetsToLength(dialog_->widthED, dialog_->widthUnit);
+       string width2;
+
+       LyXLength llen = tabular.getColumnPWidth(cell);
+       LyXLength llenMulti = tabular.getMColumnPWidth(cell);
+
+       if (multicol && !llenMulti.zero())
+                       width2 = llenMulti.asString();
+       else if (!multicol && !llen.zero())
+                       width2 = llen.asString();
+
+       // apply the special alignment
+       docstring const sa1 = qstring_to_ucs4(dialog_->specialAlignmentED->text());
+       docstring sa2;
+
+       if (multicol)
+               sa2 = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI);
+       else
+               sa2 = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_COLUMN);
+
+       if (sa1 != sa2) {
+               if (multicol)
+                       controller().set(LyXTabular::SET_SPECIAL_MULTI, to_utf8(sa1));
+               else
+                       controller().set(LyXTabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
+       }
+
+       if (width != width2) {
+               if (multicol)
+                       controller().set(LyXTabular::SET_MPWIDTH, width);
+               else
+                       controller().set(LyXTabular::SET_PWIDTH, width);
+       }
+
+       /* DO WE NEED THIS?
+       switch (dialog_->topspaceCO->currentIndex()) {
+               case 0:
+                       controller().set(LyXTabular::SET_TOP_SPACE, "");
+                       break;
+               case 1:
+                       controller().set(LyXTabular::SET_TOP_SPACE, "default");
+                       break;
+               case 2:
+                       controller().set(LyXTabular::SET_TOP_SPACE,
+                               widgetsToLength(dialog_->topspaceED, 
+                                       dialog_->topspaceUnit));
+                       break;
+       }
+
+       switch (dialog_->bottomspaceCO->currentIndex()) {
+               case 0:
+                       controller().set(LyXTabular::SET_BOTTOM_SPACE, "");
+                       break;
+               case 1:
+                       controller().set(LyXTabular::SET_BOTTOM_SPACE, "default");
+                       break;
+               case 2:
+                       controller().set(LyXTabular::SET_BOTTOM_SPACE,
+                               widgetsToLength(dialog_->bottomspaceED, 
+                                       dialog_->bottomspaceUnit));
+                       break;
+       }
+
+       switch (dialog_->interlinespaceCO->currentIndex()) {
+               case 0:
+                       controller().set(LyXTabular::SET_INTERLINE_SPACE, "");
+                       break;
+               case 1:
+                       controller().set(LyXTabular::SET_INTERLINE_SPACE, "default");
+                       break;
+               case 2:
+                       controller().set(LyXTabular::SET_INTERLINE_SPACE,
+                               widgetsToLength(dialog_->interlinespaceED, 
+                                       dialog_->interlinespaceUnit));
+                       break;
+       }
+*/
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QTabular_moc.cpp"
+
diff --git a/src/frontends/qt4/QTabularCreate.C b/src/frontends/qt4/QTabularCreate.C
deleted file mode 100644 (file)
index 7baee2c..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * \file QTabularCreate.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QTabularCreate.h"
-#include "Qt2BC.h"
-#include "EmptyTable.h"
-
-#include "controllers/ControlTabularCreate.h"
-
-#include <QSpinBox>
-#include <QPushButton>
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QTabularCreateDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QTabularCreateDialog::QTabularCreateDialog(QTabularCreate * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       rowsSB->setValue(5);
-       columnsSB->setValue(5);
-
-       connect(okPB, SIGNAL(clicked()),
-               form_, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               form_, SLOT(slotClose()));
-    connect(rowsSB, SIGNAL(valueChanged(int)),
-               this, SLOT( rowsChanged(int)));
-    connect(columnsSB, SIGNAL(valueChanged(int)),
-               this, SLOT(columnsChanged(int)));
-}
-
-
-void QTabularCreateDialog::columnsChanged(int)
-{
-       form_->changed();
-}
-
-
-void QTabularCreateDialog::rowsChanged(int)
-{
-       form_->changed();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QTabularCreate
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlTabularCreate, QView<QTabularCreateDialog> >
-       TabularCreateBase;
-
-
-QTabularCreate::QTabularCreate(Dialog & parent)
-       : TabularCreateBase(parent, _("Insert Table"))
-{
-}
-
-
-void QTabularCreate::build_dialog()
-{
-       dialog_.reset(new QTabularCreateDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QTabularCreate::apply()
-{
-       controller().params().first = dialog_->rowsSB->value();
-       controller().params().second = dialog_->columnsSB->value();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QTabularCreate_moc.cpp"
diff --git a/src/frontends/qt4/QTabularCreate.cpp b/src/frontends/qt4/QTabularCreate.cpp
new file mode 100644 (file)
index 0000000..7baee2c
--- /dev/null
@@ -0,0 +1,96 @@
+/**
+ * \file QTabularCreate.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QTabularCreate.h"
+#include "Qt2BC.h"
+#include "EmptyTable.h"
+
+#include "controllers/ControlTabularCreate.h"
+
+#include <QSpinBox>
+#include <QPushButton>
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QTabularCreateDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QTabularCreateDialog::QTabularCreateDialog(QTabularCreate * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       rowsSB->setValue(5);
+       columnsSB->setValue(5);
+
+       connect(okPB, SIGNAL(clicked()),
+               form_, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               form_, SLOT(slotClose()));
+    connect(rowsSB, SIGNAL(valueChanged(int)),
+               this, SLOT( rowsChanged(int)));
+    connect(columnsSB, SIGNAL(valueChanged(int)),
+               this, SLOT(columnsChanged(int)));
+}
+
+
+void QTabularCreateDialog::columnsChanged(int)
+{
+       form_->changed();
+}
+
+
+void QTabularCreateDialog::rowsChanged(int)
+{
+       form_->changed();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QTabularCreate
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlTabularCreate, QView<QTabularCreateDialog> >
+       TabularCreateBase;
+
+
+QTabularCreate::QTabularCreate(Dialog & parent)
+       : TabularCreateBase(parent, _("Insert Table"))
+{
+}
+
+
+void QTabularCreate::build_dialog()
+{
+       dialog_.reset(new QTabularCreateDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QTabularCreate::apply()
+{
+       controller().params().first = dialog_->rowsSB->value();
+       controller().params().second = dialog_->columnsSB->value();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QTabularCreate_moc.cpp"
diff --git a/src/frontends/qt4/QTexinfo.C b/src/frontends/qt4/QTexinfo.C
deleted file mode 100644 (file)
index 96cb02b..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-/**
- * \file QTexinfo.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QTexinfo.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "support/filetools.h"
-
-#include <QCheckBox>
-#include <QListWidget>
-#include <QPushButton>
-
-using std::string;
-using std::vector;
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QTexinfoDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-QTexinfoDialog::QTexinfoDialog(QTexinfo * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
-       connect(whatStyleCO, SIGNAL(activated(const QString &)),
-               this, SLOT(enableViewPB()));
-       connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(update()));
-       connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(update()));
-       connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
-       connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
-       connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
-               this, SLOT( enableViewPB() ) );
-       connect(fileListLW, SIGNAL(itemSelectionChanged()),
-               this, SLOT(enableViewPB()));
-}
-
-
-void QTexinfoDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QTexinfoDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QTexinfoDialog::rescanClicked()
-{
-       // build new *Files.lst
-       rescanTexStyles();
-       form_->updateStyles();
-       enableViewPB();
-}
-
-
-void QTexinfoDialog::viewClicked()
-{
-       vector<string>::size_type const fitem = fileListLW->currentRow();
-       vector<string> const & data = form_->texdata_[form_->activeStyle];
-       string file = data[fitem];
-       if (!pathCB->isChecked())
-               file = getTexFileFromList(data[fitem],
-                       form_->controller().getFileType(form_->activeStyle));
-       form_->controller().viewFile(file);
-}
-
-
-void QTexinfoDialog::update()
-{
-       switch (whatStyleCO->currentIndex()) {
-       case 0:
-               form_->updateStyles(ControlTexinfo::cls);
-               break;
-       case 1:
-               form_->updateStyles(ControlTexinfo::sty);
-               break;
-       case 2:
-               form_->updateStyles(ControlTexinfo::bst);
-               break;
-       default:
-               break;
-       }
-
-       enableViewPB();
-}
-
-
-void QTexinfoDialog::enableViewPB()
-{
-       viewPB->setEnabled(fileListLW->currentRow() > -1);
-}
-
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QTexinfo
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlTexinfo, QView<QTexinfoDialog> > texinfo_base_class;
-
-QTexinfo::QTexinfo(Dialog & parent)
-       : texinfo_base_class(parent, _("TeX Information")),
-         warningPosted(false), activeStyle(ControlTexinfo::cls)
-{
-}
-
-
-void QTexinfo::build_dialog()
-{
-       dialog_.reset(new QTexinfoDialog(this));
-
-       updateStyles(ControlTexinfo::cls);
-
-       bcview().setCancel(dialog_->closePB);
-}
-
-
-void QTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
-{
-       ContentsType & data = texdata_[whichStyle];
-       bool const withFullPath = dialog_->pathCB->isChecked();
-
-       getTexFileList(whichStyle, data, withFullPath);
-
-       dialog_->fileListLW->clear();
-       ContentsType::const_iterator it  = data.begin();
-       ContentsType::const_iterator end = data.end();
-       for (; it != end; ++it)
-               dialog_->fileListLW->addItem(toqstr(*it));
-
-       activeStyle = whichStyle;
-}
-
-
-void QTexinfo::updateStyles()
-{
-       updateStyles(activeStyle);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-
-#include "QTexinfo_moc.cpp"
diff --git a/src/frontends/qt4/QTexinfo.cpp b/src/frontends/qt4/QTexinfo.cpp
new file mode 100644 (file)
index 0000000..96cb02b
--- /dev/null
@@ -0,0 +1,169 @@
+/**
+ * \file QTexinfo.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QTexinfo.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "support/filetools.h"
+
+#include <QCheckBox>
+#include <QListWidget>
+#include <QPushButton>
+
+using std::string;
+using std::vector;
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QTexinfoDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+QTexinfoDialog::QTexinfoDialog(QTexinfo * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(viewPB, SIGNAL(clicked()), this, SLOT(viewClicked()));
+       connect(whatStyleCO, SIGNAL(activated(const QString &)),
+               this, SLOT(enableViewPB()));
+       connect(whatStyleCO, SIGNAL(activated(int)), this, SLOT(update()));
+       connect(pathCB, SIGNAL(stateChanged(int)), this, SLOT(update()));
+       connect(rescanPB, SIGNAL(clicked()), this, SLOT(enableViewPB()));
+       connect(rescanPB, SIGNAL(clicked()), this, SLOT(rescanClicked()));
+       connect(fileListLW, SIGNAL(itemClicked(QListWidgetItem *)),
+               this, SLOT( enableViewPB() ) );
+       connect(fileListLW, SIGNAL(itemSelectionChanged()),
+               this, SLOT(enableViewPB()));
+}
+
+
+void QTexinfoDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QTexinfoDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QTexinfoDialog::rescanClicked()
+{
+       // build new *Files.lst
+       rescanTexStyles();
+       form_->updateStyles();
+       enableViewPB();
+}
+
+
+void QTexinfoDialog::viewClicked()
+{
+       vector<string>::size_type const fitem = fileListLW->currentRow();
+       vector<string> const & data = form_->texdata_[form_->activeStyle];
+       string file = data[fitem];
+       if (!pathCB->isChecked())
+               file = getTexFileFromList(data[fitem],
+                       form_->controller().getFileType(form_->activeStyle));
+       form_->controller().viewFile(file);
+}
+
+
+void QTexinfoDialog::update()
+{
+       switch (whatStyleCO->currentIndex()) {
+       case 0:
+               form_->updateStyles(ControlTexinfo::cls);
+               break;
+       case 1:
+               form_->updateStyles(ControlTexinfo::sty);
+               break;
+       case 2:
+               form_->updateStyles(ControlTexinfo::bst);
+               break;
+       default:
+               break;
+       }
+
+       enableViewPB();
+}
+
+
+void QTexinfoDialog::enableViewPB()
+{
+       viewPB->setEnabled(fileListLW->currentRow() > -1);
+}
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QTexinfo
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlTexinfo, QView<QTexinfoDialog> > texinfo_base_class;
+
+QTexinfo::QTexinfo(Dialog & parent)
+       : texinfo_base_class(parent, _("TeX Information")),
+         warningPosted(false), activeStyle(ControlTexinfo::cls)
+{
+}
+
+
+void QTexinfo::build_dialog()
+{
+       dialog_.reset(new QTexinfoDialog(this));
+
+       updateStyles(ControlTexinfo::cls);
+
+       bcview().setCancel(dialog_->closePB);
+}
+
+
+void QTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
+{
+       ContentsType & data = texdata_[whichStyle];
+       bool const withFullPath = dialog_->pathCB->isChecked();
+
+       getTexFileList(whichStyle, data, withFullPath);
+
+       dialog_->fileListLW->clear();
+       ContentsType::const_iterator it  = data.begin();
+       ContentsType::const_iterator end = data.end();
+       for (; it != end; ++it)
+               dialog_->fileListLW->addItem(toqstr(*it));
+
+       activeStyle = whichStyle;
+}
+
+
+void QTexinfo::updateStyles()
+{
+       updateStyles(activeStyle);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QTexinfo_moc.cpp"
diff --git a/src/frontends/qt4/QThesaurus.C b/src/frontends/qt4/QThesaurus.C
deleted file mode 100644 (file)
index 431f608..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * \file QThesaurus.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QThesaurus.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-#include "debug.h"
-
-#include "controllers/ControlThesaurus.h"
-
-#include <QHeaderView>
-#include <QLineEdit>
-#include <QPushButton>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QTheasurusDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       meaningsTV->setColumnCount(1);
-       meaningsTV->header()->hide();
-
-       connect(closePB, SIGNAL(clicked()),
-               form, SLOT(slotClose()));
-       connect(replaceED, SIGNAL(returnPressed()),
-               this, SLOT(replaceClicked()));
-       connect(replaceED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor() ) );
-       connect(entryED, SIGNAL(returnPressed()),
-               this, SLOT(entryChanged()));
-       connect(replacePB, SIGNAL(clicked()),
-               this, SLOT(replaceClicked()));
-       connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
-               this, SLOT(itemClicked(QTreeWidgetItem *, int)));
-       connect(meaningsTV, SIGNAL(itemSelectionChanged()),
-               this, SLOT(selectionChanged()));
-       connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
-               this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
-}
-
-
-void QThesaurusDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QThesaurusDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QThesaurusDialog::entryChanged()
-{
-       updateLists();
-}
-
-
-void QThesaurusDialog::replaceClicked()
-{
-       form_->replace();
-}
-
-
-void QThesaurusDialog::selectionChanged()
-{
-       int const col = meaningsTV->currentColumn();
-       if (col<0 || form_->readOnly())
-               return;
-
-       replaceED->setText(meaningsTV->currentItem()->text(col));
-       replacePB->setEnabled(true);
-       form_->changed();
-}
-
-
-void QThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
-{
-       selectionChanged();
-}
-
-
-void QThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
-{
-       entryED->setText(item->text(col));
-       selectionChanged();
-       updateLists();
-}
-
-
-void QThesaurusDialog::updateLists()
-{
-       meaningsTV->clear();
-       meaningsTV->setUpdatesEnabled(false);
-
-       Thesaurus::Meanings meanings = form_->controller().getMeanings(qstring_to_ucs4(entryED->text()));
-
-       for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
-               cit != meanings.end(); ++cit) {
-               QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
-               i->setText(0, toqstr(cit->first));
-               meaningsTV->expandItem(i);
-               for (std::vector<docstring>::const_iterator cit2 = cit->second.begin();
-                       cit2 != cit->second.end(); ++cit2) {
-                               QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
-                               i2->setText(0, toqstr(*cit2));
-                       }
-       }
-
-       meaningsTV->setUpdatesEnabled(true);
-       meaningsTV->update();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QThesuarus
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlThesaurus, QView<QThesaurusDialog> > ThesaurusBase;
-
-QThesaurus::QThesaurus(Dialog & parent)
-       : ThesaurusBase(parent, _("Thesaurus"))
-{
-}
-
-
-void QThesaurus::build_dialog()
-{
-       dialog_.reset(new QThesaurusDialog(this));
-
-       bcview().setCancel(dialog_->closePB);
-       bcview().setApply(dialog_->replacePB);
-       bcview().addReadOnly(dialog_->replaceED);
-       bcview().addReadOnly(dialog_->replacePB);
-}
-
-
-void QThesaurus::update_contents()
-{
-       dialog_->entryED->setText(toqstr(controller().text()));
-       dialog_->replaceED->setText("");
-       dialog_->updateLists();
-}
-
-
-void QThesaurus::replace()
-{
-       controller().replace(qstring_to_ucs4(dialog_->replaceED->text()));
-}
-
-} // namespace frontend
-} // namespace lyx
-
-
-#include "QThesaurus_moc.cpp"
diff --git a/src/frontends/qt4/QThesaurus.cpp b/src/frontends/qt4/QThesaurus.cpp
new file mode 100644 (file)
index 0000000..431f608
--- /dev/null
@@ -0,0 +1,181 @@
+/**
+ * \file QThesaurus.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QThesaurus.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+#include "debug.h"
+
+#include "controllers/ControlThesaurus.h"
+
+#include <QHeaderView>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QTheasurusDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       meaningsTV->setColumnCount(1);
+       meaningsTV->header()->hide();
+
+       connect(closePB, SIGNAL(clicked()),
+               form, SLOT(slotClose()));
+       connect(replaceED, SIGNAL(returnPressed()),
+               this, SLOT(replaceClicked()));
+       connect(replaceED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor() ) );
+       connect(entryED, SIGNAL(returnPressed()),
+               this, SLOT(entryChanged()));
+       connect(replacePB, SIGNAL(clicked()),
+               this, SLOT(replaceClicked()));
+       connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
+               this, SLOT(itemClicked(QTreeWidgetItem *, int)));
+       connect(meaningsTV, SIGNAL(itemSelectionChanged()),
+               this, SLOT(selectionChanged()));
+       connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
+               this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
+}
+
+
+void QThesaurusDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QThesaurusDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QThesaurusDialog::entryChanged()
+{
+       updateLists();
+}
+
+
+void QThesaurusDialog::replaceClicked()
+{
+       form_->replace();
+}
+
+
+void QThesaurusDialog::selectionChanged()
+{
+       int const col = meaningsTV->currentColumn();
+       if (col<0 || form_->readOnly())
+               return;
+
+       replaceED->setText(meaningsTV->currentItem()->text(col));
+       replacePB->setEnabled(true);
+       form_->changed();
+}
+
+
+void QThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
+{
+       selectionChanged();
+}
+
+
+void QThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
+{
+       entryED->setText(item->text(col));
+       selectionChanged();
+       updateLists();
+}
+
+
+void QThesaurusDialog::updateLists()
+{
+       meaningsTV->clear();
+       meaningsTV->setUpdatesEnabled(false);
+
+       Thesaurus::Meanings meanings = form_->controller().getMeanings(qstring_to_ucs4(entryED->text()));
+
+       for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
+               cit != meanings.end(); ++cit) {
+               QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
+               i->setText(0, toqstr(cit->first));
+               meaningsTV->expandItem(i);
+               for (std::vector<docstring>::const_iterator cit2 = cit->second.begin();
+                       cit2 != cit->second.end(); ++cit2) {
+                               QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
+                               i2->setText(0, toqstr(*cit2));
+                       }
+       }
+
+       meaningsTV->setUpdatesEnabled(true);
+       meaningsTV->update();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QThesuarus
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlThesaurus, QView<QThesaurusDialog> > ThesaurusBase;
+
+QThesaurus::QThesaurus(Dialog & parent)
+       : ThesaurusBase(parent, _("Thesaurus"))
+{
+}
+
+
+void QThesaurus::build_dialog()
+{
+       dialog_.reset(new QThesaurusDialog(this));
+
+       bcview().setCancel(dialog_->closePB);
+       bcview().setApply(dialog_->replacePB);
+       bcview().addReadOnly(dialog_->replaceED);
+       bcview().addReadOnly(dialog_->replacePB);
+}
+
+
+void QThesaurus::update_contents()
+{
+       dialog_->entryED->setText(toqstr(controller().text()));
+       dialog_->replaceED->setText("");
+       dialog_->updateLists();
+}
+
+
+void QThesaurus::replace()
+{
+       controller().replace(qstring_to_ucs4(dialog_->replaceED->text()));
+}
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QThesaurus_moc.cpp"
diff --git a/src/frontends/qt4/QToc.C b/src/frontends/qt4/QToc.C
deleted file mode 100644 (file)
index 28c3d9b..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * \file QToc.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QToc.h"
-
-#include "TocModel.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-
-#include "controllers/ControlToc.h"
-
-#include <algorithm>
-
-using std::endl;
-
-using std::pair;
-using std::vector;
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-
-QToc::QToc(Dialog & dialog, QObject * parent)
-       : QObject(parent), ControlToc(dialog)
-{
-}
-
-
-bool QToc::canOutline(int type) const
-{
-       if (type < 0) 
-               return false;
-
-       return ControlToc::canOutline(type);
-}
-
-
-int QToc::getTocDepth(int type)
-{
-       if (type < 0)
-               return 0;
-       return toc_models_[type]->modelDepth();
-}
-
-
-QStandardItemModel * QToc::tocModel(int type)
-{
-       if (type < 0)
-               return 0;
-
-       if (toc_models_.empty()) {
-               LYXERR(Debug::GUI) << "QToc::tocModel(): no types available " << endl;
-               return 0;
-       }
-
-       LYXERR(Debug::GUI)
-               << "QToc: type_ " << type
-               << "  toc_models_.size() " << toc_models_.size()
-               << endl;
-
-       BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
-       return toc_models_[type];
-}
-
-
-QModelIndex const QToc::getCurrentIndex(int type) const
-{
-       if (type < 0)
-               return QModelIndex();
-
-       return toc_models_[type]->modelIndex(getCurrentTocItem(type));
-}
-
-
-void QToc::goTo(int type, QModelIndex const & index)
-{
-       if (type < 0 || !index.isValid() 
-               || index.model() != toc_models_[type]) {
-               LYXERR(Debug::GUI)
-                       << "QToc::goTo(): QModelIndex is invalid!"
-                       << endl;
-               return;
-       }
-
-       BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
-
-       TocIterator const it = toc_models_[type]->tocIterator(index);
-       
-       LYXERR(Debug::GUI) << "QToc::goTo " << to_utf8(it->str()) << endl;
-
-       ControlToc::goTo(*it);
-}
-
-
-bool QToc::initialiseParams(std::string const & data)
-{
-       if (!ControlToc::initialiseParams(data))
-               return false;
-       update();
-       return true;
-}
-
-
-void QToc::update()
-{
-       updateType();
-       updateToc();
-       modelReset();
-}
-
-
-void QToc::updateType()
-{
-       QStringList type_list;
-
-       vector<docstring> const & type_names = typeNames();
-       BOOST_ASSERT(!type_names.empty());
-       for (size_t i = 0; i != type_names.size(); ++i)
-               type_list.append(toqstr(type_names[i]));
-
-       type_model_.setStringList(type_list);
-}
-
-
-void QToc::updateToc()
-{
-       toc_models_.clear();
-       TocList::const_iterator it = tocs().begin();
-       TocList::const_iterator end = tocs().end();
-       for (; it != end; ++it)
-               toc_models_.push_back(new TocModel(it->second));
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QToc_moc.cpp"
diff --git a/src/frontends/qt4/QToc.cpp b/src/frontends/qt4/QToc.cpp
new file mode 100644 (file)
index 0000000..28c3d9b
--- /dev/null
@@ -0,0 +1,151 @@
+/**
+ * \file QToc.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QToc.h"
+
+#include "TocModel.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include "controllers/ControlToc.h"
+
+#include <algorithm>
+
+using std::endl;
+
+using std::pair;
+using std::vector;
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+
+QToc::QToc(Dialog & dialog, QObject * parent)
+       : QObject(parent), ControlToc(dialog)
+{
+}
+
+
+bool QToc::canOutline(int type) const
+{
+       if (type < 0) 
+               return false;
+
+       return ControlToc::canOutline(type);
+}
+
+
+int QToc::getTocDepth(int type)
+{
+       if (type < 0)
+               return 0;
+       return toc_models_[type]->modelDepth();
+}
+
+
+QStandardItemModel * QToc::tocModel(int type)
+{
+       if (type < 0)
+               return 0;
+
+       if (toc_models_.empty()) {
+               LYXERR(Debug::GUI) << "QToc::tocModel(): no types available " << endl;
+               return 0;
+       }
+
+       LYXERR(Debug::GUI)
+               << "QToc: type_ " << type
+               << "  toc_models_.size() " << toc_models_.size()
+               << endl;
+
+       BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
+       return toc_models_[type];
+}
+
+
+QModelIndex const QToc::getCurrentIndex(int type) const
+{
+       if (type < 0)
+               return QModelIndex();
+
+       return toc_models_[type]->modelIndex(getCurrentTocItem(type));
+}
+
+
+void QToc::goTo(int type, QModelIndex const & index)
+{
+       if (type < 0 || !index.isValid() 
+               || index.model() != toc_models_[type]) {
+               LYXERR(Debug::GUI)
+                       << "QToc::goTo(): QModelIndex is invalid!"
+                       << endl;
+               return;
+       }
+
+       BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
+
+       TocIterator const it = toc_models_[type]->tocIterator(index);
+       
+       LYXERR(Debug::GUI) << "QToc::goTo " << to_utf8(it->str()) << endl;
+
+       ControlToc::goTo(*it);
+}
+
+
+bool QToc::initialiseParams(std::string const & data)
+{
+       if (!ControlToc::initialiseParams(data))
+               return false;
+       update();
+       return true;
+}
+
+
+void QToc::update()
+{
+       updateType();
+       updateToc();
+       modelReset();
+}
+
+
+void QToc::updateType()
+{
+       QStringList type_list;
+
+       vector<docstring> const & type_names = typeNames();
+       BOOST_ASSERT(!type_names.empty());
+       for (size_t i = 0; i != type_names.size(); ++i)
+               type_list.append(toqstr(type_names[i]));
+
+       type_model_.setStringList(type_list);
+}
+
+
+void QToc::updateToc()
+{
+       toc_models_.clear();
+       TocList::const_iterator it = tocs().begin();
+       TocList::const_iterator end = tocs().end();
+       for (; it != end; ++it)
+               toc_models_.push_back(new TocModel(it->second));
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QToc_moc.cpp"
diff --git a/src/frontends/qt4/QURLDialog.C b/src/frontends/qt4/QURLDialog.C
deleted file mode 100644 (file)
index 4744214..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * \file QURLDialog.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QURLDialog.h"
-#include "UrlView.h"
-
-#include <QLineEdit>
-#include <QPushButton>
-#include <QCloseEvent>
-
-namespace lyx {
-namespace frontend {
-
-QURLDialog::QURLDialog(UrlView * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()),
-               form_, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()),
-               form_, SLOT(slotClose()));
-
-    connect( urlED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
-    connect( hyperlinkCB, SIGNAL( clicked() ), this, SLOT( changed_adaptor() ) );
-    connect( nameED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
-
-       setFocusProxy(urlED);
-}
-
-
-QURLDialog::~QURLDialog()
-{
-}
-
-
-void QURLDialog::show()
-{
-       QDialog::show();
-}
-
-
-void QURLDialog::changed_adaptor()
-{
-       form_->changed();
-}
-
-
-void QURLDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QURLDialog_moc.cpp"
diff --git a/src/frontends/qt4/QURLDialog.cpp b/src/frontends/qt4/QURLDialog.cpp
new file mode 100644 (file)
index 0000000..4744214
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * \file QURLDialog.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QURLDialog.h"
+#include "UrlView.h"
+
+#include <QLineEdit>
+#include <QPushButton>
+#include <QCloseEvent>
+
+namespace lyx {
+namespace frontend {
+
+QURLDialog::QURLDialog(UrlView * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()),
+               form_, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               form_, SLOT(slotClose()));
+
+    connect( urlED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
+    connect( hyperlinkCB, SIGNAL( clicked() ), this, SLOT( changed_adaptor() ) );
+    connect( nameED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
+
+       setFocusProxy(urlED);
+}
+
+
+QURLDialog::~QURLDialog()
+{
+}
+
+
+void QURLDialog::show()
+{
+       QDialog::show();
+}
+
+
+void QURLDialog::changed_adaptor()
+{
+       form_->changed();
+}
+
+
+void QURLDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QURLDialog_moc.cpp"
diff --git a/src/frontends/qt4/QVSpace.C b/src/frontends/qt4/QVSpace.C
deleted file mode 100644 (file)
index 72fa302..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-/**
- * \file QVSpace.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author André Pönitz
- * \author Jürgen Vigna
- * \author Rob Lahaye
- * \author Angus Leeming
- * \author Edwin Leuven
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QVSpace.h"
-#include "Qt2BC.h"
-
-#include "CheckedLineEdit.h"
-#include "LengthCombo.h"
-#include "qt_helpers.h"
-#include "Validator.h"
-
-#include "lyxrc.h" // to set the default length values
-#include "Spacing.h"
-#include "vspace.h"
-
-#include "controllers/ControlVSpace.h"
-#include "controllers/frontend_helpers.h"
-
-#include "support/lstrings.h"
-
-#include <QCheckBox>
-#include <QCloseEvent>
-#include <QLineEdit>
-#include <QPushButton>
-#include <QValidator>
-
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QVSpaceDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-QVSpaceDialog::QVSpaceDialog(QVSpace * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
-
-       connect(spacingCO, SIGNAL(highlighted(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(valueLE, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(spacingCO, SIGNAL(activated(int)),
-               this, SLOT(enableCustom(int)));
-       connect(keepCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(unitCO, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(change_adaptor()));
-
-       valueLE->setValidator(unsignedLengthValidator(valueLE));
-}
-
-
-void QVSpaceDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QVSpaceDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-
-void QVSpaceDialog::enableCustom(int selection)
-{
-       bool const enable = selection == 5;
-       valueLE->setEnabled(enable);
-       unitCO->setEnabled(enable);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QVSpace
-//
-/////////////////////////////////////////////////////////////////////
-
-static void setWidgetsFromVSpace(VSpace const & space,
-                         QComboBox * spacing,
-                         QLineEdit * value,
-                         LengthCombo * unit,
-                         QCheckBox * keep)
-{
-       int item = 0;
-       switch (space.kind()) {
-       case VSpace::DEFSKIP:
-               item = 0;
-               break;
-       case VSpace::SMALLSKIP:
-               item = 1;
-               break;
-       case VSpace::MEDSKIP:
-               item = 2;
-               break;
-       case VSpace::BIGSKIP:
-               item = 3;
-               break;
-       case VSpace::VFILL:
-               item = 4;
-               break;
-       case VSpace::LENGTH:
-               item = 5;
-               break;
-       }
-       spacing->setCurrentIndex(item);
-       keep->setChecked(space.keep());
-
-       LyXLength::UNIT default_unit =
-                       (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
-       bool const custom_vspace = space.kind() == VSpace::LENGTH;
-       if (custom_vspace) {
-               value->setEnabled(true);
-               unit->setEnabled(true);
-               string length = space.length().asString();
-               lengthToWidgets(value, unit, length, default_unit);
-       } else {
-               lengthToWidgets(value, unit, "", default_unit);
-               value->setEnabled(false);
-               unit->setEnabled(false);
-       }
-}
-
-
-static VSpace setVSpaceFromWidgets(int spacing,
-                           QLineEdit * value,
-                           LengthCombo * unit,
-                           bool keep)
-{
-       VSpace space;
-
-       switch (spacing) {
-       case 0:
-               space = VSpace(VSpace::DEFSKIP);
-               break;
-       case 1:
-               space = VSpace(VSpace::SMALLSKIP);
-               break;
-       case 2:
-               space = VSpace(VSpace::MEDSKIP);
-               break;
-       case 3:
-               space = VSpace(VSpace::BIGSKIP);
-               break;
-       case 4:
-               space = VSpace(VSpace::VFILL);
-               break;
-       case 5:
-               space = VSpace(LyXGlueLength(widgetsToLength(value, unit)));
-               break;
-       }
-
-       space.setKeep(keep);
-       return space;
-}
-
-
-typedef QController<ControlVSpace, QView<QVSpaceDialog> > VSpaceBase;
-
-QVSpace::QVSpace(Dialog & parent)
-       : VSpaceBase(parent, _("Vertical Space Settings"))
-{}
-
-
-void QVSpace::build_dialog()
-{
-       // the tabbed folder
-       dialog_.reset(new QVSpaceDialog(this));
-
-       // Manage the ok, apply, restore and cancel/close buttons
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-
-       // disable for read-only documents
-       bcview().addReadOnly(dialog_->spacingCO);
-       bcview().addReadOnly(dialog_->valueLE);
-       bcview().addReadOnly(dialog_->unitCO);
-       bcview().addReadOnly(dialog_->keepCB);
-
-       // initialize the length validator
-       addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
-
-       // remove the %-items from the unit choice
-       dialog_->unitCO->noPercents();
-}
-
-
-void QVSpace::apply()
-{
-       // spacing
-       // If a vspace choice is "Length" but there's no text in
-       // the input field, do not insert a vspace at all.
-       if (dialog_->spacingCO->currentIndex() == 5
-           && dialog_->valueLE->text().isEmpty())
-               return;
-
-       VSpace const space =
-               setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(),
-                                    dialog_->valueLE,
-                                    dialog_->unitCO,
-                                    dialog_->keepCB->isChecked());
-
-       controller().params() = space;
-}
-
-
-void QVSpace::update_contents()
-{
-       setWidgetsFromVSpace(controller().params(),
-                            dialog_->spacingCO,
-                            dialog_->valueLE,
-                            dialog_->unitCO,
-                            dialog_->keepCB);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-
-#include "QVSpace_moc.cpp"
diff --git a/src/frontends/qt4/QVSpace.cpp b/src/frontends/qt4/QVSpace.cpp
new file mode 100644 (file)
index 0000000..72fa302
--- /dev/null
@@ -0,0 +1,248 @@
+/**
+ * \file QVSpace.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ * \author Jürgen Vigna
+ * \author Rob Lahaye
+ * \author Angus Leeming
+ * \author Edwin Leuven
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QVSpace.h"
+#include "Qt2BC.h"
+
+#include "CheckedLineEdit.h"
+#include "LengthCombo.h"
+#include "qt_helpers.h"
+#include "Validator.h"
+
+#include "lyxrc.h" // to set the default length values
+#include "Spacing.h"
+#include "vspace.h"
+
+#include "controllers/ControlVSpace.h"
+#include "controllers/frontend_helpers.h"
+
+#include "support/lstrings.h"
+
+#include <QCheckBox>
+#include <QCloseEvent>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QValidator>
+
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QVSpaceDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+QVSpaceDialog::QVSpaceDialog(QVSpace * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
+
+       connect(spacingCO, SIGNAL(highlighted(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(valueLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(spacingCO, SIGNAL(activated(int)),
+               this, SLOT(enableCustom(int)));
+       connect(keepCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(unitCO, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(change_adaptor()));
+
+       valueLE->setValidator(unsignedLengthValidator(valueLE));
+}
+
+
+void QVSpaceDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QVSpaceDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+
+void QVSpaceDialog::enableCustom(int selection)
+{
+       bool const enable = selection == 5;
+       valueLE->setEnabled(enable);
+       unitCO->setEnabled(enable);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QVSpace
+//
+/////////////////////////////////////////////////////////////////////
+
+static void setWidgetsFromVSpace(VSpace const & space,
+                         QComboBox * spacing,
+                         QLineEdit * value,
+                         LengthCombo * unit,
+                         QCheckBox * keep)
+{
+       int item = 0;
+       switch (space.kind()) {
+       case VSpace::DEFSKIP:
+               item = 0;
+               break;
+       case VSpace::SMALLSKIP:
+               item = 1;
+               break;
+       case VSpace::MEDSKIP:
+               item = 2;
+               break;
+       case VSpace::BIGSKIP:
+               item = 3;
+               break;
+       case VSpace::VFILL:
+               item = 4;
+               break;
+       case VSpace::LENGTH:
+               item = 5;
+               break;
+       }
+       spacing->setCurrentIndex(item);
+       keep->setChecked(space.keep());
+
+       LyXLength::UNIT default_unit =
+                       (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
+       bool const custom_vspace = space.kind() == VSpace::LENGTH;
+       if (custom_vspace) {
+               value->setEnabled(true);
+               unit->setEnabled(true);
+               string length = space.length().asString();
+               lengthToWidgets(value, unit, length, default_unit);
+       } else {
+               lengthToWidgets(value, unit, "", default_unit);
+               value->setEnabled(false);
+               unit->setEnabled(false);
+       }
+}
+
+
+static VSpace setVSpaceFromWidgets(int spacing,
+                           QLineEdit * value,
+                           LengthCombo * unit,
+                           bool keep)
+{
+       VSpace space;
+
+       switch (spacing) {
+       case 0:
+               space = VSpace(VSpace::DEFSKIP);
+               break;
+       case 1:
+               space = VSpace(VSpace::SMALLSKIP);
+               break;
+       case 2:
+               space = VSpace(VSpace::MEDSKIP);
+               break;
+       case 3:
+               space = VSpace(VSpace::BIGSKIP);
+               break;
+       case 4:
+               space = VSpace(VSpace::VFILL);
+               break;
+       case 5:
+               space = VSpace(LyXGlueLength(widgetsToLength(value, unit)));
+               break;
+       }
+
+       space.setKeep(keep);
+       return space;
+}
+
+
+typedef QController<ControlVSpace, QView<QVSpaceDialog> > VSpaceBase;
+
+QVSpace::QVSpace(Dialog & parent)
+       : VSpaceBase(parent, _("Vertical Space Settings"))
+{}
+
+
+void QVSpace::build_dialog()
+{
+       // the tabbed folder
+       dialog_.reset(new QVSpaceDialog(this));
+
+       // Manage the ok, apply, restore and cancel/close buttons
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+
+       // disable for read-only documents
+       bcview().addReadOnly(dialog_->spacingCO);
+       bcview().addReadOnly(dialog_->valueLE);
+       bcview().addReadOnly(dialog_->unitCO);
+       bcview().addReadOnly(dialog_->keepCB);
+
+       // initialize the length validator
+       addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
+
+       // remove the %-items from the unit choice
+       dialog_->unitCO->noPercents();
+}
+
+
+void QVSpace::apply()
+{
+       // spacing
+       // If a vspace choice is "Length" but there's no text in
+       // the input field, do not insert a vspace at all.
+       if (dialog_->spacingCO->currentIndex() == 5
+           && dialog_->valueLE->text().isEmpty())
+               return;
+
+       VSpace const space =
+               setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(),
+                                    dialog_->valueLE,
+                                    dialog_->unitCO,
+                                    dialog_->keepCB->isChecked());
+
+       controller().params() = space;
+}
+
+
+void QVSpace::update_contents()
+{
+       setWidgetsFromVSpace(controller().params(),
+                            dialog_->spacingCO,
+                            dialog_->valueLE,
+                            dialog_->unitCO,
+                            dialog_->keepCB);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QVSpace_moc.cpp"
diff --git a/src/frontends/qt4/QViewSource.C b/src/frontends/qt4/QViewSource.C
deleted file mode 100644 (file)
index 543b063..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * \file QViewSource.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Bo Peng
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QViewSource.h"
-#include "qt_helpers.h"
-
-#include <QTextDocument>
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QViewSourceDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-QViewSourceDialog::QViewSourceDialog(QViewSource * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(viewFullSourceCB, SIGNAL(clicked()),
-               this, SLOT(update()));
-       connect(autoUpdateCB, SIGNAL(toggled(bool)),
-               updatePB, SLOT(setDisabled(bool)));
-       connect(updatePB, SIGNAL(clicked()),
-               this, SLOT(update()));
-
-       // setting a document at this point trigger an assertion in Qt
-       // so we disable the signals here:
-       form_->document()->blockSignals(true);
-       viewSourceTV->setDocument(form_->document());
-       form_->document()->blockSignals(false);
-       viewSourceTV->setReadOnly(true);
-       ///dialog_->viewSourceTV->setAcceptRichText(false);
-       // this is personal. I think source code should be in fixed-size font
-       QFont font(toqstr(theApp()->typewriterFontName()));
-       font.setKerning(false);
-       font.setFixedPitch(true);
-       font.setStyleHint(QFont::TypeWriter);
-       viewSourceTV->setFont(font);
-       // again, personal taste
-       viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
-}
-
-
-void QViewSourceDialog::update()
-{
-       if (autoUpdateCB->isChecked())
-               form_->update(viewFullSourceCB->isChecked());
-
-       QWidget::update();
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// LaTeXHighlighter
-//
-/////////////////////////////////////////////////////////////////////
-
-
-LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent)
-       : QSyntaxHighlighter(parent)
-{
-       keywordFormat.setForeground(Qt::darkBlue);
-       keywordFormat.setFontWeight(QFont::Bold);
-       commentFormat.setForeground(Qt::darkGray);
-       mathFormat.setForeground(Qt::red);
-}
-
-
-void LaTeXHighlighter::highlightBlock(QString const & text)
-{
-       // $ $ 
-       QRegExp exprMath("\\$[^\\$]*\\$");
-       int index = text.indexOf(exprMath);
-       while (index >= 0) {
-               int length = exprMath.matchedLength();
-               setFormat(index, length, mathFormat);
-               index = text.indexOf(exprMath, index + length);
-       }
-       // [ ]
-       QRegExp exprStartDispMath("(\\\\\\[|"
-               "\\\\begin\\{equation\\**\\}|"
-               "\\\\begin\\{eqnarray\\**\\}|"
-               "\\\\begin\\{align(ed|at)*\\**\\}|"
-               "\\\\begin\\{flalign\\**\\}|"
-               "\\\\begin\\{gather\\**\\}|"
-               "\\\\begin\\{multline\\**\\}|"
-               "\\\\begin\\{array\\**\\}|"
-               "\\\\begin\\{cases\\**\\}"
-               ")");
-       QRegExp exprEndDispMath("(\\\\\\]|"
-               "\\\\end\\{equation\\**\\}|"
-               "\\\\end\\{eqnarray\\**\\}|"
-               "\\\\end\\{align(ed|at)*\\**\\}|"
-               "\\\\end\\{flalign\\**\\}|"
-               "\\\\end\\{gather\\**\\}|"
-               "\\\\end\\{multline\\**\\}|"
-               "\\\\end\\{array\\**\\}|"
-               "\\\\end\\{cases\\**\\}"
-               ")");
-       int startIndex = 0;
-       // if previous block was in 'disp math'
-       // start search from 0 (for end disp math)
-       // otherwise, start search from 'begin disp math'
-       if (previousBlockState() != 1)
-               startIndex = text.indexOf(exprStartDispMath);
-       while (startIndex >= 0) {
-               int endIndex = text.indexOf(exprEndDispMath, startIndex);
-               int length;
-               if (endIndex == -1) {
-                       setCurrentBlockState(1);
-                       length = text.length() - startIndex;
-               } else {
-                       length = endIndex - startIndex + exprEndDispMath.matchedLength();
-               }
-               setFormat(startIndex, length, mathFormat);
-               startIndex = text.indexOf(exprStartDispMath, startIndex + length);
-       }
-       // \whatever
-       QRegExp exprKeyword("\\\\[A-Za-z]+");
-       index = text.indexOf(exprKeyword);
-       while (index >= 0) {
-               int length = exprKeyword.matchedLength();
-               setFormat(index, length, keywordFormat);
-               index = text.indexOf(exprKeyword, index + length);
-       }
-       // comment
-       QRegExp exprComment("(^|[^\\\\])%.*$");
-       index = text.indexOf(exprComment);
-       while (index >= 0) {
-               int const length = exprComment.matchedLength();
-               setFormat(index, length, commentFormat);
-               index = text.indexOf(exprComment, index + length);
-       }
-}
-
-
-QViewSource::QViewSource(Dialog & parent)
-       : ControlViewSource(parent)
-{
-       document_ = new QTextDocument(this);
-       highlighter_ = new LaTeXHighlighter(document_);
-}
-
-
-/////////////////////////////////////////////////////////////////////
-//
-// QViewSource
-//
-/////////////////////////////////////////////////////////////////////
-
-void QViewSource::update(bool full_source)
-{
-       document_->setPlainText(toqstr(updateContent(full_source)));
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "QViewSource_moc.cpp"
diff --git a/src/frontends/qt4/QViewSource.cpp b/src/frontends/qt4/QViewSource.cpp
new file mode 100644 (file)
index 0000000..543b063
--- /dev/null
@@ -0,0 +1,176 @@
+/**
+ * \file QViewSource.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Bo Peng
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QViewSource.h"
+#include "qt_helpers.h"
+
+#include <QTextDocument>
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QViewSourceDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+QViewSourceDialog::QViewSourceDialog(QViewSource * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(viewFullSourceCB, SIGNAL(clicked()),
+               this, SLOT(update()));
+       connect(autoUpdateCB, SIGNAL(toggled(bool)),
+               updatePB, SLOT(setDisabled(bool)));
+       connect(updatePB, SIGNAL(clicked()),
+               this, SLOT(update()));
+
+       // setting a document at this point trigger an assertion in Qt
+       // so we disable the signals here:
+       form_->document()->blockSignals(true);
+       viewSourceTV->setDocument(form_->document());
+       form_->document()->blockSignals(false);
+       viewSourceTV->setReadOnly(true);
+       ///dialog_->viewSourceTV->setAcceptRichText(false);
+       // this is personal. I think source code should be in fixed-size font
+       QFont font(toqstr(theApp()->typewriterFontName()));
+       font.setKerning(false);
+       font.setFixedPitch(true);
+       font.setStyleHint(QFont::TypeWriter);
+       viewSourceTV->setFont(font);
+       // again, personal taste
+       viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
+}
+
+
+void QViewSourceDialog::update()
+{
+       if (autoUpdateCB->isChecked())
+               form_->update(viewFullSourceCB->isChecked());
+
+       QWidget::update();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// LaTeXHighlighter
+//
+/////////////////////////////////////////////////////////////////////
+
+
+LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent)
+       : QSyntaxHighlighter(parent)
+{
+       keywordFormat.setForeground(Qt::darkBlue);
+       keywordFormat.setFontWeight(QFont::Bold);
+       commentFormat.setForeground(Qt::darkGray);
+       mathFormat.setForeground(Qt::red);
+}
+
+
+void LaTeXHighlighter::highlightBlock(QString const & text)
+{
+       // $ $ 
+       QRegExp exprMath("\\$[^\\$]*\\$");
+       int index = text.indexOf(exprMath);
+       while (index >= 0) {
+               int length = exprMath.matchedLength();
+               setFormat(index, length, mathFormat);
+               index = text.indexOf(exprMath, index + length);
+       }
+       // [ ]
+       QRegExp exprStartDispMath("(\\\\\\[|"
+               "\\\\begin\\{equation\\**\\}|"
+               "\\\\begin\\{eqnarray\\**\\}|"
+               "\\\\begin\\{align(ed|at)*\\**\\}|"
+               "\\\\begin\\{flalign\\**\\}|"
+               "\\\\begin\\{gather\\**\\}|"
+               "\\\\begin\\{multline\\**\\}|"
+               "\\\\begin\\{array\\**\\}|"
+               "\\\\begin\\{cases\\**\\}"
+               ")");
+       QRegExp exprEndDispMath("(\\\\\\]|"
+               "\\\\end\\{equation\\**\\}|"
+               "\\\\end\\{eqnarray\\**\\}|"
+               "\\\\end\\{align(ed|at)*\\**\\}|"
+               "\\\\end\\{flalign\\**\\}|"
+               "\\\\end\\{gather\\**\\}|"
+               "\\\\end\\{multline\\**\\}|"
+               "\\\\end\\{array\\**\\}|"
+               "\\\\end\\{cases\\**\\}"
+               ")");
+       int startIndex = 0;
+       // if previous block was in 'disp math'
+       // start search from 0 (for end disp math)
+       // otherwise, start search from 'begin disp math'
+       if (previousBlockState() != 1)
+               startIndex = text.indexOf(exprStartDispMath);
+       while (startIndex >= 0) {
+               int endIndex = text.indexOf(exprEndDispMath, startIndex);
+               int length;
+               if (endIndex == -1) {
+                       setCurrentBlockState(1);
+                       length = text.length() - startIndex;
+               } else {
+                       length = endIndex - startIndex + exprEndDispMath.matchedLength();
+               }
+               setFormat(startIndex, length, mathFormat);
+               startIndex = text.indexOf(exprStartDispMath, startIndex + length);
+       }
+       // \whatever
+       QRegExp exprKeyword("\\\\[A-Za-z]+");
+       index = text.indexOf(exprKeyword);
+       while (index >= 0) {
+               int length = exprKeyword.matchedLength();
+               setFormat(index, length, keywordFormat);
+               index = text.indexOf(exprKeyword, index + length);
+       }
+       // comment
+       QRegExp exprComment("(^|[^\\\\])%.*$");
+       index = text.indexOf(exprComment);
+       while (index >= 0) {
+               int const length = exprComment.matchedLength();
+               setFormat(index, length, commentFormat);
+               index = text.indexOf(exprComment, index + length);
+       }
+}
+
+
+QViewSource::QViewSource(Dialog & parent)
+       : ControlViewSource(parent)
+{
+       document_ = new QTextDocument(this);
+       highlighter_ = new LaTeXHighlighter(document_);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// QViewSource
+//
+/////////////////////////////////////////////////////////////////////
+
+void QViewSource::update(bool full_source)
+{
+       document_->setPlainText(toqstr(updateContent(full_source)));
+}
+
+
+} // namespace frontend
+} // namespace lyx
+
+#include "QViewSource_moc.cpp"
diff --git a/src/frontends/qt4/QWrap.C b/src/frontends/qt4/QWrap.C
deleted file mode 100644 (file)
index 0213a0f..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * \file QWrap.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jürgen Spitzmüller
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QWrap.h"
-#include "Qt2BC.h"
-
-#include "LengthCombo.h"
-#include "qt_helpers.h"
-
-#include "controllers/ControlWrap.h"
-
-#include "insets/InsetWrap.h"
-
-#include "support/convert.h"
-#include "support/lstrings.h"
-
-#include <QLineEdit>
-#include <QCloseEvent>
-#include <QPushButton>
-
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-/////////////////////////////////////////////////////////////////////
-//
-// QWrapDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-QWrapDialog::QWrapDialog(QWrap * form)
-       : form_(form)
-{
-       setupUi(this);
-
-       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-
-       connect(widthED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
-       connect(unitsLC, SIGNAL(selectionChanged(LyXLength::UNIT)),
-               this, SLOT(change_adaptor()));
-       connect(valignCO, SIGNAL(highlighted(const QString &)),
-               this, SLOT(change_adaptor()));
-}
-
-
-void QWrapDialog::closeEvent(QCloseEvent * e)
-{
-       form_->slotWMHide();
-       e->accept();
-}
-
-
-void QWrapDialog::change_adaptor()
-{
-       form_->changed();
-}
-
-/////////////////////////////////////////////////////////////////////
-//
-// QWrap
-//
-/////////////////////////////////////////////////////////////////////
-
-typedef QController<ControlWrap, QView<QWrapDialog> > wrap_base_class;
-
-QWrap::QWrap(Dialog & parent)
-       : wrap_base_class(parent, _("Text Wrap Settings"))
-{
-}
-
-
-void QWrap::build_dialog()
-{
-       dialog_.reset(new QWrapDialog(this));
-
-       bcview().setRestore(dialog_->restorePB);
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-
-       bcview().addReadOnly(dialog_->widthED);
-       bcview().addReadOnly(dialog_->unitsLC);
-       bcview().addReadOnly(dialog_->valignCO);
-}
-
-
-void QWrap::apply()
-{
-       double const value = convert<double>(fromqstr(dialog_->widthED->text()));
-       LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
-       if (dialog_->widthED->text().isEmpty())
-               unit = LyXLength::UNIT_NONE;
-
-       InsetWrapParams & params = controller().params();
-
-       params.width = LyXLength(value, unit);
-
-       switch (dialog_->valignCO->currentIndex()) {
-       case 0:
-               params.placement.erase();
-               break;
-       case 1:
-               params.placement = "l";
-               break;
-       case 2:
-               params.placement = "r";
-               break;
-       case 3:
-               params.placement = "p";
-               break;
-       }
-}
-
-
-static string const numtostr(double val)
-{
-       string a = convert<string>(val);
-#ifdef WITH_WARNINGS
-#warning Will this test ever trigger? (Lgb)
-#endif
-       if (a == "0")
-               a.erase();
-       return a;
-}
-
-
-void QWrap::update_contents()
-{
-       InsetWrapParams & params = controller().params();
-
-       LyXLength len(params.width);
-       dialog_->widthED->setText(toqstr(numtostr(len.value())));
-       dialog_->unitsLC->setCurrentItem(len.unit());
-
-       int item = 0;
-       if (params.placement == "l")
-               item = 1;
-       else if (params.placement == "r")
-               item = 2;
-       else if (params.placement == "p")
-               item = 3;
-
-       dialog_->valignCO->setCurrentIndex(item);
-}
-
-} // namespace frontend
-} // namespace lyx
-
-
-#include "QWrap_moc.cpp"
diff --git a/src/frontends/qt4/QWrap.cpp b/src/frontends/qt4/QWrap.cpp
new file mode 100644 (file)
index 0000000..0213a0f
--- /dev/null
@@ -0,0 +1,166 @@
+/**
+ * \file QWrap.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "QWrap.h"
+#include "Qt2BC.h"
+
+#include "LengthCombo.h"
+#include "qt_helpers.h"
+
+#include "controllers/ControlWrap.h"
+
+#include "insets/InsetWrap.h"
+
+#include "support/convert.h"
+#include "support/lstrings.h"
+
+#include <QLineEdit>
+#include <QCloseEvent>
+#include <QPushButton>
+
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+/////////////////////////////////////////////////////////////////////
+//
+// QWrapDialog
+//
+/////////////////////////////////////////////////////////////////////
+
+
+QWrapDialog::QWrapDialog(QWrap * form)
+       : form_(form)
+{
+       setupUi(this);
+
+       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
+       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+       connect(widthED, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
+       connect(unitsLC, SIGNAL(selectionChanged(LyXLength::UNIT)),
+               this, SLOT(change_adaptor()));
+       connect(valignCO, SIGNAL(highlighted(const QString &)),
+               this, SLOT(change_adaptor()));
+}
+
+
+void QWrapDialog::closeEvent(QCloseEvent * e)
+{
+       form_->slotWMHide();
+       e->accept();
+}
+
+
+void QWrapDialog::change_adaptor()
+{
+       form_->changed();
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+// QWrap
+//
+/////////////////////////////////////////////////////////////////////
+
+typedef QController<ControlWrap, QView<QWrapDialog> > wrap_base_class;
+
+QWrap::QWrap(Dialog & parent)
+       : wrap_base_class(parent, _("Text Wrap Settings"))
+{
+}
+
+
+void QWrap::build_dialog()
+{
+       dialog_.reset(new QWrapDialog(this));
+
+       bcview().setRestore(dialog_->restorePB);
+       bcview().setOK(dialog_->okPB);
+       bcview().setApply(dialog_->applyPB);
+       bcview().setCancel(dialog_->closePB);
+
+       bcview().addReadOnly(dialog_->widthED);
+       bcview().addReadOnly(dialog_->unitsLC);
+       bcview().addReadOnly(dialog_->valignCO);
+}
+
+
+void QWrap::apply()
+{
+       double const value = convert<double>(fromqstr(dialog_->widthED->text()));
+       LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
+       if (dialog_->widthED->text().isEmpty())
+               unit = LyXLength::UNIT_NONE;
+
+       InsetWrapParams & params = controller().params();
+
+       params.width = LyXLength(value, unit);
+
+       switch (dialog_->valignCO->currentIndex()) {
+       case 0:
+               params.placement.erase();
+               break;
+       case 1:
+               params.placement = "l";
+               break;
+       case 2:
+               params.placement = "r";
+               break;
+       case 3:
+               params.placement = "p";
+               break;
+       }
+}
+
+
+static string const numtostr(double val)
+{
+       string a = convert<string>(val);
+#ifdef WITH_WARNINGS
+#warning Will this test ever trigger? (Lgb)
+#endif
+       if (a == "0")
+               a.erase();
+       return a;
+}
+
+
+void QWrap::update_contents()
+{
+       InsetWrapParams & params = controller().params();
+
+       LyXLength len(params.width);
+       dialog_->widthED->setText(toqstr(numtostr(len.value())));
+       dialog_->unitsLC->setCurrentItem(len.unit());
+
+       int item = 0;
+       if (params.placement == "l")
+               item = 1;
+       else if (params.placement == "r")
+               item = 2;
+       else if (params.placement == "p")
+               item = 3;
+
+       dialog_->valignCO->setCurrentIndex(item);
+}
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "QWrap_moc.cpp"
diff --git a/src/frontends/qt4/Qt2BC.C b/src/frontends/qt4/Qt2BC.C
deleted file mode 100644 (file)
index e6b42ad..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * \file Qt2BC.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Allan Rae
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include <QPushButton>
-#include <QLineEdit>
-
-namespace lyx {
-namespace frontend {
-
-Qt2BC::Qt2BC(ButtonController const & parent,
-            docstring const & cancel, docstring const & close)
-       : GuiBC<QPushButton, QWidget>(parent, cancel, close)
-{}
-
-
-void Qt2BC::setButtonEnabled(QPushButton * obj, bool enabled) const
-{
-       obj->setEnabled(enabled);
-}
-
-
-void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const
-{
-       // yuck, rtti, but the user comes first
-       if (QLineEdit * le = qobject_cast<QLineEdit*>(obj))
-               le->setReadOnly(!enabled);
-       else
-               obj->setEnabled(enabled);
-
-       obj->setFocusPolicy(enabled ? Qt::StrongFocus : Qt::NoFocus);
-}
-
-
-void Qt2BC::setButtonLabel(QPushButton * obj, docstring const & label) const
-{
-       obj->setText(toqstr(label));
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/Qt2BC.cpp b/src/frontends/qt4/Qt2BC.cpp
new file mode 100644 (file)
index 0000000..e6b42ad
--- /dev/null
@@ -0,0 +1,53 @@
+/**
+ * \file Qt2BC.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Allan Rae
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include <QPushButton>
+#include <QLineEdit>
+
+namespace lyx {
+namespace frontend {
+
+Qt2BC::Qt2BC(ButtonController const & parent,
+            docstring const & cancel, docstring const & close)
+       : GuiBC<QPushButton, QWidget>(parent, cancel, close)
+{}
+
+
+void Qt2BC::setButtonEnabled(QPushButton * obj, bool enabled) const
+{
+       obj->setEnabled(enabled);
+}
+
+
+void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const
+{
+       // yuck, rtti, but the user comes first
+       if (QLineEdit * le = qobject_cast<QLineEdit*>(obj))
+               le->setReadOnly(!enabled);
+       else
+               obj->setEnabled(enabled);
+
+       obj->setFocusPolicy(enabled ? Qt::StrongFocus : Qt::NoFocus);
+}
+
+
+void Qt2BC::setButtonLabel(QPushButton * obj, docstring const & label) const
+{
+       obj->setText(toqstr(label));
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/TocModel.C b/src/frontends/qt4/TocModel.C
deleted file mode 100644 (file)
index 8f923d8..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/**
- * \file QTocDialog.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "TocModel.h"
-
-#include "debug.h"
-
-#include <vector>
-#include <string>
-
-using std::endl;
-using std::pair;
-using std::map;
-using std::vector;
-using std::string;
-using std::make_pair;
-using std::max;
-using std::min;
-
-namespace lyx {
-namespace frontend {
-
-
-TocModel::TocModel(Toc const & toc)
-{
-       populate(toc);
-}
-
-
-TocModel const & TocModel::operator=(Toc const & toc)
-{
-       populate(toc);
-       return *this;
-}
-
-
-TocIterator const TocModel::tocIterator(QModelIndex const & index) const
-{
-       TocMap::const_iterator map_it = toc_map_.find(index);
-       BOOST_ASSERT(map_it != toc_map_.end()); 
-       return map_it->second;
-}
-
-
-QModelIndex const TocModel::modelIndex(TocIterator const & it) const
-{
-       ModelMap::const_iterator map_it = model_map_.find(it);
-       //BOOST_ASSERT(it != model_map_.end());
-
-       if (map_it == model_map_.end())
-               return QModelIndex();
-       
-       return map_it->second;
-}
-
-
-void TocModel::clear()
-{
-       QStandardItemModel::clear();
-       toc_map_.clear();
-       model_map_.clear();
-       removeRows(0, rowCount());
-       removeColumns(0, columnCount());
-}
-
-
-void TocModel::populate(Toc const & toc)
-{
-       clear();
-
-       if (toc.empty())
-               return;
-       int current_row;
-       QModelIndex top_level_item;
-
-       TocIterator iter = toc.begin();
-       TocIterator end = toc.end();
-
-       insertColumns(0, 1);
-       maxdepth_ = 0;
-       mindepth_ = INT_MAX;
-
-       while (iter != end) {
-
-               if (iter->isValid()) {
-
-                       maxdepth_ = max(maxdepth_, iter->depth());
-                       mindepth_ = min(mindepth_, iter->depth());
-                       current_row = rowCount();
-                       insertRows(current_row, 1);
-                       top_level_item = QStandardItemModel::index(current_row, 0);
-                       //setData(top_level_item, toqstr(iter->str()));
-                       setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
-
-                       // This looks like a gcc bug, in principle this should work:
-                       //toc_map_[top_level_item] = iter;
-                       // but it crashes with gcc-4.1 and 4.0.2
-                       toc_map_.insert( TocPair(top_level_item, iter) );
-                       model_map_[iter] = top_level_item;
-
-                       LYXERR(Debug::GUI)
-                               << "Toc: at depth " << iter->depth()
-                               << ", added item " << to_utf8(iter->str())
-                               << endl;
-
-                       populate(iter, end, top_level_item);
-               }
-
-               if (iter == end)
-                       break;
-
-               ++iter;
-       }
-       
-       setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
-//     emit headerDataChanged();
-}
-
-
-void TocModel::populate(TocIterator & iter,
-                                               TocIterator const & end,
-                                               QModelIndex const & parent)
-{
-       int curdepth = iter->depth() + 1;
-       
-       int current_row;
-       QModelIndex child_item;
-
-       insertColumns(0, 1, parent);
-       while (iter != end) {
-
-               ++iter;
-
-               if (iter == end)
-                       break;
-
-               if (iter->depth() < curdepth) {
-                       --iter;
-                       return;
-               }
-               
-               maxdepth_ = max(maxdepth_, iter->depth());
-               mindepth_ = min(mindepth_, iter->depth());
-               current_row = rowCount(parent);
-               insertRows(current_row, 1, parent);
-               child_item = QStandardItemModel::index(current_row, 0, parent);
-               //setData(child_item, toqstr(iter->str()));
-               setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
-
-               // This looks like a gcc bug, in principle this should work:
-               //toc_map_[child_item] = iter;
-               // but it crashes with gcc-4.1 and 4.0.2
-               toc_map_.insert( TocPair(child_item, iter) );
-               model_map_[iter] = child_item;
-               populate(iter, end, child_item);
-       }
-}
-
-
-int TocModel::modelDepth()
-{
-       return maxdepth_ - mindepth_;
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "TocModel_moc.cpp"
diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp
new file mode 100644 (file)
index 0000000..8f923d8
--- /dev/null
@@ -0,0 +1,178 @@
+/**
+ * \file QTocDialog.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "TocModel.h"
+
+#include "debug.h"
+
+#include <vector>
+#include <string>
+
+using std::endl;
+using std::pair;
+using std::map;
+using std::vector;
+using std::string;
+using std::make_pair;
+using std::max;
+using std::min;
+
+namespace lyx {
+namespace frontend {
+
+
+TocModel::TocModel(Toc const & toc)
+{
+       populate(toc);
+}
+
+
+TocModel const & TocModel::operator=(Toc const & toc)
+{
+       populate(toc);
+       return *this;
+}
+
+
+TocIterator const TocModel::tocIterator(QModelIndex const & index) const
+{
+       TocMap::const_iterator map_it = toc_map_.find(index);
+       BOOST_ASSERT(map_it != toc_map_.end()); 
+       return map_it->second;
+}
+
+
+QModelIndex const TocModel::modelIndex(TocIterator const & it) const
+{
+       ModelMap::const_iterator map_it = model_map_.find(it);
+       //BOOST_ASSERT(it != model_map_.end());
+
+       if (map_it == model_map_.end())
+               return QModelIndex();
+       
+       return map_it->second;
+}
+
+
+void TocModel::clear()
+{
+       QStandardItemModel::clear();
+       toc_map_.clear();
+       model_map_.clear();
+       removeRows(0, rowCount());
+       removeColumns(0, columnCount());
+}
+
+
+void TocModel::populate(Toc const & toc)
+{
+       clear();
+
+       if (toc.empty())
+               return;
+       int current_row;
+       QModelIndex top_level_item;
+
+       TocIterator iter = toc.begin();
+       TocIterator end = toc.end();
+
+       insertColumns(0, 1);
+       maxdepth_ = 0;
+       mindepth_ = INT_MAX;
+
+       while (iter != end) {
+
+               if (iter->isValid()) {
+
+                       maxdepth_ = max(maxdepth_, iter->depth());
+                       mindepth_ = min(mindepth_, iter->depth());
+                       current_row = rowCount();
+                       insertRows(current_row, 1);
+                       top_level_item = QStandardItemModel::index(current_row, 0);
+                       //setData(top_level_item, toqstr(iter->str()));
+                       setData(top_level_item, toqstr(iter->str()), Qt::DisplayRole);
+
+                       // This looks like a gcc bug, in principle this should work:
+                       //toc_map_[top_level_item] = iter;
+                       // but it crashes with gcc-4.1 and 4.0.2
+                       toc_map_.insert( TocPair(top_level_item, iter) );
+                       model_map_[iter] = top_level_item;
+
+                       LYXERR(Debug::GUI)
+                               << "Toc: at depth " << iter->depth()
+                               << ", added item " << to_utf8(iter->str())
+                               << endl;
+
+                       populate(iter, end, top_level_item);
+               }
+
+               if (iter == end)
+                       break;
+
+               ++iter;
+       }
+       
+       setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
+//     emit headerDataChanged();
+}
+
+
+void TocModel::populate(TocIterator & iter,
+                                               TocIterator const & end,
+                                               QModelIndex const & parent)
+{
+       int curdepth = iter->depth() + 1;
+       
+       int current_row;
+       QModelIndex child_item;
+
+       insertColumns(0, 1, parent);
+       while (iter != end) {
+
+               ++iter;
+
+               if (iter == end)
+                       break;
+
+               if (iter->depth() < curdepth) {
+                       --iter;
+                       return;
+               }
+               
+               maxdepth_ = max(maxdepth_, iter->depth());
+               mindepth_ = min(mindepth_, iter->depth());
+               current_row = rowCount(parent);
+               insertRows(current_row, 1, parent);
+               child_item = QStandardItemModel::index(current_row, 0, parent);
+               //setData(child_item, toqstr(iter->str()));
+               setData(child_item, toqstr(iter->str()), Qt::DisplayRole);
+
+               // This looks like a gcc bug, in principle this should work:
+               //toc_map_[child_item] = iter;
+               // but it crashes with gcc-4.1 and 4.0.2
+               toc_map_.insert( TocPair(child_item, iter) );
+               model_map_[iter] = child_item;
+               populate(iter, end, child_item);
+       }
+}
+
+
+int TocModel::modelDepth()
+{
+       return maxdepth_ - mindepth_;
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "TocModel_moc.cpp"
diff --git a/src/frontends/qt4/TocWidget.C b/src/frontends/qt4/TocWidget.C
deleted file mode 100644 (file)
index 17e4c53..0000000
+++ /dev/null
@@ -1,290 +0,0 @@
-/**
- * \file TocWidget.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "TocWidget.h"
-
-#include "QToc.h"
-#include "qt_helpers.h"
-
-#include "debug.h"
-
-#include <QHeaderView>
-#include <QPushButton>
-#include <QTreeWidgetItem>
-
-#include <vector>
-#include <string>
-#include <stack>
-
-using std::endl;
-using std::pair;
-using std::stack;
-using std::vector;
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-
-TocWidget::TocWidget(QToc * form, QWidget * parent)
-       : QWidget(parent), form_(form), depth_(0)
-{
-       setupUi(this);
-
-       connect(form, SIGNAL(modelReset()),
-               SLOT(updateGui()));
-
-       // avoid flickering
-       tocTV->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-
-       tocTV->showColumn(0);
-
-       // hide the pointless QHeader for now
-       // in the future, new columns may appear
-       // like labels, bookmarks, etc...
-       // tocTV->header()->hide();
-       tocTV->header()->setVisible(false);
-}
-
-
-void TocWidget::selectionChanged(const QModelIndex & current,
-                                 const QModelIndex & /*previous*/)
-{
-       LYXERR(Debug::GUI)
-               << "selectionChanged index " << current.row()
-               << ", " << current.column()
-               << endl;
-
-       form_->goTo(typeCO->currentIndex(), current);
-}
-
-
-void TocWidget::on_updatePB_clicked()
-{
-       form_->updateBackend();
-       form_->update();
-       update();
-}
-
-/* FIXME (Ugras 17/11/06):
-I have implemented a getIndexDepth function to get the model indices. In my
-opinion, somebody should derive a new qvariant class for tocModelItem
-which saves the string data and depth information. that will save the
-depth calculation.
-*/
-int TocWidget::getIndexDepth(QModelIndex const & index, int depth)
-{
-       ++depth;
-       return (index.parent() == QModelIndex())? depth : getIndexDepth(index.parent(),depth);
-}
-
-
-void TocWidget::on_depthSL_valueChanged(int depth)
-{
-       if (depth == depth_)
-               return;
-       setTreeDepth(depth);
-}
-
-
-void TocWidget::setTreeDepth(int depth)
-{
-       depth_ = depth;
-
-       // expanding and then collapsing is probably better, 
-       // but my qt 4.1.2 doesn't have expandAll()..
-       //tocTV->expandAll(); 
-       QModelIndexList indices = tocTV->model()->match(
-               tocTV->model()->index(0,0),
-               Qt::DisplayRole, "*", -1, 
-               Qt::MatchWildcard|Qt::MatchRecursive);
-       
-       int size = indices.size();
-       for (int i = 0; i < size; i++) {
-               QModelIndex index = indices[i];
-               if (getIndexDepth(index) < depth_) 
-                       tocTV->expand(index); 
-               else
-                       tocTV->collapse(index); 
-       }
-}
-
-
-void TocWidget::on_typeCO_activated(int value)
-{
-       setTocModel(value);
-}
-
-
-void TocWidget::on_moveUpPB_clicked()
-{
-       enableControls(false);
-       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
-       if (!list.isEmpty()) {
-               enableControls(false);
-               form_->goTo(typeCO->currentIndex(), list[0]);
-               form_->outlineUp();
-               enableControls(true);
-       }
-}
-
-
-void TocWidget::on_moveDownPB_clicked()
-{
-       enableControls(false);
-       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
-       if (!list.isEmpty()) {
-               enableControls(false);
-               form_->goTo(typeCO->currentIndex(), list[0]);
-               form_->outlineDown();
-               enableControls(true);
-       }
-}
-
-
-void TocWidget::on_moveInPB_clicked()
-{
-       enableControls(false);
-       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
-       if (!list.isEmpty()) {
-               enableControls(false);
-               form_->goTo(typeCO->currentIndex(), list[0]);
-               form_->outlineIn();
-               enableControls(true);
-       }
-}
-
-
-void TocWidget::on_moveOutPB_clicked()
-{
-       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
-       if (!list.isEmpty()) {
-               enableControls(false);
-               form_->goTo(typeCO->currentIndex(), list[0]);
-               form_->outlineOut();
-               enableControls(true);
-       }
-}
-
-
-void TocWidget::select(QModelIndex const & index)
-{
-       if (!index.isValid()) {
-               LYXERR(Debug::GUI)
-                       << "TocWidget::select(): QModelIndex is invalid!" << endl;
-               return;
-       }
-
-       tocTV->selectionModel()->blockSignals(true);
-       tocTV->scrollTo(index);
-       tocTV->selectionModel()->setCurrentIndex(index,
-               QItemSelectionModel::ClearAndSelect);
-       tocTV->selectionModel()->blockSignals(false);
-}
-
-
-void TocWidget::enableControls(bool enable)
-{
-       updatePB->setEnabled(enable);
-
-       if (!form_->canOutline(typeCO->currentIndex()))
-               enable = false;
-
-       moveUpPB->setEnabled(enable);
-       moveDownPB->setEnabled(enable);
-       moveInPB->setEnabled(enable);
-       moveOutPB->setEnabled(enable);
-
-       depthSL->setEnabled(enable);
-}
-
-
-void TocWidget::update()
-{
-       LYXERR(Debug::GUI) << "In TocWidget::update()" << endl;
-       select(form_->getCurrentIndex(typeCO->currentIndex()));
-       QWidget::update();
-}
-
-
-void TocWidget::updateGui()
-{
-       QStringListModel * type_model = form_->typeModel();
-       if (type_model->stringList().isEmpty()) {
-               enableControls(false);
-               typeCO->setModel(type_model);
-               tocTV->setModel(new QStandardItemModel);
-               tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
-               return;
-       }
-
-       QString current_text = typeCO->currentText();
-       typeCO->setModel(type_model);
-       int const current_type = typeCO->findText(current_text);
-       if (current_type != -1)
-               typeCO->setCurrentIndex(current_type);
-       else
-               typeCO->setCurrentIndex(form_->selectedType());
-
-       setTocModel(typeCO->currentIndex());
-}
-
-
-void TocWidget::setTocModel(size_t type)
-{
-       bool controls_enabled = false;
-       QStandardItemModel * toc_model = form_->tocModel(type);
-       if (toc_model) {
-               controls_enabled = toc_model->rowCount() > 0;
-               tocTV->setModel(toc_model);
-               tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
-       }
-
-       enableControls(controls_enabled);
-
-       reconnectSelectionModel();
-
-       if (controls_enabled) {
-               depthSL->setMaximum(form_->getTocDepth(type));
-               depthSL->setValue(depth_);
-       }
-
-       LYXERR(Debug::GUI) << "In TocWidget::updateGui()" << endl;
-
-       select(form_->getCurrentIndex(typeCO->currentIndex()));
-
-       if (toc_model) {
-               LYXERR(Debug::GUI)
-               << "form_->tocModel()->rowCount " 
-                       << toc_model->rowCount()
-                       << "\nform_->tocModel()->columnCount "
-                       << toc_model->columnCount()
-                       << endl;
-       }
-}
-
-
-void TocWidget::reconnectSelectionModel()
-{
-       connect(tocTV->selectionModel(),
-               SIGNAL(currentChanged(const QModelIndex &,
-                       const QModelIndex &)),
-               this, SLOT(selectionChanged(const QModelIndex &,
-                       const QModelIndex &)));
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "TocWidget_moc.cpp"
diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp
new file mode 100644 (file)
index 0000000..17e4c53
--- /dev/null
@@ -0,0 +1,290 @@
+/**
+ * \file TocWidget.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ * \author Abdelrazak Younes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "TocWidget.h"
+
+#include "QToc.h"
+#include "qt_helpers.h"
+
+#include "debug.h"
+
+#include <QHeaderView>
+#include <QPushButton>
+#include <QTreeWidgetItem>
+
+#include <vector>
+#include <string>
+#include <stack>
+
+using std::endl;
+using std::pair;
+using std::stack;
+using std::vector;
+using std::string;
+
+
+namespace lyx {
+namespace frontend {
+
+
+TocWidget::TocWidget(QToc * form, QWidget * parent)
+       : QWidget(parent), form_(form), depth_(0)
+{
+       setupUi(this);
+
+       connect(form, SIGNAL(modelReset()),
+               SLOT(updateGui()));
+
+       // avoid flickering
+       tocTV->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+
+       tocTV->showColumn(0);
+
+       // hide the pointless QHeader for now
+       // in the future, new columns may appear
+       // like labels, bookmarks, etc...
+       // tocTV->header()->hide();
+       tocTV->header()->setVisible(false);
+}
+
+
+void TocWidget::selectionChanged(const QModelIndex & current,
+                                 const QModelIndex & /*previous*/)
+{
+       LYXERR(Debug::GUI)
+               << "selectionChanged index " << current.row()
+               << ", " << current.column()
+               << endl;
+
+       form_->goTo(typeCO->currentIndex(), current);
+}
+
+
+void TocWidget::on_updatePB_clicked()
+{
+       form_->updateBackend();
+       form_->update();
+       update();
+}
+
+/* FIXME (Ugras 17/11/06):
+I have implemented a getIndexDepth function to get the model indices. In my
+opinion, somebody should derive a new qvariant class for tocModelItem
+which saves the string data and depth information. that will save the
+depth calculation.
+*/
+int TocWidget::getIndexDepth(QModelIndex const & index, int depth)
+{
+       ++depth;
+       return (index.parent() == QModelIndex())? depth : getIndexDepth(index.parent(),depth);
+}
+
+
+void TocWidget::on_depthSL_valueChanged(int depth)
+{
+       if (depth == depth_)
+               return;
+       setTreeDepth(depth);
+}
+
+
+void TocWidget::setTreeDepth(int depth)
+{
+       depth_ = depth;
+
+       // expanding and then collapsing is probably better, 
+       // but my qt 4.1.2 doesn't have expandAll()..
+       //tocTV->expandAll(); 
+       QModelIndexList indices = tocTV->model()->match(
+               tocTV->model()->index(0,0),
+               Qt::DisplayRole, "*", -1, 
+               Qt::MatchWildcard|Qt::MatchRecursive);
+       
+       int size = indices.size();
+       for (int i = 0; i < size; i++) {
+               QModelIndex index = indices[i];
+               if (getIndexDepth(index) < depth_) 
+                       tocTV->expand(index); 
+               else
+                       tocTV->collapse(index); 
+       }
+}
+
+
+void TocWidget::on_typeCO_activated(int value)
+{
+       setTocModel(value);
+}
+
+
+void TocWidget::on_moveUpPB_clicked()
+{
+       enableControls(false);
+       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               enableControls(false);
+               form_->goTo(typeCO->currentIndex(), list[0]);
+               form_->outlineUp();
+               enableControls(true);
+       }
+}
+
+
+void TocWidget::on_moveDownPB_clicked()
+{
+       enableControls(false);
+       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               enableControls(false);
+               form_->goTo(typeCO->currentIndex(), list[0]);
+               form_->outlineDown();
+               enableControls(true);
+       }
+}
+
+
+void TocWidget::on_moveInPB_clicked()
+{
+       enableControls(false);
+       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               enableControls(false);
+               form_->goTo(typeCO->currentIndex(), list[0]);
+               form_->outlineIn();
+               enableControls(true);
+       }
+}
+
+
+void TocWidget::on_moveOutPB_clicked()
+{
+       QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               enableControls(false);
+               form_->goTo(typeCO->currentIndex(), list[0]);
+               form_->outlineOut();
+               enableControls(true);
+       }
+}
+
+
+void TocWidget::select(QModelIndex const & index)
+{
+       if (!index.isValid()) {
+               LYXERR(Debug::GUI)
+                       << "TocWidget::select(): QModelIndex is invalid!" << endl;
+               return;
+       }
+
+       tocTV->selectionModel()->blockSignals(true);
+       tocTV->scrollTo(index);
+       tocTV->selectionModel()->setCurrentIndex(index,
+               QItemSelectionModel::ClearAndSelect);
+       tocTV->selectionModel()->blockSignals(false);
+}
+
+
+void TocWidget::enableControls(bool enable)
+{
+       updatePB->setEnabled(enable);
+
+       if (!form_->canOutline(typeCO->currentIndex()))
+               enable = false;
+
+       moveUpPB->setEnabled(enable);
+       moveDownPB->setEnabled(enable);
+       moveInPB->setEnabled(enable);
+       moveOutPB->setEnabled(enable);
+
+       depthSL->setEnabled(enable);
+}
+
+
+void TocWidget::update()
+{
+       LYXERR(Debug::GUI) << "In TocWidget::update()" << endl;
+       select(form_->getCurrentIndex(typeCO->currentIndex()));
+       QWidget::update();
+}
+
+
+void TocWidget::updateGui()
+{
+       QStringListModel * type_model = form_->typeModel();
+       if (type_model->stringList().isEmpty()) {
+               enableControls(false);
+               typeCO->setModel(type_model);
+               tocTV->setModel(new QStandardItemModel);
+               tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
+               return;
+       }
+
+       QString current_text = typeCO->currentText();
+       typeCO->setModel(type_model);
+       int const current_type = typeCO->findText(current_text);
+       if (current_type != -1)
+               typeCO->setCurrentIndex(current_type);
+       else
+               typeCO->setCurrentIndex(form_->selectedType());
+
+       setTocModel(typeCO->currentIndex());
+}
+
+
+void TocWidget::setTocModel(size_t type)
+{
+       bool controls_enabled = false;
+       QStandardItemModel * toc_model = form_->tocModel(type);
+       if (toc_model) {
+               controls_enabled = toc_model->rowCount() > 0;
+               tocTV->setModel(toc_model);
+               tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
+       }
+
+       enableControls(controls_enabled);
+
+       reconnectSelectionModel();
+
+       if (controls_enabled) {
+               depthSL->setMaximum(form_->getTocDepth(type));
+               depthSL->setValue(depth_);
+       }
+
+       LYXERR(Debug::GUI) << "In TocWidget::updateGui()" << endl;
+
+       select(form_->getCurrentIndex(typeCO->currentIndex()));
+
+       if (toc_model) {
+               LYXERR(Debug::GUI)
+               << "form_->tocModel()->rowCount " 
+                       << toc_model->rowCount()
+                       << "\nform_->tocModel()->columnCount "
+                       << toc_model->columnCount()
+                       << endl;
+       }
+}
+
+
+void TocWidget::reconnectSelectionModel()
+{
+       connect(tocTV->selectionModel(),
+               SIGNAL(currentChanged(const QModelIndex &,
+                       const QModelIndex &)),
+               this, SLOT(selectionChanged(const QModelIndex &,
+                       const QModelIndex &)));
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "TocWidget_moc.cpp"
diff --git a/src/frontends/qt4/UrlView.C b/src/frontends/qt4/UrlView.C
deleted file mode 100644 (file)
index 5d6dd23..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * \file UrlView.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "UrlView.h"
-#include "QURLDialog.h"
-#include "Qt2BC.h"
-#include "qt_helpers.h"
-
-#include "controllers/ButtonController.h"
-#include "controllers/ControlCommand.h"
-
-#include <QCheckBox>
-#include <QLineEdit>
-#include <QPushButton>
-
-using std::string;
-
-namespace lyx {
-namespace frontend {
-
-typedef QController< ControlCommand, QView<QURLDialog> > urlview_base_class;
-
-UrlView::UrlView(Dialog & parent)
-       : urlview_base_class(parent, _("URL"))
-{
-}
-
-
-void UrlView::build_dialog()
-{
-       dialog_.reset(new QURLDialog(this));
-
-       bcview().setOK(dialog_->okPB);
-       bcview().setCancel(dialog_->closePB);
-       bcview().addReadOnly(dialog_->urlED);
-       bcview().addReadOnly(dialog_->nameED);
-       bcview().addReadOnly(dialog_->hyperlinkCB);
-}
-
-
-void UrlView::update_contents()
-{
-       InsetCommandParams const & params = controller().params();
-
-       dialog_->urlED->setText(toqstr(params["target"]));
-       dialog_->nameED->setText(toqstr(params["name"]));
-       dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
-
-       bc().valid(isValid());
-}
-
-
-void UrlView::apply()
-{
-       InsetCommandParams & params = controller().params();
-
-       params["target"] = qstring_to_ucs4(dialog_->urlED->text());
-       params["name"] = qstring_to_ucs4(dialog_->nameED->text());
-
-       if (dialog_->hyperlinkCB->isChecked())
-               params.setCmdName("htmlurl");
-       else
-               params.setCmdName("url");
-}
-
-
-bool UrlView::isValid()
-{
-       string const u(fromqstr(dialog_->urlED->text()));
-       string const n(fromqstr(dialog_->nameED->text()));
-
-       return !u.empty() || !n.empty();
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/UrlView.cpp b/src/frontends/qt4/UrlView.cpp
new file mode 100644 (file)
index 0000000..5d6dd23
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * \file UrlView.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "UrlView.h"
+#include "QURLDialog.h"
+#include "Qt2BC.h"
+#include "qt_helpers.h"
+
+#include "controllers/ButtonController.h"
+#include "controllers/ControlCommand.h"
+
+#include <QCheckBox>
+#include <QLineEdit>
+#include <QPushButton>
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
+
+typedef QController< ControlCommand, QView<QURLDialog> > urlview_base_class;
+
+UrlView::UrlView(Dialog & parent)
+       : urlview_base_class(parent, _("URL"))
+{
+}
+
+
+void UrlView::build_dialog()
+{
+       dialog_.reset(new QURLDialog(this));
+
+       bcview().setOK(dialog_->okPB);
+       bcview().setCancel(dialog_->closePB);
+       bcview().addReadOnly(dialog_->urlED);
+       bcview().addReadOnly(dialog_->nameED);
+       bcview().addReadOnly(dialog_->hyperlinkCB);
+}
+
+
+void UrlView::update_contents()
+{
+       InsetCommandParams const & params = controller().params();
+
+       dialog_->urlED->setText(toqstr(params["target"]));
+       dialog_->nameED->setText(toqstr(params["name"]));
+       dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
+
+       bc().valid(isValid());
+}
+
+
+void UrlView::apply()
+{
+       InsetCommandParams & params = controller().params();
+
+       params["target"] = qstring_to_ucs4(dialog_->urlED->text());
+       params["name"] = qstring_to_ucs4(dialog_->nameED->text());
+
+       if (dialog_->hyperlinkCB->isChecked())
+               params.setCmdName("htmlurl");
+       else
+               params.setCmdName("url");
+}
+
+
+bool UrlView::isValid()
+{
+       string const u(fromqstr(dialog_->urlED->text()));
+       string const n(fromqstr(dialog_->nameED->text()));
+
+       return !u.empty() || !n.empty();
+}
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/Validator.cpp b/src/frontends/qt4/Validator.cpp
new file mode 100644 (file)
index 0000000..262574d
--- /dev/null
@@ -0,0 +1,213 @@
+/**
+ * \file Validator.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+
+#include <config.h>
+
+#include "Validator.h"
+#include "qt_helpers.h"
+
+#include "gettext.h"
+#include "lyxrc.h"
+
+#include "frontends/Alert.h"
+
+#include "frontends/controllers/Dialog.h"
+
+#include "support/docstring.h"
+#include "support/lstrings.h"
+#include "support/std_ostream.h"
+
+#include <QLineEdit>
+#include <QWidget>
+
+#include <sstream>
+
+using lyx::support::isStrDbl;
+using std::string;
+
+
+namespace lyx {
+
+LengthValidator::LengthValidator(QWidget * parent)
+       : QValidator(parent),
+         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;
+}
+
+
+LengthAutoValidator::LengthAutoValidator(QWidget * parent)
+       : LengthValidator(parent)
+{}
+
+
+QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const
+{
+       string const text = fromqstr(qtext);
+       if (text == "auto")
+               return QValidator::Acceptable;
+       return LengthValidator::validate(qtext, dummy);
+}
+
+
+LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed)
+{
+       LengthAutoValidator * v = new LengthAutoValidator(ed);
+       v->setBottom(LyXLength());
+       return v;
+}
+
+
+DoubleAutoValidator::DoubleAutoValidator(QWidget * parent) : 
+       QDoubleValidator(parent) {}
+
+
+DoubleAutoValidator::DoubleAutoValidator(double bottom,
+       double top, int decimals, QObject * parent) : 
+       QDoubleValidator(bottom, top, decimals, parent) {}
+
+
+QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const {
+       string const text = fromqstr(input);
+       if (text == "auto")
+               return QValidator::Acceptable;
+       return QDoubleValidator::validate(input, pos);
+}
+
+
+PathValidator::PathValidator(bool acceptable_if_empty,
+                            QWidget * parent)
+       : QValidator(parent),
+         acceptable_if_empty_(acceptable_if_empty),
+         latex_doc_(false),
+         tex_allows_spaces_(false)
+{}
+
+
+static docstring const printable_list(docstring const & invalid_chars)
+{
+       docstring s;
+       docstring::const_iterator const begin = invalid_chars.begin();
+       docstring::const_iterator const end = invalid_chars.end();
+       docstring::const_iterator it = begin;
+
+       for (; it != end; ++it) {
+               if (it != begin)
+                       s += ", ";
+               if (*it == ' ')
+                       s += _("space");
+               else
+                       s += *it;
+       }
+
+       return s;
+}
+
+
+QValidator::State PathValidator::validate(QString & qtext, int &) const
+{
+       if (!latex_doc_)
+               return QValidator::Acceptable;
+
+       docstring const text = lyx::support::trim(qstring_to_ucs4(qtext));
+       if (text.empty())
+               return  acceptable_if_empty_ ?
+                       QValidator::Acceptable : QValidator::Intermediate;
+
+       docstring invalid_chars = from_ascii("#$%{}()[]\"^");
+       if (!tex_allows_spaces_)
+               invalid_chars += ' ';
+
+       if (text.find_first_of(invalid_chars) != docstring::npos) {
+
+               static int counter = 0;
+               if (counter == 0) {
+                       lyx::frontend::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);
+}
+
+} // namespace lyx
+
+#include "Validator_moc.cpp"
+
diff --git a/src/frontends/qt4/Validator.h b/src/frontends/qt4/Validator.h
new file mode 100644 (file)
index 0000000..686dd06
--- /dev/null
@@ -0,0 +1,168 @@
+// -*- C++ -*-
+/**
+ * \file Validator.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ * \author Richard Heck
+ *
+ * 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 VALIDATOR_H
+#define VALIDATOR_H
+
+#include "lyxlength.h"
+#include "lyxgluelength.h"
+
+#include <QValidator>
+
+class QWidget;
+class QLineEdit;
+
+
+namespace lyx {
+
+/** 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);
+
+       /** @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 *);
+
+//FIXME This should be generalized to take "text" as part of the
+//constructor and so to set what text we check for, rather than
+//hard-coding it as "auto". But see qt_helpers.h for reasons this
+//is not so trivial and an idea about how to do it. (RGH)
+/** A class to ascertain whether the data passed to the @c validate()
+ *  member function can be interpretted as a LyXGlueLength or is "auto".
+ */
+class LengthAutoValidator : public LengthValidator
+{
+       Q_OBJECT
+       public:
+       /// Define a validator for widget @c parent.
+               LengthAutoValidator(QWidget * parent);
+
+       /** @returns QValidator::Acceptable if @c data is a LyXGlueLength
+               * or is "auto". If not, returns QValidator::Intermediate.
+        */
+               QValidator::State validate(QString & data, int &) const;
+};
+
+/// @returns a new @c LengthAutoValidator that does not accept negative lengths.
+LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *);
+
+//FIXME As above, this should really take a text argument.
+/**
+ * A class to determine whether the passed is a double
+ * or is "auto".
+ *
+ */
+class DoubleAutoValidator : public QDoubleValidator {
+       Q_OBJECT
+       public:
+               DoubleAutoValidator(QWidget * parent);
+               DoubleAutoValidator(double bottom, double top, int decimals, 
+                       QObject * parent);
+               QValidator::State validate(QString & input, int & pos) const;
+};
+
+// Forward declarations
+class LyXRC;
+
+namespace frontend { class KernelDocType; } 
+
+
+/** 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);
+
+       /** @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(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 *);
+
+} // namespace lyx
+
+# endif // NOT VALIDATOR_H
diff --git a/src/frontends/qt4/checkedwidgets.C b/src/frontends/qt4/checkedwidgets.C
deleted file mode 100644 (file)
index 348bdef..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * \file qt4/CheckedLineEdit.cpp
- * 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 "CheckedLineEdit.h"
-
-#include <QLabel>
-#include <QLineEdit>
-#include <QValidator>
-
-namespace lyx {
-namespace frontend {
-
-void addCheckedLineEdit(BCView & bcview,
-                       QLineEdit * input, QWidget * label)
-{
-       bcview.addCheckedWidget(new CheckedLineEdit(input, label));
-}
-
-
-namespace {
-
-void setWarningColor(QWidget * widget)
-{
-       // Qt 2.3 does not have
-       // widget->setPaletteForegroundColor(QColor(255, 0, 0));
-       // So copy the appropriate parts of the function here:
-       QPalette pal = widget->palette();
-       pal.setColor(QPalette::Active,
-                    QPalette::Foreground,
-                    QColor(255, 0, 0));
-       widget->setPalette(pal);
-}
-
-
-void setWidget(bool valid, QLineEdit * input, QWidget * label)
-{
-       if (valid)
-               input->setPalette(QPalette());
-       else
-               setWarningColor(input);
-
-       if (!label)
-               return;
-
-       if (valid)
-               label->setPalette(QPalette());
-       else
-               setWarningColor(label);
-}
-
-} // namespace anon
-
-
-CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label)
-       : input_(input), label_(label)
-{}
-
-
-bool CheckedLineEdit::check() const
-{
-       QValidator const * validator = input_->validator();
-       if (!validator)
-               return true;
-
-       QString t = input_->text();
-       int p = 0;
-       bool const valid = validator->validate(t, p) == QValidator::Acceptable;
-
-       // Visual feedback.
-       setWidget(valid, input_, label_);
-
-       return valid;
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/qt4/checkedwidgets.h b/src/frontends/qt4/checkedwidgets.h
deleted file mode 100644 (file)
index 823e095..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// -*- C++ -*-
-/**
- * \file qt4/CheckedLineEdit.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 CHECKEDLINEEDIT_H
-#define CHECKEDLINEEDIT_H
-
-#include "BCView.h"
-
-class QWidget;
-class QLineEdit;
-
-namespace lyx {
-namespace frontend {
-
-void addCheckedLineEdit(BCView & bcview,
-       QLineEdit * input, QWidget * label = 0);
-
-class CheckedLineEdit : public CheckedWidget {
-public:
-       CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
-
-private:
-       ///
-       virtual bool check() const;
-
-       ///
-       QLineEdit * input_;
-       QWidget * label_;
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // CHECKEDLINEEDIT_H
diff --git a/src/frontends/qt4/emptytable.C b/src/frontends/qt4/emptytable.C
deleted file mode 100644 (file)
index bc233cb..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * \file EmptyTable.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "EmptyTable.h"
-
-#include <QPainter>
-#include <QMouseEvent>
-
-/**
- * A simple widget for a quick "preview" in TabularCreateDialog
- */
-
-unsigned int const cellsize = 20;
-
-
-EmptyTable::EmptyTable(QWidget * parent, int rows, int columns)
-       : QTableWidget(rows, columns, parent)
-{
-       resetCellSize();
-       setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
-       setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
-       viewport()->resize(cellsize*rows,cellsize*columns);
-}
-
-
-QSize EmptyTable::sizeHint() const
-{
-       return QSize(cellsize * (2+columnCount()), cellsize * (2+rowCount()));
-}
-
-void EmptyTable::resetCellSize()
-{
-       for(int i=0; i<rowCount(); ++i)
-               setRowHeight(i, cellsize);
-       for(int i=0; i<columnCount(); ++i)
-               setColumnWidth(i, cellsize);
-}
-
-void EmptyTable::paintCell(QPainter * p, int row, int col)
-{
-       int const x2 = columnWidth(col) - 1;
-       int const y2 = rowHeight(row) - 1;
-
-       p->fillRect(0, 0, x2, y2, QColor("white"));
-       p->drawLine(x2, 0, x2, y2);
-       p->drawLine(0, y2, x2, y2);
-
-       if (row + 1 != rowCount() || col + 1 != columnCount())
-               return;
-
-       // draw handle
-       int const step = cellsize / 5;
-       int const space = 4;
-       int x = cellsize - step;
-       int const y = cellsize - space;
-       int const ex = cellsize - space;
-       int ey = cellsize - step;
-       while (x > space) {
-               p->drawLine(x, y, ex, ey);
-               x -= step;
-               ey -= step;
-       }
-}
-
-
-void EmptyTable::setNumberColumns(int nr_cols)
-{
-       if (nr_cols < 1)
-               return;
-       if (nr_cols == columnCount())
-               return;
-       setColumnCount(nr_cols);
-       resetCellSize();
-       updateGeometry();
-        // emit signal
-       colsChanged(nr_cols);
-}
-
-
-void EmptyTable::setNumberRows(int nr_rows)
-{
-       if (nr_rows < 1)
-               return;
-       if (nr_rows == rowCount())
-               return;
-       setRowCount(nr_rows);
-       resetCellSize();
-       updateGeometry();
-        // emit signal
-       rowsChanged(nr_rows);
-}
-
-/*
-void EmptyTable::mouseMoveEvent(QMouseEvent *ev)
-{
-       int const x = ev->pos().x();
-       int const y = ev->pos().y();
-
-       if (x > 0)
-               setNumberColumns(x / cellsize + columnCount()-1);
-
-       if (y > 0)
-               setNumberRows(y / cellsize + rowCount()-1);
-}
-*/
-
-#include "EmptyTable_moc.cpp"
-
-
-namespace lyx {
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/emptytable.h b/src/frontends/qt4/emptytable.h
deleted file mode 100644 (file)
index 518ea1c..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// -*- C++ -*-
-/**
- * \file EmptyTable.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef EMPTYTABLE_H
-#define EMPTYTABLE_H
-
-#include <QTableWidget>
-
-
-class QMouseEvent;
-
-//namespace lyx {
-
-/**
- * A simple widget for a quick "preview" in TabularCreateDialog.
- * The user can drag on the widget to change the table dimensions.
- */
-class EmptyTable : public QTableWidget {
-       Q_OBJECT
-public:
-       EmptyTable(QWidget * parent = 0, int rows = 5, int columns = 5);
-
-       virtual QSize sizeHint() const;
-public Q_SLOTS:
-       /// set the number of columns in the table and emit colsChanged() signal
-       void setNumberColumns(int nr_cols);
-       /// set the number of rows in the table and emit rowsChanged() signal
-       void setNumberRows(int nr_rows);
-Q_SIGNALS:
-       /// the number of columns changed
-       void colsChanged(int);
-       /// the number of rows changed
-       void rowsChanged(int);
-protected:
-       /// fill in a cell
-       virtual void paintCell(class QPainter *, int, int);
-//     virtual void mouseMoveEvent(QMouseEvent *);
-
-       /// Reset all the cell size to default
-       virtual void resetCellSize();
-
-private:
-       /// number of current columns
-       unsigned int cols;
-       /// number of current rows
-       unsigned int rows;
-
-};
-
-
-//} // namespace lyx
-
-#endif
diff --git a/src/frontends/qt4/iconpalette.C b/src/frontends/qt4/iconpalette.C
deleted file mode 100644 (file)
index e990846..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/**
- * \file IconPalette.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "IconPalette.h"
-#include "qt_helpers.h"
-#include "controllers/ControlMath.h" // for find_xpm
-
-#include <QPixmap>
-#include <QGridLayout>
-#include <QToolButton>
-#include <QToolTip>
-#include <QToolBar>
-#include <QApplication>
-#include <QDesktopWidget>
-#include <QPainter>
-#include <QStyle>
-#include <QStyleOptionFrame>
-
-namespace lyx {
-namespace frontend {
-
-IconPalette::IconPalette(QWidget * parent)
-       : QWidget(parent, Qt::Popup)
-{
-       layout_ = new QGridLayout(this);
-       layout_->setSpacing(0);
-       layout_->setMargin(3);
-       setLayout(layout_);
-}
-
-
-void IconPalette::addButton(QAction * action)
-{
-       actions_.push_back(action);
-       QToolButton * tb = new QToolButton;
-       tb->setAutoRaise(true);
-       tb->setDefaultAction(action);
-       connect(tb, SIGNAL(triggered(QAction *)),
-               this, SLOT(clicked(QAction *)));
-       QToolBar * toolbar = qobject_cast<QToolBar *>(parentWidget()->parentWidget());
-       connect(toolbar, SIGNAL(iconSizeChanged(const QSize &)),
-               tb, SLOT(setIconSize(const QSize &)));
-
-       int const i = actions_.size();
-       int const ncols = qMin(6, i);
-       int const row = (i - 1)/ncols + 1;
-       int const col = qMax(1, i - (row - 1) * 6);
-       layout_->addWidget(tb, row, col);
-}
-
-
-void IconPalette::clicked(QAction * action)
-{
-       triggered(action);
-       setVisible(false);
-}
-
-
-void IconPalette::showEvent(QShowEvent * event)
-{
-       int hoffset = - parentWidget()->pos().x();
-       int voffset = - parentWidget()->pos().y();
-       int const parwidth = parentWidget()->geometry().width();
-       int const parheight = parentWidget()->geometry().height();
-
-       // vertical toolbar?
-       QToolBar * toolbar = qobject_cast<QToolBar *>(parentWidget()->parentWidget());
-       if (toolbar && toolbar->orientation() == Qt::Vertical) {
-               hoffset += parwidth;
-               voffset -= parheight;
-       }
-
-       QRect const screen = qApp->desktop()->availableGeometry(this);
-       QPoint const gpos = parentWidget()->mapToGlobal(
-               parentWidget()->geometry().bottomLeft());
-
-       // space to the right?
-       if (gpos.x() + hoffset + width() > screen.width()) {
-               hoffset -= width();
-               if (toolbar && toolbar->orientation() == Qt::Vertical)
-                       hoffset -= parwidth;
-               else
-                       hoffset += parwidth;
-       }
-       // space at the bottom?
-       if (gpos.y() + voffset + height() > screen.height()) {
-               voffset -= height();
-               if (toolbar && toolbar->orientation() == Qt::Horizontal)
-                       voffset -= parheight;
-               else
-                       voffset += parheight;
-       }
-
-       move(gpos.x() + hoffset, gpos.y() + voffset);
-       QWidget::showEvent(event);
-}
-
-
-void IconPalette::hideEvent(QHideEvent * event )
-{
-       visible(false);
-       QWidget::hideEvent(event);
-}
-
-
-void IconPalette::updateParent()
-{
-       bool enable = false;
-       for (int i = 0; i < actions_.size(); ++i)       
-               if (actions_.at(i)->isEnabled()) {
-                       enable = true;
-                       break;
-               }
-
-       parentWidget()->setEnabled(enable);
-}
-
-
-void IconPalette::paintEvent(QPaintEvent * event)
-{
-       // draw border
-       QPainter p(this);
-       QRegion emptyArea = QRegion(rect());
-       const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this);
-       if (fw) {
-               QRegion borderReg;
-               borderReg += QRect(0, 0, fw, height()); //left
-               borderReg += QRect(width()-fw, 0, fw, height()); //right
-               borderReg += QRect(0, 0, width(), fw); //top
-               borderReg += QRect(0, height()-fw, width(), fw); //bottom
-               p.setClipRegion(borderReg);
-               emptyArea -= borderReg;
-               QStyleOptionFrame frame;
-               frame.rect = rect();
-               frame.palette = palette();
-               frame.state = QStyle::State_None;
-               frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth);
-               frame.midLineWidth = 0;
-               style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, &p, this);
-       }
-       p.end();
-       // draw the rest (buttons)
-       QWidget::paintEvent(event);
-}
-
-
-ButtonMenu::ButtonMenu(const QString & title, QWidget * parent)
-       : QMenu(title, parent)
-{
-}
-
-
-void ButtonMenu::add(QAction * action)
-{
-       addAction(action);
-       actions_.push_back(action);
-}
-
-
-void ButtonMenu::updateParent()
-{
-       bool enable = false;
-       for (int i = 0; i < actions_.size(); ++i)       
-               if (actions_.at(i)->isEnabled()) {
-                       enable = true;
-                       break;
-               }
-
-       parentWidget()->setEnabled(enable);
-}
-
-
-} // namespace frontend
-} // namespace lyx
-
-#include "IconPalette_moc.cpp"
diff --git a/src/frontends/qt4/iconpalette.h b/src/frontends/qt4/iconpalette.h
deleted file mode 100644 (file)
index 1f0f37c..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-// -*- C++ -*-
-/**
- * \file IconPalette.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef ICONPALETTE_H
-#define ICONPALETTE_H
-
-#include <QWidget>
-#include <QMenu>
-#include <QLayout>
-#include "Action.h"
-
-namespace lyx {
-namespace frontend {
-
-/**
- * For holding an arbitrary set of icons.
- */
-class IconPalette : public QWidget {
-       Q_OBJECT
-public:
-       IconPalette(QWidget * parent);
-       void addButton(QAction *);
-
-public Q_SLOTS:
-       void updateParent();
-
-Q_SIGNALS:
-       void triggered(QAction *);
-       void visible(bool);
-
-protected:
-       void showEvent(QShowEvent * event);
-       void hideEvent(QHideEvent * event);
-       void paintEvent(QPaintEvent * event);
-
-private Q_SLOTS:
-       virtual void clicked(QAction *);
-
-private:
-       QGridLayout * layout_;
-       QList<QAction *> actions_;
-};
-
-/**
- * Popup menu for a toolbutton.
- * We need this to keep track whether
- * it is necessary to enable/disable
- * the toolbutton
- */
-class ButtonMenu : public QMenu {
-       Q_OBJECT
-public:
-       ButtonMenu(const QString & title, QWidget * parent = 0 );
-       void add(QAction *);
-
-public Q_SLOTS:
-       void updateParent();
-
-private:
-       QList<QAction *> actions_;
-};
-
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // ICONPALETTE_H
diff --git a/src/frontends/qt4/lengthcombo.C b/src/frontends/qt4/lengthcombo.C
deleted file mode 100644 (file)
index ba7de38..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * \file LengthCombo.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Herbert Voß
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "LengthCombo.h"
-#include "lengthcommon.h"
-#include "qt_helpers.h"
-
-
-LengthCombo::LengthCombo(QWidget * parent)
-       : QComboBox(parent)
-{
-       for (int i = 0; i < lyx::num_units; i++)
-               addItem(lyx::qt_(lyx::unit_name_gui[i]));
-
-       connect(this, SIGNAL(activated(int)),
-               this, SLOT(has_activated(int)));
-}
-
-
-lyx::LyXLength::UNIT LengthCombo::currentLengthItem() const
-{
-       return static_cast<lyx::LyXLength::UNIT>(currentIndex());
-}
-
-
-void LengthCombo::has_activated(int)
-{
-  // emit signal
-       selectionChanged(currentLengthItem());
-}
-
-
-void LengthCombo::setCurrentItem(lyx::LyXLength::UNIT unit)
-{
-       QComboBox::setCurrentIndex(int(unit));
-}
-
-
-void LengthCombo::setCurrentItem(int item)
-{
-       QComboBox::setCurrentIndex(item);
-}
-
-
-void LengthCombo::setEnabled(bool b)
-{
-       QComboBox::setEnabled(b);
-}
-
-
-void LengthCombo::noPercents()
-{
-       int num = QComboBox::count();
-       for (int i = 0; i < num; i++) {
-               if (QComboBox::itemText(i).contains('%') > 0) {
-                       QComboBox::removeItem(i);
-                       --i;
-                       --num;
-               }
-       }
-}
-
-#include "LengthCombo_moc.cpp"
diff --git a/src/frontends/qt4/lengthcombo.h b/src/frontends/qt4/lengthcombo.h
deleted file mode 100644 (file)
index a0cebec..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-// -*- C++ -*-
-/**
- * \file LengthCombo.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LENGTHCOMBO_H
-#define LENGTHCOMBO_H
-
-#include <QComboBox>
-
-#include "vspace.h"
-
-
-//namespace lyx {
-
-/**
- * A combo box for selecting LyXLength::UNIT types.
- */
-class LengthCombo : public QComboBox {
-       Q_OBJECT
-
-public:
-       LengthCombo(QWidget * parent);
-
-       /// set the current item from unit
-       virtual void setCurrentItem(lyx::LyXLength::UNIT unit);
-       /// set the current item from int
-       virtual void setCurrentItem(int item);
-       /// get the current item
-       lyx::LyXLength::UNIT currentLengthItem() const;
-       /// enable the widget
-       virtual void setEnabled(bool b);
-       /// use the %-items?
-       virtual void noPercents();
-
-protected Q_SLOTS:
-       virtual void has_activated(int index);
-Q_SIGNALS:
-       /// the current selection has changed
-       void selectionChanged(lyx::LyXLength::UNIT unit);
-};
-
-
-//} // namespace lyx
-
-#endif // LENGTHCOMBO_H
diff --git a/src/frontends/qt4/panelstack.C b/src/frontends/qt4/panelstack.C
deleted file mode 100644 (file)
index 13e3100..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * \file PanelStack.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "PanelStack.h"
-
-#include "qt_helpers.h"
-
-#include "debug.h"
-
-#include <QFontMetrics>
-#include <QStackedWidget>
-#include <QTreeWidget>
-#include <QHBoxLayout>
-#include <QHeaderView>
-
-#include <boost/assert.hpp>
-
-#include <iostream>
-
-
-using std::endl;
-using std::cout;
-
-namespace lyx {
-namespace frontend {
-
-
-PanelStack::PanelStack(QWidget * parent)
-       : QWidget(parent)
-{
-       list_ = new QTreeWidget(this);
-       stack_ = new QStackedWidget(this);
-
-       list_->setColumnCount(1);
-       // Hide the pointless list header
-       list_->header()->hide();
-//     QStringList HeaderLabels;
-//     HeaderLabels << QString("Category");
-//     list_->setHeaderLabels(HeaderLabels);
-
-       connect(list_, SIGNAL(currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),
-               this, SLOT(switchPanel(QTreeWidgetItem *, QTreeWidgetItem*)));
-
-       QHBoxLayout * layout = new QHBoxLayout(this);
-       layout->addWidget(list_, 0);
-       layout->addWidget(stack_, 1);
-}
-
-
-void PanelStack::addCategory(docstring const & n, docstring const & parent)
-{
-       QTreeWidgetItem * item = 0;
-       QString const name = toqstr(n);
-
-       LYXERR(Debug::GUI) << "addCategory n= " << to_utf8(n) << "   parent= " << endl;
-
-       int depth = 1;
-
-       if (parent.empty()) {
-               item = new QTreeWidgetItem(list_);
-               item->setText(0, name);
-       }
-       else {
-               PanelMap::iterator it = panel_map_.find(parent);
-               //BOOST_ASSERT(it != panel_map_.end());
-               if (it == panel_map_.end()) {
-                       addCategory(parent);
-                       it = panel_map_.find(parent);
-               }
-               BOOST_ASSERT(it != panel_map_.end());
-
-               item = new QTreeWidgetItem(it->second);
-               item->setText(0, name);
-               depth = 2;
-       }
-
-       panel_map_[n] = item;
-
-       QFontMetrics fm(list_->font());
-       // calculate the real size the current item needs in the listview
-       int itemsize = fm.width(name) + 10
-               + list_->indentation() * depth;
-       // adjust the listview width to the max. itemsize
-       if (itemsize > list_->minimumWidth())
-               list_->setMinimumWidth(itemsize);
-}
-
-
-void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent)
-{
-       addCategory(name, parent);
-       QTreeWidgetItem * item = panel_map_.find(name)->second;
-
-       widget_map_[item] = panel;
-       stack_->addWidget(panel);
-       stack_->setMinimumSize(panel->minimumSize());
-}
-
-
-void PanelStack::setCurrentPanel(docstring const & name)
-{
-       PanelMap::const_iterator cit = panel_map_.find(name);
-       BOOST_ASSERT(cit != panel_map_.end());
-
-       // force on first set
-       if (list_->currentItem() ==  cit->second)
-               switchPanel(cit->second);
-
-       list_->setCurrentItem(cit->second);
-}
-
-
-void PanelStack::switchPanel(QTreeWidgetItem * item,
-                            QTreeWidgetItem * /*previous*/)
-{
-       WidgetMap::const_iterator cit = widget_map_.find(item);
-       if (cit == widget_map_.end())
-               return;
-
-       stack_->setCurrentWidget(cit->second);
-}
-
-
-QSize PanelStack::sizeHint() const
-{
-       return QSize(list_->width() + stack_->width(),
-               qMax(list_->height(), stack_->height()));
-}
-
-} // namespace frontend
-} // namespace lyx
-
-#include "PanelStack_moc.cpp"
diff --git a/src/frontends/qt4/panelstack.h b/src/frontends/qt4/panelstack.h
deleted file mode 100644 (file)
index 1e38043..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// -*- C++ -*-
-/**
- * \file PanelStack.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-#ifndef PANELSTACK_H
-#define PANELSTACK_H
-
-#include "support/docstring.h"
-
-#include <QWidget>
-
-#include <map>
-
-class QTreeWidget;
-class QTreeWidgetItem;
-class QStackedWidget;
-
-namespace lyx {
-namespace frontend {
-
-
-class PanelStack : public QWidget
-{
-       Q_OBJECT
-public:
-       PanelStack(QWidget * parent = 0);
-
-       /// add a category with no associated panel
-       void addCategory(docstring const & name,
-               docstring const & parent = docstring());
-
-       /// add a widget panel with a given name, under the given parent
-       void addPanel(QWidget * panel, docstring const & name,
-               docstring const & parent = docstring());
-
-       /// set current panel by logical name
-       void setCurrentPanel(docstring const &);
-
-       virtual QSize sizeHint() const;
-
-public Q_SLOTS:
-       /// set current panel from an item
-       void switchPanel(QTreeWidgetItem * it, QTreeWidgetItem * previous = 0);
-
-private:
-       typedef std::map<docstring, QTreeWidgetItem *> PanelMap;
-
-       PanelMap panel_map_;
-
-       typedef std::map<QTreeWidgetItem *, QWidget *> WidgetMap;
-
-       WidgetMap widget_map_;
-
-       /// contains the items
-       QTreeWidget * list_;
-
-       /// contains the panes
-       QStackedWidget * stack_;
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // PANELSTACK_H
diff --git a/src/frontends/qt4/qfontexample.C b/src/frontends/qt4/qfontexample.C
deleted file mode 100644 (file)
index 7ffffbd..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * \file QFontExample.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QFontExample.h"
-
-#include <QPainter>
-#include <QPaintEvent>
-
-
-//namespace lyx {
-
-void QFontExample::set(QFont const & font, QString const & text)
-{
-       font_ = font;
-       text_ = text;
-       update();
-}
-
-
-QSize QFontExample::sizeHint() const
-{
-       QFontMetrics m(font_);
-       return QSize(m.width(text_) + 10, m.ascent() + m.descent() + 6);
-}
-
-
-void QFontExample::paintEvent(QPaintEvent *)
-{
-       QPainter p;
-       QFontMetrics m(font_);
-
-       p.begin(this);
-       p.setFont(font_);
-       p.drawRect(0, 0, width() - 1, height() - 1);
-       p.drawText(5, 3 + m.ascent(), text_);
-       p.end();
-}
-
-
-//} // namespace lyx
diff --git a/src/frontends/qt4/qfontexample.h b/src/frontends/qt4/qfontexample.h
deleted file mode 100644 (file)
index 650c6fa..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// -*- C++ -*-
-/**
- * \file QFontExample.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef QT_QFONTEXAMPLE_H
-#define QT_QFONTEXAMPLE_H
-
-#include <QWidget>
-#include <QFont>
-#include <QString>
-
-class QPaintEvent;
-
-
-//namespace lyx {
-
-class QFontExample : public QWidget {
-
-public:
-       QFontExample(QWidget * parent)
-               : QWidget(parent) {}
-
-       void set(QFont const & font, QString const & text);
-
-       virtual QSize sizeHint() const;
-
-protected:
-       virtual void paintEvent(QPaintEvent * p);
-
-private:
-       QFont font_;
-       QString text_;
-};
-
-
-//} // namespace lyx
-
-#endif
diff --git a/src/frontends/qt4/qsetborder.C b/src/frontends/qt4/qsetborder.C
deleted file mode 100644 (file)
index 4a96ed6..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-/**
- * \file QSetBorder.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QSetBorder.h"
-
-#include <QPainter>
-
-//Added by qt3to4:
-#include <QMouseEvent>
-#include <QPaintEvent>
-
-
-QSetBorder::QSetBorder(QWidget * parent, Qt::WFlags fl)
-       : QWidget(parent, fl), buffer(75, 75)
-{
-       /* length of corner line */
-       l = buffer.width() / 10;
-       /* margin */
-       m = buffer.height() / 10;
-
-       w = buffer.width();
-       h = buffer.height();
-
-       init();
-
-       setMinimumSize(w,h);
-       setMaximumSize(w,h);
-}
-
-
-void QSetBorder::paintEvent(QPaintEvent * e)
-{
-       QWidget::paintEvent(e);
-       QPainter painter(this);
-       painter.drawPixmap(0, 0, buffer);
-}
-
-
-void QSetBorder::init()
-{
-       buffer.fill();
-       QPainter paint(&buffer);
-
-       paint.setPen(Qt::black);
-
-       // FIXME: wow, readable !! :)
-
-       paint.drawLine(m + l , m, m + l, m + l);
-       paint.drawLine(w - (m + l), m, w - (m + l), m + l);
-
-       paint.drawLine(m, m + l , m + l, m + l);
-       paint.drawLine(m, h - (m + l), m + l, h - (m + l));
-
-       paint.drawLine(m + l ,h - m, m + l ,h - (m + l));
-       paint.drawLine(w - (m + l), h - m, w - (m + l), h - (m + l));
-
-       paint.drawLine(h - m, m+l, h - (m + l), m + l);
-       paint.drawLine(h - m, h - (m + l), h - (m + l),h - (m + l));
-}
-
-
-void QSetBorder::mousePressEvent(QMouseEvent * e)
-{
-       if (e->y() > e->x()) {
-               if (e->y() < height() - e->x()) {
-                       if (left_.enabled) {
-                               setLeft(!left_.set);
-                                // emit signal
-                               leftSet(left_.set);
-                       }
-               } else {
-                       if (bottom_.enabled) {
-                               setBottom(!bottom_.set);
-                                // emit signal
-                               bottomSet(bottom_.set);
-                       }
-               }
-       } else {
-               if (e->y() < height() - e->x()) {
-                       if (top_.enabled) {
-                               setTop(!top_.set);
-                                // emit signal
-                               topSet(top_.set);
-                       }
-               } else {
-                       if (right_.enabled) {
-                               setRight(!right_.set);
-                                // emit signal
-                               rightSet(right_.set);
-                       }
-               }
-       }
-       update();
-        // emit signal
-       clicked();
-}
-
-
-void QSetBorder::drawLine(QColor const & col, int x, int y, int x2, int y2)
-{
-       QPainter paint(&buffer);
-       QPen p = paint.pen();
-       p.setWidth(2);
-       p.setColor(col);
-       paint.setPen(p);
-       paint.drawLine(x, y, x2, y2);
-}
-
-
-void QSetBorder::drawLeft(bool draw)
-{
-       QColor col(draw ? Qt::black : Qt::white);
-       if (!left_.enabled)
-               col = QColor("grey");
-       drawLine(col, m + l, m + l + 2, m + l, h - m - l - 1);
-}
-
-
-void QSetBorder::drawRight(bool draw)
-{
-       QColor col(draw ? Qt::black : Qt::white);
-       if (!right_.enabled)
-               col = QColor("grey");
-       drawLine(col, h - m - l + 1, m + l + 2, h - m - l + 1, h - m - l - 1);
-}
-
-
-void QSetBorder::drawTop(bool draw)
-{
-       QColor col(draw ? Qt::black : Qt::white);
-       if (!top_.enabled)
-               col = QColor("grey");
-       drawLine(col, m + l + 2, m + l, w - m - l - 1, m + l);
-}
-
-
-void QSetBorder::drawBottom(bool draw)
-{
-       QColor col(draw ? Qt::black : Qt::white);
-       if (!bottom_.enabled)
-               col = QColor("grey");
-       drawLine(col, m + l + 2, w - m - l + 1, w - m - l - 1, w - m - l + 1);
-}
-
-
-void QSetBorder::setLeftEnabled(bool border)
-{
-       left_.enabled = border;
-       drawLeft(border);
-}
-
-
-void QSetBorder::setRightEnabled(bool border)
-{
-       right_.enabled = border;
-       drawRight(border);
-}
-
-
-void QSetBorder::setTopEnabled(bool border)
-{
-       top_.enabled = border;
-       drawTop(border);
-}
-
-
-void QSetBorder::setBottomEnabled(bool border)
-{
-       bottom_.enabled = border;
-       drawBottom(border);
-}
-
-
-void QSetBorder::setLeft(bool border)
-{
-       left_.set = border;
-       drawLeft(border);
-}
-
-
-void QSetBorder::setRight(bool border)
-{
-       right_.set = border;
-       drawRight(border);
-}
-
-
-void QSetBorder::setTop(bool border)
-{
-       top_.set = border;
-       drawTop(border);
-}
-
-
-void QSetBorder::setBottom(bool border)
-{
-       bottom_.set = border;
-       drawBottom(border);
-}
-
-
-void QSetBorder::setAll(bool border)
-{
-       setLeft(border);
-       setRight(border);
-       setTop(border);
-       setBottom(border);
-}
-
-
-bool QSetBorder::getLeft()
-{
-       return left_.set;
-}
-
-
-bool QSetBorder::getRight()
-{
-       return right_.set;
-}
-
-
-bool QSetBorder::getTop()
-{
-       return top_.set;
-}
-
-
-bool QSetBorder::getBottom()
-{
-       return bottom_.set;
-}
-
-#include "QSetBorder_moc.cpp"
-
-
-namespace lyx {
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/qsetborder.h b/src/frontends/qt4/qsetborder.h
deleted file mode 100644 (file)
index 2c53bea..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-// -*- C++ -*-
-/**
- * \file QSetBorder.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Edwin Leuven
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-#ifndef QSETBORDER_H
-#define QSETBORDER_H
-
-#include <QWidget>
-#include <QPixmap>
-
-class QColor;
-class QMouseEvent;
-class QPaintEvent;
-
-//namespace lyx {
-
-class QSetBorder : public QWidget
-{
-       Q_OBJECT
-public:
-       QSetBorder(QWidget * parent = 0, Qt::WFlags fl = 0);
-
-       bool getLeft();
-       bool getRight();
-       bool getTop();
-       bool getBottom();
-
-Q_SIGNALS:
-       void rightSet(bool);
-       void leftSet(bool);
-       void topSet(bool);
-       void bottomSet(bool);
-       void clicked();
-
-public Q_SLOTS:
-       void setLeftEnabled(bool);
-       void setRightEnabled(bool);
-       void setTopEnabled(bool);
-       void setBottomEnabled(bool);
-       void setLeft(bool);
-       void setRight(bool);
-       void setTop(bool);
-       void setBottom(bool);
-       void setAll(bool);
-
-protected:
-       void mousePressEvent(QMouseEvent * e);
-       void paintEvent(QPaintEvent * e);
-
-private:
-       void init();
-
-       void drawLine(QColor const & col, int x, int y, int x2, int y2);
-
-       void drawLeft(bool);
-       void drawRight(bool);
-       void drawTop(bool);
-       void drawBottom(bool);
-
-       class Border {
-       public:
-               Border() : set(true), enabled(true) {}
-               bool set;
-               bool enabled;
-       };
-
-       Border left_;
-       Border right_;
-       Border top_;
-       Border bottom_;
-
-       int m;
-       int l;
-       int w;
-       int h;
-
-       QPixmap buffer;
-};
-
-
-//} // namespace lyx
-
-#endif // QSETBORDER_H
diff --git a/src/frontends/qt4/qtTimeout.C b/src/frontends/qt4/qtTimeout.C
deleted file mode 100644 (file)
index 3b1ea51..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * \file qtTimeout.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "qtTimeout.h"
-
-#include <QTimerEvent>
-
-#include "debug.h"
-
-
-namespace lyx {
-
-
-Timeout::Timeout(unsigned int msec, Type t)
-       : pimpl_(new qtTimeout(*this)), type(t), timeout_ms(msec)
-{}
-
-
-qtTimeout::qtTimeout(Timeout & owner)
-       : Timeout::Impl(owner), timeout_id(-1)
-{}
-
-
-void qtTimeout::timerEvent(QTimerEvent *)
-{
-       emit();
-}
-
-
-void qtTimeout::reset()
-{
-       if (timeout_id != -1)
-               killTimer(timeout_id);
-       timeout_id = -1;
-}
-
-
-bool qtTimeout::running() const
-{
-       return timeout_id != -1;
-}
-
-
-void qtTimeout::start()
-{
-       if (running())
-               lyxerr << "Timeout::start: already running!" << std::endl;
-       timeout_id = startTimer(timeout_ms());
-}
-
-
-void qtTimeout::stop()
-{
-       if (running())
-               reset();
-}
-
-
-} // namespace lyx
diff --git a/src/frontends/qt4/qtTimeout.cpp b/src/frontends/qt4/qtTimeout.cpp
new file mode 100644 (file)
index 0000000..3b1ea51
--- /dev/null
@@ -0,0 +1,68 @@
+/**
+ * \file qtTimeout.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "qtTimeout.h"
+
+#include <QTimerEvent>
+
+#include "debug.h"
+
+
+namespace lyx {
+
+
+Timeout::Timeout(unsigned int msec, Type t)
+       : pimpl_(new qtTimeout(*this)), type(t), timeout_ms(msec)
+{}
+
+
+qtTimeout::qtTimeout(Timeout & owner)
+       : Timeout::Impl(owner), timeout_id(-1)
+{}
+
+
+void qtTimeout::timerEvent(QTimerEvent *)
+{
+       emit();
+}
+
+
+void qtTimeout::reset()
+{
+       if (timeout_id != -1)
+               killTimer(timeout_id);
+       timeout_id = -1;
+}
+
+
+bool qtTimeout::running() const
+{
+       return timeout_id != -1;
+}
+
+
+void qtTimeout::start()
+{
+       if (running())
+               lyxerr << "Timeout::start: already running!" << std::endl;
+       timeout_id = startTimer(timeout_ms());
+}
+
+
+void qtTimeout::stop()
+{
+       if (running())
+               reset();
+}
+
+
+} // namespace lyx
diff --git a/src/frontends/qt4/qt_helpers.C b/src/frontends/qt4/qt_helpers.C
deleted file mode 100644 (file)
index 24392f5..0000000
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * \file qt_helpers.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Dekel Tsur
- * \author Jürgen Spitzmüller
- * \author Richard Heck
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "LengthCombo.h"
-#include "qt_helpers.h"
-
-#include "lengthcommon.h"
-#include "gettext.h"
-
-#include "support/os.h"
-#include "support/lstrings.h"
-#include "support/convert.h"
-
-#include "debug.h"
-
-#include <QComboBox>
-#include <QCheckBox>
-#include <qlineedit.h>
-#include <qtextcodec.h>
-
-#include <algorithm>
-
-
-namespace lyx {
-
-using support::isStrDbl;
-
-using std::vector;
-using std::make_pair;
-using std::string;
-using std::pair;
-using std::endl;
-
-
-string makeFontName(string const & family, string const & foundry)
-{
-       if (foundry.empty())
-               return family;
-       return family + " [" + foundry + ']';
-}
-
-
-pair<string, string> parseFontName(string const & name)
-{
-       string::size_type const idx = name.find('[');
-       if (idx == string::npos || idx == 0)
-               return make_pair(name, string());
-       return make_pair(name.substr(0, idx - 1),
-                        name.substr(idx + 1, name.size() - idx - 2));
-}
-
-
-string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
-{
-       QString const length = input->text();
-       if (length.isEmpty())
-               return string();
-
-       // Don't return unit-from-choice if the input(field) contains a unit
-       if (isValidGlueLength(fromqstr(length)))
-               return fromqstr(length);
-
-       LyXLength::UNIT const unit = combo->currentLengthItem();
-
-       return LyXLength(length.toDouble(), unit).asString();
-}
-
-
-LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo)
-{
-       QString const length = input->text();
-       if (length.isEmpty())
-               return LyXLength();
-
-       // don't return unit-from-choice if the input(field) contains a unit
-       if (isValidGlueLength(fromqstr(length)))
-               return LyXLength(fromqstr(length));
-
-       LyXLength::UNIT const unit = unitFromString(fromqstr(combo->currentText()));
-
-       return LyXLength(length.toDouble(), unit);
-}
-
-
-void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
-       LyXLength const & len, LyXLength::UNIT defaultUnit) 
-{
-       combo->setCurrentItem(LyXLength(len).unit());
-       input->setText(toqstr(convert<string>(LyXLength(len).value())));
-}
-
-
-void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
-       string const & len, LyXLength::UNIT defaultUnit)
-{
-       if (len.empty()) {
-               // no length (UNIT_NONE)
-               combo->setCurrentItem(defaultUnit);
-               input->setText("");
-       } else if (!isValidLength(len) && !isStrDbl(len)) {
-               // use input field only for gluelengths
-               combo->setCurrentItem(defaultUnit);
-               input->setText(toqstr(len));
-       } else {
-               lengthToWidgets(input, combo, LyXLength(len), defaultUnit);
-       }
-}
-
-
-void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo, 
-       LyXLength const & len, LyXLength::UNIT defaultUnit)
-{
-       if (len.value() == 0) 
-               lengthToWidgets(input, combo, "auto", defaultUnit);
-       else
-               lengthToWidgets(input, combo, len, defaultUnit);
-}
-
-
-//NOTE "CB" here because we probably will want one of these
-//for labeled sets, as well.
-void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, 
-       LengthCombo * lengthCombo) 
-{
-       if (!checkBox->isChecked()) 
-               lengthToWidgets(lineEdit, lengthCombo,
-                               "auto", lengthCombo->currentLengthItem());
-       else if (lineEdit->text() == "auto")
-               lengthToWidgets(lineEdit, lengthCombo, string(),
-                               lengthCombo->currentLengthItem());
-}
-
-
-QString const qt_(char const * str, const char *)
-{
-       return toqstr(_(str));
-}
-
-
-QString const qt_(string const & str)
-{
-       return toqstr(_(str));
-}
-
-
-docstring const formatted(docstring const & text, int w)
-{
-       docstring sout;
-
-       if (text.empty())
-               return sout;
-
-       docstring::size_type curpos = 0;
-       docstring line;
-
-       for (;;) {
-               docstring::size_type const nxtpos1 = text.find(' ',  curpos);
-               docstring::size_type const nxtpos2 = text.find('\n', curpos);
-               docstring::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
-
-               docstring const word =
-                       nxtpos == docstring::npos ?
-                       text.substr(curpos) :
-                       text.substr(curpos, nxtpos - curpos);
-
-               bool const newline = (nxtpos2 != docstring::npos &&
-                                     nxtpos2 < nxtpos1);
-
-               docstring const line_plus_word =
-                       line.empty() ? word : line + char_type(' ') + word;
-
-               // FIXME: make w be size_t
-               if (int(line_plus_word.length()) >= w) {
-                       sout += line + char_type('\n');
-                       if (newline) {
-                               sout += word + char_type('\n');
-                               line.erase();
-                       } else {
-                               line = word;
-                       }
-
-               } else if (newline) {
-                       sout += line_plus_word + char_type('\n');
-                       line.erase();
-
-               } else {
-                       if (!line.empty())
-                               line += char_type(' ');
-                       line += word;
-               }
-
-               if (nxtpos == docstring::npos) {
-                       if (!line.empty())
-                               sout += line;
-                       break;
-               }
-
-               curpos = nxtpos + 1;
-       }
-
-       return sout;
-}
-
-} // namespace lyx
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
new file mode 100644 (file)
index 0000000..24392f5
--- /dev/null
@@ -0,0 +1,215 @@
+/**
+ * \file qt_helpers.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Dekel Tsur
+ * \author Jürgen Spitzmüller
+ * \author Richard Heck
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "LengthCombo.h"
+#include "qt_helpers.h"
+
+#include "lengthcommon.h"
+#include "gettext.h"
+
+#include "support/os.h"
+#include "support/lstrings.h"
+#include "support/convert.h"
+
+#include "debug.h"
+
+#include <QComboBox>
+#include <QCheckBox>
+#include <qlineedit.h>
+#include <qtextcodec.h>
+
+#include <algorithm>
+
+
+namespace lyx {
+
+using support::isStrDbl;
+
+using std::vector;
+using std::make_pair;
+using std::string;
+using std::pair;
+using std::endl;
+
+
+string makeFontName(string const & family, string const & foundry)
+{
+       if (foundry.empty())
+               return family;
+       return family + " [" + foundry + ']';
+}
+
+
+pair<string, string> parseFontName(string const & name)
+{
+       string::size_type const idx = name.find('[');
+       if (idx == string::npos || idx == 0)
+               return make_pair(name, string());
+       return make_pair(name.substr(0, idx - 1),
+                        name.substr(idx + 1, name.size() - idx - 2));
+}
+
+
+string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
+{
+       QString const length = input->text();
+       if (length.isEmpty())
+               return string();
+
+       // Don't return unit-from-choice if the input(field) contains a unit
+       if (isValidGlueLength(fromqstr(length)))
+               return fromqstr(length);
+
+       LyXLength::UNIT const unit = combo->currentLengthItem();
+
+       return LyXLength(length.toDouble(), unit).asString();
+}
+
+
+LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo)
+{
+       QString const length = input->text();
+       if (length.isEmpty())
+               return LyXLength();
+
+       // don't return unit-from-choice if the input(field) contains a unit
+       if (isValidGlueLength(fromqstr(length)))
+               return LyXLength(fromqstr(length));
+
+       LyXLength::UNIT const unit = unitFromString(fromqstr(combo->currentText()));
+
+       return LyXLength(length.toDouble(), unit);
+}
+
+
+void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
+       LyXLength const & len, LyXLength::UNIT defaultUnit) 
+{
+       combo->setCurrentItem(LyXLength(len).unit());
+       input->setText(toqstr(convert<string>(LyXLength(len).value())));
+}
+
+
+void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
+       string const & len, LyXLength::UNIT defaultUnit)
+{
+       if (len.empty()) {
+               // no length (UNIT_NONE)
+               combo->setCurrentItem(defaultUnit);
+               input->setText("");
+       } else if (!isValidLength(len) && !isStrDbl(len)) {
+               // use input field only for gluelengths
+               combo->setCurrentItem(defaultUnit);
+               input->setText(toqstr(len));
+       } else {
+               lengthToWidgets(input, combo, LyXLength(len), defaultUnit);
+       }
+}
+
+
+void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo, 
+       LyXLength const & len, LyXLength::UNIT defaultUnit)
+{
+       if (len.value() == 0) 
+               lengthToWidgets(input, combo, "auto", defaultUnit);
+       else
+               lengthToWidgets(input, combo, len, defaultUnit);
+}
+
+
+//NOTE "CB" here because we probably will want one of these
+//for labeled sets, as well.
+void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, 
+       LengthCombo * lengthCombo) 
+{
+       if (!checkBox->isChecked()) 
+               lengthToWidgets(lineEdit, lengthCombo,
+                               "auto", lengthCombo->currentLengthItem());
+       else if (lineEdit->text() == "auto")
+               lengthToWidgets(lineEdit, lengthCombo, string(),
+                               lengthCombo->currentLengthItem());
+}
+
+
+QString const qt_(char const * str, const char *)
+{
+       return toqstr(_(str));
+}
+
+
+QString const qt_(string const & str)
+{
+       return toqstr(_(str));
+}
+
+
+docstring const formatted(docstring const & text, int w)
+{
+       docstring sout;
+
+       if (text.empty())
+               return sout;
+
+       docstring::size_type curpos = 0;
+       docstring line;
+
+       for (;;) {
+               docstring::size_type const nxtpos1 = text.find(' ',  curpos);
+               docstring::size_type const nxtpos2 = text.find('\n', curpos);
+               docstring::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
+
+               docstring const word =
+                       nxtpos == docstring::npos ?
+                       text.substr(curpos) :
+                       text.substr(curpos, nxtpos - curpos);
+
+               bool const newline = (nxtpos2 != docstring::npos &&
+                                     nxtpos2 < nxtpos1);
+
+               docstring const line_plus_word =
+                       line.empty() ? word : line + char_type(' ') + word;
+
+               // FIXME: make w be size_t
+               if (int(line_plus_word.length()) >= w) {
+                       sout += line + char_type('\n');
+                       if (newline) {
+                               sout += word + char_type('\n');
+                               line.erase();
+                       } else {
+                               line = word;
+                       }
+
+               } else if (newline) {
+                       sout += line_plus_word + char_type('\n');
+                       line.erase();
+
+               } else {
+                       if (!line.empty())
+                               line += char_type(' ');
+                       line += word;
+               }
+
+               if (nxtpos == docstring::npos) {
+                       if (!line.empty())
+                               sout += line;
+                       break;
+               }
+
+               curpos = nxtpos + 1;
+       }
+
+       return sout;
+}
+
+} // namespace lyx
diff --git a/src/frontends/qt4/socket_callback.C b/src/frontends/qt4/socket_callback.C
deleted file mode 100644 (file)
index d3ae298..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * \file io_callback.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author unknown
- * \author John Levon
- * \author João Luis M. Assirati
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "socket_callback.h"
-
-
-namespace lyx {
-
-socket_callback::socket_callback(int fd, boost::function<void()> func)
-       : func_(func)
-{
-       sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this));
-       connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received()));
-}
-
-
-void socket_callback::data_received()
-{
-       func_();
-}
-
-} // namespace lyx
-
-#include "socket_callback_moc.cpp"
diff --git a/src/frontends/qt4/socket_callback.cpp b/src/frontends/qt4/socket_callback.cpp
new file mode 100644 (file)
index 0000000..d3ae298
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * \file io_callback.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author John Levon
+ * \author João Luis M. Assirati
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "socket_callback.h"
+
+
+namespace lyx {
+
+socket_callback::socket_callback(int fd, boost::function<void()> func)
+       : func_(func)
+{
+       sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this));
+       connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received()));
+}
+
+
+void socket_callback::data_received()
+{
+       func_();
+}
+
+} // namespace lyx
+
+#include "socket_callback_moc.cpp"
diff --git a/src/frontends/qt4/validators.C b/src/frontends/qt4/validators.C
deleted file mode 100644 (file)
index 262574d..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-/**
- * \file Validator.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- * \author Richard Heck
- *
- * Full author contact details are available in file CREDITS.
- */
-
-
-#include <config.h>
-
-#include "Validator.h"
-#include "qt_helpers.h"
-
-#include "gettext.h"
-#include "lyxrc.h"
-
-#include "frontends/Alert.h"
-
-#include "frontends/controllers/Dialog.h"
-
-#include "support/docstring.h"
-#include "support/lstrings.h"
-#include "support/std_ostream.h"
-
-#include <QLineEdit>
-#include <QWidget>
-
-#include <sstream>
-
-using lyx::support::isStrDbl;
-using std::string;
-
-
-namespace lyx {
-
-LengthValidator::LengthValidator(QWidget * parent)
-       : QValidator(parent),
-         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;
-}
-
-
-LengthAutoValidator::LengthAutoValidator(QWidget * parent)
-       : LengthValidator(parent)
-{}
-
-
-QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const
-{
-       string const text = fromqstr(qtext);
-       if (text == "auto")
-               return QValidator::Acceptable;
-       return LengthValidator::validate(qtext, dummy);
-}
-
-
-LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed)
-{
-       LengthAutoValidator * v = new LengthAutoValidator(ed);
-       v->setBottom(LyXLength());
-       return v;
-}
-
-
-DoubleAutoValidator::DoubleAutoValidator(QWidget * parent) : 
-       QDoubleValidator(parent) {}
-
-
-DoubleAutoValidator::DoubleAutoValidator(double bottom,
-       double top, int decimals, QObject * parent) : 
-       QDoubleValidator(bottom, top, decimals, parent) {}
-
-
-QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const {
-       string const text = fromqstr(input);
-       if (text == "auto")
-               return QValidator::Acceptable;
-       return QDoubleValidator::validate(input, pos);
-}
-
-
-PathValidator::PathValidator(bool acceptable_if_empty,
-                            QWidget * parent)
-       : QValidator(parent),
-         acceptable_if_empty_(acceptable_if_empty),
-         latex_doc_(false),
-         tex_allows_spaces_(false)
-{}
-
-
-static docstring const printable_list(docstring const & invalid_chars)
-{
-       docstring s;
-       docstring::const_iterator const begin = invalid_chars.begin();
-       docstring::const_iterator const end = invalid_chars.end();
-       docstring::const_iterator it = begin;
-
-       for (; it != end; ++it) {
-               if (it != begin)
-                       s += ", ";
-               if (*it == ' ')
-                       s += _("space");
-               else
-                       s += *it;
-       }
-
-       return s;
-}
-
-
-QValidator::State PathValidator::validate(QString & qtext, int &) const
-{
-       if (!latex_doc_)
-               return QValidator::Acceptable;
-
-       docstring const text = lyx::support::trim(qstring_to_ucs4(qtext));
-       if (text.empty())
-               return  acceptable_if_empty_ ?
-                       QValidator::Acceptable : QValidator::Intermediate;
-
-       docstring invalid_chars = from_ascii("#$%{}()[]\"^");
-       if (!tex_allows_spaces_)
-               invalid_chars += ' ';
-
-       if (text.find_first_of(invalid_chars) != docstring::npos) {
-
-               static int counter = 0;
-               if (counter == 0) {
-                       lyx::frontend::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);
-}
-
-} // namespace lyx
-
-#include "Validator_moc.cpp"
-
diff --git a/src/frontends/qt4/validators.h b/src/frontends/qt4/validators.h
deleted file mode 100644 (file)
index 686dd06..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-// -*- C++ -*-
-/**
- * \file Validator.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- * \author Richard Heck
- *
- * 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 VALIDATOR_H
-#define VALIDATOR_H
-
-#include "lyxlength.h"
-#include "lyxgluelength.h"
-
-#include <QValidator>
-
-class QWidget;
-class QLineEdit;
-
-
-namespace lyx {
-
-/** 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);
-
-       /** @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 *);
-
-//FIXME This should be generalized to take "text" as part of the
-//constructor and so to set what text we check for, rather than
-//hard-coding it as "auto". But see qt_helpers.h for reasons this
-//is not so trivial and an idea about how to do it. (RGH)
-/** A class to ascertain whether the data passed to the @c validate()
- *  member function can be interpretted as a LyXGlueLength or is "auto".
- */
-class LengthAutoValidator : public LengthValidator
-{
-       Q_OBJECT
-       public:
-       /// Define a validator for widget @c parent.
-               LengthAutoValidator(QWidget * parent);
-
-       /** @returns QValidator::Acceptable if @c data is a LyXGlueLength
-               * or is "auto". If not, returns QValidator::Intermediate.
-        */
-               QValidator::State validate(QString & data, int &) const;
-};
-
-/// @returns a new @c LengthAutoValidator that does not accept negative lengths.
-LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *);
-
-//FIXME As above, this should really take a text argument.
-/**
- * A class to determine whether the passed is a double
- * or is "auto".
- *
- */
-class DoubleAutoValidator : public QDoubleValidator {
-       Q_OBJECT
-       public:
-               DoubleAutoValidator(QWidget * parent);
-               DoubleAutoValidator(double bottom, double top, int decimals, 
-                       QObject * parent);
-               QValidator::State validate(QString & input, int & pos) const;
-};
-
-// Forward declarations
-class LyXRC;
-
-namespace frontend { class KernelDocType; } 
-
-
-/** 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);
-
-       /** @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(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 *);
-
-} // namespace lyx
-
-# endif // NOT VALIDATOR_H