]> sigrok.org Git - pulseview.git/blame - pv/widgets/devicetoolbutton.hpp
View: Adjust top margin when needed
[pulseview.git] / pv / widgets / devicetoolbutton.hpp
CommitLineData
079d39ea
JH
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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
079d39ea
JH
18 */
19
7a01bd36
JH
20#ifndef PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP
21#define PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP
079d39ea
JH
22
23#include <list>
24#include <memory>
25#include <vector>
26
27#include <QAction>
28#include <QMenu>
29#include <QSignalMapper>
30#include <QToolButton>
31
6f925ba9
UH
32using std::list;
33using std::shared_ptr;
34using std::vector;
35using std::weak_ptr;
36
079d39ea
JH
37struct srd_decoder;
38
079d39ea
JH
39namespace pv {
40
41class DeviceManager;
42
da30ecb7
JH
43namespace devices {
44class Device;
45}
46
079d39ea
JH
47namespace widgets {
48
49class DeviceToolButton : public QToolButton
50{
51 Q_OBJECT;
52
53public:
54 /**
55 * Constructor
56 * @param parent the parent widget.
57 * @param device_manager the device manager.
58 * @param connect_action the connect-to-device action.
59 */
60 DeviceToolButton(QWidget *parent, DeviceManager &device_manager,
61 QAction *connect_action);
62
63 /**
64 * Returns a reference to the selected device.
65 */
6f925ba9 66 shared_ptr<devices::Device> selected_device();
079d39ea
JH
67
68 /**
69 * Sets the current list of devices.
70 * @param device the list of devices.
71 * @param selected_device the currently active device.
72 */
73 void set_device_list(
6f925ba9
UH
74 const list< shared_ptr<devices::Device> > &devices,
75 shared_ptr<devices::Device> selected);
079d39ea 76
7e0c99bf
SA
77 /**
78 * Sets the current device to "no device". Useful for when a selected
79 * device fails to open.
80 */
81 void reset();
82
079d39ea
JH
83private:
84 /**
85 * Repopulates the menu from the device list.
86 */
87 void update_device_list();
88
89private Q_SLOTS:
90 void on_action(QObject *action);
91
1982c650
SA
92 void on_menu_hovered(QAction *action);
93
94 void on_menu_hover_timeout();
95
079d39ea
JH
96Q_SIGNALS:
97 void device_selected();
98
99private:
100 DeviceManager &device_manager_;
101 QAction *const connect_action_;
102
103 QMenu menu_;
104 QSignalMapper mapper_;
105
6f925ba9
UH
106 shared_ptr<devices::Device> selected_device_;
107 vector< weak_ptr<devices::Device> > devices_;
1982c650
SA
108
109 QString device_tooltip_;
079d39ea
JH
110};
111
870ea3db
UH
112} // namespace widgets
113} // namespace pv
079d39ea 114
7a01bd36 115#endif // PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP