Hello,
I am using inherited class from QPlainTextEdit,
modifications are line numbering and inclusion of QCompleter only
Now I want to make some code folding,
for start, I just want to make text folding working, before mixing it up with grammar
so my problem is, when I fold some lines, using cursor keys in text is relatively ok
problem is horizontal scroll bar (visible scroll bar, or mouse middle wheel)
when I am scrolling up (towards line 0), and I am scrolling through hidden lines,
they are somewhat included, so each click up, all lines scroll one down (wrong), and in place of hidden line, is last visible top line (so doubled now),
when I move cursor through incorrectly moved lines, they (?refresh) to what they should be, I solved this by calling
update(); // which calls lineAreaUpdate + viewport()->update();
so no more rubbish scrolling,
now you are "dud" clicking arrow up, till you skip all hidden lines, and then it scrolls,
annoying, but let us say tolerable
another problem (this post related) is moments when I hide or show lines,
if all lines are visible (no scroll bar needed), because some are hidden, and I unhide them, scrollbar WILL NOT APPEAR,
adding empty lines, will make scroll bar to appear, but only to length of added lines (some lines still inaccessible),
using arrow keys will move cursor on inaccessible lines, but textedit will not scroll (therefore relatively ok), so you can't see them,
problem solving events are:
- resize window VERTICALY (horizontaly WILL NOT help)
- maximize/restore window state
- backspace out one line
QPlainTextEdit inherited widget is being resized with window,
also setPlainText(toPlainText); solve the problem
so my first question, which event to call, to FORCE scrollbars to refresh their (?state, ?linesCounting),
second is, what else is wrong and how to correct it (not by using other widgets, I think this is almost done and need only small repair)
PS: on events when scrollbar (horizontal) correctly resizes, scrolling is working as supposed (no more dud-clicking), therefore I think calling right updateLikeMethodOnScrollsBar could resolve all problems
here are some sources,
lineTextEdit is inherited from QPlainTextEdit
line numbering, correct on folding when update called
// process all valid blocks
while (block.isValid() && top <= event->rect().bottom())
{
// print number
if (block.isVisible())
painter.
drawText(0, top, lineCntr
->width
(), fontMetrics
().
height(), Qt
::AlignRight,
QString::number(blockNumber
));
// update data
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
// next
++blockNumber;
}
// process all valid blocks
while (block.isValid() && top <= event->rect().bottom())
{
// print number
if (block.isVisible())
painter.drawText(0, top, lineCntr->width(), fontMetrics().height(), Qt::AlignRight, QString::number(blockNumber));
// update data
block = block.next();
top = bottom;
bottom = top + (int) blockBoundingRect(block).height();
// next
++blockNumber;
}
To copy to clipboard, switch view to plain text mode
code colapsing method
/// manager of code collapsing
void lineTextEdit::blockMaster()
{
// acquire first block
// default visibility depth
int depth(0);
// process all blocks
while (block.isValid())
{
// set visibility
block.setVisible(!depth);
// conditions
if (block.text().left(5) == ";HIDE")
++depth;
else if (depth && block.text().left(5) == ";SHOW")
{
--depth;
block.setVisible(!depth);
}
// next block
block = block.next();
}
// update
this->viewport()->update();//////// part of lineCntr->update (not directly, but DO IS called)
this->lineCntr->update();//////// currently connected on updateRequest()
update();
}
/// manager of code collapsing
void lineTextEdit::blockMaster()
{
// acquire first block
QTextBlock block(firstVisibleBlock());
// default visibility depth
int depth(0);
// process all blocks
while (block.isValid())
{
// set visibility
block.setVisible(!depth);
// conditions
if (block.text().left(5) == ";HIDE")
++depth;
else if (depth && block.text().left(5) == ";SHOW")
{
--depth;
block.setVisible(!depth);
}
// next block
block = block.next();
}
// update
this->viewport()->update();//////// part of lineCntr->update (not directly, but DO IS called)
this->lineCntr->update();//////// currently connected on updateRequest()
update();
}
To copy to clipboard, switch view to plain text mode
PS: I do not care about point&click hide/show arrows till this manager is not working properly, this is easier for me to test
Bookmarks