0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00
LimeReport/limereport/lritemscontainerdesignitf.cpp

146 lines
5.2 KiB
C++
Raw Normal View History

2017-04-05 00:58:04 +03:00
#include "lritemscontainerdesignitf.h"
2020-06-20 10:10:53 +03:00
#include "lrbanddesignintf.h"
#include "lritemdesignintf.h"
2017-04-05 00:58:04 +03:00
namespace LimeReport {
bool Segment::intersect(Segment value)
{
return (value.m_begin <= m_end) && (value.m_end >= m_begin);
2017-04-05 00:58:04 +03:00
}
qreal Segment::intersectValue(Segment value)
{
if (!intersect(value))
return 0;
if ((value.m_end >= m_begin) && (value.m_end <= m_end)) {
return value.m_end - m_begin;
2017-04-05 00:58:04 +03:00
}
if ((value.m_begin >= m_begin) && (value.m_end >= m_end)) {
return m_end - value.m_begin;
2017-04-05 00:58:04 +03:00
}
if ((value.m_begin >= m_begin) && (value.m_end <= m_end)) {
return value.m_end - value.m_begin;
2017-04-05 00:58:04 +03:00
}
if ((value.m_begin < m_begin) && (value.m_end > m_end)) {
return m_end - m_begin;
2017-04-05 00:58:04 +03:00
}
return 0;
}
bool itemSortContainerLessThen(const PItemSortContainer c1, const PItemSortContainer c2)
{
VSegment vS1(c1->m_rect), vS2(c2->m_rect);
HSegment hS1(c1->m_rect), hS2(c2->m_rect);
if (vS1.intersectValue(vS2) > hS1.intersectValue(hS2))
return c1->m_rect.x() < c2->m_rect.x();
else
return c1->m_rect.y() < c2->m_rect.y();
2017-04-05 00:58:04 +03:00
}
2020-06-20 10:10:53 +03:00
void ItemsContainerDesignInft::snapshotItemsLayout(SnapshotType type)
2017-04-05 00:58:04 +03:00
{
m_containerItems.clear();
foreach (BaseDesignIntf* childItem, childBaseItems()) {
if (type == IgnoreBands) {
2020-06-20 10:10:53 +03:00
if (!dynamic_cast<BandDesignIntf*>(childItem))
m_containerItems.append(PItemSortContainer(new ItemSortContainer(childItem)));
} else
m_containerItems.append(PItemSortContainer(new ItemSortContainer(childItem)));
2017-04-05 00:58:04 +03:00
}
std::sort(m_containerItems.begin(), m_containerItems.end(), itemSortContainerLessThen);
2017-04-05 00:58:04 +03:00
}
void ItemsContainerDesignInft::arrangeSubItems(RenderPass pass, DataSourceManager* dataManager,
ArrangeType type)
2017-04-05 00:58:04 +03:00
{
bool needArrage = (type == Force);
2017-04-05 00:58:04 +03:00
foreach (PItemSortContainer item, m_containerItems) {
if (item->m_item->isNeedUpdateSize(pass)) {
2017-04-05 00:58:04 +03:00
item->m_item->updateItemSize(dataManager, pass);
needArrage = true;
2017-04-05 00:58:04 +03:00
}
}
if (needArrage) {
for (int i = 0; i < m_containerItems.count(); i++) {
for (int j = i; j < m_containerItems.count(); j++) {
if ((i != j)
&& (m_containerItems[i]->m_item->collidesWithItem(
m_containerItems[j]->m_item))) {
HSegment hS1(m_containerItems[j]->m_rect), hS2(m_containerItems[i]->m_rect);
VSegment vS1(m_containerItems[j]->m_rect), vS2(m_containerItems[i]->m_rect);
if (m_containerItems[i]->m_rect.bottom()
< m_containerItems[i]->m_item->geometry().bottom()) {
if (hS1.intersectValue(hS2) > vS1.intersectValue(vS2))
m_containerItems[j]->m_item->setY(
m_containerItems[i]->m_item->y()
+ m_containerItems[i]->m_item->height()
+ m_containerItems[j]->m_rect.top()
- m_containerItems[i]->m_rect.bottom());
2017-04-05 00:58:04 +03:00
}
if (m_containerItems[i]->m_rect.right()
< m_containerItems[i]->m_item->geometry().right()) {
if (vS1.intersectValue(vS2) > hS1.intersectValue(hS2))
m_containerItems[j]->m_item->setX(
m_containerItems[i]->m_item->geometry().right()
+ (m_containerItems[j]->m_rect.x()
- m_containerItems[i]->m_rect.right()));
2017-04-05 00:58:04 +03:00
}
}
}
}
}
if (needArrage || pass == FirstPass) {
2017-04-05 00:58:04 +03:00
int maxBottom = findMaxBottom();
foreach (BaseDesignIntf* item, childBaseItems()) {
ItemDesignIntf* childItem = dynamic_cast<ItemDesignIntf*>(item);
if (childItem) {
2017-04-05 00:58:04 +03:00
if (childItem->stretchToMaxHeight())
childItem->setHeight(maxBottom - childItem->geometry().top());
2017-04-05 00:58:04 +03:00
}
}
}
}
2017-08-14 22:39:38 +03:00
qreal ItemsContainerDesignInft::findMaxBottom() const
2017-04-05 00:58:04 +03:00
{
2017-12-18 20:28:26 +03:00
qreal maxBottom = 0;
foreach (QGraphicsItem* item, childItems()) {
BaseDesignIntf* subItem = dynamic_cast<BaseDesignIntf*>(item);
if (subItem)
if (subItem->isVisible() && (subItem->geometry().bottom() > maxBottom))
maxBottom = subItem->geometry().bottom();
2017-04-05 00:58:04 +03:00
}
return maxBottom;
}
qreal ItemsContainerDesignInft::findMinTop() const
{
2017-12-18 20:28:26 +03:00
qreal minTop = height();
foreach (QGraphicsItem* item, childItems()) {
BaseDesignIntf* subItem = dynamic_cast<BaseDesignIntf*>(item);
if (subItem)
if (subItem->isVisible() && (subItem->geometry().top() < minTop))
minTop = subItem->geometry().top();
2017-12-18 20:28:26 +03:00
}
return minTop > 0 ? minTop : 0;
}
2017-08-14 22:39:38 +03:00
qreal ItemsContainerDesignInft::findMaxHeight() const
2017-04-05 00:58:04 +03:00
{
qreal maxHeight = 0;
foreach (QGraphicsItem* item, childItems()) {
BaseDesignIntf* subItem = dynamic_cast<BaseDesignIntf*>(item);
if (subItem)
if (subItem->geometry().height() > maxHeight)
maxHeight = subItem->geometry().height();
2017-04-05 00:58:04 +03:00
}
return maxHeight;
}
} // namespace LimeReport