void ChartWidget::keyPressEvent(QKeyEvent *event)
{
- m_contextMenuQwt->handleKeyPress(event);
+ if (!m_contextMenuQwt->handleKeyPress(event))
+ {
+ QWidget::keyPressEvent(event);
+ }
}
void ChartWidget::resetZoom()
}
}
-void ContextMenuQwt::handleKeyPress(QKeyEvent *event)
+bool ContextMenuQwt::handleKeyPress(QKeyEvent *event)
{
if (event->modifiers() & Qt::AltModifier)
{
}
break;
default:
- event->ignore();
- return;
+ return false;
}
event->accept();
+ return true;
}
- else
- {
- event->ignore();
- }
+ return false;
}
void initializeMenu(QMenu& menu, ChartOptions::Options options) const;
- void handleKeyPress(QKeyEvent *event);
+ bool handleKeyPress(QKeyEvent *event);
private:
QAction* m_resetZoomAction;
#include <cmath>
#include <QAction>
+#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QCursor>
layout()->addWidget(m_displayLabel);
layout()->addWidget(m_searchResultsLabel);
-#ifdef NO_K_LIB
- // TODO!! implement back and forward
-#else
+#ifndef NO_K_LIB
m_backAction = KStandardAction::back(this, SLOT(navigateBack()), this);
addAction(m_backAction);
m_forwardAction = KStandardAction::forward(this, SLOT(navigateForward()), this);
return ret;
}
+#if NO_K_LIB
+bool FlameGraph::handleKeyPress(QKeyEvent *event)
+{
+ if (m_view->hasFocus() || (qApp->focusWidget() == nullptr))
+ {
+ if (event->modifiers() & Qt::AltModifier)
+ {
+ switch (event->key())
+ {
+ case Qt::Key_Backspace:
+ case Qt::Key_Right:
+ navigateForward();
+ return true;
+ case Qt::Key_Left:
+ navigateBack();
+ return true;
+ }
+ }
+ else
+ {
+ switch (event->key())
+ {
+ case Qt::Key_Backspace:
+ navigateBack();
+ return true;
+ }
+ }
+ }
+ return false;
+}
+#endif
+
void FlameGraph::setTopDownData(const TreeData& topDownData)
{
m_topDownData = topDownData;
if (isVisible()) {
selectItem(m_rootItem);
+ // trying to fix a bug (?): sometimes the flamegraph is displayed at wrong position initially
+ // (observed after switching to the flamegraph tab soon after the application starts with
+ // a data file specified in the command line)
+ static bool firstTime = true;
+ if (firstTime)
+ {
+ m_view->updateGeometry();
+ firstTime = false;
+ }
}
}
void setBottomUpData(const TreeData& bottomUpData);
void clearData();
-
+#if NO_K_LIB
+ // handling back and forward shortcuts:
+ // keyPressEvent doesn't receive arrow keys so the main window calls
+ // this function from its event filter
+ bool handleKeyPress(QKeyEvent* event);
+#endif
protected:
bool eventFilter(QObject* object, QEvent* event) override;
-
private slots:
void setData(FrameGraphicsItem* rootItem);
void setSearchValue(const QString& value);
void HistogramWidget::keyPressEvent(QKeyEvent *event)
{
- m_contextMenuQwt->handleKeyPress(event);
+ if (!m_contextMenuQwt->handleKeyPress(event))
+ {
+ QWidget::keyPressEvent(event);
+ }
}
void HistogramWidget::toggleShowTotal()
connect(m_closeAction, &QAction::triggered, this, &MainWindow::close);
m_quitAction = new QAction(i18n("&Quit"), this);
connect(m_quitAction, &QAction::triggered, qApp, &QApplication::quit);
+
+ qApp->installEventFilter(this);
#else
m_openAction = KStandardAction::open(this, SLOT(closeFile()), this);
m_openAction->setEnabled(false);
MainWindow::~MainWindow()
{
-#ifndef NO_K_LIB
+#ifdef NO_K_LIB
+ qApp->removeEventFilter(this);
+#else
auto state = saveState(MAINWINDOW_VERSION);
auto group = m_config->group(Config::Groups::MainWindow);
group.writeEntry(Config::Entries::State, state);
#endif // QWT_FOUND
}
+bool MainWindow::eventFilter(QObject* object, QEvent* event)
+{
+ // could process arrow keys (left/right) for flamegraph (to implement back/forward) only from here
+ if ((event->type() == QEvent::KeyPress) &&
+ (m_ui->tabWidget->currentWidget() == m_ui->flameGraphTab))
+ {
+ // Qt5: sometimes (e.g. if Alt is pressed) 'object' is QWidgetWindow which is not a part
+ // of Qt public API so trying to detect it indirectly (see 2nd condition below)
+ if ((object == this) || (object->parent() == nullptr))
+ {
+ if (m_ui->flameGraphTab->handleKeyPress(static_cast<QKeyEvent*>(event)))
+ {
+ return true;
+ }
+ }
+ }
+ return QMainWindow::eventFilter(object, event);
+}
+
static void selectFile(QWidget *parent, QLineEdit *fileNameEdit)
{
QString fileName = QFileDialog::getOpenFileName(parent, "Select Data File",
#ifdef NO_K_LIB
protected:
virtual void closeEvent(QCloseEvent *event) override;
+ virtual bool eventFilter(QObject* object, QEvent* event) override;
public slots:
void selectOpenFile();
void selectCompareToFile();