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