mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 19:36:11 +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 <QKeyEvent>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@ -50,6 +51,11 @@ ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent) :
|
||||
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));
|
||||
|
||||
connect(ui->colorPicker, &ColorPicker::colorChanged, this, &ColorThemeEditDialog::colorOptionChanged);
|
||||
@ -67,7 +73,7 @@ ColorThemeEditDialog::~ColorThemeEditDialog()
|
||||
void ColorThemeEditDialog::accept()
|
||||
{
|
||||
colorTheme = Config()->getColorTheme();
|
||||
QJsonDocument sch = qobject_cast<ColorSettingsModel*>(ui->colorThemeListView->model())->getTheme();
|
||||
QJsonDocument sch = ui->colorThemeListView->colorSettingsModel()->getTheme();
|
||||
if (ThemeWorker().isCustomTheme(colorTheme)) {
|
||||
QString err = ThemeWorker().save(sch, colorTheme);
|
||||
if (!err.isEmpty()) {
|
||||
@ -115,7 +121,6 @@ void ColorThemeEditDialog::keyPressEvent(QKeyEvent *event)
|
||||
|
||||
void ColorThemeEditDialog::colorOptionChanged(const QColor& newColor)
|
||||
{
|
||||
auto model = qobject_cast<ColorSettingsModel*>(ui->colorThemeListView->model());
|
||||
QModelIndex currIndex = ui->colorThemeListView->currentIndex();
|
||||
|
||||
if (!currIndex.isValid()) {
|
||||
@ -125,7 +130,7 @@ void ColorThemeEditDialog::colorOptionChanged(const QColor& newColor)
|
||||
ColorOption currOption = currIndex.data(Qt::UserRole).value<ColorOption>();
|
||||
currOption.color = newColor;
|
||||
currOption.changed = true;
|
||||
model->setData(currIndex, QVariant::fromValue(currOption));
|
||||
ui->colorThemeListView->model()->setData(currIndex, QVariant::fromValue(currOption));
|
||||
|
||||
Config()->setColor(currOption.optionName, currOption.color);
|
||||
if (!ColorThemeWorker::cutterSpecificOptions.contains(currOption.optionName)) {
|
||||
@ -151,13 +156,13 @@ void ColorThemeEditDialog::editThemeChanged(const QString& newTheme)
|
||||
}
|
||||
}
|
||||
colorTheme = newTheme;
|
||||
qobject_cast<ColorSettingsModel*>(ui->colorThemeListView->model())->updateTheme();
|
||||
ui->colorThemeListView->colorSettingsModel()->updateTheme();
|
||||
previewDisasmWidget->colorsUpdatedSlot();
|
||||
setWindowTitle(tr("Theme Editor - <%1>").arg(colorTheme));
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -48,20 +48,31 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="ColorThemeListView" name="colorThemeListView" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="filterLineEdit">
|
||||
<property name="placeholderText">
|
||||
<string>Search</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ColorThemeListView" name="colorThemeListView" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="colorPickerAndPreviewLayout">
|
||||
|
@ -10,12 +10,14 @@
|
||||
#include <QApplication>
|
||||
#include <QSvgRenderer>
|
||||
#include <QMouseEvent>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "common/Configuration.h"
|
||||
#include "common/ColorThemeWorker.h"
|
||||
|
||||
#include "widgets/ColorThemeListView.h"
|
||||
|
||||
constexpr int allFieldsRole = Qt::UserRole + 2;
|
||||
|
||||
struct OptionInfo {
|
||||
QString info;
|
||||
@ -204,12 +206,19 @@ QPixmap ColorOptionDelegate::getPixmapFromSvg(const QString& fileName, const QCo
|
||||
ColorThemeListView::ColorThemeListView(QWidget *parent) :
|
||||
QListView (parent)
|
||||
{
|
||||
setModel(new ColorSettingsModel(static_cast<QObject *>(this)));
|
||||
static_cast<ColorSettingsModel *>(this->model())->updateTheme();
|
||||
QSortFilterProxyModel* proxy = new QSortFilterProxyModel(this);
|
||||
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));
|
||||
setResizeMode(ResizeMode::Adjust);
|
||||
|
||||
QJsonArray rgb = qobject_cast<ColorSettingsModel*>(model())->getTheme()
|
||||
QJsonArray rgb = colorSettingsModel()->getTheme()
|
||||
.object().find("gui.background").value().toArray();
|
||||
if (rgb.size() == 3) {
|
||||
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)
|
||||
{
|
||||
if (qobject_cast<ColorOptionDelegate*>(itemDelegate())->getResetButtonRect().contains(e->pos())) {
|
||||
auto model = qobject_cast<ColorSettingsModel*>(this->model());
|
||||
ColorOption co = currentIndex().data(Qt::UserRole).value<ColorOption>();
|
||||
co.changed = false;
|
||||
QJsonArray rgb = ThemeWorker().getTheme(
|
||||
Config()->getColorTheme()).object()[co.optionName].toArray();
|
||||
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;
|
||||
c.setShape(Qt::CursorShape::ArrowCursor);
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -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});
|
||||
}
|
||||
|
||||
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()) {
|
||||
dataChanged(index(0), index(theme.size() - 1));
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ struct ColorOption {
|
||||
};
|
||||
Q_DECLARE_METATYPE(ColorOption);
|
||||
|
||||
class ColorSettingsModel;
|
||||
|
||||
class ColorThemeListView : public QListView
|
||||
{
|
||||
@ -22,6 +23,8 @@ public:
|
||||
ColorThemeListView(QWidget *parent = nullptr);
|
||||
virtual ~ColorThemeListView() override {}
|
||||
|
||||
ColorSettingsModel* colorSettingsModel() const;
|
||||
|
||||
protected slots:
|
||||
void currentChanged(const QModelIndex ¤t,
|
||||
const QModelIndex &previous) override;
|
||||
@ -33,6 +36,7 @@ protected slots:
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
|
||||
|
||||
private slots:
|
||||
void blinkTimeout();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user