KTutorial
0.5.1
|
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 #include "WidgetHighlighterManager.h" 00020 00021 #include <QWidget> 00022 00023 #include "WidgetHighlighter.h" 00024 00025 namespace ktutorial { 00026 namespace extendedinformation { 00027 00028 //public: 00029 00030 WidgetHighlighterManager* WidgetHighlighterManager::self() { 00031 return sSelf; 00032 } 00033 00034 void WidgetHighlighterManager::highlight(QWidget* widget) { 00035 WidgetHighlighter* highlighter = widget->findChild<WidgetHighlighter*>(); 00036 if (highlighter && !widget->children().contains(highlighter)) { 00037 stopHighlighting(highlighter->parentWidget()); 00038 highlighter = 0; 00039 } 00040 00041 if (!highlighter) { 00042 highlighter = new WidgetHighlighter(widget); 00043 connect(highlighter, SIGNAL(stopped(extendedinformation::WidgetHighlighter*)), 00044 this, SLOT(remove(extendedinformation::WidgetHighlighter*))); 00045 } 00046 00047 highlighter->start(); 00048 } 00049 00050 void WidgetHighlighterManager::stopHighlighting(QWidget* widget) { 00051 WidgetHighlighter* highlighter = widget->findChild<WidgetHighlighter*>(); 00052 if (!highlighter || !widget->children().contains(highlighter)) { 00053 return; 00054 } 00055 00056 highlighter->stop(); 00057 } 00058 00059 //private: 00060 00061 WidgetHighlighterManager* WidgetHighlighterManager::sSelf = 00062 new WidgetHighlighterManager(); 00063 00064 WidgetHighlighterManager::WidgetHighlighterManager(): QObject() { 00065 } 00066 00067 //private slots: 00068 00069 void WidgetHighlighterManager::remove( 00070 extendedinformation::WidgetHighlighter* highlighter) { 00071 highlighter->setParent(0); 00072 delete highlighter; 00073 } 00074 00075 } 00076 }