00001 #include <cassert>
00002 #include <qpainter.h>
00003 #include <qpixmap.h>
00004 #include "mythpainter_qt.h"
00005 #include "mythfontproperties.h"
00006 #include "mythmainwindow.h"
00007 #include "compat.h"
00008
00009 class MythQtImage : public MythImage
00010 {
00011 public:
00012 MythQtImage(MythPainter *parent) : MythImage(parent) { }
00013
00014 void SetChanged(bool change = true);
00015 QPixmap *GetPixmap(void) { return &m_Pixmap; }
00016
00017 protected:
00018 QPixmap m_Pixmap;
00019 };
00020
00021 void MythQtImage::SetChanged(bool change)
00022 {
00023 if (change)
00024 m_Pixmap.convertFromImage(*((QImage *)this));
00025
00026 MythImage::SetChanged(change);
00027 }
00028
00029 MythQtPainter::MythQtPainter()
00030 : MythPainter()
00031 {
00032 }
00033
00034 MythQtPainter::~MythQtPainter()
00035 {
00036 }
00037
00038 void MythQtPainter::Begin(QWidget *parent)
00039 {
00040 assert(parent);
00041
00042 MythPainter::Begin(parent);
00043
00044
00045 mainPainter = new QPainter(parent);
00046 drawPixmap = new QPixmap(parent->size());
00047 painter = new QPainter(drawPixmap);
00048
00049 clipRegion = QRegion(QRect(0, 0, 0, 0));
00050 }
00051
00052 void MythQtPainter::End(void)
00053 {
00054 painter->end();
00055
00056 if (!clipRegion.isEmpty() && !clipRegion.isNull())
00057 {
00058 QMemArray<QRect> rects = clipRegion.rects();
00059
00060 for (unsigned int i = 0; i < rects.size(); i++)
00061 {
00062 QRect rect = rects[i];
00063
00064 if (rect.width() == 0 || rect.height() == 0)
00065 continue;
00066
00067 mainPainter->drawPixmap(rect.topLeft(), *drawPixmap, rect);
00068 }
00069 }
00070 else
00071 mainPainter->drawPixmap(0, 0, *drawPixmap);
00072
00073 mainPainter->end();
00074
00075 delete painter;
00076 delete drawPixmap;
00077 delete mainPainter;
00078
00079 MythPainter::End();
00080 }
00081
00082 void MythQtPainter::SetClipRect(const QRect &clipRect)
00083 {
00084 if (clipRect.size() == drawPixmap->size())
00085 return;
00086
00087 painter->setClipRect(clipRect);
00088 if (clipRect != QRect())
00089 {
00090 painter->setClipping(true);
00091 if (clipRegion.isNull() || clipRegion.isEmpty())
00092 clipRegion = QRegion(clipRect);
00093 else
00094 clipRegion = clipRegion.unite(clipRect);
00095 }
00096 else
00097 painter->setClipping(false);
00098 }
00099
00100 void MythQtPainter::DrawImage(const QRect &r, MythImage *im,
00101 const QRect &src, int alpha)
00102 {
00103 assert(painter);
00104 (void)alpha;
00105
00106 MythQtImage *qim = reinterpret_cast<MythQtImage *>(im);
00107
00108 painter->drawPixmap(r.topLeft(), *(qim->GetPixmap()), src);
00109 }
00110
00111 void MythQtPainter::DrawText(const QRect &r, const QString &msg,
00112 int flags, const MythFontProperties &font,
00113 int alpha)
00114 {
00115 assert(painter);
00116 (void)alpha;
00117
00118 painter->setFont(font.face());
00119
00120 if (font.hasShadow())
00121 {
00122 QPoint shadowOffset;
00123 QColor shadowColor;
00124 int shadowAlpha;
00125
00126 font.GetShadow(shadowOffset, shadowColor, shadowAlpha);
00127
00128 QRect a = r;
00129 a.moveBy(shadowOffset.x(), shadowOffset.y());
00130
00131 painter->setPen(shadowColor);
00132 painter->drawText(a, flags, msg);
00133 }
00134
00135 if (font.hasOutline() && alpha > 128)
00136 {
00137 QColor outlineColor;
00138 int outlineSize, outlineAlpha;
00139
00140 font.GetOutline(outlineColor, outlineSize, outlineAlpha);
00141
00142 if (GetMythMainWindow()->GetUIScreenRect().height() > 700)
00143 outlineSize = 1;
00144
00145 painter->setPen(outlineColor);
00146
00147 QRect a = r;
00148 a.moveBy(0 - outlineSize, 0 - outlineSize);
00149 painter->drawText(a, flags, msg);
00150
00151 for (int i = (0 - outlineSize + 1); i <= outlineSize; i++)
00152 {
00153 a.moveBy(1, 0);
00154 painter->drawText(a, flags, msg);
00155 }
00156
00157 for (int i = (0 - outlineSize + 1); i <= outlineSize; i++)
00158 {
00159 a.moveBy(0, 1);
00160 painter->drawText(a, flags, msg);
00161 }
00162
00163 for (int i = (0 - outlineSize + 1); i <= outlineSize; i++)
00164 {
00165 a.moveBy(-1, 0);
00166 painter->drawText(a, flags, msg);
00167 }
00168
00169 for (int i = (0 - outlineSize + 1); i <= outlineSize; i++)
00170 {
00171 a.moveBy(0, -1);
00172 painter->drawText(a, flags, msg);
00173 }
00174 }
00175
00176 painter->setPen(font.color());
00177 painter->drawText(r, flags, msg);
00178 }
00179
00180 MythImage *MythQtPainter::GetFormatImage()
00181 {
00182 return new MythQtImage(this);
00183 }
00184
00185 void MythQtPainter::DeleteFormatImage(MythImage* )
00186 {
00187 }
00188