]> sigrok.org Git - pulseview.git/commitdiff
Removed OpenGL from pv::view::Viewport
authorJoel Holdsworth <redacted>
Sun, 9 Sep 2012 10:13:50 +0000 (11:13 +0100)
committerJoel Holdsworth <redacted>
Sun, 9 Sep 2012 10:32:15 +0000 (11:32 +0100)
CMakeLists.txt
logicsignal.cpp
logicsignal.h
pv/view/viewport.cpp
pv/view/viewport.h
signal.h

index 3d26b236569def367d0a446519aa26e998c9e55a..872139ee4f937f648203685c494b22cb06bee54c 100644 (file)
@@ -58,8 +58,6 @@ set(pulseview_TEST_SOURCES
        logicdatasnapshot.cpp
 )
 
-set(QT_USE_QTOPENGL TRUE)
-
 qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
 qt4_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
 qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
index 7580138fe24e87af7c164c595392968a36a08133..8d2d00453fd38ed608a7edd08844a896e30a9d34 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
-
 #include <math.h>
 
 #include "extdef.h"
@@ -35,9 +31,9 @@ using namespace std;
 
 const float LogicSignal::Margin = 10.0f;
 
-const float LogicSignal::EdgeColour[3] =       {0.50f, 0.50f, 0.50f};
-const float LogicSignal::HighColour[3] =       {0.00f, 0.75f, 0.00f};
-const float LogicSignal::LowColour[3] =        {0.75f, 0.00f, 0.00f};
+const QColor LogicSignal::EdgeColour(0x80, 0x80, 0x80);
+const QColor LogicSignal::HighColour(0x00, 0xC0, 0x00);
+const QColor LogicSignal::LowColour(0xC0, 0x00, 0x00);
 
 const QColor LogicSignal::LogicSignalColours[10] = {
        QColor(0x16, 0x19, 0x1A),       // Black
@@ -61,10 +57,10 @@ LogicSignal::LogicSignal(QString name, shared_ptr<LogicData> data,
        assert(_probe_index >= 0);
 }
 
-void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
-       double scale, double offset)
+void LogicSignal::paint(QPainter &p, const QRect &rect, double scale,
+       double offset)
 {
-       Point2F *vertex;
+       QLineF *line;
 
        vector< pair<int64_t, bool> > edges;
 
@@ -95,87 +91,54 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
                samples_per_pixel, _probe_index);
 
        // Paint the edges
-       const unsigned int edge_point_count = (edges.size() - 2) * 2;
-       Point2F *const edge_points = new Point2F[edge_point_count];
-       vertex = edge_points;
-
-       for(vector<LogicDataSnapshot::EdgePair>::const_iterator i = edges.begin() + 1;
-           i != edges.end() - 1; i++)
-       {
-               const int x = (int)((*i).first / samples_per_pixel - pixels_offset) +
-                       rect.left();
-
-               vertex->x = x, vertex->y = high_offset;
-               vertex++;
-               vertex->x = x, vertex->y = low_offset;
-               vertex++;
+       const unsigned int edge_count = edges.size() - 2;
+       QLineF *const edge_lines = new QLineF[edge_count];
+       line = edge_lines;
+
+       for(vector<LogicDataSnapshot::EdgePair>::const_iterator i =
+                       edges.begin() + 1;
+               i != edges.end() - 1; i++) {
+               const int x = (int)((*i).first / samples_per_pixel -
+                       pixels_offset) + rect.left();
+               *line++ = QLineF(x, high_offset, x, low_offset);
        }
 
-       glColor3fv(EdgeColour);
-       paint_lines(edge_points, edge_point_count);
-       delete[] edge_points;
+       p.setPen(EdgeColour);
+       p.drawLines(edge_lines, edge_count);
+       delete[] edge_lines;
 
        // Paint the caps
-       const unsigned int max_cap_point_count = (edges.size() - 1) * 2;
-       Point2F *const cap_points = new Point2F[max_cap_point_count];
+       const unsigned int max_cap_line_count = (edges.size() - 1);
+       QLineF *const cap_lines = new QLineF[max_cap_line_count];
 
-       glColor3fv(HighColour);
-       paint_caps(cap_points, edges, true, samples_per_pixel,
+       p.setPen(HighColour);
+       paint_caps(p, cap_lines, edges, true, samples_per_pixel,
                pixels_offset, rect.left(), high_offset);
-       glColor3fv(LowColour);
-       paint_caps(cap_points, edges, false, samples_per_pixel,
+       p.setPen(LowColour);
+       paint_caps(p, cap_lines, edges, false, samples_per_pixel,
                pixels_offset, rect.left(), low_offset);
 
-       delete[] cap_points;
+       delete[] cap_lines;
 }
 
-int LogicSignal::paint_caps(Point2F *const cap_points,
+int LogicSignal::paint_caps(QPainter &p, QLineF *const lines,
        vector< pair<int64_t, bool> > &edges, bool level,
        double samples_per_pixel, double pixels_offset, int x_offset,
        int y_offset)
 {
-       Point2F *vertex = cap_points;
+       QLineF *line = lines;
 
        for(vector<LogicDataSnapshot::EdgePair>::const_iterator i = edges.begin();
            i != (edges.end() - 1); i++)
-               if((*i).second == level)
-               {
-                       vertex->x = (int)((*i).first / samples_per_pixel -
-                               pixels_offset) + x_offset - 1;
-                       vertex->y = y_offset;
-                       vertex++;
-
-                       vertex->x = (int)((*(i+1)).first / samples_per_pixel -
-                               pixels_offset) + x_offset;
-                       vertex->y = y_offset;
-                       vertex++;
+               if((*i).second == level) {
+                       *line++ = QLineF(
+                               (int)((*i).first / samples_per_pixel -
+                                       pixels_offset) + x_offset, y_offset,
+                               (int)((*(i+1)).first / samples_per_pixel -
+                                       pixels_offset) + x_offset, y_offset);
                }
 
-       paint_lines(cap_points, vertex - cap_points);
-}
-
-void LogicSignal::paint_lines(Point2F *points, int count)
-{
-       GLuint vbo_id;
-
-       assert(points);
-
-       glGenBuffers(1, &vbo_id);
-       glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
-
-       const unsigned int vbo_length = count * sizeof(Point2F);
-       glBufferData(GL_ARRAY_BUFFER, vbo_length, NULL, GL_STATIC_DRAW);
-       glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_length, points);
-
-       glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
-
-       glVertexPointer(2, GL_FLOAT, sizeof(Point2F), 0);
-
-       glEnableClientState(GL_VERTEX_ARRAY);
-       glDrawArrays(GL_LINES,  0,  count);
-       glDisableClientState(GL_VERTEX_ARRAY);
-
-       glDeleteBuffers(1, &vbo_id);
+       p.drawLines(lines, line - lines);
 }
 
 QColor LogicSignal::get_colour() const
index 8677afe3c03e30e9c5851ca952f8a91296593a7e..359162fd7040cedf47410f326f54638d1b9869b3 100644 (file)
@@ -26,18 +26,12 @@ class LogicData;
 
 class LogicSignal : public Signal
 {
-private:
-       struct Point2F
-       {
-               GLfloat x, y;
-       };
-
 private:
        static const float Margin;
 
-       static const float EdgeColour[3];
-       static const float HighColour[3];
-       static const float LowColour[3];
+       static const QColor EdgeColour;
+       static const QColor HighColour;
+       static const QColor LowColour;
 
        static const QColor LogicSignalColours[10];
 
@@ -47,25 +41,22 @@ public:
                int probe_index);
 
        /**
-        * Paints the signal into a QGLWidget.
-        * @param widget the QGLWidget to paint into.
+        * Paints the signal with a QPainter
+        * @param p the QPainter to paint into.
         * @param rect the rectangular area to draw the trace into.
         * @param scale the scale in seconds per pixel.
         * @param offset the time to show at the left hand edge of
         *   the view in seconds.
         **/
-       void paint(QGLWidget &widget, const QRect &rect, double scale,
-               double offset);
+       void paint(QPainter &p, const QRect &rect, double scale, double offset);
 
 private:
 
-       int paint_caps(Point2F *const cap_points,
+       int paint_caps(QPainter &p, QLineF *const lines,
                std::vector< std::pair<int64_t, bool> > &edges,
                bool level, double samples_per_pixel, double pixels_offset,
                int x_offset, int y_offset);
 
-       static void paint_lines(Point2F *points, int count);
-
        /**
         * Get the colour of the logic signal
         */
index b437175f75fa89b0adc9f325d6f43ad98a4b30c9..593edefe99beca839a943f1b9ba79977de2231a6 100644 (file)
@@ -35,11 +35,12 @@ namespace pv {
 namespace view {
 
 Viewport::Viewport(View &parent) :
-       QGLWidget(&parent),
+       QWidget(&parent),
         _view(parent)
 {
        setMouseTracking(true);
-       setAutoFillBackground(false);
+       setAutoFillBackground(true);
+       setBackgroundRole(QPalette::Base);
 }
 
 int Viewport::get_total_height() const
@@ -54,36 +55,15 @@ int Viewport::get_total_height() const
        return height;
 }
 
-void Viewport::initializeGL()
-{
-}
-
-void Viewport::resizeGL(int width, int height)
-{
-       setup_viewport(width, height);
-}
-
 void Viewport::paintEvent(QPaintEvent *event)
 {
-       int offset;
-
        const vector< shared_ptr<Signal> > &sigs =
                _view.session().get_signals();
 
-       // Prepare for OpenGL rendering
-       makeCurrent();
-       glMatrixMode(GL_MODELVIEW);
-       glPushMatrix();
-
-       setup_viewport(width(), height());
-
-       qglClearColor(Qt::white);
-       glClear(GL_COLOR_BUFFER_BIT);
+       QPainter p(this);
 
        // Plot the signal
-       glEnable(GL_SCISSOR_TEST);
-       glScissor(0, 0, width(), height());
-       offset = -_view.v_offset();
+       int offset = -_view.v_offset();
        BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
        {
                assert(s);
@@ -91,19 +71,12 @@ void Viewport::paintEvent(QPaintEvent *event)
                const QRect signal_rect(0, offset,
                        width(), View::SignalHeight);
 
-               s->paint(*this, signal_rect, _view.scale(), _view.offset());
+               s->paint(p, signal_rect, _view.scale(), _view.offset());
 
                offset += View::SignalHeight;
        }
 
-       glDisable(GL_SCISSOR_TEST);
-
-       // Prepare for QPainter rendering
-       glMatrixMode(GL_MODELVIEW);
-       glPopMatrix();
-
-       QPainter painter(this);
-       painter.end();
+       p.end();
 }
 
 void Viewport::mousePressEvent(QMouseEvent *event)
@@ -138,14 +111,5 @@ void Viewport::wheelEvent(QWheelEvent *event)
        _view.zoom(event->delta() / 120, event->x());
 }
 
-void Viewport::setup_viewport(int width, int height)
-{
-       glViewport(0, 0, (GLint)width, (GLint)height);
-       glMatrixMode(GL_PROJECTION);
-       glLoadIdentity();
-       glOrtho(0, width, height, 0, -1, 1);
-       glMatrixMode(GL_MODELVIEW);
-}
-
 } // namespace view
 } // namespace pv
index b79526ac2c8d783685aa100b6df8d424dde821fd..e32ab09cfd10749bc90f2b4d5e7eaf2474bfbb3e 100644 (file)
@@ -21,8 +21,8 @@
 #ifndef PV_VIEW_VIEWPORT_H
 #define PV_VIEW_VIEWPORT_H
 
-#include <QtOpenGL/QGLWidget>
 #include <QTimer>
+#include <QWidget>
 
 class QPainter;
 class QPaintEvent;
@@ -33,7 +33,7 @@ namespace view {
 
 class View;
 
-class Viewport : public QGLWidget
+class Viewport : public QWidget
 {
        Q_OBJECT
 
@@ -43,10 +43,6 @@ public:
        int get_total_height() const;
 
 protected:
-       void initializeGL();
-
-       void resizeGL(int width, int height);
-
        void paintEvent(QPaintEvent *event);
 
 private:
@@ -55,9 +51,6 @@ private:
        void mouseReleaseEvent(QMouseEvent *event);
        void wheelEvent(QWheelEvent *event);
 
-private:
-       void setup_viewport(int width, int height);
-
 private:
        View &_view;
 
index edab476deb7d31c22f0b16929c2221e82e05cb1a..7d59bb44021d7efe44074425eeb1a534bf453152 100644 (file)
--- a/signal.h
+++ b/signal.h
@@ -20,7 +20,6 @@
 
 #include <boost/shared_ptr.hpp>
 
-#include <QGLWidget>
 #include <QPainter>
 #include <QRect>
 #include <QString>
@@ -41,15 +40,15 @@ public:
        QString get_name() const;
 
        /**
-        * Paints the signal into a QGLWidget.
-        * @param widget the QGLWidget to paint into.
+        * Paints the signal with a QPainter
+        * @param p the QPainter to paint into.
         * @param rect the rectangular area to draw the trace into.
         * @param scale the scale in seconds per pixel.
         * @param offset the time to show at the left hand edge of
         *   the view in seconds.
         **/
-       virtual void paint(QGLWidget &widget, const QRect &rect,
-               double scale, double offset) = 0;
+       virtual void paint(QPainter &p, const QRect &rect, double scale,
+               double offset) = 0;
 
        /**
         * Paints the signal label into a QGLWidget.