it makes no sense to have the blur stuff in one header/namespace and the roundedRectangle stuff in another: it's all painting related. putting them together, however, makes "ImageEffects" really not accurate. ImageEffects will also clash, concept-wise, with a real effects lib.

therefore, introducing Plasma::PaintUtils.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=827859
This commit is contained in:
Aaron J. Seigo 2008-07-03 23:50:13 +00:00
parent 1c0edaceb7
commit 922c85c705
10 changed files with 41 additions and 38 deletions

View File

@ -39,8 +39,8 @@ set(plasma_LIB_SRCS
dialog.cpp
#FOR FUTURE
#layouts/borderlayout.cpp
imageeffects.cpp
packages.cpp
paintutils.cpp
panelsvg.cpp
paneltoolbox.cpp
plasma.cpp
@ -128,7 +128,7 @@ set(plasma_LIB_INCLUDES
dataenginemanager.h
delegate.h
dialog.h
imageeffects.h
paintutils.h
panelsvg.h
plasma.h
plasma_export.h
@ -202,13 +202,13 @@ includes/Dialog
includes/Flash
includes/GroupBox
includes/Icon
includes/ImageEffects
includes/Label
includes/LineEdit
includes/Meter
includes/Package
includes/PackageMetadata
includes/PackageStructure
includes/PaintUtils
includes/PanelSvg
includes/Plasma
includes/PushButton

View File

@ -38,6 +38,7 @@
#include "applet_p.h"
#include "containment.h"
#include "corona.h"
#include "paintutils.h"
#include "theme.h"
#include "view.h"
@ -170,7 +171,7 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
gr.setColorAt(0.1, KColorScheme::shade(m_gradientColor, KColorScheme::LightShade));
gr.setColorAt(1, KColorScheme::shade(m_gradientColor, KColorScheme::DarkShade));
painter->setBrush(gr);
QPainterPath path = Plasma::roundedRectangle(boundingRect(), 10);
QPainterPath path = PaintUtils::roundedRectangle(boundingRect(), 10);
if (m_applet) {
QPainterPath shape = m_applet->shape();

View File

@ -41,7 +41,7 @@
#include <KColorScheme>
// plasma
#include <plasma/plasma.h>
#include <plasma/paintutils.h>
namespace Plasma
{
@ -312,7 +312,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem& option, cons
}
painter->setPen(outlinePen);
painter->drawPath(Plasma::roundedRectangle(highlightRect, roundedRadius));
painter->drawPath(PaintUtils::roundedRectangle(highlightRect, roundedRadius));
painter->restore();
}

View File

@ -1 +0,0 @@
#include "../../plasma/imageeffects.h"

1
includes/PaintUtils Normal file
View File

@ -0,0 +1 @@
#include "../../plasma/paintutils.h"

View File

@ -18,16 +18,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <imageeffects.h>
#include "effects/blur.cpp"
#include <paintutils.h>
#include <QImage>
#include <QPainter>
#include <QPixmap>
#include "effects/blur.cpp"
namespace Plasma
{
namespace ImageEffects
namespace PaintUtils
{
void shadowBlur(QImage &image, int radius, const QColor &color)
@ -76,7 +78,22 @@ QPixmap shadowText(QString text, QColor textColor, QColor shadowColor, QPoint of
return finalPixmap;
}
} //ImageEffects namespace
QPainterPath roundedRectangle(const QRectF& rect, qreal radius)
{
QPainterPath path(QPointF(rect.left(), rect.top() + radius));
path.quadTo(rect.left(), rect.top(), rect.left() + radius, rect.top()); // Top left corner
path.lineTo(rect.right() - radius, rect.top()); // Top side
path.quadTo(rect.right(), rect.top(), rect.right(), rect.top() + radius); // Top right corner
path.lineTo(rect.right(), rect.bottom() - radius); // Right side
path.quadTo(rect.right(), rect.bottom(), rect.right() - radius, rect.bottom()); // Bottom right corner
path.lineTo(rect.left() + radius, rect.bottom()); // Bottom side
path.quadTo(rect.left(), rect.bottom(), rect.left(), rect.bottom() - radius); // Bottom left corner
path.closeSubpath();
return path;
}
} // PaintUtils namespace
} // Plasma namespace

View File

@ -33,7 +33,7 @@ namespace Plasma
/**
* Namespace for all Image Effects specific to Plasma
**/
namespace ImageEffects
namespace PaintUtils
{
/**
@ -51,7 +51,12 @@ PLASMA_EXPORT QPixmap shadowText(QString text,
QPoint offset = QPoint(1,1),
int radius = 2);
} // ImageEffects namespace
/**
* Returns a nicely rounded rectanglular path for painting.
*/
PLASMA_EXPORT QPainterPath roundedRectangle(const QRectF& rect, qreal radius);
} // PaintUtils namespace
} // Plasma namespace

View File

@ -62,19 +62,4 @@ Direction locationToDirection(Location location)
return Down;
}
QPainterPath roundedRectangle(const QRectF& rect, qreal radius)
{
QPainterPath path(QPointF(rect.left(), rect.top() + radius));
path.quadTo(rect.left(), rect.top(), rect.left() + radius, rect.top()); // Top left corner
path.lineTo(rect.right() - radius, rect.top()); // Top side
path.quadTo(rect.right(), rect.top(), rect.right(), rect.top() + radius); // Top right corner
path.lineTo(rect.right(), rect.bottom() - radius); // Right side
path.quadTo(rect.right(), rect.bottom(), rect.right() - radius, rect.bottom()); // Bottom right corner
path.lineTo(rect.left() + radius, rect.bottom()); // Bottom side
path.quadTo(rect.left(), rect.bottom(), rect.left(), rect.bottom() - radius); // Bottom left corner
path.closeSubpath();
return path;
}
} // Plasma namespace

View File

@ -193,11 +193,6 @@ PLASMA_EXPORT qreal scalingFactor(ZoomLevel level);
**/
PLASMA_EXPORT Direction locationToDirection(Location location);
/**
* Returns a nicely rounded rectanglular path for painting.
*/
PLASMA_EXPORT QPainterPath roundedRectangle(const QRectF& rect, qreal radius);
} // Plasma namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Constraints)

View File

@ -50,8 +50,8 @@
#include <KDebug>
#include <KColorScheme>
#include <plasma/paintutils.h>
#include <plasma/theme.h>
#include <plasma/imageeffects.h>
#include "animator.h"
#include "svg.h"
@ -394,7 +394,7 @@ QPainterPath Icon::shape() const
return QGraphicsItem::shape();
}
return roundedRectangle(QRectF(QPointF(0.0, 0.0), d->currentSize).adjusted(-2, -2, 2, 2), 10.0);
return PaintUtils::roundedRectangle(QRectF(QPointF(0.0, 0.0), d->currentSize).adjusted(-2, -2, 2, 2), 10.0);
}
QSizeF IconPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option, const qreal width) const
@ -582,7 +582,7 @@ void IconPrivate::drawBackground(QPainter *painter, IconState state)
painter->setRenderHint(QPainter::Antialiasing);
painter->setBrush(shadow);
painter->setPen(QPen(border, 1));
painter->drawPath(roundedRectangle(QRectF(QPointF(1, 1), QSize((int)currentSize.width()-2, (int)currentSize.height()-2)), 5.0));
painter->drawPath(PaintUtils::roundedRectangle(QRectF(QPointF(1, 1), QSize((int)currentSize.width()-2, (int)currentSize.height()-2)), 5.0));
painter->restore();
}
@ -939,7 +939,7 @@ void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
shadowOffset = QPoint(0,0);
}
Plasma::ImageEffects::shadowBlur(shadow, 2, d->shadowColor);
PaintUtils::shadowBlur(shadow, 2, d->shadowColor);
painter->drawImage(textBoundingRect.topLeft()+shadowOffset, shadow);
d->drawTextItems(painter, option, labelLayout, infoLayout);
}