Commit 50aa150e authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Adding a KeyboardShortcutInput to provide keyboard shortcut acquisition.

parent d9a04c21
#include <QKeyEvent>
#include <QKeySequence>
#include <QtDebug>
#include "KeyboardShortcutInput.h"
KeyboardShortcutInput::KeyboardShortcutInput( QWidget* parent ) :
QPushButton( parent ),
m_capturing( false ),
m_current( 0 )
{
m_timer = new QTimer( this );
m_timer->setSingleShot( true );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( timeout() ) );
}
void KeyboardShortcutInput::mousePressEvent( QMouseEvent* )
{
m_capturing = true;
setDown( true );
memset( m_shortcuts, 0, sizeof( m_shortcuts ) );
m_current = 0;
setText( "" );
}
void KeyboardShortcutInput::mouseReleaseEvent( QMouseEvent* )
{
}
void KeyboardShortcutInput::release()
{
m_capturing = false;
setDown( false );
}
void KeyboardShortcutInput::keyPressEvent( QKeyEvent* e )
{
if ( m_capturing == false )
{
QPushButton::keyPressEvent( e );
return ;
}
if ( e->modifiers() == Qt::NoModifier && e->key() == Qt::Key_Escape )
{
release();
}
else
{
m_timer->stop();
int key = e->key();
if ( key == Qt::Key_Control || key == Qt::Key_Meta ||
key == Qt::Key_Shift || key == Qt::Key_Alt ||
key == Qt::Key_AltGr )
key = 0;
int res = key | e->modifiers();
m_shortcuts[m_current] = res;
QKeySequence seq( m_shortcuts[0], m_shortcuts[1], m_shortcuts[2], m_shortcuts[3] );
setText( seq.toString() );
if ( key != 0 )
{
m_timer->start( 500 );
++m_current;
}
}
}
void KeyboardShortcutInput::timeout()
{
release();
}
#ifndef KEYBOARDSHORTCUTINPUT_H
#define KEYBOARDSHORTCUTINPUT_H
#include <QPushButton>
#include <QTimer>
class KeyboardShortcutInput : public QPushButton
{
Q_OBJECT
public:
KeyboardShortcutInput( QWidget* parent );
protected:
virtual void keyPressEvent( QKeyEvent* e );
virtual void mousePressEvent( QMouseEvent* e );
virtual void mouseReleaseEvent( QMouseEvent* e );
void release();
protected slots:
void timeout();
private:
bool m_capturing;
QTimer* m_timer;
unsigned int m_current;
int m_shortcuts[4];
};
#endif // KEYBOARDSHORTCUTINPUT_H
......@@ -10,6 +10,7 @@ HEADERS += AudioProjectPreferences.h \
PreferenceWidget.h \
ProjectPreferences.h \
Settings.h \
KeyboardShortcutInput.h \
VLMCPreferences.h \
VideoProjectPreferences.h
......@@ -18,5 +19,6 @@ SOURCES += AudioProjectPreferences.cpp \
PreferenceWidget.cpp \
ProjectPreferences.cpp \
Settings.cpp \
KeyboardShortcutInput.cpp \
VLMCPreferences.cpp \
VideoProjectPreferences.cpp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment