Qt 4.8
Public Functions | Public Variables | List of all members
QPlainTextEditPrivate Class Reference

#include <qplaintextedit_p.h>

Inheritance diagram for QPlainTextEditPrivate:
QAbstractScrollAreaPrivate QFramePrivate QWidgetPrivate QObjectPrivate QObjectData

Public Functions

void _q_adjustScrollbars ()
 
void _q_cursorPositionChanged ()
 
void _q_modificationChanged (bool)
 
void _q_repaintContents (const QRectF &contentsRect)
 
void _q_verticalScrollbarActionTriggered (int action)
 
void append (const QString &text, Qt::TextFormat format=Qt::AutoText)
 
void ensureCursorVisible (bool center=false)
 
void ensureViewportLayouted ()
 
void ensureVisible (int position, bool center, bool forceCenter=false)
 
int horizontalOffset () const
 
void init (const QString &txt=QString())
 
QPoint mapToContents (const QPoint &point) const
 
void pageUpDown (QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor=true)
 
 QPlainTextEditPrivate ()
 
void relayoutDocument ()
 
void sendControlEvent (QEvent *e)
 
void setTopBlock (int newTopBlock, int newTopLine, int dx=0)
 
void setTopLine (int visualTopLine, int dx=0)
 
void updateDefaultTextOption ()
 
void updateViewport ()
 
qreal verticalOffset (int topBlock, int topLine) const
 
qreal verticalOffset () const
 
- Public Functions inherited from QAbstractScrollAreaPrivate
void _q_hslide (int)
 
void _q_showOrHideScrollBars ()
 
void _q_vslide (int)
 
virtual QPoint contentsOffset () const
 
void init ()
 
void layoutChildren ()
 
 QAbstractScrollAreaPrivate ()
 
void replaceScrollBar (QScrollBar *scrollBar, Qt::Orientation orientation)
 
virtual void scrollBarPolicyChanged (Qt::Orientation, Qt::ScrollBarPolicy)
 
void setSingleFingerPanEnabled (bool on=true)
 
bool viewportEvent (QEvent *event)
 
- Public Functions inherited from QFramePrivate
void init ()
 
 QFramePrivate ()
 
void updateFrameWidth ()
 Updated the frameWidth parameter. More...
 
void updateStyledFrameWidths ()
 Updates the frame widths from the style. More...
 
- Public Functions inherited from QWidgetPrivate
void _q_showIfNotHidden ()
 
virtual void aboutToDestroy ()
 
void activateChildLayoutsRecursively ()
 
QSize adjustedSize () const
 
void adjustQuitOnCloseAttribute ()
 
QInputContextassignedInputContext () const
 
QPainterbeginSharedPainter ()
 
QWidgetchildAt_helper (const QPoint &, bool) const
 
QWidgetchildAtRecursiveHelper (const QPoint &p, bool, bool includeFrame=false) const
 
QRect clipRect () const
 
QRegion clipRegion () const
 
void clipToEffectiveMask (QRegion &region) const
 
bool close_helper (CloseMode mode)
 
void create_sys (WId window, bool initializeWindow, bool destroyOldWindow)
 
QWindowSurfacecreateDefaultWindowSurface ()
 
QWindowSurfacecreateDefaultWindowSurface_sys ()
 
void createExtra ()
 Creates the widget extra data. More...
 
void createRecursively ()
 
void createSysExtra ()
 
void createTLExtra ()
 
void createTLSysExtra ()
 
void createWinId (WId id=0)
 
void deactivateWidgetCleanup ()
 
void deleteExtra ()
 Deletes the widget extra data. More...
 
void deleteSysExtra ()
 
void deleteTLSysExtra ()
 
void drawWidget (QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter=0, QWidgetBackingStore *backingStore=0)
 
QWidgeteffectiveFocusWidget ()
 
QRect effectiveRectFor (const QRect &rect) const
 
bool endSharedPainter ()
 
void enforceNativeChildren ()
 
QWExtraextraData () const
 
QRect frameStrut () const
 
void getLayoutItemMargins (int *left, int *top, int *right, int *bottom) const
 
const QRegiongetOpaqueChildren () const
 
void handleSoftwareInputPanel (Qt::MouseButton button, bool clickCausedFocus)
 
virtual bool hasHeightForWidth () const
 
void hide_helper ()
 
void hide_sys ()
 Platform-specific part of QWidget::hide(). More...
 
void hideChildren (bool spontaneous)
 
void inheritStyle ()
 
void init (QWidget *desktopWidget, Qt::WindowFlags f)
 
QInputContextinputContext () const
 
void invalidateBuffer (const QRegion &)
 Invalidates the rgn (in widget's coordinates) of the backing store, i.e. More...
 
void invalidateBuffer (const QRect &)
 This function is equivalent to calling invalidateBuffer(QRegion(rect), ...), but is more efficient as it eliminates QRegion operations/allocations and can use the rect more precisely for additional cut-offs. More...
 
void invalidateBuffer_resizeHelper (const QPoint &oldPos, const QSize &oldSize)
 Invalidates the buffer when the widget is resized. More...
 
void invalidateGraphicsEffectsRecursively ()
 
bool isAboutToShow () const
 
bool isBackgroundInherited () const
 
bool isOverlapped (const QRect &) const
 
void lower_sys ()
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QWidgetBackingStoremaybeBackingStore () const
 
QTLWExtramaybeTopData () const
 
void moveRect (const QRect &, int dx, int dy)
 
bool nativeChildrenForced () const
 
QFont naturalWidgetFont (uint inheritedMask) const
 
QPalette naturalWidgetPalette (uint inheritedMask) const
 Returns the palette that the widget w inherits from its ancestors and QApplication::palette. More...
 
void paintBackground (QPainter *, const QRegion &, int flags=DrawAsRoot) const
 
bool paintOnScreen () const
 
void paintSiblingsRecursive (QPaintDevice *pdev, const QObjectList &children, int index, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter, QWidgetBackingStore *backingStore)
 
bool pointInsideRectAndMask (const QPoint &) const
 
QRegion prepareToRender (const QRegion &region, QWidget::RenderFlags renderFlags)
 
void propagatePaletteChange ()
 Propagate this widget's palette to all children, except style sheet widgets, and windows that don't enable window propagation (palettes don't normally propagate to windows). More...
 
 QWidgetPrivate (int version=QObjectPrivateVersion)
 
void raise_sys ()
 
QPaintDeviceredirected (QPoint *offset) const
 
void registerDropSite (bool)
 
void render (QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags, bool readyToRender)
 
void render_helper (QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
 
void repaint_sys (const QRegion &rgn)
 
void reparentFocusWidgets (QWidget *oldtlw)
 
void resolveFont ()
 Determine which font is implicitly imposed on this widget by its ancestors and QApplication::font, resolve this against its own font (attributes from the implicit font are copied over). More...
 
void resolveLayoutDirection ()
 
void resolveLocale ()
 
void resolvePalette ()
 Determine which palette is inherited from this widget's ancestors and QApplication::palette, resolve this against this widget's palette (attributes from the inherited palette are copied over this widget's palette). More...
 
void restoreRedirected ()
 
void scroll_sys (int dx, int dy)
 
void scroll_sys (int dx, int dy, const QRect &r)
 
void scrollChildren (int dx, int dy)
 
void scrollRect (const QRect &, int dx, int dy)
 
void sendPendingMoveAndResizeEvents (bool recursive=false, bool disableUpdates=false)
 
void sendStartupMessage (const char *message) const
 Platform-specific part of QWidget::show(). More...
 
void setConstraints_sys ()
 
void setCursor_sys (const QCursor &cursor)
 
void setDirtyOpaqueRegion ()
 
void setEnabled_helper (bool)
 
void setFocus_sys ()
 
void setFont_helper (const QFont &font)
 
void setGeometry_sys (int, int, int, int, bool)
 
void setLayoutDirection_helper (Qt::LayoutDirection)
 
void setLayoutItemMargins (int left, int top, int right, int bottom)
 
void setLayoutItemMargins (QStyle::SubElement element, const QStyleOption *opt=0)
 
void setLocale_helper (const QLocale &l, bool forceUpdate=false)
 
void setMask_sys (const QRegion &)
 
bool setMaximumSize_helper (int &maxw, int &maxh)
 
bool setMinimumSize_helper (int &minw, int &minh)
 
void setModal_sys ()
 
void setNetWmWindowTypes ()
 
void setOpaque (bool opaque)
 
void setPalette_helper (const QPalette &)
 
void setParent_sys (QWidget *parent, Qt::WindowFlags)
 
void setRedirected (QPaintDevice *replacement, const QPoint &offset)
 
void setSharedPainter (QPainter *painter)
 
void setStyle_helper (QStyle *newStyle, bool propagate, bool metalHack=false)
 
void setUpdatesEnabled_helper (bool)
 
void setWindowFilePath_helper (const QString &filePath)
 
void setWindowIcon_helper ()
 
void setWindowIcon_sys (bool forceReset=false)
 
void setWindowIconText_helper (const QString &cap)
 
void setWindowIconText_sys (const QString &cap)
 
void setWindowOpacity_sys (qreal opacity)
 
void setWindowRole ()
 
void setWindowTitle_helper (const QString &cap)
 
void setWindowTitle_sys (const QString &cap)
 
void setWinId (WId)
 
QPaintersharedPainter () const
 
void show_helper ()
 
void show_recursive ()
 Makes the widget visible in the isVisible() meaning of the word. More...
 
void show_sys ()
 Platform-specific part of QWidget::show(). More...
 
void showChildren (bool spontaneous)
 
void stackUnder_sys (QWidget *)
 
void subtractOpaqueChildren (QRegion &rgn, const QRect &clipRect) const
 
void subtractOpaqueSiblings (QRegion &source, bool *hasDirtySiblingsAbove=0, bool alsoNonOpaque=false) const
 
void syncBackingStore ()
 
void syncBackingStore (const QRegion &region)
 
QTLWExtratopData () const
 
void unsetCursor_sys ()
 
void updateFont (const QFont &)
 Assign font to this widget, and propagate it to all children, except style sheet widgets (handled differently) and windows that don't enable window propagation. More...
 
void updateFrameStrut ()
 Computes the frame rectangle when needed. More...
 
void updateGeometry_helper (bool forceUpdate)
 
void updateIsOpaque ()
 
void updateIsTranslucent ()
 
void updateSystemBackground ()
 
void updateX11AcceptFocus ()
 
void x11UpdateIsOpaque ()
 
 ~QWidgetPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QPoint autoScrollDragPos
 
QBasicTimer autoScrollTimer
 
uint backgroundVisible: 1
 
uint centerOnScroll: 1
 
uint clickCausedFocus: 1
 
QPlainTextEditControlcontrol
 
QPointer< QPlainTextDocumentLayoutdocumentLayoutPtr
 
uint inDrag: 1
 
QPlainTextEdit::LineWrapMode lineWrap
 
int originalOffsetY
 
qreal pageUpDownLastCursorY
 
bool pageUpDownLastCursorYIsValid
 
uint showCursorOnInitialShow: 1
 
bool tabChangesFocus
 
int topLine
 
qreal topLineFracture
 
QTextOption::WrapMode wordWrap
 
- Public Variables inherited from QAbstractScrollAreaPrivate
int bottom
 
QRect cornerPaintingRect
 
QWidgetcornerWidget
 
QScrollBarhbar
 
Qt::ScrollBarPolicy hbarpolicy
 
int left
 
QRect reverseCornerPaintingRect
 
int right
 
QAbstractScrollAreaScrollBarContainerscrollBarContainers [Qt::Vertical+1]
 
bool singleFingerPanEnabled
 
int top
 
QScrollBarvbar
 
Qt::ScrollBarPolicy vbarpolicy
 
QWidgetviewport
 
QScopedPointer< QObjectviewportFilter
 
int xoffset
 
int yoffset
 
- Public Variables inherited from QFramePrivate
short bottomFrameWidth
 
int frameStyle
 
short frameWidth
 
QRect frect
 
short leftFrameWidth
 
short lineWidth
 
short midLineWidth
 
short rightFrameWidth
 
short topFrameWidth
 
- Public Variables inherited from QWidgetPrivate
QString accessibleDescription
 
QString accessibleName
 
QList< QAction * > actions
 
QPalette::ColorRole bg_role: 8
 
signed char bottomLayoutItemMargin
 
short bottommargin
 
QWidgetData data
 
QRegion dirty
 
uint dirtyOpaqueChildren: 1
 
QWExtraextra
 
QPaintEngineextraPaintEngine
 
QPalette::ColorRole fg_role: 8
 
QWidgetfocus_child
 
QWidgetfocus_next
 
QWidgetfocus_prev
 
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
 
QGraphicsEffectgraphicsEffect
 
Qt::HANDLE hd
 
uint high_attributes [4]
 
QPointer< QInputContextic
 
Qt::InputMethodHints imHints
 
uint inDirtyList: 1
 
uint inheritedFontResolveMask
 
uint inheritedPaletteResolveMask
 
uint inheritsInputMethodHints: 1
 
uint inSetParent: 1
 
uint isGLWidget: 1
 
uint isMoved: 1
 
uint isOpaque: 1
 
uint isScrolled: 1
 
QLayoutlayout
 
signed char leftLayoutItemMargin
 
short leftmargin
 
QLocale locale
 
QRegionneedsFlush
 
QRegion opaqueChildren
 
Qt::HANDLE picture
 
const QMetaObjectpolished
 
QPaintDeviceredirectDev
 
QPoint redirectOffset
 
signed char rightLayoutItemMargin
 
short rightmargin
 
QSizePolicy size_policy
 
QString statusTip
 
QString toolTip
 
signed char topLayoutItemMargin
 
short topmargin
 
uint usesDoubleBufferedGLContext: 1
 
QString whatsThis
 
QWidgetItemV2widgetItem
 
QX11Info xinfo
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QWidgetPrivate
enum  CloseMode { CloseNoEvent, CloseWithEvent, CloseWithSpontaneousEvent }
 
enum  Direction { DirectionNorth = 0x01, DirectionEast = 0x10, DirectionSouth = 0x02, DirectionWest = 0x20 }
 
enum  DrawWidgetFlags {
  DrawAsRoot = 0x01, DrawPaintOnScreen = 0x02, DrawRecursive = 0x04, DrawInvisible = 0x08,
  DontSubtractOpaqueChildren = 0x10, DontSetCompositionMode = 0x20, DontDrawOpaqueChildren = 0x40, DontDrawNativeChildren = 0x80
}
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QWidgetPrivate
static void adjustFlags (Qt::WindowFlags &flags, QWidget *w=0)
 
static QGraphicsProxyWidgetnearestGraphicsProxyWidget (const QWidget *origin)
 Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this widget and its ancestors. More...
 
static int pointToRect (const QPoint &p, const QRect &r)
 
static QRect screenGeometry (const QWidget *widget)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 
- Static Public Variables inherited from QWidgetPrivate
static QWidgetSetallWidgets = 0
 
static int instanceCounter = 0
 
static QWidgetkeyboardGrabber = 0
 
static QWidgetMappermapper = 0
 
static int maxInstances = 0
 
static QWidgetmouseGrabber = 0
 

Detailed Description

Definition at line 111 of file qplaintextedit_p.h.

Constructors and Destructors

◆ QPlainTextEditPrivate()

QPlainTextEditPrivate::QPlainTextEditPrivate ( )

Definition at line 747 of file qplaintextedit.cpp.

748  : control(0),
749  tabChangesFocus(false),
754 {
756  backgroundVisible = false;
757  centerOnScroll = false;
758  inDrag = false;
759 }
QTextOption::WrapMode wordWrap
QPlainTextEditControl * control
QPlainTextEdit::LineWrapMode lineWrap

Functions

◆ _q_adjustScrollbars()

void QPlainTextEditPrivate::_q_adjustScrollbars ( )

Definition at line 954 of file qplaintextedit.cpp.

Referenced by init().

955 {
957  QTextDocument *doc = control->document();
959  Q_ASSERT(documentLayout);
960  bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged;
961  documentLayout->priv()->blockDocumentSizeChanged = true;
962  qreal margin = doc->documentMargin();
963 
964  int vmax = 0;
965 
966  int vSliderLength = 0;
967  if (!centerOnScroll && q->isVisible()) {
968  QTextBlock block = doc->lastBlock();
969  const qreal visible = viewport->rect().height() - margin - 1;
970  qreal y = 0;
971  int visibleFromBottom = 0;
972 
973  while (block.isValid()) {
974  if (!block.isVisible()) {
975  block = block.previous();
976  continue;
977  }
978  y += documentLayout->blockBoundingRect(block).height();
979 
980  QTextLayout *layout = block.layout();
981  int layoutLineCount = layout->lineCount();
982  if (y > visible) {
983  int lineNumber = 0;
984  while (lineNumber < layoutLineCount) {
985  QTextLine line = layout->lineAt(lineNumber);
986  const QRectF lr = line.naturalTextRect();
987  if (lr.top() >= y - visible)
988  break;
989  ++lineNumber;
990  }
991  if (lineNumber < layoutLineCount)
992  visibleFromBottom += (layoutLineCount - lineNumber);
993  break;
994 
995  }
996  visibleFromBottom += layoutLineCount;
997  block = block.previous();
998  }
999  vmax = qMax(0, doc->lineCount() - visibleFromBottom);
1000  vSliderLength = visibleFromBottom;
1001 
1002  } else {
1003  vmax = qMax(0, doc->lineCount() - 1);
1004  vSliderLength = viewport->height() / q->fontMetrics().lineSpacing();
1005  }
1006 
1007 
1008 
1009  QSizeF documentSize = documentLayout->documentSize();
1010  vbar->setRange(0, qMax(0, vmax));
1011  vbar->setPageStep(vSliderLength);
1012  int visualTopLine = vmax;
1013  QTextBlock firstVisibleBlock = q->firstVisibleBlock();
1014  if (firstVisibleBlock.isValid())
1015  visualTopLine = firstVisibleBlock.firstLineNumber() + topLine;
1016  bool vbarSignalsBlocked = vbar->blockSignals(true);
1017  vbar->setValue(visualTopLine);
1018  vbar->blockSignals(vbarSignalsBlocked);
1019 
1020  hbar->setRange(0, (int)documentSize.width() - viewport->width());
1022  documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked;
1023  setTopLine(vbar->value());
1024 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
double qreal
Definition: qglobal.h:1193
int lineCount() const
Returns the number of lines of this document (if the layout supports this).
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
QLayout * layout
Definition: qwidget_p.h:704
qreal width() const
Returns the width.
Definition: qsize.h:284
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static QSize documentSize(QTextControl *control)
Definition: qtextedit.cpp:238
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
#define Q_Q(Class)
Definition: qglobal.h:2483
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
QSizeF documentSize() const
Reimplemented Function
int value() const
bool isVisible() const
Returns true if the block is visible; otherwise returns false.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QTextDocument * document() const
int firstLineNumber() const
Returns the first line number of this block, or -1 if the block is invalid.
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
void setTopLine(int visualTopLine, int dx=0)
QPlainTextEditControl * control
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QTextBlock lastBlock() const
Returns the document&#39;s last (valid) text block.
QPlainTextDocumentLayoutPrivate * priv() const
qreal documentMargin
The margin around the document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
QRectF blockBoundingRect(const QTextBlock &block) const
Reimplemented Function
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
int lineCount() const
Returns the number of lines in this text layout.
QRectF naturalTextRect() const
Returns the rectangle covered by the line.
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ _q_cursorPositionChanged()

void QPlainTextEditPrivate::_q_cursorPositionChanged ( )

Definition at line 450 of file qplaintextedit.cpp.

Referenced by init().

451 {
453 #ifndef QT_NO_ACCESSIBILITY
456 #endif
457 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
#define Q_Q(Class)
Definition: qglobal.h:2483
The QPlainTextEdit class provides a widget that is used to edit and display plain text...

◆ _q_modificationChanged()

void QPlainTextEditPrivate::_q_modificationChanged ( bool  )

◆ _q_repaintContents()

void QPlainTextEditPrivate::_q_repaintContents ( const QRectF contentsRect)

Definition at line 821 of file qplaintextedit.cpp.

Referenced by init().

822 {
824  if (!contentsRect.isValid()) {
825  updateViewport();
826  return;
827  }
828  const int xOffset = horizontalOffset();
829  const int yOffset = (int)verticalOffset();
830  const QRect visibleRect(xOffset, yOffset, viewport->width(), viewport->height());
831 
832  QRect r = contentsRect.adjusted(-1, -1, 1, 1).intersected(visibleRect).toAlignedRect();
833  if (r.isEmpty())
834  return;
835 
836  r.translate(-xOffset, -yOffset);
837  viewport->update(r);
838  emit q->updateRequest(r, 0);
839 }
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
QRectF intersected(const QRectF &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:818
#define Q_Q(Class)
Definition: qglobal.h:2483
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
#define emit
Definition: qobjectdefs.h:76
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
qreal verticalOffset() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312

◆ _q_verticalScrollbarActionTriggered()

void QPlainTextEditPrivate::_q_verticalScrollbarActionTriggered ( int  action)

Definition at line 459 of file qplaintextedit.cpp.

Referenced by init().

459  {
460  if (action == QAbstractSlider::SliderPageStepAdd) {
462  } else if (action == QAbstractSlider::SliderPageStepSub) {
464  }
465 }
void pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor=true)

◆ append()

void QPlainTextEditPrivate::append ( const QString text,
Qt::TextFormat  format = Qt::AutoText 
)

Definition at line 2834 of file qplaintextedit.cpp.

2835 {
2837 
2838  QTextDocument *document = control->document();
2840  Q_ASSERT(documentLayout);
2841 
2842  int maximumBlockCount = document->maximumBlockCount();
2843  if (maximumBlockCount)
2844  document->setMaximumBlockCount(0);
2845 
2846  const bool atBottom = q->isVisible()
2847  && (control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset()
2848  <= viewport->rect().bottom());
2849 
2850  if (!q->isVisible())
2851  showCursorOnInitialShow = true;
2852 
2853  bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged;
2854  documentLayout->priv()->blockDocumentSizeChanged = true;
2855 
2856  if (format == Qt::RichText)
2857  control->appendHtml(text);
2858  else if (format == Qt::PlainText)
2859  control->appendPlainText(text);
2860  else
2861  control->append(text);
2862 
2863  if (maximumBlockCount > 0) {
2864  if (document->blockCount() > maximumBlockCount) {
2865  bool blockUpdate = false;
2866  if (control->topBlock) {
2867  control->topBlock--;
2868  blockUpdate = true;
2869  emit q->updateRequest(viewport->rect(), 0);
2870  }
2871 
2872  bool updatesBlocked = documentLayout->priv()->blockUpdate;
2873  documentLayout->priv()->blockUpdate = blockUpdate;
2874  QTextCursor cursor(document);
2875  cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);
2876  cursor.removeSelectedText();
2877  documentLayout->priv()->blockUpdate = updatesBlocked;
2878  }
2879  document->setMaximumBlockCount(maximumBlockCount);
2880  }
2881 
2882  documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked;
2884 
2885 
2886  if (atBottom) {
2887  const bool needScroll = !centerOnScroll
2889  > viewport->rect().bottom();
2890  if (needScroll)
2891  vbar->setValue(vbar->maximum());
2892  }
2893 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
void appendHtml(const QString &html)
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
int blockCount
Returns the number of text blocks in the document.
int maximumBlockCount
Specifies the limit for blocks in the document.
void append(const QString &text)
QRectF blockBoundingRect(const QTextBlock &block) const
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_Q(Class)
Definition: qglobal.h:2483
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
void setMaximumBlockCount(int maximum)
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
QTextDocument * document() const
qreal verticalOffset() const
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QPlainTextEditControl * control
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QTextBlock lastBlock() const
Returns the document&#39;s last (valid) text block.
QPlainTextDocumentLayoutPrivate * priv() const
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void appendPlainText(const QString &text)
int maximum() const

◆ ensureCursorVisible()

void QPlainTextEditPrivate::ensureCursorVisible ( bool  center = false)

Definition at line 2920 of file qplaintextedit.cpp.

Referenced by pageUpDown().

2921 {
2923  QRect visible = viewport->rect();
2924  QRect cr = q->cursorRect();
2925  if (cr.top() < visible.top() || cr.bottom() > visible.bottom()) {
2927  }
2928 
2929  const bool rtl = q->isRightToLeft();
2930  if (cr.left() < visible.left() || cr.right() > visible.right()) {
2931  int x = cr.center().x() + horizontalOffset() - visible.width()/2;
2932  hbar->setValue(rtl ? hbar->maximum() - x : x);
2933  }
2934 }
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QTextCursor textCursor() const
#define Q_Q(Class)
Definition: qglobal.h:2483
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
void ensureVisible(int position, bool center, bool forceCenter=false)
int position() const
Returns the absolute position of the cursor within the document.
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QPlainTextEditControl * control
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
int maximum() const

◆ ensureViewportLayouted()

void QPlainTextEditPrivate::ensureViewportLayouted ( )

Definition at line 1029 of file qplaintextedit.cpp.

1030 {
1031 }

◆ ensureVisible()

void QPlainTextEditPrivate::ensureVisible ( int  position,
bool  center,
bool  forceCenter = false 
)

Definition at line 687 of file qplaintextedit.cpp.

687  {
689  QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());
691  if (!block.isValid())
692  return;
693  QRectF br = control->blockBoundingRect(block);
694  if (!br.isValid())
695  return;
696  QRectF lr = br;
697  QTextLine line = block.layout()->lineForTextPosition(position - block.position());
698  Q_ASSERT(line.isValid());
699  lr = line.naturalTextRect().translated(br.topLeft());
700 
701  if (lr.bottom() >= visible.bottom() || (center && lr.top() < visible.top()) || forceCenter){
702 
703  qreal height = visible.height();
704  if (center)
705  height /= 2;
706 
707  qreal h = center ? line.naturalTextRect().center().y() : line.naturalTextRect().bottom();
708 
709  QTextBlock previousVisibleBlock = block;
710  while (h < height && block.previous().isValid()) {
711  previousVisibleBlock = block;
712  do {
713  block = block.previous();
714  } while (!block.isVisible() && block.previous().isValid());
715  h += q->blockBoundingRect(block).height();
716  }
717 
718  int l = 0;
719  int lineCount = block.layout()->lineCount();
720  qreal voffset = verticalOffset(block.blockNumber(), 0);
721  while (l < lineCount) {
722  QRectF lineRect = block.layout()->lineAt(l).naturalTextRect();
723  if (h - voffset - lineRect.top() <= height)
724  break;
725  ++l;
726  }
727 
728  if (l >= lineCount) {
729  block = previousVisibleBlock;
730  l = 0;
731  }
732  setTopBlock(block.blockNumber(), l);
733  } else if (lr.top() < visible.top()) {
734  setTopBlock(block.blockNumber(), line.lineNumber());
735  }
736 
737 }
double qreal
Definition: qglobal.h:1193
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QRectF blockBoundingRect(const QTextBlock &block) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
#define Q_Q(Class)
Definition: qglobal.h:2483
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
int lineNumber() const
Returns the position of the line in the text engine.
Definition: qtextlayout.h:243
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
void setTopBlock(int newTopBlock, int newTopLine, int dx=0)
QTextDocument * document() const
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
qreal verticalOffset() const
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
QPlainTextEditControl * control
QFactoryLoader * l
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
QRectF naturalTextRect() const
Returns the rectangle covered by the line.

◆ horizontalOffset()

int QPlainTextEditPrivate::horizontalOffset ( ) const
inline

Definition at line 130 of file qplaintextedit_p.h.

Referenced by _q_repaintContents().

131  { return (q_func()->isRightToLeft() ? (hbar->maximum() - hbar->value()) : hbar->value()); }
int value() const
int maximum() const

◆ init()

void QPlainTextEditPrivate::init ( const QString txt = QString())

Definition at line 762 of file qplaintextedit.cpp.

763 {
766 
767  QTextDocument *doc = new QTextDocument(control);
769  doc->setDocumentLayout(layout);
770  control->setDocument(doc);
771 
772  control->setPalette(q->palette());
773 
774  QObject::connect(vbar, SIGNAL(actionTriggered(int)), q, SLOT(_q_verticalScrollbarActionTriggered(int)));
775 
776  QObject::connect(control, SIGNAL(microFocusChanged()), q, SLOT(updateMicroFocus()));
777  QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)), q, SLOT(_q_adjustScrollbars()));
778  QObject::connect(control, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int)));
780  QObject::connect(control, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool)));
781 
782  QObject::connect(control, SIGNAL(textChanged()), q, SIGNAL(textChanged()));
783  QObject::connect(control, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));
784  QObject::connect(control, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));
785  QObject::connect(control, SIGNAL(copyAvailable(bool)), q, SIGNAL(copyAvailable(bool)));
786  QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged()));
787  QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged()));
788  QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged()));
789 
790  QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus()));
791 
792  // set a null page size initially to avoid any relayouting until the textedit
793  // is shown. relayoutDocument() will take care of setting the page size to the
794  // viewport dimensions later.
795  doc->setTextWidth(-1);
797  doc->setDefaultFont(q->font());
798 
799 
800  if (!txt.isEmpty())
801  control->setPlainText(txt);
802 
803  hbar->setSingleStep(20);
804  vbar->setSingleStep(1);
805 
807  q->setAcceptDrops(true);
808  q->setFocusPolicy(Qt::WheelFocus);
809  q->setAttribute(Qt::WA_KeyCompression);
810  q->setAttribute(Qt::WA_InputMethodEnabled);
811 
812 #ifndef QT_NO_CURSOR
814 #endif
815  originalOffsetY = 0;
816 #ifdef Q_WS_WIN
818 #endif
819 }
void setPlainText(const QString &text)
void _q_verticalScrollbarActionTriggered(int action)
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
QLayout * layout
Definition: qwidget_p.h:704
void setDocument(QTextDocument *document)
void setPalette(const QPalette &pal)
#define SLOT(a)
Definition: qobjectdefs.h:226
void _q_repaintContents(const QRectF &contentsRect)
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
void setTextWidth(qreal width)
QPlainTextEditControl * control
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setPaintDevice(QPaintDevice *device)
Sets the paint device used for rendering the document&#39;s layout to the given device.
void setSingleFingerPanEnabled(bool on=true)
void setDocumentLayout(QAbstractTextDocumentLayout *layout)
Sets the document to use the given layout.
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...

◆ mapToContents()

QPoint QPlainTextEditPrivate::mapToContents ( const QPoint point) const
inline

Definition at line 120 of file qplaintextedit_p.h.

121  { return QPoint(point.x() + horizontalOffset(), point.y() + verticalOffset()); }
qreal verticalOffset() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ pageUpDown()

void QPlainTextEditPrivate::pageUpDown ( QTextCursor::MoveOperation  op,
QTextCursor::MoveMode  moveMode,
bool  moveCursor = true 
)

Definition at line 841 of file qplaintextedit.cpp.

842 {
843 
845 
846  QTextCursor cursor = control->textCursor();
847  if (moveCursor) {
851  }
852 
854 
855 
856  if (op == QTextCursor::Down) {
857  QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());
858  QTextBlock firstVisibleBlock = q->firstVisibleBlock();
859  QTextBlock block = firstVisibleBlock;
860  QRectF br = q->blockBoundingRect(block);
861  qreal h = 0;
862  int atEnd = false;
863  while (h + br.height() <= visible.bottom()) {
864  if (!block.next().isValid()) {
865  atEnd = true;
866  lastY = visible.bottom(); // set cursor to last line
867  break;
868  }
869  h += br.height();
870  block = block.next();
871  br = q->blockBoundingRect(block);
872  }
873 
874  if (!atEnd) {
875  int line = 0;
876  qreal diff = visible.bottom() - h;
877  int lineCount = block.layout()->lineCount();
878  while (line < lineCount - 1) {
879  if (block.layout()->lineAt(line).naturalTextRect().bottom() > diff) {
880  // the first line that did not completely fit the screen
881  break;
882  }
883  ++line;
884  }
885  setTopBlock(block.blockNumber(), line);
886  }
887 
888  if (moveCursor) {
889  // move using movePosition to keep the cursor's x
890  lastY += verticalOffset();
891  bool moved = false;
892  do {
893  moved = cursor.movePosition(op, moveMode);
894  } while (moved && control->cursorRect(cursor).top() < lastY);
895  }
896 
897  } else if (op == QTextCursor::Up) {
898 
899  QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset());
900  visible.translate(0, -visible.height()); // previous page
901  QTextBlock block = q->firstVisibleBlock();
902  qreal h = 0;
903  while (h >= visible.top()) {
904  if (!block.previous().isValid()) {
905  if (control->topBlock == 0 && topLine == 0) {
906  lastY = 0; // set cursor to first line
907  }
908  break;
909  }
910  block = block.previous();
911  QRectF br = q->blockBoundingRect(block);
912  h -= br.height();
913  }
914 
915  int line = 0;
916  if (block.isValid()) {
917  qreal diff = visible.top() - h;
918  int lineCount = block.layout()->lineCount();
919  while (line < lineCount) {
920  if (block.layout()->lineAt(line).naturalTextRect().top() >= diff)
921  break;
922  ++line;
923  }
924  if (line == lineCount) {
925  if (block.next().isValid() && block.next() != q->firstVisibleBlock()) {
926  block = block.next();
927  line = 0;
928  } else {
929  --line;
930  }
931  }
932  }
933  setTopBlock(block.blockNumber(), line);
934 
935  if (moveCursor) {
936  cursor.setVisualNavigation(true);
937  // move using movePosition to keep the cursor's x
938  lastY += verticalOffset();
939  bool moved = false;
940  do {
941  moved = cursor.movePosition(op, moveMode);
942  } while (moved && control->cursorRect(cursor).top() > lastY);
943  }
944  }
945 
946  if (moveCursor) {
947  control->setTextCursor(cursor);
949  }
950 }
double qreal
Definition: qglobal.h:1193
void setTextCursor(const QTextCursor &cursor)
void ensureCursorVisible(bool center=false)
QTextCursor textCursor() const
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
#define Q_Q(Class)
Definition: qglobal.h:2483
static QCursor * moveCursor
Definition: qdnd_x11.cpp:254
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
static Bigint * diff(Bigint *a, Bigint *b)
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
QRectF cursorRect(const QTextCursor &cursor) const
void setTopBlock(int newTopBlock, int newTopLine, int dx=0)
void translate(qreal dx, qreal dy)
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position...
Definition: qrect.h:716
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
qreal verticalOffset() const
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QPlainTextEditControl * control
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.
void setVisualNavigation(bool b)
Sets visual navigation to b.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
int blockNumber() const
Returns the number of this block, or -1 if the block is invalid.
int lineCount() const
Returns the number of lines in this text layout.
QRectF naturalTextRect() const
Returns the rectangle covered by the line.
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ relayoutDocument()

void QPlainTextEditPrivate::relayoutDocument ( )

Definition at line 1816 of file qplaintextedit.cpp.

1817 {
1818  QTextDocument *doc = control->document();
1820  Q_ASSERT(documentLayout);
1821  documentLayoutPtr = documentLayout;
1822 
1823  int width = viewport->width();
1824 
1825  if (documentLayout->priv()->mainViewPrivate == 0
1826  || documentLayout->priv()->mainViewPrivate == this
1827  || width > documentLayout->textWidth()) {
1828  documentLayout->priv()->mainViewPrivate = this;
1829  documentLayout->setTextWidth(width);
1830  }
1831 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
QPointer< QPlainTextDocumentLayout > documentLayoutPtr
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QTextDocument * document() const
QPlainTextEditPrivate * mainViewPrivate
QPlainTextEditControl * control
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QPlainTextDocumentLayoutPrivate * priv() const
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setTextWidth(qreal newWidth)

◆ sendControlEvent()

void QPlainTextEditPrivate::sendControlEvent ( QEvent e)
inline

Definition at line 135 of file qplaintextedit_p.h.

The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget=0)
qreal verticalOffset() const
QPlainTextEditControl * control

◆ setTopBlock()

void QPlainTextEditPrivate::setTopBlock ( int  newTopBlock,
int  newTopLine,
int  dx = 0 
)

Definition at line 631 of file qplaintextedit.cpp.

Referenced by pageUpDown().

632 {
634  blockNumber = qMax(0, blockNumber);
635  lineNumber = qMax(0, lineNumber);
636  QTextDocument *doc = control->document();
637  QTextBlock block = doc->findBlockByNumber(blockNumber);
638 
639  int newTopLine = block.firstLineNumber() + lineNumber;
640  int maxTopLine = vbar->maximum();
641 
642  if (newTopLine > maxTopLine) {
643  block = doc->findBlockByLineNumber(maxTopLine);
644  blockNumber = block.blockNumber();
645  lineNumber = maxTopLine - block.firstLineNumber();
646  }
647 
648  bool vbarSignalsBlocked = vbar->blockSignals(true);
649  vbar->setValue(newTopLine);
650  vbar->blockSignals(vbarSignalsBlocked);
651 
652  if (!dx && blockNumber == control->topBlock && lineNumber == topLine)
653  return;
654 
655  if (viewport->updatesEnabled() && viewport->isVisible()) {
656  int dy = 0;
657  if (doc->findBlockByNumber(control->topBlock).isValid()) {
658  qreal realdy = -q->blockBoundingGeometry(block).y()
659  + verticalOffset() - verticalOffset(blockNumber, lineNumber);
660  dy = (int)realdy;
661  topLineFracture = realdy - dy;
662  }
663  control->topBlock = blockNumber;
664  topLine = lineNumber;
665 
666  bool vbarSignalsBlocked = vbar->blockSignals(true);
667  vbar->setValue(block.firstLineNumber() + lineNumber);
668  vbar->blockSignals(vbarSignalsBlocked);
669 
670  if (dx || dy) {
671  viewport->scroll(q->isRightToLeft() ? -dx : dx, dy);
672  } else {
673  viewport->update();
674  topLineFracture = 0;
675  }
676  emit q->updateRequest(viewport->rect(), dy);
677  } else {
678  control->topBlock = blockNumber;
679  topLine = lineNumber;
680  topLineFracture = 0;
681  }
682 
683 }
void scroll(int dx, int dy)
Scrolls the widget including its children dx pixels to the right and dy downward. ...
Definition: qwidget.cpp:10684
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
double qreal
Definition: qglobal.h:1193
bool isVisible() const
Definition: qwidget.h:1005
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define Q_Q(Class)
Definition: qglobal.h:2483
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
bool updatesEnabled
whether updates are enabled
Definition: qwidget.h:190
#define emit
Definition: qobjectdefs.h:76
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
QTextBlock findBlockByNumber(int blockNumber) const
Returns the text block with the specified blockNumber.
QTextDocument * document() const
int firstLineNumber() const
Returns the first line number of this block, or -1 if the block is invalid.
QTextBlock findBlockByLineNumber(int blockNumber) const
Returns the text block that contains the specified lineNumber.
qreal verticalOffset() const
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
QPlainTextEditControl * control
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
int maximum() const
int blockNumber() const
Returns the number of this block, or -1 if the block is invalid.

◆ setTopLine()

void QPlainTextEditPrivate::setTopLine ( int  visualTopLine,
int  dx = 0 
)

Definition at line 622 of file qplaintextedit.cpp.

Referenced by _q_adjustScrollbars().

623 {
624  QTextDocument *doc = control->document();
625  QTextBlock block = doc->findBlockByLineNumber(visualTopLine);
626  int blockNumber = block.blockNumber();
627  int lineNumber = visualTopLine - block.firstLineNumber();
628  setTopBlock(blockNumber, lineNumber, dx);
629 }
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
void setTopBlock(int newTopBlock, int newTopLine, int dx=0)
QTextDocument * document() const
int firstLineNumber() const
Returns the first line number of this block, or -1 if the block is invalid.
QTextBlock findBlockByLineNumber(int blockNumber) const
Returns the text block that contains the specified lineNumber.
QPlainTextEditControl * control
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
int blockNumber() const
Returns the number of this block, or -1 if the block is invalid.

◆ updateDefaultTextOption()

void QPlainTextEditPrivate::updateDefaultTextOption ( )

Definition at line 1979 of file qplaintextedit.cpp.

1980 {
1981  QTextDocument *doc = control->document();
1982 
1983  QTextOption opt = doc->defaultTextOption();
1984  QTextOption::WrapMode oldWrapMode = opt.wrapMode();
1985 
1988  else
1989  opt.setWrapMode(wordWrap);
1990 
1991  if (opt.wrapMode() != oldWrapMode)
1992  doc->setDefaultTextOption(opt);
1993 }
WrapMode
This enum describes how text is wrapped in a document.
Definition: qtextoption.h:102
void setDefaultTextOption(const QTextOption &option)
Sets the default text option.
QTextDocument * document() const
QTextOption::WrapMode wordWrap
QPlainTextEditControl * control
WrapMode wrapMode() const
Returns the text wrap mode defined by the option.
Definition: qtextoption.h:110
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
QTextOption defaultTextOption() const
the default text option will be set on all QTextLayout in the document.
QPlainTextEdit::LineWrapMode lineWrap

◆ updateViewport()

void QPlainTextEditPrivate::updateViewport ( )

Definition at line 740 of file qplaintextedit.cpp.

Referenced by _q_repaintContents().

741 {
743  viewport->update();
744  emit q->updateRequest(viewport->rect(), 0);
745 }
#define Q_Q(Class)
Definition: qglobal.h:2483
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
#define emit
Definition: qobjectdefs.h:76
The QPlainTextEdit class provides a widget that is used to edit and display plain text...
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168

◆ verticalOffset() [1/2]

qreal QPlainTextEditPrivate::verticalOffset ( int  topBlock,
int  topLine 
) const

Definition at line 487 of file qplaintextedit.cpp.

488 {
489  qreal offset = 0;
490  QTextDocument *doc = control->document();
491 
492  if (topLine) {
493  QTextBlock currentBlock = doc->findBlockByNumber(topBlock);
495  Q_ASSERT(documentLayout);
496  QRectF r = documentLayout->blockBoundingRect(currentBlock);
497  Q_UNUSED(r);
498  QTextLayout *layout = currentBlock.layout();
499  if (layout && topLine <= layout->lineCount()) {
500  QTextLine line = layout->lineAt(topLine - 1);
501  const QRectF lr = line.naturalTextRect();
502  offset = lr.bottom();
503  }
504  }
505  if (topBlock == 0 && topLine == 0)
506  offset -= doc->documentMargin(); // top margin
507  return offset;
508 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
double qreal
Definition: qglobal.h:1193
The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument.
QLayout * layout
Definition: qwidget_p.h:704
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QTextBlock findBlockByNumber(int blockNumber) const
Returns the text block with the specified blockNumber.
QTextDocument * document() const
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QPlainTextEditControl * control
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
qreal documentMargin
The margin around the document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
QRectF blockBoundingRect(const QTextBlock &block) const
Reimplemented Function
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRectF naturalTextRect() const
Returns the rectangle covered by the line.
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ verticalOffset() [2/2]

qreal QPlainTextEditPrivate::verticalOffset ( ) const

Definition at line 511 of file qplaintextedit.cpp.

Referenced by _q_repaintContents(), and pageUpDown().

Properties

◆ autoScrollDragPos

QPoint QPlainTextEditPrivate::autoScrollDragPos

Definition at line 145 of file qplaintextedit_p.h.

◆ autoScrollTimer

QBasicTimer QPlainTextEditPrivate::autoScrollTimer

Definition at line 144 of file qplaintextedit_p.h.

◆ backgroundVisible

uint QPlainTextEditPrivate::backgroundVisible

Definition at line 151 of file qplaintextedit_p.h.

Referenced by QPlainTextEditPrivate().

◆ centerOnScroll

uint QPlainTextEditPrivate::centerOnScroll

Definition at line 152 of file qplaintextedit_p.h.

Referenced by _q_adjustScrollbars(), and QPlainTextEditPrivate().

◆ clickCausedFocus

uint QPlainTextEditPrivate::clickCausedFocus

Definition at line 154 of file qplaintextedit_p.h.

◆ control

QPlainTextEditControl* QPlainTextEditPrivate::control

Definition at line 140 of file qplaintextedit_p.h.

Referenced by _q_adjustScrollbars(), init(), and pageUpDown().

◆ documentLayoutPtr

QPointer<QPlainTextDocumentLayout> QPlainTextEditPrivate::documentLayoutPtr

Definition at line 166 of file qplaintextedit_p.h.

◆ inDrag

uint QPlainTextEditPrivate::inDrag

Definition at line 153 of file qplaintextedit_p.h.

Referenced by QPlainTextEditPrivate().

◆ lineWrap

QPlainTextEdit::LineWrapMode QPlainTextEditPrivate::lineWrap

Definition at line 147 of file qplaintextedit_p.h.

◆ originalOffsetY

int QPlainTextEditPrivate::originalOffsetY

Definition at line 181 of file qplaintextedit_p.h.

Referenced by init().

◆ pageUpDownLastCursorY

qreal QPlainTextEditPrivate::pageUpDownLastCursorY

Definition at line 170 of file qplaintextedit_p.h.

Referenced by pageUpDown().

◆ pageUpDownLastCursorYIsValid

bool QPlainTextEditPrivate::pageUpDownLastCursorYIsValid

Definition at line 171 of file qplaintextedit_p.h.

Referenced by pageUpDown().

◆ showCursorOnInitialShow

uint QPlainTextEditPrivate::showCursorOnInitialShow

Definition at line 150 of file qplaintextedit_p.h.

Referenced by QPlainTextEditPrivate().

◆ tabChangesFocus

bool QPlainTextEditPrivate::tabChangesFocus

Definition at line 142 of file qplaintextedit_p.h.

◆ topLine

int QPlainTextEditPrivate::topLine

Definition at line 156 of file qplaintextedit_p.h.

Referenced by _q_adjustScrollbars(), and pageUpDown().

◆ topLineFracture

qreal QPlainTextEditPrivate::topLineFracture

Definition at line 157 of file qplaintextedit_p.h.

◆ wordWrap

QTextOption::WrapMode QPlainTextEditPrivate::wordWrap

Definition at line 148 of file qplaintextedit_p.h.


The documentation for this class was generated from the following files: