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()
m_modeFollowMouse = new KToggleAction(KIcon(QLatin1String( "followmouse" )), i18n("&Follow Mouse Mode"), this);
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->setIconText(i18n("Mouse"));
m_modeFollowMouse->setToolTip(i18n("Magnify around the mouse cursor"));
m_modeFollowMouse->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified"));
#ifdef QAccessibilityClient_FOUND
m_modeFollowFocus = new KToggleAction(KIcon(QLatin1String( "view-restore" )), i18n("&Follow Focus Mode"), this);
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->setIconText(i18n("Focus"));
m_modeFollowFocus->setToolTip(i18n("Magnify around the keyboard focus"));
m_modeFollowFocus->setWhatsThis(i18n("If selected, the area around the keyboard cursor is magnified"));
#endif
m_modeSelWin = new KToggleAction(KIcon(QLatin1String( "window" )), i18n("Se&lection Window Mode"), this);
......@@ -383,19 +385,20 @@ void KmagApp::readOptions()
unsigned int colorIndex = cg.readEntry("ColorIndex", 0);
setColorIndex(colorIndex);
emit updateColorIndex(colorIndex);
/*
QString mode = cg.readEntry("Mode", "followmouse");
if (mode == QLatin1String( "wholescreen" ))
if (mode == QLatin1String( "wholescreen" )) {
slotModeWholeScreen();
else if (mode == QLatin1String( "selectionwindow" ))
} else if (mode == QLatin1String( "selectionwindow" )) {
slotModeSelWin();
#ifdef QAccessibilityClient_FOUND
else if (mode == QLatin1String( "followfocus" ))
slotModeFollowFocus();
#endif
else
slotModeFollowMouse();
} else if (mode == QLatin1String( "followfocus" )) {
m_modeFollowFocus->setChecked(true);
slotModeChanged();
} else {
m_modeFollowMouse->setChecked(true);
slotModeChanged();
}
*/
QRect defaultRect(0,0,211,164);
m_zoomView->setSelRectPos(cg.readEntry("SelRect", defaultRect));
......@@ -651,6 +654,7 @@ void KmagApp::slotModeWholeScreen()
m_zoomView->setFitToWindow (false);
m_modeFollowMouse->setChecked(false);
#ifdef QAccessibilityClient_FOUND
m_zoomView->followBoth(false);
m_zoomView->followFocus(false);
m_modeFollowFocus->setChecked(false);
#endif
......@@ -666,6 +670,7 @@ void KmagApp::slotModeSelWin()
m_zoomView->setFitToWindow (false);
m_modeFollowMouse->setChecked(false);
#ifdef QAccessibilityClient_FOUND
m_zoomView->followBoth(false);
m_zoomView->followFocus(false);
m_modeFollowFocus->setChecked(false);
#endif
......@@ -673,25 +678,43 @@ void KmagApp::slotModeSelWin()
m_modeSelWin->setChecked(true);
}
void KmagApp::slotModeFollowMouse()
void KmagApp::slotModeChanged()
{
#ifdef QAccessibilityClient_FOUND
if(m_modeFollowMouse->isChecked() && m_modeFollowFocus->isChecked()) {
//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
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
m_zoomView->followBoth(false);
m_zoomView->followFocus(false);
m_modeFollowFocus->setChecked(false);
#endif
m_modeWholeScreen->setChecked(false);
m_modeSelWin->setChecked(false);
}
#ifdef QAccessibilityClient_FOUND
void KmagApp::slotModeFollowFocus()
{
} else if (m_modeFollowFocus->isChecked()) {
//FOCUS MODE
m_zoomView->followBoth(false);
m_zoomView->followMouse(false);
m_zoomView->followFocus(true);
m_zoomView->showSelRect(false);
......@@ -700,9 +723,11 @@ void KmagApp::slotModeFollowFocus()
m_modeFollowFocus->setChecked(true);
m_modeWholeScreen->setChecked(false);
m_modeSelWin->setChecked(false);
}
#endif
}
}
void KmagApp::slotToggleHideCursor()
{
showMouseCursor(!m_hideCursor->isChecked());
......
......@@ -113,10 +113,7 @@ class KmagApp : public KXmlGuiWindow
/// Toggle the refreshing of the window
void slotToggleRefresh();
void slotModeFollowMouse();
#ifdef QAccessibilityClient_FOUND
void slotModeFollowFocus();
#endif
void slotModeChanged();
void slotModeWholeScreen();
void slotModeSelWin();
......
......@@ -14,6 +14,7 @@
</ToolBar>
<ToolBar noMerge="1" name="settingsToolBar"><text>Settings Toolbar</text>
<Action name="mode_main"/>
<Action name="mode_followmouse"/>
<Action name="mode_followfocus"/>
<Action name="mode_selectionwindow"/>
......@@ -50,6 +51,7 @@
<Action name="show_viewToolBar"/>
<Action name="show_settingsToolBar"/-->
<Separator />
<Action name="mode_main"/>
<Action name="mode_followmouse"/>
<Action name="mode_followfocus"/>
<Action name="mode_selectionwindow"/>
......
......@@ -42,6 +42,7 @@
#include <QtGui/QResizeEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QDesktopWidget>
#include <QtGui/QCursor>
#include <QtDBus/QDBusConnection>
// include files for KDE
......@@ -211,6 +212,27 @@ void KMagZoomView::followMouse(bool follow)
}
#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.
*/
......@@ -239,8 +261,13 @@ void KMagZoomView::followFocus(bool follow)
void KMagZoomView::focusChanged(const QAccessibleClient::AccessibleObject &object)
{
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
/**
......@@ -901,6 +928,10 @@ void KMagZoomView::grabFrame()
} else if(m_followFocus) {
// set the new center to the current keyboard cursor position
newCenter = m_oldFocus;
if(m_followBoth) {
m_followFocus=false;
m_followMouse=true;
}
#endif
}
......
......@@ -115,6 +115,9 @@ class KMagZoomView : public QAbstractScrollArea
void followMouse(bool follow = true);
#ifdef QAccessibilityClient_FOUND
/// Set grab-window-follows-mouse-and-keyboard-focus mode
void followBoth(bool follow = true);
/// Set grab-window-follows-keyboard-focus mode
void followFocus(bool follow = true);
#endif
......@@ -258,6 +261,7 @@ class KMagZoomView : public QAbstractScrollArea
/// To follow keyboard focus or not
bool m_followFocus;
bool m_followBoth;
/// State of refreshing - on or off
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