2000-11-29 12:17:44 +00:00
|
|
|
#include <config.h>
|
2000-07-16 00:20:08 +00:00
|
|
|
#include <kaction.h>
|
2000-07-05 10:44:59 +00:00
|
|
|
#include <kaboutdata.h>
|
|
|
|
#include <kaboutdialog.h>
|
2001-10-10 17:57:49 +00:00
|
|
|
#include <kapplication.h>
|
2000-07-05 10:44:59 +00:00
|
|
|
#include <kbugreport.h>
|
|
|
|
#include <kconfig.h>
|
2000-05-15 04:53:53 +00:00
|
|
|
#include <kdebug.h>
|
2000-05-17 10:09:01 +00:00
|
|
|
#include <kglobal.h>
|
2001-06-04 09:44:47 +00:00
|
|
|
#include <klocale.h>
|
2000-07-05 10:44:59 +00:00
|
|
|
#include <kimageeffect.h>
|
|
|
|
#include <kinstance.h>
|
2001-05-03 08:45:04 +00:00
|
|
|
#include <kmessagebox.h>
|
2001-06-04 09:44:47 +00:00
|
|
|
#include <kprinter.h>
|
2001-10-27 11:38:16 +00:00
|
|
|
#include <kstdaction.h>
|
2000-11-29 12:17:44 +00:00
|
|
|
#include <qobject.h>
|
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qstring.h>
|
|
|
|
#include <qimage.h>
|
|
|
|
#include <qpixmap.h>
|
2000-05-15 04:53:53 +00:00
|
|
|
|
2000-11-29 12:17:44 +00:00
|
|
|
#include "fontpool.h"
|
2000-11-03 14:38:50 +00:00
|
|
|
#include "kviewpart.h"
|
2000-11-29 12:17:44 +00:00
|
|
|
#include "optiondialog.h"
|
2001-07-06 10:14:01 +00:00
|
|
|
#include "kdvi_multipage.h"
|
2000-05-15 04:53:53 +00:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
2000-06-04 15:55:22 +00:00
|
|
|
void *init_libkdvi()
|
2000-05-15 04:53:53 +00:00
|
|
|
{
|
2001-09-13 11:49:19 +00:00
|
|
|
KGlobal::locale()->insertCatalogue("kviewshell");
|
2000-05-15 04:53:53 +00:00
|
|
|
return new KDVIMultiPageFactory;
|
|
|
|
}
|
|
|
|
};
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2000-05-15 04:53:53 +00:00
|
|
|
|
|
|
|
KInstance *KDVIMultiPageFactory::s_instance = 0L;
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2000-05-15 04:53:53 +00:00
|
|
|
|
|
|
|
KDVIMultiPageFactory::KDVIMultiPageFactory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2000-05-15 04:53:53 +00:00
|
|
|
KDVIMultiPageFactory::~KDVIMultiPageFactory()
|
|
|
|
{
|
|
|
|
if (s_instance)
|
|
|
|
delete s_instance;
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2000-05-15 04:53:53 +00:00
|
|
|
s_instance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-12 17:35:46 +00:00
|
|
|
KParts::Part *KDVIMultiPageFactory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, const char *, const QStringList & )
|
2000-05-15 04:53:53 +00:00
|
|
|
{
|
2000-06-27 09:14:42 +00:00
|
|
|
KParts::Part *obj = new KDVIMultiPage(parentWidget, widgetName, parent, name);
|
2000-05-15 04:53:53 +00:00
|
|
|
return obj;
|
|
|
|
}
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2000-05-15 04:53:53 +00:00
|
|
|
|
|
|
|
KInstance *KDVIMultiPageFactory::instance()
|
|
|
|
{
|
|
|
|
if (!s_instance)
|
|
|
|
s_instance = new KInstance("kdvi");
|
|
|
|
return s_instance;
|
2000-06-27 09:14:42 +00:00
|
|
|
}
|
2000-05-15 04:53:53 +00:00
|
|
|
|
|
|
|
|
2000-06-27 09:14:42 +00:00
|
|
|
KDVIMultiPage::KDVIMultiPage(QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name)
|
|
|
|
: KMultiPage(parentWidget, widgetName, parent, name), window(0), options(0)
|
2000-05-15 04:53:53 +00:00
|
|
|
{
|
2000-06-30 06:41:47 +00:00
|
|
|
timer_id = -1;
|
|
|
|
setInstance(KDVIMultiPageFactory::instance());
|
2000-05-15 04:53:53 +00:00
|
|
|
|
2001-06-04 09:44:47 +00:00
|
|
|
printer = 0;
|
2000-11-29 12:17:44 +00:00
|
|
|
window = new dviWindow( 1.0, true, scrollView());
|
2000-05-17 10:09:01 +00:00
|
|
|
preferencesChanged();
|
|
|
|
|
2001-06-11 13:40:16 +00:00
|
|
|
connect( window, SIGNAL( setStatusBarText( const QString& ) ), this, SIGNAL( setStatusBarText( const QString& ) ) );
|
2001-05-03 08:45:04 +00:00
|
|
|
docInfoAction = new KAction(i18n("Document &Info"), 0, this, SLOT(doInfo()), actionCollection(), "info_dvi");
|
2001-10-27 11:38:16 +00:00
|
|
|
findTextAction = KStdAction::find(this, SLOT(doFindText()), actionCollection(), "find");
|
2001-05-03 08:45:04 +00:00
|
|
|
exportPSAction = new KAction(i18n("PostScript"), 0, this, SLOT(doExportPS()), actionCollection(), "export_postscript");
|
|
|
|
exportPDFAction = new KAction(i18n("PDF"), 0, this, SLOT(doExportPDF()), actionCollection(), "export_pdf");
|
2001-10-27 11:38:16 +00:00
|
|
|
exportTextAction = new KAction(i18n("Text"), 0, this, SLOT(doExportText()), actionCollection(), "export_text");
|
2000-06-30 06:41:47 +00:00
|
|
|
|
2001-05-03 08:45:04 +00:00
|
|
|
new KAction(i18n("&DVI Options"), 0, this, SLOT(doSettings()), actionCollection(), "settings_dvi");
|
|
|
|
new KAction(i18n("About the KDVI plugin..."), 0, this, SLOT(about()), actionCollection(), "about_kdvi");
|
|
|
|
new KAction(i18n("Help on the KDVI plugin..."), 0, this, SLOT(helpme()), actionCollection(), "help_dvi");
|
|
|
|
new KAction(i18n("Report Bug in the KDVI plugin..."), 0, this, SLOT(bugform()), actionCollection(), "bug_dvi");
|
2000-07-05 10:44:59 +00:00
|
|
|
|
2000-05-17 10:09:01 +00:00
|
|
|
setXMLFile("kdvi_part.rc");
|
2000-05-15 04:53:53 +00:00
|
|
|
|
|
|
|
scrollView()->addChild(window);
|
2000-06-11 07:04:57 +00:00
|
|
|
connect(window, SIGNAL(request_goto_page(int, int)), this, SLOT(goto_page(int, int) ) );
|
2001-06-05 07:25:25 +00:00
|
|
|
connect(window, SIGNAL(contents_changed(void)), this, SLOT(contents_of_dviwin_changed(void)) );
|
2000-05-22 11:58:18 +00:00
|
|
|
|
|
|
|
readSettings();
|
2001-05-03 08:45:04 +00:00
|
|
|
enableActions(false);
|
2000-05-15 04:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KDVIMultiPage::~KDVIMultiPage()
|
|
|
|
{
|
2000-06-30 06:41:47 +00:00
|
|
|
if (timer_id != -1)
|
|
|
|
killTimer(timer_id);
|
|
|
|
timer_id = -1;
|
2000-05-22 11:58:18 +00:00
|
|
|
writeSettings();
|
2001-06-04 09:44:47 +00:00
|
|
|
if (printer != 0)
|
|
|
|
delete printer;
|
2000-05-15 04:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KDVIMultiPage::openFile()
|
|
|
|
{
|
2001-06-11 13:40:16 +00:00
|
|
|
emit setStatusBarText(QString(i18n("Loading file %1")).arg(m_file));
|
|
|
|
|
2001-11-16 16:26:38 +00:00
|
|
|
bool r = window->setFile(m_file,url().ref());
|
2000-06-30 06:41:47 +00:00
|
|
|
window->changePageSize(); // This also calles drawPage();
|
2000-05-15 04:53:53 +00:00
|
|
|
emit numberOfPages(window->totalPages());
|
2001-05-03 08:45:04 +00:00
|
|
|
enableActions(r);
|
2000-05-22 08:00:41 +00:00
|
|
|
|
2001-04-14 13:47:21 +00:00
|
|
|
return r;
|
2000-05-15 04:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-20 12:46:54 +00:00
|
|
|
void KDVIMultiPage::jumpToReference(QString reference)
|
|
|
|
{
|
|
|
|
kdError() << "Reference: " << reference << endl;
|
|
|
|
if (window != 0) {
|
|
|
|
window->reference = reference;
|
|
|
|
window->all_fonts_loaded(); // In spite of its name, this method tries to parse the reference.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-05 07:25:25 +00:00
|
|
|
void KDVIMultiPage::contents_of_dviwin_changed(void)
|
|
|
|
{
|
|
|
|
emit previewChanged(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-17 08:50:57 +00:00
|
|
|
bool KDVIMultiPage::closeURL()
|
|
|
|
{
|
2000-07-25 08:52:17 +00:00
|
|
|
window->setFile(""); // That means: close the file. Resize the widget to 0x0.
|
2001-05-03 08:45:04 +00:00
|
|
|
enableActions(false);
|
2000-05-17 08:50:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 04:53:53 +00:00
|
|
|
QStringList KDVIMultiPage::fileFormats()
|
|
|
|
{
|
|
|
|
QStringList r;
|
2001-05-03 08:45:04 +00:00
|
|
|
r << i18n("*.dvi *.DVI|TeX Device Independent files (*.dvi)");
|
2000-05-15 04:53:53 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KDVIMultiPage::gotoPage(int page)
|
|
|
|
{
|
2000-05-17 08:50:57 +00:00
|
|
|
window->gotoPage(page+1);
|
2000-05-15 04:53:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-06-11 07:04:57 +00:00
|
|
|
void KDVIMultiPage::goto_page(int page, int y)
|
|
|
|
{
|
2001-05-21 07:15:24 +00:00
|
|
|
window->gotoPage(page+1, y);
|
2000-07-18 11:38:27 +00:00
|
|
|
scrollView()->ensureVisible(scrollView()->width()/2, y );
|
2000-07-08 11:58:30 +00:00
|
|
|
emit pageInfo(window->totalPages(), page );
|
2000-06-11 07:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 04:53:53 +00:00
|
|
|
|
2000-05-22 08:21:38 +00:00
|
|
|
double KDVIMultiPage::setZoom(double zoom)
|
2000-05-15 04:53:53 +00:00
|
|
|
{
|
2000-11-03 14:38:50 +00:00
|
|
|
if (zoom < KViewPart::minZoom/1000.0)
|
|
|
|
zoom = KViewPart::minZoom/1000.0;
|
|
|
|
if (zoom > KViewPart::maxZoom/1000.0)
|
|
|
|
zoom = KViewPart::maxZoom/1000.0;
|
|
|
|
|
|
|
|
double z = window->setZoom(zoom);
|
2000-05-15 04:53:53 +00:00
|
|
|
scrollView()->resizeContents(window->width(), window->height());
|
2000-05-22 08:21:38 +00:00
|
|
|
|
2000-11-03 14:38:50 +00:00
|
|
|
return z;
|
2000-05-15 04:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double KDVIMultiPage::zoomForHeight(int height)
|
|
|
|
{
|
2001-07-09 07:41:24 +00:00
|
|
|
return (double)(height-1)/(window->xres*(window->paper_height/2.54));
|
2000-05-15 04:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double KDVIMultiPage::zoomForWidth(int width)
|
|
|
|
{
|
2001-07-09 07:41:24 +00:00
|
|
|
return (double)(width-1)/(window->xres*(window->paper_width/2.54));
|
2000-05-15 04:53:53 +00:00
|
|
|
}
|
2000-05-16 11:18:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void KDVIMultiPage::setPaperSize(double w, double h)
|
|
|
|
{
|
|
|
|
window->setPaper(w, h);
|
|
|
|
}
|
2000-05-16 14:13:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool KDVIMultiPage::preview(QPainter *p, int w, int h)
|
|
|
|
{
|
2000-05-17 08:50:57 +00:00
|
|
|
QPixmap *map = window->pix();
|
|
|
|
|
|
|
|
if (!map)
|
2000-05-16 14:13:41 +00:00
|
|
|
return false;
|
|
|
|
|
2000-05-17 08:50:57 +00:00
|
|
|
p->scale((double)w/(double)map->width(), (double)h/(double)map->height());
|
|
|
|
p->drawPixmap(0, 0, *map);
|
2000-05-16 14:13:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2000-05-17 10:09:01 +00:00
|
|
|
|
|
|
|
|
2001-03-28 10:16:48 +00:00
|
|
|
void KDVIMultiPage::doInfo(void)
|
|
|
|
{
|
|
|
|
window->showInfo();
|
|
|
|
}
|
|
|
|
|
2001-05-03 08:45:04 +00:00
|
|
|
void KDVIMultiPage::doExportPS(void)
|
|
|
|
{
|
|
|
|
window->exportPS();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDVIMultiPage::doExportPDF(void)
|
|
|
|
{
|
|
|
|
window->exportPDF();
|
|
|
|
}
|
|
|
|
|
2001-10-27 11:38:16 +00:00
|
|
|
void KDVIMultiPage::doExportText(void)
|
|
|
|
{
|
|
|
|
window->exportText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDVIMultiPage::doFindText(void)
|
|
|
|
{
|
|
|
|
window->findText();
|
|
|
|
}
|
|
|
|
|
2000-05-17 10:09:01 +00:00
|
|
|
void KDVIMultiPage::doSettings()
|
|
|
|
{
|
2001-09-05 15:13:19 +00:00
|
|
|
if (!options) {
|
|
|
|
options = new OptionDialog(window);
|
|
|
|
connect(options, SIGNAL(preferencesChanged()), this, SLOT(preferencesChanged()));
|
2000-06-30 06:41:47 +00:00
|
|
|
}
|
2000-05-17 10:09:01 +00:00
|
|
|
options->show();
|
|
|
|
}
|
|
|
|
|
2000-06-30 06:41:47 +00:00
|
|
|
void KDVIMultiPage::about()
|
|
|
|
{
|
2000-07-05 10:44:59 +00:00
|
|
|
KAboutDialog *ab = new KAboutDialog(KAboutDialog::AbtAppStandard,
|
|
|
|
i18n("the KDVI plugin"),
|
|
|
|
KAboutDialog::Close, KAboutDialog::Close);
|
|
|
|
|
2001-10-18 16:40:34 +00:00
|
|
|
ab->setProduct("kdvi", "1.0alpha", QString::null, QString::null);
|
2000-07-05 10:44:59 +00:00
|
|
|
ab->addTextPage (i18n("About"),
|
|
|
|
i18n("A previewer for Device Independent files (DVI files) produced "
|
|
|
|
"by the TeX typesetting system.<br>"
|
|
|
|
"Based on kdvi 0.4.3 and on xdvik, version 18f.<br><hr>"
|
|
|
|
"For latest information, visit "
|
|
|
|
"<a href=\"http://devel-home.kde.org/~kdvi\">KDVI's Homepage</a>."),
|
|
|
|
true);
|
|
|
|
ab->addTextPage (i18n("Authors"),
|
2001-03-28 10:16:48 +00:00
|
|
|
i18n("Stefan Kebekus<br>"
|
2000-07-05 10:44:59 +00:00
|
|
|
"<a href=\"http://btm8x5.mat.uni-bayreuth.de/~kebekus\">"
|
|
|
|
"http://btm8x5.mat.uni-bayreuth.de/~kebekus</a><br>"
|
|
|
|
"<a href=\"mailto:kebekus@kde.org\">kebekus@kde.org</a><br>"
|
|
|
|
"Current maintainer of kdvi. Major rewrite of version 0.4.3."
|
|
|
|
"Implementation of hyperlinks.<br>"
|
|
|
|
"<hr>"
|
2001-03-28 10:16:48 +00:00
|
|
|
"Markku Hinhala<br>"
|
|
|
|
"Author of kdvi 0.4.3"
|
|
|
|
"<hr>"
|
2000-07-05 10:44:59 +00:00
|
|
|
"Nicolai Langfeldt<br>"
|
2001-03-28 10:16:48 +00:00
|
|
|
"Maintainer of xdvik"
|
2000-07-05 10:44:59 +00:00
|
|
|
"<hr>"
|
|
|
|
"Paul Vojta<br>"
|
|
|
|
" Author of xdvi<br>"
|
|
|
|
"<hr>"
|
|
|
|
"Many others. Really, lots of people who were involved in kdvi, xdvik and "
|
|
|
|
"xdvi. I apologize to those who I did not mention here. Please send me an "
|
|
|
|
"email if you think your name belongs here."),
|
|
|
|
true);
|
2001-03-28 10:16:48 +00:00
|
|
|
ab->setMinimumWidth(500);
|
2000-06-30 06:41:47 +00:00
|
|
|
ab->show();
|
|
|
|
}
|
|
|
|
|
2000-07-05 10:44:59 +00:00
|
|
|
void KDVIMultiPage::bugform()
|
|
|
|
{
|
2001-10-18 16:40:34 +00:00
|
|
|
KAboutData *kab = new KAboutData("kdvi", I18N_NOOP("KDVI"), "1.0alpha", 0, 0, 0, 0, 0);
|
2000-07-05 10:44:59 +00:00
|
|
|
KBugReport *kbr = new KBugReport(0, true, kab );
|
|
|
|
kbr->show();
|
|
|
|
}
|
|
|
|
|
2000-06-30 06:41:47 +00:00
|
|
|
void KDVIMultiPage::helpme()
|
|
|
|
{
|
|
|
|
kapp->invokeHelp( "", "kdvi" );
|
|
|
|
}
|
2000-05-17 10:09:01 +00:00
|
|
|
|
|
|
|
void KDVIMultiPage::preferencesChanged()
|
|
|
|
{
|
2001-04-08 09:21:27 +00:00
|
|
|
#ifdef DEBUG_MULTIPAGE
|
2000-07-05 10:44:59 +00:00
|
|
|
kdDebug(4300) << "preferencesChanged" << endl;
|
2000-06-30 06:41:47 +00:00
|
|
|
#endif
|
2000-06-14 04:15:22 +00:00
|
|
|
|
2000-05-22 11:58:18 +00:00
|
|
|
KConfig *config = instance()->config();
|
2000-05-17 10:09:01 +00:00
|
|
|
|
|
|
|
QString s;
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2000-06-14 04:15:22 +00:00
|
|
|
config->reparseConfiguration();
|
2000-05-17 10:09:01 +00:00
|
|
|
config->setGroup( "kdvi" );
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2000-11-29 12:17:44 +00:00
|
|
|
int mfmode = config->readNumEntry( "MetafontMode", DefaultMFMode );
|
|
|
|
if (( mfmode < 0 ) || (mfmode >= NumberOfMFModes))
|
|
|
|
config->writeEntry( "MetafontMode", mfmode = DefaultMFMode );
|
2000-11-25 15:31:29 +00:00
|
|
|
window->setMetafontMode( mfmode );
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2001-03-15 15:11:36 +00:00
|
|
|
int makepk = config->readBoolEntry( "MakePK", true );
|
2000-05-17 10:09:01 +00:00
|
|
|
if ( makepk != window->makePK() )
|
2000-06-27 09:14:42 +00:00
|
|
|
window->setMakePK( makepk );
|
|
|
|
|
2000-07-11 11:00:35 +00:00
|
|
|
int showPS = config->readNumEntry( "ShowPS", 1 );
|
2000-05-17 10:09:01 +00:00
|
|
|
if (showPS != window->showPS())
|
|
|
|
window->setShowPS(showPS);
|
2000-06-14 04:15:22 +00:00
|
|
|
|
2000-07-11 11:00:35 +00:00
|
|
|
int showHyperLinks = config->readNumEntry( "ShowHyperLinks", 1 );
|
2000-06-14 04:15:22 +00:00
|
|
|
if (showHyperLinks != window->showHyperLinks())
|
|
|
|
window->setShowHyperLinks(showHyperLinks);
|
2001-08-20 16:13:34 +00:00
|
|
|
|
|
|
|
window->setEditorCommand( config->readEntry( "EditorCommand", "" ));
|
2000-05-17 10:09:01 +00:00
|
|
|
}
|
2000-05-18 10:51:08 +00:00
|
|
|
|
|
|
|
|
2000-08-06 10:25:11 +00:00
|
|
|
bool KDVIMultiPage::print(const QStringList &pages, int current)
|
2000-05-18 10:51:08 +00:00
|
|
|
{
|
2001-06-04 09:44:47 +00:00
|
|
|
// Make sure the KPrinter is available
|
|
|
|
if (printer == 0) {
|
|
|
|
printer = new KPrinter();
|
|
|
|
if (printer == 0)
|
|
|
|
return false;
|
|
|
|
}
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2001-06-04 09:44:47 +00:00
|
|
|
// Feed the printer with useful defaults and information.
|
|
|
|
printer->setPageSelection( KPrinter::ApplicationSide );
|
|
|
|
printer->setCurrentPage( current+1 );
|
|
|
|
printer->setMinMax( 1, window->totalPages() );
|
|
|
|
|
|
|
|
// If pages are marked, give a list of marked pages to the
|
|
|
|
// printer. We try to be smart and optimize the list by using ranges
|
|
|
|
// ("5-11") wherever possible. The user will be tankful for
|
|
|
|
// that. Complicated? Yeah, but that's life.
|
|
|
|
if (pages.isEmpty() == true)
|
|
|
|
printer->setOption( "kde-range", "" );
|
|
|
|
else {
|
|
|
|
int commaflag = 0;
|
|
|
|
QString range;
|
|
|
|
QStringList::ConstIterator it = pages.begin();
|
|
|
|
do{
|
|
|
|
int val = (*it).toUInt()+1;
|
|
|
|
if (commaflag == 1)
|
|
|
|
range += QString(", ");
|
|
|
|
else
|
|
|
|
commaflag = 1;
|
|
|
|
int endval = val;
|
|
|
|
if (it != pages.end()) {
|
|
|
|
QStringList::ConstIterator jt = it;
|
|
|
|
jt++;
|
|
|
|
do{
|
|
|
|
int val2 = (*jt).toUInt()+1;
|
|
|
|
if (val2 == endval+1)
|
|
|
|
endval++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
jt++;
|
|
|
|
} while( jt != pages.end() );
|
|
|
|
it = jt;
|
|
|
|
} else
|
|
|
|
it++;
|
|
|
|
if (endval == val)
|
|
|
|
range += QString("%1").arg(val);
|
|
|
|
else
|
|
|
|
range += QString("%1-%2").arg(val).arg(endval);
|
|
|
|
} while (it != pages.end() );
|
|
|
|
printer->setOption( "kde-range", range );
|
|
|
|
}
|
2000-06-27 09:14:42 +00:00
|
|
|
|
2001-06-04 09:44:47 +00:00
|
|
|
// Show the printer options requestor
|
|
|
|
if (printer->setup(window) == false)
|
|
|
|
return false;
|
2001-06-11 13:40:16 +00:00
|
|
|
if (printer->pageList().isEmpty() == true) {
|
|
|
|
KMessageBox::error( window,
|
|
|
|
i18n("The list of pages you selected was empty.\n"
|
|
|
|
"Maybe you made an error in selecting the pages, \n"
|
|
|
|
"e.g. by giving in invalid range like '7-2'.") );
|
|
|
|
return false;
|
|
|
|
}
|
2000-05-18 10:58:41 +00:00
|
|
|
|
2001-06-04 09:44:47 +00:00
|
|
|
// Turn the results of the options requestor into a list arguments
|
|
|
|
// which are used by dvips.
|
2001-11-12 12:45:08 +00:00
|
|
|
QString dvips_options = QString::null;
|
2001-06-04 09:44:47 +00:00
|
|
|
// Print in reverse order.
|
|
|
|
if ( printer->pageOrder() == KPrinter::LastPageFirst )
|
|
|
|
dvips_options += "-r ";
|
|
|
|
// Print only odd pages.
|
|
|
|
if ( printer->pageSet() == KPrinter::OddPages )
|
|
|
|
dvips_options += "-A ";
|
|
|
|
// Print only even pages.
|
|
|
|
if ( printer->pageSet() == KPrinter::EvenPages )
|
|
|
|
dvips_options += "-B ";
|
|
|
|
// Orientation
|
|
|
|
if ( printer->orientation() == KPrinter::Landscape )
|
|
|
|
dvips_options += "-t landscape ";
|
|
|
|
// List of pages to print.
|
|
|
|
QValueList<int> pageList = printer->pageList();
|
|
|
|
dvips_options += "-pp ";
|
|
|
|
int commaflag = 0;
|
|
|
|
for( QValueList<int>::ConstIterator it = pageList.begin(); it != pageList.end(); ++it ) {
|
|
|
|
if (commaflag == 1)
|
|
|
|
dvips_options += QString(",");
|
|
|
|
else
|
|
|
|
commaflag = 1;
|
|
|
|
dvips_options += QString("%1").arg(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now print. For that, export the DVI-File to PostScript. Note that
|
|
|
|
// dvips will run concurrently to keep the GUI responsive, keep log
|
|
|
|
// of dvips and allow abort. Giving a non-zero printer argument
|
|
|
|
// means that the dvi-widget will print the file when dvips
|
|
|
|
// terminates, and then delete the output file.
|
|
|
|
KTempFile tf;
|
|
|
|
window->exportPS(tf.name(), dvips_options, printer);
|
|
|
|
|
|
|
|
// "True" may be a bit euphemistic. However, since dvips runs
|
|
|
|
// concurrently, there is no way of telling the result of the
|
2001-08-28 13:02:20 +00:00
|
|
|
// printing command at this stage.
|
2000-05-18 10:58:41 +00:00
|
|
|
return true;
|
2000-05-18 10:51:08 +00:00
|
|
|
}
|
2000-06-01 10:27:41 +00:00
|
|
|
|
|
|
|
|
2000-06-30 06:41:47 +00:00
|
|
|
// Explanation of the timerEvent.
|
|
|
|
//
|
|
|
|
// This is a dreadful hack. The problem we adress with this timer
|
|
|
|
// event is the following: the kviewshell has a KDirWatch object which
|
|
|
|
// looks at the DVI file and calls reload() when the object has
|
|
|
|
// changed. That works very nicely in principle, but in practise, when
|
|
|
|
// TeX runs for several seconds over a complicated file, this does not
|
|
|
|
// work at all. First, most of the time, while TeX is still writing,
|
|
|
|
// the file is invalid. Thus, reload() is very often called when the
|
|
|
|
// DVI file is bad. We solve this problem by checking the file
|
|
|
|
// first. If the file is bad, we do not reload. Second, when the file
|
|
|
|
// finally becomes good, it very often happens that KDirWatch does not
|
|
|
|
// notify us anymore. Whether this is a bug or a side effect of a
|
|
|
|
// feature of KDirWatch, I dare not say. We remedy that problem by
|
|
|
|
// using a timer: when reload() was called on a bad file, we
|
|
|
|
// automatically come back (via the timerEvent() function) every
|
|
|
|
// second and check if the file becaome good. If so, we stop the
|
|
|
|
// timer. It may well happen that KDirWatch calls us several times
|
|
|
|
// while we are waiting for the file to become good, but that does not
|
|
|
|
// do any harm.
|
|
|
|
//
|
|
|
|
// -- Stefan Kebekus.
|
|
|
|
|
2001-03-28 10:16:48 +00:00
|
|
|
void KDVIMultiPage::timerEvent( QTimerEvent * )
|
2000-06-30 06:41:47 +00:00
|
|
|
{
|
2001-04-08 09:21:27 +00:00
|
|
|
#ifdef DEBUG_MULTIPAGE
|
2000-07-05 10:44:59 +00:00
|
|
|
kdDebug(4300) << "Timer Event " << endl;
|
|
|
|
#endif
|
2000-06-30 06:41:47 +00:00
|
|
|
reload();
|
|
|
|
}
|
|
|
|
|
2000-06-01 10:27:41 +00:00
|
|
|
void KDVIMultiPage::reload()
|
|
|
|
{
|
2001-04-08 09:21:27 +00:00
|
|
|
#ifdef DEBUG_MULTIPAGE
|
2000-07-05 10:44:59 +00:00
|
|
|
kdDebug(4300) << "Reload file " << m_file << endl;
|
|
|
|
#endif
|
2000-06-23 00:22:44 +00:00
|
|
|
|
|
|
|
if (window->correctDVI(m_file)) {
|
2000-06-30 06:41:47 +00:00
|
|
|
killTimer(timer_id);
|
|
|
|
timer_id = -1;
|
|
|
|
int currsav = window->curr_page();
|
2000-07-07 02:07:26 +00:00
|
|
|
|
2001-05-03 08:45:04 +00:00
|
|
|
bool r = window->setFile(m_file);
|
|
|
|
enableActions(r);
|
2001-04-08 09:21:27 +00:00
|
|
|
|
|
|
|
// Go to the old page and tell kviewshell where we are.
|
2000-06-30 06:41:47 +00:00
|
|
|
window->gotoPage(currsav);
|
2001-04-08 09:21:27 +00:00
|
|
|
// We don't use "currsav" here, because that page may no longer
|
|
|
|
// exist. In that case, gotoPage already selected another page.
|
|
|
|
emit pageInfo(window->totalPages(), window->curr_page()-1 );
|
2000-06-30 06:41:47 +00:00
|
|
|
} else {
|
|
|
|
if (timer_id == -1)
|
|
|
|
timer_id = startTimer(1000);
|
2000-06-23 00:22:44 +00:00
|
|
|
}
|
2000-06-01 10:27:41 +00:00
|
|
|
}
|
2001-05-03 08:45:04 +00:00
|
|
|
|
|
|
|
void KDVIMultiPage::enableActions(bool b)
|
|
|
|
{
|
|
|
|
docInfoAction->setEnabled(b);
|
2001-10-27 11:38:16 +00:00
|
|
|
findTextAction->setEnabled(b);
|
2001-05-03 08:45:04 +00:00
|
|
|
exportPSAction->setEnabled(b);
|
|
|
|
exportPDFAction->setEnabled(b);
|
2001-10-27 11:38:16 +00:00
|
|
|
exportTextAction->setEnabled(b);
|
2001-05-03 08:45:04 +00:00
|
|
|
}
|
2001-07-06 10:14:01 +00:00
|
|
|
|
|
|
|
#include "kdvi_multipage.moc"
|