KBFX – an alternative to T-Menu
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.

183 lines
3.7KB

  1. /*
  2. * Copyright (C) 2006
  3. * Siraj Razick <siraj@kdemail.net>
  4. * PhobosK <phobosk@mail.kbfx.net>
  5. * see Also AUTHORS
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Library General Public License version 2 as
  9. * published by the Free Software Foundation
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this program; if not, write to the
  18. * Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #include "kbfxplasmaindexitem.h"
  22. #include <kdesktopfile.h>
  23. #include <tdeapplication.h>
  24. #include <kbfxconfig.h>
  25. KbfxPlasmaIndexItem::KbfxPlasmaIndexItem ( TQCanvasPixmapArray * a, TQCanvas * canvas ) :KbfxPlasmaCanvasAbstractItem ( a,canvas )
  26. {
  27. //this->setItemMode (1);
  28. setAnimated ( false );
  29. setCurrent ( false );
  30. m_isSelected = false;
  31. TQPixmap * _img = this->image ( 0 );
  32. m_height =_img->height();
  33. m_width= _img->width();
  34. }
  35. KbfxPlasmaIndexItem::~KbfxPlasmaIndexItem()
  36. {}
  37. void
  38. KbfxPlasmaIndexItem::setIcon ( TQString str )
  39. {
  40. TDEIconLoader *iconload = TDEGlobal::iconLoader ();
  41. m_iconPath = iconload->iconPath ( str, TDEIcon::Desktop, false );
  42. m_icon.load ( m_iconPath );
  43. }
  44. void
  45. KbfxPlasmaIndexItem::setText ( TQString text )
  46. {
  47. m_text = text;
  48. }
  49. void
  50. KbfxPlasmaIndexItem::setSelected ( bool stat )
  51. {
  52. m_isSelected = stat;
  53. }
  54. bool
  55. KbfxPlasmaIndexItem::selected()
  56. {
  57. return m_isSelected;
  58. }
  59. void
  60. KbfxPlasmaIndexItem::drawContent ( TQPainter * pe )
  61. {
  62. if ( this->isCurrent() || m_isSelected )
  63. {
  64. this->setFrame ( 1 );
  65. }
  66. else
  67. {
  68. this->setFrame ( 0 );
  69. }
  70. TQCanvasPixmap *cp = this->image ( this->frame () );
  71. m_height = cp->height();
  72. m_width = cp->width();
  73. pe->drawPixmap ( this->boundingRect (), *cp );
  74. TQRect r ( ( int ) x(), ( int ) y(), m_width, m_height );
  75. TQRect textRect ( m_height+1, ( int ) y(), m_width,m_height );
  76. TQFont * _font_plugin = new TQFont ( ConfigInit().m_pluginNameFont );
  77. TQFont * _font_index = new TQFont ( ConfigInit().m_fontIndexFont );
  78. if ( this->type() != KbfxPlasmaIndexItem::SEPARATOR )
  79. {
  80. pe->setFont ( *_font_index );
  81. pe->setPen ( ConfigInit().m_fontIndexColor );
  82. }
  83. else
  84. {
  85. pe->setFont ( *_font_plugin );
  86. pe->setPen ( ConfigInit().m_pluginNameColor);
  87. }
  88. pe->drawText ( textRect, TQt::AlignVCenter | TQt::AlignLeft ,TQString ( m_text ), -1, &r );
  89. pe->drawPixmap ( TQRect ( ( int ) x() +5 , ( int ) y() +6,m_height-12,m_height-12 ),m_icon );
  90. delete _font_plugin;
  91. delete _font_index;
  92. }
  93. int
  94. KbfxPlasmaIndexItem::height()
  95. {
  96. return m_height;
  97. }
  98. void
  99. KbfxPlasmaIndexItem::setId ( int id )
  100. {
  101. m_id = id;
  102. }
  103. void
  104. KbfxPlasmaIndexItem::draw ( TQPainter & p )
  105. {
  106. drawContent ( &p );
  107. }
  108. void
  109. KbfxPlasmaIndexItem::setLabelText ( TQString str )
  110. {
  111. TQFont * _font = new TQFont(ConfigInit().m_fontIndexFont);
  112. TQFontMetrics fm ( *_font );
  113. int _commentWidth = fm.width ( str+"..." );
  114. int _strLen = str.length();
  115. int _margin = height();;
  116. if ( _commentWidth > ( m_width -_margin ) )
  117. {
  118. for ( int i = 0; i < _strLen /*&& ( fm.width(str+"...") < width()-40 )*/ ;i++ )
  119. {
  120. str.truncate ( str.length()-2 );
  121. if ( fm.width ( str+"..." ) < m_width-_margin )
  122. break;
  123. }
  124. str+="...";
  125. }
  126. setText ( str );
  127. }
  128. TQString
  129. KbfxPlasmaIndexItem::belongsTo()
  130. {
  131. return m_parent;
  132. }
  133. void
  134. KbfxPlasmaIndexItem::setBelongsTo ( TQString parent )
  135. {
  136. m_parent = parent;
  137. }
  138. void KbfxPlasmaIndexItem::mousePressEvent ( TQMouseEvent * e )
  139. {
  140. e = e;
  141. }
  142. #include "kbfxplasmaindexitem.moc"