KnowIt – tool for managing notes
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.

knowittree.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /***************************************************************************
  2. knowittree.cpp - description
  3. -------------------
  4. begin : sob gru 20 2003
  5. copyright : (C) 2003 by Micha³ Rudolf
  6. email : mrudolf@tdewebdev.org
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include <klocale.h>
  17. #include <tqevent.h>
  18. #include <tqdragobject.h>
  19. #include <tqheader.h>
  20. #include <tqwhatsthis.h>
  21. #include "knowittree.h"
  22. KnowitTree::KnowitTree(TQWidget* parent, const char* name)
  23. : TDEListView(parent, name)
  24. {
  25. setMinimumSize(150, 150);
  26. addColumn(i18n("Notes"));
  27. setRootIsDecorated(true);
  28. setItemsRenameable(true);
  29. setDragEnabled(true);
  30. setAcceptDrops(true);
  31. setFullWidth(true);
  32. setSorting(-1);
  33. setDragAutoScroll(true);
  34. prevItem = 0;
  35. TQWhatsThis::add(this, i18n("<h2>Notes hierarchy</h2>"
  36. "Here you can browse notes tree. "
  37. "You can also add notes using right-click menu, or reorganize them using "
  38. "drag and drop."));
  39. }
  40. void KnowitTree::takeNode(TQListViewItem* item)
  41. {
  42. if (item->parent())
  43. item->parent()->takeItem(item);
  44. else
  45. takeItem(item);
  46. }
  47. void KnowitTree::insertNode(TQListViewItem* parent, TQListViewItem* item, TQListViewItem* after)
  48. {
  49. if (parent)
  50. parent->insertItem(item);
  51. else
  52. insertItem(item);
  53. if (after)
  54. item->moveItem(after);
  55. }
  56. void KnowitTree::contentsDragMoveEvent(TQDragMoveEvent* event)
  57. {
  58. TQListViewItem* item = itemAt(event->pos());
  59. /* check if on root decoration */
  60. if (!item || event->pos().x() > header()->cellPos(header()->mapToActual(0)) +
  61. treeStepSize() * (item->depth() + 1) + itemMargin() ||
  62. event->pos().x() < header()->cellPos(header()->mapToActual(0)))
  63. return;
  64. if (item && item->childCount() && !item->isOpen())
  65. item->setOpen(true);
  66. }
  67. void KnowitTree::slotCollapseAll()
  68. {
  69. TQListViewItem* it = firstChild();
  70. while(it) {
  71. it->setOpen(false);
  72. it = it->nextSibling();
  73. }
  74. }
  75. void KnowitTree::slotCollapse()
  76. {
  77. if (currentItem())
  78. currentItem()->setOpen(false);
  79. }
  80. void KnowitTree::slotExpandAll()
  81. {
  82. TQListViewItem* it = firstChild();
  83. while(it) {
  84. it->setOpen(true);
  85. it = it->nextSibling();
  86. }
  87. }
  88. void KnowitTree::slotExpand()
  89. {
  90. if (currentItem())
  91. currentItem()->setOpen(true);
  92. }
  93. void KnowitTree::slotItemUp()
  94. {
  95. if (currentItem())
  96. setCurrentItem(currentItem()->itemAbove());
  97. }
  98. void KnowitTree::slotItemDown()
  99. {
  100. if (currentItem())
  101. setCurrentItem(currentItem()->itemBelow());
  102. }
  103. void KnowitTree::slotItemBegin()
  104. {
  105. setCurrentItem(firstChild());
  106. }
  107. void KnowitTree::slotItemEnd()
  108. {
  109. TQListViewItem* elt = firstChild();
  110. if (elt)
  111. while (elt->itemBelow())
  112. elt = elt->itemBelow();
  113. setCurrentItem(elt);
  114. }
  115. void KnowitTree::slotItemLeft()
  116. {
  117. if (currentItem())
  118. setCurrentItem(currentItem()->parent());
  119. }
  120. void KnowitTree::slotItemRight()
  121. {
  122. if (currentItem())
  123. setCurrentItem(currentItem()->firstChild());
  124. }