<commit_before>/* 
 * The Biomechanical ToolKit
 * Copyright (c) 2009-2011, <NAME>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *     * Redistributions of source code must retain the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *     * Neither the name(s) of the copyright holders nor the names
 *       of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written
 *       permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "TimeEventBarWidget.h"

#include <QtGui>
#include <QLinearGradient>
#include <QFontMetrics>

#include <cmath>
#define NUMLENGTH(num) ((num==0)?1:(int)log10(std::fabs((float)num))+1)

static int oldMouseX = 0;
static int oldEventFrame = 0;
static const int WBound = 10;
static const int WSlider = 10;
static const int TopMargin = 10;
static const int BottomMargin = 30;
static const int LeftMargin = 60;
static const int RightMargin = 30;
#ifdef Q_WS_WIN
static const qreal EventRelativePosY = 13.0;
static const qreal EventSymbolSize = 15.0;
static const QFont EventFont = QFont("Lucida Sans Unicode", 14);
#else
static const qreal EventRelativePosY = 16.0;
static const qreal EventSymbolSize = 12.0;
static const QFont EventFont = QFont("Arial", 12);
#endif
static const QColor MoveBrushColor = QColor(0, 127, 255, 128);
static const QColor BoundBrushColor = QColor(0, 127, 255, 64);
static const QPen MovePen = QColor(0, 127, 255);
static const QPen MoveShadowPen = QColor(100, 100, 100, 128);

TimeEventBarWidget::TimeEventBarWidget(QWidget* parent)
: QFrame(parent), m_EventContexts(), m_Ticks(), m_TicksLabel(), 
  m_Fm(this->font()), m_EventItems(), m_EventSymbols(8), m_SelectedEvents(),
  m_RubberOrigin()
{
  this->m_FirstFrame = 0;
  this->m_LastFrame = 0;
  this->m_ROIFirstFrame = this->m_FirstFrame;
  this->m_ROILastFrame = this->m_LastFrame;
  this->m_EventContexts << "Right" << "Left" << "General";
  this->m_SliderPos = this->m_FirstFrame;
  this->m_LeftBoundPos = this->m_FirstFrame;
  this->m_RightBoundPos = this->m_LastFrame;
  this->m_UnitStep = 1.0;
  this->m_TickDivider = 1;
#ifdef Q_OS_MAC
  QFont f = this->font();
  f.setPointSize(10); this->setFont(f);
  this->m_Fm = f;
#endif
  this->m_Mode = None;
  this->m_MovingEventIndex = -1;
  this->mp_Rubber = new QRubberBand(QRubberBand::Rectangle, this);
  
  ushort s;
  s = 0x25C9; this->m_EventSymbols[0].setUtf16(&s,1); // General: Fisheye
  s = 0x25C8; this->m_EventSymbols[1].setUtf16(&s,1); // Foot strike: White diamond containing black small diamond
  s = 0x25B2; this->m_EventSymbols[2].setUtf16(&s,1); // Foot off:    Black up-pointing triangle
  s = 0x25CF; this->m_EventSymbols[3].setUtf16(&s,1); // Black circle
  s = 0x25CE; this->m_EventSymbols[4].setUtf16(&s,1); // Bullseye
  s = 0x25D2; this->m_EventSymbols[5].setUtf16(&s,1); // Circle with lower half black
  s = 0x25D3; this->m_EventSymbols[6].setUtf16(&s,1); // Circle with upper half black
  s = 0x25BC; this->m_EventSymbols[7].setUtf16(&s,1); // Black down-pointing triangle
};

void TimeEventBarWidget::load(Acquisition* acq)
{
  this->m_SelectedEvents.clear();
  this->m_FirstFrame = acq->firstFrame();
  this->m_LastFrame = acq->lastFrame();
  this->m_ROIFirstFrame = this->m_FirstFrame;
  this->m_ROILastFrame = this->m_LastFrame;
  this->m_SliderPos = this->m_FirstFrame;
  this->m_LeftBoundPos = this->m_FirstFrame;
  this->m_RightBoundPos = this->m_LastFrame;
  
  this->m_EventItems.resize(acq->eventCount());
  int inc = 0;
  for (QMap<int,Event*>::const_iterator it = acq->events().begin() ; it != acq->events().end() ; ++it)
    this->setEventItem(this->m_EventItems[inc++], it.key(), it.value());
  
  this->setSliderValue(this->m_FirstFrame);
  this->updateInternals();
  this->update();
};

void TimeEventBarWidget::reset()
{
  this->m_SelectedEvents.clear();
  this->m_EventItems.clear();<commit_msg>[FIX] Mokka: The time bar is wrongly painted when the loaded acquisition has no frames.<commit_after>/* 
 * The Biomechanical ToolKit
 * Copyright (c) 2009-2011, <NAME>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *     * Redistributions of source code must retain the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *     * Neither the name(s) of the copyright holders nor the names
 *       of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written
 *       permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "TimeEventBarWidget.h"

#include <QtGui>
#include <QLinearGradient>
#include <QFontMetrics>

#include <cmath>
#define NUMLENGTH(num) ((num==0)?1:(int)log10(std::fabs((float)num))+1)

static int oldMouseX = 0;
static int oldEventFrame = 0;
static const int WBound = 10;
static const int WSlider = 10;
static const int TopMargin = 10;
static const int BottomMargin = 30;
static const int LeftMargin = 60;
static const int RightMargin = 30;
#ifdef Q_WS_WIN
static const qreal EventRelativePosY = 13.0;
static const qreal EventSymbolSize = 15.0;
static const QFont EventFont = QFont("Lucida Sans Unicode", 14);
#else
static const qreal EventRelativePosY = 16.0;
static const qreal EventSymbolSize = 12.0;
static const QFont EventFont = QFont("Arial", 12);
#endif
static const QColor MoveBrushColor = QColor(0, 127, 255, 128);
static const QColor BoundBrushColor = QColor(0, 127, 255, 64);
static const QPen MovePen = QColor(0, 127, 255);
static const QPen MoveShadowPen = QColor(100, 100, 100, 128);

TimeEventBarWidget::TimeEventBarWidget(QWidget* parent)
: QFrame(parent), m_EventContexts(), m_Ticks(), m_TicksLabel(), 
  m_Fm(this->font()), m_EventItems(), m_EventSymbols(8), m_SelectedEvents(),
  m_RubberOrigin()
{
  this->m_FirstFrame = 0;
  this->m_LastFrame = 0;
  this->m_ROIFirstFrame = this->m_FirstFrame;
  this->m_ROILastFrame = this->m_LastFrame;
  this->m_EventContexts << "Right" << "Left" << "General";
  this->m_SliderPos = this->m_FirstFrame;
  this->m_LeftBoundPos = this->m_FirstFrame;
  this->m_RightBoundPos = this->m_LastFrame;
  this->m_UnitStep = 1.0;
  this->m_TickDivider = 1;
#ifdef Q_OS_MAC
  QFont f = this->font();
  f.setPointSize(10); this->setFont(f);
  this->m_Fm = f;
#endif
  this->m_Mode = None;
  this->m_MovingEventIndex = -1;
  this->mp_Rubber = new QRubberBand(QRubberBand::Rectangle, this);
  
  ushort s;
  s = 0x25C9; this->m_EventSymbols[0].setUtf16(&s,1); // General: Fisheye
  s = 0x25C8; this->m_EventSymbols[1].setUtf16(&s,1); // Foot strike: White diamond containing black small diamond
  s = 0x25B2; this->m_EventSymbols[2].setUtf16(&s,1); // Foot off:    Black up-pointing triangle
  s = 0x25CF; this->m_EventSymbols[3].setUtf16(&s,1); // Black circle
  s = 0x25CE; this->m_EventSymbols[4].setUtf16(&s,1); // Bullseye
  s = 0x25D2; this->m_EventSymbols[5].setUtf16(&s,1); // Circle with lower half black
  s = 0x25D3; this->m_EventSymbols[6].setUtf16(&s,1); // Circle with upper half black
  s = 0x25BC; this->m_EventSymbols[7].setUtf16(&s,1); // Black down-pointing triangle
};

void TimeEventBarWidget::load(Acquisition* acq)
{
  this->m_SelectedEvents.clear();
  if (acq->pointFrameNumber() == 0)
  {
    this->m_FirstFrame = 0;
    this->m_LastFrame = 0;
  }
  else
  {
    this->m_FirstFrame = acq->firstFrame();
    this->m_LastFrame = acq->lastFrame();
  }
    
  this->m_ROIFirstFrame = this->m_FirstFrame;
  this->m_ROILastFrame = this->m_LastFrame;
  this->m_SliderPos = this->m_FirstFrame;
  this->m_LeftBoundPos = this->m_FirstFrame;
  this->m_RightBoundPos = this->m_LastFrame;
  
  this->m_EventItems.resize(acq->eventCount());
  int inc = 0;
  for (QMap<int,Event*>::const_iterator it = acq->events().begin() ; it != acq->events().end() ; ++it)
    this->setEventItem(this->m_EventItems[inc++], it.key(), it.value());
  
  this->setSliderValue(this->m_FirstFrame);
  this->updateInternals();
  this->update();
};

void TimeEventBarWidget::reset()
{
  this->m_SelectedEvents.clear();
  this->m_EventItems.clear();
{'fraction_non_alphanumeric': 0.12016668281810253, 'fraction_numerical': 0.029750944858997964, 'mean_word_length': 4.474801061007957, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4991530', 'n_tokens_mistral': 3681, 'n_tokens_neox': 3353, 'n_words': 1003}