Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "QTWindow.h"
00047 #include "Interfaces/WindowEventInterface.h"
00048 #include "Image/ByteImage.h"
00049
00050 #include <qpainter.h>
00051 #include <qimage.h>
00052 #include <qlcdnumber.h>
00053 #include <qcheckbox.h>
00054
00055 #if QT_VERSION >= 0x040000
00056 #include <QtGui/QMouseEvent>
00057 #endif
00058
00059 #include <memory.h>
00060
00061
00062
00063
00064
00065
00066
00067 CQTWindow::CQTWindow(int nWidth, int nHeight, CWindowEventInterface *pWindowEventInterface, QWidget *pParent) : QWidget(pParent)
00068 {
00069 setFixedSize(nWidth, nHeight);
00070
00071 m_nImageWidth = -1;
00072 m_nImageHeight = -1;
00073
00074 m_pBuffer = 0;
00075
00076 m_type = -1;
00077 m_bMarkRectangle = pWindowEventInterface != 0;
00078
00079 m_bGetRect = false;
00080 m_nRectX0 = m_nRectY0 = m_nRectX1 = m_nRectY1 = 0;
00081
00082 m_pWindowEventInterface = pWindowEventInterface;
00083 }
00084
00085 CQTWindow::~CQTWindow()
00086 {
00087 if (m_pBuffer)
00088 delete [] m_pBuffer;
00089 }
00090
00091
00092
00093
00094
00095
00096 void CQTWindow::paintEvent(QPaintEvent *e)
00097 {
00098 if (m_type != -1)
00099 {
00100 QPainter painter(this);
00101
00102 #if QT_VERSION >= 0x040000
00103 QImage image(m_pBuffer, m_nImageWidth, m_nImageHeight, QImage::Format_RGB32);
00104 #else
00105 QImage image(m_pBuffer, m_nImageWidth, m_nImageHeight, 32, 0, 0, QImage::BigEndian);
00106 #endif
00107
00108 painter.drawImage(m_nImageX, m_nImageY, image);
00109
00110 if (m_bMarkRectangle && m_bGetRect)
00111 {
00112 QPen pen(Qt::blue, 1);
00113 painter.setPen(pen);
00114 painter.drawRect(m_nRectX0, m_nRectY0, m_nRectX1 - m_nRectX0, m_nRectY1 - m_nRectY0);
00115 }
00116 }
00117 }
00118
00119 void CQTWindow::Show()
00120 {
00121 show();
00122 }
00123
00124 void CQTWindow::Hide()
00125 {
00126 hide();
00127 }
00128
00129 void CQTWindow::DrawImage(const CByteImage *pImage, int x, int y)
00130 {
00131 if (m_nImageWidth != pImage->width || m_nImageHeight != pImage->height)
00132 {
00133 m_nImageWidth = pImage->width;
00134 m_nImageHeight = pImage->height;
00135
00136 if (m_pBuffer)
00137 delete [] m_pBuffer;
00138
00139 m_pBuffer = new unsigned char[m_nImageWidth * m_nImageHeight * 4];
00140 }
00141
00142 m_nImageX = x;
00143 m_nImageY = y;
00144
00145 if (pImage->type == CByteImage::eGrayScale)
00146 {
00147 const int nPixels = m_nImageWidth * m_nImageHeight;
00148 unsigned char *pixels = pImage->pixels;
00149 int *output = (int *) m_pBuffer;
00150
00151 for (int i = 0; i < nPixels; i++)
00152 output[i] = 255 << 24 | pixels[i] << 16 | pixels[i] << 8 | pixels[i];
00153
00154 m_type = CByteImage::eGrayScale;
00155 }
00156 else if (pImage->type == CByteImage::eRGB24)
00157 {
00158 const int nPixels = m_nImageWidth * m_nImageHeight;
00159 unsigned char *pixels = pImage->pixels;
00160 int *output = (int *) m_pBuffer;
00161
00162 for (int offset = 0, i = 0; i < nPixels; i++)
00163 {
00164 output[i] = 255 << 24 | pixels[offset] << 16 | pixels[offset + 1] << 8 | pixels[offset + 2];
00165 offset += 3;
00166 }
00167
00168 m_type = CByteImage::eRGB24;
00169 }
00170
00171 #if QT_VERSION >= 0x040000
00172 repaint(x, y, m_nImageWidth, m_nImageHeight);
00173 #else
00174 repaint(x, y, m_nImageWidth, m_nImageHeight, false);
00175 #endif
00176 }
00177
00178 void CQTWindow::mousePressEvent(QMouseEvent *e)
00179 {
00180 if (e->button() != Qt::LeftButton)
00181 return;
00182
00183 if (m_pWindowEventInterface)
00184 m_pWindowEventInterface->PointClicked(e->x(), e->y());
00185
00186 if (m_bGetRect)
00187 {
00188
00189 m_bGetRect = false;
00190 return;
00191 }
00192
00193 m_bGetRect = true;
00194
00195 m_nRectX0 = m_nRectX1 = e->x();
00196 m_nRectY0 = m_nRectY1 = e->y();
00197 }
00198
00199 void CQTWindow::mouseMoveEvent(QMouseEvent *e)
00200 {
00201 if (!m_bGetRect)
00202 return;
00203
00204 m_nRectX1 = e->x();
00205 m_nRectY1 = e->y();
00206 }
00207
00208 void CQTWindow::mouseReleaseEvent(QMouseEvent *e)
00209 {
00210 if (!m_bGetRect)
00211 return;
00212
00213 m_bGetRect = false;
00214
00215 if (m_nRectX0 == m_nRectX1 || m_nRectY0 == m_nRectY1)
00216 return;
00217
00218 if (m_nRectX1 < m_nRectX0)
00219 {
00220 int temp = m_nRectX1;
00221 m_nRectX1 = m_nRectX0;
00222 m_nRectX0 = temp;
00223 }
00224
00225 if (m_nRectY1 < m_nRectY0)
00226 {
00227 int temp = m_nRectY1;
00228 m_nRectY1 = m_nRectY0;
00229 m_nRectY0 = temp;
00230 }
00231
00232 if (m_pWindowEventInterface)
00233 m_pWindowEventInterface->RectSelected(m_nRectX0, m_nRectY0, m_nRectX1, m_nRectY1);
00234 }
asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:58