summaryrefslogtreecommitdiffstats
path: root/kparts/tests/example.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /kparts/tests/example.cpp
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
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
Diffstat (limited to 'kparts/tests/example.cpp')
-rw-r--r--kparts/tests/example.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/kparts/tests/example.cpp b/kparts/tests/example.cpp
new file mode 100644
index 000000000..51f493686
--- /dev/null
+++ b/kparts/tests/example.cpp
@@ -0,0 +1,135 @@
+
+#include "example.h"
+#include "parts.h"
+#include "notepad.h"
+
+#include <qsplitter.h>
+#include <qcheckbox.h>
+#include <qdir.h>
+
+#include <kiconloader.h>
+#include <kstandarddirs.h>
+#include <kapplication.h>
+#include <kmessagebox.h>
+#include <kaction.h>
+#include <klocale.h>
+
+Shell::Shell()
+{
+ setXMLFile( "kpartstest_shell.rc" );
+
+ m_manager = new KParts::PartManager( this );
+
+ // When the manager says the active part changes, the builder updates (recreates) the GUI
+ connect( m_manager, SIGNAL( activePartChanged( KParts::Part * ) ),
+ this, SLOT( createGUI( KParts::Part * ) ) );
+
+ // We can do this "switch active part" because we have a splitter with
+ // two items in it.
+ // I wonder what kdevelop uses/will use to embed kedit, BTW.
+ m_splitter = new QSplitter( this );
+
+ m_part1 = new Part1(this, m_splitter);
+ m_part2 = new Part2(this, m_splitter);
+
+ KActionCollection *coll = actionCollection();
+
+ (void)new KAction( "&View local file", 0, this, SLOT( slotFileOpen() ), coll, "open_local_file" );
+ (void)new KAction( "&View remote file", 0, this, SLOT( slotFileOpenRemote() ), coll, "open_remote_file" );
+
+ m_paEditFile = new KAction( "&Edit file", 0, this, SLOT( slotFileEdit() ), coll, "edit_file" );
+ m_paCloseEditor = new KAction( "&Close file editor", 0, this, SLOT( slotFileCloseEditor() ), coll, "close_editor" );
+ m_paCloseEditor->setEnabled(false);
+ KAction * paQuit = new KAction( "&Quit", 0, this, SLOT( close() ), coll, "shell_quit" );
+ paQuit->setIconSet(QIconSet(BarIcon("exit")));
+
+ (void)new KAction( "Yet another menu item", 0, coll, "shell_yami" );
+ (void)new KAction( "Yet another submenu item", 0, coll, "shell_yasmi" );
+
+ setCentralWidget( m_splitter );
+ m_splitter->setMinimumSize( 400, 300 );
+
+ m_splitter->show();
+
+ m_manager->addPart( m_part1, true ); // sets part 1 as the active part
+ m_manager->addPart( m_part2, false );
+ m_editorpart = 0;
+}
+
+Shell::~Shell()
+{
+ disconnect( m_manager, 0, this, 0 );
+}
+
+void Shell::slotFileOpen()
+{
+ if ( ! m_part1->openURL( locate("data", KGlobal::instance()->instanceName()+"/kpartstest_shell.rc" ) ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+void Shell::slotFileOpenRemote()
+{
+ KURL u ( "http://www.kde.org/index.html" );
+ if ( ! m_part1->openURL( u ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+void Shell::embedEditor()
+{
+ if ( m_manager->activePart() == m_part2 )
+ createGUI( 0L );
+
+ // replace part2 with the editor part
+ delete m_part2;
+ m_part2 = 0L;
+ m_editorpart = new NotepadPart( m_splitter, "editor",
+ this, "NotepadPart" );
+ m_editorpart->setReadWrite(); // read-write mode
+ m_manager->addPart( m_editorpart );
+ m_paEditFile->setEnabled(false);
+ m_paCloseEditor->setEnabled(true);
+}
+
+void Shell::slotFileCloseEditor()
+{
+ // It is very important to close the url of a read-write part
+ // before destroying it. This allows to save the document (if modified)
+ // and also to cancel.
+ if ( ! m_editorpart->closeURL() )
+ return;
+
+ // Is this necessary ? (David)
+ if ( m_manager->activePart() == m_editorpart )
+ createGUI( 0L );
+
+ delete m_editorpart;
+ m_editorpart = 0L;
+ m_part2 = new Part2(this, m_splitter);
+ m_manager->addPart( m_part2 );
+ m_paEditFile->setEnabled(true);
+ m_paCloseEditor->setEnabled(false);
+}
+
+void Shell::slotFileEdit()
+{
+ if ( !m_editorpart )
+ embedEditor();
+ // TODO use KFileDialog to allow testing remote files
+ if ( ! m_editorpart->openURL( QDir::current().absPath()+"/kpartstest_shell.rc" ) )
+ KMessageBox::error(this,"Couldn't open file !");
+}
+
+int main( int argc, char **argv )
+{
+ KApplication app( argc, argv, "kpartstest" );
+
+ Shell *shell = new Shell;
+
+ shell->show();
+
+ app.exec();
+
+ return 0;
+}
+
+#include "example.moc"