+++ /dev/null
-/*
- * This is an adaptation of Jani Huhtanen Exponential blur code.
- *
- * Copyright 2007 Jani Huhtanen <jani.huhtanen@tut.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License version 2 as
- * published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include <QImage>
-#include <cmath>
-
-#include "imageblur.h"
-
-/* ============================================================================
- * PUBLIC Constructor/Destructors
- */
-ImageBlur::ImageBlur (QImage *image, int aprec, int zprec) {
- m_image = image;
- m_aprec = aprec;
- m_zprec = zprec;
-}
-
-ImageBlur::~ImageBlur() {
- m_image = NULL;
-}
-
-/* ============================================================================
- * PUBLIC STATIC Methods
- */
-void ImageBlur::expblur (QImage *image, int aprec, int zprec, int radius) {
- ImageBlur imageBlur(image, aprec, zprec);
- imageBlur.expblur(radius);
-}
-
-/* ============================================================================
- * PUBLIC Methods
- */
-void ImageBlur::expblur (int radius) {
- if (radius < 1)
- return;
-
- /* Calculate the alpha such that 90% of
- * the kernel is within the radius.
- * (Kernel extends to infinity)
- */
- int alpha = (int)((1 << m_aprec) * (1.0f - std::exp(-2.3f / (radius + 1.f))));
-
- for (int row = 0; row < m_image->height(); ++row)
- blurrow(row, alpha);
-
- for (int col = 0; col < m_image->width(); ++col)
- blurcol(col, alpha);
-}
-
-/* ============================================================================
- * PRIVATE Methods
- */
-void ImageBlur::blurcol (int col, int alpha) {
- int zR, zG, zB, zA;
-
- QRgb *ptr = (QRgb *)m_image->bits();
- ptr += col;
-
- zR = *((unsigned char *)ptr ) << m_zprec;
- zG = *((unsigned char *)ptr + 1) << m_zprec;
- zB = *((unsigned char *)ptr + 2) << m_zprec;
- zA = *((unsigned char *)ptr + 3) << m_zprec;
-
- for (int index = m_image->width();
- index < (m_image->height() - 1) * m_image->width();
- index += m_image->width())
- {
- blurinner((unsigned char *)&ptr[index], zR, zG, zB, zA, alpha);
- }
-
- for (int index = (m_image->height() - 2) * m_image->width();
- index >= 0;
- index -= m_image->width())
- {
- blurinner((unsigned char *)&ptr[index], zR, zG, zB, zA, alpha);
- }
-}
-
-void ImageBlur::blurrow (int line, int alpha) {
- int zR, zG, zB, zA;
-
- QRgb *ptr = (QRgb *)m_image->scanLine(line);
-
- zR = *((unsigned char *)ptr ) << m_zprec;
- zG = *((unsigned char *)ptr + 1) << m_zprec;
- zB = *((unsigned char *)ptr + 2) << m_zprec;
- zA = *((unsigned char *)ptr + 3) << m_zprec;
-
- for (int index = 1; index < m_image->width(); ++index)
- blurinner((unsigned char *)&ptr[index], zR, zG, zB, zA, alpha);
-
- for (int index = m_image->width() - 2; index >= 0; --index)
- blurinner((unsigned char *)&ptr[index], zR, zG, zB, zA, alpha);
-}
-
-void ImageBlur::blurinner ( unsigned char *bptr,
- int &zR, int &zG, int &zB, int &zA,
- int alpha)
-{
- int R, G, B, A;
- R = *bptr;
- G = *(bptr + 1);
- B = *(bptr + 2);
- A = *(bptr + 3);
-
- zR += (alpha * ((R << m_zprec) - zR)) >> m_aprec;
- zG += (alpha * ((G << m_zprec) - zG)) >> m_aprec;
- zB += (alpha * ((B << m_zprec) - zB)) >> m_aprec;
- zA += (alpha * ((A << m_zprec) - zA)) >> m_aprec;
-
- *bptr = zR >> m_zprec;
- *(bptr+1) = zG >> m_zprec;
- *(bptr+2) = zB >> m_zprec;
- *(bptr+3) = zA >> m_zprec;
-}
-
+++ /dev/null
-/*
- * This is an adaptation of Jani Huhtanen Exponential blur code.
- *
- * Copyright 2007 Jani Huhtanen <jani.huhtanen@tut.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License version 2 as
- * published by the Free Software Foundation
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#ifndef _KDE_PLASMA_BLUR_H_
-#define _KDE_PLASMA_BLUR_H_
-
-class QImage;
-
-class ImageBlur {
- public:
- ImageBlur (QImage *image, int aprec, int zprec);
- ~ImageBlur();
-
- public:
- void expblur (int radius);
-
- public:
- static void expblur (QImage *image, int aprec, int zprec, int radius);
-
- private:
- void blurcol (int col, int alpha);
- void blurrow (int line, int alpha);
-
- void blurinner (unsigned char *bptr,
- int &zR, int &zG, int &zB, int &zA,
- int alpha);
-
- private:
- QImage *m_image;
- int m_aprec;
- int m_zprec;
-};
-
-#endif /* !_KDE_PLASMA_BLUR_H_ */
-
+#include <QPainter>
#include <QPaintEvent>
#include <QList>
-#include "thblackbutton.h"
#include "thblackbar.h"
-#include "thpainter.h"
#include "thaction.h"
/* ============================================================================
+++ /dev/null
-#include <QPaintEvent>
-
-#include "thblackbutton.h"
-#include "thpainter.h"
-
-/* ============================================================================
- * PRIVATE Class
- */
-class THBlackButton::Private {
- public:
- qreal leftTopRadius;
- qreal leftBottomRadius;
- qreal rightTopRadius;
- qreal rightBottomRadius;
-};
-
-/* ============================================================================
- * PUBLIC Constructor/Destructors
- */
-THBlackButton::THBlackButton (QWidget *parent)
- : QAbstractButton(parent), d(new THBlackButton::Private)
-{
- setRadius(10);
-}
-
-THBlackButton::THBlackButton (const QString& text, QWidget *parent)
- : QAbstractButton(parent), d(new THBlackButton::Private)
-{
- setRadius(10);
- setText(text);
-}
-
-THBlackButton::~THBlackButton() {
- delete d;
-}
-
-/* ============================================================================
- * PUBLIC Methods
- */
-void THBlackButton::setRadius (qreal radius) {
- d->leftTopRadius = radius;
- d->leftBottomRadius = radius;
- d->rightTopRadius = radius;
- d->rightBottomRadius = radius;
-}
-
-void THBlackButton::setRadius ( qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius)
-{
- d->leftTopRadius = leftTopRadius;
- d->leftBottomRadius = leftBottomRadius;
- d->rightTopRadius = rightTopRadius;
- d->rightBottomRadius = rightBottomRadius;
-}
-
-QSize THBlackButton::minimumSizeHint (void) const {
- QFontMetrics fontMetrics(QFont("Arial", 8, QFont::Bold));
- int width = fontMetrics.width(text()) + 48;
- return(QSize(width, 22));
-}
-
-/* ============================================================================
- * PROTECTED Methods
- */
-void THBlackButton::paintEvent (QPaintEvent *event) {
- int height = event->rect().height();
- int width = event->rect().width() - 10;
- int mh = (height / 2);
-
- THPainter p(this);
- p.setPen(QPen(QColor(0x28, 0x28, 0x28), 1));
-
- p.translate(5, 0);
-
- QLinearGradient linearGrad;
- QColor color;
- if (isDown()) {
- linearGrad = QLinearGradient(QPointF(0, 0), QPointF(0, mh));
- linearGrad.setColorAt(0, QColor(0x6c, 0x6c, 0x6c));
- linearGrad.setColorAt(1, QColor(0x40, 0x40, 0x40));
- color = QColor(0x35, 0x35, 0x35);
- } else {
- linearGrad = QLinearGradient(QPointF(0, 0), QPointF(0, mh));
- linearGrad.setColorAt(0, QColor(0x8e, 0x8e, 0x8e));
- linearGrad.setColorAt(1, QColor(0x5c, 0x5c, 0x5c));
- color = QColor(0x41, 0x41, 0x41);
- }
-
- p.fillRoundRect(QRect(0, 0, width, mh),
- d->leftTopRadius, 0, d->rightTopRadius, 0,
- QBrush(linearGrad));
- p.fillRoundRect(QRect(0, mh, width, mh),
- 0, d->leftBottomRadius, 0, d->rightBottomRadius,
- color);
- p.drawRoundRect(QRect(0, 0, width, height),
- d->leftTopRadius, d->leftBottomRadius,
- d->rightTopRadius, d->rightBottomRadius);
-
- p.translate(-5, 0);
-
- p.setFont(QFont("Arial", 8, QFont::Bold));
- p.setPen(QPen(QColor(0xff, 0xff, 0xff), 1));
- p.drawText(event->rect(), Qt::AlignCenter, text());
-
- p.end();
-}
-
+++ /dev/null
-#ifndef _THBLACKBUTTON_H_
-#define _THBLACKBUTTON_H_
-
-#include <QAbstractButton>
-
-class THBlackButton : public QAbstractButton {
- Q_OBJECT
-
- public:
- THBlackButton (QWidget *parent = 0);
- THBlackButton (const QString& text, QWidget *parent = 0);
- ~THBlackButton();
-
- public:
- void setRadius (qreal radius);
- void setRadius (qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius);
-
- QSize minimumSizeHint (void) const;
-
- protected:
- void paintEvent (QPaintEvent *event);
-
- private:
- class Private;
- Private *d;
-};
-
-#endif /* !_THBLACKBUTTON_H_ */
-
+++ /dev/null
-#include "imageblur.h"
-#include "thpainter.h"
-#include "thimage.h"
-
-/* ============================================================================
- * PUBLIC Constructor/Destructors
- */
-THImage::THImage (const QSize& size, Format format)
- : QImage(size, format)
-{
-}
-
-THImage::THImage (int width, int height, Format format)
- : QImage(width, height, format)
-{
-}
-
-THImage::THImage (uchar *data, int width, int height, Format format)
- : QImage(data, width, height, format)
-{
-}
-
-THImage::THImage (const uchar *data, int width, int height, Format format)
- : QImage(data, width, height, format)
-{
-}
-
-THImage::THImage (uchar *data, int width, int height, int bytesPerLine, Format format)
- : QImage(data, width, height, bytesPerLine, format)
-{
-}
-
-THImage::THImage (const uchar *data, int width, int height, int bytesPerLine, Format format)
- : QImage(data, width, height, bytesPerLine, format)
-{
-}
-
-THImage::THImage (const QString& fileName, const char *format)
- : QImage(fileName, format)
-{
-}
-
-THImage::THImage (const char *fileName, const char *format)
- : QImage(fileName, format)
-{
-}
-
-THImage::THImage (const QImage& image)
- : QImage(image)
-{
-}
-
-THImage::~THImage() {
-}
-
-/* ============================================================================
- * PUBLIC Methods
- */
-void THImage::expblur(int aprec, int zprec, int radius) {
- ImageBlur::expblur(this, aprec, zprec, radius);
-}
-#include <QCoreApplication>
-
-void THImage::shadowBlur (int radius, const QColor& color) {
- ImageBlur::expblur(this, 16, 7, radius);
-
- THPainter p(this);
- p.setCompositionMode(QPainter::CompositionMode_SourceIn);
- p.fillRect(rect(), color);
- p.end();
-}
-
-
+++ /dev/null
-#ifndef _THIMAGE_H_
-#define _THIMAGE_H_
-
-#include <QImage>
-
-class THImage : public QImage {
- public:
- THImage (const QSize& size, Format format);
- THImage (int width, int height, Format format);
- THImage (uchar *data, int width, int height, Format format);
- THImage (const uchar *data, int width, int height, Format format);
- THImage (uchar *data, int width, int height, int bytesPerLine, Format format);
- THImage (const uchar *data, int width, int height, int bytesPerLine, Format format);
- THImage (const QString& fileName, const char *format = 0);
- THImage (const char *fileName, const char *format = 0);
- THImage (const QImage& image);
- ~THImage();
-
- public:
- void expblur(int aprec, int zprec, int radius);
- void shadowBlur (int radius, const QColor& color);
-};
-
-#endif /* !_THIMAGE_H_ */
-
-
DEPENDPATH += $$PWD
INCLUDEPATH += $$PWD
-HEADERS += thimage.h \
- thaction.h \
+HEADERS += thaction.h \
thactiongroup.h \
- thblackbar.h \
- thblackbutton.h \
- thpainter.h \
- imageblur.h
-SOURCES += thimage.cpp \
- thaction.cpp \
+ thblackbar.h
+SOURCES += thaction.cpp \
thactiongroup.cpp \
- thblackbar.cpp \
- thblackbutton.cpp \
- thpainter.cpp \
- imageblur.cpp
+ thblackbar.cpp
+++ /dev/null
-#include "thpainter.h"
-#include "thimage.h"
-
-/* ============================================================================
- * PUBLIC Constructor/Destructors
- */
-THPainter::THPainter()
- : QPainter()
-{
- setRenderHint(QPainter::Antialiasing);
- setRenderHint(QPainter::TextAntialiasing);
-}
-
-THPainter::THPainter(QPaintDevice *device)
- : QPainter(device)
-{
- setRenderHint(QPainter::Antialiasing);
- setRenderHint(QPainter::TextAntialiasing);
-}
-
-THPainter::~THPainter() {
-}
-
-/* ============================================================================
- * PUBLIC STATIC Methods
- */
-QPainterPath THPainter::roundRectangle (const QRectF& rect, qreal radius) {
- return(roundRectangle(rect, radius, radius, radius, radius));
-}
-
-QPainterPath THPainter::roundRectangle (const QRectF& rect,
- qreal leftRadius,
- qreal rightRadius)
-{
- return(roundRectangle(rect, leftRadius, leftRadius, rightRadius, rightRadius));
-}
-
-QPainterPath THPainter::roundRectangle (const QRectF& rect,
- qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius)
-{
- // Top Left Corner
- // Top Side
- // Top right corner
- // Right side
- // Bottom right corner
- // Bottom side
- // Bottom left corner
-
- QPainterPath path(QPoint(rect.left(), rect.top() + leftTopRadius));
- path.quadTo(rect.left(), rect.top(), rect.left() + leftTopRadius, rect.top());
- path.lineTo(rect.right() - rightTopRadius, rect.top());
- path.quadTo(rect.right(), rect.top(), rect.right(), rect.top() + rightTopRadius);
- path.lineTo(rect.right(), rect.bottom() - rightBottomRadius);
- path.quadTo(rect.right(), rect.bottom(), rect.right() - rightBottomRadius, rect.bottom());
- path.lineTo(rect.left() + leftBottomRadius, rect.bottom());
- path.quadTo(rect.left(), rect.bottom(), rect.left(), rect.bottom() - leftBottomRadius);
- path.closeSubpath();
-
- return(path);
-}
-
-/* ============================================================================
- * PUBLIC Draw Methods
- */
-void THPainter::drawRoundRect (const QRectF& rect, qreal radius) {
- drawPath(roundRectangle(rect, radius, radius, radius, radius));
-}
-
-void THPainter::drawRoundRect (const QRectF& rect,
- qreal leftRadius,
- qreal rightRadius)
-{
- drawPath(roundRectangle(rect, leftRadius, leftRadius,
- rightRadius, rightRadius));
-}
-
-void THPainter::drawRoundRect ( const QRectF& rect,
- qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius)
-{
- drawPath(roundRectangle(rect, leftTopRadius, leftBottomRadius,
- rightTopRadius, rightBottomRadius));
-}
-
-void THPainter::drawShadowText (qreal x, qreal y,
- const QString& text,
- const QColor& shadowColor,
- const QPointF& offset,
- qreal radius)
-{
- QPainter p;
-
- // Draw Text
- QRect textRect = QFontMetrics(text).boundingRect(text);
- QImage textImage(textRect.size(), QImage::Format_ARGB32_Premultiplied);
- textImage.fill(Qt::transparent);
- p.begin(&textImage);
- p.setPen(pen());
- p.setFont(font());
- p.drawText(textImage.rect(), Qt::AlignLeft, text);
- p.end();
-
- // Draw Blurred Shadow
- THImage shadowImage(textRect.size() + QSize(radius * 2, radius * 2),
- QImage::Format_ARGB32_Premultiplied);
- shadowImage.fill(Qt::transparent);
- p.begin(&shadowImage);
- p.drawImage(radius, radius, textImage);
- p.end();
- shadowImage.shadowBlur(radius, shadowColor);
-
- // Compose Text and Shadow
- int addSizeX = (offset.x() > radius) ? (abs(offset.x()) - radius) : 0;
- int addSizeY = (offset.y() > radius) ? (abs(offset.y()) - radius) : 0;
- QSize finalSize = shadowImage.size() + QSize(addSizeX, addSizeY);
-
- QPointF shadowTopLeft(QPointF((finalSize.width() - shadowImage.width()) / 2.0,
- (finalSize.height() - shadowImage.height()) / 2.0) +
- (offset / 2.0));
- QPointF textTopLeft(QPointF((finalSize.width() - textImage.width()) / 2.0,
- ((finalSize.height() - textImage.height()) / 2.0)) -
- (offset / 2.0));
-
- // Paint Text and Shadow
- save();
- translate(x, y);
- setCompositionMode(QPainter::CompositionMode_Xor);
- drawImage(shadowTopLeft, shadowImage);
- drawImage(textTopLeft, textImage);
- restore();
-}
-
-/* ============================================================================
- * PUBLIC Fill Methods
- */
-void THPainter::fillRoundRect ( const QRectF& rect,
- qreal radius,
- const QBrush& brush)
-{
- fillPath(roundRectangle(rect, radius, radius, radius, radius), brush);
-}
-
-void THPainter::fillRoundRect ( const QRectF& rect,
- qreal leftRadius,
- qreal rightRadius,
- const QBrush& brush)
-{
- fillPath(roundRectangle(rect, leftRadius, leftRadius,
- rightRadius, rightRadius), brush);
-}
-
-void THPainter::fillRoundRect ( const QRectF& rect,
- qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius,
- const QBrush& brush)
-{
- fillPath(roundRectangle(rect, leftTopRadius, leftBottomRadius,
- rightTopRadius, rightBottomRadius), brush);
-}
-
+++ /dev/null
-#ifndef _THPAINTER_H_
-#define _THPAINTER_H_
-
-#include <QPainter>
-
-class THPainter : public QPainter {
- public:
- THPainter();
- THPainter(QPaintDevice *device);
- ~THPainter();
-
- // STATIC Methods
- static QPainterPath roundRectangle (const QRectF& rect, qreal radius);
- static QPainterPath roundRectangle (const QRectF& rect,
- qreal leftRadius,
- qreal rightRadius);
- static QPainterPath roundRectangle (const QRectF& rect,
- qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius);
-
- // Methods
- void drawShadowText ( qreal x, qreal y,
- const QString& text,
- const QColor& shadowColor,
- const QPointF& offset,
- qreal radius);
-
- void drawRoundRect (const QRectF& rect,
- qreal radius);
- void drawRoundRect (const QRectF& rect,
- qreal leftRadius,
- qreal rightRadius);
- void drawRoundRect (const QRectF& rect,
- qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius);
-
- void fillRoundRect (const QRectF& rect,
- qreal radius,
- const QBrush& brush);
- void fillRoundRect (const QRectF& rect,
- qreal leftRadius,
- qreal rightRadius,
- const QBrush& brush);
- void fillRoundRect (const QRectF& rect,
- qreal leftTopRadius,
- qreal leftBottomRadius,
- qreal rightTopRadius,
- qreal rightBottomRadius,
- const QBrush& brush);
-};
-
-#endif /* !_THPAINTER_H_ */
-