Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
369bf4b8
Commit
369bf4b8
authored
Mar 16, 2016
by
Jean-Baptiste Mardelle
Browse files
Titler: allow gradients in rectangles
parent
c0bfde6f
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/effectstack/graphicsscenerectmove.cpp
View file @
369bf4b8
...
...
@@ -113,6 +113,20 @@ QRectF MyTextItem::boundingRect() const
return
base
;
}
MyRectItem
::
MyRectItem
(
QGraphicsItem
*
parent
)
:
QGraphicsRectItem
(
parent
)
{
}
void
MyRectItem
::
setRect
(
const
QRectF
&
rectangle
)
{
QGraphicsRectItem
::
setRect
(
rectangle
);
if
(
m_rect
!=
rectangle
&&
!
data
(
TitleDocument
::
Gradient
).
isNull
())
{
m_rect
=
rectangle
;
QLinearGradient
gr
=
GradientWidget
::
gradientFromString
(
data
(
TitleDocument
::
Gradient
).
toString
(),
m_rect
.
width
(),
m_rect
.
height
());
setBrush
(
QBrush
(
gr
));
}
}
GraphicsSceneRectMove
::
GraphicsSceneRectMove
(
QObject
*
parent
)
:
QGraphicsScene
(
parent
),
...
...
@@ -486,7 +500,7 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
break
;
}
if
(
m_selectedItem
->
type
()
==
QGraphicsRectItem
::
Type
&&
m_resizeMode
!=
NoResize
)
{
QGraphics
RectItem
*
gi
=
(
QGraphics
RectItem
*
)
m_selectedItem
;
My
RectItem
*
gi
=
(
My
RectItem
*
)
m_selectedItem
;
// Resize using aspect ratio
if
(
!
m_selectedItem
->
data
(
0
).
isNull
())
{
// we want to keep aspect ratio
...
...
@@ -574,10 +588,13 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
// create new rect item
QRectF
r
(
0
,
0
,
e
->
scenePos
().
x
()
-
m_sceneClickPoint
.
x
(),
e
->
scenePos
().
y
()
-
m_sceneClickPoint
.
y
());
r
=
r
.
normalized
();
m_selectedItem
=
addRect
(
QRectF
(
0
,
0
,
r
.
width
(),
r
.
height
()));
emit
newRect
((
QGraphicsRectItem
*
)
m_selectedItem
);
m_selectedItem
->
setFlags
(
QGraphicsItem
::
ItemIsMovable
|
QGraphicsItem
::
ItemIsSelectable
);
MyRectItem
*
rect
=
new
MyRectItem
();
rect
->
setRect
(
QRectF
(
0
,
0
,
r
.
width
(),
r
.
height
()));
addItem
(
rect
);
m_selectedItem
=
rect
;
m_selectedItem
->
setPos
(
m_sceneClickPoint
);
emit
newRect
(
rect
);
m_selectedItem
->
setFlags
(
QGraphicsItem
::
ItemIsMovable
|
QGraphicsItem
::
ItemIsSelectable
);
m_resizeMode
=
BottomRight
;
QGraphicsScene
::
mouseMoveEvent
(
e
);
}
...
...
src/effectstack/graphicsscenerectmove.h
View file @
369bf4b8
...
...
@@ -44,6 +44,15 @@ public slots:
void
updateGeometry
();
};
class
MyRectItem
:
public
QGraphicsRectItem
{
public:
MyRectItem
(
QGraphicsItem
*
parent
=
0
);
void
setRect
(
const
QRectF
&
rectangle
);
private:
QRectF
m_rect
;
};
class
GraphicsSceneRectMove
:
public
QGraphicsScene
{
Q_OBJECT
...
...
src/titler/gradientwidget.cpp
View file @
369bf4b8
...
...
@@ -70,6 +70,10 @@ QLinearGradient GradientWidget::gradientFromString(const QString &str, int width
{
QStringList
values
=
str
.
split
(
";"
);
QLinearGradient
gr
;
if
(
values
.
count
()
<
5
)
{
// invalid gradient data
return
gr
;
}
gr
.
setColorAt
(
values
.
at
(
2
).
toDouble
()
/
100
,
values
.
at
(
0
));
gr
.
setColorAt
(
values
.
at
(
3
).
toDouble
()
/
100
,
values
.
at
(
1
));
double
angle
=
values
.
at
(
4
).
toDouble
();
...
...
src/titler/titlewidget.cpp
View file @
369bf4b8
...
...
@@ -164,6 +164,9 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
connect
(
rectFColor
,
SIGNAL
(
changed
(
QColor
)),
this
,
SLOT
(
rectChanged
()));
connect
(
rectBColor
,
SIGNAL
(
changed
(
QColor
)),
this
,
SLOT
(
rectChanged
()));
connect
(
plain_rect
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
rectChanged
()));
connect
(
gradient_rect
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
rectChanged
()));
connect
(
gradients_rect_combo
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
rectChanged
()));
connect
(
rectLineWidth
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
rectChanged
()));
// Fill effects
...
...
@@ -870,8 +873,16 @@ void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
penf
.
setWidth
(
rectLineWidth
->
value
());
penf
.
setJoinStyle
(
Qt
::
RoundJoin
);
rect
->
setPen
(
penf
);
QColor
b
=
rectBColor
->
color
();
rect
->
setBrush
(
QBrush
(
b
));
if
(
plain_rect
->
isChecked
())
{
rect
->
setBrush
(
QBrush
(
rectBColor
->
color
()));
rect
->
setData
(
TitleDocument
::
Gradient
,
QVariant
());
}
else
{
// gradient
QString
gradientData
=
gradients_rect_combo
->
currentData
().
toString
();
rect
->
setData
(
TitleDocument
::
Gradient
,
gradientData
);
QLinearGradient
gr
=
GradientWidget
::
gradientFromString
(
gradientData
,
rect
->
boundingRect
().
width
(),
rect
->
boundingRect
().
height
());
rect
->
setBrush
(
QBrush
(
gr
));
}
rect
->
setZValue
(
m_count
++
);
rect
->
setData
(
TitleDocument
::
ZoomFactor
,
100
);
prepareTools
(
rect
);
...
...
@@ -1601,8 +1612,16 @@ void TitleWidget::rectChanged()
penf
.
setWidth
(
rectLineWidth
->
value
());
penf
.
setJoinStyle
(
Qt
::
RoundJoin
);
rec
->
setPen
(
penf
);
QColor
b
=
rectBColor
->
color
();
rec
->
setBrush
(
QBrush
(
b
));
if
(
plain_rect
->
isChecked
())
{
rec
->
setBrush
(
QBrush
(
rectBColor
->
color
()));
rec
->
setData
(
TitleDocument
::
Gradient
,
QVariant
());
}
else
{
// gradient
QString
gradientData
=
gradients_rect_combo
->
currentData
().
toString
();
rec
->
setData
(
TitleDocument
::
Gradient
,
gradientData
);
QLinearGradient
gr
=
GradientWidget
::
gradientFromString
(
gradientData
,
rec
->
boundingRect
().
width
(),
rec
->
boundingRect
().
height
());
rec
->
setBrush
(
QBrush
(
gr
));
}
}
}
}
...
...
@@ -2624,7 +2643,21 @@ void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
QColor
fcol
=
rec
->
pen
().
color
();
QColor
bcol
=
rec
->
brush
().
color
();
rectFColor
->
setColor
(
fcol
);
rectBColor
->
setColor
(
bcol
);
QString
gradientData
=
rec
->
data
(
TitleDocument
::
Gradient
).
toString
();
if
(
gradientData
.
isEmpty
())
{
plain_rect
->
setChecked
(
true
);
rectBColor
->
setColor
(
bcol
);
}
else
{
gradient_rect
->
setChecked
(
true
);
gradients_rect_combo
->
blockSignals
(
true
);
int
ix
=
gradients_rect_combo
->
findData
(
gradientData
);
if
(
ix
==
-
1
)
{
storeGradient
(
gradientData
);
ix
=
gradients_rect_combo
->
findData
(
gradientData
);
}
gradients_rect_combo
->
setCurrentIndex
(
ix
);
gradients_rect_combo
->
blockSignals
(
false
);
}
settingUp
=
false
;
rectLineWidth
->
setValue
(
rec
->
pen
().
width
());
enableToolbars
(
TITLE_RECTANGLE
);
...
...
@@ -2714,14 +2747,18 @@ void TitleWidget::storeGradient(const QString &gradientData)
painter
.
end
();
QIcon
icon
(
pix
);
gradients_combo
->
addItem
(
icon
,
gradName
,
gradientData
);
gradients_rect_combo
->
addItem
(
icon
,
gradName
,
gradientData
);
}
void
TitleWidget
::
loadGradients
()
{
QMap
<
QString
,
QString
>
gradients
;
gradients_combo
->
blockSignals
(
true
);
gradients_rect_combo
->
blockSignals
(
true
);
QString
data
=
gradients_combo
->
currentData
().
toString
();
QString
rect_data
=
gradients_rect_combo
->
currentData
().
toString
();
gradients_combo
->
clear
();
gradients_rect_combo
->
clear
();
KSharedConfigPtr
config
=
KSharedConfig
::
openConfig
();
KConfigGroup
group
(
config
,
"TitleGradients"
);
QMap
<
QString
,
QString
>
values
=
group
.
entryMap
();
...
...
@@ -2737,12 +2774,18 @@ void TitleWidget::loadGradients()
painter
.
end
();
QIcon
icon
(
pix
);
gradients_combo
->
addItem
(
icon
,
k
.
key
(),
k
.
value
());
gradients_rect_combo
->
addItem
(
icon
,
k
.
key
(),
k
.
value
());
}
int
ix
=
gradients_combo
->
findData
(
data
);
if
(
ix
>=
0
)
{
gradients_combo
->
setCurrentIndex
(
ix
);
}
ix
=
gradients_rect_combo
->
findData
(
rect_data
);
if
(
ix
>=
0
)
{
gradients_rect_combo
->
setCurrentIndex
(
ix
);
}
gradients_combo
->
blockSignals
(
false
);
gradients_rect_combo
->
blockSignals
(
false
);
}
src/ui/titlewidget_ui.ui
View file @
369bf4b8
...
...
@@ -728,30 +728,25 @@
</layout>
</widget>
<widget
class=
"QWidget"
name=
"rectangle"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_
1
2"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_2"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"Q
Label
"
name=
"la
bel_2
"
>
<widget
class=
"Q
RadioButton
"
name=
"
p
la
in_rect
"
>
<property
name=
"text"
>
<string>
Color
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_11"
>
<property
name=
"text"
>
<string>
Border
</string>
<string>
P
&
lain Color
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"1"
>
<widget
class=
"QSpinBox"
name=
"rectLineWidth"
>
<property
name=
"maximum"
>
<number>
5000
</number>
<property
name=
"checked"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"KColorButton"
name=
"rectBColor"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Minimum"
vsizetype=
"Preferred"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"color"
>
<color>
<red>
0
</red>
...
...
@@ -768,14 +763,48 @@
</property>
</widget>
</item>
<item
row=
"
2
"
column=
"0"
>
<widget
class=
"Q
Label"
name=
"label_4
"
>
<item
row=
"
1
"
column=
"0"
>
<widget
class=
"Q
RadioButton"
name=
"gradient_rect
"
>
<property
name=
"text"
>
<string>
Border Width
</string>
<string>
&
Gradient
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"gradients_rect_combo"
>
<property
name=
"enabled"
>
<bool>
false
</bool>
</property>
</widget>
</item>
<item
row=
"1"
column=
"2"
>
<widget
class=
"QToolButton"
name=
"edit_gradient_2"
>
<property
name=
"text"
>
<string>
...
</string>
</property>
</widget>
</item>
<item
row=
"1"
column=
"3"
>
<spacer
name=
"horizontalSpacer_5"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item
row=
"2"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_11"
>
<property
name=
"text"
>
<string>
Border
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"1"
>
<widget
class=
"KColorButton"
name=
"rectFColor"
>
<property
name=
"color"
>
<color>
...
...
@@ -794,6 +823,20 @@
</widget>
</item>
<item
row=
"3"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_4"
>
<property
name=
"text"
>
<string>
Border Width
</string>
</property>
</widget>
</item>
<item
row=
"3"
column=
"1"
>
<widget
class=
"QSpinBox"
name=
"rectLineWidth"
>
<property
name=
"maximum"
>
<number>
5000
</number>
</property>
</widget>
</item>
<item
row=
"4"
column=
"0"
>
<spacer
name=
"verticalSpacer_5"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
...
...
@@ -806,19 +849,6 @@
</property>
</spacer>
</item>
<item
row=
"1"
column=
"2"
>
<spacer
name=
"horizontalSpacer_5"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget
class=
"QWidget"
name=
"Image"
>
...
...
@@ -1292,5 +1322,37 @@
</hint>
</hints>
</connection>
<connection>
<sender>
plain_rect
</sender>
<signal>
toggled(bool)
</signal>
<receiver>
rectBColor
</receiver>
<slot>
setEnabled(bool)
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
523
</x>
<y>
424
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
674
</x>
<y>
431
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
gradient_rect
</sender>
<signal>
toggled(bool)
</signal>
<receiver>
gradients_rect_combo
</receiver>
<slot>
setEnabled(bool)
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
523
</x>
<y>
464
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
672
</x>
<y>
464
</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment