some missing headers

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 3988bc837f
commit 8511c7ac0e
  1. 16
      plugins/cffadaptor/src/UBCFFAdaptor.cpp
  2. 15
      plugins/cffadaptor/src/UBCFFAdaptor.h
  3. 15
      plugins/cffadaptor/src/UBCFFAdaptor_global.h
  4. 15
      plugins/cffadaptor/src/UBCFFConstants.h
  5. 15
      plugins/cffadaptor/src/UBGlobals.h
  6. 3056
      src/adaptors/UBCFFSubsetAdaptor.cpp
  7. 264
      src/adaptors/UBCFFSubsetAdaptor.h
  8. 534
      src/adaptors/UBImportCFF.cpp
  9. 58
      src/adaptors/UBImportCFF.h
  10. 492
      src/adaptors/UBSvgSubsetAdaptor.h
  11. 332
      src/adaptors/UBThumbnailAdaptor.cpp
  12. 62
      src/adaptors/UBThumbnailAdaptor.h
  13. 1620
      src/adaptors/publishing/UBDocumentPublisher.cpp
  14. 242
      src/adaptors/publishing/UBDocumentPublisher.h
  15. 4992
      src/board/UBBoardController.cpp
  16. 584
      src/board/UBBoardController.h
  17. 1962
      src/board/UBBoardPaletteManager.cpp
  18. 340
      src/board/UBBoardPaletteManager.h
  19. 322
      src/board/UBBoardView.h
  20. 304
      src/core/UBApplication.h
  21. 1634
      src/core/UBApplicationController.cpp
  22. 588
      src/core/UBDocumentManager.cpp
  23. 24
      src/desktop/UBWindowCapture_mac.mm
  24. 250
      src/document/UBDocumentContainer.cpp
  25. 102
      src/document/UBDocumentContainer.h
  26. 3388
      src/document/UBDocumentController.cpp
  27. 266
      src/document/UBDocumentController.h
  28. 438
      src/document/UBDocumentProxy.cpp
  29. 172
      src/document/UBDocumentProxy.h
  30. 1968
      src/domain/UBGraphicsDelegateFrame.cpp
  31. 436
      src/domain/UBGraphicsItemUndoCommand.cpp
  32. 206
      src/domain/UBGraphicsVideoItemDelegate.h
  33. 436
      src/frameworks/UBGeometryUtils.cpp
  34. 72
      src/frameworks/UBGeometryUtils.h
  35. 6
      src/frameworks/UBPlatformUtils_mac.mm
  36. 536
      src/gui/UBDocumentNavigator.cpp
  37. 120
      src/gui/UBDocumentNavigator.h
  38. 604
      src/gui/UBDocumentThumbnailWidget.cpp
  39. 888
      src/gui/UBDocumentTreeWidget.cpp
  40. 1446
      src/gui/UBKeyboardPalette.cpp
  41. 562
      src/gui/UBKeyboardPalette.h
  42. 152
      src/gui/UBKeyboardPalette_win.cpp
  43. 766
      src/gui/UBMagnifer.cpp
  44. 168
      src/gui/UBMagnifer.h
  45. 264
      src/gui/UBNavigatorPalette.cpp
  46. 104
      src/gui/UBNavigatorPalette.h
  47. 318
      src/gui/UBPageNavigationWidget.cpp
  48. 118
      src/gui/UBPageNavigationWidget.h
  49. 1839
      src/gui/UBThumbnailWidget.cpp
  50. 828
      src/gui/UBThumbnailWidget.h
  51. 59
      tools/CrashReportViewer/CrashReporterSymbolSupplier.cpp
  52. 39
      tools/CrashReportViewer/CrashReporterSymbolSupplier.h
  53. 261
      tools/CrashReportViewer/CrashWindow.cpp
  54. 35
      tools/CrashReportViewer/CrashWindow.h
  55. 15
      tools/CrashReportViewer/main.cpp
  56. 15
      tools/pdf2image/core/UBPlatformUtils.cpp
  57. 15
      tools/pdf2image/core/UBPlatformUtils.h
  58. 17
      tools/pdf2image/pdf2image.cpp

@ -3,24 +3,24 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBCFFAdaptor.h"
#include <QtCore>

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/

File diff suppressed because it is too large Load Diff

@ -19,135 +19,135 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBCFFSUBSETADAPTOR_H
#define UBCFFSUBSETADAPTOR_H
#include <QtXml>
#include <QString>
#include <QStack>
#include <QDomDocument>
#include <QHash>
class UBDocumentProxy;
class UBGraphicsScene;
class QSvgGenerator;
class UBGraphicsSvgItem;
class UBGraphicsPixmapItem;
class UBGraphicsItemDelegate;
class QTransform;
class QPainter;
class UBGraphicsItem;
class QGraphicsItem;
class QTextBlockFormat;
class QTextCharFormat;
class QTextCursor;
class UBGraphicsStrokesGroup;
class UBCFFSubsetAdaptor
{
public:
UBCFFSubsetAdaptor();
static bool ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument);
private:
class UBCFFSubsetReader
{
public:
UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content);
~UBCFFSubsetReader();
UBDocumentProxy *mProxy;
QString pwdContent;
bool parse();
private:
QString mTempFilePath;
UBGraphicsScene *mCurrentScene;
QRectF mCurrentSceneRect;
QString mIndent;
QRectF mViewBox;
QRectF mViewPort;
qreal mVBTransFactor;
QPointF mViewBoxCenter;
QSize mSize;
QPointF mShiftVector;
bool mSvgGSectionIsOpened;
UBGraphicsGroupContainerItem *mGSectionContainer;
private:
QDomDocument mDOMdoc;
QDomNode mCurrentDOMElement;
QHash<QString, UBGraphicsItem*> persistedItems;
QMap<QString, QString> mRefToUuidMap;
QDir mTmpFlashDir;
void addItemToGSection(QGraphicsItem *item);
bool hashElements();
void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup);
void hashSvg(QDomNode *parent, QString prefix = "");
void hashSiblingIwbElements(QDomElement *parent, QDomElement *topGroup = 0);
inline void parseSvgSectionAttr(const QDomElement &);
bool parseSvgPage(const QDomElement &parent);
bool parseSvgPageset(const QDomElement &parent);
bool parseSvgElement(const QDomElement &parent);
bool parseIwbMeta(const QDomElement &element);
bool parseSvg(const QDomElement &svgSection);
inline bool parseGSection(const QDomElement &element);
inline bool parseSvgSwitchSection(const QDomElement &element);
inline bool parseSvgRect(const QDomElement &element);
inline bool parseSvgEllipse(const QDomElement &element);
inline bool parseSvgPolygon(const QDomElement &element);
inline bool parseSvgPolyline(const QDomElement &element);
inline bool parseSvgText(const QDomElement &element);
inline bool parseSvgTextarea(const QDomElement &element);
inline bool parseSvgImage(const QDomElement &element);
inline bool parseSvgFlash(const QDomElement &element);
inline bool parseSvgAudio(const QDomElement &element);
inline bool parseSvgVideo(const QDomElement &element);
inline UBGraphicsGroupContainerItem *parseIwbGroup(QDomElement &parent);
inline bool parseIwbElement(QDomElement &element);
inline void parseTSpan(const QDomElement &parent, QPainter &painter
, qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect
, qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic
, int &fontWeight, int &textAlign, QTransform &fontTransform);
inline void parseTSpan(const QDomElement &element, QTextCursor &cursor
, QTextBlockFormat &blockFormat, QTextCharFormat &charFormat);
inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item);
// to kill
inline void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor,
QString &fontFamily, QString &fontStretch, bool &italic,
int &fontWeight, int &textAlign, QTransform &fontTransform);
inline void parseTextAttributes(const QDomElement &element, QFont &font, QColor);
inline void readTextBlockAttr(const QDomElement &element, QTextBlockFormat &format);
inline void readTextCharAttr(const QDomElement &element, QTextCharFormat &format);
//elements parsing methods
bool parseDoc();
bool createNewScene();
bool persistCurrentScene();
bool persistScenes();
// helper methods
void repositionSvgItem(QGraphicsItem *item, qreal width, qreal height,
qreal x, qreal y,
QTransform &transform);
QColor colorFromString(const QString& clrString);
QTransform transformFromString(const QString trString, QGraphicsItem *item = 0);
bool getViewBoxDimenstions(const QString& viewBox);
QSvgGenerator* createSvgGenerator(qreal width, qreal height);
bool getTempFileName();
inline bool strToBool(QString);
bool createTempFlashPath();
};
};
#endif // UBCFFSUBSETADAPTOR_H
#ifndef UBCFFSUBSETADAPTOR_H
#define UBCFFSUBSETADAPTOR_H
#include <QtXml>
#include <QString>
#include <QStack>
#include <QDomDocument>
#include <QHash>
class UBDocumentProxy;
class UBGraphicsScene;
class QSvgGenerator;
class UBGraphicsSvgItem;
class UBGraphicsPixmapItem;
class UBGraphicsItemDelegate;
class QTransform;
class QPainter;
class UBGraphicsItem;
class QGraphicsItem;
class QTextBlockFormat;
class QTextCharFormat;
class QTextCursor;
class UBGraphicsStrokesGroup;
class UBCFFSubsetAdaptor
{
public:
UBCFFSubsetAdaptor();
static bool ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument);
private:
class UBCFFSubsetReader
{
public:
UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content);
~UBCFFSubsetReader();
UBDocumentProxy *mProxy;
QString pwdContent;
bool parse();
private:
QString mTempFilePath;
UBGraphicsScene *mCurrentScene;
QRectF mCurrentSceneRect;
QString mIndent;
QRectF mViewBox;
QRectF mViewPort;
qreal mVBTransFactor;
QPointF mViewBoxCenter;
QSize mSize;
QPointF mShiftVector;
bool mSvgGSectionIsOpened;
UBGraphicsGroupContainerItem *mGSectionContainer;
private:
QDomDocument mDOMdoc;
QDomNode mCurrentDOMElement;
QHash<QString, UBGraphicsItem*> persistedItems;
QMap<QString, QString> mRefToUuidMap;
QDir mTmpFlashDir;
void addItemToGSection(QGraphicsItem *item);
bool hashElements();
void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup);
void hashSvg(QDomNode *parent, QString prefix = "");
void hashSiblingIwbElements(QDomElement *parent, QDomElement *topGroup = 0);
inline void parseSvgSectionAttr(const QDomElement &);
bool parseSvgPage(const QDomElement &parent);
bool parseSvgPageset(const QDomElement &parent);
bool parseSvgElement(const QDomElement &parent);
bool parseIwbMeta(const QDomElement &element);
bool parseSvg(const QDomElement &svgSection);
inline bool parseGSection(const QDomElement &element);
inline bool parseSvgSwitchSection(const QDomElement &element);
inline bool parseSvgRect(const QDomElement &element);
inline bool parseSvgEllipse(const QDomElement &element);
inline bool parseSvgPolygon(const QDomElement &element);
inline bool parseSvgPolyline(const QDomElement &element);
inline bool parseSvgText(const QDomElement &element);
inline bool parseSvgTextarea(const QDomElement &element);
inline bool parseSvgImage(const QDomElement &element);
inline bool parseSvgFlash(const QDomElement &element);
inline bool parseSvgAudio(const QDomElement &element);
inline bool parseSvgVideo(const QDomElement &element);
inline UBGraphicsGroupContainerItem *parseIwbGroup(QDomElement &parent);
inline bool parseIwbElement(QDomElement &element);
inline void parseTSpan(const QDomElement &parent, QPainter &painter
, qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect
, qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic
, int &fontWeight, int &textAlign, QTransform &fontTransform);
inline void parseTSpan(const QDomElement &element, QTextCursor &cursor
, QTextBlockFormat &blockFormat, QTextCharFormat &charFormat);
inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item);
// to kill
inline void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor,
QString &fontFamily, QString &fontStretch, bool &italic,
int &fontWeight, int &textAlign, QTransform &fontTransform);
inline void parseTextAttributes(const QDomElement &element, QFont &font, QColor);
inline void readTextBlockAttr(const QDomElement &element, QTextBlockFormat &format);
inline void readTextCharAttr(const QDomElement &element, QTextCharFormat &format);
//elements parsing methods
bool parseDoc();
bool createNewScene();
bool persistCurrentScene();
bool persistScenes();
// helper methods
void repositionSvgItem(QGraphicsItem *item, qreal width, qreal height,
qreal x, qreal y,
QTransform &transform);
QColor colorFromString(const QString& clrString);
QTransform transformFromString(const QString trString, QGraphicsItem *item = 0);
bool getViewBoxDimenstions(const QString& viewBox);
QSvgGenerator* createSvgGenerator(qreal width, qreal height);
bool getTempFileName();
inline bool strToBool(QString);
bool createTempFlashPath();
};
};
#endif // UBCFFSUBSETADAPTOR_H

@ -19,270 +19,270 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDir>
#include <QList>
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBDocumentManager.h"
#include "core/UBPersistenceManager.h"
#include "document/UBDocumentProxy.h"
#include "domain/UBGraphicsPDFItem.h"
#include "frameworks/UBFileSystemUtils.h"
#include "pdf/PDFRenderer.h"
#include "UBCFFSubsetAdaptor.h"
#include "UBImportCFF.h"
#include "globals/UBGlobals.h"
THIRD_PARTY_WARNINGS_DISABLE
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
THIRD_PARTY_WARNINGS_ENABLE
#include "core/memcheck.h"
UBImportCFF::UBImportCFF(QObject *parent)
: UBDocumentBasedImportAdaptor(parent)
{
// NOOP
}
UBImportCFF::~UBImportCFF()
{
// NOOP
}
QStringList UBImportCFF::supportedExtentions()
{
return QStringList("iwb");
}
QString UBImportCFF::importFileFilter()
{
QString filter = tr("Common File Format (");
QStringList formats = supportedExtentions();
bool isFirst = true;
foreach(QString format, formats)
{
if(isFirst)
isFirst = false;
else
filter.append(" ");
filter.append("*."+format);
}
filter.append(")");
return filter;
}
bool UBImportCFF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile)
{
QFileInfo fi(pFile);
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true);
// first unzip the file to the correct place
//TODO create temporary path for iwb file content
QString path = QDir::tempPath();
QString documentRootFolder = expandFileToDir(pFile, path);
QString contentFile;
if (documentRootFolder.isEmpty()) //if file has failed to unzip it is probably just xml file
contentFile = pFile.fileName();
else //get path to content xml (according to iwbcff specification)
contentFile = documentRootFolder.append("/content.xml");
if(!contentFile.length()){
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return false;
}
else{
//TODO convert expanded CFF file content to the destination document
//create destination document proxy
//fill metadata and save
UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath());
QDir dir;
dir.mkdir(destDocument->persistencePath());
//try to import cff to document
if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument))
{
UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(destDocument->persistencePath(), pDocument);
UBFileSystemUtils::deleteDir(destDocument->persistencePath());
delete destDocument;
UBApplication::showMessage(tr("Import successful."));
return true;
}
else
{
UBFileSystemUtils::deleteDir(destDocument->persistencePath());
delete destDocument;
UBApplication::showMessage(tr("Import failed."));
return false;
}
}
}
QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir)
{
QuaZip zip(pZipFile.fileName());
if(!zip.open(QuaZip::mdUnzip)) {
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError();
return "";
}
zip.setFileNameCodec("UTF-8");
QuaZipFileInfo info;
QuaZipFile file(&zip);
//create unique cff document root fodler
//use current date/time and temp number for folder name
QString documentRootFolder;
int tmpNumber = 0;
QDir rootDir;
while (true) {
QString tempPath = QString("%1/sank%2.%3")
.arg(pDir)
.arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm"))
.arg(tmpNumber);
if (!rootDir.exists(tempPath)) {
documentRootFolder = tempPath;
break;
}
tmpNumber++;
if (tmpNumber == 100000) {
qWarning() << "Import failed. Failed to create temporary directory for iwb file";
return "";
}
}
if (!rootDir.mkdir(documentRootFolder)) {
qWarning() << "Import failed. Couse: failed to create temp folder for cff package";
}
QFile out;
char c;
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
if(!zip.getCurrentFileInfo(&info)) {
//TOD UB 4.3 O display error to user or use crash reporter
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
return "";
}
// if(!file.open(QIODevice::ReadOnly)) {
// qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
// return "";
// }
file.open(QIODevice::ReadOnly);
if(file.getZipError()!= UNZ_OK) {
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError();
return "";
}
QString newFileName = documentRootFolder + "/" + file.getActualFileName();
QFileInfo newFileInfo(newFileName);
rootDir.mkpath(newFileInfo.absolutePath());
out.setFileName(newFileName);
out.open(QIODevice::WriteOnly);
while(file.getChar(&c))
out.putChar(c);
out.close();
if(file.getZipError()!=UNZ_OK) {
qWarning() << "Import failed. Cause: " << zip.getZipError();
return "";
}
if(!file.atEnd()) {
qWarning() << "Import failed. Cause: read all but not EOF";
return "";
}
file.close();
if(file.getZipError()!=UNZ_OK) {
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError();
return "";
}
}
zip.close();
if(zip.getZipError()!=UNZ_OK) {
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
return "";
}
return documentRootFolder;
}
UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup)
{
Q_UNUSED(pGroup); // group is defined in the imported file
QFileInfo fi(pFile);
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true);
// first unzip the file to the correct place
//TODO create temporary path for iwb file content
QString path = QDir::tempPath();
QString documentRootFolder = expandFileToDir(pFile, path);
QString contentFile;
if (documentRootFolder.isEmpty())
//if file has failed to umzip it is probably just xml file
contentFile = pFile.fileName();
else
//get path to content xml
contentFile = QString("%1/content.xml").arg(documentRootFolder);
if(!contentFile.length()){
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return 0;
}
else{
//create destination document proxy
//fill metadata and save
UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath());
QDir dir;
dir.mkdir(destDocument->persistencePath());
if (pGroup.length() > 0)
destDocument->setMetaData(UBSettings::documentGroupName, pGroup);
if (fi.baseName() > 0)
destDocument->setMetaData(UBSettings::documentName, fi.baseName());
destDocument->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion);
destDocument->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBDocumentProxy* newDocument = NULL;
//try to import cff to document
if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument))
{
newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(destDocument->persistencePath());
UBApplication::showMessage(tr("Import successful."));
}
else
{
UBFileSystemUtils::deleteDir(destDocument->persistencePath());
UBApplication::showMessage(tr("Import failed."));
}
delete destDocument;
if (documentRootFolder.length() != 0)
UBFileSystemUtils::deleteDir(documentRootFolder);
return newDocument;
}
}
#include <QDir>
#include <QList>
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBDocumentManager.h"
#include "core/UBPersistenceManager.h"
#include "document/UBDocumentProxy.h"
#include "domain/UBGraphicsPDFItem.h"
#include "frameworks/UBFileSystemUtils.h"
#include "pdf/PDFRenderer.h"
#include "UBCFFSubsetAdaptor.h"
#include "UBImportCFF.h"
#include "globals/UBGlobals.h"
THIRD_PARTY_WARNINGS_DISABLE
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
THIRD_PARTY_WARNINGS_ENABLE
#include "core/memcheck.h"
UBImportCFF::UBImportCFF(QObject *parent)
: UBDocumentBasedImportAdaptor(parent)
{
// NOOP
}
UBImportCFF::~UBImportCFF()
{
// NOOP
}
QStringList UBImportCFF::supportedExtentions()
{
return QStringList("iwb");
}
QString UBImportCFF::importFileFilter()
{
QString filter = tr("Common File Format (");
QStringList formats = supportedExtentions();
bool isFirst = true;
foreach(QString format, formats)
{
if(isFirst)
isFirst = false;
else
filter.append(" ");
filter.append("*."+format);
}
filter.append(")");
return filter;
}
bool UBImportCFF::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile)
{
QFileInfo fi(pFile);
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true);
// first unzip the file to the correct place
//TODO create temporary path for iwb file content
QString path = QDir::tempPath();
QString documentRootFolder = expandFileToDir(pFile, path);
QString contentFile;
if (documentRootFolder.isEmpty()) //if file has failed to unzip it is probably just xml file
contentFile = pFile.fileName();
else //get path to content xml (according to iwbcff specification)
contentFile = documentRootFolder.append("/content.xml");
if(!contentFile.length()){
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return false;
}
else{
//TODO convert expanded CFF file content to the destination document
//create destination document proxy
//fill metadata and save
UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath());
QDir dir;
dir.mkdir(destDocument->persistencePath());
//try to import cff to document
if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument))
{
UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(destDocument->persistencePath(), pDocument);
UBFileSystemUtils::deleteDir(destDocument->persistencePath());
delete destDocument;
UBApplication::showMessage(tr("Import successful."));
return true;
}
else
{
UBFileSystemUtils::deleteDir(destDocument->persistencePath());
delete destDocument;
UBApplication::showMessage(tr("Import failed."));
return false;
}
}
}
QString UBImportCFF::expandFileToDir(const QFile& pZipFile, const QString& pDir)
{
QuaZip zip(pZipFile.fileName());
if(!zip.open(QuaZip::mdUnzip)) {
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError();
return "";
}
zip.setFileNameCodec("UTF-8");
QuaZipFileInfo info;
QuaZipFile file(&zip);
//create unique cff document root fodler
//use current date/time and temp number for folder name
QString documentRootFolder;
int tmpNumber = 0;
QDir rootDir;
while (true) {
QString tempPath = QString("%1/sank%2.%3")
.arg(pDir)
.arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm"))
.arg(tmpNumber);
if (!rootDir.exists(tempPath)) {
documentRootFolder = tempPath;
break;
}
tmpNumber++;
if (tmpNumber == 100000) {
qWarning() << "Import failed. Failed to create temporary directory for iwb file";
return "";
}
}
if (!rootDir.mkdir(documentRootFolder)) {
qWarning() << "Import failed. Couse: failed to create temp folder for cff package";
}
QFile out;
char c;
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
if(!zip.getCurrentFileInfo(&info)) {
//TOD UB 4.3 O display error to user or use crash reporter
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
return "";
}
// if(!file.open(QIODevice::ReadOnly)) {
// qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
// return "";
// }
file.open(QIODevice::ReadOnly);
if(file.getZipError()!= UNZ_OK) {
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError();
return "";
}
QString newFileName = documentRootFolder + "/" + file.getActualFileName();
QFileInfo newFileInfo(newFileName);
rootDir.mkpath(newFileInfo.absolutePath());
out.setFileName(newFileName);
out.open(QIODevice::WriteOnly);
while(file.getChar(&c))
out.putChar(c);
out.close();
if(file.getZipError()!=UNZ_OK) {
qWarning() << "Import failed. Cause: " << zip.getZipError();
return "";
}
if(!file.atEnd()) {
qWarning() << "Import failed. Cause: read all but not EOF";
return "";
}
file.close();
if(file.getZipError()!=UNZ_OK) {
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError();
return "";
}
}
zip.close();
if(zip.getZipError()!=UNZ_OK) {
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
return "";
}
return documentRootFolder;
}
UBDocumentProxy* UBImportCFF::importFile(const QFile& pFile, const QString& pGroup)
{
Q_UNUSED(pGroup); // group is defined in the imported file
QFileInfo fi(pFile);
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true);
// first unzip the file to the correct place
//TODO create temporary path for iwb file content
QString path = QDir::tempPath();
QString documentRootFolder = expandFileToDir(pFile, path);
QString contentFile;
if (documentRootFolder.isEmpty())
//if file has failed to umzip it is probably just xml file
contentFile = pFile.fileName();
else
//get path to content xml
contentFile = QString("%1/content.xml").arg(documentRootFolder);
if(!contentFile.length()){
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName()));
return 0;
}
else{
//create destination document proxy
//fill metadata and save
UBDocumentProxy* destDocument = new UBDocumentProxy(UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath());
QDir dir;
dir.mkdir(destDocument->persistencePath());
if (pGroup.length() > 0)
destDocument->setMetaData(UBSettings::documentGroupName, pGroup);
if (fi.baseName() > 0)
destDocument->setMetaData(UBSettings::documentName, fi.baseName());
destDocument->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion);
destDocument->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBDocumentProxy* newDocument = NULL;
//try to import cff to document
if (UBCFFSubsetAdaptor::ConvertCFFFileToUbz(contentFile, destDocument))
{
newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(destDocument->persistencePath());
UBApplication::showMessage(tr("Import successful."));
}
else
{
UBFileSystemUtils::deleteDir(destDocument->persistencePath());
UBApplication::showMessage(tr("Import failed."));
}
delete destDocument;
if (documentRootFolder.length() != 0)
UBFileSystemUtils::deleteDir(documentRootFolder);
return newDocument;
}
}

@ -19,32 +19,32 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBIMPORTCFF_H
#define UBIMPORTCFF_H
#include <QtGui>
#include "UBImportAdaptor.h"
class UBDocumentProxy;
class UBImportCFF : public UBDocumentBasedImportAdaptor
{
Q_OBJECT;
public:
UBImportCFF(QObject *parent = 0);
virtual ~UBImportCFF();
virtual QStringList supportedExtentions();
virtual QString importFileFilter();
virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile);
virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup);
private:
QString expandFileToDir(const QFile& pZipFile, const QString& pDir);
};
#endif // UBIMPORTCFF_H
#ifndef UBIMPORTCFF_H
#define UBIMPORTCFF_H
#include <QtGui>
#include "UBImportAdaptor.h"
class UBDocumentProxy;
class UBImportCFF : public UBDocumentBasedImportAdaptor
{
Q_OBJECT;
public:
UBImportCFF(QObject *parent = 0);
virtual ~UBImportCFF();
virtual QStringList supportedExtentions();
virtual QString importFileFilter();
virtual bool addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile);
virtual UBDocumentProxy* importFile(const QFile& pFile, const QString& pGroup);
private:
QString expandFileToDir(const QFile& pZipFile, const QString& pDir);
};
#endif // UBIMPORTCFF_H

@ -19,249 +19,249 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBSVGSUBSETADAPTOR_H_
#define UBSVGSUBSETADAPTOR_H_
#include <QtGui>
#include <QtXml>
#include "frameworks/UBGeometryUtils.h"
class UBGraphicsSvgItem;
class UBGraphicsPolygonItem;
class UBGraphicsPixmapItem;
class UBGraphicsPDFItem;
class UBGraphicsWidgetItem;
class UBGraphicsMediaItem;
class UBGraphicsAppleWidgetItem;
class UBGraphicsW3CWidgetItem;
class UBGraphicsTextItem;
class UBGraphicsCurtainItem;
class UBGraphicsRuler;
class UBGraphicsCompass;
class UBGraphicsProtractor;
class UBGraphicsScene;
class UBDocumentProxy;
class UBGraphicsStroke;
class UBPersistenceManager;
class UBGraphicsTriangle;
class UBGraphicsCache;
class IDataStorage;
class UBGraphicsGroupContainerItem;
class UBGraphicsStrokesGroup;
class UBSvgSubsetAdaptor
{
private:
UBSvgSubsetAdaptor() {;}
virtual ~UBSvgSubsetAdaptor() {;}
public:
static UBGraphicsScene* loadScene(UBDocumentProxy* proxy, const int pageIndex);
static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
static void upgradeScene(UBDocumentProxy* proxy, const int pageIndex);
static QUuid sceneUuid(UBDocumentProxy* proxy, const int pageIndex);
static void setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid);
static bool addElementToBeStored(QString domName,IDataStorage* dataStorageClass);
static void convertPDFObjectsToImages(UBDocumentProxy* proxy);
static void convertSvgImagesToImages(UBDocumentProxy* proxy);
static QMap<QString,IDataStorage*> getAdditionalElementToStore() { return additionalElementToStore;}
static const QString nsSvg;
static const QString nsXLink;
static const QString nsXHtml;
static const QString nsUb;
static const QString xmlTrue;
static const QString xmlFalse;
static const QString sFontSizePrefix;
static const QString sPixelUnit;
static const QString sFontWeightPrefix;
static const QString sFontStylePrefix;
static QString readTeacherGuideNode(int sceneIndex);
private:
static UBGraphicsScene* loadScene(UBDocumentProxy* proxy, const QByteArray& pArray);
static QDomDocument loadSceneDocument(UBDocumentProxy* proxy, const int pPageIndex);
static QString uniboardDocumentNamespaceUriFromVersion(int fileVersion);
static const QString sFormerUniboardDocumentNamespaceUri;
static QString toSvgTransform(const QMatrix& matrix);
static QMatrix fromSvgTransform(const QString& transform);
static QMap<QString,IDataStorage*> additionalElementToStore;
class UBSvgSubsetReader
{
public:
UBSvgSubsetReader(UBDocumentProxy* proxy, const QByteArray& pXmlData);
virtual ~UBSvgSubsetReader(){}
UBGraphicsScene* loadScene();
private:
UBGraphicsPolygonItem* polygonItemFromLineSvg(const QColor& pDefaultBrushColor);
UBGraphicsPolygonItem* polygonItemFromPolygonSvg(const QColor& pDefaultBrushColor);
QList<UBGraphicsPolygonItem*> polygonItemsFromPolylineSvg(const QColor& pDefaultColor);
UBGraphicsPixmapItem* pixmapItemFromSvg();
UBGraphicsSvgItem* svgItemFromSvg();
UBGraphicsPDFItem* pdfItemFromPDF();
UBGraphicsMediaItem* videoItemFromSvg();
UBGraphicsMediaItem* audioItemFromSvg();
UBGraphicsAppleWidgetItem* graphicsAppleWidgetFromSvg();
UBGraphicsW3CWidgetItem* graphicsW3CWidgetFromSvg();
UBGraphicsTextItem* textItemFromSvg();
UBGraphicsCurtainItem* curtainItemFromSvg();
UBGraphicsRuler* rulerFromSvg();
UBGraphicsCompass* compassFromSvg();
UBGraphicsProtractor* protractorFromSvg();
UBGraphicsTriangle* triangleFromSvg();
UBGraphicsCache* cacheFromSvg();
void readGroupRoot();
QGraphicsItem *readElementFromGroup();
UBGraphicsGroupContainerItem* readGroup();
void graphicsItemFromSvg(QGraphicsItem* gItem);
qreal getZValueFromSvg();
QUuid getUuidFromSvg();
QXmlStreamReader mXmlReader;
int mFileVersion;
UBDocumentProxy *mProxy;
QString mDocumentPath;
QColor mGroupDarkBackgroundColor;
QColor mGroupLightBackgroundColor;
qreal mGroupZIndex;
bool mGroupHasInfo;
QString mNamespaceUri;
UBGraphicsScene *mScene;
QMap<QString,UBGraphicsStrokesGroup*> mStrokesList;
};
class UBSvgSubsetWriter
{
public:
UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
bool persistScene(int pageIndex);
virtual ~UBSvgSubsetWriter(){}
private:
void persistGroupToDom(QGraphicsItem *groupItem, QDomElement *curParent, QDomDocument *curDomDocument);
void persistStrokeToDom(QGraphicsItem *strokeItem, QDomElement *curParent, QDomDocument *curDomDocument);
void polygonItemToSvgPolygon(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void strokeToSvgPolyline(UBGraphicsStroke* stroke, bool groupHoldsInfo);
void strokeToSvgPolygon(UBGraphicsStroke* stroke, bool groupHoldsInfo);
inline QString pointsToSvgPointsAttribute(QVector<QPointF> points)
{
UBGeometryUtils::crashPointList(points);
int pointsCount = points.size();
QString svgPoints;
int length = 0;
QString sBuf;
for(int j = 0; j < pointsCount; j++)
{
sBuf = "%1,%2 ";
const QPointF & point = points.at(j);
QString temp1 = "%1", temp2 = "%2";
temp1 = temp1.arg(point.x());
temp2 = temp2.arg(point.y());
QLocale loc(QLocale::C);
sBuf = sBuf.arg(loc.toFloat(temp1)).arg(loc.toFloat(temp2));
svgPoints.insert(length, sBuf);
length += sBuf.length();
}
return svgPoints;
}
inline qreal trickAlpha(qreal alpha)
{
qreal trickAlpha = alpha;
if(trickAlpha >= 0.2 && trickAlpha < 0.6){
trickAlpha /= 5;
}else if (trickAlpha < 0.8)
trickAlpha /= 3;
return trickAlpha;
}
void pixmapItemToLinkedImage(UBGraphicsPixmapItem *pixmapItem);
void svgItemToLinkedSvg(UBGraphicsSvgItem *svgItem);
void pdfItemToLinkedPDF(UBGraphicsPDFItem *pdfItem);
void videoItemToLinkedVideo(UBGraphicsMediaItem *videoItem);
void audioItemToLinkedAudio(UBGraphicsMediaItem *audioItem);
void graphicsItemToSvg(QGraphicsItem *item);
void graphicsAppleWidgetToSvg(UBGraphicsAppleWidgetItem *item);
void graphicsW3CWidgetToSvg(UBGraphicsW3CWidgetItem *item);
void graphicsWidgetToSvg(UBGraphicsWidgetItem *item);
void textItemToSvg(UBGraphicsTextItem *item);
void curtainItemToSvg(UBGraphicsCurtainItem *item);
void rulerToSvg(UBGraphicsRuler *item);
void compassToSvg(UBGraphicsCompass *item);
void protractorToSvg(UBGraphicsProtractor *item);
void cacheToSvg(UBGraphicsCache* item);
void triangleToSvg(UBGraphicsTriangle *item);
void writeSvgElement();
private:
UBGraphicsScene* mScene;
QXmlStreamWriter mXmlWriter;
QString mDocumentPath;
int mPageIndex;
};
};
#endif /* UBSVGSUBSETADAPTOR_H_ */
#ifndef UBSVGSUBSETADAPTOR_H_
#define UBSVGSUBSETADAPTOR_H_
#include <QtGui>
#include <QtXml>
#include "frameworks/UBGeometryUtils.h"
class UBGraphicsSvgItem;
class UBGraphicsPolygonItem;
class UBGraphicsPixmapItem;
class UBGraphicsPDFItem;
class UBGraphicsWidgetItem;
class UBGraphicsMediaItem;
class UBGraphicsAppleWidgetItem;
class UBGraphicsW3CWidgetItem;
class UBGraphicsTextItem;
class UBGraphicsCurtainItem;
class UBGraphicsRuler;
class UBGraphicsCompass;
class UBGraphicsProtractor;
class UBGraphicsScene;
class UBDocumentProxy;
class UBGraphicsStroke;
class UBPersistenceManager;
class UBGraphicsTriangle;
class UBGraphicsCache;
class IDataStorage;
class UBGraphicsGroupContainerItem;
class UBGraphicsStrokesGroup;
class UBSvgSubsetAdaptor
{
private:
UBSvgSubsetAdaptor() {;}
virtual ~UBSvgSubsetAdaptor() {;}
public:
static UBGraphicsScene* loadScene(UBDocumentProxy* proxy, const int pageIndex);
static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
static void upgradeScene(UBDocumentProxy* proxy, const int pageIndex);
static QUuid sceneUuid(UBDocumentProxy* proxy, const int pageIndex);
static void setSceneUuid(UBDocumentProxy* proxy, const int pageIndex, QUuid pUuid);
static bool addElementToBeStored(QString domName,IDataStorage* dataStorageClass);
static void convertPDFObjectsToImages(UBDocumentProxy* proxy);
static void convertSvgImagesToImages(UBDocumentProxy* proxy);
static QMap<QString,IDataStorage*> getAdditionalElementToStore() { return additionalElementToStore;}
static const QString nsSvg;
static const QString nsXLink;
static const QString nsXHtml;
static const QString nsUb;
static const QString xmlTrue;
static const QString xmlFalse;
static const QString sFontSizePrefix;
static const QString sPixelUnit;
static const QString sFontWeightPrefix;
static const QString sFontStylePrefix;
static QString readTeacherGuideNode(int sceneIndex);
private:
static UBGraphicsScene* loadScene(UBDocumentProxy* proxy, const QByteArray& pArray);
static QDomDocument loadSceneDocument(UBDocumentProxy* proxy, const int pPageIndex);
static QString uniboardDocumentNamespaceUriFromVersion(int fileVersion);
static const QString sFormerUniboardDocumentNamespaceUri;
static QString toSvgTransform(const QMatrix& matrix);
static QMatrix fromSvgTransform(const QString& transform);
static QMap<QString,IDataStorage*> additionalElementToStore;
class UBSvgSubsetReader
{
public:
UBSvgSubsetReader(UBDocumentProxy* proxy, const QByteArray& pXmlData);
virtual ~UBSvgSubsetReader(){}
UBGraphicsScene* loadScene();
private:
UBGraphicsPolygonItem* polygonItemFromLineSvg(const QColor& pDefaultBrushColor);
UBGraphicsPolygonItem* polygonItemFromPolygonSvg(const QColor& pDefaultBrushColor);
QList<UBGraphicsPolygonItem*> polygonItemsFromPolylineSvg(const QColor& pDefaultColor);
UBGraphicsPixmapItem* pixmapItemFromSvg();
UBGraphicsSvgItem* svgItemFromSvg();
UBGraphicsPDFItem* pdfItemFromPDF();
UBGraphicsMediaItem* videoItemFromSvg();
UBGraphicsMediaItem* audioItemFromSvg();
UBGraphicsAppleWidgetItem* graphicsAppleWidgetFromSvg();
UBGraphicsW3CWidgetItem* graphicsW3CWidgetFromSvg();
UBGraphicsTextItem* textItemFromSvg();
UBGraphicsCurtainItem* curtainItemFromSvg();
UBGraphicsRuler* rulerFromSvg();
UBGraphicsCompass* compassFromSvg();
UBGraphicsProtractor* protractorFromSvg();
UBGraphicsTriangle* triangleFromSvg();
UBGraphicsCache* cacheFromSvg();
void readGroupRoot();
QGraphicsItem *readElementFromGroup();
UBGraphicsGroupContainerItem* readGroup();
void graphicsItemFromSvg(QGraphicsItem* gItem);
qreal getZValueFromSvg();
QUuid getUuidFromSvg();
QXmlStreamReader mXmlReader;
int mFileVersion;
UBDocumentProxy *mProxy;
QString mDocumentPath;
QColor mGroupDarkBackgroundColor;
QColor mGroupLightBackgroundColor;
qreal mGroupZIndex;
bool mGroupHasInfo;
QString mNamespaceUri;
UBGraphicsScene *mScene;
QMap<QString,UBGraphicsStrokesGroup*> mStrokesList;
};
class UBSvgSubsetWriter
{
public:
UBSvgSubsetWriter(UBDocumentProxy* proxy, UBGraphicsScene* pScene, const int pageIndex);
bool persistScene(int pageIndex);
virtual ~UBSvgSubsetWriter(){}
private:
void persistGroupToDom(QGraphicsItem *groupItem, QDomElement *curParent, QDomDocument *curDomDocument);
void persistStrokeToDom(QGraphicsItem *strokeItem, QDomElement *curParent, QDomDocument *curDomDocument);
void polygonItemToSvgPolygon(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void strokeToSvgPolyline(UBGraphicsStroke* stroke, bool groupHoldsInfo);
void strokeToSvgPolygon(UBGraphicsStroke* stroke, bool groupHoldsInfo);
inline QString pointsToSvgPointsAttribute(QVector<QPointF> points)
{
UBGeometryUtils::crashPointList(points);
int pointsCount = points.size();
QString svgPoints;
int length = 0;
QString sBuf;
for(int j = 0; j < pointsCount; j++)
{
sBuf = "%1,%2 ";
const QPointF & point = points.at(j);
QString temp1 = "%1", temp2 = "%2";
temp1 = temp1.arg(point.x());
temp2 = temp2.arg(point.y());
QLocale loc(QLocale::C);
sBuf = sBuf.arg(loc.toFloat(temp1)).arg(loc.toFloat(temp2));
svgPoints.insert(length, sBuf);
length += sBuf.length();
}
return svgPoints;
}
inline qreal trickAlpha(qreal alpha)
{
qreal trickAlpha = alpha;
if(trickAlpha >= 0.2 && trickAlpha < 0.6){
trickAlpha /= 5;
}else if (trickAlpha < 0.8)
trickAlpha /= 3;
return trickAlpha;
}
void pixmapItemToLinkedImage(UBGraphicsPixmapItem *pixmapItem);
void svgItemToLinkedSvg(UBGraphicsSvgItem *svgItem);
void pdfItemToLinkedPDF(UBGraphicsPDFItem *pdfItem);
void videoItemToLinkedVideo(UBGraphicsMediaItem *videoItem);
void audioItemToLinkedAudio(UBGraphicsMediaItem *audioItem);
void graphicsItemToSvg(QGraphicsItem *item);
void graphicsAppleWidgetToSvg(UBGraphicsAppleWidgetItem *item);
void graphicsW3CWidgetToSvg(UBGraphicsW3CWidgetItem *item);
void graphicsWidgetToSvg(UBGraphicsWidgetItem *item);
void textItemToSvg(UBGraphicsTextItem *item);
void curtainItemToSvg(UBGraphicsCurtainItem *item);
void rulerToSvg(UBGraphicsRuler *item);
void compassToSvg(UBGraphicsCompass *item);
void protractorToSvg(UBGraphicsProtractor *item);
void cacheToSvg(UBGraphicsCache* item);
void triangleToSvg(UBGraphicsTriangle *item);
void writeSvgElement();
private:
UBGraphicsScene* mScene;
QXmlStreamWriter mXmlWriter;
QString mDocumentPath;
int mPageIndex;
};
};
#endif /* UBSVGSUBSETADAPTOR_H_ */

@ -19,169 +19,169 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBThumbnailAdaptor.h"
#include <QtCore>
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBPersistenceManager.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "gui/UBDockTeacherGuideWidget.h"
#include "gui/UBTeacherGuideWidget.h"
#include "board/UBBoardController.h"
#include "board/UBBoardPaletteManager.h"
#include "document/UBDocumentProxy.h"
#include "domain/UBGraphicsScene.h"
#include "UBSvgSubsetAdaptor.h"
#include "core/memcheck.h"
void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy)
{
int existingPageCount = proxy->pageCount();
for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo)
{
QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo);
QFile thumbFile(thumbFileName);
if (!thumbFile.exists())
{
bool displayMessage = (existingPageCount > 5);
int thumbCount = 0;
UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, iPageNo);
if (scene)
{
thumbCount++;
if (displayMessage && thumbCount == 1)
UBApplication::showMessage(tr("Generating preview thumbnails ..."));
persistScene(proxy, scene, iPageNo);
}
if (displayMessage && thumbCount > 0)
UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount));
}
}
}
const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex)
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
QFile file(fileName);
if (!file.exists())
{
generateMissingThumbnails(proxy);
}
QPixmap* pix = new QPixmap();
if (file.exists())
{
//Warning. Works only with modified Qt
#ifdef Q_WS_X11
pix->load(fileName, 0, Qt::AutoColor);
#else
pix->load(fileName, 0, Qt::AutoColor, false);
#endif
}
return pix;
}
void UBThumbnailAdaptor::updateDocumentToHandleZeroPage(UBDocumentProxy* proxy)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", 0);
QFile file(fileName);
if(!file.exists()){
UBPersistenceManager::persistenceManager()->persistDocumentScene(proxy,new UBGraphicsScene(proxy),0);
}
}
}
void UBThumbnailAdaptor::load(UBDocumentProxy* proxy, QList<const QPixmap*>& list)
{
updateDocumentToHandleZeroPage(proxy);
generateMissingThumbnails(proxy);
foreach(const QPixmap* pm, list)
delete pm;
list.clear();
for(int i=0; i<proxy->pageCount(); i++)
list.append(get(proxy, i));
}
void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified)
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
QFile thumbFile(fileName);
if (pScene->isModified() || overrideModified || !thumbFile.exists() || UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified())
{
qreal nominalWidth = pScene->nominalSize().width();
qreal nominalHeight = pScene->nominalSize().height();
qreal ratio = nominalWidth / nominalHeight;
QRectF sceneRect = pScene->normalizedSceneRect(ratio);
qreal width = UBSettings::maxThumbnailWidth;
qreal height = width / ratio;
QImage thumb(width, height, QImage::Format_ARGB32);
QRectF imageRect(0, 0, width, height);
QPainter painter(&thumb);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
if (pScene->isDarkBackground())
{
painter.fillRect(imageRect, Qt::black);
}
else
{
painter.fillRect(imageRect, Qt::white);
}
pScene->setRenderingContext(UBGraphicsScene::NonScreen);
pScene->setRenderingQuality(UBItem::RenderingQualityHigh);
pScene->render(&painter, imageRect, sceneRect, Qt::KeepAspectRatio);
if(UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified()){
QPixmap toque(":images/toque.svg");
painter.setOpacity(0.6);
painter.drawPixmap(QPoint(width - toque.width(),0),toque);
}
pScene->setRenderingContext(UBGraphicsScene::Screen);
pScene->setRenderingQuality(UBItem::RenderingQualityNormal);
thumb.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(fileName, "JPG");
}
}
QUrl UBThumbnailAdaptor::thumbnailUrl(UBDocumentProxy* proxy, int pageIndex)
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
return QUrl::fromLocalFile(fileName);
}
#include "UBThumbnailAdaptor.h"
#include <QtCore>
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBPersistenceManager.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "gui/UBDockTeacherGuideWidget.h"
#include "gui/UBTeacherGuideWidget.h"
#include "board/UBBoardController.h"
#include "board/UBBoardPaletteManager.h"
#include "document/UBDocumentProxy.h"
#include "domain/UBGraphicsScene.h"
#include "UBSvgSubsetAdaptor.h"
#include "core/memcheck.h"
void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy)
{
int existingPageCount = proxy->pageCount();
for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo)
{
QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo);
QFile thumbFile(thumbFileName);
if (!thumbFile.exists())
{
bool displayMessage = (existingPageCount > 5);
int thumbCount = 0;
UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, iPageNo);
if (scene)
{
thumbCount++;
if (displayMessage && thumbCount == 1)
UBApplication::showMessage(tr("Generating preview thumbnails ..."));
persistScene(proxy, scene, iPageNo);
}
if (displayMessage && thumbCount > 0)
UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount));
}
}
}
const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex)
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
QFile file(fileName);
if (!file.exists())
{
generateMissingThumbnails(proxy);
}
QPixmap* pix = new QPixmap();
if (file.exists())
{
//Warning. Works only with modified Qt
#ifdef Q_WS_X11
pix->load(fileName, 0, Qt::AutoColor);
#else
pix->load(fileName, 0, Qt::AutoColor, false);
#endif
}
return pix;
}
void UBThumbnailAdaptor::updateDocumentToHandleZeroPage(UBDocumentProxy* proxy)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()){
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", 0);
QFile file(fileName);
if(!file.exists()){
UBPersistenceManager::persistenceManager()->persistDocumentScene(proxy,new UBGraphicsScene(proxy),0);
}
}
}
void UBThumbnailAdaptor::load(UBDocumentProxy* proxy, QList<const QPixmap*>& list)
{
updateDocumentToHandleZeroPage(proxy);
generateMissingThumbnails(proxy);
foreach(const QPixmap* pm, list)
delete pm;
list.clear();
for(int i=0; i<proxy->pageCount(); i++)
list.append(get(proxy, i));
}
void UBThumbnailAdaptor::persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified)
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
QFile thumbFile(fileName);
if (pScene->isModified() || overrideModified || !thumbFile.exists() || UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified())
{
qreal nominalWidth = pScene->nominalSize().width();
qreal nominalHeight = pScene->nominalSize().height();
qreal ratio = nominalWidth / nominalHeight;
QRectF sceneRect = pScene->normalizedSceneRect(ratio);
qreal width = UBSettings::maxThumbnailWidth;
qreal height = width / ratio;
QImage thumb(width, height, QImage::Format_ARGB32);
QRectF imageRect(0, 0, width, height);
QPainter painter(&thumb);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
if (pScene->isDarkBackground())
{
painter.fillRect(imageRect, Qt::black);
}
else
{
painter.fillRect(imageRect, Qt::white);
}
pScene->setRenderingContext(UBGraphicsScene::NonScreen);
pScene->setRenderingQuality(UBItem::RenderingQualityHigh);
pScene->render(&painter, imageRect, sceneRect, Qt::KeepAspectRatio);
if(UBApplication::boardController->paletteManager()->teacherGuideDockWidget() && UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified()){
QPixmap toque(":images/toque.svg");
painter.setOpacity(0.6);
painter.drawPixmap(QPoint(width - toque.width(),0),toque);
}
pScene->setRenderingContext(UBGraphicsScene::Screen);
pScene->setRenderingQuality(UBItem::RenderingQualityNormal);
thumb.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(fileName, "JPG");
}
}
QUrl UBThumbnailAdaptor::thumbnailUrl(UBDocumentProxy* proxy, int pageIndex)
{
QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", pageIndex);
return QUrl::fromLocalFile(fileName);
}

@ -19,34 +19,34 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBTHUMBNAILADAPTOR_H
#define UBTHUMBNAILADAPTOR_H
#include <QtCore>
class UBDocument;
class UBDocumentProxy;
class UBGraphicsScene;
class UBThumbnailAdaptor //static class
{
Q_DECLARE_TR_FUNCTIONS(UBThumbnailAdaptor)
public:
static QUrl thumbnailUrl(UBDocumentProxy* proxy, int pageIndex);
static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false);
static const QPixmap* get(UBDocumentProxy* proxy, int index);
static void load(UBDocumentProxy* proxy, QList<const QPixmap*>& list);
private:
static void generateMissingThumbnails(UBDocumentProxy* proxy);
static void updateDocumentToHandleZeroPage(UBDocumentProxy* proxy);
UBThumbnailAdaptor() {}
};
#endif // UBTHUMBNAILADAPTOR_H
#ifndef UBTHUMBNAILADAPTOR_H
#define UBTHUMBNAILADAPTOR_H
#include <QtCore>
class UBDocument;
class UBDocumentProxy;
class UBGraphicsScene;
class UBThumbnailAdaptor //static class
{
Q_DECLARE_TR_FUNCTIONS(UBThumbnailAdaptor)
public:
static QUrl thumbnailUrl(UBDocumentProxy* proxy, int pageIndex);
static void persistScene(UBDocumentProxy* proxy, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false);
static const QPixmap* get(UBDocumentProxy* proxy, int index);
static void load(UBDocumentProxy* proxy, QList<const QPixmap*>& list);
private:
static void generateMissingThumbnails(UBDocumentProxy* proxy);
static void updateDocumentToHandleZeroPage(UBDocumentProxy* proxy);
UBThumbnailAdaptor() {}
};
#endif // UBTHUMBNAILADAPTOR_H

File diff suppressed because it is too large Load Diff

@ -19,124 +19,124 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOCUMENTPUBLISHER_H
#define UBDOCUMENTPUBLISHER_H
#include <QtGui>
#include <QtNetwork>
#include "ui_webPublishing.h"
#define DOCPUBLICATION_URL "http://planete.sankore.org/xwiki/bin/view/CreateResources/UniboardUpload?xpage=plain&outputSyntax=plain"
typedef struct
{
QString title;
QString description;
} sDocumentInfos;
class UBDocumentProxy;
class UBServerXMLHttpRequest;
class UBGraphicsW3CWidgetItem;
class QWebView;
class UBProxyLoginDlg : public QDialog
{
Q_OBJECT
public:
UBProxyLoginDlg(QWidget* parent=0, const char* name="ProxyLoginDlg");
~UBProxyLoginDlg();
QString username(){return mpUsername->text();}
QString password(){return mpPassword->text();}
private:
QVBoxLayout* mpLayout;
QHBoxLayout* mpUserLayout;
QHBoxLayout* mpPasswordLayout;
QDialogButtonBox* mpButtons;
QLabel* mpUserLabel;
QLabel* mpPasswordLabel;
QLineEdit* mpUsername;
QLineEdit* mpPassword;
};
class UBPublicationDlg : public QDialog
{
Q_OBJECT
public:
UBPublicationDlg(QWidget* parent=0, const char* name="UBPublicationDlg");
~UBPublicationDlg();
QString title(){return mpTitle->text();}
QString description(){return mpDescription->document()->toPlainText();}
private slots:
void onTextChanged();
private:
QVBoxLayout* mpLayout;
QHBoxLayout* mpTitleLayout;
QLabel* mpTitleLabel;
QLineEdit* mpTitle;
QLabel* mpDescLabel;
QTextEdit* mpDescription;
QDialogButtonBox* mpButtons;
};
class UBDocumentPublisher : public QObject
{
Q_OBJECT;
public:
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0);
virtual ~UBDocumentPublisher();
void publish();
signals:
void loginDone();
protected:
virtual void updateGoogleMapApiKey();
virtual void rasterizeScenes();
virtual void upgradeDocumentForPublishing();
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber);
private slots:
void onFinished(QNetworkReply* reply);
private:
UBDocumentProxy *mSourceDocument;
//UBDocumentProxy *mPublishingDocument;
QString mPublishingPath;
int mPublishingSize;
void init();
void sendUbw(QString username, QString password);
QString getBase64Of(QString stringToEncode);
QHBoxLayout* mpLayout;
QNetworkAccessManager* mpNetworkMgr;
QNetworkCookieJar* mpCookieJar;
QString mUsername;
QString mPassword;
QString mCrlf;
bool bLoginCookieSet;
void buildUbwFile();
QString mTmpZipFile;
QList<QNetworkCookie> mCookies;
sDocumentInfos mDocInfos;
};
#endif // UBDOCUMENTPUBLISHER_H
#ifndef UBDOCUMENTPUBLISHER_H
#define UBDOCUMENTPUBLISHER_H
#include <QtGui>
#include <QtNetwork>
#include "ui_webPublishing.h"
#define DOCPUBLICATION_URL "http://planete.sankore.org/xwiki/bin/view/CreateResources/UniboardUpload?xpage=plain&outputSyntax=plain"
typedef struct
{
QString title;
QString description;
} sDocumentInfos;
class UBDocumentProxy;
class UBServerXMLHttpRequest;
class UBGraphicsW3CWidgetItem;
class QWebView;
class UBProxyLoginDlg : public QDialog
{
Q_OBJECT
public:
UBProxyLoginDlg(QWidget* parent=0, const char* name="ProxyLoginDlg");
~UBProxyLoginDlg();
QString username(){return mpUsername->text();}
QString password(){return mpPassword->text();}
private:
QVBoxLayout* mpLayout;
QHBoxLayout* mpUserLayout;
QHBoxLayout* mpPasswordLayout;
QDialogButtonBox* mpButtons;
QLabel* mpUserLabel;
QLabel* mpPasswordLabel;
QLineEdit* mpUsername;
QLineEdit* mpPassword;
};
class UBPublicationDlg : public QDialog
{
Q_OBJECT
public:
UBPublicationDlg(QWidget* parent=0, const char* name="UBPublicationDlg");
~UBPublicationDlg();
QString title(){return mpTitle->text();}
QString description(){return mpDescription->document()->toPlainText();}
private slots:
void onTextChanged();
private:
QVBoxLayout* mpLayout;
QHBoxLayout* mpTitleLayout;
QLabel* mpTitleLabel;
QLineEdit* mpTitle;
QLabel* mpDescLabel;
QTextEdit* mpDescription;
QDialogButtonBox* mpButtons;
};
class UBDocumentPublisher : public QObject
{
Q_OBJECT;
public:
explicit UBDocumentPublisher(UBDocumentProxy* sourceDocument, QObject *parent = 0);
virtual ~UBDocumentPublisher();
void publish();
signals:
void loginDone();
protected:
virtual void updateGoogleMapApiKey();
virtual void rasterizeScenes();
virtual void upgradeDocumentForPublishing();
virtual void generateWidgetPropertyScript(UBGraphicsW3CWidgetItem *widgetItem, int pageNumber);
private slots:
void onFinished(QNetworkReply* reply);
private:
UBDocumentProxy *mSourceDocument;
//UBDocumentProxy *mPublishingDocument;
QString mPublishingPath;
int mPublishingSize;
void init();
void sendUbw(QString username, QString password);
QString getBase64Of(QString stringToEncode);
QHBoxLayout* mpLayout;
QNetworkAccessManager* mpNetworkMgr;
QNetworkCookieJar* mpCookieJar;
QString mUsername;
QString mPassword;
QString mCrlf;
bool bLoginCookieSet;
void buildUbwFile();
QString mTmpZipFile;
QList<QNetworkCookie> mCookies;
sDocumentInfos mDocInfos;
};
#endif // UBDOCUMENTPUBLISHER_H

File diff suppressed because it is too large Load Diff

@ -19,295 +19,295 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBBOARDCONTROLLER_H_
#define UBBOARDCONTROLLER_H_
#include <QtGui>
#include <QObject>
#include "document/UBDocumentContainer.h"
class UBMainWindow;
class UBApplication;
class UBBoardView;
class UBDocumentController;
class UBMessageWindow;
class UBGraphicsScene;
class UBDocumentProxy;
class UBBlackoutWidget;
class UBToolWidget;
class UBVersion;
class UBSoftwareUpdate;
class UBSoftwareUpdateDialog;
class UBGraphicsMediaItem;
class UBGraphicsVideoItem;
class UBGraphicsAudioItem;
class UBGraphicsWidgetItem;
class UBBoardPaletteManager;
class UBItem;
class UBGraphicsItem;
class UBBoardController : public UBDocumentContainer
{
Q_OBJECT
public:
UBBoardController(UBMainWindow *mainWindow);
virtual ~UBBoardController();
void init();
void setupLayout();
UBGraphicsScene* activeScene() const;
int activeSceneIndex() const;
QSize displayViewport();
QSize controlViewport();
QRectF controlGeometry();
void closing();
int currentPage();
QWidget* controlContainer()
{
return mControlContainer;
}
UBBoardView* controlView()
{
return mControlView;
}
UBBoardView* displayView()
{
return mDisplayView;
}
UBGraphicsScene* activeScene()
{
return mActiveScene;
}
void setPenColorOnDarkBackground(const QColor& pColor)
{
if (mPenColorOnDarkBackground == pColor)
return;
mPenColorOnDarkBackground = pColor;
emit penColorChanged();
}
void setPenColorOnLightBackground(const QColor& pColor)
{
if (mPenColorOnLightBackground == pColor)
return;
mPenColorOnLightBackground = pColor;
emit penColorChanged();
}
void setMarkerColorOnDarkBackground(const QColor& pColor)
{
mMarkerColorOnDarkBackground = pColor;
}
void setMarkerColorOnLightBackground(const QColor& pColor)
{
mMarkerColorOnLightBackground = pColor;
}
QColor penColorOnDarkBackground()
{
return mPenColorOnDarkBackground;
}
QColor penColorOnLightBackground()
{
return mPenColorOnLightBackground;
}
QColor markerColorOnDarkBackground()
{
return mMarkerColorOnDarkBackground;
}
QColor markerColorOnLightBackground()
{
return mMarkerColorOnLightBackground;
}
qreal systemScaleFactor()
{
return mSystemScaleFactor;
}
qreal currentZoom();
void persistCurrentScene();
void showNewVersionAvailable(bool automatic, const UBVersion &installedVersion, const UBSoftwareUpdate &softwareUpdate);
void setBoxing(QRect displayRect);
void setToolbarTexts();
static QUrl expandWidgetToTempDir(const QByteArray& pZipedData, const QString& pExtension = QString("wgt"));
// static QRect freeRectInGlobalPos() const {return ;}
void setPageSize(QSize newSize);
UBBoardPaletteManager *paletteManager()
{
return mPaletteManager;
}
void notifyCache(bool visible);
void notifyPageChanged();
void displayMetaData(QMap<QString, QString> metadatas);
void ClearUndoStack();
void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0, bool forceReload = false);
void setActiveDocumentScene(int pSceneIndex);
void moveSceneToIndex(int source, int target);
void duplicateScene(int index);
UBGraphicsItem *duplicateItem(UBItem *item, bool bAsync = true);
void deleteScene(int index);
bool cacheIsVisible() {return mCacheWidgetIsEnabled;}
QString actionGroupText(){ return mActionGroupText;}
QString actionUngroupText(){ return mActionUngroupText;}
public slots:
void showDocumentsDialog();
void showKeyboard(bool show);
void togglePodcast(bool checked);
void blackout();
void addScene();
void addScene(UBDocumentProxy* proxy, int sceneIndex, bool replaceActiveIfEmpty = false);
void addScene(UBGraphicsScene* scene, bool replaceActiveIfEmpty = false);
void duplicateScene();
void importPage();
void clearScene();
void clearSceneItems();
void clearSceneAnnotation();
void clearSceneBackground();
void zoomIn(QPointF scenePoint = QPointF(0,0));
void zoomOut(QPointF scenePoint = QPointF(0,0));
void zoomRestore();
void centerRestore();
void centerOn(QPointF scenePoint = QPointF(0,0));
void zoom(const qreal ratio, QPointF scenePoint);
void handScroll(qreal dx, qreal dy);
void previousScene();
void nextScene();
void firstScene();
void lastScene();
void groupButtonClicked();
void downloadURL(const QUrl& url, QString contentSourceUrl = QString(), const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false, bool internalData = false);
UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pHeader,
QByteArray pData, QPointF pPos, QSize pSize,
bool isBackground = false, bool internalData = false);
void changeBackground(bool isDark, bool isCrossed);
void setToolCursor(int tool);
void showMessage(const QString& message, bool showSpinningWheel = false);
void hideMessage();
void setDisabled(bool disable);
void setColorIndex(int pColorIndex);
void removeTool(UBToolWidget* toolWidget);
void hide();
void show();
void setWidePageSize(bool checked);
void setRegularPageSize(bool checked);
void stylusToolChanged(int tool);
void grabScene(const QRectF& pSceneRect);
UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos);
void cut();
void copy();
void paste();
void processMimeData(const QMimeData* pMimeData, const QPointF& pPos);
void moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicWidget);
void moveToolWidgetToScene(UBToolWidget* toolWidget);
void addItem();
void freezeW3CWidgets(bool freeze);
void freezeW3CWidget(QGraphicsItem* item, bool freeze);
void startScript();
void stopScript();
signals:
void newPageAdded();
void activeSceneChanged();
void zoomChanged(qreal pZoomFactor);
void systemScaleFactorChanged(qreal pSystemScaleFactor);
void penColorChanged();
void controlViewportChanged();
void backgroundChanged();
void cacheEnabled();
void cacheDisabled();
void pageChanged();
void documentReorganized(int index);
void displayMetadata(QMap<QString, QString> metadata);
void pageSelectionChanged(int index);
void npapiWidgetCreated(const QString &Url);
protected:
void setupViews();
void setupToolbar();
void connectToolbar();
void initToolbarTexts();
void updateActionStates();
void updateSystemScaleFactor();
QString truncate(QString text, int maxWidth);
protected slots:
void selectionChanged();
void undoRedoStateChange(bool canUndo);
void documentSceneChanged(UBDocumentProxy* proxy, int pIndex);
private:
void updatePageSizeState();
void saveViewState();
void adjustDisplayViews();
UBMainWindow *mMainWindow;
UBGraphicsScene* mActiveScene;
int mActiveSceneIndex;
UBBoardPaletteManager *mPaletteManager;
UBSoftwareUpdateDialog *mSoftwareUpdateDialog;
UBMessageWindow *mMessageWindow;
UBBoardView *mControlView;
UBBoardView *mDisplayView;
QWidget *mControlContainer;
QHBoxLayout *mControlLayout;
qreal mZoomFactor;
bool mIsClosing;
QColor mPenColorOnDarkBackground;
QColor mPenColorOnLightBackground;
QColor mMarkerColorOnDarkBackground;
QColor mMarkerColorOnLightBackground;
qreal mSystemScaleFactor;
bool mCleanupDone;
QMap<QAction*, QPair<QString, QString> > mActionTexts;
bool mCacheWidgetIsEnabled;
QGraphicsItem* mLastCreatedItem;
int mDeletingSceneIndex;
int mMovingSceneIndex;
QString mActionGroupText;
QString mActionUngroupText;
private slots:
void stylusToolDoubleClicked(int tool);
void boardViewResized(QResizeEvent* event);
void documentWillBeDeleted(UBDocumentProxy* pProxy);
void updateBackgroundActionsState(bool isDark, bool isCrossed);
void updateBackgroundState();
void colorPaletteChanged();
void libraryDialogClosed(int ret);
void lastWindowClosed();
void onDownloadModalFinished();
};
#endif /* UBBOARDCONTROLLER_H_ */
#ifndef UBBOARDCONTROLLER_H_
#define UBBOARDCONTROLLER_H_
#include <QtGui>
#include <QObject>
#include "document/UBDocumentContainer.h"
class UBMainWindow;
class UBApplication;
class UBBoardView;
class UBDocumentController;
class UBMessageWindow;
class UBGraphicsScene;
class UBDocumentProxy;
class UBBlackoutWidget;
class UBToolWidget;
class UBVersion;
class UBSoftwareUpdate;
class UBSoftwareUpdateDialog;
class UBGraphicsMediaItem;
class UBGraphicsVideoItem;
class UBGraphicsAudioItem;
class UBGraphicsWidgetItem;
class UBBoardPaletteManager;
class UBItem;
class UBGraphicsItem;
class UBBoardController : public UBDocumentContainer
{
Q_OBJECT
public:
UBBoardController(UBMainWindow *mainWindow);
virtual ~UBBoardController();
void init();
void setupLayout();
UBGraphicsScene* activeScene() const;
int activeSceneIndex() const;
QSize displayViewport();
QSize controlViewport();
QRectF controlGeometry();
void closing();
int currentPage();
QWidget* controlContainer()
{
return mControlContainer;
}
UBBoardView* controlView()
{
return mControlView;
}
UBBoardView* displayView()
{
return mDisplayView;
}
UBGraphicsScene* activeScene()
{
return mActiveScene;
}
void setPenColorOnDarkBackground(const QColor& pColor)
{
if (mPenColorOnDarkBackground == pColor)
return;
mPenColorOnDarkBackground = pColor;
emit penColorChanged();
}
void setPenColorOnLightBackground(const QColor& pColor)
{
if (mPenColorOnLightBackground == pColor)
return;
mPenColorOnLightBackground = pColor;
emit penColorChanged();
}
void setMarkerColorOnDarkBackground(const QColor& pColor)
{
mMarkerColorOnDarkBackground = pColor;
}
void setMarkerColorOnLightBackground(const QColor& pColor)
{
mMarkerColorOnLightBackground = pColor;
}
QColor penColorOnDarkBackground()
{
return mPenColorOnDarkBackground;
}
QColor penColorOnLightBackground()
{
return mPenColorOnLightBackground;
}
QColor markerColorOnDarkBackground()
{
return mMarkerColorOnDarkBackground;
}
QColor markerColorOnLightBackground()
{
return mMarkerColorOnLightBackground;
}
qreal systemScaleFactor()
{
return mSystemScaleFactor;
}
qreal currentZoom();
void persistCurrentScene();
void showNewVersionAvailable(bool automatic, const UBVersion &installedVersion, const UBSoftwareUpdate &softwareUpdate);
void setBoxing(QRect displayRect);
void setToolbarTexts();
static QUrl expandWidgetToTempDir(const QByteArray& pZipedData, const QString& pExtension = QString("wgt"));
// static QRect freeRectInGlobalPos() const {return ;}
void setPageSize(QSize newSize);
UBBoardPaletteManager *paletteManager()
{
return mPaletteManager;
}
void notifyCache(bool visible);
void notifyPageChanged();
void displayMetaData(QMap<QString, QString> metadatas);
void ClearUndoStack();
void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0, bool forceReload = false);
void setActiveDocumentScene(int pSceneIndex);
void moveSceneToIndex(int source, int target);
void duplicateScene(int index);
UBGraphicsItem *duplicateItem(UBItem *item, bool bAsync = true);
void deleteScene(int index);
bool cacheIsVisible() {return mCacheWidgetIsEnabled;}
QString actionGroupText(){ return mActionGroupText;}
QString actionUngroupText(){ return mActionUngroupText;}
public slots:
void showDocumentsDialog();
void showKeyboard(bool show);
void togglePodcast(bool checked);
void blackout();
void addScene();
void addScene(UBDocumentProxy* proxy, int sceneIndex, bool replaceActiveIfEmpty = false);
void addScene(UBGraphicsScene* scene, bool replaceActiveIfEmpty = false);
void duplicateScene();
void importPage();
void clearScene();
void clearSceneItems();
void clearSceneAnnotation();
void clearSceneBackground();
void zoomIn(QPointF scenePoint = QPointF(0,0));
void zoomOut(QPointF scenePoint = QPointF(0,0));
void zoomRestore();
void centerRestore();
void centerOn(QPointF scenePoint = QPointF(0,0));
void zoom(const qreal ratio, QPointF scenePoint);
void handScroll(qreal dx, qreal dy);
void previousScene();
void nextScene();
void firstScene();
void lastScene();
void groupButtonClicked();
void downloadURL(const QUrl& url, QString contentSourceUrl = QString(), const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false, bool internalData = false);
UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pHeader,
QByteArray pData, QPointF pPos, QSize pSize,
bool isBackground = false, bool internalData = false);
void changeBackground(bool isDark, bool isCrossed);
void setToolCursor(int tool);
void showMessage(const QString& message, bool showSpinningWheel = false);
void hideMessage();
void setDisabled(bool disable);
void setColorIndex(int pColorIndex);
void removeTool(UBToolWidget* toolWidget);
void hide();
void show();
void setWidePageSize(bool checked);
void setRegularPageSize(bool checked);
void stylusToolChanged(int tool);
void grabScene(const QRectF& pSceneRect);
UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos);
void cut();
void copy();
void paste();
void processMimeData(const QMimeData* pMimeData, const QPointF& pPos);
void moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicWidget);
void moveToolWidgetToScene(UBToolWidget* toolWidget);
void addItem();
void freezeW3CWidgets(bool freeze);
void freezeW3CWidget(QGraphicsItem* item, bool freeze);
void startScript();
void stopScript();
signals:
void newPageAdded();
void activeSceneChanged();
void zoomChanged(qreal pZoomFactor);
void systemScaleFactorChanged(qreal pSystemScaleFactor);
void penColorChanged();
void controlViewportChanged();
void backgroundChanged();
void cacheEnabled();
void cacheDisabled();
void pageChanged();
void documentReorganized(int index);
void displayMetadata(QMap<QString, QString> metadata);
void pageSelectionChanged(int index);
void npapiWidgetCreated(const QString &Url);
protected:
void setupViews();
void setupToolbar();
void connectToolbar();
void initToolbarTexts();
void updateActionStates();
void updateSystemScaleFactor();
QString truncate(QString text, int maxWidth);
protected slots:
void selectionChanged();
void undoRedoStateChange(bool canUndo);
void documentSceneChanged(UBDocumentProxy* proxy, int pIndex);
private:
void updatePageSizeState();
void saveViewState();
void adjustDisplayViews();
UBMainWindow *mMainWindow;
UBGraphicsScene* mActiveScene;
int mActiveSceneIndex;
UBBoardPaletteManager *mPaletteManager;
UBSoftwareUpdateDialog *mSoftwareUpdateDialog;
UBMessageWindow *mMessageWindow;
UBBoardView *mControlView;
UBBoardView *mDisplayView;
QWidget *mControlContainer;
QHBoxLayout *mControlLayout;
qreal mZoomFactor;
bool mIsClosing;
QColor mPenColorOnDarkBackground;
QColor mPenColorOnLightBackground;
QColor mMarkerColorOnDarkBackground;
QColor mMarkerColorOnLightBackground;
qreal mSystemScaleFactor;
bool mCleanupDone;
QMap<QAction*, QPair<QString, QString> > mActionTexts;
bool mCacheWidgetIsEnabled;
QGraphicsItem* mLastCreatedItem;
int mDeletingSceneIndex;
int mMovingSceneIndex;
QString mActionGroupText;
QString mActionUngroupText;
private slots:
void stylusToolDoubleClicked(int tool);
void boardViewResized(QResizeEvent* event);
void documentWillBeDeleted(UBDocumentProxy* pProxy);
void updateBackgroundActionsState(bool isDark, bool isCrossed);
void updateBackgroundState();
void colorPaletteChanged();
void libraryDialogClosed(int ret);
void lastWindowClosed();
void onDownloadModalFinished();
};
#endif /* UBBOARDCONTROLLER_H_ */

File diff suppressed because it is too large Load Diff

@ -19,173 +19,173 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBBOARDPALETTEMANAGER_H_
#define UBBOARDPALETTEMANAGER_H_
#include <QtGui>
#include <QtWebKit>
#include "gui/UBLeftPalette.h"
#include "gui/UBRightPalette.h"
#include "gui/UBPageNavigationWidget.h"
#include "gui/UBCachePropertiesWidget.h"
#include "gui/UBDockDownloadWidget.h"
#include "core/UBApplicationController.h"
#include "gui/UBFeaturesWidget.h"
class UBWebToolsPalette;
class UBStylusPalette;
class UBClockPalette;
class UBPageNumberPalette;
class UBZoomPalette;
class UBActionPalette;
class UBBoardController;
class UBServerXMLHttpRequest;
class UBKeyboardPalette;
class UBMainWindow;
class UBApplicationController;
class UBDockTeacherGuideWidget;
class UBBoardPaletteManager : public QObject
{
Q_OBJECT
public:
UBBoardPaletteManager(QWidget* container, UBBoardController* controller);
virtual ~UBBoardPaletteManager();
void setupLayout();
UBLeftPalette* leftPalette(){return mLeftPalette;}
UBRightPalette* rightPalette(){return mRightPalette;}
UBStylusPalette* stylusPalette(){return mStylusPalette;}
UBActionPalette *addItemPalette() {return mAddItemPalette;}
void showVirtualKeyboard(bool show = true);
void initPalettesPosAtStartup();
void connectToDocumentController();
void refreshPalettes();
UBKeyboardPalette *mKeyboardPalette;
void setCurrentWebToolsPalette(UBWebToolsPalette *palette) {mWebToolsCurrentPalette = palette;}
UBWebToolsPalette* mWebToolsCurrentPalette;
UBDockTeacherGuideWidget* teacherGuideDockWidget() { return mpTeacherGuideWidget;}
void processPalettersWidget(UBDockPalette *paletter, eUBDockPaletteWidgetMode mode);
void changeMode(eUBDockPaletteWidgetMode newMode, bool isInit = false);
void startDownloads();
void stopDownloads();
signals:
void connectToDocController();
void signal_changeMode(eUBDockPaletteWidgetMode newMode);
public slots:
void activeSceneChanged();
void containerResized();
void addItem(const QUrl& pUrl);
void addItem(const QPixmap& pPixmap, const QPointF& p = QPointF(0.0, 0.0), qreal scale = 1.0, const QUrl& sourceUrl = QUrl());
void slot_changeMainMode(UBApplicationController::MainMode);
void slot_changeDesktopMode(bool);
void toggleErasePalette(bool ckecked);
private:
void setupPalettes();
void connectPalettes();
void positionFreeDisplayPalette();
void setupDockPaletteWidgets();
QWidget* mContainer;
UBBoardController *mBoardControler;
UBStylusPalette *mStylusPalette;
UBZoomPalette *mZoomPalette;
/** The left dock palette */
UBLeftPalette* mLeftPalette;
/** The right dock palette */
UBRightPalette* mRightPalette;
UBActionPalette *mBackgroundsPalette;
UBActionPalette *mToolsPalette;
UBActionPalette* mAddItemPalette;
UBActionPalette* mErasePalette;
UBActionPalette* mPagePalette;
QUrl mItemUrl;
QPixmap mPixmap;
QPointF mPos;
qreal mScaleFactor;
QTime mPageButtonPressedTime;
bool mPendingPageButtonPressed;
QTime mZoomButtonPressedTime;
bool mPendingZoomButtonPressed;
QTime mPanButtonPressedTime;
bool mPendingPanButtonPressed;
QTime mEraseButtonPressedTime;
bool mPendingEraseButtonPressed;
/** The page navigator widget */
UBPageNavigationWidget* mpPageNavigWidget;
/** The cache properties widget */
UBCachePropertiesWidget* mpCachePropWidget;
UBFeaturesWidget *mpFeaturesWidget;
/** The download widget */
UBDockDownloadWidget* mpDownloadWidget;
UBDockTeacherGuideWidget* mpTeacherGuideWidget;
bool mDownloadInProgress;
private slots:
void changeBackground();
void toggleBackgroundPalette(bool checked);
void backgroundPaletteClosed();
void toggleStylusPalette(bool checked);
void tooglePodcastPalette(bool checked);
void erasePaletteButtonPressed();
void erasePaletteButtonReleased();
void erasePaletteClosed();
void togglePagePalette(bool ckecked);
void pagePaletteClosed();
void pagePaletteButtonPressed();
void pagePaletteButtonReleased();
void addItemToCurrentPage();
void addItemToNewPage();
void addItemToLibrary();
void purchaseLinkActivated(const QString&);
void linkClicked(const QUrl& url);
void zoomButtonPressed();
void zoomButtonReleased();
void panButtonPressed();
void panButtonReleased();
void changeStylusPaletteOrientation(QVariant var);
};
#endif /* UBBOARDPALETTEMANAGER_H_ */
#ifndef UBBOARDPALETTEMANAGER_H_
#define UBBOARDPALETTEMANAGER_H_
#include <QtGui>
#include <QtWebKit>
#include "gui/UBLeftPalette.h"
#include "gui/UBRightPalette.h"
#include "gui/UBPageNavigationWidget.h"
#include "gui/UBCachePropertiesWidget.h"
#include "gui/UBDockDownloadWidget.h"
#include "core/UBApplicationController.h"
#include "gui/UBFeaturesWidget.h"
class UBWebToolsPalette;
class UBStylusPalette;
class UBClockPalette;
class UBPageNumberPalette;
class UBZoomPalette;
class UBActionPalette;
class UBBoardController;
class UBServerXMLHttpRequest;
class UBKeyboardPalette;
class UBMainWindow;
class UBApplicationController;
class UBDockTeacherGuideWidget;
class UBBoardPaletteManager : public QObject
{
Q_OBJECT
public:
UBBoardPaletteManager(QWidget* container, UBBoardController* controller);
virtual ~UBBoardPaletteManager();
void setupLayout();
UBLeftPalette* leftPalette(){return mLeftPalette;}
UBRightPalette* rightPalette(){return mRightPalette;}
UBStylusPalette* stylusPalette(){return mStylusPalette;}
UBActionPalette *addItemPalette() {return mAddItemPalette;}
void showVirtualKeyboard(bool show = true);
void initPalettesPosAtStartup();
void connectToDocumentController();
void refreshPalettes();
UBKeyboardPalette *mKeyboardPalette;
void setCurrentWebToolsPalette(UBWebToolsPalette *palette) {mWebToolsCurrentPalette = palette;}
UBWebToolsPalette* mWebToolsCurrentPalette;
UBDockTeacherGuideWidget* teacherGuideDockWidget() { return mpTeacherGuideWidget;}
void processPalettersWidget(UBDockPalette *paletter, eUBDockPaletteWidgetMode mode);
void changeMode(eUBDockPaletteWidgetMode newMode, bool isInit = false);
void startDownloads();
void stopDownloads();
signals:
void connectToDocController();
void signal_changeMode(eUBDockPaletteWidgetMode newMode);
public slots:
void activeSceneChanged();
void containerResized();
void addItem(const QUrl& pUrl);
void addItem(const QPixmap& pPixmap, const QPointF& p = QPointF(0.0, 0.0), qreal scale = 1.0, const QUrl& sourceUrl = QUrl());
void slot_changeMainMode(UBApplicationController::MainMode);
void slot_changeDesktopMode(bool);
void toggleErasePalette(bool ckecked);
private:
void setupPalettes();
void connectPalettes();
void positionFreeDisplayPalette();
void setupDockPaletteWidgets();
QWidget* mContainer;
UBBoardController *mBoardControler;
UBStylusPalette *mStylusPalette;
UBZoomPalette *mZoomPalette;
/** The left dock palette */
UBLeftPalette* mLeftPalette;
/** The right dock palette */
UBRightPalette* mRightPalette;
UBActionPalette *mBackgroundsPalette;
UBActionPalette *mToolsPalette;
UBActionPalette* mAddItemPalette;
UBActionPalette* mErasePalette;
UBActionPalette* mPagePalette;
QUrl mItemUrl;
QPixmap mPixmap;
QPointF mPos;
qreal mScaleFactor;
QTime mPageButtonPressedTime;
bool mPendingPageButtonPressed;
QTime mZoomButtonPressedTime;
bool mPendingZoomButtonPressed;
QTime mPanButtonPressedTime;
bool mPendingPanButtonPressed;
QTime mEraseButtonPressedTime;
bool mPendingEraseButtonPressed;
/** The page navigator widget */
UBPageNavigationWidget* mpPageNavigWidget;
/** The cache properties widget */
UBCachePropertiesWidget* mpCachePropWidget;
UBFeaturesWidget *mpFeaturesWidget;
/** The download widget */
UBDockDownloadWidget* mpDownloadWidget;
UBDockTeacherGuideWidget* mpTeacherGuideWidget;
bool mDownloadInProgress;
private slots:
void changeBackground();
void toggleBackgroundPalette(bool checked);
void backgroundPaletteClosed();
void toggleStylusPalette(bool checked);
void tooglePodcastPalette(bool checked);
void erasePaletteButtonPressed();
void erasePaletteButtonReleased();
void erasePaletteClosed();
void togglePagePalette(bool ckecked);
void pagePaletteClosed();
void pagePaletteButtonPressed();
void pagePaletteButtonReleased();
void addItemToCurrentPage();
void addItemToNewPage();
void addItemToLibrary();
void purchaseLinkActivated(const QString&);
void linkClicked(const QUrl& url);
void zoomButtonPressed();
void zoomButtonReleased();
void panButtonPressed();
void panButtonReleased();
void changeStylusPaletteOrientation(QVariant var);
};
#endif /* UBBOARDPALETTEMANAGER_H_ */

@ -19,164 +19,164 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBBOARDVIEW_H_
#define UBBOARDVIEW_H_
#include <QtGui>
#include "core/UB.h"
#include "domain/UBGraphicsDelegateFrame.h"
class UBBoardController;
class UBGraphicsScene;
class UBGraphicsWidgetItem;
class UBRubberBand;
class UBBoardView : public QGraphicsView
{
Q_OBJECT
public:
UBBoardView(UBBoardController* pController, QWidget* pParent = 0, bool isControl = false, bool isDesktop = false);
UBBoardView(UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent = 0, bool isControl = false, bool isDesktop = false);
virtual ~UBBoardView();
UBGraphicsScene* scene();
void forcedTabletRelease();
void setToolCursor(int tool);
void rubberItems();
void moveRubberedItems(QPointF movingVector);
void setMultiselection(bool enable);
bool isMultipleSelectionEnabled() { return mMultipleSelectionIsEnabled; }
signals:
void resized(QResizeEvent* event);
void hidden();
void shown();
void clickOnBoard();
protected:
bool itemIsLocked(QGraphicsItem *item);
bool isUBItem(QGraphicsItem *item); // we should to determine items who is not UB and use general scene behavior for them.
bool isCppTool(QGraphicsItem *item);
void handleItemsSelection(QGraphicsItem *item);
bool itemShouldReceiveMousePressEvent(QGraphicsItem *item);
bool itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item);
bool itemHaveParentWithType(QGraphicsItem *item, int type);
bool itemShouldBeMoved(QGraphicsItem *item);
QGraphicsItem* determineItemToPress(QGraphicsItem *item);
QGraphicsItem* determineItemToMove(QGraphicsItem *item);
void handleItemMousePress(QMouseEvent *event);
void handleItemMouseMove(QMouseEvent *event);
virtual bool event (QEvent * e);
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
virtual void tabletEvent(QTabletEvent * event);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
virtual void leaveEvent ( QEvent * event);
virtual void focusOutEvent ( QFocusEvent * event );
virtual void drawItems(QPainter *painter, int numItems,
QGraphicsItem *items[],
const QStyleOptionGraphicsItem options[]);
// virtual void dragEnterEvent(QDragEnterEvent * event);
virtual void dropEvent(QDropEvent *event);
virtual void dragMoveEvent(QDragMoveEvent *event);
virtual void resizeEvent(QResizeEvent * event);
virtual void drawBackground(QPainter *painter, const QRectF &rect);
virtual void showEvent(QShowEvent * event);
virtual void hideEvent(QHideEvent * event);
private:
void init();
inline bool shouldDisplayItem(QGraphicsItem *item)
{
bool ok;
int itemLayerType = item->data(UBGraphicsItemData::ItemLayerType).toInt(&ok);
return (ok && (itemLayerType >= mStartLayer && itemLayerType <= mEndLayer));
}
QList<QUrl> processMimeData(const QMimeData* pMimeData);
UBBoardController* mController;
int mStartLayer, mEndLayer;
bool mFilterZIndex;
bool mTabletStylusIsPressed;
bool mUsingTabletEraser;
bool mPendingStylusReleaseEvent;
bool mMouseButtonIsPressed;
QPointF mPreviousPoint;
QPoint mMouseDownPos;
bool mPenPressureSensitive;
bool mMarkerPressureSensitive;
bool mUseHighResTabletEvent;
QRubberBand *mRubberBand;
bool mIsCreatingTextZone;
bool mIsCreatingSceneGrabZone;
bool isAbsurdPoint(QPoint point);
bool mVirtualKeyboardActive;
bool mOkOnWidget;
bool mWidgetMoved;
QPointF mLastPressedMousePos;
QGraphicsItem *movingItem;
QMouseEvent *suspendedMousePressEvent;
bool moveRubberBand;
UBRubberBand *mUBRubberBand;
QList<QGraphicsItem *> mRubberedItems;
QSet<QGraphicsItem*> mJustSelectedItems;
int mLongPressInterval;
QTimer mLongPressTimer;
bool mIsDragInProgress;
bool mMultipleSelectionIsEnabled;
bool bIsControl;
bool bIsDesktop;
bool mRubberBandInPlayMode;
static bool hasSelectedParents(QGraphicsItem * item);
private slots:
void settingChanged(QVariant newValue);
public slots:
void virtualKeyboardActivated(bool b);
void longPressEvent();
};
#endif /* UBBOARDVIEW_H_ */
#ifndef UBBOARDVIEW_H_
#define UBBOARDVIEW_H_
#include <QtGui>
#include "core/UB.h"
#include "domain/UBGraphicsDelegateFrame.h"
class UBBoardController;
class UBGraphicsScene;
class UBGraphicsWidgetItem;
class UBRubberBand;
class UBBoardView : public QGraphicsView
{
Q_OBJECT
public:
UBBoardView(UBBoardController* pController, QWidget* pParent = 0, bool isControl = false, bool isDesktop = false);
UBBoardView(UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent = 0, bool isControl = false, bool isDesktop = false);
virtual ~UBBoardView();
UBGraphicsScene* scene();
void forcedTabletRelease();
void setToolCursor(int tool);
void rubberItems();
void moveRubberedItems(QPointF movingVector);
void setMultiselection(bool enable);
bool isMultipleSelectionEnabled() { return mMultipleSelectionIsEnabled; }
signals:
void resized(QResizeEvent* event);
void hidden();
void shown();
void clickOnBoard();
protected:
bool itemIsLocked(QGraphicsItem *item);
bool isUBItem(QGraphicsItem *item); // we should to determine items who is not UB and use general scene behavior for them.
bool isCppTool(QGraphicsItem *item);
void handleItemsSelection(QGraphicsItem *item);
bool itemShouldReceiveMousePressEvent(QGraphicsItem *item);
bool itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item);
bool itemHaveParentWithType(QGraphicsItem *item, int type);
bool itemShouldBeMoved(QGraphicsItem *item);
QGraphicsItem* determineItemToPress(QGraphicsItem *item);
QGraphicsItem* determineItemToMove(QGraphicsItem *item);
void handleItemMousePress(QMouseEvent *event);
void handleItemMouseMove(QMouseEvent *event);
virtual bool event (QEvent * e);
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
virtual void tabletEvent(QTabletEvent * event);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
virtual void leaveEvent ( QEvent * event);
virtual void focusOutEvent ( QFocusEvent * event );
virtual void drawItems(QPainter *painter, int numItems,
QGraphicsItem *items[],
const QStyleOptionGraphicsItem options[]);
// virtual void dragEnterEvent(QDragEnterEvent * event);
virtual void dropEvent(QDropEvent *event);
virtual void dragMoveEvent(QDragMoveEvent *event);
virtual void resizeEvent(QResizeEvent * event);
virtual void drawBackground(QPainter *painter, const QRectF &rect);
virtual void showEvent(QShowEvent * event);
virtual void hideEvent(QHideEvent * event);
private:
void init();
inline bool shouldDisplayItem(QGraphicsItem *item)
{
bool ok;
int itemLayerType = item->data(UBGraphicsItemData::ItemLayerType).toInt(&ok);
return (ok && (itemLayerType >= mStartLayer && itemLayerType <= mEndLayer));
}
QList<QUrl> processMimeData(const QMimeData* pMimeData);
UBBoardController* mController;
int mStartLayer, mEndLayer;
bool mFilterZIndex;
bool mTabletStylusIsPressed;
bool mUsingTabletEraser;
bool mPendingStylusReleaseEvent;
bool mMouseButtonIsPressed;
QPointF mPreviousPoint;
QPoint mMouseDownPos;
bool mPenPressureSensitive;
bool mMarkerPressureSensitive;
bool mUseHighResTabletEvent;
QRubberBand *mRubberBand;
bool mIsCreatingTextZone;
bool mIsCreatingSceneGrabZone;
bool isAbsurdPoint(QPoint point);
bool mVirtualKeyboardActive;
bool mOkOnWidget;
bool mWidgetMoved;
QPointF mLastPressedMousePos;
QGraphicsItem *movingItem;
QMouseEvent *suspendedMousePressEvent;
bool moveRubberBand;
UBRubberBand *mUBRubberBand;
QList<QGraphicsItem *> mRubberedItems;
QSet<QGraphicsItem*> mJustSelectedItems;
int mLongPressInterval;
QTimer mLongPressTimer;
bool mIsDragInProgress;
bool mMultipleSelectionIsEnabled;
bool bIsControl;
bool bIsDesktop;
bool mRubberBandInPlayMode;
static bool hasSelectedParents(QGraphicsItem * item);
private slots:
void settingChanged(QVariant newValue);
public slots:
void virtualKeyboardActivated(bool b);
void longPressEvent();
};
#endif /* UBBOARDVIEW_H_ */

@ -19,155 +19,155 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBAPPLICATION_H_
#define UBAPPLICATION_H_
#include <QtGui>
#include "qtsingleapplication.h"
#include "transition/UniboardSankoreTransition.h"
namespace Ui
{
class MainWindow;
}
class UBBoardController;
class UBWebController;
class UBControlView;
class UBPreferencesController;
class UBResources;
class UBSettings;
class UBPersistenceManager;
class UBApplicationController;
class UBDocumentController;
class UBMainWindow;
class UBApplication : public QtSingleApplication
{
Q_OBJECT;
public:
UBApplication(const QString &id, int &argc, char **argv);
virtual ~UBApplication();
int exec(const QString& pFileToImport);
void cleanup();
static QPointer<QUndoStack> undoStack;
static UBApplicationController *applicationController;
static UBBoardController* boardController;
static UBWebController* webController;
static UBDocumentController* documentController;
static UniboardSankoreTransition* mUniboardSankoreTransition;
static UBMainWindow* mainWindow;
static UBApplication* app()
{
return static_cast<UBApplication*>qApp;
}
static const QString mimeTypeUniboardDocument;
static const QString mimeTypeUniboardPage;
static const QString mimeTypeUniboardPageItem;
static const QString mimeTypeUniboardPageThumbnail;
static void showMessage(const QString& message, bool showSpinningWheel = false);
static void setDisabled(bool disable);
static QObject* staticMemoryCleaner;
void decorateActionMenu(QAction* action);
void insertSpaceToToolbarBeforeAction(QToolBar* toolbar, QAction* action, int width = -1);
int toolBarHeight();
bool eventFilter(QObject *obj, QEvent *event);
bool isVerbose() { return mIsVerbose;}
void setVerbose(bool verbose){mIsVerbose = verbose;}
static QString urlFromHtml(QString html);
static bool isFromWeb(QString url);
signals:
public slots:
void showBoard();
void showInternet();
void showDocument();
void startScript();
void stopScript();
void toolBarPositionChanged(QVariant topOrBottom);
void toolBarDisplayTextChanged(QVariant display);
void closeEvent(QCloseEvent *event);
/**
* Used on Windows platform to open file in running application. On MacOS X opening file is done through the
* FileOpen event that is handle in eventFilter method.
*/
bool handleOpenMessage(const QString& pMessage);
private slots:
void closing();
#ifdef Q_WS_MAC
void showMinimized();
#endif
void importUniboardFiles();
void onScreenCountChanged(int newCount);
private:
void updateProtoActionsState();
void setupTranslators(QStringList args);
QList<QMenu*> mProtoMenus;
bool mIsVerbose;
QString checkLanguageAvailabilityForSankore(QString& language);
protected:
#if defined(Q_WS_MACX) && !defined(QT_MAC_USE_COCOA)
bool macEventFilter(EventHandlerCallRef caller, EventRef event);
#endif
UBPreferencesController* mPreferencesController;
QTranslator* mApplicationTranslator;
QTranslator* mQtGuiTranslator;
};
class UBStyle : public QPlastiqueStyle
{
public:
UBStyle()
: QPlastiqueStyle()
{
// NOOP
}
virtual ~UBStyle()
{
// NOOP
}
/*
* redefined to be more cocoa like on texts
*/
virtual void drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
bool enabled, const QString& text, QPalette::ColorRole textRole) const;
};
#endif /* UBAPPLICATION_H_ */
#ifndef UBAPPLICATION_H_
#define UBAPPLICATION_H_
#include <QtGui>
#include "qtsingleapplication.h"
#include "transition/UniboardSankoreTransition.h"
namespace Ui
{
class MainWindow;
}
class UBBoardController;
class UBWebController;
class UBControlView;
class UBPreferencesController;
class UBResources;
class UBSettings;
class UBPersistenceManager;
class UBApplicationController;
class UBDocumentController;
class UBMainWindow;
class UBApplication : public QtSingleApplication
{
Q_OBJECT;
public:
UBApplication(const QString &id, int &argc, char **argv);
virtual ~UBApplication();
int exec(const QString& pFileToImport);
void cleanup();
static QPointer<QUndoStack> undoStack;
static UBApplicationController *applicationController;
static UBBoardController* boardController;
static UBWebController* webController;
static UBDocumentController* documentController;
static UniboardSankoreTransition* mUniboardSankoreTransition;
static UBMainWindow* mainWindow;
static UBApplication* app()
{
return static_cast<UBApplication*>qApp;
}
static const QString mimeTypeUniboardDocument;
static const QString mimeTypeUniboardPage;
static const QString mimeTypeUniboardPageItem;
static const QString mimeTypeUniboardPageThumbnail;
static void showMessage(const QString& message, bool showSpinningWheel = false);
static void setDisabled(bool disable);
static QObject* staticMemoryCleaner;
void decorateActionMenu(QAction* action);
void insertSpaceToToolbarBeforeAction(QToolBar* toolbar, QAction* action, int width = -1);
int toolBarHeight();
bool eventFilter(QObject *obj, QEvent *event);
bool isVerbose() { return mIsVerbose;}
void setVerbose(bool verbose){mIsVerbose = verbose;}
static QString urlFromHtml(QString html);
static bool isFromWeb(QString url);
signals:
public slots:
void showBoard();
void showInternet();
void showDocument();
void startScript();
void stopScript();
void toolBarPositionChanged(QVariant topOrBottom);
void toolBarDisplayTextChanged(QVariant display);
void closeEvent(QCloseEvent *event);
/**
* Used on Windows platform to open file in running application. On MacOS X opening file is done through the
* FileOpen event that is handle in eventFilter method.
*/
bool handleOpenMessage(const QString& pMessage);
private slots:
void closing();
#ifdef Q_WS_MAC
void showMinimized();
#endif
void importUniboardFiles();
void onScreenCountChanged(int newCount);
private:
void updateProtoActionsState();
void setupTranslators(QStringList args);
QList<QMenu*> mProtoMenus;
bool mIsVerbose;
QString checkLanguageAvailabilityForSankore(QString& language);
protected:
#if defined(Q_WS_MACX) && !defined(QT_MAC_USE_COCOA)
bool macEventFilter(EventHandlerCallRef caller, EventRef event);
#endif
UBPreferencesController* mPreferencesController;
QTranslator* mApplicationTranslator;
QTranslator* mQtGuiTranslator;
};
class UBStyle : public QPlastiqueStyle
{
public:
UBStyle()
: QPlastiqueStyle()
{
// NOOP
}
virtual ~UBStyle()
{
// NOOP
}
/*
* redefined to be more cocoa like on texts
*/
virtual void drawItemText(QPainter *painter, const QRect &rect, int alignment, const QPalette &pal,
bool enabled, const QString& text, QPalette::ColorRole textRole) const;
};
#endif /* UBAPPLICATION_H_ */

File diff suppressed because it is too large Load Diff

@ -21,297 +21,297 @@
#include "UBDocumentManager.h"
#include "frameworks/UBStringUtils.h"
#include "adaptors/UBExportFullPDF.h"
#include "adaptors/UBExportDocument.h"
#include "adaptors/UBExportWeb.h"
#include "adaptors/UBExportCFF.h"
#include "adaptors/UBWebPublisher.h"
#include "adaptors/UBImportDocument.h"
#include "adaptors/UBImportPDF.h"
#include "adaptors/UBImportImage.h"
#include "adaptors/UBImportCFF.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsPixmapItem.h"
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentController.h"
#include "board/UBBoardController.h"
#include "UBApplication.h"
#include "UBSettings.h"
#include "UBPersistenceManager.h"
#include "../adaptors/UBExportWeb.h"
#include "core/memcheck.h"
UBDocumentManager* UBDocumentManager::sDocumentManager = 0;
UBDocumentManager* UBDocumentManager::documentManager()
{
if (!sDocumentManager)
{
sDocumentManager = new UBDocumentManager(qApp);
}
return sDocumentManager;
}
UBDocumentManager::UBDocumentManager(QObject *parent)
:QObject(parent)
{
// TODO UB 4.7 string used in document persistence (folder names)
QString dummyImages = tr("images");
QString dummyVideos = tr("videos");
QString dummyObjects = tr("objects");
QString dummyWidgets = tr("widgets");
UBExportCFF* cffExporter = new UBExportCFF(this);
UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this);
UBExportDocument* exportDocument = new UBExportDocument(this);
UBWebPublisher* webPublished = new UBWebPublisher(this);
mExportAdaptors.append(exportDocument);
mExportAdaptors.append(webPublished);
mExportAdaptors.append(exportFullPdf);
mExportAdaptors.append(cffExporter);
// UBExportWeb* exportWeb = new UBExportWeb(this);
// mExportAdaptors.append(exportWeb);
UBImportDocument* documentImport = new UBImportDocument(this);
mImportAdaptors.append(documentImport);
UBImportPDF* pdfImport = new UBImportPDF(this);
mImportAdaptors.append(pdfImport);
UBImportImage* imageImport = new UBImportImage(this);
mImportAdaptors.append(imageImport);
UBImportCFF* cffImport = new UBImportCFF(this);
mImportAdaptors.append(cffImport);
}
UBDocumentManager::~UBDocumentManager()
{
// NOOP
}
QStringList UBDocumentManager::importFileExtensions()
{
QStringList result;
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{
result << importAdaptor->supportedExtentions();
}
return result;
}
QString UBDocumentManager::importFileFilter()
{
QString result;
result += tr("All supported files (*.%1)").arg(importFileExtensions().join(" *."));
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{
if (importAdaptor->importFileFilter().length() > 0)
{
if (result.length())
{
result += ";;";
}
result += importAdaptor->importFileFilter();
}
}
qDebug() << "import file filter" << result;
return result;
}
UBDocumentProxy* UBDocumentManager::importFile(const QFile& pFile, const QString& pGroup)
{
QFileInfo fileInfo(pFile);
foreach (UBImportAdaptor *adaptor, mImportAdaptors)
{
if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1)
{
UBDocumentProxy* document;
UBApplication::setDisabled(true);
if (adaptor->isDocumentBased())
{
UBDocumentBasedImportAdaptor* importAdaptor = (UBDocumentBasedImportAdaptor*)adaptor;
document = importAdaptor->importFile(pFile, pGroup);
}
else
{
UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor;
// Document import procedure.....
QString documentName = QFileInfo(pFile.fileName()).completeBaseName();
document = UBPersistenceManager::persistenceManager()->createDocument(pGroup, documentName);
QUuid uuid = QUuid::createUuid();
QString filepath = pFile.fileName();
if (importAdaptor->folderToCopy() != "")
{
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, pFile.fileName(), importAdaptor->folderToCopy() , uuid, filepath);
if (!b)
{
UBPersistenceManager::persistenceManager()->deleteDocument(document);
UBApplication::setDisabled(false);
return NULL;
}
}
QList<UBGraphicsItem*> pages = importAdaptor->import(uuid, filepath);
int nPage = 0;
foreach(UBGraphicsItem* page, pages)
{
UBApplication::showMessage(tr("Inserting page %1 of %2").arg(++nPage).arg(pages.size()), true);
#ifdef Q_WS_MACX
//Workaround for issue 912
QApplication::processEvents();
#endif
int pageIndex = document->pageCount();
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(document, pageIndex);
importAdaptor->placeImportedItemToScene(scene, page);
UBPersistenceManager::persistenceManager()->persistDocumentScene(document, scene, pageIndex);
}
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
UBApplication::showMessage(tr("Import successful."));
}
UBApplication::setDisabled(false);
return document;
}
}
return NULL;
}
int UBDocumentManager::addFilesToDocument(UBDocumentProxy* document, QStringList fileNames)
{
int nImportedDocuments = 0;
foreach(const QString& fileName, fileNames)
{
UBApplication::showMessage(tr("Importing file %1").arg(fileName));
QFile file(fileName);
QFileInfo fileInfo(file);
foreach (UBImportAdaptor *adaptor, mImportAdaptors)
{
if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1)
{
UBApplication::setDisabled(true);
if (adaptor->isDocumentBased())
{
UBDocumentBasedImportAdaptor* importAdaptor = (UBDocumentBasedImportAdaptor*)adaptor;
if (importAdaptor->addFileToDocument(document, file))
nImportedDocuments++;
}
else
{
UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor;
QUuid uuid = QUuid::createUuid();
QString filepath = file.fileName();
if (importAdaptor->folderToCopy() != "")
{
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, file.fileName(), importAdaptor->folderToCopy() , uuid, filepath);
if (!b)
{
continue;
}
}
QList<UBGraphicsItem*> pages = importAdaptor->import(uuid, filepath);
int nPage = 0;
foreach(UBGraphicsItem* page, pages)
{
UBApplication::showMessage(tr("Inserting page %1 of %2").arg(++nPage).arg(pages.size()), true);
int pageIndex = document->pageCount();
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(document, pageIndex);
importAdaptor->placeImportedItemToScene(scene, page);
UBPersistenceManager::persistenceManager()->persistDocumentScene(document, scene, pageIndex);
UBApplication::boardController->addEmptyThumbPage();
}
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
UBApplication::showMessage(tr("Import of file %1 successful.").arg(file.fileName()));
nImportedDocuments++;
}
UBApplication::setDisabled(false);
}
}
}
return nImportedDocuments;
}
int UBDocumentManager::addImageDirToDocument(const QDir& pDir, UBDocumentProxy* pDocument)
{
QStringList filenames = pDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
filenames = UBStringUtils::sortByLastDigit(filenames);
QStringList fileNames;
foreach(QString f, filenames)
{
fileNames << pDir.absolutePath() + "/" + f;
}
return addFilesToDocument(pDocument, fileNames);
}
UBDocumentProxy* UBDocumentManager::importDir(const QDir& pDir, const QString& pGroup)
{
UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument(pGroup, pDir.dirName());
int result = addImageDirToDocument(pDir, doc);
if (result > 0)
{
doc->setMetaData(UBSettings::documentGroupName, pGroup);
doc->setMetaData(UBSettings::documentName, pDir.dirName());
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(doc);
UBApplication::showMessage(tr("File %1 saved").arg(pDir.dirName()));
}
else
{
UBPersistenceManager::persistenceManager()->deleteDocument(doc);
}
return doc;
}
QList<UBExportAdaptor*> UBDocumentManager::supportedExportAdaptors()
{
return mExportAdaptors;
}
void UBDocumentManager::emitDocumentUpdated(UBDocumentProxy* pDocument)
{
emit documentUpdated(pDocument);
}
#include "UBDocumentManager.h"
#include "frameworks/UBStringUtils.h"
#include "adaptors/UBExportFullPDF.h"
#include "adaptors/UBExportDocument.h"
#include "adaptors/UBExportWeb.h"
#include "adaptors/UBExportCFF.h"
#include "adaptors/UBWebPublisher.h"
#include "adaptors/UBImportDocument.h"
#include "adaptors/UBImportPDF.h"
#include "adaptors/UBImportImage.h"
#include "adaptors/UBImportCFF.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsPixmapItem.h"
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentController.h"
#include "board/UBBoardController.h"
#include "UBApplication.h"
#include "UBSettings.h"
#include "UBPersistenceManager.h"
#include "../adaptors/UBExportWeb.h"
#include "core/memcheck.h"
UBDocumentManager* UBDocumentManager::sDocumentManager = 0;
UBDocumentManager* UBDocumentManager::documentManager()
{
if (!sDocumentManager)
{
sDocumentManager = new UBDocumentManager(qApp);
}
return sDocumentManager;
}
UBDocumentManager::UBDocumentManager(QObject *parent)
:QObject(parent)
{
// TODO UB 4.7 string used in document persistence (folder names)
QString dummyImages = tr("images");
QString dummyVideos = tr("videos");
QString dummyObjects = tr("objects");
QString dummyWidgets = tr("widgets");
UBExportCFF* cffExporter = new UBExportCFF(this);
UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this);
UBExportDocument* exportDocument = new UBExportDocument(this);
UBWebPublisher* webPublished = new UBWebPublisher(this);
mExportAdaptors.append(exportDocument);
mExportAdaptors.append(webPublished);
mExportAdaptors.append(exportFullPdf);
mExportAdaptors.append(cffExporter);
// UBExportWeb* exportWeb = new UBExportWeb(this);
// mExportAdaptors.append(exportWeb);
UBImportDocument* documentImport = new UBImportDocument(this);
mImportAdaptors.append(documentImport);
UBImportPDF* pdfImport = new UBImportPDF(this);
mImportAdaptors.append(pdfImport);
UBImportImage* imageImport = new UBImportImage(this);
mImportAdaptors.append(imageImport);
UBImportCFF* cffImport = new UBImportCFF(this);
mImportAdaptors.append(cffImport);
}
UBDocumentManager::~UBDocumentManager()
{
// NOOP
}
QStringList UBDocumentManager::importFileExtensions()
{
QStringList result;
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{
result << importAdaptor->supportedExtentions();
}
return result;
}
QString UBDocumentManager::importFileFilter()
{
QString result;
result += tr("All supported files (*.%1)").arg(importFileExtensions().join(" *."));
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{
if (importAdaptor->importFileFilter().length() > 0)
{
if (result.length())
{
result += ";;";
}
result += importAdaptor->importFileFilter();
}
}
qDebug() << "import file filter" << result;
return result;
}
UBDocumentProxy* UBDocumentManager::importFile(const QFile& pFile, const QString& pGroup)
{
QFileInfo fileInfo(pFile);
foreach (UBImportAdaptor *adaptor, mImportAdaptors)
{
if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1)
{
UBDocumentProxy* document;
UBApplication::setDisabled(true);
if (adaptor->isDocumentBased())
{
UBDocumentBasedImportAdaptor* importAdaptor = (UBDocumentBasedImportAdaptor*)adaptor;
document = importAdaptor->importFile(pFile, pGroup);
}
else
{
UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor;
// Document import procedure.....
QString documentName = QFileInfo(pFile.fileName()).completeBaseName();
document = UBPersistenceManager::persistenceManager()->createDocument(pGroup, documentName);
QUuid uuid = QUuid::createUuid();
QString filepath = pFile.fileName();
if (importAdaptor->folderToCopy() != "")
{
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, pFile.fileName(), importAdaptor->folderToCopy() , uuid, filepath);
if (!b)
{
UBPersistenceManager::persistenceManager()->deleteDocument(document);
UBApplication::setDisabled(false);
return NULL;
}
}
QList<UBGraphicsItem*> pages = importAdaptor->import(uuid, filepath);
int nPage = 0;
foreach(UBGraphicsItem* page, pages)
{
UBApplication::showMessage(tr("Inserting page %1 of %2").arg(++nPage).arg(pages.size()), true);
#ifdef Q_WS_MACX
//Workaround for issue 912
QApplication::processEvents();
#endif
int pageIndex = document->pageCount();
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(document, pageIndex);
importAdaptor->placeImportedItemToScene(scene, page);
UBPersistenceManager::persistenceManager()->persistDocumentScene(document, scene, pageIndex);
}
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
UBApplication::showMessage(tr("Import successful."));
}
UBApplication::setDisabled(false);
return document;
}
}
return NULL;
}
int UBDocumentManager::addFilesToDocument(UBDocumentProxy* document, QStringList fileNames)
{
int nImportedDocuments = 0;
foreach(const QString& fileName, fileNames)
{
UBApplication::showMessage(tr("Importing file %1").arg(fileName));
QFile file(fileName);
QFileInfo fileInfo(file);
foreach (UBImportAdaptor *adaptor, mImportAdaptors)
{
if (adaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1)
{
UBApplication::setDisabled(true);
if (adaptor->isDocumentBased())
{
UBDocumentBasedImportAdaptor* importAdaptor = (UBDocumentBasedImportAdaptor*)adaptor;
if (importAdaptor->addFileToDocument(document, file))
nImportedDocuments++;
}
else
{
UBPageBasedImportAdaptor* importAdaptor = (UBPageBasedImportAdaptor*)adaptor;
QUuid uuid = QUuid::createUuid();
QString filepath = file.fileName();
if (importAdaptor->folderToCopy() != "")
{
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(document, file.fileName(), importAdaptor->folderToCopy() , uuid, filepath);
if (!b)
{
continue;
}
}
QList<UBGraphicsItem*> pages = importAdaptor->import(uuid, filepath);
int nPage = 0;
foreach(UBGraphicsItem* page, pages)
{
UBApplication::showMessage(tr("Inserting page %1 of %2").arg(++nPage).arg(pages.size()), true);
int pageIndex = document->pageCount();
UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(document, pageIndex);
importAdaptor->placeImportedItemToScene(scene, page);
UBPersistenceManager::persistenceManager()->persistDocumentScene(document, scene, pageIndex);
UBApplication::boardController->addEmptyThumbPage();
}
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
UBApplication::showMessage(tr("Import of file %1 successful.").arg(file.fileName()));
nImportedDocuments++;
}
UBApplication::setDisabled(false);
}
}
}
return nImportedDocuments;
}
int UBDocumentManager::addImageDirToDocument(const QDir& pDir, UBDocumentProxy* pDocument)
{
QStringList filenames = pDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
filenames = UBStringUtils::sortByLastDigit(filenames);
QStringList fileNames;
foreach(QString f, filenames)
{
fileNames << pDir.absolutePath() + "/" + f;
}
return addFilesToDocument(pDocument, fileNames);
}
UBDocumentProxy* UBDocumentManager::importDir(const QDir& pDir, const QString& pGroup)
{
UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument(pGroup, pDir.dirName());
int result = addImageDirToDocument(pDir, doc);
if (result > 0)
{
doc->setMetaData(UBSettings::documentGroupName, pGroup);
doc->setMetaData(UBSettings::documentName, pDir.dirName());
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(doc);
UBApplication::showMessage(tr("File %1 saved").arg(pDir.dirName()));
}
else
{
UBPersistenceManager::persistenceManager()->deleteDocument(doc);
}
return doc;
}
QList<UBExportAdaptor*> UBDocumentManager::supportedExportAdaptors()
{
return mExportAdaptors;
}
void UBDocumentManager::emitDocumentUpdated(UBDocumentProxy* pDocument)
{
emit documentUpdated(pDocument);
}

@ -28,22 +28,22 @@
UBWindowCapture::UBWindowCapture(UBDesktopAnnotationController *parent)
: QObject(parent)
, mParent(parent)
: QObject(parent)
, mParent(parent)
{
// NOOP
// NOOP
}
UBWindowCapture::~UBWindowCapture()
{
// NOOP
// NOOP
}
const QPixmap UBWindowCapture::getCapturedWindow()
{
return mWindowPixmap;
return mWindowPixmap;
}
@ -51,20 +51,20 @@ int UBWindowCapture::execute()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *path = [NSString pathWithComponents: [NSArray arrayWithObjects: NSTemporaryDirectory(),
[[NSString stringWithFormat:@"%d",[NSDate timeIntervalSinceReferenceDate]] stringByAppendingPathExtension:@"uninote"],
nil]];
[[NSString stringWithFormat:@"%d",[NSDate timeIntervalSinceReferenceDate]] stringByAppendingPathExtension:@"uninote"],
nil]];
NSTask *task = [[NSTask alloc] init];
NSArray *arguments = [NSArray arrayWithObjects: @"-i", @"-W", @"-m", @"-tpng", path, nil];
NSArray *arguments = [NSArray arrayWithObjects: @"-i", @"-W", @"-m", @"-tpng", path, nil];
[task setLaunchPath: @"/usr/sbin/screencapture"];
[task setArguments: arguments];
[task launch];
[task waitUntilExit];
[task release];
QString resultPath = QString::fromUtf8([path UTF8String], strlen([path UTF8String]));
mWindowPixmap.load(resultPath);
QFile::remove(resultPath);

@ -19,128 +19,128 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBDocumentContainer.h"
#include "adaptors/UBThumbnailAdaptor.h"
#include "core/UBPersistenceManager.h"
#include "core/memcheck.h"
UBDocumentContainer::UBDocumentContainer(QObject * parent)
:QObject(parent)
,mCurrentDocument(NULL)
{}
UBDocumentContainer::~UBDocumentContainer()
{
foreach(const QPixmap* pm, mDocumentThumbs){
delete pm;
pm = NULL;
}
}
void UBDocumentContainer::setDocument(UBDocumentProxy* document, bool forceReload)
{
if (mCurrentDocument != document || forceReload)
{
mCurrentDocument = document;
reloadThumbnails();
emit documentSet(mCurrentDocument);
}
}
void UBDocumentContainer::duplicatePages(QList<int>& pageIndexes)
{
int offset = 0;
foreach(int sceneIndex, pageIndexes)
{
UBPersistenceManager::persistenceManager()->duplicateDocumentScene(mCurrentDocument, sceneIndex + offset);
offset++;
}
}
bool UBDocumentContainer::movePageToIndex(int source, int target)
{
if (source==0)
{
// Title page - cant be moved
return false;
}
UBPersistenceManager::persistenceManager()->moveSceneToIndex(mCurrentDocument, source, target);
deleteThumbPage(source);
insertThumbPage(target);
emit documentThumbnailsUpdated(this);
return true;
}
void UBDocumentContainer::deletePages(QList<int>& pageIndexes)
{
UBPersistenceManager::persistenceManager()->deleteDocumentScenes(mCurrentDocument, pageIndexes);
int offset = 0;
foreach(int index, pageIndexes)
{
deleteThumbPage(index - offset);
offset++;
}
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::addPage(int index)
{
UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mCurrentDocument, index);
insertThumbPage(index);
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::updatePage(int index)
{
updateThumbPage(index);
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::deleteThumbPage(int index)
{
mDocumentThumbs.removeAt(index);
}
void UBDocumentContainer::updateThumbPage(int index)
{
mDocumentThumbs[index] = UBThumbnailAdaptor::get(mCurrentDocument, index);
emit documentPageUpdated(index);
}
void UBDocumentContainer::insertThumbPage(int index)
{
mDocumentThumbs.insert(index, UBThumbnailAdaptor::get(mCurrentDocument, index));
}
void UBDocumentContainer::reloadThumbnails()
{
if (mCurrentDocument)
{
UBThumbnailAdaptor::load(mCurrentDocument, mDocumentThumbs);
qDebug() << "Reloading Thumbnails. new mDocumentThumbs size: " << mDocumentThumbs.size();
emit documentThumbnailsUpdated(this);
}
}
int UBDocumentContainer::pageFromSceneIndex(int sceneIndex)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool())
return sceneIndex;
return sceneIndex+1;
}
int UBDocumentContainer::sceneIndexFromPage(int page)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool())
return page;
return page-1;
}
void UBDocumentContainer::addEmptyThumbPage()
{
const QPixmap* pThumb = new QPixmap();
mDocumentThumbs.append(pThumb);
}
#include "UBDocumentContainer.h"
#include "adaptors/UBThumbnailAdaptor.h"
#include "core/UBPersistenceManager.h"
#include "core/memcheck.h"
UBDocumentContainer::UBDocumentContainer(QObject * parent)
:QObject(parent)
,mCurrentDocument(NULL)
{}
UBDocumentContainer::~UBDocumentContainer()
{
foreach(const QPixmap* pm, mDocumentThumbs){
delete pm;
pm = NULL;
}
}
void UBDocumentContainer::setDocument(UBDocumentProxy* document, bool forceReload)
{
if (mCurrentDocument != document || forceReload)
{
mCurrentDocument = document;
reloadThumbnails();
emit documentSet(mCurrentDocument);
}
}
void UBDocumentContainer::duplicatePages(QList<int>& pageIndexes)
{
int offset = 0;
foreach(int sceneIndex, pageIndexes)
{
UBPersistenceManager::persistenceManager()->duplicateDocumentScene(mCurrentDocument, sceneIndex + offset);
offset++;
}
}
bool UBDocumentContainer::movePageToIndex(int source, int target)
{
if (source==0)
{
// Title page - cant be moved
return false;
}
UBPersistenceManager::persistenceManager()->moveSceneToIndex(mCurrentDocument, source, target);
deleteThumbPage(source);
insertThumbPage(target);
emit documentThumbnailsUpdated(this);
return true;
}
void UBDocumentContainer::deletePages(QList<int>& pageIndexes)
{
UBPersistenceManager::persistenceManager()->deleteDocumentScenes(mCurrentDocument, pageIndexes);
int offset = 0;
foreach(int index, pageIndexes)
{
deleteThumbPage(index - offset);
offset++;
}
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::addPage(int index)
{
UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mCurrentDocument, index);
insertThumbPage(index);
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::updatePage(int index)
{
updateThumbPage(index);
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::deleteThumbPage(int index)
{
mDocumentThumbs.removeAt(index);
}
void UBDocumentContainer::updateThumbPage(int index)
{
mDocumentThumbs[index] = UBThumbnailAdaptor::get(mCurrentDocument, index);
emit documentPageUpdated(index);
}
void UBDocumentContainer::insertThumbPage(int index)
{
mDocumentThumbs.insert(index, UBThumbnailAdaptor::get(mCurrentDocument, index));
}
void UBDocumentContainer::reloadThumbnails()
{
if (mCurrentDocument)
{
UBThumbnailAdaptor::load(mCurrentDocument, mDocumentThumbs);
qDebug() << "Reloading Thumbnails. new mDocumentThumbs size: " << mDocumentThumbs.size();
emit documentThumbnailsUpdated(this);
}
}
int UBDocumentContainer::pageFromSceneIndex(int sceneIndex)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool())
return sceneIndex;
return sceneIndex+1;
}
int UBDocumentContainer::sceneIndexFromPage(int page)
{
if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool())
return page;
return page-1;
}
void UBDocumentContainer::addEmptyThumbPage()
{
const QPixmap* pThumb = new QPixmap();
mDocumentThumbs.append(pThumb);
}

@ -19,54 +19,54 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOCUMENTCONTAINER_H_
#define UBDOCUMENTCONTAINER_H_
#include <QtGui>
#include "UBDocumentProxy.h"
class UBDocumentContainer : public QObject
{
Q_OBJECT
public:
UBDocumentContainer(QObject * parent = 0);
virtual ~UBDocumentContainer();
void setDocument(UBDocumentProxy* document, bool forceReload = false);
UBDocumentProxy* selectedDocument(){return mCurrentDocument;}
int pageCount(){return mDocumentThumbs.size();}
const QPixmap* pageAt(int index){return mDocumentThumbs[index];}
static int pageFromSceneIndex(int sceneIndex);
static int sceneIndexFromPage(int sceneIndex);
void duplicatePages(QList<int>& pageIndexes);
bool movePageToIndex(int source, int target);
void deletePages(QList<int>& pageIndexes);
void addPage(int index);
void updatePage(int index);
void addEmptyThumbPage();
private:
UBDocumentProxy* mCurrentDocument;
QList<const QPixmap*> mDocumentThumbs;
protected:
void deleteThumbPage(int index);
void updateThumbPage(int index);
void insertThumbPage(int index);
void reloadThumbnails();
signals:
void documentSet(UBDocumentProxy* document);
void documentPageUpdated(int index);
void documentThumbnailsUpdated(UBDocumentContainer* source);
};
#endif /* UBDOCUMENTPROXY_H_ */
#ifndef UBDOCUMENTCONTAINER_H_
#define UBDOCUMENTCONTAINER_H_
#include <QtGui>
#include "UBDocumentProxy.h"
class UBDocumentContainer : public QObject
{
Q_OBJECT
public:
UBDocumentContainer(QObject * parent = 0);
virtual ~UBDocumentContainer();
void setDocument(UBDocumentProxy* document, bool forceReload = false);
UBDocumentProxy* selectedDocument(){return mCurrentDocument;}
int pageCount(){return mDocumentThumbs.size();}
const QPixmap* pageAt(int index){return mDocumentThumbs[index];}
static int pageFromSceneIndex(int sceneIndex);
static int sceneIndexFromPage(int sceneIndex);
void duplicatePages(QList<int>& pageIndexes);
bool movePageToIndex(int source, int target);
void deletePages(QList<int>& pageIndexes);
void addPage(int index);
void updatePage(int index);
void addEmptyThumbPage();
private:
UBDocumentProxy* mCurrentDocument;
QList<const QPixmap*> mDocumentThumbs;
protected:
void deleteThumbPage(int index);
void updateThumbPage(int index);
void insertThumbPage(int index);
void reloadThumbnails();
signals:
void documentSet(UBDocumentProxy* document);
void documentPageUpdated(int index);
void documentThumbnailsUpdated(UBDocumentContainer* source);
};
#endif /* UBDOCUMENTPROXY_H_ */

File diff suppressed because it is too large Load Diff

@ -19,136 +19,136 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOCUMENTCONTROLLER_H_
#define UBDOCUMENTCONTROLLER_H_
#include <QtGui>
#include "document/UBDocumentContainer.h"
namespace Ui
{
class documents;
}
#include "gui/UBMessageWindow.h"
class UBGraphicsScene;
class QDialog;
class UBDocumentProxy;
class UBBoardController;
class UBThumbnailsScene;
class UBDocumentGroupTreeItem;
class UBDocumentProxyTreeItem;
class UBMainWindow;
class UBDocumentToolsPalette;
class UBDocumentController : public UBDocumentContainer
{
Q_OBJECT;
public:
UBDocumentController(UBMainWindow* mainWindow);
virtual ~UBDocumentController();
void closing();
QWidget* controlView();
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy);
bool addFileToDocument(UBDocumentProxy* document);
void deletePages(QList<QGraphicsItem*> itemsToDelete);
int getSelectedItemIndex();
bool pageCanBeMovedUp(int page);
bool pageCanBeMovedDown(int page);
bool pageCanBeDuplicated(int page);
bool pageCanBeDeleted(int page);
QString documentTrashGroupName(){ return mDocumentTrashGroupName;}
QString defaultDocumentGroupName(){ return mDefaultDocumentGroupName;}
signals:
void exportDone();
public slots:
void createNewDocument();
void createNewDocumentGroup();
void deleteSelectedItem();
void renameSelectedItem();
void openSelectedItem();
void duplicateSelectedItem();
void importFile();
void moveSceneToIndex(UBDocumentProxy* proxy, int source, int target);
void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true);
void show();
void hide();
void showMessage(const QString& message, bool showSpinningWheel = false);
void hideMessage();
void toggleDocumentToolsPalette();
void cut();
void copy();
void paste();
void focusChanged(QWidget *old, QWidget *current);
protected:
virtual void setupViews();
virtual void setupToolbar();
void setupPalettes();
bool isOKToOpenDocument(UBDocumentProxy* proxy);
UBDocumentProxy* selectedDocumentProxy();
UBDocumentProxyTreeItem* selectedDocumentProxyTreeItem();
UBDocumentGroupTreeItem* selectedDocumentGroupTreeItem();
QStringList allGroupNames();
enum LastSelectedElementType
{
None = 0, Folder, Document, Page
};
LastSelectedElementType mSelectionType;
private:
QWidget *mParentWidget;
UBBoardController *mBoardController;
Ui::documents* mDocumentUI;
UBMainWindow* mMainWindow;
QWidget *mDocumentWidget;
QPointer<UBMessageWindow> mMessageWindow;
QAction* mAddFolderOfImagesAction;
QAction* mAddFileToDocumentAction;
QAction* mAddImagesAction;
bool mIsClosing;
UBDocumentToolsPalette *mToolsPalette;
bool mToolsPalettePositionned;
UBDocumentGroupTreeItem* mTrashTi;
void moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi);
void moveFolderToTrash(UBDocumentGroupTreeItem* groupTi);
QString mDocumentTrashGroupName;
QString mDefaultDocumentGroupName;
private slots:
void documentZoomSliderValueChanged (int value);
void loadDocumentProxies();
void itemSelectionChanged();
void exportDocument();
void itemChanged(QTreeWidgetItem * item, int column);
void thumbnailViewResized();
void pageSelectionChanged();
void selectionChanged();
void documentSceneChanged(UBDocumentProxy* proxy, int pSceneIndex);
void pageDoubleClicked(QGraphicsItem* item, int index);
void pageClicked(QGraphicsItem* item, int index);
void itemClicked(QTreeWidgetItem * item, int column );
void addToDocument();
void addDocumentInTree(UBDocumentProxy* pDocument);
void updateDocumentInTree(UBDocumentProxy* pDocument);
void addFolderOfImages();
void addFileToDocument();
void addImages();
void refreshDocumentThumbnailsView(UBDocumentContainer* source);
};
#endif /* UBDOCUMENTCONTROLLER_H_ */
#ifndef UBDOCUMENTCONTROLLER_H_
#define UBDOCUMENTCONTROLLER_H_
#include <QtGui>
#include "document/UBDocumentContainer.h"
namespace Ui
{
class documents;
}
#include "gui/UBMessageWindow.h"
class UBGraphicsScene;
class QDialog;
class UBDocumentProxy;
class UBBoardController;
class UBThumbnailsScene;
class UBDocumentGroupTreeItem;
class UBDocumentProxyTreeItem;
class UBMainWindow;
class UBDocumentToolsPalette;
class UBDocumentController : public UBDocumentContainer
{
Q_OBJECT;
public:
UBDocumentController(UBMainWindow* mainWindow);
virtual ~UBDocumentController();
void closing();
QWidget* controlView();
UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy);
bool addFileToDocument(UBDocumentProxy* document);
void deletePages(QList<QGraphicsItem*> itemsToDelete);
int getSelectedItemIndex();
bool pageCanBeMovedUp(int page);
bool pageCanBeMovedDown(int page);
bool pageCanBeDuplicated(int page);
bool pageCanBeDeleted(int page);
QString documentTrashGroupName(){ return mDocumentTrashGroupName;}
QString defaultDocumentGroupName(){ return mDefaultDocumentGroupName;}
signals:
void exportDone();
public slots:
void createNewDocument();
void createNewDocumentGroup();
void deleteSelectedItem();
void renameSelectedItem();
void openSelectedItem();
void duplicateSelectedItem();
void importFile();
void moveSceneToIndex(UBDocumentProxy* proxy, int source, int target);
void selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument = true);
void show();
void hide();
void showMessage(const QString& message, bool showSpinningWheel = false);
void hideMessage();
void toggleDocumentToolsPalette();
void cut();
void copy();
void paste();
void focusChanged(QWidget *old, QWidget *current);
protected:
virtual void setupViews();
virtual void setupToolbar();
void setupPalettes();
bool isOKToOpenDocument(UBDocumentProxy* proxy);
UBDocumentProxy* selectedDocumentProxy();
UBDocumentProxyTreeItem* selectedDocumentProxyTreeItem();
UBDocumentGroupTreeItem* selectedDocumentGroupTreeItem();
QStringList allGroupNames();
enum LastSelectedElementType
{
None = 0, Folder, Document, Page
};
LastSelectedElementType mSelectionType;
private:
QWidget *mParentWidget;
UBBoardController *mBoardController;
Ui::documents* mDocumentUI;
UBMainWindow* mMainWindow;
QWidget *mDocumentWidget;
QPointer<UBMessageWindow> mMessageWindow;
QAction* mAddFolderOfImagesAction;
QAction* mAddFileToDocumentAction;
QAction* mAddImagesAction;
bool mIsClosing;
UBDocumentToolsPalette *mToolsPalette;
bool mToolsPalettePositionned;
UBDocumentGroupTreeItem* mTrashTi;
void moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi);
void moveFolderToTrash(UBDocumentGroupTreeItem* groupTi);
QString mDocumentTrashGroupName;
QString mDefaultDocumentGroupName;
private slots:
void documentZoomSliderValueChanged (int value);
void loadDocumentProxies();
void itemSelectionChanged();
void exportDocument();
void itemChanged(QTreeWidgetItem * item, int column);
void thumbnailViewResized();
void pageSelectionChanged();
void selectionChanged();
void documentSceneChanged(UBDocumentProxy* proxy, int pSceneIndex);
void pageDoubleClicked(QGraphicsItem* item, int index);
void pageClicked(QGraphicsItem* item, int index);
void itemClicked(QTreeWidgetItem * item, int column );
void addToDocument();
void addDocumentInTree(UBDocumentProxy* pDocument);
void updateDocumentInTree(UBDocumentProxy* pDocument);
void addFolderOfImages();
void addFileToDocument();
void addImages();
void refreshDocumentThumbnailsView(UBDocumentContainer* source);
};
#endif /* UBDOCUMENTCONTROLLER_H_ */

@ -19,222 +19,222 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBDocumentProxy.h"
#include "frameworks/UBStringUtils.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBSettings.h"
#include "core/UBDocumentManager.h"
#include "core/memcheck.h"
UBDocumentProxy::UBDocumentProxy()
: mPageCount(0)
{
init();
}
UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath)
: mPageCount(0)
{
init();
setPersistencePath(pPersistancePath);
}
void UBDocumentProxy::init()
{
setMetaData(UBSettings::documentGroupName, "");
QDateTime now = QDateTime::currentDateTime();
setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate));
setUuid(QUuid::createUuid());
setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize());
//teacherGuide metadata
setMetaData(UBSettings::sessionTitle,"");
setMetaData(UBSettings::sessionAuthors,"");
setMetaData(UBSettings::sessionObjectives,"");
setMetaData(UBSettings::sessionKeywords,"");
setMetaData(UBSettings::sessionGradeLevel,"");
setMetaData(UBSettings::sessionSubjects,"");
setMetaData(UBSettings::sessionType,"");
setMetaData(UBSettings::sessionLicence,"");
}
UBDocumentProxy::~UBDocumentProxy()
{
// NOOP
}
int UBDocumentProxy::pageCount()
{
return mPageCount;
}
void UBDocumentProxy::setPageCount(int pPageCount)
{
mPageCount = pPageCount;
}
int UBDocumentProxy::incPageCount()
{
if (mPageCount <= 0)
{
mPageCount = 1;
}
else
{
mPageCount++;
}
return mPageCount;
}
int UBDocumentProxy::decPageCount()
{
mPageCount --;
if (mPageCount < 0)
{
mPageCount = 0;
}
return mPageCount;
}
QString UBDocumentProxy::persistencePath() const
{
return mPersistencePath;
}
void UBDocumentProxy::setPersistencePath(const QString& pPersistencePath)
{
if (pPersistencePath != mPersistencePath)
{
mIsModified = true;
mPersistencePath = pPersistencePath;
}
}
void UBDocumentProxy::setMetaData(const QString& pKey, const QVariant& pValue)
{
if (mMetaDatas.contains(pKey) && mMetaDatas.value(pKey) == pValue)
return;
else
{
mIsModified = true;
mMetaDatas.insert(pKey, pValue);
if (pKey == UBSettings::documentUpdatedAt)
{
UBDocumentManager *documentManager = UBDocumentManager::documentManager();
if (documentManager)
documentManager->emitDocumentUpdated(this);
}
}
}
QVariant UBDocumentProxy::metaData(const QString& pKey) const
{
if (mMetaDatas.contains(pKey))
{
return mMetaDatas.value(pKey);
}
else
{
qDebug() << "Unknown metadata key" << pKey;
return QString(""); // failsafe
}
}
QHash<QString, QVariant> UBDocumentProxy::metaDatas() const
{
return mMetaDatas;
}
QString UBDocumentProxy::name() const
{
return metaData(UBSettings::documentName).toString();
}
QString UBDocumentProxy::groupName() const
{
return metaData(UBSettings::documentGroupName).toString();
}
QSize UBDocumentProxy::defaultDocumentSize() const
{
if (mMetaDatas.contains(UBSettings::documentSize))
return metaData(UBSettings::documentSize).toSize();
else
return UBSettings::settings()->pageSize->get().toSize();
}
void UBDocumentProxy::setDefaultDocumentSize(QSize pSize)
{
if (defaultDocumentSize() != pSize)
{
setMetaData(UBSettings::documentSize, QVariant(pSize));
emit defaultDocumentSizeChanged();
mIsModified = true;
}
}
void UBDocumentProxy::setDefaultDocumentSize(int pWidth, int pHeight)
{
setDefaultDocumentSize(QSize(pWidth, pHeight));
}
QUuid UBDocumentProxy::uuid() const
{
QString id = metaData(UBSettings::documentIdentifer).toString();
QString sUuid = id.replace(UBSettings::uniboardDocumentNamespaceUri + "/", "");
return QUuid(sUuid);
}
void UBDocumentProxy::setUuid(const QUuid& uuid)
{
setMetaData(UBSettings::documentIdentifer,
UBSettings::uniboardDocumentNamespaceUri + "/" + UBStringUtils::toCanonicalUuid(uuid));
}
QDateTime UBDocumentProxy::documentDate()
{
if(mMetaDatas.contains(UBSettings::documentDate))
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentDate).toString());
return QDateTime::currentDateTime();
}
QDateTime UBDocumentProxy::lastUpdate()
{
if(mMetaDatas.contains(UBSettings::documentUpdatedAt))
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentUpdatedAt).toString());
return QDateTime().currentDateTime();
}
bool UBDocumentProxy::isModified() const
{
return mIsModified;
}
#include "UBDocumentProxy.h"
#include "frameworks/UBStringUtils.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBSettings.h"
#include "core/UBDocumentManager.h"
#include "core/memcheck.h"
UBDocumentProxy::UBDocumentProxy()
: mPageCount(0)
{
init();
}
UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath)
: mPageCount(0)
{
init();
setPersistencePath(pPersistancePath);
}
void UBDocumentProxy::init()
{
setMetaData(UBSettings::documentGroupName, "");
QDateTime now = QDateTime::currentDateTime();
setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate));
setUuid(QUuid::createUuid());
setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize());
//teacherGuide metadata
setMetaData(UBSettings::sessionTitle,"");
setMetaData(UBSettings::sessionAuthors,"");
setMetaData(UBSettings::sessionObjectives,"");
setMetaData(UBSettings::sessionKeywords,"");
setMetaData(UBSettings::sessionGradeLevel,"");
setMetaData(UBSettings::sessionSubjects,"");
setMetaData(UBSettings::sessionType,"");
setMetaData(UBSettings::sessionLicence,"");
}
UBDocumentProxy::~UBDocumentProxy()
{
// NOOP
}
int UBDocumentProxy::pageCount()
{
return mPageCount;
}
void UBDocumentProxy::setPageCount(int pPageCount)
{
mPageCount = pPageCount;
}
int UBDocumentProxy::incPageCount()
{
if (mPageCount <= 0)
{
mPageCount = 1;
}
else
{
mPageCount++;
}
return mPageCount;
}
int UBDocumentProxy::decPageCount()
{
mPageCount --;
if (mPageCount < 0)
{
mPageCount = 0;
}
return mPageCount;
}
QString UBDocumentProxy::persistencePath() const
{
return mPersistencePath;
}
void UBDocumentProxy::setPersistencePath(const QString& pPersistencePath)
{
if (pPersistencePath != mPersistencePath)
{
mIsModified = true;
mPersistencePath = pPersistencePath;
}
}
void UBDocumentProxy::setMetaData(const QString& pKey, const QVariant& pValue)
{
if (mMetaDatas.contains(pKey) && mMetaDatas.value(pKey) == pValue)
return;
else
{
mIsModified = true;
mMetaDatas.insert(pKey, pValue);
if (pKey == UBSettings::documentUpdatedAt)
{
UBDocumentManager *documentManager = UBDocumentManager::documentManager();
if (documentManager)
documentManager->emitDocumentUpdated(this);
}
}
}
QVariant UBDocumentProxy::metaData(const QString& pKey) const
{
if (mMetaDatas.contains(pKey))
{
return mMetaDatas.value(pKey);
}
else
{
qDebug() << "Unknown metadata key" << pKey;
return QString(""); // failsafe
}
}
QHash<QString, QVariant> UBDocumentProxy::metaDatas() const
{
return mMetaDatas;
}
QString UBDocumentProxy::name() const
{
return metaData(UBSettings::documentName).toString();
}
QString UBDocumentProxy::groupName() const
{
return metaData(UBSettings::documentGroupName).toString();
}
QSize UBDocumentProxy::defaultDocumentSize() const
{
if (mMetaDatas.contains(UBSettings::documentSize))
return metaData(UBSettings::documentSize).toSize();
else
return UBSettings::settings()->pageSize->get().toSize();
}
void UBDocumentProxy::setDefaultDocumentSize(QSize pSize)
{
if (defaultDocumentSize() != pSize)
{
setMetaData(UBSettings::documentSize, QVariant(pSize));
emit defaultDocumentSizeChanged();
mIsModified = true;
}
}
void UBDocumentProxy::setDefaultDocumentSize(int pWidth, int pHeight)
{
setDefaultDocumentSize(QSize(pWidth, pHeight));
}
QUuid UBDocumentProxy::uuid() const
{
QString id = metaData(UBSettings::documentIdentifer).toString();
QString sUuid = id.replace(UBSettings::uniboardDocumentNamespaceUri + "/", "");
return QUuid(sUuid);
}
void UBDocumentProxy::setUuid(const QUuid& uuid)
{
setMetaData(UBSettings::documentIdentifer,
UBSettings::uniboardDocumentNamespaceUri + "/" + UBStringUtils::toCanonicalUuid(uuid));
}
QDateTime UBDocumentProxy::documentDate()
{
if(mMetaDatas.contains(UBSettings::documentDate))
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentDate).toString());
return QDateTime::currentDateTime();
}
QDateTime UBDocumentProxy::lastUpdate()
{
if(mMetaDatas.contains(UBSettings::documentUpdatedAt))
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentUpdatedAt).toString());
return QDateTime().currentDateTime();
}
bool UBDocumentProxy::isModified() const
{
return mIsModified;
}

@ -19,89 +19,89 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOCUMENTPROXY_H_
#define UBDOCUMENTPROXY_H_
#include <QtGui>
#include "frameworks/UBStringUtils.h"
#include "core/UBSettings.h"
class UBGraphicsScene;
class UBDocumentProxy : public QObject
{
Q_OBJECT
friend class UBPersistenceManager;
public:
UBDocumentProxy();
UBDocumentProxy(const QString& pPersistencePath);
virtual ~UBDocumentProxy();
QString persistencePath() const;
void setPersistencePath(const QString& pPersistencePath);
void setMetaData(const QString& pKey , const QVariant& pValue);
QVariant metaData(const QString& pKey) const;
QHash<QString, QVariant> metaDatas() const;
QString name() const;
QString groupName() const;
QDateTime documentDate();
QDateTime lastUpdate();
QSize defaultDocumentSize() const;
void setDefaultDocumentSize(QSize pSize);
void setDefaultDocumentSize(int pWidth, int pHeight);
QUuid uuid() const;
void setUuid(const QUuid& uuid);
bool isModified() const;
int pageCount();
protected:
void setPageCount(int pPageCount);
int incPageCount();
int decPageCount();
signals:
void defaultDocumentSizeChanged();
private:
void init();
QString mPersistencePath;
QHash<QString, QVariant> mMetaDatas;
bool mIsModified;
int mPageCount;
};
inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2)
{
return proxy1.persistencePath() == proxy2.persistencePath();
}
inline uint qHash(const UBDocumentProxy &key)
{
return qHash(key.persistencePath());
}
#endif /* UBDOCUMENTPROXY_H_ */
#ifndef UBDOCUMENTPROXY_H_
#define UBDOCUMENTPROXY_H_
#include <QtGui>
#include "frameworks/UBStringUtils.h"
#include "core/UBSettings.h"
class UBGraphicsScene;
class UBDocumentProxy : public QObject
{
Q_OBJECT
friend class UBPersistenceManager;
public:
UBDocumentProxy();
UBDocumentProxy(const QString& pPersistencePath);
virtual ~UBDocumentProxy();
QString persistencePath() const;
void setPersistencePath(const QString& pPersistencePath);
void setMetaData(const QString& pKey , const QVariant& pValue);
QVariant metaData(const QString& pKey) const;
QHash<QString, QVariant> metaDatas() const;
QString name() const;
QString groupName() const;
QDateTime documentDate();
QDateTime lastUpdate();
QSize defaultDocumentSize() const;
void setDefaultDocumentSize(QSize pSize);
void setDefaultDocumentSize(int pWidth, int pHeight);
QUuid uuid() const;
void setUuid(const QUuid& uuid);
bool isModified() const;
int pageCount();
protected:
void setPageCount(int pPageCount);
int incPageCount();
int decPageCount();
signals:
void defaultDocumentSizeChanged();
private:
void init();
QString mPersistencePath;
QHash<QString, QVariant> mMetaDatas;
bool mIsModified;
int mPageCount;
};
inline bool operator==(const UBDocumentProxy &proxy1, const UBDocumentProxy &proxy2)
{
return proxy1.persistencePath() == proxy2.persistencePath();
}
inline uint qHash(const UBDocumentProxy &key)
{
return qHash(key.persistencePath());
}
#endif /* UBDOCUMENTPROXY_H_ */

File diff suppressed because it is too large Load Diff

@ -19,221 +19,221 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsItemUndoCommand.h"
#include <QtGui>
#include "UBGraphicsScene.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
#include "domain/UBGraphicsGroupContainerItem.h"
#include "domain/UBGraphicsPolygonItem.h"
UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet<QGraphicsItem*>& pRemovedItems,
const QSet<QGraphicsItem*>& pAddedItems, const GroupDataTable &groupsMap)
: mScene(pScene)
, mRemovedItems(pRemovedItems - pAddedItems)
, mAddedItems(pAddedItems - pRemovedItems)
, mExcludedFromGroup(groupsMap)
{
mFirstRedo = true;
QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
while (itAdded.hasNext())
{
UBApplication::boardController->freezeW3CWidget(itAdded.next(), true);
}
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
while (itRemoved.hasNext())
{
UBApplication::boardController->freezeW3CWidget(itRemoved.next(), false);
}
}
UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem,
QGraphicsItem* pAddedItem) :
mScene(pScene)
{
if (pRemovedItem)
{
mRemovedItems.insert(pRemovedItem);
}
if (pAddedItem)
{
mAddedItems.insert(pAddedItem);
}
mFirstRedo = true;
}
UBGraphicsItemUndoCommand::~UBGraphicsItemUndoCommand()
{
//NOOP
}
void UBGraphicsItemUndoCommand::undo()
{
if (!mScene){
return;
}
QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
while (itAdded.hasNext())
{
QGraphicsItem* item = itAdded.next();
UBApplication::boardController->freezeW3CWidget(item, true);
item->setSelected(false);
mScene->removeItem(item);
}
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
while (itRemoved.hasNext())
{
QGraphicsItem* item = itRemoved.next();
if (item)
{
if (UBItemLayerType::FixedBackground == item->data(UBGraphicsItemData::ItemLayerType))
mScene->setAsBackgroundObject(item);
else
mScene->addItem(item);
if (UBGraphicsPolygonItem::Type == item->type())
{
UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
if (polygonItem)
{
mScene->removeItem(polygonItem);
mScene->removeItemFromDeletion(polygonItem);
polygonItem->strokesGroup()->addToGroup(polygonItem);
}
}
UBApplication::boardController->freezeW3CWidget(item, false);
}
}
QMapIterator<UBGraphicsGroupContainerItem*, QUuid> curMapElement(mExcludedFromGroup);
UBGraphicsGroupContainerItem *nextGroup = NULL;
UBGraphicsGroupContainerItem *previousGroupItem = NULL;
bool groupChanged = false;
while (curMapElement.hasNext()) {
curMapElement.next();
groupChanged = previousGroupItem != curMapElement.key();
//trying to find the group on the scene;
if (!nextGroup || groupChanged) {
UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key();
if (groupCandidate) {
nextGroup = groupCandidate;
if(!mScene->items().contains(nextGroup)) {
mScene->addItem(nextGroup);
}
nextGroup->setVisible(true);
}
}
QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value());
if (groupedItem) {
nextGroup->addToGroup(groupedItem);
}
previousGroupItem = curMapElement.key();
UBGraphicsItem::Delegate(nextGroup)->update();
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
mScene->update(mScene->sceneRect());
}
void UBGraphicsItemUndoCommand::redo()
{
// the Undo framework calls a redo while appending the undo command.
// as we have already plotted the elements, we do not want to do it twice
if (!mFirstRedo)
{
if (!mScene){
return;
}
QMapIterator<UBGraphicsGroupContainerItem*, QUuid> curMapElement(mExcludedFromGroup);
UBGraphicsGroupContainerItem *nextGroup = NULL;
UBGraphicsGroupContainerItem *previousGroupItem = NULL;
bool groupChanged = false;
while (curMapElement.hasNext()) {
curMapElement.next();
groupChanged = previousGroupItem != curMapElement.key();
//trying to find the group on the scene;
if (!nextGroup || groupChanged) {
UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key();
if (groupCandidate) {
nextGroup = groupCandidate;
}
}
QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value());
if (groupedItem) {
if (nextGroup->childItems().count() == 1) {
nextGroup->destroy(false);
break;
}
nextGroup->removeFromGroup(groupedItem);
}
previousGroupItem = curMapElement.key();
UBGraphicsItem::Delegate(nextGroup)->update();
}
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
while (itRemoved.hasNext())
{
QGraphicsItem* item = itRemoved.next();
item->setSelected(false);
mScene->removeItem(item);
UBApplication::boardController->freezeW3CWidget(item, true);
}
QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
while (itAdded.hasNext())
{
QGraphicsItem* item = itAdded.next();
if (item)
{
UBApplication::boardController->freezeW3CWidget(item, false);
if (UBItemLayerType::FixedBackground == item->data(UBGraphicsItemData::ItemLayerType))
mScene->setAsBackgroundObject(item);
else
mScene->addItem(item);
UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
if (polygonItem)
{
mScene->removeItem(polygonItem);
mScene->removeItemFromDeletion(polygonItem);
polygonItem->strokesGroup()->addToGroup(polygonItem);
}
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2) to trigger repaint
mScene->update(mScene->sceneRect());
}
else
{
mFirstRedo = false;
}
}
#include "UBGraphicsItemUndoCommand.h"
#include <QtGui>
#include "UBGraphicsScene.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
#include "domain/UBGraphicsGroupContainerItem.h"
#include "domain/UBGraphicsPolygonItem.h"
UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet<QGraphicsItem*>& pRemovedItems,
const QSet<QGraphicsItem*>& pAddedItems, const GroupDataTable &groupsMap)
: mScene(pScene)
, mRemovedItems(pRemovedItems - pAddedItems)
, mAddedItems(pAddedItems - pRemovedItems)
, mExcludedFromGroup(groupsMap)
{
mFirstRedo = true;
QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
while (itAdded.hasNext())
{
UBApplication::boardController->freezeW3CWidget(itAdded.next(), true);
}
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
while (itRemoved.hasNext())
{
UBApplication::boardController->freezeW3CWidget(itRemoved.next(), false);
}
}
UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem,
QGraphicsItem* pAddedItem) :
mScene(pScene)
{
if (pRemovedItem)
{
mRemovedItems.insert(pRemovedItem);
}
if (pAddedItem)
{
mAddedItems.insert(pAddedItem);
}
mFirstRedo = true;
}
UBGraphicsItemUndoCommand::~UBGraphicsItemUndoCommand()
{
//NOOP
}
void UBGraphicsItemUndoCommand::undo()
{
if (!mScene){
return;
}
QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
while (itAdded.hasNext())
{
QGraphicsItem* item = itAdded.next();
UBApplication::boardController->freezeW3CWidget(item, true);
item->setSelected(false);
mScene->removeItem(item);
}
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
while (itRemoved.hasNext())
{
QGraphicsItem* item = itRemoved.next();
if (item)
{
if (UBItemLayerType::FixedBackground == item->data(UBGraphicsItemData::ItemLayerType))
mScene->setAsBackgroundObject(item);
else
mScene->addItem(item);
if (UBGraphicsPolygonItem::Type == item->type())
{
UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
if (polygonItem)
{
mScene->removeItem(polygonItem);
mScene->removeItemFromDeletion(polygonItem);
polygonItem->strokesGroup()->addToGroup(polygonItem);
}
}
UBApplication::boardController->freezeW3CWidget(item, false);
}
}
QMapIterator<UBGraphicsGroupContainerItem*, QUuid> curMapElement(mExcludedFromGroup);
UBGraphicsGroupContainerItem *nextGroup = NULL;
UBGraphicsGroupContainerItem *previousGroupItem = NULL;
bool groupChanged = false;
while (curMapElement.hasNext()) {
curMapElement.next();
groupChanged = previousGroupItem != curMapElement.key();
//trying to find the group on the scene;
if (!nextGroup || groupChanged) {
UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key();
if (groupCandidate) {
nextGroup = groupCandidate;
if(!mScene->items().contains(nextGroup)) {
mScene->addItem(nextGroup);
}
nextGroup->setVisible(true);
}
}
QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value());
if (groupedItem) {
nextGroup->addToGroup(groupedItem);
}
previousGroupItem = curMapElement.key();
UBGraphicsItem::Delegate(nextGroup)->update();
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
mScene->update(mScene->sceneRect());
}
void UBGraphicsItemUndoCommand::redo()
{
// the Undo framework calls a redo while appending the undo command.
// as we have already plotted the elements, we do not want to do it twice
if (!mFirstRedo)
{
if (!mScene){
return;
}
QMapIterator<UBGraphicsGroupContainerItem*, QUuid> curMapElement(mExcludedFromGroup);
UBGraphicsGroupContainerItem *nextGroup = NULL;
UBGraphicsGroupContainerItem *previousGroupItem = NULL;
bool groupChanged = false;
while (curMapElement.hasNext()) {
curMapElement.next();
groupChanged = previousGroupItem != curMapElement.key();
//trying to find the group on the scene;
if (!nextGroup || groupChanged) {
UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key();
if (groupCandidate) {
nextGroup = groupCandidate;
}
}
QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value());
if (groupedItem) {
if (nextGroup->childItems().count() == 1) {
nextGroup->destroy(false);
break;
}
nextGroup->removeFromGroup(groupedItem);
}
previousGroupItem = curMapElement.key();
UBGraphicsItem::Delegate(nextGroup)->update();
}
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
while (itRemoved.hasNext())
{
QGraphicsItem* item = itRemoved.next();
item->setSelected(false);
mScene->removeItem(item);
UBApplication::boardController->freezeW3CWidget(item, true);
}
QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
while (itAdded.hasNext())
{
QGraphicsItem* item = itAdded.next();
if (item)
{
UBApplication::boardController->freezeW3CWidget(item, false);
if (UBItemLayerType::FixedBackground == item->data(UBGraphicsItemData::ItemLayerType))
mScene->setAsBackgroundObject(item);
else
mScene->addItem(item);
UBGraphicsPolygonItem *polygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
if (polygonItem)
{
mScene->removeItem(polygonItem);
mScene->removeItemFromDeletion(polygonItem);
polygonItem->strokesGroup()->addToGroup(polygonItem);
}
}
}
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2) to trigger repaint
mScene->update(mScene->sceneRect());
}
else
{
mFirstRedo = false;
}
}

@ -19,106 +19,106 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBGRAPHICSVIDEOITEMDELEGATE_H_
#define UBGRAPHICSVIDEOITEMDELEGATE_H_
#include <QtGui>
#include <phonon/MediaObject>
#include "core/UB.h"
#include "UBGraphicsItemDelegate.h"
class QGraphicsSceneMouseEvent;
class QGraphicsItem;
class UBGraphicsVideoItem;
class DelegateVideoControl: public QGraphicsRectItem
{
public:
DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent = 0);
virtual ~DelegateVideoControl()
{
// NOOP
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
QPainterPath shape() const;
void setAntiScale(qreal antiScale){ mAntiScale = antiScale; }
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void updateTicker(qint64 time);
void totalTimeChanged( qint64 newTotalTime);
protected:
void seekToMousePos(QPointF mousePos);
UBGraphicsVideoItem* mDelegate;
bool mDisplayCurrentTime;
qreal mAntiScale;
qint64 mCurrentTimeInMs;
qint64 mTotalTimeInMs;
private:
int mStartWidth;
QRectF mBalloon;
};
class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate
{
Q_OBJECT
public:
UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0);
virtual ~UBGraphicsVideoItemDelegate();
virtual void positionHandles();
public slots:
void toggleMute();
void updateTicker(qint64 time);
protected slots:
virtual void remove(bool canUndo = true);
void togglePlayPause();
void mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate );
void updatePlayPauseState();
void totalTimeChanged( qint64 newTotalTime);
protected:
virtual void buildButtons();
private:
UBGraphicsVideoItem* delegated();
DelegateButton* mPlayPauseButton;
DelegateButton* mStopButton;
DelegateButton* mMuteButton;
DelegateVideoControl *mVideoControl;
Phonon::MediaObject* mMedia;
};
#endif /* UBGRAPHICSVIDEOITEMDELEGATE_H_ */
#ifndef UBGRAPHICSVIDEOITEMDELEGATE_H_
#define UBGRAPHICSVIDEOITEMDELEGATE_H_
#include <QtGui>
#include <phonon/MediaObject>
#include "core/UB.h"
#include "UBGraphicsItemDelegate.h"
class QGraphicsSceneMouseEvent;
class QGraphicsItem;
class UBGraphicsVideoItem;
class DelegateVideoControl: public QGraphicsRectItem
{
public:
DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent = 0);
virtual ~DelegateVideoControl()
{
// NOOP
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
QPainterPath shape() const;
void setAntiScale(qreal antiScale){ mAntiScale = antiScale; }
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void updateTicker(qint64 time);
void totalTimeChanged( qint64 newTotalTime);
protected:
void seekToMousePos(QPointF mousePos);
UBGraphicsVideoItem* mDelegate;
bool mDisplayCurrentTime;
qreal mAntiScale;
qint64 mCurrentTimeInMs;
qint64 mTotalTimeInMs;
private:
int mStartWidth;
QRectF mBalloon;
};
class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate
{
Q_OBJECT
public:
UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0);
virtual ~UBGraphicsVideoItemDelegate();
virtual void positionHandles();
public slots:
void toggleMute();
void updateTicker(qint64 time);
protected slots:
virtual void remove(bool canUndo = true);
void togglePlayPause();
void mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate );
void updatePlayPauseState();
void totalTimeChanged( qint64 newTotalTime);
protected:
virtual void buildButtons();
private:
UBGraphicsVideoItem* delegated();
DelegateButton* mPlayPauseButton;
DelegateButton* mStopButton;
DelegateButton* mMuteButton;
DelegateVideoControl *mVideoControl;
Phonon::MediaObject* mMedia;
};
#endif /* UBGRAPHICSVIDEOITEMDELEGATE_H_ */

@ -19,221 +19,221 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGeometryUtils.h"
#include "core/memcheck.h"
const double PI = 4.0 * atan(1.0);
const int UBGeometryUtils::centimeterGraduationHeight = 15;
const int UBGeometryUtils::halfCentimeterGraduationHeight = 10;
const int UBGeometryUtils::millimeterGraduationHeight = 5;
const int UBGeometryUtils::millimetersPerCentimeter = 10;
const int UBGeometryUtils::millimetersPerHalfCentimeter = 5;
const float UBGeometryUtils::inchSize = 25.4f;
UBGeometryUtils::UBGeometryUtils()
{
// NOOP
}
UBGeometryUtils::~UBGeometryUtils()
{
// NOOP
}
QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidth)
{
qreal x1 = pLine.x1();
qreal y1 = pLine.y1();
qreal x2 = pLine.x2();
qreal y2 = pLine.y2();
qreal alpha = (90.0 - pLine.angle()) * PI / 180.0;
qreal hypothenuse = pWidth / 2;
// TODO UB 4.x PERF cache sin/cos table
qreal opposite = sin(alpha) * hypothenuse;
qreal adjacent = cos(alpha) * hypothenuse;
QPointF p1a(x1 - adjacent, y1 - opposite);
QPointF p1b(x1 + adjacent, y1 + opposite);
QPointF p2a(x2 - adjacent, y2 - opposite);
QPointF p2b(x2 + adjacent, y2 + opposite);
QPainterPath painterPath;
painterPath.moveTo(p1a);
painterPath.lineTo(p2a);
painterPath.arcTo(x2 - hypothenuse, y2 - hypothenuse, pWidth, pWidth, (90.0 + pLine.angle()), -180.0);
//painterPath.lineTo(p2b);
painterPath.lineTo(p1b);
painterPath.arcTo(x1 - hypothenuse, y1 - hypothenuse, pWidth, pWidth, -1 * (90.0 - pLine.angle()), -180.0);
painterPath.closeSubpath();
return painterPath.toFillPolygon();
}
QPolygonF UBGeometryUtils::lineToPolygon(const QPointF& pStart, const QPointF& pEnd,
const qreal& pStartWidth, const qreal& pEndWidth)
{
qreal x1 = pStart.x();
qreal y1 = pStart.y();
qreal x2 = pEnd.x();
qreal y2 = pEnd.y();
QLineF line(pStart, pEnd);
qreal alpha = (90.0 - line.angle()) * PI / 180.0;
qreal hypothenuseStart = pStartWidth / 2;
qreal hypothenuseEnd = pEndWidth / 2;
qreal sinAlpha = sin(alpha);
qreal cosAlpha = cos(alpha);
// TODO UB 4.x PERF cache sin/cos table
qreal oppositeStart = sinAlpha * hypothenuseStart;
qreal adjacentStart = cosAlpha * hypothenuseStart;
QPointF p1a(x1 - adjacentStart, y1 - oppositeStart);
QPointF p1b(x1 + adjacentStart, y1 + oppositeStart);
qreal oppositeEnd = sinAlpha * hypothenuseEnd;
qreal adjacentEnd = cosAlpha * hypothenuseEnd;
QPointF p2a(x2 - adjacentEnd, y2 - oppositeEnd);
QPainterPath painterPath;
painterPath.moveTo(p1a);
painterPath.lineTo(p2a);
painterPath.arcTo(x2 - hypothenuseEnd, y2 - hypothenuseEnd, pEndWidth, pEndWidth, (90.0 + line.angle()), -180.0);
painterPath.lineTo(p1b);
painterPath.arcTo(x1 - hypothenuseStart, y1 - hypothenuseStart, pStartWidth, pStartWidth, -1 * (90.0 - line.angle()), -180.0);
painterPath.closeSubpath();
return painterPath.toFillPolygon();
}
QPolygonF UBGeometryUtils::arcToPolygon(const QLineF& startRadius, qreal spanAngleInDegrees, qreal width)
{
qreal startAngleInDegrees = - startRadius.angle();
if (startAngleInDegrees > 180)
startAngleInDegrees -= 360;
else if (startAngleInDegrees < -180)
startAngleInDegrees += 360;
qreal radiusLength = startRadius.length();
qreal angle = 2 * asin(width / (2 * radiusLength)) * 180 / PI;
bool overlap = abs(spanAngleInDegrees) > 360 - angle;
if (overlap)
spanAngleInDegrees = spanAngleInDegrees < 0 ? -360 : 360;
qreal endAngleInDegrees = startAngleInDegrees + spanAngleInDegrees;
qreal innerRadius = radiusLength - width / 2;
QRectF innerSquare(
startRadius.p1().x() - innerRadius,
startRadius.p1().y() - innerRadius,
2 * innerRadius,
2 * innerRadius);
qreal outerRadius = radiusLength + width / 2;
QRectF outerSquare(
startRadius.p1().x() - outerRadius,
startRadius.p1().y() - outerRadius,
2 * outerRadius,
2 * outerRadius);
QRectF startSquare(
startRadius.p2().x() - width / 2,
startRadius.p2().y() - width / 2,
width,
width);
QRectF endSquare(
startRadius.p1().x() + radiusLength * cos(endAngleInDegrees * PI / 180.0) - width / 2,
startRadius.p1().y() + radiusLength * sin(endAngleInDegrees * PI / 180.0) - width / 2,
width,
width);
QPainterPath painterPath(
QPointF(
startRadius.p1().x() + innerRadius * cos(startAngleInDegrees * PI / 180.0),
startRadius.p1().y() + innerRadius * sin(startAngleInDegrees * PI / 180.0)));
startAngleInDegrees = - startAngleInDegrees;
endAngleInDegrees = - endAngleInDegrees;
spanAngleInDegrees = - spanAngleInDegrees;
if (overlap)
{
painterPath.addEllipse(outerSquare);
QPainterPath innerPainterPath;
innerPainterPath.addEllipse(innerSquare);
painterPath = painterPath.subtracted(innerPainterPath);
}
else
{
painterPath.arcTo(innerSquare, startAngleInDegrees, spanAngleInDegrees);
painterPath.arcTo(endSquare, 180.0 + endAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0);
painterPath.arcTo(outerSquare, endAngleInDegrees, - spanAngleInDegrees);
painterPath.arcTo(startSquare, startAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0);
painterPath.closeSubpath();
}
return painterPath.toFillPolygon();
}
QPointF UBGeometryUtils::pointConstrainedInRect(QPointF point, QRectF rect)
{
return QPointF(qMax(rect.x(), qMin(rect.x() + rect.width(), point.x())), qMax(rect.y(), qMin(rect.y() + rect.height(), point.y())));
}
QPoint UBGeometryUtils::pointConstrainedInRect(QPoint point, QRect rect)
{
return QPoint(qMax(rect.x(), qMin(rect.x() + rect.width(), point.x())), qMax(rect.y(), qMin(rect.y() + rect.height(), point.y())));
}
QRectF UBGeometryUtils::lineToInnerRect(const QLineF& pLine, const qreal& pWidth)
{
qreal centerX = (pLine.x1() + pLine.x2()) / 2;
qreal centerY = (pLine.y1() + pLine.y2()) / 2;
// Please put a fucking comment here
qreal side = sqrt((pWidth * pWidth) / 2);
qreal halfSide = side / 2;
return QRectF(centerX - halfSide, centerY - halfSide, side, side);
}
void UBGeometryUtils::crashPointList(QVector<QPointF> &points)
{
// QVector<QPointF> result(points);
int position = 1;
while(position < points.size())
{
if (points.at(position) == points.at(position - 1))
{
points.remove(position);
}
else
{
++position;
}
}
}
#include "UBGeometryUtils.h"
#include "core/memcheck.h"
const double PI = 4.0 * atan(1.0);
const int UBGeometryUtils::centimeterGraduationHeight = 15;
const int UBGeometryUtils::halfCentimeterGraduationHeight = 10;
const int UBGeometryUtils::millimeterGraduationHeight = 5;
const int UBGeometryUtils::millimetersPerCentimeter = 10;
const int UBGeometryUtils::millimetersPerHalfCentimeter = 5;
const float UBGeometryUtils::inchSize = 25.4f;
UBGeometryUtils::UBGeometryUtils()
{
// NOOP
}
UBGeometryUtils::~UBGeometryUtils()
{
// NOOP
}
QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidth)
{
qreal x1 = pLine.x1();
qreal y1 = pLine.y1();
qreal x2 = pLine.x2();
qreal y2 = pLine.y2();
qreal alpha = (90.0 - pLine.angle()) * PI / 180.0;
qreal hypothenuse = pWidth / 2;
// TODO UB 4.x PERF cache sin/cos table
qreal opposite = sin(alpha) * hypothenuse;
qreal adjacent = cos(alpha) * hypothenuse;
QPointF p1a(x1 - adjacent, y1 - opposite);
QPointF p1b(x1 + adjacent, y1 + opposite);
QPointF p2a(x2 - adjacent, y2 - opposite);
QPointF p2b(x2 + adjacent, y2 + opposite);
QPainterPath painterPath;
painterPath.moveTo(p1a);
painterPath.lineTo(p2a);
painterPath.arcTo(x2 - hypothenuse, y2 - hypothenuse, pWidth, pWidth, (90.0 + pLine.angle()), -180.0);
//painterPath.lineTo(p2b);
painterPath.lineTo(p1b);
painterPath.arcTo(x1 - hypothenuse, y1 - hypothenuse, pWidth, pWidth, -1 * (90.0 - pLine.angle()), -180.0);
painterPath.closeSubpath();
return painterPath.toFillPolygon();
}
QPolygonF UBGeometryUtils::lineToPolygon(const QPointF& pStart, const QPointF& pEnd,
const qreal& pStartWidth, const qreal& pEndWidth)
{
qreal x1 = pStart.x();
qreal y1 = pStart.y();
qreal x2 = pEnd.x();
qreal y2 = pEnd.y();
QLineF line(pStart, pEnd);
qreal alpha = (90.0 - line.angle()) * PI / 180.0;
qreal hypothenuseStart = pStartWidth / 2;
qreal hypothenuseEnd = pEndWidth / 2;
qreal sinAlpha = sin(alpha);
qreal cosAlpha = cos(alpha);
// TODO UB 4.x PERF cache sin/cos table
qreal oppositeStart = sinAlpha * hypothenuseStart;
qreal adjacentStart = cosAlpha * hypothenuseStart;
QPointF p1a(x1 - adjacentStart, y1 - oppositeStart);
QPointF p1b(x1 + adjacentStart, y1 + oppositeStart);
qreal oppositeEnd = sinAlpha * hypothenuseEnd;
qreal adjacentEnd = cosAlpha * hypothenuseEnd;
QPointF p2a(x2 - adjacentEnd, y2 - oppositeEnd);
QPainterPath painterPath;
painterPath.moveTo(p1a);
painterPath.lineTo(p2a);
painterPath.arcTo(x2 - hypothenuseEnd, y2 - hypothenuseEnd, pEndWidth, pEndWidth, (90.0 + line.angle()), -180.0);
painterPath.lineTo(p1b);
painterPath.arcTo(x1 - hypothenuseStart, y1 - hypothenuseStart, pStartWidth, pStartWidth, -1 * (90.0 - line.angle()), -180.0);
painterPath.closeSubpath();
return painterPath.toFillPolygon();
}
QPolygonF UBGeometryUtils::arcToPolygon(const QLineF& startRadius, qreal spanAngleInDegrees, qreal width)
{
qreal startAngleInDegrees = - startRadius.angle();
if (startAngleInDegrees > 180)
startAngleInDegrees -= 360;
else if (startAngleInDegrees < -180)
startAngleInDegrees += 360;
qreal radiusLength = startRadius.length();
qreal angle = 2 * asin(width / (2 * radiusLength)) * 180 / PI;
bool overlap = abs(spanAngleInDegrees) > 360 - angle;
if (overlap)
spanAngleInDegrees = spanAngleInDegrees < 0 ? -360 : 360;
qreal endAngleInDegrees = startAngleInDegrees + spanAngleInDegrees;
qreal innerRadius = radiusLength - width / 2;
QRectF innerSquare(
startRadius.p1().x() - innerRadius,
startRadius.p1().y() - innerRadius,
2 * innerRadius,
2 * innerRadius);
qreal outerRadius = radiusLength + width / 2;
QRectF outerSquare(
startRadius.p1().x() - outerRadius,
startRadius.p1().y() - outerRadius,
2 * outerRadius,
2 * outerRadius);
QRectF startSquare(
startRadius.p2().x() - width / 2,
startRadius.p2().y() - width / 2,
width,
width);
QRectF endSquare(
startRadius.p1().x() + radiusLength * cos(endAngleInDegrees * PI / 180.0) - width / 2,
startRadius.p1().y() + radiusLength * sin(endAngleInDegrees * PI / 180.0) - width / 2,
width,
width);
QPainterPath painterPath(
QPointF(
startRadius.p1().x() + innerRadius * cos(startAngleInDegrees * PI / 180.0),
startRadius.p1().y() + innerRadius * sin(startAngleInDegrees * PI / 180.0)));
startAngleInDegrees = - startAngleInDegrees;
endAngleInDegrees = - endAngleInDegrees;
spanAngleInDegrees = - spanAngleInDegrees;
if (overlap)
{
painterPath.addEllipse(outerSquare);
QPainterPath innerPainterPath;
innerPainterPath.addEllipse(innerSquare);
painterPath = painterPath.subtracted(innerPainterPath);
}
else
{
painterPath.arcTo(innerSquare, startAngleInDegrees, spanAngleInDegrees);
painterPath.arcTo(endSquare, 180.0 + endAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0);
painterPath.arcTo(outerSquare, endAngleInDegrees, - spanAngleInDegrees);
painterPath.arcTo(startSquare, startAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0);
painterPath.closeSubpath();
}
return painterPath.toFillPolygon();
}
QPointF UBGeometryUtils::pointConstrainedInRect(QPointF point, QRectF rect)
{
return QPointF(qMax(rect.x(), qMin(rect.x() + rect.width(), point.x())), qMax(rect.y(), qMin(rect.y() + rect.height(), point.y())));
}
QPoint UBGeometryUtils::pointConstrainedInRect(QPoint point, QRect rect)
{
return QPoint(qMax(rect.x(), qMin(rect.x() + rect.width(), point.x())), qMax(rect.y(), qMin(rect.y() + rect.height(), point.y())));
}
QRectF UBGeometryUtils::lineToInnerRect(const QLineF& pLine, const qreal& pWidth)
{
qreal centerX = (pLine.x1() + pLine.x2()) / 2;
qreal centerY = (pLine.y1() + pLine.y2()) / 2;
// Please put a fucking comment here
qreal side = sqrt((pWidth * pWidth) / 2);
qreal halfSide = side / 2;
return QRectF(centerX - halfSide, centerY - halfSide, side, side);
}
void UBGeometryUtils::crashPointList(QVector<QPointF> &points)
{
// QVector<QPointF> result(points);
int position = 1;
while(position < points.size())
{
if (points.at(position) == points.at(position - 1))
{
points.remove(position);
}
else
{
++position;
}
}
}

@ -19,39 +19,39 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBGEOMETRYUTILS_H_
#define UBGEOMETRYUTILS_H_
#include <QtGui>
class UBGeometryUtils
{
private:
UBGeometryUtils();
virtual ~UBGeometryUtils();
public:
static QPolygonF lineToPolygon(const QLineF& pLine, const qreal& pWidth);
static QRectF lineToInnerRect(const QLineF& pLine, const qreal& pWidth);
static QPolygonF arcToPolygon(const QLineF& startRadius, qreal spanAngle, qreal width);
static QPolygonF lineToPolygon(const QPointF& pStart, const QPointF& pEnd,
const qreal& pStartWidth, const qreal& pEndWidth);
static QPointF pointConstrainedInRect(QPointF point, QRectF rect);
static QPoint pointConstrainedInRect(QPoint point, QRect rect);
static void crashPointList(QVector<QPointF> &points);
const static int centimeterGraduationHeight;
const static int halfCentimeterGraduationHeight;
const static int millimeterGraduationHeight;
const static int millimetersPerCentimeter;
const static int millimetersPerHalfCentimeter;
const static float inchSize;
};
#endif /* UBGEOMETRYUTILS_H_ */
#ifndef UBGEOMETRYUTILS_H_
#define UBGEOMETRYUTILS_H_
#include <QtGui>
class UBGeometryUtils
{
private:
UBGeometryUtils();
virtual ~UBGeometryUtils();
public:
static QPolygonF lineToPolygon(const QLineF& pLine, const qreal& pWidth);
static QRectF lineToInnerRect(const QLineF& pLine, const qreal& pWidth);
static QPolygonF arcToPolygon(const QLineF& startRadius, qreal spanAngle, qreal width);
static QPolygonF lineToPolygon(const QPointF& pStart, const QPointF& pEnd,
const qreal& pStartWidth, const qreal& pEndWidth);
static QPointF pointConstrainedInRect(QPointF point, QRectF rect);
static QPoint pointConstrainedInRect(QPoint point, QRect rect);
static void crashPointList(QVector<QPointF> &points);
const static int centimeterGraduationHeight;
const static int halfCentimeterGraduationHeight;
const static int millimeterGraduationHeight;
const static int millimetersPerCentimeter;
const static int millimetersPerHalfCentimeter;
const static float inchSize;
};
#endif /* UBGEOMETRYUTILS_H_ */

@ -461,8 +461,8 @@ void UBPlatformUtils::initializeKeyboardLayouts()
int count = CFArrayGetCount(kbds);
QList<UBKeyboardLocale*> result;
qDebug() << "initializeKeyboardLayouts";
qDebug() << "Found system locales: " << count;
qDebug() << "initializeKeyboardLayouts";
qDebug() << "Found system locales: " << count;
for(int i=0; i<count; i++)
{
@ -554,7 +554,7 @@ void UBPlatformUtils::initializeKeyboardLayouts()
const QString resName = ":/images/flags/" + name + ".png";
QIcon *iconLang = new QIcon(resName);
qDebug() << "Locale: " << ID << ", name: " << name;
qDebug() << "Locale: " << ID << ", name: " << name;
result.append(new UBKeyboardLocale(fullName, name, ID, iconLang, keybt));
}

@ -19,271 +19,271 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QList>
#include <QPointF>
#include <QPixmap>
#include <QTransform>
#include <QScrollBar>
#include <QFontMetrics>
#include <QGraphicsItem>
#include <QGraphicsPixmapItem>
#include "core/UBApplication.h"
#include "UBDocumentNavigator.h"
#include "board/UBBoardController.h"
#include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBSvgSubsetAdaptor.h"
#include "document/UBDocumentController.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardPaletteManager.h"
#include "core/UBApplicationController.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the object name
*/
UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGraphicsView(parent)
, mScene(NULL)
, mNbColumns(1)
, mThumbnailWidth(0)
, mThumbnailMinWidth(100)
{
setObjectName(name);
mScene = new QGraphicsScene(this);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(mScene);
mThumbnailWidth = width() - 2*border();
setFrameShadow(QFrame::Plain);
connect(UBApplication::boardController, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(generateThumbnails(UBDocumentContainer*)));
connect(UBApplication::boardController, SIGNAL(documentPageUpdated(int)), this, SLOT(updateSpecificThumbnail(int)));
connect(UBApplication::boardController, SIGNAL(pageSelectionChanged(int)), this, SLOT(onScrollToSelectedPage(int)));
}
/**
* \brief Destructor
*/
UBDocumentNavigator::~UBDocumentNavigator()
{
if(NULL != mScene)
{
delete mScene;
mScene = NULL;
}
}
#include "gui/UBDockTeacherGuideWidget.h"
#include "gui/UBTeacherGuideWidget.h"
/**
* \brief Generate the thumbnails
*/
void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
{
mThumbsWithLabels.clear();
foreach(QGraphicsItem* it, mScene->items())
{
mScene->removeItem(it);
delete it;
it = NULL;
}
for(int i = 0; i < source->selectedDocument()->pageCount(); i++)
{
const QPixmap* pix = source->pageAt(i);
Q_ASSERT(!pix->isNull());
int pageIndex = UBDocumentContainer::pageFromSceneIndex(i);
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i);
QString label = pageIndex == 0 ? tr("Title page") : tr("Page %0").arg(pageIndex);
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(label);
UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem);
thumbWithText.setBorder(border());
mThumbsWithLabels.append(thumbWithText);
mScene->addItem(pixmapItem);
mScene->addItem(labelItem);
}
// Draw the items
refreshScene();
}
void UBDocumentNavigator::onScrollToSelectedPage(int index)
{
int c = 0;
foreach(UBImgTextThumbnailElement el, mThumbsWithLabels)
{
if (c==index)
{
el.getThumbnail()->setSelected(true);
}
else
{
el.getThumbnail()->setSelected(false);
}
c++;
}
}
/**
* \brief Refresh the given thumbnail
* @param iPage as the given page related thumbnail
*/
void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
{
// Generate the new thumbnail
//UBGraphicsScene* pScene = UBApplication::boardController->activeScene();
const QPixmap* pix = UBApplication::boardController->pageAt(iPage);
UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), iPage);
// Get the old thumbnail
UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail();
if(NULL != oldItem)
{
mScene->removeItem(oldItem);
mScene->addItem(newItem);
mThumbsWithLabels[iPage].setThumbnail(newItem);
delete oldItem;
oldItem = NULL;
}
}
/**
* \brief Put the element in the right place in the scene.
*/
void UBDocumentNavigator::refreshScene()
{
qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio;
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
// Get the item
UBImgTextThumbnailElement& item = mThumbsWithLabels[i];
int columnIndex = i % mNbColumns;
int rowIndex = i / mNbColumns;
item.Place(rowIndex, columnIndex, mThumbnailWidth, thumbnailHeight);
}
scene()->setSceneRect(scene()->itemsBoundingRect());
}
/**
* \brief Set the number of thumbnails columns
* @param nbColumns as the number of columns
*/
void UBDocumentNavigator::setNbColumns(int nbColumns)
{
mNbColumns = nbColumns;
}
/**
* \brief Get the number of columns
* @return the number of thumbnails columns
*/
int UBDocumentNavigator::nbColumns()
{
return mNbColumns;
}
/**
* \brief Set the thumbnails minimum width
* @param width as the minimum width
*/
void UBDocumentNavigator::setThumbnailMinWidth(int width)
{
mThumbnailMinWidth = width;
}
/**
* \brief Get the thumbnails minimum width
* @return the minimum thumbnails width
*/
int UBDocumentNavigator::thumbnailMinWidth()
{
return mThumbnailMinWidth;
}
/**
* \brief Get the border size
* @return the border size in pixels
*/
int UBDocumentNavigator::border()
{
return 20;
}
/**
* \brief Handle the resize event
* @param event as the resize event
*/
void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
// Update the thumbnails width
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth;
// Refresh the scene
refreshScene();
}
/**
* \brief Handle the mouse press event
* @param event as the mouse event
*/
void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
{
QGraphicsItem* pClickedItem = itemAt(event->pos());
if(NULL != pClickedItem)
{
// First, select the clicked item
UBSceneThumbnailNavigPixmap* pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pClickedItem);
if(NULL == pCrntItem)
{
// If we fall here we may have clicked on the label instead of the thumbnail
UBThumbnailTextItem* pTextItem = dynamic_cast<UBThumbnailTextItem*>(pClickedItem);
if(NULL != pTextItem)
{
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
const UBImgTextThumbnailElement& el = mThumbsWithLabels.at(i);
if(el.getCaption() == pTextItem)
{
pCrntItem = el.getThumbnail();
break;
}
}
}
}
int index = 0;
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
if (mThumbsWithLabels.at(i).getThumbnail() == pCrntItem)
{
index = i;
break;
}
}
UBApplication::boardController->setActiveDocumentScene(index);
}
QGraphicsView::mousePressEvent(event);
}
void UBDocumentNavigator::mouseReleaseEvent(QMouseEvent *event)
{
event->accept();
}
#include <QList>
#include <QPointF>
#include <QPixmap>
#include <QTransform>
#include <QScrollBar>
#include <QFontMetrics>
#include <QGraphicsItem>
#include <QGraphicsPixmapItem>
#include "core/UBApplication.h"
#include "UBDocumentNavigator.h"
#include "board/UBBoardController.h"
#include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBSvgSubsetAdaptor.h"
#include "document/UBDocumentController.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardPaletteManager.h"
#include "core/UBApplicationController.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the object name
*/
UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGraphicsView(parent)
, mScene(NULL)
, mNbColumns(1)
, mThumbnailWidth(0)
, mThumbnailMinWidth(100)
{
setObjectName(name);
mScene = new QGraphicsScene(this);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(mScene);
mThumbnailWidth = width() - 2*border();
setFrameShadow(QFrame::Plain);
connect(UBApplication::boardController, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(generateThumbnails(UBDocumentContainer*)));
connect(UBApplication::boardController, SIGNAL(documentPageUpdated(int)), this, SLOT(updateSpecificThumbnail(int)));
connect(UBApplication::boardController, SIGNAL(pageSelectionChanged(int)), this, SLOT(onScrollToSelectedPage(int)));
}
/**
* \brief Destructor
*/
UBDocumentNavigator::~UBDocumentNavigator()
{
if(NULL != mScene)
{
delete mScene;
mScene = NULL;
}
}
#include "gui/UBDockTeacherGuideWidget.h"
#include "gui/UBTeacherGuideWidget.h"
/**
* \brief Generate the thumbnails
*/
void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
{
mThumbsWithLabels.clear();
foreach(QGraphicsItem* it, mScene->items())
{
mScene->removeItem(it);
delete it;
it = NULL;
}
for(int i = 0; i < source->selectedDocument()->pageCount(); i++)
{
const QPixmap* pix = source->pageAt(i);
Q_ASSERT(!pix->isNull());
int pageIndex = UBDocumentContainer::pageFromSceneIndex(i);
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i);
QString label = pageIndex == 0 ? tr("Title page") : tr("Page %0").arg(pageIndex);
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(label);
UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem);
thumbWithText.setBorder(border());
mThumbsWithLabels.append(thumbWithText);
mScene->addItem(pixmapItem);
mScene->addItem(labelItem);
}
// Draw the items
refreshScene();
}
void UBDocumentNavigator::onScrollToSelectedPage(int index)
{
int c = 0;
foreach(UBImgTextThumbnailElement el, mThumbsWithLabels)
{
if (c==index)
{
el.getThumbnail()->setSelected(true);
}
else
{
el.getThumbnail()->setSelected(false);
}
c++;
}
}
/**
* \brief Refresh the given thumbnail
* @param iPage as the given page related thumbnail
*/
void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
{
// Generate the new thumbnail
//UBGraphicsScene* pScene = UBApplication::boardController->activeScene();
const QPixmap* pix = UBApplication::boardController->pageAt(iPage);
UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), iPage);
// Get the old thumbnail
UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail();
if(NULL != oldItem)
{
mScene->removeItem(oldItem);
mScene->addItem(newItem);
mThumbsWithLabels[iPage].setThumbnail(newItem);
delete oldItem;
oldItem = NULL;
}
}
/**
* \brief Put the element in the right place in the scene.
*/
void UBDocumentNavigator::refreshScene()
{
qreal thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio;
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
// Get the item
UBImgTextThumbnailElement& item = mThumbsWithLabels[i];
int columnIndex = i % mNbColumns;
int rowIndex = i / mNbColumns;
item.Place(rowIndex, columnIndex, mThumbnailWidth, thumbnailHeight);
}
scene()->setSceneRect(scene()->itemsBoundingRect());
}
/**
* \brief Set the number of thumbnails columns
* @param nbColumns as the number of columns
*/
void UBDocumentNavigator::setNbColumns(int nbColumns)
{
mNbColumns = nbColumns;
}
/**
* \brief Get the number of columns
* @return the number of thumbnails columns
*/
int UBDocumentNavigator::nbColumns()
{
return mNbColumns;
}
/**
* \brief Set the thumbnails minimum width
* @param width as the minimum width
*/
void UBDocumentNavigator::setThumbnailMinWidth(int width)
{
mThumbnailMinWidth = width;
}
/**
* \brief Get the thumbnails minimum width
* @return the minimum thumbnails width
*/
int UBDocumentNavigator::thumbnailMinWidth()
{
return mThumbnailMinWidth;
}
/**
* \brief Get the border size
* @return the border size in pixels
*/
int UBDocumentNavigator::border()
{
return 20;
}
/**
* \brief Handle the resize event
* @param event as the resize event
*/
void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
// Update the thumbnails width
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth;
// Refresh the scene
refreshScene();
}
/**
* \brief Handle the mouse press event
* @param event as the mouse event
*/
void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
{
QGraphicsItem* pClickedItem = itemAt(event->pos());
if(NULL != pClickedItem)
{
// First, select the clicked item
UBSceneThumbnailNavigPixmap* pCrntItem = dynamic_cast<UBSceneThumbnailNavigPixmap*>(pClickedItem);
if(NULL == pCrntItem)
{
// If we fall here we may have clicked on the label instead of the thumbnail
UBThumbnailTextItem* pTextItem = dynamic_cast<UBThumbnailTextItem*>(pClickedItem);
if(NULL != pTextItem)
{
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
const UBImgTextThumbnailElement& el = mThumbsWithLabels.at(i);
if(el.getCaption() == pTextItem)
{
pCrntItem = el.getThumbnail();
break;
}
}
}
}
int index = 0;
for(int i = 0; i < mThumbsWithLabels.size(); i++)
{
if (mThumbsWithLabels.at(i).getThumbnail() == pCrntItem)
{
index = i;
break;
}
}
UBApplication::boardController->setActiveDocumentScene(index);
}
QGraphicsView::mousePressEvent(event);
}
void UBDocumentNavigator::mouseReleaseEvent(QMouseEvent *event)
{
event->accept();
}

@ -19,63 +19,63 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOCUMENTNAVIGATOR_H
#define UBDOCUMENTNAVIGATOR_H
#include <QResizeEvent>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QMouseEvent>
#include <QThread>
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentContainer.h"
#include "UBThumbnailWidget.h"
#define NO_PAGESELECTED -1
class UBDocumentNavigator : public QGraphicsView
{
Q_OBJECT
public:
UBDocumentNavigator(QWidget* parent=0, const char* name="documentNavigator");
~UBDocumentNavigator();
void setNbColumns(int nbColumns);
int nbColumns();
void setThumbnailMinWidth(int width);
int thumbnailMinWidth();
public slots:
void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); }
void generateThumbnails(UBDocumentContainer* source);
void updateSpecificThumbnail(int iPage);
protected:
virtual void resizeEvent(QResizeEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
private:
void refreshScene();
int border();
/** The scene */
QGraphicsScene* mScene;
/** The current selected item */
//UBSceneThumbnailNavigPixmap* mCrntItem;
/** The list of current thumbnails with labels*/
QList<UBImgTextThumbnailElement> mThumbsWithLabels;
/** The current number of columns */
int mNbColumns;
/** The current thumbnails width */
int mThumbnailWidth;
/** The current thumbnails minimum width */
int mThumbnailMinWidth;
};
#endif // UBDOCUMENTNAVIGATOR_H
#ifndef UBDOCUMENTNAVIGATOR_H
#define UBDOCUMENTNAVIGATOR_H
#include <QResizeEvent>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QMouseEvent>
#include <QThread>
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentContainer.h"
#include "UBThumbnailWidget.h"
#define NO_PAGESELECTED -1
class UBDocumentNavigator : public QGraphicsView
{
Q_OBJECT
public:
UBDocumentNavigator(QWidget* parent=0, const char* name="documentNavigator");
~UBDocumentNavigator();
void setNbColumns(int nbColumns);
int nbColumns();
void setThumbnailMinWidth(int width);
int thumbnailMinWidth();
public slots:
void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); }
void generateThumbnails(UBDocumentContainer* source);
void updateSpecificThumbnail(int iPage);
protected:
virtual void resizeEvent(QResizeEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
private:
void refreshScene();
int border();
/** The scene */
QGraphicsScene* mScene;
/** The current selected item */
//UBSceneThumbnailNavigPixmap* mCrntItem;
/** The list of current thumbnails with labels*/
QList<UBImgTextThumbnailElement> mThumbsWithLabels;
/** The current number of columns */
int mNbColumns;
/** The current thumbnails width */
int mThumbnailWidth;
/** The current thumbnails minimum width */
int mThumbnailMinWidth;
};
#endif // UBDOCUMENTNAVIGATOR_H

@ -19,305 +19,305 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBDocumentThumbnailWidget.h"
#include "core/UBApplication.h"
#include "core/UBMimeData.h"
#include "core/UBSettings.h"
#include "board/UBBoardController.h"
#include "document/UBDocumentController.h"
#include "core/memcheck.h"
UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent)
: UBThumbnailWidget(parent)
, mDropCaretRectItem(0)
, mClosestDropItem(0)
, mDragEnabled(true)
, mScrollMagnitude(0)
{
bCanDrag = false;
mScrollTimer = new QTimer(this);
connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll()));
}
UBDocumentThumbnailWidget::~UBDocumentThumbnailWidget()
{
// NOOP
}
void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
{
if (!dragEnabled())
{
event->ignore();
return;
}
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance())
return;
QList<QGraphicsItem*> graphicsItems = items(mMousePressPos);
UBSceneThumbnailPixmap* sceneItem = 0;
while (!graphicsItems.isEmpty() && !sceneItem)
sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(graphicsItems.takeFirst());
if (sceneItem)
{
int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex());
if(pageIndex != 0){
QDrag *drag = new QDrag(this);
QList<UBMimeDataItem> mimeDataItems;
foreach (QGraphicsItem *item, selectedItems())
mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item)));
UBMimeData *mime = new UBMimeData(mimeDataItems);
drag->setMimeData(mime);
drag->setPixmap(sceneItem->pixmap().scaledToWidth(100));
drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2));
drag->exec(Qt::MoveAction);
}
}
UBThumbnailWidget::mouseMoveEvent(event);
}
void UBDocumentThumbnailWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (!event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
event->setDropAction(Qt::IgnoreAction);
event->ignore();
return;
}
UBThumbnailWidget::dragEnterEvent(event);
}
void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
Q_UNUSED(event);
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
deleteDropCaret();
UBThumbnailWidget::dragLeaveEvent(event);
}
void UBDocumentThumbnailWidget::autoScroll()
{
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude);
}
void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event)
{
QRect boundingFrame = frameRect();
//setting up automatic scrolling
const int SCROLL_DISTANCE = 16;
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y();
if(qAbs(bottomDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else if(qAbs(topDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
QList<UBSceneThumbnailPixmap*> pixmapItems;
foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame)))
{
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item);
if (sceneItem)
pixmapItems.append(sceneItem);
}
int minDistance = 0;
QGraphicsItem *underlyingItem = itemAt(event->pos());
mClosestDropItem = dynamic_cast<UBSceneThumbnailPixmap*>(underlyingItem);
int pageIndex = -1;
if(mClosestDropItem){
pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex());
if(pageIndex == 0){
event->acceptProposedAction();
return;
}
}
if (!mClosestDropItem)
{
foreach (UBSceneThumbnailPixmap *item, pixmapItems)
{
qreal scale = item->transform().m11();
QPointF itemCenter(
item->pos().x() + item->boundingRect().width() * scale / 2,
item->pos().y() + item->boundingRect().height() * scale / 2);
int distance = (itemCenter.toPoint() - mapToScene(event->pos()).toPoint()).manhattanLength();
if (!mClosestDropItem || distance < minDistance)
{
mClosestDropItem = item;
minDistance = distance;
pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex());
}
}
}
if (mClosestDropItem && pageIndex != 0)
{
qreal scale = mClosestDropItem->transform().m11();
QPointF itemCenter(
mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale / 2,
mClosestDropItem->pos().y() + mClosestDropItem->boundingRect().height() * scale / 2);
mDropIsRight = mapToScene(event->pos()).x() > itemCenter.x();
if (!mDropCaretRectItem && selectedItems().count() < mGraphicItems.count())
{
mDropCaretRectItem = new QGraphicsRectItem(0, scene());
mDropCaretRectItem->setPen(QPen(Qt::darkGray));
mDropCaretRectItem->setBrush(QBrush(Qt::lightGray));
}
QRectF dropCaretRect(
mDropIsRight ? mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale + spacing() / 2 - 1 : mClosestDropItem->pos().x() - spacing() / 2 - 1,
mClosestDropItem->pos().y(),
3,
mClosestDropItem->boundingRect().height() * scale);
if (mDropCaretRectItem)
mDropCaretRectItem->setRect(dropCaretRect);
}
event->acceptProposedAction();
}
void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event)
{
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
deleteDropCaret();
if (mClosestDropItem)
{
int targetIndex = mDropIsRight ? mGraphicItems.indexOf(mClosestDropItem) + 1 : mGraphicItems.indexOf(mClosestDropItem);
if(UBDocumentContainer::pageFromSceneIndex(targetIndex) == 0){
event->ignore();
return;
}
QList<UBMimeDataItem> mimeDataItems;
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
const UBMimeData* mimeData = qobject_cast<const UBMimeData*>(event->mimeData());
if (mimeData)
mimeDataItems = mimeData->items();
}
if (1 == mimeDataItems.count() &&
(mimeDataItems.at(0).sceneIndex() == mGraphicItems.indexOf(mClosestDropItem) ||
targetIndex == mimeDataItems.at(0).sceneIndex() ||
targetIndex == mimeDataItems.at(0).sceneIndex() + 1))
{
return;
}
int sourceIndexOffset = 0;
int actualTargetIndex = targetIndex;
for (int i = mimeDataItems.count() - 1; i >= 0; i--)
{
UBMimeDataItem sourceItem = mimeDataItems.at(i);
int actualSourceIndex = sourceItem.sceneIndex();
if (sourceItem.sceneIndex() >= targetIndex)
actualSourceIndex += sourceIndexOffset;
//event->acceptProposedAction();
if (sourceItem.sceneIndex() < targetIndex)
{
if (actualSourceIndex != actualTargetIndex - 1)
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex - 1);
actualTargetIndex -= 1;
}
else
{
if (actualSourceIndex != actualTargetIndex)
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex);
sourceIndexOffset += 1;
}
}
}
UBThumbnailWidget::dropEvent(event);
}
void UBDocumentThumbnailWidget::deleteDropCaret()
{
if (mDropCaretRectItem && scene())
{
scene()->removeItem(mDropCaretRectItem);
delete mDropCaretRectItem;
mDropCaretRectItem = 0;
}
}
void UBDocumentThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems,
const QList<QUrl>& pItemPaths, const QStringList pLabels,
const QString& pMimeType)
{
deleteDropCaret();
UBThumbnailWidget::setGraphicsItems(pGraphicsItems, pItemPaths, pLabels, pMimeType);
}
void UBDocumentThumbnailWidget::setDragEnabled(bool enabled)
{
mDragEnabled = enabled;
}
bool UBDocumentThumbnailWidget::dragEnabled() const
{
return mDragEnabled;
}
void UBDocumentThumbnailWidget::hightlightItem(int index)
{
if (0 <= index && index < mLabelsItems.length())
{
mLabelsItems.at(index)->highlight();
}
if (0 <= index && index < mGraphicItems.length())
{
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(mGraphicItems.at(index));
if (thumbnail)
thumbnail->highlight();
}
selectItemAt(index);
}
#include "UBDocumentThumbnailWidget.h"
#include "core/UBApplication.h"
#include "core/UBMimeData.h"
#include "core/UBSettings.h"
#include "board/UBBoardController.h"
#include "document/UBDocumentController.h"
#include "core/memcheck.h"
UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent)
: UBThumbnailWidget(parent)
, mDropCaretRectItem(0)
, mClosestDropItem(0)
, mDragEnabled(true)
, mScrollMagnitude(0)
{
bCanDrag = false;
mScrollTimer = new QTimer(this);
connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll()));
}
UBDocumentThumbnailWidget::~UBDocumentThumbnailWidget()
{
// NOOP
}
void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event)
{
if (!dragEnabled())
{
event->ignore();
return;
}
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance())
return;
QList<QGraphicsItem*> graphicsItems = items(mMousePressPos);
UBSceneThumbnailPixmap* sceneItem = 0;
while (!graphicsItems.isEmpty() && !sceneItem)
sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(graphicsItems.takeFirst());
if (sceneItem)
{
int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex());
if(pageIndex != 0){
QDrag *drag = new QDrag(this);
QList<UBMimeDataItem> mimeDataItems;
foreach (QGraphicsItem *item, selectedItems())
mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item)));
UBMimeData *mime = new UBMimeData(mimeDataItems);
drag->setMimeData(mime);
drag->setPixmap(sceneItem->pixmap().scaledToWidth(100));
drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2));
drag->exec(Qt::MoveAction);
}
}
UBThumbnailWidget::mouseMoveEvent(event);
}
void UBDocumentThumbnailWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (!event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
event->setDropAction(Qt::IgnoreAction);
event->ignore();
return;
}
UBThumbnailWidget::dragEnterEvent(event);
}
void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
Q_UNUSED(event);
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
deleteDropCaret();
UBThumbnailWidget::dragLeaveEvent(event);
}
void UBDocumentThumbnailWidget::autoScroll()
{
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude);
}
void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event)
{
QRect boundingFrame = frameRect();
//setting up automatic scrolling
const int SCROLL_DISTANCE = 16;
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y();
if(qAbs(bottomDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else if(qAbs(topDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
QList<UBSceneThumbnailPixmap*> pixmapItems;
foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame)))
{
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item);
if (sceneItem)
pixmapItems.append(sceneItem);
}
int minDistance = 0;
QGraphicsItem *underlyingItem = itemAt(event->pos());
mClosestDropItem = dynamic_cast<UBSceneThumbnailPixmap*>(underlyingItem);
int pageIndex = -1;
if(mClosestDropItem){
pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex());
if(pageIndex == 0){
event->acceptProposedAction();
return;
}
}
if (!mClosestDropItem)
{
foreach (UBSceneThumbnailPixmap *item, pixmapItems)
{
qreal scale = item->transform().m11();
QPointF itemCenter(
item->pos().x() + item->boundingRect().width() * scale / 2,
item->pos().y() + item->boundingRect().height() * scale / 2);
int distance = (itemCenter.toPoint() - mapToScene(event->pos()).toPoint()).manhattanLength();
if (!mClosestDropItem || distance < minDistance)
{
mClosestDropItem = item;
minDistance = distance;
pageIndex = UBDocumentContainer::pageFromSceneIndex(mClosestDropItem->sceneIndex());
}
}
}
if (mClosestDropItem && pageIndex != 0)
{
qreal scale = mClosestDropItem->transform().m11();
QPointF itemCenter(
mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale / 2,
mClosestDropItem->pos().y() + mClosestDropItem->boundingRect().height() * scale / 2);
mDropIsRight = mapToScene(event->pos()).x() > itemCenter.x();
if (!mDropCaretRectItem && selectedItems().count() < mGraphicItems.count())
{
mDropCaretRectItem = new QGraphicsRectItem(0, scene());
mDropCaretRectItem->setPen(QPen(Qt::darkGray));
mDropCaretRectItem->setBrush(QBrush(Qt::lightGray));
}
QRectF dropCaretRect(
mDropIsRight ? mClosestDropItem->pos().x() + mClosestDropItem->boundingRect().width() * scale + spacing() / 2 - 1 : mClosestDropItem->pos().x() - spacing() / 2 - 1,
mClosestDropItem->pos().y(),
3,
mClosestDropItem->boundingRect().height() * scale);
if (mDropCaretRectItem)
mDropCaretRectItem->setRect(dropCaretRect);
}
event->acceptProposedAction();
}
void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event)
{
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
deleteDropCaret();
if (mClosestDropItem)
{
int targetIndex = mDropIsRight ? mGraphicItems.indexOf(mClosestDropItem) + 1 : mGraphicItems.indexOf(mClosestDropItem);
if(UBDocumentContainer::pageFromSceneIndex(targetIndex) == 0){
event->ignore();
return;
}
QList<UBMimeDataItem> mimeDataItems;
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
const UBMimeData* mimeData = qobject_cast<const UBMimeData*>(event->mimeData());
if (mimeData)
mimeDataItems = mimeData->items();
}
if (1 == mimeDataItems.count() &&
(mimeDataItems.at(0).sceneIndex() == mGraphicItems.indexOf(mClosestDropItem) ||
targetIndex == mimeDataItems.at(0).sceneIndex() ||
targetIndex == mimeDataItems.at(0).sceneIndex() + 1))
{
return;
}
int sourceIndexOffset = 0;
int actualTargetIndex = targetIndex;
for (int i = mimeDataItems.count() - 1; i >= 0; i--)
{
UBMimeDataItem sourceItem = mimeDataItems.at(i);
int actualSourceIndex = sourceItem.sceneIndex();
if (sourceItem.sceneIndex() >= targetIndex)
actualSourceIndex += sourceIndexOffset;
//event->acceptProposedAction();
if (sourceItem.sceneIndex() < targetIndex)
{
if (actualSourceIndex != actualTargetIndex - 1)
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex - 1);
actualTargetIndex -= 1;
}
else
{
if (actualSourceIndex != actualTargetIndex)
emit sceneDropped(sourceItem.documentProxy(), actualSourceIndex, actualTargetIndex);
sourceIndexOffset += 1;
}
}
}
UBThumbnailWidget::dropEvent(event);
}
void UBDocumentThumbnailWidget::deleteDropCaret()
{
if (mDropCaretRectItem && scene())
{
scene()->removeItem(mDropCaretRectItem);
delete mDropCaretRectItem;
mDropCaretRectItem = 0;
}
}
void UBDocumentThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems,
const QList<QUrl>& pItemPaths, const QStringList pLabels,
const QString& pMimeType)
{
deleteDropCaret();
UBThumbnailWidget::setGraphicsItems(pGraphicsItems, pItemPaths, pLabels, pMimeType);
}
void UBDocumentThumbnailWidget::setDragEnabled(bool enabled)
{
mDragEnabled = enabled;
}
bool UBDocumentThumbnailWidget::dragEnabled() const
{
return mDragEnabled;
}
void UBDocumentThumbnailWidget::hightlightItem(int index)
{
if (0 <= index && index < mLabelsItems.length())
{
mLabelsItems.at(index)->highlight();
}
if (0 <= index && index < mGraphicItems.length())
{
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(mGraphicItems.at(index));
if (thumbnail)
thumbnail->highlight();
}
selectItemAt(index);
}

@ -19,447 +19,447 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBDocumentTreeWidget.h"
#include "document/UBDocumentProxy.h"
#include "core/UBSettings.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBMimeData.h"
#include "core/UBApplicationController.h"
#include "core/UBDocumentManager.h"
#include "document/UBDocumentController.h"
#include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBSvgSubsetAdaptor.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h"
UBDocumentTreeWidget::UBDocumentTreeWidget(QWidget * parent)
: QTreeWidget(parent)
, mSelectedProxyTi(0)
, mDropTargetProxyTi(0)
{
setDragDropMode(QAbstractItemView::InternalMove);
setAutoScroll(true);
mScrollTimer = new QTimer(this);
connect(UBDocumentManager::documentManager(), SIGNAL(documentUpdated(UBDocumentProxy*))
, this, SLOT(documentUpdated(UBDocumentProxy*)));
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int))
, this, SLOT(itemChangedValidation(QTreeWidgetItem *, int)));
connect(mScrollTimer, SIGNAL(timeout())
, this, SLOT(autoScroll()));
}
UBDocumentTreeWidget::~UBDocumentTreeWidget()
{
// NOOP
}
void UBDocumentTreeWidget::itemChangedValidation(QTreeWidgetItem * item, int column)
{
if (column == 0)
{
UBDocumentGroupTreeItem *group = dynamic_cast< UBDocumentGroupTreeItem *>(item);
if (group)
{
QString name = group->text(0);
for(int i = 0; i < topLevelItemCount (); i++)
{
QTreeWidgetItem *someTopLevelItem = topLevelItem(i);
if (someTopLevelItem != group &&
someTopLevelItem->text(0) == name)
{
group->setText(0, tr("%1 (copy)").arg(name));
}
}
}
}
}
Qt::DropActions UBDocumentTreeWidget::supportedDropActions() const
{
return Qt::MoveAction | Qt::CopyAction;
}
void UBDocumentTreeWidget::mousePressEvent(QMouseEvent *event)
{
QTreeWidgetItem* twItem = this->itemAt(event->pos());
mSelectedProxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(twItem);
QTreeWidget::mousePressEvent(event);
}
void UBDocumentTreeWidget::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
Q_UNUSED(event);
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
if (mDropTargetProxyTi)
{
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0;
}
}
void UBDocumentTreeWidget::dragMoveEvent(QDragMoveEvent *event)
{
QRect boundingFrame = frameRect();
//setting up automatic scrolling
const int SCROLL_DISTANCE = 4;
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y();
if(qAbs(bottomDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else if(qAbs(topDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos());
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingItem);
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi)
{
event->setDropAction(Qt::CopyAction);
event->accept();
}
else
{
event->ignore();
}
}
else
{
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem);
if (groupItem && mSelectedProxyTi && groupItem != mSelectedProxyTi->parent())
event->acceptProposedAction();
else
event->ignore();
}
if (event->isAccepted())
{
if (mDropTargetProxyTi)
{
if (underlyingItem != mDropTargetProxyTi)
{
mBackground = underlyingItem->background(0);
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = underlyingItem;
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5")));
}
}
else
{
mBackground = underlyingItem->background(0);
mDropTargetProxyTi = underlyingItem;
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5")));
}
}
else if (mDropTargetProxyTi)
{
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0;
}
}
void UBDocumentTreeWidget::focusInEvent(QFocusEvent *event)
{
Q_UNUSED(event);
// Tolik
//itemSelectionChanged();
QTreeWidget::focusInEvent(event);
}
void UBDocumentTreeWidget::dropEvent(QDropEvent *event)
{
if (mDropTargetProxyTi)
{
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0;
}
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos());
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem);
if (groupItem && mSelectedProxyTi && mSelectedProxyTi->proxy())
{
UBDocumentGroupTreeItem *sourceGroupItem = dynamic_cast<UBDocumentGroupTreeItem*>(mSelectedProxyTi->parent());
bool isTrashItem = sourceGroupItem && sourceGroupItem->isTrashFolder();
if ((isTrashItem && !groupItem->isTrashFolder()) ||
(!isTrashItem && mSelectedProxyTi->proxy()->groupName() != groupItem->groupName()))
{
QString groupName;
if (groupItem->isTrashFolder())
{
QString oldGroupName = mSelectedProxyTi->proxy()->metaData(UBSettings::documentGroupName).toString();
groupName = UBSettings::trashedDocumentGroupNamePrefix + oldGroupName;
}
else
{
if (groupItem->groupName() == UBApplication::app()->documentController->defaultDocumentGroupName())
groupName = "";
else
groupName = groupItem->groupName();
}
mSelectedProxyTi->proxy()->setMetaData(UBSettings::documentGroupName, groupName);
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mSelectedProxyTi->proxy());
mSelectedProxyTi->parent()->removeChild(mSelectedProxyTi);
int i = 0;
for (i = 0; i < groupItem->childCount(); i++)
{
QTreeWidgetItem *ti = groupItem->child(i);
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi)
{
if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
{
break;
}
}
}
groupItem->insertChild(i, mSelectedProxyTi);
if (isTrashItem)
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() | Qt::ItemIsEditable);
if (groupItem->isTrashFolder())
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() ^ Qt::ItemIsEditable);
//clearSelection();
expandItem(groupItem);
scrollToItem(mSelectedProxyTi);
// disabled, as those 2 calls are buggy on windows, the item disappears if we selected them
//
setCurrentItem(mSelectedProxyTi);
mSelectedProxyTi->setSelected(true);
event->setDropAction(Qt::IgnoreAction);
event->accept();
}
}
else
{
QTreeWidgetItem* underlyingTreeItem = this->itemAt(event->pos());
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingTreeItem);
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi)
{
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
event->setDropAction(Qt::CopyAction);
event->accept();
const UBMimeData *mimeData = qobject_cast <const UBMimeData*>(event->mimeData());
if (mimeData && mimeData->items().size() > 0)
{
int count = 0;
int total = mimeData->items().size();
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
foreach (UBMimeDataItem sourceItem, mimeData->items())
{
count++;
UBApplication::applicationController->showMessage(tr("Copying page %1/%2").arg(count).arg(total), true);
// TODO UB 4.x Move following code to some controller class
UBGraphicsScene *scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(sourceItem.documentProxy(), sourceItem.sceneIndex());
if (scene)
{
UBGraphicsScene* sceneClone = scene->sceneDeepCopy();
UBDocumentProxy *targetDocProxy = targetProxyTreeItem->proxy();
foreach (QUrl relativeFile, scene->relativeDependencies())
{
QString source = scene->document()->persistencePath() + "/" + relativeFile.toString();
QString target = targetDocProxy->persistencePath() + "/" + relativeFile.toString();
QFileInfo fi(target);
QDir d = fi.dir();
d.mkpath(d.absolutePath());
QFile::copy(source, target);
}
UBPersistenceManager::persistenceManager()->insertDocumentSceneAt(targetDocProxy, sceneClone, targetDocProxy->pageCount());
//due to incorrect generation of thumbnails of invisible scene I've used direct copying of thumbnail files
//it's not universal and good way but it's faster
QString from = sourceItem.documentProxy()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceItem.sceneIndex());
QString to = targetDocProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", targetDocProxy->pageCount());
QFile::remove(to);
QFile::copy(from, to);
}
}
QApplication::restoreOverrideCursor();
UBApplication::applicationController->showMessage(tr("%1 pages copied", "", total).arg(total), false);
}
}
else
{
event->setDropAction(Qt::IgnoreAction);
event->ignore();
}
}
}
}
void UBDocumentTreeWidget::documentUpdated(UBDocumentProxy *pDocument)
{
UBDocumentProxyTreeItem *treeItem = UBApplication::documentController->findDocument(pDocument);
if (treeItem)
{
QTreeWidgetItem * parent = treeItem->parent();
if (parent)
{
for (int i = 0; i < parent->indexOfChild(treeItem); i++)
{
QTreeWidgetItem *ti = parent->child(i);
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi)
{
if (pDocument->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
{
bool selected = treeItem->isSelected();
parent->removeChild(treeItem);
parent->insertChild(i, treeItem);
for (int j = 0; j < selectedItems().count(); j++)
selectedItems().at(j)->setSelected(false);
if (selected)
treeItem->setSelected(true);
break;
}
}
}
}
}
}
UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDocumentProxy* proxy, bool isEditable)
: QTreeWidgetItem()
, mProxy(proxy)
{
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
if (isEditable)
flags |= Qt::ItemIsEditable;
setFlags(flags);
int i = 0;
for (i = 0; i < parent->childCount(); i++)
{
QTreeWidgetItem *ti = parent->child(i);
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi)
{
if (proxy->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
{
break;
}
}
}
parent->insertChild(i, this);
}
UBDocumentGroupTreeItem::UBDocumentGroupTreeItem(QTreeWidgetItem *parent, bool isEditable)
: QTreeWidgetItem(parent)
{
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
if (isEditable)
flags |= Qt::ItemIsEditable;
setFlags(flags);
}
UBDocumentGroupTreeItem::~UBDocumentGroupTreeItem()
{
// NOOP
}
void UBDocumentGroupTreeItem::setGroupName(const QString& groupName)
{
setText(0, groupName);
}
QString UBDocumentGroupTreeItem::groupName() const
{
return text(0);
}
bool UBDocumentGroupTreeItem::isTrashFolder() const
{
return (0 == (flags() & Qt::ItemIsEditable)) && UBApplication::app()->documentController && (groupName() == UBApplication::app()->documentController->documentTrashGroupName());
}
bool UBDocumentGroupTreeItem::isDefaultFolder() const
{
return (0 == (flags() & Qt::ItemIsEditable)) && UBApplication::app()->documentController && (groupName() == UBApplication::app()->documentController->defaultDocumentGroupName());
}
void UBDocumentTreeWidget::autoScroll()
{
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude);
}
#include "UBDocumentTreeWidget.h"
#include "document/UBDocumentProxy.h"
#include "core/UBSettings.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "core/UBMimeData.h"
#include "core/UBApplicationController.h"
#include "core/UBDocumentManager.h"
#include "document/UBDocumentController.h"
#include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBSvgSubsetAdaptor.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h"
UBDocumentTreeWidget::UBDocumentTreeWidget(QWidget * parent)
: QTreeWidget(parent)
, mSelectedProxyTi(0)
, mDropTargetProxyTi(0)
{
setDragDropMode(QAbstractItemView::InternalMove);
setAutoScroll(true);
mScrollTimer = new QTimer(this);
connect(UBDocumentManager::documentManager(), SIGNAL(documentUpdated(UBDocumentProxy*))
, this, SLOT(documentUpdated(UBDocumentProxy*)));
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int))
, this, SLOT(itemChangedValidation(QTreeWidgetItem *, int)));
connect(mScrollTimer, SIGNAL(timeout())
, this, SLOT(autoScroll()));
}
UBDocumentTreeWidget::~UBDocumentTreeWidget()
{
// NOOP
}
void UBDocumentTreeWidget::itemChangedValidation(QTreeWidgetItem * item, int column)
{
if (column == 0)
{
UBDocumentGroupTreeItem *group = dynamic_cast< UBDocumentGroupTreeItem *>(item);
if (group)
{
QString name = group->text(0);
for(int i = 0; i < topLevelItemCount (); i++)
{
QTreeWidgetItem *someTopLevelItem = topLevelItem(i);
if (someTopLevelItem != group &&
someTopLevelItem->text(0) == name)
{
group->setText(0, tr("%1 (copy)").arg(name));
}
}
}
}
}
Qt::DropActions UBDocumentTreeWidget::supportedDropActions() const
{
return Qt::MoveAction | Qt::CopyAction;
}
void UBDocumentTreeWidget::mousePressEvent(QMouseEvent *event)
{
QTreeWidgetItem* twItem = this->itemAt(event->pos());
mSelectedProxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(twItem);
QTreeWidget::mousePressEvent(event);
}
void UBDocumentTreeWidget::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void UBDocumentTreeWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
Q_UNUSED(event);
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
if (mDropTargetProxyTi)
{
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0;
}
}
void UBDocumentTreeWidget::dragMoveEvent(QDragMoveEvent *event)
{
QRect boundingFrame = frameRect();
//setting up automatic scrolling
const int SCROLL_DISTANCE = 4;
int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y();
if(qAbs(bottomDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else if(qAbs(topDist) <= SCROLL_DISTANCE)
{
mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4;
if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100);
}
else
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos());
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingItem);
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi)
{
event->setDropAction(Qt::CopyAction);
event->accept();
}
else
{
event->ignore();
}
}
else
{
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem);
if (groupItem && mSelectedProxyTi && groupItem != mSelectedProxyTi->parent())
event->acceptProposedAction();
else
event->ignore();
}
if (event->isAccepted())
{
if (mDropTargetProxyTi)
{
if (underlyingItem != mDropTargetProxyTi)
{
mBackground = underlyingItem->background(0);
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = underlyingItem;
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5")));
}
}
else
{
mBackground = underlyingItem->background(0);
mDropTargetProxyTi = underlyingItem;
mDropTargetProxyTi->setBackground(0, QBrush(QColor("#6682b5")));
}
}
else if (mDropTargetProxyTi)
{
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0;
}
}
void UBDocumentTreeWidget::focusInEvent(QFocusEvent *event)
{
Q_UNUSED(event);
// Tolik
//itemSelectionChanged();
QTreeWidget::focusInEvent(event);
}
void UBDocumentTreeWidget::dropEvent(QDropEvent *event)
{
if (mDropTargetProxyTi)
{
mDropTargetProxyTi->setBackground(0, mBackground);
mDropTargetProxyTi = 0;
}
QTreeWidgetItem* underlyingItem = this->itemAt(event->pos());
UBDocumentGroupTreeItem *groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(underlyingItem);
if (groupItem && mSelectedProxyTi && mSelectedProxyTi->proxy())
{
UBDocumentGroupTreeItem *sourceGroupItem = dynamic_cast<UBDocumentGroupTreeItem*>(mSelectedProxyTi->parent());
bool isTrashItem = sourceGroupItem && sourceGroupItem->isTrashFolder();
if ((isTrashItem && !groupItem->isTrashFolder()) ||
(!isTrashItem && mSelectedProxyTi->proxy()->groupName() != groupItem->groupName()))
{
QString groupName;
if (groupItem->isTrashFolder())
{
QString oldGroupName = mSelectedProxyTi->proxy()->metaData(UBSettings::documentGroupName).toString();
groupName = UBSettings::trashedDocumentGroupNamePrefix + oldGroupName;
}
else
{
if (groupItem->groupName() == UBApplication::app()->documentController->defaultDocumentGroupName())
groupName = "";
else
groupName = groupItem->groupName();
}
mSelectedProxyTi->proxy()->setMetaData(UBSettings::documentGroupName, groupName);
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mSelectedProxyTi->proxy());
mSelectedProxyTi->parent()->removeChild(mSelectedProxyTi);
int i = 0;
for (i = 0; i < groupItem->childCount(); i++)
{
QTreeWidgetItem *ti = groupItem->child(i);
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi)
{
if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
{
break;
}
}
}
groupItem->insertChild(i, mSelectedProxyTi);
if (isTrashItem)
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() | Qt::ItemIsEditable);
if (groupItem->isTrashFolder())
mSelectedProxyTi->setFlags(mSelectedProxyTi->flags() ^ Qt::ItemIsEditable);
//clearSelection();
expandItem(groupItem);
scrollToItem(mSelectedProxyTi);
// disabled, as those 2 calls are buggy on windows, the item disappears if we selected them
//
setCurrentItem(mSelectedProxyTi);
mSelectedProxyTi->setSelected(true);
event->setDropAction(Qt::IgnoreAction);
event->accept();
}
}
else
{
QTreeWidgetItem* underlyingTreeItem = this->itemAt(event->pos());
UBDocumentProxyTreeItem *targetProxyTreeItem = dynamic_cast<UBDocumentProxyTreeItem*>(underlyingTreeItem);
if (targetProxyTreeItem && targetProxyTreeItem != mSelectedProxyTi)
{
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage))
{
event->setDropAction(Qt::CopyAction);
event->accept();
const UBMimeData *mimeData = qobject_cast <const UBMimeData*>(event->mimeData());
if (mimeData && mimeData->items().size() > 0)
{
int count = 0;
int total = mimeData->items().size();
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
foreach (UBMimeDataItem sourceItem, mimeData->items())
{
count++;
UBApplication::applicationController->showMessage(tr("Copying page %1/%2").arg(count).arg(total), true);
// TODO UB 4.x Move following code to some controller class
UBGraphicsScene *scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(sourceItem.documentProxy(), sourceItem.sceneIndex());
if (scene)
{
UBGraphicsScene* sceneClone = scene->sceneDeepCopy();
UBDocumentProxy *targetDocProxy = targetProxyTreeItem->proxy();
foreach (QUrl relativeFile, scene->relativeDependencies())
{
QString source = scene->document()->persistencePath() + "/" + relativeFile.toString();
QString target = targetDocProxy->persistencePath() + "/" + relativeFile.toString();
QFileInfo fi(target);
QDir d = fi.dir();
d.mkpath(d.absolutePath());
QFile::copy(source, target);
}
UBPersistenceManager::persistenceManager()->insertDocumentSceneAt(targetDocProxy, sceneClone, targetDocProxy->pageCount());
//due to incorrect generation of thumbnails of invisible scene I've used direct copying of thumbnail files
//it's not universal and good way but it's faster
QString from = sourceItem.documentProxy()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", sourceItem.sceneIndex());
QString to = targetDocProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", targetDocProxy->pageCount());
QFile::remove(to);
QFile::copy(from, to);
}
}
QApplication::restoreOverrideCursor();
UBApplication::applicationController->showMessage(tr("%1 pages copied", "", total).arg(total), false);
}
}
else
{
event->setDropAction(Qt::IgnoreAction);
event->ignore();
}
}
}
}
void UBDocumentTreeWidget::documentUpdated(UBDocumentProxy *pDocument)
{
UBDocumentProxyTreeItem *treeItem = UBApplication::documentController->findDocument(pDocument);
if (treeItem)
{
QTreeWidgetItem * parent = treeItem->parent();
if (parent)
{
for (int i = 0; i < parent->indexOfChild(treeItem); i++)
{
QTreeWidgetItem *ti = parent->child(i);
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi)
{
if (pDocument->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
{
bool selected = treeItem->isSelected();
parent->removeChild(treeItem);
parent->insertChild(i, treeItem);
for (int j = 0; j < selectedItems().count(); j++)
selectedItems().at(j)->setSelected(false);
if (selected)
treeItem->setSelected(true);
break;
}
}
}
}
}
}
UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDocumentProxy* proxy, bool isEditable)
: QTreeWidgetItem()
, mProxy(proxy)
{
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
if (isEditable)
flags |= Qt::ItemIsEditable;
setFlags(flags);
int i = 0;
for (i = 0; i < parent->childCount(); i++)
{
QTreeWidgetItem *ti = parent->child(i);
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi)
{
if (proxy->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString())
{
break;
}
}
}
parent->insertChild(i, this);
}
UBDocumentGroupTreeItem::UBDocumentGroupTreeItem(QTreeWidgetItem *parent, bool isEditable)
: QTreeWidgetItem(parent)
{
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
if (isEditable)
flags |= Qt::ItemIsEditable;
setFlags(flags);
}
UBDocumentGroupTreeItem::~UBDocumentGroupTreeItem()
{
// NOOP
}
void UBDocumentGroupTreeItem::setGroupName(const QString& groupName)
{
setText(0, groupName);
}
QString UBDocumentGroupTreeItem::groupName() const
{
return text(0);
}
bool UBDocumentGroupTreeItem::isTrashFolder() const
{
return (0 == (flags() & Qt::ItemIsEditable)) && UBApplication::app()->documentController && (groupName() == UBApplication::app()->documentController->documentTrashGroupName());
}
bool UBDocumentGroupTreeItem::isDefaultFolder() const
{
return (0 == (flags() & Qt::ItemIsEditable)) && UBApplication::app()->documentController && (groupName() == UBApplication::app()->documentController->defaultDocumentGroupName());
}
void UBDocumentTreeWidget::autoScroll()
{
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude);
}

File diff suppressed because it is too large Load Diff

@ -19,284 +19,284 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBKEYBOARDPALETTE_H
#define UBKEYBOARDPALETTE_H
#include "UBActionPalette.h"
#include <QLayout>
#include <QPainter>
#include <QMenu>
#include <QIcon>
#include "frameworks/UBPlatformUtils.h"
class UBKeyButton;
class UBKeyboardButton;
class UBApplication;
class UBMainWindow;
class BTNImages
{
public:
BTNImages(QString _strHeight, int _width, int _height);
QString m_strHeight;
int m_width;
int m_height;
QImage m_btnLeftPassive;
QImage m_btnCenterPassive;
QImage m_btnRightPassive;
QImage m_btnLeftActive;
QImage m_btnCenterActive;
QImage m_btnRightActive;
private:
QString m_strLeftPassive;
QString m_strCenterPassive;
QString m_strRightPassive;
QString m_strLeftActive;
QString m_strCenterActive;
QString m_strRightActive;
};
class ContentImage
{
public:
ContentImage(QString strHeight, int m_height, QString strContentPath);
QString m_strHeight;
int m_height;
QImage m_btnContent;
private:
QString m_strContent;
};
class UBKeyboardPalette : public UBActionPalette
{
Q_OBJECT
friend class UBKeyboardButton;
friend class UBCapsLockButton;
friend class UBShiftButton;
friend class UBLocaleButton;
friend class UBKeyButton;
public:
UBKeyboardPalette(QWidget *parent);
~UBKeyboardPalette();
BTNImages *currBtnImages;
bool isEnabled(){return locales!= NULL;}
virtual QSize sizeHint () const;
virtual void adjustSizeAndPosition(bool pUp = true);
QString getKeyButtonSize() const {QString res; res.sprintf("%dx%d", btnWidth, btnHeight); return res;}
void setKeyButtonSize(const QString& strSize);
bool m_isVisible;
QPoint m_pos;
signals:
void moved(const QPoint&);
void localeChanged(int);
void keyboardActivated(bool);
private slots:
void syncPosition(const QPoint & pos);
void syncLocale(int nLocale);
void keyboardPaletteButtonSizeChanged(QVariant size);
void onActivated(bool b);
void onDeactivated();
void showKeyboard(bool show);
void hideKeyboard();
protected:
bool capsLock;
bool shift;
int nCurrentLocale;
int nLocalesCount;
UBKeyboardLocale** locales;
int nSpecialModifierIndex;
KEYCODE specialModifier;
QString strSize;
int btnWidth;
int btnHeight;
//
bool languagePopupActive;
bool keyboardActive;
//
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
virtual void paintEvent(QPaintEvent *event);
virtual void moveEvent ( QMoveEvent * event );
void sendKeyEvent(KEYCODE keyCode);
void setLocale(int nLocale);
const QString* getLocaleName();
void init();
private:
QRect originalRect;
UBKeyButton** buttons;
UBKeyboardButton** ctrlButtons;
/*
For MacOS: synchronization with system locale.
*/
void checkLayout();
void createCtrlButtons();
void setInput(const UBKeyboardLocale* locale);
// Can be redefined under each platform
void onLocaleChanged(UBKeyboardLocale* locale);
// Storage for platform-dependent objects (linux)
void* storage;
// Linux-related parameters
int min_keycodes, max_keycodes, byte_per_code;
};
class UBKeyboardButton : public QWidget
{
Q_OBJECT
public:
UBKeyboardButton(UBKeyboardPalette* parent, QString contentImagePath);
~UBKeyboardButton();
protected:
UBKeyboardPalette* m_parent;
ContentImage *imgContent;
QString m_contentImagePath;
void paintEvent(QPaintEvent *event);
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
virtual void onPress() = 0;
virtual void onRelease() = 0;
virtual void paintContent(QPainter& painter) = 0;
virtual bool isPressed();
UBKeyboardPalette* keyboard;
void sendUnicodeSymbol(KEYCODE keycode);
void sendControlSymbol(int nSymbol);
private:
bool bFocused;
bool bPressed;
};
class UBKeyButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBKeyButton(UBKeyboardPalette* parent);
~UBKeyButton();
void setKeyBt(const KEYBT* keybt){this->keybt = keybt;}
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
private:
bool shifted();
const KEYBT* keybt;
};
class UBCntrlButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBCntrlButton(UBKeyboardPalette* parent, int _code, const QString& _contentImagePath );
UBCntrlButton(UBKeyboardPalette* parent, const QString& _label, int _code );
~UBCntrlButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
private:
QString label;
int code;
};
class UBCapsLockButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBCapsLockButton(UBKeyboardPalette* parent, const QString _contentImagePath);
~UBCapsLockButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
};
class UBShiftButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBShiftButton(UBKeyboardPalette* parent, const QString _contentImagePath);
~UBShiftButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
};
class UBLocaleButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBLocaleButton(UBKeyboardPalette* parent);
~UBLocaleButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
QMenu* localeMenu;
};
#endif // UBKEYBOARDPALETTE_H
#ifndef UBKEYBOARDPALETTE_H
#define UBKEYBOARDPALETTE_H
#include "UBActionPalette.h"
#include <QLayout>
#include <QPainter>
#include <QMenu>
#include <QIcon>
#include "frameworks/UBPlatformUtils.h"
class UBKeyButton;
class UBKeyboardButton;
class UBApplication;
class UBMainWindow;
class BTNImages
{
public:
BTNImages(QString _strHeight, int _width, int _height);
QString m_strHeight;
int m_width;
int m_height;
QImage m_btnLeftPassive;
QImage m_btnCenterPassive;
QImage m_btnRightPassive;
QImage m_btnLeftActive;
QImage m_btnCenterActive;
QImage m_btnRightActive;
private:
QString m_strLeftPassive;
QString m_strCenterPassive;
QString m_strRightPassive;
QString m_strLeftActive;
QString m_strCenterActive;
QString m_strRightActive;
};
class ContentImage
{
public:
ContentImage(QString strHeight, int m_height, QString strContentPath);
QString m_strHeight;
int m_height;
QImage m_btnContent;
private:
QString m_strContent;
};
class UBKeyboardPalette : public UBActionPalette
{
Q_OBJECT
friend class UBKeyboardButton;
friend class UBCapsLockButton;
friend class UBShiftButton;
friend class UBLocaleButton;
friend class UBKeyButton;
public:
UBKeyboardPalette(QWidget *parent);
~UBKeyboardPalette();
BTNImages *currBtnImages;
bool isEnabled(){return locales!= NULL;}
virtual QSize sizeHint () const;
virtual void adjustSizeAndPosition(bool pUp = true);
QString getKeyButtonSize() const {QString res; res.sprintf("%dx%d", btnWidth, btnHeight); return res;}
void setKeyButtonSize(const QString& strSize);
bool m_isVisible;
QPoint m_pos;
signals:
void moved(const QPoint&);
void localeChanged(int);
void keyboardActivated(bool);
private slots:
void syncPosition(const QPoint & pos);
void syncLocale(int nLocale);
void keyboardPaletteButtonSizeChanged(QVariant size);
void onActivated(bool b);
void onDeactivated();
void showKeyboard(bool show);
void hideKeyboard();
protected:
bool capsLock;
bool shift;
int nCurrentLocale;
int nLocalesCount;
UBKeyboardLocale** locales;
int nSpecialModifierIndex;
KEYCODE specialModifier;
QString strSize;
int btnWidth;
int btnHeight;
//
bool languagePopupActive;
bool keyboardActive;
//
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
virtual void paintEvent(QPaintEvent *event);
virtual void moveEvent ( QMoveEvent * event );
void sendKeyEvent(KEYCODE keyCode);
void setLocale(int nLocale);
const QString* getLocaleName();
void init();
private:
QRect originalRect;
UBKeyButton** buttons;
UBKeyboardButton** ctrlButtons;
/*
For MacOS: synchronization with system locale.
*/
void checkLayout();
void createCtrlButtons();
void setInput(const UBKeyboardLocale* locale);
// Can be redefined under each platform
void onLocaleChanged(UBKeyboardLocale* locale);
// Storage for platform-dependent objects (linux)
void* storage;
// Linux-related parameters
int min_keycodes, max_keycodes, byte_per_code;
};
class UBKeyboardButton : public QWidget
{
Q_OBJECT
public:
UBKeyboardButton(UBKeyboardPalette* parent, QString contentImagePath);
~UBKeyboardButton();
protected:
UBKeyboardPalette* m_parent;
ContentImage *imgContent;
QString m_contentImagePath;
void paintEvent(QPaintEvent *event);
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
virtual void onPress() = 0;
virtual void onRelease() = 0;
virtual void paintContent(QPainter& painter) = 0;
virtual bool isPressed();
UBKeyboardPalette* keyboard;
void sendUnicodeSymbol(KEYCODE keycode);
void sendControlSymbol(int nSymbol);
private:
bool bFocused;
bool bPressed;
};
class UBKeyButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBKeyButton(UBKeyboardPalette* parent);
~UBKeyButton();
void setKeyBt(const KEYBT* keybt){this->keybt = keybt;}
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
private:
bool shifted();
const KEYBT* keybt;
};
class UBCntrlButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBCntrlButton(UBKeyboardPalette* parent, int _code, const QString& _contentImagePath );
UBCntrlButton(UBKeyboardPalette* parent, const QString& _label, int _code );
~UBCntrlButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
private:
QString label;
int code;
};
class UBCapsLockButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBCapsLockButton(UBKeyboardPalette* parent, const QString _contentImagePath);
~UBCapsLockButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
};
class UBShiftButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBShiftButton(UBKeyboardPalette* parent, const QString _contentImagePath);
~UBShiftButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
};
class UBLocaleButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBLocaleButton(UBKeyboardPalette* parent);
~UBLocaleButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
QMenu* localeMenu;
};
#endif // UBKEYBOARDPALETTE_H

@ -19,79 +19,79 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBKeyboardPalette.h"
#include <windows.h>
#include "../core/UBApplication.h"
#include "../gui/UBMainWindow.h"
#include "core/memcheck.h"
void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{
INPUT input[2];
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0;
input[0].ki.wScan = keycode.symbol;
input[0].ki.dwFlags = KEYEVENTF_UNICODE;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0;
input[1].ki.wScan = keycode.symbol;
input[1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
::SendInput(2, input, sizeof(input[0]));
}
void UBKeyboardButton::sendControlSymbol(int nSymbol)
{
INPUT input[2];
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = nSymbol;
input[0].ki.wScan = 0;
input[0].ki.dwFlags = 0;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = nSymbol;
input[1].ki.wScan = 0;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
::SendInput(2, input, sizeof(input[0]));
}
void UBKeyboardPalette::createCtrlButtons()
{
int ctrlID = 0;
ctrlButtons = new UBKeyboardButton*[9];
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x08, "backspace");// Backspace
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x09, "tab"); // Tab
ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Shift
ctrlButtons[ctrlID++] = new UBCntrlButton(this, tr("Enter"), 0x0d); // Enter
ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
ctrlButtons[ctrlID++] = new UBCntrlButton(this, "", 0x20); // Space
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
}
void UBKeyboardPalette::checkLayout()
{}
void UBKeyboardPalette::onActivated(bool)
{}
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* )
{}
#include "UBKeyboardPalette.h"
#include <windows.h>
#include "../core/UBApplication.h"
#include "../gui/UBMainWindow.h"
#include "core/memcheck.h"
void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{
INPUT input[2];
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0;
input[0].ki.wScan = keycode.symbol;
input[0].ki.dwFlags = KEYEVENTF_UNICODE;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0;
input[1].ki.wScan = keycode.symbol;
input[1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
::SendInput(2, input, sizeof(input[0]));
}
void UBKeyboardButton::sendControlSymbol(int nSymbol)
{
INPUT input[2];
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = nSymbol;
input[0].ki.wScan = 0;
input[0].ki.dwFlags = 0;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = nSymbol;
input[1].ki.wScan = 0;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
::SendInput(2, input, sizeof(input[0]));
}
void UBKeyboardPalette::createCtrlButtons()
{
int ctrlID = 0;
ctrlButtons = new UBKeyboardButton*[9];
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x08, "backspace");// Backspace
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x09, "tab"); // Tab
ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Shift
ctrlButtons[ctrlID++] = new UBCntrlButton(this, tr("Enter"), 0x0d); // Enter
ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
ctrlButtons[ctrlID++] = new UBCntrlButton(this, "", 0x20); // Space
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
}
void UBKeyboardPalette::checkLayout()
{}
void UBKeyboardPalette::onActivated(bool)
{}
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* )
{}

@ -19,386 +19,386 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui>
#include "UBMagnifer.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardView.h"
#include "core/memcheck.h"
UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
: QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint))
, mShouldMoveWidget(false)
, mShouldResizeWidget(false)
, borderPen(Qt::darkGray)
, gView(0)
, mView(0)
{
isCusrsorAlreadyStored = false;
setMouseTracking(true);
//--------------------------------------------------//
QPixmap pix(":/images/cursors/resize.png");
QTransform tr;
tr.rotate(45);
mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
//--------------------------------------------------//
params.sizePercentFromScene = 20;
m_isInteractive = isInteractive;
sClosePixmap = new QPixmap(":/images/close.svg");
sIncreasePixmap = new QPixmap(":/images/increase.svg");
sDecreasePixmap = new QPixmap(":/images/decrease.svg");
mResizeItem = new QPixmap(":/images/resize.svg");
if (parent)
{
setAttribute(Qt::WA_NoMousePropagation);
}
else
{
// standalone window
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
// setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
#endif
#ifdef Q_WS_MAC
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
setAttribute(Qt::WA_MacNonActivatingToolWindow);
setAttribute(Qt::WA_MacNoShadow);
#endif
}
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh()));
}
UBMagnifier::~UBMagnifier()
{
if(sClosePixmap)
{
delete sClosePixmap;
sClosePixmap = NULL;
}
if(sIncreasePixmap)
{
delete sIncreasePixmap;
sIncreasePixmap = NULL;
}
if(sDecreasePixmap)
{
delete sDecreasePixmap;
sDecreasePixmap = NULL;
}
}
void UBMagnifier::setSize(qreal percentFromScene)
{
if(gView == NULL || mView == NULL) return;
// calculate object size
params.sizePercentFromScene = percentFromScene;
QSize sceneSize = mView->size();
qreal size = params.sizePercentFromScene * sceneSize.width() / 100;
QRect currGeom = geometry();
if(currGeom.width() == currGeom.height())
{
QPoint newPos = mView->mapFromGlobal(updPointMove);
setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size);
}
else
setGeometry(0, 0, size, size);
// prepare transparent bit mask
QImage mask_img(width(), height(), QImage::Format_Mono);
mask_img.fill(0xff);
QPainter mask_ptr(&mask_img);
mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) );
mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width());
bmpMask = QBitmap::fromImage(mask_img);
// prepare general image
pMap = QPixmap(width(), height());
pMap.fill(Qt::transparent);
pMap.setMask(bmpMask);
}
void UBMagnifier::setZoom(qreal zoom)
{
params.zoom = zoom;
}
void UBMagnifier::paintEvent(QPaintEvent * event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
if (m_isInteractive)
{
painter.setBrush(QColor(127, 127, 127, 127));
painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15);
painter.setBrush(QColor(190, 190, 190, 255));
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2);
painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap);
painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap);
painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap);
painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem);
}
else
{
painter.setBrush(QColor(127, 127, 127, 127));
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2);
}
painter.drawPixmap(0, 0, pMap);
}
void UBMagnifier::mousePressEvent ( QMouseEvent * event )
{
if(m_isInteractive)
{
QWidget::mousePressEvent(event);
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
event->pos().x() < size().width() - 20 &&
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
event->pos().y() < size().height() - - 20)
{
mShouldResizeWidget = true;
}
else
{
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton);
}
mMousePressPos = event->pos();
mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x();
event->accept();
update();
}
else
event->ignore();
}
void UBMagnifier::mouseMoveEvent ( QMouseEvent * event )
{
if(m_isInteractive)
{
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton))
{
move(pos() - mMousePressPos + event->pos());
event->accept();
QWidget::mouseMoveEvent(event);
emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 ));
return;
}
if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton))
{
QPoint currGlobalPos = event->globalPos();
qreal cvW = mView->width();
qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2;
qreal newPercentSize = newXSize * 100 / cvW;
emit magnifierResized_Signal(newPercentSize);
event->ignore();
return;
}
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
event->pos().x() < size().width() - 20 &&
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
event->pos().y() < size().height() - - 20 &&
isCusrsorAlreadyStored == false
)
{
mOldCursor = cursor();
isCusrsorAlreadyStored = true;
setCursor(mResizeCursor);
}
}
else
event->ignore();
}
void UBMagnifier::mouseReleaseEvent(QMouseEvent * event)
{
if(m_isInteractive)
{
mShouldMoveWidget = false;
mShouldResizeWidget = false;
if (event->pos().x() >= size().width() - sClosePixmap->width() &&
event->pos().x() < size().width()&&
event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2)
{
event->accept();
emit magnifierClose_Signal();
}
else
if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
event->pos().x() < size().width()&&
event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5)
{
event->accept();
emit magnifierZoomIn_Signal();
}
else
if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
event->pos().x() < size().width()&&
event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6)
{
event->accept();
emit magnifierZoomOut_Signal();
}
else
QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
}
else
event->ignore();
}
void UBMagnifier::slot_refresh()
{
if(!(updPointGrab.isNull()))
grabPoint(updPointGrab);
if(isCusrsorAlreadyStored)
{
QPoint globalCursorPos = QCursor::pos();
QPoint cursorPos = mapFromGlobal(globalCursorPos);
if (cursorPos.x() < size().width() - mResizeItem->width() - 20 ||
cursorPos.x() > size().width() - 20 ||
cursorPos.y() < size().height() - mResizeItem->height() - 20 ||
cursorPos.y() > size().height() - - 20
)
{
isCusrsorAlreadyStored = false;
setCursor(mOldCursor);
}
}
}
void UBMagnifier::grabPoint()
{
QMatrix transM = UBApplication::boardController->controlView()->matrix();
QPointF itemPos = gView->mapFromGlobal(updPointGrab);
qreal zWidth = width() / (params.zoom * transM.m11());
qreal zWidthHalf = zWidth / 2;
qreal zHeight = height() / (params.zoom * transM.m22());
qreal zHeightHalf = zHeight / 2;
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y())));
float x = pfScLtF.x() - zWidthHalf;
float y = pfScLtF.y() - zHeightHalf;
QPointF leftTop(x,y);
QPointF rightBottom(x + zWidth, y + zHeight);
QRectF srcRect(leftTop, rightBottom);
QPixmap newPixMap(QSize(width(), height()));
QPainter painter(&newPixMap);
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
painter.end();
pMap.fill(Qt::transparent);
pMap = newPixMap.scaled(QSize(width(), height()));
pMap.setMask(bmpMask);
update();
}
void UBMagnifier::grabPoint(const QPoint &pGrab)
{
QMatrix transM = UBApplication::boardController->controlView()->matrix();
updPointGrab = pGrab;
QPointF itemPos = gView->mapFromGlobal(pGrab);
qreal zWidth = width() / (params.zoom * transM.m11());
qreal zWidthHalf = zWidth / 2;
qreal zHeight = height() / (params.zoom * transM.m22());
qreal zHeightHalf = zHeight / 2;
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y())));
float x = pfScLtF.x() - zWidthHalf;
float y = pfScLtF.y() - zHeightHalf;
QPointF leftTop(x,y);
QPointF rightBottom(x + zWidth, y + zHeight);
QRectF srcRect(leftTop, rightBottom);
QPixmap newPixMap(QSize(width(), height()));
QPainter painter(&newPixMap);
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
painter.end();
// pMap.fill(Qt::transparent);
pMap = newPixMap;
pMap.setMask(bmpMask);
update();
}
// from global
void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove)
{
updPointGrab = pGrab;
updPointMove = pMove;
if(needGrab)
grabPoint(pGrab);
if(needMove)
{
QPoint movePos = mView->mapFromGlobal(pMove);
move(movePos.x() - width()/2, movePos.y() - height()/2);
// move(itemPos.x(), itemPos.y());
}
}
void UBMagnifier::setGrabView(QWidget *view)
{
gView = view;
mRefreshTimer.setInterval(40);
mRefreshTimer.start();
}
#include <QtGui>
#include "UBMagnifer.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBBoardView.h"
#include "core/memcheck.h"
UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
: QWidget(parent, parent ? Qt::Widget : Qt::Tool | (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint))
, mShouldMoveWidget(false)
, mShouldResizeWidget(false)
, borderPen(Qt::darkGray)
, gView(0)
, mView(0)
{
isCusrsorAlreadyStored = false;
setMouseTracking(true);
//--------------------------------------------------//
QPixmap pix(":/images/cursors/resize.png");
QTransform tr;
tr.rotate(45);
mResizeCursor = QCursor(pix.transformed(tr, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
//--------------------------------------------------//
params.sizePercentFromScene = 20;
m_isInteractive = isInteractive;
sClosePixmap = new QPixmap(":/images/close.svg");
sIncreasePixmap = new QPixmap(":/images/increase.svg");
sDecreasePixmap = new QPixmap(":/images/decrease.svg");
mResizeItem = new QPixmap(":/images/resize.svg");
if (parent)
{
setAttribute(Qt::WA_NoMousePropagation);
}
else
{
// standalone window
// !!!! Should be included into Windows after QT recompilation
#ifndef Q_WS_WIN
// setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
#endif
#ifdef Q_WS_MAC
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
setAttribute(Qt::WA_MacNonActivatingToolWindow);
setAttribute(Qt::WA_MacNoShadow);
#endif
}
connect(&mRefreshTimer, SIGNAL(timeout()), this, SLOT(slot_refresh()));
}
UBMagnifier::~UBMagnifier()
{
if(sClosePixmap)
{
delete sClosePixmap;
sClosePixmap = NULL;
}
if(sIncreasePixmap)
{
delete sIncreasePixmap;
sIncreasePixmap = NULL;
}
if(sDecreasePixmap)
{
delete sDecreasePixmap;
sDecreasePixmap = NULL;
}
}
void UBMagnifier::setSize(qreal percentFromScene)
{
if(gView == NULL || mView == NULL) return;
// calculate object size
params.sizePercentFromScene = percentFromScene;
QSize sceneSize = mView->size();
qreal size = params.sizePercentFromScene * sceneSize.width() / 100;
QRect currGeom = geometry();
if(currGeom.width() == currGeom.height())
{
QPoint newPos = mView->mapFromGlobal(updPointMove);
setGeometry(newPos.x() - size / 2, newPos.y() - size / 2, size, size);
}
else
setGeometry(0, 0, size, size);
// prepare transparent bit mask
QImage mask_img(width(), height(), QImage::Format_Mono);
mask_img.fill(0xff);
QPainter mask_ptr(&mask_img);
mask_ptr.setBrush( QBrush( QColor(0, 0, 0) ) );
mask_ptr.drawEllipse(QPointF(size/2, size/2), size / 2 - sClosePixmap->width(), size / 2 - sClosePixmap->width());
bmpMask = QBitmap::fromImage(mask_img);
// prepare general image
pMap = QPixmap(width(), height());
pMap.fill(Qt::transparent);
pMap.setMask(bmpMask);
}
void UBMagnifier::setZoom(qreal zoom)
{
params.zoom = zoom;
}
void UBMagnifier::paintEvent(QPaintEvent * event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
if (m_isInteractive)
{
painter.setBrush(QColor(127, 127, 127, 127));
painter.drawRoundedRect(QRectF(size().width() / 2, size().height() / 2, ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->width() ) / 2), 15, 15);
painter.setBrush(QColor(190, 190, 190, 255));
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2);
painter.drawPixmap(size().width() - sClosePixmap->width(), size().height() / 2 + sClosePixmap->height() * 1, *sClosePixmap);
painter.drawPixmap(size().width() - sIncreasePixmap->width(), size().height() / 2 + sIncreasePixmap->height() * 2.5, *sIncreasePixmap);
painter.drawPixmap(size().width() - sDecreasePixmap->width(), size().height() / 2 + sDecreasePixmap->height() * 3.6, *sDecreasePixmap);
painter.drawPixmap(size().width() - mResizeItem->width() - 20, size().height() - mResizeItem->height() - 20, *mResizeItem);
}
else
{
painter.setBrush(QColor(127, 127, 127, 127));
painter.drawEllipse(QPoint( size().width() / 2, size().height() / 2), ( size().width() - sClosePixmap->width() ) / 2, ( size().height() - sClosePixmap->height() ) / 2);
}
painter.drawPixmap(0, 0, pMap);
}
void UBMagnifier::mousePressEvent ( QMouseEvent * event )
{
if(m_isInteractive)
{
QWidget::mousePressEvent(event);
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
event->pos().x() < size().width() - 20 &&
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
event->pos().y() < size().height() - - 20)
{
mShouldResizeWidget = true;
}
else
{
mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton);
}
mMousePressPos = event->pos();
mMousePressDelta = (qreal)updPointGrab.x() + (qreal)size().width() / 2 - (qreal)event->globalPos().x();
event->accept();
update();
}
else
event->ignore();
}
void UBMagnifier::mouseMoveEvent ( QMouseEvent * event )
{
if(m_isInteractive)
{
if(mShouldMoveWidget && (event->buttons() & Qt::LeftButton))
{
move(pos() - mMousePressPos + event->pos());
event->accept();
QWidget::mouseMoveEvent(event);
emit magnifierMoved_Signal(QPoint(this->pos().x() + size().width() / 2, this->pos().y() + size().height() / 2 ));
return;
}
if(mShouldResizeWidget && (event->buttons() & Qt::LeftButton))
{
QPoint currGlobalPos = event->globalPos();
qreal cvW = mView->width();
qreal newXSize = ( currGlobalPos.x() + mMousePressDelta - updPointGrab.x() ) * 2;
qreal newPercentSize = newXSize * 100 / cvW;
emit magnifierResized_Signal(newPercentSize);
event->ignore();
return;
}
if (event->pos().x() >= size().width() - mResizeItem->width() - 20 &&
event->pos().x() < size().width() - 20 &&
event->pos().y() >= size().height() - mResizeItem->height() - 20 &&
event->pos().y() < size().height() - - 20 &&
isCusrsorAlreadyStored == false
)
{
mOldCursor = cursor();
isCusrsorAlreadyStored = true;
setCursor(mResizeCursor);
}
}
else
event->ignore();
}
void UBMagnifier::mouseReleaseEvent(QMouseEvent * event)
{
if(m_isInteractive)
{
mShouldMoveWidget = false;
mShouldResizeWidget = false;
if (event->pos().x() >= size().width() - sClosePixmap->width() &&
event->pos().x() < size().width()&&
event->pos().y() >= size().height() / 2 + sClosePixmap->height() * 1 &&
event->pos().y() < size().height() / 2 + sClosePixmap->height() * 2)
{
event->accept();
emit magnifierClose_Signal();
}
else
if (event->pos().x() >= size().width() - sIncreasePixmap->width() &&
event->pos().x() < size().width()&&
event->pos().y() >= size().height() / 2 + sIncreasePixmap->height() * 2.5 &&
event->pos().y() < size().height() / 2 + sIncreasePixmap->height() * 3.5)
{
event->accept();
emit magnifierZoomIn_Signal();
}
else
if (event->pos().x() >= size().width() - sDecreasePixmap->width() &&
event->pos().x() < size().width()&&
event->pos().y() >= size().height() / 2 + sDecreasePixmap->height() * 3.6 &&
event->pos().y() < size().height() / 2 + sDecreasePixmap->height() * 4.6)
{
event->accept();
emit magnifierZoomOut_Signal();
}
else
QWidget::mouseReleaseEvent(event); // don't propgate to parent, the widget is deleted in UBApplication::boardController->removeTool
}
else
event->ignore();
}
void UBMagnifier::slot_refresh()
{
if(!(updPointGrab.isNull()))
grabPoint(updPointGrab);
if(isCusrsorAlreadyStored)
{
QPoint globalCursorPos = QCursor::pos();
QPoint cursorPos = mapFromGlobal(globalCursorPos);
if (cursorPos.x() < size().width() - mResizeItem->width() - 20 ||
cursorPos.x() > size().width() - 20 ||
cursorPos.y() < size().height() - mResizeItem->height() - 20 ||
cursorPos.y() > size().height() - - 20
)
{
isCusrsorAlreadyStored = false;
setCursor(mOldCursor);
}
}
}
void UBMagnifier::grabPoint()
{
QMatrix transM = UBApplication::boardController->controlView()->matrix();
QPointF itemPos = gView->mapFromGlobal(updPointGrab);
qreal zWidth = width() / (params.zoom * transM.m11());
qreal zWidthHalf = zWidth / 2;
qreal zHeight = height() / (params.zoom * transM.m22());
qreal zHeightHalf = zHeight / 2;
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y())));
float x = pfScLtF.x() - zWidthHalf;
float y = pfScLtF.y() - zHeightHalf;
QPointF leftTop(x,y);
QPointF rightBottom(x + zWidth, y + zHeight);
QRectF srcRect(leftTop, rightBottom);
QPixmap newPixMap(QSize(width(), height()));
QPainter painter(&newPixMap);
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
painter.end();
pMap.fill(Qt::transparent);
pMap = newPixMap.scaled(QSize(width(), height()));
pMap.setMask(bmpMask);
update();
}
void UBMagnifier::grabPoint(const QPoint &pGrab)
{
QMatrix transM = UBApplication::boardController->controlView()->matrix();
updPointGrab = pGrab;
QPointF itemPos = gView->mapFromGlobal(pGrab);
qreal zWidth = width() / (params.zoom * transM.m11());
qreal zWidthHalf = zWidth / 2;
qreal zHeight = height() / (params.zoom * transM.m22());
qreal zHeightHalf = zHeight / 2;
QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y())));
float x = pfScLtF.x() - zWidthHalf;
float y = pfScLtF.y() - zHeightHalf;
QPointF leftTop(x,y);
QPointF rightBottom(x + zWidth, y + zHeight);
QRectF srcRect(leftTop, rightBottom);
QPixmap newPixMap(QSize(width(), height()));
QPainter painter(&newPixMap);
UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect);
painter.end();
// pMap.fill(Qt::transparent);
pMap = newPixMap;
pMap.setMask(bmpMask);
update();
}
// from global
void UBMagnifier::grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab, bool needMove)
{
updPointGrab = pGrab;
updPointMove = pMove;
if(needGrab)
grabPoint(pGrab);
if(needMove)
{
QPoint movePos = mView->mapFromGlobal(pMove);
move(movePos.x() - width()/2, movePos.y() - height()/2);
// move(itemPos.x(), itemPos.y());
}
}
void UBMagnifier::setGrabView(QWidget *view)
{
gView = view;
mRefreshTimer.setInterval(40);
mRefreshTimer.start();
}

@ -19,87 +19,87 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBMAGNIFIER_H
#define UBMAGNIFIER_H
#include <QtGui>
class UBMagnifierParams
{
public :
int x;
int y;
qreal zoom;
qreal sizePercentFromScene;
};
class UBMagnifier : public QWidget
{
Q_OBJECT
public:
UBMagnifier(QWidget *parent = 0, bool isInteractive = false);
~UBMagnifier();
void setSize(qreal percentFromScene);
void setZoom(qreal zoom);
void setGrabView(QWidget *view);
void setMoveView(QWidget *view) {mView = view;}
void grabPoint();
void grabPoint(const QPoint &point);
void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true);
UBMagnifierParams params;
signals:
void magnifierMoved_Signal(QPoint newPos);
void magnifierClose_Signal();
void magnifierZoomIn_Signal();
void magnifierZoomOut_Signal();
void magnifierResized_Signal(qreal newPercentSize);
public slots:
void slot_refresh();
protected:
void paintEvent(QPaintEvent *);
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseMoveEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
QPoint mMousePressPos;
qreal mMousePressDelta;
bool mShouldMoveWidget;
bool mShouldResizeWidget;
QPixmap *sClosePixmap;
QPixmap *sIncreasePixmap;
QPixmap *sDecreasePixmap;
QPixmap *mResizeItem;
bool isCusrsorAlreadyStored;
QCursor mOldCursor;
QCursor mResizeCursor;
private:
QTimer mRefreshTimer;
bool m_isInteractive;
QPoint updPointGrab;
QPoint updPointMove;
QPixmap pMap;
QBitmap bmpMask;
QPen borderPen;
QWidget *gView;
QWidget *mView;
};
#endif // UBMAGNIFIER_H
#ifndef UBMAGNIFIER_H
#define UBMAGNIFIER_H
#include <QtGui>
class UBMagnifierParams
{
public :
int x;
int y;
qreal zoom;
qreal sizePercentFromScene;
};
class UBMagnifier : public QWidget
{
Q_OBJECT
public:
UBMagnifier(QWidget *parent = 0, bool isInteractive = false);
~UBMagnifier();
void setSize(qreal percentFromScene);
void setZoom(qreal zoom);
void setGrabView(QWidget *view);
void setMoveView(QWidget *view) {mView = view;}
void grabPoint();
void grabPoint(const QPoint &point);
void grabNMove(const QPoint &pGrab, const QPoint &pMove, bool needGrab = true, bool needMove = true);
UBMagnifierParams params;
signals:
void magnifierMoved_Signal(QPoint newPos);
void magnifierClose_Signal();
void magnifierZoomIn_Signal();
void magnifierZoomOut_Signal();
void magnifierResized_Signal(qreal newPercentSize);
public slots:
void slot_refresh();
protected:
void paintEvent(QPaintEvent *);
virtual void mousePressEvent ( QMouseEvent * event );
virtual void mouseMoveEvent ( QMouseEvent * event );
virtual void mouseReleaseEvent ( QMouseEvent * event );
QPoint mMousePressPos;
qreal mMousePressDelta;
bool mShouldMoveWidget;
bool mShouldResizeWidget;
QPixmap *sClosePixmap;
QPixmap *sIncreasePixmap;
QPixmap *sDecreasePixmap;
QPixmap *mResizeItem;
bool isCusrsorAlreadyStored;
QCursor mOldCursor;
QCursor mResizeCursor;
private:
QTimer mRefreshTimer;
bool m_isInteractive;
QPoint updPointGrab;
QPoint updPointMove;
QPixmap pMap;
QBitmap bmpMask;
QPen borderPen;
QWidget *gView;
QWidget *mView;
};
#endif // UBMAGNIFIER_H

@ -19,135 +19,135 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBNavigatorPalette.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the object name
*/
UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name):
UBDockPalette(eUBDockPaletteType_LEFT, parent, name)
, mNavigator(NULL)
, mLayout(NULL)
, mHLayout(NULL)
, mPageNbr(NULL)
, mClock(NULL)
{
// Build the gui
mLayout = new QVBoxLayout(this);
mLayout->setContentsMargins(customMargin(), customMargin(), 2*border() + customMargin(), customMargin());
setLayout(mLayout);
mNavigator = new UBDocumentNavigator(this);
mNavigator->setStyleSheet(QString("background-color : transparent;"));
mLayout->addWidget(mNavigator, 1);
mHLayout = new QHBoxLayout();
mLayout->addLayout(mHLayout, 0);
mPageNbr = new QLabel(this);
mClock = new QLabel(this);
mHLayout->addWidget(mPageNbr);
mHLayout->addWidget(mClock);
// Configure the page number indicator
mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
setPageNumber(0, 0);
mPageNbr->setAlignment(Qt::AlignHCenter);
// Configure the clock
mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat);
mClock->setAlignment(Qt::AlignHCenter);
//strip seconds
mTimeFormat = mTimeFormat.remove(":ss");
mTimeFormat = mTimeFormat.remove(":s");
mTimerID = startTimer(1000);
}
/**
* \brief Destructor
*/
UBNavigatorPalette::~UBNavigatorPalette()
{
killTimer(mTimerID);
if(NULL != mClock)
{
delete mClock;
mClock = NULL;
}
if(NULL != mPageNbr)
{
delete mPageNbr;
mPageNbr = NULL;
}
if(NULL != mHLayout)
{
delete mHLayout;
mHLayout = NULL;
}
if(NULL != mLayout)
{
delete mLayout;
mLayout = NULL;
}
if(NULL != mNavigator)
{
delete mNavigator;
mNavigator = NULL;
}
}
/**
* \brief Set the current document in the navigator
* @param document as the given document
*/
/**
* \brief Refresh the thumbnails widget
*/
void UBNavigatorPalette::refresh()
{
}
/**
* \brief Handle the resize event
* @param event as the resize event
*/
void UBNavigatorPalette::resizeEvent(QResizeEvent *event)
{
UBDockPalette::resizeEvent(event);
if(NULL != mNavigator)
{
mNavigator->setMinimumHeight(height() - 2*border());
}
}
void UBNavigatorPalette::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
updateTime();
}
void UBNavigatorPalette::updateTime()
{
if (mClock)
{
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
}
}
void UBNavigatorPalette::setPageNumber(int current, int total)
{
mPageNbr->setText(QString("%1 / %2").arg(current).arg(total));
}
#include "UBNavigatorPalette.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the object name
*/
UBNavigatorPalette::UBNavigatorPalette(QWidget *parent, const char *name):
UBDockPalette(eUBDockPaletteType_LEFT, parent, name)
, mNavigator(NULL)
, mLayout(NULL)
, mHLayout(NULL)
, mPageNbr(NULL)
, mClock(NULL)
{
// Build the gui
mLayout = new QVBoxLayout(this);
mLayout->setContentsMargins(customMargin(), customMargin(), 2*border() + customMargin(), customMargin());
setLayout(mLayout);
mNavigator = new UBDocumentNavigator(this);
mNavigator->setStyleSheet(QString("background-color : transparent;"));
mLayout->addWidget(mNavigator, 1);
mHLayout = new QHBoxLayout();
mLayout->addLayout(mHLayout, 0);
mPageNbr = new QLabel(this);
mClock = new QLabel(this);
mHLayout->addWidget(mPageNbr);
mHLayout->addWidget(mClock);
// Configure the page number indicator
mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
setPageNumber(0, 0);
mPageNbr->setAlignment(Qt::AlignHCenter);
// Configure the clock
mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat);
mClock->setAlignment(Qt::AlignHCenter);
//strip seconds
mTimeFormat = mTimeFormat.remove(":ss");
mTimeFormat = mTimeFormat.remove(":s");
mTimerID = startTimer(1000);
}
/**
* \brief Destructor
*/
UBNavigatorPalette::~UBNavigatorPalette()
{
killTimer(mTimerID);
if(NULL != mClock)
{
delete mClock;
mClock = NULL;
}
if(NULL != mPageNbr)
{
delete mPageNbr;
mPageNbr = NULL;
}
if(NULL != mHLayout)
{
delete mHLayout;
mHLayout = NULL;
}
if(NULL != mLayout)
{
delete mLayout;
mLayout = NULL;
}
if(NULL != mNavigator)
{
delete mNavigator;
mNavigator = NULL;
}
}
/**
* \brief Set the current document in the navigator
* @param document as the given document
*/
/**
* \brief Refresh the thumbnails widget
*/
void UBNavigatorPalette::refresh()
{
}
/**
* \brief Handle the resize event
* @param event as the resize event
*/
void UBNavigatorPalette::resizeEvent(QResizeEvent *event)
{
UBDockPalette::resizeEvent(event);
if(NULL != mNavigator)
{
mNavigator->setMinimumHeight(height() - 2*border());
}
}
void UBNavigatorPalette::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
updateTime();
}
void UBNavigatorPalette::updateTime()
{
if (mClock)
{
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
}
}
void UBNavigatorPalette::setPageNumber(int current, int total)
{
mPageNbr->setText(QString("%1 / %2").arg(current).arg(total));
}

@ -19,55 +19,55 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBNAVIGATORPALETTE_H
#define UBNAVIGATORPALETTE_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QResizeEvent>
#include <QTimerEvent>
#include <QLabel>
#include <QString>
#include "UBDockPalette.h"
#include "UBDocumentNavigator.h"
#include "document/UBDocumentProxy.h"
class UBNavigatorPalette : public UBDockPalette
{
Q_OBJECT
public:
UBNavigatorPalette(QWidget* parent=0, const char* name="navigatorPalette");
~UBNavigatorPalette();
void setDocument(UBDocumentProxy* document);
void refresh();
public slots:
void setPageNumber(int current, int total);
protected:
virtual void resizeEvent(QResizeEvent *event);
virtual void timerEvent(QTimerEvent *event);
private:
void updateTime();
/** The thumbnails navigator widget */
UBDocumentNavigator* mNavigator;
/** The layout */
QVBoxLayout* mLayout;
QHBoxLayout* mHLayout;
QLabel* mPageNbr;
QLabel* mClock;
QString mTimeFormat;
int mTimerID;
};
#endif // UBNAVIGATORPALETTE_H
#ifndef UBNAVIGATORPALETTE_H
#define UBNAVIGATORPALETTE_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QResizeEvent>
#include <QTimerEvent>
#include <QLabel>
#include <QString>
#include "UBDockPalette.h"
#include "UBDocumentNavigator.h"
#include "document/UBDocumentProxy.h"
class UBNavigatorPalette : public UBDockPalette
{
Q_OBJECT
public:
UBNavigatorPalette(QWidget* parent=0, const char* name="navigatorPalette");
~UBNavigatorPalette();
void setDocument(UBDocumentProxy* document);
void refresh();
public slots:
void setPageNumber(int current, int total);
protected:
virtual void resizeEvent(QResizeEvent *event);
virtual void timerEvent(QTimerEvent *event);
private:
void updateTime();
/** The thumbnails navigator widget */
UBDocumentNavigator* mNavigator;
/** The layout */
QVBoxLayout* mLayout;
QHBoxLayout* mHLayout;
QLabel* mPageNbr;
QLabel* mClock;
QString mTimeFormat;
int mTimerID;
};
#endif // UBNAVIGATORPALETTE_H

@ -19,162 +19,162 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBPageNavigationWidget.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "document/UBDocumentContainer.h"
#include "globals/UBGlobals.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the object name
*/
UBPageNavigationWidget::UBPageNavigationWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent)
, mNavigator(NULL)
, mLayout(NULL)
, mHLayout(NULL)
, mPageNbr(NULL)
, mClock(NULL)
{
setObjectName(name);
mName = "PageNavigator";
mVisibleState = true;
SET_STYLE_SHEET();
mIconToRight = QPixmap(":images/pages_open.png");
mIconToLeft = QPixmap(":images/pages_close.png");
// Build the gui
mLayout = new QVBoxLayout(this);
setLayout(mLayout);
mNavigator = new UBDocumentNavigator(this);
mLayout->addWidget(mNavigator, 1);
mHLayout = new QHBoxLayout();
mLayout->addLayout(mHLayout, 0);
mPageNbr = new QLabel(this);
mClock = new QLabel(this);
mHLayout->addWidget(mPageNbr);
mHLayout->addWidget(mClock);
// Configure the page number indicator
mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
setPageNumber(0, 0);
mPageNbr->setAlignment(Qt::AlignHCenter);
// Configure the clock
mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat);
mClock->setAlignment(Qt::AlignHCenter);
//strip seconds
mTimeFormat = mTimeFormat.remove(":ss");
mTimeFormat = mTimeFormat.remove(":s");
mTimerID = startTimer(1000);
}
/**
* \brief Destructor
*/
UBPageNavigationWidget::~UBPageNavigationWidget()
{
killTimer(mTimerID);
if(NULL != mClock)
{
delete mClock;
mClock = NULL;
}
if(NULL != mPageNbr)
{
delete mPageNbr;
mPageNbr = NULL;
}
if(NULL != mHLayout)
{
delete mHLayout;
mHLayout = NULL;
}
if(NULL != mLayout)
{
delete mLayout;
mLayout = NULL;
}
if(NULL != mNavigator)
{
delete mNavigator;
mNavigator = NULL;
}
}
/**
* \brief Refresh the thumbnails widget
*/
void UBPageNavigationWidget::refresh()
{
// TOLIK!!!
// mNavigator->setDocument(UBApplication::boardController->activeDocument());
}
/**
* \brief Notify a timer event
* @param event as the timer event
*/
void UBPageNavigationWidget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
updateTime();
}
/**
* \brief Update the current time
*/
void UBPageNavigationWidget::updateTime()
{
if (mClock)
{
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
}
}
/**
* \brief Set the page number
* @param current as the current page
* @param total as the total number of pages
*/
void UBPageNavigationWidget::setPageNumber(int current, int total)
{
mPageNbr->setText(QString("%1 / %2").arg(current).arg(UBDocumentContainer::sceneIndexFromPage(total)));
}
/**
* \brief Get the custom margin value
* @return the custom margin value
*/
int UBPageNavigationWidget::customMargin()
{
return 5;
}
/**
* \brief Get the border value
* @return the border value
*/
int UBPageNavigationWidget::border()
{
return 15;
}
#include "UBPageNavigationWidget.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "document/UBDocumentContainer.h"
#include "globals/UBGlobals.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the object name
*/
UBPageNavigationWidget::UBPageNavigationWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent)
, mNavigator(NULL)
, mLayout(NULL)
, mHLayout(NULL)
, mPageNbr(NULL)
, mClock(NULL)
{
setObjectName(name);
mName = "PageNavigator";
mVisibleState = true;
SET_STYLE_SHEET();
mIconToRight = QPixmap(":images/pages_open.png");
mIconToLeft = QPixmap(":images/pages_close.png");
// Build the gui
mLayout = new QVBoxLayout(this);
setLayout(mLayout);
mNavigator = new UBDocumentNavigator(this);
mLayout->addWidget(mNavigator, 1);
mHLayout = new QHBoxLayout();
mLayout->addLayout(mHLayout, 0);
mPageNbr = new QLabel(this);
mClock = new QLabel(this);
mHLayout->addWidget(mPageNbr);
mHLayout->addWidget(mClock);
// Configure the page number indicator
mPageNbr->setStyleSheet(QString("QLabel { color: white; background-color: transparent; border: none; font-family: Arial; font-weight: bold; font-size: 20px }"));
setPageNumber(0, 0);
mPageNbr->setAlignment(Qt::AlignHCenter);
// Configure the clock
mClock->setStyleSheet(QString("QLabel {color: white; background-color: transparent; text-align: center; font-family: Arial; font-weight: bold; font-size: 20px}"));
mTimeFormat = QLocale::system().timeFormat(QLocale::ShortFormat);
mClock->setAlignment(Qt::AlignHCenter);
//strip seconds
mTimeFormat = mTimeFormat.remove(":ss");
mTimeFormat = mTimeFormat.remove(":s");
mTimerID = startTimer(1000);
}
/**
* \brief Destructor
*/
UBPageNavigationWidget::~UBPageNavigationWidget()
{
killTimer(mTimerID);
if(NULL != mClock)
{
delete mClock;
mClock = NULL;
}
if(NULL != mPageNbr)
{
delete mPageNbr;
mPageNbr = NULL;
}
if(NULL != mHLayout)
{
delete mHLayout;
mHLayout = NULL;
}
if(NULL != mLayout)
{
delete mLayout;
mLayout = NULL;
}
if(NULL != mNavigator)
{
delete mNavigator;
mNavigator = NULL;
}
}
/**
* \brief Refresh the thumbnails widget
*/
void UBPageNavigationWidget::refresh()
{
// TOLIK!!!
// mNavigator->setDocument(UBApplication::boardController->activeDocument());
}
/**
* \brief Notify a timer event
* @param event as the timer event
*/
void UBPageNavigationWidget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
updateTime();
}
/**
* \brief Update the current time
*/
void UBPageNavigationWidget::updateTime()
{
if (mClock)
{
mClock->setText(QLocale::system().toString (QTime::currentTime(), mTimeFormat));
}
}
/**
* \brief Set the page number
* @param current as the current page
* @param total as the total number of pages
*/
void UBPageNavigationWidget::setPageNumber(int current, int total)
{
mPageNbr->setText(QString("%1 / %2").arg(current).arg(UBDocumentContainer::sceneIndexFromPage(total)));
}
/**
* \brief Get the custom margin value
* @return the custom margin value
*/
int UBPageNavigationWidget::customMargin()
{
return 5;
}
/**
* \brief Get the border value
* @return the border value
*/
int UBPageNavigationWidget::border()
{
return 15;
}

@ -19,62 +19,62 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBPAGENAVIGATIONWIDGET_H
#define UBPAGENAVIGATIONWIDGET_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QResizeEvent>
#include <QTimerEvent>
#include <QLabel>
#include <QString>
#include "UBDocumentNavigator.h"
#include "UBDockPaletteWidget.h"
#include "document/UBDocumentProxy.h"
class UBPageNavigationWidget : public UBDockPaletteWidget
{
Q_OBJECT
public:
UBPageNavigationWidget(QWidget* parent=0, const char* name="UBPageNavigationWidget");
~UBPageNavigationWidget();
//void setDocument(UBDocumentProxy* document);
void refresh();
bool visibleInMode(eUBDockPaletteWidgetMode mode)
{
return mode == eUBDockPaletteWidget_BOARD;
}
signals:
void resizeRequest(QResizeEvent* event);
public slots:
void setPageNumber(int current, int total);
protected:
virtual void timerEvent(QTimerEvent *event);
private:
void updateTime();
int customMargin();
int border();
/** The thumbnails navigator widget */
UBDocumentNavigator* mNavigator;
/** The layout */
QVBoxLayout* mLayout;
QHBoxLayout* mHLayout;
QLabel* mPageNbr;
QLabel* mClock;
QString mTimeFormat;
int mTimerID;
};
#endif // UBPAGENAVIGATIONWIDGET_H
#ifndef UBPAGENAVIGATIONWIDGET_H
#define UBPAGENAVIGATIONWIDGET_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QResizeEvent>
#include <QTimerEvent>
#include <QLabel>
#include <QString>
#include "UBDocumentNavigator.h"
#include "UBDockPaletteWidget.h"
#include "document/UBDocumentProxy.h"
class UBPageNavigationWidget : public UBDockPaletteWidget
{
Q_OBJECT
public:
UBPageNavigationWidget(QWidget* parent=0, const char* name="UBPageNavigationWidget");
~UBPageNavigationWidget();
//void setDocument(UBDocumentProxy* document);
void refresh();
bool visibleInMode(eUBDockPaletteWidgetMode mode)
{
return mode == eUBDockPaletteWidget_BOARD;
}
signals:
void resizeRequest(QResizeEvent* event);
public slots:
void setPageNumber(int current, int total);
protected:
virtual void timerEvent(QTimerEvent *event);
private:
void updateTime();
int customMargin();
int border();
/** The thumbnails navigator widget */
UBDocumentNavigator* mNavigator;
/** The layout */
QVBoxLayout* mLayout;
QHBoxLayout* mHLayout;
QLabel* mPageNbr;
QLabel* mClock;
QString mTimeFormat;
int mTimerID;
};
#endif // UBPAGENAVIGATIONWIDGET_H

File diff suppressed because it is too large Load Diff

@ -19,417 +19,417 @@
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBTHUMBNAILWIDGET_H_
#define UBTHUMBNAILWIDGET_H_
#include <QtGui>
#include <QtSvg>
#include <QTime>
#include <QGraphicsSceneHoverEvent>
#include "frameworks/UBCoreGraphicsScene.h"
#include "core/UBSettings.h"
#include "domain/UBItem.h"
#define STARTDRAGTIME 1000000
#define BUTTONSIZE 48
#define BUTTONSPACING 5
class UBDocumentProxy;
class UBThumbnailTextItem;
class UBThumbnail;
class UBThumbnailWidget : public QGraphicsView
{
Q_OBJECT;
public:
UBThumbnailWidget(QWidget* parent);
virtual ~UBThumbnailWidget();
QList<QGraphicsItem*> selectedItems();
void selectItemAt(int pIndex, bool extend = false);
void unselectItemAt(int pIndex);
qreal thumbnailWidth()
{
return mThumbnailWidth;
}
void setBackgroundBrush(const QBrush& brush)
{
mThumbnailsScene.setBackgroundBrush(brush);
}
public slots:
void setThumbnailWidth(qreal pThumbnailWidth);
void setSpacing(qreal pSpacing);
virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString(""));
void refreshScene();
void sceneSelectionChanged();
signals:
void resized();
void selectionChanged();
void mouseDoubleClick(QGraphicsItem* item, int index);
void mouseClick(QGraphicsItem* item, int index);
protected:
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void resizeEvent(QResizeEvent * event);
void mouseDoubleClickEvent(QMouseEvent * event);
virtual void keyPressEvent(QKeyEvent *event);
virtual void focusInEvent(QFocusEvent *event);
QList<QGraphicsItem*> mGraphicItems;
QList<UBThumbnailTextItem*> mLabelsItems;
QPointF mMousePressScenePos;
QPoint mMousePressPos;
protected:
qreal spacing() { return mSpacing; }
QList<QUrl> mItemsPaths;
QStringList mLabels;
bool bSelectionInProgress;
bool bCanDrag;
private:
void selectAll();
void selectItems(int startIndex, int count);
int rowCount() const;
int columnCount() const;
static bool thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2);
void deleteLasso();
UBCoreGraphicsScene mThumbnailsScene;
QString mMimeType;
QPointF prevMoveMousePos;
qreal mThumbnailWidth;
qreal mThumbnailHeight;
qreal mSpacing;
UBThumbnail *mLastSelectedThumbnail;
int mSelectionSpan;
QRectF mPrevLassoRect;
QGraphicsRectItem *mLassoRectItem;
QSet<QGraphicsItem*> mSelectedThumbnailItems;
QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsX;
QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsY;
QTime mClickTime;
};
class UBThumbnail
{
public:
UBThumbnail();
virtual ~UBThumbnail();
QStyleOptionGraphicsItem muteStyleOption(const QStyleOptionGraphicsItem *option)
{
// Never draw the rubber band, we draw our custom selection with the DelegateFrame
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option);
styleOption.state &= ~QStyle::State_Selected;
return styleOption;
}
virtual void itemChange(QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
Q_UNUSED(value);
if ((change == QGraphicsItem::ItemSelectedHasChanged
|| change == QGraphicsItem::ItemTransformHasChanged
|| change == QGraphicsItem::ItemPositionHasChanged)
&& item->scene())
{
if (item->isSelected())
{
if (!mSelectionItem->scene())
{
item->scene()->addItem(mSelectionItem);
mSelectionItem->setZValue(item->zValue() - 1);
// UBGraphicsItem::assignZValue(mSelectionItem, item->zValue() - 1);
mAddedToScene = true;
}
mSelectionItem->setRect(
item->sceneBoundingRect().x() - 5,
item->sceneBoundingRect().y() - 5,
item->sceneBoundingRect().width() + 10,
item->sceneBoundingRect().height() + 10);
mSelectionItem->show();
}
else
{
mSelectionItem->hide();
}
}
}
int column() { return mColumn; }
void setColumn(int column) { mColumn = column; }
int row() { return mRow; }
void setRow(int row) { mRow = row; }
protected:
QGraphicsRectItem *mSelectionItem;
private:
bool mAddedToScene;
int mColumn;
int mRow;
};
class UBThumbnailSvg : public QGraphicsSvgItem, public UBThumbnail
{
public:
UBThumbnailSvg(const QString& path)
: QGraphicsSvgItem(path)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
virtual ~UBThumbnailSvg()
{
// NOOP
}
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsSvgItem::paint(painter, &styleOption, widget);
}
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
{
UBThumbnail::itemChange(this, change, value);
return QGraphicsSvgItem::itemChange(change, value);
}
};
class UBThumbnailPixmap : public QGraphicsPixmapItem, public UBThumbnail
{
public:
UBThumbnailPixmap(const QPixmap& pix)
: QGraphicsPixmapItem(pix)
{
setTransformationMode(Qt::SmoothTransformation); // UB 4.3 may be expensive -- make configurable
setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
virtual ~UBThumbnailPixmap()
{
// NOOP
}
virtual QPainterPath shape () const
{
QPainterPath path;
path.addRect(boundingRect());
return path;
}
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsPixmapItem::paint(painter, &styleOption, widget);
}
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
{
UBThumbnail::itemChange(this, change, value);
return QGraphicsPixmapItem::itemChange(change, value);
}
};
class UBSceneThumbnailPixmap : public UBThumbnailPixmap
{
public:
UBSceneThumbnailPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
: UBThumbnailPixmap(pix)
, mProxy(proxy)
, mSceneIndex(pSceneIndex)
{
// NOOP
}
virtual ~UBSceneThumbnailPixmap()
{
// NOOP
}
UBDocumentProxy* proxy()
{
return mProxy;
}
int sceneIndex()
{
return mSceneIndex;
}
void highlight()
{
//NOOP
}
private:
UBDocumentProxy* mProxy;
int mSceneIndex;
};
class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
{
public:
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex);
~UBSceneThumbnailNavigPixmap();
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
void updateButtonsState();
void deletePage();
void duplicatePage();
void moveUpPage();
void moveDownPage();
bool bButtonsVisible;
bool bCanDelete;
bool bCanMoveUp;
bool bCanMoveDown;
bool bCanDuplicate;
};
class UBThumbnailVideo : public UBThumbnailPixmap
{
public:
UBThumbnailVideo(const QUrl &path)
: UBThumbnailPixmap(QPixmap(":/images/movie.svg"))
, mPath(path)
{
// NOOP
}
virtual ~UBThumbnailVideo()
{
// NOOP
}
QUrl path()
{
return mPath;
}
private:
QUrl mPath;
};
class UBThumbnailTextItem : public QGraphicsTextItem
{
public:
UBThumbnailTextItem(const QString& text)
: QGraphicsTextItem(text)
, mUnelidedText(text)
, mIsHighlighted(false)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));}
void setWidth(qreal pWidth)
{
if (mWidth != pWidth)
{
prepareGeometryChange();
mWidth = pWidth;
computeText();
}
};
qreal width() {return mWidth;}
void highlight()
{
if (!mIsHighlighted)
{
mIsHighlighted = true;
computeText();
}
}
void computeText()
{
QFontMetricsF fm(font());
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideRight, mWidth);
if (mIsHighlighted)
{
setHtml("<span style=\"color: #6682b5\">" + elidedText + "</span>");
}
else
{
setPlainText(elidedText);
}
}
private:
qreal mWidth;
QString mUnelidedText;
bool mIsHighlighted;
};
class UBImgTextThumbnailElement
{
private:
UBSceneThumbnailNavigPixmap* thumbnail;
UBThumbnailTextItem* caption;
int border;
public:
UBImgTextThumbnailElement(UBSceneThumbnailNavigPixmap* thumb, UBThumbnailTextItem* text): border(0)
{
this->thumbnail = thumb;
this->caption = text;
}
UBSceneThumbnailNavigPixmap* getThumbnail() const { return this->thumbnail; }
void setThumbnail(UBSceneThumbnailNavigPixmap* newGItem) { this->thumbnail = newGItem; }
UBThumbnailTextItem* getCaption() const { return this->caption; }
void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }
void Place(int row, int col, qreal width, qreal height);
int getBorder() const { return this->border; }
void setBorder(int newBorder) { this->border = newBorder; }
};
#endif /* UBTHUMBNAILWIDGET_H_ */
#ifndef UBTHUMBNAILWIDGET_H_
#define UBTHUMBNAILWIDGET_H_
#include <QtGui>
#include <QtSvg>
#include <QTime>
#include <QGraphicsSceneHoverEvent>
#include "frameworks/UBCoreGraphicsScene.h"
#include "core/UBSettings.h"
#include "domain/UBItem.h"
#define STARTDRAGTIME 1000000
#define BUTTONSIZE 48
#define BUTTONSPACING 5
class UBDocumentProxy;
class UBThumbnailTextItem;
class UBThumbnail;
class UBThumbnailWidget : public QGraphicsView
{
Q_OBJECT;
public:
UBThumbnailWidget(QWidget* parent);
virtual ~UBThumbnailWidget();
QList<QGraphicsItem*> selectedItems();
void selectItemAt(int pIndex, bool extend = false);
void unselectItemAt(int pIndex);
qreal thumbnailWidth()
{
return mThumbnailWidth;
}
void setBackgroundBrush(const QBrush& brush)
{
mThumbnailsScene.setBackgroundBrush(brush);
}
public slots:
void setThumbnailWidth(qreal pThumbnailWidth);
void setSpacing(qreal pSpacing);
virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString(""));
void refreshScene();
void sceneSelectionChanged();
signals:
void resized();
void selectionChanged();
void mouseDoubleClick(QGraphicsItem* item, int index);
void mouseClick(QGraphicsItem* item, int index);
protected:
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void resizeEvent(QResizeEvent * event);
void mouseDoubleClickEvent(QMouseEvent * event);
virtual void keyPressEvent(QKeyEvent *event);
virtual void focusInEvent(QFocusEvent *event);
QList<QGraphicsItem*> mGraphicItems;
QList<UBThumbnailTextItem*> mLabelsItems;
QPointF mMousePressScenePos;
QPoint mMousePressPos;
protected:
qreal spacing() { return mSpacing; }
QList<QUrl> mItemsPaths;
QStringList mLabels;
bool bSelectionInProgress;
bool bCanDrag;
private:
void selectAll();
void selectItems(int startIndex, int count);
int rowCount() const;
int columnCount() const;
static bool thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2);
void deleteLasso();
UBCoreGraphicsScene mThumbnailsScene;
QString mMimeType;
QPointF prevMoveMousePos;
qreal mThumbnailWidth;
qreal mThumbnailHeight;
qreal mSpacing;
UBThumbnail *mLastSelectedThumbnail;
int mSelectionSpan;
QRectF mPrevLassoRect;
QGraphicsRectItem *mLassoRectItem;
QSet<QGraphicsItem*> mSelectedThumbnailItems;
QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsX;
QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsY;
QTime mClickTime;
};
class UBThumbnail
{
public:
UBThumbnail();
virtual ~UBThumbnail();
QStyleOptionGraphicsItem muteStyleOption(const QStyleOptionGraphicsItem *option)
{
// Never draw the rubber band, we draw our custom selection with the DelegateFrame
QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option);
styleOption.state &= ~QStyle::State_Selected;
return styleOption;
}
virtual void itemChange(QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
Q_UNUSED(value);
if ((change == QGraphicsItem::ItemSelectedHasChanged
|| change == QGraphicsItem::ItemTransformHasChanged
|| change == QGraphicsItem::ItemPositionHasChanged)
&& item->scene())
{
if (item->isSelected())
{
if (!mSelectionItem->scene())
{
item->scene()->addItem(mSelectionItem);
mSelectionItem->setZValue(item->zValue() - 1);
// UBGraphicsItem::assignZValue(mSelectionItem, item->zValue() - 1);
mAddedToScene = true;
}
mSelectionItem->setRect(
item->sceneBoundingRect().x() - 5,
item->sceneBoundingRect().y() - 5,
item->sceneBoundingRect().width() + 10,
item->sceneBoundingRect().height() + 10);
mSelectionItem->show();
}
else
{
mSelectionItem->hide();
}
}
}
int column() { return mColumn; }
void setColumn(int column) { mColumn = column; }
int row() { return mRow; }
void setRow(int row) { mRow = row; }
protected:
QGraphicsRectItem *mSelectionItem;
private:
bool mAddedToScene;
int mColumn;
int mRow;
};
class UBThumbnailSvg : public QGraphicsSvgItem, public UBThumbnail
{
public:
UBThumbnailSvg(const QString& path)
: QGraphicsSvgItem(path)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
virtual ~UBThumbnailSvg()
{
// NOOP
}
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsSvgItem::paint(painter, &styleOption, widget);
}
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
{
UBThumbnail::itemChange(this, change, value);
return QGraphicsSvgItem::itemChange(change, value);
}
};
class UBThumbnailPixmap : public QGraphicsPixmapItem, public UBThumbnail
{
public:
UBThumbnailPixmap(const QPixmap& pix)
: QGraphicsPixmapItem(pix)
{
setTransformationMode(Qt::SmoothTransformation); // UB 4.3 may be expensive -- make configurable
setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
virtual ~UBThumbnailPixmap()
{
// NOOP
}
virtual QPainterPath shape () const
{
QPainterPath path;
path.addRect(boundingRect());
return path;
}
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
QGraphicsPixmapItem::paint(painter, &styleOption, widget);
}
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
{
UBThumbnail::itemChange(this, change, value);
return QGraphicsPixmapItem::itemChange(change, value);
}
};
class UBSceneThumbnailPixmap : public UBThumbnailPixmap
{
public:
UBSceneThumbnailPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
: UBThumbnailPixmap(pix)
, mProxy(proxy)
, mSceneIndex(pSceneIndex)
{
// NOOP
}
virtual ~UBSceneThumbnailPixmap()
{
// NOOP
}
UBDocumentProxy* proxy()
{
return mProxy;
}
int sceneIndex()
{
return mSceneIndex;
}
void highlight()
{
//NOOP
}
private:
UBDocumentProxy* mProxy;
int mSceneIndex;
};
class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
{
public:
UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex);
~UBSceneThumbnailNavigPixmap();
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
void updateButtonsState();
void deletePage();
void duplicatePage();
void moveUpPage();
void moveDownPage();
bool bButtonsVisible;
bool bCanDelete;
bool bCanMoveUp;
bool bCanMoveDown;
bool bCanDuplicate;
};
class UBThumbnailVideo : public UBThumbnailPixmap
{
public:
UBThumbnailVideo(const QUrl &path)
: UBThumbnailPixmap(QPixmap(":/images/movie.svg"))
, mPath(path)
{
// NOOP
}
virtual ~UBThumbnailVideo()
{
// NOOP
}
QUrl path()
{
return mPath;
}
private:
QUrl mPath;
};
class UBThumbnailTextItem : public QGraphicsTextItem
{
public:
UBThumbnailTextItem(const QString& text)
: QGraphicsTextItem(text)
, mUnelidedText(text)
, mIsHighlighted(false)
{
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));}
void setWidth(qreal pWidth)
{
if (mWidth != pWidth)
{
prepareGeometryChange();
mWidth = pWidth;
computeText();
}
};
qreal width() {return mWidth;}
void highlight()
{
if (!mIsHighlighted)
{
mIsHighlighted = true;
computeText();
}
}
void computeText()
{
QFontMetricsF fm(font());
QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideRight, mWidth);
if (mIsHighlighted)
{
setHtml("<span style=\"color: #6682b5\">" + elidedText + "</span>");
}
else
{
setPlainText(elidedText);
}
}
private:
qreal mWidth;
QString mUnelidedText;
bool mIsHighlighted;
};
class UBImgTextThumbnailElement
{
private:
UBSceneThumbnailNavigPixmap* thumbnail;
UBThumbnailTextItem* caption;
int border;
public:
UBImgTextThumbnailElement(UBSceneThumbnailNavigPixmap* thumb, UBThumbnailTextItem* text): border(0)
{
this->thumbnail = thumb;
this->caption = text;
}
UBSceneThumbnailNavigPixmap* getThumbnail() const { return this->thumbnail; }
void setThumbnail(UBSceneThumbnailNavigPixmap* newGItem) { this->thumbnail = newGItem; }
UBThumbnailTextItem* getCaption() const { return this->caption; }
void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }
void Place(int row, int col, qreal width, qreal height);
int getBorder() const { return this->border; }
void setBorder(int newBorder) { this->border = newBorder; }
};
#endif /* UBTHUMBNAILWIDGET_H_ */

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
@ -34,39 +33,39 @@
CrashReporterSymbolSupplier::CrashReporterSymbolSupplier(QString pUniboardSymFiles) {
mUniboardSymFile.setFileName(pUniboardSymFiles);
mUniboardSymFile.setFileName(pUniboardSymFiles);
}
// Returns the path to the symbol file for the given module.
google_breakpad::SymbolSupplier::SymbolResult CrashReporterSymbolSupplier::GetSymbolFile(const google_breakpad::CodeModule *module,
const google_breakpad::SystemInfo *system_info,
string *symbol_file)
const google_breakpad::SystemInfo *system_info,
string *symbol_file)
{
QString moduleName = QString::fromStdString(module->code_file());
if (moduleName.contains("Uniboard"))
{
*symbol_file = mUniboardSymFile.fileName().toStdString();
return FOUND;
}
QString moduleName = QString::fromStdString(module->code_file());
if (moduleName.contains("Uniboard"))
{
*symbol_file = mUniboardSymFile.fileName().toStdString();
return FOUND;
}
return NOT_FOUND;
}
// Returns the path to the symbol file for the given module.
google_breakpad::SymbolSupplier::SymbolResult CrashReporterSymbolSupplier::GetSymbolFile(const google_breakpad::CodeModule *module,
const google_breakpad::SystemInfo *system_info,
string *symbol_file,
string *symbol_data)
const google_breakpad::SystemInfo *system_info,
string *symbol_file,
string *symbol_data)
{
SymbolSupplier::SymbolResult s = GetSymbolFile(module,
system_info,
symbol_file);
SymbolSupplier::SymbolResult s = GetSymbolFile(module,
system_info,
symbol_file);
if (s == FOUND) {
std::ifstream in(symbol_file->c_str());
getline(in, *symbol_data, std::string::traits_type::to_char_type(
std::string::traits_type::eof()));
in.close();
}
if (s == FOUND) {
std::ifstream in(symbol_file->c_str());
getline(in, *symbol_data, std::string::traits_type::to_char_type(
std::string::traits_type::eof()));
in.close();
}
return s;
return s;
}

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
@ -32,22 +31,22 @@ using std::string;
class CrashReporterSymbolSupplier : public google_breakpad::SymbolSupplier
{
public:
CrashReporterSymbolSupplier(QString pUniboardSymFiles);
virtual ~CrashReporterSymbolSupplier() {}
CrashReporterSymbolSupplier(QString pUniboardSymFiles);
virtual ~CrashReporterSymbolSupplier() {}
// Returns the path to the symbol file for the given module.
SymbolResult GetSymbolFile(const google_breakpad::CodeModule *module,
const google_breakpad::SystemInfo *system_info,
string *symbol_file);
// Returns the path to the symbol file for the given module.
SymbolResult GetSymbolFile(const google_breakpad::CodeModule *module,
const google_breakpad::SystemInfo *system_info,
string *symbol_file);
// Returns the path to the symbol file for the given module.
SymbolResult GetSymbolFile(const google_breakpad::CodeModule *module,
const google_breakpad::SystemInfo *system_info,
string *symbol_file,
string *symbol_data);
// Returns the path to the symbol file for the given module.
SymbolResult GetSymbolFile(const google_breakpad::CodeModule *module,
const google_breakpad::SystemInfo *system_info,
string *symbol_file,
string *symbol_data);
private:
QFile mUniboardSymFile;
QFile mUniboardSymFile;
};
#endif /* CRASHREPORTERSYMBOLSUPPLIER_H_ */

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
@ -31,14 +30,14 @@ CrashWindow::CrashWindow(QWidget* parent) : QDialog(parent)
mCrashReporterUi->setupUi(this);
mCrashReporterUi->crashReportResult->setFont(QFont("Monaco", 11));
connect(mCrashReporterUi->viewReportButton, SIGNAL(clicked(bool)), this, SLOT(showReport()));
connect(mCrashReporterUi->dumpFileButton, SIGNAL(clicked(bool)), this, SLOT(chooseDumpFile()));
connect(mCrashReporterUi->symFileButton, SIGNAL(clicked(bool)), this, SLOT(chooseSymboleFile()));
connect(mCrashReporterUi->viewReportButton, SIGNAL(clicked(bool)), this, SLOT(showReport()));
connect(mCrashReporterUi->dumpFileButton, SIGNAL(clicked(bool)), this, SLOT(chooseDumpFile()));
connect(mCrashReporterUi->symFileButton, SIGNAL(clicked(bool)), this, SLOT(chooseSymboleFile()));
}
CrashWindow::~CrashWindow()
{
// NOOP
// NOOP
}
void CrashWindow::setDumpFilePath(const QString &fileName)
@ -48,47 +47,47 @@ void CrashWindow::setDumpFilePath(const QString &fileName)
void CrashWindow::chooseDumpFile()
{
QSettings settings("Mnemis", "CrashReporter");
QString dumpFileName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
if (settings.contains("DumpFileName"))
{
dumpFileName = settings.value("DumpFileName").toString();
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
dumpFileName,
tr("Dump file (*.dmp)"));
settings.setValue("DumpFileName", QVariant(fileName));
QSettings settings("Mnemis", "CrashReporter");
QString dumpFileName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
if (settings.contains("DumpFileName"))
{
dumpFileName = settings.value("DumpFileName").toString();
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
dumpFileName,
tr("Dump file (*.dmp)"));
settings.setValue("DumpFileName", QVariant(fileName));
setDumpFilePath(fileName);
}
void CrashWindow::chooseSymboleFile()
{
QSettings settings("Mnemis", "CrashReporter");
QString symFileName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
if (settings.contains("SymFileName"))
{
symFileName = settings.value("SymFileName").toString();
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
symFileName,
tr("Symbol file (*.sym)"));
settings.setValue("SymFileName", QVariant(fileName));
mCrashReporterUi->symFilePath->setText(fileName);
QSettings settings("Mnemis", "CrashReporter");
QString symFileName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
if (settings.contains("SymFileName"))
{
symFileName = settings.value("SymFileName").toString();
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
symFileName,
tr("Symbol file (*.sym)"));
settings.setValue("SymFileName", QVariant(fileName));
mCrashReporterUi->symFilePath->setText(fileName);
}
//=============================================================================
int CrashWindow::PrintRegister(const char *name, u_int32_t value, int sequence) {
if (sequence % 4 == 0) {
mReport.append("\n");
}
if (sequence % 4 == 0) {
mReport.append("\n");
}
// string should not exceed 200 byte!!!
size_t BufSize = 2000;
char buf[BufSize];
char buf[BufSize];
snprintf(buf, BufSize, "%6s = 0x%08x ", name, value);
QString str = QString::fromAscii(buf);
mReport.append(str);
return ++sequence;
snprintf(buf, BufSize, "%6s = 0x%08x ", name, value);
QString str = QString::fromAscii(buf);
mReport.append(str);
return ++sequence;
}
//=============================================================================
@ -101,9 +100,9 @@ void CrashWindow::PrintStack(const CallStack* stack, const string &cpu) {
const CodeModule *module = frame->module;
// string should not exceed 200 byte!!!
size_t BufSize = 2000;
char buf[BufSize];
snprintf(buf, BufSize, "%2d ", frame_index);
mReport.append(QString::fromAscii(buf));
char buf[BufSize];
snprintf(buf, BufSize, "%2d ", frame_index);
mReport.append(QString::fromAscii(buf));
if (module) {
// Module name (20 chars max)
@ -229,98 +228,98 @@ void CrashWindow::PrintModules(const CodeModules *modules) {
u_int64_t base_address = module->base_address();
// string should not exceed 200 byte!!!
size_t BufSize = 2000;
char buf[BufSize];
snprintf(buf, BufSize, "0x%08llx - 0x%08llx %s %s%s %s\n",
base_address, base_address + module->size() - 1,
PathnameStripper::File(module->code_file()).c_str(),
module->version().empty() ? "???" : module->version().c_str(),
main_module != NULL && base_address == main_address ?
" (main)" : "",
module->code_file().c_str());
mReport.append(QString::fromAscii(buf));
char buf[BufSize];
snprintf(buf, BufSize, "0x%08llx - 0x%08llx %s %s%s %s\n",
base_address, base_address + module->size() - 1,
PathnameStripper::File(module->code_file()).c_str(),
module->version().empty() ? "???" : module->version().c_str(),
main_module != NULL && base_address == main_address ?
" (main)" : "",
module->code_file().c_str());
mReport.append(QString::fromAscii(buf));
}
}
void CrashWindow::showReport()
{
qDebug() << "compute report";
mReport.clear();
QString minidump_file = mCrashReporterUi->dumpFilePath->text();
BasicSourceLineResolver resolver;
scoped_ptr<CrashReporterSymbolSupplier> symbol_supplier(
new CrashReporterSymbolSupplier(mCrashReporterUi->symFilePath->text()));
scoped_ptr<MinidumpProcessor>
minidump_processor(new MinidumpProcessor(symbol_supplier.get(), &resolver));
ProcessState process_state;
if (minidump_processor->Process(minidump_file.toStdString(), &process_state) !=
MinidumpProcessor::PROCESS_OK) {
mReport += "MinidumpProcessor::Process failed\n";
return;
}
const SystemInfo *system_info = process_state.system_info();
string cpu = system_info->cpu;
// Convert the time to a string
u_int32_t time_date_stamp = process_state.time_date_stamp();
struct tm timestruct;
gmtime_r(reinterpret_cast<time_t*>(&time_date_stamp), &timestruct);
char timestr[20];
// string should not exceed 200 byte!!!
size_t BufSize = 2000;
char buf[BufSize];
strftime(timestr, 20, "%Y-%m-%d %H:%M:%S", &timestruct);
snprintf(buf, BufSize, "Date: %s GMT\n", timestr);
mReport.append(QString::fromAscii(buf));
snprintf(buf, BufSize, "Operating system: %s (%s)\n", system_info->os.c_str(),
system_info->os_version.c_str());
mReport.append(QString::fromAscii(buf));
snprintf(buf, BufSize, "Architecture: %s\n", cpu.c_str());
mReport.append(QString::fromAscii(buf));
if (process_state.crashed()) {
snprintf(buf, BufSize, "Crash reason: %s\n", process_state.crash_reason().c_str());
mReport.append(QString::fromAscii(buf));
snprintf(buf, BufSize, "Crash address: 0x%llx\n", process_state.crash_address());
mReport.append(QString::fromAscii(buf));
} else {
mReport.append("No crash\n");
}
int requesting_thread = process_state.requesting_thread();
if (requesting_thread != -1) {
mReport.append("\n");
snprintf(buf, BufSize, "Thread %d (%s)\n",
requesting_thread,
process_state.crashed() ? "crashed" :
"requested dump, did not crash");
mReport.append(QString::fromAscii(buf));
PrintStack(process_state.threads()->at(requesting_thread), cpu);
}
// Print all of the threads in the dump.
int thread_count = process_state.threads()->size();
for (int thread_index = 0; thread_index < thread_count; ++thread_index) {
if (thread_index != requesting_thread) {
// Don't print the crash thread again, it was already printed.
mReport.append("\n");
snprintf(buf, BufSize,"Thread %d\n", thread_index);
mReport.append(QString::fromAscii(buf));
PrintStack(process_state.threads()->at(thread_index), cpu);
}
}
// Print the crashed registers
if (requesting_thread != -1) {
snprintf(buf, BufSize,"\nThread %d:", requesting_thread);
mReport.append(QString::fromAscii(buf));
PrintRegisters(process_state.threads()->at(requesting_thread), cpu);
}
// Print information about modules
PrintModules(process_state.modules());
mCrashReporterUi->crashReportResult->setPlainText(mReport);
qDebug() << "compute report";
mReport.clear();
QString minidump_file = mCrashReporterUi->dumpFilePath->text();
BasicSourceLineResolver resolver;
scoped_ptr<CrashReporterSymbolSupplier> symbol_supplier(
new CrashReporterSymbolSupplier(mCrashReporterUi->symFilePath->text()));
scoped_ptr<MinidumpProcessor>
minidump_processor(new MinidumpProcessor(symbol_supplier.get(), &resolver));
ProcessState process_state;
if (minidump_processor->Process(minidump_file.toStdString(), &process_state) !=
MinidumpProcessor::PROCESS_OK) {
mReport += "MinidumpProcessor::Process failed\n";
return;
}
const SystemInfo *system_info = process_state.system_info();
string cpu = system_info->cpu;
// Convert the time to a string
u_int32_t time_date_stamp = process_state.time_date_stamp();
struct tm timestruct;
gmtime_r(reinterpret_cast<time_t*>(&time_date_stamp), &timestruct);
char timestr[20];
// string should not exceed 200 byte!!!
size_t BufSize = 2000;
char buf[BufSize];
strftime(timestr, 20, "%Y-%m-%d %H:%M:%S", &timestruct);
snprintf(buf, BufSize, "Date: %s GMT\n", timestr);
mReport.append(QString::fromAscii(buf));
snprintf(buf, BufSize, "Operating system: %s (%s)\n", system_info->os.c_str(),
system_info->os_version.c_str());
mReport.append(QString::fromAscii(buf));
snprintf(buf, BufSize, "Architecture: %s\n", cpu.c_str());
mReport.append(QString::fromAscii(buf));
if (process_state.crashed()) {
snprintf(buf, BufSize, "Crash reason: %s\n", process_state.crash_reason().c_str());
mReport.append(QString::fromAscii(buf));
snprintf(buf, BufSize, "Crash address: 0x%llx\n", process_state.crash_address());
mReport.append(QString::fromAscii(buf));
} else {
mReport.append("No crash\n");
}
int requesting_thread = process_state.requesting_thread();
if (requesting_thread != -1) {
mReport.append("\n");
snprintf(buf, BufSize, "Thread %d (%s)\n",
requesting_thread,
process_state.crashed() ? "crashed" :
"requested dump, did not crash");
mReport.append(QString::fromAscii(buf));
PrintStack(process_state.threads()->at(requesting_thread), cpu);
}
// Print all of the threads in the dump.
int thread_count = process_state.threads()->size();
for (int thread_index = 0; thread_index < thread_count; ++thread_index) {
if (thread_index != requesting_thread) {
// Don't print the crash thread again, it was already printed.
mReport.append("\n");
snprintf(buf, BufSize,"Thread %d\n", thread_index);
mReport.append(QString::fromAscii(buf));
PrintStack(process_state.threads()->at(thread_index), cpu);
}
}
// Print the crashed registers
if (requesting_thread != -1) {
snprintf(buf, BufSize,"\nThread %d:", requesting_thread);
mReport.append(QString::fromAscii(buf));
PrintRegisters(process_state.threads()->at(requesting_thread), cpu);
}
// Print information about modules
PrintModules(process_state.modules());
mCrashReporterUi->crashReportResult->setPlainText(mReport);
}

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
@ -59,23 +58,23 @@ namespace Ui
class CrashWindow : public QDialog
{
Q_OBJECT;
Q_OBJECT;
public:
CrashWindow(QWidget* parent = 0);
virtual ~CrashWindow();
CrashWindow(QWidget* parent = 0);
virtual ~CrashWindow();
void setDumpFilePath(const QString &fileName);
private slots:
void showReport();
void chooseDumpFile();
void chooseSymboleFile();
void showReport();
void chooseDumpFile();
void chooseSymboleFile();
private:
int PrintRegister(const char *name, u_int32_t value, int sequence);
void PrintStack(const CallStack* stack, const string &cpu);
void PrintRegisters(const CallStack *stack, const string &cpu);
void PrintModules(const CodeModules *modules);
int PrintRegister(const char *name, u_int32_t value, int sequence);
void PrintStack(const CallStack* stack, const string &cpu);
void PrintRegisters(const CallStack *stack, const string &cpu);
void PrintModules(const CodeModules *modules);
Ui::UniboardCrashreporter* mCrashReporterUi;
QString mReport;
};

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/

@ -3,21 +3,20 @@
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* Open-Sankoré is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License
* along with Open-Sankoré. If not, see <http://www.gnu.org/licenses/>.
*/
@ -79,7 +78,7 @@ int main(int argc, char *argv[])
return 1;
}
//qDebug() << "Converting" << pdfFile << "(" << pageNumber << ") into" << imageFormat;
//qDebug() << "Converting" << pdfFile << "(" << pageNumber << ") into" << imageFormat;
QImage image(width, height, QImage::Format_ARGB32);

Loading…
Cancel
Save