summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2021-04-14 19:14:53 +0300
committerMavridis Philippe <mavridisf@gmail.com>2021-04-23 15:09:49 +0300
commit0267f1cf497043a04a5367a33a0d66ae5e879705 (patch)
treebdd04f95e294e73b44cf19add63d3528fe09a0f7
parent22875e8865b87e40646015e882a444b8bf6965ac (diff)
downloadkompose-0267f1cf497043a04a5367a33a0d66ae5e879705.tar.gz
kompose-0267f1cf497043a04a5367a33a0d66ae5e879705.zip
Added Ctrl+[movement keys] for keyboard navigation between desktops.
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--src/komposedesktopwidget.cpp68
-rw-r--r--src/komposedesktopwidget.h6
-rw-r--r--src/komposefullscreenwidget.cpp115
-rw-r--r--src/komposefullscreenwidget.h15
4 files changed, 178 insertions, 26 deletions
diff --git a/src/komposedesktopwidget.cpp b/src/komposedesktopwidget.cpp
index 4c1bbde..0f3c567 100644
--- a/src/komposedesktopwidget.cpp
+++ b/src/komposedesktopwidget.cpp
@@ -31,6 +31,7 @@
#include <tqpainter.h>
#include <tqapplication.h>
#include <tqdragobject.h>
+#include <tqobjectlist.h>
#include <tqtooltip.h>
#include <tdelocale.h>
@@ -109,48 +110,75 @@ void KomposeDesktopWidget::initFonts()
// return (double)deskRect.width() / (double)deskRect.height();
// }
+void KomposeDesktopWidget::setHighlight()
+{
+ highlight = true;
+ repaint();
+}
+
+void KomposeDesktopWidget::clearHighlight()
+{
+ highlight = false;
+ repaint();
+}
+
+void KomposeDesktopWidget::setInactive()
+{
+ if( hasFocus() )
+ clearFocus();
+}
+
+void KomposeDesktopWidget::setActive()
+{
+ // Focus first window (if there is one)
+ const TQObjectList *lst = children();
+
+ if ( lst )
+ {
+ TQObjectListIterator it( *lst );
+ TQWidget *widget;
+ while ( (widget = (TQWidget*)it.current() ) )
+ {
+ if (widget->inherits("KomposeTaskWidget"))
+ {
+ widget->setFocus();
+ break;
+ }
+ ++it;
+ }
+ }
+
+ emit activated(this);
+}
void KomposeDesktopWidget::leaveEvent ( TQEvent * )
{
- // Unset highlight if cursor moves out of our rect
+ unsetCursor();
+
+ // Mark desktop as inactive if cursor moves out of our rect
// but not if it enters a child widget
TQRect deskRect;
deskRect.setTopLeft(mapToGlobal( TQPoint(0,0) ));
deskRect.setWidth(width());
deskRect.setHeight(height());
if ( !deskRect.contains( TQCursor::pos() ) )
- highlight = false;
-
- unsetCursor();
- repaint();
+ setInactive();
}
void KomposeDesktopWidget::enterEvent ( TQEvent * )
{
- setFocus();
setCursor( KCursor::handCursor() );
- highlight = true;
- repaint();
+ setActive();
}
void KomposeDesktopWidget::focusInEvent ( TQFocusEvent * )
{
- highlight = true;
- repaint();
+ setActive();
}
void KomposeDesktopWidget::focusOutEvent ( TQFocusEvent * )
{
- // Unset highlight if cursor moves out of our rect
- // but not if it enters a child widget
- TQRect deskRect;
- deskRect.setTopLeft(mapToGlobal( TQPoint(0,0) ));
- deskRect.setWidth(width());
- deskRect.setHeight(height());
- if ( !deskRect.contains( TQCursor::pos() ) )
- highlight = false;
-
- repaint();
+ setInactive();
}
void KomposeDesktopWidget::mouseReleaseEvent ( TQMouseEvent * e )
diff --git a/src/komposedesktopwidget.h b/src/komposedesktopwidget.h
index a3a3449..e3e646b 100644
--- a/src/komposedesktopwidget.h
+++ b/src/komposedesktopwidget.h
@@ -36,12 +36,18 @@ public:
~KomposeDesktopWidget();
+ void setHighlight();
+ void clearHighlight();
+ void setInactive();
+ void setActive();
+
// int getHeightForWidth( int w ) const;
// int getWidthForHeight( int h ) const;
// double getAspectRatio();
signals:
void contentsChanged();
+ void activated(KomposeDesktopWidget*);
protected:
void paintEvent ( TQPaintEvent * );
diff --git a/src/komposefullscreenwidget.cpp b/src/komposefullscreenwidget.cpp
index 4fdda7f..f54c633 100644
--- a/src/komposefullscreenwidget.cpp
+++ b/src/komposefullscreenwidget.cpp
@@ -33,6 +33,7 @@
#include <kdebug.h>
#include <krootpixmap.h>
+static bool controlHold = false; // is the control key pressed
KomposeFullscreenWidget::KomposeFullscreenWidget( int displayType, KomposeLayout *l )
: KomposeTaskContainerWidget( -1, 0, l ),
@@ -160,7 +161,8 @@ void KomposeFullscreenWidget::createDesktopWidgets()
//int col = i % 2;
//kdDebug() << "rc %d %d", row, col);
KomposeDesktopWidget *desktop = new KomposeDesktopWidget(i, this );
- connect(desktop, SIGNAL(contentsChanged()), layout, SLOT(arrangeLayout()) );
+ connect( desktop, SIGNAL(contentsChanged()), layout, SLOT(arrangeLayout()) );
+ connect( desktop, SIGNAL(activated(KomposeDesktopWidget*)), this, SLOT(desktopChanged(KomposeDesktopWidget*)) );
desktop->show();
}
}
@@ -190,7 +192,16 @@ void KomposeFullscreenWidget::mousePressEvent ( TQMouseEvent * e )
}
}
-void KomposeFullscreenWidget::keyReleaseEvent ( TQKeyEvent * e )
+void KomposeFullscreenWidget::keyPressEvent( TQKeyEvent *e )
+{
+ if ( e->key() == TQt::Key_Control )
+ {
+ controlHold = true;
+ e->accept();
+ }
+}
+
+void KomposeFullscreenWidget::keyReleaseEvent ( TQKeyEvent *e )
{
if ( e->key() == TQt::Key_Escape )
{
@@ -198,14 +209,114 @@ void KomposeFullscreenWidget::keyReleaseEvent ( TQKeyEvent * e )
KomposeViewManager::instance()->closeCurrentView();
e->accept();
}
+
+ else if ( e->key() == TQt::Key_Control )
+ {
+ controlHold = false;
+ e->accept();
+ return;
+ }
+
+ // Movement keys
+ else if ( e->key() == TQt::Key_Right || e->key() == TQt::Key_D || e->key() == TQt::Key_H ||
+ e->key() == TQt::Key_Left || e->key() == TQt::Key_A || e->key() == TQt::Key_J ||
+ e->key() == TQt::Key_Up || e->key() == TQt::Key_W || e->key() == TQt::Key_K ||
+ e->key() == TQt::Key_Down || e->key() == TQt::Key_S || e->key() == TQt::Key_L )
+ {
+ // Map keys to directions
+ int direction = DLAYOUT_RIGHT;
+ switch( e->key() )
+ {
+ case TQt::Key_Right:
+ direction = DLAYOUT_RIGHT;
+ break;
+ case TQt::Key_D:
+ direction = DLAYOUT_RIGHT;
+ break;
+ case TQt::Key_L:
+ direction = DLAYOUT_RIGHT;
+ break;
+ case TQt::Key_Left:
+ direction = DLAYOUT_LEFT;
+ break;
+ case TQt::Key_A:
+ direction = DLAYOUT_LEFT;
+ break;
+ case TQt::Key_H:
+ direction = DLAYOUT_LEFT;
+ break;
+ case TQt::Key_Up:
+ direction = DLAYOUT_TOP;
+ break;
+ case TQt::Key_W:
+ direction = DLAYOUT_TOP;
+ break;
+ case TQt::Key_K:
+ direction = DLAYOUT_TOP;
+ break;
+ case TQt::Key_Down:
+ direction = DLAYOUT_BOTTOM;
+ break;
+ case TQt::Key_S:
+ direction = DLAYOUT_BOTTOM;
+ break;
+ case TQt::Key_J:
+ direction = DLAYOUT_BOTTOM;
+ break;
+ }
+
+ focusNeighbourDesk( direction );
+ e->accept();
+ return;
+ }
+
else
{
kdDebug() << "KomposeFullscreenWidget::keyReleaseEvent - ignored..." << endl;
e->ignore();
}
+
KomposeTaskContainerWidget::keyReleaseEvent(e);
}
+bool KomposeFullscreenWidget::focusNeighbourDesk( int direction )
+{
+ bool successfull = false;
+ KomposeWidget *widget;
+ if ( ( widget = layout->getNeighbour( dynamic_cast<KomposeWidget*>(current), direction, WLAYOUT_BOTH ) ) != 0 )
+ {
+ kdDebug() << "KomposeFullscreenWidget::keyReleaseEvent - Focussing " << widget->className() << endl;
+ dynamic_cast<KomposeDesktopWidget*>(widget)->setActive();
+ successfull = true;
+ }
+
+ return successfull;
+}
+
+void KomposeFullscreenWidget::desktopChanged( KomposeDesktopWidget* desk )
+{
+ kdDebug() << "KomposeFullscreenWidget: desktopChanged" << endl;
+ // Remove highlight from all other desks
+ const TQObjectList *lst = children();
+
+ if( lst )
+ {
+ TQObjectListIterator it( *lst );
+ TQWidget *widget;
+ while ( (widget = (TQWidget*)it.current() ) )
+ {
+ if ( widget->inherits("KomposeDesktopWidget") )
+ {
+ dynamic_cast<KomposeDesktopWidget*>(widget)->clearHighlight();
+ }
+ ++it;
+ }
+ }
+
+ desk->setHighlight();
+ current = desk;
+}
+
int KomposeFullscreenWidget::getHeightForWidth ( int w ) const
{
return (int)(((double)w / (double)width()) * (double)height());
diff --git a/src/komposefullscreenwidget.h b/src/komposefullscreenwidget.h
index 7b1af6e..15f3fdf 100644
--- a/src/komposefullscreenwidget.h
+++ b/src/komposefullscreenwidget.h
@@ -44,18 +44,25 @@ protected:
void initMenu();
void createDesktopWidgets();
- void mouseReleaseEvent (TQMouseEvent *);
- void mousePressEvent (TQMouseEvent *);
- void keyReleaseEvent ( TQKeyEvent * e );
+ void mouseReleaseEvent( TQMouseEvent * );
+ void mousePressEvent( TQMouseEvent * );
+ void keyPressEvent( TQKeyEvent *e );
+ void keyReleaseEvent( TQKeyEvent *e );
// void paintEvent ( TQPaintEvent * );
+ bool focusNeighbourDesk( int direction );
+
void destroyChildWidgets();
// virtual void closeEvent ( TQCloseEvent * e );
-
+
+protected slots:
+ void desktopChanged( KomposeDesktopWidget* desk );
+
private:
int type;
TDEPopupMenu *menu;
KRootPixmap *rootpix;
+ KomposeDesktopWidget *current;
};
#endif