]> git.sesse.net Git - kdenlive/blob - src/titlewidget.cpp
start/endviewport not setup'able
[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         startViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0)));
54         endViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0)));
55         
56         startViewportSize->setValue(40);
57         endViewportSize->setValue(40);
58         
59         scene->addItem(startViewport);
60         scene->addItem(endViewport);
61         
62         
63  // a gradient background
64         QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
65         gradient->setSpread(QGradient::RepeatSpread);
66         //scene->setBackgroundBrush(*gradient);
67         
68         graphicsView->setScene(scene);
69         connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
70         
71         graphicsView->show();
72         graphicsView->setRenderHint(QPainter::Antialiasing);
73         graphicsView->setInteractive(true);
74         graphicsView->resize(400, 300);
75         //update();
76 }
77
78 void TitleWidget::slotNewRect(){
79         
80         QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
81         ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
82 }
83 void TitleWidget::slotNewText(){
84         QGraphicsTextItem *tt=graphicsView->scene()->addText("Text here");
85         tt->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
86         tt->setTextInteractionFlags (Qt::TextEditorInteraction);
87         connect (tt->document(), SIGNAL (contentsChanged()), this, SLOT(selectionChanged()));
88         kDebug() << tt->metaObject()->className();
89         /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
90         ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/
91         
92 }
93
94 void TitleWidget::selectionChanged(){
95         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
96         if (l.size()==1){
97                 kDebug() << (l[0])->type();
98                 if ((l[0])->type()==8  ){
99                         QGraphicsTextItem* i=((QGraphicsTextItem*)l[0]);
100                         if (l[0]->hasFocus() )
101                         ktextedit->setHtml(i->toHtml());
102                         toolBox->setCurrentIndex(1);
103                 }else
104                 if ((l[0])->type()==3){
105                         settingUp=true;
106                         QGraphicsRectItem *rec=((QGraphicsRectItem*)l[0]);
107                         toolBox->setCurrentIndex(2);
108                         rectFAlpha->setValue(rec->pen().color().alpha());
109                         rectBAlpha->setValue(rec->brush().isOpaque() ? rec->brush().color().alpha() : 0);
110                         kDebug() << rec->brush().color().alpha();
111                         QColor fcol=rec->pen().color();
112                         QColor bcol=rec->brush().color();
113                         //fcol.setAlpha(255);
114                         //bcol.setAlpha(255);
115                         rectFColor->setColor(fcol);
116                         rectBColor->setColor(bcol);
117                         settingUp=false;
118                         rectLineWidth->setValue(rec->pen().width());
119                 }
120                 else{
121                         //toolBox->setCurrentIndex(0);
122                 }
123         }
124 }
125
126 void TitleWidget::slotChangeBackground(){
127         QColor color=kcolorbutton->color();
128         color.setAlpha(horizontalSlider->value());
129         graphicsView->scene()->setBackgroundBrush(QBrush(color));
130 }
131
132 void TitleWidget::textChanged(){
133         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
134         if (l.size()==1 && (l[0])->type()==8 && !l[0]->hasFocus()){
135                 kDebug() << ktextedit->document()->toHtml();
136                 ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
137         }
138 }
139
140 void TitleWidget::rectChanged(){
141         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
142         if (l.size()==1 && (l[0])->type()==3 && !settingUp){
143                 QGraphicsRectItem *rec=(QGraphicsRectItem*)l[0];
144                 QColor f=rectFColor->color();
145                 f.setAlpha(rectFAlpha->value());
146                 QPen penf(f);
147                 penf.setWidth(rectLineWidth->value());
148                 rec->setPen(penf);
149                 QColor b=rectBColor->color();
150                 b.setAlpha(rectBAlpha->value());
151                 rec->setBrush(QBrush(b));
152         }
153 }
154
155 void TitleWidget::fontBold(){
156         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
157         if (l.size()==1 && (l[0])->type()==8 && !l[0]->hasFocus()){
158                 //ktextedit->document()->setTextOption();
159         }
160 }
161
162 void TitleWidget::setupViewports(){
163         double aspect_ratio=4.0/3.0;//read from project
164         
165         QRectF sp(startViewportX->value(), startViewportY->value(),0,0);
166         QRectF ep(endViewportX->value(),endViewportY->value(),0,0);
167         
168         double sv_size=startViewportSize->value();
169         double ev_size=endViewportSize->value();
170         sp.adjust(-sv_size,-sv_size/aspect_ratio,sv_size,sv_size/aspect_ratio);
171         ep.adjust(-ev_size,-ev_size/aspect_ratio,ev_size,ev_size/aspect_ratio); 
172         
173         startViewport->setPolygon(QPolygonF(sp));
174         endViewport->setPolygon(QPolygonF(ep));
175         
176         
177         
178         
179 }
180 #include "moc_titlewidget.cpp"
181