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