Skip to content

Commit

Permalink
created the raptorgraphics widget, easier to mantain and extend.. Unf…
Browse files Browse the repository at this point in the history
…ortunately a size issue occurs
  • Loading branch information
alediaferia committed Sep 17, 2008
1 parent 6a3132c commit ba07d98
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 57 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -23,6 +23,7 @@ set(raptor_SRCS
raptor.cpp
view/raptoritemsview.cpp # When starting implementing raptoritemsview include also engine/kickoff/*
view/raptoritemdelegate.cpp
view/raptorgraphicswidget.cpp
engine/kickoff/applicationmodel.cpp
engine/kickoff/kickoffabstractmodel.cpp
engine/kickoff/models.cpp
Expand Down
56 changes: 6 additions & 50 deletions raptor.cpp
Expand Up @@ -8,21 +8,11 @@
version 2 of the License, or (at your option) any later version.
*/
#include "raptor.h"
#include "view/raptoritemsview.h"
#include "view/raptoritemdelegate.h"
#include "engine/kickoff/applicationmodel.h"
#include "view/raptorgraphicswidget.h"

#include <QPainter>
#include <QFontMetrics>
#include <QSizeF>
#include <QGraphicsLinearLayout>
#include <QGraphicsProxyWidget>
#include <QPalette>

// KDE
#include <KDesktopFile>
#include <KService>
#include <KRun>

#include <plasma/svg.h>
#include <plasma/theme.h>
Expand All @@ -31,7 +21,7 @@ Raptor::Raptor(QObject *parent, const QVariantList &args)
: Plasma::PopupApplet(parent, args),
m_svg(this),
m_icon("plasma"),
m_view(0)
m_gwidget(0)
{
// this will get us the standard applet background, for free!
setBackgroundHints(Plasma::Applet::StandardBackground);
Expand All @@ -56,46 +46,19 @@ void Raptor::init()
}

setupView();
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updateColors()));

setPopupIcon("plasma");
}


void Raptor::setupView()
{
//WARNING: ruphy this is just for test, don't be scared :) (alediaferia)

m_view = new RaptorItemsView();
RaptorItemDelegate *delegate = new RaptorItemDelegate();
//TODO: connect this to theme change
delegate->setTextColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));

Kickoff::ApplicationModel *model = new Kickoff::ApplicationModel();

// let's make the view nicer in the applet
//m_view->viewport()->setAttribute(Qt::WA_NoSystemBackground);
m_view->setAttribute(Qt::WA_NoSystemBackground);//FIXME: Probable just setStyleSheet("background: transparent;"); ?
m_view->viewport()->setAutoFillBackground(true);
QPalette p = m_view->viewport()->palette();
p.setColor(QPalette::Base, Qt::transparent);
m_view->viewport()->setPalette(p);

m_view->setModel(model);
m_view->setItemDelegate(delegate);

m_view->hideScrollBars();

connect(m_view, SIGNAL(applicationClicked(const KUrl &)), this, SLOT(launchApplication(const KUrl &)));
}

QWidget* Raptor::widget()
{
return static_cast<QWidget*>(m_view);
m_gwidget = new RaptorGraphicsWidget(this);
}

void Raptor::updateColors()
QGraphicsWidget* Raptor::graphicsWidget()
{
static_cast<RaptorItemDelegate*>(m_view->itemDelegate())->setTextColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
return m_gwidget;
}

void Raptor::paintInterface(QPainter *p,
Expand All @@ -119,12 +82,5 @@ void Raptor::paintInterface(QPainter *p,

PopupApplet::paintInterface(p, option, contentsRect);
}

void Raptor::launchApplication(const KUrl &url)
{
KDesktopFile desktopFile(url.pathOrUrl());
KService service(&desktopFile);
KRun::run(service, KUrl::List(), m_view);
}

#include "raptor.moc"
9 changes: 3 additions & 6 deletions raptor.h
Expand Up @@ -16,7 +16,7 @@
#include <Plasma/PopupApplet>
#include <Plasma/Svg>

class RaptorItemsView;
class RaptorGraphicsWidget;

class QSizeF;

Expand All @@ -36,19 +36,16 @@ class Raptor : public Plasma::PopupApplet

void init();

QWidget *widget();
QGraphicsWidget *graphicsWidget();

protected:
void setupView();

protected slots:
void updateColors();
void launchApplication(const KUrl &);

private:
Plasma::Svg m_svg;
KIcon m_icon;
RaptorItemsView *m_view;
RaptorGraphicsWidget *m_gwidget;
};

// This is the command that links your applet to the .desktop file
Expand Down
95 changes: 95 additions & 0 deletions view/raptorgraphicswidget.cpp
@@ -0,0 +1,95 @@
/* This file is part of the KDE project
Copyright (C) 2008 Alessandro Diaferia <alediaferia@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 the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/

#include "raptorgraphicswidget.h"

// Local
#include "view/raptoritemsview.h"
#include "view/raptoritemdelegate.h"
#include "engine/kickoff/applicationmodel.h"

// Qt
#include <QGraphicsLinearLayout>
#include <QGraphicsProxyWidget>

// KDE
#include <KDesktopFile>
#include <KRun>
#include <KService>

// Plasma
#include <Plasma/Theme>

class RaptorGraphicsWidget::Private
{
public:
Private(RaptorGraphicsWidget *q) : q(q),
view(0),
proxy(0)
{}
~Private(){}

RaptorGraphicsWidget *q;
RaptorItemsView *view;
QGraphicsProxyWidget *proxy;
};

RaptorGraphicsWidget::RaptorGraphicsWidget(QGraphicsItem *parent) : QGraphicsWidget(parent),
d(new Private(this))
{
d->view = new RaptorItemsView();
RaptorItemDelegate *delegate = new RaptorItemDelegate();

delegate->setTextColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));

Kickoff::ApplicationModel *model = new Kickoff::ApplicationModel();

// let's make the view nicer in the applet
d->view->setAttribute(Qt::WA_NoSystemBackground);
d->view->viewport()->setAutoFillBackground(true);
QPalette p = d->view->viewport()->palette();
p.setColor(QPalette::Base, Qt::transparent);
d->view->viewport()->setPalette(p);

d->view->setModel(model);
d->view->setItemDelegate(delegate);

d->view->hideScrollBars();

QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this);
layout->setOrientation(Qt::Horizontal);

d->proxy = new QGraphicsProxyWidget(this);
d->proxy->setWidget(d->view);

layout->addItem(d->proxy);

setLayout(layout);

connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updateColors()));
connect(d->view, SIGNAL(applicationClicked(const KUrl &)), this, SLOT(launchApplication(const KUrl &)));
}

RaptorGraphicsWidget::~RaptorGraphicsWidget()
{
delete d;
}

void RaptorGraphicsWidget::launchApplication(const KUrl &url)
{
KDesktopFile desktopFile(url.pathOrUrl());
KService service(&desktopFile);
KRun::run(service, KUrl::List(), d->view);
}

void RaptorGraphicsWidget::updateColors()
{
static_cast<RaptorItemDelegate*>(d->view->itemDelegate())->setTextColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
}
35 changes: 35 additions & 0 deletions view/raptorgraphicswidget.h
@@ -0,0 +1,35 @@
/* This file is part of the KDE project
Copyright (C) 2008 Alessandro Diaferia <alediaferia@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 the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/

#ifndef RAPTORGRAPHICSWIDGET_H
#define RAPTORGRAPHICSWIDGET_H

#include <QGraphicsWidget>

class KUrl;

class RaptorGraphicsWidget : public QGraphicsWidget
{
Q_OBJECT
public:
RaptorGraphicsWidget(QGraphicsItem *parent);
~RaptorGraphicsWidget();

protected slots:
void updateColors();
void launchApplication(const KUrl &);

private:
class Private;
Private *d;

};

#endif
2 changes: 1 addition & 1 deletion view/raptoritemdelegate.cpp
Expand Up @@ -62,7 +62,7 @@ void RaptorItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & o
}

d->optV4 = option;
initStyleOption(&d->optV4 ,index);
initStyleOption(&d->optV4, index);

This comment has been minimized.

Copy link
@ruphy

ruphy Sep 18, 2008

Owner

good one

d->view = qobject_cast<const QAbstractItemView*>(d->optV4.widget);


Expand Down

0 comments on commit ba07d98

Please sign in to comment.