| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 5 |
* * |
| 6 |
* This file is part of the FreeCAD CAx development system. * |
| 7 |
* * |
| 8 |
* This library is free software; you can redistribute it and/or * |
| 9 |
* modify it under the terms of the GNU Library General Public * |
| 10 |
* License as published by the Free Software Foundation; either * |
| 11 |
* version 2 of the License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* This library is distributed in the hope that it will be useful, * |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 |
* GNU Library General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Library General Public * |
| 19 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 20 |
* write to the Free Software Foundation, Inc., 51 Franklin Street, * |
| 21 |
* Fifth Floor, Boston, MA 02110-1301, USA * |
| 22 |
* * |
| 23 |
***************************************************************************/ |
| 24 |
|
| 25 |
#include <QCoreApplication> |
| 26 |
#include <QEvent> |
| 27 |
|
| 28 |
#include "Debugger.h" |
| 29 |
#include "Console.h" |
| 30 |
|
| 31 |
|
| 32 |
using namespace Base; |
| 33 |
|
| 34 |
Debugger::Debugger(QObject* parent) |
| 35 |
: QObject(parent) |
| 36 |
{} |
| 37 |
|
| 38 |
Debugger::~Debugger() = default; |
| 39 |
|
| 40 |
void Debugger::attach() |
| 41 |
{ |
| 42 |
QCoreApplication::instance()->installEventFilter(this); |
| 43 |
isAttached = true; |
| 44 |
} |
| 45 |
|
| 46 |
void Debugger::detach() |
| 47 |
{ |
| 48 |
QCoreApplication::instance()->removeEventFilter(this); |
| 49 |
isAttached = false; |
| 50 |
} |
| 51 |
|
| 52 |
bool Debugger::eventFilter(QObject* /*watched*/, QEvent* event) |
| 53 |
{ |
| 54 |
if (event->type() == QEvent::KeyPress) { |
| 55 |
if (loop.isRunning()) { |
| 56 |
loop.quit(); |
| 57 |
return true; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
int Debugger::exec() |
| 65 |
{ |
| 66 |
if (isAttached) { |
| 67 |
Base::Console().message("TO CONTINUE PRESS ANY KEY...\n"); |
| 68 |
} |
| 69 |
return loop.exec(); |
| 70 |
} |
| 71 |
|
| 72 |
void Debugger::quit() |
| 73 |
{ |
| 74 |
loop.quit(); |
| 75 |
} |
| 76 |
|
| 77 |
#include "moc_Debugger.cpp" |