[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [Amarok] Initial commit of a new menu to add applets to the
From: William Viana Soares <vianasw () gmail ! com>
Date: 2009-12-01 16:51:38
Message-ID: 200912011651.nB1GpcJV029225 () Wurst ! kollide ! net
[Download RAW message or body]
commit e011f69c28531f119618c985741e88c0a27e44da
Author: William Viana Soares <vianasw@gmail.com>
AuthorDate: Tue Dec 1 17:26:49 2009 +0100
Commit: William Viana Soares <vianasw@gmail.com>
CommitDate: Tue Dec 1 17:41:33 2009 +0100
Initial commit of a new menu to add applets to the context view.
Some basic functionalities are still missing, like scrolling the list of applets.
Help is welcome.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3a224cc..1194112 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -42,6 +42,7 @@ include_directories(
configdialog/dialogs
context
context/widgets
+ context/widgets/appletsexplorer/
dbus
dialogs
dynamic
@@ -366,7 +367,10 @@ set( libcontextview_SRCS
context/widgets/ToolBoxIcon.cpp
context/widgets/ContainmentArrow.cpp
context/widgets/ContainmentSelectionLayer.cpp
- context/widgets/ToolBoxMenu.cpp
+ context/widgets/appletsexplorer/AppletsExplorer.cpp
+ context/widgets/appletsexplorer/AppletsIcon.cpp
+ context/widgets/appletsexplorer/AppletsItemModel.cpp
+ context/widgets/appletsexplorer/AppletsList.cpp
context/widgets/TrackWidget.cpp
)
diff --git a/src/context/toolbar/AppletToolbarAddItem.cpp \
b/src/context/toolbar/AppletToolbarAddItem.cpp index 145f746..451c526 100644
--- a/src/context/toolbar/AppletToolbarAddItem.cpp
+++ b/src/context/toolbar/AppletToolbarAddItem.cpp
@@ -21,7 +21,6 @@
#include "ContextView.h"
#include "Debug.h"
#include "PaletteHandler.h"
-#include "widgets/ToolBoxMenu.h"
#include <KIcon>
@@ -32,7 +31,8 @@
#include <QSizeF>
#include <QStyleOptionGraphicsItem>
-#define TOOLBAR_X_OFFSET 2000
+#define TOOLBAR_X_OFFSET 5
+#define TOOLBAR_Y_OFFSET 5
Context::AppletToolbarAddItem::AppletToolbarAddItem( QGraphicsItem* parent, \
Context::Containment* cont, bool fixedAdd ) : AppletToolbarBase( parent )
@@ -69,12 +69,15 @@ Context::AppletToolbarAddItem::AppletToolbarAddItem( \
QGraphicsItem* parent, Cont
m_label = new QGraphicsSimpleTextItem( i18n( "Add Applet..." ), this );
m_label->hide();
-
- m_addMenu = new Context::AmarokToolBoxMenu( this, false );
+
+ m_addMenu = new Context::AppletsExplorer( cont );
m_addMenu->setContainment( cont );
- m_addMenu->setZValue( zValue() - 10000 );
- connect( m_addMenu, SIGNAL( addAppletToContainment( const QString& ) ), this, \
SLOT( addApplet( const QString& ) ) );
- connect( m_addMenu, SIGNAL( installApplets() ), this, SIGNAL( installApplets() ) \
); + m_addMenu->resize( Context::ContextView::self()->size().width() - 20, \
m_addMenu->geometry().height() ); + m_addMenu->hide();
+
+ m_addMenu->setZValue( zValue() + 10000 );
+
+ connect( m_addMenu, SIGNAL( addAppletToContainment( const QString& ) ), this, \
SLOT( addApplet( const QString & ) ) );
if( m_fixedAdd )
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
@@ -91,7 +94,6 @@ void
Context::AppletToolbarAddItem::hideMenu()
{
m_addMenu->hide();
- m_addMenu->setZValue( zValue() - 10000 );
}
void
@@ -118,14 +120,18 @@ void
Context::AppletToolbarAddItem::resizeEvent( QGraphicsSceneResizeEvent * event )
{
Q_UNUSED( event )
- if( m_label->boundingRect().width() < ( boundingRect().width() - \
2*m_icon->boundingRect().width() ) ) // do we have size to show it? + if( \
m_label->boundingRect().width() < ( boundingRect().width() - \
2*m_icon->boundingRect().width() ) ) + // do we have size to show it?
{
- m_icon->setPos( boundingRect().width() - m_icon->boundingRect().width(), ( \
boundingRect().height() / 2 ) - ( m_icon->size().height() / 2 ) );
- m_label->setPos( ( boundingRect().width() / 2 ) - ( \
m_label->boundingRect().width() / 2 ), ( boundingRect().height() / 2 ) - ( \
m_label->boundingRect().height() / 2 ) ); + m_icon->setPos( \
boundingRect().width() - m_icon->boundingRect().width(), ( boundingRect().height() / \
2 ) - ( +m_icon->size().height() / 2 ) );
+ m_label->setPos( ( boundingRect().width() / 2 ) - ( \
m_label->boundingRect().width() / 2 ), ( +boundingRect().height() / 2 ) - ( \
m_label->boundingRect().height() / 2 ) ); m_label->show();
} else
{
- m_icon->setPos( ( boundingRect().width() / 2 ) - ( \
m_icon->boundingRect().width() / 2 ) , ( boundingRect().height() / 2 ) - ( \
m_icon->size().height() / 2 ) ); + m_icon->setPos( ( boundingRect().width() / \
2 ) - ( m_icon->boundingRect().width() / 2 ) , ( +boundingRect().height() / 2 ) - ( \
m_icon->size().height() / 2 ) ); m_label->hide();
}
}
@@ -135,13 +141,15 @@ QSizeF
Context::AppletToolbarAddItem::sizeHint( Qt::SizeHint which, const QSizeF & \
constraint ) const {
if( m_fixedAdd )
- // return QSizeF( m_icon->size().width() + 2 * m_iconPadding, \
QGraphicsWidget::sizeHint( which, constraint ).height() ); + // return QSizeF( \
m_icon->size().width() + 2 * m_iconPadding, QGraphicsWidget::sizeHint( \
which,constraint +//).height() );
return QGraphicsWidget::sizeHint(which, constraint);
else
if( which == Qt::MinimumSize )
return QSizeF();
else
- return QSizeF( m_icon->size().width() + 2 * m_iconPadding, \
QGraphicsWidget::sizeHint( which, constraint ).height() ); + return \
QSizeF( m_icon->size().width() + 2 * m_iconPadding, QGraphicsWidget::sizeHint( which, \
constraint +).height() );
}
@@ -156,26 +164,19 @@ void
Context::AppletToolbarAddItem::showAddAppletsMenu( QPointF pos )
{
DEBUG_BLOCK
- if( m_addMenu->showing() )
+ Q_UNUSED( pos )
+ if( m_addMenu->isVisible() )
{ // hide again on double-click
m_addMenu->hide();
- m_addMenu->setZValue( zValue() - 10000 );
return;
}
- // HACK to compensate for the toolbar actually being at (1000,0). we want
- // the menu to be seen in the "main" view
- qreal xpos = pos.x() - TOOLBAR_X_OFFSET;
- const qreal ypos = Context::ContextView::self()->size().height() - \
m_addMenu->boundingRect().height() - 20 /* push the down arrow above \
the toolbar */;
- debug() << "placing at X coord:" << QPointF( xpos, ypos ) << "in scene coords" \
<< mapToScene( QPointF( xpos, ypos ) );
-
- qreal diff = Context::ContextView::self()->size().width() - ( mapToScene( \
QPointF( xpos, ypos ) ).x() + m_addMenu->boundingRect().width() );
- debug() << "checking if it will overflow, diff is:" << diff;
- if( diff < 0 )
- xpos += diff;
+ const qreal xpos = TOOLBAR_X_OFFSET;
+ const qreal ypos = Context::ContextView::self()->size().height() - \
m_addMenu->geometry().height() - TOOLBAR_Y_OFFSET;
+ m_addMenu->resize( Context::ContextView::self()->size().width() - ( 2 * \
TOOLBAR_X_OFFSET ), m_addMenu->geometry().height() ); m_addMenu->setPos( xpos, ypos \
); m_addMenu->show();
- m_addMenu->setZValue( zValue() + 10000 );
+
}
#include "AppletToolbarAddItem.moc"
diff --git a/src/context/toolbar/AppletToolbarAddItem.h \
b/src/context/toolbar/AppletToolbarAddItem.h index de5e304..9b90b31 100644
--- a/src/context/toolbar/AppletToolbarAddItem.h
+++ b/src/context/toolbar/AppletToolbarAddItem.h
@@ -19,6 +19,7 @@
#include "amarok_export.h"
+#include "widgets/appletsexplorer/AppletsExplorer.h"
#include <plasma/widgets/iconwidget.h>
@@ -33,9 +34,9 @@ class QStyleOptionGraphicsItem;
namespace Context
{
-
-class AmarokToolBoxMenu;
+
class Containment;
+class WidgetExplorer;
class AppletToolbarAddItem : public AppletToolbarBase
{
@@ -68,7 +69,7 @@ class AppletToolbarAddItem : public AppletToolbarBase
Containment* m_cont;
Plasma::IconWidget* m_icon;
QGraphicsSimpleTextItem* m_label;
- AmarokToolBoxMenu* m_addMenu;
+ AppletsExplorer *m_addMenu;
};
}
diff --git a/src/context/widgets/appletsexplorer/AppletIcon.cpp \
b/src/context/widgets/appletsexplorer/AppletIcon.cpp new file mode 100644
index 0000000..59d7c9e
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletIcon.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+#include "AppletIcon.h"
+#include <KStandardDirs>
+
+#include <QColor>
+#include <QGraphicsSceneMouseEvent>
+
+namespace Context
+{
+
+AppletIconWidget::AppletIconWidget( AppletItem *appletItem, QGraphicsItem *parent )
+ : Plasma::IconWidget( parent )
+ , m_appletItem( appletItem )
+{
+ if( appletItem )
+ {
+ setText( appletItem->name() );
+ setIcon( appletItem->icon() );
+ }
+ else
+ {
+ setText( "no name" );
+ setIcon( "widgets/clock" );
+ }
+ setTextBackgroundColor( QColor() );
+}
+
+AppletIconWidget::~AppletIconWidget()
+{}
+
+AppletItem *
+AppletIconWidget::appletItem() const
+{
+ return m_appletItem;
+}
+
+void
+AppletIconWidget::mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
+{
+ emit( doubleClicked( this ) );
+}
+
+
+void
+AppletIconWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget ) +{
+ Q_UNUSED( option )
+ Q_UNUSED( widget )
+
+ painter->save();
+ painter->setRenderHint( QPainter::Antialiasing );
+
+ QColor topColor( 255, 255, 255, 160 );
+ QColor bottomColor( 255, 255, 255, 90 );
+ qreal radius = 6;
+
+ // draw top half of rounded applet
+ QPainterPath path;
+ path.moveTo( 0, boundingRect().height() / 2 );
+ path.lineTo( 0, radius );
+ path.quadTo( 0, 0,
+ radius, 0 );
+ path.lineTo( boundingRect().width() - radius, 0 );
+ path.quadTo( boundingRect().width(), 0,
+ boundingRect().width(), radius );
+ path.lineTo( boundingRect().width(), boundingRect().height() / 2 );
+ path.lineTo( 0, boundingRect().height() / 2 );
+
+ painter->fillPath( path, topColor );
+ QPainterPath bottom;
+ bottom.moveTo( 0, boundingRect().height() / 2 );
+ bottom.lineTo( 0, boundingRect().height() - radius );
+ bottom.quadTo( 0, boundingRect().height(),
+ radius, boundingRect().height() );
+ bottom.lineTo( boundingRect().width() - radius, boundingRect().height() );
+ bottom.quadTo( boundingRect().width(), boundingRect().height(),
+ boundingRect().width(), boundingRect().height() - radius );
+ bottom.lineTo( boundingRect().width(), boundingRect().height() / 2 );
+ bottom.lineTo( 0, boundingRect().height() / 2 );
+
+ painter->fillPath( bottom, bottomColor );
+ painter->restore();
+ Plasma::IconWidget::paint( painter, option, widget );
+}
+
+}
+
+#include "AppletIcon.moc"
\ No newline at end of file
diff --git a/src/context/widgets/appletsexplorer/AppletIcon.h \
b/src/context/widgets/appletsexplorer/AppletIcon.h new file mode 100644
index 0000000..92032d9
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletIcon.h
@@ -0,0 +1,64 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+#ifndef APPLET_ICON_H
+#define APPLET_ICON_H
+
+#include "amarok_export.h"
+#include "AppletItemModel.h"
+
+#include <plasma/widgets/iconwidget.h>
+
+
+#include <QtGui>
+
+class QGraphicsSceneMouseEvent;
+
+namespace Context
+{
+
+class AMAROK_EXPORT AppletIconWidget: public Plasma::IconWidget
+{
+ Q_OBJECT
+
+ public:
+
+ explicit AppletIconWidget( AppletItem *appletItem = 0, QGraphicsItem *parent \
= 0 ); + virtual ~AppletIconWidget();
+
+ AppletItem *appletItem() const;
+
+ signals:
+ void doubleClicked( AppletIconWidget *applet );
+
+ protected:
+ void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget = 0 ); + void mouseDoubleClickEvent( QGraphicsSceneMouseEvent \
*event ); +
+ private:
+ AppletItem *m_appletItem;
+};
+
+}
+
+#endif
\ No newline at end of file
diff --git a/src/context/widgets/appletsexplorer/AppletItemModel.cpp \
b/src/context/widgets/appletsexplorer/AppletItemModel.cpp new file mode 100644
index 0000000..fe713fa
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletItemModel.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+
+#include "AppletItemModel.h"
+
+#include <plasma/applet.h>
+
+#include <KIcon>
+#include <KPluginInfo>
+
+#include <QIcon>
+
+namespace Context
+{
+
+//AppletItem
+
+AppletItem::AppletItem( AppletItemModel *model, const QMap< QString, QVariant > \
&info ) +{
+ m_model = model;
+ setText( info[ "name" ].toString() );
+ setData( info );
+ setIcon( qvariant_cast< QIcon >( info[ "icon" ] ) );
+}
+
+
+QString
+AppletItem::name() const
+{
+ return data().toMap()[ "name" ].toString();
+}
+
+
+QString
+AppletItem::pluginName() const
+{
+ return data().toMap()[ "pluginName" ].toString();
+}
+
+int
+AppletItem::running() const
+{
+ return data().toMap()[ "runningCount" ].toInt();
+}
+
+void
+AppletItem::setRunning( int count )
+{
+ QMap< QString, QVariant > info = data().toMap();
+ info.insert( "runningCount", count );
+ setData( QVariant( info ) );
+}
+
+
+
+//AppletItemModel
+
+AppletItemModel::AppletItemModel( QObject *parent )
+ : QStandardItemModel( parent )
+{
+ populateModel();
+}
+
+
+void
+AppletItemModel::populateModel()
+{
+ clear();
+
+ foreach( const KPluginInfo &info, Plasma::Applet::listAppletInfo( QString(), \
"amarok" ) ) + {
+ if( info.property( "NoDisplay" ).toBool() || info.category() == i18n( \
"Containments" ) ) + {
+ continue;
+ }
+
+ QMap< QString, QVariant > attrs;
+ attrs.insert( "name", info.name() );
+ attrs.insert( "pluginName", info.pluginName() );
+ attrs.insert( "icon",
+ static_cast< QIcon >( KIcon( info.icon().isEmpty() ?
+ "application-x-plasma": info.icon() ) ) );
+ appendRow( new AppletItem( this, attrs ) );
+ }
+}
+
+}
+
+#include "AppletItemModel.moc"
\ No newline at end of file
diff --git a/src/context/widgets/appletsexplorer/AppletItemModel.h \
b/src/context/widgets/appletsexplorer/AppletItemModel.h new file mode 100644
index 0000000..c46d8ce
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletItemModel.h
@@ -0,0 +1,72 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+
+#ifndef APPLET_ITEM_MODEL_H
+#define APPLET_ITEM_MODEL_H
+
+#include "amarok_export.h"
+
+#include <QStandardItem>
+#include <QStandardItemModel>
+
+namespace Context
+{
+
+class AppletItemModel;
+
+class AMAROK_EXPORT AppletItem: public QObject, public QStandardItem
+{
+ Q_OBJECT
+
+ public:
+ AppletItem( AppletItemModel *model, const QMap< QString, QVariant>& info );
+
+ QString name() const;
+ QString pluginName() const;
+ int running() const;
+
+ void setRunning( int count );
+
+ private:
+ AppletItemModel *m_model;
+
+
+};
+
+class AMAROK_EXPORT AppletItemModel: public QStandardItemModel
+{
+ Q_OBJECT
+
+ public:
+ AppletItemModel( QObject *parent = 0 );
+
+ private:
+ void populateModel();
+
+};
+
+
+}//namespace Context
+
+#endif
\ No newline at end of file
diff --git a/src/context/widgets/appletsexplorer/AppletsExplorer.cpp \
b/src/context/widgets/appletsexplorer/AppletsExplorer.cpp new file mode 100644
index 0000000..6d2e491
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletsExplorer.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+
+#include "AppletsExplorer.h"
+
+#include "AppletIcon.h"
+#include "PaletteHandler.h"
+
+#include <plasma/containment.h>
+#include <plasma/widgets/pushbutton.h>
+#include <plasma/widgets/label.h>
+
+#include <KIcon>
+
+#include <QAction>
+#include <QStyleOptionGraphicsItem>
+#include <QSizePolicy>
+
+#define HEIGHT 140
+#define ICON_SIZE 16
+
+namespace Context
+{
+
+AppletsExplorer::AppletsExplorer( QGraphicsItem *parent )
+ : QGraphicsWidget( parent )
+ , m_containment( 0 )
+ , m_mainLayout( 0 )
+{
+ init();
+}
+
+AppletsExplorer::~AppletsExplorer()
+{}
+
+void
+AppletsExplorer::addApplet( AppletItem *appletItem )
+{
+ if( appletItem && !appletItem->pluginName().isEmpty() && containment() )
+ {
+ emit( addAppletToContainment( appletItem->pluginName() ) );
+ }
+}
+
+void
+AppletsExplorer::hideMenu()
+{
+ hide();
+}
+
+void
+AppletsExplorer::init()
+{
+ m_mainLayout = new QGraphicsLinearLayout( Qt::Vertical );
+
+ m_appletsListWidget = new AppletsListWidget();
+
+ m_appletsListWidget->setPreferredSize( -1, -1 );
+
+ connect( m_appletsListWidget, SIGNAL( appletDoubleClicked( AppletItem * ) ), \
this, SLOT( addApplet( AppletItem * ) ) ); +
+ m_appletsListWidget->setModel( &m_model );
+
+ m_hideIcon = new Plasma::IconWidget( this );
+
+ m_hideIcon->setIcon( KIcon( "window-close" ) );
+ m_hideIcon->setToolTip( i18n( "Hide menu" ) );
+
+ connect( m_hideIcon, SIGNAL( clicked() ), this, SLOT( hideMenu() ) );
+ m_hideIcon->setMinimumSize( m_hideIcon->sizeFromIconSize( ICON_SIZE ) );
+ m_hideIcon->setMaximumSize( m_hideIcon->sizeFromIconSize( ICON_SIZE ) );
+
+ m_mainLayout->addItem( m_hideIcon );
+ m_mainLayout->addItem( m_appletsListWidget );
+ m_mainLayout->setAlignment( m_hideIcon, Qt::AlignLeft );
+ m_mainLayout->setAlignment( m_appletsListWidget, Qt::AlignTop | Qt::AlignHCenter \
); +
+ setMaximumHeight( HEIGHT );
+ setMinimumHeight( HEIGHT );
+
+ setLayout( m_mainLayout );
+
+}
+
+void
+AppletsExplorer::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget ) +{
+ Q_UNUSED( option )
+ Q_UNUSED( widget )
+
+ painter->setRenderHint( QPainter::Antialiasing );
+ painter->save();
+
+ QColor col = PaletteHandler::highlightColor();
+ qreal radius = 6;
+
+ QPainterPath outline;
+ outline.addRoundedRect( boundingRect(), radius, radius );
+ painter->fillPath( outline, QBrush( col ) );
+
+ painter->restore();
+}
+
+void
+AppletsExplorer::setContainment( Containment *containment )
+{
+ m_containment = containment;
+}
+
+Containment *
+AppletsExplorer::containment() const
+{
+ return m_containment;
+}
+
+void
+AppletsExplorer::resizeEvent( QGraphicsSceneResizeEvent *event )
+{
+ m_mainLayout->setGeometry( QRectF( QPointF( 0, 0 ), event->newSize() ) );
+}
+
+}//namespace Context
+
+#include "AppletsExplorer.moc"
diff --git a/src/context/widgets/appletsexplorer/AppletsExplorer.h \
b/src/context/widgets/appletsexplorer/AppletsExplorer.h new file mode 100644
index 0000000..2e44dc8
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletsExplorer.h
@@ -0,0 +1,89 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+
+#ifndef WIDGET_EXPLORER_H
+#define WIDGET_EXPLORER_H
+
+#include "amarok_export.h"
+#include "AppletItemModel.h"
+#include "AppletsList.h"
+#include "Containment.h"
+
+#include <QGraphicsLinearLayout>
+#include <QGraphicsWidget>
+#include <QPainter>
+
+class QAction;
+class QStyleOptionGraphicsItem;
+class QSizePolicy;
+
+namespace Context
+{
+
+class AMAROK_EXPORT AppletsExplorer: public QGraphicsWidget
+{
+
+ Q_OBJECT
+
+ public:
+
+ AppletsExplorer( QGraphicsItem *parent );
+ ~AppletsExplorer();
+
+ void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget = 0 ); +
+ void setContainment( Containment *containment );
+
+ QSizePolicy sizePolicy () const;
+
+ Containment *containment() const;
+
+ signals:
+ void addAppletToContainment( const QString &pluginName );
+
+ private slots:
+ void addApplet( AppletItem *appletItem );
+ void hideMenu();
+
+ protected:
+
+ virtual void resizeEvent( QGraphicsSceneResizeEvent *event );
+
+
+ private:
+
+ void init();
+
+ Containment *m_containment;
+ QGraphicsLinearLayout *m_mainLayout;
+
+ AppletItemModel m_model;
+ AppletsListWidget *m_appletsListWidget;
+ Plasma::IconWidget *m_hideIcon;
+
+};
+
+}// namespace Context
+
+#endif
diff --git a/src/context/widgets/appletsexplorer/AppletsList.cpp \
b/src/context/widgets/appletsexplorer/AppletsList.cpp new file mode 100644
index 0000000..8fb95fb
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletsList.cpp
@@ -0,0 +1,185 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+#include "AppletsList.h"
+#include "Debug.h"
+
+#include <KIcon>
+
+#include <cmath>
+
+#define ICON_SIZE 70
+#define ARROW_SIZE 15
+
+namespace Context
+{
+
+AppletsListWidget::AppletsListWidget( QGraphicsItem *parent )
+ : QGraphicsWidget( parent )
+{
+ init();
+}
+
+AppletsListWidget::~AppletsListWidget()
+{}
+
+
+void
+AppletsListWidget::init()
+{
+ m_mainLayout = new QGraphicsLinearLayout( Qt::Horizontal );
+
+ m_leftArrow = new Plasma::IconWidget();
+ m_rightArrow = new Plasma::IconWidget();
+
+ m_leftArrow->setIcon( KIcon( "go-previous" ) );
+ m_rightArrow->setIcon( KIcon( "go-next" ) );
+
+ m_leftArrow->setDrawBackground( false );
+ m_rightArrow->setDrawBackground( false );
+
+ m_leftArrow->setMinimumSize( m_leftArrow->sizeFromIconSize( ARROW_SIZE ) );
+ m_leftArrow->setMaximumSize( m_leftArrow->sizeFromIconSize( ARROW_SIZE ) );
+ m_rightArrow->setMinimumSize( m_rightArrow->sizeFromIconSize( ARROW_SIZE ) );
+ m_rightArrow->setMaximumSize( m_rightArrow->sizeFromIconSize( ARROW_SIZE ) );
+
+ m_appletsListWidget = new QGraphicsWidget();
+ m_appletsListWindow = new QGraphicsWidget();
+
+ m_appletsListLayout = new QGraphicsLinearLayout( Qt::Horizontal );
+ m_appletsListWidget->setLayout( m_appletsListLayout );
+
+
+ m_appletsListWindow->setFlag( QGraphicsItem::ItemClipsChildrenToShape, true );
+ m_appletsListWidget->setParentItem( m_appletsListWindow );
+
+ m_mainLayout->addItem( m_leftArrow );
+ m_mainLayout->addItem( m_appletsListWindow );
+ m_mainLayout->addItem( m_rightArrow );
+
+ m_mainLayout->setAlignment( m_leftArrow, Qt::AlignVCenter | Qt::AlignHCenter );
+ m_mainLayout->setAlignment( m_rightArrow, Qt::AlignVCenter | Qt::AlignHCenter );
+ m_mainLayout->setAlignment( m_appletsListWindow, Qt::AlignVCenter | \
Qt::AlignHCenter ); + setLayout( m_mainLayout );
+
+}
+
+void
+AppletsListWidget::appletIconDoubleClicked( AppletIconWidget *applet )
+{
+ emit( appletDoubleClicked( applet->appletItem() ) );
+}
+
+AppletIconWidget *
+AppletsListWidget::createAppletIcon( AppletItem *appletItem )
+{
+ AppletIconWidget *applet = new AppletIconWidget( appletItem );
+ applet->setMinimumSize( applet->sizeFromIconSize( ICON_SIZE ) );
+ applet->setMaximumSize( applet->sizeFromIconSize( ICON_SIZE ) );
+
+ connect( applet, SIGNAL( doubleClicked( AppletIconWidget * ) ), this, SLOT( \
appletIconDoubleClicked( AppletIconWidget * ) ) ); + return applet;
+}
+
+void
+AppletsListWidget::insertAppletIcon( AppletIconWidget *appletIcon )
+{
+ appletIcon->setVisible( true );
+ m_appletsListLayout->addItem( appletIcon );
+ m_appletsListLayout->setAlignment( appletIcon, Qt::AlignHCenter );
+ m_appletsListLayout->setAlignment( appletIcon, Qt::AlignVCenter );
+}
+
+int
+AppletsListWidget::maximumVisibleAppletsOnList()
+{
+ DEBUG_BLOCK
+ qreal listTotalSize = m_appletsListLayout->preferredSize().width();
+ qreal iconAverageSize = listTotalSize / m_model->rowCount() + \
m_appletsListLayout->spacing(); + qreal visibleRectSize = boundingRect().width();
+ debug() << "model row count: " << m_model->rowCount();
+ debug() << "icon average size: " << iconAverageSize;
+ debug() << "visible rect size: " << visibleRectSize;
+ debug() << "listTotalSize: " << listTotalSize;
+ return floor( visibleRectSize / iconAverageSize );
+}
+
+
+void
+AppletsListWidget::resizeEvent( QGraphicsSceneResizeEvent *event )
+{
+ DEBUG_BLOCK
+ Q_UNUSED( event );
+
+ updateGeometry();
+ debug() << "visible icons:" << maximumVisibleAppletsOnList();
+}
+
+
+void
+AppletsListWidget::setModel( QStandardItemModel *model )
+{
+ m_model = model;
+ AppletItem *appletItem;
+ m_applets = new QHash< QString, AppletIconWidget * >();
+ m_model->sort( 0 );
+
+ for( int i = 0; i < m_model->rowCount(); i++ )
+ {
+ appletItem = ( AppletItem * )m_model->item( i );
+ m_applets->insert( appletItem->pluginName(), createAppletIcon( appletItem ) \
); + }
+ updateList();
+
+}
+
+
+void
+AppletsListWidget::updateList()
+{
+ DEBUG_BLOCK
+ AppletItem *appletItem;
+ AppletIconWidget *appletIcon;
+ m_appletsListLayout = new QGraphicsLinearLayout( Qt::Horizontal );
+
+ m_appletsListWidget->setLayout( NULL );
+ m_appletsListLayout = new QGraphicsLinearLayout( Qt::Horizontal );
+
+ for( int i = 0; i < m_model->rowCount(); i++ )
+ {
+ appletItem = ( AppletItem * )m_model->item( i );
+ if( appletItem != 0 )
+ {
+ appletIcon = m_applets->value( appletItem->pluginName() );
+ insertAppletIcon( appletIcon );
+ }
+ }
+ m_appletsListWidget->setLayout( m_appletsListLayout );
+ m_appletsListLayout->setSpacing( 10 );
+ debug() << "visible icons:" << maximumVisibleAppletsOnList();
+}
+
+
+}
+
+#include "AppletsList.moc"
\ No newline at end of file
diff --git a/src/context/widgets/appletsexplorer/AppletsList.h \
b/src/context/widgets/appletsexplorer/AppletsList.h new file mode 100644
index 0000000..b9a1ac0
--- /dev/null
+++ b/src/context/widgets/appletsexplorer/AppletsList.h
@@ -0,0 +1,81 @@
+/****************************************************************************************
+ * Copyright (c) 2009 William Viana Soares <vianasw@gmail.com> \
* + * Significant parts of this code is inspired \
* + * and/or copied from KDE Plasma sources, available \
* + * at kdebase/workspace/libs/plasmagenericshell \
* + * \
* + ****************************************************************************************/
+
+/****************************************************************************************
+ * \
* + * 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, see <http://www.gnu.org/licenses/>. \
* + ****************************************************************************************/
+
+
+#ifndef APPLETS_LIST_H
+#define APPLETS_LIST_H
+
+#include "amarok_export.h"
+#include "AppletIcon.h"
+#include "AppletItemModel.h"
+
+#include "plasma/widgets/iconwidget.h"
+
+#include <QtGui>
+
+
+namespace Context
+{
+
+class AMAROK_EXPORT AppletsListWidget: public QGraphicsWidget
+{
+ Q_OBJECT
+ public:
+ AppletsListWidget( QGraphicsItem *parent = 0 );
+ ~AppletsListWidget();
+
+ void setModel( QStandardItemModel *model );
+
+ signals:
+ void appletDoubleClicked( AppletItem *appletItem );
+
+ private slots:
+ void appletIconDoubleClicked( AppletIconWidget *applet );
+
+ private:
+ void init();
+
+ AppletIconWidget *createAppletIcon( AppletItem *appletItem );
+ void insertAppletIcon( AppletIconWidget *appletIcon );
+ void updateList();
+ int maximumVisibleAppletsOnList();
+
+ protected:
+ void resizeEvent( QGraphicsSceneResizeEvent *event );
+
+
+ private:
+ QGraphicsLinearLayout *m_mainLayout;
+ QGraphicsLinearLayout *m_appletsListLayout;
+ QStandardItemModel *m_model;
+ QHash< QString, AppletIconWidget *> *m_applets;
+ QGraphicsWidget *m_appletsListWidget;
+ QGraphicsWidget *m_appletsListWindow;
+
+ Plasma::IconWidget *m_leftArrow;
+ Plasma::IconWidget *m_rightArrow;
+
+};
+
+}//namespace Context
+#endif
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic