Working around our font dialog option listing issues.
Font dialog options are now persisted.
Fixing issue with italic font being cut by using proper string width from boundigRect.
1 #include "minidisplay.h"
5 const int KMaxReadAttempt=100;
7 MiniDisplay::MiniDisplay(QQuickItem *parent):
8 QQuickItem(parent),iReadAttempt(0),iBrightness(0)
10 // By default, QQuickItem does not draw anything. If you subclass
11 // QQuickItem to create a visual item, you will need to uncomment the
12 // following line and re-implement updatePaintNode()
14 // setFlag(ItemHasContents, true);
16 //qDebug() << "New MiniDisplay";
19 MiniDisplay::~MiniDisplay()
21 //qDebug() << "Delete MiniDisplay";
26 void MiniDisplay::open()
30 iDisplay.SetBrightness(iBrightness);
41 void MiniDisplay::close()
43 //qDebug() << "MiniDisplay::close";
44 //Try to put back ourframe position to RAM 0,0 which is a multiple of 128
45 if (iDisplay.IsOpen())
49 if (iDisplay.DisplayPositionY()%128!=0)
51 //qDebug() << "SwapBuffer to put back our frame position to zero " << iDisplay.DisplayPositionY();
52 iDisplay.SwapBuffers();
60 bool MiniDisplay::isOpen()
62 return iDisplay.IsOpen();
65 void MiniDisplay::clear()
67 if (!iDisplay.IsOpen()) return;
72 void MiniDisplay::fill()
74 if (!iDisplay.IsOpen()) return;
76 iDisplay.SetAllPixels(0xFF);
79 void MiniDisplay::swapBuffers()
81 if (!iDisplay.IsOpen()) return;
83 iDisplay.SwapBuffers();
86 void MiniDisplay::requestPowerStatus()
88 if (!iDisplay.IsOpen()) return;
90 iDisplay.RequestPowerSupplyStatus();
91 QTimer::singleShot(4, this, SLOT(readTimer()));
95 void MiniDisplay::requestDeviceId()
97 if (!iDisplay.IsOpen()) return;
99 iDisplay.RequestDeviceId();
100 QTimer::singleShot(4, this, SLOT(readTimer()));
104 void MiniDisplay::requestFirmwareVersion()
106 if (!iDisplay.IsOpen()) return;
108 iDisplay.RequestFirmwareRevision();
109 QTimer::singleShot(4, this, SLOT(readTimer()));
119 void MiniDisplay::setFont(const QFont& aFont)
122 iFont.setStyleStrategy(QFont::NoAntialias);
123 QString strDemo="0123456789ABCDEF";
124 QFontMetrics metrics(iFont);
125 int w=metrics.boundingRect(strDemo).width();
126 int h=metrics.height();
127 //int h=metrics.boundingRect(strDemo).height();
129 //Rendering in mono is quite broken we need RGB32
130 QImage image(size,QImage::Format_RGB32);
131 image.fill(0xFFFFFFFF);
132 //Draw some text into our image
134 QPainter painter(&image);
135 painter.setPen(0xFF000000);
136 painter.setFont(iFont);
137 painter.drawText(0,metrics.ascent(),strDemo);
139 //Save image as PNG for validation
140 image.save("font.png");
142 //int sizeInBytes=image.byteCount();
144 BitArray bits(pixelCount);
146 for (int i=0;i<w;i++)
148 for (int j=0;j<h;j++)
150 QRgb color=image.pixel(i,j);
151 if (color!=0xffffffff)
158 if (iDisplay.IsOpen())
161 iDisplay.BitBlit(bits,w,h,0,0);
162 iDisplay.SwapBuffers();
168 QString MiniDisplay::vendor()
170 return QString::fromWCharArray(iDisplay.Vendor());
173 QString MiniDisplay::product()
175 return QString::fromWCharArray(iDisplay.Product());
178 QString MiniDisplay::serialNumber()
180 return QString::fromWCharArray(iDisplay.SerialNumber());
184 * @brief MiniDisplay::readTimer
185 * Called when our read timer completes.
186 * We then attempt to complete our pending display request.
187 * We typically attempt to read an input report from our HID device.
189 void MiniDisplay::readTimer()
191 if (!iDisplay.IsOpen()) return;
192 if (!iDisplay.RequestPending()) return;
195 GP1212A01A::Request request = iDisplay.AttemptRequestCompletion();
199 if (iReadAttempt<KMaxReadAttempt)
201 //Will try again later
202 QTimer::singleShot(4, this, SLOT(readTimer()));
208 //TODO: Find a way to remove device specific stuff from here
209 if (request==GP1212A01A::ERequestFirmwareRevision)
211 QString version=QString::fromLocal8Bit((const char*)iDisplay.InputReport().Buffer()+1);
212 emit firmwareVersion(version);
214 else if (request==GP1212A01A::ERequestDeviceId)
216 QString id=QString::fromLocal8Bit((const char*)iDisplay.InputReport().Buffer()+1);
219 else if (request==GP1212A01A::ERequestPowerSupplyStatus)
221 emit powerStatus(iDisplay.PowerOn());
226 int MiniDisplay::maxBrightness() const
228 return iDisplay.MaxBrightness();
231 int MiniDisplay::minBrightness() const
233 return iDisplay.MinBrightness();
236 int MiniDisplay::brightness() const
241 void MiniDisplay::setBrightness(int aBrightness)
243 //Still track the brightness when disconnected
244 iBrightness=aBrightness;
246 if (!iDisplay.IsOpen()) return;
248 iDisplay.SetBrightness(aBrightness);
251 QPoint MiniDisplay::framePosition() const
253 return QPoint(iDisplay.DisplayPositionX(),iDisplay.DisplayPositionX());
256 void MiniDisplay::setFramePosition(const QPoint& aPoint)
258 iFramePosition = aPoint;
260 if (!iDisplay.IsOpen()) return;
262 iDisplay.SetDisplayPosition(aPoint.x(),aPoint.y());