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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/***************************************************************************
* Copyright (C) 2005 by Alexander Dymo *
* [email protected] *
* *
* 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 "dmainwindow.h"
#include <kdebug.h>
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kiconloader.h>
#include <tqtoolbutton.h>
#include "dtabwidget.h"
#include "docksplitter.h"
DMainWindow::DMainWindow(TQWidget *parent, const char *name)
:KParts::MainWindow(parent, name), m_firstRemoved(false), m_currentWidget(0)
{
loadSettings();
createToolWindows();
m_central = new Ideal::DockSplitter(Qt::Horizontal, this);
m_activeTabWidget = createTab();
m_central->addDock(0, 0, m_activeTabWidget);
setCentralWidget(m_central);
}
void DMainWindow::loadSettings()
{
TDEConfig *config = kapp->config();
config->setGroup("UI");
m_openTabAfterCurrent = config->readBoolEntry("OpenNewTabAfterCurrent", true);
m_showIconsOnTabs = config->readBoolEntry("ShowTabIcons", false);
}
void DMainWindow::saveSettings()
{
m_leftDock->saveSettings();
m_rightDock->saveSettings();
m_bottomDock->saveSettings();
}
DMainWindow::~DMainWindow()
{
/* for (TQValueList<TQWidget*>::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it)
removeWidget(*it);*/
}
DDockWindow *DMainWindow::toolWindow(DDockWindow::Position position) const
{
switch (position) {
case DDockWindow::Bottom: return m_bottomDock;
case DDockWindow::Left: return m_leftDock;
case DDockWindow::Right: return m_rightDock;
}
return 0;
}
void DMainWindow::createToolWindows()
{
m_bottomDock = new DDockWindow(this, DDockWindow::Bottom);
moveDockWindow(m_bottomDock, TQt::DockBottom);
m_leftDock = new DDockWindow(this, DDockWindow::Left);
moveDockWindow(m_leftDock, TQt::DockLeft);
m_rightDock = new DDockWindow(this, DDockWindow::Right);
moveDockWindow(m_rightDock, TQt::DockRight);
}
void DMainWindow::addWidget(TQWidget *widget, const TQString &title)
{
// invalidateActiveTabWidget();
if (m_firstRemoved && m_activeTabWidget == m_tabs.first())
{
m_central->addDock(0, 0, m_activeTabWidget);
m_firstRemoved = false;
}
addWidget(m_activeTabWidget, widget, title);
}
void DMainWindow::addWidget(DTabWidget *tab, TQWidget *widget, const TQString &title)
{
static TQPixmap emptyPixmap;
int idx = -1;
if (m_openTabAfterCurrent && (tab->count() > 0))
idx = tab->currentPageIndex() + 1;
if (m_showIconsOnTabs)
{
const TQPixmap *pixmap = widget->icon();
const TQIconSet &icons = (pixmap && (pixmap->size().height() <= 16)) ? *(pixmap) : SmallIcon("tdevelop");
tab->insertTab(widget, icons, title, idx);
}
else
tab->insertTab(widget, emptyPixmap, title, idx);
m_widgets.append(widget);
m_widgetTabs[widget] = tab;
widget->installEventFilter(this);
tab->showPage(widget);
}
void DMainWindow::removeWidget(TQWidget *widget)
{
if (!m_widgets.contains(widget))
return; //not a widget in main window
if (m_widgetTabs.contains(widget))
{
DTabWidget *tab = m_widgetTabs[widget];
if (tab->indexOf(widget) >= 0)
{
tab->removePage(widget);
widget->reparent(0,TQPoint(0,0),false);
if (tab->count() == 0)
{
if (tab->closeButton())
tab->closeButton()->hide();
//remove and delete tabwidget if it is not the first one
if (tab != m_tabs.first())
{
TQPair<uint, uint> idx = m_central->indexOf(tab);
m_tabs.remove(tab);
m_activeTabWidget = m_tabs.first();
m_central->removeDock(idx.first, idx.second, true);
}
//only temporarily remove the first tabwidget
else
{
m_central->removeDock(0, 0, false);
m_firstRemoved = true;
}
//focus smth in m_activeTabWidget
if (m_activeTabWidget)
{
if (m_activeTabWidget->currentPage())
{
m_activeTabWidget->currentPage()->setFocus();
}
}
}
}
}
m_widgets.remove(widget);
m_widgetTabs.remove(widget);
if (m_activeTabWidget && m_activeTabWidget->currentPage())
{
//a hack to please multibuffer and actually switch the active part
TQFocusEvent ev(TQEvent::FocusIn);
TQApplication::sendEvent(m_activeTabWidget->currentPage(), &ev);
}
}
DTabWidget *DMainWindow::splitHorizontal()
{
m_activeTabWidget = createTab();
m_central->addDock(m_central->numRows(), 0, m_activeTabWidget);
return m_activeTabWidget;
}
DTabWidget *DMainWindow::splitVertical()
{
// invalidateActiveTabWidget();
int row = m_central->indexOf(m_activeTabWidget).first;
m_activeTabWidget = createTab();
m_central->addDock(row, m_central->numCols(row), m_activeTabWidget);
return m_activeTabWidget;
}
void DMainWindow::invalidateActiveTabWidget()
{
/* TQWidget *focused = m_central->focusWidget();
kdDebug(9000) << "invalidate: " << focused << endl;
if (focused == 0)
return;
if (!m_widgets.contains(focused))
{
kdDebug(9000) << " focused is not in m_widgets" << endl;
return;
}
if (m_widgetTabs.contains(focused))
{
kdDebug(9000) << " focused is in m_widgets and m_widgetTabs" << endl;
DTabWidget *tab = m_widgetTabs[focused];
if (tab->indexOf(focused) >= 0)
m_activeTabWidget = tab;
kdDebug(9000) << " tab: " << tab << endl;
}*/
}
DTabWidget *DMainWindow::createTab()
{
DTabWidget *tab = new DTabWidget(m_central);
m_tabs.append(tab);
if (tab->closeButton())
connect(tab->closeButton(), TQT_SIGNAL(clicked()), this, TQT_SLOT(closeTab()));
connect(tab, TQT_SIGNAL(closeRequest(TQWidget*)), this, TQT_SLOT(closeTab(TQWidget*)));
connect(tab, TQT_SIGNAL(contextMenu(TQWidget*,const TQPoint &)),
this, TQT_SLOT(tabContext(TQWidget*,const TQPoint &)));
return tab;
}
bool DMainWindow::eventFilter(TQObject *obj, TQEvent *ev)
{
TQWidget *w = (TQWidget*)obj;
if (!m_widgets.contains(w))
return KParts::MainWindow::eventFilter(obj, ev);
if ((m_currentWidget != w) && (ev->type() == TQEvent::FocusIn))
{
m_currentWidget = w;
emit widgetChanged(w);
}
else if (ev->type() == TQEvent::IconChange)
{
if (m_widgetTabs.contains(w))
{
DTabWidget *tab = m_widgetTabs[w];
tab->setTabIconSet(w, w->icon() ? (*(w->icon())) : TQPixmap());
}
}
else if (ev->type() == TQEvent::CaptionChange)
{
kdDebug(9000) << "caption change" << endl;
DTabWidget *tab = m_widgetTabs[w];
tab->changeTab(w, w->caption());
}
return KParts::MainWindow::eventFilter(obj, ev);
}
void DMainWindow::closeTab()
{
//nothing to do here, should be reimplemented
}
void DMainWindow::tabContext(TQWidget *, const TQPoint &)
{
//nothing to do here, should be reimplemented
}
void DMainWindow::closeTab(TQWidget *)
{
//nothing to do here, should be reimplemented
}
void DMainWindow::moveWidget(DDockWindow::Position position, TQWidget * view, const TQString & title)
{
if (m_docks.contains(view))
{
toolWindow(m_docks[view])->removeWidget(view);
toolWindow(position)->addWidget( title, view, true );
m_docks[view] = position;
}
}
void DMainWindow::addDockWidget(DDockWindow::Position position, TQWidget *view, const TQString &title)
{
toolWindow(position)->addWidget(title, view);
m_docks[view] = position;
connect(view, TQT_SIGNAL(destroyed()), this, TQT_SLOT(widgetDestroyed()));
}
void DMainWindow::removeDockWidget(TQWidget *view)
{
toolWindow(m_docks[view])->removeWidget(view);
m_docks.remove(view);
}
bool DMainWindow::hasDockWidget(TQWidget *view)
{
return m_docks.contains(view);
}
DDockWindow::Position DMainWindow::dockWidgetPosition(TQWidget *view)
{
return m_docks[view];
}
void DMainWindow::widgetDestroyed()
{
TQWidget *w = TQT_TQWIDGET(const_cast<TQObject*>(sender()));
if (m_docks.contains(w))
{
kdError() << "Widget destroyed before being removed from UI!" << endl;
m_docks.remove(w);
}
}
#include "dmainwindow.moc"
|