[nostalgia/core/studio] Make TileSheetEditor not highlight color cell
This commit is contained in:
parent
5a5905d257
commit
5f0217545c
@ -27,27 +27,25 @@ enum class PaletteEditorCommandId {
|
||||
UpdateColor,
|
||||
};
|
||||
|
||||
class ColorTableDelegate: public QStyledItemDelegate {
|
||||
public:
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex &idx) const {
|
||||
const auto max = idx.column() != 3 ? 31 : 1;
|
||||
auto le = new QLineEdit(parent);
|
||||
auto validator = new QIntValidator(0, max, le);
|
||||
le->setValidator(validator);
|
||||
return le;
|
||||
}
|
||||
struct PaletteEditorColorTableDelegate: public QStyledItemDelegate {
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
if (index.column() != 4) {
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->fillRect(option.rect, option.palette.highlight());
|
||||
}
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
} else {
|
||||
auto color = index.model()->data(index, Qt::DisplayRole).toString();
|
||||
painter->fillRect(option.rect, QColor(color));
|
||||
}
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex &idx) const {
|
||||
const auto max = idx.column() != 3 ? 31 : 1;
|
||||
auto le = new QLineEdit(parent);
|
||||
auto validator = new QIntValidator(0, max, le);
|
||||
le->setValidator(validator);
|
||||
return le;
|
||||
}
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &idx) const {
|
||||
if (idx.column() != 4) {
|
||||
QStyledItemDelegate::paint(painter, opt, idx);
|
||||
} else {
|
||||
auto color = idx.model()->data(idx, Qt::DisplayRole).toString();
|
||||
painter->fillRect(opt.rect, QColor(color));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class AddColorCommand: public QUndoCommand {
|
||||
@ -172,7 +170,7 @@ PaletteEditor::PaletteEditor(QString path, const studio::Context *ctx, QWidget *
|
||||
canvasLyt->setMenuBar(tb);
|
||||
|
||||
m_table = new QTableWidget(this);
|
||||
m_table->setItemDelegate(new ColorTableDelegate);
|
||||
m_table->setItemDelegate(new PaletteEditorColorTableDelegate);
|
||||
m_table->setColumnCount(5);
|
||||
m_table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <QBuffer>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QPainter>
|
||||
#include <QPointer>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickItem>
|
||||
@ -19,6 +20,7 @@
|
||||
#include <QSettings>
|
||||
#include <QSpinBox>
|
||||
#include <QSplitter>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QUndoCommand>
|
||||
#include <QTableWidget>
|
||||
#include <QToolBar>
|
||||
@ -53,6 +55,19 @@ struct LabeledSpinner: public QWidget {
|
||||
|
||||
};
|
||||
|
||||
struct TileSheetEditorColorTableDelegate: public QStyledItemDelegate {
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &idx) const {
|
||||
if (idx.column() != 1) {
|
||||
QStyledItemDelegate::paint(painter, opt, idx);
|
||||
} else {
|
||||
auto color = idx.model()->data(idx, Qt::DisplayRole).toString();
|
||||
painter->fillRect(opt.rect, QColor(color));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class UpdateDimensionsCommand: public QUndoCommand {
|
||||
public:
|
||||
@ -491,6 +506,7 @@ QWidget *TileSheetEditor::setupColorPicker(QWidget *parent) {
|
||||
auto lyt = new QVBoxLayout(colorPicker);
|
||||
m_colorPicker.palette = new QComboBox(colorPicker);
|
||||
m_colorPicker.colorTable = new QTableWidget(colorPicker);
|
||||
m_colorPicker.colorTable->setItemDelegate(new TileSheetEditorColorTableDelegate);
|
||||
m_colorPicker.colorTable->setColumnCount(2);
|
||||
m_colorPicker.colorTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_colorPicker.colorTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
@ -621,7 +637,7 @@ void TileSheetEditor::setColorTable() {
|
||||
auto hi = tbl->item(i, 0);
|
||||
hi->setFlags(hi->flags() & ~Qt::ItemIsEditable);
|
||||
auto color = new QTableWidgetItem;
|
||||
color->setBackground(QColor(hexColors[i]));
|
||||
color->setText(hexColors[i]);
|
||||
tbl->setItem(i, 1, color);
|
||||
auto ci = tbl->item(i, 1);
|
||||
ci->setFlags(ci->flags() & ~Qt::ItemIsEditable);
|
||||
|
Loading…
x
Reference in New Issue
Block a user