]> sigrok.org Git - pulseview.git/commitdiff
Added pv::widgets::PopupToolButton
authorJoel Holdsworth <redacted>
Sun, 6 Oct 2013 13:59:39 +0000 (14:59 +0100)
committerJoel Holdsworth <redacted>
Sun, 13 Oct 2013 10:05:23 +0000 (11:05 +0100)
CMakeLists.txt
pv/widgets/popuptoolbutton.cpp [new file with mode: 0644]
pv/widgets/popuptoolbutton.h [new file with mode: 0644]

index 05af3458acf462527df0a0b04d1b225d9b4b70de..945b40cdad72677db556bcf58832685a404aeb8f 100644 (file)
@@ -145,6 +145,7 @@ set(pulseview_SOURCES
        pv/widgets/colourbutton.cpp
        pv/widgets/colourpopup.cpp
        pv/widgets/popup.cpp
+       pv/widgets/popuptoolbutton.cpp
        pv/widgets/wellarray.cpp
 )
 
@@ -171,6 +172,7 @@ set(pulseview_HEADERS
        pv/view/viewport.h
        pv/widgets/colourbutton.h
        pv/widgets/colourpopup.h
+       pv/widgets/popuptoolbutton.h
        pv/widgets/wellarray.h
 )
 
diff --git a/pv/widgets/popuptoolbutton.cpp b/pv/widgets/popuptoolbutton.cpp
new file mode 100644 (file)
index 0000000..ea3515c
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "popuptoolbutton.h"
+
+namespace pv {
+namespace widgets {
+
+PopupToolButton::PopupToolButton(QWidget *parent) :
+       QToolButton(parent)
+{
+       connect(this, SIGNAL(clicked(bool)), this, SLOT(on_clicked(bool)));
+}
+
+Popup* PopupToolButton::popup() const
+{
+       return _popup;
+}
+
+void PopupToolButton::set_popup(Popup *popup)
+{
+       assert(popup);
+       _popup = popup;
+}
+
+void PopupToolButton::on_clicked(bool)
+{
+       if(!_popup)
+               return;
+
+       _popup->set_position(mapToGlobal(rect().center()), Popup::Bottom);
+       _popup->show();
+}
+
+} // widgets
+} // pv
diff --git a/pv/widgets/popuptoolbutton.h b/pv/widgets/popuptoolbutton.h
new file mode 100644 (file)
index 0000000..363f3dc
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_WIDGETS_POPUPTOOLBUTTON_H
+#define PULSEVIEW_PV_WIDGETS_POPUPTOOLBUTTON_H
+
+#include "popup.h"
+
+namespace pv {
+namespace widgets {
+
+class PopupToolButton : public QToolButton
+{
+       Q_OBJECT;
+
+public:
+       PopupToolButton(QWidget *parent);
+
+       Popup* popup() const;
+
+       void set_popup(Popup *popup);
+
+private slots:
+       void on_clicked(bool);
+
+private:
+       Popup *_popup;
+};
+
+} // widgets
+} // pv
+
+#endif // PULSEVIEW_PV_WIDGETS_POPUPTOOLBUTTON_H