AbaKus – a complex calculator
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.

150 lines
4.1 KiB

  1. #ifndef ABAKUS_LISTVIEW_H
  2. #define ABAKUS_LISTVIEW_H
  3. /*
  4. * abakuslistview.h - part of abakus
  5. * Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <klistview.h>
  22. #include "numerictypes.h"
  23. class KPopupMenu;
  24. class ListView : public KListView
  25. {
  26. Q_OBJECT
  27. TQ_OBJECT
  28. public:
  29. ListView(TQWidget *parent, const char *name = 0);
  30. protected:
  31. virtual TQDragObject *dragObject();
  32. /**
  33. * Used to enable fancy popup handling support in subclasses. Subclasses
  34. * also need to reimplement a few functions if they want to use this.
  35. *
  36. * This should be called in the subclass's constructor.
  37. */
  38. void enablePopupHandler(bool enable);
  39. /**
  40. * If using the popup menu handling, the subclass needs to return a
  41. * translated string of the form "Remove selected <itemtype>".
  42. */
  43. virtual TQString removeItemString() const;
  44. /**
  45. * If using the popup menu handling, the subclass needs to return a
  46. * translated string of the form "Remove all <itemtype>s." I recommend
  47. * also appending a " (%n <itemtype>s), which you can use the @p count
  48. * parameter for.
  49. */
  50. virtual TQString removeAllItemsString(unsigned count) const;
  51. protected slots:
  52. /**
  53. * If using the popup menu handing, the subclass needs to reimplement this
  54. * function to remove the selected item, which is passed in as a
  55. * parameter.
  56. */
  57. virtual void removeSelectedItem(TQListViewItem *item);
  58. /**
  59. * If using the popup menu handling, the subclass needs to reimplement this
  60. * function to remove all items.
  61. */
  62. virtual void removeAllItems();
  63. /**
  64. * If using the popup menu handling, this function may be called to
  65. * determine whether the selected item given by @p item is removable.
  66. */
  67. virtual bool isItemRemovable(TQListViewItem *item) const;
  68. private slots:
  69. void rightClicked(TQListViewItem *item, const TQPoint &pt);
  70. void removeSelected();
  71. private:
  72. KPopupMenu *m_menu;
  73. bool m_usePopup;
  74. int m_removeSingleId;
  75. int m_removeAllId;
  76. };
  77. class ValueListViewItem : public KListViewItem
  78. {
  79. public:
  80. ValueListViewItem (TQListView *listView, const TQString &name, const Abakus::number_t &value);
  81. // Will cause the list item to rethink the text.
  82. void valueChanged();
  83. void valueChanged(const Abakus::number_t &newValue);
  84. Abakus::number_t itemValue() const;
  85. private:
  86. Abakus::number_t m_value;
  87. };
  88. /**
  89. * Subclass used for the list of variables.
  90. */
  91. class VariableListView : public ListView
  92. {
  93. Q_OBJECT
  94. TQ_OBJECT
  95. public:
  96. VariableListView(TQWidget *parent, const char *name = 0);
  97. protected:
  98. virtual TQString removeItemString() const;
  99. virtual TQString removeAllItemsString(unsigned count) const;
  100. virtual bool isItemRemovable(TQListViewItem *item) const;
  101. protected slots:
  102. virtual void removeSelectedItem(TQListViewItem *item);
  103. virtual void removeAllItems();
  104. };
  105. /**
  106. * Subclass used for the list of functions.
  107. */
  108. class FunctionListView : public ListView
  109. {
  110. Q_OBJECT
  111. TQ_OBJECT
  112. public:
  113. FunctionListView(TQWidget *parent, const char *name = 0);
  114. protected:
  115. virtual TQString removeItemString() const;
  116. virtual TQString removeAllItemsString(unsigned count) const;
  117. virtual bool isItemRemovable(TQListViewItem *item) const;
  118. protected slots:
  119. virtual void removeSelectedItem(TQListViewItem *item);
  120. virtual void removeAllItems();
  121. };
  122. #endif