2 #include "kgraphinterface.h"
4 #include <kkeydialog.h>
5 #include <kfiledialog.h>
9 #include <kedittoolbar.h>
12 #include <kstdaction.h>
14 #include <klibloader.h>
15 #include <kmessagebox.h>
16 #include <kstatusbar.h>
19 KGraphInterface::KGraphInterface()
20 : KParts::MainWindow( 0L, "KGraphInterface" )
22 // set the shell's ui resource file
23 setXMLFile("kgraphinterface_shell.rc");
25 // then, setup our actions
31 // this routine will find and load our Part. it finds the Part by
32 // name which is a bad idea usually.. but it's alright in this
33 // case since our Part is made for this Shell
34 KLibFactory
*factory
= KLibLoader::self()->factory("libkgraphinterfacepart");
37 // now that the Part is loaded, we cast it to a Part to get
39 m_part
= static_cast<KParts::ReadWritePart
*>(factory
->create(this,
40 "kgraphinterface_part", "KParts::ReadWritePart" ));
44 // tell the KParts::MainWindow that this is indeed the main widget
45 setCentralWidget(m_part
->widget());
47 // and integrate the part's GUI with the shell's
53 // if we couldn't find our Part, we exit since the Shell by
54 // itself can't do anything useful
55 KMessageBox::error(this, i18n("Could not find our part."));
57 // we return here, cause kapp->quit() only means "exit the
58 // next time we enter the event loop...
62 // apply the saved mainwindow settings, if any, and ask the mainwindow
63 // to automatically save settings if changed: window size, toolbar
64 // position, icon size, etc.
65 setAutoSaveSettings();
68 KGraphInterface::~KGraphInterface()
72 void KGraphInterface::load(const KURL
& url
)
74 m_part
->openURL( url
);
77 void KGraphInterface::setupActions()
79 KStdAction::openNew(this, SLOT(fileNew()), actionCollection());
80 KStdAction::open(this, SLOT(fileOpen()), actionCollection());
82 KStdAction::quit(kapp
, SLOT(quit()), actionCollection());
84 m_toolbarAction
= KStdAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection());
85 m_statusbarAction
= KStdAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection());
87 KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
88 KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
91 void KGraphInterface::saveProperties(KConfig
* /*config*/)
93 // the 'config' object points to the session managed
94 // config file. anything you write here will be available
95 // later when this app is restored
98 void KGraphInterface::readProperties(KConfig
* /*config*/)
100 // the 'config' object points to the session managed
101 // config file. this function is automatically called whenever
102 // the app is being restored. read in here whatever you wrote
103 // in 'saveProperties'
106 void KGraphInterface::fileNew()
108 // this slot is called whenever the File->New menu is selected,
109 // the New shortcut is pressed (usually CTRL+N) or the New toolbar
112 // About this function, the style guide (
113 // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
114 // says that it should open a new window if the document is _not_
115 // in its initial state. This is what we do here..
116 if ( ! m_part
->url().isEmpty() || m_part
->isModified() )
118 (new KGraphInterface
)->show();
123 void KGraphInterface::optionsShowToolbar()
125 // this is all very cut and paste code for showing/hiding the
127 if (m_toolbarAction
->isChecked())
133 void KGraphInterface::optionsShowStatusbar()
135 // this is all very cut and paste code for showing/hiding the
137 if (m_statusbarAction
->isChecked())
143 void KGraphInterface::optionsConfigureKeys()
145 KKeyDialog::configure(actionCollection());
148 void KGraphInterface::optionsConfigureToolbars()
150 #if defined(KDE_MAKE_VERSION)
151 # if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
152 saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
154 saveMainWindowSettings(KGlobal::config() );
157 saveMainWindowSettings(KGlobal::config() );
160 // use the standard toolbar editor
161 KEditToolbar
dlg(factory());
162 connect(&dlg
, SIGNAL(newToolbarConfig()),
163 this, SLOT(applyNewToolbarConfig()));
167 void KGraphInterface::applyNewToolbarConfig()
169 #if defined(KDE_MAKE_VERSION)
170 # if KDE_VERSION >= KDE_MAKE_VERSION(3,1,0)
171 applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
173 applyMainWindowSettings(KGlobal::config());
176 applyMainWindowSettings(KGlobal::config());
180 void KGraphInterface::fileOpen()
182 // this slot is called whenever the File->Open menu is selected,
183 // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
186 KFileDialog::getOpenURL( QString::null
, QString::null
, this );
188 if (url
.isEmpty() == false)
190 // About this function, the style guide (
191 // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
192 // says that it should open a new window if the document is _not_
193 // in its initial state. This is what we do here..
194 if ( m_part
->url().isEmpty() && ! m_part
->isModified() )
196 // we open the file in this window...
201 // we open the file in a new window...
202 KGraphInterface
* newWin
= new KGraphInterface
;
209 #include "kgraphinterface.moc"