]> git.sesse.net Git - kdenlive/blob - src/titlewidget.cpp
colored viewports and stepsize for move/resize increased
[kdenlive] / src / titlewidget.cpp
1 /***************************************************************************
2                           titlewidget.h  -  description
3                              -------------------
4     begin                : Feb 28 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "titlewidget.h"
19 #include "graphicsscenerectmove.h"
20 #include <QGraphicsView>
21 #include <KDebug>
22 #include <QGraphicsItem>
23 int settingUp=false;
24
25 TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
26         setupUi(this);
27         connect (newTextButton,SIGNAL(clicked()), this, SLOT( slotNewText()));
28         connect (newRectButton,SIGNAL(clicked()), this, SLOT( slotNewRect()));
29         connect (kcolorbutton, SIGNAL ( clicked()), this, SLOT( slotChangeBackground()) ) ;
30         connect (horizontalSlider, SIGNAL ( valueChanged(int) ), this, SLOT( slotChangeBackground()) ) ;
31         connect (ktextedit, SIGNAL(textChanged()), this , SLOT (textChanged()));
32         connect (fontColorButton, SIGNAL ( clicked()), this, SLOT( textChanged()) ) ;
33         //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ;
34         
35         connect (kfontrequester, SIGNAL ( fontSelected(const QFont &)), this, SLOT( textChanged()) ) ;
36         connect(textAlpha, SIGNAL( valueChanged(int) ), this, SLOT (textChanged()));
37         //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged()));
38         
39         connect(rectFAlpha, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged()));
40         connect(rectBAlpha, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged()));
41         connect(rectFColor, SIGNAL( clicked() ), this, SLOT (rectChanged()));
42         connect(rectBColor, SIGNAL( clicked() ), this, SLOT (rectChanged()));
43         connect(rectLineWidth, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged()));
44         
45         connect (startViewportX,SIGNAL(valueChanged(int)), this, SLOT( setupViewports()));
46         connect (startViewportY,SIGNAL(valueChanged(int)), this, SLOT( setupViewports()));
47         connect (startViewportSize,SIGNAL(valueChanged(int)), this, SLOT( setupViewports()));
48         connect (endViewportX,SIGNAL(valueChanged(int)), this, SLOT( setupViewports()));
49         connect (endViewportY,SIGNAL(valueChanged(int)), this, SLOT( setupViewports()));
50         connect (endViewportSize,SIGNAL(valueChanged(int)), this, SLOT( setupViewports()));     
51         
52         GraphicsSceneRectMove *scene=new GraphicsSceneRectMove(this);
53         
54         
55         
56  // a gradient background
57         QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
58         gradient->setSpread(QGradient::RepeatSpread);
59         //scene->setBackgroundBrush(*gradient);
60         
61         graphicsView->setScene(scene);
62         connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
63         initViewports();
64         
65         graphicsView->show();
66         graphicsView->setRenderHint(QPainter::Antialiasing);
67         graphicsView->setInteractive(true);
68         graphicsView->resize(400, 300);
69         //update();
70 }
71                
72 void TitleWidget::initViewports(){
73         startViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0)));
74         endViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0)));
75         
76         QPen startpen(Qt::DotLine);
77         QPen endpen(Qt::DashDotLine);
78         startpen.setColor(QColor(100,200,100,140));
79         endpen.setColor(QColor(200,100,100,140));
80         
81         startViewport->setPen(startpen);
82         endViewport->setPen(endpen);
83         
84         startViewportSize->setValue(40);
85         endViewportSize->setValue(40);
86         
87         graphicsView->scene()->addItem(startViewport);
88         graphicsView->scene()->addItem(endViewport);
89 }
90                
91 void TitleWidget::slotNewRect(){
92         
93         QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
94         ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
95 }
96                
97 void TitleWidget::slotNewText(){
98         QGraphicsTextItem *tt=graphicsView->scene()->addText("Text here");
99         tt->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
100         tt->setTextInteractionFlags (Qt::TextEditorInteraction);
101         connect (tt->document(), SIGNAL (contentsChanged()), this, SLOT(selectionChanged()));
102         kDebug() << tt->metaObject()->className();
103         /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
104         ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/
105         
106 }
107
108 void TitleWidget::selectionChanged(){
109         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
110         if (l.size()==1){
111                 kDebug() << (l[0])->type();
112                 if ((l[0])->type()==8  ){
113                         QGraphicsTextItem* i=((QGraphicsTextItem*)l[0]);
114                         if (l[0]->hasFocus() )
115                         ktextedit->setHtml(i->toHtml());
116                         toolBox->setCurrentIndex(1);
117                 }else
118                 if ((l[0])->type()==3){
119                         settingUp=true;
120                         QGraphicsRectItem *rec=((QGraphicsRectItem*)l[0]);
121                         toolBox->setCurrentIndex(2);
122                         rectFAlpha->setValue(rec->pen().color().alpha());
123                         rectBAlpha->setValue(rec->brush().isOpaque() ? rec->brush().color().alpha() : 0);
124                         kDebug() << rec->brush().color().alpha();
125                         QColor fcol=rec->pen().color();
126                         QColor bcol=rec->brush().color();
127                         //fcol.setAlpha(255);
128                         //bcol.setAlpha(255);
129                         rectFColor->setColor(fcol);
130                         rectBColor->setColor(bcol);
131                         settingUp=false;
132                         rectLineWidth->setValue(rec->pen().width());
133                 }
134                 else{
135                         //toolBox->setCurrentIndex(0);
136                 }
137         }
138 }
139
140 void TitleWidget::slotChangeBackground(){
141         QColor color=kcolorbutton->color();
142         color.setAlpha(horizontalSlider->value());
143         graphicsView->scene()->setBackgroundBrush(QBrush(color));
144 }
145
146 void TitleWidget::textChanged(){
147         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
148         if (l.size()==1 && (l[0])->type()==8 && !l[0]->hasFocus()){
149                 kDebug() << ktextedit->document()->toHtml();
150                 ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
151         }
152 }
153
154 void TitleWidget::rectChanged(){
155         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
156         if (l.size()==1 && (l[0])->type()==3 && !settingUp){
157                 QGraphicsRectItem *rec=(QGraphicsRectItem*)l[0];
158                 QColor f=rectFColor->color();
159                 f.setAlpha(rectFAlpha->value());
160                 QPen penf(f);
161                 penf.setWidth(rectLineWidth->value());
162                 rec->setPen(penf);
163                 QColor b=rectBColor->color();
164                 b.setAlpha(rectBAlpha->value());
165                 rec->setBrush(QBrush(b));
166         }
167 }
168
169 void TitleWidget::fontBold(){
170         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
171         if (l.size()==1 && (l[0])->type()==8 && !l[0]->hasFocus()){
172                 //ktextedit->document()->setTextOption();
173         }
174 }
175
176 void TitleWidget::setupViewports(){
177         double aspect_ratio=4.0/3.0;//read from project
178         
179         QRectF sp(startViewportX->value(), startViewportY->value(),0,0);
180         QRectF ep(endViewportX->value(),endViewportY->value(),0,0);
181         
182         double sv_size=startViewportSize->value();
183         double ev_size=endViewportSize->value();
184         sp.adjust(-sv_size,-sv_size/aspect_ratio,sv_size,sv_size/aspect_ratio);
185         ep.adjust(-ev_size,-ev_size/aspect_ratio,ev_size,ev_size/aspect_ratio); 
186         
187         startViewport->setPolygon(QPolygonF(sp));
188         endViewport->setPolygon(QPolygonF(ep));
189         
190         
191         
192         
193 }
194 #include "moc_titlewidget.cpp"
195