cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sawNoteRecorderQtComponent.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5  $Id: sawNoteRecorderQtComponent.h 3361 2012-01-19 14:24:13Z mbalick1 $
6 
7  Author(s): Marcin Balicki
8  Created on: 2011-02-10
9 
10  (C) Copyright 2011 Johns Hopkins University (JHU), All Rights
11  Reserved.
12 
13 --- begin cisst license - do not edit ---
14 
15 This software is provided "as is" under an open source license, with
16 no warranty. The complete license can be found in license.txt and
17 http://www.cisst.org/cisst/license.txt.
18 
19 --- end cisst license ---
20 */
21 
22 #ifndef _sawNoteRecorderQtComponent_h
23 #define _sawNoteRecorderQtComponent_h
24 
25 #include <QObject>
26 #include <QDockWidget>
27 #include <QTimerEvent>
28 #include <QErrorMessage>
29 #include <QSlider>
30 
35 
36 #include "ui_sawNoteRecorderQtWidget.h"
37 #include <QButtonGroup>
38 #include <QMap>
39 #include <QPushButton>
40 #include <QLineEdit>
41 #include <QVBoxLayout>
42 #include <QHBoxLayout>
43 #include <QDockWidget>
44 #include <QSizePolicy>
45 
46 #include <stdio.h>
47 #include <iostream>
48 #include <iomanip>
49 #include <fstream>
50 
51 
52 // Always include last!
54 
55 
58 
59 class NoteWidget : public QWidget {
60  Q_OBJECT
61 
62 public:
63  //needs to register
64  NoteWidget( const QObject * noteRecorder, QString note) :
65  QWidget(),
66  SaveButton("Note"),
67  RemoveButton("X"),
68  ClickTime(0){
69 
70  RemoveButton.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
71  SaveButton.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
72  NoteLineEdit.setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
73 
74  QHBoxLayout *horLayout = new QHBoxLayout(this) ;
75 
76  this->setLayout(horLayout);
77 
78  horLayout->addWidget(&SaveButton);
79  horLayout->addWidget(&NoteLineEdit);
80  horLayout->addWidget(&RemoveButton);
81 
82  NoteLineEdit.setText(note);
83  connect(this, SIGNAL(QSignalSaveClicked(NoteWidget *)), noteRecorder, SLOT(QSlotLogNoteClicked(NoteWidget *)));
84  connect(this, SIGNAL(QSignalRemoveClicked(NoteWidget *)), noteRecorder, SLOT(QSlotRemoveNoteClicked(NoteWidget *)));
85 
86  connect(&SaveButton, SIGNAL(clicked()), this, SLOT(QSlotSaveClicked()));
87  connect(&RemoveButton, SIGNAL(clicked()), this, SLOT(QSlotRemoveClicked()));
88  connect(&NoteLineEdit, SIGNAL( returnPressed()), this, SLOT(QSlotSaveClicked()));
89  RemoveButton.setToolTip("Remove Note from GUI");
90 
91  RemoveButton.setStyleSheet(" QPushButton { background: qradialgradient(cx:0, cy:0, radius: 2, fx:0.5, fy:0.5, stop:0 white, stop:1 rgba(190,0,0, 60%)); border-radius: 3px;}");
92  //SaveButton.setStyleSheet(" QPushButton { background: qradialgradient(cx:0, cy:0, radius: 2, fx:0.5, fy:0.5, stop:0 white, stop:1 rgba(0,210,0, 60%)); border-radius: 10px;}");
93  SaveButton.setStyleSheet(" QPushButton { background-color : rgb(0, 180, 0); }");
94 
95  }
96 
97  void UpdateGUI(double currentTime) {
98  double t = currentTime - ClickTime;
99  double decayTime = 1;
100  if (t <= decayTime) {
101 
102  int color = static_cast<int>(255 - (t/decayTime * 255));
103 
104  QString ss = "QLineEdit { background-color : hsv(120," + QString::number(color) + ",255); }";
105  NoteLineEdit.setStyleSheet(ss);
106  // NoteLineEdit.setStyleSheet(" QLineEdit { background: qradialgradient(cx:0, cy:0, radius: 1, fx:0.5, fy:0.5, stop:0 white, stop:1 rgba(0,190,0, 60%)); border-radius: 9px;}");
107  }
108  }
109 
110  QString GetText(void) {return NoteLineEdit.text();};
111 
113 
114 private :
115  NoteWidget();
116 
117  QPushButton SaveButton;
118  QPushButton RemoveButton;
119  QLineEdit NoteLineEdit;
120 
121  double ClickTime;
122 
123 
124 public slots:
125 
127  emit QSignalRemoveClicked(this);
128  }
129 
132  emit QSignalSaveClicked(this);
133  }
134 
135 signals:
138 
139 };
140 
142 {
143  Q_OBJECT;
145 
146 public:
147 
148  QDockWidget * GetWidget(void) {
149  return &Widget;
150  }
151 
152  sawNoteRecorderQtComponent(const std::string & name, double updatePeriod);
154  void Configure(const std::string & filename = "");
155 
156  void Show() { Widget.show(); }
157  void Hide() { Widget.hide(); }
158 
159  void LogNote(const mtsStdString &note);
160 
161 private:
162  //The instance of the widget representing this behavior.
163  QDockWidget Widget;
164  QVBoxLayout NotesVLayout;
165 
166  void AddNote(const QString & noteTxt);
167 
168  //Store and Load notes from files.
169  void LoadPresets();
170  void SavePresets();
171 
172  Ui::sawNoteRecorderQtWidget NoteRecorderWidget;
173  void MakeQTConnections(void);
174 
175  QVector<NoteWidget *> NoteVec;
176  std::ofstream LogFile;
177 
178  osaTimeServer TimeServer;
179  QErrorMessage * ErrorMessageDialog;
180  void ErrorMessage(const std::string & message);
181 
182  void timerEvent(QTimerEvent *);
183 
184  void RangeChangedEvent(void) {
185  emit QSignalUpdateRange();
186  }
187 
188 public slots:
189 
190  void QSlotRemoveNoteClicked(NoteWidget *);
191  void QSlotLogNoteClicked(NoteWidget *);
192 
193  void QSlotAddExtraNoteClicked();
194  void QSlotNewLogFileClicked();
195 
197  SavePresets();
198  }
200  LoadPresets();
201  }
202 
203  void QSlotPathClicked(void);
204 
205 signals:
206  void QSignalUpdateRange(void);
207 
208 };
209 
211 
212 #endif //_sawNoteRecorderQtComponent_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
void QSlotRemoveClicked()
Definition: sawNoteRecorderQtComponent.h:126
static mtsManagerLocal * GetInstance(void)
Declaration of osaTimeServer class.
std::ofstream * LogFile
Definition: mtsComponent.h:461
QDockWidget * GetWidget(void)
Definition: sawNoteRecorderQtComponent.h:148
Declaration of Local Component ManagerThis class defines the local component manager (LCM) that manag...
void Show()
Definition: sawNoteRecorderQtComponent.h:156
QString GetText(void)
Definition: sawNoteRecorderQtComponent.h:110
Declaration of mtsComponent.
void QSignalSaveClicked(NoteWidget *)
void QSignalRemoveClicked(NoteWidget *)
Definition: sawNoteRecorderQtComponent.h:59
#define CMN_LOG_ALLOW_VERBOSE
Definition: cmnLogLoD.h:73
Definition: mtsComponent.h:150
double GetAbsoluteTimeInSeconds(void) const
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
void QSlotLoadPresetsClicked()
Definition: sawNoteRecorderQtComponent.h:199
void Hide()
Definition: sawNoteRecorderQtComponent.h:157
Class for relative time.
Definition: osaTimeServer.h:73
void QSlotSaveClicked()
Definition: sawNoteRecorderQtComponent.h:130
NoteWidget(const QObject *noteRecorder, QString note)
Definition: sawNoteRecorderQtComponent.h:64
void QSlotSavePresetsClicked()
Definition: sawNoteRecorderQtComponent.h:196
~NoteWidget()
Definition: sawNoteRecorderQtComponent.h:112
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
virtual void Configure(const std::string &filename="")
const osaTimeServer & GetTimeServer(void) const
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
Definition: sawNoteRecorderQtComponent.h:141
void UpdateGUI(double currentTime)
Definition: sawNoteRecorderQtComponent.h:97