forked from qt-creator/qt-creator
QmlDesigner: Allow to assign custom colors to the timeline bar items
Cherry-picked from: ac0cf3ecacf84b87a6b654d6bbcbed6103458bd9 Note that there need to be changes to the auxiliary-data-mechanism in order to make persistence of these color settings reliable Change-Id: Id88e4e862ad00bef1c3830c0468691c5aa46ec67 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -69,6 +69,8 @@ const char C_CURVE_PICKER[] = "QmlDesigner.CurvePicker";
|
||||
const char C_ZOOM_IN[] = "QmlDesigner.ZoomIn";
|
||||
const char C_ZOOM_OUT[] = "QmlDesigner.ZoomOut";
|
||||
|
||||
const char C_BAR_ITEM_OVERRIDE[] = "Timeline.OverrideColor";
|
||||
|
||||
const int keyFrameSize = 17;
|
||||
const int keyFrameMargin = 2;
|
||||
} // namespace TimelineConstants
|
||||
|
@@ -44,6 +44,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QColorDialog>
|
||||
#include <QComboBox>
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QGraphicsScene>
|
||||
@@ -200,6 +201,11 @@ bool TimelineSectionItem::isSelected() const
|
||||
return m_targetNode.isValid() && m_targetNode.isSelected();
|
||||
}
|
||||
|
||||
ModelNode TimelineSectionItem::targetNode() const
|
||||
{
|
||||
return m_targetNode;
|
||||
}
|
||||
|
||||
QVector<qreal> TimelineSectionItem::keyframePositions() const
|
||||
{
|
||||
QVector<qreal> out;
|
||||
@@ -841,17 +847,24 @@ void TimelineBarItem::scrollOffsetChanged()
|
||||
sectionItem()->invalidateBar();
|
||||
}
|
||||
|
||||
void TimelineBarItem::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
void TimelineBarItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
const QColor brushColorSelected = Theme::getColor(Theme::QmlDesigner_HighlightColor);
|
||||
const QColor brushColor = Theme::getColor(Theme::QmlDesigner_HighlightColor).darker(120);
|
||||
QColor brushColorSelected = Theme::getColor(Theme::QmlDesigner_HighlightColor);
|
||||
QColor brushColor = Theme::getColor(Theme::QmlDesigner_HighlightColor).darker(120);
|
||||
const QColor indicatorColor = Theme::getColor(Theme::PanelTextColorLight);
|
||||
|
||||
ModelNode target = sectionItem()->targetNode();
|
||||
if (target.isValid()) {
|
||||
QColor overrideColor = target.auxiliaryData(TimelineConstants::C_BAR_ITEM_OVERRIDE).value<QColor>();
|
||||
if (overrideColor.isValid()) {
|
||||
brushColorSelected = overrideColor;
|
||||
brushColor = brushColorSelected.darker(120);
|
||||
}
|
||||
}
|
||||
|
||||
const QRectF itemRect = rect();
|
||||
|
||||
painter->save();
|
||||
@@ -902,6 +915,34 @@ void TimelineBarItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineBarItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
||||
{
|
||||
QMenu menu;
|
||||
QAction* overrideColor = menu.addAction(tr("Override Color"));
|
||||
|
||||
auto setColor = [this] () {
|
||||
ModelNode target = sectionItem()->targetNode();
|
||||
if (target.isValid()) {
|
||||
QColor current = target.auxiliaryData(TimelineConstants::C_BAR_ITEM_OVERRIDE).value<QColor>();
|
||||
QColor color = QColorDialog::getColor(current, nullptr);
|
||||
if (color.isValid())
|
||||
target.setAuxiliaryData(TimelineConstants::C_BAR_ITEM_OVERRIDE, color);
|
||||
}
|
||||
};
|
||||
|
||||
QObject::connect(overrideColor, &QAction::triggered, setColor);
|
||||
|
||||
QAction* resetColor = menu.addAction(tr("Reset Color"));
|
||||
auto reset = [this]() {
|
||||
ModelNode target = sectionItem()->targetNode();
|
||||
if (target.isValid())
|
||||
target.removeAuxiliaryData(TimelineConstants::C_BAR_ITEM_OVERRIDE);
|
||||
};
|
||||
QObject::connect(resetColor, &QAction::triggered, reset);
|
||||
|
||||
menu.exec(event->screenPos());
|
||||
}
|
||||
|
||||
TimelineSectionItem *TimelineBarItem::sectionItem() const
|
||||
{
|
||||
/* The parentItem is always a TimelineSectionItem. See constructor */
|
||||
|
@@ -54,7 +54,7 @@ protected:
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget = nullptr) override;
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
|
||||
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
|
||||
private:
|
||||
TimelineSectionItem *sectionItem() const;
|
||||
|
||||
@@ -105,6 +105,7 @@ public:
|
||||
AbstractView *view() const;
|
||||
bool isSelected() const;
|
||||
|
||||
ModelNode targetNode() const;
|
||||
QVector<qreal> keyframePositions() const;
|
||||
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user