1 /***************************************************************************
2 titlewidget.h - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
18 #include "titlewidget.h"
19 #include "graphicsscenerectmove.h"
20 #include <QGraphicsView>
22 #include <QGraphicsItem>
25 TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
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()) ) ;
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()));
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()));
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()));
52 GraphicsSceneRectMove *scene=new GraphicsSceneRectMove(this);
56 // a gradient background
57 QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
58 gradient->setSpread(QGradient::RepeatSpread);
59 //scene->setBackgroundBrush(*gradient);
61 graphicsView->setScene(scene);
62 connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
66 graphicsView->setRenderHint(QPainter::Antialiasing);
67 graphicsView->setInteractive(true);
68 graphicsView->resize(400, 300);
72 void TitleWidget::initViewports(){
73 startViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0)));
74 endViewport=new QGraphicsPolygonItem(QPolygonF(QRectF(0,0,0,0)));
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));
81 startViewport->setPen(startpen);
82 endViewport->setPen(endpen);
84 startViewportSize->setValue(40);
85 endViewportSize->setValue(40);
87 graphicsView->scene()->addItem(startViewport);
88 graphicsView->scene()->addItem(endViewport);
91 void TitleWidget::slotNewRect(){
93 QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
94 ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
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);*/
108 void TitleWidget::selectionChanged(){
109 QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
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);
118 if ((l[0])->type()==3){
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);
132 rectLineWidth->setValue(rec->pen().width());
135 //toolBox->setCurrentIndex(0);
140 void TitleWidget::slotChangeBackground(){
141 QColor color=kcolorbutton->color();
142 color.setAlpha(horizontalSlider->value());
143 graphicsView->scene()->setBackgroundBrush(QBrush(color));
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());
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());
161 penf.setWidth(rectLineWidth->value());
163 QColor b=rectBColor->color();
164 b.setAlpha(rectBAlpha->value());
165 rec->setBrush(QBrush(b));
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();
176 void TitleWidget::setupViewports(){
177 double aspect_ratio=4.0/3.0;//read from project
179 QRectF sp(startViewportX->value(), startViewportY->value(),0,0);
180 QRectF ep(endViewportX->value(),endViewportY->value(),0,0);
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);
187 startViewport->setPolygon(QPolygonF(sp));
188 endViewport->setPolygon(QPolygonF(ep));
194 #include "moc_titlewidget.cpp"