Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving job files option

  • Loading branch information...
commit a122e55eee8f40526e91aeb7f84d75ffc8283a7f 1 parent d2bff24
@SokoloffA SokoloffA authored
View
1  gui/CMakeLists.txt
@@ -46,7 +46,6 @@ set(SOURCES
)
set (MOCS
- kernel/psfile.h
kernel/psproject.h
mainwindow.h
widgets.h
View
8 gui/kernel/psengine.cpp
@@ -136,7 +136,7 @@ void PsEngine::writeProcSetText(QTextStream *out)
void PsEngine::writePage(const PsProjectPage *page, QTextStream *out)
{
if (page)
- mProject->psFile()->writePageBody(page->begin(), page->end(), out);
+ page->writePage(out);
else
*out << "showpage\n";
}
@@ -222,8 +222,8 @@ void PsEngine::writeDocument(const QList<const PsSheet*> &sheets, QTextStream *o
writeProcSetText(out);
- mProject->psFile()->writeFilePart(mProject->psFile()->prologPos(), out);
- mProject->psFile()->writeFilePart(mProject->psFile()->setupPos(), out);
+ mProject->psFile()->writeProlog(out);
+ mProject->psFile()->writeSetup(out);
int n=1;
foreach(const PsSheet *sheet, sheets)
@@ -231,7 +231,7 @@ void PsEngine::writeDocument(const QList<const PsSheet*> &sheets, QTextStream *o
*out << QString("%%Page: %1\n").arg(n++);
writeSheet(*sheet, out);
}
- mProject->psFile()->writeFilePart(mProject->psFile()->trailerPos(), out);
+ mProject->psFile()->writeTrailer(out);
}
View
136 gui/kernel/psfile.cpp
@@ -34,6 +34,7 @@
#include <ghostscript/iapi.h>
#include <ghostscript/ierrors.h>
+#define EMPTY_PS_PAGE "showpage\n"
/************************************************
@@ -69,10 +70,18 @@ void PsFilePage::setRect(const QRect &value)
/************************************************
************************************************/
-PsFile::PsFile(const QString &fileName, QObject *parent):
- QObject(parent),
+PsFile::PsFile()
+{
+}
+
+
+/************************************************
+
+ ************************************************/
+PsFile::PsFile(const QString &fileName):
mFile(fileName)
{
+ parse();
}
@@ -97,51 +106,45 @@ QString PsFile::fileName() const
/************************************************
************************************************/
-void PsFile::writeFilePart(const PsFilePos &pos, QTextStream *out)
+void PsFile::writeProlog(QTextStream *out) const
{
- writeFilePart(pos.begin, pos.end, out);
+ writeFilePart(mPrologPos.begin, mPrologPos.end, out);
}
/************************************************
************************************************/
-void PsFile::writeFilePart(long begin, long end, QTextStream *out)
+void PsFile::writeSetup(QTextStream *out) const
{
- if (!mFile.isOpen())
- mFile.open(QIODevice::ReadOnly | QIODevice::Text);
-
- if (mFile.isOpen())
- {
- mFile.seek(begin);
- QByteArray buf = mFile.read(end - begin);
- *out << buf;
- }
+ writeFilePart(mSetupPos.begin, mSetupPos.end, out);
}
/************************************************
************************************************/
-void PsFile::writePageBody(const PsFilePos &pos, QTextStream *out)
+void PsFile::writeTrailer(QTextStream *out) const
{
- writePageBody(pos.begin, pos.end, out);
+ writeFilePart(mTrailerPos.begin, mTrailerPos.end, out);
}
/************************************************
************************************************/
-void PsFile::writePageBody(long begin, long end, QTextStream *out)
+void PsFile::writeFilePart(long begin, long end, QTextStream *out) const
{
- mFile.seek(begin);
+ QFile *f = const_cast<QFile*>(&mFile);
+ if (!f->isOpen())
+ f->open(QIODevice::ReadOnly | QIODevice::Text);
- // Skeep %%Page: tag line
- QString s = mFile.readLine();
- qint64 len = end - begin - s.length();
-
- QByteArray buf = mFile.read(len);
- *out << buf;
+ if (f->isOpen())
+ {
+ f->seek(begin);
+ QByteArray buf = f->read(end - begin);
+ *out << buf;
+ }
}
@@ -182,6 +185,7 @@ bool PsFile::parse()
int ly=0;
psgetpagebox(doc, i, &rx, &ry, &lx, &ly);
psPage.setRect(QRect(lx, ly, rx - lx, ry - ly));
+
mPages << psPage;
}
@@ -194,9 +198,10 @@ bool PsFile::parse()
/************************************************
************************************************/
-GsMergeFile::GsMergeFile(const QString &fileName, QObject *parent):
- PsFile(fileName, parent)
+GsMergeFile::GsMergeFile(const QString &fileName):
+ PsFile()
{
+ mFile.setFileName(fileName);
}
@@ -212,8 +217,10 @@ GsMergeFile::~GsMergeFile()
/************************************************
************************************************/
-bool GsMergeFile::merge(const QStringList inputFiles)
+bool GsMergeFile::merge(const QList<PsFile *> inputFiles)
{
+ mMergedFiles.clear();
+
if (inputFiles.isEmpty())
{
mPages.clear();
@@ -222,6 +229,13 @@ bool GsMergeFile::merge(const QStringList inputFiles)
return true;
}
+ int n=0;
+ for (int i=0; i<inputFiles.count(); ++i)
+ {
+ mMergedFiles.insert(inputFiles.at(i), n);
+ n += inputFiles.at(i)->pageCount();
+ }
+
mFile.close();
void *gsInstance;
int gsRes;
@@ -229,7 +243,6 @@ bool GsMergeFile::merge(const QStringList inputFiles)
if (gsRes < 0)
return false;
-
QList<QByteArray> args;
args << "merge";
args << "-q";
@@ -239,7 +252,9 @@ bool GsMergeFile::merge(const QStringList inputFiles)
args << "-sDEVICE=ps2write";
args << QString("-sOutputFile=%1").arg(fileName()).toLocal8Bit();
for (int i=0; i<inputFiles.count(); ++i)
- args << inputFiles.at(i).toLocal8Bit();
+ {
+ args << inputFiles.at(i)->fileName().toLocal8Bit();
+ }
int argc = args.count();
char *argv[100];
@@ -271,11 +286,64 @@ bool GsMergeFile::merge(const QStringList inputFiles)
/************************************************
************************************************/
-bool GsMergeFile::merge(const QList<PsFile *> inputFiles)
+int GsMergeFile::pageIndex(const PsFile *mergedFile, int pageNum) const
{
- QStringList files;
- foreach (PsFile *f, inputFiles)
- files << f->fileName();
+ if (!mMergedFiles.contains(mergedFile))
+ return -1;
+
+ int res = mMergedFiles.value(mergedFile) + pageNum;
+ if (res < mPages.count())
+ return res;
+ else
+ return -1;
+}
+
+
+/************************************************
+
+ ************************************************/
+void GsMergeFile::writePage(const PsFile *mergedFile, int pageNum, QTextStream *out) const
+{
+ int n = pageIndex(mergedFile, pageNum);
+ if (n<0)
+ {
+ *out << EMPTY_PS_PAGE;
+ return;
+ }
+
+ const PsFilePage &page = mPages.at(n);
+
+ QFile *f = const_cast<QFile*>(&mFile);
+ if (!f->isOpen())
+ f->open(QIODevice::ReadOnly | QIODevice::Text);
+
+ if (!f->isOpen())
+ {
+ *out << EMPTY_PS_PAGE;
+ return;
+ }
- return merge(files);
+ f->seek(page.filePos().begin);
+
+ // Skeep %%Page: tag line
+ QString s = f->readLine();
+ qint64 len = page.filePos().end - page.filePos().begin - s.length();
+
+ QByteArray buf = f->read(len);
+ *out << buf;
}
+
+
+/************************************************
+
+ ************************************************/
+QRect GsMergeFile::pageRect(const PsFile *mergedFile, int pageNum) const
+{
+ int n = pageIndex(mergedFile, pageNum);
+
+ if (n>-1)
+ return mPages.at(n).rect();
+ else
+ return QRect();
+}
+
View
34 gui/kernel/psfile.h
@@ -32,6 +32,7 @@
#include <QList>
#include <QFile>
#include <QRect>
+#include <QHash>
class PsFile;
class QTextStream;
@@ -67,11 +68,10 @@ class PsFilePage
};
-class PsFile : public QObject
+class PsFile
{
- Q_OBJECT
public:
- explicit PsFile(const QString &fileName, QObject *parent = 0);
+ explicit PsFile(const QString &fileName);
virtual ~PsFile();
QString fileName() const;
@@ -81,22 +81,19 @@ class PsFile : public QObject
PsFilePage page(int index) { return mPages[index]; }
int pageCount() const { return mPages.count(); }
- PsFilePos prologPos() const { return mPrologPos; }
- PsFilePos setupPos() const { return mSetupPos; }
- PsFilePos trailerPos() const { return mTrailerPos; }
-
- void writeFilePart(const PsFilePos &pos, QTextStream *out);
- void writeFilePart(long begin, long end, QTextStream *out);
-
- void writePageBody(const PsFilePos &pos, QTextStream *out);
- void writePageBody(long begin, long end, QTextStream *out);
-
- bool parse();
+ void writeProlog(QTextStream *out) const;
+ void writeSetup(QTextStream *out) const;
+ void writeTrailer(QTextStream *out) const;
protected:
+ PsFile();
+
QFile mFile;
QList<PsFilePage> mPages;
+ bool parse();
+ void writeFilePart(long begin, long end, QTextStream *out) const;
+
private:
QString mTitle;
PsFilePos mPrologPos;
@@ -107,16 +104,19 @@ class PsFile : public QObject
class GsMergeFile: public PsFile
{
- Q_OBJECT
public:
- GsMergeFile(const QString &fileName, QObject *parent = 0);
+ GsMergeFile(const QString &fileName);
virtual ~GsMergeFile();
- bool merge(const QStringList inputFiles);
bool merge(const QList<PsFile*> inputFiles);
+ void writePage(const PsFile* mergedFile, int pageNum, QTextStream *out) const;
+ QRect pageRect(const PsFile* mergedFile, int pageNum) const;
+
private:
+ QHash<const PsFile*, int> mMergedFiles;
+ int pageIndex(const PsFile* mergedFile, int pageNum) const;
};
#endif // PSFILE_H
View
103 gui/kernel/psproject.cpp
@@ -44,7 +44,7 @@ PsProject::PsProject(QObject *parent) :
mEngine(0),
mPrinter(&mNullPrinter)
{
- mPsFile = new GsMergeFile(QDir::tempPath() + QString("/boomaga_%1.ps").arg(QCoreApplication::applicationPid()), this);
+ mPsFile = new GsMergeFile(QDir::tempPath() + QString("/boomaga_%1.ps").arg(QCoreApplication::applicationPid()));
setLayout(settings->layout());
}
@@ -59,6 +59,7 @@ PsProject::~PsProject()
settings->sync();
qDeleteAll(mPages);
qDeleteAll(mFiles);
+ delete mPsFile;
}
@@ -69,19 +70,17 @@ void PsProject::addFile(QString fileName)
{
emit fileAboutToBeAdded(fileName);
- PsFile *file = new PsFile(fileName, this);
+ PsFile *file = new PsFile(fileName);
mFiles << file;
- file->parse();
qApp->processEvents();
for (int i=0; i<file->pageCount(); ++i)
{
- PsProjectPage *p = new PsProjectPage(file, i);
+ PsProjectPage *p = new PsProjectPage(file, i, this);
mPages << p;
}
mPsFile->merge(mFiles);
- updatePages();
updateSheets();
emit fileAdded(file);
@@ -107,7 +106,6 @@ void PsProject::removeFile(int index)
delete oldFile;
mPsFile->merge(mFiles);
- updatePages();
updateSheets();
emit fileRemoved();
@@ -117,24 +115,35 @@ void PsProject::removeFile(int index)
/************************************************
************************************************/
-void PsProject::updatePages()
+void PsProject::moveFile(int from, int to)
{
- int n=0;
- foreach(const PsFile *f, mFiles)
+ PsFile *movedFile = mFiles.at(from);
+ emit fileAboutToBeMoved(movedFile);
+
+ mFiles.move(from, to);
+
+ int insertIdx = 0;
+ for (int i=0; i<to; ++i)
+ insertIdx+=mFiles.at(i)->pageCount();
+
+
+ QList<PsProjectPage*> movedPages;
+ for(int i=mPages.count()-1; i>-1; --i)
{
- foreach(PsProjectPage *page, mPages)
+ if (mPages.at(i)->file() == movedFile)
{
- if (page->file() == f)
- {
- const PsFilePage &fPage = mPsFile->page(n + page->pageNum());
- page->setBegin(fPage.filePos().begin);
- page->setEnd(fPage.filePos().end);
- page->setRect(fPage.rect());
- }
+ movedPages << mPages.takeAt(i);
}
+ }
- n+=f->pageCount();
+ for(int i=0; i<movedPages.count(); ++i)
+ {
+ mPages.insert(insertIdx, movedPages.at(i));
}
+
+ updateSheets();
+
+ emit fileMoved();
}
@@ -240,6 +249,41 @@ void PsProject::writeDocument(PsProject::PagesType pages, PsProject::PagesOrder
/************************************************
************************************************/
+void PsProject::writeDocument(const QList<const PsSheet *> &sheets, const QString &fileName)
+{
+ QFile f(fileName);
+ f.open(QIODevice::Text | QIODevice::WriteOnly);
+ QTextStream stream(&f);
+ writeDocument(sheets, &stream);
+ f.close();
+}
+
+
+/************************************************
+
+ ************************************************/
+void PsProject::writeDocument(PsProject::PagesType pages, const QString &fileName)
+{
+ writeDocument(pages, ForwardOrder, fileName);
+}
+
+
+/************************************************
+
+ ************************************************/
+void PsProject::writeDocument(PsProject::PagesType pages, PsProject::PagesOrder order, const QString &fileName)
+{
+ QFile f(fileName);
+ f.open(QIODevice::Text | QIODevice::WriteOnly);
+ QTextStream stream(&f);
+ writeDocument(pages, order, &stream);
+ f.close();
+}
+
+
+/************************************************
+
+ ************************************************/
void PsProject::setLayout(PsProject::PsLayout layout)
{
if (!mEngine || mLayout != layout)
@@ -326,11 +370,30 @@ void PsProject::setPrinter(Printer *value)
/************************************************
************************************************/
-PsProjectPage::PsProjectPage(PsFile *file, int pageNum):
+PsProjectPage::PsProjectPage(PsFile *file, int pageNum, PsProject *project):
mFile(file),
- mPageNum(pageNum)
+ mPageNum(pageNum),
+ mProject(project)
+{
+
+}
+
+
+/************************************************
+
+ ************************************************/
+QRect PsProjectPage::rect() const
{
+ return mProject->psFile()->pageRect(mFile, mPageNum);
+}
+
+/************************************************
+
+ ************************************************/
+void PsProjectPage::writePage(QTextStream *out) const
+{
+ mProject->psFile()->writePage(mFile, mPageNum, out);
}
View
33 gui/kernel/psproject.h
@@ -42,6 +42,7 @@ class PsProject : public QObject
{
Q_OBJECT
friend class PsEngine;
+ friend class PsProjectPage;
public:
enum PsLayout
{
@@ -84,6 +85,10 @@ class PsProject : public QObject
void writeDocument(PagesType pages, QTextStream *out);
void writeDocument(PagesType pages, PagesOrder order, QTextStream *out);
+ void writeDocument(const QList<const PsSheet*> &sheets, const QString &fileName);
+ void writeDocument(PagesType pages, const QString &fileName);
+ void writeDocument(PagesType pages, PagesOrder order, const QString &fileName);
+
PsLayout layout() const { return mLayout; }
@@ -97,6 +102,7 @@ class PsProject : public QObject
public slots:
void addFile(QString fileName);
void removeFile(int index);
+ void moveFile(int from, int to);
void setLayout(PsLayout layout);
@@ -106,9 +112,12 @@ public slots:
void fileAdded(const PsFile *file);
void fileAboutToBeRemoved(const PsFile *file);
void fileRemoved();
+ void fileAboutToBeMoved(const PsFile *file);
+ void fileMoved();
+
protected:
- PsFile *psFile() { return mPsFile; }
+ GsMergeFile *psFile() { return mPsFile; }
private:
PsLayout mLayout;
@@ -122,45 +131,33 @@ public slots:
PsEngine *mEngine;
GsMergeFile *mPsFile;
+ Printer mNullPrinter;
- void updatePages();
void updateSheets();
-
- Printer mNullPrinter;
};
class PsProjectPage
{
- friend class PsProject;
public:
- PsProjectPage(PsFile *file, int pageNum);
+ PsProjectPage(PsFile *file, int pageNum, PsProject *project);
PsFile *file() const { return mFile; }
- long begin() const { return mBegin; }
- long end() const { return mEnd; }
-
bool visible() const { return mVisible;}
void setVisible(bool value);
int pageNum() const { return mPageNum; }
- QRect rect() const { return mRect; }
-protected:
- void setBegin(long value) { mBegin = value; }
- void setEnd(long value) { mEnd = value; }
- void setRect(const QRect &value) { mRect = value; }
+ QRect rect() const;
+ void writePage(QTextStream *out) const;
private:
PsFile *mFile;
- long mBegin;
- long mEnd;
bool mVisible;
int mPageNum;
- QRect mRect;
-
+ PsProject *mProject;
};
View
3  gui/mainwindow.cpp
@@ -122,6 +122,9 @@ MainWindow::MainWindow(PsProject *project, QWidget *parent):
connect(mProject, SIGNAL(fileAdded(const PsFile*)), mRender, SLOT(refresh()));
connect(mProject, SIGNAL(fileRemoved()), mRender, SLOT(refresh()));
connect(mProject, SIGNAL(fileRemoved()), this, SLOT(updateCurrentSheet()));
+ connect(mProject, SIGNAL(fileMoved()), mRender, SLOT(refresh()));
+ connect(mProject, SIGNAL(fileMoved()), this, SLOT(updateCurrentSheet()));
+
connect(mRender, SIGNAL(finished()), this, SLOT(updateWidgets()));
View
12 gui/mainwindow.ui
@@ -165,6 +165,18 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="dragEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::InternalMove</enum>
+ </property>
+ <property name="defaultDropAction">
+ <enum>Qt::MoveAction</enum>
+ </property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
View
19 gui/widgets.cpp
@@ -123,6 +123,7 @@ PsFilesListView::PsFilesListView(QWidget *parent):
{
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
+ connect(this->model(), SIGNAL(layoutChanged()), this, SLOT(layoutChanged()));
}
@@ -151,7 +152,7 @@ void PsFilesListView::updateItems()
item->setText(tr("( %1 pages ) ").arg(file->pageCount()) +
(file->title().isEmpty() ? tr("Untitled") : file->title()));
- ;
+
addItem(item);
}
}
@@ -192,7 +193,7 @@ void PsFilesListView::deleteFile()
/************************************************
************************************************/
-void PsFilesListView::mousePressEvent(QMouseEvent *event)
+void PsFilesListView::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
@@ -207,6 +208,20 @@ void PsFilesListView::mousePressEvent(QMouseEvent *event)
}
}
}
+ QListWidget::mouseReleaseEvent(event);
}
+/************************************************
+
+ ************************************************/
+void PsFilesListView::layoutChanged()
+{
+ for (int i=0; i<count()-1; ++i)
+ {
+ int from = item(i)->data(Qt::UserRole).toInt();
+ if (from != i)
+ mProject->moveFile(from, i);
+ }
+}
+
View
3  gui/widgets.h
@@ -89,9 +89,10 @@ private slots:
void updateItems();
void showContextMenu(const QPoint &pos);
void deleteFile();
+ void layoutChanged();
protected:
- void mousePressEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
private:
PsProject *mProject;
Please sign in to comment.
Something went wrong with that request. Please try again.