/* This file is part of the KDE project
   Copyright (C) 2004 - 2007 Dag Andersen <danders@get2net.dk>
   Copyright (C) 2019 Dag Andersen <danders@get2net.dk>
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KPTTASKPROGRESSPANEL_H
#define KPTTASKPROGRESSPANEL_H

#include "planui_export.h"

#include "ui_kpttaskprogresspanelbase.h"
#include "kpttask.h"

#include <QWidget>


namespace KPlato
{

class StandardWorktime;
class Duration;
class ScheduleManager;
class MacroCommand;

//------------------------
class PLANUI_EXPORT TaskProgressPanelImpl : public QWidget, public Ui_TaskProgressPanelBase {
    Q_OBJECT
public:
    explicit TaskProgressPanelImpl(Task &task, QWidget *parent=0);

    void enableWidgets();

    void setYear(int year);

Q_SIGNALS:
    void changed();

public Q_SLOTS:
    void slotChanged();
    void slotEditmodeChanged(int idx);
    void slotStartedChanged(bool state);
    void slotFinishedChanged(bool state);
    void slotPercentFinishedChanged(int value);
    void slotStartTimeChanged(const QDateTime &dt);
    void slotFinishTimeChanged(const QDateTime &dt);
    void slotEntryChanged();
    void slotSelectionChanged(const QItemSelection &sel);

    void slotPrevWeekBtnClicked();
    void slotNextWeekBtnClicked();

    void updateResourceCombo();
    void slotEffortChanged(const QDate &date);

protected Q_SLOTS:
    void slotCalculateEffort();
    void slotFillWeekNumbers(int year);

protected:
    void setFinished();

    Task &m_task;
    Completion &m_original;
    Completion m_completion;
    int m_dayLength;

    Duration scheduledEffort;
    int m_weekOffset;
    int m_year;
    bool m_firstIsPrevYear;
    bool m_lastIsNextYear;
};

class PLANUI_EXPORT TaskProgressPanel : public TaskProgressPanelImpl {
    Q_OBJECT
public:
    explicit TaskProgressPanel(Task &task, ScheduleManager *sm, StandardWorktime *workTime=0, QWidget *parent=0);

    MacroCommand *buildCommand();

    static MacroCommand *buildCommand(const Project &project, Completion &org, Completion &curr);

protected Q_SLOTS:
    void slotWeekNumberChanged(int);
    void slotEntryAdded(const QDate &date);
};

}  //KPlato namespace

#endif // TASKPROGRESSPANEL_H
