Browse Source

Added Ctrl+[movement keys] for keyboard navigation between desktops.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/9/head
Mavridis Philippe 1 year ago
parent
commit
0267f1cf49
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494
  1. 68
      src/komposedesktopwidget.cpp
  2. 6
      src/komposedesktopwidget.h
  3. 115
      src/komposefullscreenwidget.cpp
  4. 15
      src/komposefullscreenwidget.h

68
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 )

6
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 * );

115
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());

15
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

Loading…
Cancel
Save