1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
22 #include <MUtils/GUI.h>
25 #include <QApplication>
28 ///////////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////////
32 bool MUtils::GUI::broadcast(int eventType, const bool &onlyToVisible)
34 if(QApplication *app = dynamic_cast<QApplication*>(QApplication::instance()))
36 qDebug("Broadcasting %d", eventType);
39 QEvent poEvent(static_cast<QEvent::Type>(eventType));
40 QWidgetList list = app->topLevelWidgets();
42 while(!list.isEmpty())
44 QWidget *widget = list.takeFirst();
45 if(!onlyToVisible || widget->isVisible())
47 if(!app->sendEvent(widget, &poEvent))
54 qDebug("Broadcast %d done (%s)", eventType, (allOk ? "OK" : "Stopped"));
59 qWarning("Broadcast failed, could not get QApplication instance!");
64 ///////////////////////////////////////////////////////////////////////////////
66 ///////////////////////////////////////////////////////////////////////////////
68 void MUtils::GUI::force_quit(void)
70 qApp->closeAllWindows();
74 ///////////////////////////////////////////////////////////////////////////////