File indexing completed on 2024-10-13 03:57:39
0001 /*************************************************************************** 0002 kimepart.cpp - description 0003 ------------------- 0004 begin : Mon Aug 5 2002 0005 copyright : (C) 2002 by Jan Schäfer 0006 email : janschaefer@users.sourceforge.net 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "kimeshell.h" 0019 0020 #include <iostream> 0021 0022 #include <QAction> 0023 #include <QApplication> 0024 #include <QDockWidget> 0025 #include <QFileDialog> 0026 #include <QScrollArea> 0027 #include <QStatusBar> 0028 0029 #include "kimagemapeditor_debug.h" 0030 #include <KActionCollection> 0031 #include <KConfigGroup> 0032 #include <KEditToolBar> 0033 #include <KMessageBox> 0034 #include <KParts/GUIActivateEvent> 0035 #include <KSharedConfig> 0036 #include <KShortcutsDialog> 0037 #include <KStandardAction> 0038 #include <KToolBar> 0039 #include <KWindowConfig> 0040 #include <KXMLGUIFactory> 0041 #include <KPluginFactory> 0042 #include <KPluginMetaData> 0043 0044 #include "drawzone.h" 0045 #include "kimagemapeditor.h" // the KPart 0046 0047 KimeShell::KimeShell(const char * ) 0048 : KParts::MainWindow() 0049 { 0050 setXMLFile("kimagemapeditorui.rc"); 0051 0052 // QDockWidget* mainDock = new QDockWidget(this); 0053 // mainDock = createDockWidget( "MainDockWidget", 0L, 0L, "main_dock_widget"); 0054 // QWidget *mainWidget = new KHBox( this ); 0055 // QScrollArea* mainWidget = new QScrollArea(this); 0056 // setCentralWidget(mainWidget); 0057 // QLayout* layout = new QGridLayout( mainDock ); 0058 0059 // mainDock->setWidget( w ); 0060 // allow others to dock to the 4 sides 0061 // mainDock->setDockSite(K3DockWidget::DockCorner); 0062 // forbid docking abilities of mainDock itself 0063 // mainDock->setEnableDocking(K3DockWidget::DockNone); 0064 // setView( mainDock); // central widget in a KDE mainwindow 0065 // setMainDockWidget( mainDock); // master dockwidget 0066 qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 0"; 0067 0068 qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 1"; 0069 setupActions(); 0070 qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 2"; 0071 0072 const auto result = KPluginFactory::instantiatePlugin<KParts::ReadWritePart>(KPluginMetaData(QStringLiteral("kf" QT_STRINGIFY(QT_VERSION_MAJOR) "/parts/kimagemapeditorpart")), this); 0073 0074 if (!result) { 0075 // can't do anything useful without part, thus quit the app 0076 KMessageBox::error(this, i18n("Could not find kimagemapeditorpart part!")); 0077 0078 qApp->quit(); 0079 // return here, because qApp->quit() only means "exit the 0080 // next time we enter the event loop... 0081 return; 0082 } 0083 0084 m_part = result.plugin; 0085 m_editorInterface = qobject_cast<KImageMapEditorInterface*>(m_part); 0086 0087 if (!m_editorInterface) { 0088 // can't do anything useful without part, thus quit the app 0089 KMessageBox::error(this, i18n("Could not create kimagemapeditorpart part!")); 0090 0091 qApp->quit(); 0092 // return here, because qApp->quit() only means "exit the 0093 // next time we enter the event loop... 0094 return; 0095 } 0096 0097 // setCentralWidget( part->widget() ); 0098 0099 _stdout=false; 0100 0101 // createGUI( m_part ); 0102 createShellGUI( true ); 0103 guiFactory()->addClient( m_part ); 0104 KParts::GUIActivateEvent ev( true ); 0105 QApplication::sendEvent( m_part, &ev ); 0106 //setCentralWidget(part->widget()); 0107 qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 3"; 0108 resize( QSize(725, 525).expandedTo(minimumSizeHint())); 0109 0110 connect( m_part, SIGNAL(setStatusBarText(QString)), 0111 this, SLOT(slotSetStatusBarText(QString))); 0112 0113 connect( m_part, SIGNAL(setWindowCaption(QString)), 0114 this, SLOT(setWindowTitle(QString))); 0115 0116 setAutoSaveSettings( "General Options" ); 0117 qCDebug(KIMAGEMAPEDITOR_LOG) << "KimeShell starting 4"; 0118 0119 } 0120 0121 KimeShell::~KimeShell() 0122 { 0123 // delete part; 0124 } 0125 0126 bool KimeShell::queryClose() 0127 { 0128 if (_stdout) { 0129 //FIXME std::cout << m_part->getHtmlCode() << std::endl; 0130 } 0131 0132 return m_part->queryClose(); 0133 } 0134 0135 0136 bool KimeShell::queryExit() 0137 { 0138 // writeConfig(); 0139 #ifdef __GNUC__ 0140 #warning what group is correct here? A random one? 0141 #endif 0142 KConfigGroup cg( KSharedConfig::openConfig(), QString() ); 0143 saveProperties( cg ); 0144 0145 return true; 0146 } 0147 0148 0149 void KimeShell::setupActions() 0150 { 0151 (void)KStandardAction::openNew(this, SLOT(fileNew()), actionCollection()); 0152 0153 // File Quit 0154 (void)KStandardAction::quit(this, SLOT(close()),actionCollection()); 0155 0156 0157 //FIXME (void)KStandardAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection()); 0158 (void)KStandardAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection()); 0159 (void)KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection()); 0160 (void)KStandardAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection()); 0161 0162 0163 } 0164 0165 void KimeShell::fileNew() 0166 { 0167 // this slot is called whenever the File->New menu is selected, 0168 // the New shortcut is pressed (usually CTRL+N) or the New toolbar 0169 // button is clicked 0170 0171 // About this function, the style guide ( 0172 // says that it should open a new window if the document is _not_ 0173 // in its initial state. This is what we do here.. 0174 if ( ! m_part->url().isEmpty() || m_part->isModified() ) 0175 { 0176 KimeShell * newShell = new KimeShell(); 0177 0178 newShell->show(); 0179 newShell->readConfig(); 0180 }; 0181 } 0182 0183 void KimeShell::openFile(const QUrl & url) 0184 { 0185 m_editorInterface->openFile(url); 0186 } 0187 0188 void KimeShell::openLastFile() 0189 { 0190 #ifdef __GNUC__ 0191 #warning there is no group defined 0192 #endif 0193 KConfigGroup cg( KSharedConfig::openConfig(), QString() ); 0194 if (cg.readEntry("start-with-last-used-document",true)) 0195 m_editorInterface->openLastURL( cg ); 0196 } 0197 0198 void KimeShell::fileOpen() 0199 { 0200 QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Choose Picture to Open"), QUrl(), 0201 i18n("Web File (*.png *.jpg *.jpeg *.gif *.htm *.html);;Images (*.png *.jpg *.jpeg *.gif *.bmp *.xbm *.xpm *.pnm *.mng);;" 0202 "HTML Files (*.htm *.html);;All Files (*)")); 0203 if (!url.isEmpty()) { 0204 // About this function, the style guide ( 0205 // says that it should open a new window if the document is _not_ 0206 // in its initial state. This is what we do here.. 0207 if ( m_part->url().isEmpty() && ! m_part->isModified() ) 0208 { 0209 // we open the file in this window... 0210 m_editorInterface->openURL(url); 0211 } 0212 else 0213 { 0214 // we open the file in a new window... 0215 KimeShell* newWin = new KimeShell; 0216 newWin->openFile( url ); 0217 newWin->show(); 0218 } 0219 } 0220 } 0221 0222 0223 0224 void KimeShell::readConfig() { 0225 KSharedConfigPtr config = KSharedConfig::openConfig(); 0226 readConfig(config->group("General Options") ); 0227 } 0228 0229 void KimeShell::readConfig(const KConfigGroup &) { 0230 // applyMainWindowSettings(config); 0231 // restoreWindowSize(config); 0232 // readDockConfig(config); 0233 } 0234 0235 void KimeShell::writeConfig() { 0236 KConfigGroup config( KSharedConfig::openConfig(), "General Options"); 0237 writeConfig( config ); 0238 } 0239 0240 void KimeShell::writeConfig(KConfigGroup &config) { 0241 saveMainWindowSettings(config); 0242 KWindowConfig::saveWindowSize(windowHandle(), config); 0243 // writeDockConfig(config); 0244 config.sync(); 0245 0246 } 0247 0248 0249 void KimeShell::saveProperties(KConfigGroup &config) 0250 { 0251 //writeConfig(config); 0252 m_editorInterface->saveProperties(config); 0253 writeConfig(); 0254 0255 } 0256 0257 void KimeShell::readProperties(const KConfigGroup &config) 0258 { 0259 readConfig(); 0260 m_editorInterface->readProperties(config); 0261 0262 0263 } 0264 0265 0266 void KimeShell::optionsConfigureKeys() { 0267 // KShortcutsDialog::configureKeys(actionCollection(), "testprog_shell.rc"); 0268 0269 KShortcutsDialog dlg; 0270 dlg.addCollection(actionCollection()); 0271 dlg.addCollection(m_part->actionCollection()); 0272 dlg.configure(); 0273 } 0274 0275 void KimeShell::optionsConfigureToolbars() 0276 { 0277 KConfigGroup configGroup = KSharedConfig::openConfig()->group(autoSaveGroup()); 0278 saveMainWindowSettings(configGroup); 0279 0280 // use the standard toolbar editor 0281 KEditToolBar dlg(factory()); 0282 connect(&dlg, SIGNAL(newToolbarConfig()), 0283 this, SLOT(applyNewToolbarConfig())); 0284 dlg.exec(); 0285 } 0286 0287 void KimeShell::applyNewToolbarConfig() 0288 { 0289 KConfigGroup configGroup = KSharedConfig::openConfig()->group(autoSaveGroup()); 0290 applyMainWindowSettings(configGroup); 0291 } 0292 0293 0294 void KimeShell::optionsShowToolbar() 0295 { 0296 if (toolBar()->isVisible()) 0297 toolBar()->hide(); 0298 else 0299 toolBar()->show(); 0300 } 0301 0302 void KimeShell::optionsShowStatusbar() 0303 { 0304 if (statusBar()->isVisible()) 0305 statusBar()->hide(); 0306 else 0307 statusBar()->show(); 0308 } 0309 0310