kwrite widget- better performance
Dave Robbins
dmrobbin at mindspring.com
Wed Nov 3 03:03:37 GMT 1999
Hi
I tried this and it works great.
I view kdevelop via a remote x-server and before scrolling was very jagged.
Now everthing is smooth.
Thanks
Dave
Vladimir Dvorak wrote:
> Hi all,
> I have used a modified text-drawing function in kwrite widget
> for some time. It looks much better especially on remote X-server.
> Let's try to change ./kdevelop/kwrite/kwdoc.cpp :
>
> ////////////////////////////////////////////////////////////////////////
> void
> KWriteDoc::paintTextLine(QPainter &paint, int line, int xStart, int xEnd)
> {
> int y;
> TextLine *textLine;
> int z, x;
> char ch;
> Attribute *a = 0L;
> int attr, nextAttr;
> int xs;
> int xc, zc;
> static char aLB[256];
> int aCnt, xcp;
>
> y = 0;//line*fontHeight - yPos;
> if (line >= (int) contents.count()) {
> paint.fillRect(0,y,xEnd - xStart,fontHeight,colors[4]);
> return;
> }
> //printf("xStart = %d, xEnd = %d, line = %d\n",xStart,xEnd,line);
> //printf("text = ");
> textLine = contents.at(line);
>
> z = 0;
> x = 0;
> do {
> xc = x;
> ch = textLine->getChar(z);
> if (ch == '\t') {
> x += tabWidth - (x % tabWidth);
> } else {
> a = &attribs[textLine->getAttr(z)];
> x += a->fm.width(&ch,1);
> }
> z++;
> } while (x <= xStart);
> zc = z - 1;
>
> xs = xStart;
> attr = textLine->getRawAttr(zc);
> while (x < xEnd) {
> nextAttr = textLine->getRawAttr(z);
> if ((nextAttr ^ attr) & (taSelectMask | 256)) {
> paint.fillRect(xs - xStart,y,x - xs,fontHeight,colors[attr >> taShift]);
> xs = x;
> attr = nextAttr;
> }
> ch = textLine->getChar(z);
> if (ch == '\t') {
> x += tabWidth - (x % tabWidth);
> } else {
> a = &attribs[attr & taAttrMask];
> x += a->fm.width(&ch,1);
> }
> z++;
> }
>
> paint.fillRect(xs - xStart,y,xEnd - xs,fontHeight,colors[attr >> taShift]);
>
> y += fontAscent -1;
> attr = -1;
> aCnt = 0;
> xcp = xc;
>
> while (xc < xEnd) {
> ch = textLine->getChar(zc);
>
> if (ch == '\t') {
> xc += tabWidth - (xc % tabWidth);
> if(aCnt!=0) {
> paint.drawText(xcp - xStart,y,aLB,aCnt);
> aCnt = 0;
> }
> xcp = xc;
> }
>
> else {
> nextAttr = textLine->getRawAttr(zc);
> if (nextAttr != attr) {
>
> if(aCnt!=0) {
> paint.drawText(xcp - xStart,y,aLB,aCnt);
> aCnt = 0;
> xcp = xc;
> }
>
> attr = nextAttr;
> a = &attribs[attr & taAttrMask];
> if (attr & taSelectMask) paint.setPen(a->selCol); else paint.setPen(a->col);
> paint.setFont(a->font);
> }
>
> aLB[aCnt++] = ch;
> xc += a->fm.width(&ch,1);
>
> if(aCnt == 256) {
> paint.drawText(xcp - xStart,y,aLB,aCnt);
> aCnt = 0;
> xcp = xc;
> }
>
> }
> zc++;
> }
>
> if(aCnt!=0) {
> paint.drawText(xcp - xStart,y,aLB,aCnt);
> aCnt = 0;
> xcp = xc;
> }
> //printf("\n");
> }
>
> //////////////////////////////////////////////////////////////////////////
More information about the KDevelop
mailing list