Skip to content

Commit

Permalink
Merge branch 'RB-2.0-viewerkeys' into RB-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed May 23, 2016
2 parents 67d7558 + 2961dc9 commit 8889bc9
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 36 deletions.
29 changes: 29 additions & 0 deletions Gui/ActionShortcuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,35 @@ CLANG_DIAG_ON(uninitialized)
#define kShortcutIDActionConnectViewerToInput10 "connectViewerInput10"
#define kShortcutDescActionConnectViewerToInput10 "Connect Viewer to Input 10"

#define kShortcutIDActionConnectViewerBToInput1 "connectViewerBInput1"
#define kShortcutDescActionConnectViewerBToInput1 "Connect Viewer B Side to Input 1"

#define kShortcutIDActionConnectViewerBToInput2 "connectViewerBInput2"
#define kShortcutDescActionConnectViewerBToInput2 "Connect Viewer B Side to Input 2"

#define kShortcutIDActionConnectViewerBToInput3 "connectViewerBInput3"
#define kShortcutDescActionConnectViewerBToInput3 "Connect Viewer B Side to Input 3"

#define kShortcutIDActionConnectViewerBToInput4 "connectViewerBInput4"
#define kShortcutDescActionConnectViewerBToInput4 "Connect Viewer B Side to Input 4"

#define kShortcutIDActionConnectViewerBToInput5 "connectViewerBInput5"
#define kShortcutDescActionConnectViewerBToInput5 "Connect Viewer B Side to Input 5"

#define kShortcutIDActionConnectViewerBToInput6 "connectViewerBInput6"
#define kShortcutDescActionConnectViewerBToInput6 "Connect Viewer B Side to Input 6"

#define kShortcutIDActionConnectViewerBToInput7 "connectViewerBInput7"
#define kShortcutDescActionConnectViewerBToInput7 "Connect Viewer B Side to Input 7"

#define kShortcutIDActionConnectViewerBToInput8 "connectViewerBInput8"
#define kShortcutDescActionConnectViewerBToInput8 "Connect Viewer B Side to Input 8"

#define kShortcutIDActionConnectViewerBToInput9 "connectViewerBInput9"
#define kShortcutDescActionConnectViewerBToInput9 "Connect Viewer B Side to Input 9"

#define kShortcutIDActionConnectViewerBToInput10 "connectViewerBInput10"
#define kShortcutDescActionConnectViewerBToInput10 "Connect Viewer B Side to Input 10"

#define kShortcutIDActionShowPaneFullScreen "showPaneFullScreen"
#define kShortcutDescActionShowPaneFullScreen "Show Pane Full Screen"
Expand Down
53 changes: 41 additions & 12 deletions Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,9 @@ Gui::createMenuActions()
_imp->menuDisplay = new Menu(tr("Display"), _imp->menubar);
_imp->menuRender = new Menu(tr("Render"), _imp->menubar);
_imp->viewersMenu = new Menu(tr("Viewer(s)"), _imp->menuDisplay);
_imp->viewerInputsMenu = new Menu(tr("Connect Current Viewer"), _imp->viewersMenu);
_imp->viewersViewMenu = new Menu(tr("Display View Number"), _imp->viewersMenu);
_imp->viewerInputsMenu = new Menu(tr("Connect to A Side"), _imp->viewersMenu);
_imp->viewerInputsBMenu = new Menu(tr("Connect to B Side"), _imp->viewersMenu);
_imp->viewersViewMenu = new Menu(tr("View"), _imp->viewersMenu);
_imp->cacheMenu = new Menu(tr("Cache"), _imp->menubar);
_imp->menuHelp = new Menu(tr("Help"), _imp->menubar);

Expand Down Expand Up @@ -514,7 +515,7 @@ Gui::createMenuActions()
connect( _imp->actionsOpenRecentFile[c], SIGNAL(triggered()), this, SLOT(openRecentFile()) );
}

const char* descs[10] = {
const char* descs[NATRON_CONNECT_INPUT_NB] = {
kShortcutDescActionConnectViewerToInput1,
kShortcutDescActionConnectViewerToInput2,
kShortcutDescActionConnectViewerToInput3,
Expand All @@ -524,9 +525,19 @@ Gui::createMenuActions()
kShortcutDescActionConnectViewerToInput7,
kShortcutDescActionConnectViewerToInput8,
kShortcutDescActionConnectViewerToInput9,
kShortcutDescActionConnectViewerToInput10
kShortcutDescActionConnectViewerToInput10,
kShortcutDescActionConnectViewerBToInput1,
kShortcutDescActionConnectViewerBToInput2,
kShortcutDescActionConnectViewerBToInput3,
kShortcutDescActionConnectViewerBToInput4,
kShortcutDescActionConnectViewerBToInput5,
kShortcutDescActionConnectViewerBToInput6,
kShortcutDescActionConnectViewerBToInput7,
kShortcutDescActionConnectViewerBToInput8,
kShortcutDescActionConnectViewerBToInput9,
kShortcutDescActionConnectViewerBToInput10
};
const char* ids[10] = {
const char* ids[NATRON_CONNECT_INPUT_NB] = {
kShortcutIDActionConnectViewerToInput1,
kShortcutIDActionConnectViewerToInput2,
kShortcutIDActionConnectViewerToInput3,
Expand All @@ -536,16 +547,29 @@ Gui::createMenuActions()
kShortcutIDActionConnectViewerToInput7,
kShortcutIDActionConnectViewerToInput8,
kShortcutIDActionConnectViewerToInput9,
kShortcutIDActionConnectViewerToInput10
kShortcutIDActionConnectViewerToInput10,
kShortcutIDActionConnectViewerBToInput1,
kShortcutIDActionConnectViewerBToInput2,
kShortcutIDActionConnectViewerBToInput3,
kShortcutIDActionConnectViewerBToInput4,
kShortcutIDActionConnectViewerBToInput5,
kShortcutIDActionConnectViewerBToInput6,
kShortcutIDActionConnectViewerBToInput7,
kShortcutIDActionConnectViewerBToInput8,
kShortcutIDActionConnectViewerBToInput9,
kShortcutIDActionConnectViewerBToInput10
};


for (int i = 0; i < 10; ++i) {
for (int i = 0; i < NATRON_CONNECT_INPUT_NB; ++i) {
_imp->actionConnectInput[i] = new ActionWithShortcut(kShortcutGroupGlobal, ids[i], descs[i], this);
_imp->actionConnectInput[i]->setData(i);
_imp->actionConnectInput[i]->setData( i % (NATRON_CONNECT_INPUT_NB / 2) );
_imp->actionConnectInput[i]->setShortcutContext(Qt::WidgetShortcut);
QObject::connect( _imp->actionConnectInput[i], SIGNAL(triggered()), this, SLOT(connectInput()) );
}
if (i < NATRON_CONNECT_INPUT_NB/2) {
QObject::connect( _imp->actionConnectInput[i], SIGNAL(triggered()), this, SLOT(connectInput()) );
} else {
QObject::connect( _imp->actionConnectInput[i], SIGNAL(triggered()), this, SLOT(connectBInput()) );
} }

_imp->actionImportLayout = new ActionWithShortcut(kShortcutGroupGlobal, kShortcutIDActionImportLayout, kShortcutDescActionImportLayout, this);
QObject::connect( _imp->actionImportLayout, SIGNAL(triggered()), this, SLOT(importLayout()) );
Expand Down Expand Up @@ -605,9 +629,14 @@ Gui::createMenuActions()
_imp->menuDisplay->addAction(_imp->actionNewViewer);
_imp->menuDisplay->addAction( _imp->viewersMenu->menuAction() );
_imp->viewersMenu->addAction( _imp->viewerInputsMenu->menuAction() );
_imp->viewersMenu->addAction( _imp->viewerInputsBMenu->menuAction() );
_imp->viewersMenu->addAction( _imp->viewersViewMenu->menuAction() );
for (int i = 0; i < 10; ++i) {
_imp->viewerInputsMenu->addAction(_imp->actionConnectInput[i]);
for (int i = 0; i < NATRON_CONNECT_INPUT_NB; ++i) {
if ( i < (NATRON_CONNECT_INPUT_NB / 2) ) {
_imp->viewerInputsMenu->addAction(_imp->actionConnectInput[i]);
} else {
_imp->viewerInputsBMenu->addAction(_imp->actionConnectInput[i]);
}
}

_imp->menuDisplay->addAction(_imp->actionProject_settings);
Expand Down
5 changes: 5 additions & 0 deletions Gui/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON
void setLastKeyPressVisitedClickFocus(bool visited);
void setLastKeyUpVisitedClickFocus(bool visited);

/// Handle the viewer keys separately: use the nativeVirtualKey so that they work
/// on any keyboard, including French AZERTY (where numbers are shifted)
static int handleNativeKeys(int key, quint32 nativeScanCode, quint32 nativeVirtualKey) WARN_UNUSED_RETURN;

void setApplicationConsoleActionVisible(bool visible);

bool saveProjectAs(const std::string& filename);
Expand Down Expand Up @@ -613,6 +617,7 @@ public Q_SLOTS:
void connectInput();

void connectInput(int inputNb);
void connectBInput(int inputNb);


void showView0();
Expand Down
9 changes: 9 additions & 0 deletions Gui/Gui30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "Global/Macros.h"

#include <QtCore/QThread>
#include <QtCore/QDebug>

#include <QAction>
#include <QApplication> // qApp
Expand Down Expand Up @@ -497,6 +498,14 @@ Gui::connectInput(int inputNb)
graph->connectCurrentViewerToSelection(inputNb);
}

void
Gui::connectBInput(int inputNb)
{
#pragma message WARN("TODO: Gui::connectBInput()")
qDebug() << "Gui::connectBInput" << inputNb;
return connectInput(inputNb);
}

void
Gui::connectInput()
{
Expand Down
135 changes: 134 additions & 1 deletion Gui/Gui50.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,128 @@ Gui::setLastKeyUpVisitedClickFocus(bool visited)
_imp->keyUpEventHasVisitedFocusWidget = visited;
}

/// Handle the viewer keys separately: use the nativeVirtualKey so that they work
/// on any keyboard, including French AZERTY (where numbers are shifted)
int
Gui::handleNativeKeys(int key, quint32 nativeScanCode, quint32 nativeVirtualKey)
{
//qDebug() << "scancode=" << nativeScanCode << "virtualkey=" << nativeVirtualKey;
#ifdef Q_WS_MAC
// OS X virtual key codes, from
// MacOSX10.11.sdk/System/Library/Frameworks/Carbon.framework/Frameworks/HIToolbox.framework/Headers/Events.h
// kVK_ANSI_1 = 0x12,
// kVK_ANSI_2 = 0x13,
// kVK_ANSI_3 = 0x14,
// kVK_ANSI_4 = 0x15,
// kVK_ANSI_6 = 0x16,
// kVK_ANSI_5 = 0x17,
// kVK_ANSI_9 = 0x19,
// kVK_ANSI_7 = 0x1A,
// kVK_ANSI_8 = 0x1C,
// kVK_ANSI_0 = 0x1D,
Q_UNUSED(nativeScanCode);
switch (nativeVirtualKey) {
case 0x12:
return Qt::Key_1;
case 0x13:
return Qt::Key_2;
case 0x14:
return Qt::Key_3;
case 0x15:
return Qt::Key_4;
case 0x16:
return Qt::Key_6;
case 0x17:
return Qt::Key_5;
case 0x18:
return Qt::Key_9;
case 0x1A:
return Qt::Key_7;
case 0x1C:
return Qt::Key_8;
case 0x1D:
return Qt::Key_0;
}
#endif
#ifdef Q_WS_WIN
#pragma message WARN("TODO: handle keys 0-9 on AZERTY keyboards")
// https://msdn.microsoft.com/en-us/library/aa299374%28v=vs.60%29.aspx
// 48 0x30 (VK_0) | 0 key
// 49 0x31 (VK_1) | 1 key
// 50 0x32 (VK_2) | 2 key
// 51 0x33 (VK_3) | 3 key
// 52 0x34 (VK_4) | 4 key
// 53 0x35 (VK_5) | 5 key
// 54 0x36 (VK_6) | 6 key
// 55 0x37 (VK_7) | 7 key
// 56 0x38 (VK_8) | 8 key
// 57 0x39 (VK_9) | 9 key
// Windows seems to always return the same virtual key for digits, whatever the modifi
Q_UNUSED(nativeScanCode);
switch (nativeVirtualKey) {
case 0x30:
return Qt::Key_0;
case 0x31:
return Qt::Key_1;
case 0x32:
return Qt::Key_2;
case 0x33:
return Qt::Key_3;
case 0x34:
return Qt::Key_4;
case 0x35:
return Qt::Key_5;
case 0x36:
return Qt::Key_6;
case 0x37:
return Qt::Key_7;
case 0x38:
return Qt::Key_8;
case 0x39:
return Qt::Key_9;
}
#endif
#if defined(Q_WS_X11) && defined(Q_OS_LINUX)
#pragma message WARN("TODO: handle keys 0-9 on AZERTY keyboards")
// probably only possible on Linux, since scancodes are OS-dependent
// https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
Q_UNUSED(nativeVirtualKey);
switch (nativeScanCode) {
case 10:
return Qt::Key_1;
case 11:
return Qt::Key_2;
case 12:
return Qt::Key_3;
case 13:
return Qt::Key_4;
case 14:
return Qt::Key_5;
case 15:
return Qt::Key_6;
case 16:
return Qt::Key_7;
case 17:
return Qt::Key_8;
case 18:
return Qt::Key_9;
case 19:
return Qt::Key_0;
}
#endif
return key;
}

void
Gui::keyPressEvent(QKeyEvent* e)
{
//qDebug() << "Gui::keyPressed:" << e->text() << "modifiers:" << e->modifiers();
if (_imp->currentPanelFocusEventRecursion > 0) {
return;
}

QWidget* w = qApp->widgetAt( QCursor::pos() );
Qt::Key key = (Qt::Key)e->key();
Qt::Key key = (Qt::Key)Gui::handleNativeKeys( e->key(), e->nativeScanCode(), e->nativeVirtualKey() );
Qt::KeyboardModifiers modifiers = e->modifiers();

if (key == Qt::Key_Escape) {
Expand Down Expand Up @@ -489,6 +602,26 @@ Gui::keyPressEvent(QKeyEvent* e)
connectInput(8);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerToInput10, modifiers, key) ) {
connectInput(9);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput1, modifiers, key) ) {
connectBInput(0);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput2, modifiers, key) ) {
connectBInput(1);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput3, modifiers, key) ) {
connectBInput(2);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput4, modifiers, key) ) {
connectBInput(3);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput5, modifiers, key) ) {
connectBInput(4);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput6, modifiers, key) ) {
connectBInput(5);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput7, modifiers, key) ) {
connectBInput(6);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput8, modifiers, key) ) {
connectBInput(7);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput9, modifiers, key) ) {
connectBInput(8);
} else if ( isKeybind(kShortcutGroupGlobal, kShortcutIDActionConnectViewerBToInput10, modifiers, key) ) {
connectBInput(9);
} else {
/*
* Modifiers are always uncaught by child implementations so that we can forward them to 1 ViewerTab so that
Expand Down
Loading

0 comments on commit 8889bc9

Please sign in to comment.