7#include "MarbleGraphicsGridLayout.h"
10#include "MarbleDebug.h"
11#include "ScreenGraphicsItem.h"
22class MarbleGraphicsGridLayoutPrivate
25 MarbleGraphicsGridLayoutPrivate(
int rows,
int columns)
31 m_items =
new ScreenGraphicsItem **[rows];
32 for (
int i = 0; i < rows; ++i) {
33 m_items[i] =
new ScreenGraphicsItem *[columns];
35 for (
int row = 0; row < rows; row++) {
36 for (
int column = 0; column < columns; column++) {
37 m_items[row][column] =
nullptr;
42 ~MarbleGraphicsGridLayoutPrivate()
44 for (
int i = 0; i < m_rows; ++i) {
51 ScreenGraphicsItem ***m_items;
59MarbleGraphicsGridLayout::MarbleGraphicsGridLayout(
int rows,
int columns)
60 : d(new MarbleGraphicsGridLayoutPrivate(rows, columns))
64MarbleGraphicsGridLayout::~MarbleGraphicsGridLayout()
69void MarbleGraphicsGridLayout::addItem(ScreenGraphicsItem *item,
int row,
int column)
71 if (row < d->m_rows && column < d->m_columns) {
72 d->m_items[row][column] = item;
76void MarbleGraphicsGridLayout::updatePositions(MarbleGraphicsItem *parent)
83 for (
int row = 0; row < d->m_rows; row++) {
84 for (
int column = 0; column < d->m_columns; column++) {
85 if (d->m_items[row][column] ==
nullptr) {
89 QSizeF size = d->m_items[row][column]->size();
90 double width = size.
width();
91 double height = size.
height();
93 if (width > maxWidth[column]) {
94 maxWidth[column] = width;
96 if (height > maxHeight[row]) {
97 maxHeight[row] = height;
106 QRectF contentRect = parent->contentRect();
108 for (
int i = 0; i < d->m_columns; i++) {
110 startX[0] = contentRect.
left();
111 }
else if (maxWidth[i] == 0) {
112 startX[i] = endX[i - 1];
114 startX[i] = endX[i - 1] + d->m_spacing;
117 endX[i] = startX[i] + maxWidth[i];
120 for (
int i = 0; i < d->m_rows; i++) {
122 startY[0] = contentRect.
left();
123 }
else if (maxHeight[i] == 0) {
124 startY[i] = endY[i - 1];
126 startY[i] = endY[i - 1] + d->m_spacing;
129 endY[i] = startY[i] + maxHeight[i];
133 for (
int row = 0; row < d->m_rows; row++) {
134 for (
int column = 0; column < d->m_columns; column++) {
135 if (d->m_items[row][column] ==
nullptr) {
144 xPos = endX[column] - d->m_items[row][column]->size().width();
146 xPos = startX[column] + (maxWidth[column] - d->m_items[row][column]->size().width()) / 2.0;
148 xPos = startX[column];
152 yPos = endY[row] - d->m_items[row][column]->size().height();
154 yPos = startY[row] + (maxHeight[row] - d->m_items[row][column]->size().height()) / 2.0;
159 d->m_items[row][column]->setPosition(
QPointF(xPos, yPos));
163 parent->setContentSize(
QSizeF(endX[d->m_columns - 1] - contentRect.
left(), endY[d->m_rows - 1] - contentRect.
top()));
168 return d->m_alignment;
171Qt::Alignment MarbleGraphicsGridLayout::alignment(ScreenGraphicsItem *item)
const
173 return d->m_itemAlignment.value(item, d->m_alignment);
176void MarbleGraphicsGridLayout::setAlignment(
Qt::Alignment align)
178 d->m_alignment = align;
181void MarbleGraphicsGridLayout::setAlignment(ScreenGraphicsItem *item,
Qt::Alignment align)
183 d->m_itemAlignment.insert(item, align);
186int MarbleGraphicsGridLayout::spacing()
const
191void MarbleGraphicsGridLayout::setSpacing(
int spacing)
193 d->m_spacing = spacing;
Binds a QML item to a specific geodetic location in screen coordinates.
qreal height() const const
qreal width() const const