Saturday, March 30, 2013

QGraphicsWidget

Usually it's easy to get things working with Qt (http://qt-project.org), but recently I encoutered an issue when trying to implement simple component derived from QGraphicsWidget. My initial idea was to use QGraphicsItem, so I made this little class:
class TestItem : public QGraphicsItem
{
public:
        TestItem(QGraphicsItem *parent=0) : QGraphicsItem(parent) {}
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
        virtual QRectF boundingRect () const;

protected:
        virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};

void TestItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
        qDebug() << __PRETTY_FUNCTION__ << "press";
}

void TestItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
        qDebug() << __PRETTY_FUNCTION__ <<  "release";
}

void TestItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
        Q_UNUSED(option)
        Q_UNUSED(widget)
        painter->fillRect(boundingRect(), QColor(255,0,0,100));
}

QRectF TestItem::boundingRect () const
{
        return QRectF(-100, -40, 100, 40);
}
Everything was working like expected, but in order to use a QGraphicsLayout, I wanted to derive that class from QGraphicsWidget. The naive way was to make minimal changes:
class TestWid : public QGraphicsWidget
{
        Q_OBJECT
public:
        TestWid(QGraphicsItem *parent=0) : QGraphicsWidget(parent) { }
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
        virtual QRectF boundingRect () const;

protected:
        virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
};

void TestWid::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
        qDebug() << __PRETTY_FUNCTION__ <<  "press";
}

void TestWid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
        qDebug() << __PRETTY_FUNCTION__ <<  "release";
}

void TestWid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
        Q_UNUSED(option)
        Q_UNUSED(widget)
        painter->fillRect(boundingRect(), QColor(0,0,255,100));
}

QRectF TestWid::boundingRect () const
{
        return QRectF(-100, -40, 100, 40);
}

Pretty straightforward, isn't it? It showed and painted things like expected, but I didn't get any mouse events. Wait what?

I spent hours just trying out things and googling this problem. I knew I had this very same issue earlier but didn't remember how I solved it. Until I figured out a very crucial thing, in case of QGraphicsWidget you must NOT implement boundingRect(). Instead use setGeometry for the object.

So the needed changes was to remote the boundingRect() method, and to call setGeometry in TestWid constructor:

setGeometry(QRectF(-100, -40, 100, 40));

After these very tiny little changes I finally got everthing working. That all thing made me really frustrated. Solving this issue didn't cause good feeling, I was just feeling stupid. Sometimes programming is a great waste of time.

Friday, August 31, 2012

Adventures in Ubuntu land with Ivy Bridge

Recently I got a Intel Ivy Bridge based laptop. Generally I'm quite satisfied with it. Of course installed latest Ubuntu on it. First problem was EFI boot and BIOS had no other options. Best way to work around it was to use EFI aware grub2. I wanted to keep the preinstalled Windows 7 there for couple of things, so needed dual boot.

After digging around this German links was most relevant and helpful: http://thinkpad-forum.de/threads/123262-EFI-Grub2-Multiboot-HowTo.

In the end all I needed to do was to install Grub2 to EFI boot parition (/dev/sda1 on my case) and create the grub.efi binary under that. Then just copy /boot/grub/grub.cfg under it as well. On BIOS set up new boot label to boot \EFI\grub\grub.efi

After using the system couple of days found out random crashes. The system totally hanged. Finally traced the problem to HD4000 graphics driver: http://partiallysanedeveloper.blogspot.fi/2012/05/ivy-bridge-hd4000-linux-freeze.html

Needed to update Kernel. But which one? After multiple tries, I took the "latest" and "shiniest" one: http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/. With that kernel I got almost all the functionality and stability I needed.

However one BIG problem: headphones. I got sound normally from the speakers but after plugging in the headphones I got nothing. This problem seems to be on almost all the kernels I tried. Then I somehow figured out a important thing related to this. When I boot with headphone plugged in I got no sound from them. When I boot WITHOUT headphones plugged then they work just fine. Of course I debugged this problem all the time with the headphones plugged in and newer noticed this could be some weird detection problem. Since I kind of found solution for this I didn't bother to google it down. And of course Canonical does not provide support for unsupported kernels. If I remember correctly with the original Ubuntu 12.04 kernel this worked, but the HD4000 problem is on my scale bigger one than remember to boot without plugging anything to the 3.5" jack....

Of course my hopes are on 12.10 and don't want to dig it deeper, just wanted to inform you about this one.

Monday, March 21, 2011

Wayland

Recently Wayland have become a hot topic. Canonical has announced that Ubuntu will go to Wayland. Also MeeGo has great interest on it.

Qt has had (experimental) Wayland client support for some time now.

A very new thing is support for Qt as Wayland server. With that one can easily make own Qt based Wayland compositor. This is huge. Since this the only working Wayland compositor has been under wayland-demos. Using Qt for this opens many opportunities.

My vision is that Wayland is the future. And the future might be there sooner than you think...

Thursday, February 24, 2011

Friday, November 26, 2010

Encrypted rootfs on MeeGo 1.1 netbook

I promised my scripts to encrypt the rootfs on my Lenovo Ideapad running MeeGo 1.1. It's currently just a dirty hack but thought it could be nice to share it with you.

My scripts uses cryptoloop. Unfortunately MeeGo 1.1 netbook stock kernel didn't support md_crypt so that was a no go. Of course I could compile the module myself but I wanted out-of-the box solution.

Basic idea is to create custom initrd and use it. My solution needs Live USB stick to boot and do the magic. Also another USB drive is needed to get the current root filesystem in safe while encrypting the partition. I don't know if it's possible to encrypt "in place" meaning to use two loopback devices. However this is the safe solution.

For the busy ones, just boot the MeeGo 1.1 Live USB and grab these files:
http://kaaos.huutonauru.net/meego/netbook_rootfs_crypt/crypt_hd.sh
http://kaaos.huutonauru.net/meego/netbook_rootfs_crypt/mkcryptrd.sh

Then:
chmod a+x crypt_hd.sh mkcryptrd.sh
su
./crypt_hd.sh

And follow the instructions.

The ones who have more time and want to double check everything, please follow instructions at: http://kaaos.huutonauru.net/meego/netbook_rootfs_crypt/README

This solution has at least one drawback. Once the kernel updates you have to recreate the initrd. For that purposes I created a tiny script than can be run after kernel update:
http://kaaos.huutonauru.net/meego/netbook_rootfs_crypt/update_initrd.sh

That script also needs the mkcryptrd.sh script above.

Of course that may break your system at any time, so be warned.

For my Lenovo Ideapad S10-3t and MeeGo 1.1 netbook it worked fine. My test case was to make very fresh installation first from the Live/installation USB. Boot again and setup the cryptoloop from Live USB. After that I could easily boot my crypted MeeGo 1.1. It asks password in very early phase of boot process. After it's written correctly the MeeGo 1.1 system should boot up normally.

This worked for me, and I give no guarantee that this works for you. However you're welcome to send patches and improvements.

UPDATE 29.11.2010:
Some people have reported problems when they have different kernel version than on Live USB. The're unable to boot back to their system. I try to figure out solution for this issue.

Thursday, November 25, 2010

Wednesday, November 24, 2010

MeeGo on Lenovo Ideapad S10-3t

I was one of the lucky people that received Lenovo Ideapad S10-3t in MeeGo Conference 2010 at Dublin. Of course I'm using MeeGo on that and now I have been playing with it a while.

Unfortunately I needed to reinstall the MeeGo 1.1 and I used the image available at http://meego.com/downloads/releases/1.1/meego-v1.1-netbooks

After some time and multiple reboots the WLAN and Bluetooth stopped working. Little googling revealed that there's something wrong with BIOS/settings. This helped a lot: http://forum.meego.com/showthread.php?t=2011

So just go to BIOS (F2 at boot), reset factory default and save.


Thought that this could be nice machine to take with me when traveling. So In order to use it more productive way I installed LibreOffice.

Actually I downloaded the GNU/Linux 32 bit tar.gz and found RPM:s under that. I was a bit adventurous and created a repository for them.
So did:
tar xzvf LibO_3.3.0_Linux_x86-64_install-rpm_en-US.tar.gz
sudo mkdir -p /usr/local/repos/libreoffice
sudo cp -r LibO_3.3.0beta3_20101115_Linux_x86_install-rpm_en-US/RPMS/* /usr/local/repos/libreoffice
cd /usr/local/repos/libreoffice
sudo zypper install createrepo
sudo createrepo .

After that set up zypper repository for that. Created file /etc/zypp/repos.d/libreoffice.repo:
[libreoffice]
name=libreoffice
enabled=1
autorefresh=0
baseurl=file:///usr/local/repos/libreoffice
type=rpm-md
gpgcheck=0

After that just:
sudo zypper refresh
sudo zypper install libreoffice3-* libreoffice3.3-freedesktop-menus

So this far it has been quite nice to play around with this Ideapad and MeeGo. Another idea was to have the whole rootfs encrypted to protect my data in case I lost the machine. I actually accomplished that and will post scripts and instructions soon!