PulseView  0.3.0
A Qt-based sigrok GUI
devicetoolbutton.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2014 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 #ifndef PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP
22 #define PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP
23 
24 #include <list>
25 #include <memory>
26 #include <vector>
27 
28 #include <QAction>
29 #include <QMenu>
30 #include <QSignalMapper>
31 #include <QToolButton>
32 
33 struct srd_decoder;
34 
35 namespace pv {
36 
37 class DeviceManager;
38 
39 namespace devices {
40 class Device;
41 }
42 
43 namespace widgets {
44 
45 class DeviceToolButton : public QToolButton
46 {
47  Q_OBJECT;
48 
49 public:
56  DeviceToolButton(QWidget *parent, DeviceManager &device_manager,
57  QAction *connect_action);
58 
62  std::shared_ptr<devices::Device> selected_device();
63 
69  void set_device_list(
70  const std::list< std::shared_ptr<devices::Device> > &devices,
71  std::shared_ptr<devices::Device> selected);
72 
73 private:
77  void update_device_list();
78 
79 private Q_SLOTS:
80  void on_action(QObject *action);
81 
82  void on_menu_hovered(QAction *action);
83 
84  void on_menu_hover_timeout();
85 
86 Q_SIGNALS:
87  void device_selected();
88 
89 private:
91  QAction *const connect_action_;
92 
93  QMenu menu_;
94  QSignalMapper mapper_;
95 
96  std::shared_ptr<devices::Device> selected_device_;
97  std::vector< std::weak_ptr<devices::Device> > devices_;
98 
99  QString device_tooltip_;
100 };
101 
102 } // widgets
103 } // pv
104 
105 #endif // PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP
void set_device_list(const std::list< std::shared_ptr< devices::Device > > &devices, std::shared_ptr< devices::Device > selected)
std::shared_ptr< devices::Device > selected_device_
std::vector< std::weak_ptr< devices::Device > > devices_
DeviceToolButton(QWidget *parent, DeviceManager &device_manager, QAction *connect_action)
std::shared_ptr< devices::Device > selected_device()
void on_action(QObject *action)
void on_menu_hovered(QAction *action)