4#include <tqpaintdevicemetrics.h> 
   10#include "karmutility.h"         
   15const int levelIndent = 10;
 
   17MyPrinter::MyPrinter(
const TaskView *taskView)
 
   22void MyPrinter::print()
 
   25  if (setup(0L, i18n(
"Print Times"))) {
 
   27    TQPainter painter(
this);
 
   28    TQPaintDeviceMetrics deviceMetrics(
this);
 
   29    TQFontMetrics metrics = painter.fontMetrics();
 
   30    pageHeight = deviceMetrics.height();
 
   31    int pageWidth = deviceMetrics.width();
 
   32    xMargin = margins().width();
 
   33    yMargin = margins().height();
 
   35    lineHeight = metrics.height();
 
   44               task = 
static_cast<Task *
>(task->nextSibling())) {
 
   45      totalTotal += task->totalTime();
 
   46      sessionTotal += task->totalSessionTime();
 
   50    timeWidth = TQMAX(metrics.width(i18n(
"Total")),
 
   51                     metrics.width(formatTime(totalTotal)));
 
   52    sessionTimeWidth = TQMAX(metrics.width(i18n(
"Session")),
 
   53                            metrics.width(formatTime(sessionTotal)));
 
   55    nameFieldWidth = pageWidth - xMargin - timeWidth - sessionTimeWidth - 2*5;
 
   57    int maxReqNameFieldWidth= metrics.width(i18n(
"Task Name "));
 
   61          task = 
static_cast<Task *
>(task->nextSibling()))
 
   63      int width = calculateReqNameWidth(task, metrics, 0);
 
   64      maxReqNameFieldWidth = TQMAX(maxReqNameFieldWidth, width);
 
   66    nameFieldWidth = TQMIN(nameFieldWidth, maxReqNameFieldWidth);
 
   68    int realPageWidth = nameFieldWidth + timeWidth + sessionTimeWidth + 2*5;
 
   71    TQFont origFont, newFont;
 
   72    origFont = painter.font();
 
   74    newFont.setPixelSize( 
static_cast<int>(origFont.pixelSize() * 1.5) );
 
   75    painter.setFont(newFont);
 
   77    int height = metrics.height();
 
   78    TQString now = TDEGlobal::locale()->formatDateTime(TQDateTime::currentDateTime());
 
   80    painter.drawText(xMargin, yoff, pageWidth, height,
 
   81         TQPainter::AlignCenter, 
 
   82         i18n(
"KArm - %1").arg(now));
 
   84    painter.setFont(origFont);
 
   88    printLine(i18n(
"Total"), i18n(
"Session"), i18n(
"Task Name"), painter, 0);
 
   91    painter.drawLine(xMargin, yoff, xMargin + realPageWidth, yoff);
 
   97                task = 
static_cast<Task *
>(task->nextSibling()) )
 
   99      printTask(task, painter, 0);
 
  103    painter.drawLine(xMargin, yoff, xMargin + realPageWidth, yoff);
 
  107    printLine( formatTime( totalTotal ),
 
  108               formatTime( sessionTotal ),
 
  109               TQString(), painter, 0);
 
  113int MyPrinter::calculateReqNameWidth( 
Task* task,
 
  114                                      TQFontMetrics &metrics,
 
  117  int width = metrics.width(task->
name()) + level * levelIndent;
 
  121              subTask = subTask->nextSibling() ) {
 
  122    int subTaskWidth = calculateReqNameWidth(subTask, metrics, level+1);
 
  123    width = TQMAX(width, subTaskWidth);
 
  128void MyPrinter::printTask(
Task *task, TQPainter &painter, 
int level)
 
  130  TQString time = formatTime(task->totalTime());
 
  131  TQString sessionTime = formatTime(task->totalSessionTime());
 
  132  TQString name = task->
name();
 
  133  printLine(time, sessionTime, name, painter, level);
 
  137              subTask = subTask->nextSibling())
 
  139    printTask(subTask, painter, level+1);
 
  143void MyPrinter::printLine( TQString total, TQString session, TQString name, 
 
  144                           TQPainter &painter, 
int level )
 
  146  int xoff = xMargin + 10 * level;
 
  148  painter.drawText( xoff, yoff, nameFieldWidth, lineHeight,
 
  149                    TQPainter::AlignLeft, name);
 
  150  xoff = xMargin + nameFieldWidth;
 
  152  painter.drawText( xoff, yoff, sessionTimeWidth, lineHeight,
 
  153                    TQPainter::AlignRight, session);
 
  154  xoff += sessionTimeWidth+ 5;
 
  156  painter.drawText( xoff, yoff, timeWidth, lineHeight,
 
  157                    TQPainter::AlignRight, total);
 
  162  if (yoff + 2* lineHeight > pageHeight) {
 
Container and interface for the tasks.
Task * first_child() const
Return the first item in the view, cast to a Task pointer.
A class representing a task.
TQString name() const
returns the name of this task.
Task * firstChild() const
return parent Task or null in case of TaskView.