PanelList.C 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
  3. *
  4. * See the LICENSE file for terms of use.
  5. */
  6. #include <Wt/WPanel>
  7. #include "PanelList.h"
  8. using namespace Wt;
  9. PanelList::PanelList(WContainerWidget *parent)
  10. : WContainerWidget(parent)
  11. { }
  12. WPanel *PanelList::addWidget(const WString& text, WWidget *w)
  13. {
  14. WPanel *p = new WPanel();
  15. p->setTitle(text);
  16. p->setCentralWidget(w);
  17. addPanel(p);
  18. return p;
  19. }
  20. void PanelList::addPanel(WPanel *panel)
  21. {
  22. panel->setCollapsible(true);
  23. panel->collapse();
  24. panel->expandedSS().connect(this, &PanelList::onExpand);
  25. WContainerWidget::addWidget(panel);
  26. }
  27. void PanelList::onExpand(bool notUndo)
  28. {
  29. WPanel *panel = dynamic_cast<WPanel *>(sender());
  30. if (notUndo) {
  31. wasExpanded_ = -1;
  32. for (unsigned i = 0; i < children().size(); ++i) {
  33. WPanel *p = dynamic_cast<WPanel *>(children()[i]);
  34. if (p != panel) {
  35. if (!p->isCollapsed())
  36. wasExpanded_ = i;
  37. p->collapse();
  38. }
  39. }
  40. } else {
  41. if (wasExpanded_ != -1) {
  42. WPanel *p = dynamic_cast<WPanel *>(children()[wasExpanded_]);
  43. p->expand();
  44. }
  45. }
  46. }