File: tabview.h

package info (click to toggle)
kcachegrind 4%3A16.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,844 kB
  • ctags: 3,250
  • sloc: cpp: 28,541; perl: 325; python: 235; makefile: 7; sh: 5
file content (185 lines) | stat: -rw-r--r-- 4,453 bytes parent folder | download
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
/* This file is part of KCachegrind.
   Copyright (c) 2003-2015 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.
*/

/*
 * Tab View, enclosing detailed views for one trace item in
 * two tab widgets, separated by a splitter
 */

#ifndef TABVIEW_H
#define TABVIEW_H

#include <QWidget>
#include <QTabWidget>
#include <QTabBar>
#include <QMouseEvent>
#include <QHideEvent>
#include <QShowEvent>
#include <QMoveEvent>
#include <QResizeEvent>
#include <QEvent>
#include <QSplitter>
#include <QList>

#include "traceitemview.h"

class QLabel;
class TabView;

/**
 * Subclass of QTabBar to enable context menu on tabs
 */
class TabBar : public QTabBar
{
  Q_OBJECT

 public:
  TabBar(TabView*, QTabWidget* parent, const char *name = 0);
 protected:
  void mousePressEvent(QMouseEvent *e);

 private:
  void context(QWidget*, const QPoint &);

  QTabWidget* _tabWidget;
  TabView* _tabView;
};


/**
 * Own Splitter:
 * Call checkVisiblity for all TabWidget children of the splitter
 * on a MoveEvent. This typically is produced when collapsing the widget
 * inside of another splitter.
 */
class Splitter: public QSplitter
{
  Q_OBJECT

public:
  explicit Splitter(Qt::Orientation o, QWidget* parent = 0);
  void checkVisiblity();

protected:
  void moveEvent(QMoveEvent *);
};


/**
 * Own TabView:
 * - A QTabWidget able to track its visible rect via resizeEvents.
 *   This is needed to track if this widget is collapsed in a QSplitter.
 * - Use own TabBar for context menu
 */
class TabWidget: public QTabWidget
{
  Q_OBJECT

public:

  explicit TabWidget(TabView*, QWidget* parent = 0);

  bool hasVisibleRect() { return _hasVisibleRect; }
  void checkVisibility();

signals:
  void visibleRectChanged(TabWidget*);

protected:
  void resizeEvent(QResizeEvent *);
  void showEvent(QShowEvent *);
  void hideEvent(QHideEvent *);
  void moveEvent(QMoveEvent *);

private:
  bool _hasVisibleRect;
};



class TabView : public QWidget, public TraceItemView
{
  Q_OBJECT

public:

  explicit TabView( TraceItemView* parentView,
                    QWidget* parent = 0 );

  virtual QWidget* widget() { return this; }
  QString whatsThis() const;
  void setData(TraceData*);
  bool isViewVisible() { return !_isCollapsed; }
  void selected(TraceItemView*, CostItem*);
  bool active() const { return _active; }
  void setActive(bool);

  /**
   * Rearrange tabs
   * if <w> == 0, move hidden tabs
   */
  void moveTab(QWidget* w, Position, bool wholeArea = false);

  Position tabPosition(QWidget*);
  int visibleTabs();
  int visibleAreas();

  void saveLayout(const QString& prefix, const QString& postfix);
  void restoreLayout(const QString& prefix, const QString& postfix);
  void saveOptions(const QString& prefix, const QString& postfix);
  void restoreOptions(const QString& prefix, const QString& postfix);

public slots:
  void tabChanged(int);
  void visibleRectChangedSlot(TabWidget*);

signals:
  void tabActivated(TabView*);

protected:
  void resizeEvent(QResizeEvent *);
  bool eventFilter(QObject*, QEvent*);
  void mousePressEvent(QMouseEvent*);

private:
  TraceItemView* addTab(const QString&, TraceItemView*);
  void addTop(TraceItemView*);
  void addBottom(TraceItemView*);
  TabWidget* tabWidget(Position);
  void updateVisibility();
  void doUpdate(int, bool);
  void updateNameLabel(QString n = QString::null);
  void installFocusFilters();
  void tabCounts(int&, int&, int&, int&);

  // this is true if width or height <= 1, and no child updates are done
  bool _isCollapsed;

  QLabel* _nameLabel;
  QString _nameLabelText, _nameLabelTooltip;
  int _textWidth;

  QSplitter *_mainSplitter, *_leftSplitter, *_bottomSplitter;
  TabWidget *_topTW, *_leftTW, *_bottomTW, *_rightTW;
  QList<TraceItemView*> _tabs;

  QWidget* _lastFocus;
  bool _active;
};

#endif