]> sigrok.org Git - pulseview.git/commitdiff
Move the "new session" button to the main window's tab area
authorSoeren Apel <redacted>
Sat, 8 Oct 2016 13:47:12 +0000 (15:47 +0200)
committerSoeren Apel <redacted>
Sun, 4 Dec 2016 13:37:37 +0000 (14:37 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/toolbars/mainbar.cpp
pv/toolbars/mainbar.hpp

index a04396234c72efda44d4592c641500275f4b82da..53ff35a9d427dcc108343e318281b3ecf5dc6d67 100644 (file)
@@ -31,6 +31,7 @@
 #include <QApplication>
 #include <QCloseEvent>
 #include <QDockWidget>
+#include <QHBoxLayout>
 #include <QSettings>
 #include <QWidget>
 
@@ -203,8 +204,6 @@ shared_ptr<views::ViewBase> MainWindow::add_view(const QString &title,
                                dock_main->addToolBar(main_bar.get());
                                session.set_main_bar(main_bar);
 
-                               connect(main_bar.get(), SIGNAL(new_session()),
-                                       this, SLOT(on_new_session()));
                                connect(main_bar.get(), SIGNAL(new_view(Session*)),
                                        this, SLOT(on_new_view(Session*)));
                        }
@@ -309,11 +308,30 @@ void MainWindow::setup_ui()
        action_about_->setObjectName(QString::fromUtf8("actionAbout"));
        action_about_->setText(tr("&About..."));
 
+       // Set up the tab area
+       new_session_button_ = new QToolButton();
+       new_session_button_->setIcon(QIcon::fromTheme("document-new",
+               QIcon(":/icons/document-new.png")));
+       new_session_button_->setAutoRaise(true);
+
+       QHBoxLayout* layout = new QHBoxLayout();
+       layout->setContentsMargins(2, 2, 2, 2);
+       layout->addWidget(new_session_button_);
+
+       QWidget* static_tab_widget_ = new QWidget();
+       static_tab_widget_->setLayout(layout);
+
+       session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
+
        session_selector_.setTabsClosable(true);
 
+       connect(new_session_button_, SIGNAL(clicked(bool)),
+               this, SLOT(on_new_session_clicked()));
+
        connect(&session_selector_, SIGNAL(tabCloseRequested(int)),
                this, SLOT(on_tab_close_requested(int)));
 
+
        connect(static_cast<QApplication *>(QCoreApplication::instance()),
                SIGNAL(focusChanged(QWidget*, QWidget*)),
                this, SLOT(on_focus_changed()));
@@ -425,7 +443,7 @@ void MainWindow::on_focus_changed()
                setWindowTitle(WindowTitle);
 }
 
-void MainWindow::on_new_session()
+void MainWindow::on_new_session_clicked()
 {
        add_session();
 }
index 37954fe85ac8e0006c78916737fe8aadbe47ac6d..8dfe1bd00e5beaac8bcdaaea694c15618a24e01c 100644 (file)
@@ -26,6 +26,7 @@
 #include <memory>
 
 #include <QMainWindow>
+#include <QToolButton>
 #include <QTabWidget>
 
 #include "session.hpp"
@@ -102,7 +103,7 @@ private Q_SLOTS:
 
        void on_focus_changed();
 
-       void on_new_session();
+       void on_new_session_clicked();
        void on_session_name_changed();
        void on_new_view(Session *session);
        void on_view_close_clicked();
@@ -124,6 +125,7 @@ private:
 
        std::map< std::shared_ptr<Session>, QMainWindow*> session_windows_;
 
+       QToolButton *new_session_button_;
        QTabWidget session_selector_;
 
        QAction *const action_view_sticky_scrolling_;
index ea36a77e90957609158017775c9a01bfae694247..f928de5166afe46063be9ccaf6215063961d3689 100644 (file)
@@ -89,7 +89,6 @@ const char *MainBar::SettingSaveDirectory = "MainWindow/SaveDirectory";
 
 MainBar::MainBar(Session &session, MainWindow &main_window) :
        QToolBar("Sampling Bar", &main_window),
-       action_new_session_(new QAction(this)),
        action_new_view_(new QAction(this)),
        action_open_(new QAction(this)),
        action_save_as_(new QAction(this)),
@@ -128,12 +127,6 @@ MainBar::MainBar(Session &session, MainWindow &main_window) :
        setContextMenuPolicy(Qt::PreventContextMenu);
 
        // Actions
-       action_new_session_->setText(tr("New &Session"));
-       action_new_session_->setIcon(QIcon::fromTheme("document-new",
-               QIcon(":/icons/document-new.png")));
-       connect(action_new_session_, SIGNAL(triggered(bool)),
-               this, SLOT(on_actionNewSession_triggered()));
-
        action_new_view_->setText(tr("New &View"));
        action_new_view_->setIcon(QIcon::fromTheme("window-new",
                QIcon(":/icons/window-new.png")));
@@ -268,7 +261,6 @@ MainBar::MainBar(Session &session, MainWindow &main_window) :
 #endif
 
        // Setup the toolbar
-       addAction(action_new_session_);
        addAction(action_new_view_);
        addSeparator();
        addWidget(open_button);
@@ -957,11 +949,6 @@ void MainBar::on_config_changed()
        commit_sample_rate();   
 }
 
-void MainBar::on_actionNewSession_triggered()
-{
-       new_session();
-}
-
 void MainBar::on_actionNewView_triggered()
 {
        new_view(&session_);
index bb467ec68144d4928d41d890a850fac77d5b241b..0b82e95d833ed550fe0203718b02e97a6bab12fd 100644 (file)
@@ -93,7 +93,6 @@ public:
        void load_init_file(const std::string &file_name,
                const std::string &format);
 
-       QAction* action_new_session() const;
        QAction* action_new_view() const;
        QAction* action_open() const;
        QAction* action_save_as() const;
@@ -127,7 +126,6 @@ private:
 
        void session_error(const QString text, const QString info_text);
 
-       QAction *const action_new_session_;
        QAction *const action_new_view_;
        QAction *const action_open_;
        QAction *const action_save_as_;
@@ -158,7 +156,6 @@ private Q_SLOTS:
 
        void on_config_changed();
 
-       void on_actionNewSession_triggered();
        void on_actionNewView_triggered();
 
        void on_actionOpen_triggered();
@@ -183,7 +180,6 @@ protected:
        bool eventFilter(QObject *watched, QEvent *event);
 
 Q_SIGNALS:
-       void new_session();
        void new_view(Session *session);
 
 private: