1 | /*************************************************************************** |
2 | kimepart.cpp - description |
3 | ------------------- |
4 | begin : Mon Aug 5 2002 |
5 | copyright : (C) 2002 by Jan Sch�er |
6 | email : janschaefer@users.sourceforge.net |
7 | ***************************************************************************/ |
8 | |
9 | /*************************************************************************** |
10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * |
15 | * * |
16 | ***************************************************************************/ |
17 | |
18 | |
19 | #include <iostream> |
20 | |
21 | #include <QDockWidget> |
22 | #include <QScrollArea> |
23 | |
24 | #include <kaction.h> |
25 | #include <kstandarddirs.h> |
26 | #include <kfiledialog.h> |
27 | #include <kmessagebox.h> |
28 | #include <kshortcutsdialog.h> |
29 | #include <kedittoolbar.h> |
30 | #include <kstatusbar.h> |
31 | #include <kapplication.h> |
32 | #include <kdebug.h> |
33 | #include <kxmlguifactory.h> |
34 | #include <kstandardaction.h> |
35 | |
36 | #include <khbox.h> |
37 | #include <kglobal.h> |
38 | #include <ktoolbar.h> |
39 | #include <kvbox.h> |
40 | |
41 | #include "drawzone.h" |
42 | #include "kimagemapeditor.h" // the KPart |
43 | #include "kimeshell.h" |
44 | #include "kimeshell.moc" |
45 | #include <kactioncollection.h> |
46 | KimeShell::KimeShell(const char * ) |
47 | : KParts::MainWindow() |
48 | { |
49 | setXMLFile("kimagemapeditorui.rc" ); |
50 | |
51 | // QDockWidget* mainDock = new QDockWidget(this); |
52 | // mainDock = createDockWidget( "MainDockWidget", 0L, 0L, "main_dock_widget"); |
53 | // QWidget *mainWidget = new KHBox( this ); |
54 | // QScrollArea* mainWidget = new QScrollArea(this); |
55 | // setCentralWidget(mainWidget); |
56 | // QLayout* layout = new QGridLayout( mainDock ); |
57 | |
58 | // mainDock->setWidget( w ); |
59 | // allow others to dock to the 4 sides |
60 | // mainDock->setDockSite(K3DockWidget::DockCorner); |
61 | // forbit docking abilities of mainDock itself |
62 | // mainDock->setEnableDocking(K3DockWidget::DockNone); |
63 | // setView( mainDock); // central widget in a KDE mainwindow |
64 | // setMainDockWidget( mainDock); // master dockwidget |
65 | kDebug() << "KimeShell starting 0" ; |
66 | |
67 | m_part = new KImageMapEditor((QWidget*)0L, this); |
68 | |
69 | // setCentralWidget( part->widget() ); |
70 | |
71 | kDebug() << "KimeShell starting 1" ; |
72 | setupActions(); |
73 | kDebug() << "KimeShell starting 2" ; |
74 | |
75 | _stdout=false; |
76 | |
77 | // createGUI( part ); |
78 | createShellGUI( true ); |
79 | guiFactory()->addClient( m_part ); |
80 | KParts::GUIActivateEvent ev( true ); |
81 | QApplication::sendEvent( m_part, &ev ); |
82 | //setCentralWidget(part->widget()); |
83 | kDebug() << "KimeShell starting 3" ; |
84 | if (!initialGeometrySet()) |
85 | resize( QSize(725, 525).expandedTo(minimumSizeHint())); |
86 | |
87 | connect( m_part, SIGNAL(setStatusBarText(const QString &)), |
88 | this, SLOT(slotSetStatusBarText ( const QString & ))); |
89 | |
90 | connect( m_part, SIGNAL(setWindowCaption(const QString &)), |
91 | this, SLOT(setCaption( const QString &))); |
92 | |
93 | setAutoSaveSettings( "General Options" ); |
94 | kDebug() << "KimeShell starting 4" ; |
95 | |
96 | } |
97 | |
98 | KimeShell::~KimeShell() |
99 | { |
100 | // delete part; |
101 | } |
102 | |
103 | bool KimeShell::queryClose() |
104 | { |
105 | if (_stdout) { |
106 | //FIXME std::cout << m_part->getHtmlCode() << std::endl; |
107 | } |
108 | |
109 | return m_part->queryClose(); |
110 | } |
111 | |
112 | |
113 | bool KimeShell::queryExit() |
114 | { |
115 | // writeConfig(); |
116 | #ifdef __GNUC__ |
117 | #warning what group is correct here? A random one? |
118 | #endif |
119 | KConfigGroup cg( KGlobal::config(), QString() ); |
120 | saveProperties( cg ); |
121 | |
122 | return true; |
123 | } |
124 | |
125 | |
126 | void KimeShell::setupActions() |
127 | { |
128 | (void)KStandardAction::openNew(this, SLOT(fileNew()), actionCollection()); |
129 | |
130 | // File Quit |
131 | (void)KStandardAction::quit(this, SLOT(close()),actionCollection()); |
132 | |
133 | |
134 | //FIXME (void)KStandardAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection()); |
135 | (void)KStandardAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection()); |
136 | (void)KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection()); |
137 | (void)KStandardAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection()); |
138 | |
139 | |
140 | } |
141 | |
142 | void KimeShell::fileNew() |
143 | { |
144 | // this slot is called whenever the File->New menu is selected, |
145 | // the New shortcut is pressed (usually CTRL+N) or the New toolbar |
146 | // button is clicked |
147 | |
148 | // About this function, the style guide ( |
149 | // http://developer.kde.org/documentation/standards/kde/style/basics/index.html ) |
150 | // says that it should open a new window if the document is _not_ |
151 | // in its initial state. This is what we do here.. |
152 | if ( ! m_part->url().isEmpty() || m_part->isModified() ) |
153 | { |
154 | KimeShell * newShell = new KimeShell(); |
155 | |
156 | newShell->show(); |
157 | newShell->readConfig(); |
158 | }; |
159 | } |
160 | |
161 | void KimeShell::openFile(const KUrl & url) |
162 | { |
163 | m_part->openFile(url); |
164 | } |
165 | |
166 | void KimeShell::openLastFile() |
167 | { |
168 | #ifdef __GNUC__ |
169 | #warning there is no group defined |
170 | #endif |
171 | KConfigGroup cg( m_part->config(), QString() ); |
172 | if (cg.readEntry("start-with-last-used-document" ,true)) |
173 | m_part->openLastURL( cg ); |
174 | } |
175 | |
176 | void KimeShell::fileOpen() |
177 | { |
178 | KUrl url=KFileDialog::getOpenUrl(KUrl(), |
179 | "*.png *.jpg *.jpeg *.gif *.htm *.html|" + i18n( "Web Files" ) + '\n' + |
180 | "*.png *.jpg *.jpeg *.gif *.bmp *.xbm *.xpm *.pnm *.mng|" + i18n( "Images" ) + '\n' + |
181 | "*.htm *.html|" + i18n( "HTML Files" ) + '\n' + |
182 | "*.png|" + i18n( "PNG Images" ) + "\n*.jpg *.jpeg|" + i18n( "JPEG Images" ) + "\n*.gif|" + i18n( "GIF Images" ) + "\n*|" + i18n( "All Files" ) |
183 | ,this,i18n("Choose Picture to Open" )); |
184 | |
185 | if (!url.isEmpty()) { |
186 | // About this function, the style guide ( |
187 | // http://developer.kde.org/documentation/standards/kde/style/basics/index.html ) |
188 | // says that it should open a new window if the document is _not_ |
189 | // in its initial state. This is what we do here.. |
190 | if ( m_part->url().isEmpty() && ! m_part->isModified() ) |
191 | { |
192 | // we open the file in this window... |
193 | m_part->openURL(url); |
194 | } |
195 | else |
196 | { |
197 | // we open the file in a new window... |
198 | KimeShell* newWin = new KimeShell; |
199 | newWin->openFile( url ); |
200 | newWin->show(); |
201 | } |
202 | } |
203 | } |
204 | |
205 | |
206 | |
207 | void KimeShell::readConfig() { |
208 | KSharedConfigPtr config = KGlobal::config(); |
209 | readConfig(config->group("General Options" ) ); |
210 | } |
211 | |
212 | void KimeShell::readConfig(const KConfigGroup &) { |
213 | // applyMainWindowSettings(config); |
214 | // restoreWindowSize(config); |
215 | // readDockConfig(config); |
216 | } |
217 | |
218 | void KimeShell::writeConfig() { |
219 | KConfigGroup config( KGlobal::config(), "General Options" ); |
220 | writeConfig( config ); |
221 | } |
222 | |
223 | void KimeShell::writeConfig(KConfigGroup &config) { |
224 | saveMainWindowSettings(config); |
225 | saveWindowSize(config); |
226 | // writeDockConfig(config); |
227 | config.sync(); |
228 | |
229 | } |
230 | |
231 | |
232 | void KimeShell::saveProperties(KConfigGroup &config) |
233 | { |
234 | //writeConfig(config); |
235 | m_part->saveProperties(config); |
236 | writeConfig(); |
237 | |
238 | } |
239 | |
240 | void KimeShell::readProperties(const KConfigGroup &config) |
241 | { |
242 | readConfig(); |
243 | m_part->readProperties(config); |
244 | |
245 | |
246 | } |
247 | |
248 | |
249 | void KimeShell::optionsConfigureKeys() { |
250 | // KShortcutsDialog::configureKeys(actionCollection(), "testprog_shell.rc"); |
251 | |
252 | KShortcutsDialog dlg; |
253 | dlg.addCollection(actionCollection()); |
254 | dlg.addCollection(m_part->actionCollection()); |
255 | dlg.configure(); |
256 | } |
257 | |
258 | void KimeShell::optionsConfigureToolbars() |
259 | { |
260 | saveMainWindowSettings(KGlobal::config()->group( autoSaveGroup()) ); |
261 | |
262 | // use the standard toolbar editor |
263 | KEditToolBar dlg(factory()); |
264 | connect(&dlg, SIGNAL(newToolbarConfig()), |
265 | this, SLOT(applyNewToolbarConfig())); |
266 | dlg.exec(); |
267 | } |
268 | |
269 | void KimeShell::applyNewToolbarConfig() |
270 | { |
271 | applyMainWindowSettings(KGlobal::config()->group( autoSaveGroup()) ); |
272 | } |
273 | |
274 | |
275 | void KimeShell::optionsShowToolbar() |
276 | { |
277 | if (toolBar()->isVisible()) |
278 | toolBar()->hide(); |
279 | else |
280 | toolBar()->show(); |
281 | } |
282 | |
283 | void KimeShell::optionsShowStatusbar() |
284 | { |
285 | if (statusBar()->isVisible()) |
286 | statusBar()->hide(); |
287 | else |
288 | statusBar()->show(); |
289 | } |
290 | |
291 | |
292 | |