1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/***************************************************************************
* Copyright (C) 2004 by Alexander Dymo *
* adymo@kdevelop.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "docksplitter.h"
#include <kdebug.h>
namespace Ideal {
DockSplitter::DockSplitter(Qt::Orientation orientation, TQWidget *parent, const char *name)
:TQSplitter(parent, name), m_orientation(orientation)
{
switch (m_orientation)
{
case Qt::Horizontal:
setOrientation(Qt::Vertical);
break;
case Qt::Vertical:
setOrientation(Qt::Horizontal);
break;
}
setOpaqueResize(true);
appendSplitter();
}
DockSplitter::~DockSplitter()
{
}
void DockSplitter::addDock(uint row, uint col, TQWidget *dock)
{
if (m_docks.count() <= row)
for (uint i = m_docks.count(); i <= row ; ++i)
m_docks.append(TQValueList<TQWidget*>());
if (m_docks[row].count() <= col)
{
for (uint i = m_docks[row].count(); i <= col ; ++i)
m_docks[row].append(0);
m_docks[row][col] = dock;
}
else if (m_docks[row][col] == 0)
m_docks[row][col] = dock;
else
m_docks[row].insert(m_docks[row].at(col), dock);
if (m_splitters.count() <= row)
createSplitters(row);
TQSplitter *splitter = m_splitters[row];
dock->reparent(splitter, TQPoint(0,0), true);
if (col < m_docks[row].count()-1)
shiftWidgets(splitter, row, col+1);
}
void DockSplitter::appendSplitter()
{
switch (m_orientation)
{
case Qt::Horizontal:
m_splitters.append(new TQSplitter(Qt::Horizontal, this));
break;
case Qt::Vertical:
m_splitters.append(new TQSplitter(Qt::Vertical, this));
break;
}
m_splitters[m_splitters.size()-1]->setOpaqueResize(true);
m_splitters[m_splitters.size()-1]->show();
}
void DockSplitter::createSplitters(uint index)
{
kdDebug(9000) << "DockSplitter::createSplitters index = " << index << " count = " << m_splitters.count() << endl;
for (uint i = m_splitters.count(); i <= index; ++i)
{
kdDebug(9000) << " appendSplitter..." << endl;
appendSplitter();
}
}
void DockSplitter::removeDock(uint row, uint col, bool alsoDelete)
{
if ((row >= m_docks.count()) || (col >= m_docks[row].count()))
return;
TQWidget *w = m_docks[row][col];
m_docks[row].remove(m_docks[row].at(col));
if (alsoDelete)
{
delete w;
w = 0;
}
else
{
w->reparent(0, TQPoint(0,0), false);
w->hide();
}
m_splitters[row]->setMinimumSize(m_splitters[row]->minimumSizeHint());
if (isRowEmpty(row))
{
m_docks.remove(m_docks.at(row));
delete m_splitters[row];
m_splitters[row] = 0;
m_splitters.remove(m_splitters.at(row));
}
}
bool DockSplitter::isRowEmpty(int row)
{
if (m_docks[row].count() == 0)
return true;
for (uint i = 0; i < m_docks[row].count(); ++i)
if (m_docks[row][i] != 0)
return false;
return true;
}
void DockSplitter::shiftWidgets(TQSplitter *splitter, uint row, uint fromCol)
{
kdDebug(9000) << "shiftWidgets: row=" << row << " from col=" << fromCol << endl;
kdDebug(9000) << "row size is: " << m_docks[row].count() << endl;
for (uint i = fromCol; i < m_docks[row].count(); ++i)
{
kdDebug(9000) << "move from " << i << " to last" << endl;
if (m_docks[row][i])
splitter->moveToLast(m_docks[row][i]);
else
kdDebug(9000) << "m_docks[" << row << "][" << i << "] is 0" << endl;
}
}
int DockSplitter::numRows() const
{
return m_docks.count();
}
int DockSplitter::numCols(int row) const
{
if (row < numRows())
return m_docks[row].count();
return 0;
}
TQPair<uint, uint> DockSplitter::indexOf(TQWidget *dock)
{
for (uint i = 0; i < m_docks.count(); ++i)
for (uint j = 0; j < m_docks[i].count(); ++j)
if (dock == m_docks[i][j])
return tqMakePair(i, j);
return tqMakePair(0u, 0u);
}
}
#include "docksplitter.moc"
|