Added special setActive() and setInactive() functions.

They handle both focus and highlight, which seems logical.

This fixes most annoying bugs with desktop switching.

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/8/head
Mavridis Philippe 3 years ago
parent cc13befa92
commit b5e39bb95f
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -109,48 +109,53 @@ void KomposeDesktopWidget::initFonts()
// return (double)deskRect.width() / (double)deskRect.height(); // return (double)deskRect.width() / (double)deskRect.height();
// } // }
void KomposeDesktopWidget::setInactive()
{
if( hasFocus() )
clearFocus();
highlight = false;
repaint();
}
void KomposeDesktopWidget::setActive()
{
if( !hasFocus() )
setFocus();
highlight = true;
repaint();
}
void KomposeDesktopWidget::leaveEvent ( TQEvent * ) 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 // but not if it enters a child widget
TQRect deskRect; TQRect deskRect;
deskRect.setTopLeft(mapToGlobal( TQPoint(0,0) )); deskRect.setTopLeft(mapToGlobal( TQPoint(0,0) ));
deskRect.setWidth(width()); deskRect.setWidth(width());
deskRect.setHeight(height()); deskRect.setHeight(height());
if ( !deskRect.contains( TQCursor::pos() ) ) if ( !deskRect.contains( TQCursor::pos() ) )
highlight = false; setInactive();
unsetCursor();
repaint();
} }
void KomposeDesktopWidget::enterEvent ( TQEvent * ) void KomposeDesktopWidget::enterEvent ( TQEvent * )
{ {
setFocus();
setCursor( KCursor::handCursor() ); setCursor( KCursor::handCursor() );
highlight = true; setActive();
repaint();
} }
void KomposeDesktopWidget::focusInEvent ( TQFocusEvent * ) void KomposeDesktopWidget::focusInEvent ( TQFocusEvent * )
{ {
highlight = true; setActive();
repaint();
} }
void KomposeDesktopWidget::focusOutEvent ( TQFocusEvent * ) void KomposeDesktopWidget::focusOutEvent ( TQFocusEvent * )
{ {
// Unset highlight if cursor moves out of our rect setInactive();
// 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();
} }
void KomposeDesktopWidget::mouseReleaseEvent ( TQMouseEvent * e ) void KomposeDesktopWidget::mouseReleaseEvent ( TQMouseEvent * e )

@ -36,6 +36,9 @@ public:
~KomposeDesktopWidget(); ~KomposeDesktopWidget();
void setInactive();
void setActive();
// int getHeightForWidth( int w ) const; // int getHeightForWidth( int w ) const;
// int getWidthForHeight( int h ) const; // int getWidthForHeight( int h ) const;
// double getAspectRatio(); // double getAspectRatio();

Loading…
Cancel
Save