[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: KTextEditor enhancement
From: Carsten Pfeiffer <carpdjih () cetus ! zrz ! tu-berlin ! de>
Date: 2001-10-07 21:48:15
[Download RAW message or body]
On Sun, Oct 07, 2001 at 11:12:56PM +0200, Christoph Cullmann wrote:
Hi,
> I would propose to enhance the KTextEditor stuff now ;)
great :) I agree with your changes and want to add some more.
- the eventhandlers (i.e. about changed text) should not be virtual
functions to reimplement, but observer-like. That way, you could register
yourself even if you don't inherit from the Document class yourself (think
plugins)
- user-input, i.e. mouseclicks or keypresses should be available, so that
e.g. a plugin could get keypress events and offer completion
- the Document should have Cursor objects to change text. A cursor is
basically a line/col wrapper, that is always updated when the document
changes. Every view references exactly one cursor object (but others
may exist as well). Attached is a rough version I made a week ago or so.
- a method to selectively get text from the document is needed (e.g.
QString getText( const Cursor& from, const Cursor& to )).
Comments welcome.
> - there should be a queryInterface (QString name) function to allow progs to \
> implement the interface even if they don't support all stuff
What about naming it supportsInterface()?
Cheers
Carsten Pfeiffer
["ktexteditor_stuff.h" (text/plain)]
/****************************************************************************
** $Id: .emacs,v 1.3 1998/02/20 15:06:53 gis Exp $
**
** Created : 2001
**
** Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>
**
****************************************************************************/
#ifndef KTEXTEDITOR_STUFF_H
#define KTEXTEDITOR_STUFF_H
namespace KTextEditor {
class Cursor
{
public:
Cursor( Document *doc );
~Cursor() {}
void operator ++() {
if ( m_col >= m_doc->textLine( m_row ).length() ) {
if ( m_row < m_doc->numLines() - 1 ) {
m_row++;
m_col = 0;
}
}
else
m_col++;
}
void operator --() {
if ( m_col == 0 ) {
if ( m_row > 0 ) {
m_row--;
m_col = m_doc->textLine( m_row ).length();
}
}
else
m_col--;
}
void getPosition( uint *row, uint *col ) {
if ( row )
*row = m_row;
if ( col )
*col = m_col;
}
bool setPosition( uint row, uint col ) {
if ( row > m_doc->numLines() || textLine( row ).length() < col )
return false;
m_row = row;
m_col = col;
return true;
}
bool move( int numberOfCharacters );
void insert( const QString& text );
void overwrite( const QString& text );
int backspace( int numberOfCharacters );
int delete( int numberOfCharacters );
Document *document() const { return m_doc; }
QChar current() const {
if ( m_doc->numLines() > 0 )
return m_doc->textLine( m_row ).at( m_col );
else
return QChar();
}
private:
Document *m_doc;
uint m_row, m_col;
};
};
#endif // KTEXTEDITOR_STUFF_H
["ktexteditor_stuff.cpp" (text/plain)]
#include <assert.h>
#include "ktexteditor_stuff.h"
using namespace KTextEditor;
Cursor::Cursor( Document *doc )
: m_doc( doc ),
m_row( 0 ),
m_col( 0 )
{
assert( doc );
}
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic