]> sigrok.org Git - pulseview.git/blame_incremental - pv/mainwindow.cpp
ViewItem: Make select virtual
[pulseview.git] / pv / mainwindow.cpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <cassert>
22
23#ifdef ENABLE_DECODE
24#include <libsigrokdecode/libsigrokdecode.h>
25#endif
26
27#include <algorithm>
28#include <iterator>
29
30#include <boost/algorithm/string/join.hpp>
31
32#include <QAction>
33#include <QApplication>
34#include <QButtonGroup>
35#include <QCloseEvent>
36#include <QFileDialog>
37#include <QMessageBox>
38#include <QMenu>
39#include <QMenuBar>
40#include <QSettings>
41#include <QStatusBar>
42#include <QVBoxLayout>
43#include <QWidget>
44
45#include "mainwindow.hpp"
46
47#include "devicemanager.hpp"
48#include "devices/hardwaredevice.hpp"
49#include "devices/inputfile.hpp"
50#include "devices/sessionfile.hpp"
51#include "dialogs/about.hpp"
52#include "dialogs/connect.hpp"
53#include "dialogs/inputoutputoptions.hpp"
54#include "dialogs/storeprogress.hpp"
55#include "toolbars/mainbar.hpp"
56#include "view/logicsignal.hpp"
57#include "view/view.hpp"
58#include "widgets/exportmenu.hpp"
59#include "widgets/importmenu.hpp"
60#ifdef ENABLE_DECODE
61#include "widgets/decodermenu.hpp"
62#endif
63#include "widgets/hidingmenubar.hpp"
64
65#include <inttypes.h>
66#include <stdint.h>
67#include <stdarg.h>
68#include <glib.h>
69#include <libsigrokcxx/libsigrokcxx.hpp>
70
71using std::cerr;
72using std::endl;
73using std::list;
74using std::map;
75using std::pair;
76using std::shared_ptr;
77using std::string;
78using std::vector;
79
80using boost::algorithm::join;
81
82using sigrok::Error;
83using sigrok::OutputFormat;
84using sigrok::InputFormat;
85
86namespace pv {
87
88namespace view {
89class ViewItem;
90}
91
92const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory";
93const char *MainWindow::SettingSaveDirectory = "MainWindow/SaveDirectory";
94
95MainWindow::MainWindow(DeviceManager &device_manager,
96 string open_file_name, string open_file_format,
97 QWidget *parent) :
98 QMainWindow(parent),
99 device_manager_(device_manager),
100 session_(device_manager),
101 action_open_(new QAction(this)),
102 action_save_as_(new QAction(this)),
103 action_connect_(new QAction(this)),
104 action_quit_(new QAction(this)),
105 action_view_zoom_in_(new QAction(this)),
106 action_view_zoom_out_(new QAction(this)),
107 action_view_zoom_fit_(new QAction(this)),
108 action_view_zoom_one_to_one_(new QAction(this)),
109 action_view_sticky_scrolling_(new QAction(this)),
110 action_view_show_cursors_(new QAction(this)),
111 action_about_(new QAction(this))
112#ifdef ENABLE_DECODE
113 , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true))
114#endif
115{
116 setup_ui();
117 restore_ui_settings();
118 if (open_file_name.empty())
119 select_init_device();
120 else
121 load_init_file(open_file_name, open_file_format);
122}
123
124QAction* MainWindow::action_open() const
125{
126 return action_open_;
127}
128
129QAction* MainWindow::action_save_as() const
130{
131 return action_save_as_;
132}
133
134QAction* MainWindow::action_connect() const
135{
136 return action_connect_;
137}
138
139QAction* MainWindow::action_quit() const
140{
141 return action_quit_;
142}
143
144QAction* MainWindow::action_view_zoom_in() const
145{
146 return action_view_zoom_in_;
147}
148
149QAction* MainWindow::action_view_zoom_out() const
150{
151 return action_view_zoom_out_;
152}
153
154QAction* MainWindow::action_view_zoom_fit() const
155{
156 return action_view_zoom_fit_;
157}
158
159QAction* MainWindow::action_view_zoom_one_to_one() const
160{
161 return action_view_zoom_one_to_one_;
162}
163
164QAction* MainWindow::action_view_sticky_scrolling() const
165{
166 return action_view_sticky_scrolling_;
167}
168
169QAction* MainWindow::action_view_show_cursors() const
170{
171 return action_view_show_cursors_;
172}
173
174QAction* MainWindow::action_about() const
175{
176 return action_about_;
177}
178
179#ifdef ENABLE_DECODE
180QMenu* MainWindow::menu_decoder_add() const
181{
182 return menu_decoders_add_;
183}
184#endif
185
186void MainWindow::run_stop()
187{
188 switch(session_.get_capture_state()) {
189 case Session::Stopped:
190 session_.start_capture([&](QString message) {
191 session_error("Capture failed", message); });
192 break;
193
194 case Session::AwaitingTrigger:
195 case Session::Running:
196 session_.stop_capture();
197 break;
198 }
199}
200
201void MainWindow::select_device(shared_ptr<devices::Device> device)
202{
203 try {
204 if (device)
205 session_.set_device(device);
206 else
207 session_.set_default_device();
208 } catch(const QString &e) {
209 QMessageBox msg(this);
210 msg.setText(e);
211 msg.setInformativeText(tr("Failed to Select Device"));
212 msg.setStandardButtons(QMessageBox::Ok);
213 msg.setIcon(QMessageBox::Warning);
214 msg.exec();
215 }
216}
217
218void MainWindow::export_file(shared_ptr<OutputFormat> format)
219{
220 using pv::dialogs::StoreProgress;
221
222 // Stop any currently running capture session
223 session_.stop_capture();
224
225 QSettings settings;
226 const QString dir = settings.value(SettingSaveDirectory).toString();
227
228 // Construct the filter
229 const vector<string> exts = format->extensions();
230 QString filter = tr("%1 files ").arg(
231 QString::fromStdString(format->description()));
232
233 if (exts.empty())
234 filter += "(*.*)";
235 else
236 filter += QString("(*.%1);;%2 (*.*)").arg(
237 QString::fromStdString(join(exts, ", *."))).arg(
238 tr("All Files"));
239
240 // Show the file dialog
241 const QString file_name = QFileDialog::getSaveFileName(
242 this, tr("Save File"), dir, filter);
243
244 if (file_name.isEmpty())
245 return;
246
247 const QString abs_path = QFileInfo(file_name).absolutePath();
248 settings.setValue(SettingSaveDirectory, abs_path);
249
250 // Show the options dialog
251 map<string, Glib::VariantBase> options;
252 if (!format->options().empty()) {
253 dialogs::InputOutputOptions dlg(
254 tr("Export %1").arg(QString::fromStdString(
255 format->description())),
256 format->options(), this);
257 if (!dlg.exec())
258 return;
259 options = dlg.options();
260 }
261
262 StoreProgress *dlg = new StoreProgress(file_name, format, options,
263 session_, this);
264 dlg->run();
265}
266
267void MainWindow::import_file(shared_ptr<InputFormat> format)
268{
269 assert(format);
270
271 QSettings settings;
272 const QString dir = settings.value(SettingOpenDirectory).toString();
273
274 // Construct the filter
275 const vector<string> exts = format->extensions();
276 const QString filter = exts.empty() ? "" :
277 tr("%1 files (*.%2)").arg(
278 QString::fromStdString(format->description())).arg(
279 QString::fromStdString(join(exts, ", *.")));
280
281 // Show the file dialog
282 const QString file_name = QFileDialog::getOpenFileName(
283 this, tr("Import File"), dir, tr(
284 "%1 files (*.*);;All Files (*.*)").arg(
285 QString::fromStdString(format->description())));
286
287 if (file_name.isEmpty())
288 return;
289
290 // Show the options dialog
291 map<string, Glib::VariantBase> options;
292 if (!format->options().empty()) {
293 dialogs::InputOutputOptions dlg(
294 tr("Import %1").arg(QString::fromStdString(
295 format->description())),
296 format->options(), this);
297 if (!dlg.exec())
298 return;
299 options = dlg.options();
300 }
301
302 load_file(file_name, format, options);
303
304 const QString abs_path = QFileInfo(file_name).absolutePath();
305 settings.setValue(SettingOpenDirectory, abs_path);
306}
307
308void MainWindow::setup_ui()
309{
310 setObjectName(QString::fromUtf8("MainWindow"));
311
312 // Set the window icon
313 QIcon icon;
314 icon.addFile(QString(":/icons/sigrok-logo-notext.svg"));
315 setWindowIcon(icon);
316
317 // Setup the central widget
318 central_widget_ = new QWidget(this);
319 vertical_layout_ = new QVBoxLayout(central_widget_);
320 vertical_layout_->setSpacing(6);
321 vertical_layout_->setContentsMargins(0, 0, 0, 0);
322 setCentralWidget(central_widget_);
323
324 view_ = new pv::view::View(session_, this);
325
326 vertical_layout_->addWidget(view_);
327
328 // Setup the menu bar
329 pv::widgets::HidingMenuBar *const menu_bar =
330 new pv::widgets::HidingMenuBar(this);
331
332 // File Menu
333 QMenu *const menu_file = new QMenu;
334 menu_file->setTitle(tr("&File"));
335
336 action_open_->setText(tr("&Open..."));
337 action_open_->setIcon(QIcon::fromTheme("document-open",
338 QIcon(":/icons/document-open.png")));
339 action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
340 action_open_->setObjectName(QString::fromUtf8("actionOpen"));
341 menu_file->addAction(action_open_);
342
343 action_save_as_->setText(tr("&Save As..."));
344 action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
345 QIcon(":/icons/document-save-as.png")));
346 action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
347 action_save_as_->setObjectName(QString::fromUtf8("actionSaveAs"));
348 menu_file->addAction(action_save_as_);
349
350 menu_file->addSeparator();
351
352 widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
353 device_manager_.context());
354 menu_file_export->setTitle(tr("&Export"));
355 connect(menu_file_export,
356 SIGNAL(format_selected(std::shared_ptr<sigrok::OutputFormat>)),
357 this, SLOT(export_file(std::shared_ptr<sigrok::OutputFormat>)));
358 menu_file->addAction(menu_file_export->menuAction());
359
360 widgets::ImportMenu *menu_file_import = new widgets::ImportMenu(this,
361 device_manager_.context());
362 menu_file_import->setTitle(tr("&Import"));
363 connect(menu_file_import,
364 SIGNAL(format_selected(std::shared_ptr<sigrok::InputFormat>)),
365 this, SLOT(import_file(std::shared_ptr<sigrok::InputFormat>)));
366 menu_file->addAction(menu_file_import->menuAction());
367
368 menu_file->addSeparator();
369
370 action_connect_->setText(tr("&Connect to Device..."));
371 action_connect_->setObjectName(QString::fromUtf8("actionConnect"));
372 menu_file->addAction(action_connect_);
373
374 menu_file->addSeparator();
375
376 action_quit_->setText(tr("&Quit"));
377 action_quit_->setIcon(QIcon::fromTheme("application-exit",
378 QIcon(":/icons/application-exit.png")));
379 action_quit_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
380 action_quit_->setObjectName(QString::fromUtf8("actionQuit"));
381 menu_file->addAction(action_quit_);
382
383 // View Menu
384 QMenu *menu_view = new QMenu;
385 menu_view->setTitle(tr("&View"));
386
387 action_view_zoom_in_->setText(tr("Zoom &In"));
388 action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in",
389 QIcon(":/icons/zoom-in.png")));
390 // simply using Qt::Key_Plus shows no + in the menu
391 action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn);
392 action_view_zoom_in_->setObjectName(
393 QString::fromUtf8("actionViewZoomIn"));
394 menu_view->addAction(action_view_zoom_in_);
395
396 action_view_zoom_out_->setText(tr("Zoom &Out"));
397 action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out",
398 QIcon(":/icons/zoom-out.png")));
399 action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut);
400 action_view_zoom_out_->setObjectName(
401 QString::fromUtf8("actionViewZoomOut"));
402 menu_view->addAction(action_view_zoom_out_);
403
404 action_view_zoom_fit_->setCheckable(true);
405 action_view_zoom_fit_->setText(tr("Zoom to &Fit"));
406 action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit",
407 QIcon(":/icons/zoom-fit.png")));
408 action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F));
409 action_view_zoom_fit_->setObjectName(
410 QString::fromUtf8("actionViewZoomFit"));
411 menu_view->addAction(action_view_zoom_fit_);
412
413 action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One"));
414 action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original",
415 QIcon(":/icons/zoom-original.png")));
416 action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O));
417 action_view_zoom_one_to_one_->setObjectName(
418 QString::fromUtf8("actionViewZoomOneToOne"));
419 menu_view->addAction(action_view_zoom_one_to_one_);
420
421 menu_file->addSeparator();
422
423 action_view_sticky_scrolling_->setCheckable(true);
424 action_view_sticky_scrolling_->setChecked(true);
425 action_view_sticky_scrolling_->setShortcut(QKeySequence(Qt::Key_S));
426 action_view_sticky_scrolling_->setObjectName(
427 QString::fromUtf8("actionViewStickyScrolling"));
428 action_view_sticky_scrolling_->setText(tr("&Sticky Scrolling"));
429 menu_view->addAction(action_view_sticky_scrolling_);
430
431 view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
432
433 menu_view->addSeparator();
434
435 action_view_show_cursors_->setCheckable(true);
436 action_view_show_cursors_->setChecked(view_->cursors_shown());
437 action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors",
438 QIcon(":/icons/show-cursors.svg")));
439 action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C));
440 action_view_show_cursors_->setObjectName(
441 QString::fromUtf8("actionViewShowCursors"));
442 action_view_show_cursors_->setText(tr("Show &Cursors"));
443 menu_view->addAction(action_view_show_cursors_);
444
445 // Decoders Menu
446#ifdef ENABLE_DECODE
447 QMenu *const menu_decoders = new QMenu;
448 menu_decoders->setTitle(tr("&Decoders"));
449
450 menu_decoders_add_->setTitle(tr("&Add"));
451 connect(menu_decoders_add_, SIGNAL(decoder_selected(srd_decoder*)),
452 this, SLOT(add_decoder(srd_decoder*)));
453
454 menu_decoders->addMenu(menu_decoders_add_);
455#endif
456
457 // Help Menu
458 QMenu *const menu_help = new QMenu;
459 menu_help->setTitle(tr("&Help"));
460
461 action_about_->setObjectName(QString::fromUtf8("actionAbout"));
462 action_about_->setText(tr("&About..."));
463 menu_help->addAction(action_about_);
464
465 menu_bar->addAction(menu_file->menuAction());
466 menu_bar->addAction(menu_view->menuAction());
467#ifdef ENABLE_DECODE
468 menu_bar->addAction(menu_decoders->menuAction());
469#endif
470 menu_bar->addAction(menu_help->menuAction());
471
472 setMenuBar(menu_bar);
473 QMetaObject::connectSlotsByName(this);
474
475 // Also add all actions to the main window for always-enabled hotkeys
476 for (QAction* action : menu_bar->actions())
477 this->addAction(action);
478
479 // Setup the toolbar
480 main_bar_ = new toolbars::MainBar(session_, *this);
481
482 // Populate the device list and select the initially selected device
483 update_device_list();
484
485 addToolBar(main_bar_);
486
487 // Set the title
488 setWindowTitle(tr("PulseView"));
489
490 // Setup session_ events
491 connect(&session_, SIGNAL(capture_state_changed(int)), this,
492 SLOT(capture_state_changed(int)));
493 connect(&session_, SIGNAL(device_selected()), this,
494 SLOT(device_selected()));
495
496 // Setup view_ events
497 connect(view_, SIGNAL(sticky_scrolling_changed(bool)), this,
498 SLOT(sticky_scrolling_changed(bool)));
499 connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)), this,
500 SLOT(always_zoom_to_fit_changed(bool)));
501}
502
503void MainWindow::select_init_device() {
504 QSettings settings;
505 map<string, string> dev_info;
506 list<string> key_list;
507
508 // Re-select last used device if possible.
509 settings.beginGroup("Device");
510 key_list.push_back("vendor");
511 key_list.push_back("model");
512 key_list.push_back("version");
513 key_list.push_back("serial_num");
514 key_list.push_back("connection_id");
515
516 for (string key : key_list) {
517 const QString k = QString::fromStdString(key);
518 if (!settings.contains(k))
519 continue;
520
521 const string value = settings.value(k).toString().toStdString();
522 if (!value.empty())
523 dev_info.insert(std::make_pair(key, value));
524 }
525
526 const shared_ptr<devices::HardwareDevice> device =
527 device_manager_.find_device_from_info(dev_info);
528 select_device(device);
529 update_device_list();
530
531 settings.endGroup();
532}
533
534void MainWindow::load_init_file(const std::string &file_name,
535 const std::string &format) {
536 shared_ptr<InputFormat> input_format;
537
538 if (!format.empty()) {
539 const map<string, shared_ptr<InputFormat> > formats =
540 device_manager_.context()->input_formats();
541 const auto iter = find_if(formats.begin(), formats.end(),
542 [&](const pair<string, shared_ptr<InputFormat> > f) {
543 return f.first == format; });
544 if (iter == formats.end()) {
545 cerr << "Unexpected input format: " << format << endl;
546 return;
547 }
548
549 input_format = (*iter).second;
550 }
551
552 load_file(QString::fromStdString(file_name), input_format);
553}
554
555
556void MainWindow::save_ui_settings()
557{
558 QSettings settings;
559
560 map<string, string> dev_info;
561 list<string> key_list;
562
563 settings.beginGroup("MainWindow");
564 settings.setValue("state", saveState());
565 settings.setValue("geometry", saveGeometry());
566 settings.endGroup();
567
568 if (session_.device()) {
569 settings.beginGroup("Device");
570 key_list.push_back("vendor");
571 key_list.push_back("model");
572 key_list.push_back("version");
573 key_list.push_back("serial_num");
574 key_list.push_back("connection_id");
575
576 dev_info = device_manager_.get_device_info(
577 session_.device());
578
579 for (string key : key_list) {
580
581 if (dev_info.count(key))
582 settings.setValue(QString::fromUtf8(key.c_str()),
583 QString::fromUtf8(dev_info.at(key).c_str()));
584 else
585 settings.remove(QString::fromUtf8(key.c_str()));
586 }
587
588 settings.endGroup();
589 }
590}
591
592void MainWindow::restore_ui_settings()
593{
594 QSettings settings;
595
596 settings.beginGroup("MainWindow");
597
598 if (settings.contains("geometry")) {
599 restoreGeometry(settings.value("geometry").toByteArray());
600 restoreState(settings.value("state").toByteArray());
601 } else
602 resize(1000, 720);
603
604 settings.endGroup();
605}
606
607void MainWindow::session_error(
608 const QString text, const QString info_text)
609{
610 QMetaObject::invokeMethod(this, "show_session_error",
611 Qt::QueuedConnection, Q_ARG(QString, text),
612 Q_ARG(QString, info_text));
613}
614
615void MainWindow::update_device_list()
616{
617 main_bar_->update_device_list();
618}
619
620void MainWindow::load_file(QString file_name,
621 std::shared_ptr<sigrok::InputFormat> format,
622 const std::map<std::string, Glib::VariantBase> &options)
623{
624 const QString errorMessage(
625 QString("Failed to load file %1").arg(file_name));
626
627 try {
628 if (format)
629 session_.set_device(shared_ptr<devices::Device>(
630 new devices::InputFile(
631 device_manager_.context(),
632 file_name.toStdString(),
633 format, options)));
634 else
635 session_.set_device(shared_ptr<devices::Device>(
636 new devices::SessionFile(
637 device_manager_.context(),
638 file_name.toStdString())));
639 } catch(Error e) {
640 show_session_error(tr("Failed to load ") + file_name, e.what());
641 session_.set_default_device();
642 update_device_list();
643 return;
644 }
645
646 update_device_list();
647
648 session_.start_capture([&, errorMessage](QString infoMessage) {
649 session_error(errorMessage, infoMessage); });
650}
651
652void MainWindow::closeEvent(QCloseEvent *event)
653{
654 save_ui_settings();
655 event->accept();
656}
657
658void MainWindow::keyReleaseEvent(QKeyEvent *event)
659{
660 if (event->key() == Qt::Key_Alt) {
661 menuBar()->setHidden(!menuBar()->isHidden());
662 menuBar()->setFocus();
663 }
664 QMainWindow::keyReleaseEvent(event);
665}
666
667void MainWindow::show_session_error(
668 const QString text, const QString info_text)
669{
670 QMessageBox msg(this);
671 msg.setText(text);
672 msg.setInformativeText(info_text);
673 msg.setStandardButtons(QMessageBox::Ok);
674 msg.setIcon(QMessageBox::Warning);
675 msg.exec();
676}
677
678void MainWindow::on_actionOpen_triggered()
679{
680 QSettings settings;
681 const QString dir = settings.value(SettingOpenDirectory).toString();
682
683 // Show the dialog
684 const QString file_name = QFileDialog::getOpenFileName(
685 this, tr("Open File"), dir, tr(
686 "Sigrok Sessions (*.sr);;"
687 "All Files (*.*)"));
688
689 if (!file_name.isEmpty()) {
690 load_file(file_name);
691
692 const QString abs_path = QFileInfo(file_name).absolutePath();
693 settings.setValue(SettingOpenDirectory, abs_path);
694 }
695}
696
697void MainWindow::on_actionSaveAs_triggered()
698{
699 export_file(device_manager_.context()->output_formats()["srzip"]);
700}
701
702void MainWindow::on_actionConnect_triggered()
703{
704 // Stop any currently running capture session
705 session_.stop_capture();
706
707 dialogs::Connect dlg(this, device_manager_);
708
709 // If the user selected a device, select it in the device list. Select the
710 // current device otherwise.
711 if (dlg.exec())
712 select_device(dlg.get_selected_device());
713
714 update_device_list();
715}
716
717void MainWindow::on_actionQuit_triggered()
718{
719 close();
720}
721
722void MainWindow::on_actionViewZoomIn_triggered()
723{
724 view_->zoom(1);
725}
726
727void MainWindow::on_actionViewZoomOut_triggered()
728{
729 view_->zoom(-1);
730}
731
732void MainWindow::on_actionViewZoomFit_triggered()
733{
734 view_->zoom_fit(action_view_zoom_fit_->isChecked());
735}
736
737void MainWindow::on_actionViewZoomOneToOne_triggered()
738{
739 view_->zoom_one_to_one();
740}
741
742void MainWindow::on_actionViewStickyScrolling_triggered()
743{
744 view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
745}
746
747void MainWindow::on_actionViewShowCursors_triggered()
748{
749 assert(view_);
750
751 const bool show = !view_->cursors_shown();
752 if (show)
753 view_->centre_cursors();
754
755 view_->show_cursors(show);
756}
757
758void MainWindow::on_actionAbout_triggered()
759{
760 dialogs::About dlg(device_manager_.context(), this);
761 dlg.exec();
762}
763
764void MainWindow::sticky_scrolling_changed(bool state)
765{
766 action_view_sticky_scrolling_->setChecked(state);
767}
768
769void MainWindow::always_zoom_to_fit_changed(bool state)
770{
771 action_view_zoom_fit_->setChecked(state);
772}
773
774void MainWindow::add_decoder(srd_decoder *decoder)
775{
776#ifdef ENABLE_DECODE
777 assert(decoder);
778 session_.add_decoder(decoder);
779#else
780 (void)decoder;
781#endif
782}
783
784void MainWindow::capture_state_changed(int state)
785{
786 main_bar_->set_capture_state((pv::Session::capture_state)state);
787}
788
789void MainWindow::device_selected()
790{
791 // Set the title to include the device/file name
792 const shared_ptr<devices::Device> device = session_.device();
793 if (!device)
794 return;
795
796 const string display_name = device->display_name(device_manager_);
797 setWindowTitle(tr("%1 - PulseView").arg(display_name.c_str()));
798}
799
800} // namespace pv