MiniDisplay/minidisplay.cpp
changeset 15 737f8bb110be
parent 14 9903a5edeb56
child 16 35f01a0d460a
     1.1 --- a/MiniDisplay/minidisplay.cpp	Wed May 28 21:31:03 2014 +0200
     1.2 +++ b/MiniDisplay/minidisplay.cpp	Thu May 29 14:27:08 2014 +0200
     1.3 @@ -5,7 +5,7 @@
     1.4  const int KMaxReadAttempt=100;
     1.5  
     1.6  MiniDisplay::MiniDisplay(QQuickItem *parent):
     1.7 -    QQuickItem(parent),iReadAttempt(0),iBrightness(0)
     1.8 +    QQuickItem(parent),iReadAttempt(0),iBrightness(iDisplay.MaxBrightness())
     1.9  {
    1.10      // By default, QQuickItem does not draw anything. If you subclass
    1.11      // QQuickItem to create a visual item, you will need to uncomment the
    1.12 @@ -137,9 +137,47 @@
    1.13          painter.drawText(0,metrics.ascent(),strDemo);
    1.14      }
    1.15      //Save image as PNG for validation
    1.16 -    image.save("font.png");
    1.17 +    //image.save("font.png");
    1.18      //
    1.19 -    //int sizeInBytes=image.byteCount();
    1.20 +    renderImage(&image);
    1.21 +}
    1.22 +
    1.23 +/**
    1.24 + * @brief MiniDisplay::renderWindow
    1.25 + */
    1.26 +void MiniDisplay::renderOwnWindow()
    1.27 +{
    1.28 +    QImage image=window()->grabWindow();
    1.29 +    //image.save("window.png");
    1.30 +    renderImage(&image);
    1.31 +}
    1.32 +
    1.33 +/**
    1.34 + * @brief MiniDisplay::render
    1.35 + * @param aWindow
    1.36 + */
    1.37 +void MiniDisplay::renderWindow(QQuickWindow* aWindow)
    1.38 +{
    1.39 +    QImage image=aWindow->grabWindow();
    1.40 +    //image.save("window.png");
    1.41 +    renderImage(&image);
    1.42 +}
    1.43 +
    1.44 +/**
    1.45 + * @brief MiniDisplay::render
    1.46 + * @param aImage
    1.47 + */
    1.48 +void MiniDisplay::renderImage(QImage* aImage)
    1.49 +{
    1.50 +    if (!iDisplay.IsOpen())
    1.51 +    {
    1.52 +        return;
    1.53 +    }
    1.54 +
    1.55 +    //Convert our image into a bit array
    1.56 +    int w=aImage->width();
    1.57 +    int h=aImage->height();
    1.58 +
    1.59      int pixelCount=w*h;
    1.60      BitArray bits(pixelCount);
    1.61  
    1.62 @@ -147,7 +185,7 @@
    1.63          {
    1.64          for (int j=0;j<h;j++)
    1.65              {
    1.66 -            QRgb color=image.pixel(i,j);
    1.67 +            QRgb color=aImage->pixel(i,j);
    1.68              if (color!=0xffffffff)
    1.69                  {
    1.70                  bits.SetBit(i*h+j);
    1.71 @@ -155,26 +193,32 @@
    1.72              }
    1.73          }
    1.74  
    1.75 -    if (iDisplay.IsOpen())
    1.76 -    {
    1.77 -        iDisplay.Clear();
    1.78 -        iDisplay.BitBlit(bits,w,h,0,0);
    1.79 -        iDisplay.SwapBuffers();
    1.80 -    }
    1.81 -    //
    1.82 +    //Just blit it then
    1.83 +    iDisplay.BitBlit(bits,w,h,0,0);
    1.84  }
    1.85  
    1.86 -
    1.87 +/**
    1.88 + * @brief MiniDisplay::vendor
    1.89 + * @return
    1.90 + */
    1.91  QString MiniDisplay::vendor()
    1.92  {
    1.93      return QString::fromWCharArray(iDisplay.Vendor());
    1.94  }
    1.95  
    1.96 +/**
    1.97 + * @brief MiniDisplay::product
    1.98 + * @return
    1.99 + */
   1.100  QString MiniDisplay::product()
   1.101  {
   1.102      return QString::fromWCharArray(iDisplay.Product());
   1.103  }
   1.104  
   1.105 +/**
   1.106 + * @brief MiniDisplay::serialNumber
   1.107 + * @return
   1.108 + */
   1.109  QString MiniDisplay::serialNumber()
   1.110  {
   1.111      return QString::fromWCharArray(iDisplay.SerialNumber());