Exemple #1
0
int
main(int argc, char *argv[])
{
	int i;
	DataTh *dt;
	pthread_t thr[maxArgs];
	void *sts[maxArgs];
	int posPix;

	posPix = posMap;
	i = 0;
	dt = malloc(sizeof(DataTh));

	checkArgs(argc,argv);
	if(strcmp(argv[1],"-p") == 0){
		printPixmap(argv[posPix+1]);
		exit(EXIT_SUCCESS);
	}

	(*dt).map = malloc(strlen(argv[posPix]));
	strcpy((*dt).map,argv[posPix]);
	fprintf(stdout, "-------------------- bigrams ---------------------\n");
	createPixmap(argv[posPix],asciiRange*asciiRange);
	for(i=posPix+1; i < argc; i++){
		pthread_mutex_lock(&dt->lock);
		(*dt).file = malloc(strlen(argv[i]));
		strcpy((*dt).file,argv[i]);
		if(pthread_create(thr+i, NULL, tPF, dt) != 0) {
			err(1, "thread");
		}
	}
	for(i = posPix+1; i < argc; i++) {
		pthread_join(thr[i], sts+i);
		free(sts[i]);
	}

	exit(EXIT_SUCCESS);
}
void printerStream::printQTable(QTableView *tbl, bool left_margin,
                                bool top_margin)
{
    if (fwbdebug)
    {
        qDebug("printQTable ----------------------------------------------");
        qDebug("Size: %dx%d", tbl->width(), tbl->height());
//        qDebug("Visible: %dx%d",
//               tbl->contentsRect().width(), tbl->contentsRect().height());
//        qDebug("Viewport: %dx%d",
//               tbl->viewport()->width(), tbl->viewport()->height());
//        qDebug("pageBody.height(): %d", pageBody.height());
        qDebug("YSpace: %d", getYSpace());
        qDebug("yPos: %d", yPos);
    }

    int top_row = 0;
    int bottom_row = 1;

    int columnsWidth = 0;
    int i = 0;
    while (i < tbl->model()->columnCount())
    {
        columnsWidth += tbl->columnWidth(i);
        i++;
    }

    int rowCount = tbl->model()->rowCount();
    while (top_row <= (rowCount-1))
    {
        int row = 0;

        int tblHeight = (int)(
            (float)(tbl->horizontalHeader()->height()) * pixmap_scaling_ratio);

        /* ===================================================================
         * Row height is screen pixels, getYSpace returns remaining
         * space in printer resolution units. Keep track of both to
         * resize pixmap
         * ===================================================================
         */
        int pixMapHeight = tbl->horizontalHeader()->height();
        for (row=top_row; row < rowCount; ++row)
        {
            if (tbl->isRowHidden(row))
            {
                // hidden rows count but do not contribute to table height
                continue;
            }

            int nth = tblHeight +
                (int)((float)(tbl->rowHeight(row)) * pixmap_scaling_ratio);

            if ( nth==getYSpace() )  break;

            if ( nth>getYSpace() ) 
            { 
                row--; 
                break; 
            }

            tblHeight = nth;
            pixMapHeight += tbl->rowHeight(row);
        }
        
        // if row < top_row then even single row does not fit on the page
        if (row < top_row)
        {
            row = top_row;
            pixMapHeight = tbl->rowHeight(top_row);
        }

        if (row == rowCount) row--;

        bottom_row = row;

        int left_hdr_w = 0;
        if (left_margin && tbl->verticalHeader() != NULL)
            left_hdr_w = tbl->verticalHeader()->width();

        int top_hdr_h = 0;
        if (top_margin && tbl->horizontalHeader() != NULL)
            top_hdr_h = tbl->horizontalHeader()->height();

        int tblWidth = columnsWidth + left_hdr_w;

        if (fwbdebug)
            qDebug("Page %d -- (%d-%d of %d rows) tblWidth: %d   tblHeight: %d",
                   pageNo, top_row, bottom_row, rowCount, tblWidth, tblHeight);

        tbl->resize(tblWidth, pixMapHeight);

        tbl->verticalHeader()->resize(
            tbl->verticalHeader()->width(),
            tbl->height() - tbl->horizontalHeader()->height());
        tbl->horizontalHeader()->resize(
            tbl->width() - tbl->verticalHeader()->width(),
            tbl->horizontalHeader()->height());


// QTableView::scrollTo() makes row visible, but if there are not enough
// rows below it, it appears in the middle of the table. This means the table
// shows few rows that belong on the previous page, which is bad.
//
//        tbl->scrollTo(tbl->model()->index(top_row, 0),
//                      QAbstractItemView::PositionAtTop);

        int top_row_position = tbl->verticalHeader()->sectionPosition(top_row);
        tbl->verticalHeader()->setOffset(top_row_position);

        tbl->update();


        printPixmap(QPixmap::grabWidget(tbl));  //,0,0,-1,pixMapHeight));

        if (bottom_row>=(rowCount-1)) break;

        flushPage();
        beginPage();

        top_row = bottom_row + 1;

    }
}
void printerStream::printRuleSetView(RuleSetView *tbl, bool top_margin)
{
    if (fwbdebug)
    {
        qDebug("printQTable ----------------------------------------------");
        qDebug("Size: %dx%d", tbl->width(), tbl->height());
        qDebug("YSpace: %d", getYSpace());
        qDebug("yPos: %d", yPos);
    }

    int columnsWidth = 0;
    int i = 0;

    while (i < tbl->model()->columnCount())
    {
        columnsWidth += tbl->columnWidth(i);
        i++;
    }

    RuleSetModelIterator it = ((RuleSetModel*)tbl->model())->begin();
    RuleSetModelIterator end = ((RuleSetModel*)tbl->model())->end();

    RuleSetModelIterator bottomIt;

    while (it.isValid() && it != end)
    {
        // Pages iterations

        int tblHeight = (int)(
            (float)(tbl->header()->height()) * pixmap_scaling_ratio);

        /* ===================================================================
         * Row height is screen pixels, getYSpace returns remaining
         * space in printer resolution units. Keep track of both to
         * resize pixmap
         * ===================================================================
         */
        int pixMapHeight = tbl->header()->height();


        RuleSetModelIterator pit = it;
        while (pit != end)
        {

            // Check if current index is collapsed
            QModelIndex index = pit.index();
            QModelIndex parent = index.parent();
            if (!parent.isValid() || tbl->isExpanded(parent))
            {

                int nth = tblHeight +
                    (int)((float)(tbl->rowHeight(index)) * pixmap_scaling_ratio);

                if ( nth==getYSpace() )  break;

                if ( nth>getYSpace() )
                {
                    // if it == pit then even single row does not fit on the page
                    if (it == pit)
                    {
                        pixMapHeight = tbl->rowHeight(index);
                    } else
                    {
                        --pit;
                    }
                    break;
                }

                tblHeight = nth;
                pixMapHeight += tbl->rowHeight(index);
            }

            ++pit;
        }

        bottomIt = pit;

        int left_hdr_w = 0;

        int top_hdr_h = 0;
        if (top_margin && tbl->header() != NULL)
            top_hdr_h = tbl->header()->height();

        int tblWidth = columnsWidth + left_hdr_w;


            qDebug("Page %d -- tblWidth: %d   tblHeight: %d",
                   pageNo, tblWidth, tblHeight);

        tbl->resize(tblWidth, pixMapHeight);
        tbl->updateWidget();

        tbl->scrollTo(it.index(), QAbstractItemView::PositionAtTop);

        printPixmap(QPixmap::grabWidget(tbl));

        if (bottomIt == end) break;

        flushPage();
        beginPage();

        it = bottomIt;
        ++it;
    }
}