/*============================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center (DKFZ)
All rights reserved.

Use of this source code is governed by a 3-clause BSD license that can be
found in the LICENSE file.

============================================================================*/

#ifndef QmitkMemoryUsageIndicatorView_h
#define QmitkMemoryUsageIndicatorView_h

#include <MitkQtWidgetsExports.h>

#include <QWidget>

#include <array>
#include <utility>
#include <memory>

namespace Ui
{
  class QmitkMemoryUsageIndicator;
}

/** \brief Widget that displays the current process memory usage.
 *
 * Shows memory usage as a percentage bar with an icon that changes
 * based on usage thresholds. Updates periodically via a timer.
 *
 * \ingroup QmitkModule
 */
class MITKQTWIDGETS_EXPORT QmitkMemoryUsageIndicatorView : public QWidget
{
  Q_OBJECT

public:
  /** \brief Construct the memory usage indicator.
   * \param[in] parent Parent widget.
   */
  QmitkMemoryUsageIndicatorView(QWidget* parent = nullptr);
  ~QmitkMemoryUsageIndicatorView() override;

private:
  void UpdateMemoryUsage();
  std::string FormatMemorySize(size_t size);
  std::string FormatPercentage(double val);
  std::string GetMemoryDescription(size_t processSize, float percentage);

  std::unique_ptr<Ui::QmitkMemoryUsageIndicator> m_Ui;
  size_t m_PreviousState;
  std::array<std::pair<float, QPixmap>, 4> m_States;
};

#endif
