Implemented transparent background settings
This commit is contained in:
1 parent
7d1c2c7d15
commit
52561186af
30 files changed
+829
-239
No files matched your search
@@ -9,6 +9,12 @@ SpritesModel::SpritesModel(const std::vector<QPixmap> &pixmaps, QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
SpritesModel::SpritesModel(std::vector<QPixmap> &&pixmaps, QObject *parent) :
|
||||
QAbstractListModel{parent},
|
||||
m_pixmaps{std::move(pixmaps)}
|
||||
{
|
||||
}
|
||||
|
||||
int SpritesModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
@@ -45,10 +51,124 @@ QVariant SpritesModel::data(const QModelIndex &index, int role) const
|
||||
return {};
|
||||
}
|
||||
|
||||
bool SpritesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
|
||||
if (row < 0 || std::size_t(row) >= m_pixmaps.size())
|
||||
{
|
||||
qWarning() << "unexpected row" << row;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count < 0 || std::size_t(count) > m_pixmaps.size() - row)
|
||||
{
|
||||
qWarning() << "unexpected row+count" << count << row;
|
||||
return false;
|
||||
}
|
||||
|
||||
beginRemoveRows({}, row, row + count - 1);
|
||||
auto begin = std::next(std::begin(m_pixmaps), row);
|
||||
auto end = std::next(begin, count);
|
||||
m_pixmaps.erase(begin, end);
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SpritesModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
|
||||
{
|
||||
if (sourceParent.isValid())
|
||||
return false;
|
||||
if (destinationParent.isValid())
|
||||
return false;
|
||||
if (count != 1)
|
||||
return false;
|
||||
|
||||
beginMoveRows({}, sourceRow, sourceRow, {}, destinationChild);
|
||||
auto first = m_pixmaps.begin();
|
||||
auto src = first + sourceRow;
|
||||
auto dst = first + destinationChild;
|
||||
|
||||
if (src < dst)
|
||||
std::rotate(src, src + 1, dst);
|
||||
else if (dst < src)
|
||||
std::rotate(dst, src, src + 1);
|
||||
endMoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmaps(const std::vector<QPixmap> &pixmaps)
|
||||
{
|
||||
beginResetModel();
|
||||
m_pixmaps = pixmaps;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmaps(std::vector<QPixmap> &&pixmaps)
|
||||
{
|
||||
beginResetModel();
|
||||
m_pixmaps = std::move(pixmaps);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
const QPixmap &SpritesModel::pixmap(const QModelIndex &index) const
|
||||
{
|
||||
if (index.row() < 0 || std::size_t(index.row()) >= m_pixmaps.size())
|
||||
if (!index.isValid())
|
||||
qFatal("invalid index");
|
||||
return pixmap(index.row());
|
||||
}
|
||||
|
||||
const QPixmap &SpritesModel::pixmap(int row) const
|
||||
{
|
||||
if (row < 0 || std::size_t(row) >= m_pixmaps.size())
|
||||
qFatal("row %i out of range", row);
|
||||
return m_pixmaps.at(row);
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(const QPixmap &pixmap, const QModelIndex &index)
|
||||
{
|
||||
m_pixmaps[index.row()] = pixmap;
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(QPixmap &&pixmap, const QModelIndex &index)
|
||||
{
|
||||
m_pixmaps[index.row()] = std::move(pixmap);
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(const QPixmap &pixmap, int row)
|
||||
{
|
||||
const auto index = createIndex(row, 0);
|
||||
m_pixmaps[index.row()] = pixmap;
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::setPixmap(QPixmap &&pixmap, int row)
|
||||
{
|
||||
const auto index = createIndex(row, 0);
|
||||
m_pixmaps[index.row()] = std::move(pixmap);
|
||||
emit dataChanged(index, index, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
void SpritesModel::insertPixmap(const QPixmap &pixmap, std::size_t index)
|
||||
{
|
||||
if (index > m_pixmaps.size())
|
||||
qFatal("index out of range");
|
||||
|
||||
return m_pixmaps.at(index.row());
|
||||
beginInsertRows({}, index, index);
|
||||
m_pixmaps.emplace(std::begin(m_pixmaps) + index, pixmap);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void SpritesModel::insertPixmap(QPixmap &&pixmap, std::size_t index)
|
||||
{
|
||||
if (index > m_pixmaps.size())
|
||||
qFatal("index out of range");
|
||||
|
||||
beginInsertRows({}, index, index);
|
||||
m_pixmaps.emplace(std::begin(m_pixmaps) + index, std::move(pixmap));
|
||||
endInsertRows();
|
||||
}
|
||||
@@ -11,24 +11,31 @@ class SpritesModel : public QAbstractListModel
|
||||
|
||||
public:
|
||||
explicit SpritesModel(const std::vector<QPixmap> &pixmaps, QObject *parent = nullptr);
|
||||
explicit SpritesModel(std::vector<QPixmap> &&pixmaps, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
|
||||
|
||||
const std::vector<QPixmap> &pixmaps() const { return m_pixmaps; }
|
||||
void setPixmaps(const std::vector<QPixmap> &pixmaps);
|
||||
void setPixmaps(std::vector<QPixmap> &&pixmaps);
|
||||
|
||||
auto size() const { return m_pixmaps.size(); }
|
||||
auto empty() const { return m_pixmaps.empty(); }
|
||||
const auto &front() const { return m_pixmaps.front(); }
|
||||
|
||||
const QPixmap &pixmap(const QModelIndex &index) const;
|
||||
const QPixmap &pixmap(int row) const;
|
||||
void setPixmap(const QPixmap &pixmap, const QModelIndex &index);
|
||||
void setPixmap(QPixmap &&pixmap, const QModelIndex &index);
|
||||
void setPixmap(const QPixmap &pixmap, int row);
|
||||
void setPixmap(QPixmap &&pixmap, int row);
|
||||
|
||||
using QAbstractListModel::beginResetModel;
|
||||
using QAbstractListModel::endResetModel;
|
||||
|
||||
using QAbstractListModel::beginInsertRows;
|
||||
using QAbstractListModel::endInsertRows;
|
||||
|
||||
using QAbstractListModel::beginRemoveRows;
|
||||
using QAbstractListModel::endRemoveRows;
|
||||
|
||||
using QAbstractListModel::beginMoveRows;
|
||||
using QAbstractListModel::endMoveRows;
|
||||
void insertPixmap(const QPixmap &pixmap, std::size_t index);
|
||||
void insertPixmap(QPixmap &&pixmap, std::size_t index);
|
||||
|
||||
private:
|
||||
const std::vector<QPixmap> &m_pixmaps;
|
||||
std::vector<QPixmap> m_pixmaps;
|
||||
};
|
||||
Reference in new issue
Block a user