From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kparts/tests/notepad.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 kparts/tests/notepad.cpp (limited to 'kparts/tests/notepad.cpp') diff --git a/kparts/tests/notepad.cpp b/kparts/tests/notepad.cpp new file mode 100644 index 000000000..8e6f5462c --- /dev/null +++ b/kparts/tests/notepad.cpp @@ -0,0 +1,101 @@ + +#include "notepad.h" +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +NotepadPart::NotepadPart( QWidget* parentWidget, const char*, + QObject* parent, const char* name, + const QStringList& ) + : KParts::ReadWritePart( parent, name ) +{ + setInstance( NotepadFactory::instance() ); + + m_edit = new QMultiLineEdit( parentWidget, "NotepadPart's multiline edit" ); + setWidget( m_edit ); + + (void)new KAction( "Search and replace", 0, this, SLOT( slotSearchReplace() ), actionCollection(), "searchreplace" ); + setXMLFile( "notepadpart.rc" ); + setReadWrite( true ); +} + +NotepadPart::~NotepadPart() +{ +} + +void NotepadPart::setReadWrite( bool rw ) +{ + m_edit->setReadOnly( !rw ); + if (rw) + connect( m_edit, SIGNAL( textChanged() ), this, SLOT( setModified() ) ); + else + disconnect( m_edit, SIGNAL( textChanged() ), this, SLOT( setModified() ) ); + + ReadWritePart::setReadWrite( rw ); +} + +KAboutData* NotepadPart::createAboutData() +{ + return new KAboutData( "notepadpart", I18N_NOOP( "Notepad" ), "2.0" ); +} + +bool NotepadPart::openFile() +{ + kdDebug() << "NotepadPart: opening " << m_file << endl; + // Hehe this is from a tutorial I did some time ago :) + QFile f(m_file); + QString s; + if ( f.open(IO_ReadOnly) ) { + QTextStream t( &f ); + while ( !t.eof() ) { + s += t.readLine() + "\n"; + } + f.close(); + } + m_edit->setText(s); + + emit setStatusBarText( m_url.prettyURL() ); + + return true; +} + +bool NotepadPart::saveFile() +{ + if ( !isReadWrite() ) + return false; + QFile f(m_file); + QString s; + if ( f.open(IO_WriteOnly) ) { + QTextStream t( &f ); + t << m_edit->text(); + f.close(); + return true; + } else + return false; +} + +void NotepadPart::slotSearchReplace() +{ + // What's this ? (David) +/* + QValueList plugins = KParts::Plugin::pluginServants( this ); + QValueList::ConstIterator it = plugins.begin(); + QValueList::ConstIterator end = plugins.end(); + for (; it != end; ++it ) + factory()->removeServant( *it ); +*/ +} + +#include "notepad.moc" -- cgit v1.2.1