Merge branch 'master' of github.com:Sankore/Sankore-3.1

preferencesAboutTextFull
Claudio Valerio 13 years ago
commit 44616b3491
  1. 6
      Sankore 3.1.iss
  2. 43
      release.linux.sh
  3. 2
      release.win7.vc9.64.bat
  4. 2
      release.win7.vc9.bat
  5. 15
      src/adaptors/UBSvgSubsetAdaptor.cpp
  6. 10
      src/board/UBBoardController.cpp
  7. 12
      src/board/UBBoardView.cpp
  8. 1
      src/board/UBBoardView.h
  9. 10
      src/board/UBDrawingController.cpp
  10. 2
      src/board/UBDrawingController.h
  11. 3
      src/core/UB.h
  12. 2
      src/domain/UBGraphicsDelegateFrame.cpp
  13. 56
      src/domain/UBGraphicsItemDelegate.cpp
  14. 7
      src/domain/UBGraphicsItemDelegate.h
  15. 23
      src/domain/UBGraphicsPolygonItem.cpp
  16. 6
      src/domain/UBGraphicsPolygonItem.h
  17. 333
      src/domain/UBGraphicsScene.cpp
  18. 4
      src/domain/UBGraphicsScene.h
  19. 5
      src/domain/UBGraphicsStrokesGroup.h
  20. 5
      src/domain/UBGraphicsWidgetItem.cpp
  21. 2
      src/domain/UBGraphicsWidgetItem.h
  22. 158
      src/domain/ubgraphicsgroupcontaineritem.cpp
  23. 18
      src/domain/ubgraphicsgroupcontaineritem.h
  24. 24
      src/domain/ubgraphicsgroupcontaineritemdelegate.cpp
  25. 6
      src/domain/ubgraphicsgroupcontaineritemdelegate.h
  26. 3
      src/frameworks/UBGeometryUtils.cpp
  27. 19
      src/gui/UBFeaturesActionBar.cpp
  28. 4
      src/gui/UBFeaturesActionBar.h
  29. 184
      src/gui/UBFeaturesWidget.cpp
  30. 13
      src/gui/UBFeaturesWidget.h
  31. 1
      src/tools/UBGraphicsCompass.cpp
  32. 1
      src/tools/UBGraphicsProtractor.cpp
  33. 2
      src/tools/UBGraphicsProtractor.h
  34. 3
      src/tools/UBGraphicsRuler.cpp
  35. 1
      src/tools/UBGraphicsTriangle.cpp

@ -45,7 +45,10 @@ Type: files ; Name: "{app}\*.dll"
[Files]
Source: "..\Sankore-ThirdParty\microsoft\vcredist_x86.exe"; DestDir:"{tmp}"
Source: ".\build\win32\release\product\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "build\win32\release\product\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
;Sankore plugins
Source: "plugins\cffadaptor\build\win32\release\lib\CFF_Adaptor.dll"; DestDir: "{app}"; Flags: ignoreversion
;OpenSSL
Source: "..\Sankore-ThirdParty\openssl\win32\libeay32.dll"; DestDir:"{app}"; Flags: ignoreversion
@ -60,6 +63,7 @@ Source: "..\Qt-sankore3.1\lib\QtWebKit4.dll"; DestDir: "{app}"; Flags: ignorever
Source: "..\Qt-sankore3.1\lib\phonon4.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\Qt-sankore3.1\lib\QtNetwork4.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\Qt-sankore3.1\lib\QtSvg4.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\Qt-sankore3.1\lib\QtOpenGL4.dll"; DestDir: "{app}"; Flags: ignoreversion
;Qt plugins
Source: "..\Qt-sankore3.1\plugins\accessible\qtaccessiblecompatwidgets4.dll"; DestDir: "{app}\accessible"; Flags: ignoreversion

@ -39,14 +39,18 @@ checkDirectory(){
# path definition #
#######################################################################
QT_PATH="/usr/local/Trolltech/Qt-4.7.3"
PLUGINS_PATH="$QT_PATH/plugins"
QT_PLUGINS_PATH="$QT_PATH/plugins"
RELEASE_DIR=build/linux/release
BUILD_DIR=$RELEASE_DIR/product
GUI_TRANSLATIONS_DIRECTORY_PATH="../Qt-sankore3.1/translations"
QT_LIBRARY_SOURCE_PATH="$QT_PATH/lib"
SANKORE_SRC_PLUGINS_PATH="plugins"
SANKORE_DST_PLUGINS_PATH=build/linux/release/product/plugins
CFF_ADAPTOR_SRC_PLUGIN_PATH=$SANKORE_SRC_PLUGINS_PATH/cffadaptor/build/linux/release/lib
QMAKE_PATH="$QT_PATH/bin/qmake"
LRELEASE="/usr/local/Trolltech/Qt-4.7.3/bin/lrelease"
LRELEASE="../Qt-sankore3.1/bin/lrelease"
#LRELEASE="/usr/local/Trolltech/Qt-4.7.3/bin/lrelease"
ARCHITECTURE=`uname -m`
@ -57,13 +61,15 @@ checkExecutable $QMAKE_PATH
checkExecutable $LRELEASE
checkDirectory $GUI_TRANSLATIONS_DIRECTORY_PATH
checkDirectory $PLUGINS_PATH
checkDirectory $QT_PLUGINS_PATH
checkDirectory $QT_LIBRARY_SOURCE_PATH
checkDirectory $CFF_ADAPTOR_PLUGIN_PATH
#######################################################################
# cleaning #
#######################################################################
rm -rf $RELEASE_DIR
#rm -rf $RELEASE_DIR
#######################################################################
@ -126,21 +132,26 @@ cp -R resources/linux/qtlinux/* $BUILD_DIR
cp -R resources/customizations $BUILD_DIR
notify-send "Sankore" "Copying plugins..."
mkdir "$SANKORE_DST_PLUGINS_PATH"
mkdir "$SANKORE_DST_PLUGINS_PATH/cffadaptor"
cp -R $CFF_ADAPTOR_SRC_PLUGIN_PATH/*.so* "$SANKORE_DST_PLUGINS_PATH/cffadaptor"
notify-send "QT" "Coping plugins and library ..."
cp -R $PLUGINS_PATH $BUILD_DIR
cp -R $QT_PLUGINS_PATH $BUILD_DIR
#copying custom qt library
QT_LIBRARY_DEST_PATH="$BUILD_DIR/qtlib"
mkdir $QT_LIBRARY_DEST_PATH
copyQtLibrary(){
if [ ! -e "$QT_LIBRARY_SOURCE_PATH/$1.so.4.7.3" ]; then
if [ ! -e "$QT_LIBRARY_SOURCE_PATH/$1.so.4" ]; then
notifyError "$1 library not found in path: $QT_LIBRARY_SOURCE_PATH"
fi
cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4" "$QT_LIBRARY_DEST_PATH/"
cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4.7.3" "$QT_LIBRARY_DEST_PATH/"
cp $QT_LIBRARY_SOURCE_PATH/$1.so.4.* $QT_LIBRARY_DEST_PATH/
}
copyQtLibrary libphonon
copyQtLibrary libQtWebKit
copyQtLibrary libQtDBus
copyQtLibrary libQtScript
@ -150,14 +161,8 @@ copyQtLibrary libQtNetwork
copyQtLibrary libQtXml
copyQtLibrary libQtGui
copyQtLibrary libQtCore
if [ ! -e "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4.4.0" ]; then
notifyError "phonon library not found in path: $QT_LIBRARY_SOURCE_PATH"
else
cp "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4" "$QT_LIBRARY_DEST_PATH/"
cp "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4.4.0" "$QT_LIBRARY_DEST_PATH/"
fi
# uncomment for Qt 4.8
#copyQtLibrary libQtOpenGL
#######################################################################
# Removing unwanted files #
@ -279,7 +284,7 @@ echo "Priority: optional" >> "$CONTROL_FILE"
echo "Architecture: $ARCHITECTURE" >> "$CONTROL_FILE"
echo "Essential: no" >> "$CONTROL_FILE"
echo "Installed-Size: `du -s $SANKORE_PACKAGE_DIRECTORY | awk '{ print $1 }'`" >> "$CONTROL_FILE"
echo "Maintainer: Open-Sankoré Developers team <dev@open-sankore.org>" >> "$CONTROL_FILE"
echo "Maintainer: Open-Sankore Developers team <dev@open-sankore.org>" >> "$CONTROL_FILE"
echo "Homepage: http://dev.open-sankore.org" >> "$CONTROL_FILE"
echo -n "Depends: " >> "$CONTROL_FILE"
unset tab
@ -318,7 +323,7 @@ echo "Version=$VERSION" >> $SANKORE_SHORTCUT
echo "Encoding=UTF-8" >> $SANKORE_SHORTCUT
echo "Name=Open-Sankore ($VERSION)" >> $SANKORE_SHORTCUT
echo "GenericName=Open-Sankore" >> $SANKORE_SHORTCUT
echo "Comment=Logiciel de création de présentations pour tableau numérique interactif (TNI)" >> $SANKORE_SHORTCUT
echo "Comment=Logiciel de creation de presentations pour tableau numerique interactif (TNI)" >> $SANKORE_SHORTCUT
echo "Exec=/usr/local/$SANKORE_DIRECTORY_NAME/run.sh" >> $SANKORE_SHORTCUT
echo "Icon=/usr/local/$SANKORE_DIRECTORY_NAME/sankore.png" >> $SANKORE_SHORTCUT
echo "StartupNotify=true" >> $SANKORE_SHORTCUT
@ -353,4 +358,4 @@ cd $RELEASE_DIR
rm ../../../install/linux/Open-Sankore.tar.gz
tar cvzf ../../../install/linux/Open-Sankore.tar.gz Open-Sankore.$VERSION -C .
notify-send "Open-Sankore" "tar.gz Build done"
notify-send "Open-Sankore" "tar.gz Build done"

@ -62,7 +62,7 @@ nmake release-install
copy %BASE_QT_TRANSLATIONS_DIRECTORY%\qt_*.qm build\win32\release\product\i18n\
del build\win32\release\product\i18n\qt_help*
del ".\build\win32\release\product\Sankore.pdb"
del "build\win32\release\product\Sankore.pdb"
set INSTALLER_NAME=Open-Sankore

@ -66,7 +66,7 @@ copy resources\customizations build\win32\release\product\
del build\win32\release\product\i18n\qt_help*
del ".\build\win32\release\product\Sankore.pdb"
del "build\win32\release\product\Sankore.pdb"
set INSTALLER_NAME=Open-Sankore

@ -30,6 +30,7 @@
#include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsStroke.h"
#include "domain/UBGraphicsStrokesGroup.h"
#include "domain/ubgraphicsgroupcontaineritem.h"
#include "domain/UBItem.h"
#include "tools/UBGraphicsRuler.h"
@ -1004,8 +1005,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement()
bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
{
if (mScene->isModified())
{
static int i = 0;
qDebug() << "persist call no is " << ++i;
QBuffer buffer;
buffer.open(QBuffer::WriteOnly);
mXmlWriter.setDevice(&buffer);
@ -1218,6 +1224,14 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
triangleToSvg(triangle);
continue;
}
UBGraphicsGroupContainerItem *groupItem = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item);
if (groupItem && groupItem->isVisible())
{
qDebug() << "came across the group during the parsing";
continue;
}
}
if (openStroke)
@ -1269,7 +1283,6 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
return true;
}
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo)
{
mXmlWriter.writeStartElement("line");

@ -1259,10 +1259,12 @@ void UBBoardController::ClearUndoStack()
while (itUniq.hasNext())
{
QGraphicsItem* item = itUniq.next();
UBGraphicsScene *scene = dynamic_cast<UBGraphicsScene*>(item->scene());
if(!scene)
{
mActiveScene->deleteItem(item);
if (item->scene()) {
UBGraphicsScene *scene = dynamic_cast<UBGraphicsScene*>(item->scene());
if(!scene)
{
mActiveScene->deleteItem(item);
}
}
}

@ -50,6 +50,8 @@
#include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/ubgraphicsgroupcontaineritem.h"
#include "domain/UBGraphicsStrokesGroup.h"
#include "document/UBDocumentProxy.h"
@ -435,8 +437,8 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
|| movingItem->type() == UBGraphicsCache::Type
|| movingItem->type() == UBGraphicsTriangle::Type
|| movingItem == this->scene()->backgroundObject()
|| movingItem->group())
{
|| (movingItem->parentItem() && movingItem->parentItem()->type() == UBGraphicsGroupContainerItem::Type))
{
movingItem = NULL;
QGraphicsView::mousePressEvent (event);
@ -515,8 +517,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
}
}
QSet<QGraphicsItem*> mJustSelectedItems;
void
UBBoardView::mouseMoveEvent (QMouseEvent *event)
{
@ -562,7 +562,9 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
|| item->type() == UBGraphicsPixmapItem::Type
|| item->type() == UBGraphicsVideoItem::Type
|| item->type() == UBGraphicsAudioItem::Type
|| item->type() == UBGraphicsSvgItem::Type) {
|| item->type() == UBGraphicsSvgItem::Type
|| item->type() == UBGraphicsTextItem::Type
|| item->type() == UBGraphicsStrokesGroup::Type) {
if (!mJustSelectedItems.contains(item)) {
item->setSelected(true);

@ -125,6 +125,7 @@ class UBBoardView : public QGraphicsView
QMouseEvent *suspendedMousePressEvent;
UBRubberBand *mUBRubberBand;
QSet<QGraphicsItem*> mJustSelectedItems;
private slots:

@ -45,7 +45,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
, mActiveRuler(NULL)
, mStylusTool((UBStylusTool::Enum)-1)
, mLatestDrawingTool((UBStylusTool::Enum)-1)
//, mDrawingMode(eDrawingMode_Vector)
, mDrawingMode(/*DRAWING_MODE*/eDrawingMode_Vector)
{
connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged()));
@ -106,10 +106,16 @@ void UBDrawingController::setStylusTool(int tool)
mStylusTool = (UBStylusTool::Enum)tool;
if(eDrawingMode_Vector == DRAWING_MODE){
mDrawingMode = eDrawingMode_Vector;
}
if (mStylusTool == UBStylusTool::Pen)
UBApplication::mainWindow->actionPen->setChecked(true);
else if (mStylusTool == UBStylusTool::Eraser)
else if (mStylusTool == UBStylusTool::Eraser){
UBApplication::mainWindow->actionEraser->setChecked(true);
//mDrawingMode = eDrawingMode_Artistic;
}
else if (mStylusTool == UBStylusTool::Marker)
UBApplication::mainWindow->actionMarker->setChecked(true);
else if (mStylusTool == UBStylusTool::Selector)

@ -27,6 +27,8 @@ typedef enum{
eDrawingMode_Vector
}eDrawingMode;
#define DRAWING_MODE eDrawingMode_Vector
class UBDrawingController : public QObject
{
Q_OBJECT;

@ -123,7 +123,8 @@ struct UBGraphicsItemType
StrokeItemType,
TriangleItemType,
MagnifierItemType,
cacheItemType
cacheItemType,
groupContainerType
};
};

@ -583,7 +583,7 @@ void UBGraphicsDelegateFrame::positionHandles()
{
QRectF itemRect = delegated()->boundingRect();
if (mDelegate->getToolBarItem()->isVisibleOnBoard()
if (mDelegate->getToolBarItem()->isVisibleOnBoard()
&& mDelegate->getToolBarItem()->isShifting())
itemRect.setHeight(itemRect.height() + mDelegate->getToolBarItem()->rect().height() * mDelegate->antiScaleRatio() * 1.1);

@ -40,6 +40,7 @@
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsVideoItem.h"
#include "domain/ubgraphicsgroupcontaineritem.h"
#include "web/UBWebController.h"
@ -167,7 +168,9 @@ UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedHasChanged) {
if(change == QGraphicsItem::ItemChildAddedChange){
}else if (change == QGraphicsItem::ItemSelectedHasChanged) {
bool ok;
bool selected = value.toUInt(&ok);
if (ok) {
@ -217,10 +220,9 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
startUndoStep();
if (!mDelegated->isSelected())
if (!delegated()->isSelected())
{
mDelegated->setSelected(true);
positionHandles();
delegated()->setSelected(true);
return true;
}
else
@ -236,33 +238,31 @@ void UBGraphicsItemDelegate::setMimeData(QMimeData *mimeData)
bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if((NULL != mMimeData) && ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance()))
{
QDrag* mDrag = new QDrag(event->widget());
mDrag->setMimeData(mMimeData);
if (!mDragPixmap.isNull()) {
mDrag->setPixmap(mDragPixmap);
mDrag->setHotSpot(mDragPixmap.rect().center());
}
mDrag->exec();
mDragPixmap = QPixmap();
return true;
if(mMimeData) {
QDrag* mDrag = new QDrag(event->widget());
mDrag->setMimeData(mMimeData);
if (!mDragPixmap.isNull()) {
mDrag->setPixmap(mDragPixmap);
mDrag->setHotSpot(mDragPixmap.rect().center());
}
mDrag->exec();
mDragPixmap = QPixmap();
if(isLocked())
{
event->accept();
return true;
}
return true;
if(isLocked()) {
event->accept();
return true;
} else {
return false;
}
}
bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event)
{
Q_UNUSED(event);
if( mDelegated->isSelected() )
if( delegated()->isSelected() )
{
// event->accept();
return true;
@ -310,6 +310,18 @@ void UBGraphicsItemDelegate::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
// }
}
QGraphicsItem *UBGraphicsItemDelegate::delegated()
{
QGraphicsItem *curDelegate = 0;
if (mDelegated->parentItem() && mDelegated->parentItem()->type() == UBGraphicsGroupContainerItem::Type) {
curDelegate = mDelegated->parentItem(); // considering delegated item as an item's group which contains everything
} else {
curDelegate = mDelegated;
}
return curDelegate;
}
void UBGraphicsItemDelegate::positionHandles()
{
if (mDelegated->isSelected()) {
@ -363,7 +375,7 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible)
void UBGraphicsItemDelegate::remove(bool canUndo)
{
// QGraphicsScene* scene = mDelegated->scene();
UBGraphicsScene* scene = (UBGraphicsScene*)(mDelegated->scene());
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene());
if (scene)
{
foreach(DelegateButton* button, mButtons)

@ -4,7 +4,7 @@
* 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,
* This prograscenem 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.
@ -121,10 +121,7 @@ class UBGraphicsItemDelegate : public QObject
void printMessage(const QString &mess) {qDebug() << mess;}
QGraphicsItem* delegated()
{
return mDelegated;
}
QGraphicsItem* delegated();
void setCanDuplicate(bool allow){ mCanDuplicate = allow; }

@ -39,6 +39,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi
, mOriginalWidth(-1)
, mIsNominalLine(false)
, mStroke(0)
, mpGroup(NULL)
{
// NOOP
initialize();
@ -77,6 +78,10 @@ UBGraphicsPolygonItem::~UBGraphicsPolygonItem()
clearStroke();
}
void UBGraphicsPolygonItem::setStrokesGroup(UBGraphicsStrokesGroup *group)
{
mpGroup = group;
}
void UBGraphicsPolygonItem::setStroke(UBGraphicsStroke* stroke)
{
@ -156,7 +161,7 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con
copy->mIsNominalLine = false;
copy->setStroke(this->stroke());
copy->setGroup(this->group());
copy->setStrokesGroup(this->strokesGroup());
copy->setBrush(this->brush());
copy->setPen(this->pen());
copy->mHasAlpha = this->mHasAlpha;
@ -184,18 +189,18 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi
QGraphicsPolygonItem::paint(painter, option, widget);
}
QPainterPath UBGraphicsPolygonItem::shape() const
{
//QPainterPath UBGraphicsPolygonItem::shape() const
//{
QPainterPath path;
path.addRect(boundingRect());
// QPainterPath path;
// path.addRect(boundingRect());
return path;
// return path;
// static QPainterPath shapePath = QGraphicsPolygonItem::shape();
//// static QPainterPath shapePath = QGraphicsPolygonItem::shape();
// return shapePath;
}
//// return shapePath;
//}
UBGraphicsScene* UBGraphicsPolygonItem::scene()

@ -19,6 +19,7 @@
#include "core/UB.h"
#include "UBItem.h"
#include "UBGraphicsStrokesGroup.h"
class UBItem;
class UBGraphicsScene;
@ -37,6 +38,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
void initialize();
void setStrokesGroup(UBGraphicsStrokesGroup* group);
UBGraphicsStrokesGroup* strokesGroup() const{return mpGroup;}
void setColor(const QColor& color);
QColor color() const;
@ -115,7 +118,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
protected:
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
QPainterPath shape () const;
// QPainterPath shape () const;
private:
@ -132,6 +135,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
QColor mColorOnLightBackground;
UBGraphicsStroke* mStroke;
UBGraphicsStrokesGroup* mpGroup;
};

@ -65,6 +65,9 @@
#include "core/memcheck.h"
const QString groupText = "Group items";
const QString ungroupText = "Ungroup items";
qreal UBZLayerController::errorNumber = -20000001.0;
UBZLayerController::UBZLayerController(QGraphicsScene *scene) :
@ -291,9 +294,15 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
}
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(enableGroupingButton()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(updateGroupButtonState()));
connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(processGroupItems()));
// just a stub don't treat as a result code
// static int i = 0;
// i++;
// if (i == 1) {
connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(groupButtonClicked()));
// qDebug() << "the connect is accepted";
// }
}
UBGraphicsScene::~UBGraphicsScene()
@ -308,39 +317,78 @@ UBGraphicsScene::~UBGraphicsScene()
void UBGraphicsScene::selectionChangedProcessing()
{
if (selectedItems().count())
if (selectedItems().count()){
qDebug() << "Selected item bounding rect: " << selectedItems().first()->boundingRect();
UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is "
+ QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f'));
}
}
void UBGraphicsScene::enableGroupingButton()
void UBGraphicsScene::updateGroupButtonState()
{
QAction *groupAction = UBApplication::mainWindow->actionGroupItems;
QList<QGraphicsItem*> selItems = selectedItems();
int selCount = selItems.count();
if (selectedItems().count() > 1) {
groupAction->setEnabled(true);
} else {
if (selCount < 1) {
groupAction->setEnabled(false);
groupAction->setText(groupText);
} else if (selCount == 1) {
if (selItems.first()->type() == UBGraphicsGroupContainerItem::Type) {
groupAction->setEnabled(true);
groupAction->setText(ungroupText);
} else {
groupAction->setEnabled(false);
}
} else if (selCount > 1) {
groupAction->setEnabled(true);
groupAction->setText(groupText);
}
}
void UBGraphicsScene::processGroupItems()
void UBGraphicsScene::groupButtonClicked()
{
qDebug() << "processing grouping items";
QAction *groupAction = UBApplication::mainWindow->actionGroupItems;
QList<QGraphicsItem*> selItems = selectedItems();
if (!selItems.count()) {
qDebug() << "Got grouping request when there is no any selected item on the scene";
return;
}
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
if (groupAction->text() == groupText) { //The only way to get information from item, considering using smth else
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
foreach (QGraphicsItem *item, selectedItems()) {
item->setSelected(false);
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
item->setFlag( QGraphicsItem::ItemIsMovable, false);
item->setFlag(QGraphicsItem::ItemIsFocusable);
groupItem->addToGroup(item);
foreach (QGraphicsItem *item, selItems) {
if (item->type() == UBGraphicsGroupContainerItem::Type) {
QList<QGraphicsItem*> childItems = item->childItems();
UBGraphicsGroupContainerItem *currentGroup = dynamic_cast<UBGraphicsGroupContainerItem*>(item);
if (currentGroup) {
currentGroup->destroy();
}
foreach (QGraphicsItem *chItem, childItems) {
groupItem->addToGroup(chItem);
}
} else {
groupItem->addToGroup(item);
}
}
addItem(groupItem);
groupItem->setVisible(true);
groupItem->setFocus();
} else if (groupAction->text() == ungroupText) {
//Considering one selected item and it's a group
if (selItems.count() > 1) {
qDebug() << "can't make sense of ungrouping more then one item. Grouping action should be performed for that purpose";
return;
}
UBGraphicsGroupContainerItem *currentGroup = dynamic_cast<UBGraphicsGroupContainerItem*>(selItems.first());
if (currentGroup) {
currentGroup->destroy();
}
}
addItem(groupItem);
// groupItem->setPos(50, 50);
groupItem->setVisible(true);
groupItem->setFocus();
qDebug() << groupItem->boundingRect();
}
// MARK: -
@ -432,7 +480,6 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
return accepted;
}
bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pressure)
{
bool accepted = false;
@ -567,7 +614,7 @@ bool UBGraphicsScene::inputDeviceRelease()
}
}else if (mCurrentStroke)
{
if(eDrawingMode_Vector == dc->drawingMode()){
if(eDrawingMode_Vector == DRAWING_MODE){
UBGraphicsStrokesGroup* pStrokes = new UBGraphicsStrokesGroup();
// Remove the strokes that were just drawn here and replace them by a stroke item
@ -575,6 +622,7 @@ bool UBGraphicsScene::inputDeviceRelease()
mPreviousPolygonItems.removeAll(poly);
removeItem(poly);
UBCoreGraphicsScene::removeItemFromDeletion(poly);
poly->setStrokesGroup(pStrokes);
pStrokes->addToGroup(poly);
}
@ -746,6 +794,8 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth,
void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
{
// QList<QGraphicsItem*> itemList;
const QLineF line(mPreviousPoint, pEndPoint);
const QPolygonF eraserPolygon = UBGeometryUtils::lineToPolygon(line, pWidth);
@ -756,114 +806,208 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
eraserPathVar.addPolygon(eraserPolygon);
const QPainterPath eraserPath = eraserPathVar;
// Get all the items that are intersecting with the eraser path
QList<QGraphicsItem*> collidItems = items(eraserBoundingRect, Qt::IntersectsItemBoundingRect);
QSet<QGraphicsItem*> toBeAddedItems;
QSet<QGraphicsItem*> toBeRemovedItems;
int collidItemsSize = collidItems.size();
if(eDrawingMode_Vector == UBDrawingController::drawingController()->drawingMode()){
// NOTE: I decided to reuse the 'artistic' eraser all the time in order to have a better eraser
// For this reason, the following code is not used but we will keep it for now, in case of
// futur requirements.
foreach(QGraphicsItem* poly, collidItems){
UBGraphicsStrokesGroup* pGroup = dynamic_cast<UBGraphicsStrokesGroup*>(poly);
if(NULL != pGroup){
// TODO: Ungroup the item, put back the polygons on the scene, deal with the
// eraser's bounding rect, remove the polygons that must be removed
// then create new groups.
// Get all substrokes and verify if they are part of the eraserpath then deal with it
foreach(QGraphicsItem* item, poly->childItems()){
UBGraphicsPolygonItem* polygon = dynamic_cast<UBGraphicsPolygonItem*>(item);
if(NULL != polygon){
if(eraserBoundingRect.intersects(polygon->boundingRect())){
pGroup->removeFromGroup(polygon);
removeItem(polygon);
}
}
}
}
}
toBeAddedItems.reserve(collidItemsSize);
toBeRemovedItems.reserve(collidItemsSize);
}else{
QSet<QGraphicsItem*> toBeAddedItems;
QSet<QGraphicsItem*> toBeRemovedItems;
int collidItemsSize = collidItems.size();
toBeAddedItems.reserve(collidItemsSize);
toBeRemovedItems.reserve(collidItemsSize);
if (mShouldUseOMP)
{
#pragma omp parallel for
for (int i = 0; i < collidItemsSize; i++)
if (mShouldUseOMP)
{
UBGraphicsPolygonItem *collidingPolygonItem
= qgraphicsitem_cast<UBGraphicsPolygonItem*> (collidItems.at(i));
if (collidingPolygonItem)
// #pragma omp parallel for
for (int i = 0; i < collidItemsSize; i++)
{
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect()))
{
#pragma omp critical
toBeRemovedItems << collidingPolygonItem;
}
else
UBGraphicsPolygonItem *collidingPolygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems.at(i));
if (NULL != collidingPolygonItem)
{
QPolygonF collidingPolygon = collidingPolygonItem->polygon();
QPainterPath collidingPath;
collidingPath.addPolygon(collidingPolygon);
collidingPolygonItem->setColor(QColor(Qt::green));
QPainterPath croppedPath = collidingPath.subtracted(eraserPath);
QPainterPath croppedPathSimplified = croppedPath.simplified();
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup();
if (croppedPath == collidingPath)
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect()))
{
// NOOP
}
else if (croppedPathSimplified.isEmpty())
{
#pragma omp critical
// #pragma omp critical
qDebug() << "case 1";
// Put the entire polygon into the remove list
collidingPolygonItem->setColor(QColor(Qt::blue));
toBeRemovedItems << collidingPolygonItem;
}
else
{
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons())
// Here we get the polygon of the colliding item
QPolygonF collidingPolygon = collidingPolygonItem->polygon();
QPainterPath collidingPath;
collidingPath.addPolygon(collidingPolygon);
// Then we substract the eraser path to the polygon and we simplify it
QPainterPath croppedPath = collidingPath.subtracted(eraserPath);
QPainterPath croppedPathSimplified = croppedPath.simplified();
/*if (croppedPath == collidingPath)
{
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol);
#pragma omp critical
toBeAddedItems << croppedPolygonItem;
// NOOP
qDebug() << "case 2";
toBeRemovedItems << collidingPolygonItem;
}
else */if (croppedPathSimplified.isEmpty())
{
// #pragma omp critical
qDebug() << "case 3";
// Put the entire polygon into the remove list if the eraser removes all its visible content
collidingPolygonItem->setColor(QColor(Qt::blue));
toBeRemovedItems << collidingPolygonItem;
}
else
{
//qDebug() << "case 4";
// Then we convert the remaining path to a list of polygons that will be converted in
// UBGraphicsPolygonItems and added to the scene
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons())
{
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol);
croppedPolygonItem->setColor(QColor(Qt::black));
// #pragma omp critical
if(NULL != pGroup){
croppedPolygonItem->setStrokesGroup(pGroup);
// croppedPolygonItem->setTransform(pGroup->sceneTransform().inverted());
}
// Add this new polygon to the 'added' list
toBeAddedItems << croppedPolygonItem;
}
// #pragma omp critical
// Remove the original polygonitem because it has been replaced by many smaller polygons
collidingPolygonItem->setColor(QColor(Qt::blue));
toBeRemovedItems << collidingPolygonItem;
}
#pragma omp critical
toBeRemovedItems << collidingPolygonItem;
}
}
}
}
}
else
{
for (int i = 0; i < collidItemsSize; i++)
else
{
UBGraphicsPolygonItem *collidingPolygonItem
= qgraphicsitem_cast<UBGraphicsPolygonItem*> (collidItems.at(i));
if (collidingPolygonItem)
for (int i = 0; i < collidItemsSize; i++)
{
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect()))
{
toBeRemovedItems << collidingPolygonItem;
}
else
{
QPolygonF collidingPolygon = collidingPolygonItem->polygon();
QPainterPath collidingPath;
collidingPath.addPolygon(collidingPolygon);
UBGraphicsPolygonItem *collidingPolygonItem = dynamic_cast<UBGraphicsPolygonItem*> (collidItems.at(i));
QPainterPath croppedPath = collidingPath.subtracted(eraserPath);
QPainterPath croppedPathSimplified = croppedPath.simplified();
if (collidingPolygonItem)
{
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup();
if (croppedPath == collidingPath)
{
// NOOP
}
else if (croppedPathSimplified.isEmpty())
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect()))
{
toBeRemovedItems << collidingPolygonItem;
}
else
{
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons())
QPolygonF collidingPolygon = collidingPolygonItem->polygon();
QPainterPath collidingPath;
collidingPath.addPolygon(collidingPolygon);
QPainterPath croppedPath = collidingPath.subtracted(eraserPath);
QPainterPath croppedPathSimplified = croppedPath.simplified();
if (croppedPath == collidingPath)
{
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol);
toBeAddedItems << croppedPolygonItem;
// NOOP
}
else if (croppedPathSimplified.isEmpty())
{
toBeRemovedItems << collidingPolygonItem;
}
else
{
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons())
{
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol);
toBeAddedItems << croppedPolygonItem;
if(NULL != pGroup){
croppedPolygonItem->setStrokesGroup(pGroup);
}
}
toBeRemovedItems << collidingPolygonItem;
}
toBeRemovedItems << collidingPolygonItem;
}
}
}
}
}
addItems(toBeAddedItems);
mAddedItems += toBeAddedItems;
if(eDrawingMode_Vector == DRAWING_MODE){
foreach(QGraphicsItem* item, toBeRemovedItems){
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item);
if(NULL != poly){
if(NULL != poly->strokesGroup()){
poly->strokesGroup()->removeFromGroup(poly);
removeItem(poly);
}else{
qDebug() << "No group present";
}
}
}
}else{
removeItems(toBeRemovedItems);
mRemovedItems += toBeRemovedItems;
}
removeItems(toBeRemovedItems);
mRemovedItems += toBeRemovedItems;
// bool hack = false;
// UBGraphicsStrokesGroup* pG = new UBGraphicsStrokesGroup();
if(eDrawingMode_Vector == DRAWING_MODE){
foreach(QGraphicsItem* item, toBeAddedItems){
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item);
if(NULL != poly && NULL != poly->strokesGroup()){
// if(!hack){
// itemList = poly->strokesGroup()->childItems();
// removeItem(poly->strokesGroup());
// foreach(QGraphicsItem* it, itemList){
// pG->addToGroup(it);
// }
// hack = true;
// }
qreal dx = -poly->strokesGroup()->sceneTransform().inverted().dx();
qreal dy = -poly->strokesGroup()->sceneTransform().inverted().dy();
//poly->setTransform(QTransform().translate(20, 0));
poly->setTransform(QTransform().translate(dx, dy));
poly->strokesGroup()/*pG*/->addToGroup(poly);
}
}
//addItem(pG);
}else{
addItems(toBeAddedItems);
mAddedItems += toBeAddedItems;
}
}
mPreviousPoint = pEndPoint;
}
@ -1759,7 +1903,6 @@ QGraphicsItem* UBGraphicsScene::scaleToFitDocumentSize(QGraphicsItem* item, bool
return item;
}
void UBGraphicsScene::addRuler(QPointF center)
{
UBGraphicsRuler* ruler = new UBGraphicsRuler(); // mem : owned and destroyed by the scene

@ -306,8 +306,8 @@ public slots:
void setToolCursor(int tool);
void selectionChangedProcessing();
void enableGroupingButton();
void processGroupItems();
void updateGroupButtonState();
void groupButtonClicked();
void moveMagnifier(QPoint newPos);
void closeMagnifier();

@ -16,6 +16,11 @@ public:
virtual UBItem* deepCopy() const;
virtual void remove();
virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;}
enum { Type = UBGraphicsItemType::StrokeItemType };
virtual int type() const
{
return Type;
}
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);

@ -91,6 +91,11 @@ void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
mDelegate->hoverLeaveEvent(event);
UBGraphicsProxyWidget::hoverLeaveEvent(event);
}
void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
UBGraphicsProxyWidget::hoverMoveEvent(event);
}
bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event)
{

@ -87,6 +87,8 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event);

@ -9,7 +9,7 @@
#include "core/memcheck.h"
UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent)
: QGraphicsItemGroup(parent)
: QGraphicsItem(parent)
{
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
@ -23,12 +23,137 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent
UBGraphicsGroupContainerItem::setAcceptHoverEvents(true);
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
}
void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
{
if (!item) {
qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add null item");
return;
}
if (item == this) {
qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add a group to itself");
return;
}
// COMBINE
bool ok;
QTransform itemTransform = item->itemTransform(this, &ok);
if (!ok) {
qWarning("UBGraphicsGroupContainerItem::addToGroup: could not find a valid transformation from item to group coordinates");
return;
}
//setting item flags to given item
item->setSelected(false);
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
item->setFlag( QGraphicsItem::ItemIsMovable, false);
item->setFlag(QGraphicsItem::ItemIsFocusable, true);
QTransform newItemTransform(itemTransform);
item->setPos(mapFromItem(item, 0, 0));
item->setParentItem(this);
// removing position from translation component of the new transform
if (!item->pos().isNull())
newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y());
// removing additional transformations properties applied with itemTransform()
QPointF origin = item->transformOriginPoint();
QMatrix4x4 m;
QList<QGraphicsTransform*> transformList = item->transformations();
for (int i = 0; i < transformList.size(); ++i)
transformList.at(i)->applyTo(&m);
newItemTransform *= m.toTransform().inverted();
newItemTransform.translate(origin.x(), origin.y());
newItemTransform.rotate(-item->rotation());
newItemTransform.scale(1/item->scale(), 1/item->scale());
newItemTransform.translate(-origin.x(), -origin.y());
// ### Expensive, we could maybe use dirtySceneTransform bit for optimization
item->setTransform(newItemTransform);
// item->d_func()->setIsMemberOfGroup(true);
prepareGeometryChange();
itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect());
update();
}
void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item)
{
if (!item) {
qWarning("QGraphicsItemGroup::removeFromGroup: cannot remove null item");
return;
}
QGraphicsItem *newParent = parentItem();
// COMBINE
bool ok;
QTransform itemTransform;
if (newParent)
itemTransform = item->itemTransform(newParent, &ok);
else
itemTransform = item->sceneTransform();
QPointF oldPos = item->mapToItem(newParent, 0, 0);
item->setParentItem(newParent);
item->setPos(oldPos);
// removing position from translation component of the new transform
if (!item->pos().isNull())
itemTransform *= QTransform::fromTranslate(-item->x(), -item->y());
// removing additional transformations properties applied
// with itemTransform() or sceneTransform()
QPointF origin = item->transformOriginPoint();
QMatrix4x4 m;
QList<QGraphicsTransform*> transformList = item->transformations();
for (int i = 0; i < transformList.size(); ++i)
transformList.at(i)->applyTo(&m);
itemTransform *= m.toTransform().inverted();
itemTransform.translate(origin.x(), origin.y());
itemTransform.rotate(-item->rotation());
itemTransform.scale(1 / item->scale(), 1 / item->scale());
itemTransform.translate(-origin.x(), -origin.y());
// ### Expensive, we could maybe use dirtySceneTransform bit for optimization
item->setTransform(itemTransform);
// item->d_func()->setIsMemberOfGroup(item->group() != 0);
// ### Quite expensive. But removeFromGroup() isn't called very often.
prepareGeometryChange();
itemsBoundingRect = childrenBoundingRect();
}
QRectF UBGraphicsGroupContainerItem::boundingRect() const
{
return itemsBoundingRect;
}
void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(painter);
Q_UNUSED(option);
// we would not use paint smth for the moment
// if (option->state & QStyle::State_Selected) {
// painter->setBrush(Qt::NoBrush);
// QPen tmpPen;
// qreal tmpPenWidth = 1.0;
// tmpPen.setWidth(tmpPenWidth);
// tmpPen.setColor(Qt::lightGray);
// painter->setPen(tmpPen);
// painter->drawRect(itemsBoundingRect.adjusted(tmpPenWidth / 2, tmpPenWidth / 2, -tmpPenWidth / 2, -tmpPenWidth / 2));
// }
}
UBGraphicsScene *UBGraphicsGroupContainerItem::scene()
{
UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(scene());
UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(QGraphicsItem::scene());
return castScene;
}
@ -55,15 +180,33 @@ void UBGraphicsGroupContainerItem::remove()
mDelegate->remove();
}
void UBGraphicsGroupContainerItem::destroy() {
foreach (QGraphicsItem *item, childItems()) {
removeFromGroup(item);
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
item->setFlag(QGraphicsItem::ItemIsFocusable, true);
}
remove();
if (scene()) {
qDebug() << "scene is well casted";
scene()->removeItem(this);
}
}
void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (mDelegate->mousePressEvent(event)) {
//NOOP
} else {
QGraphicsItemGroup::mousePressEvent(event);
QGraphicsItem::mousePressEvent(event);
setSelected(true);
}
}
void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
@ -71,18 +214,19 @@ void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *even
if (mDelegate->mouseMoveEvent(event)) {
// NOOP;
} else {
QGraphicsItemGroup::mouseMoveEvent(event);
QGraphicsItem::mouseMoveEvent(event);
}
}
void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mDelegate->mouseReleaseEvent(event);
QGraphicsItemGroup::mouseReleaseEvent(event);
// mDelegate->mouseReleaseEvent(event);
QGraphicsItem::mouseReleaseEvent(event);
}
QVariant UBGraphicsGroupContainerItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
QVariant newValue = mDelegate->itemChange(change, value);
return QGraphicsItemGroup::itemChange(change, newValue);
return QGraphicsItem::itemChange(change, newValue);
}

@ -5,20 +5,33 @@
#include "domain/UBItem.h"
class UBGraphicsGroupContainerItem : public QGraphicsItemGroup, public UBItem, public UBGraphicsItem
class UBGraphicsGroupContainerItem : public QGraphicsItem, public UBItem, public UBGraphicsItem
{
public:
UBGraphicsGroupContainerItem (QGraphicsItem *parent = 0);
void addToGroup(QGraphicsItem *item);
void removeFromGroup(QGraphicsItem *item);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;}
virtual UBGraphicsScene* scene();
virtual UBGraphicsGroupContainerItem *deepCopy() const;
virtual void remove();
enum { Type = UBGraphicsItemType::groupContainerType };
virtual int type() const
{
return Type;
}
protected:
void destroy();
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
@ -26,6 +39,7 @@ protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
QRectF itemsBoundingRect;
};

@ -45,21 +45,25 @@ void UBGraphicsGroupContainerItemDelegate::decorateMenu(QMenu *menu)
void UBGraphicsGroupContainerItemDelegate::buildButtons()
{
UBGraphicsItemDelegate::buildButtons();
}
mDestroyGroupButton = new DelegateButton(":/images/font.svg", mDelegated, mFrame, Qt::TopLeftSection);
bool UBGraphicsGroupContainerItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
mButtons << mDestroyGroupButton;
return false;
}
bool UBGraphicsGroupContainerItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
connect(mDestroyGroupButton, SIGNAL(clicked()), (UBGraphicsGroupContainerItemDelegate*)this, SLOT(destroyGroup()));
return false;
}
void UBGraphicsGroupContainerItemDelegate::destroyGroup()
bool UBGraphicsGroupContainerItemDelegate::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << "got an event";
foreach (QGraphicsItem *item, delegated()->childItems()) {
delegated()->removeFromGroup(item);
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
}
Q_UNUSED(event)
remove(true);
return false;
}

@ -17,9 +17,9 @@ protected:
virtual void decorateMenu(QMenu *menu);
virtual void buildButtons();
private slots:
void destroyGroup();
virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
DelegateButton *mDestroyGroupButton;

@ -198,8 +198,9 @@ QRectF UBGeometryUtils::lineToInnerRect(const QLineF& pLine, const qreal& pWidth
qreal centerX = (pLine.x1() + pLine.x2()) / 2;
qreal centerY = (pLine.y1() + pLine.y2()) / 2;
// Please put a fucking comment here
qreal side = sqrt((pWidth * pWidth) / 2);
qreal halfSide = side / 2;
qreal halfSide = side / 2;
return QRectF(centerX - halfSide, centerY - halfSide, side, side);
}

@ -66,8 +66,8 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid
mButtonGroup->addButton(mpRemoveFavoriteBtn);
mButtonGroup->addButton(mpNewFolderBtn);
// Connect signals & slots
connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite()));
/*connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial()));
/*connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite()));
connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial()));
connect(mpSearchAction,SIGNAL(triggered()), this, SLOT(onActionSearch()));
connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash()));
connect(mpCloseAction, SIGNAL(triggered()), this, SLOT(onActionClose()));
@ -75,8 +75,11 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid
connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString)));
connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder()));*/
connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite()));
connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString)));
connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder()));
connect(mpRemoveFavorite, SIGNAL(triggered()), this, SLOT(onActionRemoveFavorite()));
connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash()));
// Build the default toolbar
mLayout->addWidget(mpFavoriteBtn);
@ -148,6 +151,8 @@ void UBFeaturesActionBar::setButtons()
mpFavoriteBtn->hide();
mpSocialBtn->hide();
mSearchBar->show();
mpDeleteBtn->show();
mpDeleteBtn->setEnabled(true);
//mpSearchBtn->show();
//mpDeleteBtn->hide();
mpCloseBtn->hide();
@ -175,6 +180,16 @@ void UBFeaturesActionBar::onActionFavorite()
emit addElementsToFavorite();
}
void UBFeaturesActionBar::onActionRemoveFavorite()
{
emit removeElementsFromFavorite();
}
void UBFeaturesActionBar::onActionTrash()
{
emit deleteSelectedElements();
}
/*
void UBFeaturesActionBar::dragMoveEvent(QDragMoveEvent *event)
{

@ -31,10 +31,14 @@ signals:
void addToFavorite( const QMimeData &data );
void removeFromFavorite( const QMimeData &data );
void addElementsToFavorite();
void removeElementsFromFavorite();
void deleteSelectedElements();
private slots:
void onSearchTextChanged(QString txt);
void onActionNewFolder();
void onActionFavorite();
void onActionRemoveFavorite();
void onActionTrash();
protected:
//void dragMoveEvent(QDragMoveEvent *event);
void dragEnterEvent( QDragEnterEvent *event );

@ -10,7 +10,7 @@
#include "globals/UBGlobals.h"
#include "board/UBBoardController.h"
UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent)
UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent)
{
setObjectName(name);
mName = "FeaturesWidget";
@ -82,7 +82,6 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
//pathListView->setMovement( QListView::Static );
pathListView->setDragDropMode( QAbstractItemView::DropOnly );
pathScene = new QGraphicsScene(this);
//pathViewer = new UBFeaturesPathViewer( QPixmap(":images/libpalette/home.png"), controller->getRootPath(), pathScene, this );
featureProperties = new UBFeatureProperties(this);
webView = new UBFeaturesWebView(this);
@ -121,7 +120,9 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
connect( mActionBar, SIGNAL( deleteElements(const QMimeData &) ), this, SLOT( deleteElements(const QMimeData &) ) );
connect( mActionBar, SIGNAL( addToFavorite(const QMimeData &) ), this, SLOT( addToFavorite(const QMimeData &) ) );
connect( mActionBar, SIGNAL( removeFromFavorite(const QMimeData &) ), this, SLOT( removeFromFavorite(const QMimeData &) ) );
connect ( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) );
connect( mActionBar, SIGNAL( addElementsToFavorite() ), this, SLOT ( addElementsToFavorite() ) );
connect( mActionBar, SIGNAL( removeElementsFromFavorite() ), this, SLOT ( removeElementsFromFavorite() ) );
connect( mActionBar, SIGNAL( deleteSelectedElements() ), this, SLOT( deleteSelectedElements() ) );
connect( pathListView, SIGNAL(clicked( const QModelIndex & ) ),
this, SLOT( currentPathChanged( const QModelIndex & ) ) );
connect( thumbSlider, SIGNAL( sliderMoved(int) ), this, SLOT(thumbnailSizeChanged( int ) ) );
@ -131,6 +132,15 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPale
this, SLOT( onAddDownloadedFileToLibrary( bool, QUrl, QString,QByteArray ) ) );
}
UBFeaturesWidget::~UBFeaturesWidget()
{
if ( thumbSlider != NULL )
{
delete thumbSlider;
thumbSlider = NULL;
}
}
bool UBFeaturesWidget::eventFilter( QObject *target, QEvent *event )
{
if ( target == featuresListView && event->type() == QEvent::Resize )
@ -277,6 +287,37 @@ void UBFeaturesWidget::deleteElements( const QMimeData & mimeData )
model->invalidate();
}
void UBFeaturesWidget::deleteSelectedElements()
{
QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes();
QList <QUrl> urls;
foreach ( QModelIndex sel, selected )
{
UBFeature feature = sel.data( Qt::UserRole + 1 ).value<UBFeature>();
if ( feature.isDeletable() )
urls.append( feature.getFullPath() );
}
foreach (QUrl url, urls)
{
if ( controller->isTrash( url ) )
{
controller->deleteItem( url );
}
else
{
UBFeature elem = controller->moveItemToFolder( url, controller->getTrashElement() );
controller->removeFromFavorite( url );
featuresModel->addItem( elem );
featuresModel->deleteFavoriteItem( url.toString() );
}
featuresModel->deleteItem( url.toString() );
}
QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( featuresListView->model() );
model->invalidate();
}
void UBFeaturesWidget::addToFavorite( const QMimeData & mimeData )
{
if ( !mimeData.hasUrls() )
@ -335,14 +376,45 @@ void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUr
}
void UBFeaturesWidget::addElementsToFavorite()
{
if ( currentStackedWidget == ID_PROPERTIES )
{
UBFeature feature = featureProperties->getCurrentElement();
if ( feature != UBFeature() && !UBApplication::isFromWeb( feature.getFullPath().toString() ) )
{
UBFeature elem = controller->addToFavorite( feature.getFullPath() );
featuresModel->addItem( elem );
}
}
else if ( currentStackedWidget == ID_LISTVIEW )
{
QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes();
for ( int i = 0; i < selected.size(); ++i )
{
UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value<UBFeature>();
UBFeature elem = controller->addToFavorite( feature.getFullPath() );
if ( !elem.getVirtualPath().isEmpty() && !elem.getVirtualPath().isNull() )
featuresModel->addItem( elem );
}
}
QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( featuresListView->model() );
model->invalidate();
}
void UBFeaturesWidget::removeElementsFromFavorite()
{
QModelIndexList selected = featuresListView->selectionModel()->selectedIndexes();
//qSort( selected.begin(), selected.end(), qGreater<QModelIndex>() );
QList <QUrl> items;
for ( int i = 0; i < selected.size(); ++i )
{
UBFeature feature = selected.at(i).data( Qt::UserRole + 1 ).value<UBFeature>();
UBFeature elem = controller->addToFavorite( feature.getFullPath() );
if ( !elem.getVirtualPath().isEmpty() && !elem.getVirtualPath().isNull() )
featuresModel->addItem( elem );
items.append( feature.getFullPath() );
}
foreach ( QUrl url, items )
{
controller->removeFromFavorite( url );
featuresModel->deleteFavoriteItem( url.toString() );
}
QSortFilterProxyModel *model = dynamic_cast<QSortFilterProxyModel *>( featuresListView->model() );
model->invalidate();
@ -380,9 +452,7 @@ void UBFeaturesWidget::currentPathChanged(const QString &path)
*/
UBFeaturesWidget::~UBFeaturesWidget()
{
}
UBFeaturesListView::UBFeaturesListView( QWidget* parent, const char* name )
: QListView(parent)
@ -435,7 +505,7 @@ void UBFeaturesListView::dropEvent( QDropEvent *event )
{
event->setDropAction( Qt::MoveAction );
}
QListView::dropEvent( event );
QListView::dropEvent( event );
}
@ -473,15 +543,18 @@ UBFeaturesWebView::UBFeaturesWebView(QWidget* parent, const char* name):QWidget(
UBFeaturesWebView::~UBFeaturesWebView()
{
if(NULL != mpSankoreAPI){
if( NULL != mpSankoreAPI )
{
delete mpSankoreAPI;
mpSankoreAPI = NULL;
}
if(NULL != mpView){
if( NULL != mpView )
{
delete mpView;
mpView = NULL;
}
if(NULL != mpLayout){
if( NULL != mpLayout )
{
delete mpLayout;
mpLayout = NULL;
}
@ -597,6 +670,55 @@ UBFeatureProperties::UBFeatureProperties( QWidget *parent, const char *name ) :
connect( mpAddToLibButton, SIGNAL( clicked() ), this, SLOT(onAddToLib() ) );
}
UBFeatureProperties::~UBFeatureProperties()
{
if ( mpOrigPixmap )
{
delete mpOrigPixmap;
mpOrigPixmap = NULL;
}
if ( mpElement )
{
delete mpElement;
mpElement = NULL;
}
if ( mpThumbnail )
{
delete mpThumbnail;
mpThumbnail = NULL;
}
if ( mpButtonLayout )
{
delete mpButtonLayout;
mpButtonLayout = NULL;
}
if ( mpAddPageButton )
{
delete mpAddPageButton;
mpAddPageButton = NULL;
}
if ( mpSetAsBackgroundButton )
{
delete mpSetAsBackgroundButton;
mpSetAsBackgroundButton = NULL;
}
if ( mpAddToLibButton )
{
delete mpAddToLibButton;
mpAddToLibButton = NULL;
}
if ( mpObjInfoLabel )
{
delete mpObjInfoLabel;
mpObjInfoLabel = NULL;
}
if ( mpObjInfos )
{
delete mpObjInfos;
mpObjInfos = NULL;
}
}
void UBFeatureProperties::resizeEvent( QResizeEvent *event )
{
Q_UNUSED(event);
@ -609,6 +731,13 @@ void UBFeatureProperties::showEvent (QShowEvent *event )
adaptSize();
}
UBFeature UBFeatureProperties::getCurrentElement() const
{
if ( mpElement )
return *mpElement;
return UBFeature();
}
void UBFeatureProperties::adaptSize()
{
if( NULL != mpOrigPixmap )
@ -716,19 +845,7 @@ void UBFeatureProperties::onSetAsBackground()
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)
{
@ -854,7 +971,7 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path )
{
for ( int i = 0; i < featuresList->size(); ++i )
{
if ( !QString::compare( featuresList->at(i).getUrl(), path, Qt::CaseInsensitive ) &&
if ( !QString::compare( featuresList->at(i).getFullPath().toString(), path, Qt::CaseInsensitive ) &&
!QString::compare( featuresList->at(i).getVirtualPath(), "/root/favorites", Qt::CaseInsensitive ) )
{
removeRow( i, QModelIndex() );
@ -863,6 +980,18 @@ void UBFeaturesModel::deleteFavoriteItem( const QString &path )
}
}
void UBFeaturesModel::deleteItem( const QString &path )
{
for ( int i = 0; i < featuresList->size(); ++i )
{
if ( !QString::compare( featuresList->at(i).getFullPath().toString(), path, Qt::CaseInsensitive ) )
{
removeRow( i, QModelIndex() );
return;
}
}
}
bool UBFeaturesModel::removeRows( int row, int count, const QModelIndex & parent )
{
if ( row < 0 )
@ -889,6 +1018,7 @@ bool UBFeaturesModel::removeRow( int row, const QModelIndex & parent )
return true;
}
Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const
{
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);

@ -80,7 +80,7 @@ private:
QSlider *thumbSlider;
QVBoxLayout *layout;
//UBFeaturesPathViewer *pathViewer;
QGraphicsScene *pathScene;
//QGraphicsScene *pathScene;
UBFeaturesActionBar *mActionBar;
UBFeatureProperties *featureProperties;
UBFeaturesWebView *webView;
@ -88,7 +88,6 @@ private:
int currentStackedWidget;
QModelIndex trashIndex;
private slots:
void currentSelected( const QModelIndex & );
//void currentPathChanged(const QString &);
@ -102,6 +101,8 @@ private slots:
void onDisplayMetadata( QMap<QString,QString> );
void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray);
void addElementsToFavorite();
void removeElementsFromFavorite();
void deleteSelectedElements();
protected:
bool eventFilter(QObject *target, QEvent *event);
};
@ -129,7 +130,7 @@ class UBFeaturesWebView : public QWidget
Q_OBJECT
public:
UBFeaturesWebView(QWidget* parent = 0, const char* name = "UBFeaturesWebView");
~UBFeaturesWebView();
virtual ~UBFeaturesWebView();
void showElement(const UBFeature &elem);
@ -151,8 +152,7 @@ public:
~UBFeatureProperties();
void showElement(const UBFeature &elem);
UBFeature getCurrentElement() const;
protected:
void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event);
@ -200,6 +200,7 @@ public:
void addItem( const UBFeature &item );
void deleteFavoriteItem( const QString &path );
void deleteItem( const QString &path );
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
QMimeData *mimeData( const QModelIndexList &indexes ) const;
@ -209,6 +210,8 @@ public:
bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent);
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
bool removeRow(int row, const QModelIndex &parent = QModelIndex());
//bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
//bool insertRow(int row, const QModelIndex &parent = QModelIndex());
Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }

@ -71,6 +71,7 @@ UBGraphicsCompass::UBGraphicsCompass()
unsetCursor();
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly
setFlag(QGraphicsItem::ItemIsSelectable, false);
connect(UBApplication::boardController, SIGNAL(penColorChanged()), this, SLOT(penColorChanged()));
connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged()));

@ -64,6 +64,7 @@ UBGraphicsProtractor::UBGraphicsProtractor()
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly
setFlag(QGraphicsItem::ItemIsSelectable, false);
scale(1.5, 1.5);
}

@ -28,7 +28,7 @@ class UBGraphicsScene;
class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipseItem, public UBItem
{
Q_OBJECT;
Q_OBJECT
public:
UBGraphicsProtractor ();

@ -46,7 +46,8 @@ UBGraphicsRuler::UBGraphicsRuler()
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly
updateResizeCursor();
setFlag(QGraphicsItem::ItemIsSelectable, false);
updateResizeCursor();
}
void UBGraphicsRuler::updateResizeCursor()

@ -55,6 +55,7 @@ UBGraphicsTriangle::UBGraphicsTriangle()
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control));
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly
setFlag(QGraphicsItem::ItemIsSelectable, false);
updateResizeCursor();
}

Loading…
Cancel
Save