Commit 2278a10a authored by Amandeep Singh's avatar Amandeep Singh

Allowing KMag to follow both mouse & kbd-focus together

   -Made the followMouseMode & followFocusMode selectable together.
   -With just followMouseMode checked, Kmag follows mouse,
     and with followFocusMode checked, Kmag follows focus.
   -And when both are selected, it follows both the mouse,
     and the keyboard focus, whichever is relevant.
parent 0f73e1f2
...@@ -176,20 +176,22 @@ void KmagApp::initActions() ...@@ -176,20 +176,22 @@ void KmagApp::initActions()
m_modeFollowMouse = new KToggleAction(KIcon(QLatin1String( "followmouse" )), i18n("&Follow Mouse Mode"), this); m_modeFollowMouse = new KToggleAction(KIcon(QLatin1String( "followmouse" )), i18n("&Follow Mouse Mode"), this);
actionCollection()->addAction(QLatin1String( "mode_followmouse" ), m_modeFollowMouse); actionCollection()->addAction(QLatin1String( "mode_followmouse" ), m_modeFollowMouse);
connect(m_modeFollowMouse, SIGNAL(triggered(bool)), SLOT(slotModeFollowMouse())); connect(m_modeFollowMouse, SIGNAL(triggered(bool)), SLOT(slotModeChanged()));
m_modeFollowMouse->setShortcut(Qt::Key_F1); m_modeFollowMouse->setShortcut(Qt::Key_F1);
m_modeFollowMouse->setIconText(i18n("Mouse")); m_modeFollowMouse->setIconText(i18n("Mouse"));
m_modeFollowMouse->setToolTip(i18n("Magnify around the mouse cursor")); m_modeFollowMouse->setToolTip(i18n("Magnify around the mouse cursor"));
m_modeFollowMouse->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified")); m_modeFollowMouse->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified"));
#ifdef QAccessibilityClient_FOUND #ifdef QAccessibilityClient_FOUND
m_modeFollowFocus = new KToggleAction(KIcon(QLatin1String( "view-restore" )), i18n("&Follow Focus Mode"), this); m_modeFollowFocus = new KToggleAction(KIcon(QLatin1String( "view-restore" )), i18n("&Follow Focus Mode"), this);
actionCollection()->addAction(QLatin1String( "mode_followfocus" ), m_modeFollowFocus); actionCollection()->addAction(QLatin1String( "mode_followfocus" ), m_modeFollowFocus);
connect(m_modeFollowFocus, SIGNAL(triggered(bool)), SLOT(slotModeFollowFocus())); connect(m_modeFollowFocus, SIGNAL(triggered(bool)), SLOT(slotModeChanged()));
m_modeFollowFocus->setShortcut(Qt::Key_F2); m_modeFollowFocus->setShortcut(Qt::Key_F2);
m_modeFollowFocus->setIconText(i18n("Focus")); m_modeFollowFocus->setIconText(i18n("Focus"));
m_modeFollowFocus->setToolTip(i18n("Magnify around the keyboard focus")); m_modeFollowFocus->setToolTip(i18n("Magnify around the keyboard focus"));
m_modeFollowFocus->setWhatsThis(i18n("If selected, the area around the keyboard cursor is magnified")); m_modeFollowFocus->setWhatsThis(i18n("If selected, the area around the keyboard cursor is magnified"));
#endif #endif
m_modeSelWin = new KToggleAction(KIcon(QLatin1String( "window" )), i18n("Se&lection Window Mode"), this); m_modeSelWin = new KToggleAction(KIcon(QLatin1String( "window" )), i18n("Se&lection Window Mode"), this);
...@@ -383,19 +385,20 @@ void KmagApp::readOptions() ...@@ -383,19 +385,20 @@ void KmagApp::readOptions()
unsigned int colorIndex = cg.readEntry("ColorIndex", 0); unsigned int colorIndex = cg.readEntry("ColorIndex", 0);
setColorIndex(colorIndex); setColorIndex(colorIndex);
emit updateColorIndex(colorIndex); emit updateColorIndex(colorIndex);
/*
QString mode = cg.readEntry("Mode", "followmouse"); QString mode = cg.readEntry("Mode", "followmouse");
if (mode == QLatin1String( "wholescreen" )) if (mode == QLatin1String( "wholescreen" )) {
slotModeWholeScreen(); slotModeWholeScreen();
else if (mode == QLatin1String( "selectionwindow" )) } else if (mode == QLatin1String( "selectionwindow" )) {
slotModeSelWin(); slotModeSelWin();
#ifdef QAccessibilityClient_FOUND } else if (mode == QLatin1String( "followfocus" )) {
else if (mode == QLatin1String( "followfocus" )) m_modeFollowFocus->setChecked(true);
slotModeFollowFocus(); slotModeChanged();
#endif } else {
else m_modeFollowMouse->setChecked(true);
slotModeFollowMouse(); slotModeChanged();
}
*/
QRect defaultRect(0,0,211,164); QRect defaultRect(0,0,211,164);
m_zoomView->setSelRectPos(cg.readEntry("SelRect", defaultRect)); m_zoomView->setSelRectPos(cg.readEntry("SelRect", defaultRect));
...@@ -651,6 +654,7 @@ void KmagApp::slotModeWholeScreen() ...@@ -651,6 +654,7 @@ void KmagApp::slotModeWholeScreen()
m_zoomView->setFitToWindow (false); m_zoomView->setFitToWindow (false);
m_modeFollowMouse->setChecked(false); m_modeFollowMouse->setChecked(false);
#ifdef QAccessibilityClient_FOUND #ifdef QAccessibilityClient_FOUND
m_zoomView->followBoth(false);
m_zoomView->followFocus(false); m_zoomView->followFocus(false);
m_modeFollowFocus->setChecked(false); m_modeFollowFocus->setChecked(false);
#endif #endif
...@@ -666,6 +670,7 @@ void KmagApp::slotModeSelWin() ...@@ -666,6 +670,7 @@ void KmagApp::slotModeSelWin()
m_zoomView->setFitToWindow (false); m_zoomView->setFitToWindow (false);
m_modeFollowMouse->setChecked(false); m_modeFollowMouse->setChecked(false);
#ifdef QAccessibilityClient_FOUND #ifdef QAccessibilityClient_FOUND
m_zoomView->followBoth(false);
m_zoomView->followFocus(false); m_zoomView->followFocus(false);
m_modeFollowFocus->setChecked(false); m_modeFollowFocus->setChecked(false);
#endif #endif
...@@ -673,35 +678,55 @@ void KmagApp::slotModeSelWin() ...@@ -673,35 +678,55 @@ void KmagApp::slotModeSelWin()
m_modeSelWin->setChecked(true); m_modeSelWin->setChecked(true);
} }
void KmagApp::slotModeChanged()
void KmagApp::slotModeFollowMouse()
{ {
m_zoomView->followMouse(true);
m_zoomView->showSelRect(false);
m_zoomView->setFitToWindow (true);
m_modeFollowMouse->setChecked(true);
#ifdef QAccessibilityClient_FOUND #ifdef QAccessibilityClient_FOUND
m_zoomView->followFocus(false); if(m_modeFollowMouse->isChecked() && m_modeFollowFocus->isChecked()) {
m_modeFollowFocus->setChecked(false);
//BOTH MODE
m_zoomView->followMouse(false);
m_zoomView->followBoth(true);
m_zoomView->followFocus(false);
m_zoomView->showSelRect(false);
m_zoomView->setFitToWindow (true);
m_modeWholeScreen->setChecked(false);
m_modeSelWin->setChecked(false);
return;
}
#endif #endif
m_modeWholeScreen->setChecked(false);
m_modeSelWin->setChecked(false);
}
if (m_modeFollowMouse->isChecked()) {
//MOUSE MODE
m_zoomView->followMouse(true);
m_zoomView->showSelRect(false);
m_zoomView->setFitToWindow (true);
m_modeFollowMouse->setChecked(true);
#ifdef QAccessibilityClient_FOUND #ifdef QAccessibilityClient_FOUND
void KmagApp::slotModeFollowFocus() m_zoomView->followBoth(false);
{ m_zoomView->followFocus(false);
m_zoomView->followMouse(false); m_modeFollowFocus->setChecked(false);
m_zoomView->followFocus(true);
m_zoomView->showSelRect(false);
m_zoomView->setFitToWindow (true);
m_modeFollowMouse->setChecked(false);
m_modeFollowFocus->setChecked(true);
m_modeWholeScreen->setChecked(false);
m_modeSelWin->setChecked(false);
}
#endif #endif
m_modeWholeScreen->setChecked(false);
m_modeSelWin->setChecked(false);
#ifdef QAccessibilityClient_FOUND
} else if (m_modeFollowFocus->isChecked()) {
//FOCUS MODE
m_zoomView->followBoth(false);
m_zoomView->followMouse(false);
m_zoomView->followFocus(true);
m_zoomView->showSelRect(false);
m_zoomView->setFitToWindow (true);
m_modeFollowMouse->setChecked(false);
m_modeFollowFocus->setChecked(true);
m_modeWholeScreen->setChecked(false);
m_modeSelWin->setChecked(false);
#endif
}
}
void KmagApp::slotToggleHideCursor() void KmagApp::slotToggleHideCursor()
{ {
......
...@@ -113,10 +113,7 @@ class KmagApp : public KXmlGuiWindow ...@@ -113,10 +113,7 @@ class KmagApp : public KXmlGuiWindow
/// Toggle the refreshing of the window /// Toggle the refreshing of the window
void slotToggleRefresh(); void slotToggleRefresh();
void slotModeFollowMouse(); void slotModeChanged();
#ifdef QAccessibilityClient_FOUND
void slotModeFollowFocus();
#endif
void slotModeWholeScreen(); void slotModeWholeScreen();
void slotModeSelWin(); void slotModeSelWin();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
</ToolBar> </ToolBar>
<ToolBar noMerge="1" name="settingsToolBar"><text>Settings Toolbar</text> <ToolBar noMerge="1" name="settingsToolBar"><text>Settings Toolbar</text>
<Action name="mode_main"/>
<Action name="mode_followmouse"/> <Action name="mode_followmouse"/>
<Action name="mode_followfocus"/> <Action name="mode_followfocus"/>
<Action name="mode_selectionwindow"/> <Action name="mode_selectionwindow"/>
...@@ -50,6 +51,7 @@ ...@@ -50,6 +51,7 @@
<Action name="show_viewToolBar"/> <Action name="show_viewToolBar"/>
<Action name="show_settingsToolBar"/--> <Action name="show_settingsToolBar"/-->
<Separator /> <Separator />
<Action name="mode_main"/>
<Action name="mode_followmouse"/> <Action name="mode_followmouse"/>
<Action name="mode_followfocus"/> <Action name="mode_followfocus"/>
<Action name="mode_selectionwindow"/> <Action name="mode_selectionwindow"/>
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <QtGui/QResizeEvent> #include <QtGui/QResizeEvent>
#include <QtGui/QMouseEvent> #include <QtGui/QMouseEvent>
#include <QtGui/QDesktopWidget> #include <QtGui/QDesktopWidget>
#include <QtGui/QCursor>
#include <QtDBus/QDBusConnection> #include <QtDBus/QDBusConnection>
// include files for KDE // include files for KDE
...@@ -211,6 +212,27 @@ void KMagZoomView::followMouse(bool follow) ...@@ -211,6 +212,27 @@ void KMagZoomView::followMouse(bool follow)
} }
#ifdef QAccessibilityClient_FOUND #ifdef QAccessibilityClient_FOUND
void KMagZoomView::followBoth(bool follow)
{
m_followBoth = follow;
if(follow){
m_followMouse = true;
m_followFocus = false;
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
connect(&m_registry, SIGNAL(focusChanged(const QAccessibleClient::AccessibleObject &)),
this, SLOT(focusChanged(const QAccessibleClient::AccessibleObject &)));
} else {
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
disconnect(&m_registry, SIGNAL(focusChanged(const QAccessibleClient::AccessibleObject &)),
this, SLOT(focusChanged(const QAccessibleClient::AccessibleObject &)));
}
}
/** /**
* This function will set/reset keyboard focus following of grab window. * This function will set/reset keyboard focus following of grab window.
*/ */
...@@ -239,8 +261,13 @@ void KMagZoomView::followFocus(bool follow) ...@@ -239,8 +261,13 @@ void KMagZoomView::followFocus(bool follow)
void KMagZoomView::focusChanged(const QAccessibleClient::AccessibleObject &object) void KMagZoomView::focusChanged(const QAccessibleClient::AccessibleObject &object)
{ {
m_oldFocus = object.focusPoint(); m_oldFocus = object.focusPoint();
qDebug() << m_oldFocus; if(m_followBoth && !m_selRect.contains(m_oldFocus)) {
QCursor::setPos(m_oldFocus);
m_followFocus = true;
m_followMouse = false;
}
} }
#endif #endif
/** /**
...@@ -901,6 +928,10 @@ void KMagZoomView::grabFrame() ...@@ -901,6 +928,10 @@ void KMagZoomView::grabFrame()
} else if(m_followFocus) { } else if(m_followFocus) {
// set the new center to the current keyboard cursor position // set the new center to the current keyboard cursor position
newCenter = m_oldFocus; newCenter = m_oldFocus;
if(m_followBoth) {
m_followFocus=false;
m_followMouse=true;
}
#endif #endif
} }
......
...@@ -113,8 +113,11 @@ class KMagZoomView : public QAbstractScrollArea ...@@ -113,8 +113,11 @@ class KMagZoomView : public QAbstractScrollArea
/// Set grab-window-follows-mouse mode /// Set grab-window-follows-mouse mode
void followMouse(bool follow = true); void followMouse(bool follow = true);
#ifdef QAccessibilityClient_FOUND #ifdef QAccessibilityClient_FOUND
/// Set grab-window-follows-mouse-and-keyboard-focus mode
void followBoth(bool follow = true);
/// Set grab-window-follows-keyboard-focus mode /// Set grab-window-follows-keyboard-focus mode
void followFocus(bool follow = true); void followFocus(bool follow = true);
#endif #endif
...@@ -258,6 +261,7 @@ class KMagZoomView : public QAbstractScrollArea ...@@ -258,6 +261,7 @@ class KMagZoomView : public QAbstractScrollArea
/// To follow keyboard focus or not /// To follow keyboard focus or not
bool m_followFocus; bool m_followFocus;
bool m_followBoth;
/// State of refreshing - on or off /// State of refreshing - on or off
bool m_refreshSwitch; bool m_refreshSwitch;
......
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