[Panel-devel] KDE/kdebase/workspace/plasma

Riccardo Iaconelli ruphy at fsfe.org
Sun May 20 23:01:36 CEST 2007


SVN commit 666767 by ruphy:

The clock now shows (and moves) SVG hands. I had to do an hack on Plasma::Svg to make it work, it was doing strange things with the plasmoid painter, and especially its coordinate system, check the differences in lib/svg.cpp to see what changed.
Still have a couple of problems with hands other than second, and for the black thingy in the middle.
Too tired right now, will check (and hopefully fix) them again tomorrow.
Let's party though! The first (mostly) working plasmoid goes public! Yay!

CCMAIL:panel-devel at kde.org


 M  +1 -0      applets/CMakeLists.txt  
 M  +14 -13    images/clock.svg  
 M  +3 -1      lib/svg.cpp  
 M  +43 -32    plasma/clock.cpp  
 M  +1 -0      plasma/clock.h  


--- trunk/KDE/kdebase/workspace/plasma/applets/CMakeLists.txt #666766:666767
@@ -1 +1,2 @@
 # add_subdirectory( test )
+# add_subdirectory( clock )
--- trunk/KDE/kdebase/workspace/plasma/images/clock.svg #666766:666767
@@ -15,7 +15,7 @@
    width="250"
    height="250"
    version="1.0"
-   sodipodi:docbase="/home/pinheiro/Desktop"
+   sodipodi:docbase="/home/kde4/kde4/kdebase/workspace/plasma/images"
    sodipodi:docname="clock.svg"
    inkscape:output_extension="org.inkscape.output.svg.inkscape"
    inkscape:export-filename="/home/pinheiro/Desktop/clock.png"
@@ -232,8 +232,8 @@
        r="74.609375" />
   </defs>
   <sodipodi:namedview
-     inkscape:window-height="584"
-     inkscape:window-width="796"
+     inkscape:window-height="957"
+     inkscape:window-width="1280"
      inkscape:pageshadow="2"
      inkscape:pageopacity="0.0"
      guidetolerance="10.0"
@@ -248,11 +248,11 @@
      showgrid="false"
      width="250px"
      height="250px"
-     inkscape:zoom="0.72028434"
-     inkscape:cx="-3.3264214"
-     inkscape:cy="218.71345"
-     inkscape:window-x="271"
-     inkscape:window-y="303"
+     inkscape:zoom="4"
+     inkscape:cx="80.45"
+     inkscape:cy="85.596251"
+     inkscape:window-x="0"
+     inkscape:window-y="0"
      inkscape:current-layer="svg2" />
   <g
      id="ClockFace"
@@ -1090,19 +1090,20 @@
   </g>
   <path
      style="opacity:1;fill:#606060;fill-opacity:1;stroke:none;stroke-width:8;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:1.08779998;stroke-opacity:1"
-     d="M 122.99143,42.582362 L 122.99143,122.52565 C 122.41518,122.88047 122.03871,123.48944 122.03857,124.20437 C 122.03857,124.91926 122.41504,125.57364 122.99143,125.92846 L 122.99143,129.14978 L 125.12378,129.14978 L 125.12378,125.92846 C 125.71527,125.57681 126.12208,124.93041 126.12208,124.20437 C 126.12208,123.47831 125.71527,122.87731 125.12378,122.52565 L 125.12378,42.582362 L 122.99143,42.582362 z "
+     d="M 123.68922,207.89978 L 123.68922,127.95649 C 123.11297,127.60167 122.7365,126.9927 122.73636,126.27777 C 122.73636,125.56288 123.11283,124.9085 123.68922,124.55368 L 123.68922,121.33236 L 125.82157,121.33236 L 125.82157,124.55368 C 126.41306,124.90533 126.81987,125.55173 126.81987,126.27777 C 126.81987,127.00383 126.41306,127.60483 125.82157,127.95649 L 125.82157,207.89978 L 123.68922,207.89978 z "
      id="HourHand"
      inkscape:label="#rect3745" />
   <path
      id="MinuteHand"
-     d="M 216.56052,123.87281 L 125.8679,123.87282 C 125.55991,123.37262 125.03131,123.04583 124.41073,123.04571 C 123.79018,123.04571 123.22218,123.37249 122.91417,123.87282 L 120.118,123.87281 L 120.11799,125.72374 L 122.91418,125.72374 C 123.21942,126.23718 123.78052,126.59029 124.41072,126.5903 C 125.04097,126.5903 125.56265,126.23718 125.86791,125.72374 L 216.56051,125.72374 L 216.56052,123.87281 z "
+     d="M 123.85954,218.88897 L 123.72604,128.19644 C 123.22539,127.88919 122.89782,127.36107 122.89679,126.7405 C 122.89587,126.11995 123.22181,125.55146 123.72169,125.24271 L 123.71757,122.44655 L 125.5685,122.44381 L 125.57261,125.24 C 126.0865,125.54449 126.44043,126.10507 126.44138,126.73526 C 126.4423,127.36551 126.08995,127.88772 125.57696,128.19373 L 125.71047,218.88623 L 123.85954,218.88897 z "
      style="opacity:1;fill:#606060;fill-opacity:1;stroke:none;stroke-width:8;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:1.08779998;stroke-opacity:1"
      sodipodi:nodetypes="ccsccccsccc"
-     inkscape:transform-center-x="-47.163748"
-     inkscape:label="#path3750" />
+     inkscape:transform-center-x="-0.0047679295"
+     inkscape:label="#path3750"
+     inkscape:transform-center-y="47.163723" />
   <path
      style="fill:#cc5457;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-     d="M 131.65827,114.43329 L 133.0557,115.83073 L 64.764947,182.89344 L 131.65827,114.43329 z "
+     d="M 125.71146,119.57604 L 123.7352,119.58282 L 124.93134,215.28863 L 125.71146,119.57604 z "
      id="SecondHand"
      sodipodi:nodetypes="cccc"
      inkscape:label="#path3752" />
--- trunk/KDE/kdebase/workspace/plasma/lib/svg.cpp #666766:666767
@@ -146,8 +146,10 @@
 
 void Svg::paint( QPainter* painter, const QRectF& rect, const QString& elementID )
 {
+//     QPixmap pix(rect.width(), rect.height());
     QPixmap pix;
-    d->findInCache( painter, pix, elementID );
+    QPainter *pain = new QPainter();
+    d->findInCache( pain, pix, elementID );
 
 /*    QMatrix matrix = painter->worldMatrix();
     painter->setWorldMatrix( QMatrix() );*/
--- trunk/KDE/kdebase/workspace/plasma/plasma/clock.cpp #666766:666767
@@ -28,6 +28,8 @@
 #include <QGraphicsScene>
 #include <QStyleOptionGraphicsItem>
 
+#include <QSvgRenderer>
+
 #include <KDebug>
 #include <KLocale>
 
@@ -41,7 +43,6 @@
       QGraphicsItem(parent)
 {
     setFlags(QGraphicsItem::ItemIsMovable); // | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
-
     Plasma::DataEngine* timeEngine = Plasma::Interface::self()->loadDataEngine("time");
     if (timeEngine) {
         timeEngine->connectSource("time", this);
@@ -71,54 +72,64 @@
 void Clock::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
 {
     Q_UNUSED(widget)
+    p->setRenderHint(QPainter::SmoothPixmapTransform);
 
     qreal seconds = 6.0 * m_time.second();
     qreal minutes = 6.0 * m_time.minute();
     qreal hours = 30.0 * m_time.hour();
 
+    QRectF rrr(0, 0, 0, 0);
     QRectF boundRect = boundingRect();
-
-    QRectF r = option->exposedRect;
-    p->setRenderHint(QPainter::SmoothPixmapTransform);
-
     QSizeF clockSize = m_theme->elementSize("ClockFace");
     m_theme->paint(p, boundRect, "ClockFace");
-/*
+    QSize elementSize;
+
     p->save();
-    p->translate(clockSize.width() / 2, clockSize.height() / 2);
-    p->rotate(hours);
-    QSizeF elementSize = m_theme->elementSize("HourHand");
-    QRectF rect = QRectF(-(elementSize.width() / 2), -(elementSize.height() - 32),
-                         elementSize.width(), elementSize.height());
-    m_theme->paint(p, rect, "HourHand");
+      p->translate(clockSize.height()/2, clockSize.width()/2);
+      p->rotate(seconds-90);
+      elementSize = m_theme->elementSize("SecondHand");
+      m_theme->resize(elementSize);
+      rrr.setSize(elementSize);
+      m_theme->paint(p, rrr, "SecondHand");
+//     p->drawRect(rrr);
     p->restore();
 
+    elementSize = QSize(0, 0);
+
     p->save();
-    p->translate(clockSize.width() / 2, clockSize.height() / 2);
-    p->rotate(minutes);
-    elementSize = m_theme->elementSize("MinuteHand");
-    rect = QRectF(-(elementSize.width() / 2),-(elementSize.height() - 16),
-                  elementSize.width(), elementSize.height());
-    m_theme->paint(p, rect, "MinuteHand");
+      p->translate(clockSize.height()/2, clockSize.width()/2);
+      p->rotate(hours-90);
+#warning FIXME: Need to uncomment these 3 linse, but (dunno why) if I calculate the size, I get 0 witdth.
+//     elementSize = m_theme->elementSize("HourHand");
+//     m_theme->resize(elementSize);
+//     rrr.setSize(elementSize);
+      m_theme->paint(p, rrr, "HourHand");
     p->restore();
 
+    elementSize = QSize(0, 0);
+
     p->save();
-    p->translate(clockSize.width() / 2, clockSize.width() / 2);
-    p->rotate(seconds);
-    elementSize = m_theme->elementSize("SecondHand");
-    rect = QRectF(-(elementSize.width() / 2),-(elementSize.height() - 16),
-                  elementSize.width(), elementSize.height());
-    m_theme->paint(p, rect, "SecondHand");
+      p->translate(clockSize.height()/2, clockSize.width()/2);
+      p->rotate(minutes-90);
+//       elementSize = m_theme->elementSize("MinuteHand");
+//       m_theme->resize(elementSize);
+//       rrr.setSize(elementSize);
+      m_theme->paint(p, rrr, "MinuteHand");
+//     p->drawRect(rrr);
     p->restore();
 
-    p->save();
-    p->translate(clockSize.width() / 2, clockSize.width() / 2);
-    m_theme->paint(p, 0, 0, "HandCenterScrew");
-    p->restore();*/
-
-    m_theme->paint(p, boundRect, "Glass");
-    p->drawText(100, 100, m_time.toString());
-//     p->drawRect(boundRect);
+//FIXME: re-enable this.
+//     elementSize = QSize(0, 0);
+// 
+//     p->save();
+//     p->translate(clockSize.width() / 2, clockSize.width() / 2);
+//     elementSize = m_theme->elementSize("HandCenterScrew");
+//     m_theme->resize(elementSize);
+//     rrr.setSize(elementSize);
+//     m_theme->paint(p, 0, 0, "HandCenterScrew");
+//     p->restore();
+    p->drawText(boundingRect().width()/2, (boundingRect().height()/2)+32, m_time.toString());
+    m_theme->resize(boundingRect().size());
 }
 /*
 QVariant Clock::itemChange(GraphicsItemChange change, const QVariant &value)
--- trunk/KDE/kdebase/workspace/plasma/plasma/clock.h #666766:666767
@@ -40,6 +40,7 @@
 #include "dataengine.h"
 
 class QTimer;
+
 namespace Plasma
 {
     class Svg;


More information about the Panel-devel mailing list