Improve color selection and display (#5057)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "util/LayoutHelper.hpp"
|
||||
#include "util/RapidJsonSerializeQString.hpp"
|
||||
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
||||
#include "widgets/helper/ColorButton.hpp"
|
||||
#include "widgets/helper/color/ColorButton.hpp"
|
||||
#include "widgets/helper/Line.hpp"
|
||||
|
||||
#include <QRegularExpression>
|
||||
@@ -214,20 +214,18 @@ ColorButton *GeneralPageView::addColorButton(
|
||||
|
||||
QObject::connect(
|
||||
colorButton, &ColorButton::clicked, [this, &setting, colorButton]() {
|
||||
auto dialog = new ColorPickerDialog(QColor(setting), this);
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->show();
|
||||
// We can safely ignore this signal connection, for now, since the
|
||||
auto *dialog = new ColorPickerDialog(QColor(setting), this);
|
||||
// colorButton & setting are never deleted and the signal is deleted
|
||||
// once the dialog is closed
|
||||
std::ignore = dialog->closed.connect(
|
||||
[&setting, colorButton](QColor selected) {
|
||||
if (selected.isValid())
|
||||
{
|
||||
setting = selected.name(QColor::HexArgb);
|
||||
colorButton->setColor(selected);
|
||||
}
|
||||
});
|
||||
QObject::connect(dialog, &ColorPickerDialog::colorConfirmed, this,
|
||||
[&setting, colorButton](auto selected) {
|
||||
if (selected.isValid())
|
||||
{
|
||||
setting = selected.name(QColor::HexArgb);
|
||||
colorButton->setColor(selected);
|
||||
}
|
||||
});
|
||||
dialog->show();
|
||||
});
|
||||
|
||||
this->groups_.back().widgets.push_back({label, {text}});
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "widgets/dialogs/BadgePickerDialog.hpp"
|
||||
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
||||
#include "widgets/helper/color/ColorItemDelegate.hpp"
|
||||
#include "widgets/helper/EditableModelView.hpp"
|
||||
|
||||
#include <QFileDialog>
|
||||
@@ -82,6 +83,8 @@ HighlightingPage::HighlightingPage()
|
||||
QHeaderView::Fixed);
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
0, QHeaderView::Stretch);
|
||||
view->getTableView()->setItemDelegateForColumn(
|
||||
HighlightModel::Column::Color, new ColorItemDelegate(view));
|
||||
|
||||
// fourtf: make class extrend BaseWidget and add this to
|
||||
// dpiChanged
|
||||
@@ -134,6 +137,9 @@ HighlightingPage::HighlightingPage()
|
||||
QHeaderView::Fixed);
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
0, QHeaderView::Stretch);
|
||||
view->getTableView()->setItemDelegateForColumn(
|
||||
UserHighlightModel::Column::Color,
|
||||
new ColorItemDelegate(view));
|
||||
|
||||
// fourtf: make class extrend BaseWidget and add this to
|
||||
// dpiChanged
|
||||
@@ -176,6 +182,9 @@ HighlightingPage::HighlightingPage()
|
||||
QHeaderView::Fixed);
|
||||
view->getTableView()->horizontalHeader()->setSectionResizeMode(
|
||||
0, QHeaderView::Stretch);
|
||||
view->getTableView()->setItemDelegateForColumn(
|
||||
BadgeHighlightModel::Column::Color,
|
||||
new ColorItemDelegate(view));
|
||||
|
||||
// fourtf: make class extrend BaseWidget and add this to
|
||||
// dpiChanged
|
||||
@@ -330,18 +339,18 @@ void HighlightingPage::openColorDialog(const QModelIndex &clicked,
|
||||
auto initial =
|
||||
view->getModel()->data(clicked, Qt::DecorationRole).value<QColor>();
|
||||
|
||||
auto dialog = new ColorPickerDialog(initial, this);
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->show();
|
||||
// We can safely ignore this signal connection since the view and tab are never deleted
|
||||
auto *dialog = new ColorPickerDialog(initial, this);
|
||||
// TODO: The QModelIndex clicked is technically not safe to persist here since the model
|
||||
// can be changed between the color dialog being created & the color dialog being closed
|
||||
std::ignore = dialog->closed.connect([=](auto selected) {
|
||||
if (selected.isValid())
|
||||
{
|
||||
view->getModel()->setData(clicked, selected, Qt::DecorationRole);
|
||||
}
|
||||
});
|
||||
QObject::connect(dialog, &ColorPickerDialog::colorConfirmed, this,
|
||||
[=](auto selected) {
|
||||
if (selected.isValid())
|
||||
{
|
||||
view->getModel()->setData(clicked, selected,
|
||||
Qt::DecorationRole);
|
||||
}
|
||||
});
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
void HighlightingPage::tableCellClicked(const QModelIndex &clicked,
|
||||
|
||||
Reference in New Issue
Block a user