#include <basictoolsplugin.h>
Inheritance diagram for BasicToolsPlugin:


Definition at line 35 of file basictoolsplugin.h.
Public Member Functions | |
| QStringList | brushes () const |
| QRect | mousePress (const QString &brush, QPainter &painter, const QPoint &pos) |
| QRect | mouseMove (const QString &brush, QPainter &painter, const QPoint &oldPos, const QPoint &newPos) |
| QRect | mouseRelease (const QString &brush, QPainter &painter, const QPoint &pos) |
| QStringList | shapes () const |
| QPainterPath | generateShape (const QString &shape, QWidget *parent) |
| QStringList | filters () const |
| QImage | filterImage (const QString &filter, const QImage &image, QWidget *parent) |
| QStringList BasicToolsPlugin::brushes | ( | ) | const [virtual] |
Implements BrushInterface.
Definition at line 33 of file basictoolsplugin.cpp.
00034 { 00035 return QStringList() << tr("Pencil") << tr("Air Brush") 00036 << tr("Random Letters"); 00037 }
| QRect BasicToolsPlugin::mousePress | ( | const QString & | brush, | |
| QPainter & | painter, | |||
| const QPoint & | pos | |||
| ) | [virtual] |
Implements BrushInterface.
Definition at line 39 of file basictoolsplugin.cpp.
References mouseMove().
00041 { 00042 return mouseMove(brush, painter, pos, pos); 00043 }
Here is the call graph for this function:

| QRect BasicToolsPlugin::mouseMove | ( | const QString & | brush, | |
| QPainter & | painter, | |||
| const QPoint & | oldPos, | |||
| const QPoint & | newPos | |||
| ) | [virtual] |
Implements BrushInterface.
Definition at line 45 of file basictoolsplugin.cpp.
References QColor::blue, QPen::color(), Qt::Dense6Pattern, QPainter::drawEllipse(), QPainter::drawLine(), QPainter::drawText(), QPainter::font(), QColor::green, i, metrics(), Qt::NoPen, QPainter::pen(), QFont::pointSize(), qrand(), QColor::red, QPainter::restore(), QPainter::save(), QFont::setBold(), QPainter::setBrush(), QPainter::setFont(), QPainter::setPen(), QFont::setPointSize(), QPen::width(), QPoint::x(), x, QPoint::y(), and y.
Referenced by mousePress().
00047 { 00048 painter.save(); 00049 00050 int rad = painter.pen().width() / 2; 00051 QRect boundingRect = QRect(oldPos, newPos).normalized() 00052 .adjusted(-rad, -rad, +rad, +rad); 00053 QColor color = painter.pen().color(); 00054 int thickness = painter.pen().width(); 00055 QColor transparentColor(color.red(), color.green(), color.blue(), 0); 00056 00057 if (brush == tr("Pencil")) { 00058 painter.drawLine(oldPos, newPos); 00059 } else if (brush == tr("Air Brush")) { 00060 int numSteps = 2 + (newPos - oldPos).manhattanLength() / 2; 00061 00062 painter.setBrush(QBrush(color, Qt::Dense6Pattern)); 00063 painter.setPen(Qt::NoPen); 00064 00065 for (int i = 0; i < numSteps; ++i) { 00066 int x = oldPos.x() + i * (newPos.x() - oldPos.x()) / (numSteps - 1); 00067 int y = oldPos.y() + i * (newPos.y() - oldPos.y()) / (numSteps - 1); 00068 00069 painter.drawEllipse(x - (thickness / 2), y - (thickness / 2), 00070 thickness, thickness); 00071 } 00072 } else if (brush == tr("Random Letters")) { 00073 QChar ch('A' + (qrand() % 26)); 00074 00075 QFont biggerFont = painter.font(); 00076 biggerFont.setBold(true); 00077 biggerFont.setPointSize(biggerFont.pointSize() + thickness); 00078 painter.setFont(biggerFont); 00079 00080 painter.drawText(newPos, QString(ch)); 00081 00082 QFontMetrics metrics(painter.font()); 00083 boundingRect = metrics.boundingRect(ch); 00084 boundingRect.translate(newPos); 00085 boundingRect.adjust(-10, -10, +10, +10); 00086 } 00087 painter.restore(); 00088 return boundingRect; 00089 }
Here is the call graph for this function:

| QRect BasicToolsPlugin::mouseRelease | ( | const QString & | brush, | |
| QPainter & | painter, | |||
| const QPoint & | pos | |||
| ) | [virtual] |
Implements BrushInterface.
Definition at line 91 of file basictoolsplugin.cpp.
00094 { 00095 return QRect(0, 0, 0, 0); 00096 }
| QStringList BasicToolsPlugin::shapes | ( | ) | const [virtual] |
Implements ShapeInterface.
Definition at line 98 of file basictoolsplugin.cpp.
00099 { 00100 return QStringList() << tr("Circle") << tr("Star") << tr("Text..."); 00101 }
| QPainterPath BasicToolsPlugin::generateShape | ( | const QString & | shape, | |
| QWidget * | parent | |||
| ) | [virtual] |
Implements ShapeInterface.
Definition at line 103 of file basictoolsplugin.cpp.
References QFont::ForceOutline, QInputDialog::getText(), i, QString::isEmpty(), QLineEdit::Normal, QObject::parent(), path, and Pi.
00105 { 00106 QPainterPath path; 00107 00108 if (shape == tr("Circle")) { 00109 path.addEllipse(0, 0, 50, 50); 00110 } else if (shape == tr("Star")) { 00111 path.moveTo(90, 50); 00112 for (int i = 1; i < 5; ++i) { 00113 path.lineTo(50 + 40 * cos(0.8 * i * Pi), 00114 50 + 40 * sin(0.8 * i * Pi)); 00115 } 00116 path.closeSubpath(); 00117 } else if (shape == tr("Text...")) { 00118 QString text = QInputDialog::getText(parent, tr("Text Shape"), 00119 tr("Enter text:"), 00120 QLineEdit::Normal, tr("Qt")); 00121 if (!text.isEmpty()) { 00122 QFont timesFont("Times", 50); 00123 timesFont.setStyleStrategy(QFont::ForceOutline); 00124 path.addText(0, 0, timesFont, text); 00125 } 00126 } 00127 00128 return path; 00129 }
Here is the call graph for this function:

| QStringList BasicToolsPlugin::filters | ( | ) | const [virtual] |
Implements FilterInterface.
Definition at line 131 of file basictoolsplugin.cpp.
00132 { 00133 return QStringList() << tr("Invert Pixels") << tr("Swap RGB") 00134 << tr("Grayscale"); 00135 }
| QImage BasicToolsPlugin::filterImage | ( | const QString & | filter, | |
| const QImage & | image, | |||
| QWidget * | parent | |||
| ) | [virtual] |
Implements FilterInterface.
Definition at line 137 of file basictoolsplugin.cpp.
References alpha, QImage::Format_RGB32, Qt::gray, QImage::height(), image, QImage::invertPixels(), QImage::pixel(), qAlpha(), qGray(), qRgba(), QImage::rgbSwapped(), QImage::setPixel(), QImage::width(), x, and y.
00139 { 00140 QImage result = image.convertToFormat(QImage::Format_RGB32); 00141 00142 if (filter == tr("Invert Pixels")) { 00143 result.invertPixels(); 00144 } else if (filter == tr("Swap RGB")) { 00145 result = result.rgbSwapped(); 00146 } else if (filter == tr("Grayscale")) { 00147 for (int y = 0; y < result.height(); ++y) { 00148 for (int x = 0; x < result.width(); ++x) { 00149 int pixel = result.pixel(x, y); 00150 int gray = qGray(pixel); 00151 int alpha = qAlpha(pixel); 00152 result.setPixel(x, y, qRgba(gray, gray, gray, alpha)); 00153 } 00154 } 00155 } 00156 return result; 00157 }
Here is the call graph for this function:

1.5.1