Anatoly Mihalchenko 13 years ago
parent 9fcd791c39
commit bff3e8343d
  1. 4304
      src/board/UBBoardController.cpp
  2. 574
      src/board/UBBoardController.h
  3. 15
      src/core/UBApplication.cpp
  4. 324
      src/core/UBApplication.h
  5. 588
      src/core/UBDocumentManager.cpp
  6. 247
      src/domain/UBGraphicsItemUndoCommand.cpp
  7. 4018
      src/domain/UBGraphicsScene.cpp
  8. 759
      src/domain/UBGraphicsScene.h

File diff suppressed because it is too large Load Diff

@ -1,285 +1,289 @@
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBBOARDCONTROLLER_H_ #ifndef UBBOARDCONTROLLER_H_
#define UBBOARDCONTROLLER_H_ #define UBBOARDCONTROLLER_H_
#include <QtGui> #include <QtGui>
#include <QObject> #include <QObject>
class UBMainWindow; class UBMainWindow;
class UBApplication; class UBApplication;
class UBBoardView; class UBBoardView;
class UBDocumentController; class UBDocumentController;
class UBMessageWindow; class UBMessageWindow;
class UBGraphicsScene; class UBGraphicsScene;
class UBDocumentProxy; class UBDocumentProxy;
class UBBlackoutWidget; class UBBlackoutWidget;
class UBToolWidget; class UBToolWidget;
class UBVersion; class UBVersion;
class UBSoftwareUpdate; class UBSoftwareUpdate;
class UBSoftwareUpdateDialog; class UBSoftwareUpdateDialog;
class UBGraphicsVideoItem; class UBGraphicsVideoItem;
class UBGraphicsAudioItem; class UBGraphicsAudioItem;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class UBBoardPaletteManager; class UBBoardPaletteManager;
class UBBoardController : public QObject class UBBoardController : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
UBBoardController(UBMainWindow *mainWindow); UBBoardController(UBMainWindow *mainWindow);
virtual ~UBBoardController(); virtual ~UBBoardController();
void init(); void init();
void setupLayout(); void setupLayout();
UBDocumentProxy* activeDocument() const; UBDocumentProxy* activeDocument() const;
UBGraphicsScene* activeScene() const; UBGraphicsScene* activeScene() const;
int activeSceneIndex() const; int activeSceneIndex() const;
QSize displayViewport(); QSize displayViewport();
QSize controlViewport(); QSize controlViewport();
QRectF controlGeometry(); QRectF controlGeometry();
void closing(); void closing();
UBDocumentProxy* activeDocument() UBDocumentProxy* activeDocument()
{ {
return mActiveDocument; return mActiveDocument;
} }
QWidget* controlContainer() QWidget* controlContainer()
{ {
return mControlContainer; return mControlContainer;
} }
UBBoardView* controlView() UBBoardView* controlView()
{ {
return mControlView; return mControlView;
} }
UBBoardView* displayView() UBBoardView* displayView()
{ {
return mDisplayView; return mDisplayView;
} }
UBGraphicsScene* activeScene() UBGraphicsScene* activeScene()
{ {
return mActiveScene; return mActiveScene;
} }
void setPenColorOnDarkBackground(const QColor& pColor) void setPenColorOnDarkBackground(const QColor& pColor)
{ {
if (mPenColorOnDarkBackground == pColor) if (mPenColorOnDarkBackground == pColor)
return; return;
mPenColorOnDarkBackground = pColor; mPenColorOnDarkBackground = pColor;
emit penColorChanged(); emit penColorChanged();
} }
void setPenColorOnLightBackground(const QColor& pColor) void setPenColorOnLightBackground(const QColor& pColor)
{ {
if (mPenColorOnLightBackground == pColor) if (mPenColorOnLightBackground == pColor)
return; return;
mPenColorOnLightBackground = pColor; mPenColorOnLightBackground = pColor;
emit penColorChanged(); emit penColorChanged();
} }
void setMarkerColorOnDarkBackground(const QColor& pColor) void setMarkerColorOnDarkBackground(const QColor& pColor)
{ {
mMarkerColorOnDarkBackground = pColor; mMarkerColorOnDarkBackground = pColor;
} }
void setMarkerColorOnLightBackground(const QColor& pColor) void setMarkerColorOnLightBackground(const QColor& pColor)
{ {
mMarkerColorOnLightBackground = pColor; mMarkerColorOnLightBackground = pColor;
} }
QColor penColorOnDarkBackground() QColor penColorOnDarkBackground()
{ {
return mPenColorOnDarkBackground; return mPenColorOnDarkBackground;
} }
QColor penColorOnLightBackground() QColor penColorOnLightBackground()
{ {
return mPenColorOnLightBackground; return mPenColorOnLightBackground;
} }
QColor markerColorOnDarkBackground() QColor markerColorOnDarkBackground()
{ {
return mMarkerColorOnDarkBackground; return mMarkerColorOnDarkBackground;
} }
QColor markerColorOnLightBackground() QColor markerColorOnLightBackground()
{ {
return mMarkerColorOnLightBackground; return mMarkerColorOnLightBackground;
} }
qreal systemScaleFactor() qreal systemScaleFactor()
{ {
return mSystemScaleFactor; return mSystemScaleFactor;
} }
qreal currentZoom(); qreal currentZoom();
void persistCurrentScene(); void persistCurrentScene();
void showNewVersionAvailable(bool automatic, const UBVersion &installedVersion, const UBSoftwareUpdate &softwareUpdate); void showNewVersionAvailable(bool automatic, const UBVersion &installedVersion, const UBSoftwareUpdate &softwareUpdate);
void setBoxing(QRect displayRect); void setBoxing(QRect displayRect);
void setToolbarTexts(); void setToolbarTexts();
static QUrl expandWidgetToTempDir(const QByteArray& pZipedData, const QString& pExtension = QString("wgt")); static QUrl expandWidgetToTempDir(const QByteArray& pZipedData, const QString& pExtension = QString("wgt"));
// static QRect freeRectInGlobalPos() const {return ;} // static QRect freeRectInGlobalPos() const {return ;}
void setPageSize(QSize newSize); void setPageSize(QSize newSize);
UBBoardPaletteManager *paletteManager() UBBoardPaletteManager *paletteManager()
{ {
return mPaletteManager; return mPaletteManager;
} }
void notifyCache(bool visible); void notifyCache(bool visible);
void notifyPageChanged(); void notifyPageChanged();
void displayMetaData(QMap<QString, QString> metadatas); void displayMetaData(QMap<QString, QString> metadatas);
void ClearUndoStack(); void ClearUndoStack();
public slots:
public slots: void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0);
void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0); void showDocumentsDialog();
void showDocumentsDialog(); void showKeyboard(bool show);
void showKeyboard(bool show); void togglePodcast(bool checked);
void togglePodcast(bool checked); void blackout();
void blackout(); void addScene();
void addScene(); void addScene(UBDocumentProxy* proxy, int sceneIndex, bool replaceActiveIfEmpty = false);
void addScene(UBDocumentProxy* proxy, int sceneIndex, bool replaceActiveIfEmpty = false); void addScene(UBGraphicsScene* scene, bool replaceActiveIfEmpty = false);
void addScene(UBGraphicsScene* scene, bool replaceActiveIfEmpty = false); void duplicateScene();
void duplicateScene(); void importPage();
void importPage(); void clearScene();
void clearScene(); void clearSceneItems();
void clearSceneItems(); void clearSceneAnnotation();
void clearSceneAnnotation(); void zoomIn(QPointF scenePoint = QPointF(0,0));
void zoomIn(QPointF scenePoint = QPointF(0,0)); void zoomOut(QPointF scenePoint = QPointF(0,0));
void zoomOut(QPointF scenePoint = QPointF(0,0)); void zoomRestore();
void zoomRestore(); void centerRestore();
void centerRestore(); void centerOn(QPointF scenePoint = QPointF(0,0));
void centerOn(QPointF scenePoint = QPointF(0,0)); void zoom(const qreal ratio, QPointF scenePoint);
void zoom(const qreal ratio, QPointF scenePoint); void handScroll(qreal dx, qreal dy);
void handScroll(qreal dx, qreal dy); void previousScene();
void previousScene(); void nextScene();
void nextScene(); void firstScene();
void firstScene(); void lastScene();
void lastScene(); void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false);
void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false); void downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false);
void downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false); void changeBackground(bool isDark, bool isCrossed);
void changeBackground(bool isDark, bool isCrossed); void setToolCursor(int tool);
void setToolCursor(int tool); void showMessage(const QString& message, bool showSpinningWheel);
void showMessage(const QString& message, bool showSpinningWheel); void hideMessage();
void hideMessage(); void setDisabled(bool disable);
void setDisabled(bool disable); void setColorIndex(int pColorIndex);
void setColorIndex(int pColorIndex); UBToolWidget* addTool(const QUrl& toolUrl, QPointF scenePos);
UBToolWidget* addTool(const QUrl& toolUrl, QPointF scenePos); UBToolWidget* addTool(const QUrl& toolUrl);
UBToolWidget* addTool(const QUrl& toolUrl); void removeTool(UBToolWidget* toolWidget);
void removeTool(UBToolWidget* toolWidget); void hide();
void hide(); void show();
void show(); void setWidePageSize(bool checked);
void setWidePageSize(bool checked); void setRegularPageSize(bool checked);
void setRegularPageSize(bool checked); void stylusToolChanged(int tool);
void stylusToolChanged(int tool); void grabScene(const QRectF& pSceneRect);
void grabScene(const QRectF& pSceneRect); void controlViewHidden();
void controlViewHidden(); void controlViewShown();
void controlViewShown(); UBGraphicsVideoItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos);
UBGraphicsVideoItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsAudioItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos);
UBGraphicsAudioItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos);
UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos);
void cut();
void cut(); void copy();
void copy(); void paste();
void paste(); void processMimeData(const QMimeData* pMimeData, const QPointF& pPos);
void processMimeData(const QMimeData* pMimeData, const QPointF& pPos); void moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicWidget);
void moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicWidget); void moveToolWidgetToScene(UBToolWidget* toolWidget);
void moveToolWidgetToScene(UBToolWidget* toolWidget); void addItem();
void addItem();
void freezeW3CWidgets(bool freeze);
signals: void freezeW3CWidget(QGraphicsItem* item, bool freeze);
void activeSceneWillBePersisted(); void startScript();
void activeSceneWillChange(); void stopScript();
void activeSceneChanged();
void activeDocumentChanged(); signals:
void zoomChanged(qreal pZoomFactor); void activeSceneWillBePersisted();
void systemScaleFactorChanged(qreal pSystemScaleFactor); void activeSceneWillChange();
void penColorChanged(); void activeSceneChanged();
void controlViewportChanged(); void activeDocumentChanged();
void backgroundChanged(); void zoomChanged(qreal pZoomFactor);
void cacheEnabled(); void systemScaleFactorChanged(qreal pSystemScaleFactor);
void cacheDisabled(); void penColorChanged();
void pageChanged(); void controlViewportChanged();
void setDocOnPageNavigator(UBDocumentProxy* doc); void backgroundChanged();
void documentReorganized(int index); void cacheEnabled();
void displayMetadata(QMap<QString, QString> metadata); void cacheDisabled();
void pageChanged();
protected: void setDocOnPageNavigator(UBDocumentProxy* doc);
void setupViews(); void documentReorganized(int index);
void setupToolbar(); void displayMetadata(QMap<QString, QString> metadata);
void connectToolbar();
void initToolbarTexts(); protected:
void updateActionStates(); void setupViews();
void updateSystemScaleFactor(); void setupToolbar();
QString truncate(QString text, int maxWidth); void connectToolbar();
void initToolbarTexts();
protected slots: void updateActionStates();
void selectionChanged(); void updateSystemScaleFactor();
void undoRedoStateChange(bool canUndo); QString truncate(QString text, int maxWidth);
void documentSceneChanged(UBDocumentProxy* proxy, int pIndex);
protected slots:
private: void selectionChanged();
void updatePageSizeState(); void undoRedoStateChange(bool canUndo);
void saveViewState(); void documentSceneChanged(UBDocumentProxy* proxy, int pIndex);
void adjustDisplayViews();
private:
UBMainWindow *mMainWindow; void updatePageSizeState();
UBDocumentProxy* mActiveDocument; void saveViewState();
UBGraphicsScene* mActiveScene; void adjustDisplayViews();
int mActiveSceneIndex;
UBBoardPaletteManager *mPaletteManager; UBMainWindow *mMainWindow;
UBSoftwareUpdateDialog *mSoftwareUpdateDialog; UBDocumentProxy* mActiveDocument;
UBMessageWindow *mMessageWindow; UBGraphicsScene* mActiveScene;
UBBoardView *mControlView; int mActiveSceneIndex;
UBBoardView *mDisplayView; UBBoardPaletteManager *mPaletteManager;
QWidget *mControlContainer; UBSoftwareUpdateDialog *mSoftwareUpdateDialog;
QHBoxLayout *mControlLayout; UBMessageWindow *mMessageWindow;
qreal mZoomFactor; UBBoardView *mControlView;
bool mIsClosing; UBBoardView *mDisplayView;
QColor mPenColorOnDarkBackground; QWidget *mControlContainer;
QColor mPenColorOnLightBackground; QHBoxLayout *mControlLayout;
QColor mMarkerColorOnDarkBackground; qreal mZoomFactor;
QColor mMarkerColorOnLightBackground; bool mIsClosing;
QList<UBToolWidget*> mTools; QColor mPenColorOnDarkBackground;
qreal mSystemScaleFactor; QColor mPenColorOnLightBackground;
bool mCleanupDone; QColor mMarkerColorOnDarkBackground;
QMap<QAction*, QPair<QString, QString> > mActionTexts; QColor mMarkerColorOnLightBackground;
QList<UBToolWidget*> mTools;
private slots: qreal mSystemScaleFactor;
void stylusToolDoubleClicked(int tool); bool mCleanupDone;
void boardViewResized(QResizeEvent* event); QMap<QAction*, QPair<QString, QString> > mActionTexts;
void documentWillBeDeleted(UBDocumentProxy* pProxy);
void updateBackgroundActionsState(bool isDark, bool isCrossed); private slots:
void updateBackgroundState(); void stylusToolDoubleClicked(int tool);
void colorPaletteChanged(); void boardViewResized(QResizeEvent* event);
void libraryDialogClosed(int ret); void documentWillBeDeleted(UBDocumentProxy* pProxy);
void lastWindowClosed(); void updateBackgroundActionsState(bool isDark, bool isCrossed);
void onDownloadModalFinished(); void updateBackgroundState();
void colorPaletteChanged();
}; void libraryDialogClosed(int ret);
void lastWindowClosed();
void onDownloadModalFinished();
#endif /* UBBOARDCONTROLLER_H_ */
};
#endif /* UBBOARDCONTROLLER_H_ */

@ -237,8 +237,11 @@ int UBApplication::exec(const QString& pFileToImport)
mainWindow->actionCut->setShortcuts(QKeySequence::Cut); mainWindow->actionCut->setShortcuts(QKeySequence::Cut);
connect(mainWindow->actionBoard, SIGNAL(triggered()), this, SLOT(showBoard())); connect(mainWindow->actionBoard, SIGNAL(triggered()), this, SLOT(showBoard()));
connect(mainWindow->actionBoard, SIGNAL(triggered()), this, SLOT(startScript()));
connect(mainWindow->actionWeb, SIGNAL(triggered()), this, SLOT(showInternet())); connect(mainWindow->actionWeb, SIGNAL(triggered()), this, SLOT(showInternet()));
connect(mainWindow->actionWeb, SIGNAL(triggered()), this, SLOT(stopScript()));
connect(mainWindow->actionDocument, SIGNAL(triggered()), this, SLOT(showDocument())); connect(mainWindow->actionDocument, SIGNAL(triggered()), this, SLOT(showDocument()));
connect(mainWindow->actionDocument, SIGNAL(triggered()), this, SLOT(stopScript()));
connect(mainWindow->actionQuit, SIGNAL(triggered()), this, SLOT(closing())); connect(mainWindow->actionQuit, SIGNAL(triggered()), this, SLOT(closing()));
connect(mainWindow, SIGNAL(closeEvent_Signal(QCloseEvent*)), this, SLOT(closeEvent(QCloseEvent*))); connect(mainWindow, SIGNAL(closeEvent_Signal(QCloseEvent*)), this, SLOT(closeEvent(QCloseEvent*)));
@ -262,6 +265,7 @@ int UBApplication::exec(const QString& pFileToImport)
connect(mainWindow->actionDesktop, SIGNAL(triggered(bool)), applicationController, SLOT(showDesktop(bool))); connect(mainWindow->actionDesktop, SIGNAL(triggered(bool)), applicationController, SLOT(showDesktop(bool)));
connect(mainWindow->actionDesktop, SIGNAL(triggered(bool)), this, SLOT(stopScript()));
#ifndef Q_WS_MAC #ifndef Q_WS_MAC
connect(mainWindow->actionHideApplication, SIGNAL(triggered()), mainWindow, SLOT(showMinimized())); connect(mainWindow->actionHideApplication, SIGNAL(triggered()), mainWindow, SLOT(showMinimized()));
#else #else
@ -274,6 +278,7 @@ int UBApplication::exec(const QString& pFileToImport)
connect(mainWindow->actionPreferences, SIGNAL(triggered()), mPreferencesController, SLOT(show())); connect(mainWindow->actionPreferences, SIGNAL(triggered()), mPreferencesController, SLOT(show()));
connect(mainWindow->actionTutorial, SIGNAL(triggered()), applicationController, SLOT(showTutorial())); connect(mainWindow->actionTutorial, SIGNAL(triggered()), applicationController, SLOT(showTutorial()));
connect(mainWindow->actionTutorial, SIGNAL(triggered()), this, SLOT(stopScript()));
connect(mainWindow->actionSankoreEditor, SIGNAL(triggered()), applicationController, SLOT(showSankoreEditor())); connect(mainWindow->actionSankoreEditor, SIGNAL(triggered()), applicationController, SLOT(showSankoreEditor()));
connect(mainWindow->actionCheckUpdate, SIGNAL(triggered()), applicationController, SLOT(checkUpdateRequest())); connect(mainWindow->actionCheckUpdate, SIGNAL(triggered()), applicationController, SLOT(checkUpdateRequest()));
@ -353,6 +358,16 @@ void UBApplication::showMinimized()
#endif #endif
void UBApplication::startScript()
{
this->boardController->freezeW3CWidgets(false);
}
void UBApplication::stopScript()
{
this->boardController->freezeW3CWidgets(true);
}
void UBApplication::showBoard() void UBApplication::showBoard()
{ {
applicationController->showBoard(); applicationController->showBoard();

@ -1,161 +1,163 @@
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBAPPLICATION_H_ #ifndef UBAPPLICATION_H_
#define UBAPPLICATION_H_ #define UBAPPLICATION_H_
#include <QtGui> #include <QtGui>
#include "qtsingleapplication.h" #include "qtsingleapplication.h"
#include "transition/UniboardSankoreTransition.h" #include "transition/UniboardSankoreTransition.h"
namespace Ui namespace Ui
{ {
class MainWindow; class MainWindow;
} }
class UBBoardController; class UBBoardController;
class UBWebController; class UBWebController;
class UBControlView; class UBControlView;
class UBPreferencesController; class UBPreferencesController;
class UBResources; class UBResources;
class UBSettings; class UBSettings;
class UBPersistenceManager; class UBPersistenceManager;
class UBApplicationController; class UBApplicationController;
class UBDocumentController; class UBDocumentController;
class UBSoftwareUpdateController; class UBSoftwareUpdateController;
class UBMainWindow; class UBMainWindow;
class UBApplication : public QtSingleApplication class UBApplication : public QtSingleApplication
{ {
Q_OBJECT; Q_OBJECT;
public: public:
UBApplication(const QString &id, int &argc, char **argv); UBApplication(const QString &id, int &argc, char **argv);
virtual ~UBApplication(); virtual ~UBApplication();
int exec(const QString& pFileToImport); int exec(const QString& pFileToImport);
void cleanup(); void cleanup();
static QPointer<QUndoStack> undoStack; static QPointer<QUndoStack> undoStack;
static UBApplicationController *applicationController; static UBApplicationController *applicationController;
static UBBoardController* boardController; static UBBoardController* boardController;
static UBWebController* webController; static UBWebController* webController;
static UBDocumentController* documentController; static UBDocumentController* documentController;
static UBSoftwareUpdateController* softwareUpdateController; static UBSoftwareUpdateController* softwareUpdateController;
static UniboardSankoreTransition* mUniboardSankoreTransition; static UniboardSankoreTransition* mUniboardSankoreTransition;
static UBMainWindow* mainWindow; static UBMainWindow* mainWindow;
static UBApplication* app() static UBApplication* app()
{ {
return static_cast<UBApplication*>qApp; return static_cast<UBApplication*>qApp;
} }
static const QString mimeTypeUniboardDocument; static const QString mimeTypeUniboardDocument;
static const QString mimeTypeUniboardPage; static const QString mimeTypeUniboardPage;
static const QString mimeTypeUniboardPageItem; static const QString mimeTypeUniboardPageItem;
static const QString mimeTypeUniboardPageThumbnail; static const QString mimeTypeUniboardPageThumbnail;
static void showMessage(const QString& message, bool showSpinningWheel = false); static void showMessage(const QString& message, bool showSpinningWheel = false);
static void setDisabled(bool disable); static void setDisabled(bool disable);
static QObject* staticMemoryCleaner; static QObject* staticMemoryCleaner;
static QString globalStyleSheet(); static QString globalStyleSheet();
void decorateActionMenu(QAction* action); void decorateActionMenu(QAction* action);
void insertSpaceToToolbarBeforeAction(QToolBar* toolbar, QAction* action, int width = -1); void insertSpaceToToolbarBeforeAction(QToolBar* toolbar, QAction* action, int width = -1);
int toolBarHeight(); int toolBarHeight();
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);
bool isVerbose() { return mIsVerbose;} bool isVerbose() { return mIsVerbose;}
void setVerbose(bool verbose){mIsVerbose = verbose;} void setVerbose(bool verbose){mIsVerbose = verbose;}
static QString urlFromHtml(QString html); static QString urlFromHtml(QString html);
static bool isFromWeb(QString url); static bool isFromWeb(QString url);
signals: signals:
public slots: public slots:
void showBoard(); void showBoard();
void showInternet(); void showInternet();
void showDocument(); void showDocument();
void startScript();
void toolBarPositionChanged(QVariant topOrBottom); void stopScript();
void toolBarDisplayTextChanged(QVariant display);
void toolBarPositionChanged(QVariant topOrBottom);
void closeEvent(QCloseEvent *event); 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. /**
*/ * Used on Windows platform to open file in running application. On MacOS X opening file is done through the
bool handleOpenMessage(const QString& pMessage); * FileOpen event that is handle in eventFilter method.
*/
private slots: bool handleOpenMessage(const QString& pMessage);
void closing(); private slots:
#ifdef Q_WS_MAC
void showMinimized(); void closing();
#endif #ifdef Q_WS_MAC
void importUniboardFiles(); void showMinimized();
private: #endif
void importUniboardFiles();
void updateProtoActionsState(); private:
QList<QMenu*> mProtoMenus;
bool mIsVerbose; void updateProtoActionsState();
QList<QMenu*> mProtoMenus;
protected: bool mIsVerbose;
#if defined(Q_WS_MACX) && !defined(QT_MAC_USE_COCOA) protected:
bool macEventFilter(EventHandlerCallRef caller, EventRef event);
#endif #if defined(Q_WS_MACX) && !defined(QT_MAC_USE_COCOA)
bool macEventFilter(EventHandlerCallRef caller, EventRef event);
UBPreferencesController* mPreferencesController; #endif
}; UBPreferencesController* mPreferencesController;
};
class UBStyle : public QPlastiqueStyle
{
public: class UBStyle : public QPlastiqueStyle
{
UBStyle() public:
: QPlastiqueStyle()
{ UBStyle()
// NOOP : QPlastiqueStyle()
} {
// NOOP
virtual ~UBStyle() }
{
// 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, * redefined to be more cocoa like on texts
bool enabled, const QString& text, QPalette::ColorRole textRole) const; */
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_ */ };
#endif /* UBAPPLICATION_H_ */

@ -1,294 +1,294 @@
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBDocumentManager.h" #include "UBDocumentManager.h"
#include "frameworks/UBStringUtils.h" #include "frameworks/UBStringUtils.h"
#include "adaptors/UBExportFullPDF.h" #include "adaptors/UBExportFullPDF.h"
#include "adaptors/UBExportDocument.h" #include "adaptors/UBExportDocument.h"
#include "adaptors/UBExportWeb.h" #include "adaptors/UBExportWeb.h"
#include "adaptors/UBWebPublisher.h" #include "adaptors/UBWebPublisher.h"
#include "adaptors/UBImportDocument.h" #include "adaptors/UBImportDocument.h"
#include "adaptors/UBImportPDF.h" #include "adaptors/UBImportPDF.h"
#include "adaptors/UBImportImage.h" #include "adaptors/UBImportImage.h"
#include "adaptors/UBImportCFF.h" #include "adaptors/UBImportCFF.h"
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsPixmapItem.h" #include "domain/UBGraphicsPixmapItem.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "UBApplication.h" #include "UBApplication.h"
#include "UBSettings.h" #include "UBSettings.h"
#include "UBPersistenceManager.h" #include "UBPersistenceManager.h"
#include "../adaptors/UBExportWeb.h" #include "../adaptors/UBExportWeb.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBDocumentManager* UBDocumentManager::sDocumentManager = 0; UBDocumentManager* UBDocumentManager::sDocumentManager = 0;
UBDocumentManager* UBDocumentManager::documentManager() UBDocumentManager* UBDocumentManager::documentManager()
{ {
if (!sDocumentManager) if (!sDocumentManager)
{ {
sDocumentManager = new UBDocumentManager(qApp); sDocumentManager = new UBDocumentManager(qApp);
} }
return sDocumentManager; return sDocumentManager;
} }
UBDocumentManager::UBDocumentManager(QObject *parent) UBDocumentManager::UBDocumentManager(QObject *parent)
:QObject(parent) :QObject(parent)
{ {
// TODO UB 4.7 string used in document persistence (folder names) // TODO UB 4.7 string used in document persistence (folder names)
QString dummyImages = tr("images"); QString dummyImages = tr("images");
QString dummyVideos = tr("videos"); QString dummyVideos = tr("videos");
QString dummyObjects = tr("objects"); QString dummyObjects = tr("objects");
QString dummyWidgets = tr("widgets"); QString dummyWidgets = tr("widgets");
UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this); UBExportFullPDF* exportFullPdf = new UBExportFullPDF(this);
mExportAdaptors.append(exportFullPdf); mExportAdaptors.append(exportFullPdf);
UBExportDocument* exportDocument = new UBExportDocument(this); UBExportDocument* exportDocument = new UBExportDocument(this);
mExportAdaptors.append(exportDocument); mExportAdaptors.append(exportDocument);
// UBExportWeb* exportWeb = new UBExportWeb(this); // UBExportWeb* exportWeb = new UBExportWeb(this);
// mExportAdaptors.append(exportWeb); // mExportAdaptors.append(exportWeb);
UBWebPublisher* webPublished = new UBWebPublisher(this); UBWebPublisher* webPublished = new UBWebPublisher(this);
mExportAdaptors.append(webPublished); mExportAdaptors.append(webPublished);
UBImportDocument* documentImport = new UBImportDocument(this); UBImportDocument* documentImport = new UBImportDocument(this);
mImportAdaptors.append(documentImport); mImportAdaptors.append(documentImport);
UBImportPDF* pdfImport = new UBImportPDF(this); UBImportPDF* pdfImport = new UBImportPDF(this);
mImportAdaptors.append(pdfImport); mImportAdaptors.append(pdfImport);
UBImportImage* imageImport = new UBImportImage(this); UBImportImage* imageImport = new UBImportImage(this);
mImportAdaptors.append(imageImport); mImportAdaptors.append(imageImport);
UBImportCFF* cffImport = new UBImportCFF(this); UBImportCFF* cffImport = new UBImportCFF(this);
mImportAdaptors.append(cffImport); mImportAdaptors.append(cffImport);
} }
UBDocumentManager::~UBDocumentManager() UBDocumentManager::~UBDocumentManager()
{ {
// NOOP // NOOP
} }
QStringList UBDocumentManager::importFileExtensions() QStringList UBDocumentManager::importFileExtensions()
{ {
QStringList result; QStringList result;
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors) foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{ {
result << importAdaptor->supportedExtentions(); result << importAdaptor->supportedExtentions();
} }
return result; return result;
} }
QString UBDocumentManager::importFileFilter() QString UBDocumentManager::importFileFilter()
{ {
QString result; QString result;
result += tr("All supported files (*.%1)").arg(importFileExtensions().join(" *.")); result += tr("All supported files (*.%1)").arg(importFileExtensions().join(" *."));
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors) foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{ {
if (importAdaptor->importFileFilter().length() > 0) if (importAdaptor->importFileFilter().length() > 0)
{ {
if (result.length()) if (result.length())
{ {
result += ";;"; result += ";;";
} }
result += importAdaptor->importFileFilter(); result += importAdaptor->importFileFilter();
} }
} }
qDebug() << "import file filter" << result; qDebug() << "import file filter" << result;
return result; return result;
} }
UBDocumentProxy* UBDocumentManager::importFile(const QFile& pFile, const QString& pGroup) UBDocumentProxy* UBDocumentManager::importFile(const QFile& pFile, const QString& pGroup)
{ {
QFileInfo fileInfo(pFile); QFileInfo fileInfo(pFile);
UBDocumentProxy* document = 0; UBDocumentProxy* document = 0;
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors) foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{ {
if (importAdaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) if (importAdaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1)
{ {
UBApplication::setDisabled(true); UBApplication::setDisabled(true);
document = importAdaptor->importFile(pFile, pGroup); document = importAdaptor->importFile(pFile, pGroup);
UBApplication::setDisabled(false); UBApplication::setDisabled(false);
} }
} }
return document; return document;
} }
bool UBDocumentManager::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) bool UBDocumentManager::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile)
{ {
QFileInfo fileInfo(pFile); QFileInfo fileInfo(pFile);
foreach (UBImportAdaptor *importAdaptor, mImportAdaptors) foreach (UBImportAdaptor *importAdaptor, mImportAdaptors)
{ {
if (importAdaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1) if (importAdaptor->supportedExtentions().lastIndexOf(fileInfo.suffix().toLower()) != -1)
{ {
UBApplication::setDisabled(true); UBApplication::setDisabled(true);
bool result = importAdaptor->addFileToDocument(pDocument, pFile); bool result = importAdaptor->addFileToDocument(pDocument, pFile);
UBApplication::setDisabled(false); UBApplication::setDisabled(false);
return result; return result;
} }
} }
return false; return false;
} }
int UBDocumentManager::addImageDirToDocument(const QDir& pDir, UBDocumentProxy* pDocument) int UBDocumentManager::addImageDirToDocument(const QDir& pDir, UBDocumentProxy* pDocument)
{ {
QStringList filenames = pDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringList filenames = pDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
filenames = UBStringUtils::sortByLastDigit(filenames); filenames = UBStringUtils::sortByLastDigit(filenames);
QStringList fullPathFilenames; QStringList fullPathFilenames;
foreach(QString f, filenames) foreach(QString f, filenames)
{ {
fullPathFilenames << pDir.absolutePath() + "/" + f; fullPathFilenames << pDir.absolutePath() + "/" + f;
} }
return addImageAsPageToDocument(fullPathFilenames, pDocument); return addImageAsPageToDocument(fullPathFilenames, pDocument);
} }
UBDocumentProxy* UBDocumentManager::importDir(const QDir& pDir, const QString& pGroup) UBDocumentProxy* UBDocumentManager::importDir(const QDir& pDir, const QString& pGroup)
{ {
UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument(pGroup, pDir.dirName()); UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument(pGroup, pDir.dirName());
int result = addImageDirToDocument(pDir, doc); int result = addImageDirToDocument(pDir, doc);
if (result > 0) if (result > 0)
{ {
doc->setMetaData(UBSettings::documentGroupName, pGroup); doc->setMetaData(UBSettings::documentGroupName, pGroup);
doc->setMetaData(UBSettings::documentName, pDir.dirName()); doc->setMetaData(UBSettings::documentName, pDir.dirName());
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(doc); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(doc);
UBApplication::showMessage(tr("File %1 saved").arg(pDir.dirName())); UBApplication::showMessage(tr("File %1 saved").arg(pDir.dirName()));
} }
else else
{ {
UBPersistenceManager::persistenceManager()->deleteDocument(doc); UBPersistenceManager::persistenceManager()->deleteDocument(doc);
} }
return doc; return doc;
} }
QList<UBExportAdaptor*> UBDocumentManager::supportedExportAdaptors() QList<UBExportAdaptor*> UBDocumentManager::supportedExportAdaptors()
{ {
return mExportAdaptors; return mExportAdaptors;
} }
int UBDocumentManager::addImageAsPageToDocument(const QStringList& filenames, UBDocumentProxy* pDocument) int UBDocumentManager::addImageAsPageToDocument(const QStringList& filenames, UBDocumentProxy* pDocument)
{ {
int result = 0; int result = 0;
if (filenames.size() > 0) if (filenames.size() > 0)
{ {
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QApplication::processEvents(); QApplication::processEvents();
int pageIndex = pDocument->pageCount(); int pageIndex = pDocument->pageCount();
if (pageIndex == 1 && UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, 0)->isEmpty()) if (pageIndex == 1 && UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, 0)->isEmpty())
{ {
pageIndex = 0; pageIndex = 0;
} }
int expectedPageCount = filenames.size(); int expectedPageCount = filenames.size();
for(int i = 0; i < filenames.size(); i ++) for(int i = 0; i < filenames.size(); i ++)
{ {
UBApplication::showMessage(tr("Importing page %1 of %2").arg(i + 1).arg(expectedPageCount)); UBApplication::showMessage(tr("Importing page %1 of %2").arg(i + 1).arg(expectedPageCount));
UBGraphicsScene* scene = 0; UBGraphicsScene* scene = 0;
QString fullPath = filenames.at(i); QString fullPath = filenames.at(i);
QGraphicsItem *gi = 0; QGraphicsItem *gi = 0;
if (pageIndex == 0) if (pageIndex == 0)
{ {
scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, pageIndex); scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocument, pageIndex);
} }
else else
{ {
scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(pDocument, pageIndex); scene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(pDocument, pageIndex);
} }
scene->setBackground(false, false); scene->setBackground(false, false);
if (fullPath.endsWith(".svg") || fullPath.endsWith(".svgz")) if (fullPath.endsWith(".svg") || fullPath.endsWith(".svgz"))
{ {
gi = scene->addSvg(QUrl::fromLocalFile(fullPath), QPointF(0, 0)); gi = scene->addSvg(QUrl::fromLocalFile(fullPath), QPointF(0, 0));
} }
else else
{ {
QPixmap pix(fullPath); QPixmap pix(fullPath);
if (pix.isNull()) if (pix.isNull())
{ {
UBApplication::showMessage(tr("Erronous image data, skipping file %1").arg(filenames.at(i))); UBApplication::showMessage(tr("Erronous image data, skipping file %1").arg(filenames.at(i)));
expectedPageCount--; expectedPageCount--;
continue; continue;
} }
else else
{ {
gi = scene->addPixmap(pix, QPointF(0, 0)); gi = scene->addPixmap(pix, QPointF(0, 0));
} }
} }
if (gi) if (gi)
{ {
scene->setAsBackgroundObject(gi, true); scene->setAsBackgroundObject(gi, true);
UBPersistenceManager::persistenceManager()->persistDocumentScene(pDocument, scene, pageIndex); UBPersistenceManager::persistenceManager()->persistDocumentScene(pDocument, scene, pageIndex);
pageIndex++; pageIndex++;
} }
} }
result = expectedPageCount; result = expectedPageCount;
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
return result; return result;
} }
void UBDocumentManager::emitDocumentUpdated(UBDocumentProxy* pDocument) void UBDocumentManager::emitDocumentUpdated(UBDocumentProxy* pDocument)
{ {
emit documentUpdated(pDocument); emit documentUpdated(pDocument);
} }

@ -1,110 +1,137 @@
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UBGraphicsItemUndoCommand.h" #include "UBGraphicsItemUndoCommand.h"
#include <QtGui> #include <QtGui>
#include "UBGraphicsScene.h" #include "UBGraphicsScene.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "core/UBApplication.h"
UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet<QGraphicsItem*>& pRemovedItems,
const QSet<QGraphicsItem*>& pAddedItems) #include "board/UBBoardController.h"
: mScene(pScene)
, mRemovedItems(pRemovedItems - pAddedItems) UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet<QGraphicsItem*>& pRemovedItems,
, mAddedItems(pAddedItems - pRemovedItems) const QSet<QGraphicsItem*>& pAddedItems)
{ : mScene(pScene)
mFirstRedo = true; , mRemovedItems(pRemovedItems - pAddedItems)
} , mAddedItems(pAddedItems - pRemovedItems)
{
UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem, mFirstRedo = true;
QGraphicsItem* pAddedItem) :
mScene(pScene) QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
{ while (itAdded.hasNext())
{
if (pRemovedItem) UBApplication::boardController->freezeW3CWidget(itAdded.next(), true);
mRemovedItems.insert(pRemovedItem); }
if (pAddedItem) QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
mAddedItems.insert(pAddedItem); while (itRemoved.hasNext())
{
mFirstRedo = true; UBApplication::boardController->freezeW3CWidget(itRemoved.next(), false);
}
} }
UBGraphicsItemUndoCommand::~UBGraphicsItemUndoCommand() UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem,
{ QGraphicsItem* pAddedItem) :
//NOOP mScene(pScene)
} {
void UBGraphicsItemUndoCommand::undo() if (pRemovedItem)
{ {
if (!mScene){ mRemovedItems.insert(pRemovedItem);
return; UBApplication::boardController->freezeW3CWidget(pRemovedItem, true);
} }
QSetIterator<QGraphicsItem*> itAdded(mAddedItems); if (pAddedItem)
while (itAdded.hasNext()) {
{ mAddedItems.insert(pAddedItem);
QGraphicsItem* item = itAdded.next(); UBApplication::boardController->freezeW3CWidget(pAddedItem, false);
item->setSelected(false); }
mScene->removeItem(item);
} mFirstRedo = true;
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems); }
while (itRemoved.hasNext())
{ UBGraphicsItemUndoCommand::~UBGraphicsItemUndoCommand()
mScene->addItem(itRemoved.next()); {
} //NOOP
}
// 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::undo()
{
} if (!mScene){
return;
void UBGraphicsItemUndoCommand::redo() }
{
// the Undo framework calls a redo while appending the undo command. QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
// as we have already plotted the elements, we do not want to do it twice while (itAdded.hasNext())
if (!mFirstRedo) {
{ QGraphicsItem* item = itAdded.next();
if (!mScene){ item->setSelected(false);
return; mScene->removeItem(item);
} UBApplication::boardController->freezeW3CWidget(item, true);
}
QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
while (itRemoved.hasNext()) QSetIterator<QGraphicsItem*> itRemoved(mRemovedItems);
{ while (itRemoved.hasNext())
QGraphicsItem* item = itRemoved.next(); {
item->setSelected(false); QGraphicsItem* item = itRemoved.next();
mScene->removeItem(item); mScene->addItem(item);
} UBApplication::boardController->freezeW3CWidget(item, false);
}
QSetIterator<QGraphicsItem*> itAdded(mAddedItems);
while (itAdded.hasNext()) // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint
{ mScene->update(mScene->sceneRect());
mScene->addItem(itAdded.next());
} }
// force refresh, QT is a bit lazy and take a lot of time (nb item ^2) to trigger repaint void UBGraphicsItemUndoCommand::redo()
mScene->update(mScene->sceneRect()); {
} // the Undo framework calls a redo while appending the undo command.
else // as we have already plotted the elements, we do not want to do it twice
{ if (!mFirstRedo)
mFirstRedo = false; {
} if (!mScene){
} return;
}
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();
mScene->addItem(item);
UBApplication::boardController->freezeW3CWidget(item, false);
}
// 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;
}
}

File diff suppressed because it is too large Load Diff

@ -1,377 +1,382 @@
/* /*
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UBGRAPHICSSCENE_H_ #ifndef UBGRAPHICSSCENE_H_
#define UBGRAPHICSSCENE_H_ #define UBGRAPHICSSCENE_H_
#include <QtGui> #include <QtGui>
#include "frameworks/UBCoreGraphicsScene.h" #include "frameworks/UBCoreGraphicsScene.h"
#include "core/UB.h" #include "core/UB.h"
#include "UBItem.h" #include "UBItem.h"
#include "tools/UBGraphicsCurtainItem.h" #include "tools/UBGraphicsCurtainItem.h"
class UBGraphicsPixmapItem; class UBGraphicsPixmapItem;
class UBGraphicsProxyWidget; class UBGraphicsProxyWidget;
class UBGraphicsSvgItem; class UBGraphicsSvgItem;
class UBGraphicsPolygonItem; class UBGraphicsPolygonItem;
class UBGraphicsVideoItem; class UBGraphicsVideoItem;
class UBGraphicsAudioItem; class UBGraphicsAudioItem;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
class UBGraphicsAppleWidgetItem; class UBGraphicsAppleWidgetItem;
class UBGraphicsPDFItem; class UBGraphicsPDFItem;
class UBGraphicsTextItem; class UBGraphicsTextItem;
class UBGraphicsRuler; class UBGraphicsRuler;
class UBGraphicsProtractor; class UBGraphicsProtractor;
class UBGraphicsCompass; class UBGraphicsCompass;
class UBAbstractWidget; class UBAbstractWidget;
class UBDocumentProxy; class UBDocumentProxy;
class UBGraphicsCurtainItem; class UBGraphicsCurtainItem;
class UBGraphicsStroke; class UBGraphicsStroke;
class UBMagnifierParams; class UBMagnifierParams;
class UBMagnifier; class UBMagnifier;
class UBGraphicsCache; class UBGraphicsCache;
const double PI = 4.0 * atan(1.0); const double PI = 4.0 * atan(1.0);
class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
{ {
Q_OBJECT Q_OBJECT
public: public:
// tmp stub for divide addings scene objects from undo mechanism implementation // tmp stub for divide addings scene objects from undo mechanism implementation
void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} void setURStackEnable(bool set = true) {enableUndoRedoStack = set;}
UBGraphicsScene(UBDocumentProxy *parent); UBGraphicsScene(UBDocumentProxy *parent);
virtual ~UBGraphicsScene(); virtual ~UBGraphicsScene();
virtual UBItem* deepCopy() const; virtual UBItem* deepCopy() const;
UBGraphicsScene* sceneDeepCopy() const; UBGraphicsScene* sceneDeepCopy() const;
void clearItemsAndAnnotations(); void clearItemsAndAnnotations();
void clearItems(); void clearItems();
void clearAnnotations(); void clearAnnotations();
bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0);
bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0);
bool inputDeviceRelease(); bool inputDeviceRelease();
void leaveEvent (QEvent* event); void leaveEvent (QEvent* event);
void addItem(QGraphicsItem* item); void addItem(QGraphicsItem* item);
void removeItem(QGraphicsItem* item); void removeItem(QGraphicsItem* item);
void addItems(const QSet<QGraphicsItem*>& item); void addItems(const QSet<QGraphicsItem*>& item);
void removeItems(const QSet<QGraphicsItem*>& item); void removeItems(const QSet<QGraphicsItem*>& item);
UBGraphicsWidgetItem* addWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsWidgetItem* addWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0));
UBGraphicsAppleWidgetItem* addAppleWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsAppleWidgetItem* addAppleWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0));
UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0),int widgetType = UBGraphicsItemType::W3CWidgetItemType); UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0),int widgetType = UBGraphicsItemType::W3CWidgetItemType);
void addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos = QPointF(0, 0)); void addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos = QPointF(0, 0));
UBGraphicsVideoItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsVideoItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0));
UBGraphicsAudioItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsAudioItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0));
UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0));
UBGraphicsTextItem* addText(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0)); UBGraphicsTextItem* addText(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0));
UBGraphicsTextItem* addTextWithFont(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0) UBGraphicsTextItem* addTextWithFont(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0)
, int pointSize = -1, const QString& fontFamily = "", bool bold = false, bool italic = false); , int pointSize = -1, const QString& fontFamily = "", bool bold = false, bool italic = false);
UBGraphicsTextItem* addTextHtml(const QString &pString = QString(), const QPointF& pTopLeft = QPointF(0, 0)); UBGraphicsTextItem* addTextHtml(const QString &pString = QString(), const QPointF& pTopLeft = QPointF(0, 0));
UBGraphicsW3CWidgetItem* addOEmbed(const QUrl& pContentUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsW3CWidgetItem* addOEmbed(const QUrl& pContentUrl, const QPointF& pPos = QPointF(0, 0));
QGraphicsItem* setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation = false, bool expand = false); QGraphicsItem* setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation = false, bool expand = false);
QGraphicsItem* backgroundObject() const QGraphicsItem* backgroundObject() const
{ {
return mBackgroundObject; return mBackgroundObject;
} }
bool isBackgroundObject(const QGraphicsItem* item) const bool isBackgroundObject(const QGraphicsItem* item) const
{ {
return item == mBackgroundObject; return item == mBackgroundObject;
} }
QGraphicsItem* scaleToFitDocumentSize(QGraphicsItem* item, bool center = false, int margin = 0, bool expand = false); QGraphicsItem* scaleToFitDocumentSize(QGraphicsItem* item, bool center = false, int margin = 0, bool expand = false);
QRectF normalizedSceneRect(qreal ratio = -1.0); QRectF normalizedSceneRect(qreal ratio = -1.0);
void moveTo(const QPointF& pPoint); void moveTo(const QPointF& pPoint);
void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth, bool bLineStyle); void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth, bool bLineStyle);
void eraseLineTo(const QPointF& pEndPoint, const qreal& pWidth); void eraseLineTo(const QPointF& pEndPoint, const qreal& pWidth);
void drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle); void drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle);
bool isEmpty() const; bool isEmpty() const;
bool isModified() const bool isModified() const
{ {
return mIsModified; return mIsModified;
} }
void setModified(bool pModified) void setModified(bool pModified)
{ {
mIsModified = pModified; mIsModified = pModified;
} }
void setDocument(UBDocumentProxy* pDocument); void setDocument(UBDocumentProxy* pDocument);
UBDocumentProxy* document() const UBDocumentProxy* document() const
{ {
return mDocument; return mDocument;
} }
bool isDarkBackground() const bool isDarkBackground() const
{ {
return mDarkBackground; return mDarkBackground;
} }
bool isLightBackground() const bool isLightBackground() const
{ {
return !mDarkBackground; return !mDarkBackground;
} }
bool isCrossedBackground() const bool isCrossedBackground() const
{ {
return mCrossedBackground; return mCrossedBackground;
} }
void setDrawingZIndex(qreal pDrawingZIndex) void setDrawingZIndex(qreal pDrawingZIndex)
{ {
mDrawingZIndex = pDrawingZIndex; mDrawingZIndex = pDrawingZIndex;
} }
void setObjectZIndex(qreal pObjectZIndex) void setObjectZIndex(qreal pObjectZIndex)
{ {
mObjectZIndex = pObjectZIndex; mObjectZIndex = pObjectZIndex;
} }
bool hasBackground() bool hasBackground()
{ {
return (mBackgroundObject != 0); return (mBackgroundObject != 0);
} }
qreal getNextObjectZIndex(); qreal getNextObjectZIndex();
void addRuler(QPointF center); void addRuler(QPointF center);
void addProtractor(QPointF center); void addProtractor(QPointF center);
void addCompass(QPointF center); void addCompass(QPointF center);
void addTriangle(QPointF center); void addTriangle(QPointF center);
void addMagnifier(UBMagnifierParams params); void addMagnifier(UBMagnifierParams params);
void addMask(const QPointF &center = QPointF()); void addMask(const QPointF &center = QPointF());
void addCache(); void addCache();
class SceneViewState QList<QGraphicsItem*> getFastAccessItems()
{ {
public: return mFastAccessItems;
SceneViewState() }
{
zoomFactor = 1; class SceneViewState
horizontalPosition = 0; {
verticalPostition = 0; public:
} SceneViewState()
{
SceneViewState(qreal pZoomFactor, int pHorizontalPosition, int pVerticalPostition) zoomFactor = 1;
{ horizontalPosition = 0;
zoomFactor = pZoomFactor; verticalPostition = 0;
horizontalPosition = pHorizontalPosition; }
verticalPostition = pVerticalPostition;
} SceneViewState(qreal pZoomFactor, int pHorizontalPosition, int pVerticalPostition)
{
qreal zoomFactor; zoomFactor = pZoomFactor;
int horizontalPosition; horizontalPosition = pHorizontalPosition;
int verticalPostition; verticalPostition = pVerticalPostition;
}; }
SceneViewState viewState() const qreal zoomFactor;
{ int horizontalPosition;
return mViewState; int verticalPostition;
} };
void setViewState(const SceneViewState& pViewState) SceneViewState viewState() const
{ {
mViewState = pViewState; return mViewState;
} }
virtual void setRenderingQuality(UBItem::RenderingQuality pRenderingQuality); void setViewState(const SceneViewState& pViewState)
{
QList<QUrl> relativeDependencies() const; mViewState = pViewState;
}
QSize nominalSize();
virtual void setRenderingQuality(UBItem::RenderingQuality pRenderingQuality);
void setNominalSize(const QSize& pSize);
QList<QUrl> relativeDependencies() const;
void setNominalSize(int pWidth, int pHeight);
QSize nominalSize();
qreal currentObjectZIndex()
{ void setNominalSize(const QSize& pSize);
return mObjectZIndex;
} void setNominalSize(int pWidth, int pHeight);
enum RenderingContext qreal currentObjectZIndex()
{ {
Screen = 0, NonScreen, PdfExport, Podcast return mObjectZIndex;
}; }
void setRenderingContext(RenderingContext pRenderingContext) enum RenderingContext
{ {
mRenderingContext = pRenderingContext; Screen = 0, NonScreen, PdfExport, Podcast
} };
RenderingContext renderingContext() const void setRenderingContext(RenderingContext pRenderingContext)
{ {
return mRenderingContext; mRenderingContext = pRenderingContext;
} }
static qreal backgroundLayerStart; RenderingContext renderingContext() const
static qreal objectLayerStart; {
static qreal drawingLayerStart; return mRenderingContext;
static qreal toolLayerStart; }
static qreal toolOffsetEraser; static qreal backgroundLayerStart;
static qreal toolOffsetPointer; static qreal objectLayerStart;
static qreal toolOffsetRuler; static qreal drawingLayerStart;
static qreal toolOffsetProtractor; static qreal toolLayerStart;
static qreal toolOffsetCompass;
static qreal toolOffsetCurtain; static qreal toolOffsetEraser;
static qreal toolOffsetTriangle; static qreal toolOffsetPointer;
static qreal toolOffsetCache; static qreal toolOffsetRuler;
static qreal toolOffsetProtractor;
QSet<QGraphicsItem*> tools(){ return mTools;} static qreal toolOffsetCompass;
static qreal toolOffsetCurtain;
void registerTool(QGraphicsItem* item) static qreal toolOffsetTriangle;
{ static qreal toolOffsetCache;
mTools << item;
} QSet<QGraphicsItem*> tools(){ return mTools;}
const QPointF& previousPoint() void registerTool(QGraphicsItem* item)
{ {
return mPreviousPoint; mTools << item;
} }
public slots: const QPointF& previousPoint()
{
void hideEraser(); return mPreviousPoint;
}
void setBackground(bool pIsDark, bool pIsCrossed);
public slots:
void deselectAllItems();
void hideEraser();
UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, const QPointF& pPos = QPointF(0,0), qreal scaleFactor = 1.0, bool pUseAnimation = false);
void setBackground(bool pIsDark, bool pIsCrossed);
void textUndoCommandAdded(UBGraphicsTextItem *textItem);
void deselectAllItems();
void setToolCursor(int tool);
UBGraphicsPixmapItem* addPixmap(const QPixmap& pPixmap, const QPointF& pPos = QPointF(0,0), qreal scaleFactor = 1.0, bool pUseAnimation = false);
void selectionChangedProcessing();
void textUndoCommandAdded(UBGraphicsTextItem *textItem);
void moveMagnifier(QPoint newPos);
void closeMagnifier(); void setToolCursor(int tool);
void zoomInMagnifier();
void zoomOutMagnifier(); void selectionChangedProcessing();
void resizedMagnifier(qreal newPercent);
void moveMagnifier(QPoint newPos);
signals: void closeMagnifier();
void zoomInMagnifier();
void pageSizeChanged(); void zoomOutMagnifier();
void resizedMagnifier(qreal newPercent);
protected:
signals:
UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth);
UBGraphicsPolygonItem* arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth); void pageSizeChanged();
UBGraphicsPolygonItem* polygonToPolygonItem(const QPolygonF pPolygon);
protected:
void initPolygonItem(UBGraphicsPolygonItem*);
UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth);
void drawEraser(const QPointF& pEndPoint, bool isFirstDraw = false); UBGraphicsPolygonItem* arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth);
void drawPointer(const QPointF& pEndPoint, bool isFirstDraw = false); UBGraphicsPolygonItem* polygonToPolygonItem(const QPolygonF pPolygon);
void DisposeMagnifierQWidgets();
void initPolygonItem(UBGraphicsPolygonItem*);
virtual void keyReleaseEvent(QKeyEvent * keyEvent); void drawEraser(const QPointF& pEndPoint, bool isFirstDraw = false);
void drawPointer(const QPointF& pEndPoint, bool isFirstDraw = false);
void recolorAllItems(); void DisposeMagnifierQWidgets();
qreal getNextDrawingZIndex();
virtual void keyReleaseEvent(QKeyEvent * keyEvent);
virtual void drawItems (QPainter * painter, int numItems,
QGraphicsItem * items[], const QStyleOptionGraphicsItem options[], QWidget * widget = 0); void recolorAllItems();
QGraphicsItem* rootItem(QGraphicsItem* item) const; qreal getNextDrawingZIndex();
private: virtual void drawItems (QPainter * painter, int numItems,
void setDocumentUpdated(); QGraphicsItem * items[], const QStyleOptionGraphicsItem options[], QWidget * widget = 0);
qreal mDrawingZIndex; QGraphicsItem* rootItem(QGraphicsItem* item) const;
qreal mObjectZIndex;
private:
QGraphicsEllipseItem* mEraser; void setDocumentUpdated();
QGraphicsEllipseItem* mPointer;
qreal mDrawingZIndex;
QSet<QGraphicsItem*> mAddedItems; qreal mObjectZIndex;
QSet<QGraphicsItem*> mRemovedItems;
QGraphicsEllipseItem* mEraser;
UBDocumentProxy* mDocument; QGraphicsEllipseItem* mPointer;
bool mDarkBackground; QSet<QGraphicsItem*> mAddedItems;
bool mCrossedBackground; QSet<QGraphicsItem*> mRemovedItems;
bool mIsModified; UBDocumentProxy* mDocument;
QGraphicsItem* mBackgroundObject; bool mDarkBackground;
bool mCrossedBackground;
QPointF mPreviousPoint;
qreal mPreviousWidth; bool mIsModified;
QList<UBGraphicsPolygonItem*> mPreviousPolygonItems; QGraphicsItem* mBackgroundObject;
SceneViewState mViewState; QPointF mPreviousPoint;
qreal mPreviousWidth;
bool mInputDeviceIsPressed;
QList<UBGraphicsPolygonItem*> mPreviousPolygonItems;
QSet<QGraphicsItem*> mTools;
SceneViewState mViewState;
UBGraphicsPolygonItem *mArcPolygonItem;
bool mInputDeviceIsPressed;
QSize mNominalSize;
QSet<QGraphicsItem*> mTools;
RenderingContext mRenderingContext;
UBGraphicsPolygonItem *mArcPolygonItem;
UBGraphicsStroke* mCurrentStroke;
QSize mNominalSize;
bool mShouldUseOMP;
RenderingContext mRenderingContext;
int mItemCount;
UBGraphicsStroke* mCurrentStroke;
QList<QGraphicsItem*> mFastAccessItems; // a local copy as QGraphicsScene::items() is very slow in Qt 4.6
bool mShouldUseOMP;
//int mMesure1Ms, mMesure2Ms;
int mItemCount;
bool mHasCache;
// tmp stub for divide addings scene objects from undo mechanism implementation QList<QGraphicsItem*> mFastAccessItems; // a local copy as QGraphicsScene::items() is very slow in Qt 4.6
bool enableUndoRedoStack;
//int mMesure1Ms, mMesure2Ms;
UBMagnifier *magniferControlViewWidget;
UBMagnifier *magniferDisplayViewWidget; bool mHasCache;
// tmp stub for divide addings scene objects from undo mechanism implementation
bool enableUndoRedoStack;
};
UBMagnifier *magniferControlViewWidget;
#endif /* UBGRAPHICSSCENE_H_ */ UBMagnifier *magniferDisplayViewWidget;
};
#endif /* UBGRAPHICSSCENE_H_ */

Loading…
Cancel
Save