140 lines
3.5 KiB
C++
140 lines
3.5 KiB
C++
#include "eobject.h"
|
|
#include "eobjectattr.h"
|
|
|
|
eObject::eObject(InteractiveType type, QGraphicsItem *parent) :
|
|
LoQGraphicsObject(type, parent)
|
|
{
|
|
init();
|
|
}
|
|
|
|
eObject::eObject(QRectF rect, InteractiveType type, QGraphicsItem *parent) :
|
|
LoQGraphicsObject(rect, type, parent)
|
|
{
|
|
setGeometry(rect);
|
|
init();
|
|
}
|
|
|
|
eObject::eObject(const QJsonObject &json, InteractiveType type, QGraphicsItem *parent) :
|
|
LoQGraphicsObject(type, parent)
|
|
{
|
|
setZValue(json["order"].toInt());//toDouble());
|
|
// setGeometry(QRectF(json["x"].toDouble(), json["y"].toDouble(),
|
|
// json["w"].toDouble(), json["h"].toDouble()));
|
|
setGeometry(QRectF(json["x"].toInt(), json["y"].toInt(),
|
|
json["w"].toInt(), json["h"].toInt()));
|
|
init();
|
|
}
|
|
|
|
void eObject::init()
|
|
{
|
|
connect(this, SIGNAL(sPlayBQ()), this, SLOT(playElectment()), Qt::BlockingQueuedConnection);
|
|
connect(this, SIGNAL(sStopBQ()), this, SLOT(stopElectment()), Qt::BlockingQueuedConnection);
|
|
}
|
|
|
|
QWidget* eObject::wAttr()
|
|
{
|
|
Data data;
|
|
data.x = geometry().x();
|
|
data.y = geometry().y();
|
|
data.w = geometry().width();
|
|
data.h = geometry().height();
|
|
eObjectAttr *w = new eObjectAttr(data, rLimit());
|
|
connect(this, SIGNAL(geometryChanged(const QRectF &)), this, SLOT(onAttrSetting(const QRectF &)));
|
|
connect( w, SIGNAL(sAttrChanged(const eObject::Data &)), this, SLOT(onAttrChanged(const eObject::Data &)));
|
|
connect(this, SIGNAL(sAttrSetting(const eObject::Data &)), w, SLOT(onAttrSetting(const eObject::Data &)));
|
|
m_wAttr = w;
|
|
return w;
|
|
}
|
|
|
|
QJsonObject eObject::elementJson() const
|
|
{
|
|
QJsonObject oRoot;
|
|
QRectF r = geometry();
|
|
oRoot["order"] = zValue();
|
|
oRoot["x"] = (int)r.x();
|
|
oRoot["y"] = (int)r.y();
|
|
oRoot["w"] = (int)r.width();
|
|
oRoot["h"] = (int)r.height();
|
|
return oRoot;
|
|
}
|
|
|
|
void eObject::setRLimit(const QRectF r)
|
|
{
|
|
if(isSelected())
|
|
m_wAttr->setRLimit(r);
|
|
LoQGraphicsObject::setRLimit(r);
|
|
}
|
|
|
|
void eObject::onAttrChanged(const eObject::Data &data)
|
|
{
|
|
setGeometry(data.x, data.y, data.w, data.h);
|
|
}
|
|
|
|
void eObject::onAttrSetting(const QRectF &r)
|
|
{
|
|
eObject::Data data;
|
|
data.x = r.x();
|
|
data.y = r.y();
|
|
data.w = r.width();
|
|
data.h = r.height();
|
|
emit sAttrSetting(data);
|
|
}
|
|
//QString eObject::getFileMd5(QString filePath)
|
|
//{
|
|
// QFile theFile(filePath);
|
|
// theFile.open(QIODevice::ReadOnly);
|
|
// QByteArray ba = QCryptographicHash::hash(theFile.readAll(), QCryptographicHash::Md5);
|
|
// theFile.close();
|
|
// QString strRes="";
|
|
// strRes.append(ba.toHex());
|
|
// return strRes;
|
|
//}
|
|
QString eObject::getFileMd5(QString filePath)
|
|
{
|
|
QFile localFile(filePath);
|
|
|
|
if (!localFile.open(QFile::ReadOnly))
|
|
{
|
|
qDebug() << "file open error.";
|
|
return 0;
|
|
}
|
|
|
|
QCryptographicHash ch(QCryptographicHash::Md5);
|
|
|
|
quint64 totalBytes = 0;
|
|
quint64 bytesWritten = 0;
|
|
quint64 bytesToWrite = 0;
|
|
quint64 loadSize = 1024 * 4;
|
|
QByteArray buf;
|
|
|
|
totalBytes = localFile.size();
|
|
bytesToWrite = totalBytes;
|
|
|
|
while (1)
|
|
{
|
|
if(bytesToWrite > 0)
|
|
{
|
|
buf = localFile.read(qMin(bytesToWrite, loadSize));
|
|
ch.addData(buf);
|
|
bytesWritten += buf.length();
|
|
bytesToWrite -= buf.length();
|
|
buf.resize(0);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
|
|
if(bytesWritten == totalBytes)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
localFile.close();
|
|
QByteArray md5 = ch.result();
|
|
QString strRes="";
|
|
strRes.append(md5.toHex());
|
|
return strRes;
|
|
}
|