mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-25 06:15:26 +00:00
Add search color option feature + sort color options by name (#1803)
This commit is contained in:
parent
2589e713fd
commit
59161e633f
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent) :
|
ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@ -50,6 +51,11 @@ ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent) :
|
|||||||
ui->colorPicker->setAlphaEnabled(showAlphaOptions.contains(optionName));
|
ui->colorPicker->setAlphaEnabled(showAlphaOptions.contains(optionName));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(ui->filterLineEdit, &QLineEdit::textChanged, this,
|
||||||
|
[this](const QString& s) {
|
||||||
|
static_cast<QSortFilterProxyModel*>(ui->colorThemeListView->model())->setFilterFixedString(s);
|
||||||
|
});
|
||||||
|
|
||||||
ui->colorThemeListView->setCurrentIndex(ui->colorThemeListView->model()->index(0, 0));
|
ui->colorThemeListView->setCurrentIndex(ui->colorThemeListView->model()->index(0, 0));
|
||||||
|
|
||||||
connect(ui->colorPicker, &ColorPicker::colorChanged, this, &ColorThemeEditDialog::colorOptionChanged);
|
connect(ui->colorPicker, &ColorPicker::colorChanged, this, &ColorThemeEditDialog::colorOptionChanged);
|
||||||
@ -67,7 +73,7 @@ ColorThemeEditDialog::~ColorThemeEditDialog()
|
|||||||
void ColorThemeEditDialog::accept()
|
void ColorThemeEditDialog::accept()
|
||||||
{
|
{
|
||||||
colorTheme = Config()->getColorTheme();
|
colorTheme = Config()->getColorTheme();
|
||||||
QJsonDocument sch = qobject_cast<ColorSettingsModel*>(ui->colorThemeListView->model())->getTheme();
|
QJsonDocument sch = ui->colorThemeListView->colorSettingsModel()->getTheme();
|
||||||
if (ThemeWorker().isCustomTheme(colorTheme)) {
|
if (ThemeWorker().isCustomTheme(colorTheme)) {
|
||||||
QString err = ThemeWorker().save(sch, colorTheme);
|
QString err = ThemeWorker().save(sch, colorTheme);
|
||||||
if (!err.isEmpty()) {
|
if (!err.isEmpty()) {
|
||||||
@ -115,7 +121,6 @@ void ColorThemeEditDialog::keyPressEvent(QKeyEvent *event)
|
|||||||
|
|
||||||
void ColorThemeEditDialog::colorOptionChanged(const QColor& newColor)
|
void ColorThemeEditDialog::colorOptionChanged(const QColor& newColor)
|
||||||
{
|
{
|
||||||
auto model = qobject_cast<ColorSettingsModel*>(ui->colorThemeListView->model());
|
|
||||||
QModelIndex currIndex = ui->colorThemeListView->currentIndex();
|
QModelIndex currIndex = ui->colorThemeListView->currentIndex();
|
||||||
|
|
||||||
if (!currIndex.isValid()) {
|
if (!currIndex.isValid()) {
|
||||||
@ -125,7 +130,7 @@ void ColorThemeEditDialog::colorOptionChanged(const QColor& newColor)
|
|||||||
ColorOption currOption = currIndex.data(Qt::UserRole).value<ColorOption>();
|
ColorOption currOption = currIndex.data(Qt::UserRole).value<ColorOption>();
|
||||||
currOption.color = newColor;
|
currOption.color = newColor;
|
||||||
currOption.changed = true;
|
currOption.changed = true;
|
||||||
model->setData(currIndex, QVariant::fromValue(currOption));
|
ui->colorThemeListView->model()->setData(currIndex, QVariant::fromValue(currOption));
|
||||||
|
|
||||||
Config()->setColor(currOption.optionName, currOption.color);
|
Config()->setColor(currOption.optionName, currOption.color);
|
||||||
if (!ColorThemeWorker::cutterSpecificOptions.contains(currOption.optionName)) {
|
if (!ColorThemeWorker::cutterSpecificOptions.contains(currOption.optionName)) {
|
||||||
@ -151,13 +156,13 @@ void ColorThemeEditDialog::editThemeChanged(const QString& newTheme)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
colorTheme = newTheme;
|
colorTheme = newTheme;
|
||||||
qobject_cast<ColorSettingsModel*>(ui->colorThemeListView->model())->updateTheme();
|
ui->colorThemeListView->colorSettingsModel()->updateTheme();
|
||||||
previewDisasmWidget->colorsUpdatedSlot();
|
previewDisasmWidget->colorsUpdatedSlot();
|
||||||
setWindowTitle(tr("Theme Editor - <%1>").arg(colorTheme));
|
setWindowTitle(tr("Theme Editor - <%1>").arg(colorTheme));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColorThemeEditDialog::themeWasEdited(const QString& theme) const
|
bool ColorThemeEditDialog::themeWasEdited(const QString& theme) const
|
||||||
{
|
{
|
||||||
auto model = qobject_cast<ColorSettingsModel*>(ui->colorThemeListView->model());
|
auto model = ui->colorThemeListView->colorSettingsModel();
|
||||||
return ThemeWorker().getTheme(theme) != model->getTheme();
|
return ThemeWorker().getTheme(theme) != model->getTheme();
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,15 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="filterLineEdit">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Search</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="ColorThemeListView" name="colorThemeListView" native="true">
|
<widget class="ColorThemeListView" name="colorThemeListView" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -63,6 +72,8 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="colorPickerAndPreviewLayout">
|
<layout class="QVBoxLayout" name="colorPickerAndPreviewLayout">
|
||||||
<item>
|
<item>
|
||||||
|
@ -10,12 +10,14 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "common/Configuration.h"
|
#include "common/Configuration.h"
|
||||||
#include "common/ColorThemeWorker.h"
|
#include "common/ColorThemeWorker.h"
|
||||||
|
|
||||||
#include "widgets/ColorThemeListView.h"
|
#include "widgets/ColorThemeListView.h"
|
||||||
|
|
||||||
|
constexpr int allFieldsRole = Qt::UserRole + 2;
|
||||||
|
|
||||||
struct OptionInfo {
|
struct OptionInfo {
|
||||||
QString info;
|
QString info;
|
||||||
@ -204,12 +206,19 @@ QPixmap ColorOptionDelegate::getPixmapFromSvg(const QString& fileName, const QCo
|
|||||||
ColorThemeListView::ColorThemeListView(QWidget *parent) :
|
ColorThemeListView::ColorThemeListView(QWidget *parent) :
|
||||||
QListView (parent)
|
QListView (parent)
|
||||||
{
|
{
|
||||||
setModel(new ColorSettingsModel(static_cast<QObject *>(this)));
|
QSortFilterProxyModel* proxy = new QSortFilterProxyModel(this);
|
||||||
static_cast<ColorSettingsModel *>(this->model())->updateTheme();
|
ColorSettingsModel* model = new ColorSettingsModel(this);
|
||||||
|
proxy->setSourceModel(model);
|
||||||
|
model->updateTheme();
|
||||||
|
setModel(proxy);
|
||||||
|
proxy->setFilterRole(allFieldsRole);
|
||||||
|
proxy->setFilterCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||||
|
proxy->setSortRole(Qt::DisplayRole);
|
||||||
|
proxy->setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||||
setItemDelegate(new ColorOptionDelegate(this));
|
setItemDelegate(new ColorOptionDelegate(this));
|
||||||
setResizeMode(ResizeMode::Adjust);
|
setResizeMode(ResizeMode::Adjust);
|
||||||
|
|
||||||
QJsonArray rgb = qobject_cast<ColorSettingsModel*>(model())->getTheme()
|
QJsonArray rgb = colorSettingsModel()->getTheme()
|
||||||
.object().find("gui.background").value().toArray();
|
.object().find("gui.background").value().toArray();
|
||||||
if (rgb.size() == 3) {
|
if (rgb.size() == 3) {
|
||||||
backgroundColor = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
backgroundColor = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
||||||
@ -253,13 +262,12 @@ void ColorThemeListView::dataChanged(const QModelIndex& topLeft, const QModelInd
|
|||||||
void ColorThemeListView::mouseReleaseEvent(QMouseEvent* e)
|
void ColorThemeListView::mouseReleaseEvent(QMouseEvent* e)
|
||||||
{
|
{
|
||||||
if (qobject_cast<ColorOptionDelegate*>(itemDelegate())->getResetButtonRect().contains(e->pos())) {
|
if (qobject_cast<ColorOptionDelegate*>(itemDelegate())->getResetButtonRect().contains(e->pos())) {
|
||||||
auto model = qobject_cast<ColorSettingsModel*>(this->model());
|
|
||||||
ColorOption co = currentIndex().data(Qt::UserRole).value<ColorOption>();
|
ColorOption co = currentIndex().data(Qt::UserRole).value<ColorOption>();
|
||||||
co.changed = false;
|
co.changed = false;
|
||||||
QJsonArray rgb = ThemeWorker().getTheme(
|
QJsonArray rgb = ThemeWorker().getTheme(
|
||||||
Config()->getColorTheme()).object()[co.optionName].toArray();
|
Config()->getColorTheme()).object()[co.optionName].toArray();
|
||||||
co.color = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
co.color = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
||||||
model->setData(currentIndex(), QVariant::fromValue(co));
|
model()->setData(currentIndex(), QVariant::fromValue(co));
|
||||||
QCursor c;
|
QCursor c;
|
||||||
c.setShape(Qt::CursorShape::ArrowCursor);
|
c.setShape(Qt::CursorShape::ArrowCursor);
|
||||||
setCursor(c);
|
setCursor(c);
|
||||||
@ -279,6 +287,11 @@ void ColorThemeListView::mouseMoveEvent(QMouseEvent* e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ColorSettingsModel* ColorThemeListView::colorSettingsModel() const
|
||||||
|
{
|
||||||
|
return static_cast<ColorSettingsModel *>(static_cast<QSortFilterProxyModel *>(model())->sourceModel());
|
||||||
|
}
|
||||||
|
|
||||||
void ColorThemeListView::blinkTimeout()
|
void ColorThemeListView::blinkTimeout()
|
||||||
{
|
{
|
||||||
static enum { Normal, Invisible } state = Normal;
|
static enum { Normal, Invisible } state = Normal;
|
||||||
@ -328,6 +341,14 @@ QVariant ColorSettingsModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant::fromValue(optionInfoMap__[theme.at(index.row()).optionName].info);
|
return QVariant::fromValue(optionInfoMap__[theme.at(index.row()).optionName].info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == allFieldsRole) {
|
||||||
|
const QString name = theme.at(index.row()).optionName;
|
||||||
|
return QVariant::fromValue(optionInfoMap__[name].displayingtext + " " +
|
||||||
|
optionInfoMap__[theme.at(index.row()).optionName].info + " " +
|
||||||
|
name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,6 +377,12 @@ void ColorSettingsModel::updateTheme()
|
|||||||
theme.push_back({it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt(), rgb[3].toInt()), false});
|
theme.push_back({it.key(), QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt(), rgb[3].toInt()), false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::sort(theme.begin(), theme.end(), [](const ColorOption& f, const ColorOption& s) {
|
||||||
|
QString s1 = optionInfoMap__[f.optionName].displayingtext;
|
||||||
|
QString s2 = optionInfoMap__[s.optionName].displayingtext;
|
||||||
|
int r = s1.compare(s2, Qt::CaseSensitivity::CaseInsensitive);
|
||||||
|
return r < 0;
|
||||||
|
});
|
||||||
if (!theme.isEmpty()) {
|
if (!theme.isEmpty()) {
|
||||||
dataChanged(index(0), index(theme.size() - 1));
|
dataChanged(index(0), index(theme.size() - 1));
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ struct ColorOption {
|
|||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(ColorOption);
|
Q_DECLARE_METATYPE(ColorOption);
|
||||||
|
|
||||||
|
class ColorSettingsModel;
|
||||||
|
|
||||||
class ColorThemeListView : public QListView
|
class ColorThemeListView : public QListView
|
||||||
{
|
{
|
||||||
@ -22,6 +23,8 @@ public:
|
|||||||
ColorThemeListView(QWidget *parent = nullptr);
|
ColorThemeListView(QWidget *parent = nullptr);
|
||||||
virtual ~ColorThemeListView() override {}
|
virtual ~ColorThemeListView() override {}
|
||||||
|
|
||||||
|
ColorSettingsModel* colorSettingsModel() const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void currentChanged(const QModelIndex ¤t,
|
void currentChanged(const QModelIndex ¤t,
|
||||||
const QModelIndex &previous) override;
|
const QModelIndex &previous) override;
|
||||||
@ -33,6 +36,7 @@ protected slots:
|
|||||||
|
|
||||||
void mouseMoveEvent(QMouseEvent *e) override;
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void blinkTimeout();
|
void blinkTimeout();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user