Commit 04194d3a authored by allens's avatar allens

reworte the collapsable gui

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@23922 18c085ea-50e0-402c-830e-de6fd14e8384
parent 171bae80
......@@ -90,6 +90,7 @@ QvisAppearanceWindow.C
QvisApplication.C
QvisAxisAttributesWidget.C
QvisCMFEWizard.C
QvisCollapsibleFrame.C
QvisColorButton.C
QvisColorGridWidget.C
QvisColorManagerWidget.C
......@@ -221,7 +222,6 @@ SimCommandSlots.C
SplashScreen.C
WidgetDataNode.C
mini3D.C
QvisCollapsiblePanel.C
)
# The subset of the sources that have Q_OBJECT in their header.
......@@ -330,6 +330,7 @@ QvisSimulationMessageWindow.h
QvisSimulationCommandWindow.h
QvisFileOpenDialog.h
QvisCMFEWizard.h
QvisCollapsibleFrame.h
QvisColorManagerWidget.h
QvisColorSwatchListWidget.h
QvisSILSetSelector.h
......@@ -357,7 +358,6 @@ QvisKeyframeWidget.h
QvisKeyframePlotRangeWidget.h
QvisViewportWidget.h
QvisXRayImageQueryWidget.h
QvisCollapsiblePanel.h
)
QT_WRAP_CPP(gui GUILIB_SOURCES ${GUILIB_MOC_SOURCES})
......
/*****************************************************************************
*
* Copyright (c) 2000 - 2014, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* 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 disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY 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.
*
* This code file was originally inspired by the Mantid Project:
* http://www.mantidproject.org/.
*
*****************************************************************************/
#include "QvisCollapsibleFrame.h"
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QFontMetrics>
#include <QPolygon>
#include <QTimer>
// ****************************************************************************
// Class: QvisTitleBar::QvisTitleBar
//
// Purpose:
// Creates a title bar that goes across the frame
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
QvisTitleBar::QvisTitleBar(const QString& title, QWidget* parent) :
QLabel(title, parent), state(Exposed)
{
setFrameStyle(QFrame::WinPanel);
setFrameShadow(QFrame::Raised);
}
// ****************************************************************************
// Class: QvisTitleBar::mousePressEvent
//
// Purpose:
// Captures the mouse events for collapsing or expanding the frame.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisTitleBar::mousePressEvent(QMouseEvent* event)
{
if (event->buttons() & Qt::LeftButton)
{
event->accept();
if( state == Hidden )
state = Exposed;
else // if( state == Exposed )
state = Hidden;
// Send a signal out that will trigger the associated widget to be
// exposed or hidden.
emit showOrHide( state );
}
else
{
event->ignore();
}
}
// ****************************************************************************
// Class: QvisTitleBar::paintEvent
//
// Purpose:
// Creates arrow indicating whether the panel is collapsed or expanded.
// This methos is called after a mouse event which will updates the state.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisTitleBar::paintEvent(QPaintEvent *event)
{
// Update the label as normal.
QLabel::paintEvent(event);
QFontMetrics fm(this->font());
int s = (fm.height() - 4);
// Update the label to have a plus/minus sign and an arrow.
if (s > 0)
{
QPainter painter(this);
painter.setBrush(QBrush(QColor(Qt::black)));
int x = this->width() - 2*s;
int y = (this->height() - s) / 2;
QPolygon triangle(3);
if( state == Exposed )
{
painter.drawText(x - s, y + s*3/4, "-" );
// Downward pointing arrow
triangle.setPoint(0, x, y);
triangle.setPoint(1, x + s, y);
triangle.setPoint(2, x + s/2, y + s);
}
else // if( state == Hidden )
{
painter.drawText(x - s, y + s*3/4, "+" );
// Left pointing arrow
triangle.setPoint(0, x, y);
triangle.setPoint(1, x, y + s);
triangle.setPoint(2, x + s, y + s/2);
}
painter.drawPolygon(triangle);
}
}
// ****************************************************************************
// Class: QvisTitleBar::setShow
//
// Purpose:
// Manually sets the state to show and shows the associated widget
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisTitleBar::setShow()
{
state = Exposed;
emit showOrHide(state);
}
// ****************************************************************************
// Class: QvisTitleBar::setHide
//
// Purpose:
// Manually sets the state to hide and hides the associated widget
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisTitleBar::setHide()
{
state = Hidden;
emit showOrHide(state);
}
// ****************************************************************************
// Class: QvisCollapsibleFrame::QvisCollapsibleFrame
//
// Purpose:
// This class creates a titlebar (label) and a frame (layout) that contains
// a widget that get shown or hidden.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
QvisCollapsibleFrame::QvisCollapsibleFrame(const QString& title,
QWidget* parent) :
QWidget(parent), widget(NULL)
{
titleBar = new QvisTitleBar(title,this);
layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget( titleBar);
// The titlebar will send a signal with state that the frame needs
// to process, i.e. show or hide the associated widget.
connect(titleBar, SIGNAL(showOrHide(QvisTitleBar::LayoutState)), this,
SLOT(showOrHide(QvisTitleBar::LayoutState)));
}
// ****************************************************************************
// Class: QvisCollapsibleFrame::~QvisCollapsibleFrame
//
// Purpose:
// This class is a label and a layout (panel) for widgets
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
QvisCollapsibleFrame::~QvisCollapsibleFrame()
{
delete titleBar;
delete layout;
}
// ****************************************************************************
// Class: QvisCollapsibleFrame::setWidget
//
// Purpose: Sets the widget that will be contained in the layout. Only
// one widget per layout (panel).
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisCollapsibleFrame::setWidget(QWidget* w)
{
widget = w;
widget->setParent(this);
// Add the widget to the layout.
layout->addWidget(widget);
}
// ****************************************************************************
// Class: QvisCollapsibleFrame::showOrHide
//
// Purpose:
// QT slot that shows or hides the widget associated with the frame (layout).
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisCollapsibleFrame::showOrHide(QvisTitleBar::LayoutState state)
{
if (!widget)
return;
if (state == QvisTitleBar::Exposed)
widget->show();
else // if (state == QvisTitleBar::Hidden)
widget->hide();
// Now that the widget is exposed or hidden send another signal to
// update the layout to be the right size.
emit invalidateLayout();
}
// ****************************************************************************
// Class: QvisCollapsibleFrame::setShow
//
// Purpose:
// Manually shows the associated widget and updates the titlebar.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisCollapsibleFrame::setShow()
{
titleBar->setShow();
showOrHide( QvisTitleBar::Exposed );
}
// ****************************************************************************
// Class: QvisCollapsibleFrame::setHide
//
// Purpose:
// Manually hides the associated widget and updates the titlebar.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisCollapsibleFrame::setHide()
{
titleBar->setHide();
showOrHide( QvisTitleBar::Hidden );
}
// ****************************************************************************
// Class: QvisCollapsibleLayout::QvisCollapsibleLayout
//
// Purpose:
// This class (QWidget) manages the collapsable frames using a layout
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
QvisCollapsibleLayout::QvisCollapsibleLayout(QWidget* parent) : QWidget(parent)
{
layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
// Add the layout to the base widget.
setLayout(layout);
}
// ****************************************************************************
// Class: QvisCollapsibleLayout::~QvisCollapsibleLayout
//
// Purpose:
// This class creates layout for managing collapsable frames.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
QvisCollapsibleLayout::~QvisCollapsibleLayout()
{
delete layout;
}
// ****************************************************************************
// Class: QvisCollapsibleLayout::addFrame
//
// Purpose:
// Adds a new collapsable frame to the layout.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
QvisCollapsibleFrame* QvisCollapsibleLayout::addFrame(const QString& title,
QWidget* widget)
{
QvisCollapsibleFrame *frame = new QvisCollapsibleFrame(title, this);
frame->setWidget(widget);
layout->addWidget(frame);
// The frame will send a signal that the layout needs to be resized.
connect(frame, SIGNAL(invalidateLayout()), this, SLOT(invalidateLayout()));
// Return the frame so the user can manually set the state.
return frame;
}
// ****************************************************************************
// Class: QvisCollapsibleLayout::invalidateLayout
//
// Purpose: QT slot that invalidates the layout then forces the
// parent window to resize the layout after a show/hide event.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisCollapsibleLayout::invalidateLayout()
{
if (layout->count() == 0)
return;
layout->invalidate();
// Use the timer to set up the adjustWindowSize as it can not be
// called directly.
QTimer::singleShot(0, this, SLOT(adjustWindowSize()));
emit adjustWindowSize();
}
// ****************************************************************************
// Class: QvisCollapsibleLayout::adjustWindowSize
//
// Purpose: QT slot that forces the parent window to resize after
// a show/hide event.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
void QvisCollapsibleLayout::adjustWindowSize()
{
QWidget *parent = layout->parentWidget();
while (parent)
{
parent->adjustSize();
parent = parent->parentWidget();
}
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2014, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* 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 disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY 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.
*
* This code file was originally inspired by the Mantid Project:
* http://www.mantidproject.org/.
*
*****************************************************************************/
#ifndef QVISCOLLAPSIBLEFRAME_H_
#define QVISCOLLAPSIBLEFRAME_H_
#include <QLabel>
#include <gui_exports.h>
class QVBoxLayout;
// ****************************************************************************
// Class: QvisTitleBar
//
// Purpose:
// This class is a title bar (aka QLabel) with a state variable
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
class GUI_API QvisTitleBar : public QLabel
{
Q_OBJECT
public:
enum LayoutState { Hidden, Exposed };
QvisTitleBar(const QString& title, QWidget* parent);
void mousePressEvent(QMouseEvent* event);
void paintEvent(QPaintEvent *event);
void setShow();
void setHide();
signals: // Used to communicate with the associated frame.
void showOrHide(QvisTitleBar::LayoutState state);
private:
LayoutState state;
};
// ****************************************************************************
// Class: QvisCollapsibleFrame
//
// Purpose:
// This class creates a titlebar (label) and a frame (layout) that contains
// a widget that get shown or hidden.
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
class GUI_API QvisCollapsibleFrame : public QWidget
{
Q_OBJECT
public:
QvisCollapsibleFrame(const QString& title, QWidget* parent);
~QvisCollapsibleFrame();
void setWidget(QWidget* w);
void setShow();
void setHide();
signals: // Used to communicate with the parent layout.
void invalidateLayout();
private slots: // Used to communicate with the associated titlebar.
void showOrHide(QvisTitleBar::LayoutState state);
private:
QvisTitleBar* titleBar;
QVBoxLayout* layout;
QWidget *widget;
};
// ****************************************************************************
// Class: QvisCollapsibleLayout
//
// Purpose:
// This class (QWidget) manages the collapsable frames using a layout
//
// Programmer: Allen Sanderson
// Creation: 23 July 2014
//
class GUI_API QvisCollapsibleLayout : public QWidget
{
Q_OBJECT
public:
QvisCollapsibleLayout(QWidget* parent);
~QvisCollapsibleLayout();
QvisCollapsibleFrame* addFrame(const QString& title, QWidget* widget);
private slots: // Used to communicate with the child frames.
void invalidateLayout();
void adjustWindowSize();
private:
QVBoxLayout* layout;
};
#endif /*QVISCOLLAPSIBLEFRAME_H_*/
/*****************************************************************************
*
* This file is part of Mantid. For details, see http://www.mantidproject.org/.
* The full copyright notice is contained in:
* http://www.mantidproject.org/Mantid:About#License_and_Distribution.
*
* Mantid is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* Mantid 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
* General Public License for more details: http://www.gnu.org/licenses.
*
*****************************************************************************/
#include "QvisCollapsiblePanel.h"
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QFontMetrics>
#include <QPolygon>
#include <QTimer>
#include <stdexcept>
#include <iostream>
// ****************************************************************************
// Class: QvisCaptionLabel::QvisCaptionLabel
//
// Purpose:
// Creates a label that goes across the frame
//
// Notes:
//
// Programmer: MANTiD Project
// Creation:
//
// Modifications:
//
// Allen Sanderson : The original class name has been changed to
// relfect the VisIt name style.
//
QvisCaptionLabel::QvisCaptionLabel(const QString& caption,
QWidget* parent) :
QLabel(caption,parent), m_collapsed(false)
{
setFrameStyle(QFrame::WinPanel);
setFrameShadow(QFrame::Raised);
}
// ****************************************************************************
// Class: QvisCaptionLabel::mousePressEvent
//
// Purpose:
// Captures the mouse events for collapsing or expanding the panel.
//
// Notes:
//
// Programmer: MANTiD Project
// Creation:
//
// Modifications:
//
// Allen Sanderson : The original class name has been changed to
// relfect the VisIt name style.
//
void QvisCaptionLabel::mousePressEvent(QMouseEvent* e)
{
if (e->buttons() & Qt::LeftButton)
{
e->accept();
m_collapsed = !m_collapsed;
emit collapseOrExpand(m_collapsed);
}
else
{
e->ignore();
}
}
// ****************************************************************************
// Class: QvisCaptionLabel::paintEvent
//
// Purpose:
// Creates arrow indicating whether the panel is collapsed or expanded.
//
// Notes:
//
// Programmer: MANTiD Project