I guess the kde3's kmdi code (esp dockcontainer) did something similar. It seems to be bit old(qt3) and complicated. But i guess you will get vague idea on how to implement tearoff. Not sure though