00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ippreportdlg.h"
00021 #include "ipprequest.h"
00022 #include "kprinter.h"
00023
00024 #include <tdelocale.h>
00025 #include <kguiitem.h>
00026 #include <tdemessagebox.h>
00027 #include <kdebug.h>
00028 #include <ktextedit.h>
00029 #include <tqsimplerichtext.h>
00030 #include <tqpainter.h>
00031 #include <tqpaintdevicemetrics.h>
00032
00033 IppReportDlg::IppReportDlg(TQWidget *parent, const char *name)
00034 : KDialogBase(parent, name, true, i18n("IPP Report"), Close|User1, Close, false, KGuiItem(i18n("&Print"), "document-print"))
00035 {
00036 m_edit = new KTextEdit(this);
00037 m_edit->setReadOnly(true);
00038 setMainWidget(m_edit);
00039 resize(540, 500);
00040 setFocusProxy(m_edit);
00041 setButtonGuiItem(User1, KGuiItem(i18n("&Print"),"document-print"));
00042 }
00043
00044 void IppReportDlg::slotUser1()
00045 {
00046 KPrinter printer;
00047 printer.setFullPage(true);
00048 printer.setDocName(caption());
00049 if (printer.setup(this))
00050 {
00051 TQPainter painter(&printer);
00052 TQPaintDeviceMetrics metrics(&printer);
00053
00054
00055 TQSimpleRichText rich(m_edit->text(), font());
00056 rich.setWidth(&painter, metrics.width());
00057 int margin = (int)(1.5 / 2.54 * metrics.logicalDpiY());
00058 TQRect r(margin, margin, metrics.width()-2*margin, metrics.height()-2*margin);
00059 int hh = rich.height(), page(1);
00060 while (1)
00061 {
00062 rich.draw(&painter, margin, margin, r, colorGroup());
00063 TQString s = caption() + ": " + TQString::number(page);
00064 TQRect br = painter.fontMetrics().boundingRect(s);
00065 painter.drawText(r.right()-br.width()-5, r.top()-br.height()-4, br.width()+5, br.height()+4, Qt::AlignRight|Qt::AlignTop, s);
00066 r.moveBy(0, r.height()-10);
00067 painter.translate(0, -(r.height()-10));
00068 if (r.top() < hh)
00069 {
00070 printer.newPage();
00071 page++;
00072 }
00073 else
00074 break;
00075 }
00076 }
00077 }
00078
00079 void IppReportDlg::report(IppRequest *req, int group, const TQString& caption)
00080 {
00081 TQString str_report;
00082 TQTextStream t(&str_report, IO_WriteOnly);
00083
00084 if (req->htmlReport(group, t))
00085 {
00086 IppReportDlg dlg;
00087 if (!caption.isEmpty())
00088 dlg.setCaption(caption);
00089 dlg.m_edit->setText(str_report);
00090 dlg.exec();
00091 }
00092 else
00093 KMessageBox::error(0, i18n("Internal error: unable to generate HTML report."));
00094 }
00095
00096 #include "ippreportdlg.moc"