Changeset - 1d12f68d4882
[Not reviewed]
scalezoomer
0 5 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-08-27 15:44:42
hy@ozderya.net
change color of the scale picker according to background
5 files changed with 23 insertions and 2 deletions:
0 comments (0 inline, 0 general)
plot.cpp
Show inline comments
 
@@ -89,22 +89,24 @@ void Plot::unzoom()
 
{
 
    zoomer.zoom(0);
 
}
 

	
 
void Plot::darkBackground(bool enabled)
 
{
 
    if (enabled)
 
    {
 
        setCanvasBackground(QBrush(Qt::black));
 
        grid.setPen(Qt::darkGray);
 
        zoomer.setRubberBandPen(QPen(Qt::white));
 
        zoomer.setTrackerPen(QPen(Qt::white));
 
        sZoomer.setPickerPen(QPen(Qt::white));
 
    }
 
    else
 
    {
 
        setCanvasBackground(QBrush(Qt::white));
 
        grid.setPen(Qt::lightGray);
 
        zoomer.setRubberBandPen(QPen(Qt::black));
 
        zoomer.setTrackerPen(QPen(Qt::black));
 
        sZoomer.setPickerPen(QPen(Qt::black));
 
    }
 
    replot();
 
}
scalepicker.cpp
Show inline comments
 
@@ -121,28 +121,35 @@ void ScalePicker::drawOverlay(QPainter* 
 
        QRect rect;
 
        if (_scaleWidget->alignment() == QwtScaleDraw::BottomScale ||
 
            _scaleWidget->alignment() == QwtScaleDraw::TopScale)
 
        {
 
            int height = painter->device()->height();
 
            rect = QRect(firstPosPx, 0, (currentPosPx-firstPosPx), height);
 
        }
 
        else // vertical
 
        {
 
            int width = painter->device()->width();
 
            rect = QRect(0, firstPosPx, width, (currentPosPx-firstPosPx));
 
        }
 

	
 
        painter->setPen(_pen);
 
        painter->drawRect(rect);
 
    }
 
}
 

	
 
void ScalePicker::setPen(QPen pen)
 
{
 
    _pen = pen;
 
}
 

	
 
double ScalePicker::position(QMouseEvent* mouseEvent)
 
{
 
    double pos;
 
    pos = positionPx(mouseEvent);
 
    // convert the position of the click to the plot coordinates
 
    pos = _scaleWidget->scaleDraw()->scaleMap().invTransform(pos);
 
    return pos;
 
}
 

	
 
double ScalePicker::positionPx(QMouseEvent* mouseEvent)
 
{
 
    double pos;
scalepicker.h
Show inline comments
 
@@ -13,44 +13,48 @@
 
  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 serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef SCALEPICKER_H
 
#define SCALEPICKER_H
 

	
 
#include <QObject>
 
#include <QMouseEvent>
 
#include <QPen>
 
#include <qwt_scale_widget.h>
 
#include <qwt_widget_overlay.h>
 

	
 
class ScalePicker : public QObject
 
{
 
    Q_OBJECT
 

	
 
public:
 
    ScalePicker(QwtScaleWidget* scaleWidget, QWidget* canvas);
 
    virtual bool eventFilter(QObject*, QEvent*);
 

	
 
    void drawOverlay(QPainter*); // called from ScalePickerOverlay
 
    void setPen(QPen pen);
 

	
 
signals:
 
    void pickStarted(double pos);
 
    void picking(double firstPos, double lastPos);
 
    void picked(double firstPos, double lastPos);
 

	
 
private:
 
    QwtScaleWidget* _scaleWidget;
 
    QwtWidgetOverlay* pickerOverlay; // ScalePickerOverlay
 
    double position(QMouseEvent*); // returns the axis mouse position relative to plot coordinates
 
    double positionPx(QMouseEvent*); // returns the axis mouse position in pixels
 
    QPen _pen;
 

	
 
    bool pressed;
 
    bool started;
 
    double firstPos; // converted to plot coordinates
 
    double firstPosPx; // pixel coordinates
 
    double currentPosPx; // current position in pixel coordinates
 

	
 
    double position(QMouseEvent*); // returns the axis mouse position relative to plot coordinates
 
    double positionPx(QMouseEvent*); // returns the axis mouse position in pixels
 
};
 

	
 
#endif // SCALEPICKER_H
scalezoomer.cpp
Show inline comments
 
@@ -23,24 +23,30 @@
 

	
 
ScaleZoomer::ScaleZoomer(QwtPlot* plot, QwtPlotZoomer* zoomer) :
 
    QObject(plot),
 
    bottomPicker(plot->axisWidget(QwtPlot::xBottom), plot->canvas()),
 
    leftPicker(plot->axisWidget(QwtPlot::yLeft), plot->canvas())
 
{
 
    _plot = plot;
 
    _zoomer = zoomer;
 
    connect(&bottomPicker, &ScalePicker::picked, this, &ScaleZoomer::bottomPicked);
 
    connect(&leftPicker, &ScalePicker::picked, this, &ScaleZoomer::leftPicked);
 
}
 

	
 
void ScaleZoomer::setPickerPen(QPen pen)
 
{
 
    bottomPicker.setPen(pen);
 
    leftPicker.setPen(pen);
 
}
 

	
 
void ScaleZoomer::bottomPicked(double firstPos, double lastPos)
 
{
 
    QRectF zRect;
 
    if (lastPos > firstPos)
 
    {
 
        zRect.setLeft(firstPos);
 
        zRect.setRight(lastPos);
 
    }
 
    else
 
    {
 
        zRect.setLeft(lastPos);
 
        zRect.setRight(firstPos);
scalezoomer.h
Show inline comments
 
@@ -12,35 +12,37 @@
 
  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 serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef SCALEZOOMER_H
 
#define SCALEZOOMER_H
 

	
 
#include <QObject>
 
#include <QPen>
 
#include <qwt_plot.h>
 
#include <qwt_plot_zoomer.h>
 

	
 
#include "scalepicker.h"
 

	
 
class ScaleZoomer : public QObject
 
{
 
    Q_OBJECT
 

	
 
public:
 
    ScaleZoomer(QwtPlot*, QwtPlotZoomer*);
 
    void setPickerPen(QPen pen);
 

	
 
private:
 
    QwtPlot* _plot;
 
    QwtPlotZoomer* _zoomer;
 
    ScalePicker bottomPicker;
 
    ScalePicker leftPicker;
 

	
 
private slots:
 
    void bottomPicked(double firstPos, double lastPos);
 
    void leftPicked(double firstPos, double lastPos);
 
};
 

	
0 comments (0 inline, 0 general)