Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scribuswin.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                           scribuswin.cpp  -  description
00009                              -------------------
00010     begin                : Mit Nov 6 2002
00011     copyright            : (C) 2002 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 #include <qfileinfo.h>
00024 #include <qdir.h>
00025 #include "scribuswin.h"
00026 #include "pageselector.h"
00027 #include "scmessagebox.h"
00028 #include "scribuswin.moc"
00029 #include "fileloader.h"
00030 #include "scribus.h"
00031 #include "story.h"
00032 #include "util.h"
00033 #include "commonstrings.h"
00034 
00035 
00036 
00037 ScribusWin::ScribusWin(QWidget* parent, ScribusDoc* doc) : QMainWindow(parent, "", WDestructiveClose)
00038 {
00039        setIcon(loadIcon("AppIcon2.png"));
00040        m_Doc = doc;
00041        m_masterPagesPalette = NULL;
00042        currentDir = QDir::currentDirPath();
00043 }
00044 
00045 void ScribusWin::setMainWindow(ScribusMainWindow *mw)
00046 {
00047        m_MainWindow=mw;
00048 }
00049 
00050 void ScribusWin::setView(ScribusView* newView)
00051 {
00052        m_View = newView;
00053        ++m_Doc->viewCount;
00054        winIndex = ++m_Doc->viewID;
00055        QPoint point(0,0);
00056        statusFrame = new QFrame(this, "newDocFrame");
00057        statusFrameLayout = new QHBoxLayout( statusFrame, 0, 0, "statusFrame");
00058        m_View->unitSwitcher->reparent(statusFrame, point);
00059        m_View->layerMenu->reparent(statusFrame, point);
00060        m_View->zoomOutToolbarButton->reparent(statusFrame, point);
00061        m_View->zoomDefaultToolbarButton->reparent(statusFrame, point);
00062        m_View->zoomInToolbarButton->reparent(statusFrame, point);
00063        m_View->pageSelector->reparent(statusFrame, point);
00064        m_View->zoomSpinBox->reparent(statusFrame, point);
00065        m_View->cmsToolbarButton->reparent(statusFrame, point);
00066        m_View->previewToolbarButton->reparent(statusFrame, point);
00067        m_View->visualMenu->reparent(statusFrame, point);
00068        statusFrameLayout->addWidget(m_View->unitSwitcher);
00069        statusFrameLayout->addWidget(m_View->zoomSpinBox);
00070        statusFrameLayout->addWidget(m_View->zoomOutToolbarButton);
00071        statusFrameLayout->addWidget(m_View->zoomDefaultToolbarButton);
00072        statusFrameLayout->addWidget(m_View->zoomInToolbarButton);
00073        statusFrameLayout->addWidget(m_View->pageSelector);
00074        statusFrameLayout->addWidget(m_View->layerMenu);
00075        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00076        statusFrameLayout->addItem( spacer );
00077        statusFrameLayout->addWidget(m_View->cmsToolbarButton);
00078        statusFrameLayout->addWidget(m_View->previewToolbarButton);
00079        statusFrameLayout->addWidget(m_View->visualMenu);
00080 #ifndef HAVE_CAIRO
00081        m_View->previewToolbarButton->hide();
00082        m_View->visualMenu->hide();
00083 #endif
00084        statusBar()->addWidget(statusFrame, 4, true);
00085        currentDir = QDir::currentDirPath();
00086 }
00087 
00088 void ScribusWin::slotAutoSave()
00089 {
00090        if ((m_Doc->hasName) && (m_Doc->isModified()))
00091        {
00092               moveFile(m_Doc->DocName, m_Doc->DocName+".bak");
00093               QFileInfo fi(m_Doc->DocName);
00094               QDir::setCurrent(fi.dirPath(true));
00095               FileLoader fl(m_Doc->DocName);
00096               if (fl.SaveFile(m_Doc->DocName, m_Doc, 0))
00097               {
00098                      m_Doc->setModified(false);
00099                      setCaption(QDir::convertSeparators(m_Doc->DocName));
00100                      qApp->processEvents();
00101                      emit AutoSaved();
00102               }
00103        }
00104 }
00105 
00106 void ScribusWin::closeEvent(QCloseEvent *ce)
00107 {
00108        if (m_Doc->isModified() && (m_Doc->viewCount == 1))
00109        {
00110               qApp->setOverrideCursor(QCursor(arrowCursor), true);
00111               int exit=ScMessageBox::information(m_MainWindow, CommonStrings::trWarning, tr("Document:")+" "+
00112                                                                              QDir::convertSeparators(m_Doc->DocName)+"\n"+
00113                                                                              tr("has been changed since the last save."),
00114                                                                              CommonStrings::tr_Save, tr("&Discard"),
00115                                                                              CommonStrings::tr_Cancel, 2, 2);
00116               if (exit==2)
00117                      return;
00118               if (exit==0)
00119               {
00120                      if (m_MainWindow->slotFileSave())
00121                      {
00122                             if (m_Doc==m_MainWindow->storyEditor->currentDocument())
00123                                    m_MainWindow->storyEditor->close();
00124                      }
00125                      else
00126                             return;
00127               }
00128        }
00129        m_MainWindow->DoFileClose();
00130        ce->accept();
00131 }
00132 
00133 void ScribusWin::setMasterPagesPaletteShown(bool isShown) const
00134 {
00135        if (m_masterPagesPalette==NULL)
00136               return;
00137        if (isShown)
00138               m_masterPagesPalette->show();
00139        else
00140               m_masterPagesPalette->hide();
00141 }
00142 
00143 void ScribusWin::windowActivationChange ( bool oldActive )
00144 {
00145        if( isActiveWindow() )
00146               QDir::setCurrent( currentDir );
00147        else
00148               currentDir = QDir::currentDirPath();
00149        QMainWindow::windowActivationChange( oldActive );
00150 }