本文整理汇总了C++中QSplitter::indexOf方法的典型用法代码示例。如果您正苦于以下问题:C++ QSplitter::indexOf方法的具体用法?C++ QSplitter::indexOf怎么用?C++ QSplitter::indexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSplitter
的用法示例。
在下文中一共展示了QSplitter::indexOf方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: closestLegalPosition
int QSplitterHandle::closestLegalPosition(int pos)
{
Q_D(QSplitterHandle);
QSplitter *s = d->s;
if (s->isRightToLeft() && d->orient == Qt::Horizontal) {
int w = s->contentsRect().width();
return w - s->closestLegalPosition(w - pos, s->indexOf(this));
}
return s->closestLegalPosition(pos, s->indexOf(this));
}
示例2: minimizeWidget
//!
//! Minimizes the given widget inside its parent widget.
//!
//! The widget can be a panel frame or a splitter widget.
//!
//! \param widget The widget to minimize.
//!
void PanelFrame::minimizeWidget ( QWidget *widget )
{
QWidget *parentWidget = widget->parentWidget();
QSplitter *parentSplitter = qobject_cast<QSplitter *>(parentWidget);
parentSplitter->setHandleWidth(1);
if (!parentSplitter) {
QMessageBox::information(this, "Minimize Panel", "The last visible panel cannot be minimized.");
return;
}
int index = parentSplitter->indexOf(widget);
QList<int> sizes = parentSplitter->sizes();
// count number of visible panel frames
int visiblePanelFrames = 0;
for (int i = 0; i < sizes.size(); ++i)
if (sizes[i] > 0)
++visiblePanelFrames;
if (visiblePanelFrames == 1)
minimizeWidget(parentSplitter);
else {
sizes[index] = 0;
parentSplitter->setSizes(sizes);
}
}
示例3: split
void SplitView::split(BufferView* view, Qt::Orientation orientation)
{
if (view) {
QSplitter* container = qobject_cast<QSplitter*>(view->parentWidget());
if (container) {
int index = container->indexOf(view);
BufferView* bv = 0;
const int size = (orientation == Qt::Horizontal ? container->width() : container->height()) - container->handleWidth();
if (container->count() == 1 || container->orientation() == orientation) {
container->setOrientation(orientation);
bv = createBufferView(container, index + 1);
QList<int> sizes;
for (int i = 0; i < container->count(); ++i)
sizes += size / container->count();
container->setSizes(sizes);
} else if (index != -1) {
QList<int> sizes = container->sizes();
QSplitter* splitter = wrap(view, orientation);
if (splitter) {
container->setSizes(sizes);
bv = createBufferView(splitter);
splitter->setSizes(QList<int>() << size/2 << size/2);
}
}
if (bv) {
bv->setBuffer(view->buffer());
emit viewAdded(bv);
}
}
}
}
示例4: maximizeWidget
//!
//! Maximizes the given widget inside its parent widget.
//!
//! The widget can be a panel frame or a splitter widget.
//!
//! \param widget The widget to maximize.
//!
void PanelFrame::maximizeWidget ( QWidget *widget )
{
QWidget *parentWidget = widget->parentWidget();
QSplitter *parentSplitter = qobject_cast<QSplitter *>(parentWidget);
parentSplitter->setHandleWidth(1);
if (!parentSplitter) {
QMessageBox::information(this, "Maximize Panel", "The panel is already maximized.");
return;
}
int index = parentSplitter->indexOf(widget);
QList<int> sizes = parentSplitter->sizes();
// count number of visible panel frames
int visiblePanelFrames = 0;
for (int i = 0; i < sizes.size(); ++i)
if (sizes[i] > 0)
++visiblePanelFrames;
if (visiblePanelFrames == 1)
maximizeWidget(parentSplitter);
else {
// hide all other panels in the same splitter
for (int i = 0; i < sizes.size(); ++i)
if (i != index)
sizes[i] = 0;
parentSplitter->setSizes(sizes);
}
}
示例5: splitView
void MultiViewWidget::splitView(Qt::Orientation orient,
ContainerWidget *container)
{
QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout *>(container->parent());
QSplitter *split = qobject_cast<QSplitter *>(container->parent());
if (!widgetLayout)
if (container->parent() == this)
widgetLayout = qobject_cast<QVBoxLayout *>(layout());
if (widgetLayout) {
QSplitter *splitter = new QSplitter(orient, this);
widgetLayout->removeWidget(container);
widgetLayout->addWidget(splitter);
splitter->addWidget(container);
container = createContainer();
splitter->addWidget(container);
QList<int> sizes;
int s = Qt::Horizontal ? splitter->size().width() / 2
: splitter->size().height() / 2;
sizes << s << s;
splitter->setSizes(sizes);
}
else if (split) {
QSplitter *splitter = new QSplitter(orient, this);
int idx = split->indexOf(container);
splitter->addWidget(container);
container = createContainer();
splitter->addWidget(container);
split->insertWidget(idx, splitter);
QList<int> sizes;
int s = Qt::Horizontal ? splitter->size().width() / 2
: splitter->size().height() / 2;
sizes << s << s;
splitter->setSizes(sizes);
}
}
示例6: splitViewSpace
void KateViewManager::splitViewSpace( KateViewSpace* vs, // = 0
Qt::Orientation o )// = Qt::Horizontal
{
// emergency: fallback to activeViewSpace, and if still invalid, abort
if (!vs) vs = activeViewSpace();
if (!vs) return;
// get current splitter, and abort if null
QSplitter *currentSplitter = qobject_cast<QSplitter*>(vs->parentWidget());
if (!currentSplitter) return;
// index where to insert new splitter/viewspace
const int index = currentSplitter->indexOf( vs );
// create new viewspace
KateViewSpace* vsNew = new KateViewSpace( this );
// only 1 children -> we are the root container. So simply set the orientation
// and add the new view space, then correct the sizes to 50%:50%
if (currentSplitter->count() == 1)
{
if( currentSplitter->orientation() != o )
currentSplitter->setOrientation( o );
QList<int> sizes = currentSplitter->sizes();
sizes << (sizes.first() - currentSplitter->handleWidth() ) / 2;
sizes[0] = sizes[1];
currentSplitter->insertWidget( index, vsNew );
currentSplitter->setSizes( sizes );
}
else
{
// create a new QSplitter and replace vs with the splitter. vs and newVS are
// the new children of the new QSplitter
QSplitter* newContainer = new QSplitter( o );
newContainer->setOpaqueResize( KGlobalSettings::opaqueResize() );
QList<int> currentSizes = currentSplitter->sizes();
newContainer->addWidget( vs );
newContainer->addWidget( vsNew );
currentSplitter->insertWidget( index, newContainer );
newContainer->show();
// fix sizes of children of old and new splitter
currentSplitter->setSizes( currentSizes );
QList<int> newSizes = newContainer->sizes();
newSizes[0] = (newSizes[0] + newSizes[1] - newContainer->handleWidth()) / 2;
newSizes[1] = newSizes[0];
newContainer->setSizes( newSizes );
}
m_viewSpaceList.append( vsNew );
activeViewSpace()->setActive( false );
vsNew->setActive( true, true );
vsNew->show();
createView ((KTextEditor::Document*)activeView()->document());
updateViewSpaceActions ();
}
示例7: file
SSheetSetting::SSheetSetting(const QString ¤t, const QString &defsheet,
bool dic, QWidget *parent)
: QDialog(parent), initialSheet(current), defaultSheet(defsheet)
{
#ifdef Q_WS_MAC
setWindowFlags(Qt::Sheet);
#else
setWindowTitle(tr("Browser style sheet setting"));
#endif
QFile file((dic) ? ":/data/dict-style.html" : ":/data/book-style.html");
file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&file);
testText = in.readAll();
QVBoxLayout *v = new QVBoxLayout;
#ifdef Q_WS_MAC
TitleLabel *l = new TitleLabel(tr("Browser style sheet setting"));
v->addWidget(l);
#endif
QSplitter *splitter = new QSplitter(this);
edit = new QTextEdit();
edit->setPlainText(current);
view = new QTextEdit();
view->setReadOnly(true);
view->setHtml(setViewText());
splitter->addWidget(edit);
splitter->addWidget(view);
splitter->setStretchFactor(splitter->indexOf(view), 1);
v->addWidget(splitter);
v->setStretchFactor(splitter, 1);
QDialogButtonBox *bBox = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Reset);
QPushButton *save = bBox->addButton(tr("Save to file..."),
QDialogButtonBox::ActionRole);
QPushButton *load = bBox->addButton(tr("Load from file..."),
QDialogButtonBox::ActionRole);
QPushButton *aply = bBox->addButton(tr("Test"),
QDialogButtonBox::ActionRole);
connect(bBox, SIGNAL(accepted()), SLOT(accept()));
connect(bBox, SIGNAL(rejected()), SLOT(reject()));
connect(bBox->button(QDialogButtonBox::RestoreDefaults),
SIGNAL(clicked()), SLOT(defaultReset()));
connect(bBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
SLOT(reset()));
connect(save, SIGNAL(clicked()), SLOT(save()));
connect(load, SIGNAL(clicked()), SLOT(load()));
connect(aply, SIGNAL(clicked()), SLOT(apply()));
v->addWidget(bBox);
setLayout(v);
}
示例8: split
//!
//! Splits the panel frame according to the given orientation.
//!
//! \param orientation The orientation in which to split the panel frame.
//!
void PanelFrame::split ( Qt::Orientation orientation )
{
QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
QSplitter *parentSplitter = qobject_cast<QSplitter *>(parentWidget());
parentSplitter->setHandleWidth(1);
if (!parentSplitter && !mainWindow) {
QMessageBox::information(this, "Split Panel", "Splitting this panel is not possible.");
return;
}
// flip the orientation
if (orientation == Qt::Horizontal)
orientation = Qt::Vertical;
else
orientation = Qt::Horizontal;
// save the size of this panel
QSize panelSize = size();
int widthHeight = orientation == Qt::Horizontal ? panelSize.width() : panelSize.height();
// clone this panel frame
PanelFrame *clonedPanelFrame = new PanelFrame(m_panelType, parentWidget(), windowFlags());
QList<int> sizes;
int panelIndex;
if (parentSplitter) {
// save the parent splitter's sizes
sizes = parentSplitter->sizes();
// obtain the index of this panel in its parent splitter
panelIndex = parentSplitter->indexOf(this);
}
// create new splitter for this panel and its clone
QSplitter *newSplitter = new QSplitter(orientation);
newSplitter->setHandleWidth(1);
newSplitter->addWidget(this);
newSplitter->addWidget(clonedPanelFrame);
// give both panels in the new splitter the same space
QList<int> newSizes;
newSizes << widthHeight / 2 << widthHeight / 2;
newSplitter->setSizes(newSizes);
if (parentSplitter) {
// insert the new splitter into the panel's former parent splitter
parentSplitter->insertWidget(panelIndex, newSplitter);
// restore the parent splitter's sizes
parentSplitter->setSizes(sizes);
} else {
mainWindow->setCentralWidget(newSplitter);
}
}
示例9: wrap
QSplitter* SplitView::wrap(BufferView* view, Qt::Orientation orientation)
{
QSplitter* container = qobject_cast<QSplitter*>(view->parentWidget());
if (container) {
int index = container->indexOf(view);
QSplitter* splitter = new QSplitter(orientation, container);
container->insertWidget(index, splitter);
container->setCollapsible(index, false);
splitter->addWidget(view);
splitter->setCollapsible(0, false);
return splitter;
}
return 0;
}
示例10: dropViewInsidePane
void ViewAreaImpl::dropViewInsidePane(ViewPane* pane, View* view, int dropEdge)
{
if(dropEdge == OVER){
addView(pane, view, true);
} else {
QSize destSize = pane->size();
QSplitter* parentSplitter = static_cast<QSplitter*>(pane->parentWidget());
if(parentSplitter->count() >= 2){
QList<int> sizes = parentSplitter->sizes();
QSplitter* newSplitter = new QSplitter(parentSplitter);
parentSplitter->insertWidget(parentSplitter->indexOf(pane), newSplitter);
newSplitter->addWidget(pane);
parentSplitter->setSizes(sizes);
parentSplitter = newSplitter;
}
ViewPane* newViewPane = new ViewPane(this, parentSplitter);
if(dropEdge == LEFT){
parentSplitter->setOrientation(Qt::Horizontal);
parentSplitter->insertWidget(0, newViewPane);
} else if(dropEdge == RIGHT){
parentSplitter->setOrientation(Qt::Horizontal);
parentSplitter->insertWidget(1, newViewPane);
} else if(dropEdge == TOP){
parentSplitter->setOrientation(Qt::Vertical);
parentSplitter->insertWidget(0, newViewPane);
} else {
parentSplitter->setOrientation(Qt::Vertical);
parentSplitter->insertWidget(1, newViewPane);
}
addView(newViewPane, view, true);
int half;
if(parentSplitter->orientation() == Qt::Horizontal){
half = destSize.height() / 2;
} else {
half = destSize.width() / 2;
}
QList<int> sizes;
sizes << half << half;
parentSplitter->setSizes(sizes);
}
}
示例11: applyStoredSize
void RightPanePlaceHolder::applyStoredSize(int width)
{
if (width) {
QSplitter *splitter = qobject_cast<QSplitter *>(parentWidget());
if (splitter) {
// A splitter we need to resize the splitter sizes
QList<int> sizes = splitter->sizes();
int index = splitter->indexOf(this);
int diff = width - sizes.at(index);
int adjust = sizes.count() > 1 ? (diff / (sizes.count() - 1)) : 0;
for (int i = 0; i < sizes.count(); ++i) {
if (i != index)
sizes[i] -= adjust;
}
sizes[index]= width;
splitter->setSizes(sizes);
} else {
QSize s = size();
s.setWidth(width);
resize(s);
}
}
}
示例12: removeView
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);
}
}
}
示例13: removeViewSpace
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();
}