2021-09-04 17:10:25 +03:00
|
|
|
//#
|
|
|
|
//# Copyright (C) 2021-2021 QuasarApp.
|
|
|
|
//# Distributed under the GPLv3 software license, see the accompanying
|
|
|
|
//# Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
//# of this license document, but changing it is not allowed.
|
|
|
|
//#
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
#include "layout.h"
|
2021-09-08 22:20:52 +03:00
|
|
|
#include "clasteritem.h"
|
|
|
|
#include <QtMath>
|
2021-09-04 17:10:25 +03:00
|
|
|
|
|
|
|
namespace CRAWL {
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
Layout::Layout() {
|
2021-09-04 17:10:25 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::add(ClasterItem *object) {
|
2021-09-04 17:10:25 +03:00
|
|
|
|
2021-09-08 22:20:52 +03:00
|
|
|
Claster::add(object);
|
|
|
|
updatePosition();
|
2021-09-04 17:10:25 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::remove(ClasterItem *object) {
|
2021-09-04 17:10:25 +03:00
|
|
|
|
2021-09-10 11:18:54 +03:00
|
|
|
Claster::remove(object);
|
2021-09-08 22:20:52 +03:00
|
|
|
updatePosition();
|
2021-09-04 17:10:25 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::changeLayout(const Refresh &fig) {
|
2021-09-08 22:20:52 +03:00
|
|
|
_shape = fig;
|
2021-09-10 11:18:22 +03:00
|
|
|
updatePosition();
|
2021-09-08 22:20:52 +03:00
|
|
|
}
|
2021-09-04 17:10:25 +03:00
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::setDistance(int dist) {
|
2021-09-08 22:20:52 +03:00
|
|
|
_distance = dist;
|
2021-09-10 11:18:22 +03:00
|
|
|
updatePosition();
|
2021-09-08 22:20:52 +03:00
|
|
|
}
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::updatePosition() {
|
2021-09-08 22:20:52 +03:00
|
|
|
|
|
|
|
switch (_shape) {
|
|
|
|
case CIRCLE:
|
|
|
|
drawCircle();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SQUARE:
|
|
|
|
drawSquare();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LINE:
|
2021-09-10 21:50:03 +03:00
|
|
|
drawLine();
|
2021-09-08 22:20:52 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-09-04 17:10:25 +03:00
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::drawCircle() {
|
2021-09-08 22:20:52 +03:00
|
|
|
|
2021-09-09 22:37:05 +03:00
|
|
|
if (objects().size() == 0) {
|
2021-09-10 21:50:03 +03:00
|
|
|
QuasarAppUtils::Params::log(QString("The number of objects is zero. Add object."), QuasarAppUtils::Error);
|
2021-09-09 22:37:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-08 22:20:52 +03:00
|
|
|
float step = 360 / objects().size();
|
2021-09-09 22:37:05 +03:00
|
|
|
int temp = 0;
|
2021-09-08 22:20:52 +03:00
|
|
|
|
|
|
|
for (ClasterItem* object: objects()) {
|
|
|
|
|
|
|
|
float x = _distance * qCos(step*temp);
|
|
|
|
float y = _distance * qSin(step*temp);
|
|
|
|
GroupObject::updatePosition(object->guiId(), {x, y, 0});
|
|
|
|
|
|
|
|
temp++;
|
2021-09-04 17:10:25 +03:00
|
|
|
}
|
|
|
|
|
2021-09-08 22:20:52 +03:00
|
|
|
}
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::drawSquare() {
|
2021-09-08 22:20:52 +03:00
|
|
|
|
2021-09-09 22:37:05 +03:00
|
|
|
if (objects().size() == 0) {
|
2021-09-10 21:50:03 +03:00
|
|
|
QuasarAppUtils::Params::log(QString("The number of objects is zero. Add object."), QuasarAppUtils::Error);
|
2021-09-09 22:37:05 +03:00
|
|
|
return;
|
|
|
|
}
|
2021-09-08 22:20:52 +03:00
|
|
|
|
2021-09-09 22:37:05 +03:00
|
|
|
int height = qFloor(qSqrt(objects().size()));
|
2021-09-10 21:50:03 +03:00
|
|
|
|
|
|
|
int indObject = 0;
|
|
|
|
for (auto idObj = objects().keyBegin(); idObj != objects().keyEnd(); idObj++) {
|
|
|
|
|
2021-09-11 10:31:39 +03:00
|
|
|
float x = indObject % height;
|
|
|
|
float y = qCeil(indObject / height);
|
2021-09-10 21:50:03 +03:00
|
|
|
|
2021-09-11 10:31:39 +03:00
|
|
|
GroupObject::updatePosition(*idObj, {x + _distance,
|
2021-09-10 21:50:03 +03:00
|
|
|
y + _distance,
|
|
|
|
0});
|
|
|
|
indObject++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-17 21:12:33 +03:00
|
|
|
void Layout::drawLine() {
|
2021-09-10 21:50:03 +03:00
|
|
|
|
|
|
|
if (objects().size() == 0) {
|
|
|
|
QuasarAppUtils::Params::log(QString("The number of objects is zero. Add object."), QuasarAppUtils::Error);
|
|
|
|
return;
|
2021-09-04 17:10:25 +03:00
|
|
|
}
|
|
|
|
|
2021-09-10 21:50:03 +03:00
|
|
|
float xObject = 0;
|
|
|
|
for (ClasterItem* object: objects()) {
|
|
|
|
GroupObject::updatePosition(object->guiId(), {xObject + _distance, 0, 0});
|
|
|
|
|
|
|
|
xObject++;
|
|
|
|
}
|
2021-09-04 17:10:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|