Commit a6043930 authored by Ivan Ilyin's avatar Ivan Ilyin

Sankore smart button

parent 8be4c32b
...@@ -123,7 +123,8 @@ struct UBGraphicsItemType ...@@ -123,7 +123,8 @@ struct UBGraphicsItemType
StrokeItemType, StrokeItemType,
TriangleItemType, TriangleItemType,
MagnifierItemType, MagnifierItemType,
cacheItemType cacheItemType,
groupContainerType
}; };
}; };
......
...@@ -184,18 +184,18 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi ...@@ -184,18 +184,18 @@ void UBGraphicsPolygonItem::paint ( QPainter * painter, const QStyleOptionGraphi
QGraphicsPolygonItem::paint(painter, option, widget); QGraphicsPolygonItem::paint(painter, option, widget);
} }
QPainterPath UBGraphicsPolygonItem::shape() const //QPainterPath UBGraphicsPolygonItem::shape() const
{ //{
QPainterPath path; // QPainterPath path;
path.addRect(boundingRect()); // path.addRect(boundingRect());
return path; // return path;
// static QPainterPath shapePath = QGraphicsPolygonItem::shape(); //// static QPainterPath shapePath = QGraphicsPolygonItem::shape();
// return shapePath; //// return shapePath;
} //}
UBGraphicsScene* UBGraphicsPolygonItem::scene() UBGraphicsScene* UBGraphicsPolygonItem::scene()
......
...@@ -115,7 +115,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem ...@@ -115,7 +115,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
protected: protected:
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
QPainterPath shape () const; // QPainterPath shape () const;
private: private:
......
...@@ -65,6 +65,9 @@ ...@@ -65,6 +65,9 @@
#include "core/memcheck.h" #include "core/memcheck.h"
const QString groupText = "Group items";
const QString ungroupText = "Ungroup items";
qreal UBZLayerController::errorNumber = -20000001.0; qreal UBZLayerController::errorNumber = -20000001.0;
UBZLayerController::UBZLayerController(QGraphicsScene *scene) : UBZLayerController::UBZLayerController(QGraphicsScene *scene) :
...@@ -291,9 +294,9 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) ...@@ -291,9 +294,9 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
} }
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(enableGroupingButton())); connect(this, SIGNAL(selectionChanged()), this, SLOT(groupButtonProcessing()));
connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(processGroupItems())); connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(groupButtonClicked()));
} }
UBGraphicsScene::~UBGraphicsScene() UBGraphicsScene::~UBGraphicsScene()
...@@ -312,15 +315,65 @@ void UBGraphicsScene::selectionChangedProcessing() ...@@ -312,15 +315,65 @@ void UBGraphicsScene::selectionChangedProcessing()
UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is "
+ QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); + QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f'));
} }
void UBGraphicsScene::enableGroupingButton() void UBGraphicsScene::groupButtonProcessing()
{ {
QAction *groupAction = UBApplication::mainWindow->actionGroupItems; QAction *groupAction = UBApplication::mainWindow->actionGroupItems;
QList<QGraphicsItem*> selItems = selectedItems();
int selCount = selItems.count();
if (selectedItems().count() > 1) { if (selCount < 1) {
groupAction->setEnabled(true);
} else {
groupAction->setEnabled(false); 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::groupButtonClicked()
{
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;
} }
if (groupAction->text() == groupText) { //The only way to get information from item, considering using smth else
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
foreach (QGraphicsItem *item, selItems) {
item->setSelected(false);
item->setFlag(QGraphicsItem::ItemIsSelectable, false);
item->setFlag( QGraphicsItem::ItemIsMovable, false);
item->setFlag(QGraphicsItem::ItemIsFocusable);
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();
}
}
} }
void UBGraphicsScene::processGroupItems() void UBGraphicsScene::processGroupItems()
{ {
...@@ -432,7 +485,6 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre ...@@ -432,7 +485,6 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
return accepted; return accepted;
} }
bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pressure) bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pressure)
{ {
bool accepted = false; bool accepted = false;
......
...@@ -305,7 +305,8 @@ public slots: ...@@ -305,7 +305,8 @@ public slots:
void setToolCursor(int tool); void setToolCursor(int tool);
void selectionChangedProcessing(); void selectionChangedProcessing();
void enableGroupingButton(); void groupButtonProcessing();
void groupButtonClicked();
void processGroupItems(); void processGroupItems();
void moveMagnifier(QPoint newPos); void moveMagnifier(QPoint newPos);
......
...@@ -53,6 +53,15 @@ void UBGraphicsGroupContainerItem::remove() ...@@ -53,6 +53,15 @@ void UBGraphicsGroupContainerItem::remove()
mDelegate->remove(); mDelegate->remove();
} }
void UBGraphicsGroupContainerItem::destroy() {
foreach (QGraphicsItem *item, childItems()) {
removeFromGroup(item);
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
}
mDelegate->remove(true);
}
void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
......
...@@ -15,6 +15,14 @@ public: ...@@ -15,6 +15,14 @@ public:
virtual UBGraphicsScene* scene(); virtual UBGraphicsScene* scene();
virtual UBGraphicsGroupContainerItem *deepCopy() const; virtual UBGraphicsGroupContainerItem *deepCopy() const;
virtual void remove(); virtual void remove();
enum { Type = UBGraphicsItemType::groupContainerType };
virtual int type() const
{
return Type;
}
void destroy();
protected: protected:
......
...@@ -71,6 +71,7 @@ UBGraphicsCompass::UBGraphicsCompass() ...@@ -71,6 +71,7 @@ UBGraphicsCompass::UBGraphicsCompass()
unsetCursor(); unsetCursor();
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly 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(UBApplication::boardController, SIGNAL(penColorChanged()), this, SLOT(penColorChanged()));
connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged())); connect(UBDrawingController::drawingController(), SIGNAL(lineWidthIndexChanged(int)), this, SLOT(lineWidthChanged()));
......
...@@ -64,6 +64,7 @@ UBGraphicsProtractor::UBGraphicsProtractor() ...@@ -64,6 +64,7 @@ UBGraphicsProtractor::UBGraphicsProtractor()
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); 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 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); scale(1.5, 1.5);
} }
......
...@@ -28,7 +28,7 @@ class UBGraphicsScene; ...@@ -28,7 +28,7 @@ class UBGraphicsScene;
class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipseItem, public UBItem class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipseItem, public UBItem
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsProtractor (); UBGraphicsProtractor ();
......
...@@ -46,7 +46,8 @@ UBGraphicsRuler::UBGraphicsRuler() ...@@ -46,7 +46,8 @@ UBGraphicsRuler::UBGraphicsRuler()
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly 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() void UBGraphicsRuler::updateResizeCursor()
......
...@@ -55,6 +55,7 @@ UBGraphicsTriangle::UBGraphicsTriangle() ...@@ -55,6 +55,7 @@ UBGraphicsTriangle::UBGraphicsTriangle()
mRotateSvgItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); 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 setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly
setFlag(QGraphicsItem::ItemIsSelectable, false);
updateResizeCursor(); updateResizeCursor();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment