nicer painting of the bakground. we use the colour scheme from the theme for this, though now an svg. i want this to be a bit more of a standardized element and svg's don't deal overly well with having rounded corners bent to odd proportions =)

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=738425
This commit is contained in:
Aaron J. Seigo 2007-11-18 21:34:27 +00:00
parent 9c9e6e4371
commit c9ce91e944
2 changed files with 29 additions and 6 deletions

View File

@ -20,14 +20,17 @@
#include "applethandle_p.h"
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QtGui/QLinearGradient>
#include <QtGui/QPainter>
#include <KColorScheme>
#include <KIcon>
#include <cmath>
#include "containment.h"
#include "applet.h"
#include "containment.h"
#include "theme.h"
namespace Plasma
{
@ -39,13 +42,15 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet)
m_pressedButton(NoButton),
m_containment(parent),
m_applet(applet),
m_svg("widgets/iconbutton"),
m_opacity(0.0),
m_anim(FadeIn),
m_animId(0),
m_angle(0.0),
m_scale(1.0)
{
KColorScheme colors(QPalette::Active, KColorScheme::View, Theme::self()->colors());
m_gradientColor = colors.background(KColorScheme::NormalBackground).color();
m_originalMatrix = m_applet->transform();
m_rect = m_applet->boundingRect();
m_rect = m_applet->mapToParent(m_rect).boundingRect();
@ -111,8 +116,17 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
painter->save();
painter->setOpacity(m_opacity);
m_svg.paint(painter, boundingRect(), "background");
m_svg.paint(painter, boundingRect(), "foreground-hover");
painter->save();
painter->setOpacity(m_opacity * 0.4);
painter->setPen(Qt::NoPen);
painter->setRenderHints(QPainter::Antialiasing);
QLinearGradient gr(boundingRect().topLeft(), boundingRect().bottomRight());
gr.setColorAt(0, m_gradientColor);
gr.setColorAt(0.1, KColorScheme::shade(m_gradientColor, KColorScheme::LightShade));
gr.setColorAt(1, KColorScheme::shade(m_gradientColor, KColorScheme::DarkShade));
painter->setBrush(gr);
painter->drawPath(Plasma::roundedRectangle(boundingRect(), 10));
painter->restore();
QPointF point = m_rect.topLeft();
@ -187,10 +201,19 @@ AppletHandle::ButtonType AppletHandle::mapToButton(const QPointF &point) const
void AppletHandle::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button()==Qt::LeftButton) {
if (event->button() == Qt::LeftButton) {
m_pressedButton = mapToButton(event->pos());
if (m_pressedButton == NoButton) {
// since drag is everywhere there isn't a button, NoButton clicks mean the applet
}
event->accept();
update();
return;
}
QGraphicsItem::mousePressEvent(event);
}
void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)

View File

@ -73,13 +73,13 @@ class AppletHandle : public QObject, public QGraphicsItem
ButtonType m_pressedButton;
Containment *m_containment;
Applet *m_applet;
Svg m_svg;
qreal m_opacity;
FadeType m_anim;
Phase::AnimId m_animId;
qreal m_angle;
qreal m_scale;
QTransform m_originalMatrix;
QColor m_gradientColor;
};
}