lcd_gfx_qt: Implement bitmap scaling
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 17 Aug 2008 20:48:04 +0000 (20:48 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 17 Aug 2008 20:48:04 +0000 (20:48 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1658 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/drv/lcd_gfx_qt.cpp
bertos/drv/lcd_gfx_qt.h
bertos/emul/emulwin.cpp

index 8d04471e67df6e622e5d55cc63be3e6a14992822..b7a2e519273f1294af261d60cc055af7c4692e5d 100644 (file)
@@ -65,6 +65,16 @@ EmulLCD::EmulLCD(QWidget *parent) :
        // set widget frame
        setFrameStyle(QFrame::Panel | QFrame::Sunken);
        frame_width = frameWidth();
+
+       setMinimumSize(WIDTH + frame_width * 2, HEIGHT + frame_width * 2);
+
+       #if CONFIG_EMULLCD_SCALE
+               QSizePolicy pol = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred, QSizePolicy::Frame);
+               pol.setHeightForWidth(true);
+       #else
+               QSizePolicy pol = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::Frame);
+       #endif
+       setSizePolicy(pol);
 }
 
 
@@ -73,33 +83,38 @@ EmulLCD::~EmulLCD()
        // nop
 }
 
-
-QSizePolicy EmulLCD::sizePolicy() const
+#if CONFIG_EMULLCD_SCALE
+int EmulLCD::heightForWidth(int w) const
 {
-       return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::Frame);
-}
+               int h;
 
+               w -= frame_width * 2;
+               h = (w * HEIGHT + WIDTH/2) / WIDTH;
+               h += frame_width * 2;
 
-QSize EmulLCD::sizeHint() const
-{
-       return QSize(
-               WIDTH + frame_width * 2,
-               HEIGHT + frame_width * 2);
-}
-
-QSize EmulLCD::minimumSizeHint() const
-{
-       return sizeHint();
+               return h;
 }
+#endif // CONFIG_EMULLCD_SCALE
 
 void EmulLCD::paintEvent(QPaintEvent * /*event*/)
 {
        QPainter p(this);
        QImage img(raster, WIDTH, HEIGHT, QImage::Format_Mono);
 
+       #if CONFIG_EMULLCD_SCALE
+               int w = width() - frame_width * 2;
+               int h = height() - frame_width * 2;
+               if ((w != WIDTH) || (h != HEIGHT))
+               {
+                       p.scale((qreal)w / WIDTH, (qreal)h / HEIGHT);
+                       //p.setRenderHint(QPainter::SmoothPixmapTransform);
+               }
+       #endif // CONFIG_EMULLCD_SCALE
+
        p.setBackgroundMode(Qt::OpaqueMode);
        p.setBackground(bg_brush);
        p.setPen(fg_color);
+
        p.drawImage(QPoint(frame_width, frame_width), img);
 }
 
@@ -107,12 +122,16 @@ void EmulLCD::writeRaster(uint8_t *new_raster)
 {
 #if CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_H_MSB
 
-       /* Straight copy */
-       memcpy(raster, new_raster, sizeof(raster));
+       // Straight copy
+       //memcpy(raster, new_raster, sizeof(raster));
+
+       // Inverting copy
+       for (int i = 0; i < (int)sizeof(raster); ++i)
+               raster[i] = ~new_raster[i];
 
 #elif CONFIG_BITMAP_FMT == BITMAP_FMT_PLANAR_V_LSB
 
-       /* Rotation */
+       // Rotation + inversion
        for (int y = 0; y < HEIGHT; ++y)
        {
                for (int xbyte = 0; xbyte < WIDTH/8; ++xbyte)
@@ -120,12 +139,11 @@ void EmulLCD::writeRaster(uint8_t *new_raster)
                        uint8_t v = 0;
                        for (int xbit = 0; xbit < 8; ++xbit)
                                v |= (new_raster[(xbyte * 8 + xbit) + (y / 8) * WIDTH] & (1 << (y%8)) )
-                                       ? 0 : (1 << (7 - xbit));
+                                       ? (1 << (7 - xbit)) : 0;
 
                        raster[y * ((WIDTH + 7) / 8) + xbyte] = v;
                }
        }
-
 #else
        #error Unsupported bitmap format
 #endif
index a5538f39299fcfc8dad995e4cda52dd8692e49de..c74b7883d9ae42543e9b5d728d779e094a6fb0da 100644 (file)
@@ -47,6 +47,7 @@ class QSizePolicy;
 class QPaintEvent;
 class QResizeEvent;
 
+#define CONFIG_EMULLCD_SCALE 1
 
 class EmulLCD : public QFrame
 {
@@ -62,11 +63,12 @@ public:
 
 // Base class overrides
 protected:
-       virtual QSizePolicy sizePolicy() const;
-       virtual QSize sizeHint() const;
-       virtual QSize minimumSizeHint() const;
        virtual void paintEvent(QPaintEvent *event);
 
+       #if CONFIG_EMULLCD_SCALE
+               virtual int heightForWidth(int w) const;
+       #endif
+
 // Operations
 public:
        void writeRaster(uint8_t *raster);
index f7dc84d004f3a3d1309a6680c1c2436e2ea52a35..c3c7c074d45696fb5f0e0fc03c5558bab31e77d7 100644 (file)
@@ -88,9 +88,9 @@ EmulWin::EmulWin(Emulator *e)
                // LCD
                QHBoxLayout *lay_lcd = new QHBoxLayout();
                box_right->addLayout(lay_lcd);
-                       lay_lcd->addStretch();
-                       lay_lcd->addWidget(e->emulLCD = new EmulLCD(central));
-                       lay_lcd->addStretch();
+                       lay_lcd->addStretch(1);
+                       lay_lcd->addWidget(e->emulLCD = new EmulLCD(central), 8);
+                       lay_lcd->addStretch(1);
 
                // Keyboard
                box_right->addWidget(e->emulKbd = new EmulKbd(central));