From: Soeren Apel Date: Sat, 8 Oct 2016 13:47:12 +0000 (+0200) Subject: Move the "new session" button to the main window's tab area X-Git-Tag: pulseview-0.4.0~234 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f1e2d26b867fc5ab5723d83c00bd9467add2f748;p=pulseview.git Move the "new session" button to the main window's tab area --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index a0439623..53ff35a9 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -203,8 +204,6 @@ shared_ptr 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(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(); } diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 37954fe8..8dfe1bd0 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -26,6 +26,7 @@ #include #include +#include #include #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, QMainWindow*> session_windows_; + QToolButton *new_session_button_; QTabWidget session_selector_; QAction *const action_view_sticky_scrolling_; diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index ea36a77e..f928de51 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -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_); diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index bb467ec6..0b82e95d 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -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: