TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

112 lines
3.1 KiB

  1. /*******************************************************************
  2. KNotes -- Notes for the KDE project
  3. Copyright (c) 2002-2004, The KNotes Developers
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. *******************************************************************/
  16. #include <tqstyle.h>
  17. #include <tqpainter.h>
  18. #include <tqiconset.h>
  19. #include <tqsizepolicy.h>
  20. #include <tdeglobal.h>
  21. #include <kicontheme.h>
  22. #include <kiconloader.h>
  23. #include "knotebutton.h"
  24. KNoteButton::KNoteButton( const TQString& icon, TQWidget *parent, const char *name )
  25. : TQPushButton( parent, name )
  26. {
  27. setFocusPolicy( TQ_NoFocus );
  28. setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
  29. m_flat = true;
  30. if ( !icon.isEmpty() )
  31. setIconSet( TDEGlobal::iconLoader()->loadIconSet( icon, TDEIcon::Small, 10 ) );
  32. }
  33. KNoteButton::~KNoteButton()
  34. {
  35. }
  36. void KNoteButton::enterEvent( TQEvent * )
  37. {
  38. m_flat = false;
  39. repaint( false );
  40. }
  41. void KNoteButton::leaveEvent( TQEvent * )
  42. {
  43. m_flat = true;
  44. repaint();
  45. }
  46. TQSize KNoteButton::sizeHint() const
  47. {
  48. return TQSize( TQPushButton::sizeHint().height(), TQPushButton::sizeHint().height() );
  49. }
  50. void KNoteButton::drawButton( TQPainter* p )
  51. {
  52. TQStyle::SFlags flags = TQStyle::Style_Default;
  53. if ( isEnabled() )
  54. flags |= TQStyle::Style_Enabled;
  55. if ( isDown() )
  56. flags |= TQStyle::Style_Down;
  57. if ( isOn() )
  58. flags |= TQStyle::Style_On;
  59. if ( !isFlat() && !isDown() )
  60. flags |= TQStyle::Style_Raised;
  61. if ( !m_flat )
  62. flags |= TQStyle::Style_MouseOver;
  63. style().tqdrawPrimitive( TQStyle::PE_ButtonTool, p, rect(), colorGroup(), flags );
  64. drawButtonLabel( p );
  65. }
  66. void KNoteButton::drawButtonLabel( TQPainter* p )
  67. {
  68. if ( iconSet() && !iconSet()->isNull() )
  69. {
  70. TQIconSet::Mode mode = TQIconSet::Disabled;
  71. TQIconSet::State state = TQIconSet::Off;
  72. if ( isEnabled() )
  73. mode = hasFocus() ? TQIconSet::Active : TQIconSet::Normal;
  74. if ( isToggleButton() && isOn() )
  75. state = TQIconSet::On;
  76. TQPixmap pix = iconSet()->pixmap( TQIconSet::Small, mode, state );
  77. int dx = ( width() - pix.width() ) / 2;
  78. int dy = ( height() - pix.height() ) / 2;
  79. // Shift button contents if pushed.
  80. if ( isOn() || isDown() )
  81. {
  82. dx += style().pixelMetric( TQStyle::PM_ButtonShiftHorizontal, this );
  83. dy += style().pixelMetric( TQStyle::PM_ButtonShiftVertical, this );
  84. }
  85. p->drawPixmap( dx, dy, pix );
  86. }
  87. }