]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Hide the main menu unless Altt is pressed
authorJoel Holdsworth <redacted>
Sat, 10 Jan 2015 17:18:32 +0000 (17:18 +0000)
committerJoel Holdsworth <redacted>
Sat, 10 Jan 2015 21:53:47 +0000 (21:53 +0000)
CMakeLists.txt
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/widgets/hidingmenubar.cpp [new file with mode: 0644]
pv/widgets/hidingmenubar.hpp [new file with mode: 0644]

index 3e621a1f04a08726ce863b86017e862ec841f26b..3f9009abf4e7eca49172d75be855bdb13f01d46a 100644 (file)
@@ -190,6 +190,7 @@ set(pulseview_SOURCES
        pv/widgets/colourbutton.cpp
        pv/widgets/colourpopup.cpp
        pv/widgets/devicetoolbutton.cpp
+       pv/widgets/hidingmenubar.cpp
        pv/widgets/popup.cpp
        pv/widgets/popuptoolbutton.cpp
        pv/widgets/sweeptimingwidget.cpp
@@ -233,6 +234,7 @@ set(pulseview_HEADERS
        pv/widgets/colourbutton.hpp
        pv/widgets/colourpopup.hpp
        pv/widgets/devicetoolbutton.hpp
+       pv/widgets/hidingmenubar.hpp
        pv/widgets/popup.hpp
        pv/widgets/popuptoolbutton.hpp
        pv/widgets/sweeptimingwidget.hpp
index dc9e7de5be8589ce8f0f23244bbc7fae03c36ae9..21b66b534f59119b492b6be69bb049c094389768 100644 (file)
@@ -52,6 +52,7 @@
 #ifdef ENABLE_DECODE
 #include "widgets/decodermenu.hpp"
 #endif
+#include "widgets/hidingmenubar.hpp"
 
 #include <inttypes.h>
 #include <stdint.h>
@@ -211,8 +212,8 @@ void MainWindow::setup_ui()
        vertical_layout_->addWidget(view_);
 
        // Setup the menu bar
-       QMenuBar *const menu_bar = new QMenuBar(this);
-       menu_bar->setGeometry(QRect(0, 0, 400, 25));
+       pv::widgets::HidingMenuBar *const menu_bar =
+               new pv::widgets::HidingMenuBar(this);
 
        // File Menu
        QMenu *const menu_file = new QMenu;
@@ -276,7 +277,7 @@ void MainWindow::setup_ui()
                QString::fromUtf8("actionViewZoomFit"));
        menu_view->addAction(action_view_zoom_fit_);
 
-       action_view_zoom_one_to_one_->setText(tr("Zoom to &One-to-One"));
+       action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One"));
        action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original",
                QIcon(":/icons/zoom-original.png")));
        action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O));
@@ -447,6 +448,15 @@ void MainWindow::closeEvent(QCloseEvent *event)
        event->accept();
 }
 
+void MainWindow::keyReleaseEvent(QKeyEvent *event)
+{
+       if (event->key() == Qt::Key_Alt) {
+               menuBar()->setHidden(!menuBar()->isHidden());
+               menuBar()->setFocus();
+       }
+       QMainWindow::keyReleaseEvent(event);
+}
+
 void MainWindow::load_file(QString file_name)
 {
        const QString errorMessage(
index 2e6e55c1d1dee53bbb12c796bbd3d6c28a1e7046..c0717e4fc3fb94b929958f2eb108bc35725aceb3 100644 (file)
@@ -104,10 +104,13 @@ private:
        /**
         * Updates the device list in the toolbar
         */
-       void update_device_list();
+       void update_device_list();      
 
+private:
        void closeEvent(QCloseEvent *event);
 
+       void keyReleaseEvent(QKeyEvent *event);
+
 private Q_SLOTS:
        void load_file(QString file_name);
 
diff --git a/pv/widgets/hidingmenubar.cpp b/pv/widgets/hidingmenubar.cpp
new file mode 100644 (file)
index 0000000..dcc8fde
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <QKeyEvent>
+
+#include "hidingmenubar.hpp"
+
+namespace pv {
+namespace widgets {
+
+HidingMenuBar::HidingMenuBar(QWidget *parent) :
+       QMenuBar(parent)
+{
+       setHidden(true);
+       connect(this, SIGNAL(triggered(QAction*)),
+               this, SLOT(item_triggered()));
+}
+
+void HidingMenuBar::focusOutEvent(QFocusEvent *e)
+{
+       if (e->reason() != Qt::PopupFocusReason)
+               setHidden(true);
+       QMenuBar::focusOutEvent(e);
+}
+
+void HidingMenuBar::keyPressEvent(QKeyEvent *e)
+{
+       if (e->key() == Qt::Key_Escape)
+               setHidden(true);
+       QMenuBar::keyPressEvent(e);
+}
+
+void HidingMenuBar::item_triggered()
+{
+       setHidden(true);
+}
+
+}  // namespace widgets
+}  // namespace pv
diff --git a/pv/widgets/hidingmenubar.hpp b/pv/widgets/hidingmenubar.hpp
new file mode 100644 (file)
index 0000000..bd9a115
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_WIDGETS_HIDINGMENUBAR_H
+#define PULSEVIEW_PV_WIDGETS_HIDINGMENUBAR_H
+
+#include <QMenuBar>
+
+namespace pv {
+namespace widgets {
+
+/**
+ * A menu bar widget that only remains visible while it retains focus.
+ */
+class HidingMenuBar : public QMenuBar
+{
+       Q_OBJECT
+
+public:
+       /**
+        * Constructor
+        * @param parent The parent widget.
+        */
+       HidingMenuBar(QWidget *parent = nullptr);
+
+private:
+       /**
+        * Handles the event that the widget loses keyboard focus.
+        * @param e the representation of the event details.
+        */
+       void focusOutEvent(QFocusEvent *e);
+
+       /**
+        * Handles the event that a key is depressed.
+        * @param e the representation of the event details.
+        */
+       void keyPressEvent(QKeyEvent *e);
+
+private Q_SLOTS:
+       /**
+        * Handles a menu items being triggered.
+        */
+       void item_triggered();
+};
+
+} // widgets
+} // pv
+
+#endif // PULSEVIEW_PV_WIDGETS_HIDINGMENUBAR_H