• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

kateviewinternal.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002-2007 Hamish Rodda <rodda@kde.org>
00003    Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
00004    Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
00005    Copyright (C) 2002 Christoph Cullmann <cullmann@kde.org>
00006    Copyright (C) 2007 Mirko Stocker <me@misto.ch>
00007 
00008    Based on:
00009      KWriteView : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
00010 
00011    This library is free software; you can redistribute it and/or
00012    modify it under the terms of the GNU Library General Public
00013    License version 2 as published by the Free Software Foundation.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Library General Public License for more details.
00019 
00020    You should have received a copy of the GNU Library General Public License
00021    along with this library; see the file COPYING.LIB.  If not, write to
00022    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023    Boston, MA 02110-1301, USA.
00024 */
00025 
00026 #ifndef _KATE_VIEW_INTERNAL_
00027 #define _KATE_VIEW_INTERNAL_
00028 
00029 #include <ktexteditor/attribute.h>
00030 #include <ktexteditor/rangefeedback.h>
00031 
00032 #include "katesmartcursor.h"
00033 #include "katelinelayout.h"
00034 #include "katetextline.h"
00035 #include "katedocument.h"
00036 
00037 #include <QtCore/QPoint>
00038 #include <QtCore/QTimer>
00039 #include <QtGui/QDrag>
00040 #include <QtGui/QWidget>
00041 #include <QtCore/QSet>
00042 #include <QtCore/QPointer>
00043 
00044 class KateView;
00045 class KateIconBorder;
00046 class KateScrollBar;
00047 class KateSmartRange;
00048 class KateTextLayout;
00049 
00050 class QScrollBar;
00051 
00052 class KateViewInternal : public QWidget, private KTextEditor::SmartRangeWatcher
00053 {
00054     Q_OBJECT
00055 
00056     friend class KateView;
00057     friend class KateIconBorder;
00058     friend class KateScrollBar;
00059     friend class CalculatingCursor;
00060     friend class BoundedCursor;
00061     friend class WrappingCursor;
00062 
00063   public:
00064     enum Bias
00065     {
00066         left  = -1,
00067         none  =  0,
00068         right =  1
00069     };
00070 
00071   public:
00072     KateViewInternal ( KateView *view, KateDocument *doc );
00073     ~KateViewInternal ();
00074 
00075   //BEGIN EDIT STUFF
00076   public:
00077     void editStart ();
00078     void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00079 
00080     void editSetCursor (const KTextEditor::Cursor &cursor);
00081 
00082   private:
00083     uint editSessionNumber;
00084     bool editIsRunning;
00085     KTextEditor::Cursor editOldCursor;
00086   //END
00087 
00088   //BEGIN TAG & CLEAR & UPDATE STUFF
00089   public:
00090     bool tagLine (const KTextEditor::Cursor& virtualCursor);
00091 
00092     bool tagLines (int start, int end, bool realLines = false);
00093     // cursors not const references as they are manipulated within
00094     bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
00095 
00096     bool tagRange(const KTextEditor::Range& range, bool realCursors);
00097 
00098     void tagAll ();
00099 
00100     void relayoutRange(const KTextEditor::Range& range, bool realCursors = true);
00101 
00102     void updateDirty();
00103 
00104     void clear ();
00105 
00106   Q_SIGNALS:
00107     // Trigger this signal whenever you want to call updateView() and may not be in the same thread.
00108     void requestViewUpdate(bool changed);
00109   //END
00110 
00111   private Q_SLOTS:
00112     // Updates the view and requests a redraw.
00113     void updateView (bool changed = false, int viewLinesScrolled = 0);
00114 
00115   private:
00116     // Actually performs the updating, but doesn't call update().
00117     void doUpdateView(bool changed = false, int viewLinesScrolled = 0);
00118     void makeVisible (const KTextEditor::Cursor& c, int endCol, bool force = false, bool center = false, bool calledExternally = false);
00119 
00120   public:
00121     // Start Position is a virtual cursor
00122     inline const KTextEditor::Cursor& startPos() const { return m_startPos; }
00123     inline int startLine () const { return m_startPos.line(); }
00124     inline int startX () const { return m_startX; }
00125 
00126     KTextEditor::Cursor endPos () const;
00127     int endLine () const;
00128 
00129     KateTextLayout yToKateTextLayout(int y) const;
00130 
00131     void prepareForDynWrapChange();
00132     void dynWrapChanged();
00133 
00134     KateView *view () { return m_view; }
00135 
00136   public Q_SLOTS:
00137     void slotIncFontSizes();
00138     void slotDecFontSizes();
00139 
00140   private Q_SLOTS:
00141     void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll
00142     void scrollViewLines(int offset);
00143     void scrollAction(int action);
00144     void scrollNextPage();
00145     void scrollPrevPage();
00146     void scrollPrevLine();
00147     void scrollNextLine();
00148     void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll
00149     void viewSelectionChanged ();
00150 
00151   public:
00152     void doReturn();
00153     void doDelete();
00154     void doBackspace();
00155     void doTranspose();
00156     void doDeleteWordLeft();
00157     void doDeleteWordRight();
00158 
00159     void cursorLeft(bool sel=false);
00160     void cursorRight(bool sel=false);
00161     void wordLeft(bool sel=false);
00162     void wordRight(bool sel=false);
00163     void home(bool sel=false);
00164     void end(bool sel=false);
00165     void cursorUp(bool sel=false);
00166     void cursorDown(bool sel=false);
00167     void cursorToMatchingBracket(bool sel=false);
00168     void scrollUp();
00169     void scrollDown();
00170     void topOfView(bool sel=false);
00171     void bottomOfView(bool sel=false);
00172     void pageUp(bool sel=false);
00173     void pageDown(bool sel=false);
00174     void top(bool sel=false);
00175     void bottom(bool sel=false);
00176     void top_home(bool sel=false);
00177     void bottom_end(bool sel=false);
00178 
00179     KTextEditor::Cursor getCursor() const;
00180     QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor, bool realCursor = true, bool includeBorder = true) const;
00181     QPoint cursorCoordinates(bool includeBorder = true) const;
00182 
00183   // EVENT HANDLING STUFF - IMPORTANT
00184   private:
00185     void fixDropEvent(QDropEvent *event);
00186   protected:
00187     virtual void hideEvent(QHideEvent* e);
00188     virtual void paintEvent(QPaintEvent *e);
00189     virtual bool eventFilter( QObject *obj, QEvent *e );
00190     virtual void keyPressEvent( QKeyEvent* );
00191     virtual void keyReleaseEvent( QKeyEvent* );
00192     virtual void resizeEvent( QResizeEvent* );
00193     virtual void mousePressEvent(       QMouseEvent* );
00194     virtual void mouseDoubleClickEvent( QMouseEvent* );
00195     virtual void mouseReleaseEvent(     QMouseEvent* );
00196     virtual void mouseMoveEvent(        QMouseEvent* );
00197     virtual void leaveEvent( QEvent* );
00198     virtual void dragEnterEvent( QDragEnterEvent* );
00199     virtual void dragMoveEvent( QDragMoveEvent* );
00200     virtual void dropEvent( QDropEvent* );
00201     virtual void showEvent ( QShowEvent *);
00202     virtual void wheelEvent(QWheelEvent* e);
00203     virtual void focusInEvent (QFocusEvent *);
00204     virtual void focusOutEvent (QFocusEvent *);
00205     virtual void inputMethodEvent(QInputMethodEvent* e);
00206 
00207     void contextMenuEvent ( QContextMenuEvent * e );
00208 
00209   private Q_SLOTS:
00210     void tripleClickTimeout();
00211 
00212   Q_SIGNALS:
00213     // emitted when KateViewInternal is not handling its own URI drops
00214     void dropEventPass(QDropEvent*);
00215 
00216   private Q_SLOTS:
00217     void slotRegionVisibilityChangedAt(unsigned int);
00218     void slotRegionBeginEndAddedRemoved(unsigned int);
00219     void slotCodeFoldingChanged();
00220 
00221   private:
00222     void moveChar( Bias bias, bool sel );
00223     void moveEdge( Bias bias, bool sel );
00224     KTextEditor::Cursor maxStartPos(bool changed = false);
00225     void scrollPos(KTextEditor::Cursor& c, bool force = false, bool calledExternally = false);
00226     void scrollLines( int lines, bool sel );
00227 
00228     int linesDisplayed() const;
00229 
00230     int lineToY(int viewLine) const;
00231 
00232     void updateSelection( const KTextEditor::Cursor&, bool keepSel );
00233     void updateCursor( const KTextEditor::Cursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00234     void updateBracketMarks();
00235 
00236     void paintCursor();
00237 
00238     void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00239     bool isTargetSelected( const QPoint& p );
00240 
00241     void doDrag();
00242 
00243     inline KateView* view() const { return m_view; }
00244     KateRenderer* renderer() const;
00245 
00246     KateView *m_view;
00247     KateDocument* m_doc;
00248     class KateIconBorder *m_leftBorder;
00249 
00250     int m_mouseX;
00251     int m_mouseY;
00252     int m_scrollX;
00253     int m_scrollY;
00254 
00255     Qt::CursorShape m_mouseCursor;
00256 
00257     KateSmartCursor m_cursor;
00258     KTextEditor::Cursor m_mouse;
00259     KTextEditor::Cursor m_displayCursor;
00260     int m_cursorX;
00261 
00262     bool m_possibleTripleClick;
00263 
00264     // Bracket mark and corresponding decorative ranges
00265     KateSmartRange *m_bm, *m_bmStart, *m_bmEnd;
00266     bool m_bmHighlighted;
00267     void updateBracketMarkAttributes();
00268 
00269     enum DragState { diNone, diPending, diDragging };
00270 
00271     struct _dragInfo {
00272       DragState    state;
00273       QPoint       start;
00274       QDrag*   dragObject;
00275     } m_dragInfo;
00276 
00277     uint m_iconBorderHeight;
00278 
00279     //
00280     // line scrollbar + first visible (virtual) line in the current view
00281     //
00282     KateScrollBar *m_lineScroll;
00283     QWidget* m_dummy;
00284 
00285     // These are now cursors to account for word-wrap.
00286     // Start Position is a virtual cursor
00287     KateSmartCursor m_startPos;
00288 
00289     // This is set to false on resize or scroll (other than that called by makeVisible),
00290     // so that makeVisible is again called when a key is pressed and the cursor is in the same spot
00291     bool m_madeVisible;
00292     bool m_shiftKeyPressed;
00293 
00294     // How many lines to should be kept visible above/below the cursor when possible
00295     void setAutoCenterLines(int viewLines, bool updateView = true);
00296     int m_autoCenterLines;
00297     int m_minLinesVisible;
00298 
00299     //
00300     // column scrollbar + x position
00301     //
00302     QScrollBar *m_columnScroll;
00303     int m_startX;
00304 
00305     // has selection changed while your mouse or shift key is pressed
00306     bool m_selChangedByUser;
00307     KTextEditor::Cursor m_selectAnchor;
00308 
00309     enum SelectionMode { Default=0, Mouse, Word, Line }; 
00310     uint m_selectionMode;
00311     // when drag selecting after double/triple click, keep the initial selected
00312     // word/line independent of direction.
00313     // They get set in the event of a double click, and is used with mouse move + leftbutton
00314     KTextEditor::Range m_selectionCached;
00315 
00316     // maximal length of textlines visible from given startLine
00317     int maxLen(int startLine);
00318 
00319     // are we allowed to scroll columns?
00320     bool columnScrollingPossible ();
00321 
00322     // returns the maximum X value / col value a cursor can take for a specific line range
00323     int lineMaxCursorX(const KateTextLayout& line);
00324     int lineMaxCol(const KateTextLayout& line);
00325 
00326     class KateLayoutCache* cache() const;
00327     KateLayoutCache* m_layoutCache;
00328 
00329     // convenience methods
00330     KateTextLayout currentLayout() const;
00331     KateTextLayout previousLayout() const;
00332     KateTextLayout nextLayout() const;
00333 
00334     // find the cursor offset by (offset) view lines from a cursor.
00335     // when keepX is true, the column position will be calculated based on the x
00336     // position of the specified cursor.
00337     KTextEditor::Cursor viewLineOffset(const KTextEditor::Cursor& virtualCursor, int offset, bool keepX = false);
00338 
00339     KTextEditor::Cursor toRealCursor(const KTextEditor::Cursor& virtualCursor) const;
00340     KTextEditor::Cursor toVirtualCursor(const KTextEditor::Cursor& realCursor) const;
00341 
00342     // These variable holds the most recent maximum real & visible column number
00343     bool m_preserveMaxX;
00344     int m_currentMaxX;
00345 
00346     bool m_usePlainLines; // accept non-highlighted lines if this is set
00347 
00348     inline KateTextLine::Ptr textLine( int realLine ) const
00349     {
00350       if (m_usePlainLines)
00351         return m_doc->plainKateTextLine(realLine);
00352       else
00353         return m_doc->kateTextLine(realLine);
00354     }
00355 
00356     bool m_updatingView;
00357     int m_wrapChangeViewLine;
00358     KTextEditor::Cursor m_cachedMaxStartPos;
00359 
00360   private Q_SLOTS:
00361     void doDragScroll();
00362     void startDragScroll();
00363     void stopDragScroll();
00364 
00365   private:
00366     // Timers
00367     QTimer m_dragScrollTimer;
00368     QTimer m_scrollTimer;
00369     QTimer m_cursorTimer;
00370     QTimer m_textHintTimer;
00371 
00372     static const int s_scrollTime = 30;
00373     static const int s_scrollMargin = 16;
00374 
00375   private Q_SLOTS:
00376     void scrollTimeout ();
00377     void cursorTimeout ();
00378     void textHintTimeout ();
00379 
00380   //TextHint
00381  public:
00382    void enableTextHints(int timeout);
00383    void disableTextHints();
00384 
00385  private:
00386    bool m_textHintEnabled;
00387    int m_textHintTimeout;
00388    int m_textHintMouseX;
00389    int m_textHintMouseY;
00390 
00394   public:
00395     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00396 
00397   private:
00398     KTextEditor::SmartRange* m_imPreedit;
00399 
00400   // Arbitrary highlighting
00401   public:
00402     void addHighlightRange(KTextEditor::SmartRange* range);
00403     void removeHighlightRange(KTextEditor::SmartRange* range);
00404 
00405   private:
00406     // Dynamic highlighting
00407     struct DynamicRangeHL {
00408       DynamicRangeHL(KateSmartRange* top);
00409       ~DynamicRangeHL();
00410 
00411       KateSmartRange* top;
00412       bool isView;
00413       KateSmartRange* caretOver;
00414       KateSmartRange* mouseOver;
00415       QHash<KateSmartRange*, QPointer<class KateDynamicAnimation> > caretAnimations;
00416       QHash<KateSmartRange*, QPointer<KateDynamicAnimation> > mouseAnimations;
00417     };
00418 
00419     void mouseMoved();
00420     void cursorMoved();
00421     void dynamicMoved(bool mouse);
00422     void startDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00423     void endDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00424 
00425   private:
00426     // Overrides for watched highlighting ranges
00427     void rangePositionChanged(KTextEditor::SmartRange* range);
00428     void rangeDeleted(KTextEditor::SmartRange* range);
00429     void childRangeInserted(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00430     void childRangeRemoved(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00431     void rangeAttributeChanged(KTextEditor::SmartRange* range, KTextEditor::Attribute::Ptr currentAttribute, KTextEditor::Attribute::Ptr previousAttribute);
00432 
00433   public Q_SLOTS:
00434     void dynamicHighlightAdded(KateSmartRange* range);
00435     void dynamicHighlightRemoved(KateSmartRange* range);
00436     void rangeDeleted(KateSmartRange* range);
00437 
00438     void updateRange(KateSmartRange* range);
00439 
00440   private:
00441     QHash<KateSmartRange*, DynamicRangeHL*> m_dynamicHighlights;
00442     bool m_smartDirty;
00443 
00444     void removeWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00445     void addWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00446     int m_watcherCount1, m_watcherCount3;
00447 };
00448 
00449 #endif
00450 
00451 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal