Logo Search packages:      
Sourcecode: edfbrowser version File versions  Download package

edit_annotation_dock.cpp

/*
***************************************************************************
*
* Author: Teunis van Beelen
*
* Copyright (C) 2009 Teunis van Beelen
*
* teuniz@gmail.com
*
***************************************************************************
*
* This program 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 of the License.
*
* 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; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
***************************************************************************
*
* This version of GPL is at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*
***************************************************************************
*/



#include "annotations_dock.h"



UI_AnnotationEditwindow::UI_AnnotationEditwindow(int file_number, QWidget *parent)
{
  mainwindow = (UI_Mainwindow *)parent;

  file_num = file_number;

  annotation = mainwindow->annotationlist[file_num];

  dockedit = new QDockWidget("Annotation editor", parent);
  dockedit->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
  dockedit->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);

  annot_edit_dialog = new QDialog;
  annot_edit_dialog->setMinimumSize(640, 45);

  dockedit->setWidget(annot_edit_dialog);

  descriptionLabel = new QLabel(annot_edit_dialog);
  descriptionLabel->setGeometry(10, 10, 78, 25);
  descriptionLabel->setText("Description");

  annot_descript_lineEdit = new QLineEdit(annot_edit_dialog);
  annot_descript_lineEdit->setGeometry(90, 10, 150, 25);

  onsetLabel = new QLabel(annot_edit_dialog);
  onsetLabel->setGeometry(270, 10, 48, 25);
  onsetLabel->setText("Onset");

  onset_timeEdit = new QTimeEdit(annot_edit_dialog);
  onset_timeEdit->setGeometry(320, 10, 100, 25);
  onset_timeEdit->setDisplayFormat("hh:mm:ss.zzz");

  durationLabel = new QLabel(annot_edit_dialog);
  durationLabel->setGeometry(450, 10, 58, 25);
  durationLabel->setText("Duration");

  duration_spinbox = new QDoubleSpinBox(annot_edit_dialog);
  duration_spinbox->setGeometry(510, 10, 120, 25);
  duration_spinbox->setRange(-1.0, 10000.0);
  duration_spinbox->setSingleStep(1.0);
  duration_spinbox->setDecimals(3);
  duration_spinbox->setSuffix(" sec");
  duration_spinbox->setValue(-1.0);

  modifybutton = new QPushButton(annot_edit_dialog);
  modifybutton->setGeometry(710, 10, 100, 25);
  modifybutton->setText("Modify");
  modifybutton->setEnabled(FALSE);

  deletebutton = new QPushButton(annot_edit_dialog);
  deletebutton->setGeometry(830, 10, 100, 25);
  deletebutton->setText("Delete");
  deletebutton->setEnabled(FALSE);

  createbutton = new QPushButton(annot_edit_dialog);
  createbutton->setGeometry(950, 10, 100, 25);
  createbutton->setText("Create");

  QObject::connect(modifybutton, SIGNAL(clicked()),               this, SLOT(modifyButtonClicked()));
  QObject::connect(deletebutton, SIGNAL(clicked()),               this, SLOT(deleteButtonClicked()));
  QObject::connect(createbutton, SIGNAL(clicked()),               this, SLOT(createButtonClicked()));
  QObject::connect(dockedit,     SIGNAL(visibilityChanged(bool)), this, SLOT(open_close_dock(bool)));
}



void UI_AnnotationEditwindow::open_close_dock(bool visible)
{
  struct annotationblock *annot,
                         *annot2;

  if(visible==TRUE)
  {
    mainwindow->annot_editor_active = 1;

    mainwindow->show_annot_markers = 1;

    if(mainwindow->annotationlist_backup==NULL)
    {
      annot = mainwindow->annotationlist[0];

      if(annot!=NULL)
      {
        mainwindow->annotationlist_backup = (struct annotationblock *)s_calloc(1, sizeof(struct annotationblock));

        annot2 = mainwindow->annotationlist_backup;

        memcpy(annot2, annot, sizeof(struct annotationblock));

        annot = annot->next_annotation;

        while(annot!=NULL)
        {
          annot2->next_annotation = (struct annotationblock *)s_calloc(1, sizeof(struct annotationblock));

          memcpy(annot2->next_annotation, annot, sizeof(struct annotationblock));

          annot2->next_annotation->former_annotation = annot2;

          annot2 = annot2->next_annotation;

          annot = annot->next_annotation;
        }
      }
    }
  }
  else
  {
    modifybutton->setEnabled(FALSE);

    deletebutton->setEnabled(FALSE);

    mainwindow->annot_editor_active = 0;
  }
}



void UI_AnnotationEditwindow::modifyButtonClicked()
{
  int n;


  annotation = mainwindow->annotationlist[file_num];

  n = annot_num;

  while(n)
  {
    annotation = annotation->next_annotation;

    n--;
  }

  annotation->onset = onset_timeEdit->time().hour() * 3600 * TIME_DIMENSION;
  annotation->onset += onset_timeEdit->time().minute() * 60 * TIME_DIMENSION;
  annotation->onset += onset_timeEdit->time().second() * TIME_DIMENSION;
  annotation->onset += onset_timeEdit->time().msec() * (TIME_DIMENSION / 1000);

  if(duration_spinbox->value()>0.0)
  {
    snprintf(annotation->duration, 16, "%f", duration_spinbox->value());
  }
  else
  {
    annotation->duration[0] = 0;
  }

  strncpy(annotation->annotation, annot_descript_lineEdit->text().toUtf8().data(), MAX_ANNOTATION_LEN);

  annotation->annotation[MAX_ANNOTATION_LEN] = 0;

  annotation->modified = 1;

  annotation->selected = 1;

  mainwindow->annotations_edited = 1;

  mainwindow->annotations_dock[file_num]->updateList(file_num);

  mainwindow->maincurve->update();
}



void UI_AnnotationEditwindow::deleteButtonClicked()
{
  int n;


  annotation = mainwindow->annotationlist[file_num];

  n = annot_num;

  if(annotation==NULL)
  {
    return;
  }

  while(n)
  {
    if(annotation->next_annotation==NULL)
    {
      return;
    }

    annotation = annotation->next_annotation;

    n--;
  }

  if(annotation->former_annotation!=NULL)
  {
    annotation->former_annotation->next_annotation = annotation->next_annotation;
  }

  if(annotation->next_annotation!=NULL)
  {
    annotation->next_annotation->former_annotation = annotation->former_annotation;

    annotation->next_annotation->selected = 1;

    annotation->next_annotation->jump = 1;
  }

  if(annotation->former_annotation==NULL)
  {
    mainwindow->annotationlist[file_num] = annotation->next_annotation;
  }

  s_free(annotation);

  modifybutton->setEnabled(FALSE);

  deletebutton->setEnabled(FALSE);

  mainwindow->annotations_edited = 1;

  mainwindow->annotations_dock[file_num]->updateList(file_num);

  mainwindow->maincurve->update();
}



void UI_AnnotationEditwindow::createButtonClicked()
{
  struct annotationblock *tmp_annot;


  annotation = (struct annotationblock *)s_calloc(1, sizeof(struct annotationblock));

  annotation->onset = onset_timeEdit->time().hour() * 3600 * TIME_DIMENSION;
  annotation->onset += onset_timeEdit->time().minute() * 60 * TIME_DIMENSION;
  annotation->onset += onset_timeEdit->time().second() * TIME_DIMENSION;
  annotation->onset += onset_timeEdit->time().msec() * (TIME_DIMENSION / 1000);

  if(duration_spinbox->value()>0.0)
  {
    snprintf(annotation->duration, 16, "%f", duration_spinbox->value());
  }
  else
  {
    annotation->duration[0] = 0;
  }

  strncpy(annotation->annotation, annot_descript_lineEdit->text().toUtf8().data(), MAX_ANNOTATION_LEN);

  annotation->annotation[MAX_ANNOTATION_LEN] = 0;

  tmp_annot = mainwindow->annotationlist[file_num];

  if(tmp_annot==NULL)
  {
    annotation->former_annotation = NULL;

    annotation->next_annotation = NULL;

    mainwindow->annotationlist[file_num] = annotation;
  }
  else
  {
    if(tmp_annot->onset>annotation->onset)
    {
      annotation->former_annotation = NULL;

      annotation->next_annotation = tmp_annot;

      tmp_annot->former_annotation = annotation;

      mainwindow->annotationlist[file_num] = annotation;
    }
    else
    {
      while(tmp_annot->next_annotation!=NULL)
      {
        if(tmp_annot->next_annotation->onset>annotation->onset)
        {
          break;
        }

        tmp_annot = tmp_annot->next_annotation;
      }

      if(tmp_annot->next_annotation==NULL)
      {
        annotation->next_annotation = NULL;
      }
      else
      {
        annotation->next_annotation = tmp_annot->next_annotation;

        tmp_annot->next_annotation->former_annotation = annotation;
      }

      annotation->former_annotation = tmp_annot;

      tmp_annot->next_annotation = annotation;
    }
  }

  annotation->modified = 1;

  mainwindow->annotations_edited = 1;

  mainwindow->annotations_dock[file_num]->updateList(file_num);

  mainwindow->maincurve->update();
}



void UI_AnnotationEditwindow::annotEditSetOnset(long long onset)
{
  QTime ta;

  ta.setHMS((onset / TIME_DIMENSION / 3600) % 24,
           ((onset / TIME_DIMENSION) % 3600) / 60,
           (onset / TIME_DIMENSION) % 60,
           (onset % TIME_DIMENSION) / 10000);
  onset_timeEdit->setTime(ta);
}



void UI_AnnotationEditwindow::annotEditSetDuration(long long duration)
{
  double tmp;

  tmp = duration;
  tmp /= TIME_DIMENSION;

  duration_spinbox->setValue(tmp);
}



void UI_AnnotationEditwindow::set_selected_annotation(int file_nr, int annot_nr)
{
  QTime ta;


  file_num = file_nr;

  annot_num = annot_nr;

  annotation = mainwindow->annotationlist[file_num];

  while(annot_nr)
  {
    annotation = annotation->next_annotation;

    annot_nr--;
  }

  annot_descript_lineEdit->setText(QString::fromUtf8(annotation->annotation));

  ta.setHMS((annotation->onset / TIME_DIMENSION / 3600) % 24,
           ((annotation->onset / TIME_DIMENSION) % 3600) / 60,
           (annotation->onset / TIME_DIMENSION) % 60,
           (annotation->onset % TIME_DIMENSION) / 10000);
  onset_timeEdit->setTime(ta);

  if(strlen(annotation->duration))
  {
    duration_spinbox->setValue(atof(annotation->duration));
  }
  else
  {
    duration_spinbox->setValue(-1);
  }

  modifybutton->setEnabled(TRUE);

  deletebutton->setEnabled(TRUE);
}




void UI_AnnotationEditwindow::set_selected_annotation(struct annotationblock *annot)
{
  QTime ta;


  annotation = annot;

  file_num = annot->file_num;

  annot_descript_lineEdit->setText(QString::fromUtf8(annotation->annotation));

  ta.setHMS((annotation->onset / TIME_DIMENSION / 3600) % 24,
           ((annotation->onset / TIME_DIMENSION) % 3600) / 60,
           (annotation->onset / TIME_DIMENSION) % 60,
           (annotation->onset % TIME_DIMENSION) / 10000);
  onset_timeEdit->setTime(ta);

  if(strlen(annotation->duration))
  {
    duration_spinbox->setValue(atof(annotation->duration));
  }
  else
  {
    duration_spinbox->setValue(-1);
  }

  modifybutton->setEnabled(FALSE);

  deletebutton->setEnabled(FALSE);
}















Generated by  Doxygen 1.6.0   Back to index