[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/applets/groupphoto
From:       Sebastian Kügler <sebas () kde ! nl>
Date:       2007-09-28 10:18:06
Message-ID: 1190974686.780286.1744.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 718273 by sebas:

Fix up groupphoto to work again + CodingStyle.


 M  +78 -75    groupphoto.cpp  


--- trunk/playground/base/plasma/applets/groupphoto/groupphoto.cpp #718272:718273
@@ -103,7 +103,7 @@
     m_layout = new Plasma::VBoxLayout(0);
     m_layout->setGeometry(QRectF(0, 0, 400, 800));
     m_layout->setMargin(12);
-
+    setDrawStandardBackground(false);
     //Initialize the picture
     m_cmpPicture = NULL;
     choosePicture();
@@ -130,14 +130,16 @@
 
 void Groupphoto::readNames()
 {
-    foreach (_person* person, m_personList)
-       delete person;
+    foreach (_person* person, m_personList) {
+        delete person;
+    }
     m_personList.clear();
 
     QFile file(KGlobal::dirs()->findAllResources("data", (m_year==2007) ? \
"groupphoto/group-photo.html" : "groupphoto/group-photo-2006.html")[0]);  
-    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        return;
+    }
 
     QTextStream in(&file);
     while (!in.atEnd()) {
@@ -158,53 +160,54 @@
 
 void Groupphoto::autoSearch(const QString &word)
 {
+    Q_UNUSED( word );
     m_timer->start();
 }
 
 void Groupphoto::search()
 {
-    foreach (HitBox* hitbox, m_hitboxList)
+    foreach (HitBox* hitbox, m_hitboxList) {
        delete hitbox;
+    }
     m_hitboxList.clear();
 
     const QString searchTerm = m_searchEdit->toPlainText();
 
     foreach (_person* person, m_personList) {
-       if (person->name.indexOf(searchTerm, 0, Qt::CaseInsensitive)!=-1) {
-
-          HitBox* hitbox = new HitBox(this, person->name, person->width);
-         const int frameThickness = 16;
-         hitbox->setPos((contentSize().width()-(frameThickness*2))/myPicture.width()*person->x,
                
-                      \
                (contentSize().height()-(frameThickness*2))/myPicture.height()*person->y);
                
-         hitbox->setZValue(1);
-         m_hitboxList.append(hitbox);
-       }
+        if (person->name.indexOf(searchTerm, 0, Qt::CaseInsensitive)!=-1) {
+            HitBox* hitbox = new HitBox(this, person->name, person->width);
+            const int frameThickness = 16;
+            hitbox->setPos((contentSize().width()-(frameThickness*2))/myPicture.width()*person->x,
 +                        \
(contentSize().height()-(frameThickness*2))/myPicture.height()*person->y); +          \
hitbox->setZValue(1); +            m_hitboxList.append(hitbox);
+        }
     }
-
 }
 
 void Groupphoto::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
 { 
-    if (m_oldPos==event->pos()) 
-       return;
-
+    if (m_oldPos==event->pos()) {
+        return;
+    }
     m_oldPos = event->pos();
 
-    foreach (HitBox* hitbox, m_hitboxList)
-       delete hitbox;
+    foreach (HitBox* hitbox, m_hitboxList) {
+        delete hitbox;
+    }
     m_hitboxList.clear();
 
     const int frameThickness = 16;
     foreach (_person* person, m_personList) {
-       QRect rect((contentSize().width()-(frameThickness*2))/myPicture.width()*person->x, \
(contentSize().height()-(frameThickness*2))/myPicture.height()*person->y, \
                person->width, person->width);
-       if (rect.contains(event->pos().toPoint()) ) {
-         HitBox* hitbox = new HitBox(this, person->name, person->width);
-         const int frameThickness = 16;
-         hitbox->setPos((contentSize().width()-(frameThickness*2))/myPicture.width()*person->x,
                
-                      \
                (contentSize().height()-(frameThickness*2))/myPicture.height()*person->y);
                
-         hitbox->setZValue(1);
-         m_hitboxList.append(hitbox);
-         break;
+       QRect rect((int)((contentSize().width()-(frameThickness*2))/myPicture.width()*person->x), \
(int)((contentSize().height()-(frameThickness*2))/myPicture.height()*person->y), \
person->width, person->width); +        if (rect.contains(event->pos().toPoint()) ) {
+            HitBox* hitbox = new HitBox(this, person->name, person->width);
+            const int frameThickness = 16;
+            hitbox->setPos((contentSize().width()-(frameThickness*2))/myPicture.width()*person->x,
 +                            \
(contentSize().height()-(frameThickness*2))/myPicture.height()*person->y); +          \
hitbox->setZValue(1); +            m_hitboxList.append(hitbox);
+            break;
        }
     }
 }
@@ -219,7 +222,7 @@
     Q_UNUSED(source);
     Q_UNUSED(data);
     QGraphicsItem::update();
-
+    updateGeometry();
 }
 
 void Groupphoto::choosePicture()
@@ -228,11 +231,11 @@
 
     QString tmpFile;
     if ( !KIO::NetAccess::download( currentUrl, tmpFile, 0L ) ) {
-	return;
+        return;
     }
     myPicture.load(tmpFile);
     if (myPicture.isNull()) {
-	return;
+        return;
     }
 }
 
@@ -241,7 +244,7 @@
     if (m_dialog == 0) {
         m_dialog = new KDialog;
         m_dialog->setCaption( "Configure Group Photo Frame" );
-	ui.setupUi(m_dialog->mainWidget());
+        ui.setupUi(m_dialog->mainWidget());
         m_dialog->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply );
         connect( m_dialog, SIGNAL(applyClicked()), this, SLOT(configAccepted()) );
         connect( m_dialog, SIGNAL(okClicked()), this, SLOT(configAccepted()) );
@@ -253,7 +256,7 @@
     ui.spinSize->setValue(m_pixelSize);
     ui.sliderRotation->setValue(m_rotation/5);
     ui.yearComboBox->setCurrentIndex( (m_year==2007) ? 1 : 0);
-	
+
     m_dialog->show();
 }
 
@@ -278,17 +281,19 @@
     m_year = (ui.yearComboBox->currentIndex() ==0) ? 2006 : 2007;
     cg.writeEntry("year", m_year);
 
-    foreach (HitBox* hitbox, m_hitboxList)
-       delete hitbox;
+    foreach (HitBox* hitbox, m_hitboxList) {
+        delete hitbox;
+    }
     m_hitboxList.clear();
+    //m_theme->resize(m_pixelSize, m_pixelSize);
 
     choosePicture();
     composePicture();
-
+    update();
     readNames();
 
     cg.config()->sync();
-  
+
 }
 
 QSizeF Groupphoto::contentSizeHint() const
@@ -310,10 +315,10 @@
     kDebug () << "Groupphoto::dropEvent";
     event->setAccepted(event->mimeData()->hasFormat("image/png"));//hasImage());
     /*if (event->mimeData()->hasFormat("image/png")) {//hasImage()) {
-	image = qvariant_cast<QImage>(event->mimeData()->imageData());
-	kDebug() << "image " << image.rect();
+    image = qvariant_cast<QImage>(event->mimeData()->imageData());
+    kDebug() << "image " << image.rect();
     }*/
-    update();
+    updateGeometry();
 }
 
 Groupphoto::~Groupphoto()
@@ -326,60 +331,57 @@
     QPixmap tempPicture;
     QPicture paintRecorder;
     QPainter p;
-    
+
     // scale picture
     if (myPicture.width() > myPicture.height()) {
-	    tempPicture = myPicture.scaledToWidth(m_pixelSize, Qt::SmoothTransformation);
+        tempPicture = myPicture.scaledToWidth(m_pixelSize, \
Qt::SmoothTransformation); +    } else {
+        tempPicture = myPicture.scaledToHeight(m_pixelSize, \
Qt::SmoothTransformation);  }
-    else {
-	    tempPicture = myPicture.scaledToHeight(m_pixelSize, Qt::SmoothTransformation);
-    }
-    
-    
+
     int roundingFactor = 12 * m_roundCorners;
     const int frameThickness = 16;
     double swRadious = 20;
     int swRound =  12 + m_roundCorners*6 + m_frame * 4;
     //int m_swOffset = 3;
-    
+
     p.begin(&paintRecorder);
     p.setRenderHint(QPainter::Antialiasing);
-    
+
     //shadow
     if (m_shadow) {
-	int swWidth = (int) (tempPicture.width() + frameThickness*m_frame + swRadious) ;
-	int swHeight = (int) (tempPicture.height() + frameThickness * m_frame + swRadious);
-	p.setBrush(QBrush(Qt::NoBrush));
-	p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));	
-	for (int r=1; r<=swRadious; r++) {
-	    p.setOpacity((r/swRadious)*(r/swRadious));
-	    if (r == swRadious) {
-		p.setBrush(QBrush(Qt::black,Qt::SolidPattern)); //the last rect will be filled
-	    }
-	    p.drawRoundRect(r, r, swWidth - 2 * r, swHeight - 2 * r, swRound-r, swRound-r);
-	}
-	p.translate(8,8);    
+        int swWidth = (int) (tempPicture.width() + frameThickness*m_frame + \
swRadious) ; +        int swHeight = (int) (tempPicture.height() + frameThickness * \
m_frame + swRadious); +        p.setBrush(QBrush(Qt::NoBrush));
+        p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));	
+        for (int r=1; r<=swRadious; r++) {
+            p.setOpacity((r/swRadious)*(r/swRadious));
+            if (r == swRadious) {
+            p.setBrush(QBrush(Qt::black,Qt::SolidPattern)); //the last rect will be \
filled +            }
+            p.drawRoundRect(r, r, swWidth - 2 * r, swHeight - 2 * r, swRound-r, \
swRound-r); +        }
+        p.translate(8,8);
     }
 
     // frame
     if (m_frame) {
-	QPainterPath framePath;
-	p.setOpacity(0.5);
-	QBrush blueBrush(m_frameColor);
-	framePath.addRoundRect(0, 0, tempPicture.width() + frameThickness, \
                tempPicture.height()+ frameThickness, roundingFactor);
-	p.fillPath(framePath, blueBrush);//it's easier to fill the base with the frame \
                color
-	framePath.closeSubpath();
-	p.translate(frameThickness/2, frameThickness/2);
+        QPainterPath framePath;
+        p.setOpacity(0.5);
+        QBrush blueBrush(m_frameColor);
+        framePath.addRoundRect(0, 0, tempPicture.width() + frameThickness, \
tempPicture.height()+ frameThickness, roundingFactor); +        p.fillPath(framePath, \
blueBrush);//it's easier to fill the base with the frame color +        \
framePath.closeSubpath(); +        p.translate(frameThickness/2, frameThickness/2);
     }
     // black frame
     p.setOpacity(1);
     QPainterPath path;
     if (m_frame) {
-	p.setPen(QPen(Qt::black, 4, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
+        p.setPen(QPen(Qt::black, 4, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
+    } else {
+        p.setPen(QPen(Qt::black, 4, Qt::NoPen, Qt::RoundCap,Qt::RoundJoin));
     }
-    else {
-	p.setPen(QPen(Qt::black, 4, Qt::NoPen, Qt::RoundCap,Qt::RoundJoin));
-    }
     path.addRoundRect(0, 0, tempPicture.width(), tempPicture.height(), \
roundingFactor-4);  p.drawPath(path);
     // picture
@@ -396,15 +398,16 @@
     p2.begin(m_cmpPicture);
     p2.drawPicture( 0 - paintRecorder.boundingRect().x(), \
0-paintRecorder.boundingRect().y(),paintRecorder);  prepareGeometryChange();
-    update();	
+    updateGeometry();	
 }
 
 void Groupphoto::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, \
const QRect &contentsRect)  {
     
     Q_UNUSED(option);
+    Q_UNUSED(contentsRect);
 
-    setDrawStandardBackground(true);
+    //setDrawStandardBackground(false);
     p->setRenderHint(QPainter::SmoothPixmapTransform, true);
     //Set transform matrix (rotation) 
     //FIXME where do I should put this?


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic