00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ktexteditor.h"
00023
00024 using namespace KTextEditor;
00025
00026 class View::ViewPrivate
00027 {
00028 public:
00029 ViewPrivate()
00030 {
00031 }
00032 ~ViewPrivate()
00033 {
00034 }
00035
00036 Document *m_doc;
00037 bool m_bContextPopup;
00038 };
00039
00040 View::View( Document *doc, QWidget *parent, const char *name )
00041 : QWidget( parent, name )
00042 {
00043 d = new ViewPrivate;
00044 d->m_doc = doc;
00045 d->m_bContextPopup = true;
00046 }
00047
00048 View::~View()
00049 {
00050 delete d;
00051 }
00052
00053 Document *View::document() const
00054 {
00055 return d->m_doc;
00056 }
00057
00058 void View::insertText( const QString &text, bool mark )
00059 {
00060 int line, col;
00061 getCursorPosition( &line, &col );
00062 document()->insertAt( text, line, col, mark );
00063 }
00064
00065 void View::setInternalContextMenuEnabled( bool b )
00066 {
00067 d->m_bContextPopup = b;
00068 }
00069
00070 bool View::internalContextMenuEnabled() const
00071 {
00072 return d->m_bContextPopup;
00073 }
00074
00075 class Document::DocumentPrivate
00076 {
00077 public:
00078 DocumentPrivate()
00079 {
00080 }
00081 ~DocumentPrivate()
00082 {
00083 }
00084
00085 };
00086
00087 Document::Document( QObject *parent, const char *name )
00088 : QObject(parent,name)
00089 {
00090 d = new DocumentPrivate;
00091 }
00092
00093 Document::~Document()
00094 {
00095
00096 QListIterator<View> it( m_views );
00097
00098 for (; it.current(); ++it )
00099 disconnect( it.current(), SIGNAL( destroyed() ),
00100 this, SLOT( slotViewDestroyed() ) );
00101
00102 delete d;
00103 }
00104
00105 QList<View> Document::views() const
00106 {
00107 return m_views;
00108 }
00109
00110 void Document::addView( View *view )
00111 {
00112 if ( !view )
00113 return;
00114
00115 if ( m_views.findRef( view ) != -1 )
00116 return;
00117
00118 m_views.append( view );
00119 connect( view, SIGNAL( destroyed() ),
00120 this, SLOT( slotViewDestroyed() ) );
00121 }
00122
00123 void Document::removeView( View *view )
00124 {
00125 if ( !view )
00126 return;
00127
00128 disconnect( view, SIGNAL( destroyed() ),
00129 this, SLOT( slotViewDestroyed() ) );
00130
00131 m_views.removeRef( view );
00132 }
00133
00134 void Document::slotViewDestroyed()
00135 {
00136 const View *view = static_cast<const View *>( sender() );
00137 m_views.removeRef( view );
00138 }
00139
00140