Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
56eceb66
Commit
56eceb66
authored
May 07, 2012
by
Ivan Ilyin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:Sankore/Sankore-3.1
parents
f4fffe47
17dd8564
Changes
43
Hide whitespace changes
Inline
Side-by-side
Showing
43 changed files
with
2228 additions
and
1613 deletions
+2228
-1613
style.qss
resources/style.qss
+7
-0
UBExportCFF.cpp
src/adaptors/UBExportCFF.cpp
+1
-0
UBBoardPaletteManager.cpp
src/board/UBBoardPaletteManager.cpp
+15
-8
UBBoardPaletteManager.h
src/board/UBBoardPaletteManager.h
+192
-184
UBFeaturesController.cpp
src/board/UBFeaturesController.cpp
+145
-54
UBFeaturesController.h
src/board/UBFeaturesController.h
+50
-22
main.cpp
src/core/main.cpp
+1
-1
UBActionableWidget.cpp
src/customWidgets/UBActionableWidget.cpp
+2
-0
UBMediaWidget.cpp
src/customWidgets/UBMediaWidget.cpp
+2
-0
UBAbstractUndoCommand.cpp
src/domain/UBAbstractUndoCommand.cpp
+2
-0
UBAngleWidget.cpp
src/domain/UBAngleWidget.cpp
+2
-0
UBGraphicsDelegateFrame.cpp
src/domain/UBGraphicsDelegateFrame.cpp
+802
-794
UBGraphicsItemDelegate.cpp
src/domain/UBGraphicsItemDelegate.cpp
+98
-3
UBGraphicsItemDelegate.h
src/domain/UBGraphicsItemDelegate.h
+37
-17
UBGraphicsItemUndoCommand.cpp
src/domain/UBGraphicsItemUndoCommand.cpp
+2
-2
UBGraphicsMediaItem.cpp
src/domain/UBGraphicsMediaItem.cpp
+2
-2
UBGraphicsStrokesGroup.cpp
src/domain/UBGraphicsStrokesGroup.cpp
+2
-0
UBGraphicsTextItemDelegate.cpp
src/domain/UBGraphicsTextItemDelegate.cpp
+11
-6
UBGraphicsVideoItemDelegate.cpp
src/domain/UBGraphicsVideoItemDelegate.cpp
+351
-336
UBGraphicsVideoItemDelegate.h
src/domain/UBGraphicsVideoItemDelegate.h
+116
-114
ubgraphicsgroupcontaineritem.cpp
src/domain/ubgraphicsgroupcontaineritem.cpp
+2
-0
ubgraphicsgroupcontaineritemdelegate.cpp
src/domain/ubgraphicsgroupcontaineritemdelegate.cpp
+2
-1
UBCoreGraphicsScene.cpp
src/frameworks/UBCoreGraphicsScene.cpp
+2
-1
UBDockDownloadWidget.cpp
src/gui/UBDockDownloadWidget.cpp
+2
-0
UBDockTeacherGuideWidget.cpp
src/gui/UBDockTeacherGuideWidget.cpp
+2
-0
UBFeaturesActionBar.cpp
src/gui/UBFeaturesActionBar.cpp
+19
-0
UBFeaturesActionBar.h
src/gui/UBFeaturesActionBar.h
+2
-1
UBFeaturesWidget.cpp
src/gui/UBFeaturesWidget.cpp
+289
-53
UBFeaturesWidget.h
src/gui/UBFeaturesWidget.h
+43
-7
UBLibItemProperties.cpp
src/gui/UBLibItemProperties.cpp
+2
-1
UBLibNavigatorWidget.cpp
src/gui/UBLibNavigatorWidget.cpp
+2
-1
UBLibPathViewer.cpp
src/gui/UBLibPathViewer.cpp
+2
-1
UBLibWebView.cpp
src/gui/UBLibWebView.cpp
+1
-2
UBLibWidget.cpp
src/gui/UBLibWidget.cpp
+2
-1
UBPageNavigationWidget.cpp
src/gui/UBPageNavigationWidget.cpp
+2
-1
UBTGWidgetTreeDelegate.cpp
src/gui/UBTGWidgetTreeDelegate.cpp
+2
-0
UBTeacherGuideDelegate.cpp
src/gui/UBTeacherGuideDelegate.cpp
+1
-0
UBTeacherGuideWidget.cpp
src/gui/UBTeacherGuideWidget.cpp
+2
-0
UBTeacherGuideWidgetsTools.cpp
src/gui/UBTeacherGuideWidgetsTools.cpp
+2
-0
CCITTFaxDecode.cpp
src/pdf-merger/CCITTFaxDecode.cpp
+2
-0
DCTDecode.cpp
src/pdf-merger/DCTDecode.cpp
+2
-0
JBIG2Decode.cpp
src/pdf-merger/JBIG2Decode.cpp
+1
-0
UBOEmbedParser.cpp
src/web/UBOEmbedParser.cpp
+2
-0
No files found.
resources/style.qss
View file @
56eceb66
...
...
@@ -26,6 +26,13 @@ QWidget#UBLibWebView
border: 2px solid #999999;
}
QWidget#UBFeaturesWebView
{
background: #EEEEEE;
border-radius : 10px;
border: 2px solid #999999;
}
QListView
{
background: #EEEEEE;
...
...
src/adaptors/UBExportCFF.cpp
View file @
56eceb66
...
...
@@ -3,6 +3,7 @@
#include "document/UBDocumentProxy.h"
#include "core/UBDocumentManager.h"
#include "core/UBApplication.h"
#include "core/memcheck.h"
UBExportCFF
::
UBExportCFF
(
QObject
*
parent
)
...
...
src/board/UBBoardPaletteManager.cpp
View file @
56eceb66
...
...
@@ -58,10 +58,10 @@
#include "UBBoardController.h"
#include "core/memcheck.h"
#include "document/UBDocumentController.h"
#include "core/memcheck.h"
UBBoardPaletteManager
::
UBBoardPaletteManager
(
QWidget
*
container
,
UBBoardController
*
pBoardController
)
:
QObject
(
container
)
,
mKeyboardPalette
(
0
)
...
...
@@ -81,7 +81,9 @@ UBBoardPaletteManager::UBBoardPaletteManager(QWidget* container, UBBoardControll
,
mPendingPanButtonPressed
(
false
)
,
mPendingEraseButtonPressed
(
false
)
,
mpPageNavigWidget
(
NULL
)
#ifdef USE_WEB_WIDGET
,
mpLibWidget
(
NULL
)
#endif
,
mpCachePropWidget
(
NULL
)
,
mpDownloadWidget
(
NULL
)
,
mpDesktopLibWidget
(
NULL
)
...
...
@@ -132,7 +134,9 @@ void UBBoardPaletteManager::setupDockPaletteWidgets()
mpPageNavigWidget
=
new
UBPageNavigationWidget
();
#ifdef USE_WEB_WIDGET
mpLibWidget
=
new
UBLibWidget
();
#endif
mpCachePropWidget
=
new
UBCachePropertiesWidget
();
...
...
@@ -159,8 +163,11 @@ void UBBoardPaletteManager::setupDockPaletteWidgets()
mRightPalette
->
addTab
(
mpFeaturesWidget
);
//Do not show deprecated lib widget to prevent collisions. Uncomment to return lib widget
// mRightPalette->registerWidget(mpLibWidget);
// mRightPalette->addTab(mpLibWidget);
#ifdef USE_WEB_WIDGET
mRightPalette
->
registerWidget
(
mpLibWidget
);
mRightPalette
->
addTab
(
mpLibWidget
);
#endif
// The cache widget will be visible only if a cache is put on the page
...
...
@@ -841,10 +848,10 @@ void UBBoardPaletteManager::addItemToLibrary()
}
QImage
image
=
mPixmap
.
toImage
();
if
(
NULL
!=
mpLibWidget
)
{
mpLibWidget
->
libNavigator
()
->
libraryWidget
()
->
libraryController
()
->
importImageOnLibrary
(
image
);
}
#ifdef USE_WEB_WIDGET
mpLibWidget
->
libNavigator
()
->
libraryWidget
()
->
libraryController
()
->
importImageOnLibrary
(
image
);
#endif
}
else
{
...
...
src/board/UBBoardPaletteManager.h
View file @
56eceb66
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBBOARDPALETTEMANAGER_H_
#define UBBOARDPALETTEMANAGER_H_
#include <QtGui>
#include <QtWebKit>
#include "web/UBRoutedMouseEventWebView.h"
#include "gui/UBLeftPalette.h"
#include "gui/UBRightPalette.h"
#include "gui/UBPageNavigationWidget.h"
#include "gui/UBLibWidget.h"
#include "gui/UBCachePropertiesWidget.h"
#include "gui/UBDockDownloadWidget.h"
#include "core/UBApplicationController.h"
#include "gui/UBFeaturesWidget.h"
class
UBStylusPalette
;
class
UBClockPalette
;
class
UBPageNumberPalette
;
class
UBZoomPalette
;
class
UBActionPalette
;
class
UBBoardController
;
class
UBFloatingPalette
;
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
;}
void
showVirtualKeyboard
(
bool
show
=
true
);
void
initPalettesPosAtStartup
();
void
connectToDocumentController
();
void
refreshPalettes
();
UBKeyboardPalette
*
mKeyboardPalette
;
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
);
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 library widget */
UBLibWidget
*
mpLibWidget
;
/** The cache properties widget */
UBCachePropertiesWidget
*
mpCachePropWidget
;
UBFeaturesWidget
*
mpFeaturesWidget
;
/** The download widget */
UBDockDownloadWidget
*
mpDownloadWidget
;
// HACK: here we duplicate the lib widget for the desktop mode
// we MUST refactor the architecture in order to use only one
// lib widget!
UBLibWidget
*
mpDesktopLibWidget
;
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
toggleErasePalette
(
bool
ckecked
);
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_ */
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBBOARDPALETTEMANAGER_H_
#define UBBOARDPALETTEMANAGER_H_
#include <QtGui>
#include <QtWebKit>
#include "web/UBRoutedMouseEventWebView.h"
#include "gui/UBLeftPalette.h"
#include "gui/UBRightPalette.h"
#include "gui/UBPageNavigationWidget.h"
#include "gui/UBLibWidget.h"
#include "gui/UBCachePropertiesWidget.h"
#include "gui/UBDockDownloadWidget.h"
#include "core/UBApplicationController.h"
#include "gui/UBFeaturesWidget.h"
class
UBStylusPalette
;
class
UBClockPalette
;
class
UBPageNumberPalette
;
class
UBZoomPalette
;
class
UBActionPalette
;
class
UBBoardController
;
class
UBFloatingPalette
;
class
UBServerXMLHttpRequest
;
class
UBKeyboardPalette
;
class
UBMainWindow
;
class
UBApplicationController
;
class
UBDockTeacherGuideWidget
;
// Uncomment this to use old-styles lib paletter
// #define USE_WEB_WIDGET
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
;}
void
showVirtualKeyboard
(
bool
show
=
true
);
void
initPalettesPosAtStartup
();
void
connectToDocumentController
();
void
refreshPalettes
();
UBKeyboardPalette
*
mKeyboardPalette
;
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
);
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
;
#ifdef USE_WEB_WIDGET
/** The library widget */
UBLibWidget
*
mpLibWidget
;
#endif
/** The cache properties widget */
UBCachePropertiesWidget
*
mpCachePropWidget
;
UBFeaturesWidget
*
mpFeaturesWidget
;
/** The download widget */
UBDockDownloadWidget
*
mpDownloadWidget
;
// HACK: here we duplicate the lib widget for the desktop mode
// we MUST refactor the architecture in order to use only one
// lib widget!
UBLibWidget
*
mpDesktopLibWidget
;
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
toggleErasePalette
(
bool
ckecked
);
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_ */
src/board/UBFeaturesController.cpp
View file @
56eceb66
...
...
@@ -18,13 +18,30 @@
#include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsWidgetItem.h"
UBFeature
::
UBFeature
(
const
QString
&
url
,
const
QPixmap
&
icon
,
const
QString
&
name
,
const
Q
String
&
realPath
,
UBFeatureElementType
type
)
UBFeature
::
UBFeature
(
const
QString
&
url
,
const
QPixmap
&
icon
,
const
QString
&
name
,
const
Q
Url
&
realPath
,
UBFeatureElementType
type
)
:
virtualPath
(
url
),
mThumbnail
(
icon
),
mName
(
name
),
mPath
(
realPath
),
elementType
(
type
)
{
}
QString
UBFeature
::
getUrl
()
const
{
if
(
elementType
==
FEATURE_INTERNAL
)
return
getFullPath
().
toString
();
/*if ( UBApplication::isFromWeb( getFullPath() ) )
return QUrl( getFullPath() );*/
return
getFullPath
().
toLocalFile
();
}
bool
UBFeature
::
operator
==
(
const
UBFeature
&
f
)
const
{
return
virtualPath
==
f
.
getVirtualPath
()
&&
mName
==
f
.
getName
()
&&
mPath
==
f
.
getFullPath
()
&&
elementType
==
f
.
getType
();
}
bool
UBFeature
::
operator
!=
(
const
UBFeature
&
f
)
const
{
return
!
(
*
this
==
f
);
}
bool
UBFeature
::
isFolder
()
const
{
...
...
@@ -32,6 +49,10 @@ bool UBFeature::isFolder() const
||
elementType
==
FEATURE_FOLDER
;
}
bool
UBFeature
::
isDeletable
()
const
{
return
elementType
==
FEATURE_ITEM
;
}
UBFeaturesController
::
UBFeaturesController
(
QWidget
*
pParentWidget
)
:
QObject
(
pParentWidget
),
...
...
@@ -43,23 +64,24 @@ UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) :
void
UBFeaturesController
::
initDirectoryTree
()
{
mUserAudioDirectoryPath
=
UBSettings
::
settings
()
->
userAudioDirectory
();
mUserVideoDirectoryPath
=
UBSettings
::
settings
()
->
userVideoDirectory
();
mUserPicturesDirectoryPath
=
UBSettings
::
settings
()
->
userImageDirectory
();
mUserInteractiveDirectoryPath
=
UBSettings
::
settings
()
->
userInteractiveDirectory
();
mUserAnimationDirectoryPath
=
UBSettings
::
settings
()
->
userAnimationDirectory
();
mLibPicturesDirectoryPath
=
UBSettings
::
settings
()
->
applicationImageLibraryDirectory
();
mLibInteractiveDirectoryPath
=
UBSettings
::
settings
()
->
applicationInteractivesDirectory
();
mLibApplicationsDirectoryPath
=
UBSettings
::
settings
()
->
applicationApplicationsLibraryDirectory
();
mLibShapesDirectoryPath
=
UBSettings
::
settings
()
->
applicationShapeLibraryDirectory
()
;
trashDirectoryPath
=
UBSettings
::
userTrashDirPath
();
mUserAudioDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
userAudioDirectory
()
);
mUserVideoDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
userVideoDirectory
()
);
mUserPicturesDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
userImageDirectory
()
);
mUserInteractiveDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
userInteractiveDirectory
()
);
mUserAnimationDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
userAnimationDirectory
()
);
mLibPicturesDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
applicationImageLibraryDirectory
()
);
mLibInteractiveDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
applicationInteractivesDirectory
()
);
mLibApplicationsDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
applicationApplicationsLibraryDirectory
()
);
mLibShapesDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
applicationShapeLibraryDirectory
()
);
mLibSearchDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
settings
()
->
userSearchDirectory
()
);
trashDirectoryPath
=
QUrl
::
fromLocalFile
(
UBSettings
::
userTrashDirPath
()
);
featuresList
=
new
QList
<
UBFeature
>
();
QList
<
UBToolsManager
::
UBToolDescriptor
>
tools
=
UBToolsManager
::
manager
()
->
allTools
();
featuresList
->
append
(
UBFeature
(
QString
(),
QPixmap
(
":images/libpalette/home.png"
),
"root"
,
Q
String
()
)
);
featuresList
->
append
(
UBFeature
(
QString
(),
QPixmap
(
":images/libpalette/home.png"
),
"root"
,
Q
Url
()
)
);
currentElement
=
featuresList
->
at
(
0
);
appPath
=
rootPath
+
"/Applications"
;
...
...
@@ -72,26 +94,32 @@ void UBFeaturesController::initDirectoryTree()
trashPath
=
rootPath
+
"/Trash"
;
favoritePath
=
rootPath
+
"/Favorites"
;
featuresList
->
append
(
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/AudiosCategory.svg"
),
"Audios"
,
mUserAudioDirectoryPath
)
);
featuresList
->
append
(
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/MoviesCategory.svg"
),
"Movies"
,
mUserVideoDirectoryPath
)
);
featuresList
->
append
(
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/PicturesCategory.svg"
),
"Pictures"
,
mUserPicturesDirectoryPath
)
);
audiosElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/AudiosCategory.svg"
),
"Audios"
,
mUserAudioDirectoryPath
);
featuresList
->
append
(
audiosElement
);
moviesElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/MoviesCategory.svg"
),
"Movies"
,
mUserVideoDirectoryPath
);
featuresList
->
append
(
moviesElement
);
picturesElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/PicturesCategory.svg"
),
"Pictures"
,
mUserPicturesDirectoryPath
);
featuresList
->
append
(
picturesElement
);
featuresList
->
append
(
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/ApplicationsCategory.svg"
),
"Applications"
,
mUserInteractiveDirectoryPath
)
);
featuresList
->
append
(
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/FlashCategory.svg"
),
"Animations"
,
mUserAnimationDirectoryPath
)
);
featuresList
->
append
(
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/InteractivesCategory.svg"
),
"Interactivities"
,
mLibInteractiveDirectoryPath
)
);
flashElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/FlashCategory.svg"
),
"Animations"
,
mUserAnimationDirectoryPath
);
featuresList
->
append
(
flashElement
);
interactElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/InteractivesCategory.svg"
),
"Interactivities"
,
mLibInteractiveDirectoryPath
);
featuresList
->
append
(
interactElement
);
featuresList
->
append
(
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/ShapesCategory.svg"
),
"Shapes"
,
mLibShapesDirectoryPath
)
);
trashElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/TrashCategory.svg"
),
"Trash"
,
trashDirectoryPath
,
FEATURE_TRASH
);
featuresList
->
append
(
trashElement
);
favoriteElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/FavoritesCategory.svg"
),
"Favorites"
,
"favorites"
,
FEATURE_FAVORITE
);
favoriteElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/FavoritesCategory.svg"
),
"Favorites"
,
QUrl
(
"favorites"
)
,
FEATURE_FAVORITE
);
featuresList
->
append
(
favoriteElement
);
webSearchElement
=
UBFeature
(
rootPath
,
QPixmap
(
":images/libpalette/WebSearchCategory.svg"
),
"Web search"
,
mLibSearchDirectoryPath
);
featuresList
->
append
(
webSearchElement
);
loadFavoriteList
();
foreach
(
UBToolsManager
::
UBToolDescriptor
tool
,
tools
)
{
featuresList
->
append
(
UBFeature
(
appPath
,
tool
.
icon
,
tool
.
label
,
tool
.
id
,
FEATURE_INTERNAL
)
);
if
(
favoriteSet
->
find
(
tool
.
id
)
!=
favoriteSet
->
end
()
)
featuresList
->
append
(
UBFeature
(
appPath
,
tool
.
icon
,
tool
.
label
,
QUrl
(
tool
.
id
)
,
FEATURE_INTERNAL
)
);
if
(
favoriteSet
->
find
(
QUrl
(
tool
.
id
)
)
!=
favoriteSet
->
end
()
)
{
featuresList
->
append
(
UBFeature
(
favoritePath
,
tool
.
icon
,
tool
.
label
,
tool
.
id
,
FEATURE_INTERNAL
)
);
featuresList
->
append
(
UBFeature
(
favoritePath
,
tool
.
icon
,
tool
.
label
,
QUrl
(
tool
.
id
)
,
FEATURE_INTERNAL
)
);
}
}
fileSystemScan
(
mUserInteractiveDirectoryPath
,
appPath
);
...
...
@@ -105,14 +133,14 @@ void UBFeaturesController::initDirectoryTree()
fileSystemScan
(
mLibShapesDirectoryPath
,
shapesPath
);
fileSystemScan
(
mLibInteractiveDirectoryPath
,
interactPath
);
fileSystemScan
(
trashDirectoryPath
,
trashPath
);
fileSystemScan
(
mLibSearchDirectoryPath
,
rootPath
+
"/"
+
"Web search"
);
}
void
UBFeaturesController
::
fileSystemScan
(
const
Q
String
&
currentPath
,
const
QString
&
currVirtualPath
)
void
UBFeaturesController
::
fileSystemScan
(
const
Q
Url
&
currentPath
,
const
QString
&
currVirtualPath
)
{
QFileInfoList
fileInfoList
=
UBFileSystemUtils
::
allElementsInDirectory
(
currentPath
);
QFileInfoList
fileInfoList
=
UBFileSystemUtils
::
allElementsInDirectory
(
currentPath
.
toLocalFile
()
);
QFileInfoList
::
iterator
fileInfo
;
for
(
fileInfo
=
fileInfoList
.
begin
();
fileInfo
!=
fileInfoList
.
end
();
fileInfo
+=
1
)
...
...
@@ -120,12 +148,19 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt
UBFeatureElementType
fileType
=
fileInfo
->
isDir
()
?
FEATURE_FOLDER
:
FEATURE_ITEM
;
QString
fileName
=
fileInfo
->
fileName
();
if
(
UBFileSystemUtils
::
mimeTypeFromFileName
(
fileName
).
contains
(
"application"
)
)
{
fileType
=
FEATURE_INTERACTIVE
;
if
(
UBFileSystemUtils
::
mimeTypeFromFileName
(
fileName
).
contains
(
"application"
)
)
{
if
(
UBFileSystemUtils
::
mimeTypeFromFileName
(
fileName
).
contains
(
"application/search"
)
)
{
fileType
=
FEATURE_SEARCH
;
}
else
fileType
=
FEATURE_INTERACTIVE
;
}
QString
itemName
=
(
fileType
!=
FEATURE_ITEM
)
?
fileName
:
fileInfo
->
completeBaseName
();
QPixmap
icon
=
QPixmap
(
":images/libpalette/soundIcon.svg"
);
QString
fullFileName
=
fileInfo
->
filePath
();
if
(
fileType
==
FEATURE_FOLDER
)
{
...
...
@@ -146,15 +181,15 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt
icon = QPixmap( thumbnailPath );
else icon = createThumbnail( fullFileName );*/
}
featuresList
->
append
(
UBFeature
(
currVirtualPath
,
icon
,
fileName
,
fullFileName
,
fileType
)
);
if
(
favoriteSet
->
find
(
fullFileName
)
!=
favoriteSet
->
end
()
)
featuresList
->
append
(
UBFeature
(
currVirtualPath
,
icon
,
fileName
,
QUrl
::
fromLocalFile
(
fullFileName
)
,
fileType
)
);
if
(
favoriteSet
->
find
(
QUrl
::
fromLocalFile
(
fullFileName
)
)
!=
favoriteSet
->
end
()
)
{
featuresList
->
append
(
UBFeature
(
favoritePath
,
icon
,
fileName
,
fullFileName
,
fileType
)
);
featuresList
->
append
(
UBFeature
(
favoritePath
,
icon
,
fileName
,
QUrl
::
fromLocalFile
(
fullFileName
)
,
fileType
)
);
}
if
(
fileType
==
FEATURE_FOLDER
)
{
fileSystemScan
(
fullFileName
,
currVirtualPath
+
"/"
+
fileName
);
fileSystemScan
(
QUrl
::
fromLocalFile
(
fullFileName
)
,
currVirtualPath
+
"/"
+
fileName
);
}
}
...
...
@@ -162,7 +197,7 @@ void UBFeaturesController::fileSystemScan(const QString & currentPath, const QSt
void
UBFeaturesController
::
loadFavoriteList
()
{
favoriteSet
=
new
QSet
<
Q
String
>
();
favoriteSet
=
new
QSet
<
Q
Url
>
();
QFile
file
(
UBSettings
::
userDataDirectory
()
+
"/favorites.dat"
);
if
(
file
.
exists
()
)
{
...
...
@@ -172,7 +207,7 @@ void UBFeaturesController::loadFavoriteList()
in
>>
elementsNumber
;
for
(
int
i
=
0
;
i
<
elementsNumber
;
++
i
)
{
Q
String
path
;
Q
Url
path
;
in
>>
path
;
/*QFileInfo fileInfo( path );
QString fileName = fileInfo.fileName();
...
...
@@ -191,7 +226,7 @@ void UBFeaturesController::saveFavoriteList()
file
.
open
(
QIODevice
::
WriteOnly
);
QDataStream
out
(
&
file
);
out
<<
favoriteSet
->
size
();
for
(
QSet
<
Q
String
>::
iterator
it
=
favoriteSet
->
begin
();
it
!=
favoriteSet
->
end
();
++
it
)
for
(
QSet
<
Q
Url
>::
iterator
it
=
favoriteSet
->
begin
();
it
!=
favoriteSet
->
end
();
++
it
)
{
out
<<
(
*
it
);
}
...
...
@@ -201,12 +236,12 @@ void UBFeaturesController::saveFavoriteList()
UBFeature
UBFeaturesController
::
addToFavorite
(
const
QUrl
&
path
)
{
QString
filePath
=
fileNameFromUrl
(
path
);
if
(
favoriteSet
->
find
(
fileP
ath
)
==
favoriteSet
->
end
()
)
if
(
favoriteSet
->
find
(
p
ath
)
==
favoriteSet
->
end
()
)
{
QFileInfo
fileInfo
(
filePath
);
QString
fileName
=
fileInfo
.
fileName
();
UBFeature
elem
(
favoritePath
,
thumbnailForFile
(
filePath
),
fileName
,
fileP
ath
,
fileTypeFromUrl
(
filePath
)
);
favoriteSet
->
insert
(
fileP
ath
);
UBFeature
elem
(
favoritePath
,
thumbnailForFile
(
filePath
),
fileName
,
p
ath
,
fileTypeFromUrl
(
filePath
)
);
favoriteSet
->
insert
(
p
ath
);
saveFavoriteList
();
return
elem
;
}
...
...
@@ -216,9 +251,9 @@ UBFeature UBFeaturesController::addToFavorite( const QUrl &path )
void
UBFeaturesController
::
removeFromFavorite
(
const
QUrl
&
path
)
{
QString
filePath
=
fileNameFromUrl
(
path
);
if
(
favoriteSet
->
find
(
fileP
ath
)
!=
favoriteSet
->
end
()
)
if
(
favoriteSet
->
find
(
p
ath
)
!=
favoriteSet
->
end
()
)
{
favoriteSet
->
erase
(
favoriteSet
->
find
(
fileP
ath
)
);
favoriteSet
->
erase
(
favoriteSet
->
find
(
p
ath
)
);
saveFavoriteList
();
}
}
...
...
@@ -231,6 +266,7 @@ QString UBFeaturesController::fileNameFromUrl( const QUrl &url )
return
url
.
toLocalFile
();
}
UBFeatureElementType
UBFeaturesController
::
fileTypeFromUrl
(
const
QString
&
path
)
{
QFileInfo
fileInfo
(
path
);
...
...
@@ -268,6 +304,12 @@ QPixmap UBFeaturesController::thumbnailForFile(const QString &path)
return
thumb
;
}
bool
UBFeaturesController
::
isDeletable
(
const
QUrl
&
url
)
{
UBFeatureElementType
type
=
fileTypeFromUrl
(
fileNameFromUrl
(
url
)
);
return
type
==
FEATURE_ITEM
;
}
QPixmap
UBFeaturesController
::
createThumbnail
(
const
QString
&
path
)
{
QString
thumbnailPath
=
UBFileSystemUtils
::
thumbnailPath
(
path
);
...
...
@@ -305,24 +347,63 @@ QPixmap UBFeaturesController::createThumbnail(const QString &path)
UBFeature
UBFeaturesController
::
newFolder
(
const
QString
&
name
)
{
QString
path
=
currentElement
.
getFullPath
()
+
"/"
+
name
;
QString
path
=
currentElement
.
getFullPath
().
toLocalFile
()
+
"/"
+
name
;
if
(
!
QFileInfo
(
path
).
exists
())
{
QDir
().
mkpath
(
path
);
}
return
UBFeature
(
currentElement
.
getUrl
()
+
"/"
+
currentElement
.
getName
(),
QPixmap
(
":images/libpalette/folder.svg"
),
name
,
path
,
FEATURE_FOLDER
);
return
UBFeature
(
currentElement
.
getFullVirtualPath
(),
QPixmap
(
":images/libpalette/folder.svg"
),
name
,
QUrl
::
fromLocalFile
(
path
),
FEATURE_FOLDER
);
}
void
UBFeaturesController
::
addItemToPage
(
const
UBFeature
&
item
)
{
if
(
item
.
getType
()
==
FEATURE_INTERNAL
)
{
UBApplication
::
boardController
->
downloadURL
(
QUrl
(
item
.
getFullPath
()
)
);
}
else
UBApplication
::
boardController
->
downloadURL
(
item
.
getFullPath
()
);
}
void
UBFeaturesController
::
addItemAsBackground
(
const
UBFeature
&
item
)
{
UBApplication
::
boardController
->
downloadURL
(
item
.
getFullPath
(),
QPointF
(),
QSize
(),
true
);
}
UBFeature
UBFeaturesController
::
getDestinationForItem
(
const
QUrl
&
url
)
{
QString
mimetype
=
UBFileSystemUtils
::
mimeTypeFromFileName
(
url
.
toString
()
);
if
(
mimetype
.
contains
(
"audio"
)
)
return
audiosElement
;
if
(
mimetype
.
contains
(
"video"
)
)
return
moviesElement
;
else
if
(
mimetype
.
contains
(
"image"
)
)
return
picturesElement
;
else
if
(
mimetype
.
contains
(
"application"
)
)
{
UBApplication
::
boardController
->
downloadURL
(
QUrl
::
fromLocalFile
(
item
.
getFullPath
()
)
);
}
if
(
mimetype
.
contains
(
"x-shockwave-flash"
)
)
return
flashElement
;
else
return
interactElement
;
}
return
UBFeature
();
}
UBFeature
UBFeaturesController
::
addDownloadedFile
(
const
QUrl
&
sourceUrl
,
const
QByteArray
&
pData
)
{
UBFeature
dest
=
getDestinationForItem
(
sourceUrl
);
if
(
dest
==
UBFeature
()
)
return
UBFeature
();
QString
fileName
=
QFileInfo
(
sourceUrl
.
toString
()
).
fileName
();
QString
filePath
=
dest
.
getFullPath
().
toLocalFile
()
+
"/"
+
fileName
;
QFile
file
(
filePath
);
if
(
file
.
open
(
QIODevice
::
WriteOnly
))
{
file
.
write
(
pData
);
file
.
close
();
return
UBFeature
(
dest
.
getFullVirtualPath
(),
thumbnailForFile
(
filePath
),
fileName
,
QUrl
::
fromLocalFile
(
filePath
),
FEATURE_ITEM
);
}
return
UBFeature
();
}
UBFeature
UBFeaturesController
::
moveItemToFolder
(
const
QUrl
&
url
,
const
UBFeature
&
destination
)
...
...
@@ -338,9 +419,19 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu
Q_ASSERT
(
QFileInfo
(
sourcePath
).
exists
()
);
UBFeature
possibleDest
=
getDestinationForItem
(
url
);
UBFeature
dest
=
destination
;
if
(
destination
!=
trashElement
&&
!
destination
.
getFullVirtualPath
().
startsWith
(
possibleDest
.
getFullVirtualPath
(),
Qt
::
CaseInsensitive
)
)
{
dest
=
possibleDest
;
}
QString
name
=
QFileInfo
(
sourcePath
).
fileName
();
QString
destPath
=
destination
.
getFullPath
();
QString
destVirtualPath
=
dest
ination
.
getUrl
()
+
"/"
+
destination
.
getName
();
QString
destPath
=
dest
.
getFullPath
().
toLocalFile
();
QString
destVirtualPath
=
dest
.
getFullVirtualPath
();
QString
newFullPath
=
destPath
+
"/"
+
name
;
QFile
(
sourcePath
).
copy
(
newFullPath
);
...
...
@@ -349,7 +440,7 @@ UBFeature UBFeaturesController::copyItemToFolder( const QUrl &url, const UBFeatu
UBFeatureElementType
type
=
FEATURE_ITEM
;
if
(
UBFileSystemUtils
::
mimeTypeFromFileName
(
newFullPath
).
contains
(
"application"
)
)
type
=
FEATURE_INTERACTIVE
;
UBFeature
newElement
(
destVirtualPath
,
thumb
,
name
,
newFullPath
,
type
);
UBFeature
newElement
(
destVirtualPath
,
thumb
,
name
,
QUrl
::
fromLocalFile
(
newFullPath
)
,
type
);
return
newElement
;
}
...
...
@@ -359,7 +450,7 @@ void UBFeaturesController::deleteItem( const QUrl &url )
Q_ASSERT
(
QFileInfo
(
path
).
exists
()
);
QString
thumbnailPath
=
UBFileSystemUtils
::
thumbnailPath
(
path
);
if
(
thumbnailPath
.
length
()
&&
QFileInfo
(
thumbnailPath
).
exists
()
)
if
(
thumbnailPath
.
length
()
&&
QFileInfo
(
thumbnailPath
).
exists
()
)
{
QFile
::
remove
(
thumbnailPath
);
}
...
...
@@ -368,7 +459,7 @@ void UBFeaturesController::deleteItem( const QUrl &url )
bool
UBFeaturesController
::
isTrash
(
const
QUrl
&
url
)
{
return
url
.
toLocalFile
().
startsWith
(
trashDirectoryPath
);
return
url
.
toLocalFile
().
startsWith
(
trashDirectoryPath
.
toLocalFile
()
);
}
UBFeaturesController
::~
UBFeaturesController
()
...
...
src/board/UBFeaturesController.h
View file @
56eceb66
...
...
@@ -4,9 +4,13 @@
#include <QMetaType>
#include <QObject>
#include <QWidget>
#include <QSet>
#include <QVector>
#include <QString>
#include <QPixmap>
#include <QMap>
#include <QUrl>
#include <QByteArray>
//#include "UBDockPaletteWidget.h"
...
...
@@ -19,7 +23,8 @@ enum UBFeatureElementType
FEATURE_INTERNAL
,
FEATURE_ITEM
,
FEATURE_TRASH
,
FEATURE_FAVORITE
FEATURE_FAVORITE
,
FEATURE_SEARCH
};
class
UBFeature
...
...
@@ -27,21 +32,30 @@ class UBFeature
public
:
UBFeature
()
{;}
//UBFeature(const UBFeature &f);
UBFeature
(
const
QString
&
url
,
const
QPixmap
&
icon
,
const
QString
&
name
,
const
Q
String
&
realPath
,
UBFeatureElementType
type
=
FEATURE_CATEGORY
);
UBFeature
(
const
QString
&
url
,
const
QPixmap
&
icon
,
const
QString
&
name
,
const
Q
Url
&
realPath
,
UBFeatureElementType
type
=
FEATURE_CATEGORY
);
virtual
~
UBFeature
()
{;}
QString
getName
()
const
{
return
mName
;
}
QPixmap
getThumbnail
()
const
{
return
mThumbnail
;}
QString
get
Url
()
const
{
return
virtualPath
;
}
QString
get
VirtualPath
()
const
{
return
virtualPath
;
}
//QString getPath() const { return mPath; };
QString
getFullPath
()
const
{
return
mPath
;
}
QUrl
getFullPath
()
const
{
return
mPath
;
}
QString
getFullVirtualPath
()
const
{
return
virtualPath
+
"/"
+
mName
;
}
QString
getUrl
()
const
;
UBFeatureElementType
getType
()
const
{
return
elementType
;
}
bool
isFolder
()
const
;
bool
isDeletable
()
const
;
bool
operator
==
(
const
UBFeature
&
f
)
const
;
bool
operator
!=
(
const
UBFeature
&
f
)
const
;
const
QMap
<
QString
,
QString
>
&
getMetadata
()
const
{
return
metadata
;
}
void
setMetadata
(
const
QMap
<
QString
,
QString
>
&
data
)
{
metadata
=
data
;
}
private
:
QString
virtualPath
;
QPixmap
mThumbnail
;
QString
mName
;
Q
String
mPath
;
Q
Url
mPath
;
UBFeatureElementType
elementType
;
QMap
<
QString
,
QString
>
metadata
;
};
Q_DECLARE_METATYPE
(
UBFeature
)
...
...
@@ -57,10 +71,14 @@ public:
const
QString
&
getRootPath
()
const
{
return
rootPath
;
}
void
addItemToPage
(
const
UBFeature
&
item
);
void
addItemToPage
(
const
UBFeature
&
item
);
void
addItemAsBackground
(
const
UBFeature
&
item
);
const
UBFeature
&
getCurrentElement
()
const
{
return
currentElement
;
}
void
setCurrentElement
(
const
UBFeature
&
elem
)
{
currentElement
=
elem
;
}
const
UBFeature
&
getTrashElement
()
const
{
return
trashElement
;
}
UBFeature
addDownloadedFile
(
const
QUrl
&
sourceUrl
,
const
QByteArray
&
pData
);
UBFeature
moveItemToFolder
(
const
QUrl
&
url
,
const
UBFeature
&
destination
);
UBFeature
copyItemToFolder
(
const
QUrl
&
url
,
const
UBFeature
&
destination
);
void
deleteItem
(
const
QUrl
&
url
);
...
...
@@ -71,34 +89,37 @@ public:
static
QString
fileNameFromUrl
(
const
QUrl
&
url
);
static
QPixmap
thumbnailForFile
(
const
QString
&
path
);
static
bool
isDeletable
(
const
QUrl
&
url
);
private
:
void
initDirectoryTree
();
void
fileSystemScan
(
const
Q
String
&
currPath
,
const
QString
&
currVirtualPath
);
void
fileSystemScan
(
const
Q
Url
&
currPath
,
const
QString
&
currVirtualPath
);
static
QPixmap
createThumbnail
(
const
QString
&
path
);
//void addImageToCurrentPage( const QString &path );
void
loadFavoriteList
();
void
saveFavoriteList
();
UBFeature
getDestinationForItem
(
const
QUrl
&
url
);
static
UBFeatureElementType
fileTypeFromUrl
(
const
QString
&
path
);
QList
<
UBFeature
>
*
featuresList
;
UBFeature
*
rootElement
;
Q
String
mUserAudioDirectoryPath
;
Q
String
mUserVideoDirectoryPath
;
Q
String
mUserPicturesDirectoryPath
;
Q
String
mUserInteractiveDirectoryPath
;
Q
String
mUserAnimationDirectoryPath
;
Q
Url
mUserAudioDirectoryPath
;
Q
Url
mUserVideoDirectoryPath
;
Q
Url
mUserPicturesDirectoryPath
;
Q
Url
mUserInteractiveDirectoryPath
;
Q
Url
mUserAnimationDirectoryPath
;
QString
libraryPath
;
QString
mLibAudioDirectoryPath
;
QString
mLibVideoDirectoryPath
;
QString
mLibPicturesDirectoryPath
;
QString
mLibInteractiveDirectoryPath
;
QString
mLibAnimationDirectoryPath
;
QString
mLibApplicationsDirectoryPath
;
QString
mLibShapesDirectoryPath
;
QString
trashDirectoryPath
;
QUrl
mLibAudioDirectoryPath
;
QUrl
mLibVideoDirectoryPath
;
QUrl
mLibPicturesDirectoryPath
;
QUrl
mLibInteractiveDirectoryPath
;
QUrl
mLibAnimationDirectoryPath
;
QUrl
mLibApplicationsDirectoryPath
;
QUrl
mLibShapesDirectoryPath
;
QUrl
trashDirectoryPath
;
QUrl
mLibSearchDirectoryPath
;
QString
rootPath
;
QString
audiosPath
;
...
...
@@ -115,8 +136,15 @@ private:
UBFeature
currentElement
;
UBFeature
trashElement
;
UBFeature
favoriteElement
;
QSet
<
QString
>
*
favoriteSet
;
UBFeature
audiosElement
;
UBFeature
moviesElement
;
UBFeature
picturesElement
;
UBFeature
interactElement
;
UBFeature
flashElement
;
UBFeature
shapesElement
;
UBFeature
webSearchElement
;
QSet
<
QUrl
>
*
favoriteSet
;
};
...
...
src/core/main.cpp
View file @
56eceb66
...
...
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
// Uncomment next section to have memory leaks information
// tracing in VC++ debug mode under Windows
/*
/*
#if defined(_MSC_VER) && defined(_DEBUG)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
...
...
src/customWidgets/UBActionableWidget.cpp
View file @
56eceb66
...
...
@@ -18,6 +18,8 @@
#include "UBActionableWidget.h"
#include "core/memcheck.h"
UBActionableWidget
::
UBActionableWidget
(
QWidget
*
parent
,
const
char
*
name
)
:
QWidget
(
parent
)
,
mShowActions
(
false
)
{
...
...
src/customWidgets/UBMediaWidget.cpp
View file @
56eceb66
...
...
@@ -16,6 +16,8 @@
#include "globals/UBGlobals.h"
#include "UBMediaWidget.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param type as the media type
...
...
src/domain/UBAbstractUndoCommand.cpp
View file @
56eceb66
...
...
@@ -15,6 +15,8 @@
#include "UBAbstractUndoCommand.h"
#include "core/memcheck.h"
UBAbstractUndoCommand
::
UBAbstractUndoCommand
()
{
// NOOP
...
...
src/domain/UBAngleWidget.cpp
View file @
56eceb66
#include "UBAngleWidget.h"
#include <QPainter>
#include "core/memcheck.h"
UBAngleWidget
::
UBAngleWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
{
...
...
src/domain/UBGraphicsDelegateFrame.cpp
View file @
56eceb66
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsDelegateFrame.h"
#include <QtGui>
#include <QtSvg>
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "domain/UBGraphicsItemDelegate.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsProxyWidget.h"
#include "gui/UBResources.h"
#include "core/memcheck.h"
UBGraphicsDelegateFrame
::
UBGraphicsDelegateFrame
(
UBGraphicsItemDelegate
*
pDelegate
,
QRectF
pRect
,
qreal
pFrameWidth
,
bool
respectRatio
)
:
QGraphicsRectItem
(),
QObject
(
pDelegate
)
,
mCurrentTool
(
None
)
,
mDelegate
(
pDelegate
)
,
mVisible
(
true
)
,
mFrameWidth
(
pFrameWidth
)
,
mNominalFrameWidth
(
pFrameWidth
)
,
mRespectRatio
(
respectRatio
)
,
mAngle
(
0
)
,
mAngleOffset
(
0
)
,
mTotalScaleX
(
-
1
)
,
mTotalScaleY
(
-
1
)
,
mTranslateX
(
0
)
,
mTranslateY
(
0
)
,
mTotalTranslateX
(
0
)
,
mTotalTranslateY
(
0
)
,
mOperationMode
(
Scaling
)
,
mMirrorX
(
false
)
,
mMirrorY
(
false
)
{
mAngleTolerance
=
UBSettings
::
settings
()
->
angleTolerance
->
get
().
toReal
();
setFlag
(
QGraphicsItem
::
ItemSendsGeometryChanges
,
true
);
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
setRect
(
pRect
.
adjusted
(
mFrameWidth
,
mFrameWidth
,
mFrameWidth
*
-
1
,
mFrameWidth
*
-
1
));
setBrush
(
QBrush
(
UBSettings
::
paletteColor
));
setPen
(
Qt
::
NoPen
);
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
mBottomRightResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resize.svg"
,
this
);
mBottomResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeBottom.svg"
,
this
);
mLeftResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeLeft.svg"
,
this
);
mRightResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeRight.svg"
,
this
);
mTopResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeTop.svg"
,
this
);
mBottomRightResizeGrip
=
new
QGraphicsRectItem
(
this
);
mBottomRightResizeGrip
->
setPen
(
Qt
::
NoPen
);
mBottomResizeGrip
=
new
QGraphicsRectItem
(
this
);
mBottomResizeGrip
->
setPen
(
Qt
::
NoPen
);
mLeftResizeGrip
=
new
QGraphicsRectItem
(
this
);
mLeftResizeGrip
->
setToolTip
(
"left"
);
mLeftResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRightResizeGrip
=
new
QGraphicsRectItem
(
this
);
mRightResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRightResizeGrip
->
setToolTip
(
"Right"
);
mTopResizeGrip
=
new
QGraphicsRectItem
(
this
);
mTopResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRotateButton
=
new
QGraphicsSvgItem
(
":/images/rotate.svg"
,
this
);
mRotateButton
->
setCursor
(
UBResources
::
resources
()
->
rotateCursor
);
mRotateButton
->
setVisible
(
mDelegate
->
canRotate
());
updateResizeCursors
();
setAntiScale
(
1.0
);
positionHandles
();
this
->
setAcceptHoverEvents
(
true
);
angleWidget
=
new
UBAngleWidget
();
}
UBGraphicsDelegateFrame
::~
UBGraphicsDelegateFrame
()
{
delete
angleWidget
;
// NOOP
}
void
UBGraphicsDelegateFrame
::
setAntiScale
(
qreal
pAntiScale
)
{
mFrameWidth
=
mNominalFrameWidth
*
pAntiScale
;
QTransform
tr
;
tr
.
scale
(
pAntiScale
,
pAntiScale
);
mBottomRightResizeGripSvgItem
->
setTransform
(
tr
);
mBottomResizeGripSvgItem
->
setTransform
(
tr
);
mLeftResizeGripSvgItem
->
setTransform
(
tr
);
mRightResizeGripSvgItem
->
setTransform
(
tr
);
mTopResizeGripSvgItem
->
setTransform
(
tr
);
mRotateButton
->
setTransform
(
tr
);
}
void
UBGraphicsDelegateFrame
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
Q_UNUSED
(
option
);
Q_UNUSED
(
widget
);
QPainterPath
path
;
path
.
addRoundedRect
(
rect
(),
mFrameWidth
/
2
,
mFrameWidth
/
2
);
if
(
rect
().
width
()
>
1
&&
rect
().
height
()
>
1
)
{
QPainterPath
extruded
;
extruded
.
addRect
(
rect
().
adjusted
(
mFrameWidth
,
mFrameWidth
,
(
mFrameWidth
*
-
1
),
(
mFrameWidth
*
-
1
)));
path
=
path
.
subtracted
(
extruded
);
}
painter
->
fillPath
(
path
,
brush
());
}
QPainterPath
UBGraphicsDelegateFrame
::
shape
()
const
{
QPainterPath
path
;
//We do not use the rounded rect here because we want the bottom right corner
//to be included in the frame (for resize grip handling : #702)
path
.
addRect
(
rect
());
if
(
rect
().
width
()
>
0
&&
rect
().
height
()
>
0
)
{
QPainterPath
extruded
;
extruded
.
addRect
(
rect
().
adjusted
(
mFrameWidth
,
mFrameWidth
,
mFrameWidth
*
-
1
,
mFrameWidth
*
-
1
));
path
=
path
.
subtracted
(
extruded
);
}
return
path
;
}
void
UBGraphicsDelegateFrame
::
initializeTransform
()
{
QTransform
itemTransform
=
delegated
()
->
sceneTransform
();
QRectF
itemRect
=
delegated
()
->
boundingRect
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
qreal
horizontalFlip
=
(
topLeft
.
x
()
>
topRight
.
x
())
?
-
1
:
1
;
mMirrorX
=
horizontalFlip
<
0
;
if
(
horizontalFlip
<
0
){
// why this is because of the way of calculating the translations that checks which side is the most is the
// nearest instead of checking which one is the left side.
QPointF
tmp
=
topLeft
;
topLeft
=
topRight
;
topRight
=
tmp
;
// because of the calculation of the height is done by lenght and not deltaY
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
}
qreal
verticalFlip
=
(
bottomLeft
.
y
()
<
topLeft
.
y
())
?
-
1
:
1
;
// not sure that is usefull
mMirrorY
=
verticalFlip
<
0
;
if
(
verticalFlip
<
0
&&
!
mMirrorX
){
topLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
topRight
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
bottomLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
}
QLineF
topLine
(
topLeft
,
topRight
);
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
width
=
topLine
.
length
();
qreal
height
=
leftLine
.
length
();
mAngle
=
topLine
.
angle
();
// the fact the the length is used we loose the horizontalFlip information
// a better way to do this is using DeltaX that preserve the direction information.
mTotalScaleX
=
(
width
/
itemRect
.
width
())
*
horizontalFlip
;
mTotalScaleY
=
height
/
itemRect
.
height
()
*
verticalFlip
;
QTransform
tr
;
QPointF
center
=
delegated
()
->
boundingRect
().
center
();
tr
.
translate
(
center
.
x
()
*
mTotalScaleX
,
center
.
y
()
*
mTotalScaleY
);
tr
.
rotate
(
-
mAngle
);
tr
.
translate
(
-
center
.
x
()
*
mTotalScaleX
,
-
center
.
y
()
*
mTotalScaleY
);
tr
.
scale
(
mTotalScaleX
,
mTotalScaleY
);
mTotalTranslateX
=
delegated
()
->
transform
().
dx
()
-
tr
.
dx
();
mTotalTranslateY
=
delegated
()
->
transform
().
dy
()
-
tr
.
dy
();
}
void
UBGraphicsDelegateFrame
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mDelegate
->
startUndoStep
();
mStartingPoint
=
event
->
scenePos
();
initializeTransform
();
mScaleX
=
1
;
mScaleY
=
1
;
mTranslateX
=
0
;
mTranslateY
=
0
;
mAngleOffset
=
0
;
mInitialTransform
=
buildTransform
();
mCurrentTool
=
toolFromPos
(
event
->
pos
());
event
->
accept
();
}
bool
UBGraphicsDelegateFrame
::
canResizeBottomRight
(
qreal
width
,
qreal
height
,
qreal
scaleFactor
)
{
bool
res
=
false
;
if
(
!
mMirrorX
&&
!
mMirrorX
&&
((
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
height
*
scaleFactor
)
>
2
*
mFrameWidth
)){
res
=
true
;
}
else
if
(
mMirrorX
&&
!
mMirrorY
&&
(
-
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
height
*
scaleFactor
)
>
2
*
mFrameWidth
){
res
=
true
;
}
else
if
(
!
mMirrorX
&&
mMirrorY
&&
(
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
-
height
*
scaleFactor
)
>
2
*
mFrameWidth
){
res
=
true
;
}
else
if
(
mMirrorX
&&
mMirrorY
&&
(
-
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
-
height
*
scaleFactor
)
>
2
*
mFrameWidth
){
res
=
true
;
}
return
res
;
}
void
UBGraphicsDelegateFrame
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
QLineF
move
(
mStartingPoint
,
event
->
scenePos
());
qreal
moveX
=
move
.
length
()
*
cos
((
move
.
angle
()
-
mAngle
)
*
PI
/
180
);
qreal
moveY
=
-
move
.
length
()
*
sin
((
move
.
angle
()
-
mAngle
)
*
PI
/
180
);
qreal
width
=
delegated
()
->
boundingRect
().
width
()
*
mTotalScaleX
;
qreal
height
=
delegated
()
->
boundingRect
().
height
()
*
mTotalScaleY
;
if
(
mOperationMode
==
Scaling
)
{
mTranslateX
=
moveX
;
// Perform the resize
if
(
resizingBottomRight
())
{
// -----------------------------------------------------
// ! We want to keep the aspect ratio with this resize !
// -----------------------------------------------------
qreal
scaleX
;
qreal
scaleY
;
if
(
!
mMirrorX
){
scaleX
=
(
width
+
moveX
)
/
width
;
}
else
{
scaleX
=
(
width
-
moveX
)
/
width
;
}
if
(
!
mMirrorY
){
scaleY
=
(
height
+
moveY
)
/
height
;
}
else
{
scaleY
=
(
height
-
moveY
)
/
height
;
}
qreal
scaleFactor
=
(
scaleX
+
scaleY
)
/
2
;
// Do not allow resizing of image size under frame size
if
(
canResizeBottomRight
(
width
,
height
,
scaleFactor
))
{
if
(
mRespectRatio
)
{
mScaleX
=
scaleFactor
;
mScaleY
=
scaleFactor
;
}
else
{
mScaleX
=
scaleX
;
mScaleY
=
scaleY
;
}
}
}
else
if
(
resizingLeft
()
||
resizingRight
())
{
if
(
width
!=
0
){
qreal
scaleX
=
0.0
;
if
(
resizingLeft
()){
scaleX
=
(
width
-
moveX
)
/
width
;
}
else
if
(
resizingRight
()){
scaleX
=
(
width
+
moveX
)
/
width
;
}
if
(
mDelegate
->
isFlippable
()
&&
qAbs
(
scaleX
)
!=
0
){
if
((
qAbs
(
width
*
scaleX
))
<
2
*
mFrameWidth
){
bool
negative
=
(
scaleX
<
0
)
?
true
:
false
;
if
(
negative
){
if
(
mMirrorX
)
scaleX
=
2
*
mFrameWidth
/
width
;
else
scaleX
=
-
2
*
mFrameWidth
/
width
;
}
else
{
scaleX
=
-
1
;
}
}
mScaleX
=
scaleX
;
}
else
if
(
scaleX
>
1
||
(
width
*
scaleX
)
>
2
*
mFrameWidth
){
mScaleX
=
scaleX
;
if
(
resizingLeft
()){
mTranslateX
=
moveX
;
}
}
}
}
else
if
(
resizingTop
()
||
resizingBottom
()){
if
(
height
!=
0
){
qreal
scaleY
=
0.0
;
if
(
resizingTop
()){
scaleY
=
(
height
-
moveY
)
/
height
;
}
else
if
(
resizingBottom
()){
scaleY
=
(
height
+
moveY
)
/
height
;
}
if
(
mDelegate
->
isFlippable
()
&&
qAbs
(
scaleY
)
!=
0
){
if
((
qAbs
(
height
*
scaleY
))
<
2
*
mFrameWidth
){
bool
negative
=
(
scaleY
<
0
)
?
true
:
false
;
if
(
negative
){
if
(
mMirrorY
)
scaleY
=
2
*
mFrameWidth
/
width
;
else
scaleY
=
-
2
*
mFrameWidth
/
width
;
}
else
{
scaleY
=
-
1
;
}
}
mScaleY
=
scaleY
;
}
else
if
(
scaleY
>
1
||
(
height
*
scaleY
)
>
2
*
mFrameWidth
)
{
mScaleY
=
scaleY
;
if
(
resizingTop
()){
mTranslateY
=
moveY
;
}
}
}
}
}
else
if
(
mOperationMode
==
Resizing
)
{
mTranslateX
=
moveX
;
UBResizableGraphicsItem
*
resizableItem
=
dynamic_cast
<
UBResizableGraphicsItem
*>
(
delegated
());
if
(
resizableItem
)
{
QLineF
mousePosDelta
(
delegated
()
->
mapFromScene
(
event
->
lastScenePos
())
,
delegated
()
->
mapFromScene
(
event
->
scenePos
()));
QSizeF
incVector
(
0
,
0
);
if
(
resizingBottomRight
())
{
incVector
=
QSizeF
(
mousePosDelta
.
dx
(),
mousePosDelta
.
dy
());
}
else
if
(
resizingRight
())
{
incVector
=
QSizeF
(
mousePosDelta
.
dx
(),
0
);
}
else
if
(
resizingBottom
())
{
incVector
=
QSizeF
(
0
,
mousePosDelta
.
dy
());
}
else
if
(
resizingLeft
())
{
incVector
=
QSizeF
(
-
mousePosDelta
.
dx
(),
0
);
}
else
if
(
resizingTop
())
{
incVector
=
QSizeF
(
0
,
-
mousePosDelta
.
dy
());
}
QSizeF
newSize
=
resizableItem
->
size
()
+
incVector
;
resizableItem
->
resize
(
newSize
);
}
}
if
(
rotating
())
{
mTranslateX
=
0
;
mTranslateY
=
0
;
QLineF
startLine
(
sceneBoundingRect
().
center
(),
event
->
lastScenePos
());
QLineF
currentLine
(
sceneBoundingRect
().
center
(),
event
->
scenePos
());
mAngle
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngle
%
45
>=
45
-
mAngleTolerance
||
(
int
)
mAngle
%
45
<=
mAngleTolerance
)
{
mAngle
=
qRound
(
mAngle
/
45
)
*
45
;
mAngleOffset
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngleOffset
%
360
>
mAngleTolerance
&&
(
int
)
mAngleOffset
%
360
<
360
-
mAngleTolerance
)
{
mAngle
+=
mAngleOffset
;
mAngleOffset
=
0
;
}
}
else
if
((
int
)
mAngle
%
30
>=
30
-
mAngleTolerance
||
(
int
)
mAngle
%
30
<=
mAngleTolerance
)
{
mAngle
=
qRound
(
mAngle
/
30
)
*
30
;
mAngleOffset
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngleOffset
%
360
>
mAngleTolerance
&&
(
int
)
mAngleOffset
%
360
<
360
-
mAngleTolerance
)
{
mAngle
+=
mAngleOffset
;
mAngleOffset
=
0
;
}
}
if
(
!
angleWidget
->
isVisible
())
angleWidget
->
show
();
angleWidget
->
setText
(
QString
::
number
((
int
)
mAngle
%
360
));
angleWidget
->
update
();
}
else
if
(
moving
())
{
mTranslateX
=
move
.
dx
();
mTranslateY
=
move
.
dy
();
}
QTransform
tr
=
buildTransform
();
//TODO UB 4.x: Could find a better solution ?
if
(
resizingRight
()
||
resizingBottom
()
||
resizingBottomRight
())
{
QPointF
ref
;
if
(
!
mMirrorX
&&
!
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topLeft
();
}
else
if
(
mMirrorX
&&
!
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topLeft
();
}
else
if
(
!
mMirrorX
&&
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topLeft
();
}
else
if
(
mMirrorX
&&
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topRight
();
}
// Map the item topleft point to the current mouse move transform
QPointF
topLeft
=
tr
.
map
(
ref
);
// Map the item topleft point to the mouse press transform
QPointF
fixedPoint
=
mInitialTransform
.
map
(
ref
);
// Update the translation coordinates
mTranslateX
+=
fixedPoint
.
x
()
-
topLeft
.
x
();
mTranslateY
+=
fixedPoint
.
y
()
-
topLeft
.
y
();
// Update the transform
tr
=
buildTransform
();
}
else
if
(
resizingTop
()
||
resizingLeft
())
{
if
(
mOperationMode
==
Scaling
)
{
QPointF
bottomRight
=
tr
.
map
(
delegated
()
->
boundingRect
().
bottomRight
());
QPointF
fixedPoint
=
mInitialTransform
.
map
(
delegated
()
->
boundingRect
().
bottomRight
());
mTranslateX
+=
fixedPoint
.
x
()
-
bottomRight
.
x
();
mTranslateY
+=
fixedPoint
.
y
()
-
bottomRight
.
y
();
}
else
{
QLineF
vector
;
if
(
resizingLeft
())
{
QPointF
topRight1
=
mInitialTransform
.
map
(
QPointF
(
delegated
()
->
boundingRect
().
width
()
-
moveX
,
0
));
QPointF
topRight2
=
mInitialTransform
.
map
(
QPointF
(
delegated
()
->
boundingRect
().
width
(),
0
));
vector
.
setPoints
(
topRight1
,
topRight2
);
}
else
{
QPointF
bottomLeft1
=
mInitialTransform
.
map
(
QPointF
(
0
,
delegated
()
->
boundingRect
().
height
()
-
moveY
));
QPointF
bottomLeft2
=
mInitialTransform
.
map
(
QPointF
(
0
,
delegated
()
->
boundingRect
().
height
()));
vector
.
setPoints
(
bottomLeft1
,
bottomLeft2
);
}
mTranslateX
=
vector
.
dx
();
mTranslateY
=
vector
.
dy
();
}
tr
=
buildTransform
();
}
delegated
()
->
setTransform
(
tr
);
event
->
accept
();
}
QTransform
UBGraphicsDelegateFrame
::
buildTransform
()
{
QTransform
tr
;
QPointF
center
=
delegated
()
->
boundingRect
().
center
();
// Translate
tr
.
translate
(
mTotalTranslateX
+
mTranslateX
,
mTotalTranslateY
+
mTranslateY
);
// Set angle
tr
.
translate
(
center
.
x
()
*
mTotalScaleX
*
mScaleX
,
center
.
y
()
*
mTotalScaleY
*
mScaleY
);
tr
.
rotate
(
-
mAngle
);
tr
.
translate
(
-
center
.
x
()
*
mTotalScaleX
*
mScaleX
,
-
center
.
y
()
*
mTotalScaleY
*
mScaleY
);
// Scale
tr
.
scale
(
mTotalScaleX
*
mScaleX
,
mTotalScaleY
*
mScaleY
);
return
tr
;
}
void
UBGraphicsDelegateFrame
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
angleWidget
->
isVisible
())
angleWidget
->
hide
();
updateResizeCursors
();
mDelegate
->
commitUndoStep
();
mTotalScaleX
*=
mScaleX
;
mTotalScaleY
*=
mScaleY
;
mTotalTranslateX
+=
mTranslateX
;
mTotalTranslateY
+=
mTranslateY
;
event
->
accept
();
mCurrentTool
=
None
;
QGraphicsRectItem
::
mouseReleaseEvent
(
event
);
// Show the buttons
if
(
isResizing
()){
mResizing
=
false
;
}
mDelegate
->
setButtonsVisible
(
true
);
}
void
UBGraphicsDelegateFrame
::
updateResizeCursors
()
{
QPixmap
pix
(
":/images/cursors/resize.png"
);
QTransform
tr
;
tr
.
rotate
(
-
mAngle
);
QCursor
resizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
mLeftResizeGrip
->
setCursor
(
resizeCursor
);
mRightResizeGrip
->
setCursor
(
resizeCursor
);
tr
.
rotate
(
-
90
);
resizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
mBottomResizeGrip
->
setCursor
(
resizeCursor
);
mTopResizeGrip
->
setCursor
(
resizeCursor
);
tr
.
rotate
(
-
45
);
resizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
mBottomRightResizeGrip
->
setCursor
(
resizeCursor
);
}
void
UBGraphicsDelegateFrame
::
setVisible
(
bool
visible
)
{
mVisible
=
visible
;
if
(
mVisible
)
setBrush
(
QBrush
(
UBSettings
::
paletteColor
));
else
setBrush
(
Qt
::
NoBrush
);
}
void
UBGraphicsDelegateFrame
::
positionHandles
()
{
QRectF
itemRect
=
delegated
()
->
boundingRect
();
QTransform
itemTransform
=
delegated
()
->
sceneTransform
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
QPointF
bottomRight
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
QPointF
center
=
itemTransform
.
map
(
itemRect
.
center
());
int
rotateHeight
=
QLineF
(
topLeft
,
bottomLeft
).
length
();
// Handle the mirroring
if
(
topLeft
.
x
()
>
topRight
.
x
()){
QPointF
topTmp
=
topRight
;
QPointF
bottomTmp
=
bottomRight
;
topRight
=
topLeft
;
topLeft
=
topTmp
;
bottomRight
=
bottomLeft
;
bottomLeft
=
bottomTmp
;
}
if
(
bottomLeft
.
y
()
>
topLeft
.
y
()){
QPointF
leftTmp
=
bottomLeft
;
QPointF
rightTmp
=
bottomRight
;
bottomLeft
=
topLeft
;
topLeft
=
leftTmp
;
bottomRight
=
topRight
;
topRight
=
rightTmp
;
}
QLineF
topLine
(
topLeft
,
topRight
);
qreal
angle
=
topLine
.
angle
();
qreal
width
=
topLine
.
length
();
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
height
=
leftLine
.
length
();
int
h
=
rotating
()
?
rotateHeight
:
height
;
if
(
mVisible
)
{
setRect
(
center
.
x
()
-
mFrameWidth
-
width
/
2
,
center
.
y
()
-
mFrameWidth
-
h
/
2
,
width
+
2
*
mFrameWidth
,
h
+
2
*
mFrameWidth
);
}
else
{
setRect
(
center
.
x
()
-
width
/
2
,
center
.
y
()
-
h
/
2
,
width
,
h
);
}
resetTransform
();
translate
(
center
.
x
(),
center
.
y
());
rotate
(
-
angle
);
translate
(
-
center
.
x
(),
-
center
.
y
());
mBottomRightResizeGripSvgItem
->
setParentItem
(
this
);
mBottomResizeGripSvgItem
->
setParentItem
(
this
);
mLeftResizeGripSvgItem
->
setParentItem
(
this
);
mRightResizeGripSvgItem
->
setParentItem
(
this
);
mTopResizeGripSvgItem
->
setParentItem
(
this
);
mRotateButton
->
setParentItem
(
this
);
mBottomRightResizeGrip
->
setParentItem
(
this
);
mBottomResizeGrip
->
setParentItem
(
this
);
mLeftResizeGrip
->
setParentItem
(
this
);
mRightResizeGrip
->
setParentItem
(
this
);
mTopResizeGrip
->
setParentItem
(
this
);
QRectF
brRect
=
mBottomRightResizeGripSvgItem
->
mapRectToParent
(
mBottomRightResizeGripSvgItem
->
boundingRect
());
QRectF
bRect
=
mBottomResizeGripSvgItem
->
mapRectToParent
(
mBottomResizeGripSvgItem
->
boundingRect
());
QRectF
lRect
=
mLeftResizeGripSvgItem
->
mapRectToParent
(
mLeftResizeGripSvgItem
->
boundingRect
());
QRectF
rRect
=
mRightResizeGripSvgItem
->
mapRectToParent
(
mRightResizeGripSvgItem
->
boundingRect
());
QRectF
trRect
=
mTopResizeGripSvgItem
->
mapRectToParent
(
mTopResizeGripSvgItem
->
boundingRect
());
mBottomRightResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
brRect
.
width
(),
rect
().
bottom
()
-
brRect
.
height
());
mBottomResizeGripSvgItem
->
setPos
(
rect
().
center
().
x
()
-
bRect
.
width
()
/
2
,
rect
().
bottom
()
-
bRect
.
height
());
mLeftResizeGripSvgItem
->
setPos
(
rect
().
left
(),
rect
().
center
().
y
()
-
lRect
.
height
()
/
2
);
mRightResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
rRect
.
width
(),
rect
().
center
().
y
()
-
rRect
.
height
()
/
2
);
mTopResizeGripSvgItem
->
setPos
(
rect
().
center
().
x
()
-
trRect
.
width
()
/
2
,
rect
().
y
());
mRotateButton
->
setPos
(
rect
().
right
()
-
mFrameWidth
-
5
,
rect
().
top
()
+
5
);
mBottomRightResizeGrip
->
setRect
(
bottomRightResizeGripRect
());
mBottomResizeGrip
->
setRect
(
bottomResizeGripRect
());
mLeftResizeGrip
->
setRect
(
leftResizeGripRect
());
mRightResizeGrip
->
setRect
(
rightResizeGripRect
());
mTopResizeGrip
->
setRect
(
topResizeGripRect
());
QVariant
vLocked
=
delegated
()
->
data
(
UBGraphicsItemData
::
ItemLocked
);
bool
isLocked
=
(
vLocked
.
isValid
()
&&
vLocked
.
toBool
());
mBottomRightResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mBottomResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mLeftResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mRightResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mTopResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mRotateButton
->
setVisible
(
mDelegate
->
canRotate
()
&&
!
isLocked
);
mBottomRightResizeGrip
->
setVisible
(
!
isLocked
);
mBottomResizeGrip
->
setVisible
(
!
isLocked
);
mLeftResizeGrip
->
setVisible
(
!
isLocked
);
mRightResizeGrip
->
setVisible
(
!
isLocked
);
mTopResizeGrip
->
setVisible
(
!
isLocked
);
if
(
isLocked
)
{
QColor
baseColor
=
UBSettings
::
paletteColor
;
baseColor
.
setAlphaF
(
baseColor
.
alphaF
()
/
3
);
setBrush
(
QBrush
(
baseColor
));
}
else
{
setBrush
(
QBrush
(
UBSettings
::
paletteColor
));
}
//make frame interact like delegated item when selected. Maybe should be deleted if selection logic will change
setZValue
(
delegated
()
->
zValue
());
}
QGraphicsItem
*
UBGraphicsDelegateFrame
::
delegated
()
{
return
mDelegate
->
delegated
();
}
UBGraphicsDelegateFrame
::
FrameTool
UBGraphicsDelegateFrame
::
toolFromPos
(
QPointF
pos
)
{
if
(
mDelegate
->
isLocked
())
return
None
;
else
if
(
bottomRightResizeGripRect
().
contains
(
pos
))
return
ResizeBottomRight
;
else
if
(
bottomResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorY
){
return
ResizeTop
;
}
else
{
return
ResizeBottom
;
}
}
else
if
(
leftResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorX
){
return
ResizeRight
;
}
else
{
return
ResizeLeft
;
}
return
ResizeLeft
;
}
else
if
(
rightResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorX
){
return
ResizeLeft
;
}
else
{
return
ResizeRight
;
}
}
else
if
(
topResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorY
){
return
ResizeBottom
;
}
else
{
return
ResizeTop
;
}
}
else
if
(
rotateButtonBounds
().
contains
(
pos
)
&&
mDelegate
&&
mDelegate
->
canRotate
())
return
Rotate
;
else
return
Move
;
}
QRectF
UBGraphicsDelegateFrame
::
bottomRightResizeGripRect
()
const
{
return
QRectF
(
rect
().
right
()
-
mFrameWidth
,
rect
().
bottom
()
-
mFrameWidth
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
bottomResizeGripRect
()
const
{
return
QRectF
(
rect
().
center
().
x
()
-
mFrameWidth
/
2
,
rect
().
bottom
()
-
mFrameWidth
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
leftResizeGripRect
()
const
{
return
QRectF
(
rect
().
left
(),
rect
().
center
().
y
()
-
mFrameWidth
/
2
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
rightResizeGripRect
()
const
{
return
QRectF
(
rect
().
right
()
-
mFrameWidth
,
rect
().
center
().
y
()
-
mFrameWidth
/
2
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
topResizeGripRect
()
const
{
return
QRectF
(
rect
().
center
().
x
()
-
mFrameWidth
/
2
,
rect
().
top
(),
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
rotateButtonBounds
()
const
{
return
QRectF
(
rect
().
right
()
-
mFrameWidth
,
rect
().
top
(),
mFrameWidth
,
mFrameWidth
);
}
void
UBGraphicsDelegateFrame
::
refreshGeometry
()
{
// Here we want to have the left on the left, the right on the right, the top on the top and the bottom on the bottom!
QRectF
itemRect
=
delegated
()
->
boundingRect
();
QTransform
itemTransform
=
delegated
()
->
sceneTransform
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
QLineF
topLine
(
topLeft
,
topRight
);
qreal
width
=
topLine
.
length
();
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
height
=
leftLine
.
length
();
setRect
(
topRight
.
x
()
-
mFrameWidth
,
topLeft
.
y
()
-
mFrameWidth
,
width
+
2
*
mFrameWidth
,
height
+
2
*
mFrameWidth
);
}
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UBGraphicsDelegateFrame.h"
#include <QtGui>
#include <QtSvg>
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "domain/UBGraphicsItemDelegate.h"
#include "domain/UBGraphicsScene.h"
#include "domain/UBGraphicsProxyWidget.h"
#include "gui/UBResources.h"
#include "core/memcheck.h"
UBGraphicsDelegateFrame
::
UBGraphicsDelegateFrame
(
UBGraphicsItemDelegate
*
pDelegate
,
QRectF
pRect
,
qreal
pFrameWidth
,
bool
respectRatio
)
:
QGraphicsRectItem
(),
QObject
(
pDelegate
)
,
mCurrentTool
(
None
)
,
mDelegate
(
pDelegate
)
,
mVisible
(
true
)
,
mFrameWidth
(
pFrameWidth
)
,
mNominalFrameWidth
(
pFrameWidth
)
,
mRespectRatio
(
respectRatio
)
,
mAngle
(
0
)
,
mAngleOffset
(
0
)
,
mTotalScaleX
(
-
1
)
,
mTotalScaleY
(
-
1
)
,
mTranslateX
(
0
)
,
mTranslateY
(
0
)
,
mTotalTranslateX
(
0
)
,
mTotalTranslateY
(
0
)
,
mOperationMode
(
Scaling
)
,
mMirrorX
(
false
)
,
mMirrorY
(
false
)
{
mAngleTolerance
=
UBSettings
::
settings
()
->
angleTolerance
->
get
().
toReal
();
setFlag
(
QGraphicsItem
::
ItemSendsGeometryChanges
,
true
);
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
setRect
(
pRect
.
adjusted
(
mFrameWidth
,
mFrameWidth
,
mFrameWidth
*
-
1
,
mFrameWidth
*
-
1
));
setBrush
(
QBrush
(
UBSettings
::
paletteColor
));
setPen
(
Qt
::
NoPen
);
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
mBottomRightResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resize.svg"
,
this
);
mBottomResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeBottom.svg"
,
this
);
mLeftResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeLeft.svg"
,
this
);
mRightResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeRight.svg"
,
this
);
mTopResizeGripSvgItem
=
new
QGraphicsSvgItem
(
":/images/resizeTop.svg"
,
this
);
mBottomRightResizeGrip
=
new
QGraphicsRectItem
(
this
);
mBottomRightResizeGrip
->
setPen
(
Qt
::
NoPen
);
mBottomResizeGrip
=
new
QGraphicsRectItem
(
this
);
mBottomResizeGrip
->
setPen
(
Qt
::
NoPen
);
mLeftResizeGrip
=
new
QGraphicsRectItem
(
this
);
mLeftResizeGrip
->
setToolTip
(
"left"
);
mLeftResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRightResizeGrip
=
new
QGraphicsRectItem
(
this
);
mRightResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRightResizeGrip
->
setToolTip
(
"Right"
);
mTopResizeGrip
=
new
QGraphicsRectItem
(
this
);
mTopResizeGrip
->
setPen
(
Qt
::
NoPen
);
mRotateButton
=
new
QGraphicsSvgItem
(
":/images/rotate.svg"
,
this
);
mRotateButton
->
setCursor
(
UBResources
::
resources
()
->
rotateCursor
);
mRotateButton
->
setVisible
(
mDelegate
->
canRotate
());
updateResizeCursors
();
setAntiScale
(
1.0
);
positionHandles
();
this
->
setAcceptHoverEvents
(
true
);
angleWidget
=
new
UBAngleWidget
();
}
UBGraphicsDelegateFrame
::~
UBGraphicsDelegateFrame
()
{
delete
angleWidget
;
// NOOP
}
void
UBGraphicsDelegateFrame
::
setAntiScale
(
qreal
pAntiScale
)
{
mFrameWidth
=
mNominalFrameWidth
*
pAntiScale
;
QTransform
tr
;
tr
.
scale
(
pAntiScale
,
pAntiScale
);
mBottomRightResizeGripSvgItem
->
setTransform
(
tr
);
mBottomResizeGripSvgItem
->
setTransform
(
tr
);
mLeftResizeGripSvgItem
->
setTransform
(
tr
);
mRightResizeGripSvgItem
->
setTransform
(
tr
);
mTopResizeGripSvgItem
->
setTransform
(
tr
);
mRotateButton
->
setTransform
(
tr
);
}
void
UBGraphicsDelegateFrame
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
Q_UNUSED
(
option
);
Q_UNUSED
(
widget
);
QPainterPath
path
;
path
.
addRoundedRect
(
rect
(),
mFrameWidth
/
2
,
mFrameWidth
/
2
);
if
(
rect
().
width
()
>
1
&&
rect
().
height
()
>
1
)
{
QPainterPath
extruded
;
extruded
.
addRect
(
rect
().
adjusted
(
mFrameWidth
,
mFrameWidth
,
(
mFrameWidth
*
-
1
),
(
mFrameWidth
*
-
1
)));
path
=
path
.
subtracted
(
extruded
);
}
painter
->
fillPath
(
path
,
brush
());
}
QPainterPath
UBGraphicsDelegateFrame
::
shape
()
const
{
QPainterPath
path
;
//We do not use the rounded rect here because we want the bottom right corner
//to be included in the frame (for resize grip handling : #702)
path
.
addRect
(
rect
());
if
(
rect
().
width
()
>
0
&&
rect
().
height
()
>
0
)
{
QPainterPath
extruded
;
extruded
.
addRect
(
rect
().
adjusted
(
mFrameWidth
,
mFrameWidth
,
mFrameWidth
*
-
1
,
mFrameWidth
*
-
1
));
path
=
path
.
subtracted
(
extruded
);
}
return
path
;
}
void
UBGraphicsDelegateFrame
::
initializeTransform
()
{
QTransform
itemTransform
=
delegated
()
->
sceneTransform
();
QRectF
itemRect
=
delegated
()
->
boundingRect
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
qreal
horizontalFlip
=
(
topLeft
.
x
()
>
topRight
.
x
())
?
-
1
:
1
;
mMirrorX
=
horizontalFlip
<
0
;
if
(
horizontalFlip
<
0
){
// why this is because of the way of calculating the translations that checks which side is the most is the
// nearest instead of checking which one is the left side.
QPointF
tmp
=
topLeft
;
topLeft
=
topRight
;
topRight
=
tmp
;
// because of the calculation of the height is done by lenght and not deltaY
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
}
qreal
verticalFlip
=
(
bottomLeft
.
y
()
<
topLeft
.
y
())
?
-
1
:
1
;
// not sure that is usefull
mMirrorY
=
verticalFlip
<
0
;
if
(
verticalFlip
<
0
&&
!
mMirrorX
){
topLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
topRight
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
bottomLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
}
QLineF
topLine
(
topLeft
,
topRight
);
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
width
=
topLine
.
length
();
qreal
height
=
leftLine
.
length
();
mAngle
=
topLine
.
angle
();
// the fact the the length is used we loose the horizontalFlip information
// a better way to do this is using DeltaX that preserve the direction information.
mTotalScaleX
=
(
width
/
itemRect
.
width
())
*
horizontalFlip
;
mTotalScaleY
=
height
/
itemRect
.
height
()
*
verticalFlip
;
QTransform
tr
;
QPointF
center
=
delegated
()
->
boundingRect
().
center
();
tr
.
translate
(
center
.
x
()
*
mTotalScaleX
,
center
.
y
()
*
mTotalScaleY
);
tr
.
rotate
(
-
mAngle
);
tr
.
translate
(
-
center
.
x
()
*
mTotalScaleX
,
-
center
.
y
()
*
mTotalScaleY
);
tr
.
scale
(
mTotalScaleX
,
mTotalScaleY
);
mTotalTranslateX
=
delegated
()
->
transform
().
dx
()
-
tr
.
dx
();
mTotalTranslateY
=
delegated
()
->
transform
().
dy
()
-
tr
.
dy
();
}
void
UBGraphicsDelegateFrame
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mDelegate
->
startUndoStep
();
mStartingPoint
=
event
->
scenePos
();
initializeTransform
();
mScaleX
=
1
;
mScaleY
=
1
;
mTranslateX
=
0
;
mTranslateY
=
0
;
mAngleOffset
=
0
;
mInitialTransform
=
buildTransform
();
mCurrentTool
=
toolFromPos
(
event
->
pos
());
event
->
accept
();
}
bool
UBGraphicsDelegateFrame
::
canResizeBottomRight
(
qreal
width
,
qreal
height
,
qreal
scaleFactor
)
{
bool
res
=
false
;
if
(
!
mMirrorX
&&
!
mMirrorX
&&
((
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
height
*
scaleFactor
)
>
2
*
mFrameWidth
)){
res
=
true
;
}
else
if
(
mMirrorX
&&
!
mMirrorY
&&
(
-
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
height
*
scaleFactor
)
>
2
*
mFrameWidth
){
res
=
true
;
}
else
if
(
!
mMirrorX
&&
mMirrorY
&&
(
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
-
height
*
scaleFactor
)
>
2
*
mFrameWidth
){
res
=
true
;
}
else
if
(
mMirrorX
&&
mMirrorY
&&
(
-
width
*
scaleFactor
)
>
2
*
mFrameWidth
&&
(
-
height
*
scaleFactor
)
>
2
*
mFrameWidth
){
res
=
true
;
}
return
res
;
}
void
UBGraphicsDelegateFrame
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
QLineF
move
(
mStartingPoint
,
event
->
scenePos
());
qreal
moveX
=
move
.
length
()
*
cos
((
move
.
angle
()
-
mAngle
)
*
PI
/
180
);
qreal
moveY
=
-
move
.
length
()
*
sin
((
move
.
angle
()
-
mAngle
)
*
PI
/
180
);
qreal
width
=
delegated
()
->
boundingRect
().
width
()
*
mTotalScaleX
;
qreal
height
=
delegated
()
->
boundingRect
().
height
()
*
mTotalScaleY
;
if
(
mOperationMode
==
Scaling
)
{
mTranslateX
=
moveX
;
// Perform the resize
if
(
resizingBottomRight
())
{
// -----------------------------------------------------
// ! We want to keep the aspect ratio with this resize !
// -----------------------------------------------------
qreal
scaleX
;
qreal
scaleY
;
if
(
!
mMirrorX
){
scaleX
=
(
width
+
moveX
)
/
width
;
}
else
{
scaleX
=
(
width
-
moveX
)
/
width
;
}
if
(
!
mMirrorY
){
scaleY
=
(
height
+
moveY
)
/
height
;
}
else
{
scaleY
=
(
height
-
moveY
)
/
height
;
}
qreal
scaleFactor
=
(
scaleX
+
scaleY
)
/
2
;
// Do not allow resizing of image size under frame size
if
(
canResizeBottomRight
(
width
,
height
,
scaleFactor
))
{
if
(
mRespectRatio
)
{
mScaleX
=
scaleFactor
;
mScaleY
=
scaleFactor
;
}
else
{
mScaleX
=
scaleX
;
mScaleY
=
scaleY
;
}
}
}
else
if
(
resizingLeft
()
||
resizingRight
())
{
if
(
width
!=
0
){
qreal
scaleX
=
0.0
;
if
(
resizingLeft
()){
scaleX
=
(
width
-
moveX
)
/
width
;
}
else
if
(
resizingRight
()){
scaleX
=
(
width
+
moveX
)
/
width
;
}
if
(
mDelegate
->
isFlippable
()
&&
qAbs
(
scaleX
)
!=
0
){
if
((
qAbs
(
width
*
scaleX
))
<
2
*
mFrameWidth
){
bool
negative
=
(
scaleX
<
0
)
?
true
:
false
;
if
(
negative
){
if
(
mMirrorX
)
scaleX
=
2
*
mFrameWidth
/
width
;
else
scaleX
=
-
2
*
mFrameWidth
/
width
;
}
else
{
scaleX
=
-
1
;
}
}
mScaleX
=
scaleX
;
}
else
if
(
scaleX
>
1
||
(
width
*
scaleX
)
>
2
*
mFrameWidth
){
mScaleX
=
scaleX
;
if
(
resizingLeft
()){
mTranslateX
=
moveX
;
}
}
}
}
else
if
(
resizingTop
()
||
resizingBottom
()){
if
(
height
!=
0
){
qreal
scaleY
=
0.0
;
if
(
resizingTop
()){
scaleY
=
(
height
-
moveY
)
/
height
;
}
else
if
(
resizingBottom
()){
scaleY
=
(
height
+
moveY
)
/
height
;
}
if
(
mDelegate
->
isFlippable
()
&&
qAbs
(
scaleY
)
!=
0
){
if
((
qAbs
(
height
*
scaleY
))
<
2
*
mFrameWidth
){
bool
negative
=
(
scaleY
<
0
)
?
true
:
false
;
if
(
negative
){
if
(
mMirrorY
)
scaleY
=
2
*
mFrameWidth
/
width
;
else
scaleY
=
-
2
*
mFrameWidth
/
width
;
}
else
{
scaleY
=
-
1
;
}
}
mScaleY
=
scaleY
;
}
else
if
(
scaleY
>
1
||
(
height
*
scaleY
)
>
2
*
mFrameWidth
)
{
mScaleY
=
scaleY
;
if
(
resizingTop
()){
mTranslateY
=
moveY
;
}
}
}
}
}
else
if
(
mOperationMode
==
Resizing
)
{
mTranslateX
=
moveX
;
UBResizableGraphicsItem
*
resizableItem
=
dynamic_cast
<
UBResizableGraphicsItem
*>
(
delegated
());
if
(
resizableItem
)
{
QLineF
mousePosDelta
(
delegated
()
->
mapFromScene
(
event
->
lastScenePos
())
,
delegated
()
->
mapFromScene
(
event
->
scenePos
()));
QSizeF
incVector
(
0
,
0
);
if
(
resizingBottomRight
())
{
incVector
=
QSizeF
(
mousePosDelta
.
dx
(),
mousePosDelta
.
dy
());
}
else
if
(
resizingRight
())
{
incVector
=
QSizeF
(
mousePosDelta
.
dx
(),
0
);
}
else
if
(
resizingBottom
())
{
incVector
=
QSizeF
(
0
,
mousePosDelta
.
dy
());
}
else
if
(
resizingLeft
())
{
incVector
=
QSizeF
(
-
mousePosDelta
.
dx
(),
0
);
}
else
if
(
resizingTop
())
{
incVector
=
QSizeF
(
0
,
-
mousePosDelta
.
dy
());
}
QSizeF
newSize
=
resizableItem
->
size
()
+
incVector
;
if
(
!
(
mDelegate
->
getToolBarItem
()
->
isVisibleOnBoard
()
&&
(
newSize
.
width
()
<
mDelegate
->
getToolBarItem
()
->
minWidth
()
/
mDelegate
->
antiScaleRatio
()
||
newSize
.
height
()
<
mDelegate
->
getToolBarItem
()
->
minWidth
()
/
mDelegate
->
antiScaleRatio
()
*
3
/
4
)))
resizableItem
->
resize
(
newSize
);
}
}
if
(
rotating
())
{
mTranslateX
=
0
;
mTranslateY
=
0
;
QLineF
startLine
(
sceneBoundingRect
().
center
(),
event
->
lastScenePos
());
QLineF
currentLine
(
sceneBoundingRect
().
center
(),
event
->
scenePos
());
mAngle
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngle
%
45
>=
45
-
mAngleTolerance
||
(
int
)
mAngle
%
45
<=
mAngleTolerance
)
{
mAngle
=
qRound
(
mAngle
/
45
)
*
45
;
mAngleOffset
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngleOffset
%
360
>
mAngleTolerance
&&
(
int
)
mAngleOffset
%
360
<
360
-
mAngleTolerance
)
{
mAngle
+=
mAngleOffset
;
mAngleOffset
=
0
;
}
}
else
if
((
int
)
mAngle
%
30
>=
30
-
mAngleTolerance
||
(
int
)
mAngle
%
30
<=
mAngleTolerance
)
{
mAngle
=
qRound
(
mAngle
/
30
)
*
30
;
mAngleOffset
+=
startLine
.
angleTo
(
currentLine
);
if
((
int
)
mAngleOffset
%
360
>
mAngleTolerance
&&
(
int
)
mAngleOffset
%
360
<
360
-
mAngleTolerance
)
{
mAngle
+=
mAngleOffset
;
mAngleOffset
=
0
;
}
}
if
(
!
angleWidget
->
isVisible
())
angleWidget
->
show
();
angleWidget
->
setText
(
QString
::
number
((
int
)
mAngle
%
360
));
angleWidget
->
update
();
}
else
if
(
moving
())
{
mTranslateX
=
move
.
dx
();
mTranslateY
=
move
.
dy
();
}
QTransform
tr
=
buildTransform
();
//TODO UB 4.x: Could find a better solution ?
if
(
resizingRight
()
||
resizingBottom
()
||
resizingBottomRight
())
{
QPointF
ref
;
if
(
!
mMirrorX
&&
!
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topLeft
();
}
else
if
(
mMirrorX
&&
!
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topLeft
();
}
else
if
(
!
mMirrorX
&&
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topLeft
();
}
else
if
(
mMirrorX
&&
mMirrorY
){
ref
=
delegated
()
->
boundingRect
().
topRight
();
}
// Map the item topleft point to the current mouse move transform
QPointF
topLeft
=
tr
.
map
(
ref
);
// Map the item topleft point to the mouse press transform
QPointF
fixedPoint
=
mInitialTransform
.
map
(
ref
);
// Update the translation coordinates
mTranslateX
+=
fixedPoint
.
x
()
-
topLeft
.
x
();
mTranslateY
+=
fixedPoint
.
y
()
-
topLeft
.
y
();
// Update the transform
tr
=
buildTransform
();
}
else
if
(
resizingTop
()
||
resizingLeft
())
{
if
(
mOperationMode
==
Scaling
)
{
QPointF
bottomRight
=
tr
.
map
(
delegated
()
->
boundingRect
().
bottomRight
());
QPointF
fixedPoint
=
mInitialTransform
.
map
(
delegated
()
->
boundingRect
().
bottomRight
());
mTranslateX
+=
fixedPoint
.
x
()
-
bottomRight
.
x
();
mTranslateY
+=
fixedPoint
.
y
()
-
bottomRight
.
y
();
}
else
{
QLineF
vector
;
if
(
resizingLeft
())
{
QPointF
topRight1
=
mInitialTransform
.
map
(
QPointF
(
delegated
()
->
boundingRect
().
width
()
-
moveX
,
0
));
QPointF
topRight2
=
mInitialTransform
.
map
(
QPointF
(
delegated
()
->
boundingRect
().
width
(),
0
));
vector
.
setPoints
(
topRight1
,
topRight2
);
}
else
{
QPointF
bottomLeft1
=
mInitialTransform
.
map
(
QPointF
(
0
,
delegated
()
->
boundingRect
().
height
()
-
moveY
));
QPointF
bottomLeft2
=
mInitialTransform
.
map
(
QPointF
(
0
,
delegated
()
->
boundingRect
().
height
()));
vector
.
setPoints
(
bottomLeft1
,
bottomLeft2
);
}
mTranslateX
=
vector
.
dx
();
mTranslateY
=
vector
.
dy
();
}
tr
=
buildTransform
();
}
delegated
()
->
setTransform
(
tr
);
event
->
accept
();
}
QTransform
UBGraphicsDelegateFrame
::
buildTransform
()
{
QTransform
tr
;
QPointF
center
=
delegated
()
->
boundingRect
().
center
();
// Translate
tr
.
translate
(
mTotalTranslateX
+
mTranslateX
,
mTotalTranslateY
+
mTranslateY
);
// Set angle
tr
.
translate
(
center
.
x
()
*
mTotalScaleX
*
mScaleX
,
center
.
y
()
*
mTotalScaleY
*
mScaleY
);
tr
.
rotate
(
-
mAngle
);
tr
.
translate
(
-
center
.
x
()
*
mTotalScaleX
*
mScaleX
,
-
center
.
y
()
*
mTotalScaleY
*
mScaleY
);
// Scale
tr
.
scale
(
mTotalScaleX
*
mScaleX
,
mTotalScaleY
*
mScaleY
);
return
tr
;
}
void
UBGraphicsDelegateFrame
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
angleWidget
->
isVisible
())
angleWidget
->
hide
();
updateResizeCursors
();
mDelegate
->
commitUndoStep
();
mTotalScaleX
*=
mScaleX
;
mTotalScaleY
*=
mScaleY
;
mTotalTranslateX
+=
mTranslateX
;
mTotalTranslateY
+=
mTranslateY
;
event
->
accept
();
mCurrentTool
=
None
;
QGraphicsRectItem
::
mouseReleaseEvent
(
event
);
// Show the buttons
if
(
isResizing
()){
mResizing
=
false
;
}
mDelegate
->
setButtonsVisible
(
true
);
}
void
UBGraphicsDelegateFrame
::
updateResizeCursors
()
{
QPixmap
pix
(
":/images/cursors/resize.png"
);
QTransform
tr
;
tr
.
rotate
(
-
mAngle
);
QCursor
resizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
mLeftResizeGrip
->
setCursor
(
resizeCursor
);
mRightResizeGrip
->
setCursor
(
resizeCursor
);
tr
.
rotate
(
-
90
);
resizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
mBottomResizeGrip
->
setCursor
(
resizeCursor
);
mTopResizeGrip
->
setCursor
(
resizeCursor
);
tr
.
rotate
(
-
45
);
resizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
mBottomRightResizeGrip
->
setCursor
(
resizeCursor
);
}
void
UBGraphicsDelegateFrame
::
setVisible
(
bool
visible
)
{
mVisible
=
visible
;
if
(
mVisible
)
setBrush
(
QBrush
(
UBSettings
::
paletteColor
));
else
setBrush
(
Qt
::
NoBrush
);
}
void
UBGraphicsDelegateFrame
::
positionHandles
()
{
QRectF
itemRect
=
delegated
()
->
boundingRect
();
if
(
mDelegate
->
getToolBarItem
()
->
isVisibleOnBoard
()
&&
mDelegate
->
getToolBarItem
()
->
isShifting
())
itemRect
.
setHeight
(
itemRect
.
height
()
+
mDelegate
->
getToolBarItem
()
->
rect
().
height
()
*
mDelegate
->
antiScaleRatio
()
*
1.1
);
QTransform
itemTransform
=
delegated
()
->
sceneTransform
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
QPointF
bottomRight
=
itemTransform
.
map
(
itemRect
.
bottomRight
());
QPointF
center
=
itemTransform
.
map
(
itemRect
.
center
());
int
rotateHeight
=
QLineF
(
topLeft
,
bottomLeft
).
length
();
// Handle the mirroring
if
(
topLeft
.
x
()
>
topRight
.
x
()){
QPointF
topTmp
=
topRight
;
QPointF
bottomTmp
=
bottomRight
;
topRight
=
topLeft
;
topLeft
=
topTmp
;
bottomRight
=
bottomLeft
;
bottomLeft
=
bottomTmp
;
}
if
(
bottomLeft
.
y
()
>
topLeft
.
y
()){
QPointF
leftTmp
=
bottomLeft
;
QPointF
rightTmp
=
bottomRight
;
bottomLeft
=
topLeft
;
topLeft
=
leftTmp
;
bottomRight
=
topRight
;
topRight
=
rightTmp
;
}
QLineF
topLine
(
topLeft
,
topRight
);
qreal
angle
=
topLine
.
angle
();
qreal
width
=
topLine
.
length
();
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
height
=
leftLine
.
length
();
int
h
=
rotating
()
?
rotateHeight
:
height
;
if
(
mVisible
)
{
setRect
(
center
.
x
()
-
mFrameWidth
-
width
/
2
,
center
.
y
()
-
mFrameWidth
-
h
/
2
,
width
+
2
*
mFrameWidth
,
h
+
2
*
mFrameWidth
);
}
else
{
setRect
(
center
.
x
()
-
width
/
2
,
center
.
y
()
-
h
/
2
,
width
,
h
);
}
resetTransform
();
translate
(
center
.
x
(),
center
.
y
());
rotate
(
-
angle
);
translate
(
-
center
.
x
(),
-
center
.
y
());
mBottomRightResizeGripSvgItem
->
setParentItem
(
this
);
mBottomResizeGripSvgItem
->
setParentItem
(
this
);
mLeftResizeGripSvgItem
->
setParentItem
(
this
);
mRightResizeGripSvgItem
->
setParentItem
(
this
);
mTopResizeGripSvgItem
->
setParentItem
(
this
);
mRotateButton
->
setParentItem
(
this
);
mBottomRightResizeGrip
->
setParentItem
(
this
);
mBottomResizeGrip
->
setParentItem
(
this
);
mLeftResizeGrip
->
setParentItem
(
this
);
mRightResizeGrip
->
setParentItem
(
this
);
mTopResizeGrip
->
setParentItem
(
this
);
QRectF
brRect
=
mBottomRightResizeGripSvgItem
->
mapRectToParent
(
mBottomRightResizeGripSvgItem
->
boundingRect
());
QRectF
bRect
=
mBottomResizeGripSvgItem
->
mapRectToParent
(
mBottomResizeGripSvgItem
->
boundingRect
());
QRectF
lRect
=
mLeftResizeGripSvgItem
->
mapRectToParent
(
mLeftResizeGripSvgItem
->
boundingRect
());
QRectF
rRect
=
mRightResizeGripSvgItem
->
mapRectToParent
(
mRightResizeGripSvgItem
->
boundingRect
());
QRectF
trRect
=
mTopResizeGripSvgItem
->
mapRectToParent
(
mTopResizeGripSvgItem
->
boundingRect
());
mBottomRightResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
brRect
.
width
(),
rect
().
bottom
()
-
brRect
.
height
());
mBottomResizeGripSvgItem
->
setPos
(
rect
().
center
().
x
()
-
bRect
.
width
()
/
2
,
rect
().
bottom
()
-
bRect
.
height
());
mLeftResizeGripSvgItem
->
setPos
(
rect
().
left
(),
rect
().
center
().
y
()
-
lRect
.
height
()
/
2
);
mRightResizeGripSvgItem
->
setPos
(
rect
().
right
()
-
rRect
.
width
(),
rect
().
center
().
y
()
-
rRect
.
height
()
/
2
);
mTopResizeGripSvgItem
->
setPos
(
rect
().
center
().
x
()
-
trRect
.
width
()
/
2
,
rect
().
y
());
mRotateButton
->
setPos
(
rect
().
right
()
-
mFrameWidth
-
5
,
rect
().
top
()
+
5
);
mBottomRightResizeGrip
->
setRect
(
bottomRightResizeGripRect
());
mBottomResizeGrip
->
setRect
(
bottomResizeGripRect
());
mLeftResizeGrip
->
setRect
(
leftResizeGripRect
());
mRightResizeGrip
->
setRect
(
rightResizeGripRect
());
mTopResizeGrip
->
setRect
(
topResizeGripRect
());
QVariant
vLocked
=
delegated
()
->
data
(
UBGraphicsItemData
::
ItemLocked
);
bool
isLocked
=
(
vLocked
.
isValid
()
&&
vLocked
.
toBool
());
mBottomRightResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mBottomResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mLeftResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mRightResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mTopResizeGripSvgItem
->
setVisible
(
!
isLocked
);
mRotateButton
->
setVisible
(
mDelegate
->
canRotate
()
&&
!
isLocked
);
mBottomRightResizeGrip
->
setVisible
(
!
isLocked
);
mBottomResizeGrip
->
setVisible
(
!
isLocked
);
mLeftResizeGrip
->
setVisible
(
!
isLocked
);
mRightResizeGrip
->
setVisible
(
!
isLocked
);
mTopResizeGrip
->
setVisible
(
!
isLocked
);
if
(
isLocked
)
{
QColor
baseColor
=
UBSettings
::
paletteColor
;
baseColor
.
setAlphaF
(
baseColor
.
alphaF
()
/
3
);
setBrush
(
QBrush
(
baseColor
));
}
else
{
setBrush
(
QBrush
(
UBSettings
::
paletteColor
));
}
//make frame interact like delegated item when selected. Maybe should be deleted if selection logic will change
setZValue
(
delegated
()
->
zValue
());
}
QGraphicsItem
*
UBGraphicsDelegateFrame
::
delegated
()
{
return
mDelegate
->
delegated
();
}
UBGraphicsDelegateFrame
::
FrameTool
UBGraphicsDelegateFrame
::
toolFromPos
(
QPointF
pos
)
{
if
(
mDelegate
->
isLocked
())
return
None
;
else
if
(
bottomRightResizeGripRect
().
contains
(
pos
))
return
ResizeBottomRight
;
else
if
(
bottomResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorY
){
return
ResizeTop
;
}
else
{
return
ResizeBottom
;
}
}
else
if
(
leftResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorX
){
return
ResizeRight
;
}
else
{
return
ResizeLeft
;
}
return
ResizeLeft
;
}
else
if
(
rightResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorX
){
return
ResizeLeft
;
}
else
{
return
ResizeRight
;
}
}
else
if
(
topResizeGripRect
().
contains
(
pos
)){
if
(
mMirrorY
){
return
ResizeBottom
;
}
else
{
return
ResizeTop
;
}
}
else
if
(
rotateButtonBounds
().
contains
(
pos
)
&&
mDelegate
&&
mDelegate
->
canRotate
())
return
Rotate
;
else
return
Move
;
}
QRectF
UBGraphicsDelegateFrame
::
bottomRightResizeGripRect
()
const
{
return
QRectF
(
rect
().
right
()
-
mFrameWidth
,
rect
().
bottom
()
-
mFrameWidth
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
bottomResizeGripRect
()
const
{
return
QRectF
(
rect
().
center
().
x
()
-
mFrameWidth
/
2
,
rect
().
bottom
()
-
mFrameWidth
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
leftResizeGripRect
()
const
{
return
QRectF
(
rect
().
left
(),
rect
().
center
().
y
()
-
mFrameWidth
/
2
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
rightResizeGripRect
()
const
{
return
QRectF
(
rect
().
right
()
-
mFrameWidth
,
rect
().
center
().
y
()
-
mFrameWidth
/
2
,
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
topResizeGripRect
()
const
{
return
QRectF
(
rect
().
center
().
x
()
-
mFrameWidth
/
2
,
rect
().
top
(),
mFrameWidth
,
mFrameWidth
);
}
QRectF
UBGraphicsDelegateFrame
::
rotateButtonBounds
()
const
{
return
QRectF
(
rect
().
right
()
-
mFrameWidth
,
rect
().
top
(),
mFrameWidth
,
mFrameWidth
);
}
void
UBGraphicsDelegateFrame
::
refreshGeometry
()
{
// Here we want to have the left on the left, the right on the right, the top on the top and the bottom on the bottom!
QRectF
itemRect
=
delegated
()
->
boundingRect
();
QTransform
itemTransform
=
delegated
()
->
sceneTransform
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
QLineF
topLine
(
topLeft
,
topRight
);
qreal
width
=
topLine
.
length
();
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
height
=
leftLine
.
length
();
setRect
(
topRight
.
x
()
-
mFrameWidth
,
topLeft
.
y
()
-
mFrameWidth
,
width
+
2
*
mFrameWidth
,
height
+
2
*
mFrameWidth
);
}
src/domain/UBGraphicsItemDelegate.cpp
View file @
56eceb66
...
...
@@ -37,6 +37,9 @@
#include "UBGraphicsWidgetItem.h"
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsVideoItem.h"
#include "web/UBWebController.h"
...
...
@@ -47,6 +50,27 @@
class
UBGraphicsParaschoolEditorWidgetItem
;
DelegateButton
::
DelegateButton
(
const
QString
&
fileName
,
QGraphicsItem
*
pDelegated
,
QGraphicsItem
*
parent
,
Qt
::
WindowFrameSection
section
)
:
QGraphicsSvgItem
(
fileName
,
parent
)
,
mDelegated
(
pDelegated
)
,
mIsTransparentToMouseEvent
(
false
)
,
mButtonAlignmentSection
(
section
)
{
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
}
DelegateButton
::~
DelegateButton
()
{
// NOOP
}
void
DelegateButton
::
setFileName
(
const
QString
&
fileName
)
{
QGraphicsSvgItem
::
setSharedRenderer
(
new
QSvgRenderer
(
fileName
,
this
));
}
void
DelegateButton
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
// make sure delegate is selected, to avoid control being hidden
...
...
@@ -93,6 +117,8 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
void
UBGraphicsItemDelegate
::
init
()
{
mToolBarItem
=
new
UBGraphicsToolBarItem
(
delegated
());
mFrame
=
new
UBGraphicsDelegateFrame
(
this
,
QRectF
(
0
,
0
,
0
,
0
),
mFrameWidth
,
mRespectRatio
);
mFrame
->
hide
();
mFrame
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
...
...
@@ -123,10 +149,13 @@ void UBGraphicsItemDelegate::init()
foreach
(
DelegateButton
*
button
,
mButtons
)
{
if
(
button
->
getSection
()
!=
Qt
::
TitleBarArea
)
{
button
->
hide
();
button
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
}
}
}
UBGraphicsItemDelegate
::~
UBGraphicsItemDelegate
()
...
...
@@ -292,13 +321,20 @@ void UBGraphicsItemDelegate::positionHandles()
updateButtons
(
true
);
if
(
mToolBarItem
->
isVisibleOnBoard
())
{
updateToolBar
();
mToolBarItem
->
show
();
}
}
else
{
foreach
(
DelegateButton
*
button
,
mButtons
)
button
->
hide
();
mFrame
->
hide
();
mToolBarItem
->
hide
();
}
}
void
UBGraphicsItemDelegate
::
setZOrderButtonsVisible
(
bool
visible
)
{
if
(
visible
)
{
...
...
@@ -335,6 +371,7 @@ void UBGraphicsItemDelegate::remove(bool canUndo)
scene
->
removeItem
(
mFrame
);
scene
->
removeItem
(
mDelegated
);
scene
->
removeItem
(
mToolBarItem
);
if
(
canUndo
)
{
...
...
@@ -577,14 +614,16 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
int
i
=
1
,
j
=
0
,
k
=
0
;
while
((
i
+
j
+
k
)
<
mButtons
.
size
())
{
DelegateButton
*
button
=
mButtons
[
i
+
j
];
button
->
setParentItem
(
mFrame
);
button
->
setTransform
(
tr
);
if
(
button
->
getSection
()
==
Qt
::
TopLeftSection
)
{
button
->
setParentItem
(
mFrame
);
button
->
setPos
(
topX
+
(
i
++
*
1.6
*
mFrameWidth
*
mAntiScaleRatio
),
topY
);
button
->
setTransform
(
tr
);
}
else
if
(
button
->
getSection
()
==
Qt
::
BottomLeftSection
)
{
button
->
setParentItem
(
mFrame
);
button
->
setPos
(
bottomX
+
(
++
j
*
1.6
*
mFrameWidth
*
mAntiScaleRatio
),
bottomY
);
}
else
if
(
button
->
getSection
()
==
Qt
::
NoSection
)
{
button
->
setTransform
(
tr
);
}
else
if
(
button
->
getSection
()
==
Qt
::
TitleBarArea
||
button
->
getSection
()
==
Qt
::
NoSection
){
++
k
;
}
if
(
!
button
->
scene
())
...
...
@@ -599,9 +638,65 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated)
}
}
void
UBGraphicsItemDelegate
::
updateToolBar
()
{
QTransform
transformForToolbarButtons
;
transformForToolbarButtons
.
scale
(
mAntiScaleRatio
,
1
);
QRectF
toolBarRect
=
mToolBarItem
->
rect
();
toolBarRect
.
setWidth
(
delegated
()
->
boundingRect
().
width
()
-
10
);
mToolBarItem
->
setRect
(
toolBarRect
);
if
(
mToolBarItem
->
isShifting
())
mToolBarItem
->
setPos
(
delegated
()
->
boundingRect
().
bottomLeft
()
+
QPointF
(
5
*
mAntiScaleRatio
,
0
));
else
mToolBarItem
->
setPos
(
delegated
()
->
boundingRect
().
bottomLeft
()
-
QPointF
(
-
5
*
mAntiScaleRatio
,
mToolBarItem
->
rect
().
height
()
*
1.1
*
mAntiScaleRatio
));
int
offsetOnToolBar
=
5
*
mAntiScaleRatio
;
QList
<
QGraphicsItem
*>
itemList
=
mToolBarItem
->
itemsOnToolBar
();
foreach
(
QGraphicsItem
*
item
,
itemList
)
{
item
->
setPos
(
offsetOnToolBar
,
0
);
offsetOnToolBar
+=
(
item
->
boundingRect
().
width
()
+
5
)
*
mAntiScaleRatio
;
item
->
setTransform
(
transformForToolbarButtons
);
item
->
show
();
}
mToolBarItem
->
setOffsetOnToolBar
(
offsetOnToolBar
);
QTransform
tr
;
tr
.
scale
(
1
,
mAntiScaleRatio
);
mToolBarItem
->
setTransform
(
tr
);
}
void
UBGraphicsItemDelegate
::
setButtonsVisible
(
bool
visible
)
{
foreach
(
DelegateButton
*
pButton
,
mButtons
){
pButton
->
setVisible
(
visible
);
}
}
UBGraphicsToolBarItem
::
UBGraphicsToolBarItem
(
QGraphicsItem
*
parent
)
:
QGraphicsRectItem
(
parent
),
mShifting
(
true
),
mVisible
(
false
),
mMinWidth
(
200
)
{
QRectF
rect
=
this
->
rect
();
rect
.
setHeight
(
26
);
this
->
setRect
(
rect
);
setBrush
(
QColor
(
UBSettings
::
paletteColor
));
setPen
(
Qt
::
NoPen
);
hide
();
}
void
UBGraphicsToolBarItem
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
Q_UNUSED
(
option
);
Q_UNUSED
(
widget
);
QPainterPath
path
;
path
.
addRoundedRect
(
rect
(),
10
,
10
);
painter
->
fillPath
(
path
,
brush
());
}
\ No newline at end of file
src/domain/UBGraphicsItemDelegate.h
View file @
56eceb66
...
...
@@ -35,30 +35,16 @@ class DelegateButton: public QGraphicsSvgItem
Q_OBJECT
public
:
DelegateButton
(
const
QString
&
fileName
,
QGraphicsItem
*
pDelegated
,
QGraphicsItem
*
parent
=
0
,
Qt
::
WindowFrameSection
section
=
Qt
::
TopLeftSection
)
:
QGraphicsSvgItem
(
fileName
,
parent
)
,
mDelegated
(
pDelegated
)
,
mIsTransparentToMouseEvent
(
false
)
,
mButtonAlignmentSection
(
section
)
{
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
}
DelegateButton
(
const
QString
&
fileName
,
QGraphicsItem
*
pDelegated
,
QGraphicsItem
*
parent
=
0
,
Qt
::
WindowFrameSection
section
=
Qt
::
TopLeftSection
);
virtual
~
DelegateButton
()
{
// NOOP
}
virtual
~
DelegateButton
();
void
setTransparentToMouseEvent
(
bool
tr
)
{
mIsTransparentToMouseEvent
=
tr
;
}
void
setFileName
(
const
QString
&
fileName
)
{
QGraphicsSvgItem
::
setSharedRenderer
(
new
QSvgRenderer
(
fileName
,
this
));
}
void
setFileName
(
const
QString
&
fileName
);
void
setSection
(
Qt
::
WindowFrameSection
section
)
{
mButtonAlignmentSection
=
section
;}
Qt
::
WindowFrameSection
getSection
()
const
{
return
mButtonAlignmentSection
;}
...
...
@@ -84,6 +70,31 @@ class DelegateButton: public QGraphicsSvgItem
};
class
UBGraphicsToolBarItem
:
public
QGraphicsRectItem
,
public
QObject
{
public
:
UBGraphicsToolBarItem
(
QGraphicsItem
*
parent
=
0
);
virtual
~
UBGraphicsToolBarItem
()
{};
bool
isVisibleOnBoard
()
const
{
return
mVisible
;
}
void
setVisibleOnBoard
(
bool
visible
)
{
mVisible
=
visible
;
}
bool
isShifting
()
const
{
return
mShifting
;
}
void
setShifting
(
bool
shifting
)
{
mShifting
=
shifting
;
}
int
offsetOnToolBar
()
const
{
return
mOffsetOnToolBar
;
}
void
setOffsetOnToolBar
(
int
pOffset
)
{
mOffsetOnToolBar
=
pOffset
;
}
QList
<
QGraphicsItem
*>
itemsOnToolBar
()
const
{
return
mItemsOnToolBar
;
}
void
setItemsOnToolBar
(
QList
<
QGraphicsItem
*>
itemsOnToolBar
)
{
mItemsOnToolBar
=
itemsOnToolBar
;}
int
minWidth
()
{
return
mMinWidth
;
}
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
private
:
bool
mShifting
;
bool
mVisible
;
int
mOffsetOnToolBar
;
int
mMinWidth
;
QList
<
QGraphicsItem
*>
mItemsOnToolBar
;
};
class
UBGraphicsItemDelegate
:
public
QObject
{
...
...
@@ -138,6 +149,10 @@ class UBGraphicsItemDelegate : public QObject
void
setButtonsVisible
(
bool
visible
);
UBGraphicsToolBarItem
*
getToolBarItem
()
const
{
return
mToolBarItem
;
}
qreal
antiScaleRatio
()
const
{
return
mAntiScaleRatio
;
}
signals
:
void
showOnDisplayChanged
(
bool
shown
);
void
lockChanged
(
bool
locked
);
...
...
@@ -183,12 +198,17 @@ class UBGraphicsItemDelegate : public QObject
QList
<
DelegateButton
*>
mButtons
;
UBGraphicsToolBarItem
*
mToolBarItem
;
protected
slots
:
virtual
void
gotoContentSource
(
bool
checked
);
private
:
void
updateFrame
();
void
updateButtons
(
bool
showUpdated
=
false
);
void
updateToolBar
();
QPointF
mOffset
;
QTransform
mPreviousTransform
;
...
...
src/domain/UBGraphicsItemUndoCommand.cpp
View file @
56eceb66
...
...
@@ -19,12 +19,12 @@
#include "UBGraphicsScene.h"
#include "core/memcheck.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
UBGraphicsItemUndoCommand
::
UBGraphicsItemUndoCommand
(
UBGraphicsScene
*
pScene
,
const
QSet
<
QGraphicsItem
*>&
pRemovedItems
,
const
QSet
<
QGraphicsItem
*>&
pAddedItems
)
:
mScene
(
pScene
)
...
...
src/domain/UBGraphicsMediaItem.cpp
View file @
56eceb66
...
...
@@ -23,10 +23,10 @@
#include "board/UBBoardController.h"
#include "core/memcheck.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h"
bool
UBGraphicsMediaItem
::
sIsMutedByDefault
=
false
;
UBGraphicsMediaItem
::
UBGraphicsMediaItem
(
const
QUrl
&
pMediaFileUrl
,
QGraphicsItem
*
parent
)
...
...
src/domain/UBGraphicsStrokesGroup.cpp
View file @
56eceb66
#include "UBGraphicsStrokesGroup.h"
#include "core/memcheck.h"
UBGraphicsStrokesGroup
::
UBGraphicsStrokesGroup
(
QGraphicsItem
*
parent
)
:
QGraphicsItemGroup
(
parent
)
{
mDelegate
=
new
UBGraphicsItemDelegate
(
this
,
0
,
true
,
true
);
...
...
src/domain/UBGraphicsTextItemDelegate.cpp
View file @
56eceb66
...
...
@@ -24,9 +24,10 @@
#include "domain/UBGraphicsDelegateFrame.h"
#include "core/UBSettings.h"
#include "core/memcheck.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
const
int
UBGraphicsTextItemDelegate
::
sMinPixelSize
=
8
;
const
int
UBGraphicsTextItemDelegate
::
sMinPointSize
=
8
;
...
...
@@ -94,17 +95,21 @@ void UBGraphicsTextItemDelegate::buildButtons()
{
UBGraphicsItemDelegate
::
buildButtons
();
mFontButton
=
new
DelegateButton
(
":/images/font.svg"
,
mDelegated
,
m
Frame
,
Qt
::
TopLeftSection
);
mColorButton
=
new
DelegateButton
(
":/images/color.svg"
,
mDelegated
,
m
Frame
,
Qt
::
TopLeftSection
);
mDecreaseSizeButton
=
new
DelegateButton
(
":/images/minus.svg"
,
mDelegated
,
m
Frame
,
Qt
::
TopLeftSection
);
mIncreaseSizeButton
=
new
DelegateButton
(
":/images/plus.svg"
,
mDelegated
,
m
Frame
,
Qt
::
TopLeftSection
);
mFontButton
=
new
DelegateButton
(
":/images/font.svg"
,
mDelegated
,
m
ToolBarItem
,
Qt
::
TitleBarArea
);
mColorButton
=
new
DelegateButton
(
":/images/color.svg"
,
mDelegated
,
m
ToolBarItem
,
Qt
::
TitleBarArea
);
mDecreaseSizeButton
=
new
DelegateButton
(
":/images/minus.svg"
,
mDelegated
,
m
ToolBarItem
,
Qt
::
TitleBarArea
);
mIncreaseSizeButton
=
new
DelegateButton
(
":/images/plus.svg"
,
mDelegated
,
m
ToolBarItem
,
Qt
::
TitleBarArea
);
connect
(
mFontButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
pickFont
()));
connect
(
mColorButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
pickColor
()));
connect
(
mDecreaseSizeButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
decreaseSize
()));
connect
(
mIncreaseSizeButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
increaseSize
()));
mButtons
<<
mFontButton
<<
mColorButton
<<
mDecreaseSizeButton
<<
mIncreaseSizeButton
;
QList
<
QGraphicsItem
*>
itemsOnToolBar
;
itemsOnToolBar
<<
mFontButton
<<
mColorButton
<<
mDecreaseSizeButton
<<
mIncreaseSizeButton
;
mToolBarItem
->
setItemsOnToolBar
(
itemsOnToolBar
);
mToolBarItem
->
setVisibleOnBoard
(
true
);
}
void
UBGraphicsTextItemDelegate
::
contentsChanged
()
...
...
src/domain/UBGraphicsVideoItemDelegate.cpp
View file @
56eceb66
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui>
#include <QtSvg>
#include "UBGraphicsVideoItemDelegate.h"
#include "UBGraphicsScene.h"
#include "core/UBSettings.h"
#include "core/UBApplication.h"
#include "core/UBApplicationController.h"
#include "core/UBDisplayManager.h"
#include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsDelegateFrame.h"
#include "core/memcheck.h"
UBGraphicsVideoItemDelegate
::
UBGraphicsVideoItemDelegate
(
UBGraphicsVideoItem
*
pDelegated
,
Phonon
::
MediaObject
*
pMedia
,
QObject
*
parent
)
:
UBGraphicsItemDelegate
(
pDelegated
,
parent
,
true
,
false
)
,
mMedia
(
pMedia
)
{
// NOOP
}
void
UBGraphicsVideoItemDelegate
::
buildButtons
()
{
mPlayPauseButton
=
new
DelegateButton
(
":/images/play.svg"
,
mDelegated
,
mFrame
);
mStopButton
=
new
DelegateButton
(
":/images/stop.svg"
,
mDelegated
,
mFrame
);
mStopButton
->
hide
();
if
(
delegated
()
->
isMuted
())
mMuteButton
=
new
DelegateButton
(
":/images/soundOff.svg"
,
mDelegated
,
mFrame
);
else
mMuteButton
=
new
DelegateButton
(
":/images/soundOn.svg"
,
mDelegated
,
mFrame
);
mMuteButton
->
hide
();
mVideoControl
=
new
DelegateVideoControl
(
delegated
(),
mFrame
);
UBGraphicsItem
::
assignZValue
(
mVideoControl
,
delegated
()
->
zValue
());
mVideoControl
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
connect
(
mPlayPauseButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
togglePlayPause
()));
connect
(
mStopButton
,
SIGNAL
(
clicked
(
bool
)),
mMedia
,
SLOT
(
stop
()));
connect
(
mMuteButton
,
SIGNAL
(
clicked
(
bool
)),
delegated
(),
SLOT
(
toggleMute
()));
connect
(
mMuteButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
toggleMute
()));
mButtons
<<
mPlayPauseButton
<<
mStopButton
<<
mMuteButton
;
mMedia
->
setTickInterval
(
50
);
connect
(
mMedia
,
SIGNAL
(
stateChanged
(
Phonon
::
State
,
Phonon
::
State
)),
this
,
SLOT
(
mediaStateChanged
(
Phonon
::
State
,
Phonon
::
State
)));
connect
(
mMedia
,
SIGNAL
(
finished
()),
this
,
SLOT
(
updatePlayPauseState
()));
connect
(
mMedia
,
SIGNAL
(
tick
(
qint64
)),
this
,
SLOT
(
updateTicker
(
qint64
)));
connect
(
mMedia
,
SIGNAL
(
totalTimeChanged
(
qint64
)),
this
,
SLOT
(
totalTimeChanged
(
qint64
)));
}
UBGraphicsVideoItemDelegate
::~
UBGraphicsVideoItemDelegate
()
{
//NOOP
}
void
UBGraphicsVideoItemDelegate
::
positionHandles
()
{
UBGraphicsItemDelegate
::
positionHandles
();
if
(
mDelegated
->
isSelected
())
{
qreal
scaledFrameWidth
=
mFrameWidth
*
mAntiScaleRatio
;
qreal
width
=
mFrame
->
rect
().
width
();
qreal
height
=
mFrame
->
rect
().
height
();
qreal
x
=
mFrame
->
rect
().
left
();
qreal
y
=
mFrame
->
rect
().
top
();
mVideoControl
->
setRect
(
x
+
2
*
scaledFrameWidth
,
y
+
height
-
3
*
scaledFrameWidth
,
width
-
4
*
scaledFrameWidth
,
2
*
scaledFrameWidth
);
if
(
!
mVideoControl
->
scene
())
{
mVideoControl
->
setParentItem
(
mFrame
);
//update parent for the case the item has been previously removed from scene
mDelegated
->
scene
()
->
addItem
(
mVideoControl
);
}
mVideoControl
->
setAntiScale
(
mAntiScaleRatio
);
mVideoControl
->
setZValue
(
delegated
()
->
zValue
());
mVideoControl
->
show
();
}
else
{
mVideoControl
->
hide
();
}
}
void
UBGraphicsVideoItemDelegate
::
remove
(
bool
canUndo
)
{
if
(
delegated
()
&&
delegated
()
->
mediaObject
())
delegated
()
->
mediaObject
()
->
stop
();
QGraphicsScene
*
scene
=
mDelegated
->
scene
();
scene
->
removeItem
(
mVideoControl
);
UBGraphicsItemDelegate
::
remove
(
canUndo
);
}
void
UBGraphicsVideoItemDelegate
::
toggleMute
()
{
if
(
delegated
()
->
isMuted
())
mMuteButton
->
setFileName
(
":/images/soundOff.svg"
);
else
mMuteButton
->
setFileName
(
":/images/soundOn.svg"
);
}
UBGraphicsVideoItem
*
UBGraphicsVideoItemDelegate
::
delegated
()
{
return
static_cast
<
UBGraphicsVideoItem
*>
(
mDelegated
);
}
void
UBGraphicsVideoItemDelegate
::
togglePlayPause
()
{
if
(
delegated
()
&&
delegated
()
->
mediaObject
())
{
Phonon
::
MediaObject
*
media
=
delegated
()
->
mediaObject
();
if
(
media
->
state
()
==
Phonon
::
StoppedState
)
{
media
->
play
();
}
else
if
(
media
->
state
()
==
Phonon
::
PlayingState
)
{
if
(
media
->
remainingTime
()
<=
0
)
{
media
->
stop
();
media
->
play
();
}
else
{
media
->
pause
();
if
(
delegated
()
->
scene
())
delegated
()
->
scene
()
->
setModified
(
true
);
}
}
else
if
(
media
->
state
()
==
Phonon
::
PausedState
)
{
if
(
media
->
remainingTime
()
<=
0
)
{
media
->
stop
();
}
media
->
play
();
}
else
if
(
media
->
state
()
==
Phonon
::
LoadingState
)
{
delegated
()
->
mediaObject
()
->
setCurrentSource
(
delegated
()
->
mediaFileUrl
());
media
->
play
();
}
else
if
(
media
->
state
()
==
Phonon
::
ErrorState
){
qDebug
()
<<
"Error appeared."
<<
media
->
errorString
();
}
}
}
void
UBGraphicsVideoItemDelegate
::
mediaStateChanged
(
Phonon
::
State
newstate
,
Phonon
::
State
oldstate
)
{
Q_UNUSED
(
newstate
);
Q_UNUSED
(
oldstate
);
updatePlayPauseState
();
}
void
UBGraphicsVideoItemDelegate
::
updatePlayPauseState
()
{
Phonon
::
MediaObject
*
media
=
delegated
()
->
mediaObject
();
if
(
media
->
state
()
==
Phonon
::
PlayingState
)
mPlayPauseButton
->
setFileName
(
":/images/pause.svg"
);
else
mPlayPauseButton
->
setFileName
(
":/images/play.svg"
);
}
void
UBGraphicsVideoItemDelegate
::
updateTicker
(
qint64
time
)
{
Phonon
::
MediaObject
*
media
=
delegated
()
->
mediaObject
();
mVideoControl
->
totalTimeChanged
(
media
->
totalTime
());
mVideoControl
->
updateTicker
(
time
);
}
void
UBGraphicsVideoItemDelegate
::
totalTimeChanged
(
qint64
newTotalTime
)
{
mVideoControl
->
totalTimeChanged
(
newTotalTime
);
}
DelegateVideoControl
::
DelegateVideoControl
(
UBGraphicsVideoItem
*
pDelegated
,
QGraphicsItem
*
parent
)
:
QGraphicsRectItem
(
parent
)
,
mDelegate
(
pDelegated
)
,
mDisplayCurrentTime
(
false
)
,
mAntiScale
(
1.0
)
,
mCurrentTimeInMs
(
0
)
,
mTotalTimeInMs
(
0
)
{
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
setBrush
(
QBrush
(
UBSettings
::
paletteColor
));
setPen
(
Qt
::
NoPen
);
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
}
void
DelegateVideoControl
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
Q_UNUSED
(
option
);
Q_UNUSED
(
widget
);
painter
->
fillPath
(
shape
(),
brush
());
qreal
frameWidth
=
rect
().
height
()
/
2
;
int
position
=
frameWidth
;
if
(
mTotalTimeInMs
>
0
)
{
position
=
frameWidth
+
(
rect
().
width
()
-
(
2
*
frameWidth
))
/
mTotalTimeInMs
*
mCurrentTimeInMs
;
}
int
radius
=
rect
().
height
()
/
6
;
QRectF
r
(
rect
().
x
()
+
position
-
radius
,
rect
().
y
()
+
(
rect
().
height
()
/
4
)
-
radius
,
radius
*
2
,
radius
*
2
);
painter
->
setBrush
(
UBSettings
::
documentViewLightColor
);
painter
->
drawEllipse
(
r
);
if
(
mDisplayCurrentTime
)
{
painter
->
setBrush
(
UBSettings
::
paletteColor
);
painter
->
setPen
(
QPen
(
Qt
::
NoPen
));
QRectF
balloon
(
rect
().
x
()
+
position
-
frameWidth
,
rect
().
y
()
-
(
frameWidth
*
1.2
),
2
*
frameWidth
,
frameWidth
);
painter
->
drawRoundedRect
(
balloon
,
frameWidth
/
2
,
frameWidth
/
2
);
QTime
t
;
t
=
t
.
addMSecs
(
mCurrentTimeInMs
<
0
?
0
:
mCurrentTimeInMs
);
QFont
f
=
painter
->
font
();
f
.
setPointSizeF
(
f
.
pointSizeF
()
*
mAntiScale
);
painter
->
setFont
(
f
);
painter
->
setPen
(
Qt
::
white
);
painter
->
drawText
(
balloon
,
Qt
::
AlignCenter
,
t
.
toString
(
"m:ss"
));
}
}
QPainterPath
DelegateVideoControl
::
shape
()
const
{
QPainterPath
path
;
QRectF
r
=
rect
().
adjusted
(
0
,
0
,
0
,
-
rect
().
height
()
/
2
);
path
.
addRoundedRect
(
r
,
rect
().
height
()
/
4
,
rect
().
height
()
/
4
);
return
path
;
}
void
DelegateVideoControl
::
updateTicker
(
qint64
time
)
{
mCurrentTimeInMs
=
time
;
update
();
}
void
DelegateVideoControl
::
totalTimeChanged
(
qint64
newTotalTime
)
{
mTotalTimeInMs
=
newTotalTime
;
update
();
}
void
DelegateVideoControl
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mDisplayCurrentTime
=
true
;
seekToMousePos
(
event
->
pos
());
update
();
event
->
accept
();
}
void
DelegateVideoControl
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
seekToMousePos
(
event
->
pos
());
update
();
event
->
accept
();
}
void
DelegateVideoControl
::
seekToMousePos
(
QPointF
mousePos
)
{
qreal
minX
,
length
;
qreal
frameWidth
=
rect
().
height
()
/
2
;
minX
=
rect
().
x
()
+
frameWidth
;
length
=
rect
().
width
()
-
(
2
*
frameWidth
);
qreal
mouseX
=
mousePos
.
x
();
if
(
mTotalTimeInMs
>
0
&&
length
>
0
&&
mDelegate
&&
mDelegate
->
mediaObject
()
&&
mDelegate
->
mediaObject
()
->
isSeekable
())
{
qint64
tickPos
=
mTotalTimeInMs
/
length
*
(
mouseX
-
minX
);
mDelegate
->
mediaObject
()
->
seek
(
tickPos
);
//OSX is a bit lazy
updateTicker
(
tickPos
);
}
}
void
DelegateVideoControl
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mDisplayCurrentTime
=
false
;
update
();
event
->
accept
();
}
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui>
#include <QtSvg>
#include "UBGraphicsVideoItemDelegate.h"
#include "UBGraphicsScene.h"
#include "core/UBSettings.h"
#include "core/UBApplication.h"
#include "core/UBApplicationController.h"
#include "core/UBDisplayManager.h"
#include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsDelegateFrame.h"
#include "core/memcheck.h"
UBGraphicsVideoItemDelegate
::
UBGraphicsVideoItemDelegate
(
UBGraphicsVideoItem
*
pDelegated
,
Phonon
::
MediaObject
*
pMedia
,
QObject
*
parent
)
:
UBGraphicsItemDelegate
(
pDelegated
,
parent
,
true
,
false
)
,
mMedia
(
pMedia
)
{
// NOOP
}
void
UBGraphicsVideoItemDelegate
::
buildButtons
()
{
mPlayPauseButton
=
new
DelegateButton
(
":/images/play.svg"
,
mDelegated
,
mToolBarItem
,
Qt
::
TitleBarArea
);
mStopButton
=
new
DelegateButton
(
":/images/stop.svg"
,
mDelegated
,
mToolBarItem
,
Qt
::
TitleBarArea
);
mVideoControl
=
new
DelegateVideoControl
(
delegated
(),
mToolBarItem
);
UBGraphicsItem
::
assignZValue
(
mVideoControl
,
delegated
()
->
zValue
());
mVideoControl
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
if
(
delegated
()
->
isMuted
())
mMuteButton
=
new
DelegateButton
(
":/images/soundOff.svg"
,
mDelegated
,
mToolBarItem
,
Qt
::
TitleBarArea
);
else
mMuteButton
=
new
DelegateButton
(
":/images/soundOn.svg"
,
mDelegated
,
mToolBarItem
,
Qt
::
TitleBarArea
);
connect
(
mPlayPauseButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
togglePlayPause
()));
connect
(
mStopButton
,
SIGNAL
(
clicked
(
bool
)),
mMedia
,
SLOT
(
stop
()));
connect
(
mMuteButton
,
SIGNAL
(
clicked
(
bool
)),
delegated
(),
SLOT
(
toggleMute
()));
connect
(
mMuteButton
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
toggleMute
()));
mButtons
<<
mPlayPauseButton
<<
mStopButton
<<
mMuteButton
;
QList
<
QGraphicsItem
*>
itemsOnToolBar
;
itemsOnToolBar
<<
mPlayPauseButton
<<
mStopButton
<<
mVideoControl
<<
mMuteButton
;
mToolBarItem
->
setItemsOnToolBar
(
itemsOnToolBar
);
mMedia
->
setTickInterval
(
50
);
connect
(
mMedia
,
SIGNAL
(
stateChanged
(
Phonon
::
State
,
Phonon
::
State
)),
this
,
SLOT
(
mediaStateChanged
(
Phonon
::
State
,
Phonon
::
State
)));
connect
(
mMedia
,
SIGNAL
(
finished
()),
this
,
SLOT
(
updatePlayPauseState
()));
connect
(
mMedia
,
SIGNAL
(
tick
(
qint64
)),
this
,
SLOT
(
updateTicker
(
qint64
)));
connect
(
mMedia
,
SIGNAL
(
totalTimeChanged
(
qint64
)),
this
,
SLOT
(
totalTimeChanged
(
qint64
)));
mToolBarItem
->
setVisibleOnBoard
(
true
);
mToolBarItem
->
setShifting
(
false
);
}
UBGraphicsVideoItemDelegate
::~
UBGraphicsVideoItemDelegate
()
{
//NOOP
}
void
UBGraphicsVideoItemDelegate
::
positionHandles
()
{
UBGraphicsItemDelegate
::
positionHandles
();
if
(
mDelegated
->
isSelected
())
{
qreal
scaledFrameWidth
=
mFrameWidth
*
mAntiScaleRatio
;
int
offset
=
0
;
foreach
(
DelegateButton
*
button
,
mButtons
)
{
if
(
button
->
getSection
()
==
Qt
::
TitleBarArea
)
offset
+=
button
->
boundingRect
().
width
()
*
mAntiScaleRatio
;
}
mVideoControl
->
setRect
(
mVideoControl
->
rect
().
x
()
,
scaledFrameWidth
/
6
-
0.5
,
(
mToolBarItem
->
rect
().
width
()
-
35
-
offset
)
/
mAntiScaleRatio
,
(
2
*
scaledFrameWidth
)
/
mAntiScaleRatio
);
offset
+=
(
mVideoControl
->
rect
().
width
()
+
5
)
*
mAntiScaleRatio
;
mMuteButton
->
setPos
(
offset
,
0
);
if
(
!
mVideoControl
->
scene
())
{
mVideoControl
->
setParentItem
(
mToolBarItem
);
//update parent for the case the item has been previously removed from scene
mDelegated
->
scene
()
->
addItem
(
mVideoControl
);
}
mVideoControl
->
setAntiScale
(
mAntiScaleRatio
);
mVideoControl
->
setZValue
(
delegated
()
->
zValue
());
mVideoControl
->
show
();
}
else
{
mVideoControl
->
hide
();
}
}
void
UBGraphicsVideoItemDelegate
::
remove
(
bool
canUndo
)
{
if
(
delegated
()
&&
delegated
()
->
mediaObject
())
delegated
()
->
mediaObject
()
->
stop
();
QGraphicsScene
*
scene
=
mDelegated
->
scene
();
scene
->
removeItem
(
mVideoControl
);
UBGraphicsItemDelegate
::
remove
(
canUndo
);
}
void
UBGraphicsVideoItemDelegate
::
toggleMute
()
{
if
(
delegated
()
->
isMuted
())
mMuteButton
->
setFileName
(
":/images/soundOff.svg"
);
else
mMuteButton
->
setFileName
(
":/images/soundOn.svg"
);
}
UBGraphicsVideoItem
*
UBGraphicsVideoItemDelegate
::
delegated
()
{
return
static_cast
<
UBGraphicsVideoItem
*>
(
mDelegated
);
}
void
UBGraphicsVideoItemDelegate
::
togglePlayPause
()
{
if
(
delegated
()
&&
delegated
()
->
mediaObject
())
{
Phonon
::
MediaObject
*
media
=
delegated
()
->
mediaObject
();
if
(
media
->
state
()
==
Phonon
::
StoppedState
)
{
media
->
play
();
}
else
if
(
media
->
state
()
==
Phonon
::
PlayingState
)
{
if
(
media
->
remainingTime
()
<=
0
)
{
media
->
stop
();
media
->
play
();
}
else
{
media
->
pause
();
if
(
delegated
()
->
scene
())
delegated
()
->
scene
()
->
setModified
(
true
);
}
}
else
if
(
media
->
state
()
==
Phonon
::
PausedState
)
{
if
(
media
->
remainingTime
()
<=
0
)
{
media
->
stop
();
}
media
->
play
();
}
else
if
(
media
->
state
()
==
Phonon
::
LoadingState
)
{
delegated
()
->
mediaObject
()
->
setCurrentSource
(
delegated
()
->
mediaFileUrl
());
media
->
play
();
}
else
if
(
media
->
state
()
==
Phonon
::
ErrorState
){
qDebug
()
<<
"Error appeared."
<<
media
->
errorString
();
}
}
}
void
UBGraphicsVideoItemDelegate
::
mediaStateChanged
(
Phonon
::
State
newstate
,
Phonon
::
State
oldstate
)
{
Q_UNUSED
(
newstate
);
Q_UNUSED
(
oldstate
);
updatePlayPauseState
();
}
void
UBGraphicsVideoItemDelegate
::
updatePlayPauseState
()
{
Phonon
::
MediaObject
*
media
=
delegated
()
->
mediaObject
();
if
(
media
->
state
()
==
Phonon
::
PlayingState
)
mPlayPauseButton
->
setFileName
(
":/images/pause.svg"
);
else
mPlayPauseButton
->
setFileName
(
":/images/play.svg"
);
}
void
UBGraphicsVideoItemDelegate
::
updateTicker
(
qint64
time
)
{
Phonon
::
MediaObject
*
media
=
delegated
()
->
mediaObject
();
mVideoControl
->
totalTimeChanged
(
media
->
totalTime
());
mVideoControl
->
updateTicker
(
time
);
}
void
UBGraphicsVideoItemDelegate
::
totalTimeChanged
(
qint64
newTotalTime
)
{
mVideoControl
->
totalTimeChanged
(
newTotalTime
);
}
DelegateVideoControl
::
DelegateVideoControl
(
UBGraphicsVideoItem
*
pDelegated
,
QGraphicsItem
*
parent
)
:
QGraphicsRectItem
(
parent
)
,
mDelegate
(
pDelegated
)
,
mDisplayCurrentTime
(
false
)
,
mAntiScale
(
1.0
)
,
mCurrentTimeInMs
(
0
)
,
mTotalTimeInMs
(
0
)
,
mStartWidth
(
200
)
{
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
setBrush
(
QBrush
(
Qt
::
white
));
setPen
(
Qt
::
NoPen
);
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
QRectF
rect
=
this
->
rect
();
rect
.
setWidth
(
mStartWidth
);
this
->
setRect
(
rect
);
}
void
DelegateVideoControl
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
Q_UNUSED
(
option
);
Q_UNUSED
(
widget
);
painter
->
fillPath
(
shape
(),
brush
());
qreal
frameWidth
=
rect
().
height
()
/
2
;
int
position
=
frameWidth
;
if
(
mTotalTimeInMs
>
0
)
{
position
=
frameWidth
+
(
rect
().
width
()
-
(
2
*
frameWidth
))
/
mTotalTimeInMs
*
mCurrentTimeInMs
;
}
int
radius
=
rect
().
height
()
/
6
;
QRectF
r
(
rect
().
x
()
+
position
-
radius
,
rect
().
y
()
+
(
rect
().
height
()
/
4
)
-
radius
,
radius
*
2
,
radius
*
2
);
painter
->
setBrush
(
UBSettings
::
documentViewLightColor
);
painter
->
drawEllipse
(
r
);
if
(
mDisplayCurrentTime
)
{
painter
->
setBrush
(
UBSettings
::
paletteColor
);
painter
->
setPen
(
QPen
(
Qt
::
NoPen
));
mBalloon
.
setRect
(
rect
().
x
()
+
position
-
frameWidth
,
rect
().
y
()
-
(
frameWidth
*
1.2
),
2
*
frameWidth
,
frameWidth
);
painter
->
drawRoundedRect
(
mBalloon
,
frameWidth
/
2
,
frameWidth
/
2
);
QTime
t
;
t
=
t
.
addMSecs
(
mCurrentTimeInMs
<
0
?
0
:
mCurrentTimeInMs
);
QFont
f
=
painter
->
font
();
f
.
setPointSizeF
(
f
.
pointSizeF
()
*
mAntiScale
);
painter
->
setFont
(
f
);
painter
->
setPen
(
Qt
::
white
);
painter
->
drawText
(
mBalloon
,
Qt
::
AlignCenter
,
t
.
toString
(
"m:ss"
));
}
}
QPainterPath
DelegateVideoControl
::
shape
()
const
{
QPainterPath
path
;
QRectF
r
=
rect
().
adjusted
(
0
,
0
,
0
,
-
rect
().
height
()
/
2
);
path
.
addRoundedRect
(
r
,
rect
().
height
()
/
4
,
rect
().
height
()
/
4
);
return
path
;
}
void
DelegateVideoControl
::
updateTicker
(
qint64
time
)
{
mCurrentTimeInMs
=
time
;
update
();
}
void
DelegateVideoControl
::
totalTimeChanged
(
qint64
newTotalTime
)
{
mTotalTimeInMs
=
newTotalTime
;
update
();
}
void
DelegateVideoControl
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mDisplayCurrentTime
=
true
;
seekToMousePos
(
event
->
pos
());
update
();
event
->
accept
();
}
void
DelegateVideoControl
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
shape
().
contains
(
event
->
pos
()
-
QPointF
(
mBalloon
.
width
()
/
2
,
0
))
&&
shape
().
contains
(
event
->
pos
()
+
QPointF
(
mBalloon
.
width
()
/
2
,
0
)))
{
seekToMousePos
(
event
->
pos
());
update
();
event
->
accept
();
}
}
void
DelegateVideoControl
::
seekToMousePos
(
QPointF
mousePos
)
{
qreal
minX
,
length
;
qreal
frameWidth
=
rect
().
height
()
/
2
;
minX
=
rect
().
x
()
+
frameWidth
;
length
=
rect
().
width
()
-
(
2
*
frameWidth
);
qreal
mouseX
=
mousePos
.
x
();
if
(
mTotalTimeInMs
>
0
&&
length
>
0
&&
mDelegate
&&
mDelegate
->
mediaObject
()
&&
mDelegate
->
mediaObject
()
->
isSeekable
())
{
qint64
tickPos
=
mTotalTimeInMs
/
length
*
(
mouseX
-
minX
);
mDelegate
->
mediaObject
()
->
seek
(
tickPos
);
//OSX is a bit lazy
updateTicker
(
tickPos
);
}
}
void
DelegateVideoControl
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
mDisplayCurrentTime
=
false
;
update
();
event
->
accept
();
}
src/domain/UBGraphicsVideoItemDelegate.h
View file @
56eceb66
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. 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
;
};
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_ */
/*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. 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_ */
src/domain/ubgraphicsgroupcontaineritem.cpp
View file @
56eceb66
...
...
@@ -6,6 +6,8 @@
#include "domain/ubgraphicsgroupcontaineritemdelegate.h"
#include "domain/UBGraphicsScene.h"
#include "core/memcheck.h"
UBGraphicsGroupContainerItem
::
UBGraphicsGroupContainerItem
(
QGraphicsItem
*
parent
)
:
QGraphicsItemGroup
(
parent
)
{
...
...
src/domain/ubgraphicsgroupcontaineritemdelegate.cpp
View file @
56eceb66
...
...
@@ -8,9 +8,10 @@
#include "domain/UBGraphicsDelegateFrame.h"
#include "domain/ubgraphicsgroupcontaineritem.h"
#include "core/memcheck.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
UBGraphicsGroupContainerItemDelegate
::
UBGraphicsGroupContainerItemDelegate
(
QGraphicsItem
*
pDelegated
,
QObject
*
parent
)
:
UBGraphicsItemDelegate
(
pDelegated
,
parent
),
mDestroyGroupButton
(
0
)
...
...
src/frameworks/UBCoreGraphicsScene.cpp
View file @
56eceb66
...
...
@@ -15,12 +15,13 @@
#include "UBCoreGraphicsScene.h"
#include "core/memcheck.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsMediaItem.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "core/memcheck.h"
UBCoreGraphicsScene
::
UBCoreGraphicsScene
(
QObject
*
parent
)
:
QGraphicsScene
(
parent
)
{
...
...
src/gui/UBDockDownloadWidget.cpp
View file @
56eceb66
...
...
@@ -17,6 +17,8 @@
#include "globals/UBGlobals.h"
#include "core/memcheck.h"
UBDockDownloadWidget
::
UBDockDownloadWidget
(
QWidget
*
parent
,
const
char
*
name
)
:
UBDockPaletteWidget
(
parent
,
name
)
,
mpLayout
(
NULL
)
,
mpDLWidget
(
NULL
)
...
...
src/gui/UBDockTeacherGuideWidget.cpp
View file @
56eceb66
...
...
@@ -19,6 +19,8 @@
#include "UBDockTeacherGuideWidget.h"
#include "UBTeacherGuideWidget.h"
#include "core/memcheck.h"
UBDockTeacherGuideWidget
::
UBDockTeacherGuideWidget
(
QWidget
*
parent
,
const
char
*
name
)
:
UBDockPaletteWidget
(
parent
,
name
)
...
...
src/gui/UBFeaturesActionBar.cpp
View file @
56eceb66
#include "UBFeaturesActionBar.h"
#include "core/memcheck.h"
UBFeaturesActionBar
::
UBFeaturesActionBar
(
UBFeaturesController
*
controller
,
QWidget
*
parent
,
const
char
*
name
)
:
QWidget
(
parent
)
,
featuresController
(
controller
)
...
...
@@ -143,6 +144,16 @@ void UBFeaturesActionBar::setButtons()
mpRemoveFavoriteBtn
->
show
();
mpNewFolderBtn
->
hide
();
break
;
case
IN_TRASH
:
mpFavoriteBtn
->
hide
();
mpSocialBtn
->
hide
();
mSearchBar
->
show
();
//mpSearchBtn->show();
//mpDeleteBtn->hide();
mpCloseBtn
->
hide
();
//mpRemoveFavoriteBtn->show();
mpNewFolderBtn
->
hide
();
break
;
default
:
break
;
}
...
...
@@ -169,7 +180,9 @@ void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event)
void
UBFeaturesActionBar
::
dragEnterEvent
(
QDragEnterEvent
*
event
)
{
if
(
event
->
mimeData
()
->
hasFormat
(
"text/uri-list"
))
{
event
->
acceptProposedAction
();
}
}
void
UBFeaturesActionBar
::
dropEvent
(
QDropEvent
*
event
)
...
...
@@ -177,6 +190,12 @@ void UBFeaturesActionBar::dropEvent( QDropEvent *event )
QWidget
*
dest
=
childAt
(
event
->
pos
()
);
if
(
dest
==
mpDeleteBtn
)
{
QList
<
QUrl
>
urls
=
event
->
mimeData
()
->
urls
();
foreach
(
QUrl
url
,
urls
)
{
if
(
!
UBFeaturesController
::
isDeletable
(
url
)
)
return
;
}
event
->
setDropAction
(
Qt
::
MoveAction
);
event
->
accept
();
emit
deleteElements
(
*
event
->
mimeData
()
);
...
...
src/gui/UBFeaturesActionBar.h
View file @
56eceb66
...
...
@@ -12,7 +12,8 @@ enum UBFeaturesActionBarState
IN_ROOT
,
IN_FOLDER
,
IN_PROPERTIES
,
IN_FAVORITE
IN_FAVORITE
,
IN_TRASH
};
class
UBFeaturesActionBar
:
public
QWidget
...
...
src/gui/UBFeaturesWidget.cpp
View file @
56eceb66
#include <QDomDocument>
#include "UBFeaturesWidget.h"
#include "domain/UBAbstractWidget.h"
#include "gui/UBThumbnailWidget.h"
...
...
@@ -6,6 +8,7 @@
#include "core/UBApplication.h"
#include "core/UBDownloadManager.h"
#include "globals/UBGlobals.h"
#include "board/UBBoardController.h"
UBFeaturesWidget
::
UBFeaturesWidget
(
QWidget
*
parent
,
const
char
*
name
)
:
UBDockPaletteWidget
(
parent
)
{
...
...
@@ -56,6 +59,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
featuresListView
->
setViewMode
(
QListView
::
IconMode
);
itemDelegate
=
new
UBFeaturesItemDelegate
(
this
,
featuresListView
);
featuresListView
->
setItemDelegate
(
itemDelegate
);
//featuresListView->setSelectionRectVisible(false);
featuresListView
->
setIconSize
(
QSize
(
defaultThumbnailSize
,
defaultThumbnailSize
)
);
featuresListView
->
setGridSize
(
QSize
(
defaultThumbnailSize
*
1.75
,
defaultThumbnailSize
*
1.75
)
);
...
...
@@ -71,6 +75,9 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
pathListView
->
setSelectionMode
(
QAbstractItemView
::
NoSelection
);
pathListView
->
setVerticalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
pathListView
->
setHorizontalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOn
);
pathListView
->
setFlow
(
QListView
::
LeftToRight
);
pathListView
->
setWrapping
(
false
);
//pathListView->setResizeMode( QListView::Adjust );
//pathListView->setMovement( QListView::Static );
pathListView
->
setDragDropMode
(
QAbstractItemView
::
DropOnly
);
...
...
@@ -78,6 +85,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
pathScene
=
new
QGraphicsScene
(
this
);
//pathViewer = new UBFeaturesPathViewer( QPixmap(":images/libpalette/home.png"), controller->getRootPath(), pathScene, this );
featureProperties
=
new
UBFeatureProperties
(
this
);
webView
=
new
UBFeaturesWebView
(
this
);
//layout->addWidget( pathViewer );
//pathViewer->show();
...
...
@@ -87,6 +95,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
stackedWidget
->
addWidget
(
featuresListView
);
stackedWidget
->
addWidget
(
featureProperties
);
stackedWidget
->
addWidget
(
webView
);
stackedWidget
->
setCurrentIndex
(
ID_LISTVIEW
);
currentStackedWidget
=
ID_LISTVIEW
;
...
...
@@ -107,7 +116,7 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
this, SLOT(currentSelected(const QModelIndex &)));*/
connect
(
featuresListView
,
SIGNAL
(
clicked
(
const
QModelIndex
&
)
),
this
,
SLOT
(
currentSelected
(
const
QModelIndex
&
)
)
);
connect
(
mActionBar
,
SIGNAL
(
searchElement
(
const
QString
&
)
),
this
,
SLOT
(
const
searchStarted
(
QString
&
)
)
);
connect
(
mActionBar
,
SIGNAL
(
searchElement
(
const
QString
&
)
),
this
,
SLOT
(
searchStarted
(
const
QString
&
)
)
);
connect
(
mActionBar
,
SIGNAL
(
newFolderToCreate
()
),
this
,
SLOT
(
createNewFolder
()
)
);
connect
(
mActionBar
,
SIGNAL
(
deleteElements
(
const
QMimeData
&
)
),
this
,
SLOT
(
deleteElements
(
const
QMimeData
&
)
)
);
connect
(
mActionBar
,
SIGNAL
(
addToFavorite
(
const
QMimeData
&
)
),
this
,
SLOT
(
addToFavorite
(
const
QMimeData
&
)
)
);
...
...
@@ -115,6 +124,10 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
connect
(
pathListView
,
SIGNAL
(
clicked
(
const
QModelIndex
&
)
),
this
,
SLOT
(
currentPathChanged
(
const
QModelIndex
&
)
)
);
connect
(
thumbSlider
,
SIGNAL
(
sliderMoved
(
int
)
),
this
,
SLOT
(
thumbnailSizeChanged
(
int
)
)
);
connect
(
UBApplication
::
boardController
,
SIGNAL
(
displayMetadata
(
QMap
<
QString
,
QString
>
)
),
this
,
SLOT
(
onDisplayMetadata
(
QMap
<
QString
,
QString
>
)
)
);
connect
(
UBDownloadManager
::
downloadManager
(),
SIGNAL
(
addDownloadedFileToLibrary
(
bool
,
QUrl
,
QString
,
QByteArray
)
),
this
,
SLOT
(
onAddDownloadedFileToLibrary
(
bool
,
QUrl
,
QString
,
QByteArray
)
)
);
}
bool
UBFeaturesWidget
::
eventFilter
(
QObject
*
target
,
QEvent
*
event
)
...
...
@@ -156,7 +169,7 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t)
if
(
feature
.
isFolder
()
)
{
QString
newPath
=
feature
.
get
Url
()
+
"/"
+
feature
.
getName
();
QString
newPath
=
feature
.
get
FullVirtualPath
();
//pathViewer->addPathElement( feature.getThumbnail(), newPath );
controller
->
setCurrentElement
(
feature
);
...
...
@@ -170,11 +183,20 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t)
{
mActionBar
->
setCurrentState
(
IN_FAVORITE
);
}
else
if
(
feature
.
getType
()
==
FEATURE_TRASH
)
{
mActionBar
->
setCurrentState
(
IN_TRASH
);
}
else
{
mActionBar
->
setCurrentState
(
IN_FOLDER
);
}
}
else
if
(
feature
.
getType
()
==
FEATURE_SEARCH
)
{
webView
->
showElement
(
feature
);
switchToWebView
();
}
else
{
featureProperties
->
showElement
(
feature
);
...
...
@@ -190,7 +212,7 @@ void UBFeaturesWidget::currentPathChanged(const QModelIndex &index)
if
(
index
.
isValid
()
)
{
UBFeature
feature
=
featuresPathModel
->
data
(
index
,
Qt
::
UserRole
+
1
).
value
<
UBFeature
>
();
QString
newPath
=
feature
.
get
Url
()
+
"/"
+
feature
.
getName
();
QString
newPath
=
feature
.
get
FullVirtualPath
();
featuresPathModel
->
setPath
(
newPath
);
featuresPathModel
->
invalidate
();
...
...
@@ -208,6 +230,10 @@ void UBFeaturesWidget::currentPathChanged(const QModelIndex &index)
{
mActionBar
->
setCurrentState
(
IN_FAVORITE
);
}
else
if
(
feature
.
getType
()
==
FEATURE_TRASH
)
{
mActionBar
->
setCurrentState
(
IN_TRASH
);
}
else
{
mActionBar
->
setCurrentState
(
IN_FOLDER
);
...
...
@@ -224,7 +250,6 @@ void UBFeaturesWidget::createNewFolder()
featuresModel
->
addItem
(
newFolder
);
featuresProxyModel
->
invalidate
();
}
}
void
UBFeaturesWidget
::
deleteElements
(
const
QMimeData
&
mimeData
)
...
...
@@ -260,7 +285,7 @@ void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData )
foreach
(
QUrl
url
,
urls
)
{
UBFeature
elem
=
controller
->
addToFavorite
(
url
);
if
(
!
elem
.
get
Url
().
isEmpty
()
&&
!
elem
.
getUrl
().
isNull
()
)
if
(
!
elem
.
get
VirtualPath
().
isEmpty
()
&&
!
elem
.
getVirtualPath
().
isNull
()
)
featuresModel
->
addItem
(
elem
);
}
QSortFilterProxyModel
*
model
=
dynamic_cast
<
QSortFilterProxyModel
*>
(
featuresListView
->
model
()
);
...
...
@@ -284,6 +309,30 @@ void UBFeaturesWidget::thumbnailSizeChanged( int value )
featuresListView
->
setGridSize
(
QSize
(
value
*
1.75
,
value
*
1.75
)
);
}
void
UBFeaturesWidget
::
onDisplayMetadata
(
QMap
<
QString
,
QString
>
metadata
)
{
UBFeature
feature
(
QString
(),
QPixmap
(
":images/libpalette/notFound.png"
),
QString
(),
metadata
[
"Url"
],
FEATURE_ITEM
);
feature
.
setMetadata
(
metadata
);
featureProperties
->
showElement
(
feature
);
switchToProperties
();
mActionBar
->
setCurrentState
(
IN_PROPERTIES
);
}
void
UBFeaturesWidget
::
onAddDownloadedFileToLibrary
(
bool
pSuccess
,
QUrl
sourceUrl
,
QString
pContentHeader
,
QByteArray
pData
)
{
if
(
pSuccess
)
{
UBFeature
newFeature
=
controller
->
addDownloadedFile
(
sourceUrl
,
pData
);
if
(
newFeature
!=
UBFeature
()
)
{
featuresModel
->
addItem
(
newFeature
);
QSortFilterProxyModel
*
model
=
dynamic_cast
<
QSortFilterProxyModel
*>
(
featuresListView
->
model
()
);
model
->
invalidate
();
}
}
}
void
UBFeaturesWidget
::
switchToListView
()
{
stackedWidget
->
setCurrentIndex
(
ID_LISTVIEW
);
...
...
@@ -296,6 +345,11 @@ void UBFeaturesWidget::switchToProperties()
currentStackedWidget
=
ID_PROPERTIES
;
}
void
UBFeaturesWidget
::
switchToWebView
()
{
stackedWidget
->
setCurrentIndex
(
ID_WEBVIEW
);
currentStackedWidget
=
ID_WEBVIEW
;
}
/*
...
...
@@ -315,11 +369,39 @@ UBFeaturesWidget::~UBFeaturesWidget()
{
}
UBFeaturesListView
::
UBFeaturesListView
(
QWidget
*
parent
,
const
char
*
name
)
:
QListView
(
parent
)
UBFeaturesListView
::
UBFeaturesListView
(
QWidget
*
parent
,
const
char
*
name
)
:
QListView
(
parent
)
{
setObjectName
(
name
);
//rubberBand = new UBRubberBand( QRubberBand::Rectangle, this );
}
/*
void UBFeaturesListView::mousePressEvent( QMouseEvent *event )
{
rubberOrigin = event->pos();
rubberBand->setGeometry( QRect( rubberOrigin, QSize() ) );
//qDebug() << rubberOrigin.x() << rubberOrigin.y();
rubberBand->show();
QListView::mousePressEvent(event);
}
void UBFeaturesListView::mouseMoveEvent( QMouseEvent *event )
{
QPoint current = event->pos();
rubberBand->setGeometry( QRect( rubberOrigin, current ).normalized() );
//setSelection( rubberBand->rect(), QItemSelectionModel::Select );
QListView::mouseMoveEvent(event);
}
void UBFeaturesListView::mouseReleaseEvent( QMouseEvent *event )
{
rubberBand->hide();
QListView::mouseReleaseEvent(event);
}
*/
void
UBFeaturesListView
::
dragEnterEvent
(
QDragEnterEvent
*
event
)
{
if
(
event
->
mimeData
()
->
hasUrls
()
)
...
...
@@ -336,6 +418,96 @@ void UBFeaturesListView::dropEvent( QDropEvent *event )
}
UBFeaturesWebView
::
UBFeaturesWebView
(
QWidget
*
parent
,
const
char
*
name
)
:
QWidget
(
parent
)
,
mpView
(
NULL
)
,
mpWebSettings
(
NULL
)
,
mpLayout
(
NULL
)
,
mpSankoreAPI
(
NULL
)
{
setObjectName
(
name
);
SET_STYLE_SHEET
();
mpLayout
=
new
QVBoxLayout
();
setLayout
(
mpLayout
);
mpView
=
new
QWebView
(
this
);
mpView
->
setObjectName
(
"SearchEngineView"
);
mpSankoreAPI
=
new
UBWidgetUniboardAPI
(
UBApplication
::
boardController
->
activeScene
());
mpView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
mpSankoreAPI
);
mpWebSettings
=
QWebSettings
::
globalSettings
();
mpWebSettings
->
setAttribute
(
QWebSettings
::
JavaEnabled
,
true
);
mpWebSettings
->
setAttribute
(
QWebSettings
::
PluginsEnabled
,
true
);
mpWebSettings
->
setAttribute
(
QWebSettings
::
LocalStorageDatabaseEnabled
,
true
);
mpWebSettings
->
setAttribute
(
QWebSettings
::
OfflineWebApplicationCacheEnabled
,
true
);
mpWebSettings
->
setAttribute
(
QWebSettings
::
OfflineStorageDatabaseEnabled
,
true
);
mpWebSettings
->
setAttribute
(
QWebSettings
::
JavascriptCanAccessClipboard
,
true
);
mpWebSettings
->
setAttribute
(
QWebSettings
::
DnsPrefetchEnabled
,
true
);
mpLayout
->
addWidget
(
mpView
);
connect
(
mpView
,
SIGNAL
(
loadFinished
(
bool
)),
this
,
SLOT
(
onLoadFinished
(
bool
)));
}
UBFeaturesWebView
::~
UBFeaturesWebView
()
{
if
(
NULL
!=
mpSankoreAPI
){
delete
mpSankoreAPI
;
mpSankoreAPI
=
NULL
;
}
if
(
NULL
!=
mpView
){
delete
mpView
;
mpView
=
NULL
;
}
if
(
NULL
!=
mpLayout
){
delete
mpLayout
;
mpLayout
=
NULL
;
}
}
void
UBFeaturesWebView
::
showElement
(
const
UBFeature
&
elem
)
{
QString
qsWidgetName
;
QString
path
=
elem
.
getFullPath
().
toLocalFile
();
QString
qsConfigPath
=
QString
(
"%0/config.xml"
).
arg
(
path
);
if
(
QFile
::
exists
(
qsConfigPath
))
{
QFile
f
(
qsConfigPath
);
if
(
f
.
open
(
QIODevice
::
ReadOnly
))
{
QDomDocument
domDoc
;
domDoc
.
setContent
(
QString
(
f
.
readAll
()));
QDomElement
root
=
domDoc
.
documentElement
();
QDomNode
node
=
root
.
firstChild
();
while
(
!
node
.
isNull
())
{
if
(
node
.
toElement
().
tagName
()
==
"content"
)
{
QDomAttr
srcAttr
=
node
.
toElement
().
attributeNode
(
"src"
);
qsWidgetName
=
srcAttr
.
value
();
break
;
}
node
=
node
.
nextSibling
();
}
f
.
close
();
}
}
mpView
->
load
(
QUrl
::
fromLocalFile
(
QString
(
"%0/%1"
).
arg
(
path
).
arg
(
qsWidgetName
)));
}
void
UBFeaturesWebView
::
onLoadFinished
(
bool
ok
)
{
if
(
ok
&&
NULL
!=
mpSankoreAPI
){
mpView
->
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"sankore"
,
mpSankoreAPI
);
}
}
UBFeatureProperties
::
UBFeatureProperties
(
QWidget
*
parent
,
const
char
*
name
)
:
QWidget
(
parent
)
,
mpLayout
(
NULL
)
,
mpButtonLayout
(
NULL
)
...
...
@@ -346,6 +518,7 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) :
,
mpThumbnail
(
NULL
)
,
mpOrigPixmap
(
NULL
)
,
mpElement
(
NULL
)
,
mpObjInfos
(
NULL
)
{
setObjectName
(
name
);
...
...
@@ -385,12 +558,49 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) :
mpButtonLayout
->
addStretch
(
1
);
mpObjInfoLabel
=
new
QLabel
(
tr
(
"Object informations"
));
mpObjInfoLabel
=
new
QLabel
(
tr
(
"Object informations"
));
mpObjInfoLabel
->
setStyleSheet
(
QString
(
"color: #888888; font-size : 18px; font-weight:bold;"
));
mpLayout
->
addWidget
(
mpObjInfoLabel
,
0
);
connect
(
mpAddPageButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
onAddToPage
()));
mpObjInfos
=
new
QTreeWidget
(
this
);
mpObjInfos
->
setColumnCount
(
2
);
mpObjInfos
->
header
()
->
hide
();
mpObjInfos
->
setAlternatingRowColors
(
true
);
mpObjInfos
->
setRootIsDecorated
(
false
);
mpObjInfos
->
setObjectName
(
"DockPaletteWidgetBox"
);
mpObjInfos
->
setStyleSheet
(
"background:white;"
);
mpLayout
->
addWidget
(
mpObjInfos
,
1
);
connect
(
mpAddPageButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
onAddToPage
())
);
connect
(
mpSetAsBackgroundButton
,
SIGNAL
(
clicked
()
),
this
,
SLOT
(
onSetAsBackground
()
)
);
connect
(
mpAddToLibButton
,
SIGNAL
(
clicked
()
),
this
,
SLOT
(
onAddToLib
()
)
);
}
void
UBFeatureProperties
::
resizeEvent
(
QResizeEvent
*
event
)
{
Q_UNUSED
(
event
);
adaptSize
();
}
void
UBFeatureProperties
::
showEvent
(
QShowEvent
*
event
)
{
Q_UNUSED
(
event
);
adaptSize
();
}
void
UBFeatureProperties
::
adaptSize
()
{
if
(
NULL
!=
mpOrigPixmap
)
{
if
(
width
()
<
THUMBNAIL_WIDTH
+
40
)
{
mpThumbnail
->
setPixmap
(
mpOrigPixmap
->
scaledToWidth
(
width
()
-
40
)
);
}
else
{
mpThumbnail
->
setPixmap
(
mpOrigPixmap
->
scaledToWidth
(
THUMBNAIL_WIDTH
)
);
}
}
}
void
UBFeatureProperties
::
showElement
(
const
UBFeature
&
elem
)
...
...
@@ -408,59 +618,95 @@ void UBFeatureProperties::showElement( const UBFeature &elem )
mpElement
=
new
UBFeature
(
elem
);
mpOrigPixmap
=
new
QPixmap
(
elem
.
getThumbnail
()
);
mpThumbnail
->
setPixmap
(
elem
.
getThumbnail
().
scaledToWidth
(
THUMBNAIL_WIDTH
));
//
populateMetadata();
populateMetadata
();
if
(
UBApplication
::
isFromWeb
(
elem
.
get
Url
()
)
)
if
(
UBApplication
::
isFromWeb
(
elem
.
get
FullPath
().
toString
()
)
)
{
mpAddToLibButton
->
show
();
/*if(elem->metadatas()["Type"].toLower().contains("image")
)
if
(
elem
.
getMetadata
()[
"Type"
].
toLower
().
contains
(
"image"
)
)
{
mpSetAsBackgroundButton
->
show
();
}
else
{
mpSetAsBackgroundButton
->
hide
();
}
*/
}
}
else
{
mpAddToLibButton
->
hide
();
if
(
UBFileSystemUtils
::
mimeTypeFromFileName
(
elem
.
get
Url
()
).
contains
(
"image"
))
if
(
UBFileSystemUtils
::
mimeTypeFromFileName
(
elem
.
get
FullPath
().
toLocalFile
()
).
contains
(
"image"
))
{
mpSetAsBackgroundButton
->
show
();
}
else
else
{
mpSetAsBackgroundButton
->
hide
();
}
}
}
void
UBFeatureProperties
::
populateMetadata
()
{
if
(
NULL
!=
mpObjInfos
){
mpObjInfos
->
clear
();
QMap
<
QString
,
QString
>
metas
=
mpElement
->
getMetadata
();
QList
<
QString
>
lKeys
=
metas
.
keys
();
QList
<
QString
>
lValues
=
metas
.
values
();
for
(
int
i
=
0
;
i
<
metas
.
size
();
i
++
){
QStringList
values
;
values
<<
lKeys
.
at
(
i
);
values
<<
lValues
.
at
(
i
);
mpItem
=
new
QTreeWidgetItem
(
values
);
mpObjInfos
->
addTopLevelItem
(
mpItem
);
}
mpObjInfos
->
resizeColumnToContents
(
0
);
}
}
void
UBFeatureProperties
::
onAddToPage
()
{
QWidget
*
w
=
parentWidget
()
->
parentWidget
();
UBFeaturesWidget
*
featuresWidget
=
dynamic_cast
<
UBFeaturesWidget
*>
(
w
);
featuresWidget
->
getFeaturesController
()
->
addItemToPage
(
*
mpElement
);
/*if ( UBApplication::isFromWeb( mpElement->getUrl() ) )
{
}
void
UBFeatureProperties
::
onAddToLib
()
{
if
(
UBApplication
::
isFromWeb
(
mpElement
->
getFullPath
().
toString
()
)
)
{
sDownloadFileDesc
desc
;
desc
.
isBackground
=
false
;
desc.modal = true;
desc.name = QFileInfo( mpElement->getName() ).fileName();
desc.url = mpElement->getUrl();
desc
.
modal
=
false
;
desc
.
name
=
QFileInfo
(
mpElement
->
getFullPath
().
toString
()).
fileName
();
qDebug
()
<<
desc
.
name
;
desc
.
url
=
mpElement
->
getFullPath
().
toString
();
qDebug
()
<<
desc
.
url
;
UBDownloadManager
::
downloadManager
()
->
addFileToDownload
(
desc
);
}
else
{
QWidget *w = parentWidget()->parentWidget();
UBFeaturesWidget* featuresWidget = dynamic_cast<UBFeaturesWidget*>( w );
featuresWidget->getFeaturesController()->addItemToPage( *mpElement );
}*/
}
void
UBFeatureProperties
::
onSetAsBackground
()
{
QWidget
*
w
=
parentWidget
()
->
parentWidget
();
UBFeaturesWidget
*
featuresWidget
=
dynamic_cast
<
UBFeaturesWidget
*>
(
w
);
featuresWidget
->
getFeaturesController
()
->
addItemAsBackground
(
*
mpElement
);
}
UBFeatureProperties
::~
UBFeatureProperties
()
{
if
(
mpOrigPixmap
)
{
delete
mpOrigPixmap
;
mpOrigPixmap
=
NULL
;
}
if
(
mpElement
)
{
delete
mpElement
;
mpElement
=
NULL
;
}
}
UBFeatureItemButton
::
UBFeatureItemButton
(
QWidget
*
parent
,
const
char
*
name
)
:
QPushButton
(
parent
)
...
...
@@ -487,7 +733,7 @@ QVariant UBFeaturesModel::data(const QModelIndex &index, int role) const
}
else
if
(
role
==
Qt
::
UserRole
)
{
return
featuresList
->
at
(
index
.
row
()).
get
Url
();
return
featuresList
->
at
(
index
.
row
()).
get
VirtualPath
();
}
else
if
(
role
==
Qt
::
UserRole
+
1
)
{
...
...
@@ -509,14 +755,15 @@ QMimeData* UBFeaturesModel::mimeData(const QModelIndexList &indexes) const
if
(
index
.
isValid
()
)
{
UBFeature
element
=
data
(
index
,
Qt
::
UserRole
+
1
).
value
<
UBFeature
>
();
if
(
element
.
getType
()
==
FEATURE_INTERNAL
)
urlList
.
push_back
(
element
.
getFullPath
()
);
/*if ( element.getType() == FEATURE_INTERNAL )
{
urlList.push_back( QUrl( element.getFullPath() ) );
}
else if ( element.getType() == FEATURE_INTERACTIVE || element.getType() == FEATURE_ITEM )
{
urlList
.
push_back
(
QUrl
::
fromLocalFile
(
element
.
getFullPath
()
)
);
}
urlList.push_back(
element.getFullPath(
) );
}
*/
}
}
mimeData
->
setUrls
(
urlList
);
...
...
@@ -537,19 +784,15 @@ bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction act
int
endRow
=
0
;
UBFeature
parentFeature
;
if
(
!
parent
.
isValid
()
)
{
return
false
;
/*if (row < 0)
endRow = featuresList->size();
else
endRow = qMin( row, featuresList->size() );*/
parentFeature
=
dynamic_cast
<
UBFeaturesWidget
*>
(
QObject
::
parent
())
->
getFeaturesController
()
->
getCurrentElement
();
}
else
endRow
=
parent
.
row
();
Q_UNUSED
(
endRow
)
//why do we need this variable?
UBFeature
parentFeature
=
parent
.
data
(
Qt
::
UserRole
+
1
).
value
<
UBFeature
>
();
{
parentFeature
=
parent
.
data
(
Qt
::
UserRole
+
1
).
value
<
UBFeature
>
();
}
QList
<
QUrl
>
urls
=
mimeData
->
urls
();
...
...
@@ -581,8 +824,8 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path )
{
for
(
int
i
=
0
;
i
<
featuresList
->
size
();
++
i
)
{
if
(
!
QString
::
compare
(
featuresList
->
at
(
i
).
get
FullPath
(),
path
,
Qt
::
CaseInsensitive
)
&&
!
QString
::
compare
(
featuresList
->
at
(
i
).
get
Url
(),
"/root/favorites"
,
Qt
::
CaseInsensitive
)
)
if
(
!
QString
::
compare
(
featuresList
->
at
(
i
).
get
Url
(),
path
,
Qt
::
CaseInsensitive
)
&&
!
QString
::
compare
(
featuresList
->
at
(
i
).
get
VirtualPath
(),
"/root/favorites"
,
Qt
::
CaseInsensitive
)
)
{
removeRow
(
i
,
QModelIndex
()
);
return
;
...
...
@@ -626,9 +869,9 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
item
.
getType
()
==
FEATURE_ITEM
||
item
.
getType
()
==
FEATURE_INTERNAL
)
return
Qt
::
ItemIsDragEnabled
|
defaultFlags
;
if
(
item
.
isFolder
()
&&
!
item
.
get
Ful
lPath
().
isNull
()
)
if
(
item
.
isFolder
()
&&
!
item
.
get
Virtua
lPath
().
isNull
()
)
return
defaultFlags
|
Qt
::
ItemIsDropEnabled
;
else
return
defaultFlags
;
else
return
defaultFlags
|
Qt
::
ItemIsDropEnabled
;
}
/*if ( index.isValid() )
{
...
...
@@ -647,7 +890,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
default:;
}
}*/
return
defaultFlags
;
return
defaultFlags
|
Qt
::
ItemIsDropEnabled
;
}
...
...
@@ -696,9 +939,8 @@ bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelInde
eUBLibElementType type = (eUBLibElementType)sourceModel()->data(index, Qt::UserRole + 1).toInt();*/
UBFeature
feature
=
sourceModel
()
->
data
(
index
,
Qt
::
UserRole
+
1
).
value
<
UBFeature
>
();
QString
virtualFullPath
=
feature
.
getUrl
()
+
"/"
+
feature
.
getName
();
return
feature
.
isFolder
()
&&
path
.
startsWith
(
virtualFullPath
);
return
feature
.
isFolder
()
&&
path
.
startsWith
(
feature
.
getFullVirtualPath
()
);
}
QString
UBFeaturesItemDelegate
::
displayText
(
const
QVariant
&
value
,
const
QLocale
&
locale
)
const
...
...
@@ -710,13 +952,7 @@ QString UBFeaturesItemDelegate::displayText ( const QVariant & value, const QLoc
{
const
QFontMetrics
fm
=
listView
->
fontMetrics
();
const
QSize
iSize
=
listView
->
iconSize
();
if
(
iSize
.
width
()
>
0
&&
fm
.
width
(
text
)
>
iSize
.
width
()
)
{
while
(
fm
.
width
(
text
)
>
iSize
.
width
())
text
.
resize
(
text
.
size
()
-
1
);
text
+=
"..."
;
}
return
elidedText
(
fm
,
iSize
.
width
(),
Qt
::
ElideRight
,
text
);
}
return
text
;
}
...
...
src/gui/UBFeaturesWidget.h
View file @
56eceb66
...
...
@@ -18,12 +18,15 @@
#include "UBDockPaletteWidget.h"
//#include "UBLibActionBar.h"
#include "board/UBFeaturesController.h"
#include "api/UBWidgetUniboardAPI.h"
#include "UBFeaturesActionBar.h"
#include "UBRubberBand.h"
#define THUMBNAIL_WIDTH 400
#define ID_LISTVIEW 0
#define ID_PROPERTIES 1
#define ID_WEBVIEW 2
class
UBListModel
;
...
...
@@ -37,6 +40,7 @@ class UBFeaturesPathViewer;
class
UBFeatureProperties
;
class
UBFeatureItemButton
;
class
UBFeaturesListView
;
class
UBFeaturesWebView
;
class
UBFeaturesWidget
:
public
UBDockPaletteWidget
{
...
...
@@ -58,6 +62,7 @@ public:
private
:
void
switchToListView
();
void
switchToProperties
();
void
switchToWebView
();
UBFeaturesController
*
controller
;
...
...
@@ -78,7 +83,9 @@ private:
QGraphicsScene
*
pathScene
;
UBFeaturesActionBar
*
mActionBar
;
UBFeatureProperties
*
featureProperties
;
UBFeaturesWebView
*
webView
;
QStackedWidget
*
stackedWidget
;
int
currentStackedWidget
;
QModelIndex
trashIndex
;
...
...
@@ -92,6 +99,8 @@ private slots:
void
addToFavorite
(
const
QMimeData
&
);
void
removeFromFavorite
(
const
QMimeData
&
);
void
thumbnailSizeChanged
(
int
);
void
onDisplayMetadata
(
QMap
<
QString
,
QString
>
);
void
onAddDownloadedFileToLibrary
(
bool
,
QUrl
,
QString
,
QByteArray
);
protected
:
bool
eventFilter
(
QObject
*
target
,
QEvent
*
event
);
};
...
...
@@ -105,8 +114,32 @@ public:
protected
:
virtual
void
dragEnterEvent
(
QDragEnterEvent
*
event
);
virtual
void
dropEvent
(
QDropEvent
*
event
);
/*virtual void mousePressEvent( QMouseEvent *event );
virtual void mouseMoveEvent( QMouseEvent *event );
virtual void mouseReleaseEvent( QMouseEvent *event );*/
private
:
//UBRubberBand *rubberBand;
//QPoint rubberOrigin;
};
class
UBFeaturesWebView
:
public
QWidget
{
Q_OBJECT
public
:
UBFeaturesWebView
(
QWidget
*
parent
=
0
,
const
char
*
name
=
"UBFeaturesWebView"
);
~
UBFeaturesWebView
();
void
showElement
(
const
UBFeature
&
elem
);
private
slots
:
void
onLoadFinished
(
bool
ok
);
private
:
QWebView
*
mpView
;
QWebSettings
*
mpWebSettings
;
QVBoxLayout
*
mpLayout
;
UBWidgetUniboardAPI
*
mpSankoreAPI
;
};
class
UBFeatureProperties
:
public
QWidget
{
...
...
@@ -119,28 +152,31 @@ public:
protected
:
//
void resizeEvent(QResizeEvent *event);
//
void showEvent(QShowEvent *event);
void
resizeEvent
(
QResizeEvent
*
event
);
void
showEvent
(
QShowEvent
*
event
);
private
slots
:
void
onAddToPage
();
//
void onAddToLib();
//
void onSetAsBackground();
void
onAddToLib
();
void
onSetAsBackground
();
//void onBack();
private
:
void
populateMetadata
();
void
adaptSize
();
QVBoxLayout
*
mpLayout
;
QHBoxLayout
*
mpButtonLayout
;
UBFeatureItemButton
*
mpAddPageButton
;
UBFeatureItemButton
*
mpAddToLibButton
;
UBFeatureItemButton
*
mpSetAsBackgroundButton
;
QLabel
*
mpObjInfoLabel
;
//
QTreeWidget* mpObjInfos;
QTreeWidget
*
mpObjInfos
;
QLabel
*
mpThumbnail
;
QPixmap
*
mpOrigPixmap
;
int
maxThumbHeight
;
UBFeature
*
mpElement
;
//
QTreeWidgetItem* mpItem;
QTreeWidgetItem
*
mpItem
;
};
...
...
@@ -174,7 +210,7 @@ public:
Qt
::
DropActions
supportedDropActions
()
const
{
return
Qt
::
MoveAction
|
Qt
::
CopyAction
;
}
void
setFeaturesList
(
QList
<
UBFeature
>
*
flist
)
{
featuresList
=
flist
;
}
void
setFeaturesList
(
QList
<
UBFeature
>
*
flist
)
{
featuresList
=
flist
;
}
private
:
QList
<
UBFeature
>
*
featuresList
;
};
...
...
src/gui/UBLibItemProperties.cpp
View file @
56eceb66
...
...
@@ -18,12 +18,13 @@
#include "core/UBApplication.h"
#include "core/UBDownloadManager.h"
#include "core/memcheck.h"
#include "frameworks/UBFileSystemUtils.h"
#include "globals/UBGlobals.h"
#include "core/memcheck.h"
/**
* \brief Constructor
...
...
src/gui/UBLibNavigatorWidget.cpp
View file @
56eceb66
...
...
@@ -16,10 +16,11 @@
#include "UBLibWidget.h"
#include "core/UBApplication.h"
#include "core/memcheck.h"
#include "globals/UBGlobals.h"
#include "core/memcheck.h"
static
int
lowBoundForSlider
=
40
;
static
int
topBoundForSlider
=
120
;
static
int
tickIntervalForSlider
=
10
;
...
...
src/gui/UBLibPathViewer.cpp
View file @
56eceb66
...
...
@@ -20,10 +20,11 @@
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
#include "core/UBDownloadManager.h"
#include "board/UBBoardPaletteManager.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
...
...
src/gui/UBLibWebView.cpp
View file @
56eceb66
#include <QDomDocument>
#include "core/UBApplication.h"
#include "core/memcheck.h"
#include "board/UBBoardController.h"
...
...
@@ -9,7 +8,7 @@
#include "UBLibWebView.h"
#include "core/memcheck.h"
UBLibWebView
::
UBLibWebView
(
QWidget
*
parent
,
const
char
*
name
)
:
QWidget
(
parent
)
,
mpView
(
NULL
)
...
...
src/gui/UBLibWidget.cpp
View file @
56eceb66
...
...
@@ -17,10 +17,11 @@
#include "UBLibWidget.h"
#include "core/UBApplication.h"
#include "core/memcheck.h"
#include "globals/UBGlobals.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
...
...
src/gui/UBPageNavigationWidget.cpp
View file @
56eceb66
...
...
@@ -14,12 +14,13 @@
*/
#include "UBPageNavigationWidget.h"
#include "core/UBApplication.h"
#include "core/memcheck.h"
#include "board/UBBoardController.h"
#include "globals/UBGlobals.h"
#include "core/memcheck.h"
/**
* \brief Constructor
* @param parent as the parent widget
...
...
src/gui/UBTGWidgetTreeDelegate.cpp
View file @
56eceb66
...
...
@@ -7,6 +7,8 @@
#include <QModelIndex>
#include "UBTGWidgetTreeDelegate.h"
#include "core/memcheck.h"
UBTGWidgetTreeDelegate
::
UBTGWidgetTreeDelegate
(
QObject
*
parent
)
:
QStyledItemDelegate
(
parent
)
{
...
...
src/gui/UBTeacherGuideDelegate.cpp
View file @
56eceb66
#include "UBTeacherGuideDelegate.h"
#include "core/memcheck.h"
UBTeacherGuideDelegate
::
UBTeacherGuideDelegate
()
{
...
...
src/gui/UBTeacherGuideWidget.cpp
View file @
56eceb66
...
...
@@ -40,6 +40,8 @@
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentController.h"
#include "core/memcheck.h"
#define UBTG_SEPARATOR_FIXED_HEIGHT 3
...
...
src/gui/UBTeacherGuideWidgetsTools.cpp
View file @
56eceb66
...
...
@@ -32,6 +32,8 @@
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h"
/***************************************************************************
* class UBAddItem *
...
...
src/pdf-merger/CCITTFaxDecode.cpp
View file @
56eceb66
...
...
@@ -16,6 +16,8 @@
#include <QtGlobal>
#include "CCITTFaxDecode.h"
#include "core/memcheck.h"
using
namespace
merge_lib
;
bool
CCITTFaxDecode
::
encode
(
std
::
string
&
decoded
)
...
...
src/pdf-merger/DCTDecode.cpp
View file @
56eceb66
...
...
@@ -16,6 +16,8 @@
#include <QtGlobal>
#include "DCTDecode.h"
#include "core/memcheck.h"
using
namespace
merge_lib
;
bool
DCTDecode
::
encode
(
std
::
string
&
decoded
)
...
...
src/pdf-merger/JBIG2Decode.cpp
View file @
56eceb66
...
...
@@ -15,6 +15,7 @@
#include <QtGlobal>
#include "JBIG2Decode.h"
#include "core/memcheck.h"
using
namespace
merge_lib
;
...
...
src/web/UBOEmbedParser.cpp
View file @
56eceb66
...
...
@@ -24,6 +24,8 @@
#include "UBOEmbedParser.h"
#include "core/memcheck.h"
UBOEmbedParser
::
UBOEmbedParser
(
QObject
*
parent
,
const
char
*
name
)
{
Q_UNUSED
(
parent
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment