[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/krunner/interfaces/default
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2009-08-31 12:30:23
Message-ID: 1251721823.580984.13095.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1017772 by aseigo:
use the item background from libplasma (and yes, i'm aware of the keyboard nav \
regression, will fix after lunch :)
M +3 -3 resultscene.cpp
M +8 -153 selectionbar.cpp
M +3 -32 selectionbar.h
--- trunk/KDE/kdebase/workspace/krunner/interfaces/default/resultscene.cpp \
#1017771:1017772 @@ -67,7 +67,7 @@
m_selectionBar->hide();
updateItemMargins();
- connect(m_selectionBar, SIGNAL(graphicsChanged()), this, \
SLOT(updateItemMargins())); + connect(m_selectionBar, SIGNAL(appearanceChanged()), \
this, SLOT(updateItemMargins())); //QColor bg(255, 255, 255, 126);
//setBackgroundBrush(bg);
}
@@ -399,8 +399,8 @@
*/
void ResultScene::updateItemMargins()
{
- m_selectionBar->getMargins(m_itemMarginLeft, m_itemMarginTop,
- m_itemMarginRight, m_itemMarginBottom);
+ m_selectionBar->getContentsMargins(&m_itemMarginLeft, &m_itemMarginTop,
+ &m_itemMarginRight, &m_itemMarginBottom);
foreach (ResultItem *item, m_items) {
item->setContentsMargins(m_itemMarginLeft, m_itemMarginTop,
--- trunk/KDE/kdebase/workspace/krunner/interfaces/default/selectionbar.cpp \
#1017771:1017772 @@ -31,142 +31,34 @@
#include "resultitem.h"
SelectionBar::SelectionBar(QGraphicsWidget *parent)
- : QGraphicsWidget(parent),
- m_frame(new Plasma::FrameSvg(this)),
- m_animId(0),
- m_target(0)
+ : Plasma::ItemBackground(parent)
{
- setCacheMode(DeviceCoordinateCache);
- setZValue(-1000);
- setFlag(ItemIsMovable, false);
- setFlag(ItemIsSelectable, false);
- setFlag(ItemIsFocusable, false);
-
- m_hideTimer = new QTimer(this);
- m_hideTimer->setInterval(100);
- m_hideTimer->setSingleShot(true);
- connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(disappear()));
-
- m_frame->setImagePath("widgets/viewitem");
- m_frame->setCacheAllRenderedFrames(true);
- m_frame->setElementPrefix("hover");
-
- connect(m_frame, SIGNAL(repaintNeeded()), this, SLOT(frameSvgChanged()));
- connect(Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)),
- this, SLOT(movementFinished(int)));
}
-void SelectionBar::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) \
const
-{
- return m_frame->getMargins(left, top, right, bottom);
-}
-
-void SelectionBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget)
-{
- Q_UNUSED(widget)
- m_frame->paintFrame(painter, option->exposedRect, option->exposedRect);
-}
-
-void SelectionBar::animateAndCenter(qreal t)
-{
- setPos(m_animStartRect.topLeft()*(1-t)+m_animEndRect.topLeft()*t);
- if (m_target && !m_target->mouseHovered()) {
- emit ensureVisibility(this);
- }
-}
-
void SelectionBar::acquireTarget()
{
- if (m_target) {
- disconnect(m_target, 0, this, 0);
- m_target->removeSceneEventFilter(this);
- }
-
- m_target = 0;
QList<QGraphicsItem *> selection = scene()->selectedItems();
-
- if (selection.count() != 1) {
+ if (selection.isEmpty()) {
+ setTargetItem(0);
return;
}
- m_target = dynamic_cast<ResultItem *>(selection.first());
-
- if (m_target) {
- connect(m_target, SIGNAL(sizeChanged(ResultItem*)), this, \
SLOT(targetChangedSize()));
- connect(m_target, SIGNAL(destroyed(QObject*)), this, \
SLOT(targetDestroyed()));
- m_target->installSceneEventFilter(this);
- }
+ kDebug() << "showing an item!";
+ setVisible(true);
+ setTargetItem(selection.first());
}
-void SelectionBar::movementFinished(int id)
-{
- if (id != m_animId) {
- return;
- }
-
- m_animId = 0;
-
- if (m_target) {
- resize(m_target->size());
- }
-}
-
-void SelectionBar::frameSvgChanged()
-{
- update();
- emit graphicsChanged();
-}
-
-void SelectionBar::disappear()
-{
- hide();
-}
-
-void SelectionBar::targetDestroyed()
-{
- m_target = 0;
-}
-
-void SelectionBar::itemSelected()
-{
- if (m_animId) {
- Plasma::Animator::self()->stopCustomAnimation(m_animId);
- }
-
- acquireTarget();
-
- if (!m_target) {
- //TODO: animate the hide
- m_hideTimer->start();
- return;
- }
-
- m_hideTimer->stop();
-
- QRectF rect(m_target->geometry());
-
- if (!isVisible()) {
- resize(rect.size());
- setPos(rect.topLeft());
- show();
- } else {
- m_animStartRect = geometry();
- m_animEndRect = rect;
- m_animId = Plasma::Animator::self()->customAnimation(ANIM_FRAMES,ANIM_DURATION, \
Plasma::Animator::EaseInCurve, this, "animateAndCenter");
- }
-}
-
QVariant SelectionBar::itemChange(QGraphicsItem::GraphicsItemChange change, const \
QVariant &value) {
switch (change) {
case ItemSceneChange: {
if (scene()) {
- disconnect(scene(), SIGNAL(selectionChanged()), this, \
SLOT(itemSelected())); + disconnect(scene(), \
SIGNAL(selectionChanged()), this, SLOT(acquireTarget())); }
QGraphicsScene *newScene = value.value<QGraphicsScene*>();
if (newScene) {
- connect(newScene, SIGNAL(selectionChanged()), this, \
SLOT(itemSelected())); + connect(newScene, SIGNAL(selectionChanged()), \
this, SLOT(acquireTarget())); }
}
break;
@@ -178,42 +70,5 @@
return QGraphicsWidget::itemChange(change, value);
}
-bool SelectionBar::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
-{
- if (static_cast<QGraphicsItem*>(m_target) == watched) {
- //kDebug() << event->type() << QEvent::GraphicsSceneResize << \
QEvent::Resize;
- switch (event->type()) {
- case QEvent::GraphicsSceneResize: {
- QResizeEvent *resizeEvent = static_cast<QResizeEvent*>(event);
- //kDebug() << "resizing to" << resizeEvent->oldSize() << \
resizeEvent->size();
- resize(resizeEvent->size());
- update();
- }
- break;
-
- case QEvent::GraphicsSceneMove:
- setPos(m_target->pos());
- break;
-
- default:
- break;
- }
- }
-
- return QGraphicsWidget::sceneEventFilter(watched, event);
-}
-
-void SelectionBar::targetChangedSize()
-{
- resize(m_target->size());
-}
-
-void SelectionBar::resizeEvent(QGraphicsSceneResizeEvent *event)
-{
- Q_UNUSED(event)
- m_frame->resizeFrame(rect().size());
- update();
-}
-
#include <selectionbar.moc>
--- trunk/KDE/kdebase/workspace/krunner/interfaces/default/selectionbar.h \
#1017771:1017772 @@ -20,7 +20,7 @@
#ifndef SELECTIONBAR_H
#define SELECTIONBAR_H
-#include <QGraphicsWidget>
+#include <Plasma/ItemBackground>
class QTimer;
@@ -31,47 +31,18 @@
class ResultItem;
-class SelectionBar : public QGraphicsWidget
+class SelectionBar : public Plasma::ItemBackground
{
Q_OBJECT
public:
SelectionBar(QGraphicsWidget *parent);
- void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget \
* widget = 0);
- void getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const;
-
-signals:
- void graphicsChanged();
- void ensureVisibility(QGraphicsItem * item);
-
protected:
- void resizeEvent(QGraphicsSceneResizeEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant \
&value);
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
-private:
+private Q_SLOTS:
void acquireTarget();
-
-private slots:
- void itemSelected();
- void movementFinished(int id);
- void frameSvgChanged();
- void disappear();
- void targetDestroyed();
- void targetChangedSize();
- void animateAndCenter(qreal t);
-
-private:
- QTimer *m_hideTimer;
- Plasma::FrameSvg *m_frame;
- int m_animId;
- ResultItem *m_target;
- QRectF m_animStartRect;
- QRectF m_animEndRect;
-
- static const int ANIM_FRAMES = 20;
- static const int ANIM_DURATION = 100;
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic