Belle II Software  release-08-01-10
MultilineWidget.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 //This module
9 #include <ecl/modules/eclDisplay/MultilineWidget.h>
10 
11 //Root
12 #include <TGLabel.h>
13 
14 using namespace Belle2;
15 
16 MultilineWidget::MultilineWidget(const TGWindow* p, const char* title,
17  int line_count) :
18  TGGroupFrame(p, title)
19 {
20  SetLayoutManager(new TGVerticalLayout(this));
21 
22  for (int i = 0; i < line_count; i++) {
23  addLine();
24  }
25 }
26 
27 MultilineWidget::~MultilineWidget()
28 {
29  for (unsigned int i = 0; i < lines.size(); i++) {
30  delete lines[i];
31  }
32 }
33 
35 {
36  return lines.size();
37 }
38 
39 void MultilineWidget::setLineCount(int new_count)
40 {
41  int prev_count = getLineCount();
42 
43  if (new_count > prev_count) {
44  for (int i = new_count - prev_count; i > 0; i--)
45  addLine();
46  } else {
47  for (int i = prev_count - new_count; i > 0; i--)
48  removeLine(new_count);
49  }
50 }
51 
52 void MultilineWidget::removeLine(int line_id)
53 {
54  TGLabel* line = lines[line_id];
55 
56  RemoveFrame(line);
57  lines.erase(lines.begin() + line_id);
58 
59  delete line;
60 }
61 
63 {
64  removeLine(lines.size() - 1);
65 }
66 void MultilineWidget::setLine(int line_id, const char* text)
67 {
68  if (line_id >= getLineCount())
69  setLineCount(line_id + 1);
70 
71  TGLabel* line = lines[line_id];
72 
73  line->SetText(text);
74 }
75 void MultilineWidget::addLine(const char* text)
76 {
77  TGLabel* line = new TGLabel(this, text);
78 
79  lines.push_back(line);
80  AddFrame(line, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
81  line->Paint();
82 }
void setLine(int line_id, const char *text)
Set content of the specified line to 'text'.
void removeLine(int line_id)
Remove line with specified id.
void removeLastLine()
Removes last line from multiline widget and reduces line count.
int getLineCount()
Return number of lines in widget.
std::vector< TGLabel * > lines
Content of multiline widget.
MultilineWidget(const TGWindow *p=0, const char *title=0, int line_count=0)
Create multiline widget with parent window p.
void addLine(const char *text=0)
Append line to multiline widget.
void setLineCount(int count)
Add or remove lines depending on current line count.
Abstract base class for different kinds of events.