1 #include "titlewidget.h"
2 #include "graphicsscenerectmove.h"
3 #include <QGraphicsView>
5 #include <QGraphicsItem>
8 TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
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()));
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);
29 // a gradient background
30 QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
31 gradient->setSpread(QGradient::RepeatSpread);
32 //scene->setBackgroundBrush(*gradient);
34 graphicsView->setScene(scene);
35 connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
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);
49 void TitleWidget::slotNewRect(){
51 QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
52 ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
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);*/
65 void TitleWidget::selectionChanged(){
66 QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
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);
75 if ((l[0])->type()==3){
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();
86 rectFColor->setColor(fcol);
87 rectBColor->setColor(bcol);
89 rectLineWidth->setValue(rec->pen().width());
92 //toolBox->setCurrentIndex(0);
97 void TitleWidget::slotChangeBackground(){
98 QColor color=kcolorbutton->color();
99 color.setAlpha(horizontalSlider->value());
100 graphicsView->scene()->setBackgroundBrush(QBrush(color));
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());
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());
116 penf.setWidth(rectLineWidth->value());
118 QColor b=rectBColor->color();
119 b.setAlpha(rectBAlpha->value());
120 rec->setBrush(QBrush(b));
124 #include "moc_titlewidget.cpp"