since it leads to confusion for users, breaks occassionally in svn due to its complexity, incurs overhead on every applet paint but especially when dragging, doesn't look nice at all without composite ... just kill the top level view thing and when you drag something it just "pops" into the right containment.

BUG:176298

svn path=/trunk/KDE/kdelibs/; revision=890331
This commit is contained in:
Aaron J. Seigo 2008-11-28 22:39:29 +00:00
parent 766dc8ab60
commit 4a7699ce82
4 changed files with 69 additions and 191 deletions

View File

@ -986,99 +986,74 @@ void Applet::addAction(QString name, QAction *action)
void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
if (!d->started) { if (!d->started) {
kDebug() << "not started";
return; return;
} }
QPainter *p = painter;
QPixmap *pixmap = 0;
if (d->ghost) {
// The applet has to be displayed semi transparent. Create a pixmap and a painter on
// that pixmap where the applet can draw on so we can draw the result transparently
// at the end.
kDebug() << "Painting ghosted...";
pixmap = new QPixmap(boundingRect().size().toSize());
pixmap->fill(Qt::transparent);
p = new QPainter();
p->begin(pixmap);
}
p->save();
if (transform().isRotating()) { if (transform().isRotating()) {
p->setRenderHint(QPainter::SmoothPixmapTransform); painter->setRenderHint(QPainter::SmoothPixmapTransform);
p->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
} }
if (d->background && if (d->background &&
formFactor() != Plasma::Vertical && formFactor() != Plasma::Vertical &&
formFactor() != Plasma::Horizontal) { formFactor() != Plasma::Horizontal) {
//kDebug() << "option rect is" << option->rect; //kDebug() << "option rect is" << option->rect;
d->background->paintFrame(p); d->background->paintFrame(painter);
} }
if (!d->failed) { if (d->failed) {
qreal left, top, right, bottom; kDebug() << "failed!";
getContentsMargins(&left, &top, &right, &bottom); return;
QRect contentsRect = }
QRectF(QPointF(0, 0),
boundingRect().size()).adjusted(left, top, -right, -bottom).toRect();
if (widget && isContainment()) { qreal left, top, right, bottom;
// note that the widget we get is actually the viewport of the view, not the view itself getContentsMargins(&left, &top, &right, &bottom);
View* v = qobject_cast<Plasma::View*>(widget->parent()); QRect contentsRect = QRectF(QPointF(0, 0),
Containment* c = qobject_cast<Plasma::Containment*>(this); boundingRect().size()).adjusted(left, top, -right, -bottom).toRect();
//update the view transform of the toolbox, since it ignores transforms if (widget && isContainment()) {
if (c && c->d->toolBox) { // note that the widget we get is actually the viewport of the view, not the view itself
c->d->toolBox->setViewTransform(v->transform()); View* v = qobject_cast<Plasma::View*>(widget->parent());
} Containment* c = qobject_cast<Plasma::Containment*>(this);
if (!v || v->isWallpaperEnabled()) { //update the view transform of the toolbox, since it ignores transforms
if (c && c->drawWallpaper() && c->wallpaper()) { if (c && c->d->toolBox) {
Wallpaper *w = c->wallpaper(); c->d->toolBox->setViewTransform(v->transform());
if (!w->isInitialized()) {
// delayed paper initialization
KConfigGroup wallpaperConfig = c->config();
wallpaperConfig = KConfigGroup(&wallpaperConfig, "Wallpaper");
wallpaperConfig = KConfigGroup(&wallpaperConfig, w->pluginName());
w->restore(wallpaperConfig);
}
p->save();
c->wallpaper()->paint(p, option->exposedRect);
p->restore();
}
Containment::StyleOption coption(*option);
coption.view = v;
paintInterface(p, &coption, contentsRect);
}
p->restore();
return;
} }
if (!v || v->isWallpaperEnabled()) {
// paint the wallpaper
if (c && c->drawWallpaper() && c->wallpaper()) {
Wallpaper *w = c->wallpaper();
if (!w->isInitialized()) {
// delayed paper initialization
KConfigGroup wallpaperConfig = c->config();
wallpaperConfig = KConfigGroup(&wallpaperConfig, "Wallpaper");
wallpaperConfig = KConfigGroup(&wallpaperConfig, w->pluginName());
w->restore(wallpaperConfig);
}
painter->save();
c->wallpaper()->paint(painter, option->exposedRect);
painter->restore();
}
// .. and now paint the actual containment interface, but with
// a Containment style option based on the one we get
Containment::StyleOption coption(*option);
coption.view = v;
paintInterface(painter, &coption, contentsRect);
}
} else {
//kDebug() << "paint interface of" << (QObject*) this; //kDebug() << "paint interface of" << (QObject*) this;
paintInterface(p, option, contentsRect); // paint the applet's interface
} paintInterface(painter, option, contentsRect);
p->restore();
if (d->ghost) {
// Lets display the pixmap that we've just drawn... transparently.
p->setCompositionMode(QPainter::CompositionMode_DestinationIn);
p->fillRect(pixmap->rect(), QColor(0, 0, 0, (0.3 * 255)));
p->end();
delete p;
painter->drawPixmap(0, 0, *pixmap);
delete pixmap;
} }
} }
void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
const QRect &contentsRect)
{ {
if (d->script) { if (d->script) {
d->script->paintInterface(painter, option, contentsRect); d->script->paintInterface(painter, option, contentsRect);
@ -1791,7 +1766,6 @@ AppletPrivate::AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet
failed(false), failed(false),
isContainment(false), isContainment(false),
transient(false), transient(false),
ghost(false),
needsConfig(false), needsConfig(false),
started(false) started(false)
{ {
@ -2059,7 +2033,6 @@ void AppletOverlayWidget::paint(QPainter *painter,
{ {
Q_UNUSED(option) Q_UNUSED(option)
Q_UNUSED(widget) Q_UNUSED(widget)
painter->save();
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor); QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
wash.setAlphaF(.6); wash.setAlphaF(.6);
@ -2071,8 +2044,6 @@ void AppletOverlayWidget::paint(QPainter *painter,
} else { } else {
painter->fillPath(parentItem()->shape(), wash); painter->fillPath(parentItem()->shape(), wash);
} }
painter->restore();
} }
} // Plasma namespace } // Plasma namespace

View File

@ -113,7 +113,6 @@ public:
bool isContainment : 1; bool isContainment : 1;
bool square : 1; bool square : 1;
bool transient : 1; bool transient : 1;
bool ghost : 1;
bool needsConfig : 1; bool needsConfig : 1;
bool started : 1; bool started : 1;
}; };

View File

@ -63,7 +63,6 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet, const QPointF &h
m_tempAngle(0.0), m_tempAngle(0.0),
m_scaleWidth(1.0), m_scaleWidth(1.0),
m_scaleHeight(1.0), m_scaleHeight(1.0),
m_topview(0),
m_backgroundBuffer(0), m_backgroundBuffer(0),
m_currentView(applet->view()), m_currentView(applet->view()),
m_entryPos(hoverPos), m_entryPos(hoverPos),
@ -136,9 +135,6 @@ AppletHandle::~AppletHandle()
{ {
detachApplet(); detachApplet();
delete m_backgroundBuffer; delete m_backgroundBuffer;
if (m_topview) {
delete m_topview;
}
} }
Applet *AppletHandle::applet() const Applet *AppletHandle::applet() const
@ -229,15 +225,15 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
Q_UNUSED(option); Q_UNUSED(option);
Q_UNUSED(widget); Q_UNUSED(widget);
//kDebug() << m_opacity << m_anim << FadeOut;
if (qFuzzyCompare(m_opacity + 1.0, 1.0)) { if (qFuzzyCompare(m_opacity + 1.0, 1.0)) {
if (m_anim == FadeOut) { if (m_anim == FadeOut) {
//kDebug() << "WOOOOOOOOO";
QTimer::singleShot(0, this, SLOT(emitDisappear())); QTimer::singleShot(0, this, SLOT(emitDisappear()));
} }
return; return;
} }
painter->save();
qreal translation; qreal translation;
if (m_buttonsOnRight) { if (m_buttonsOnRight) {
@ -393,8 +389,6 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
basePoint = m_rect.bottomLeft() + QPointF(HANDLE_MARGIN, 0) - step; basePoint = m_rect.bottomLeft() + QPointF(HANDLE_MARGIN, 0) - step;
sourceIconRect.translate(0, m_iconSize); sourceIconRect.translate(0, m_iconSize);
painter->drawPixmap(QRectF(basePoint + shiftD, iconSize), *m_backgroundBuffer, sourceIconRect); painter->drawPixmap(QRectF(basePoint + shiftD, iconSize), *m_backgroundBuffer, sourceIconRect);
painter->restore();
} }
void AppletHandle::emitDisappear() void AppletHandle::emitDisappear()
@ -500,10 +494,7 @@ bool AppletHandle::leaveCurrentView(const QPoint &pos) const
//is this widget a plasma view, a different view then our current one, //is this widget a plasma view, a different view then our current one,
//AND not a dashboardview? //AND not a dashboardview?
Plasma::View *v = qobject_cast<Plasma::View *>(widget); Plasma::View *v = qobject_cast<Plasma::View *>(widget);
if (v && if (v && v != m_currentView && v->containment() != m_containment) {
v != m_currentView &&
v != m_topview &&
v->containment() != m_containment) {
return true; return true;
} }
} }
@ -550,27 +541,6 @@ void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
break; break;
case MoveButton: case MoveButton:
{ {
if (m_topview) {
m_topview->hide();
delete m_topview;
m_topview = 0;
m_applet->d->ghost = false;
m_applet->update();
}
//find out if we were dropped on a panel or something
if (leaveCurrentView(event->screenPos())) {
startFading(FadeOut, m_entryPos);
Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
if (v && v != m_currentView) {
Containment *c = v->containment();
QPoint pos = v->mapFromGlobal(event->screenPos());
//we actually have been dropped on another containment, so
//move there: we have a screenpos, we need a scenepos
//FIXME how reliable is this transform?
switchContainment(c, v->mapToScene(pos));
}
} else {
// test for containment change // test for containment change
//kDebug() << "testing for containment change, sceneBoundingRect = " //kDebug() << "testing for containment change, sceneBoundingRect = "
// << m_containment->sceneBoundingRect(); // << m_containment->sceneBoundingRect();
@ -599,7 +569,6 @@ void AppletHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
} }
} }
} }
}
break; break;
} }
default: default:
@ -641,75 +610,22 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (m_pressedButton == MoveButton) { if (m_pressedButton == MoveButton) {
m_pos += deltaScene; m_pos += deltaScene;
if (leaveCurrentView(event->screenPos())) {
//Are we moving out of the current view? Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
bool toTopLevel = leaveCurrentView(event->screenPos()); if (v && v != m_currentView) {
Containment *c = v->containment();
if (!toTopLevel) { QPoint pos = v->mapFromGlobal(event->screenPos());
setPos(m_pos); //we actually have been dropped on another containment, so
if (m_topview) { //move there: we have a screenpos, we need a scenepos
//We were on a toplevel view, but are moving back on the scene //FIXME how reliable is this transform?
//again. destroy the toplevel view: m_pressedButton = NoButton;
m_topview->hide(); switchContainment(c, v->mapToScene(pos));
delete m_topview; } else {
m_topview = 0; setPos(m_pos);
m_applet->d->ghost = false;
} }
} else { } else {
//set the screenRect correctly. the screenRect contains the bounding setPos(m_pos);
//rect of the applet in screen coordinates. m_mousePos contains the
//position of the mouse relative to the applet, in screen coords.
QRect screenRect = QRect(event->screenPos() - m_mousePos, m_applet->size().toSize());
//kDebug() << "screenRect = " << screenRect;
if (!m_topview) { //create a new toplevel view
m_topview = new View(m_containment, -1, 0);
m_topview->setTrackContainmentChanges(false);
m_topview->setWindowFlags(
Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
m_topview->setWallpaperEnabled(false);
m_topview->resize(screenRect.size());
m_topview->setSceneRect(m_applet->sceneBoundingRect());
m_topview->centerOn(m_applet);
//We might have to scale the view, because we might be zoomed out.
qreal scale = screenRect.width() / m_applet->boundingRect().width();
m_topview->scale(scale, scale);
//Paint a mask based on the applets shape.
//TODO: I think it's nicer to have this functionality in Applet.
//TODO: When the corona tiled background is disabled, disable the
//mask when compositing is enabled.
//FIXME: the mask doesn't function correctly when zoomed out.
QBitmap bitmap(screenRect.size());
{
QPainter shapePainter;
shapePainter.begin(&bitmap);
shapePainter.fillRect(0, 0, screenRect.width(),
screenRect.height(),
Qt::white);
shapePainter.setBrush(Qt::black);
shapePainter.drawPath(m_applet->shape());
shapePainter.end();
}
m_topview->setMask(bitmap);
m_topview->show();
m_applet->d->ghost = true;
//TODO: non compositing users are screwed: masking looks terrible.
//Consider always enabling the applet background. Stuff like the analog clock
//looks absolutely terrible when masked, while the minor rounded corners of most
//themes should look quite ok. I said should, since shape() doesn't really
//function correctly right now for applets drawing standard backgrounds.
}
m_topview->setGeometry(screenRect);
} }
} else if (m_pressedButton == RotateButton || } else if (m_pressedButton == RotateButton ||
m_pressedButton == ResizeButton) { m_pressedButton == ResizeButton) {
if (_k_distanceForPoint(deltaScene) <= 1.0) { if (_k_distanceForPoint(deltaScene) <= 1.0) {
@ -874,7 +790,7 @@ void AppletHandle::switchContainment(Containment *containment, const QPointF &po
{ {
if (containment->containmentType() != Containment::PanelContainment) { if (containment->containmentType() != Containment::PanelContainment) {
//FIXME assuming everything else behaves like desktop? //FIXME assuming everything else behaves like desktop?
kDebug() << "desktop"; //kDebug() << "desktop";
m_containment = containment; m_containment = containment;
} }
@ -930,15 +846,6 @@ void AppletHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
//wait a moment to hide the handle in order to recheck the mouse position //wait a moment to hide the handle in order to recheck the mouse position
m_leaveTimer->start(); m_leaveTimer->start();
} }
if (m_topview) {
//We were on a toplevel view, but are moving back on the scene
//again. destroy the toplevel view:
m_topview->hide();
delete m_topview;
m_topview = 0;
m_applet->d->ghost = false;
}
} }
bool AppletHandle::sceneEventFilter(QGraphicsItem *watched, QEvent *event) bool AppletHandle::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
@ -958,7 +865,8 @@ void AppletHandle::fadeAnimation(qreal progress)
} else { } else {
m_opacity = 1 - progress; m_opacity = 1 - progress;
} }
//kDebug() << "progress" << progress << "m_opacity" << m_opacity;// << endOpacity;
//kDebug() << "progress" << progress << "m_opacity" << m_opacity << m_anim << "(" << FadeIn << ")";
if (qFuzzyCompare(progress, qreal(1.0))) { if (qFuzzyCompare(progress, qreal(1.0))) {
m_animId = 0; m_animId = 0;
delete m_backgroundBuffer; delete m_backgroundBuffer;
@ -1009,6 +917,7 @@ void AppletHandle::startFading(FadeType anim, const QPointF &hoverPos)
if (!m_applet || (anim == FadeOut && m_hoverTimer->isActive())) { if (!m_applet || (anim == FadeOut && m_hoverTimer->isActive())) {
// fading out before we've started fading in // fading out before we've started fading in
m_anim = FadeOut;
fadeAnimation(1.0); fadeAnimation(1.0);
return; return;
} }
@ -1055,8 +964,8 @@ void AppletHandle::startFading(FadeType anim, const QPointF &hoverPos)
m_anim = anim; m_anim = anim;
//kDebug() << "animating for " << time << "ms"; //kDebug() << "animating for " << time << "ms";
m_animId = Animator::self()->customAnimation( m_animId = Animator::self()->customAnimation(80 * (time / 1000.0), (int)time,
80 * (time / 1000.0), (int)time, Animator::EaseInCurve, this, "fadeAnimation"); Animator::EaseInCurve, this, "fadeAnimation");
} }
void AppletHandle::forceDisappear() void AppletHandle::forceDisappear()

View File

@ -120,7 +120,6 @@ class AppletHandle : public QObject, public QGraphicsItem
QColor m_gradientColor; QColor m_gradientColor;
QTimer *m_hoverTimer; QTimer *m_hoverTimer;
QTimer *m_leaveTimer; QTimer *m_leaveTimer;
View *m_topview;
QPixmap *m_backgroundBuffer; QPixmap *m_backgroundBuffer;
QGraphicsView *m_currentView; QGraphicsView *m_currentView;