bool ContainerWidget::raiseSectionContent(const SectionContent::RefPtr& sc) { // Search SC in sections for (int i = 0; i < _sections.count(); ++i) { SectionWidget* sw = _sections.at(i); int index = sw->indexOfContent(sc); if (index < 0) continue; sw->setCurrentIndex(index); return true; } // Search SC in floatings for (int i = 0; i < _floatings.size(); ++i) { FloatingWidget* fw = _floatings.at(i); if (fw->content()->uid() != sc->uid()) continue; fw->setVisible(true); fw->raise(); return true; } // Search SC in hidden if (_hiddenSectionContents.contains(sc->uid())) return showSectionContent(sc); qFatal("Unable to hide SectionContent, don't know this one 8-/"); return false; }
bool ContainerWidget::hideSectionContent(const SectionContent::RefPtr& sc) { // Search SC in floatings // We can simply hide floatings, nothing else required. for (int i = 0; i < _floatings.count(); ++i) { const bool found = _floatings.at(i)->content()->uid() == sc->uid(); if (!found) continue; _floatings.at(i)->setVisible(false); emit sectionContentVisibilityChanged(sc, false); return true; } // Search SC in sections // It's required to remove the SC from SW completely and hold it in a // separate list as long as a "showSectionContent" gets called for the SC again. // In case that the SW does not have any other SCs, we need to delete it. for (int i = 0; i < _sections.count(); ++i) { SectionWidget* sw = _sections.at(i); const bool found = sw->indexOfContent(sc) >= 0; if (!found) continue; HiddenSectionItem hsi; hsi.preferredSectionId = sw->uid(); hsi.preferredSectionIndex = sw->indexOfContent(sc); if (!sw->takeContent(sc->uid(), hsi.data)) return false; hsi.data.titleWidget->setVisible(false); hsi.data.contentWidget->setVisible(false); _hiddenSectionContents.insert(sc->uid(), hsi); if (sw->contents().isEmpty()) { delete sw; sw = NULL; deleteEmptySplitter(this); } emit sectionContentVisibilityChanged(sc, false); return true; } // Search SC in hidden elements // The content may already be hidden if (_hiddenSectionContents.contains(sc->uid())) return true; qFatal("Unable to hide SectionContent, don't know this one 8-/"); return false; }
bool ContainerWidget::showSectionContent(const SectionContent::RefPtr& sc) { // Search SC in floatings for (int i = 0; i < _floatings.count(); ++i) { FloatingWidget* fw = _floatings.at(i); const bool found = fw->content()->uid() == sc->uid(); if (!found) continue; fw->setVisible(true); fw->_titleWidget->setVisible(true); fw->_contentWidget->setVisible(true); emit sectionContentVisibilityChanged(sc, true); return true; } // Search SC in hidden sections // Try to show them in the last position, otherwise simply append // it to the first section (or create a new section?) if (_hiddenSectionContents.contains(sc->uid())) { const HiddenSectionItem hsi = _hiddenSectionContents.take(sc->uid()); hsi.data.titleWidget->setVisible(true); hsi.data.contentWidget->setVisible(true); SectionWidget* sw = NULL; if (hsi.preferredSectionId > 0 && (sw = SWLookupMapById(this).value(hsi.preferredSectionId)) != NULL) { sw->addContent(hsi.data, true); emit sectionContentVisibilityChanged(sc, true); return true; } else if (_sections.size() > 0 && (sw = _sections.first()) != NULL) { sw->addContent(hsi.data, true); emit sectionContentVisibilityChanged(sc, true); return true; } else { sw = newSectionWidget(); addSection(sw); sw->addContent(hsi.data, true); emit sectionContentVisibilityChanged(sc, true); return true; } } // Already visible? // TODO qWarning("Unable to show SectionContent, don't know where 8-/ (already visible?)"); return false; }
bool ContainerWidget::removeSectionContent(const SectionContent::RefPtr& sc) { // Hide the content. // The hideSectionContent() automatically deletes no longer required SectionWidget objects. if (!hideSectionContent(sc)) return false; // Begin of ugly work arround. // TODO The hideSectionContent() method should take care of deleting FloatingWidgets and SectionWidgets, // but only cares about SectionWidgets right now. So we need to check whether it was a FloatingWidget // and delete it. bool found = false; for (int i = 0; i < _floatings.count(); ++i) { FloatingWidget* fw = _floatings.at(i); InternalContentData data; if (!(found = fw->takeContent(data))) continue; _floatings.removeAll(fw); delete fw; delete data.titleWidget; delete data.contentWidget; break; } // End of ugly work arround. // Get from hidden contents and delete associated internal stuff. if (!_hiddenSectionContents.contains(sc->uid())) { qFatal("Something went wrong... The content should have been there :-/"); return false; } // Delete internal objects. HiddenSectionItem hsi = _hiddenSectionContents.take(sc->uid()); delete hsi.data.titleWidget; delete hsi.data.contentWidget; // Hide the custom widgets of SectionContent. // ... should we? ... return true; }