bool CObjectModel::isLayer(const QModelIndex &index) const
{
	if ( !index.isValid() ) { return false ; }
	ObjectItem *p = getItemFromIndex(index) ;
	return p->parent() == m_pRoot ? false : true ;
//	return index.parent().internalPointer() != m_pRoot ? true : false ;
}
void AnimationForm::slot_setColorFromPicker(QRgb rgba)
{
	CObjectModel *pModel = m_pEditData->getObjectModel() ;
	QModelIndex index = m_pEditData->getSelIndex() ;
	if ( !pModel->isLayer(index) ) { return ; }

	int frame = m_pEditData->getSelectFrame() ;
	ObjectItem *pItem = pModel->getItemFromIndex(index) ;
	FrameData *pData = pItem->getFrameDataPtr(frame) ;
	if ( !pData ) {
		pData = pModel->getFrameDataFromPrevFrame(index, frame, true) ;
		if ( !pData ) { return ; }
		FrameData *pNext = pModel->getFrameDataFromNextFrame(index, frame) ;
		FrameData data = pData->getInterpolation(pNext, frame) ;
		data.rgba[0] = qRed(rgba) ;
		data.rgba[1] = qGreen(rgba) ;
		data.rgba[2] = qBlue(rgba) ;
		slot_addNewFrameData(index, frame, data);
	}
	else {
		pData->rgba[0] = qRed(rgba) ;
		pData->rgba[1] = qGreen(rgba) ;
		pData->rgba[2] = qBlue(rgba) ;

		addCommandEdit(*pData);
	}
}
// 選択オブジェクト変更
void AnimationForm::slot_changeSelectObject(QModelIndex index)
{
//	m_pEditData->setSelIndex(index) ;

	if ( !index.isValid() ) { return ; }

	CObjectModel *pModel = m_pEditData->getObjectModel() ;

	if ( pModel->isLayer(index) ) {
		bool valid ;
		ObjectItem *pItem = pModel->getItemFromIndex(index) ;
		FrameData data = pItem->getDisplayFrameData(m_pEditData->getSelectFrame(), &valid) ;
		if ( valid ) {
			slot_setUI(data) ;
		}
		emit sig_changeSelectLayer(index) ;
	}

	ObjectItem *pObj = pModel->getObject(index) ;
	if ( pObj ) {
		ui->spinBox_loop->setValue(pObj->getLoop());
		ui->spinBox_fps->setValue(pObj->getFps()) ;
	}

	m_pDataMarker->repaint();
	m_pGlWidget->update();
}
QModelIndex CObjectModel::addItem(QString name, const QModelIndex &parent)
{
	ObjectItem *p = getItemFromIndex(parent) ;
	int row = p->childCount() ;

	return insertItem(row, name, parent) ;
}
bool CObjectModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
	if ( action == Qt::IgnoreAction ) { return true ; }
	if ( !data->hasFormat("AnimationCreator/object.item.list") ) { return false ; }
	if ( column > 0 ) { return false ; }

	qDebug() << "dropMimeData row:" << row << " col:" << column ;
	qDebug() << " parent:" << parent << " action:" << action ;

	QByteArray encodeData = data->data("AnimationCreator/object.item.list") ;
	QDataStream stream(&encodeData, QIODevice::ReadOnly) ;

	while ( !stream.atEnd() ) {
		quint64 val ;
		ObjectItem *p ;
		stream >> val ;
		p = reinterpret_cast<ObjectItem *>(val) ;

		if ( p->parent() == m_pRoot ) {	// オブジェクト
			if ( !parent.isValid() ) {
				emit sig_copyIndex(row, p, parent, action) ;
			}
		}
		else {							// レイヤ
			if ( parent.isValid() ) {
				emit sig_copyIndex(row, p, parent, action) ;
			}
		}
	}

	return true ;
}
// アニメ再生
void AnimationForm::slot_playAnimation( void )
{
	if ( !m_pEditData->getPauseAnime() ) {	// ポーズ中じゃなかったら0フレームから再生
		ui->label_frame->setValue(0);
		m_pEditData->setCurrLoopNum(0);
	}

	m_pEditData->setPlayAnime(true) ;

	// 最大フレーム設定
	ObjectItem *p = m_pEditData->getObjectModel()->getObject(m_pEditData->getSelIndex()) ;
	if ( p ) {
		m_nMaxFrameNum = p->getMaxFrameNum() ;
	}

	m_pEditData->setPauseAnime(false);
	disconnect(ui->pushButton_play, SIGNAL(clicked()), this, SLOT(slot_playAnimation())) ;
	connect(ui->pushButton_play, SIGNAL(clicked()), this, SLOT(slot_pauseAnimation())) ;

	QIcon icon;
	icon.addFile(QString::fromUtf8(":/root/Resources/images/Button Pause_32.png"), QSize(), QIcon::Normal, QIcon::Off);
	ui->pushButton_play->setIcon(icon);

	m_pTimer->start();	// タイマースタート
	m_pGlWidget->update();
}
void CObjectModel::flat()
{
	for ( int i = 0 ; i < m_pRoot->childCount() ; i ++ ) {
		ObjectItem *pObj = m_pRoot->child(i) ;
		pObj->flat() ;
	}
	updateIndex() ;
}
QModelIndex CObjectModel::parent(const QModelIndex &child) const
{
	if ( !child.isValid() ) { return QModelIndex() ; }
	ObjectItem *c = static_cast<ObjectItem *>(child.internalPointer()) ;
	ObjectItem *p = c->parent() ;
	if ( p == m_pRoot || c == m_pRoot ) { return QModelIndex() ; }
	return createIndex(p->row(), 0, p) ;
}
// ループ回数変更
void AnimationForm::slot_changeLoop( int val )
{
	CObjectModel *pModel = m_pEditData->getObjectModel() ;
	QModelIndex index = m_pEditData->getSelIndex() ;
	ObjectItem *pItem = pModel->getObject(index) ;
	if ( !pItem ) { return ; }
	pItem->setLoop(val);
}
ObjectItem *CObjectModel::getObject(const QModelIndex &index)
{
	if ( !index.isValid() ) { return NULL ; }
	ObjectItem *p = static_cast<ObjectItem *>(index.internalPointer()) ;
	while ( p->parent() != m_pRoot ) {
		p = p->parent() ;
	}
	return p ;
}
Beispiel #11
0
// Store objects with their propterties as QJsonObjects
// This way, every object can have custom properties, without creating special object classes
// The objects and its properties also may be saved to file in a human readable and modifiable format
bool ObjectContainer::add(ObjectType type, QJsonObject& data)
{
	if (!verifyData(data)) return false;

	ObjectItem* item = new ObjectItem(data["name"].toString());
	item->setData(data);
	m_model.appendRow(item);
	return true;
}
FrameData *ObjectItem::getParentFrameDataPtr(int frame)
{
	ObjectItem *parent = m_pParent ;
	while ( parent ) {
		FrameData *p = parent->getFrameDataPtr(frame) ;
		if ( p ) { return p ; }
		parent = parent->m_pParent ;
	}
	return NULL ;
}
void DataMarkerLabel::slot_deleteAllFrame()
{
    ObjectModel *pModel = m_pEditData->getObjectModel();
    ObjectItem *pItem = pModel->getObject(m_pEditData->getSelIndex());
    if (!pItem)
    {
        return;
    }
    m_pEditData->cmd_deleteAllFrame(pItem->getIndex(), m_value);
}
bool CObjectModel::removeRows(int row, int count, const QModelIndex &parent)
{
	beginRemoveRows(parent, row, row+count-1) ;

	ObjectItem *p = getItemFromIndex(parent) ;
	p->removeChild(p->child(row)) ;

	endRemoveRows();
	return true ;
}
void DataMarkerLabel::mousePressEvent(QMouseEvent *ev)
{
    m_bMouseMove = false;
    m_bPressLeft = false;
    m_moveMode = kMoveMode_None;
#if 0
	if ( ev->button() != Qt::LeftButton ) {
		ev->ignore();
		return ;
	}
#endif
    m_oldMousePos = ev->pos();
    m_bPressLeft = true;
    m_pressFrame = m_pressCurrentFrame = -1;

    ObjectModel *pModel = m_pEditData->getObjectModel();
    QModelIndex index = m_pEditData->getSelIndex();
    ObjectItem *pItem = pModel->getItemFromIndex(index);

    // 移動予定のフレームデータ取得
    if (ev->y() < height() / 3)
    {
        if (pModel->isLayer(index))
        {
            for (int i = m_frameStart; i <= m_frameEnd; i++)
            {
                if (ev->pos().x() >= getX(i) && ev->pos().x() < getX(i + 1))
                {
                    if (pItem->getFrameDataPtr(i))
                    {
                        m_pressCurrentFrame = m_pressFrame = i;
                        m_moveMode = kMoveMode_Layer;
                    }
                    break;
                }
            }
        }
    }
    else if (pModel->isObject(index) && ev->y() < height() * 2 / 3)
    {
        for (int i = m_frameStart; i <= m_frameEnd; i++)
        {
            if (ev->pos().x() >= getX(i) && ev->pos().x() < getX(i + 1))
            {
                if (pItem->getFrameDataPtr(i, true))
                {
                    m_pressCurrentFrame = m_pressFrame = i;
                    m_moveMode = kMoveMode_Object;
                }
                break;
            }
        }
    }
}
QModelIndex CObjectModel::insertItem(int row, QString name, const QModelIndex &parent)
{
	insertRows(row, 1, parent) ;

	QModelIndex index = this->index(row, 0, parent) ;
	ObjectItem *p = static_cast<ObjectItem *>(index.internalPointer()) ;
	p->setIndex(index) ;
	setData(index, name, Qt::EditRole) ;
//	qDebug() << "insertItem row:" << row << " name:" << name << " p:" << p ;
	return index ;
}
Beispiel #17
0
QJsonObject ObjectContainer::getData(int id)
{
	ObjectItem* item = getItem(id);
	if (!item)
	{
		StaticLogger::logit("WARNING: Object not found! The object with id '" + QString::number(id) + "' does not exist.");
		return QJsonObject();
	}

	return item->data().toJsonObject();
}
bool CObjectModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
	if ( role != Qt::DisplayRole && role != Qt::EditRole ) {
		return false ;
	}

	ObjectItem *p = getItemFromIndex(index) ;
	p->setName(value.toString()) ;
	emit dataChanged(index, index);
	return true ;
}
bool CObjectModel::insertRows(int row, int count, const QModelIndex &parent)
{
//	qDebug() << "insertRows " << row << count << parent ;
	beginInsertRows(parent, row, row+count-1) ;

	ObjectItem *p = getItemFromIndex(parent) ;
	p->insertChild(row, new ObjectItem(QString(), p)) ;

	endInsertRows();
	return true ;
}
Beispiel #20
0
QMatrix4x4 EditData::getNowSelectMatrix()
{
    QModelIndex index = getSelIndex();
    if (!getObjectModel()->isLayer(index))
    {
        return QMatrix4x4();
    }

    int frame = getSelectFrame();
    ObjectItem *pItem = getObjectModel()->getItemFromIndex(index);
    return pItem->getDisplayMatrix(frame);
}
Beispiel #21
0
QVariant TreeModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (role != Qt::DisplayRole)
        return QVariant();

    ObjectItem *item = static_cast<ObjectItem*>(index.internalPointer());

    return item->data(index.column());
}
QModelIndex CObjectModel::index(int row, int column, const QModelIndex &parent) const
{
	if ( !hasIndex(row, column, parent) ) { return QModelIndex() ; }

	ObjectItem *p = getItemFromIndex(parent) ;

	ObjectItem *pChild = p->child(row) ;
	if ( pChild ) {
		return createIndex(row, column, pChild) ;
	}
	return QModelIndex() ;
}
Beispiel #23
0
ObjectTree::~ObjectTree()
{
	QList<QStandardItem *> items = itemModel->findItems("*", Qt::MatchRecursive | Qt::MatchWildcard);

	int i;

	for (i=0; i<items.size(); i++) {
		ObjectItem *item = dynamic_cast<ObjectItem*>(items[i]);
		if (item && item->screenElement())
			delete item->screenElement();
	}
}
Beispiel #24
0
QModelIndex TreeModel::parent(const QModelIndex &index) const
{
    if (!index.isValid())
        return QModelIndex();

    ObjectItem *childItem = static_cast<ObjectItem*>(index.internalPointer());
    ObjectItem *parentItem = childItem->parentItem();

    if (parentItem == rootItem)
        return QModelIndex();

    return createIndex(parentItem->rowinParentList(), 0, parentItem);
}
Beispiel #25
0
int TreeModel::rowCount(const QModelIndex &parent) const
{
    ObjectItem *parentItem;
    if (parent.column() > 0)
        return 0;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast<ObjectItem*>(parent.internalPointer());

    return parentItem->childCount();
}
// 指定フレームのフレームデータを選択する
bool AnimationForm::setSelectFrameDataFromFrame( int frame, QModelIndex indexLayer )
{
	CObjectModel *pModel = m_pEditData->getObjectModel() ;
	if ( !pModel->isLayer(indexLayer) ) { return false ; }
	ObjectItem *pItem = pModel->getItemFromIndex(indexLayer) ;
	FrameData *pData = pItem->getFrameDataPtr(frame) ;
	if ( !pData ) { return false ; }

	ui->spinBox_nowSequence->setValue(frame);
	slot_setUI(*pData);
	m_pGlWidget->update();
	return true ;
}
Beispiel #27
0
void
MainWindow::MakeEmpty(void)
{
	while (fListView->CountItems())
	{
		ObjectItem *item = (ObjectItem*)fListView->RemoveItem(0L);
		if (item)
		{
			delete item->GetObject();
			delete item;
		}
	}
}
Beispiel #28
0
void ObjectContainer::modifyCmd(const QJsonObject& data, Modifications mod)
{
	ObjectItem* item = getItem(data["id"].toInt());

	if (!item)
		return;

	QJsonObject oldData = item->data().toJsonObject();
	if (oldData != data)
	{
		QUndoCommand* cmd = new ModifyObjectCmd(oldData, data, item, mod);
		g_undoStack.push(cmd);
	}
}
Beispiel #29
0
// 選択しているフレームデータ取得
bool EditData::getNowSelectFrameData(FrameData &ret)
{
    QModelIndex index = getSelIndex();
    if (!getObjectModel()->isLayer(index))
    {
        return false;
    }

    int frame = getSelectFrame();
    ObjectItem *pItem = getObjectModel()->getItemFromIndex(index);
    bool valid;
    ret = pItem->getDisplayFrameData(frame, &valid);
    return valid;
}
Beispiel #30
0
void
MainWindow::UpdateFloaters(void)
{
	ObjectItem *item = dynamic_cast<ObjectItem*>(fListView->FullListItemAt(
											fListView->FullListCurrentSelection()));
	
	FloaterBroker *broker = FloaterBroker::GetInstance();
	broker->DetachAllFloaters();
	
	if (item)
	{
		PView *view = dynamic_cast<PView*>(item->GetObject());
		broker->AttachAllFloaters(view);
	}
}