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

List:       kde-commits
Subject:    playground/base/plasma/wallpapers/movingscene
From:       Drake Justice <hallowname () gmail ! com>
Date:       2010-01-15 16:55:34
Message-ID: 1263574534.574109.4809.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1075199 by djustice:

3.7x faster/smoother :)
UI: option for tracking mouse movement




 M  +0 -2      README  
 M  +60 -21    movingscene.cpp  
 M  +6 -3      movingscene.h  


--- trunk/playground/base/plasma/wallpapers/movingscene/README #1075198:1075199
@@ -6,8 +6,6 @@
 
 super-alpha
  - why?
-   : unaccelerated (and unacceptable) painting
-      + needs GL probably... or maybe Qt has some magic for this?
    : unacceptable configuration interface (no KHNS3?? wtf?)
       + pretty much copy and paste from kdebase/workspace/plasma/generic/image/...
    : doesn't scale/repeat/check input image at all
--- trunk/playground/base/plasma/wallpapers/movingscene/movingscene.cpp \
#1075198:1075199 @@ -23,10 +23,13 @@
     m_time = new QTime();
     m_time->start();
     m_cursor = new QCursor();
+    m_timer = new QTimer();
     x_d = 0;
     y_d = 0;
     x = 0;
     y = 0;
+    
+    m_timer->start(100);
 }
 
 MovingScene::~MovingScene()
@@ -37,15 +40,11 @@
 {
     if (event->buttons() == Qt::LeftButton) {
         event->accept();
-        if ( m_time->elapsed() < (m_pM + 80) ) {
-            x = event->screenPos().x();
-            y = event->screenPos().y();
-            x_d = x / 4;
-            y_d = y / 4;
-            emit update(boundingRect());
-        }
-
-        m_pM = m_time->elapsed();
+        x = event->screenPos().x();
+        y = event->screenPos().y();
+        x_d = x / 4;
+        y_d = y / 4;
+        emit update(boundingRect());
     }
 }
 
@@ -53,7 +52,13 @@
 {
     if (event->buttons() == Qt::LeftButton) {
         event->accept();
-        m_cursor->setPos(x_d*4, y_d*4);
+        if (x_d > 0 && y_d > 0) {
+            m_cursor->setPos(x_d*4, y_d*4);
+            emit update(boundingRect());
+        } else {
+            m_cursor->setPos(boundingRect().width() / 2, boundingRect().height() / \
2); +            emit update(boundingRect());
+        }
     }
 }
 
@@ -72,32 +77,46 @@
     m_configWidget = new QWidget(parent);
 
     m_kurl = new KUrlRequester();
+    m_moveWithMouseCheckBox = new QCheckBox();
     m_layout = new QVBoxLayout();
     m_layout->addWidget(m_kurl);
+    m_layout->addWidget(m_moveWithMouseCheckBox);
     m_kurl->setText(m_wallpaper);
+    m_moveWithMouseCheckBox->setText("Sync wallpaper with mouse movement");
+    m_moveWithMouseCheckBox->setChecked(m_moveWithMouse);
     m_configWidget->setLayout(m_layout);
 
     connect(m_kurl, SIGNAL(textChanged(QString)), this, \
                SLOT(setWallpaper(QString)));
     connect(m_kurl, SIGNAL(returnPressed(QString)), this, \
SLOT(setWallpaper(QString))); +    connect(m_moveWithMouseCheckBox, \
                SIGNAL(stateChanged(int)), this, SLOT(changeMouseBehavior(int)));
     connect(m_kurl, SIGNAL(urlSelected(KUrl)), this, SLOT(setWallpaper(KUrl)));
 
+    connect(this, SIGNAL(settingsChanged(bool)), parent, \
SLOT(settingsChanged(bool))); +    
     return m_configWidget;
 }
 
 void MovingScene::save(KConfigGroup &config)
 {
     config.writeEntry("wallpaper", m_wallpaper);
+    config.writeEntry("movewithmouse", m_moveWithMouse);
     config.writeEntry("current_x", x_d);
     config.writeEntry("current_y", y_d);
 }
 
 void MovingScene::init(const KConfigGroup &config)
 {
-     m_imageIsPainted = false;
      m_wallpaper = config.readEntry("wallpaper", \
"/usr/share/wallpapers/Air/contents/images/1280x800.jpg"); +     m_moveWithMouse = \
config.readEntry("movewithmouse", false);  x_d = config.readEntry("current_x", 0);
      y_d = config.readEntry("current_y", 0);
-     m_pixmap = QPixmap(m_wallpaper);
+     m_image = QImage(m_wallpaper);
+     
+     if(m_moveWithMouse) {
+         connect(m_timer, SIGNAL(timeout()), this, SLOT(updateWallpaper()));
+     } else {
+         disconnect(m_timer, SIGNAL(timeout()), this, SLOT(updateWallpaper()));
+     }
 }
 
 void MovingScene::setWallpaper(const QString& url)
@@ -118,16 +137,36 @@
 {
     Q_UNUSED(exposedRect);
 
-    if ( m_imageIsPainted == false)
-    {
-        QRectF area(0, 0, boundingRect().width() + 350, boundingRect().height() + \
                200);
-        painter->drawPixmap(area, m_pixmap, boundingRect());
-        m_imageIsPainted = true;
-        return;
-    }
+//    QTime cTime = QTime::currentTime();
 
-    QRectF area(-x_d, -y_d, boundingRect().width() + 350, boundingRect().height() + \
                200);
-    painter->drawPixmap(area, m_pixmap, boundingRect());
+    int expandW = boundingRect().width() / 3;
+    int expandH = boundingRect().height() / 4;
+
+    QRectF area(-x_d, -y_d, boundingRect().width() + expandW, \
boundingRect().height() + expandH); +    painter->drawImage(area, \
m_image.transformed(QTransform::fromTranslate(-x_d, -y_d)), boundingRect()); +//    \
qDebug() << "paint needed " << cTime.msecsTo(QTime::currentTime())<<"ms";  }
 
+void MovingScene::updateWallpaper()
+{
+    x = m_cursor->pos().x();
+    y = m_cursor->pos().y();
+    x_d = x / 4;
+    y_d = y / 4;
+    emit update(boundingRect());  
+}
+
+void MovingScene::changeMouseBehavior(int movewithmouse)
+{
+    if (movewithmouse) {
+        m_moveWithMouse = true;
+	emit configNeedsSaving();
+	emit settingsChanged(true);
+    } else {
+        m_moveWithMouse = false;
+	emit configNeedsSaving();
+	emit settingsChanged(true);      
+    }
+}
+
 #include "movingscene.moc"
--- trunk/playground/base/plasma/wallpapers/movingscene/movingscene.h \
#1075198:1075199 @@ -30,6 +30,8 @@
     protected slots:
         void setWallpaper(const QString& url);
         void setWallpaper(const KUrl& url);
+        void updateWallpaper();
+	void changeMouseBehavior(int);
 
     signals:
         void settingsChanged(bool);
@@ -41,18 +43,19 @@
         void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
 
     private:
-        bool m_imageIsPainted;
-        long int m_pM;
+        bool m_moveWithMouse;
         int x;
         int y;
         int x_d;
         int y_d;
         KUrlRequester *m_kurl;
+	QCheckBox *m_moveWithMouseCheckBox;
         QVBoxLayout *m_layout;
         QCursor *m_cursor;
         QString m_wallpaper;
-        QPixmap m_pixmap;
+        QImage m_image;
         QWidget *m_configWidget;
+        QTimer *m_timer;
 };
 
 #endif


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

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