From: Joel Holdsworth Date: Sun, 21 Dec 2014 17:56:31 +0000 (+0000) Subject: Added ViewWidget as a common ancestor of all view widgets X-Git-Tag: pulseview-0.3.0~306 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=40aca27ed83559f7f79873e353f64d2c36a18fce;p=pulseview.git Added ViewWidget as a common ancestor of all view widgets --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 546b99dc..edb8a82c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,6 +186,7 @@ set(pulseview_SOURCES pv/view/viewitem.cpp pv/view/viewitempaintparams.cpp pv/view/viewport.cpp + pv/view/viewwidget.cpp pv/widgets/colourbutton.cpp pv/widgets/colourpopup.cpp pv/widgets/popup.cpp @@ -227,6 +228,7 @@ set(pulseview_HEADERS pv/view/view.hpp pv/view/viewitem.hpp pv/view/viewport.hpp + pv/view/viewwidget.hpp pv/widgets/colourbutton.hpp pv/widgets/colourpopup.hpp pv/widgets/popup.hpp diff --git a/pv/view/marginwidget.cpp b/pv/view/marginwidget.cpp index 7582f4af..fcbb31bf 100644 --- a/pv/view/marginwidget.cpp +++ b/pv/view/marginwidget.cpp @@ -34,8 +34,7 @@ namespace pv { namespace view { MarginWidget::MarginWidget(View &parent) : - QWidget(&parent), - view_(parent), + ViewWidget(parent), dragging_(false) { setAttribute(Qt::WA_NoSystemBackground, true); diff --git a/pv/view/marginwidget.hpp b/pv/view/marginwidget.hpp index 54ace028..308d9348 100644 --- a/pv/view/marginwidget.hpp +++ b/pv/view/marginwidget.hpp @@ -24,15 +24,15 @@ #include #include -#include + +#include "viewwidget.hpp" namespace pv { namespace view { -class View; class ViewItem; -class MarginWidget : public QWidget +class MarginWidget : public ViewWidget { Q_OBJECT @@ -109,7 +109,6 @@ Q_SIGNALS: void selection_changed(); protected: - pv::view::View &view_; QPoint mouse_point_; QPoint mouse_down_point_; std::shared_ptr mouse_down_item_; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index feb880e9..0c33fe2c 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -43,14 +43,12 @@ namespace pv { namespace view { Viewport::Viewport(View &parent) : - QWidget(&parent), - view_(parent), + ViewWidget(parent), mouse_down_valid_(false), pinch_zoom_active_(false) { setAttribute(Qt::WA_AcceptTouchEvents, true); - setMouseTracking(true); setAutoFillBackground(true); setBackgroundRole(QPalette::Base); diff --git a/pv/view/viewport.hpp b/pv/view/viewport.hpp index 07bfcad9..94ebe8ee 100644 --- a/pv/view/viewport.hpp +++ b/pv/view/viewport.hpp @@ -22,9 +22,10 @@ #define PULSEVIEW_PV_VIEW_VIEWPORT_H #include -#include #include +#include "viewwidget.hpp" + class QPainter; class QPaintEvent; class Session; @@ -34,7 +35,7 @@ namespace view { class View; -class Viewport : public QWidget +class Viewport : public ViewWidget { Q_OBJECT @@ -57,8 +58,6 @@ private Q_SLOTS: void on_signals_moved(); private: - View &view_; - QPoint mouse_down_point_; double mouse_down_offset_; bool mouse_down_valid_; diff --git a/pv/view/viewwidget.cpp b/pv/view/viewwidget.cpp new file mode 100644 index 00000000..357b6fea --- /dev/null +++ b/pv/view/viewwidget.cpp @@ -0,0 +1,34 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * 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 "view.hpp" +#include "viewwidget.hpp" + +namespace pv { +namespace view { + +ViewWidget::ViewWidget(View &parent) : + QWidget(&parent), + view_(parent) +{ +} + +} // namespace view +} // namespace pv diff --git a/pv/view/viewwidget.hpp b/pv/view/viewwidget.hpp new file mode 100644 index 00000000..5c8889e3 --- /dev/null +++ b/pv/view/viewwidget.hpp @@ -0,0 +1,45 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * 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_VIEWWIDGET_H +#define PULSEVIEW_PV_VIEWWIDGET_H + +#include + +namespace pv { +namespace view { + +class View; + +class ViewWidget : public QWidget +{ + Q_OBJECT + +protected: + ViewWidget(View &parent); + +protected: + pv::view::View &view_; +}; + +} // namespace view +} // namespace pv + +#endif // PULSEVIEW_PV_VIEWWIDGET_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 446c868b..4041d293 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,6 +58,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/view/viewitem.cpp ${PROJECT_SOURCE_DIR}/pv/view/viewitempaintparams.cpp ${PROJECT_SOURCE_DIR}/pv/view/viewport.cpp + ${PROJECT_SOURCE_DIR}/pv/view/viewwidget.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourbutton.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/popup.cpp @@ -97,6 +98,7 @@ set(pulseview_TEST_HEADERS ${PROJECT_SOURCE_DIR}/pv/view/view.hpp ${PROJECT_SOURCE_DIR}/pv/view/viewitem.hpp ${PROJECT_SOURCE_DIR}/pv/view/viewport.hpp + ${PROJECT_SOURCE_DIR}/pv/view/viewwidget.hpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourbutton.hpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.hpp ${PROJECT_SOURCE_DIR}/pv/widgets/popup.hpp