/*[
 * This file is part of the SharedComponents Software.
 * 
 * Copyright 2008 Paradigm B.V. and/or its affiliates and subsidiaries.
 * All rights reserved.
 * 
 * Use of this software is subject to the terms and conditions of the license
 * agreement with Paradigm Geophysical B.V. and/or its affiliates and
 * subsidiaries (collectively "Paradigm").
 * 
 * Warning: This computer program is protected by copyright law and international
 * treaties. Unauthorized reproduction or distribution of this program, or any
 * portion of it, may result in severe civil and criminal penalties, and will be
 * prosecuted to the maximum extent possible under the law.
]*/

#ifndef PDGM_WIDGETS_EXPANDABLEFRAME_H
#define PDGM_WIDGETS_EXPANDABLEFRAME_H

#include <widgets/export.h>

#include <QtGui/QFrame>
#include <QtGui/QMouseEvent>
#include <QtGui/QPaintEvent>
#include <QtGui/QCursor>
#include <QtCore/QString>


namespace pdgm {
namespace gui {

class PDGM_WIDGETS_EXPORT ExpandableFrame : public QFrame {
    Q_OBJECT
    Q_ENUMS(HeaderPad)
    Q_PROPERTY( QString title READ title WRITE setTitle )

public:
    
    enum HeaderPad { DefaultHeaderPad = 3 };

    ExpandableFrame(QWidget* parent = 0);

    ExpandableFrame(const QString& title, 
        QWidget* parent);

    virtual ~ExpandableFrame();

    QString title() const;
    void setTitle(const QString& title);

    int headerPad() const;
    void setHeaderPad(int pad);

    virtual QSize sizeHint() const;

    QWidget* widget() const;
    void setWidget(QWidget* widget);
    QWidget* takeWidget();

protected:
    virtual bool event(QEvent *event);
    virtual void paintEvent(QPaintEvent* event);

private:
    QSize headerSize() const;
    bool updateHeaderSize();

    const QWidget* sizeHintComputerWidget() const;

    void updatePointer(const QPoint& pos);

private: 
    QString title_;

    int headerPad_;
    QSize headerSize_;
    int topMargin_;

    QWidget* widget_;

    QCursor cursor_;
    bool cursorOverHeader_;
};

}} //namespace pdgm::gui

#endif

