tallforasmurf / PPQT

A post-processing tool for PGDP written in Python, PyQt4, and Qt
GNU General Public License v3.0
4 stars 2 forks source link

center text when using find next/prior/... #105

Closed bibimbop closed 11 years ago

bibimbop commented 11 years ago

For some kind of searches, it's useful to have the line containing the text found to always be on the same location on the edit window (usually at the center of it). That way the searched item doesn't jump all over the place in the window when clicking on next/prior/... It's easier on the eyes.

It's how guiguts and many editors work. This also could be an option.

tallforasmurf commented 11 years ago

Yeah, if I knew how to do it, I'd a did it. Something in QPlainTextEdit or QTextBlock or somewhere. I'll look into it soon.

tallforasmurf commented 11 years ago

QTextEdit.cursorRect() returns the viewport coordinates of the cursor's selected text as a QRect QTextEdit inherits from QAbstractScrollArea QTextEdit (via QAbstractScrollArea) .viewport returns the viewport (a QWidget) thus editWidget.viewport().size().height() returns the height of the viewport --in what units? Same units as the cursorRect anyway -- so editWidget.cursorRect().x() is the top edge of the cursor text -- this can be related to the viewport height/2 -- if greater, need to scroll down to bring text up

QAbstractScrollArea.verticalScrollBar() returns the QScrollBar for the vertical. (Will there be one when the doc is less than a page? prob. returns null: check) If there is no scrollbar -- or if it is already at its maximum (QScrollBar.maximum()) -- do nothing. QScrollBar.value() returns the absolute value of the scrollbar (in what units? pixels? lines?) QScrollBar.setValue( previous value + adjustment ) should move the document...

tallforasmurf commented 11 years ago

Major drawback: the cursorRect() does not give the size of the selected text, but only the size and position of the cursor (insertion point) itself. So its height is always 11 (if the font size is 11) and you cannot tell what the height of the complete selectioin is.

Also not good: the position is of the logical cursor position, which on a large multiline selection, may well be the END of the selection not the beginning.

Additional problem: the scrollBar.value is in logical line units, not pixel units like the cursorRect is.

tallforasmurf commented 11 years ago

Commit 69c28cc