[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdereview/plasma/applets/previewer
From: Alessandro Diaferia <alediaferia () gmail ! com>
Date: 2008-10-11 8:09:11
Message-ID: 1223717960.244180.9526.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 869840 by adiaferia:
smooth expanding animation
M +12 -13 plasma-previewer.cpp
M +0 -2 previewdialog.cpp
M +45 -10 previewwidget.cpp
M +8 -0 previewwidget.h
--- trunk/kdereview/plasma/applets/previewer/plasma-previewer.cpp #869839:869840
@@ -48,6 +48,7 @@
#include <plasma/theme.h>
+
Previewer::Previewer(QObject *parent, const QVariantList &args)
: Plasma::PopupApplet(parent, args),
m_base(0),
@@ -66,9 +67,9 @@
setAcceptHoverEvents(true);
setAcceptDrops(true);
+
// initialize the widget
graphicsWidget();
- resize(500, PreviewWidget::s_topBorder + m_previewWidget->bottomBorderHeight());
}
Previewer::~Previewer()
@@ -86,7 +87,7 @@
{
if (!m_previewWidget) {
m_previewWidget = new PreviewWidget(this);
- m_previewWidget->setMinimumSize(400, 200);
+ m_previewWidget->setMinimumSize(400, 150);
}
connect(m_previewWidget, SIGNAL(urlsDropped(KUrl::List)), this, \
SLOT(openUrls(KUrl::List))); @@ -101,11 +102,11 @@
setupActions();
//TODO save state!
- if (m_previewHistory.isEmpty() &&
- formFactor() != Plasma::Vertical &&
- formFactor() != Plasma::Horizontal) {
- resize(size().width(), PreviewWidget::s_topBorder + \
m_previewWidget->bottomBorderHeight());
- }
+// if (m_previewHistory.isEmpty() &&
+// formFactor() != Plasma::Vertical &&
+// formFactor() != Plasma::Horizontal) {
+// resize(size().width(), 200);
+// }
}
void Previewer::constraintsEvent(Plasma::Constraints constraints)
@@ -116,6 +117,7 @@
if (constraints & Plasma::StartupCompletedConstraint && (formFactor() != \
Plasma::Vertical || formFactor() != Plasma::Horizontal)) {
setAspectRatioMode(Plasma::IgnoreAspectRatio);
+ resize(size().width(), 200);
}
}
@@ -126,7 +128,7 @@
m_actions << open;
- KAction *onTop = new KAction(i18n("Stay always on top"), this);
+ KAction *onTop = new KAction(i18n("Preview dialog always on top"), this);
onTop->setCheckable(true);
onTop->setChecked(true);
connect(onTop, SIGNAL(toggled(bool)), this, SLOT(stayOnTop(bool)));
@@ -251,7 +253,6 @@
void Previewer::closeFile(bool hide)
{
- //previewing = false;
//mime_icon->clear();
setupPreviewDialog();
m_dialog->setMimeIcon(QPixmap());
@@ -287,7 +288,6 @@
openUrls(urls);
}
-// FIXME: update the PreviewWidget
void Previewer::addPreview(const QUrl& url, KMimeType::Ptr mimeType)
{
if (m_previewHistory.contains(url)) {
@@ -314,9 +314,8 @@
}
if (m_previewHistory.isEmpty()) {
- //TODO: animating this would be WICKED smooth =)
- resize(size().width(), PreviewWidget::s_topBorder + \
m_previewWidget->bottomBorderHeight() +
- m_previewWidget->iconSize().height() + \
PreviewWidget::s_spacing*2); + // animating this is WICKED smooth =)
+ m_previewWidget->expand();
}
KAction *a = new KAction(KIcon(mimeType->iconName()), KUrl(url).fileName(), \
this);
--- trunk/kdereview/plasma/applets/previewer/previewdialog.cpp #869839:869840
@@ -64,7 +64,6 @@
remove_i->setIcon(KIcon("user-trash"));
remove_i->setToolTip(i18n("Close and remove the file"));
-
QToolButton *close_i = new QToolButton(this);
close_i->setAutoRaise(true);
close_i->setIcon(KIcon("dialog-close"));
@@ -74,7 +73,6 @@
run_i->setIcon(KIcon("system-run"));
run_i->setToolTip(i18n("Open with the correct application"));
-
connect(close_i, SIGNAL(clicked()), this, SIGNAL(closeClicked()));
connect(remove_i, SIGNAL(clicked()), this, SIGNAL(removeClicked()));
connect(run_i, SIGNAL(clicked()), this, SIGNAL(runClicked()));
--- trunk/kdereview/plasma/applets/previewer/previewwidget.cpp #869839:869840
@@ -23,6 +23,7 @@
#include <QGraphicsSceneWheelEvent>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
+#include <QTimeLine>
// KDE
#include <KDebug>
@@ -39,12 +40,13 @@
#include <Plasma/ScrollBar>
#include <Plasma/Theme>
+const int EXPANDING_DURATION = 250;
PreviewWidget::PreviewWidget(QGraphicsItem *parent)
: QGraphicsWidget(parent),
m_selectedIndex(-1),
m_hoveredIndex(-1),
- m_closeStatus(false)
+ m_closeStatus(true)
{
m_scrollBar = new Plasma::ScrollBar(Qt::Vertical, this);
connect(m_scrollBar->nativeWidget(), SIGNAL(valueChanged(int)), this, \
SLOT(scrolled( int ))); @@ -64,6 +66,9 @@
m_logo = new Plasma::Svg(this);
m_logo->setImagePath("widgets/previewer-16");
+ m_timeLine = new QTimeLine(EXPANDING_DURATION, this);
+ connect(m_timeLine, SIGNAL(frameChanged(int)), this, SLOT(expandingSlot(int)));
+
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setupOptionViewItem()));
}
@@ -277,8 +282,11 @@
if (m_arrowRect.contains(event->pos().toPoint())) {
m_closeStatus = !m_closeStatus;
- calculateRects();
- update();
+ if (m_closeStatus) {
+ contract();
+ } else {
+ expand();
+ }
}
}
@@ -299,8 +307,10 @@
{
m_previewHistory.clear();
m_previewHistory = list;
+
calculateRects();
update();
+
lookForPreview();
}
@@ -320,18 +330,22 @@
const int bottomBorder = bottomBorderHeight();
// items rect shouldn't be visible even if the status is close
- if (m_previewHistory.isEmpty() || m_closeStatus) {
- m_itemsRect = QRect(5, s_topBorder, itemRectWidth, 0);
+ if (m_previewHistory.isEmpty() || (m_closeStatus && m_timeLine->state() == \
QTimeLine::NotRunning)) { + m_animationHeight = s_topBorder + bottomBorder;
m_scrollBar->setGeometry(QRect());
} else {
- const int itemRectHeight = rect.height() - s_topBorder - bottomBorder;
+ if (m_timeLine->state() == QTimeLine::NotRunning) {
+ m_animationHeight = rect.height();
+ }
+ const int itemRectHeight = m_animationHeight - s_topBorder - bottomBorder;
m_itemsRect = QRect(5, s_topBorder, itemRectWidth, itemRectHeight);
QRect r = QRect(m_itemsRect.right() - scrollBarWidth + 2, s_topBorder + 1, \
scrollBarWidth,
- rect.height() - s_topBorder - bottomBorder - 2);
+ m_animationHeight - s_topBorder - bottomBorder - 2);
m_scrollBar->setGeometry(r);
}
+ kDebug()<<m_animationHeight;
m_arrowRect = QRect(rect.width() - 30 - 5, (s_topBorder / 2), 10,10);
@@ -339,10 +353,32 @@
rect.width() - m_itemsRect.right() - rect.x(),
m_itemsRect.height());
- //kDebug() << m_itemsRect << m_previewRect;
m_layoutIsValid = false;
}
+void PreviewWidget::expandingSlot(int frame)
+{
+ m_animationHeight = frame;
+ calculateRects();
+ update();
+}
+
+void PreviewWidget::contract()
+{
+ m_closeStatus = true;
+
+ m_timeLine->setFrameRange(contentsRect().height(), s_topBorder + \
bottomBorderHeight()); + m_timeLine->start();
+}
+
+void PreviewWidget::expand()
+{
+ m_closeStatus = false;
+
+ m_timeLine->setFrameRange(s_topBorder + bottomBorderHeight(), \
contentsRect().height()); + m_timeLine->start();
+}
+
void PreviewWidget::scrolled( int value )
{
Q_UNUSED(value);
@@ -420,13 +456,12 @@
drawOpenCloseArrow(painter);
- if (!m_items.isEmpty() && !m_closeStatus) {
+ if (!m_items.isEmpty() ) {
painter->save();
painter->setClipping(true);
painter->setClipRect(m_itemsRect);
PreviewItemModel model(m_previewHistory);
- m_delegate.setShadowColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
//TODO: this could look a lot nicer with a gradient
painter->fillRect(m_itemsRect.intersected(opt->rect), QColor(0, 0, 0, 80));
--- trunk/kdereview/plasma/applets/previewer/previewwidget.h #869839:869840
@@ -35,6 +35,7 @@
class QGraphicsSceneWheelEvent;
class QGraphicsSceneResizeEvent;
class KFileItem;
+class QTimeLine;
class PreviewWidget : public QGraphicsWidget
{
@@ -59,6 +60,10 @@
static const int s_logoSize = 27;
static const int s_topBorder = s_logoSize + 8;
+ public slots:
+ void expand();
+ void contract();
+
protected:
void layoutItems();
void lookForPreview();
@@ -84,6 +89,7 @@
virtual void scrolled(int);
void setupOptionViewItem();
void calculateRects();
+ virtual void expandingSlot(int);
signals:
void fileOpenRequested(const KUrl &);
@@ -108,6 +114,8 @@
QPoint m_clicked;
bool m_closeStatus; // defines whether the widget should be drawn open or \
close QRect m_arrowRect;
+ QTimeLine *m_timeLine;
+ int m_animationHeight;
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic