3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_UTIL_MULTI_SPLITTER_HPP_INCLUDED
22 #define SCIDE_WIDGETS_UTIL_MULTI_SPLITTER_HPP_INCLUDED
28 class MultiSplitter
: public QSplitter
31 explicit MultiSplitter(QWidget
*parent
= 0):
34 setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Expanding
);
37 void insertWidget( QWidget
*widget
, QWidget
*neighbour
, Qt::Orientation direction
)
39 if (!neighbour
|| !widgetIsChild(neighbour
)) {
40 qWarning("MultiSplitter: neighbour widget invalid");
44 QSplitter
*parentSplitter
= parentSplitterOf(neighbour
);
45 Q_ASSERT(parentSplitter
);
46 int posInParent
= parentSplitter
->indexOf(neighbour
);
47 Q_ASSERT(posInParent
!= -1);
49 if (parentSplitter
->orientation() == direction
) {
50 parentSplitter
->insertWidget(posInParent
+ 1, widget
);
52 else if (parentSplitter
->count() < 2)
54 parentSplitter
->setOrientation(direction
);
55 parentSplitter
->addWidget(widget
);
58 QSplitter
* splitter
= new QSplitter(direction
);
59 splitter
->addWidget(neighbour
);
60 splitter
->addWidget(widget
);
61 parentSplitter
->insertWidget(posInParent
, splitter
);
65 void removeWidget( QWidget
*widget
)
67 if (!widget
|| !widgetIsChild(widget
)) {
68 qWarning("MultiSplitter: widget invalid");
72 QSplitter
*parent
= parentSplitterOf(widget
);
73 if (parent
== this && parent
->count() < 2) {
74 qWarning("MultiSplitter: can not remove last widget");
80 Q_ASSERT(parent
->count());
82 if (parent
!= this && parent
->count() == 1) {
83 QSplitter
*grandParent
= parentSplitterOf(parent
);
84 int posInParent
= grandParent
->indexOf(parent
);
85 Q_ASSERT(posInParent
!= -1);
86 grandParent
->insertWidget(posInParent
, parent
->widget(0));
92 QSplitter
*parentSplitterOf( QWidget
*widget
)
94 return qobject_cast
<QSplitter
*>( widget
->parent() );
97 bool widgetIsChild( QWidget
*widget
)
99 QObject
*object
= widget
->parent();
103 object
= object
->parent();
111 #endif // SCIDE_WIDGETS_UTIL_MULTI_SPLITTER_HPP_INCLUDED