/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2015 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#ifndef OSGEARTHQT_ANNOTATIONLISTWIDGET_H
#define OSGEARTHQT_ANNOTATIONLISTWIDGET_H 1

#include <osgEarthQt/Actions>
#include <osgEarthQt/AnnotationDialogs>
#include <osgEarthQt/CollapsiblePairWidget>
#include <osgEarthQt/Common>
#include <osgEarthQt/DataManager>

#include <QAction>
#include <QFrame>
#include <QLabel>
#include <QListWidget>
#include <QPointer>
#include <QScrollArea>
#include <QWidget>

namespace osgEarth { namespace QtGui 
{
    using namespace osgEarth;

    class OSGEARTHQT_EXPORT AnnotationListWidget : public CollapsiblePairWidget
    {
    Q_OBJECT

    public:
      AnnotationListWidget(DataManager* dm);
      virtual ~AnnotationListWidget() { }

      void setActiveView(osgViewer::View* view);
      void setActiveViews(const ViewVector& views);

    private slots:
      void onMapChanged();
      void onSelectionChanged(/*const AnnotationVector& selection*/);
      void onItemDoubleClicked(QListWidgetItem* item);
      void onItemChanged(QListWidgetItem* item);
      void onListSelectionChanged();
      void onRemoveSelected();
      void onEditSelected();
      void onAddFinished(int result);

    protected:
      friend class AnnotationListActionCallbackProxy;

      void initialize();
      void refresh();

      QListWidget*  _annoList;
      QScrollArea*  _detailsScroll;
      QFrame*       _detailsBox;
      QLabel*       _nameField;
      QLabel*       _priorityField;
      QLabel*       _viewpointField;
      QLabel*       _descriptionField;
      QAction*      _removeAction;
      QAction*      _editAction;

      QPointer<BaseAnnotationDialog>  _activeDialog;

      osg::ref_ptr<DataManager>  _manager;
      ViewVector                 _views;
      int                        _updating;
    };
} }

#endif // OSGEARTHQT_ANNOTATIONLISTWIDGET_H
