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

List:       kde-commits
Subject:    playground/base/plasma/applets/moodbar
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2008-09-30 20:31:01
Message-ID: 1222806661.985628.4903.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 866428 by aseigo:

* proper .desktop
* proper painting
* lots of unecessary code ripped out
* proper configuration


 M  +7 -2      amarok_moodbar.cpp  
 M  +1 -0      amarok_moodbar.h  
 M  +30 -89    moodbarConfig.ui  
 M  +1 -1      plasma-applet-moodbar.desktop  
 M  +30 -60    plasmamoodbar.cpp  
 M  +5 -11     plasmamoodbar.h  


--- trunk/playground/base/plasma/applets/moodbar/amarok_moodbar.cpp #866427:866428
@@ -325,6 +325,7 @@
 #include <QPainter>
 #include <string.h> // for memset()
 
+#include <KDebug>
 
 //class include
 #include "amarok_moodbar.h"
@@ -991,6 +992,10 @@
 //     m_bundle->moodbarJobEvent( newState );
 // }
 
+QSize HMoodbar::size() const
+{
+    return m_pixmap.size();
+}
 
 // Draw the moodbar onto a pixmap of the given dimensions and return
 // it.  This is mostly Gav's original code, cut and pasted from
@@ -1109,9 +1114,9 @@
     if( path.isEmpty() )
       return false;
 
-    QFile moodFile( path );
+    QFile moodFile( path.path() );
 
-    if( !QFile::exists( path )  ||
+    if( !QFile::exists( path.path() )  ||
          !moodFile.open( IO_ReadOnly ) )
     {
 
--- trunk/playground/base/plasma/applets/moodbar/amarok_moodbar.h #866427:866428
@@ -81,6 +81,7 @@
   //bool dataExists( void );
   //bool canHaveMood( void );
   //void load( void );
+  QSize size() const;
   QPixmap draw( int width, int height );
 
   int hueSort( void ) const
--- trunk/playground/base/plasma/applets/moodbar/moodbarConfig.ui #866427:866428
@@ -5,105 +5,46 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>599</width>
-    <height>380</height>
+    <width>425</width>
+    <height>41</height>
    </rect>
   </property>
-  <layout class="QVBoxLayout" >
-   <item>
-    <layout class="QHBoxLayout" >
-     <item>
-      <widget class="QLabel" name="labelSize_3" >
-       <property name="text" >
-        <string>moodbar file:</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="lineEdit" />
-     </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" >
-     <property name="spacing" >
-      <number>5</number>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <widget class="QLabel" name="labelSize_3" >
+     <property name="text" >
+      <string>Moodbar File: </string>
      </property>
-     <property name="leftMargin" >
-      <number>0</number>
+     <property name="buddy" >
+      <cstring>m_file</cstring>
      </property>
-     <property name="topMargin" >
-      <number>0</number>
-     </property>
-     <property name="rightMargin" >
-      <number>0</number>
-     </property>
-     <property name="bottomMargin" >
-      <number>0</number>
-     </property>
-     <item>
-      <widget class="QLabel" name="labelSize_2" >
-       <property name="text" >
-       <string>Width  of moodbar:</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QSpinBox" name="spinWidth" >
-       <property name="toolTip" >
-        <string/>
-       </property>
-       <property name="whatsThis" >
-        <string/>
-       </property>
-       <property name="maximum" >
-        <number>20000</number>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    </widget>
    </item>
-   <item>
-    <layout class="QHBoxLayout" >
-     <property name="spacing" >
-      <number>5</number>
+   <item row="0" column="1" >
+    <widget class="KUrlRequester" name="m_file" />
+   </item>
+   <item row="1" column="1" >
+    <spacer name="verticalSpacer" >
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
      </property>
-     <property name="leftMargin" >
-      <number>0</number>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>17</width>
+       <height>6</height>
+      </size>
      </property>
-     <property name="topMargin" >
-      <number>0</number>
-     </property>
-     <property name="rightMargin" >
-      <number>0</number>
-     </property>
-     <property name="bottomMargin" >
-      <number>0</number>
-     </property>
-     <item>
-      <widget class="QLabel" name="labelSize" >
-       <property name="text" >
-       <string>Height of moodbar:</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QSpinBox" name="spinHeight" >
-       <property name="toolTip" >
-        <string/>
-       </property>
-       <property name="whatsThis" >
-        <string/>
-       </property>
-       <property name="maximum" >
-        <number>200</number>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    </spacer>
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>KUrlRequester</class>
+   <extends>QFrame</extends>
+   <header>kurlrequester.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>
--- trunk/playground/base/plasma/applets/moodbar/plasma-applet-moodbar.desktop \
#866427:866428 @@ -33,7 +33,7 @@
 X-KDE-Library=plasma_applet_moodbar
 X-KDE-PluginInfo-Author=Mario Young
 X-KDE-PluginInfo-Email=maye.co@gmail.com
-X-KDE-PluginInfo-Name=plasma_applet_moodbar
+X-KDE-PluginInfo-Name=moodbar
 X-KDE-PluginInfo-Version=0.0.1
 X-KDE-PluginInfo-Website=http://plasma.kde.org/
 X-KDE-PluginInfo-Category=Miscellaneous
--- trunk/playground/base/plasma/applets/moodbar/plasmamoodbar.cpp #866427:866428
@@ -20,8 +20,10 @@
 
 //Qt includes
 #include <QPainter>
+#include <QStyleOptionGraphicsItem>
 
 //KDE includes
+#include <KConfigDialog>
 #include <KDebug>
 #include <KLocale>
 #include <KIconLoader>
@@ -42,93 +44,61 @@
 
 PlasmaMoodBar::PlasmaMoodBar(QObject *parent, const QVariantList &args)
     : Plasma::Applet(parent, args),
-      m_dialog(0)
+      m_file(KStandardDirs::locate("data", "moodbar/01_-_My_Fairy_King.mood"))
 {
+    kDebug() << "will read" << m_file << m_file.path();
     setHasConfigurationInterface(true);
 
-    KConfigGroup cg = config();
-    m_pixelheight = cg.readEntry("height", 100);
-    m_pixelwidth = cg.readEntry("width", 500);
-
     m_mood = new HMoodbar();
 
-    m_mood->readFile(KStandardDirs::locate("data", \
                "moodbar/01_-_My_Fairy_King.mood"));
-    m_pixmap = m_mood->draw ( m_pixelwidth, m_pixelheight );
+    //FIXME: eventually this shouldn't be here
+    m_mood->readFile(m_file);
 
-    qDebug( "moodbar constructor" );
 
+    resize(500, 100);
+    qDebug( "moodbar constructor" );
 }
 
 PlasmaMoodBar::~PlasmaMoodBar()
 {
-
-    KConfigGroup cg = config();
-    cg.writeEntry( "width", m_pixelwidth );
-    cg.writeEntry( "height", m_pixelheight );
-
+    delete m_mood;
 }
 
-QSizeF PlasmaMoodBar::contentSizeHint() const
+void PlasmaMoodBar::createConfigurationInterface(KConfigDialog *parent)
 {
+    QWidget *w = new QWidget;
+    ui.setupUi(w);
+    parent->mainWidget()->layout()->setMargin(0);
+    //parent->setButtons( KDialog::Ok | KDialog::Cancel:Apply );
+    parent->addPage(w, i18n("Moodbar"));
 
-    return QSizeF(m_pixelwidth, m_pixelheight);
+    connect( parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()) );
+    connect( parent, SIGNAL(okClicked()), this, SLOT(configAccepted()) );
 
+    //m_dialog->show();
 }
 
-void PlasmaMoodBar::showConfigurationInterface()
+void PlasmaMoodBar::paintInterface(QPainter *p, const QStyleOptionGraphicsItem \
*option, const QRect &rect)  {
-
-     if (m_dialog == 0) {
-
-        m_dialog = new KDialog;
-        m_dialog->setCaption( i18n("Configure PlasmaMoodBar") );
-
-        ui.setupUi(m_dialog->mainWidget());
-        m_dialog->mainWidget()->layout()->setMargin(0);
-        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()) );
-
+    if (rect.size() != m_pixmap.size()) {
+        QSize s = contentsRect().size().toSize();
+        m_pixmap = m_mood->draw(s.width(), s.height());
     }
 
-    ui.spinWidth->setValue( m_pixelwidth );
-    ui.spinHeight->setValue( m_pixelheight );
-
-    m_dialog->show();
-
+    // draw just what is needed
+    QRect drawArea = rect.intersected(option->rect);
+    p->drawPixmap(drawArea, m_pixmap, drawArea.translated(-rect.x(), -rect.y()));
 }
 
-void PlasmaMoodBar::paintInterface(QPainter *p, const QStyleOptionGraphicsItem \
                *option, const QRect &rect)
-{
-
-    Q_UNUSED(option)
-    Q_UNUSED(rect)
-
-    p->setOpacity(0.7);
-    p->drawText(rect, Qt::AlignCenter, QString("Moodbar Applet !!!!!"));
-    p->drawPixmap( 0, 0, m_pixmap );
-
-
-}
-
 void PlasmaMoodBar::configAccepted()
 {
+    KUrl newUrl = ui.m_file->url();
 
-    KConfigGroup cg = config();
-
-    QGraphicsItem::update();
-    m_pixelheight = ui.spinHeight->value();
-    m_pixelwidth = ui.spinWidth->value();
-    m_pixmap = m_mood->draw ( m_pixelwidth, m_pixelheight );
-
-    cg.writeEntry( "width", m_pixelwidth );
-    cg.writeEntry( "height", m_pixelheight );
-
-    updateConstraints();
-
+    if (newUrl.isValid() && newUrl != m_file) {
+        m_file = newUrl;
+        m_mood->readFile(m_file);
+    }
     qDebug( "config accepted" );
-
 }
 
 #include "plasmamoodbar.moc"
--- trunk/playground/base/plasma/applets/moodbar/plasmamoodbar.h #866427:866428
@@ -44,24 +44,18 @@
         ~PlasmaMoodBar();
 
         void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem \
                *option, const QRect &contentsRect);
-        QSizeF contentSizeHint() const;
 
     public slots:
-        void showConfigurationInterface();
+        void createConfigurationInterface(KConfigDialog *parent);
 
     protected slots:
         void configAccepted();
 
     private:
-
-        KDialog                 *m_dialog;
-        HMoodbar                *m_mood;
-        int                     m_pixelheight;
-        int                     m_pixelwidth;
-        QPixmap                 m_pixmap;
-        QGraphicsPixmapItem     m_pixmapitem;
-        Ui::moodbarConfig       ui;
-
+        HMoodbar *m_mood;
+        KUrl m_file;
+        QPixmap m_pixmap;
+        Ui::moodbarConfig ui;
 };
 
 K_EXPORT_PLASMA_APPLET(moodbar, PlasmaMoodBar)


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

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