Apply new theming colors to the curveeditor

Change-Id: Ia919bfda4db1205b9c30ece247d2e3d49a6362ed
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Knud Dollereder
2021-03-15 15:31:52 +01:00
parent 2bcc33e010
commit d41d59774a
4 changed files with 55 additions and 22 deletions

View File

@@ -63,9 +63,9 @@ CurveEditorStyle CurveEditorModel::style() const
{ {
// Pseudo auto generated. See: CurveEditorStyleDialog // Pseudo auto generated. See: CurveEditorStyleDialog
CurveEditorStyle out; CurveEditorStyle out;
out.backgroundBrush = QBrush(QColor(21, 21, 21)); out.backgroundBrush = QmlDesigner::Theme::getColor(QmlDesigner::Theme::DSsectionHeadBackground);
out.backgroundAlternateBrush = QBrush(QColor(32, 32, 32)); out.backgroundAlternateBrush = QmlDesigner::Theme::getColor(QmlDesigner::Theme::DSpanelBackground);
out.fontColor = QColor(255, 255, 255); out.fontColor = QmlDesigner::Theme::getColor(QmlDesigner::Theme::DStextColor);
out.gridColor = QColor(114, 116, 118); out.gridColor = QColor(114, 116, 118);
out.canvasMargin = 15; out.canvasMargin = 15;
out.zoomInWidth = 99; out.zoomInWidth = 99;

View File

@@ -31,6 +31,9 @@
#include "treeitem.h" #include "treeitem.h"
#include "utils.h" #include "utils.h"
#include <theme.h>
#include <utils/fileutils.h>
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
#include <QResizeEvent> #include <QResizeEvent>
@@ -84,6 +87,11 @@ GraphicsView::GraphicsView(CurveEditorModel *model, QWidget *parent)
applyZoom(m_zoomX, m_zoomY); applyZoom(m_zoomX, m_zoomY);
update(); update();
const QString css = Theme::replaceCssColors(QString::fromUtf8(
Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css"))));
horizontalScrollBar()->setStyleSheet(css);
verticalScrollBar()->setStyleSheet(css);
} }
GraphicsView::~GraphicsView() GraphicsView::~GraphicsView()

View File

@@ -55,11 +55,10 @@ constexpr int spacingg = 5;
const QColor background = Qt::white; const QColor background = Qt::white;
const QColor labelBackground = qRgb(0x70, 0x70, 0x70); PresetItemDelegate::PresetItemDelegate(const QColor& background)
const QColor canvasBackground = qRgb(0x46, 0x46, 0x46); : QStyledItemDelegate()
const QColor curveLine = qRgb(0xe6, 0xe7, 0xe8); , m_background(background)
{}
PresetItemDelegate::PresetItemDelegate() = default;
void PresetItemDelegate::paint(QPainter *painter, void PresetItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &opt, const QStyleOptionViewItem &opt,
@@ -80,10 +79,10 @@ void PresetItemDelegate::paint(QPainter *painter,
option.font.setPixelSize(Theme::instance()->smallFontPixelSize()); option.font.setPixelSize(Theme::instance()->smallFontPixelSize());
painter->save(); painter->save();
painter->fillRect(option.rect, canvasBackground); painter->fillRect(option.rect, m_background);
if (option.text.isEmpty()) if (option.text.isEmpty())
painter->fillRect(textRect, canvasBackground); painter->fillRect(textRect, m_background);
else else
painter->fillRect(textRect, Theme::instance()->qmlDesignerButtonColor()); painter->fillRect(textRect, Theme::instance()->qmlDesignerButtonColor());
@@ -118,23 +117,25 @@ QSize PresetItemDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModel
return size; return size;
} }
QIcon paintPreview() QIcon paintPreview(const QColor& background)
{ {
QPixmap pm(iconWidth, iconHeight); QPixmap pm(iconWidth, iconHeight);
pm.fill(canvasBackground); pm.fill(background);
return QIcon(pm); return QIcon(pm);
} }
QIcon paintPreview(const EasingCurve &curve) QIcon paintPreview(const EasingCurve &curve, const QColor& background, const QColor& curveColor)
{ {
const QColor curveLine = Theme::getColor(Theme::DStextColor);
QPixmap pm(iconWidth, iconHeight); QPixmap pm(iconWidth, iconHeight);
pm.fill(canvasBackground); pm.fill(background);
QPainter painter(&pm); QPainter painter(&pm);
painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::Antialiasing, true);
Canvas canvas(iconWidth, iconHeight, 2, 2, 9, 6, 0, 1); Canvas canvas(iconWidth, iconHeight, 2, 2, 9, 6, 0, 1);
canvas.paintCurve(&painter, curve, curveLine); canvas.paintCurve(&painter, curve, curveColor);
return QIcon(pm); return QIcon(pm);
} }
@@ -159,6 +160,8 @@ PresetList::PresetList(QSettings::Scope scope, QWidget *parent)
, m_scope(scope) , m_scope(scope)
, m_index(-1) , m_index(-1)
, m_filename(Internal::settingsFullFilePath(scope)) , m_filename(Internal::settingsFullFilePath(scope))
, m_background(Theme::getColor(Theme::DSsectionHeadBackground ))
, m_curveColor(Theme::getColor(Theme::DStextColor))
{ {
int magic = 4; int magic = 4;
int scrollBarWidth = this->style()->pixelMetric(QStyle::PM_ScrollBarExtent); int scrollBarWidth = this->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
@@ -168,7 +171,7 @@ PresetList::PresetList(QSettings::Scope scope, QWidget *parent)
setModel(new QStandardItemModel); setModel(new QStandardItemModel);
setItemDelegate(new PresetItemDelegate); setItemDelegate(new PresetItemDelegate(m_background));
setSpacing(spacingg); setSpacing(spacingg);
@@ -260,6 +263,16 @@ bool PresetList::isEditable(const QModelIndex &index) const
return flags.testFlag(Qt::ItemIsEditable); return flags.testFlag(Qt::ItemIsEditable);
} }
QColor PresetList::backgroundColor() const
{
return m_background;
}
QColor PresetList::curveColor() const
{
return m_curveColor;
}
void PresetList::initialize(int index) void PresetList::initialize(int index)
{ {
m_index = index; m_index = index;
@@ -278,7 +291,7 @@ void PresetList::readPresets()
for (int i = 0; i < curves.size(); ++i) { for (int i = 0; i < curves.size(); ++i) {
QVariant curveData = QVariant::fromValue(curves[i].curve()); QVariant curveData = QVariant::fromValue(curves[i].curve());
auto *item = new QStandardItem(paintPreview(curves[i].curve()), curves[i].name()); auto *item = new QStandardItem(paintPreview(curves[i].curve(), m_background, m_curveColor), curves[i].name());
item->setData(curveData, ItemRole_Data); item->setData(curveData, ItemRole_Data);
item->setEditable(m_scope == QSettings::UserScope); item->setEditable(m_scope == QSettings::UserScope);
item->setToolTip(curves[i].name()); item->setToolTip(curves[i].name());
@@ -320,7 +333,7 @@ void PresetList::revert(const QModelIndex &index)
for (const auto &curve : curves) { for (const auto &curve : curves) {
if (curve.name() == name) { if (curve.name() == name) {
item->setData(false, ItemRole_Dirty); item->setData(false, ItemRole_Dirty);
item->setData(paintPreview(curve.curve()), Qt::DecorationRole); item->setData(paintPreview(curve.curve(), m_background, m_curveColor), Qt::DecorationRole);
item->setData(QVariant::fromValue(curve.curve()), ItemRole_Data); item->setData(QVariant::fromValue(curve.curve()), ItemRole_Data);
item->setToolTip(name); item->setToolTip(name);
return; return;
@@ -334,7 +347,7 @@ void PresetList::updateCurve(const EasingCurve &curve)
if (!selectionModel()->hasSelection()) if (!selectionModel()->hasSelection())
return; return;
QVariant icon = QVariant::fromValue(paintPreview(curve)); QVariant icon = QVariant::fromValue(paintPreview(curve, m_background, m_curveColor));
QVariant curveData = QVariant::fromValue(curve); QVariant curveData = QVariant::fromValue(curve);
for (const auto &index : selectionModel()->selectedIndexes()) for (const auto &index : selectionModel()->selectedIndexes())
@@ -382,7 +395,7 @@ void PresetList::createItem()
void PresetList::createItem(const QString &name, const EasingCurve &curve) void PresetList::createItem(const QString &name, const EasingCurve &curve)
{ {
auto *item = new QStandardItem(paintPreview(curve), name); auto *item = new QStandardItem(paintPreview(curve, m_background, m_curveColor), name);
item->setData(QVariant::fromValue(curve), ItemRole_Data); item->setData(QVariant::fromValue(curve), ItemRole_Data);
item->setToolTip(name); item->setToolTip(name);
@@ -507,7 +520,8 @@ void PresetEditor::update(const EasingCurve &curve)
m_presets->selectionModel()->clear(); m_presets->selectionModel()->clear();
else { else {
if (m_customs->selectionModel()->hasSelection()) { if (m_customs->selectionModel()->hasSelection()) {
QVariant icon = QVariant::fromValue(paintPreview(curve)); QVariant icon = QVariant::fromValue(
paintPreview(curve, m_presets->backgroundColor(), m_presets->curveColor()));
QVariant curveData = QVariant::fromValue(curve); QVariant curveData = QVariant::fromValue(curve);
for (const QModelIndex &index : m_customs->selectionModel()->selectedIndexes()) for (const QModelIndex &index : m_customs->selectionModel()->selectedIndexes())
m_customs->setItemData(index, curveData, icon); m_customs->setItemData(index, curveData, icon);

View File

@@ -43,13 +43,16 @@ class PresetItemDelegate : public QStyledItemDelegate
Q_OBJECT Q_OBJECT
public: public:
PresetItemDelegate(); PresetItemDelegate(const QColor& background);
void paint(QPainter *painter, void paint(QPainter *painter,
const QStyleOptionViewItem &opt, const QStyleOptionViewItem &opt,
const QModelIndex &index) const override; const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private:
QColor m_background;
}; };
class PresetList : public QListView class PresetList : public QListView
@@ -80,6 +83,10 @@ public:
bool isEditable(const QModelIndex &index) const; bool isEditable(const QModelIndex &index) const;
QColor backgroundColor() const;
QColor curveColor() const;
void initialize(int index); void initialize(int index);
void readPresets(); void readPresets();
@@ -118,6 +125,10 @@ private:
int m_index; int m_index;
QString m_filename; QString m_filename;
QColor m_background;
QColor m_curveColor;
}; };
class PresetEditor : public QStackedWidget class PresetEditor : public QStackedWidget