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 (kcolorbutton, SIGNAL ( clicked()), this, SLOT( slotChangeBackground()) ) ;
11 connect (horizontalSlider, SIGNAL ( valueChanged(int) ), this, SLOT( slotChangeBackground()) ) ;
12 connect (ktextedit, SIGNAL(textChanged()), this , SLOT (textChanged()));
14 QGraphicsScene *scene=new QGraphicsScene(this);
18 // a gradient background
19 QRadialGradient *gradient=new QRadialGradient(0, 0, 10);
20 gradient->setSpread(QGradient::RepeatSpread);
21 //scene->setBackgroundBrush(*gradient);
23 graphicsView->setScene(scene);
24 connect (graphicsView->scene(), SIGNAL (selectionChanged()), this , SLOT( selectionChanged()));
27 graphicsView->setRenderHint(QPainter::Antialiasing);
28 //graphicsView->setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
29 //graphicsView->setCacheMode(QGraphicsView::CacheBackground);
30 //graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
31 graphicsView->setInteractive(true);
32 graphicsView->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
33 graphicsView->resize(400, 300);
38 void TitleWidget::slotNewText(){
40 QGraphicsTextItem *tt=graphicsView->scene()->addText("Text here");
41 tt->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
42 tt->setTextInteractionFlags (Qt::TextEditorInteraction);
43 kDebug() << tt->metaObject()->className();
44 /*QGraphicsRectItem * ri=graphicsView->scene()->addRect(-50,-50,100,100);
45 ri->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);*/
48 void TitleWidget::selectionChanged(){
49 QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
51 if ((l[0])->type()==8){
52 ktextedit->setHtml(((QGraphicsTextItem*)l[0])->toHtml());
53 toolBox->setCurrentIndex(1);
58 void TitleWidget::slotChangeBackground(){
59 QColor color=kcolorbutton->color();
60 color.setAlpha(horizontalSlider->value());
61 graphicsView->scene()->setBackgroundBrush(QBrush(color));
64 void TitleWidget::textChanged(){
65 QList<QGraphicsItem*> l=graphicsView->scene()->selectedItems();
66 if (l.size()>0 && (l[0])->type()==8 /*textitem*/){
68 ((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
71 #include "moc_titlewidget.cpp"