PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/guitone-1.0rc5/src/view/widgets/ToolBox.cpp

#
C++ | 81 lines | 49 code | 13 blank | 19 comment | 8 complexity | 73003c5751d26d308d35d3a3174c7d4a MD5 | raw file
Possible License(s): GPL-3.0
  1. /***************************************************************************
  2. * Copyright (C) 2009 by Thomas Keller *
  3. * me@thomaskeller.biz *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation, either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  17. ***************************************************************************/
  18. #include "ToolBox.h"
  19. #include "vocab.h"
  20. ToolBox::ToolBox(QWidget * parent) : QToolBox(parent)
  21. {
  22. connect(
  23. this, SIGNAL(currentChanged(int)),
  24. this, SLOT(currentIndexChanged(int))
  25. );
  26. currentIndexChanged(currentIndex());
  27. }
  28. ToolBox::~ToolBox() {}
  29. void ToolBox::setItemText(int index, const QString & text)
  30. {
  31. QString txt(text);
  32. if (txt.indexOf(QChar(9656)) != 0 &&
  33. txt.indexOf(QChar(9662)) != 0)
  34. {
  35. txt.prepend(" ").prepend(QChar(9656));
  36. }
  37. QToolBox::setItemText(index, txt);
  38. }
  39. void ToolBox::itemInserted(int index)
  40. {
  41. setItemText(index, itemText(index));
  42. }
  43. void ToolBox::setCurrentIndex(int index)
  44. {
  45. QToolBox::setCurrentIndex(index);
  46. currentIndexChanged(index);
  47. }
  48. void ToolBox::currentIndexChanged(int idx)
  49. {
  50. for (int i=0; i<count(); i++)
  51. {
  52. QString text = itemText(i);
  53. // the > arrow is present
  54. if (text.indexOf(QChar(9656)) == 0)
  55. continue;
  56. // the v arrow is present
  57. if (text.indexOf(QChar(9662)) == 0)
  58. {
  59. text = text.mid(1);
  60. }
  61. text.prepend(QChar(9656));
  62. QToolBox::setItemText(i, text);
  63. }
  64. QString text = itemText(idx);
  65. text = text.mid(1);
  66. text.prepend(QChar(9662));
  67. QToolBox::setItemText(idx, text);
  68. }