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
c0bfde6f
Commit
c0bfde6f
authored
Mar 16, 2016
by
Jean-Baptiste Mardelle
Browse files
Add support for gradient fill in titler
(MLT patch coming soon)
parent
976744d2
Changes
11
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
c0bfde6f
...
...
@@ -203,6 +203,7 @@ ki18n_wrap_ui(kdenlive_UIS
ui/fontval_ui.ui
ui/cutjobdialog_ui.ui
ui/scenecutdialog_ui.ui
ui/gradientedit_ui.ui
)
if
(
BUILD_JogShuttle
)
...
...
src/effectstack/graphicsscenerectmove.cpp
View file @
c0bfde6f
...
...
@@ -19,6 +19,8 @@
***************************************************************************/
#include
"graphicsscenerectmove.h"
#include
"titler/titledocument.h"
#include
"titler/gradientwidget.h"
#include
<QDebug>
#include
<QGraphicsSceneMouseEvent>
...
...
@@ -65,6 +67,21 @@ void MyTextItem::setAlignment(Qt::Alignment alignment)
void
MyTextItem
::
updateGeometry
(
int
,
int
,
int
)
{
updateGeometry
();
// update gradient if necessary
QString
gradientData
=
data
(
TitleDocument
::
Gradient
).
toString
();
if
(
!
gradientData
.
isEmpty
())
{
QTextCursor
cursor
=
textCursor
();
QTextCharFormat
cformat
;
QRectF
rect
=
boundingRect
();
int
position
=
textCursor
().
position
();
QLinearGradient
gr
=
GradientWidget
::
gradientFromString
(
gradientData
,
rect
.
width
(),
rect
.
height
());
cursor
.
select
(
QTextCursor
::
Document
);
cformat
.
setForeground
(
QBrush
(
gr
));
cursor
.
mergeCharFormat
(
cformat
);
cursor
.
clearSelection
();
cursor
.
setPosition
(
position
);
// restore cursor position
setTextCursor
(
cursor
);
}
}
void
MyTextItem
::
updateGeometry
()
...
...
src/titler/CMakeLists.txt
View file @
c0bfde6f
...
...
@@ -3,6 +3,7 @@ set(kdenlive_SRCS
#titler/KoSliderCombo.cpp
titler/titledocument.cpp
titler/titlewidget.cpp
titler/gradientwidget.cpp
titler/unicodedialog.cpp
PARENT_SCOPE
)
src/titler/gradientwidget.cpp
0 → 100644
View file @
c0bfde6f
/*
Copyright (C) 2016 Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.kdenlive.org.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"gradientwidget.h"
#include
<QPainter>
#include
<QPixmap>
#include
<QtMath>
#include
<QLinearGradient>
#include
<KSharedConfig>
#include
<KConfigGroup>
#include
"utils/KoIconUtils.h"
GradientWidget
::
GradientWidget
(
QWidget
*
parent
)
:
QDialog
(
parent
),
Ui
::
GradientEdit_UI
()
{
setupUi
(
this
);
updatePreview
();
connect
(
color1_pos
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
updatePreview
()));
connect
(
color2_pos
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
updatePreview
()));
connect
(
angle
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
updatePreview
()));
connect
(
color1
,
SIGNAL
(
changed
(
const
QColor
&
)),
this
,
SLOT
(
updatePreview
()));
connect
(
color2
,
SIGNAL
(
changed
(
const
QColor
&
)),
this
,
SLOT
(
updatePreview
()));
add_gradient
->
setIcon
(
KoIconUtils
::
themedIcon
(
QStringLiteral
(
"list-add"
)));
remove_gradient
->
setIcon
(
KoIconUtils
::
themedIcon
(
QStringLiteral
(
"list-remove"
)));
connect
(
add_gradient
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
saveGradient
()));
connect
(
remove_gradient
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
deleteGradient
()));
QFontMetrics
metrics
(
font
());
m_height
=
metrics
.
lineSpacing
();
gradient_list
->
setIconSize
(
QSize
(
6
*
m_height
,
m_height
));
connect
(
gradient_list
,
SIGNAL
(
currentRowChanged
(
int
)),
this
,
SLOT
(
loadGradient
()));
loadGradients
();
}
void
GradientWidget
::
resizeEvent
(
QResizeEvent
*
event
)
{
QDialog
::
resizeEvent
(
event
);
updatePreview
();
}
QString
GradientWidget
::
gradientToString
()
const
{
QStringList
result
;
result
<<
color1
->
color
().
name
(
QColor
::
HexArgb
)
<<
color2
->
color
().
name
(
QColor
::
HexArgb
)
<<
QString
::
number
(
color1_pos
->
value
())
<<
QString
::
number
(
color2_pos
->
value
())
<<
QString
::
number
(
angle
->
value
());
return
result
.
join
(
";"
);
}
QLinearGradient
GradientWidget
::
gradientFromString
(
const
QString
&
str
,
int
width
,
int
height
)
{
QStringList
values
=
str
.
split
(
";"
);
QLinearGradient
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
();
if
(
angle
<=
90
)
{
gr
.
setStart
(
0
,
0
);
gr
.
setFinalStop
(
width
*
qCos
(
qDegreesToRadians
(
angle
)),
height
*
qSin
(
qDegreesToRadians
(
angle
)));
}
else
{
gr
.
setStart
(
width
,
0
);
gr
.
setFinalStop
(
width
+
width
*
qCos
(
qDegreesToRadians
(
angle
)),
height
*
qSin
(
qDegreesToRadians
(
angle
)));
}
return
gr
;
}
void
GradientWidget
::
updatePreview
()
{
QPixmap
p
(
preview
->
width
(),
preview
->
height
());
m_gradient
=
QLinearGradient
();
m_gradient
.
setColorAt
(
color1_pos
->
value
()
/
100.0
,
color1
->
color
());
m_gradient
.
setColorAt
(
color2_pos
->
value
()
/
100.0
,
color2
->
color
());
double
ang
=
angle
->
value
();
if
(
ang
<=
90
)
{
m_gradient
.
setStart
(
0
,
0
);
m_gradient
.
setFinalStop
(
p
.
width
()
/
2
*
qCos
(
qDegreesToRadians
(
ang
)),
p
.
height
()
*
qSin
(
qDegreesToRadians
(
ang
)));
}
else
{
m_gradient
.
setStart
(
p
.
width
()
/
2
,
0
);
m_gradient
.
setFinalStop
(
p
.
width
()
/
2
+
(
p
.
width
()
/
2
)
*
qCos
(
qDegreesToRadians
(
ang
)),
p
.
height
()
*
qSin
(
qDegreesToRadians
(
ang
)));
}
//qDebug()<<"* * * ANGLE: "<<angle->value()<<" = "<<p.height() * tan(angle->value() * 3.1415926 / 180.0);
QLinearGradient
copy
=
m_gradient
;
QPointF
gradStart
=
m_gradient
.
start
()
+
QPointF
(
p
.
width
()
/
2
,
0
);
QPointF
gradStop
=
m_gradient
.
finalStop
()
+
QPointF
(
p
.
width
()
/
2
,
0
);
copy
.
setStart
(
gradStart
);
copy
.
setFinalStop
(
gradStop
);
QBrush
br
(
m_gradient
);
QBrush
br2
(
copy
);
p
.
fill
(
Qt
::
transparent
);
QPainter
painter
(
&
p
);
painter
.
fillRect
(
0
,
0
,
p
.
width
()
/
2
,
p
.
height
(),
br
);
QPainterPath
path
;
QFont
f
=
font
();
f
.
setPixelSize
(
p
.
height
());
int
margin
=
p
.
height
()
/
8
;
path
.
addText
(
p
.
width
()
/
2
+
2
*
margin
,
p
.
height
()
-
margin
,
f
,
QStringLiteral
(
"Ax"
));
painter
.
fillPath
(
path
,
br2
);
painter
.
end
();
preview
->
setPixmap
(
p
);
}
void
GradientWidget
::
saveGradient
()
{
QPixmap
pix
(
6
*
m_height
,
m_height
);
pix
.
fill
(
Qt
::
transparent
);
m_gradient
.
setStart
(
0
,
pix
.
height
()
/
2
);
m_gradient
.
setFinalStop
(
pix
.
width
(),
pix
.
height
()
/
2
);
QPainter
painter
(
&
pix
);
painter
.
fillRect
(
0
,
0
,
pix
.
width
(),
pix
.
height
(),
QBrush
(
m_gradient
));
painter
.
end
();
QIcon
icon
(
pix
);
int
ct
=
gradient_list
->
count
();
QStringList
existing
=
getNames
();
QString
test
=
i18n
(
"Gradient %1"
,
ct
);
while
(
existing
.
contains
(
test
))
{
ct
++
;
test
=
i18n
(
"Gradient %1"
,
ct
);
}
QListWidgetItem
*
item
=
new
QListWidgetItem
(
icon
,
test
,
gradient_list
);
item
->
setData
(
Qt
::
UserRole
,
gradientToString
());
item
->
setFlags
(
Qt
::
ItemIsEditable
|
Qt
::
ItemIsSelectable
|
Qt
::
ItemIsEnabled
);
}
QStringList
GradientWidget
::
getNames
()
const
{
QStringList
result
;
for
(
int
i
=
0
;
i
<
gradient_list
->
count
();
i
++
)
{
result
<<
gradient_list
->
item
(
i
)
->
text
();
}
return
result
;
}
void
GradientWidget
::
deleteGradient
()
{
QListWidgetItem
*
item
=
gradient_list
->
currentItem
();
if
(
!
item
)
return
;
delete
item
;
}
void
GradientWidget
::
loadGradient
()
{
QListWidgetItem
*
item
=
gradient_list
->
currentItem
();
if
(
!
item
)
return
;
QString
data
=
item
->
data
(
Qt
::
UserRole
).
toString
();
QStringList
res
=
data
.
split
(
';'
);
color1
->
setColor
(
QColor
(
res
.
at
(
0
)));
color2
->
setColor
(
QColor
(
res
.
at
(
1
)));
color1_pos
->
setValue
(
res
.
at
(
2
).
toInt
());
color2_pos
->
setValue
(
res
.
at
(
3
).
toInt
());
angle
->
setValue
(
res
.
at
(
4
).
toInt
());
}
QMap
<
QString
,
QString
>
GradientWidget
::
gradients
()
const
{
QMap
<
QString
,
QString
>
gradients
;
for
(
int
i
=
0
;
i
<
gradient_list
->
count
();
i
++
)
{
gradients
.
insert
(
gradient_list
->
item
(
i
)
->
text
(),
gradient_list
->
item
(
i
)
->
data
(
Qt
::
UserRole
).
toString
());
}
return
gradients
;
}
QList
<
QIcon
>
GradientWidget
::
icons
()
const
{
QList
<
QIcon
>
icons
;
for
(
int
i
=
0
;
i
<
gradient_list
->
count
();
i
++
)
{
QPixmap
pix
=
gradient_list
->
item
(
i
)
->
icon
().
pixmap
(
6
*
m_height
,
m_height
);
QIcon
icon
(
pix
.
scaled
(
30
,
30
));
icons
<<
icon
;
}
return
icons
;
}
void
GradientWidget
::
loadGradients
()
{
QMap
<
QString
,
QString
>
gradients
;
gradient_list
->
clear
();
KSharedConfigPtr
config
=
KSharedConfig
::
openConfig
();
KConfigGroup
group
(
config
,
"TitleGradients"
);
QMap
<
QString
,
QString
>
values
=
group
.
entryMap
();
QMapIterator
<
QString
,
QString
>
k
(
values
);
while
(
k
.
hasNext
())
{
k
.
next
();
QPixmap
pix
(
6
*
m_height
,
m_height
);
pix
.
fill
(
Qt
::
transparent
);
QLinearGradient
gr
=
gradientFromString
(
k
.
value
(),
pix
.
width
(),
pix
.
height
());
gr
.
setStart
(
0
,
pix
.
height
()
/
2
);
gr
.
setFinalStop
(
pix
.
width
(),
pix
.
height
()
/
2
);
QPainter
painter
(
&
pix
);
painter
.
fillRect
(
0
,
0
,
pix
.
width
(),
pix
.
height
(),
QBrush
(
gr
));
painter
.
end
();
QIcon
icon
(
pix
);
QListWidgetItem
*
item
=
new
QListWidgetItem
(
icon
,
k
.
key
(),
gradient_list
);
item
->
setData
(
Qt
::
UserRole
,
k
.
value
());
item
->
setFlags
(
Qt
::
ItemIsEditable
|
Qt
::
ItemIsSelectable
|
Qt
::
ItemIsEnabled
);
}
}
src/titler/gradientwidget.h
0 → 100644
View file @
c0bfde6f
/*
Copyright (C) 2016 Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.kdenlive.org.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRADIENTWIDGET_H
#define GRADIENTWIDGET_H
#include
"ui_gradientedit_ui.h"
#include
<QDialog>
/*! \class GradientWidget
\brief Title creation dialog
Instances of TitleWidget classes are instansiated by KdenliveDoc::slotCreateTextClip ()
*/
class
GradientWidget
:
public
QDialog
,
public
Ui
::
GradientEdit_UI
{
Q_OBJECT
public:
/** @brief Draws the dialog and loads a title document (if any).
* @param url title document to load
* @param tc timecode of the project
* @param projectPath default path to save to or load from title documents
* @param render project renderer
* @param parent (optional) parent widget */
explicit
GradientWidget
(
QWidget
*
parent
=
0
);
void
resizeEvent
(
QResizeEvent
*
event
);
QString
gradientToString
()
const
;
static
QLinearGradient
gradientFromString
(
const
QString
&
str
,
int
width
,
int
height
);
QMap
<
QString
,
QString
>
gradients
()
const
;
QList
<
QIcon
>
icons
()
const
;
private:
QLinearGradient
m_gradient
;
int
m_height
;
QStringList
getNames
()
const
;
void
loadGradients
();
private
slots
:
void
updatePreview
();
void
saveGradient
();
void
loadGradient
();
void
deleteGradient
();
};
#endif
src/titler/titledocument.cpp
View file @
c0bfde6f
...
...
@@ -16,6 +16,7 @@
***************************************************************************/
#include
"titledocument.h"
#include
"gradientwidget.h"
#include
"kdenlivesettings.h"
#include
"timecode.h"
...
...
@@ -146,6 +147,7 @@ QDomDocument TitleDocument::xml(QGraphicsRectItem* startv, QGraphicsRectItem* en
QDomElement
e
=
doc
.
createElement
(
QStringLiteral
(
"item"
));
QDomElement
content
=
doc
.
createElement
(
QStringLiteral
(
"content"
));
QFont
font
;
QString
gradient
;
MyTextItem
*
t
;
double
xPosition
=
item
->
pos
().
x
();
...
...
@@ -181,6 +183,10 @@ QDomDocument TitleDocument::xml(QGraphicsRectItem* startv, QGraphicsRectItem* en
content
.
setAttribute
(
QStringLiteral
(
"font-italic"
),
font
.
italic
());
content
.
setAttribute
(
QStringLiteral
(
"font-underline"
),
font
.
underline
());
content
.
setAttribute
(
QStringLiteral
(
"letter-spacing"
),
QString
::
number
(
font
.
letterSpacing
()));
gradient
=
item
->
data
(
TitleDocument
::
Gradient
).
toString
();
if
(
!
gradient
.
isEmpty
())
{
content
.
setAttribute
(
QStringLiteral
(
"gradient"
),
gradient
);
}
cur
=
QTextCursor
(
t
->
document
());
cur
.
select
(
QTextCursor
::
Document
);
format
=
cur
.
blockFormat
();
...
...
@@ -212,9 +218,9 @@ QDomDocument TitleDocument::xml(QGraphicsRectItem* startv, QGraphicsRectItem* en
cursor
.
select
(
QTextCursor
::
Document
);
QColor
fontcolor
=
cursor
.
charFormat
().
foreground
().
color
();
content
.
setAttribute
(
QStringLiteral
(
"font-color"
),
colorToString
(
fontcolor
));
if
(
!
t
->
data
(
101
).
isNull
())
content
.
setAttribute
(
QStringLiteral
(
"font-outline"
),
QString
::
number
(
t
->
data
(
101
).
toDouble
()));
if
(
!
t
->
data
(
102
).
isNull
())
{
QVariant
variant
=
t
->
data
(
102
);
if
(
!
t
->
data
(
TitleDocument
::
OutlineWidth
).
isNull
())
content
.
setAttribute
(
QStringLiteral
(
"font-outline"
),
QString
::
number
(
t
->
data
(
TitleDocument
::
OutlineWidth
).
toDouble
()));
if
(
!
t
->
data
(
TitleDocument
::
OutlineColor
).
isNull
())
{
QVariant
variant
=
t
->
data
(
TitleDocument
::
OutlineColor
);
QColor
outlineColor
=
variant
.
value
<
QColor
>
();
content
.
setAttribute
(
QStringLiteral
(
"font-outline-color"
),
colorToString
(
outlineColor
));
}
...
...
@@ -247,11 +253,11 @@ QDomDocument TitleDocument::xml(QGraphicsRectItem* startv, QGraphicsRectItem* en
pos
.
setAttribute
(
QStringLiteral
(
"y"
),
QString
::
number
(
item
->
pos
().
y
()));
QTransform
transform
=
item
->
transform
();
QDomElement
tr
=
doc
.
createElement
(
QStringLiteral
(
"transform"
));
if
(
!
item
->
data
(
ZOOMFACTOR
).
isNull
())
{
tr
.
setAttribute
(
QStringLiteral
(
"zoom"
),
QString
::
number
(
item
->
data
(
ZOOMFACTOR
).
toInt
()));
if
(
!
item
->
data
(
TitleDocument
::
ZoomFactor
).
isNull
())
{
tr
.
setAttribute
(
QStringLiteral
(
"zoom"
),
QString
::
number
(
item
->
data
(
TitleDocument
::
ZoomFactor
).
toInt
()));
}
if
(
!
item
->
data
(
ROTATEFACTOR
).
isNull
())
{
QList
<
QVariant
>
rotlist
=
item
->
data
(
ROTATEFACTOR
).
toList
();
if
(
!
item
->
data
(
TitleDocument
::
RotateFactor
).
isNull
())
{
QList
<
QVariant
>
rotlist
=
item
->
data
(
TitleDocument
::
RotateFactor
).
toList
();
tr
.
setAttribute
(
QStringLiteral
(
"rotation"
),
QStringLiteral
(
"%1,%2,%3"
).
arg
(
rotlist
[
0
].
toDouble
()).
arg
(
rotlist
[
1
].
toDouble
()).
arg
(
rotlist
[
2
].
toDouble
()));
}
tr
.
appendChild
(
doc
.
createTextNode
(
...
...
@@ -421,14 +427,15 @@ int TitleDocument::loadFromXml(const QDomDocument& doc, QGraphicsRectItem* start
QColor
col
(
stringToColor
(
txtProperties
.
namedItem
(
QStringLiteral
(
"font-color"
)).
nodeValue
()));
MyTextItem
*
txt
=
new
MyTextItem
(
items
.
item
(
i
).
namedItem
(
QStringLiteral
(
"content"
)).
firstChild
().
nodeValue
(),
NULL
);
txt
->
setFont
(
font
);
txt
->
setTextInteractionFlags
(
Qt
::
NoTextInteraction
);
m_scene
->
addItem
(
txt
);
QTextCursor
cursor
(
txt
->
document
());
cursor
.
select
(
QTextCursor
::
Document
);
QTextCharFormat
format
;
QTextCharFormat
c
format
=
cursor
.
charFormat
()
;
if
(
txtProperties
.
namedItem
(
QStringLiteral
(
"font-outline"
)).
nodeValue
().
toDouble
()
>
0.0
)
{
txt
->
setData
(
101
,
txtProperties
.
namedItem
(
QStringLiteral
(
"font-outline"
)).
nodeValue
().
toDouble
());
txt
->
setData
(
102
,
stringToColor
(
txtProperties
.
namedItem
(
QStringLiteral
(
"font-outline-color"
)).
nodeValue
()));
format
.
setTextOutline
(
txt
->
setData
(
TitleDocument
::
OutlineWidth
,
txtProperties
.
namedItem
(
QStringLiteral
(
"font-outline"
)).
nodeValue
().
toDouble
());
txt
->
setData
(
TitleDocument
::
OutlineColor
,
stringToColor
(
txtProperties
.
namedItem
(
QStringLiteral
(
"font-outline-color"
)).
nodeValue
()));
c
format
.
setTextOutline
(
QPen
(
QColor
(
stringToColor
(
txtProperties
.
namedItem
(
QStringLiteral
(
"font-outline-color"
)).
nodeValue
())),
txtProperties
.
namedItem
(
QStringLiteral
(
"font-outline"
)).
nodeValue
().
toDouble
(),
Qt
::
SolidLine
,
Qt
::
RoundCap
,
Qt
::
RoundJoin
)
...
...
@@ -440,9 +447,17 @@ int TitleDocument::loadFromXml(const QDomDocument& doc, QGraphicsRectItem* start
format
.
setLineHeight
(
txtProperties
.
namedItem
(
QStringLiteral
(
"line-spacing"
)).
nodeValue
().
toInt
(),
QTextBlockFormat
::
LineDistanceHeight
);
cursor
.
setBlockFormat
(
format
);
}
format
.
setForeground
(
QBrush
(
col
));
cursor
.
mergeCharFormat
(
format
);
txt
->
setTextInteractionFlags
(
Qt
::
NoTextInteraction
);
cformat
.
setForeground
(
QBrush
(
col
));
cursor
.
setCharFormat
(
cformat
);
if
(
txtProperties
.
namedItem
(
QStringLiteral
(
"gradient"
)).
isNull
()
==
false
)
{
// Gradient color
QString
data
=
txtProperties
.
namedItem
(
QStringLiteral
(
"gradient"
)).
nodeValue
();
txt
->
setData
(
TitleDocument
::
Gradient
,
data
);
QLinearGradient
gr
=
GradientWidget
::
gradientFromString
(
data
,
txt
->
boundingRect
().
width
(),
txt
->
boundingRect
().
height
());
cformat
.
setForeground
(
QBrush
(
gr
));
cursor
.
setCharFormat
(
cformat
);
}
if
(
txtProperties
.
namedItem
(
QStringLiteral
(
"alignment"
)).
isNull
()
==
false
)
{
txt
->
setAlignment
((
Qt
::
Alignment
)
txtProperties
.
namedItem
(
QStringLiteral
(
"alignment"
)).
nodeValue
().
toInt
());
}
...
...
@@ -529,9 +544,9 @@ int TitleDocument::loadFromXml(const QDomDocument& doc, QGraphicsRectItem* start
QDomElement
trans
=
items
.
item
(
i
).
namedItem
(
QStringLiteral
(
"position"
)).
firstChild
().
toElement
();
gitem
->
setTransform
(
stringToTransform
(
trans
.
firstChild
().
nodeValue
()));
QString
rotate
=
trans
.
attribute
(
QStringLiteral
(
"rotation"
));
if
(
!
rotate
.
isEmpty
())
gitem
->
setData
(
ROTATEFACTOR
,
stringToList
(
rotate
));
if
(
!
rotate
.
isEmpty
())
gitem
->
setData
(
TitleDocument
::
RotateFactor
,
stringToList
(
rotate
));
QString
zoom
=
trans
.
attribute
(
QStringLiteral
(
"zoom"
));
if
(
!
zoom
.
isEmpty
())
gitem
->
setData
(
ZOOMFACTOR
,
zoom
.
toInt
());
if
(
!
zoom
.
isEmpty
())
gitem
->
setData
(
TitleDocument
::
ZoomFactor
,
zoom
.
toInt
());
int
zValue
=
items
.
item
(
i
).
attributes
().
namedItem
(
QStringLiteral
(
"z-index"
)).
nodeValue
().
toInt
();
if
(
zValue
>
maxZValue
)
maxZValue
=
zValue
;
gitem
->
setZValue
(
zValue
);
...
...
src/titler/titledocument.h
View file @
c0bfde6f
...
...
@@ -28,14 +28,18 @@ class QGraphicsScene;
class
QGraphicsRectItem
;
class
QGraphicsItem
;
const
int
ROTATEFACTOR
=
103
;
const
int
ZOOMFACTOR
=
104
;
class
TitleDocument
{
public:
TitleDocument
();
enum
TitleProperties
{
OutlineWidth
=
101
,
OutlineColor
,
Gradient
,
RotateFactor
,
ZoomFactor
};
void
setScene
(
QGraphicsScene
*
scene
,
int
width
,
int
height
);
bool
saveDocument
(
const
QUrl
&
url
,
QGraphicsRectItem
*
startv
,
QGraphicsRectItem
*
endv
,
int
duration
,
bool
embed_images
=
false
);
QDomDocument
xml
(
QGraphicsRectItem
*
startv
,
QGraphicsRectItem
*
endv
,
bool
embed_images
=
false
);
...
...
src/titler/titlewidget.cpp
View file @
c0bfde6f
...
...
@@ -16,6 +16,7 @@
***************************************************************************/
#include
"titlewidget.h"
#include
"gradientwidget.h"
#include
"kdenlivesettings.h"
#include
"doc/kthumb.h"
#include
"KoSliderCombo.h"
...
...
@@ -87,6 +88,15 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
fontColorButton
->
setAlphaChannelEnabled
(
true
);
textOutlineColor
->
setAlphaChannelEnabled
(
true
);
QButtonGroup
*
colorGroup
=
new
QButtonGroup
(
this
);
colorGroup
->
addButton
(
gradient_color
);
colorGroup
->
addButton
(
plain_color
);
QButtonGroup
*
alignGroup
=
new
QButtonGroup
(
this
);
alignGroup
->
addButton
(
buttonAlignLeft
);
alignGroup
->
addButton
(
buttonAlignCenter
);
alignGroup
->
addButton
(
buttonAlignRight
);
textOutline
->
setMinimum
(
0
);
textOutline
->
setMaximum
(
200
);
//textOutline->setDecimals(0);
...
...
@@ -137,7 +147,11 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
connect
(
backgroundColor
,
SIGNAL
(
changed
(
QColor
)),
this
,
SLOT
(
slotChangeBackground
()))
;
connect
(
backgroundAlpha
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
slotChangeBackground
()))
;
connect
(
fontColorButton
,
SIGNAL
(
changed
(
QColor
)),
this
,
SLOT
(
slotUpdateText
()))
;
connect
(
fontColorButton
,
SIGNAL
(
changed
(
QColor
)),
this
,
SLOT
(
slotUpdateText
()));
connect
(
plain_color
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
slotUpdateText
()));
connect
(
gradient_color
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
slotUpdateText
()));
connect
(
gradients_combo
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
slotUpdateText
()));
connect
(
textOutlineColor
,
SIGNAL
(
changed
(
QColor
)),
this
,
SLOT
(
slotUpdateText
()))
;
connect
(
font_family
,
SIGNAL
(
currentFontChanged
(
QFont
)),
this
,
SLOT
(
slotUpdateText
()))
;
connect
(
font_size
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
slotUpdateText
()));
...
...
@@ -200,6 +214,7 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
connect
(
buttonAlignLeft
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
slotUpdateText
()));
connect
(
buttonAlignRight
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
slotUpdateText
()));
connect
(
buttonAlignCenter
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
slotUpdateText
()));
connect
(
edit_gradient
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
slotEditGradient
()));
connect
(
displayBg
,
SIGNAL
(
stateChanged
(
int
)),
this
,
SLOT
(
displayBackgroundFrame
()));
connect
(
m_unicodeDialog
,
SIGNAL
(
charSelected
(
QString
)),
this
,
SLOT
(
slotInsertUnicodeString
(
QString
)));
...
...
@@ -231,6 +246,7 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
buttonAlignCenter
->
setIcon
(
KoIconUtils
::
themedIcon
(
QStringLiteral
(
"format-justify-center"
)));
buttonAlignLeft
->
setIcon
(
KoIconUtils
::
themedIcon
(
QStringLiteral
(
"format-justify-left"
)));
buttonAlignRight
->
setIcon
(
KoIconUtils
::
themedIcon
(
QStringLiteral
(
"format-justify-right"
)));
edit_gradient
->
setIcon
(
KoIconUtils
::
themedIcon
(
QStringLiteral
(
"configure"
)));
buttonAlignRight
->
setToolTip
(
i18n
(
"Align right"
));
buttonAlignLeft
->
setToolTip
(
i18n
(
"Align left"
));
...
...
@@ -399,7 +415,7 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
m_titledocument
.
setScene
(
m_scene
,
m_frameWidth
,
m_frameHeight
);
connect
(
m_scene
,
SIGNAL
(
changed
(
QList
<
QRectF
>
)),
this
,
SLOT
(
slotChanged
()));
connect
(
font_size
,
SIGNAL
(
valueChanged
(
int
)),
m_scene
,
SLOT
(
slotUpdateFontSize
(
int
)));
QPen
framepen
(
Qt
::
DotLine
);
framepen
.
setColor
(
Qt
::
red
);
...
...
@@ -409,7 +425,7 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
m_frameBorder
->
setBrush
(
Qt
::
transparent
);
m_frameBorder
->
setFlags
(
0
);
graphicsView
->
scene
()
->
addItem
(
m_frameBorder
);
m_frameImage
=
new
QGraphicsPixmapItem
();
QTransform
qtrans
;
qtrans
.
scale
(
2.0
,
2.0
);
...
...
@@ -429,6 +445,7 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, const QString &pro
connect
(
zoom_spin
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
slotUpdateZoom
(
int
)));
// mbd: load saved settings
loadGradients
();
readChoices
();
// Hide effects not implemented
...
...
@@ -703,7 +720,7 @@ void TitleWidget::slotImageTool()
void
TitleWidget
::
showToolbars
(
TITLETOOL
toolType
)
{
toolbar_stack
->
setEnabled
(
toolType
!=
TITLE_SELECT
);
//
toolbar_stack->setEnabled(toolType != TITLE_SELECT);
switch
(
toolType
)
{
case
TITLE_IMAGE
:
toolbar_stack
->
setCurrentIndex
(
2
);
...
...
@@ -856,7 +873,7 @@ void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
QColor
b
=
rectBColor
->
color
();
rect
->
setBrush
(
QBrush
(
b
));
rect
->
setZValue
(
m_count
++
);
rect
->
setData
(
ZOOMFACTOR
,
100
);
rect
->
setData
(
TitleDocument
::
ZoomFactor
,
100
);
prepareTools
(
rect
);
//setCurrentItem(rect);
//graphicsView->setFocus();
...
...
@@ -893,11 +910,18 @@ void TitleWidget::slotNewText(MyTextItem *tt)
QTextCharFormat
cformat
=
cur
.
charFormat
();
double
outlineWidth
=
textOutline
->
value
()
/
10.0
;
tt
->
setData
(
101
,
outlineWidth
);
tt
->
setData
(
102
,
outlineColor
);
tt
->
setData
(
TitleDocument
::
OutlineWidth
,
outlineWidth
);
tt
->
setData
(
TitleDocument
::
OutlineColor
,
outlineColor
);
if
(
outlineWidth
>
0.0
)
cformat
.
setTextOutline
(
QPen
(
outlineColor
,
outlineWidth
));
cformat
.
setForeground
(
QBrush
(
color
));
if
(
gradient_color
->
isChecked
())
{
QString
gradientData
=
gradients_combo
->
currentData
().
toString
();
tt
->
setData
(
TitleDocument
::
Gradient
,
gradientData
);
QLinearGradient
gr
=
GradientWidget
::
gradientFromString
(
gradientData
,
tt
->
boundingRect
().
width
(),
tt
->
boundingRect
().
height
());
cformat
.
setForeground
(
QBrush
(
gr
));
}
else
{
cformat
.
setForeground
(
QBrush
(
color
));
}
cur
.
setCharFormat
(
cformat
);
cur
.
setBlockFormat
(
format
);
tt
->
setTextCursor
(
cur
);
...
...
@@ -1265,7 +1289,7 @@ void TitleWidget::updateRotZoom(QGraphicsItem *i)
Transform
t
=
m_transformations
.
value
(
i
);
if
(
!
i
->
data
(
ZOOMFACTOR
).
isNull
())
itemzoom
->
setValue
(
i
->
data
(
ZOOMFACTOR
).
toInt
());
if
(
!
i
->
data
(
TitleDocument
::
ZoomFactor
).
isNull
())
itemzoom
->
setValue
(
i
->
data
(
TitleDocument
::
ZoomFactor
).
toInt
());
else
itemzoom
->
setValue
((
int
)(
t
.
scalex
*
100.0
+
0.5
));
itemrotatex
->
setValue
((
int
)(
t
.
rotatex
));
...
...
@@ -1508,6 +1532,11 @@ void TitleWidget::slotUpdateText()
font
.
setLetterSpacing
(
QFont
::
AbsoluteSpacing
,
letter_spacing
->
value
());
QColor
color
=
fontColorButton
->
color
();
QColor
outlineColor
=
textOutlineColor
->
color
();
QString
gradientData
;