nftemplate.cpp
Go to the documentation of this file.00001 /* 00002 For general Scribus (>=1.3.2) copyright and licensing information please refer 00003 to the COPYING file provided with the program. Following this notice may exist 00004 a copyright and/or license notice that predates the release of Scribus 1.3.2 00005 for which a new license (GPL+exception) is in place. 00006 */ 00007 /*************************************************************************** 00008 * Riku Leino, tsoots@gmail.com * 00009 ***************************************************************************/ 00010 #include <QString> 00011 #include <QCursor> 00012 #include <QDir> 00013 #include <QWidget> 00014 00015 #include "scribus.h" 00016 #include "scribuscore.h" 00017 #include "nftemplate.h" 00018 #include "nftdialog.h" 00019 #include "scraction.h" 00020 #include "menumanager.h" 00021 #include "undomanager.h" 00022 #include "prefsmanager.h" 00023 00024 int newfromtemplateplugin_getPluginAPIVersion() 00025 { 00026 return PLUGIN_API_VERSION; 00027 } 00028 00029 ScPlugin* newfromtemplateplugin_getPlugin() 00030 { 00031 NewFromTemplatePlugin* plug = new NewFromTemplatePlugin(); 00032 Q_CHECK_PTR(plug); 00033 return plug; 00034 } 00035 00036 void newfromtemplateplugin_freePlugin(ScPlugin* plugin) 00037 { 00038 NewFromTemplatePlugin* plug = dynamic_cast<NewFromTemplatePlugin*>(plugin); 00039 Q_ASSERT(plug); 00040 delete plug; 00041 } 00042 00043 NewFromTemplatePlugin::NewFromTemplatePlugin() : ScActionPlugin() 00044 { 00045 // Set action info in languageChange, so we only have to do 00046 // it in one place. 00047 languageChange(); 00048 } 00049 00050 NewFromTemplatePlugin::~NewFromTemplatePlugin() {}; 00051 00052 void NewFromTemplatePlugin::languageChange() 00053 { 00054 // Note that we leave the unused members unset. They'll be initialised 00055 // with their default ctors during construction. 00056 // Action name 00057 m_actionInfo.name = "NewFromDocumentTemplate"; 00058 // Action text for menu, including accel 00059 m_actionInfo.text = tr("New &from Template..."); 00060 // Shortcut 00061 m_actionInfo.keySequence = "Ctrl+Alt+N"; 00062 // Menu 00063 m_actionInfo.menu = "File"; 00064 m_actionInfo.menuAfterName = "New"; 00065 m_actionInfo.enabledOnStartup = true; 00066 m_actionInfo.needsNumObjects = -1; 00067 } 00068 00069 const QString NewFromTemplatePlugin::fullTrName() const 00070 { 00071 return QObject::tr("New From Template"); 00072 } 00073 00074 const ScActionPlugin::AboutData* NewFromTemplatePlugin::getAboutData() const 00075 { 00076 AboutData* about = new AboutData; 00077 Q_CHECK_PTR(about); 00078 about->authors = QString::fromUtf8("Riku Leino <riku@scribus.info>"); 00079 about->shortDescription = tr("Load documents with predefined layout"); 00080 about->description = tr("Start a document from a template made by other users or " 00081 "yourself (f.e. for documents you have a constant style)."); 00082 // about->version 00083 // about->releaseDate 00084 // about->copyright 00085 about->license = "GPL"; 00086 return about; 00087 } 00088 00089 void NewFromTemplatePlugin::deleteAboutData(const AboutData* about) const 00090 { 00091 Q_ASSERT(about); 00092 delete about; 00093 } 00094 00095 bool NewFromTemplatePlugin::run(ScribusDoc* doc, QString target) 00096 { 00097 Q_ASSERT(target.isNull()); 00098 Nft = new MenuNFT(); 00099 Q_CHECK_PTR(Nft); 00100 Nft->RunNFTPlug(doc); 00101 return true; 00102 } 00103 00104 00105 void MenuNFT::RunNFTPlug(ScribusDoc* /*doc*/) 00106 { 00107 ScribusMainWindow* mw=ScCore->primaryMainWindow(); 00108 nftdialog* nftdia = new nftdialog(mw, ScCore->getGuiLanguage(), PrefsManager::instance()->appPrefs.documentTemplatesDir); 00109 if (nftdia->exec()) 00110 { 00111 qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); 00112 if (mw->loadDoc(QDir::cleanPath(nftdia->currentDocumentTemplate->file))) 00113 { 00114 mw->doc->hasName = false; 00115 UndoManager::instance()->renameStack(nftdia->currentDocumentTemplate->name); 00116 mw->doc->DocName = nftdia->currentDocumentTemplate->name; 00117 mw->updateActiveWindowCaption(QObject::tr("Document Template: ") + nftdia->currentDocumentTemplate->name); 00118 QDir::setCurrent(PrefsManager::instance()->documentDir()); 00119 mw->removeRecent(QDir::cleanPath(nftdia->currentDocumentTemplate->file)); 00120 } 00121 qApp->restoreOverrideCursor(); 00122 } 00123 delete nftdia; 00124 }
