Esempio n. 1
0
// repaint cells that have been changed from previous generation
void Pstable::repaint_changed()
{
    int rows = procview->procs.size();
    int cols = procview->cats.size();
    int left = leftCell(), right = lastColVisible();
    int top = topCell(), bottom = lastRowVisible();
    if(right >= cols) right = cols - 1;
    if(bottom >= rows) bottom = rows - 1;
    int far_right = right;
    if(leftmostchanged != -1 && right >= leftmostchanged)
	right = leftmostchanged - 1;
    for(int c = right + 1; c <= far_right; c++)
	updateHeading(c);
    for(int r = top; r <= bottom; r++) {
	for(int c = left; c <= right; c++) {
	    Category *cat = procview->cats[c];
	    Procinfo *p = procview->procs[r], *op = 0;
	    if(r >= procview->old_procs.size()
	       || (op = procview->old_procs[r], cat->compare(p, op) != 0)
	       || p->selected != op->selected) {
		updateCell(r, c);
	    }
	}
	// update all cells that have moved or changed width
	for(int c = right + 1; c <= far_right; c++)
	    updateCell(r, c);
    }
    if(leftmostchanged != -1)
	clearRight();
}
Esempio n. 2
0
bool TableHead::isCellChanged(int row, int col)
{
    int xpos;
    int ypos;
    int w;
    int fold, dep;
    QString str;
    bool sorted = (htable->sortedCol() == col);

    w = htable->max_widths[col];
    xpos = htable->colXPos(col);

    {
        str = htable->title(col);
    }
    // int left = leftCell();
    // int top	 = topCell();
    CellAttribute *attr = tablecache.value(row - topCell(), col - leftCell());

    if (attr == NULL) // Uninitialed?
    {
        return true;
    }
    else
    {
        bool result = false;
        if (attr->text == str and attr->sorted == sorted and
            attr->size == tmp_size and attr->xpos == xpos
            //	and attr->w==w
            )
        {
            return false;
        }
        else
        {
            attr->text = str;
            attr->sorted = sorted;
            attr->xpos = xpos;
            //		attr->w=w;
            attr->size = tmp_size;
            //			if(head)	printf("head
            // true");
            return true;
        }
        // printf("return  %s x=%d\n",str.toAscii().data(),xpos);
    }
}
Esempio n. 3
0
// DRAFT CODE !!  BOTTLENECK !!!
// Description : draw a cell of table
// 		1. draw the background of a cell
// 		2. draw the text of a cell
//
// called by
// 		1.QtTableView::paintEvent()
void TableBody::paintCell(QPainter *p, int row, int col, bool use_cache)
{
    // *** sequence important !!!
    //	if(isCellChanged(row,col)==false)	{
    // if(use_cache==true)	return;
    //}

    CellAttribute *attr =
        tablecache.value(row - topCell(), col - leftCell()); // save cache
    //	isCellChanged(row,col);

    bool sort;
    int h = cellHeight();
    int w = htable->max_widths[col];
    attr->w = w; //

    QColor baseColor = palette().brush(QPalette::Base).color();
    sort = (col == htable->sorted_col);
    attr->sorted = sort;

    // gridline
    QColor lineColor, textColor;
    QColor altColor = palette().brush(QPalette::AlternateBase).color();
    lineColor.setRgb((baseColor.red() * 0.5 + altColor.red() * 0.5),
                     (baseColor.green() * 0.4 + altColor.green() * 0.6),
                     (baseColor.blue() * 0.4 + altColor.blue() * 0.6));

    //	QStyleOption opt;
    //	opt.rect=QRect(0,0,w,h-1);
    //	opt.state = QStyle::State_Active; //?
    // QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea
    //  const int gridHint =
    //  style()->styleHint(QStyle::SH_Table_GridLineColor,
    //  &opt, this);

    p->setPen(lineColor);
    p->drawLine(0, h - 1, w, h - 1);

    // background
    if (htable->isSelected(row))
    {
        p->fillRect(0, 0, w, h - 1, palette().brush(QPalette::Highlight));
        p->setPen(palette().brush(QPalette::HighlightedText).color()); // text
        attr->selected = true;
    }
    else
    {
        attr->selected = false;
        if (sort)
        {
            p->fillRect(0, 0, w, h - 1, lineColor.dark(101));
        }
        else
        {
            p->fillRect(0, 0, w, h - 1, baseColor);
        }
        // style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p,
        // this);
        p->setPen(palette().brush(QPalette::Text).color()); // text
    }

    // tree gadget , treestep=height
    int gap = h / 4;
    int testFlag = 0;
    if (col == 0 and htable->treemode == true)
    {
        QStyleOption opt;
        int d = htable->rowDepth(row);
        attr->depth = d; //**
        int treestep = htable->treestep;
        if (true /*lines*/)
        {
            /// int dx = folding ? gadget_space : 6;
            for (int level = d, prow = row; level >= 0 and prow >= 0;
                 level--, prow = htable->parentRow(prow))
            {
                if (level == d)
                    continue;
                int x = gap + level * treestep;
                QRect branchR(x, 0, treestep, h);
                opt.rect = branchR;

                if (htable->lastChild(prow) == false)
                {
                    if (testFlag)
                    {
                        p->drawLine(x + treestep / 2, 0, x + treestep / 2, h);
                    }
                    else
                    {
                        opt.state = QStyle::State_Sibling; // | vertical
                                                           // line
                        style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt,
                                               p, this);
                    }
                }
            }

            QRect branchR(gap + d * treestep, 0, treestep, h);
            opt.rect = branchR;
            if (testFlag)
            {
                int x = gap + d * treestep + treestep / 2;

                p->drawLine(x, h / 2, x + treestep / 2, h / 2);
                if (!htable->lastChild(row))
                {
                    p->drawLine(x, 0, x, h);
                }
                else
                {
                    p->drawLine(x, 0, x, h / 2);
                }
            }
            else
            {
                opt.state = QStyle::State_Item; //?
                if (!htable->lastChild(row))
                    opt.state = opt.state | QStyle::State_Sibling; // |
            }
            attr->lastchild = htable->lastChild(row);
        }

        if (true /*folding*/)
        {
            HeadedTable::NodeState fs = htable->folded(row);
            attr->folded = fs; //**
            if (fs != HeadedTable::Leaf)
            {
                opt.state = opt.state | QStyle::State_Children;
                if (fs != HeadedTable::Closed)
                    opt.state = opt.state | QStyle::State_Open;
            }
            p->save(); // temp , save pencolor
            style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, p, this);
            p->restore();
        }
        gap = htable->gadget_space + d * treestep + 1;
    }

    // virtual int Pstable::alignment(int col)
    if (htable->alignment_col[col] == Qt::AlignRight) // using cache
    {
        w -= gap;
        gap = 0;
    }
    // Qt::IncludeTrailingSpaces
    // p->drawText(gap, 0, w , h, Qt::TextIncludeTrailingSpace |
    // Qt::IncludeTrailingSpaces | Qt::AlignVCenter |
    // htable->alignment_col[col],htable->text(row,col));
    // p->drawText(gap, 0, w , h, Qt::TextIncludeTrailingSpace |
    // Qt::AlignVCenter
    // | htable->alignment_col[col],htable->text(row,col));
    p->drawText(gap, 0, w, h, Qt::AlignVCenter | htable->alignment_col[col],
                htable->text(row, col));

    htable->overpaintCell(p, row, col, gap);

    // cache write!
    // attr->xpos=tmp_x ;
    attr->text = htable->text(row, col);
    attr->xpos = htable->colXPos(col);
    attr->size = tmp_size;
}
Esempio n. 4
0
// new, possible COMMON?
bool TableBody::isCellChanged(int row, int col)
{
    QString str;
    int xpos;
    int fold, dep;
    bool selected;
    bool sorted;
    int lc;
    int width;

    {
        str = htable->text(row, col);
        xpos = htable->colXPos(col);
        selected = htable->isSelected(row);
        sorted = (htable->sortedCol() == col);
        width = htable->max_widths[col];
    }

    // int left = leftCell(), top = topCell();
    CellAttribute *attr = tablecache.value(row - topCell(), col - leftCell());

    if (attr == NULL) // never NULL
    {
        return true;
    }
    else
    {
        bool result = false;
        if (attr->text == str and attr->selected == selected and
            attr->sorted == sorted and attr->xpos == xpos and attr->w == width
            // and attr->size==tmp_size
            and
            (attr->size.height() >= tmp_size.height())
            //	and (attr->size.width()>=tmp_size.width())
            )
        {
            result = false;
        }
        else
        {
            //	attr->text=str;
            //	attr->selected=selected;
            //	attr->sorted=sorted;
            //	attr->xpos=xpos;
            //	attr->size=tmp_size;
            //	attr->w=width;

            //	if (row==29 and col==0)
            //	printf("(%d %d) xpos=%d %d sorted=%d %d sel=%d
            //%d str=%s
            //%s\n",attr->size.height(),tmp_size.height(),
            //			attr->xpos,xpos,attr->sorted,sorted,attr->selected,selected
            //			,qPrintable(attr->text),qPrintable(str));
            //	printf("true (%d
            //%d)\n",row-topCell(),col-leftCell());
            return true;
        }

        if (col == 0)
        {
            dep = htable->rowDepth(row); // folding_level
            fold = htable->folded(row);
            lc = htable->lastChild(row);

            if (attr->depth == dep /* Uninitial*/
                and attr->folded == fold and attr->lastchild == lc)
            {
                // false
            }
            else
            {
                //	attr->depth=dep;
                //	attr->folded=fold;
                result = true;
                //	printf("true (%d
                //%d)\n",row-topCell(),col-leftCell());
            }
        }
        return result;
    }
}