From: Joel Holdsworth Date: Sat, 13 Dec 2014 11:02:01 +0000 (+0000) Subject: SelectableItem: Renamed to ViewItem X-Git-Tag: pulseview-0.3.0~355 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=26e3af6b15f083239981729b2c3c109ed1d87ba8 SelectableItem: Renamed to ViewItem --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 036946c3..9635bfce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,7 +177,6 @@ set(pulseview_SOURCES pv/view/rowitemowner.cpp pv/view/rowitempaintparams.cpp pv/view/ruler.cpp - pv/view/selectableitem.cpp pv/view/signal.cpp pv/view/timeitem.cpp pv/view/timemarker.cpp @@ -185,6 +184,7 @@ set(pulseview_SOURCES pv/view/tracegroup.cpp pv/view/tracepalette.cpp pv/view/view.cpp + pv/view/viewitem.cpp pv/view/viewport.cpp pv/widgets/colourbutton.cpp pv/widgets/colourpopup.cpp @@ -219,13 +219,13 @@ set(pulseview_HEADERS pv/view/marginwidget.hpp pv/view/rowitem.hpp pv/view/ruler.hpp - pv/view/selectableitem.hpp pv/view/signal.hpp pv/view/timeitem.hpp pv/view/timemarker.hpp pv/view/trace.hpp pv/view/tracegroup.hpp pv/view/view.hpp + pv/view/viewitem.hpp pv/view/viewport.hpp pv/widgets/colourbutton.hpp pv/widgets/colourpopup.hpp diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index b7f360ff..9fa4eee6 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -71,7 +71,7 @@ using sigrok::HardwareDevice; namespace pv { namespace view { -class SelectableItem; +class ViewItem; } const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory"; diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index ecce1389..8432a24b 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -135,7 +135,7 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect) p.setPen(Cursor::FillColour.lighter()); p.drawRoundedRect(delta_rect, highlight_radius, highlight_radius); - p.setPen(SelectableItem::select_text_colour( + p.setPen(ViewItem::select_text_colour( Cursor::FillColour)); p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter, pv::util::format_time(second_->time() - first_->time(), prefix, 2)); diff --git a/pv/view/rowitem.hpp b/pv/view/rowitem.hpp index 91c84d35..e7f55c62 100644 --- a/pv/view/rowitem.hpp +++ b/pv/view/rowitem.hpp @@ -26,14 +26,14 @@ #include #include "rowitempaintparams.hpp" -#include "selectableitem.hpp" +#include "viewitem.hpp" namespace pv { namespace view { class RowItemOwner; -class RowItem : public SelectableItem, +class RowItem : public ViewItem, public std::enable_shared_from_this { Q_OBJECT diff --git a/pv/view/selectableitem.cpp b/pv/view/selectableitem.cpp deleted file mode 100644 index 6921f19a..00000000 --- a/pv/view/selectableitem.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 - */ - -#include "selectableitem.hpp" - -#include - -#include -#include -#include - -namespace pv { -namespace view { - -const int SelectableItem::HighlightRadius = 6; - -SelectableItem::SelectableItem() : - context_parent_(NULL), - selected_(false), - drag_point_(INT_MIN, INT_MIN) -{ -} - -bool SelectableItem::selected() const -{ - return selected_; -} - -void SelectableItem::select(bool select) -{ - selected_ = select; -} - -bool SelectableItem::dragging() const -{ - return drag_point_.x() != INT_MIN && drag_point_.y() != INT_MIN; -} - -QPoint SelectableItem::drag_point() const -{ - return drag_point_; -} - -void SelectableItem::drag() -{ - drag_point_ = point(); -} - -void SelectableItem::drag_release() -{ - drag_point_ = QPoint(INT_MIN, INT_MIN); -} - -QMenu* SelectableItem::create_context_menu(QWidget *parent) -{ - context_parent_ = parent; - return new QMenu(parent); -} - -void SelectableItem::delete_pressed() -{ -} - -QPen SelectableItem::highlight_pen() -{ - return QPen(QApplication::palette().brush( - QPalette::Highlight), HighlightRadius, - Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); -} - -QColor SelectableItem::select_text_colour(QColor background) -{ - return (background.lightness() > 64) ? Qt::black : Qt::white; -} - -} // namespace view -} // namespace pv diff --git a/pv/view/selectableitem.hpp b/pv/view/selectableitem.hpp deleted file mode 100644 index b61c54d6..00000000 --- a/pv/view/selectableitem.hpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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_SELECTABLEITEM_H -#define PULSEVIEW_PV_SELECTABLEITEM_H - -#include - -#include - -class QAction; -class QMenu; -class QWidget; - -namespace pv { - -namespace widgets { -class Popup; -} - -namespace view { - -class SelectableItem : public QObject -{ - Q_OBJECT - -private: - static const int HighlightRadius; - -public: - SelectableItem(); - -public: - /** - * Returns true if the item is visible and enabled. - */ - virtual bool enabled() const = 0; - - /** - * Returns true if the item has been selected by the user. - */ - bool selected() const; - - /** - * Selects or deselects the signal. - */ - void select(bool select = true); - - /** - * Returns true if the item is being dragged. - */ - bool dragging() const; - - /** - * Retunrns the current drag point. - */ - QPoint drag_point() const; - - /** - * Sets this item into the dragged state. - */ - void drag(); - - /** - * Sets this item into the un-dragged state. - */ - void drag_release(); - - /** - * Get the drag point. - */ - virtual QPoint point() const = 0; - - /** - * Computes the outline rectangle of a label. - * @param rect the rectangle of the header area. - * @return Returns the rectangle of the signal label. - */ - virtual QRectF label_rect(const QRectF &rect) const = 0; - -public: - /** - * Gets the text colour. - * @remarks This colour is computed by comparing the lightness - * of the trace colour against a threshold to determine whether - * white or black would be more visible. - */ - static QColor select_text_colour(QColor background); - -public: - virtual QMenu* create_context_menu(QWidget *parent); - - virtual pv::widgets::Popup* create_popup(QWidget *parent) = 0; - - virtual void delete_pressed(); - -protected: - static QPen highlight_pen(); - -protected: - QWidget *context_parent_; - -private: - bool selected_; - QPoint drag_point_; -}; - -} // namespace view -} // namespace pv - -#endif // PULSEVIEW_PV_SELECTABLEITEM_H diff --git a/pv/view/timeitem.hpp b/pv/view/timeitem.hpp index 02d22d21..80fecb5d 100644 --- a/pv/view/timeitem.hpp +++ b/pv/view/timeitem.hpp @@ -21,14 +21,14 @@ #ifndef PULSEVIEW_PV_VIEW_TIMEITEM_H #define PULSEVIEW_PV_VIEW_TIMEITEM_H -#include "selectableitem.hpp" +#include "viewitem.hpp" namespace pv { namespace view { class View; -class TimeItem : public SelectableItem +class TimeItem : public ViewItem { Q_OBJECT diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index df6bd63d..b24afac2 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -124,7 +124,7 @@ void Trace::paint_label(QPainter &p, const QRect &rect, bool hover) QMenu* Trace::create_context_menu(QWidget *parent) { - QMenu *const menu = SelectableItem::create_context_menu(parent); + QMenu *const menu = ViewItem::create_context_menu(parent); return menu; } diff --git a/pv/view/viewitem.cpp b/pv/view/viewitem.cpp new file mode 100644 index 00000000..0d83ee84 --- /dev/null +++ b/pv/view/viewitem.cpp @@ -0,0 +1,94 @@ +/* + * 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 + */ + +#include "viewitem.hpp" + +#include + +#include +#include +#include + +namespace pv { +namespace view { + +const int ViewItem::HighlightRadius = 6; + +ViewItem::ViewItem() : + context_parent_(NULL), + selected_(false), + drag_point_(INT_MIN, INT_MIN) +{ +} + +bool ViewItem::selected() const +{ + return selected_; +} + +void ViewItem::select(bool select) +{ + selected_ = select; +} + +bool ViewItem::dragging() const +{ + return drag_point_.x() != INT_MIN && drag_point_.y() != INT_MIN; +} + +QPoint ViewItem::drag_point() const +{ + return drag_point_; +} + +void ViewItem::drag() +{ + drag_point_ = point(); +} + +void ViewItem::drag_release() +{ + drag_point_ = QPoint(INT_MIN, INT_MIN); +} + +QMenu* ViewItem::create_context_menu(QWidget *parent) +{ + context_parent_ = parent; + return new QMenu(parent); +} + +void ViewItem::delete_pressed() +{ +} + +QPen ViewItem::highlight_pen() +{ + return QPen(QApplication::palette().brush( + QPalette::Highlight), HighlightRadius, + Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); +} + +QColor ViewItem::select_text_colour(QColor background) +{ + return (background.lightness() > 64) ? Qt::black : Qt::white; +} + +} // namespace view +} // namespace pv diff --git a/pv/view/viewitem.hpp b/pv/view/viewitem.hpp new file mode 100644 index 00000000..6a78b1af --- /dev/null +++ b/pv/view/viewitem.hpp @@ -0,0 +1,128 @@ +/* + * 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_VIEWITEM_H +#define PULSEVIEW_PV_VIEWITEM_H + +#include + +#include + +class QAction; +class QMenu; +class QWidget; + +namespace pv { + +namespace widgets { +class Popup; +} + +namespace view { + +class ViewItem : public QObject +{ + Q_OBJECT + +private: + static const int HighlightRadius; + +public: + ViewItem(); + +public: + /** + * Returns true if the item is visible and enabled. + */ + virtual bool enabled() const = 0; + + /** + * Returns true if the item has been selected by the user. + */ + bool selected() const; + + /** + * Selects or deselects the signal. + */ + void select(bool select = true); + + /** + * Returns true if the item is being dragged. + */ + bool dragging() const; + + /** + * Retunrns the current drag point. + */ + QPoint drag_point() const; + + /** + * Sets this item into the dragged state. + */ + void drag(); + + /** + * Sets this item into the un-dragged state. + */ + void drag_release(); + + /** + * Get the drag point. + */ + virtual QPoint point() const = 0; + + /** + * Computes the outline rectangle of a label. + * @param rect the rectangle of the header area. + * @return Returns the rectangle of the signal label. + */ + virtual QRectF label_rect(const QRectF &rect) const = 0; + +public: + /** + * Gets the text colour. + * @remarks This colour is computed by comparing the lightness + * of the trace colour against a threshold to determine whether + * white or black would be more visible. + */ + static QColor select_text_colour(QColor background); + +public: + virtual QMenu* create_context_menu(QWidget *parent); + + virtual pv::widgets::Popup* create_popup(QWidget *parent) = 0; + + virtual void delete_pressed(); + +protected: + static QPen highlight_pen(); + +protected: + QWidget *context_parent_; + +private: + bool selected_; + QPoint drag_point_; +}; + +} // namespace view +} // namespace pv + +#endif // PULSEVIEW_PV_VIEWITEM_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3526af69..064b4e59 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -49,7 +49,6 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/view/rowitemowner.cpp ${PROJECT_SOURCE_DIR}/pv/view/rowitempaintparams.cpp ${PROJECT_SOURCE_DIR}/pv/view/ruler.cpp - ${PROJECT_SOURCE_DIR}/pv/view/selectableitem.cpp ${PROJECT_SOURCE_DIR}/pv/view/signal.cpp ${PROJECT_SOURCE_DIR}/pv/view/timeitem.cpp ${PROJECT_SOURCE_DIR}/pv/view/timemarker.cpp @@ -57,6 +56,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/view/tracegroup.cpp ${PROJECT_SOURCE_DIR}/pv/view/tracepalette.cpp ${PROJECT_SOURCE_DIR}/pv/view/view.cpp + ${PROJECT_SOURCE_DIR}/pv/view/viewitem.cpp ${PROJECT_SOURCE_DIR}/pv/view/viewport.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourbutton.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.cpp @@ -89,13 +89,13 @@ set(pulseview_TEST_HEADERS ${PROJECT_SOURCE_DIR}/pv/view/marginwidget.hpp ${PROJECT_SOURCE_DIR}/pv/view/rowitem.hpp ${PROJECT_SOURCE_DIR}/pv/view/ruler.hpp - ${PROJECT_SOURCE_DIR}/pv/view/selectableitem.hpp ${PROJECT_SOURCE_DIR}/pv/view/signal.hpp ${PROJECT_SOURCE_DIR}/pv/view/timeitem.hpp ${PROJECT_SOURCE_DIR}/pv/view/timemarker.hpp ${PROJECT_SOURCE_DIR}/pv/view/trace.hpp ${PROJECT_SOURCE_DIR}/pv/view/tracegroup.hpp ${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/widgets/colourbutton.hpp ${PROJECT_SOURCE_DIR}/pv/widgets/colourpopup.hpp