[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/plasma/applets/frame
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2007-12-21 0:44:52
Message-ID: 1198197892.564343.23930.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 751071 by aseigo:
* don't resize on choosing a picture, let the user do that
* center the image if we don't have the same size as the contents (e.g. on \
slideshows)
* use the contentRect() method to get the right picture size
* use Plasma::roundedRectangle instead of making our own
M +20 -28 frame.cpp
M +1 -3 frame.h
--- trunk/extragear/plasma/applets/frame/frame.cpp #751070:751071
@@ -48,7 +48,7 @@
Frame::Frame(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
- m_dialog(0), m_paintCount(0)
+ m_dialog(0)
{
setHasConfigurationInterface(true);
setAcceptDrops(true);
@@ -168,12 +168,7 @@
}
}
- QSize frameSize = m_picture.size();
- frameSize.scale(contentSize().toSize(), Qt::KeepAspectRatio);
- setSize(frameSize);
-
m_pixmapCache = QPixmap();
-
update();
}
@@ -279,42 +274,38 @@
}
void Frame::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option,
- const QRect &contentsRect)
+ const QRect &rect)
{
- // HACK: paintCount is a work around to ensure we paint in the cache
- // several times the first time. Without this workaround we get garbage
- // in the cache (likely to be a Qt bug)
-
- if (m_pixmapCache.isNull() || contentsRect.size()!=m_pixmapCache.size()
- || m_paintCount<2) {
-
- paintCache(option, contentsRect);
-
- if (m_paintCount<2) {
- ++m_paintCount;
- }
+ if (m_pixmapCache.isNull() || \
contentRect().toRect().size()!=m_pixmapCache.size()) { + paintCache(option, \
contentRect().toRect().size()); }
- p->drawPixmap(contentsRect, m_pixmapCache);
+// p->save();
+// p->setCompositionMode(QPainter::CompositionMode_Source);
+ p->drawPixmap(rect, m_pixmapCache, rect);
+// p->restore();
}
void Frame::paintCache(const QStyleOptionGraphicsItem *option,
- const QRect &contentsRect)
+ const QSize &contentsSize)
{
Q_UNUSED(option);
- m_pixmapCache = QPixmap(contentsRect.size());
+ m_pixmapCache = QPixmap(contentsSize);
m_pixmapCache.fill(Qt::transparent);
QPainter *p = new QPainter(&m_pixmapCache);
- p->fillRect(m_pixmapCache.rect(), Qt::transparent);
int roundingFactor = 12 * m_roundCorners;
int swRoundness = roundingFactor+m_frameOutline/2*m_frame*m_roundCorners;
- QRect frameRect = contentsRect.adjusted(m_swOutline, m_swOutline,
- -m_swOutline, -m_swOutline); //Pretty \
useless. + QRect frameRect = m_pixmapCache.rect().adjusted(m_swOutline, \
m_swOutline, + -m_swOutline, \
-m_swOutline); //Pretty useless.
+ QImage scaledImage = m_picture.scaled(frameRect.size(), Qt::KeepAspectRatio, \
Qt::FastTransformation); + frameRect = QRect(QPoint(frameRect.x() + \
(frameRect.width() - scaledImage.width()) / 2, + frameRect.y() + \
(frameRect.height() - scaledImage.height()) / 2), scaledImage.size()); +
QRect shadowRect;
if (m_frame) {
shadowRect = frameRect.adjusted(-m_frameOutline+1, -m_frameOutline+1,
@@ -326,8 +317,7 @@
//choose where to draw.
///The frame path. It will be used to draw the frame and clip the image.
- QPainterPath framePath;
- framePath.addRoundRect(frameRect, roundingFactor);
+ QPainterPath framePath = Plasma::roundedRectangle(frameRect, roundingFactor);
p->setRenderHint(QPainter::SmoothPixmapTransform, true);
p->setRenderHint(QPainter::Antialiasing, true);
@@ -363,7 +353,9 @@
p->setClipPath(framePath);
}
- p->drawImage(frameRect, m_picture.scaledToWidth(frameRect.width()));
+ // scale and center
+// kDebug() << "painting to" << frameRect << imageTarget << "for image of size" \
<< scaledImage.size(); + p->drawImage(frameRect, scaledImage);
p->restore();
// black frame
--- trunk/extragear/plasma/applets/frame/frame.h #751070:751071
@@ -68,7 +68,7 @@
private:
void paintCache(const QStyleOptionGraphicsItem *option,
- const QRect &contentsRect);
+ const QSize &contentsSize);
/// The current color of the frame
QColor m_frameColor;
@@ -100,8 +100,6 @@
int m_swOutline;
/// Max Picture Dimension
static const int m_maxDimension=800;
- // HACK: Ensure several repaints, cf. paintInterface() code
- int m_paintCount;
/// Designer Config file
Ui::config ui;
/// Default image
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic