From cf63d947364d851044d32d2c0048ec70aac9f86d Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Fri, 11 Dec 2015 15:00:08 +0100 Subject: [PATCH] New event filter to eat space bar events which should be ignored in QDialog context --- .../ExtendedDetectorDialog.cpp | 15 +++++-- GUI/coregui/Views/MaskWidgets/MaskEditor.cpp | 2 + GUI/coregui/mainwindow/mainwindow.cpp | 2 +- GUI/coregui/utils/CustomEventFilters.cpp | 41 +++++++++++++++++++ GUI/coregui/utils/CustomEventFilters.h | 37 +++++++++++++++++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 GUI/coregui/utils/CustomEventFilters.cpp create mode 100644 GUI/coregui/utils/CustomEventFilters.h diff --git a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp index 70f6db21eca..5e62e203f27 100644 --- a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp @@ -17,9 +17,12 @@ #include "MaskEditor.h" #include "MaskModel.h" #include "DetectorMaskDelegate.h" +#include "CustomEventFilters.h" #include <QPushButton> #include <QModelIndex> #include <QVBoxLayout> +#include <QKeyEvent> +#include <QDebug> ExtendedDetectorDialog::ExtendedDetectorDialog(QWidget *parent) : QDialog(parent) @@ -27,7 +30,7 @@ ExtendedDetectorDialog::ExtendedDetectorDialog(QWidget *parent) , m_detectorMaskDelegate(new DetectorMaskDelegate(this)) { setMinimumSize(256, 256); - resize(800, 600); + resize(750, 650); setWindowTitle("Mask Editor"); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setAttribute(Qt::WA_DeleteOnClose, true); @@ -35,7 +38,6 @@ ExtendedDetectorDialog::ExtendedDetectorDialog(QWidget *parent) QVBoxLayout *layout = new QVBoxLayout; QPushButton *button = new QPushButton("Close", this); - button->setAutoDefault(false); connect(button, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *buttonLayout = new QHBoxLayout; @@ -49,7 +51,14 @@ ExtendedDetectorDialog::ExtendedDetectorDialog(QWidget *parent) layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); -// m_maskEditor->init_test_model(); + // hadling keyboar focus policies + button->setDefault(false); + button->setAutoDefault(false); + setFocusProxy(m_maskEditor); + + SpaceKeyEater *filter = new SpaceKeyEater(this); + installEventFilter(filter); + button->installEventFilter(filter); } diff --git a/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp b/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp index 2e59134f028..7893f276cad 100644 --- a/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp +++ b/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp @@ -54,6 +54,8 @@ MaskEditor::MaskEditor(QWidget *parent) setCentralWidget(m_splitter); setup_connections(); + + m_editorPropertyPanel->setPanelHidden(true); } //void MaskEditor::setModel(SessionModel *model, const QModelIndex &rootIndex) diff --git a/GUI/coregui/mainwindow/mainwindow.cpp b/GUI/coregui/mainwindow/mainwindow.cpp index dac89dd2d4f..d63eb470676 100644 --- a/GUI/coregui/mainwindow/mainwindow.cpp +++ b/GUI/coregui/mainwindow/mainwindow.cpp @@ -134,7 +134,7 @@ MainWindow::MainWindow(QWidget *parent) //m_tabWidget->insertTab(FitViewTab, m_fitView, QIcon(":/images/main_simulation.png"), "Fit"); //m_tabWidget->insertTab(FIT_VIEW, new TestView(this), QIcon(":/images/main_simulation.png"), "Test"); - m_tabWidget->setCurrentIndex(TEST_VIEW); + m_tabWidget->setCurrentIndex(INSTRUMENT); m_progressBar = new Manhattan::ProgressBar(this); m_tabWidget->addBottomCornerWidget(m_progressBar); diff --git a/GUI/coregui/utils/CustomEventFilters.cpp b/GUI/coregui/utils/CustomEventFilters.cpp new file mode 100644 index 00000000000..3fa3d693a69 --- /dev/null +++ b/GUI/coregui/utils/CustomEventFilters.cpp @@ -0,0 +1,41 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/utils/CustomEventFilters.cpp +//! @brief Defines classes releted to event filtering +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#include "CustomEventFilters.h" +#include <QEvent> +#include <QKeyEvent> + +SpaceKeyEater::SpaceKeyEater(QObject *parent) + : QObject(parent) +{ + +} + +bool SpaceKeyEater::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); + bool res = QObject::eventFilter(obj, event); + + if (keyEvent->key() == Qt::Key_Space) { + return true; /* Always accept space bar */ + } else { + return res; + } + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } +} diff --git a/GUI/coregui/utils/CustomEventFilters.h b/GUI/coregui/utils/CustomEventFilters.h new file mode 100644 index 00000000000..3e829401551 --- /dev/null +++ b/GUI/coregui/utils/CustomEventFilters.h @@ -0,0 +1,37 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file coregui/utils/CustomEventFilters.h +//! @brief Defines classes releted to event filtering +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2015 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke +// +// ************************************************************************** // + +#ifndef CUSTOMEVENTFILTERS_H +#define CUSTOMEVENTFILTERS_H + +#include "WinDllMacros.h" +#include <QObject> + +class QEvent; + +//! Filter out space bar key events, which is special case for dialog windows + +class BA_CORE_API_ SpaceKeyEater : public QObject +{ + Q_OBJECT +public: + + SpaceKeyEater(QObject *parent = 0); + +protected: + bool eventFilter(QObject *obj, QEvent *event); +}; + +#endif -- GitLab