• Skip to content
  • Skip to link menu
KDE 4.3 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 #include "kateview.h"
00037 
00038 #include <QtCore/QPoint>
00039 #include <QtCore/QTimer>
00040 #include <QtGui/QDrag>
00041 #include <QtGui/QWidget>
00042 #include <QtCore/QSet>
00043 #include <QtCore/QPointer>
00044 
00045 class KateIconBorder;
00046 class KateScrollBar;
00047 class KateSmartRange;
00048 class KateTextLayout;
00049 
00050 class KateViInputModeManager;
00051 
00052 class QScrollBar;
00053 
00054 class KateViewInternal : public QWidget, private KTextEditor::SmartRangeWatcher
00055 {
00056     Q_OBJECT
00057 
00058     friend class KateView;
00059     friend class KateIconBorder;
00060     friend class KateScrollBar;
00061     friend class CalculatingCursor;
00062     friend class BoundedCursor;
00063     friend class WrappingCursor;
00064     friend class KateViModeBase;
00065 
00066   public:
00067     enum Bias
00068     {
00069         left  = -1,
00070         none  =  0,
00071         right =  1
00072     };
00073 
00074   public:
00075     KateViewInternal ( KateView *view, KateDocument *doc );
00076     ~KateViewInternal ();
00077 
00078   //BEGIN EDIT STUFF
00079   public:
00080     void editStart ();
00081     void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00082 
00083     void editSetCursor (const KTextEditor::Cursor &cursor);
00084 
00085   private:
00086     uint editSessionNumber;
00087     bool editIsRunning;
00088     KTextEditor::Cursor editOldCursor;
00089   //END
00090 
00091   //BEGIN TAG & CLEAR & UPDATE STUFF
00092   public:
00093     bool tagLine (const KTextEditor::Cursor& virtualCursor);
00094 
00095     bool tagLines (int start, int end, bool realLines = false);
00096     // cursors not const references as they are manipulated within
00097     bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
00098 
00099     bool tagRange(const KTextEditor::Range& range, bool realCursors);
00100 
00101     void tagAll ();
00102 
00103     void relayoutRange(const KTextEditor::Range& range, bool realCursors = true);
00104 
00105     void updateDirty();
00106 
00107     void clear ();
00108 
00109   Q_SIGNALS:
00110     // Trigger this signal whenever you want to call updateView() and may not be in the same thread.
00111     // Make sure to set m_smartDirty = false before, else nothing will happen
00112     void requestViewUpdateIfSmartDirty();
00113   //END
00114 
00115   private Q_SLOTS:
00116     // Updates the view and requests a redraw.
00117     void updateView (bool changed = false, int viewLinesScrolled = 0);
00118     // This is used to prevent multiple unneeded view updates
00119     void updateViewIfSmartDirty();
00120 
00121   private:
00122     // Actually performs the updating, but doesn't call update().
00123     void doUpdateView(bool changed = false, int viewLinesScrolled = 0);
00124     void makeVisible (const KTextEditor::Cursor& c, int endCol, bool force = false, bool center = false, bool calledExternally = false);
00125 
00126   public:
00127     // Start Position is a virtual cursor
00128     inline const KTextEditor::Cursor& startPos() const { return m_startPos; }
00129     inline int startLine () const { return m_startPos.line(); }
00130     inline int startX () const { return m_startX; }
00131 
00132     KTextEditor::Cursor endPos () const;
00133     int endLine () const;
00134 
00135     KateTextLayout yToKateTextLayout(int y) const;
00136 
00137     void prepareForDynWrapChange();
00138     void dynWrapChanged();
00139 
00140     KateView *view () { return m_view; }
00141 
00142   public Q_SLOTS:
00143     void slotIncFontSizes();
00144     void slotDecFontSizes();
00145 
00146   private Q_SLOTS:
00147     void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll
00148     void scrollViewLines(int offset);
00149     void scrollAction(int action);
00150     void scrollNextPage();
00151     void scrollPrevPage();
00152     void scrollPrevLine();
00153     void scrollNextLine();
00154     void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll
00155     void viewSelectionChanged ();
00156 
00157   public:
00158     void doReturn();
00159     void doSmartNewline();
00160     void doDelete();
00161     void doBackspace();
00162     void doTranspose();
00163     void doDeleteWordLeft();
00164     void doDeleteWordRight();
00165 
00166     void cursorLeft(bool sel=false);
00167     void cursorRight(bool sel=false);
00168     void wordLeft(bool sel=false);
00169     void wordRight(bool sel=false);
00170     void home(bool sel=false);
00171     void end(bool sel=false);
00172     void cursorUp(bool sel=false);
00173     void cursorDown(bool sel=false);
00174     void cursorToMatchingBracket(bool sel=false);
00175     void scrollUp();
00176     void scrollDown();
00177     void topOfView(bool sel=false);
00178     void bottomOfView(bool sel=false);
00179     void pageUp(bool sel=false);
00180     void pageDown(bool sel=false);
00181     void top(bool sel=false);
00182     void bottom(bool sel=false);
00183     void top_home(bool sel=false);
00184     void bottom_end(bool sel=false);
00185 
00186     KTextEditor::Cursor getCursor() const;
00187     QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor, bool realCursor = true, bool includeBorder = true) const;
00188     //Always works on coordinates of the whole widget, eg. offsetted by the border
00189     KTextEditor::Cursor coordinatesToCursor(const QPoint& coord) const;
00190     QPoint cursorCoordinates(bool includeBorder = true) const;
00191     KTextEditor::Cursor findMatchingBracket();
00192 
00193   // EVENT HANDLING STUFF - IMPORTANT
00194   private:
00195     void fixDropEvent(QDropEvent *event);
00196   protected:
00197     virtual void hideEvent(QHideEvent* e);
00198     virtual void paintEvent(QPaintEvent *e);
00199     virtual bool eventFilter( QObject *obj, QEvent *e );
00200     virtual void keyPressEvent( QKeyEvent* );
00201     virtual void keyReleaseEvent( QKeyEvent* );
00202     virtual void resizeEvent( QResizeEvent* );
00203     virtual void mousePressEvent(       QMouseEvent* );
00204     virtual void mouseDoubleClickEvent( QMouseEvent* );
00205     virtual void mouseReleaseEvent(     QMouseEvent* );
00206     virtual void mouseMoveEvent(        QMouseEvent* );
00207     virtual void leaveEvent( QEvent* );
00208     virtual void dragEnterEvent( QDragEnterEvent* );
00209     virtual void dragMoveEvent( QDragMoveEvent* );
00210     virtual void dropEvent( QDropEvent* );
00211     virtual void showEvent ( QShowEvent *);
00212     virtual void wheelEvent(QWheelEvent* e);
00213     virtual void focusInEvent (QFocusEvent *);
00214     virtual void focusOutEvent (QFocusEvent *);
00215     virtual void inputMethodEvent(QInputMethodEvent* e);
00216 
00217     void contextMenuEvent ( QContextMenuEvent * e );
00218 
00219   private Q_SLOTS:
00220     void tripleClickTimeout();
00221 
00222   Q_SIGNALS:
00223     // emitted when KateViewInternal is not handling its own URI drops
00224     void dropEventPass(QDropEvent*);
00225 
00226   private Q_SLOTS:
00227     void slotRegionVisibilityChangedAt(unsigned int,bool clear_cache);
00228     void slotRegionBeginEndAddedRemoved(unsigned int);
00229     void slotCodeFoldingChanged();
00230 
00231   private:
00232     void moveChar( Bias bias, bool sel );
00233     void moveEdge( Bias bias, bool sel );
00234     KTextEditor::Cursor maxStartPos(bool changed = false);
00235     void scrollPos(KTextEditor::Cursor& c, bool force = false, bool calledExternally = false);
00236     void scrollLines( int lines, bool sel );
00237 
00238     int linesDisplayed() const;
00239 
00240     int lineToY(int viewLine) const;
00241 
00242     void updateSelection( const KTextEditor::Cursor&, bool keepSel );
00243     void moveCursorToSelectionEdge();
00244     //The smart-lock should not be locked when this is called
00245     void updateCursor( const KTextEditor::Cursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00246     void updateBracketMarks();
00247 
00248     void paintCursor();
00249 
00250     void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00251     bool isTargetSelected( const QPoint& p );
00252     //Returns whether the given range affects the area currently visible in the view
00253     bool rangeAffectsView(const KTextEditor::Range& range) const;
00254 
00255     void doDrag();
00256 
00257     inline KateView* view() const { return m_view; }
00258     KateRenderer* renderer() const;
00259 
00260     KateView *m_view;
00261     KateDocument* m_doc;
00262     class KateIconBorder *m_leftBorder;
00263 
00264     int m_mouseX;
00265     int m_mouseY;
00266     int m_scrollX;
00267     int m_scrollY;
00268 
00269     Qt::CursorShape m_mouseCursor;
00270 
00271     KateSmartCursor m_cursor;
00272     KTextEditor::Cursor m_mouse;
00273     KTextEditor::Cursor m_displayCursor;
00274 
00275     bool m_possibleTripleClick;
00276 
00277     //Whether the current completion-item was expanded while the last press of ALT
00278     bool m_completionItemExpanded;
00279     QTime m_altDownTime;
00280     
00281     // Bracket mark and corresponding decorative ranges
00282     KateSmartRange *m_bm, *m_bmStart, *m_bmEnd;
00283     bool m_bmHighlighted;
00284     void updateBracketMarkAttributes();
00285 
00286     enum DragState { diNone, diPending, diDragging };
00287 
00288     struct _dragInfo {
00289       DragState    state;
00290       QPoint       start;
00291       QDrag*   dragObject;
00292     } m_dragInfo;
00293 
00294     uint m_iconBorderHeight;
00295 
00296     //
00297     // line scrollbar + first visible (virtual) line in the current view
00298     //
00299     KateScrollBar *m_lineScroll;
00300     QWidget* m_dummy;
00301 
00302     // These are now cursors to account for word-wrap.
00303     // Start Position is a virtual cursor
00304     KateSmartCursor m_startPos;
00305     //Count of lines that are visible behind m_startPos.
00306     //This does not respect dynamic word wrap, so take it as an approximation.
00307     uint m_visibleLineCount;
00308 
00309     // This is set to false on resize or scroll (other than that called by makeVisible),
00310     // so that makeVisible is again called when a key is pressed and the cursor is in the same spot
00311     bool m_madeVisible;
00312     bool m_shiftKeyPressed;
00313 
00314     // How many lines to should be kept visible above/below the cursor when possible
00315     void setAutoCenterLines(int viewLines, bool updateView = true);
00316     int m_autoCenterLines;
00317     int m_minLinesVisible;
00318 
00319     //
00320     // column scrollbar + x position
00321     //
00322     QScrollBar *m_columnScroll;
00323     int m_startX;
00324 
00325     // has selection changed while your mouse or shift key is pressed
00326     bool m_selChangedByUser;
00327     KTextEditor::Cursor m_selectAnchor;
00328 
00329     enum SelectionMode { Default=0, Mouse, Word, Line }; 
00330     uint m_selectionMode;
00331     // when drag selecting after double/triple click, keep the initial selected
00332     // word/line independent of direction.
00333     // They get set in the event of a double click, and is used with mouse move + leftbutton
00334     KTextEditor::Range m_selectionCached;
00335 
00336     // maximal length of textlines visible from given startLine
00337     int maxLen(int startLine);
00338 
00339     // are we allowed to scroll columns?
00340     bool columnScrollingPossible ();
00341 
00342     // returns the maximum X value / col value a cursor can take for a specific line range
00343     int lineMaxCursorX(const KateTextLayout& line);
00344     int lineMaxCol(const KateTextLayout& line);
00345 
00346     class KateLayoutCache* cache() const;
00347     KateLayoutCache* m_layoutCache;
00348 
00349     // convenience methods
00350     KateTextLayout currentLayout() const;
00351     KateTextLayout previousLayout() const;
00352     KateTextLayout nextLayout() const;
00353 
00354     // find the cursor offset by (offset) view lines from a cursor.
00355     // when keepX is true, the column position will be calculated based on the x
00356     // position of the specified cursor.
00357     KTextEditor::Cursor viewLineOffset(const KTextEditor::Cursor& virtualCursor, int offset, bool keepX = false);
00358 
00359     KTextEditor::Cursor toRealCursor(const KTextEditor::Cursor& virtualCursor) const;
00360     KTextEditor::Cursor toVirtualCursor(const KTextEditor::Cursor& realCursor) const;
00361 
00362     // These variable holds the most recent maximum real & visible column number
00363     bool m_preserveX;
00364     int m_preservedX;
00365 
00366     bool m_updatingView;
00367     int m_wrapChangeViewLine;
00368     KTextEditor::Cursor m_cachedMaxStartPos;
00369 
00370   private Q_SLOTS:
00371     void doDragScroll();
00372     void startDragScroll();
00373     void stopDragScroll();
00374 
00375   private:
00376     // Timers
00377     QTimer m_dragScrollTimer;
00378     QTimer m_scrollTimer;
00379     QTimer m_cursorTimer;
00380     QTimer m_textHintTimer;
00381 
00382     static const int s_scrollTime = 30;
00383     static const int s_scrollMargin = 16;
00384 
00385   private Q_SLOTS:
00386     void scrollTimeout ();
00387     void cursorTimeout ();
00388     void textHintTimeout ();
00389 
00390   //TextHint
00391  public:
00392    void enableTextHints(int timeout);
00393    void disableTextHints();
00394 
00395  private:
00396    bool m_textHintEnabled;
00397    int m_textHintTimeout;
00398    int m_textHintMouseX;
00399    int m_textHintMouseY;
00400 
00404   public:
00405     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
00406 
00407   private:
00408     KTextEditor::SmartRange* m_imPreedit;
00409 
00410   // Arbitrary highlighting
00411   public:
00412     void addHighlightRange(KTextEditor::SmartRange* range);
00413     void removeHighlightRange(KTextEditor::SmartRange* range);
00414 
00415   private:
00416     // Dynamic highlighting
00417     struct DynamicRangeHL {
00418       DynamicRangeHL(KateSmartRange* top);
00419       ~DynamicRangeHL();
00420 
00421       KateSmartRange* top;
00422       bool isView;
00423       KateSmartRange* caretOver;
00424       KateSmartRange* mouseOver;
00425       QHash<KateSmartRange*, QPointer<class KateDynamicAnimation> > caretAnimations;
00426       QHash<KateSmartRange*, QPointer<KateDynamicAnimation> > mouseAnimations;
00427     };
00428 
00429     void mouseMoved();
00430     void cursorMoved();
00431     void dynamicMoved(bool mouse);
00432     void startDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00433     void endDynamic(DynamicRangeHL* hl, KateSmartRange* range, KTextEditor::Attribute::ActivationType type);
00434 
00435   private:
00436     // Overrides for watched highlighting ranges
00437     void rangePositionChanged(KTextEditor::SmartRange* range);
00438     void rangeDeleted(KTextEditor::SmartRange* range);
00439     void childRangeInserted(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00440     void childRangeRemoved(KTextEditor::SmartRange* range, KTextEditor::SmartRange* child);
00441     void rangeAttributeChanged(KTextEditor::SmartRange* range, KTextEditor::Attribute::Ptr currentAttribute, KTextEditor::Attribute::Ptr previousAttribute);
00442 
00443   public Q_SLOTS:
00444     void dynamicHighlightAdded(KateSmartRange* range);
00445     void dynamicHighlightRemoved(KateSmartRange* range);
00446     void rangeDeleted(KateSmartRange* range);
00447 
00448     void updateRange(KateSmartRange* range);
00449 
00450   private:
00451     QHash<KateSmartRange*, DynamicRangeHL*> m_dynamicHighlights;
00452     bool m_smartDirty;
00453 
00454     void removeWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00455     void addWatcher(KTextEditor::SmartRange* range, KTextEditor::SmartRangeWatcher* watcher);
00456     int m_watcherCount1, m_watcherCount3;
00457 
00458   // vi Mode
00459   private:
00460     bool m_viInputMode;
00461     bool m_viInputModeStealKeys;
00462     //ViMode m_currentViMode;
00463 
00464     //KateViNormalMode* m_viNormalMode;
00465     //KateViNormalMode* getViNormalMode();
00466 
00467     //KateViVisualMode* m_viVisualMode;
00468     //KateViVisualMode* getViVisualMode();
00469 
00470     //KateViInsertMode* m_viInsertMode;
00471     //KateViInsertMode* getViInsertMode();
00472 
00476     ViMode getCurrentViMode();
00477 
00482     KateViInputModeManager* m_viInputModeManager;
00483 
00487     KateViInputModeManager* getViInputModeManager();
00488 };
00489 
00490 #endif
00491 
00492 // 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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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