52 #include <qlcdnumber.h>
53 #include <qcheckbox.h>
55 #if QT_VERSION >= 0x040000
56 #include <QtGui/QMouseEvent>
69 setFixedSize(nWidth, nHeight);
77 m_bMarkRectangle = pWindowEventInterface != 0;
80 m_nRectX0 = m_nRectY0 = m_nRectX1 = m_nRectY1 = 0;
82 m_pWindowEventInterface = pWindowEventInterface;
96 void CQTWindow::paintEvent(QPaintEvent *e)
100 QPainter painter(
this);
102 #if QT_VERSION >= 0x040000
103 QImage image(m_pBuffer, m_nImageWidth, m_nImageHeight, QImage::Format_RGB32);
105 QImage image(m_pBuffer, m_nImageWidth, m_nImageHeight, 32, 0, 0, QImage::BigEndian);
108 painter.drawImage(m_nImageX, m_nImageY, image);
110 if (m_bMarkRectangle && m_bGetRect)
112 QPen pen(Qt::blue, 1);
114 painter.drawRect(m_nRectX0, m_nRectY0, m_nRectX1 - m_nRectX0, m_nRectY1 - m_nRectY0);
131 if (m_nImageWidth != pImage->
width || m_nImageHeight != pImage->
height)
133 m_nImageWidth = pImage->
width;
134 m_nImageHeight = pImage->
height;
139 m_pBuffer =
new unsigned char[m_nImageWidth * m_nImageHeight * 4];
147 const int nPixels = m_nImageWidth * m_nImageHeight;
148 unsigned char *pixels = pImage->
pixels;
149 int *output = (
int *) m_pBuffer;
151 for (
int i = 0; i < nPixels; i++)
152 output[i] = 255 << 24 | pixels[i] << 16 | pixels[i] << 8 | pixels[i];
158 const int nPixels = m_nImageWidth * m_nImageHeight;
159 unsigned char *pixels = pImage->
pixels;
160 int *output = (
int *) m_pBuffer;
162 for (
int offset = 0, i = 0; i < nPixels; i++)
164 output[i] = 255 << 24 | pixels[offset] << 16 | pixels[offset + 1] << 8 | pixels[offset + 2];
171 #if QT_VERSION >= 0x040000
172 repaint(x, y, m_nImageWidth, m_nImageHeight);
174 repaint(x, y, m_nImageWidth, m_nImageHeight,
false);
178 void CQTWindow::mousePressEvent(QMouseEvent *e)
180 if (e->button() != Qt::LeftButton)
183 if (m_pWindowEventInterface)
195 m_nRectX0 = m_nRectX1 = e->x();
196 m_nRectY0 = m_nRectY1 = e->y();
199 void CQTWindow::mouseMoveEvent(QMouseEvent *e)
208 void CQTWindow::mouseReleaseEvent(QMouseEvent *e)
215 if (m_nRectX0 == m_nRectX1 || m_nRectY0 == m_nRectY1)
218 if (m_nRectX1 < m_nRectX0)
220 int temp = m_nRectX1;
221 m_nRectX1 = m_nRectX0;
225 if (m_nRectY1 < m_nRectY0)
227 int temp = m_nRectY1;
228 m_nRectY1 = m_nRectY0;
232 if (m_pWindowEventInterface)
233 m_pWindowEventInterface->
RectSelected(m_nRectX0, m_nRectY0, m_nRectX1, m_nRectY1);
virtual void PointClicked(int x, int y)
void DrawImage(const CByteImage *pImage, int x=0, int y=0)
virtual void RectSelected(int x0, int y0, int x1, int y1)
ImageType type
The type of the image.
int width
The width of the image in pixels.
int height
The height of the image in pixels.
CQTWindow(int nWidth, int nHeight, CWindowEventInterface *pWindowEventInterface=0, QWidget *pParent=0)
unsigned char * pixels
The pointer to the the pixels.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...