sticking wheelEvents together for smooth visual experience.

This commit is contained in:
rachytski 2011-01-04 01:19:43 +02:00 committed by Alex Zolotarev
parent bc2d4a6aea
commit a7566208e7
3 changed files with 37 additions and 3 deletions

View file

@ -100,6 +100,9 @@ class FrameWork
m2::PointD m_position;
double m_confidenceRadius;
/// is AddRedrawCommand enabled?
bool m_isRedrawEnabled;
void Invalidate()
{
m_windowHandle->invalidate();
@ -113,7 +116,7 @@ class FrameWork
void AddRedrawCommand()
{
yg::gl::RenderState const state = m_renderQueue.CopyState();
if (state.m_currentScreen != m_navigator.Screen())
if ((state.m_currentScreen != m_navigator.Screen()) && (m_isRedrawEnabled))
AddRedrawCommandSure();
}
@ -163,7 +166,8 @@ public:
: m_windowHandle(windowHandle),
m_renderQueue(GetPlatform().SkinName(), GetPlatform().IsMultiSampled()),
m_isHeadingEnabled(false),
m_isPositionEnabled(false)
m_isPositionEnabled(false),
m_isRedrawEnabled(true)
{
m_renderQueue.AddWindowHandle(m_windowHandle);
}
@ -223,6 +227,13 @@ public:
UpdateNow();
}
/// enabling/disabling AddRedrawCommand
void SetRedrawEnabled(bool isRedrawEnabled)
{
m_isRedrawEnabled = isRedrawEnabled;
AddRedrawCommand();
}
/// respond to device orientation changes
void SetOrientation(EOrientation orientation)
{

View file

@ -17,9 +17,12 @@ namespace qt
m_handle(new handle_t(this)),
m_framework(m_handle),
m_isDrag(false),
m_pScale(0)
m_pScale(0),
m_redrawInterval(100)
{
m_framework.Init(storage);
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(ScaleTimerElapsed()));
}
void DrawWidget::SetScaleControl(QSlider * pScale)
@ -149,6 +152,7 @@ namespace qt
if (e->button() == Qt::LeftButton)
{
m_framework.SetRedrawEnabled(false);
m_framework.StartDrag(get_drag_event(e));
setCursor(Qt::CrossCursor);
@ -163,6 +167,7 @@ namespace qt
{
if (m_isDrag)
{
m_framework.SetRedrawEnabled(true);
m_framework.StopDrag(get_drag_event(e));
setCursor(Qt::ArrowCursor);
m_isDrag = false;
@ -186,6 +191,7 @@ namespace qt
if (m_isDrag && e->button() == Qt::LeftButton)
{
m_framework.SetRedrawEnabled(true);
m_framework.StopDrag(get_drag_event(e));
setCursor(Qt::ArrowCursor);
@ -193,10 +199,22 @@ namespace qt
}
}
void DrawWidget::ScaleTimerElapsed()
{
m_framework.SetRedrawEnabled(true);
m_timer->stop();
}
void DrawWidget::wheelEvent(QWheelEvent * e)
{
if (!m_isDrag)
{
/// if we are inside the timer, cancel it
if (m_timer->isActive())
m_timer->stop();
m_framework.SetRedrawEnabled(false);
m_timer->start(m_redrawInterval);
//m_framework.Scale(exp(e->delta() / 360.0));
m_framework.ScaleToPoint(ScaleToPointEvent(e->pos().x(), e->pos().y(), exp(e->delta() / 360.0)));
UpdateScaleControl();

View file

@ -7,6 +7,7 @@
#include "../map/framework.hpp"
#include "../map/navigator.hpp"
#include <QtCore/QTimer>
class FileReader;
template <class> class ReaderSource;
@ -35,6 +36,9 @@ namespace qt
bool m_isDrag;
QTimer * m_timer;
size_t m_redrawInterval;
Q_OBJECT
public Q_SLOTS:
@ -47,6 +51,7 @@ namespace qt
void ShowAll();
void Repaint();
void ScaleChanged(int action);
void ScaleTimerElapsed();
public:
DrawWidget(QWidget * pParent, storage::Storage & storage);