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

List:       kde-commits
Subject:    [gluon/creator-distributionsupport-shreya] /: Some testing
From:       Shreya Pandit <shreya () shreyapandit ! com>
Date:       2012-08-18 11:43:51
Message-ID: 20120818114351.134B7A6094 () git ! kde ! org
[Download RAW message or body]

Git commit 4a82e502793590cdad3796db039ff7adc17cb065 by Shreya Pandit.
Committed on 18/08/2012 at 13:42.
Pushed by pandit into branch 'creator-distributionsupport-shreya'.

Some testing

A  +229  -0    creator/plugins/docks/distributiondock/commentsDelegate.cpp     \
[License: GPL (v2+)] A  +67   -0    \
creator/plugins/docks/distributiondock/commentsDelegate.h     [License: GPL (v2+)] D  \
+0    -51   player/lib/models/comments.gdl

http://commits.kde.org/gluon/4a82e502793590cdad3796db039ff7adc17cb065

diff --git a/creator/plugins/docks/distributiondock/commentsDelegate.cpp \
b/creator/plugins/docks/distributiondock/commentsDelegate.cpp new file mode 100644
index 0000000..311b318
--- /dev/null
+++ b/creator/plugins/docks/distributiondock/commentsDelegate.cpp
@@ -0,0 +1,229 @@
+/*****************************************************************************
+ * This file is part of the Gluon Development Platform
+ * Copyright (c) 2011 Laszlo Papp <lpapp@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *****************************************************************************/
+
+#include "commentsDelegate.h"
+
+//#include "views/gametextlabel.h"
+
+#include "player/lib/models/commentitemsmodel.h"
+
+#include <KDE/KDebug>
+
+#include <QtGui/QPainter>
+#include <QtGui/QSortFilterProxyModel>
+#include <QtGui/QApplication>
+#include <QtGui/QToolButton>
+
+enum
+{
+    DelegateCommentAuthor,
+    DelegateCommentTitle,
+    DelegateCommentBody,
+    DelegateCommentDateTime,
+    DelegateCommentRating,
+    DelegateCommentReplyButton
+};
+
+static const int PreviewWidth = 96;
+static const int PreviewHeight = 72;
+
+
+CommentsDelegate::CommentsDelegate( QAbstractItemView* itemView, QObject* parent )
+    : KWidgetItemDelegate( itemView, parent )
+{
+}
+
+CommentsDelegate::~CommentsDelegate()
+{
+}
+
+bool CommentsDelegate::eventFilter( QObject* watched, QEvent* event )
+{
+    if( event->type() == QEvent::MouseButtonDblClick )
+    {
+        return true;
+    }
+
+    return KWidgetItemDelegate::eventFilter( watched, event );
+}
+
+QList<QWidget*> CommentsDelegate::createItemWidgets() const
+{
+    QList<QWidget*> list;
+
+    KSqueezedTextLabel* author = new KSqueezedTextLabel();
+    author->setOpenExternalLinks( true );
+    // not so nice - work around constness to install the event filter
+    CommentsDelegate* delegate = const_cast<CommentsDelegate*>( this );
+    author->installEventFilter( delegate );
+    list << author;
+
+    KSqueezedTextLabel* title = new KSqueezedTextLabel();
+    title->setOpenExternalLinks( true );
+    list << title;
+
+    KSqueezedTextLabel* dateTime = new KSqueezedTextLabel();
+    dateTime->setOpenExternalLinks( true );
+    list << dateTime;
+
+    KSqueezedTextLabel* rating = new KSqueezedTextLabel();
+    rating->setOpenExternalLinks( true );
+    list << rating;
+
+    KSqueezedTextLabel* body = new KSqueezedTextLabel();
+    body->setOpenExternalLinks( true );
+    body->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding );
+    list << body;
+
+    KPushButton* replyButton = new KPushButton();
+    replyButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding \
); +    list << replyButton;
+    setBlockedEventTypes( replyButton, QList<QEvent::Type>() << \
QEvent::MouseButtonPress +                          << QEvent::MouseButtonRelease << \
QEvent::MouseButtonDblClick ); +    connect( replyButton, SIGNAL(clicked()), \
SLOT(slotReplyClicked()) ); +
+    return list;
+}
+
+void CommentsDelegate::updateItemWidgets( const QList<QWidget*> widgets,
+        const QStyleOptionViewItem& option,
+        const QPersistentModelIndex& index ) const
+{
+    const GluonPlayer::CommentItemsModel* model = qobject_cast<const \
GluonPlayer::CommentItemsModel*>( index.model() ); +    if( !model )
+    {
+        kDebug() << "Warning - Invalid Model!";
+        return;
+    }
+
+    // setup the install button
+    int margin = option.fontMetrics.height() / 2;
+    int right = option.rect.width();
+    int bottom = option.rect.height();
+
+    const_cast<QSize&>( m_buttonSize ) = QSize( 32, 32 );
+
+    KPushButton* replyButton = qobject_cast<KPushButton*>( widgets.at( \
DelegateCommentReplyButton ) ); +    if( replyButton )
+    {
+        replyButton->setVisible( const_cast<GluonPlayer::CommentItemsModel*>( model \
)->isOnline() ); +        replyButton->setIcon( KIcon( "edit-undo" ) );
+        replyButton->setSizePolicy( QSizePolicy::Maximum, \
QSizePolicy::MinimumExpanding ); +        replyButton->resize( m_buttonSize );
+        replyButton->move( right - replyButton->width() - margin, bottom - \
m_buttonSize.height() * 1.5 ); +    }
+
+    KSqueezedTextLabel* author = qobject_cast<KSqueezedTextLabel*>( widgets.at( \
DelegateCommentAuthor ) ); +    if( author )
+    {
+        author->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::MinimumExpanding \
); +        author->resize( right / 5, m_buttonSize.height() );
+        author->move( margin, option.fontMetrics.height() );
+        author->setText( index.data( GluonPlayer::CommentItemsModel::AuthorRole \
).toString() ); +    }
+
+    KSqueezedTextLabel* dateTime = qobject_cast<KSqueezedTextLabel*>( widgets.at( \
DelegateCommentDateTime ) ); +    if( dateTime )
+    {
+        dateTime->resize( author->size().width(), author->size().height() );
+        dateTime->move( author->x() + author->size().width(), author->y() );
+        dateTime->setText( index.data( GluonPlayer::CommentItemsModel::DateTimeRole \
).toString() ); +    }
+
+    KSqueezedTextLabel* title = qobject_cast<KSqueezedTextLabel*>( widgets.at( \
DelegateCommentTitle ) ); +    if( title )
+    {
+        title->resize( dateTime->size().width(), dateTime->size().height() );
+        title->move( dateTime->x() + dateTime->size().width(), dateTime->y() );
+        title->setText( index.data( GluonPlayer::CommentItemsModel::TitleRole \
).toString() ); +    }
+
+    KSqueezedTextLabel* rating = qobject_cast<KSqueezedTextLabel*>( widgets.at( \
DelegateCommentRating ) ); +    if( rating )
+    {
+        rating->resize( title->size().width(), title->size().height() );
+        rating->move( title->x() + title->size().width(), title->y() );
+        rating->setText( index.data( GluonPlayer::CommentItemsModel::RatingRole \
).toString() ); +    }
+
+    KSqueezedTextLabel* body = qobject_cast<KSqueezedTextLabel*>( widgets.at( \
DelegateCommentBody ) ); +    if( body )
+    {
+        body->resize( right - 2 * margin, bottom - author->size().height() - 2 * \
margin ); +        body->move( margin, option.fontMetrics.height()  + \
author->size().height() ); +        body->setText( index.data( \
GluonPlayer::CommentItemsModel::BodyRole ).toString() ); +    }
+}
+
+// draws the preview
+void CommentsDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, \
const QModelIndex& /* index */ ) const +{
+    // int margin = option.fontMetrics.height() / 2;
+
+    QStyle* style = QApplication::style();
+    style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, 0 );
+
+    painter->save();
+
+    if( option.state & QStyle::State_Selected )
+    {
+        painter->setPen( QPen( option.palette.highlightedText().color() ) );
+    }
+    else
+    {
+        painter->setPen( QPen( option.palette.text().color() ) );
+    }
+
+    /* const GluonPlayer::GameItemsModel* realmodel = qobject_cast<const \
GluonPlayer::GameItemsModel*>(index.model()); +
+    int height = option.rect.height();
+    QPoint point(option.rect.left() + margin, option.rect.top() + ((height - \
PreviewHeight) / 2)); +
+    QImage image = KIcon("gluon-cretor").pixmap(32, 32).toImage();
+    if (!image.isNull()) {
+        point.setX((PreviewWidth - image.width())/2 + 5);
+        point.setY(option.rect.top() + ((height - image.height()) / 2));
+        painter->drawImage(point, image);
+
+        QPoint framePoint(point.x() - 5, point.y() - 5);
+        painter->drawPixmap(framePoint, KIcon("gluon-creator").pixmap(32, \
32).scaled(image.width() + 10, image.height() + 10)); +    } else {
+        QRect rect(point, QSize(PreviewWidth, PreviewHeight));
+        painter->drawText(rect, Qt::AlignCenter | Qt::TextWordWrap, i18n("Loading \
Preview")); +    } */
+    painter->restore();
+}
+
+QSize CommentsDelegate::sizeHint( const QStyleOptionViewItem& option, const \
QModelIndex& /* index */ ) const +{
+    QSize size;
+
+    size.setWidth( option.fontMetrics.height() * 4 );
+    size.setHeight( qMax( option.fontMetrics.height() * 7, PreviewHeight ) ); // up \
to 6 lines of text, and two margins +    return size;
+}
+
+void CommentsDelegate::slotReplyClicked()
+{
+    QModelIndex index = focusedIndex();
+    if( index.isValid() )
+    {
+        emit commentReplyClicked( index );
+    }
+}
diff --git a/creator/plugins/docks/distributiondock/commentsDelegate.h \
b/creator/plugins/docks/distributiondock/commentsDelegate.h new file mode 100644
index 0000000..0dfa753
--- /dev/null
+++ b/creator/plugins/docks/distributiondock/commentsDelegate.h
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * This file is part of the Gluon Development Platform
+ * Copyright (c) 2011 Laszlo Papp <lpapp@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *****************************************************************************/
+
+#ifndef GLUON_COMMENTSDELEGATE_H
+#define GLUON_COMMENTSDELEGATE_H
+
+#include <KDE/KIcon>
+#include <KDE/KWidgetItemDelegate>
+#include <KDE/KSqueezedTextLabel>
+#include <KDE/KPushButton>
+#include <KDE/KLocalizedString>
+
+#include <QtGui/QAbstractItemView>
+#include <QtGui/QImage>
+
+#include <QtCore/QList>
+#include <QtCore/QModelIndex>
+
+    class CommentsDelegate: public KWidgetItemDelegate
+    {
+            Q_OBJECT
+        public:
+            explicit CommentsDelegate( QAbstractItemView* itemView, QObject* parent \
= 0 ); +            virtual ~CommentsDelegate();
+
+            // paint the item at index with all its attributes shown
+            virtual void paint( QPainter* painter, const QStyleOptionViewItem& \
option, const QModelIndex& index ) const; +
+            // get the list of widgets
+            virtual QList<QWidget*> createItemWidgets() const;
+
+            // update the widgets
+            virtual void updateItemWidgets( const QList<QWidget*> widgets,
+                                            const QStyleOptionViewItem& option,
+                                            const QPersistentModelIndex& index ) \
const; +
+            virtual QSize sizeHint( const QStyleOptionViewItem& option, const \
QModelIndex& index ) const; +
+        signals:
+            void commentReplyClicked( const QModelIndex& index );
+
+        protected slots:
+            bool eventFilter( QObject* watched, QEvent* event );
+            void slotReplyClicked();
+
+        protected:
+            QSize m_buttonSize;
+    };
+
+
+#endif
diff --git a/player/lib/models/comments.gdl b/player/lib/models/comments.gdl
deleted file mode 100644
index b2534b3..0000000
--- a/player/lib/models/comments.gdl
+++ /dev/null
@@ -1,51 +0,0 @@
-{ GluonCore::GluonObject(Comments)
-    { GluonCore::GluonObject(Comment)
-        Author string(Author1)
-        Title string(Title1 is the title)
-        Body string(This is the body of the comment1)
-        DateTime string(SomeDate SomeTime)
-        Rating string(5)
-        { GluonCore::GluonObject(Comment)
-            Author string(Author2)
-            Title string(Title2 is the title)
-            Body string(This is the body of comment1-1)
-            DateTime string(SomeDate1-1 SomeTime)
-            Rating int(10)
-            { GluonCore::GluonObject(Comment)
-                Author string(Author5)
-                Title string(Title1 is the title)
-                Body string(This is the body of the comment1-1-1)
-                DateTime string(SomeDate SomeTime)
-                Rating string(5)
-                { GluonCore::GluonObject(Comment)
-                    Author string(Author6)
-                    Title string(Title2 is the title)
-                    Body string(This is the body of comment1-1-1-1)
-                    DateTime string(SomeDate1-1 SomeTime)
-                    Rating int(10)
-                }
-				{ GluonCore::GluonObject(Comment)
-                    Author string(Author6)
-                    Title string(Title2 is the title)
-                    Body string(This is the body of comment1-1-1-2)
-                    DateTime string(SomeDate1-1 SomeTime)
-                    Rating int(10)
-                }
-            }
-        }
-    }
-    { GluonCore::GluonObject(Comment)
-        Author string(Author3)
-        Title string(Title1 is the title)
-        Body string(This is the body of the comment2)
-        DateTime string(SomeDate SomeTime)
-        Rating string(5)
-        { GluonCore::GluonObject(Comment)
-            Author string(Author4)
-            Title string(Title2 is the title)
-            Body string(This is the body of comment2-1)
-            DateTime string(SomeDate2-1 SomeTime)
-            Rating int(10)
-        }
-    }
-}


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

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