23 #define BREAKPOLICY Qt::TextWrapAnywhere
28 #define PRBGCOLOR QColor(80,80,80)
30 #define SHADOWPATTERN Qt::Dense2Pattern
49 palette.setColor(QPalette::Window,PRBGCOLOR);
50 palette.setColor(QPalette::WindowText,QColor(0,0,0));
52 setAutoFillBackground(
true);
55 setFocusPolicy(Qt::StrongFocus);
57 setCursor(Qt::PointingHandCursor);
58 resize(A4_X+100,A4_Y+100);
68 void HPreviewFrame::reset(
void)
75 void HPreviewFrame::mousePressEvent(QMouseEvent *e)
81 void HPreviewFrame::mouseMoveEvent(QMouseEvent *e)
90 void HPreviewFrame::mouseReleaseEvent(QMouseEvent *e)
97 void HPreviewFrame::resizeEvent(QResizeEvent *e)
102 void HPreviewFrame::wheelEvent(QWheelEvent *e)
104 if(e->modifiers() != Qt::NoModifier)
120 if(scale >= 3)
return;
127 if(scale <= 0.2)
return;
134 void HPreviewFrame::keyPressEvent(QKeyEvent *e)
136 sdebug(
"*** HPreviewFrame::keyPressEvent ***");
137 if(e->key() == Qt::Key_PageUp)
144 if(e->key() == Qt::Key_PageDown)
151 if(e->key() == Qt::Key_S)
158 if(e->key() == Qt::Key_W)
165 if(e->key() == Qt::Key_A)
172 if(e->key() == Qt::Key_D)
180 void HPreviewFrame::paintEvent(QPaintEvent *e)
183 QFrame::paintEvent(e);
199 setWindowTitle(
"Print preview...");
212 printfont = QApplication::font();
219 QPushButton *printButton,*refreshButton,*closeButton;
221 vl =
new QVBoxLayout(
this );
224 hl =
new QHBoxLayout( 0 );
228 printButton =
new QPushButton(
this);
229 printButton->setText(
"Print");
230 refreshButton =
new QPushButton(
this);
231 refreshButton->setText(
"Refresh");
232 closeButton =
new QPushButton(
this);
233 closeButton->setText(
"Close");
234 pn =
new QLabel(
this);
238 else if(data->
getWhoami() ==
"HPlainDataMatrix")
240 pn->setText(
" Print preview: "+tTitle);
248 palette.setColor(QPalette::Window,PRBGCOLOR);
249 preview->setPalette(palette);
250 preview->setAutoFillBackground(
true);
251 preview->setFrameShape ( QFrame::StyledPanel );
252 preview->setFrameShadow( QFrame::Raised );
253 preview->setLineWidth( 4 );
255 hl->addWidget(printButton);
256 hl->addWidget(refreshButton);
259 hl->addWidget(closeButton);
262 vl->addWidget(preview);
264 resize( QSize(525, 639).expandedTo(minimumSizeHint()) );
266 connect(closeButton ,SIGNAL(clicked()),
this,SLOT(close()));
267 connect(refreshButton,SIGNAL(clicked()),
this,SLOT(updateDisplay()));
268 connect(printButton ,SIGNAL(clicked()),
this,SLOT(printIt()));
276 void HPrintTable::keyPressEvent(QKeyEvent *e)
279 QWidget::keyPressEvent(e);
282 void HPrintTable::resizeEvent(QResizeEvent *e)
288 void HPrintTable::scanIt(
void)
290 if(data->
getWhoami() ==
"HPlainDataMatrix")
291 scanPlainDataMatrix();
297 error(
"HPrintTable::scanIt - Cannot draw item: Not supported type!");
300 void HPrintTable::scanPlainDataMatrix(
void)
302 sdebug(
"*** HPrintTable::scanPlainDataMatrix ***");
317 slist =
new QStringList();
320 QPainter *p =
new QPainter();
332 cellh = QFontMetrics(printfont).height();
334 cellh += CELLVMARGIN*2;
349 column = (int)slist->size();
351 for(i=0;i<column;i++)
356 if(column != (
int)slist->size())
358 error(
"*** HPrintTable::scanList *** - found different column number in lines!");
366 for(i=0;i < column;++i)
369 j = QFontMetrics(printfont).width( (*slist)[i] );
383 t = QFontMetrics(printfont)
384 .boundingRect(0,0,maxcellw
385 ,A4_Y,Qt::AlignLeft | BREAKPOLICY,(*slist)[i]).height();
411 cellrh.push_back(curr_cellh);
415 if(pageY > A4_Y - cellh)
427 for(i=0;i < column;++i)
435 for(i=0;i < column;++i)
437 cellw[i] += CELLHMARGIN*2;
440 sdebug(QString(
">>>>Calculated pagenum: %1").arg(page));
444 sdebug(
"*** HPrintTable::scanPlainDataMatrix *** END");
448 void HPrintTable::scanList(
void)
450 sdebug(
"*** HPrintTable::scanList ***");
467 QPainter *p =
new QPainter();
479 cellh = QFontMetrics(printfont).height();
481 cellh += CELLVMARGIN*2;
489 QList<QStringList *>::Iterator iv = data->
getValues()->begin();
496 column = (int)slist->size();
498 for(i=0;i<column;i++)
503 if(column != (
int)slist->size())
505 error(
"*** HPrintTable::scanList *** - found different column number in lines!");
513 for(i=0;i < column;++i)
516 j = QFontMetrics(printfont).width( (*slist)[i] );
530 t = QFontMetrics(printfont)
531 .boundingRect(0,0,maxcellw
532 ,A4_Y,Qt::AlignLeft | BREAKPOLICY,(*slist)[i]).height();
558 cellrh.push_back(curr_cellh);
562 if(pageY > A4_Y - cellh)
573 for(i=0;i < column;++i)
575 j = QFontMetrics(printfont).width( (*data)[i] );
581 for(i=0;i < column;++i)
583 cellw[i] += CELLHMARGIN*2;
586 sdebug(QString(
">>>>Calculated pagenum: %1").arg(page));
589 sdebug(
"*** HPrintTable::scanList *** END");
592 void HPrintTable::scanTable(
void)
594 sdebug(
"*** HPrintTable::scanTable ***");
598 cellh = QFontMetrics(printfont).height()*2+CELLVMARGIN*3;
599 i = (A4_X-(LMARGIN+RMARGIN+4*CELLHMARGIN))/2;
604 sdebug(
"*** HPrintTable::scanTable *** END");
607 int HPrintTable::drawIt(QPainter *p,
double scale,
bool print)
614 p->setClipRect(4,4,preview->width()-8,preview->height()-8);
615 p->translate(preview->panx,preview->pany);
618 p->scale(scale,scale);
621 p->fillRect(20,20,A4_X,A4_Y,QBrush(QColor(50,50,50),SHADOWPATTERN));
622 p->fillRect(0,0,A4_X,A4_Y,QBrush(QColor(255,255,255),Qt::SolidPattern));
624 p->setPen(QColor(0,0,0));
626 p->drawRect(LMARGIN,TMARGIN,A4_X-(RMARGIN+LMARGIN),A4_Y-(BMARGIN+TMARGIN));
628 if(data->
getWhoami() ==
"HPlainDataMatrix")
629 return drawPlainDataMatrix(p,print);
631 return drawTable(p,print);
633 return drawList(p,print);
635 error(
"HPrintTable::drawIt - Cannot draw item: Not supported type!");
641 int HPrintTable::newPage(QPainter *p,
bool print)
646 p->translate(0,(A4_Y+100));
649 p->fillRect(20,20,A4_X,A4_Y,QBrush(QColor(50,50,50),SHADOWPATTERN));
650 p->fillRect(0,0,A4_X,A4_Y,QBrush(QColor(255,255,255),Qt::SolidPattern));
666 p->setPen(QColor(0,0,0));
667 p->drawRect(LMARGIN,TMARGIN,A4_X-(RMARGIN+LMARGIN),A4_Y-(BMARGIN+TMARGIN));
672 DRAWLINE(LMARGIN,downY,A4_X-RMARGIN,downY);
674 #define DRAWTEXT(a,b,c) \
677 #define DRAWTEXTBOX(a,b,c,d,s) \
678 p->drawText(a,b,c,d,Qt::AlignLeft | BREAKPOLICY,s);
680 #define DRAWLINE(a,b,c,d) \
681 p->drawLine(a,b,c,d);
683 #define DRAWRECT(a,b,c,d) \
684 p->drawRect(a,b,c,d);
686 int HPrintTable::drawPlainDataMatrix(QPainter *p,
bool print)
691 int downX=LMARGIN,downY=TMARGIN;
696 slist =
new QStringList();
704 if(print || (!print && !hide ))
710 DRAWTEXT(LMARGIN + 20,TMARGIN+20,(
711 data->
getTitle().isEmpty() ?
"Printed page" : data->
getTitle()) + QString(
"(%1)").arg(pagerun));
714 for(i=0;i < column;++i)
716 DRAWTEXTBOX(downX+CELLHMARGIN,downY+CELLVMARGIN,cellw[i],cellh,data->
getHeaderItem(i));
728 for(i=0;i<column;++i)
730 DRAWTEXTBOX(downX+CELLHMARGIN,downY+CELLVMARGIN,cellw[i],cellrh[rowrun],(*slist)[i]);
739 downY += 35 + 2 + cellh;
744 downY += cellrh[rowrun];
747 if(downY >= A4_Y - (TMARGIN+BMARGIN))
764 int HPrintTable::drawList(QPainter *p,
bool print)
768 int downX=LMARGIN,downY=TMARGIN;
777 QList<QStringList *>::Iterator iv = data->
getValues()->begin();
780 if(print || (!print && !hide ))
786 DRAWTEXT(LMARGIN + 20,TMARGIN+20,(
787 data->
tableTitle ().isEmpty() ?
"Printed page" : data->
tableTitle ())+QString(
"(%1)").arg(pagerun));
790 for(i=0;i < column;++i)
792 DRAWTEXTBOX(downX+CELLHMARGIN,downY+CELLVMARGIN,cellw[i],cellh,(*data)[i]);
804 for(i=0;i<column;++i)
806 DRAWTEXTBOX(downX+CELLHMARGIN,downY+CELLVMARGIN,cellw[i],cellrh[rowrun],(*slist)[i]);
815 downY += 35 + 2 + cellh;
820 downY += cellrh[rowrun];
823 if(downY >= A4_Y - (TMARGIN+BMARGIN))
838 int HPrintTable::drawTable(QPainter *p,
bool print)
841 int downX=LMARGIN,downY=TMARGIN;
848 DRAWTEXT(LMARGIN + 20,TMARGIN+20,(
849 data->
tableTitle ().isEmpty() ?
"Printed page" : data->
tableTitle ())+QString(
"(%1)").arg(pagerun));
862 DRAWTEXTBOX(downX+CELLHMARGIN,downY+CELLVMARGIN,
870 DRAWLINE(downX,downY-2,downX,downY+cellh);
871 DRAWTEXTBOX(downX+CELLHMARGIN,downY+CELLVMARGIN,
884 int HPrintTable::printIt(
void)
888 sdebug(
"*** HPrintTable::printIt ***");
889 printer =
new QPrinter();
890 printer->setPageSize(QPrinter::A4);
891 QPrintDialog psdialog(printer,
this);
904 int HPrintTable::updateDisplay(
void)
HDataField * nextFieldAll(void)
HPrintTable(QWidget *parent, HBase *d, QFont *pf=NULL)
HPtintTable //////////////////////////////////////////////////////////////.
int getColumnPrintMaxWidth(int col)
HPreviewFrame(HPrintTable *p, QWidget *parent)
PreviewTable ///////////////////////////////////////////////////////////////.
HDataField * fieldByIndex(int i, bool all=false)
bool isPrintCellWrap(void)
virtual QList< QStringList * > * getValues(void)
QString getHeaderItem(int col)
QList< QString > currentRowStr(void)
virtual QVariant dbValueToDispValue(QVariant v)
QString getExplainText(void)
int getPrintCellWidth(void)
virtual QVariant getValue(void)
bool getColumnPrintWrap(int col)