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

List:       kde-commits
Subject:    koffice
From:       Sven Langkamp <sven.langkamp () gmail ! com>
Date:       2009-06-30 20:54:49
Message-ID: 1246395289.007270.18857.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 989756 by langkamp:

fixed the brush chooser looks a bit like in 1.6 now

 M  +51 -0     krita/plugins/paintops/libpaintop/kis_brush_chooser.cpp  
 M  +12 -0     libs/widgets/resources/KoResourceItemChooser.cpp  
 M  +7 -0      libs/widgets/resources/KoResourceItemChooser.h  


--- trunk/koffice/krita/plugins/paintops/libpaintop/kis_brush_chooser.cpp \
#989755:989756 @@ -1,5 +1,6 @@
 /*
  *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
+ *  Copyright (c) 2009 Sven Langkamp <sven.langkamp@gmail.com>
  *
  *  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
@@ -23,6 +24,8 @@
 #include <QCheckBox>
 #include <QVBoxLayout>
 #include <QGridLayout>
+#include <QPainter>
+#include <QAbstractItemDelegate>
 #include <klocale.h>
 
 #include <KoResourceItemChooser.h>
@@ -37,6 +40,51 @@
 #include "kis_global.h"
 #include "kis_gbr_brush.h"
 
+/// The resource item delegate for rendering the resource preview
+class KisBrushDelegate : public QAbstractItemDelegate
+{
+public:
+    KisBrushDelegate( QObject * parent = 0 ) : QAbstractItemDelegate( parent ) {}
+    virtual ~KisBrushDelegate() {}
+    /// reimplemented
+    virtual void paint( QPainter *, const QStyleOptionViewItem &, const QModelIndex \
& ) const; +    /// reimplemented
+    QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & ) \
const +    {
+        return option.decorationSize;
+    }
+};
+
+void KisBrushDelegate::paint( QPainter * painter, const QStyleOptionViewItem & \
option, const QModelIndex & index ) const +{
+    if( ! index.isValid() )
+        return;
+
+    KisBrush * brush = static_cast<KisBrush*>( index.internalPointer() );
+    if (!brush)
+        return;
+
+    QRect itemRect = option.rect;
+    QImage thumbnail = brush->img();
+
+    if(thumbnail.height() > itemRect.height() || thumbnail.width() > \
itemRect.width()) { +        thumbnail = thumbnail.scaled( itemRect.size() , \
Qt::KeepAspectRatio ); +    }
+
+    painter->save();
+    int dx = (itemRect.width() - thumbnail.width()) / 2;
+    int dy = (itemRect.height() - thumbnail.height()) / 2;
+    painter->drawImage( itemRect.x() + dx, itemRect.y() + dy, thumbnail );
+
+    if (option.state & QStyle::State_Selected) {
+        painter->setPen( QPen(option.palette.highlight(), 2.0) );
+        painter->drawRect( option.rect );
+    }
+
+    painter->restore();
+}
+
+
 KisBrushChooser::KisBrushChooser(QWidget *parent, const char *name)
         : QWidget(parent)
 {
@@ -56,6 +104,9 @@
     KoResourceServer<KisBrush>* rServer = KisBrushServer::instance()->brushServer();
     KoResourceServerAdapter<KisBrush>* adapter = new \
KoResourceServerAdapter<KisBrush>(rServer);  m_itemChooser = new \
KoResourceItemChooser(adapter, this); +    m_itemChooser->setColumnCount(10);
+    m_itemChooser->setRowHeight(30);
+    m_itemChooser->setItemDelegate(new KisBrushDelegate(this));
 
     connect( m_itemChooser, SIGNAL(resourceSelected( KoResource * ) ),
              this, SLOT( update( KoResource * ) ) );
--- trunk/koffice/libs/widgets/resources/KoResourceItemChooser.cpp #989755:989756
@@ -23,6 +23,7 @@
 #include <QGridLayout>
 #include <QButtonGroup>
 #include <QPushButton>
+#include <QHeaderView>
 
 #include <kfiledialog.h>
 #include <kiconloader.h>
@@ -52,6 +53,7 @@
     d->view = new KoResourceItemView(this);
     d->view->setModel(d->model);
     d->view->setItemDelegate( new KoResourceItemDelegate( this ) );
+    d->view->setSelectionMode( QAbstractItemView::SingleSelection );
     connect( d->view, SIGNAL(activated ( const QModelIndex & ) ),
              this, SLOT(activated ( const QModelIndex & ) ) );
 
@@ -124,6 +126,16 @@
     d->model->setColumnCount( columnCount );
 }
 
+void KoResourceItemChooser::setRowHeight( int rowHeight )
+{
+    d->view->verticalHeader()->setDefaultSectionSize( rowHeight );
+}
+
+void KoResourceItemChooser::setItemDelegate( QAbstractItemDelegate * delegate )
+{
+    d->view->setItemDelegate(delegate);
+}
+
 KoResource *  KoResourceItemChooser::currentResource()
 {
     QModelIndex index = d->view->currentIndex();
--- trunk/koffice/libs/widgets/resources/KoResourceItemChooser.h #989755:989756
@@ -28,6 +28,7 @@
 #include "kowidgets_export.h"
 
 class QButtonGroup;
+class QAbstractItemDelegate;
 class KoAbstractResourceServerAdapter;
 class KoResourceItemView;
 class KoResource;
@@ -46,6 +47,12 @@
     /// Sets number of columns in the view
     void setColumnCount( int columnCount );
 
+    /// Sets the height of the view rows
+    void setRowHeight( int rowHeight );
+
+    /// Sets a custom delegate for the view
+    void setItemDelegate( QAbstractItemDelegate * delegate );
+
     /// Gets the currently selected resource
     /// @returns the selected resource, 0 is no resource is selected
     KoResource * currentResource();


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

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