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