summaryrefslogtreecommitdiffstats
path: root/tdecachegrind/tdecachegrind/multiview.cpp
blob: 4288e2dfe06a6255957a031f2aca1a165fc7f65d (plain)
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
/* This file is part of KCachegrind.
   Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

   KCachegrind is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   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 General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/*
 * MultiView, enclosing multiple TabView's with a user choosable
 * active view (i.e. focus), separated by a splitter.
 * Selection of the active view is shown in the next to the right view
 * (with wrap around).
 */

#include <tqobjectlist.h>
#include <kconfig.h>
#include <kdebug.h>

#include "multiview.h"
#include "tabview.h"

//
// MultiView
//

MultiView::MultiView(TopLevel* top, TQWidget* parent, const char* name)
    : TQSplitter(parent, name), TraceItemView(0, top)
{
  // default
  setOrientation(Qt::Horizontal);

    appendView();
    _active = _views.first();
    _active->setActive(true);
}

void MultiView::setData(TraceData* d)
{
  TraceItemView::setData(d);

  TabView* tv;
  for(tv=_views.first(); tv; tv=_views.next())
    tv->setData(d);
}

void MultiView::setChildCount(int n)
{
    while(n< (int)_views.count()) removeView();
    while(n> (int)_views.count()) appendView();
}

void MultiView::appendView()
{
    int n = _views.count()+1;

    TabView* tv = new TabView(this, this,
			      TQString("TabView-%1").arg(n).ascii());
    connect(tv, TQT_SIGNAL(activated(TabView*)),
	    this, TQT_SLOT(tabActivated(TabView*)) );
    _views.append(tv);
    tv->show();

    // set same attributes as in active view
    tv->set(0, _data, _costType, _costType2,
	    _groupType, _partList, _activeItem, 0);
    tv->updateView();

    if (0) kdDebug() << "MultiView::appendView, now "
		     << _views.count() << endl;
}

void MultiView::removeView()
{
    if (_views.count()<=1) return;

    TabView* last = _views.last();

    // if last tab is active, make first active
    if (last == _active) {
	TabView* newActive = _views.first();
	newActive->setActive(true);
	tabActivated(newActive);
    }

    _views.removeRef(last);
    delete last;

    if (0) kdDebug() << "MultiView::removeView, now "
		     << _views.count() << endl;
}


void MultiView::tabActivated(TabView* newActiveTab)
{
    if (_active == newActiveTab) return;

    if (0) kdDebug() << "MultiView::tabActivated " 
		     << newActiveTab->name() << endl;

    TraceItem* oldActiveItem = 0;
    if (_active) {
	oldActiveItem = _active->activeItem();
	_active->setActive(false);
    }
    _active = newActiveTab;

    // make the active item of the new TabView active
    if (_active && (oldActiveItem != _active->activeItem()))
	TraceItemView::activated(_active->activeItem());
}

void MultiView::selected(TraceItemView* sender, TraceItem* i)
{
    if (0) kdDebug() << "MultiView::selected " << i->name()
		     << ", sender " << sender->widget()->name() << endl;

     // we react only on selection changes of the active TabView
    if (sender != (TraceItemView*)_active) return;

    _views.findRef(_active);
    TabView* next = _views.next();
    if (!next) next = _views.first();

    // don't change item of active tab
    if (next == _active) return;

    next->activate(i);
    next->updateView();
}

void MultiView::activated(TraceItemView* sender, TraceItem* i)
{
    if (0) kdDebug() << "MultiView::activated " << i->name()
		     << ", sender " << sender->widget()->name() << endl;

    // we react only on selection changes of the active TabView
    if (sender != (TraceItemView*)_active) return;

    TraceItemView::activated(sender,i);
}

void MultiView::doUpdate(int changeType)
{
    TabView* tv;
    for(tv=_views.first(); tv; tv=_views.next()) {
	tv->set(changeType, _data, _costType, _costType2,
		_groupType, _partList,
		(tv == _active) ? _activeItem : tv->activeItem(),
		tv->selectedItem());
	tv->notifyChange(changeType);
	if (tv->isViewVisible())
	    tv->updateView();
    }
}


void MultiView::readViewConfig(KConfig* c,
			       TQString prefix, TQString postfix,
			       bool withOptions)
{
  if (0) qDebug("%s::readConfig(%s%s)", name(),
		prefix.ascii(), postfix.ascii());

  TQString active;
  KConfigGroup* g = configGroup(c, prefix, postfix);
  int n = g->readNumEntry("Panels", 1);
  setChildCount(n);
  setOrientation( (g->readEntry("Orientation") == TQString("Horizontal")) ?
		  Qt::Horizontal : Qt::Vertical );
  
  setSizes(g->readIntListEntry("PanelSizes"));
  
  active = g->readEntry("ActivePanel", "");
  delete g;

  TabView* tv, *activeTV = 0;
  for(tv=_views.first();tv;tv=_views.next()) {
    if (tv->name() == active) activeTV=tv;
    tv->readViewConfig(c, TQString("%1-%2").arg(prefix).arg(tv->name()),
		       postfix, withOptions);
  }

  // activate panel after restoring
  if (!activeTV) activeTV = _views.first();
  
  if (_active == activeTV)
    TraceItemView::activated(_active->activeItem());
  else
    activeTV->setActive(true);
}

void MultiView::saveViewConfig(KConfig* c, 
			       TQString prefix, TQString postfix,
			       bool withOptions)
{
  KConfigGroup g(c, (prefix+postfix).ascii());
  
  g.writeEntry("Panels", childCount());
  g.writeEntry("Orientation",
	       (orientation() == Qt::Horizontal) ?
	       "Horizontal" : "Vertical");
  
  g.writeEntry("PanelSizes", sizes());
  g.writeEntry("ActivePanel", _active ? _active->name() : "none");

  TabView* tv;
  for(tv=_views.first();tv;tv=_views.next())
    tv->saveViewConfig(c, TQString("%1-%2").arg(prefix).arg(tv->name()),
		       postfix, withOptions);
}


#include "multiview.moc"