]> git.sesse.net Git - kdenlive/blob - src/titlewidget.cpp
first titler test
[kdenlive] / src / titlewidget.cpp
1 #include "titlewidget.h"
2 #include <QGraphicsScene>
3 #include <QGraphicsView>
4 #include <KDebug>
5 #include <QGraphicsItem>
6
7 TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
8         setupUi(this);
9         connect (newTextButton,SIGNAL(clicked()), this, SLOT( slotNewText()));
10         connect (kcolorbutton, SIGNAL ( clicked()), this, SLOT( slotChangeBackground()) ) ;
11         connect (horizontalSlider, SIGNAL ( valueChanged(int) ), this, SLOT( slotChangeBackground()) ) ;
12         connect (ktextedit, SIGNAL(textChanged()), this , SLOT (textChanged()));
13         
14         QGraphicsScene *scene=new QGraphicsScene(this);
15         
16         
17         
18  // a gradient background
19         QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
20         gradient->setSpread(QGradient::RepeatSpread);
21         //scene->setBackgroundBrush(*gradient);
22         
23         graphicsView->setScene(scene);
24         connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
25         
26         graphicsView->show();
27         graphicsView->setRenderHint(QPainter::Antialiasing);
28         //graphicsView->setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
29         //graphicsView->setCacheMode(QGraphicsView::CacheBackground);
30         //graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
31         graphicsView->setInteractive(true);
32         graphicsView->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
33         graphicsView->resize(400, 300);
34         
35         update();
36 }
37
38 void TitleWidget::slotNewText(){
39         
40         QGraphicsTextItem *tt=graphicsView->scene()->addText("Text here");
41         tt->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
42         tt->setTextInteractionFlags (Qt::TextEditorInteraction);
43         kDebug() << tt->metaObject()->className();
44         /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
45         ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/
46
47 }
48 void TitleWidget::selectionChanged(){
49         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
50         if (l.size()>0){
51                 if ((l[0])->type()==8){
52                         ktextedit->setHtml(((QGraphicsTextItem*)l[0])->toHtml());
53                         toolBox->setCurrentIndex(1);
54                 }
55         }
56 }
57
58 void TitleWidget::slotChangeBackground(){
59         QColor color=kcolorbutton->color();
60         color.setAlpha(horizontalSlider->value());
61         graphicsView->scene()->setBackgroundBrush(QBrush(color));
62 }
63
64 void TitleWidget::textChanged(){
65         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
66         if (l.size()>0 && (l[0])->type()==8 /*textitem*/){
67                 
68                 ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
69         }
70 }
71 #include "moc_titlewidget.cpp"
72