KTutorial  0.5.1
WindowOnTopEnforcer.h
00001 /***************************************************************************
00002  *   Copyright (C) 2010 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00003  *   Copyright (C) 2012 by Daniel Calviño Sánchez <danxuliu@gmail.com>     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; If not, see <http://www.gnu.org/licenses/>.  *
00017  ***************************************************************************/
00018 
00019 #ifndef KTUTORIAL_VIEW_WINDOWONTOPENFORCER_H
00020 #define KTUTORIAL_VIEW_WINDOWONTOPENFORCER_H
00021 
00022 #include <QObject>
00023 #include <QStack>
00024 
00025 namespace ktutorial {
00026 namespace common {
00027 class WindowVisibilitySpy;
00028 }
00029 }
00030 
00031 namespace ktutorial {
00032 namespace view {
00033 
00040 class WindowOnTopEnforcer: public QObject {
00041 Q_OBJECT
00042 public:
00043 
00051     explicit WindowOnTopEnforcer(QWidget* widget);
00052 
00058     void setBaseWindow(QWidget* baseWindow);
00059 
00060 private:
00061 
00065     QWidget* mWidgetToKeepOnTop;
00066 
00072     QStack<QWidget*> mParentStack;
00073 
00081     bool isAncestorOf(QObject* object, QObject* childObject) const;
00082 
00090     void reparentWindowTo(QWidget* window, QWidget* parent) const;
00091 
00092 private Q_SLOTS:
00093 
00103     void handleWindowShown(QWidget* window);
00104 
00114     void handleWindowHidden(QWidget* window);
00115 
00116 };
00117 
00118 }
00119 }
00120 
00121 #endif