mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 12:34:39 +03:00
Layout spacing property has been added to layouts
This commit is contained in:
parent
65a3a36770
commit
867448d0fd
@ -4,7 +4,7 @@ namespace LimeReport {
|
||||
|
||||
AbstractLayout::AbstractLayout(QString xmlTag, QObject* owner, QGraphicsItem* parent)
|
||||
: LayoutDesignIntf(xmlTag, owner, parent), m_isRelocating(false), m_layoutType(Layout),
|
||||
m_hideEmptyItems(false)
|
||||
m_hideEmptyItems(false), m_layoutSpacing(0)
|
||||
{
|
||||
setPossibleResizeDirectionFlags(AllDirections);
|
||||
m_layoutMarker = new LayoutMarker(this);
|
||||
@ -336,6 +336,22 @@ void AbstractLayout::slotOnChildSelectionHasChanged(BaseDesignIntf* item, bool v
|
||||
item->setZValue(value ? item->zValue()+1 : item->zValue()-1);
|
||||
}
|
||||
|
||||
int AbstractLayout::layoutSpacing() const
|
||||
{
|
||||
return m_layoutSpacing;
|
||||
}
|
||||
|
||||
void AbstractLayout::setLayoutSpacing(int layoutSpacing)
|
||||
{
|
||||
if (m_layoutSpacing != layoutSpacing){
|
||||
int oldValue = m_layoutSpacing;
|
||||
m_layoutSpacing = layoutSpacing;
|
||||
int delta = (m_layoutSpacing - oldValue) * (m_children.count()-1);
|
||||
notify("layoutSpacing", oldValue, m_layoutSpacing);
|
||||
setWidth(width() + delta);
|
||||
}
|
||||
}
|
||||
|
||||
bool AbstractLayout::hideEmptyItems() const
|
||||
{
|
||||
return m_hideEmptyItems;
|
||||
|
@ -10,6 +10,7 @@ class AbstractLayout: public LayoutDesignIntf
|
||||
Q_OBJECT
|
||||
Q_ENUMS(LayoutType)
|
||||
Q_PROPERTY(bool hideEmptyItems READ hideEmptyItems WRITE setHideEmptyItems)
|
||||
Q_PROPERTY(int layoutSpacing READ layoutSpacing WRITE setLayoutSpacing)
|
||||
public:
|
||||
enum LayoutType{Layout,Table};
|
||||
AbstractLayout(QString xmlTag, QObject *owner = 0, QGraphicsItem *parent = 0);
|
||||
@ -31,6 +32,9 @@ public:
|
||||
void setHideEmptyItems(bool hideEmptyItems);
|
||||
Q_INVOKABLE QObject* at(int index);
|
||||
int childrenCount();
|
||||
int layoutSpacing() const;
|
||||
void setLayoutSpacing(int layoutSpacing);
|
||||
|
||||
protected:
|
||||
void beforeDelete();
|
||||
void childAddedEvent(BaseDesignIntf *child);
|
||||
@ -64,6 +68,7 @@ private:
|
||||
LayoutMarker* m_layoutMarker;
|
||||
LayoutType m_layoutType;
|
||||
bool m_hideEmptyItems;
|
||||
int m_layoutSpacing;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
@ -148,16 +148,18 @@ void HorizontalLayout::updateLayoutSize()
|
||||
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
|
||||
qreal w = spaceBorder*2;
|
||||
qreal h = 0;
|
||||
int visibleItemCount = 0;
|
||||
foreach(BaseDesignIntf* item, layoutsChildren()){
|
||||
if (item->isEmpty() && hideEmptyItems()) item->setVisible(false);
|
||||
if (item->isVisible()){
|
||||
if (h<item->height()) h=item->height();
|
||||
w+=item->width();
|
||||
visibleItemCount++;
|
||||
}
|
||||
}
|
||||
if (h>0) setHeight(h+spaceBorder*2);
|
||||
if (layoutType() == Layout)
|
||||
setWidth(w);
|
||||
setWidth(w + layoutSpacing() * (visibleItemCount-1));
|
||||
else{
|
||||
relocateChildren();
|
||||
if (!isRelocating()){
|
||||
@ -181,7 +183,7 @@ void HorizontalLayout::relocateChildren()
|
||||
foreach (BaseDesignIntf* item, layoutsChildren()) {
|
||||
if (item->isVisible() || itemMode() == DesignMode){
|
||||
item->setPos(curX,spaceBorder);
|
||||
curX+=item->width();
|
||||
curX += item->width() + layoutSpacing();
|
||||
item->setHeight(height()-(spaceBorder * 2));
|
||||
}
|
||||
}
|
||||
@ -201,6 +203,8 @@ void HorizontalLayout::divideSpace(){
|
||||
}
|
||||
}
|
||||
|
||||
itemsSumSize += layoutSpacing() * (visibleItemsCount-1);
|
||||
|
||||
if (itemMode() == DesignMode && !layoutsChildren().isEmpty()){
|
||||
qreal delta = (width() - (itemsSumSize+spaceBorder*2));
|
||||
layoutsChildren().last()->setWidth(layoutsChildren().last()->width()+delta);
|
||||
|
@ -41,15 +41,17 @@ void VerticalLayout::updateLayoutSize()
|
||||
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
|
||||
int h = spaceBorder*2;
|
||||
qreal w = 0;
|
||||
int visibleItemCount = 0;
|
||||
foreach(BaseDesignIntf* item, layoutsChildren()){
|
||||
if (item->isEmpty() && hideEmptyItems()) item->setVisible(false);
|
||||
if (item->isVisible()){
|
||||
if (w < item->width()) w = item->width();
|
||||
h+=item->height();
|
||||
visibleItemCount++;
|
||||
}
|
||||
}
|
||||
if (w>0) setWidth(w+spaceBorder*2);
|
||||
setHeight(h);
|
||||
setHeight(h + layoutSpacing() *(visibleItemCount-1));
|
||||
}
|
||||
|
||||
void VerticalLayout::relocateChildren()
|
||||
@ -67,7 +69,7 @@ void VerticalLayout::relocateChildren()
|
||||
foreach (BaseDesignIntf* item, layoutsChildren()) {
|
||||
if (item->isVisible() || itemMode() == DesignMode){
|
||||
item->setPos(spaceBorder, curY);
|
||||
curY+=item->height();
|
||||
curY+=item->height() + layoutSpacing();
|
||||
item->setWidth(width() - (spaceBorder * 2));
|
||||
}
|
||||
}
|
||||
@ -160,6 +162,8 @@ void VerticalLayout::divideSpace()
|
||||
visibleItemsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
itemsSumSize += layoutSpacing() * (visibleItemsCount - 1);
|
||||
qreal delta = (height() - (itemsSumSize+spaceBorder*2)) / (visibleItemsCount!=0 ? visibleItemsCount : 1);
|
||||
|
||||
for (int i=0; i<layoutsChildren().size(); ++i){
|
||||
|
@ -1854,14 +1854,16 @@ TableBuilder::TableBuilder(HorizontalLayout* layout, DataSourceManager* dataMana
|
||||
QObject* TableBuilder::addRow()
|
||||
{
|
||||
checkBaseLayout();
|
||||
HorizontalLayout* newRow = new HorizontalLayout(m_baseLayout, m_baseLayout);
|
||||
for(int i = 0; i < m_horizontalLayout->childrenCount(); ++i){
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(m_patternLayout->at(i));
|
||||
BaseDesignIntf* cloneItem = item->cloneItem(item->itemMode(), newRow, newRow);
|
||||
newRow->addChild(cloneItem);
|
||||
}
|
||||
m_baseLayout->addChild(newRow);
|
||||
return newRow;
|
||||
if (m_baseLayout && m_patternLayout){
|
||||
HorizontalLayout* newRow = new HorizontalLayout(m_baseLayout, m_baseLayout);
|
||||
for(int i = 0; i < m_horizontalLayout->childrenCount(); ++i){
|
||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(m_patternLayout->at(i));
|
||||
BaseDesignIntf* cloneItem = item->cloneItem(item->itemMode(), newRow, newRow);
|
||||
newRow->addChild(cloneItem);
|
||||
}
|
||||
m_baseLayout->addChild(newRow);
|
||||
return newRow;
|
||||
} else return 0;
|
||||
}
|
||||
|
||||
QObject* TableBuilder::currentRow()
|
||||
|
Loading…
Reference in New Issue
Block a user