]> git.sesse.net Git - kdenlive/blob - src/titlewidget.cpp
text changeable in editor
[kdenlive] / src / titlewidget.cpp
1 #include "titlewidget.h"
2 #include "graphicsscenerectmove.h"
3 #include <QGraphicsView>
4 #include <KDebug>
5 #include <QGraphicsItem>
6 int settingUp=false;
7
8 TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
9         setupUi(this);
10         connect (newTextButton,SIGNAL(clicked()), this, SLOT( slotNewText()));
11         connect (newRectButton,SIGNAL(clicked()), this, SLOT( slotNewRect()));
12         connect (kcolorbutton, SIGNAL ( clicked()), this, SLOT( slotChangeBackground()) ) ;
13         connect (horizontalSlider, SIGNAL ( valueChanged(int) ), this, SLOT( slotChangeBackground()) ) ;
14         connect (ktextedit, SIGNAL(textChanged()), this , SLOT (textChanged()));
15         connect (fontColorButton, SIGNAL ( clicked()), this, SLOT( textChanged()) ) ;
16         connect (kfontrequester, SIGNAL ( fontSelected(const QFont &)), this, SLOT( textChanged()) ) ;
17         connect(textAlpha, SIGNAL( valueChanged(int) ), this, SLOT (textChanged()));
18         //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged()));
19         
20         connect(rectFAlpha, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged()));
21         connect(rectBAlpha, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged()));
22         connect(rectFColor, SIGNAL( clicked() ), this, SLOT (rectChanged()));
23         connect(rectBColor, SIGNAL( clicked() ), this, SLOT (rectChanged()));
24         connect(rectLineWidth, SIGNAL( valueChanged(int) ), this, SLOT (rectChanged()));
25         GraphicsSceneRectMove *scene=new GraphicsSceneRectMove(this);
26         
27         
28         
29  // a gradient background
30         QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
31         gradient->setSpread(QGradient::RepeatSpread);
32         //scene->setBackgroundBrush(*gradient);
33         
34         graphicsView->setScene(scene);
35         connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
36         
37         graphicsView->show();
38         graphicsView->setRenderHint(QPainter::Antialiasing);
39         //graphicsView->setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
40         //graphicsView->setCacheMode(QGraphicsView::CacheBackground);
41         //graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
42         graphicsView->setInteractive(true);
43         graphicsView->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
44         graphicsView->resize(400, 300);
45         
46         update();
47 }
48
49 void TitleWidget::slotNewRect(){
50         
51         QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
52         ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
53 }
54 void TitleWidget::slotNewText(){
55         QGraphicsTextItem *tt=graphicsView->scene()->addText("Text here");
56         tt->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
57         tt->setTextInteractionFlags (Qt::TextEditorInteraction);
58         connect (tt->document(), SIGNAL (contentsChanged()), this, SLOT(selectionChanged()));
59         kDebug() << tt->metaObject()->className();
60         /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
61         ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/
62         
63 }
64
65 void TitleWidget::selectionChanged(){
66         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
67         if (l.size()==1){
68                 kDebug() << (l[0])->type();
69                 if ((l[0])->type()==8  ){
70                         QGraphicsTextItem* i=((QGraphicsTextItem*)l[0]);
71                         if (l[0]->hasFocus() )
72                         ktextedit->setHtml(i->toHtml());
73                         toolBox->setCurrentIndex(1);
74                 }else
75                 if ((l[0])->type()==3){
76                         settingUp=true;
77                         QGraphicsRectItem *rec=((QGraphicsRectItem*)l[0]);
78                         toolBox->setCurrentIndex(2);
79                         rectFAlpha->setValue(rec->pen().color().alpha());
80                         rectBAlpha->setValue(rec->brush().isOpaque() ? rec->brush().color().alpha() : 0);
81                         kDebug() << rec->brush().color().alpha();
82                         QColor fcol=rec->pen().color();
83                         QColor bcol=rec->brush().color();
84                         //fcol.setAlpha(255);
85                         //bcol.setAlpha(255);
86                         rectFColor->setColor(fcol);
87                         rectBColor->setColor(bcol);
88                         settingUp=false;
89                         rectLineWidth->setValue(rec->pen().width());
90                 }
91                 else{
92                         //toolBox->setCurrentIndex(0);
93                 }
94         }
95 }
96
97 void TitleWidget::slotChangeBackground(){
98         QColor color=kcolorbutton->color();
99         color.setAlpha(horizontalSlider->value());
100         graphicsView->scene()->setBackgroundBrush(QBrush(color));
101 }
102
103 void TitleWidget::textChanged(){
104         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
105         if (l.size()==1 && (l[0])->type()==8 && !l[0]->hasFocus()){
106                 ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
107         }
108 }
109 void TitleWidget::rectChanged(){
110         QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
111         if (l.size()==1 && (l[0])->type()==3 && !settingUp){
112                 QGraphicsRectItem *rec=(QGraphicsRectItem*)l[0];
113                 QColor f=rectFColor->color();
114                 f.setAlpha(rectFAlpha->value());
115                 QPen penf(f);
116                 penf.setWidth(rectLineWidth->value());
117                 rec->setPen(penf);
118                 QColor b=rectBColor->color();
119                 b.setAlpha(rectBAlpha->value());
120                 rec->setBrush(QBrush(b));
121         }
122 }
123
124 #include "moc_titlewidget.cpp"
125