bool eventFilter(QObject* obj, QEvent* event) override { // check input if (event->type() != QEvent::MouseButtonDblClick) return false; QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); if (mouseEvent->button() != Qt::LeftButton) return false; QSplitterHandle* splitterHandle = qobject_cast<QSplitterHandle*>(obj); if (!splitterHandle) return false; QSplitter* splitter = splitterHandle->splitter(); if (!splitter || splitter->count() < 2) return false; // change splitter sizes to make description panel occupy ideal height QWidget* bottomWidget = splitter->widget(1); QList<int> sizes = splitter->sizes(); if (sizes.size() != 2) return false; sizes[0] += sizes[1]; sizes[1] = bottomWidget->heightForWidth(bottomWidget->size().width()); sizes[0] -= qMax(sizes[1], 0); splitter->setSizes(sizes); return true; }
ScoreView* ScoreTab::view(int n) const { QSplitter* s = viewSplitter(n); if (s) return static_cast<ScoreView*>(s->widget(0)); return 0; }
QSplitter* ScoreTab::viewSplitter(int n) const { TabScoreView* tsv = static_cast<TabScoreView*>(tab->tabData(n).value<void*>()); if (tsv == 0) { // qDebug("ScoreTab::viewSplitter %d is zero", n); return 0; } Score* score = tsv->score; if (tsv->part) { QList<Excerpt*>& excerpts = score->excerpts(); if (!excerpts.isEmpty() && ((tsv->part - 1) < excerpts.size())) score = excerpts.at(tsv->part - 1)->partScore(); } int nn = stack->count(); for (int i = 0; i < nn; ++i) { QSplitter* sp = static_cast<QSplitter*>(stack->widget(i)); if (sp->count() == 0) return 0; ScoreView* v = static_cast<ScoreView*>(sp->widget(0)); if (v->score() == score) return sp; } return 0; }
DockTabMotherWidget::TabWidgetArea DockTabMotherWidget::dropAreaAt(const QPoint &pos, Direction dir) { int countSplitter = _splitterLists[dir].size(); for (int indexSplitter = 0; indexSplitter < countSplitter; ++indexSplitter) { QSplitter *splitter = _splitterLists[dir].at(indexSplitter); int countTabWidget = splitter->count(); for (int indexTabWidget = 0; indexTabWidget < countTabWidget; ++indexTabWidget) { InsertionDirection insertionDir; if (getInsertionDirection(pos, splitter->widget(indexTabWidget), dir, insertionDir)) { switch (insertionDir) { case NextSplitter: return TabWidgetArea(dir, indexSplitter + 1, -1); case PreviousSplitter: return TabWidgetArea(dir, indexSplitter, -1); case Next: return TabWidgetArea(dir, indexSplitter, indexTabWidget + 1); case Previous: return TabWidgetArea(dir, indexSplitter, indexTabWidget); default: break; } } } } return TabWidgetArea(); }
EditorView *EditorView::findNextView() { SplitterOrView *current = parentSplitterOrView(); QTC_ASSERT(current, return this); SplitterOrView *parent = current->findParentSplitter(); while (parent) { QSplitter *splitter = parent->splitter(); QTC_ASSERT(splitter, return this); QTC_ASSERT(splitter->count() == 2, return this); // is current the first child? then the next view is the first one in current's sibling if (splitter->widget(0) == current) { SplitterOrView *second = qobject_cast<SplitterOrView *>(splitter->widget(1)); QTC_ASSERT(second, return this); return second->findFirstView(); } // otherwise go up the hierarchy current = parent; parent = current->findParentSplitter(); }
QStackedWidget* SplitGrid2::getCellImp(int row, int col) const { if( col < 0 || col >= count() ) return 0; QSplitter* s = static_cast<QSplitter*>( QSplitter::widget( col ) ); if( row < 0 || row >= s->count() ) return 0; else return static_cast<QStackedWidget*>( s->widget( row ) ); }
bool HistogramWindowImp::toXml(XMLWriter* pXml) const { if ((pXml == NULL) || (DockWindowImp::toXml(pXml) == false)) { return false; } if (mpPlotSetGroup->toXml(pXml) == false) { return false; } vector<PlotWidget*> plots = mpPlotSetGroup->getPlots(HISTOGRAM_PLOT); for (vector<PlotWidget*>::const_iterator iter = plots.begin(); iter != plots.end(); ++iter) { PlotWidgetImp* pPlotWidget = dynamic_cast<PlotWidgetImp*>(*iter); if (pPlotWidget != NULL) { pXml->pushAddPoint(pXml->addElement("HistogramPlot")); pXml->addAttr("id", pPlotWidget->getId()); HistogramPlotImp* pPlot = dynamic_cast<HistogramPlotImp*>(pPlotWidget->getPlot()); if (pPlot != NULL) { Layer* pLayer = pPlot->getLayer(); if (pLayer != NULL) { pXml->addAttr("layerId", pLayer->getId()); } } bool statsShown = mpStatisticsShowAction->isChecked(); QSplitter* pSplitter = pPlotWidget->getSplitter(); if (pSplitter != NULL) { QWidget* pWidget = pSplitter->widget(2); if (pWidget != NULL) { statsShown = pWidget->isVisibleTo(pSplitter); } } pXml->addAttr("statisticsShown", statsShown); pXml->popAddPoint(); } } return true; }
void MultiViewWidget::removeView() { ContainerWidget *container = qobject_cast<ContainerWidget *>(sender()); if (container) { QSplitter *splitter = qobject_cast<QSplitter *>(container->parent()); if (splitter && splitter->count() == 2) { // Get its parent, and insert the other widget into it, delete this widget. QSplitter *splitterParent = qobject_cast<QSplitter *>(splitter->parent()); QWidget *moveWidget = splitter->widget(0); if (moveWidget == container) moveWidget = splitter->widget(1); setActiveWidget(moveWidget); if (splitterParent) { int idx = splitterParent->indexOf(splitter); splitterParent->insertWidget(idx, moveWidget); splitter->deleteLater(); } else if (splitter->parent() == this) { // No more splits - back to single view widget. QVBoxLayout *layoutParent = qobject_cast<QVBoxLayout *>(layout()); if (layoutParent) { layoutParent->addWidget(moveWidget); layoutParent->removeWidget(splitter); splitter->deleteLater(); } } } else if (container->parent() == this) { // Delete the current container, and create the option container. QVBoxLayout *vLayout = qobject_cast<QVBoxLayout *>(layout()); container->deleteLater(); ContainerWidget *newContainer = createContainer(); vLayout->addWidget(newContainer); setActiveWidget(newContainer); } } }
void FrostEdit::closeTabWidgetFrame(TabWidgetFrame* tabWidFrame) { QWidget* parent = tabWidFrame->parentWidget(); QSplitter* parentsplitter = qobject_cast<QSplitter*>(parent); if(tabWidFrame->tabWidget() == mCurrentTabWidget) mCurrentTabWidget = nullptr; if(parentsplitter != NULL) { for(int i = 0; i < tabWidFrame->tabWidget()->count(); i++) { closeTab(tabWidFrame->tabWidget(), i); } int index = mTabWidgetFrames.indexOf(tabWidFrame); mTabWidgetFrames.first()->tabWidget()->setActive(true); mTabWidgetFrames.remove(index); delete tabWidFrame; if(!parentsplitter->count() > 1) { FrostEdit* edit = qobject_cast<FrostEdit*>(parentsplitter->parentWidget()); QSplitter* splitter = qobject_cast<QSplitter*>(parentsplitter->parentWidget()); TabWidgetFrame* wid = toTabWidgetFrame(parentsplitter->widget(0)); if(edit != nullptr && splitter == nullptr) { edit->setCentralWidget(wid); wid->setParent(edit); } else if (splitter != nullptr && edit == nullptr) { splitter->addWidget(wid); wid->setParent(splitter); } delete parentsplitter; } } }
void ScoreTab::setCurrent(int n) { if (n == -1) { clearTab2(); tab2->setVisible(false); // clearTab2(); //?? emit currentScoreViewChanged(0); return; } TabScoreView* tsv = static_cast<TabScoreView*>(tab->tabData(n).value<void*>()); QSplitter* vs = viewSplitter(n); ScoreView* v; if (!vs) { vs = new QSplitter; v = new ScoreView; tab2->blockSignals(true); tab2->setCurrentIndex(0); tab2->blockSignals(false); vs->addWidget(v); v->setScore(scoreList->value(n)); stack->addWidget(vs); } else { v = static_cast<ScoreView*>(vs->widget(0)); } #ifdef OMR if (v) { Score* score = v->score(); if (score->showOmr() && score->omr()) { if (vs->count() < 2) { Omr* omr = score->omr(); OmrView* sv = omr->newOmrView(v); v->setOmrView(sv); vs->addWidget(sv); connect(v, SIGNAL(scaleChanged(double)), sv, SLOT(setScale(double))); connect(v, SIGNAL(offsetChanged(double,double)), sv, SLOT(setOffset(double,double))); const QTransform _matrix = v->matrix(); double _spatium = score->spatium(); double scale = _matrix.m11() * _spatium; sv->setScale(scale); sv->setOffset(_matrix.dx(), _matrix.dy()); QList<int> sizes; sizes << 100 << 100; vs->setSizes(sizes); } } else { if (vs->count() > 1) { QWidget* w = vs->widget(1); delete w; } } } #endif stack->setCurrentWidget(vs); clearTab2(); if (v) { Score* score = v->score(); if (score->parentScore()) score = score->parentScore(); QList<Excerpt*>& excerpts = score->excerpts(); if (!excerpts.isEmpty()) { tab2->blockSignals(true); tab2->addTab(score->name().replace("&","&&")); foreach(const Excerpt* excerpt, excerpts) { tab2->addTab(excerpt->partScore()->name().replace("&","&&")); } tab2->setCurrentIndex(tsv->part); tab2->blockSignals(false); tab2->setVisible(true); }
void KateViewManager::removeViewSpace (KateViewSpace *viewspace) { // abort if viewspace is 0 if (!viewspace) return; // abort if this is the last viewspace if (m_viewSpaceList.count() < 2) return; // get current splitter QSplitter *currentSplitter = qobject_cast<QSplitter*>(viewspace->parentWidget()); // no splitter found, bah if (!currentSplitter) return; // delete views of the viewspace while (viewspace->viewCount() > 0 && viewspace->currentView()) { deleteView( viewspace->currentView(), false ); } // cu viewspace m_viewSpaceList.removeAt( m_viewSpaceList.indexOf( viewspace ) ); delete viewspace; // at this point, the splitter has exactly 1 child Q_ASSERT( currentSplitter->count() == 1 ); // if we are not the root splitter, move the child one level up and delete // the splitter then. if (currentSplitter != this) { // get parent splitter QSplitter *parentSplitter = qobject_cast<QSplitter*>(currentSplitter->parentWidget()); // only do magic if found ;) if (parentSplitter) { int index = parentSplitter->indexOf (currentSplitter); // save current splitter size, as the removal of currentSplitter looses the info QList<int> parentSizes = parentSplitter->sizes(); parentSplitter->insertWidget (index, currentSplitter->widget (0)); if (qVersion() == QLatin1String("4.6.2")) currentSplitter->hide(); // bug in Qt v4.6.2, prevents crash (bug:232140), line can be removed once we are sure that noone uses Qt 4.6.2 anymore. delete currentSplitter; // now restore the sizes again parentSplitter->setSizes(parentSizes); } } else if( QSplitter* splitter = qobject_cast<QSplitter*>(currentSplitter->widget(0)) ) { // we are the root splitter and have only one child, which is also a splitter // -> eliminate the redundant splitter and move both children into the root splitter QList<int> sizes = splitter->sizes(); // adapt splitter orientation to the splitter we are about to delete currentSplitter->setOrientation(splitter->orientation()); currentSplitter->addWidget( splitter->widget(0) ); currentSplitter->addWidget( splitter->widget(0) ); delete splitter; currentSplitter->setSizes( sizes ); } // find the view that is now active. KTextEditor::View* v = activeViewSpace()->currentView(); if ( v ) activateView( v ); updateViewSpaceActions (); emit viewChanged(); }