Make LcdSpinBox double-clickable to enter value

This commit is contained in:
Vesa
2014-03-01 23:44:58 +02:00
parent 5586141bf5
commit dd8fa5d80c
2 changed files with 30 additions and 3 deletions

View File

@@ -23,8 +23,8 @@
*/
#ifndef _LCD_SPINBOX_H
#define _LCD_SPINBOX_H
#ifndef LCD_SPINBOX_H
#define LCD_SPINBOX_H
#include "LcdWidget.h"
#include "AutomatableModelView.h"
@@ -70,12 +70,13 @@ protected:
virtual void mouseMoveEvent( QMouseEvent * _me );
virtual void mouseReleaseEvent( QMouseEvent * _me );
virtual void wheelEvent( QWheelEvent * _we );
virtual void mouseDoubleClickEvent( QMouseEvent * _me );
private:
bool m_mouseMoving;
QPoint m_origMousePos;
int m_displayOffset;
void enterValue();
signals:
void manualChange();

View File

@@ -29,6 +29,7 @@
#include <QtGui/QPainter>
#include <QtGui/QFontMetrics>
#include <QtGui/QStyleOptionFrameV2>
#include <QtGui/QInputDialog>
#include "LcdSpinBox.h"
#include "caption_menu.h"
@@ -119,6 +120,8 @@ void LcdSpinBox::mouseMoveEvent( QMouseEvent* event )
if( m_mouseMoving )
{
int dy = event->globalY() - m_origMousePos.y();
if( engine::mainWindow()->isShiftPressed() )
dy = qBound( -4, dy/4, 4 );
if( dy > 1 || dy < -1 )
{
model()->setInitValue( model()->value() -
@@ -156,7 +159,30 @@ void LcdSpinBox::wheelEvent( QWheelEvent * _we )
emit manualChange();
}
void LcdSpinBox::mouseDoubleClickEvent( QMouseEvent * )
{
enterValue();
}
void LcdSpinBox::enterValue()
{
bool ok;
int new_val;
new_val = QInputDialog::getInt(
this, windowTitle(),
tr( "Please enter a new value between %1 and %2:" ).
arg( model()->minValue() ).
arg( model()->maxValue() ),
model()->value(),
model()->minValue(),
model()->maxValue(), 4, &ok );
if( ok )
{
model()->setValue( new_val );
}
}
#include "moc_LcdSpinBox.cxx"