git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20803 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-06 21:31:01 +00:00
parent 9ccb603c96
commit 868cb241a2
8 changed files with 155 additions and 333 deletions

View File

@ -1,135 +0,0 @@
/**
* \file ControlPrint.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 "ControlPrint.h"
#include "frontend_helpers.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "support/convert.h"
#include "support/FileFilterList.h"
#include "support/filetools.h"
using std::string;
namespace lyx {
using support::changeExtension;
using support::FileFilterList;
namespace frontend {
ControlPrint::ControlPrint(Dialog & parent)
: Controller(parent)
{}
bool ControlPrint::initialiseParams(std::string const &)
{
/// get global printer parameters
string const name = changeExtension(buffer().fileName(),
lyxrc.print_file_extension);
params_ = PrinterParams(PrinterParams::PRINTER, lyxrc.printer, name);
dialog().setButtonsValid(true); // so that the user can press Ok
return true;
}
void ControlPrint::clearParams()
{
params_ = PrinterParams();
}
docstring const ControlPrint::browse(docstring const & in_name) const
{
return browseRelFile(in_name, lyx::from_utf8(buffer().filePath()),
_("Print to file"),
FileFilterList(_("PostScript files (*.ps)")),
true);
}
/// print the current buffer
void ControlPrint::dispatchParams()
{
PrinterParams const pp = params();
string command(lyxrc.print_command + ' ');
if (pp.target == PrinterParams::PRINTER
&& lyxrc.print_adapt_output // dvips wants a printer name
&& !pp.printer_name.empty()) {// printer name given
command += lyxrc.print_to_printer
+ pp.printer_name
+ ' ';
}
if (!pp.all_pages && pp.from_page) {
command += lyxrc.print_pagerange_flag + ' ';
command += convert<string>(pp.from_page);
if (pp.to_page) {
// we have a range "from-to"
command += '-'
+ convert<string>(pp.to_page);
}
command += ' ';
}
// If both are, or both are not selected, then skip the odd/even printing
if (pp.odd_pages != pp.even_pages) {
if (pp.odd_pages) {
command += lyxrc.print_oddpage_flag + ' ';
} else if (pp.even_pages) {
command += lyxrc.print_evenpage_flag + ' ';
}
}
if (pp.count_copies > 1) {
if (pp.sorted_copies) {
command += lyxrc.print_collcopies_flag;
} else {
command += lyxrc.print_copies_flag;
}
command += ' '
+ convert<string>(pp.count_copies)
+ ' ';
}
if (pp.reverse_order) {
command += lyxrc.print_reverse_flag + ' ';
}
if (!lyxrc.print_extra_options.empty()) {
command += lyxrc.print_extra_options + ' ';
}
command += buffer().params().dvips_options();
string const target = (pp.target == PrinterParams::PRINTER) ?
"printer" : "file";
string const target_name = (pp.target == PrinterParams::PRINTER) ?
(pp.printer_name.empty() ? "default" : pp.printer_name) :
pp.file_name;
string const data = target + " \"" + target_name + "\" \"" + command + '"';
dispatch(FuncRequest(getLfun(), data));
}
} // namespace frontend
} // namespace lyx

View File

@ -1,57 +0,0 @@
// -*- C++ -*-
/**
* \file ControlPrint.h
* 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.
*/
#ifndef CONTROLPRINT_H
#define CONTROLPRINT_H
#include "Dialog.h"
#include "PrinterParams.h"
#include "support/docstring.h"
namespace lyx {
namespace frontend {
/** A controller for Print dialogs.
*/
class ControlPrint : public Controller
{
public:
///
ControlPrint(Dialog &);
///
virtual bool initialiseParams(std::string const & data);
///
virtual void clearParams();
///
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
virtual bool canApplyToReadOnly() const { return true; }
///
virtual kb_action getLfun() const { return LFUN_BUFFER_PRINT; }
/// Browse for a file
docstring const browse(docstring const &) const;
///
PrinterParams & params() { return params_; }
///
PrinterParams const & params() const { return params_; }
private:
///
PrinterParams params_;
};
} // namespace frontend
} // namespace lyx
#endif // CONTROLPRINT_H

View File

@ -1,46 +0,0 @@
/**
* \file ControlSearch.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 "ControlSearch.h"
#include "FuncRequest.h"
#include "lyxfind.h"
namespace lyx {
namespace frontend {
ControlSearch::ControlSearch(Dialog & parent)
: Controller(parent)
{}
void ControlSearch::find(docstring const & search, bool casesensitive,
bool matchword, bool forward)
{
docstring const data = find2string(search, casesensitive,
matchword, forward);
dispatch(FuncRequest(LFUN_WORD_FIND, data));
}
void ControlSearch::replace(docstring const & search, docstring const & replace,
bool casesensitive, bool matchword,
bool forward, bool all)
{
docstring const data =
replace2string(search, replace, casesensitive,
matchword, all, forward);
dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
}
} // namespace frontend
} // namespace lyx

View File

@ -1,44 +0,0 @@
// -*- C++ -*-
/**
* \file ControlSearch.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 CONTROLSEARCH_H
#define CONTROLSEARCH_H
#include "Dialog.h"
namespace lyx {
namespace frontend {
/** A controller for Search dialogs.
*/
class ControlSearch : public Controller {
public:
ControlSearch(Dialog &);
virtual bool initialiseParams(std::string const &) { return true; }
virtual void clearParams() {}
virtual void dispatchParams() {}
virtual bool isBufferDependent() const { return true; }
/// Searches occurence of string
void find(docstring const & search,
bool casesensitive, bool matchword, bool forward);
/// Replaces occurence of string
void replace(docstring const & search, docstring const & replace,
bool casesensitive, bool matchword,
bool forward, bool all);
};
} // namespace frontend
} // namespace lyx
#endif // CONTROLSEARCH_H

View File

@ -17,8 +17,6 @@ SOURCEFILES = \
ControlMath.cpp \ ControlMath.cpp \
ControlParagraph.cpp \ ControlParagraph.cpp \
ControlPrefs.cpp \ ControlPrefs.cpp \
ControlPrint.cpp \
ControlSearch.cpp \
frontend_helpers.cpp frontend_helpers.cpp
HEADERFILES = \ HEADERFILES = \
@ -31,8 +29,6 @@ HEADERFILES = \
ControlMath.h \ ControlMath.h \
ControlParagraph.h \ ControlParagraph.h \
ControlPrefs.h \ ControlPrefs.h \
ControlPrint.h \
ControlSearch.h \
frontend_helpers.h frontend_helpers.h
if MONOLITHIC_CONTROLLERS if MONOLITHIC_CONTROLLERS

View File

@ -26,10 +26,7 @@
#include "GuiNomencl.h" #include "GuiNomencl.h"
#include "GuiParagraph.h" #include "GuiParagraph.h"
#include "GuiPrefs.h" #include "GuiPrefs.h"
#include "GuiPrint.h"
#include "GuiShowFile.h"
#include "GuiView.h" #include "GuiView.h"
#include "TocWidget.h"
#include "GuiURL.h" #include "GuiURL.h"
// Uncomment this if you prefer dock widget // Uncomment this if you prefer dock widget
@ -198,7 +195,7 @@ Dialog * Dialogs::build(string const & name)
if (name == "prefs") if (name == "prefs")
return new GuiPrefsDialog(lyxview_); return new GuiPrefsDialog(lyxview_);
if (name == "print") if (name == "print")
return new GuiPrintDialog(lyxview_); return createGuiPrint(lyxview_);
if (name == "ref") if (name == "ref")
return createGuiRef(lyxview_); return createGuiRef(lyxview_);
if (name == "sendto") if (name == "sendto")

View File

@ -5,6 +5,7 @@
* *
* \author John Levon * \author John Levon
* \author Edwin Leuven * \author Edwin Leuven
* \author Angus Leeming
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -13,10 +14,19 @@
#include "GuiPrint.h" #include "GuiPrint.h"
#include "ControlPrint.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "PrinterParams.h" #include "PrinterParams.h"
#include "frontend_helpers.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "support/convert.h"
#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/os.h" #include "support/os.h"
#include <QLineEdit> #include <QLineEdit>
@ -25,24 +35,29 @@
#include <QSpinBox> #include <QSpinBox>
#include <QPushButton> #include <QPushButton>
using std::string;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
GuiPrintDialog::GuiPrintDialog(LyXView & lv) using support::FileFilterList;
: GuiDialog(lv, "print")
GuiPrint::GuiPrint(LyXView & lv)
: GuiDialog(lv, "print"), Controller(this)
{ {
setupUi(this); setupUi(this);
setController(new ControlPrint(*this)); setController(this, false);
setViewTitle(_("Print Document")); setViewTitle(_("Print Document"));
connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(printPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int))); connect(copiesSB, SIGNAL(valueChanged(int)), this, SLOT(copiesChanged(int)));
connect(printerED, SIGNAL(textChanged(const QString&)), connect(printerED, SIGNAL(textChanged(QString)),
this, SLOT(printerChanged())); this, SLOT(printerChanged()));
connect(fileED, SIGNAL(textChanged(const QString&)), connect(fileED, SIGNAL(textChanged(QString)),
this, SLOT(fileChanged() )); this, SLOT(fileChanged() ));
connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked())); connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(allRB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
@ -67,21 +82,20 @@ GuiPrintDialog::GuiPrintDialog(LyXView & lv)
} }
ControlPrint & GuiPrintDialog::controller() void GuiPrint::change_adaptor()
{
return static_cast<ControlPrint &>(GuiDialog::controller());
}
void GuiPrintDialog::change_adaptor()
{ {
changed(); changed();
} }
void GuiPrintDialog::browseClicked() void GuiPrint::browseClicked()
{ {
QString file = toqstr(controller().browse(docstring())); docstring name =
browseRelFile(docstring(), from_utf8(buffer().filePath()),
_("Print to file"),
FileFilterList(_("PostScript files (*.ps)")),
true);
QString file = toqstr(name);
if (!file.isNull()) { if (!file.isNull()) {
fileED->setText(file); fileED->setText(file);
changed(); changed();
@ -89,7 +103,7 @@ void GuiPrintDialog::browseClicked()
} }
void GuiPrintDialog::fileChanged() void GuiPrint::fileChanged()
{ {
if (!fileED->text().isEmpty()) if (!fileED->text().isEmpty())
fileRB->setChecked(true); fileRB->setChecked(true);
@ -97,67 +111,66 @@ void GuiPrintDialog::fileChanged()
} }
void GuiPrintDialog::copiesChanged(int i) void GuiPrint::copiesChanged(int i)
{ {
collateCB->setEnabled(i != 1); collateCB->setEnabled(i != 1);
changed(); changed();
} }
void GuiPrintDialog::printerChanged() void GuiPrint::printerChanged()
{ {
printerRB->setChecked(true); printerRB->setChecked(true);
changed(); changed();
} }
void GuiPrintDialog::pagerangeChanged() void GuiPrint::pagerangeChanged()
{ {
changed(); changed();
} }
void GuiPrintDialog::updateContents() void GuiPrint::updateContents()
{ {
PrinterParams & pp = controller().params();
// only reset params if a different buffer // only reset params if a different buffer
if (!pp.file_name.empty() && pp.file_name == fromqstr(fileED->text())) if (!params_.file_name.empty()
&& params_.file_name == fromqstr(fileED->text()))
return; return;
printerED->setText(toqstr(pp.printer_name)); printerED->setText(toqstr(params_.printer_name));
fileED->setText(toqstr(pp.file_name)); fileED->setText(toqstr(params_.file_name));
printerRB->setChecked(true); printerRB->setChecked(true);
if (pp.target == PrinterParams::FILE) if (params_.target == PrinterParams::FILE)
fileRB->setChecked(true); fileRB->setChecked(true);
reverseCB->setChecked(pp.reverse_order); reverseCB->setChecked(params_.reverse_order);
copiesSB->setValue(pp.count_copies); copiesSB->setValue(params_.count_copies);
oddCB->setChecked(pp.odd_pages); oddCB->setChecked(params_.odd_pages);
evenCB->setChecked(pp.even_pages); evenCB->setChecked(params_.even_pages);
collateCB->setChecked(pp.sorted_copies); collateCB->setChecked(params_.sorted_copies);
if (pp.all_pages) { if (params_.all_pages) {
allRB->setChecked(true); allRB->setChecked(true);
} else { } else {
rangeRB->setChecked(true); rangeRB->setChecked(true);
fromED->setText(QString::number(pp.from_page)); fromED->setText(QString::number(params_.from_page));
toED->setText(QString::number(pp.to_page)); toED->setText(QString::number(params_.to_page));
} }
} }
void GuiPrintDialog::applyView() void GuiPrint::applyView()
{ {
PrinterParams::Target t = PrinterParams::PRINTER; PrinterParams::Target t = PrinterParams::PRINTER;
if (fileRB->isChecked()) if (fileRB->isChecked())
t = PrinterParams::FILE; t = PrinterParams::FILE;
PrinterParams const pp(t, params_ = PrinterParams(t,
fromqstr(printerED->text()), fromqstr(printerED->text()),
support::os::internal_path(fromqstr(fileED->text())), support::os::internal_path(fromqstr(fileED->text())),
allRB->isChecked(), allRB->isChecked(),
@ -167,11 +180,89 @@ void GuiPrintDialog::applyView()
evenCB->isChecked(), evenCB->isChecked(),
copiesSB->text().toUInt(), copiesSB->text().toUInt(),
collateCB->isChecked(), collateCB->isChecked(),
reverseCB->isChecked()); reverseCB->isChecked()
);
controller().params() = pp;
} }
bool GuiPrint::initialiseParams(std::string const &)
{
/// get global printer parameters
string const name = support::changeExtension(buffer().fileName(),
lyxrc.print_file_extension);
params_ = PrinterParams(PrinterParams::PRINTER, lyxrc.printer, name);
dialog().setButtonsValid(true); // so that the user can press Ok
return true;
}
void GuiPrint::clearParams()
{
params_ = PrinterParams();
}
/// print the current buffer
void GuiPrint::dispatchParams()
{
string command = lyxrc.print_command + ' ';
if (params_.target == PrinterParams::PRINTER
&& lyxrc.print_adapt_output // dvips wants a printer name
&& !params_.printer_name.empty()) {// printer name given
command += lyxrc.print_to_printer + params_.printer_name + ' ';
}
if (!params_.all_pages && params_.from_page) {
command += lyxrc.print_pagerange_flag + ' ';
command += convert<string>(params_.from_page);
if (params_.to_page) {
// we have a range "from-to"
command += '-' + convert<string>(params_.to_page);
}
command += ' ';
}
// If both are, or both are not selected, then skip the odd/even printing
if (params_.odd_pages != params_.even_pages) {
if (params_.odd_pages)
command += lyxrc.print_oddpage_flag + ' ';
else if (params_.even_pages)
command += lyxrc.print_evenpage_flag + ' ';
}
if (params_.count_copies > 1) {
if (params_.sorted_copies)
command += lyxrc.print_collcopies_flag;
else
command += lyxrc.print_copies_flag;
command += ' ' + convert<string>(params_.count_copies) + ' ';
}
if (params_.reverse_order)
command += lyxrc.print_reverse_flag + ' ';
if (!lyxrc.print_extra_options.empty())
command += lyxrc.print_extra_options + ' ';
command += buffer().params().dvips_options();
string const target = (params_.target == PrinterParams::PRINTER) ?
"printer" : "file";
string const target_name = (params_.target == PrinterParams::PRINTER) ?
(params_.printer_name.empty() ? "default" : params_.printer_name) :
params_.file_name;
string const data = target + " \"" + target_name + "\" \"" + command + '"';
dispatch(FuncRequest(getLfun(), data));
}
Dialog * createGuiPrint(LyXView & lv) { return new GuiPrint(lv); }
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -4,6 +4,8 @@
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Allan Rae
* \author Angus Leeming
* \author John Levon * \author John Levon
* \author Edwin Leuven * \author Edwin Leuven
* *
@ -14,18 +16,21 @@
#define GUIPRINT_H #define GUIPRINT_H
#include "GuiDialog.h" #include "GuiDialog.h"
#include "ControlPrint.h"
#include "ui_PrintUi.h" #include "ui_PrintUi.h"
#include "Dialog.h"
#include "PrinterParams.h"
#include "support/docstring.h"
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class GuiPrintDialog : public GuiDialog, public Ui::PrintUi class GuiPrint : public GuiDialog, public Ui::PrintUi, public Controller
{ {
Q_OBJECT Q_OBJECT
public: public:
GuiPrintDialog(LyXView & lv); GuiPrint(LyXView & lv);
private Q_SLOTS: private Q_SLOTS:
void change_adaptor(); void change_adaptor();
@ -35,13 +40,28 @@ private Q_SLOTS:
void printerChanged(); void printerChanged();
void pagerangeChanged(); void pagerangeChanged();
/// parent controller /// parent controller
ControlPrint & controller(); Controller & controller() { return *this; }
private: private:
/// Apply changes /// Apply changes
void applyView(); void applyView();
/// update /// update
void updateContents(); void updateContents();
///
bool initialiseParams(std::string const & data);
///
void clearParams();
///
void dispatchParams();
///
bool isBufferDependent() const { return true; }
///
bool canApplyToReadOnly() const { return true; }
///
kb_action getLfun() const { return LFUN_BUFFER_PRINT; }
///
PrinterParams params_;
}; };
} // namespace frontend } // namespace frontend