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.

151 lines
4.1KB

  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 TDEPopupMenu;
  24. class ListView : public TDEListView
  25. {
  26. Q_OBJECT
  27. public:
  28. ListView(TQWidget *parent, const char *name = 0);
  29. protected:
  30. virtual TQDragObject *dragObject();
  31. /**
  32. * Used to enable fancy popup handling support in subclasses. Subclasses
  33. * also need to reimplement a few functions if they want to use this.
  34. *
  35. * This should be called in the subclass's constructor.
  36. */
  37. void enablePopupHandler(bool enable);
  38. /**
  39. * If using the popup menu handling, the subclass needs to return a
  40. * translated string of the form "Remove selected <itemtype>".
  41. */
  42. virtual TQString removeItemString() const;
  43. /**
  44. * If using the popup menu handling, the subclass needs to return a
  45. * translated string of the form "Remove all <itemtype>s." I recommend
  46. * also appending a " (%n <itemtype>s), which you can use the @p count
  47. * parameter for.
  48. */
  49. virtual TQString removeAllItemsString(unsigned count) const;
  50. protected slots:
  51. /**
  52. * If using the popup menu handing, the subclass needs to reimplement this
  53. * function to remove the selected item, which is passed in as a
  54. * parameter.
  55. */
  56. virtual void removeSelectedItem(TQListViewItem *item);
  57. /**
  58. * If using the popup menu handling, the subclass needs to reimplement this
  59. * function to remove all items.
  60. */
  61. virtual void removeAllItems();
  62. /**
  63. * If using the popup menu handling, this function may be called to
  64. * determine whether the selected item given by @p item is removable.
  65. */
  66. virtual bool isItemRemovable(TQListViewItem *item) const;
  67. private slots:
  68. void rightClicked(TQListViewItem *item, const TQPoint &pt);
  69. void removeSelected();
  70. private:
  71. TDEPopupMenu *m_menu;
  72. bool m_usePopup;
  73. int m_removeSingleId;
  74. int m_removeAllId;
  75. };
  76. class ValueListViewItem : public TDEListViewItem
  77. {
  78. public:
  79. ValueListViewItem (TQListView *listView, const TQString &name, const Abakus::number_t &value);
  80. // Will cause the list item to rethink the text.
  81. void valueChanged();
  82. void valueChanged(const Abakus::number_t &newValue);
  83. Abakus::number_t itemValue() const;
  84. private:
  85. Abakus::number_t m_value;
  86. };
  87. /**
  88. * Subclass used for the list of variables.
  89. */
  90. class VariableListView : public ListView
  91. {
  92. Q_OBJECT
  93. public:
  94. VariableListView(TQWidget *parent, const char *name = 0);
  95. protected:
  96. virtual TQString removeItemString() const;
  97. virtual TQString removeAllItemsString(unsigned count) const;
  98. virtual bool isItemRemovable(TQListViewItem *item) const;
  99. protected slots:
  100. virtual void removeSelectedItem(TQListViewItem *item);
  101. virtual void removeAllItems();
  102. };
  103. /**
  104. * Subclass used for the list of functions.
  105. */
  106. class FunctionListView : public ListView
  107. {
  108. Q_OBJECT
  109. public:
  110. FunctionListView(TQWidget *parent, const char *name = 0);
  111. protected:
  112. virtual TQString removeItemString() const;
  113. virtual TQString removeAllItemsString(unsigned count) const;
  114. virtual bool isItemRemovable(TQListViewItem *item) const;
  115. protected slots:
  116. virtual void removeSelectedItem(TQListViewItem *item);
  117. virtual void removeAllItems();
  118. };
  119. #endif