00001
00002
00003
00004
00005
00006
00007 #include "EnumsToQt.h"
00008 #include "Logger.h"
00009 #include <QPainter>
00010 #include "ViewPointStyle.h"
00011
00012
00013 const QColor COLOR_FOR_BRUSH_ENABLED (Qt::white);
00014 const QColor COLOR_FOR_BRUSH_DISABLED (Qt::gray);
00015
00016 ViewPointStyle::ViewPointStyle(QWidget *parent) :
00017 QLabel (parent),
00018 m_enabled (false)
00019 {
00020
00021 }
00022
00023 QPixmap ViewPointStyle::pixmapForCurrentSettings () const
00024 {
00025 LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::pixmapForCurrentSettings";
00026
00027
00028 QPolygonF polygonUnscaled = m_pointStyle.polygon();
00029
00030
00031 double xMinGot = polygonUnscaled.boundingRect().left();
00032 double xMaxGot = polygonUnscaled.boundingRect().right();
00033 double yMinGot = polygonUnscaled.boundingRect().top();
00034 double yMaxGot = polygonUnscaled.boundingRect().bottom();
00035
00036 QPolygonF polygonScaled;
00037 for (int i = 0; i < polygonUnscaled.length(); i++) {
00038 QPointF pOld = polygonUnscaled.at(i);
00039 polygonScaled.append (QPointF ((width () - 1) * (pOld.x() - xMinGot) / (xMaxGot - xMinGot),
00040 (height () - 1) * (pOld.y() - yMinGot) / (yMaxGot - yMinGot)));
00041 }
00042
00043
00044 QColor color = ColorPaletteToQColor(m_pointStyle.paletteColor());
00045 if (!m_enabled) {
00046 color = QColor (Qt::black);
00047 }
00048
00049
00050 QImage img (width (),
00051 height (),
00052 QImage::Format_RGB32);
00053 QPainter painter (&img);
00054
00055 painter.fillRect (0,
00056 0,
00057 width (),
00058 height (),
00059 QBrush (m_enabled ? COLOR_FOR_BRUSH_ENABLED : COLOR_FOR_BRUSH_DISABLED));
00060
00061 if (m_enabled) {
00062 painter.setPen (QPen (color, m_pointStyle.lineWidth()));
00063 painter.drawPolygon (polygonScaled);
00064 }
00065
00066
00067 QPixmap pixmap = QPixmap::fromImage (img);
00068
00069 return pixmap;
00070 }
00071
00072 void ViewPointStyle::setEnabled (bool enabled)
00073 {
00074 LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::setEnabled"
00075 << " enabled=" << (enabled ? "true" : "false");
00076
00077 m_enabled = enabled;
00078 setPixmap (pixmapForCurrentSettings ());
00079 }
00080
00081 void ViewPointStyle::setPointStyle (const PointStyle &pointStyle)
00082 {
00083 LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::setPointStyle";
00084
00085 m_pointStyle = pointStyle;
00086 setPixmap (pixmapForCurrentSettings ());
00087 }
00088
00089 void ViewPointStyle::unsetPointStyle ()
00090 {
00091 LOG4CPP_INFO_S ((*mainCat)) << "ViewPointStyle::unsetPointStyle";
00092
00093 QPixmap pEmpty (width (),
00094 height ());
00095 pEmpty.fill (COLOR_FOR_BRUSH_DISABLED);
00096
00097 setPixmap (pEmpty);
00098 }