void PencilTool::init(TupGraphicsScene *scene) { #ifdef K_DEBUG T_FUNCINFOX("tools"); #endif k->scene = scene; /* foreach (QGraphicsView *view, scene->views()) { view->setDragMode(QGraphicsView::NoDrag); Q_CHECK_PTR(view->scene()); if (QGraphicsScene *scene = qobject_cast<QGraphicsScene *>(view->scene())) { foreach (QGraphicsItem *item, scene->items()) { item->setFlag(QGraphicsItem::ItemIsSelectable, false); item->setFlag(QGraphicsItem::ItemIsMovable, false); } } } foreach (QGraphicsItem *item, scene->items()) { item->setFlag(QGraphicsItem::ItemIsSelectable, false); item->setFlag(QGraphicsItem::ItemIsMovable, false); } */ reset(k->scene); }
void TupGraphicLibraryItem::setObject(TupLibraryObject *object) { if (!object) { #ifdef K_DEBUG tWarning("library") << "Setting null library object"; #endif return; } #ifdef K_DEBUG T_FUNCINFOX("library") << object->symbolName(); #endif k->symbolName = object->symbolName(); switch(object->type()) { case TupLibraryObject::Item: case TupLibraryObject::Text: case TupLibraryObject::Image: { setItem(qvariant_cast<QGraphicsItem *>(object->data())); } break; case TupLibraryObject::Svg: { setSvgContent(object->dataPath()); } break; default: break; } }
void TupGraphicsScene::itemResponse(TupItemResponse *event) { #ifdef K_DEBUG T_FUNCINFOX("scene"); #endif if (k->tool) k->tool->itemResponse(event); }
void NodesTool::resizeNodes(qreal scaleFactor) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[NodesTool::resizeNodes()]"; #else T_FUNCINFOX("tools"); #endif #endif k->realFactor = scaleFactor; if (k->activeSelection) k->nodeGroup->resizeNodes(scaleFactor); }
bool TupProject::createSymbol(int type, const QString &name, const QByteArray &data, const QString &folder) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[TupProject::createSymbol()]"; #else T_FUNCINFOX("symbol"); #endif #endif if (!k->isOpen) { #ifdef K_DEBUG QString msg = "TupProject::createSymbol() - Fatal error: project is NOT open!"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif return false; } if (k->library->createSymbol(TupLibraryObject::Type(type), name, data, folder) == 0) { #ifdef K_DEBUG QString msg = "TupProject::createSymbol() - Fatal error: object can't be created. Data is NULL!"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif return false; } #ifdef K_DEBUG QString msg = "TupProject::createSymbol() - Object added successfully -> " + name; #ifdef Q_OS_WIN qWarning() << msg; #else tWarning() << msg; #endif #endif return true; }
void TupScenesWidget::sceneResponse(TupSceneResponse *e) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[TupScenesWidget::sceneResponse()]"; qDebug() << "SHOW_VAR: " << e->action(); #else T_FUNCINFOX("scenes"); SHOW_VAR(e->action()); #endif #endif int index = e->sceneIndex(); switch (e->action()) { case TupProjectRequest::Add: { k->scenesTable->insertScene(index, e->arg().toString()); } break; case TupProjectRequest::Remove: { k->scenesTable->removeScene(index); } break; case TupProjectRequest::Reset: { k->scenesTable->renameScene(index, e->arg().toString()); } break; case TupProjectRequest::Rename: { k->scenesTable->renameScene(index, e->arg().toString()); } break; case TupProjectRequest::Select: { if (k->scenesTable->currentSceneIndex() != index) k->scenesTable->selectScene(index); } break; default: break; } }
void PencilTool::init(TupGraphicsScene *scene) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[PencilTool::init()]"; #else T_FUNCINFOX("tools"); #endif #endif k->scene = scene; k->brushManager = k->scene->brushManager(); k->input = k->scene->inputDeviceInformation(); k->resize = false; k->circleZValue = (2*ZLAYER_LIMIT) + (scene->scene()->layersCount() * ZLAYER_LIMIT); TCONFIG->beginGroup("BrushParameters"); k->penWidth = TCONFIG->value("Thickness", 3).toInt(); foreach (QGraphicsView * view, scene->views()) view->setDragMode(QGraphicsView::NoDrag); }
TupScene *TupProject::sceneAt(int position) const { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[TupProject::sceneAt()] - position: " << position; #else T_FUNCINFOX("project") << position; #endif #endif if (position < 0) { #ifdef K_DEBUG QString msg = "TupProject::sceneAt() - FATAL ERROR: index out of bound (" + QString::number(position) + ")"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif return 0; } return k->scenes.value(position); }
void NodesTool::release(const TupInputDeviceInformation *input, TupBrushManager *brushManager, TupGraphicsScene *scene) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[NodesTool::release()]"; #else T_FUNCINFOX("tools"); #endif #endif Q_UNUSED(brushManager); QList<QGraphicsItem *> currentSelection = scene->selectedItems(); if (!currentSelection.isEmpty()) { QGraphicsItem *selectedItem = currentSelection.at(0); TupFrame *frame = currentFrame(); int itemIndex = frame->indexOf(selectedItem); if (qgraphicsitem_cast<TupSvgItem *>(selectedItem)) { TOsd::self()->display(tr("Error"), tr("SVG objects cannot be edited!"), TOsd::Error); return; } if (TupGraphicLibraryItem *libraryItem = qgraphicsitem_cast<TupGraphicLibraryItem *>(selectedItem)) { if (libraryItem->itemType() == TupLibraryObject::Image) { TOsd::self()->display(tr("Error"), tr("Images have no nodes!"), TOsd::Error); return; } } if (qgraphicsitem_cast<TupItemGroup *>(selectedItem)) { if (k->activeSelection) k->nodeGroup->clear(); QPointF coord = input->pos(); if (itemIndex >= 0) { TupProjectRequest event = TupRequestBuilder::createItemRequest( scene->currentSceneIndex(), k->currentLayer, k->currentFrame, itemIndex, coord, scene->spaceContext(), TupLibraryObject::Item, TupProjectRequest::Ungroup); emit requested(&event); } return; } if (!qgraphicsitem_cast<TControlNode*>(selectedItem)) { if (!qgraphicsitem_cast<TupPathItem *>(selectedItem)) { TOsd::self()->display(tr("Error"), tr("Only pencil/ink lines can be edited!"), TOsd::Error); return; } } if (itemIndex == -1) { if (qgraphicsitem_cast<TControlNode*>(selectedItem)) { QGraphicsItem *item = k->nodeGroup->parentItem(); int position = frame->indexOf(item); if (position >= 0) { // if (qgraphicsitem_cast<QGraphicsPathItem *>(item)) { QString path = qgraphicsitem_cast<TupPathItem *>(item)->pathToString(); TupProjectRequest event = TupRequestBuilder::createItemRequest(scene->currentSceneIndex(), k->currentLayer, k->currentFrame, position, QPointF(), scene->spaceContext(), TupLibraryObject::Item, TupProjectRequest::EditNodes, path); emit requested(&event); k->nodeGroup->clearChangedNodes(); // } } else { #ifdef K_DEBUG QString msg = "NodesTool::release() - Fatal Error: Invalid position [ " + QString::number(position) + " ]"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif } } else { #ifdef K_DEBUG QString msg = "NodesTool::release() - Invalid selected item index: " + QString::number(itemIndex); #ifdef Q_OS_WIN qDebug() << msg; #else tWarning() << msg; #endif #endif } return; } // Avoiding to select the same item twice if (k->activeSelection) { TupFrame *frame = currentFrame(); int oldIndex = frame->indexOf(k->nodeGroup->parentItem()); if (oldIndex != itemIndex) { k->nodeGroup->clear(); k->nodeGroup = new TNodeGroup(selectedItem, scene, TNodeGroup::LineSelection, k->baseZValue); k->nodeGroup->show(); k->nodeGroup->resizeNodes(k->realFactor); if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(selectedItem)) { if (path->isNotEdited()) path->saveOriginalPath(); } } else { if (k->nodeGroup->hasChangedNodes()) { QGraphicsItem *item = k->nodeGroup->parentItem(); int position = frame->indexOf(item); if (position >= 0) { QString path = qgraphicsitem_cast<TupPathItem *>(item)->pathToString(); TupProjectRequest event = TupRequestBuilder::createItemRequest(scene->currentSceneIndex(), k->currentLayer, k->currentFrame, position, QPointF(), scene->spaceContext(), TupLibraryObject::Item, TupProjectRequest::EditNodes, path); emit requested(&event); k->nodeGroup->clearChangedNodes(); } else { #ifdef K_DEBUG QString msg = "NodesTool::release() - Fatal Error: Invalid position [ " + QString::number(position) + " ]"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif } } else { #ifdef K_DEBUG QString msg = "NodesTool::release() - Node group has NO changes!"; #ifdef Q_OS_WIN qDebug() << msg; #else tWarning() << msg; #endif #endif } } } else { k->nodeGroup = new TNodeGroup(selectedItem, scene, TNodeGroup::LineSelection, k->baseZValue); k->nodeGroup->show(); k->activeSelection = true; k->nodeGroup->resizeNodes(k->realFactor); if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(selectedItem)) { if (path->isNotEdited()) path->saveOriginalPath(); } } } else { if (k->activeSelection) { #ifdef K_DEBUG QString msg = "NodesTool::release() - Empty selection! Removing nodes..."; #ifdef Q_OS_WIN qDebug() << msg; #else tWarning() << msg; #endif #endif k->nodeGroup->clear(); k->nodeGroup = 0; k->activeSelection = false; } } }
void NodesTool::itemResponse(const TupItemResponse *response) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[NodesTool::itemResponse()]"; #else T_FUNCINFOX("NodesTool"); #endif #endif QGraphicsItem *item = 0; if (response->action() != TupProjectRequest::Remove) { TupFrame *frame = currentFrame(); if (response->action() == TupProjectRequest::Ungroup) { QPointF point = response->position(); item = k->scene->itemAt(point, QTransform()); } else { item = frame->item(response->itemIndex()); } } switch (response->action()) { case TupProjectRequest::Convert: { if (item) { k->nodeGroup = new TNodeGroup(item, k->scene, TNodeGroup::LineSelection, k->baseZValue); } else { #ifdef K_DEBUG QString msg = "NodesTool::itemResponse() - Fatal Error: No item was found"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif } } break; case TupProjectRequest::EditNodes: { if (item) { if (k->activeSelection) { if (qgraphicsitem_cast<QGraphicsPathItem *>(k->nodeGroup->parentItem()) == item) { k->nodeGroup->show(); k->nodeGroup->syncNodesFromParent(); k->nodeGroup->saveParentProperties(); } } else { k->nodeGroup = new TNodeGroup(item, k->scene, TNodeGroup::LineSelection, k->baseZValue); k->nodeGroup->show(); k->activeSelection = true; k->nodeGroup->resizeNodes(k->realFactor); } } else { #ifdef K_DEBUG QString msg = "NodesTool::itemResponse() - Fatal Error: No item was found"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif } } break; case TupProjectRequest::Remove: { return; } break; case TupProjectRequest::Ungroup: { // reset(k->scene); if (item) { k->nodeGroup = new TNodeGroup(item, k->scene, TNodeGroup::LineSelection, k->baseZValue); k->nodeGroup->show(); k->activeSelection = true; k->nodeGroup->resizeNodes(k->realFactor); } else { #ifdef K_DEBUG QString msg = "NodesTool::itemResponse() - Fatal error: No item was found"; #ifdef Q_OS_WIN qDebug() << msg; #else tError() << msg; #endif #endif } return; } break; default: { #ifdef K_DEBUG qDebug() << "NodesTool::itemResponse() - default action"; #endif if (k->activeSelection) { k->nodeGroup->show(); if (k->nodeGroup->parentItem()) { k->nodeGroup->parentItem()->setSelected(true); k->nodeGroup->syncNodesFromParent(); } } } break; } }