KisRectsGrid.h 914 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 *  SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef KISRECTSGRID_H
#define KISRECTSGRID_H

#include <QRect>
#include <QVector>
#include "kritaglobal_export.h"

class KRITAGLOBAL_EXPORT KisRectsGrid
{
public:
    KisRectsGrid(int gridSize = 64);

    QRect alignRect(const QRect &rc) const;

    QVector<QRect> addRect(const QRect &rc);
    QVector<QRect> removeRect(const QRect &rc);

    QVector<QRect> addAlignedRect(const QRect &rc);
    QVector<QRect> removeAlignedRect(const QRect &rc);

    bool contains(const QRect &rc) const;

private:
    void resize(const QRect &newMappedAreaSize);
    static QRect shrinkRectToAlignedGrid(const QRect &srcRect, int lod);

private:
    int m_gridSize;
    int m_logGridSize;
    QVector<quint8> m_mapping;
    QRect m_mappedAreaSize; // measured in col/row

};

#endif // KISRECTSGRID_H