1 #include "titlewidget.h"
2 #include <QGraphicsScene>
3 #include <QGraphicsView>
5 #include <QGraphicsItem>
7 TitleWidget::TitleWidget (QDialog *parent):QDialog(parent){
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()));
15 QGraphicsScene *scene=new QGraphicsScene(this);
19 // a gradient background
20 QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
21 gradient->setSpread(QGradient::RepeatSpread);
22 //scene->setBackgroundBrush(*gradient);
24 graphicsView->setScene(scene);
25 connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
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);
39 void TitleWidget::slotNewRect(){
41 QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
42 ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
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);*/
55 void TitleWidget::selectionChanged(){
56 QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
58 kDebug() << (l[0])->type();
59 if ((l[0])->type()==8){
60 ktextedit->setHtml(((QGraphicsTextItem*)l[0])->toHtml());
61 toolBox->setCurrentIndex(1);
63 if ((l[0])->type()==3){
65 toolBox->setCurrentIndex(2);
67 toolBox->setCurrentIndex(0);
72 void TitleWidget::slotChangeBackground(){
73 QColor color=kcolorbutton->color();
74 color.setAlpha(horizontalSlider->value());
75 graphicsView->scene()->setBackgroundBrush(QBrush(color));
78 void TitleWidget::textChanged(){
79 QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
80 if (l.size()>0 && (l[0])->type()==8 /*textitem*/){
82 ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
85 #include "moc_titlewidget.cpp"