##// END OF EJS Templates
adds QChartView PIMPL, refactor public API
adds QChartView PIMPL, refactor public API

File last commit:

r642:232e93af7ea7
r746:646ccd5c026b
Show More
chartwidget.cpp
74 lines | 1.5 KiB | text/x-c | CppLexer
Michal Klocek
Add zoom support...
r67 #include "chartwidget.h"
#include <QMouseEvent>
ChartWidget::ChartWidget(QWidget *parent)
: QChartView(parent),
m_rubberBand(QRubberBand::Rectangle,this)
{
}
void ChartWidget::mousePressEvent(QMouseEvent *event)
{
if(event->button()!=Qt::LeftButton) return;
Tero Ahola
Fixed build issue with margin related funcs
r642 int margin = 25;
Michal Klocek
Add zoom support...
r67 QRect rect(margin,margin,width()-2*margin,height()-2*margin);
m_origin = event->pos();
if (!rect.contains(m_origin)) return;
m_rubberBand.setGeometry(QRect(m_origin, QSize()));
m_rubberBand.show();
event->accept();
}
void ChartWidget::mouseMoveEvent(QMouseEvent *event)
{
if(m_rubberBand.isVisible())
m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized());
}
void ChartWidget::mouseReleaseEvent(QMouseEvent *event)
{
if( event->button()==Qt::LeftButton && m_rubberBand.isVisible()) {
m_rubberBand.hide();
QRect rect = m_rubberBand.geometry();
Michal Klocek
Fixes zoomline chart example
r226 zoomIn(rect);
Michal Klocek
Add zoom support...
r67 event->accept();
}
if(event->button()==Qt::RightButton) {
zoomOut();
}
}
void ChartWidget::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Plus:
zoomIn();
break;
case Qt::Key_Minus:
zoomOut();
break;
Michal Klocek
Adds scroll support...
r531 case Qt::Key_Left:
Michal Klocek
Fix zoom presenter examples
r601 scrollLeft();
Michal Klocek
Adds scroll support...
r531 break;
case Qt::Key_Right:
Michal Klocek
Fix zoom presenter examples
r601 scrollRight();
Michal Klocek
Adds scroll support...
r531 break;
case Qt::Key_Up:
Michal Klocek
Fix zoom presenter examples
r601 scrollUp();
Michal Klocek
Adds scroll support...
r531 break;
case Qt::Key_Down:
Michal Klocek
Fix zoom presenter examples
r601 scrollDown();
Michal Klocek
Adds scroll support...
r531 break;
Michal Klocek
Add zoom support...
r67 default:
QGraphicsView::keyPressEvent(event);
break;
}
}