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_IN[] = "QmlDesigner.ZoomIn";
|
||||||
const char C_ZOOM_OUT[] = "QmlDesigner.ZoomOut";
|
const char C_ZOOM_OUT[] = "QmlDesigner.ZoomOut";
|
||||||
|
|
||||||
|
const char C_BAR_ITEM_OVERRIDE[] = "Timeline.OverrideColor";
|
||||||
|
|
||||||
const int keyFrameSize = 17;
|
const int keyFrameSize = 17;
|
||||||
const int keyFrameMargin = 2;
|
const int keyFrameMargin = 2;
|
||||||
} // namespace TimelineConstants
|
} // namespace TimelineConstants
|
||||||
|
@@ -44,6 +44,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QColorDialog>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
@@ -200,6 +201,11 @@ bool TimelineSectionItem::isSelected() const
|
|||||||
return m_targetNode.isValid() && m_targetNode.isSelected();
|
return m_targetNode.isValid() && m_targetNode.isSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModelNode TimelineSectionItem::targetNode() const
|
||||||
|
{
|
||||||
|
return m_targetNode;
|
||||||
|
}
|
||||||
|
|
||||||
QVector<qreal> TimelineSectionItem::keyframePositions() const
|
QVector<qreal> TimelineSectionItem::keyframePositions() const
|
||||||
{
|
{
|
||||||
QVector<qreal> out;
|
QVector<qreal> out;
|
||||||
@@ -841,17 +847,24 @@ void TimelineBarItem::scrollOffsetChanged()
|
|||||||
sectionItem()->invalidateBar();
|
sectionItem()->invalidateBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineBarItem::paint(QPainter *painter,
|
void TimelineBarItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
const QStyleOptionGraphicsItem *option,
|
|
||||||
QWidget *widget)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(widget);
|
Q_UNUSED(widget);
|
||||||
|
|
||||||
const QColor brushColorSelected = Theme::getColor(Theme::QmlDesigner_HighlightColor);
|
QColor brushColorSelected = Theme::getColor(Theme::QmlDesigner_HighlightColor);
|
||||||
const QColor brushColor = Theme::getColor(Theme::QmlDesigner_HighlightColor).darker(120);
|
QColor brushColor = Theme::getColor(Theme::QmlDesigner_HighlightColor).darker(120);
|
||||||
const QColor indicatorColor = Theme::getColor(Theme::PanelTextColorLight);
|
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();
|
const QRectF itemRect = rect();
|
||||||
|
|
||||||
painter->save();
|
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
|
TimelineSectionItem *TimelineBarItem::sectionItem() const
|
||||||
{
|
{
|
||||||
/* The parentItem is always a TimelineSectionItem. See constructor */
|
/* The parentItem is always a TimelineSectionItem. See constructor */
|
||||||
|
@@ -54,7 +54,7 @@ protected:
|
|||||||
const QStyleOptionGraphicsItem *option,
|
const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget = nullptr) override;
|
QWidget *widget = nullptr) override;
|
||||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
|
||||||
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
|
||||||
private:
|
private:
|
||||||
TimelineSectionItem *sectionItem() const;
|
TimelineSectionItem *sectionItem() const;
|
||||||
|
|
||||||
@@ -105,6 +105,7 @@ public:
|
|||||||
AbstractView *view() const;
|
AbstractView *view() const;
|
||||||
bool isSelected() const;
|
bool isSelected() const;
|
||||||
|
|
||||||
|
ModelNode targetNode() const;
|
||||||
QVector<qreal> keyframePositions() const;
|
QVector<qreal> keyframePositions() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Reference in New Issue
Block a user