QToolBar* TabManager::GetToolBar (int position) const { QWidget *widget = TabWidget_->Widget (position); ITabWidget *itw = qobject_cast<ITabWidget*> (widget); if (itw) { try { return itw->GetToolBar (); } catch (const std::exception& e) { qWarning () << Q_FUNC_INFO << "failed to ITabWidget::GetToolBar" << e.what () << widget; return 0; } catch (...) { qWarning () << Q_FUNC_INFO << "failed to ITabWidget::GetToolBar" << widget; return 0; } } else return 0; }
void TabManager::remove (QWidget *contents) { if (!TabWidget_->WidgetCount ()) return; const int tabNumber = FindTabForWidget (contents); if (tabNumber == -1) return; TabWidget_->RemoveTab (tabNumber); OriginalTabNames_.removeAt (tabNumber); InvalidateName (); ITabWidget *itw = qobject_cast<ITabWidget*> (contents); if (!itw) { qWarning () << Q_FUNC_INFO << contents << "doesn't implement ITabWidget"; return; } const auto& features = itw->GetTabClassInfo ().Features_; if (features & TFSingle) Core::Instance ().GetNewTabMenuManager ()->SingleRemoved (itw); if (features & TFByDefault) Core::Instance ().GetNewTabMenuManager ()->ToggleHide (itw, true); }
void TabManager::remove (int index) { if (!TabWidget_->WidgetCount ()) return; QWidget *widget = TabWidget_->Widget (index); ITabWidget *itw = qobject_cast<ITabWidget*> (widget); if (!itw) { qWarning () << Q_FUNC_INFO << widget << "doesn't implement ITabWidget"; return; } try { itw->Remove (); } catch (const std::exception& e) { qWarning () << Q_FUNC_INFO << "failed to ITabWidget::Remove" << e.what () << TabWidget_->Widget (index); } catch (...) { qWarning () << Q_FUNC_INFO << "failed to ITabWidget::Remove" << TabWidget_->Widget (index); } }
void mdr::Node:: setParent(Node* parent, int index) { // WARN: мы не можем использовать (un)refLeaf так как будет рекурсия // Если родитель изменился if(m_parent != parent) { // Удаляем у старого родителя if(m_parent) { m_parent->m_leaves.removeOne(this); // Если у старого родителя список детей пуст, то удаляем у его виджета // кнопку свернуть/развернуть if(m_parent->m_widget && m_parent->m_leaves.empty()) { ITabWidget* widget = m_parent->m_widget; widget->toggleExpandCollapseButton(false); } } // Добавляем к новому родителю if(parent) { if(index == -1) parent->m_leaves.push_back(this); else parent->m_leaves.insert(index, this); // Добавляем виджету нового родителя кнопку свернуть/развернуть if(parent->m_widget) { ITabWidget* widget = parent->m_widget; widget->toggleExpandCollapseButton(true); } } m_parent = parent; } // Если родителя не было и не будет else if(m_parent == nullptr && parent == nullptr) {} // Если родитель не изменился, но он есть else { QList<Node*>& parent_leaves = m_parent->m_leaves; int cur_idx = parent_leaves.indexOf(this); // Не изменился ни родитель, ни индекс if(cur_idx == index) return; // Если index == -1, то это значит, что перемещаем в конец if(index == -1) parent_leaves.move(cur_idx, parent_leaves.size() - 1); else parent_leaves.move(cur_idx, index); } }
void TabWidget::handleTabBarContextMenu (const QPoint& pos) { QMenu *menu = new QMenu ("", tabBar ()); int tabIndex = tabBar ()->tabAt (pos); if (tabIndex != -1 && XmlSettingsManager::Instance ()-> property ("ShowPluginMenuInTabs").toBool ()) { bool asSub = XmlSettingsManager::Instance ()-> property ("ShowPluginMenuInTabsAsSubmenu").toBool (); ITabWidget *imtw = qobject_cast<ITabWidget*> (widget (tabIndex)); if (imtw) { QList<QAction*> tabActions = imtw->GetTabBarContextMenuActions (); QMenu *subMenu = new QMenu (tabText (tabIndex), menu); Q_FOREACH (QAction *act, tabActions) (asSub ? subMenu : menu)->addAction (act); if (asSub) menu->addMenu (subMenu); if (tabActions.size ()) menu->addSeparator (); } } Q_FOREACH (QAction *act, TabBarActions_) { if (!act) { qWarning () << Q_FUNC_INFO << "detected null pointer"; continue; } act->setProperty ("_Core/ClickPos", tabBar ()->mapToGlobal (pos)); menu->addAction (act); } menu->exec (tabBar ()->mapToGlobal (pos)); Q_FOREACH (QAction *act, TabBarActions_) { if (!act) { qWarning () << Q_FUNC_INFO << "detected null pointer"; continue; } act->setProperty ("_Core/ClickPos", QVariant ()); } delete menu; }
void SBWidget::RemoveCurTabAction (QAction *act, QWidget *w) { ITabWidget *tw = qobject_cast<ITabWidget*> (w); const auto& tabClass = tw->GetTabClassInfo (); TabClass2Action_ [tabClass.TabClass_].removeAll (act); TabAction2Tab_.remove (act); delete CurTab2Button_.take (act); if (TabClass2Action_ [tabClass.TabClass_].size () < FoldThreshold) UnfoldTabClass (tabClass); }
void SBWidget::AddCurTabAction (QAction *act, QWidget *w) { ITabWidget *tw = qobject_cast<ITabWidget*> (w); const auto& tabClass = tw->GetTabClassInfo (); TabClass2Action_ [tabClass.TabClass_] << act; TabAction2Tab_ [act] = w; if (TabClass2Action_ [tabClass.TabClass_].size () >= FoldThreshold) FoldTabClass (tabClass, act); else { auto but = AddTabButton (act, Ui_.TabsLay_); CurTab2Button_ [act] = but; but->setProperty ("Sidebar/TabPage", QVariant::fromValue<QWidget*> (w)); but->setContextMenuPolicy (Qt::CustomContextMenu); connect (but, SIGNAL (customContextMenuRequested (QPoint)), this, SLOT (handleTabContextMenu (QPoint))); } }
void TabManager::add (const QString& name, QWidget *contents, QIcon icon) { if (icon.isNull ()) { ITabWidget *itw = qobject_cast<ITabWidget*> (contents); if (!itw) { qWarning () << Q_FUNC_INFO << contents << "doesn't implement ITabWidget"; return; } icon = itw->GetTabClassInfo ().Icon_; if (itw->GetTabClassInfo ().Features_ & TFSingle) Core::Instance ().GetNewTabMenuManager ()->HideAction (itw); } if (XmlSettingsManager::Instance ()-> property ("OpenTabNext").toBool ()) { const int current = TabWidget_->CurrentIndex (); OriginalTabNames_.insert (current + 1, name); TabWidget_->InsertTab (current + 1, contents, icon, name); } else { OriginalTabNames_ << name; TabWidget_->AddTab (contents, icon, name); } InvalidateName (); }