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

List:       kde-commits
Subject:    extragear/plasma/applets/twitter
From:       Andre Duffeck <andre () duffeck ! de>
Date:       2008-05-08 11:46:44
Message-ID: 1210247204.930853.27214.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 805379 by duffeck:

KDE Twitter compiles and even shows the tweets


 M  +84 -44    twitter.cpp  
 M  +13 -6     twitter.h  


--- trunk/extragear/plasma/applets/twitter/twitter.cpp #805378:805379
@@ -31,6 +31,8 @@
 #include <QFontMetrics>
 #include <QGraphicsView>
 #include <QGraphicsLinearLayout>
+#include <QWebPage>
+#include <QWebFrame>
 
 #include <KDebug>
 #include <KIcon>
@@ -38,6 +40,7 @@
 #include <KSharedConfig>
 #include <KDialog>
 #include <KLineEdit>
+#include <KTextEdit>
 #include <KStringHandler>
 #include <KWallet/Wallet>
 #include <KMessageBox>
@@ -46,24 +49,27 @@
 #include <plasma/svg.h>
 #include <plasma/theme.h>
 #include <plasma/dataengine.h>
-#include <plasma/widgets/lineedit.h>
+// #include <plasma/widgets/lineedit.h>
 #include <plasma/widgets/flash.h>
 #include <plasma/widgets/icon.h>
+#include <plasma/widgets/webcontent.h>
 
 Q_DECLARE_METATYPE(Plasma::DataEngine::Data)
 
 Twitter::Twitter(QObject *parent, const QVariantList &args)
     : Plasma::Applet(parent, args),
-      m_dialog(0), m_lastTweet(0), m_wallet(0), m_walletWait(None)
+      m_dialog(0), m_lastTweet(0), m_wallet(0), m_walletWait(None),
+      m_colorScheme(0)
 {
     setHasConfigurationInterface(true);
-    setContentSize(300,150); //should be an ok default
+    resize(600, 350);
 }
 
 void Twitter::init()
 {
+    m_colorScheme = new KColorScheme(QPalette::Active, KColorScheme::View, \
Plasma::Theme::defaultTheme()->colorScheme());  m_theme = new Plasma::Svg(this);
-    m_theme.setImagePath("widgets/twitter");
+    m_theme->setImagePath("widgets/twitter");
     //config stuff
     KConfigGroup cg = config();
     m_username = cg.readEntry( "username" );
@@ -79,24 +85,25 @@
     }
 
     //ui setup
-    m_layout = new QGraphicsLinearLayout( Qt::Vertical, this );
-    m_layout->setMargin( 0 );
+    m_layout = new QGraphicsLinearLayout( Qt::Vertical );
+    setLayout( m_layout );
     m_layout->setSpacing( 0 );
 
+    QGraphicsLinearLayout *flashLayout = new QGraphicsLinearLayout( Qt::Horizontal \
);  m_flash = new Plasma::Flash( this );
+    m_flash->setMinimumSize( 0, 20 );
     m_flash->setColor( Qt::gray );
     QFont fnt = qApp->font();
     fnt.setBold( true );
     QFontMetrics fm( fnt );
-    m_flash->resize( QSize(250, fm.height()) );
-    m_flash->setMaximumSize( QSizeF(250, fm.height()+4 ) );
     m_flash->setFont( fnt );
-    m_layout->addItem( m_flash );
+    m_flash->flash( "test", 20000 );
+    flashLayout->addItem( m_flash );
+    flashLayout->setItemSpacing( 0, 175 );
+    m_layout->addItem( flashLayout );
 
-
     m_headerLayout = new QGraphicsLinearLayout( Qt::Horizontal );
-    m_headerLayout->setMargin( 5 );
-    m_headerLayout->setMargin( Plasma::BottomMargin, 10 );
+    m_headerLayout->setContentsMargins( 5, 5, 5, 10 );
     m_headerLayout->setSpacing( 5 );
     m_layout->addItem( m_headerLayout );
 
@@ -109,14 +116,18 @@
     m_icon->setMaximumSize( iconSize );
     m_headerLayout->addItem( m_icon );
 
-    m_statusEdit = new Plasma::LineEdit( this );
-    m_statusEdit->hide();
-    m_statusEdit->setStyled( true );
-    m_statusEdit->setTextWidth( 250 );
-    connect( m_statusEdit->document(), SIGNAL(contentsChanged()), \
                SLOT(geometryChanged()) ); //FIXME no such slot
-    connect( m_statusEdit, SIGNAL(editingFinished()), SLOT(updateStatus()) );
-    m_headerLayout->addItem( m_statusEdit );
+    m_statusProxy = new QGraphicsProxyWidget( this );
+    m_statusEdit = new KTextEdit();
+    m_statusEdit->setFrameShape( QFrame::NoFrame );
+    m_statusEdit->setAttribute( Qt::WA_NoSystemBackground );
+    m_statusEdit->setTextBackgroundColor( QColor(0,0,0,0) );
+    m_statusEdit->viewport()->setAutoFillBackground( false );
+    m_statusEdit->setTextColor( m_colorScheme->foreground().color() );
+    m_statusProxy->setWidget( m_statusEdit );
+    m_headerLayout->addItem( m_statusProxy );
 
+    m_layout->addStretch();
+
     //hook up some sources
     m_engine->connectSource("LatestImage", this);
     m_engine->connectSource("Error:UserImages", this);
@@ -203,7 +214,7 @@
     Plasma::DataEngine::Data conf = \
m_engine->property("config").value<Plasma::DataEngine::Data>();  conf[m_username] = \
m_password;  m_engine->setProperty("config", QVariant::fromValue(conf));
-    m_statusEdit->setVisible( !( m_username.isEmpty() || m_password.isEmpty() ) );
+//     m_statusEdit->setVisible( !( m_username.isEmpty() || m_password.isEmpty() ) \
);  downloadHistory();
 }
 
@@ -277,33 +288,48 @@
 
 void Twitter::showTweets()
 {
+    prepareGeometryChange();
     // Adjust the number of the TweetWidgets if the configuration has changed
     // Add more tweetWidgets if there are not enough
     while( m_tweetWidgets.size() < m_historySize ) {
         QGraphicsLinearLayout *tweetLayout = new QGraphicsLinearLayout( \
                Qt::Horizontal );
-        tweetLayout->setMargin( 5 );
+        tweetLayout->setContentsMargins( 0, 5, 0, 5 );
         tweetLayout->setSpacing( 5 );
-        m_layout->addItem( tweetLayout );
+        m_layout->insertItem( m_layout->count()-1, tweetLayout );
 
-        Plasma::LineEdit *e = new Plasma::LineEdit( this );
-        e->setTextWidth( 300 );
-        e->setStyled( false );
-        e->setEnabled( false );
-        e->setCursor( Qt::ArrowCursor );
-        e->setAcceptedMouseButtons( Qt::NoButton );
+        KTextEdit *c = new KTextEdit();
+        QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget( this );
+        proxy->setWidget( c );
+        c->setCursor( Qt::ArrowCursor );
+        c->setFrameShape(QFrame::NoFrame);
+        c->setAttribute(Qt::WA_NoSystemBackground);
+        c->setTextBackgroundColor(QColor(0,0,0,0));
+        c->viewport()->setAutoFillBackground(false);
+        c->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+        c->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
 
         Plasma::Icon *icon = new Plasma::Icon( this );
         QSizeF iconSize = icon->sizeFromIconSize(30);
         icon->setMinimumSize( iconSize );
         icon->setMaximumSize( iconSize );
+
+        Plasma::Icon *favIcon = new Plasma::Icon( this );
+        QSizeF favIconSize = icon->sizeFromIconSize(16);
+        favIcon->setMinimumSize( favIconSize );
+        favIcon->setMaximumSize( favIconSize );
+        
+
         tweetLayout->addItem( icon );
-        tweetLayout->addItem( e );
+        tweetLayout->addItem( proxy );
+        tweetLayout->addItem( favIcon );
         tweetLayout->updateGeometry();
 
         Tweet t;
         t.layout = tweetLayout;
         t.icon = icon;
-        t.edit = e;
+        t.content = c;
+        t.contentProxy = proxy;
+        t.favIcon = favIcon;
 
         m_tweetWidgets.append( t );
     }
@@ -312,45 +338,54 @@
         Tweet t = m_tweetWidgets[m_tweetWidgets.size()-1];
         m_layout->removeItem( t.layout );
         delete t.icon;
-        delete t.edit;
+        delete t.content;
         delete t.layout;
         m_tweetWidgets.removeAt( m_tweetWidgets.size()-1 );
     }
 
     int i = 0;
     int pos = m_tweetMap.keys().size() - 1;
-    KColorScheme colorScheme(QPalette::Active, KColorScheme::View, \
Plasma::Theme::self()->colors());  while(i < m_historySize && pos >= 0 ) {
         Plasma::DataEngine::Data tweetData = m_tweetMap[m_tweetMap.keys()[pos]];
         QString user = tweetData.value( "User" ).toString();
+        QPixmap favIcon = tweetData.value("SourceFavIcon").value<QPixmap>();
 
         Tweet t = m_tweetWidgets[i];
         t.icon->setIcon( QIcon(m_pictureMap[user]) );
         QSizeF iconSize = t.icon->sizeFromIconSize(30);
         t.icon->setMinimumSize( iconSize );
         t.icon->setMaximumSize( iconSize );
-        t.icon->updateGeometry();
 
+        QString sourceString;
+        if( favIcon.isNull() ) {
+            sourceString = i18n(" from %1", tweetData.value( "Source" ).toString());
+        }
         QString html = "<table cellspacing='0' spacing='5'>";
-        html += i18n( "<tr><td align='left' width='1%'><font \
color='%2'>%1</font></td><td align='right' width='99%'><font color='%2'>%3 from \
%4</font></td></tr>", user, \
                colorScheme.foreground(KColorScheme::InactiveText).color().name(),
-                timeDescription( tweetData.value( "Date" ).toDateTime() ),
-                tweetData.value( "Source" ).toString() );
+        html += i18n( "<tr><td align='left' width='1%'><font \
color='%2'>%1</font></td><td align='right' width='99%'><font \
color='%2'>%3%4</font></td></tr>", user, \
m_colorScheme->foreground(KColorScheme::InactiveText).color().name(), +               \
                timeDescription( tweetData.value( "Date" ).toDateTime() ), \
                sourceString);
         html += QString( "<tr><td colspan='2'><font color='%1'>%2</font></td></tr>" \
                )
-                .arg( colorScheme.foreground().color().name()).arg( tweetData.value( \
"Status" ).toString() ); +                .arg( \
m_colorScheme->foreground().color().name()).arg( tweetData.value( "Status" \
).toString() );  html += "</table>";
-        t.edit->setHtml( html );
+        t.content->setHtml( html );
+        t.content->document()->setTextWidth(t.content->width());
+        t.content->setMinimumHeight(t.content->document()->size().height());
+        t.content->update();
+
+        if( !favIcon.isNull() ) {
+            t.favIcon->setIcon( QIcon(favIcon) );
+        }
+
         ++i;
         --pos;
     }
-
-    m_layout->invalidate();
+    resize(m_layout->sizeHint(Qt::PreferredSize));
     updateGeometry();
 }
 
-void Twitter::createConfigurationInterface()
+void Twitter::createConfigurationInterface(KConfigDialog *parent)
 {
      if (m_dialog == 0) {
-        m_dialog = new KDialog;
+        m_dialog = new KDialog();
         m_dialog->setPlainCaption(i18n("Configure Twitter Applet"));
 
         m_dialog->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply );
@@ -467,6 +502,7 @@
 Twitter::~Twitter()
 {
     delete m_dialog;
+    delete m_colorScheme;
 }
 
 void Twitter::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, \
const QRect &contentsRect) @@ -477,11 +513,15 @@
     m_theme->paint( p, QRect(contentsRect.x()+contentsRect.width()-75, \
m_flash->geometry().y(), 75, 14), "twitter" );  
     foreach( Tweet t, m_tweetWidgets ) {
-        QRectF tweetRect(0, t.layout->geometry().y(), contentSize().width(), \
t.layout->geometry().height()); +        QRectF tweetRect(0, \
t.layout->geometry().y(), size().width(), t.layout->geometry().height());  \
m_theme->paint( p, tweetRect, "tweet" );  }
-    QRectF headerRect(0, m_headerLayout->geometry().y(), contentSize().width(), \
m_headerLayout->geometry().height()-5); +    QRectF headerRect(0, \
m_headerLayout->geometry().y(), size().width(), \
m_headerLayout->geometry().height()-5);  m_theme->paint( p, headerRect, "tweet" );
+
+    p->setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
+    p->setPen( m_colorScheme->shade( KColorScheme::LightShade ) );
+    p->drawRoundedRect( m_statusEdit->geometry(), 5, 5 );
 }
 
 
--- trunk/extragear/plasma/applets/twitter/twitter.h #805378:805379
@@ -24,6 +24,7 @@
 #include <QLabel>
 #include <QDomDocument>
 #include <QMap>
+#include <QGraphicsProxyWidget>
 
 #include <plasma/applet.h>
 #include <plasma/dataengine.h>
@@ -31,9 +32,11 @@
 
 class KDialog;
 class KLineEdit;
+class KTextEdit;
 class QSpinBox;
 class QCheckBox;
 class QGraphicsLinearLayout;
+class KColorScheme;
 
 namespace KWallet
 {
@@ -43,15 +46,17 @@
 namespace Plasma
 {
     class Svg;
-    class LineEdit;
     class Flash;
     class Icon;
+    class WebContent;
 }
 
 struct Tweet {
     QGraphicsLinearLayout *layout;
     Plasma::Icon *icon;
-    Plasma::LineEdit *edit;
+    KTextEdit *content;
+    QGraphicsProxyWidget *contentProxy;
+    Plasma::Icon *favIcon;
 };
 
 class Twitter : public Plasma::Applet
@@ -67,7 +72,7 @@
 
     public slots:
         void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
-        void createConfigurationInterface();
+        void createConfigurationInterface( KConfigDialog *parent );
         /**
          * read from the opened KWallet
          * @param success whether we got to open it
@@ -109,9 +114,9 @@
 
         Plasma::Svg *m_theme;
         KDialog *m_dialog;
-        Plasma::LineEdit *m_title;
-        Plasma::LineEdit *m_statusEdit;
-        Plasma::LineEdit *m_historyEdit;
+        KTextEdit *m_statusEdit;
+        QGraphicsProxyWidget *m_statusProxy;
+        Plasma::WebContent *m_historyEdit;
         Plasma::Flash *m_flash;
         Plasma::Icon *m_icon;
         QGraphicsLinearLayout *m_layout;
@@ -140,6 +145,8 @@
         KWallet::Wallet *m_wallet;
         enum WalletWait { None=0, Read, Write };
         WalletWait m_walletWait;
+
+        KColorScheme *m_colorScheme;
 };
 
 K_EXPORT_PLASMA_APPLET(twitter, Twitter)


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

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