From 0ad89bfab8e26e1b7c2bc8bf12275e6f0e7153fd Mon Sep 17 00:00:00 2001 From: Mathias Soeken Date: Mon, 9 Feb 2009 10:21:03 +0000 Subject: [PATCH] Close button when in tray icon mode. This can be configured to be visible independent from the other tool buttons. svn path=/trunk/KDE/kdegraphics/kruler/; revision=923733 --- TODO | 5 ++--- cfg_appearance.ui | 26 +++++++++++++++++++++++++- klineal.cpp | 43 ++++++++++++++++++++++++++++++++----------- klineal.h | 3 ++- kruler.kcfg | 6 +++++- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/TODO b/TODO index 69bea2b..91dd052 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,9 @@ TODO * non-model preferences dialog, so that you can see the result when you change the color -* show/hide tray icon (and close action) when configuring tray icon * move tray icon to another page in configuration dialog * move some actions to tray icon context menu -* close button (visible on hover) on the lineal +* show/hide tray icon (and close action) when configuring tray icon DONE * Center scale @@ -13,4 +12,4 @@ DONE * Store last orientation and scale direction * Store scale offset * Relative scale (percent). Then ignoring offset? - +* close button (visible on hover) on the lineal diff --git a/cfg_appearance.ui b/cfg_appearance.ui index 854959d..bd8ea8e 100644 --- a/cfg_appearance.ui +++ b/cfg_appearance.ui @@ -48,6 +48,13 @@ + + + + Show close button + + + @@ -67,5 +74,22 @@ kcfg_BgColor - + + + kcfg_TrayIcon + toggled(bool) + kcfg_CloseButtonVisible + setEnabled(bool) + + + 172 + 100 + + + 183 + 127 + + + + diff --git a/klineal.cpp b/klineal.cpp index 0f9ac3c..0fb99f9 100644 --- a/klineal.cpp +++ b/klineal.cpp @@ -79,7 +79,8 @@ KLineal::KLineal( QWidget *parent ) mCenterOriginAction( 0 ), mOffsetAction( 0 ), mClicked( false ), - mActionCollection( 0 ) + mActionCollection( 0 ), + mCloseButton( 0 ) { KWindowSystem::setType( winId(), NET::Override ); // or NET::Normal KWindowSystem::setState( winId(), NET::KeepAbove ); @@ -121,7 +122,6 @@ KLineal::KLineal( QWidget *parent ) mLabel->setWhatsThis( i18n( "This is the current distance measured in pixels." ) ); mColorLabel = new QAutoSizeLabel( this ); mColorLabel->setAutoFillBackground( true ); - mColorLabel->hide(); QFont colorFont( KGlobalSettings::fixedFont().family(), 10 ); colorFont.setPixelSize( 10 ); mColorLabel->setFont( colorFont ); @@ -132,17 +132,13 @@ KLineal::KLineal( QWidget *parent ) "little square at the end of the line cursor." ) ); mBtnRotateLeft = new QToolButton( this ); - mBtnRotateLeft->setGeometry( mLongEdgeLen / 2 - 28, 5, 26, 26 ); mBtnRotateLeft->setIcon( KIcon( "object-rotate-left" ) ); mBtnRotateLeft->setToolTip( i18n( "Turn Left" ) ); - mBtnRotateLeft->hide(); connect( mBtnRotateLeft, SIGNAL( clicked() ), this, SLOT( turnLeft() ) ); mBtnRotateRight = new QToolButton( this ); - mBtnRotateRight->setGeometry( mLongEdgeLen / 2 + 2, 5, 26, 26 ); mBtnRotateRight->setIcon( KIcon( "object-rotate-right" ) ); mBtnRotateRight->setToolTip( i18n( "Turn Right" ) ); - mBtnRotateRight->hide(); connect( mBtnRotateRight, SIGNAL( clicked() ), this, SLOT( turnRight() ) ); resize( QSize( mLongEdgeLen, mShortEdgeLen ) ); @@ -232,6 +228,11 @@ KLineal::KLineal( QWidget *parent ) KAction *closeAction = KStandardAction::close( this, SLOT( slotClose() ), this ); mActionCollection->addAction( "close", closeAction ); mMenu->addAction( closeAction ); + + mCloseButton = new QToolButton( this ); + mCloseButton->setIcon( closeAction->icon() ); + mCloseButton->setToolTip( closeAction->text().replace( '&', QString() ) ); + connect( mCloseButton, SIGNAL( clicked() ), this, SLOT( slotClose() ) ); } KAction *quit = KStandardAction::quit( kapp, SLOT( quit() ), this ); @@ -243,6 +244,7 @@ KLineal::KLineal( QWidget *parent ) mLastClickPos = geometry().topLeft() + QPoint( width() / 2, height() / 2 ); + hideLabel(); setOrientation( mOrientation ); if ( RulerSettings::self()->trayIcon() ) { @@ -413,7 +415,7 @@ void KLineal::setOrientation( int inOrientation ) break; } - adjustRotateButtons(); + adjustButtons(); if ( mLenMenu && mFullScreenAction ) { mFullScreenAction->setText( mOrientation % 2 ? i18n( "&Full Screen Height" ) : i18n( "&Full Screen Width" ) ); @@ -480,7 +482,7 @@ void KLineal::reLength( int percentOfScreen ) move( x(), 10 ); } - adjustRotateButtons(); + adjustButtons(); saveSettings(); } @@ -507,7 +509,7 @@ void KLineal::reLengthAbsolute( int length ) move( x(), 10 ); } - adjustRotateButtons(); + adjustButtons(); saveSettings(); } @@ -612,6 +614,7 @@ void KLineal::slotPreferences() Ui::ConfigAppearance appearanceConfig; QWidget *appearanceConfigWidget = new QWidget( dialog ); appearanceConfig.setupUi( appearanceConfigWidget ); + appearanceConfig.kcfg_CloseButtonVisible->setEnabled( appearanceConfig.kcfg_TrayIcon->isChecked() ); dialog->addPage( appearanceConfigWidget, i18n( "Appearance" ), "preferences-desktop-default-applications" ); dialog->exec(); @@ -698,6 +701,9 @@ void KLineal::showLabel() mBtnRotateLeft->show(); mBtnRotateRight->show(); } + if ( mCloseButton && RulerSettings::self()->closeButtonVisible() ) { + mCloseButton->show(); + } } /** @@ -709,6 +715,9 @@ void KLineal::hideLabel() mColorLabel->hide(); mBtnRotateLeft->hide(); mBtnRotateRight->hide(); + if ( mCloseButton ) { + mCloseButton->hide(); + } } /** @@ -741,29 +750,41 @@ void KLineal::adjustLabel() } /** - * Updates the position of the rotation buttons + * Updates the position of the tool buttons */ -void KLineal::adjustRotateButtons() +void KLineal::adjustButtons() { switch( mOrientation ) { case North: mBtnRotateLeft->move( mLongEdgeLen / 2 - 28, height() - 31 ); mBtnRotateRight->move( mLongEdgeLen / 2 + 2, height() - 31 ); + if ( mCloseButton ) { + mCloseButton->move( width() - 31, height() - 31 ); + } break; case South: mBtnRotateLeft->move( mLongEdgeLen / 2 - 28, 5 ); mBtnRotateRight->move( mLongEdgeLen / 2 + 2, 5 ); + if ( mCloseButton ) { + mCloseButton->move( width() - 31, 5 ); + } break; case East: mBtnRotateLeft->move( 5, mLongEdgeLen / 2 - 28 ); mBtnRotateRight->move( 5, mLongEdgeLen / 2 + 2 ); + if ( mCloseButton ) { + mCloseButton->move( 5, height() - 31 ); + } break; case West: mBtnRotateLeft->move( width() - 31, mLongEdgeLen / 2 - 28 ); mBtnRotateRight->move( width() - 31, mLongEdgeLen / 2 + 2 ); + if ( mCloseButton ) { + mCloseButton->move( width() - 31, height() - 31 ); + } break; } } diff --git a/klineal.h b/klineal.h index c6ffe1c..3ab8527 100644 --- a/klineal.h +++ b/klineal.h @@ -92,6 +92,7 @@ private: KActionCollection *mActionCollection; int mOpacity; QToolButton *mBtnRotateLeft, *mBtnRotateRight; + QToolButton *mCloseButton; public slots: void setOrientation( int ); @@ -105,7 +106,7 @@ public slots: void hideLabel(); void showLabel(); void adjustLabel(); - void adjustRotateButtons(); + void adjustButtons(); void setShortLength(); void setMediumLength(); void setTallLength(); diff --git a/kruler.kcfg b/kruler.kcfg index 46a6f02..12eda07 100644 --- a/kruler.kcfg +++ b/kruler.kcfg @@ -42,7 +42,11 @@ 255 - + + false + + + false -- GitLab