mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1337 Changed the GroupBoxes to MinimizePanels to increase readability and allow collapsing of the groups.
This commit is contained in:
parent
5b934b1747
commit
a1d14dc8a3
@ -42,6 +42,7 @@ set( QOBJECT_HEADERS
|
||||
cafPdmUiTreeViewModel.h
|
||||
cafPdmUiTreeViewEditor.h
|
||||
cafUiProcess.h
|
||||
QMinimizePanel.h
|
||||
)
|
||||
|
||||
if ( (${CMAKE_VERSION} VERSION_LESS 2.8.6) OR (NOT CMAKE_AUTOMOC) )
|
||||
@ -121,6 +122,8 @@ set( PROJECT_FILES
|
||||
cafProgressInfo.h
|
||||
cafUiProcess.cpp
|
||||
cafUiProcess.h
|
||||
QMinimizePanel.cpp
|
||||
QMinimizePanel.h
|
||||
)
|
||||
|
||||
add_library( ${PROJECT_NAME}
|
||||
|
253
Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp
Normal file
253
Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp
Normal file
@ -0,0 +1,253 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// QMinimizePanel
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This class may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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.
|
||||
//
|
||||
// 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library 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.1 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
#include "QMinimizePanel.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
#include <QLabel>
|
||||
#include "QApplication"
|
||||
#include <QPixmap>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
static const struct {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
|
||||
unsigned char pixel_data[7 * 10 * 4 + 1];
|
||||
} expandDownArrow = {
|
||||
7, 10, 4,
|
||||
"QRY\317445A\0\0\0\0\0\0\0\0\0\0\0\0""445AJJN\317OQW\256OPW\317445#\0\0\0"
|
||||
"\0""445#IJP\317HIN\256445#MOT\317LMS\317445#IJP\317GHM\317445#\0\0\0\0""4"
|
||||
"45#DEK\317??C\317BBG\317445#\0\0\0\0\0\0\0\0\0\0\0\0""445#>?B\317445#\0\0"
|
||||
"\0\0\0\0\0\0LNT\317445A\0\0\0\0\0\0\0\0\0\0\0\0""445ACEI\317JKR\256IJP\317"
|
||||
"445#\0\0\0\0""445#DEH\317BCJ\256445#GHO\317EGK\317445#DEH\317BDI\317445#"
|
||||
"\0\0\0\0""445#@AE\317??C\317??B\317445#\0\0\0\0\0\0\0\0\0\0\0\0""445#<<?"
|
||||
"\317445#\0\0\0\0\0\0\0\0",
|
||||
};
|
||||
|
||||
QIcon createExpandDownIcon()
|
||||
{
|
||||
QImage img(expandDownArrow.pixel_data,expandDownArrow.width, expandDownArrow.height, QImage::Format_ARGB32 );
|
||||
QPixmap pxMap;
|
||||
pxMap = QPixmap::fromImage(img);
|
||||
|
||||
return QIcon(pxMap);
|
||||
}
|
||||
|
||||
static const QIcon& expandDownIcon()
|
||||
{
|
||||
static QIcon expandDownIcon(createExpandDownIcon());
|
||||
return expandDownIcon;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
static const struct {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
|
||||
unsigned char pixel_data[7 * 10 * 4 + 1];
|
||||
} expandUpArrow = {
|
||||
7, 10, 4,
|
||||
"\0\0\0\0\0\0\0\0""445#<<?\317445#\0\0\0\0\0\0\0\0\0\0\0\0""445#@AE\317??"
|
||||
"C\317??B\317445#\0\0\0\0""445#GHO\317EGK\317445#DEH\317BDI\317445#JKR\256"
|
||||
"IJP\317445#\0\0\0\0""445#DEH\317BCJ\256LNT\317445A\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0""445ACEI\317\0\0\0\0\0\0\0\0""445#>?B\317445#\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"""445#DEK\317??C\317BBG\317445#\0\0\0\0""445#MOT\317LMS\317445#IJP\317GH"
|
||||
"M\317445#OQW\256OPW\317445#\0\0\0\0""445#IJP\317HIN\256QRY\317445A\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0""445AJJN\317",
|
||||
};
|
||||
|
||||
QIcon createExpandUpIcon()
|
||||
{
|
||||
QImage img(expandUpArrow.pixel_data,expandUpArrow.width, expandUpArrow.height, QImage::Format_ARGB32 );
|
||||
QPixmap pxMap;
|
||||
pxMap = QPixmap::fromImage(img);
|
||||
|
||||
return QIcon(pxMap);
|
||||
}
|
||||
|
||||
static const QIcon& expandUpIcon()
|
||||
{
|
||||
static QIcon expandUpIcon(createExpandUpIcon());
|
||||
return expandUpIcon;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMinimizePanel::QMinimizePanel(QWidget* parent/*=0*/)
|
||||
{
|
||||
this->initialize("");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMinimizePanel::QMinimizePanel(const QString &title, QWidget* parent/*=0*/)
|
||||
{
|
||||
this->initialize(title);
|
||||
}
|
||||
|
||||
void QMinimizePanel::initialize(const QString &title)
|
||||
{
|
||||
m_titleFrame = new QFrame(this);
|
||||
m_titleFrame->setFrameStyle(QFrame::Box | QFrame::Plain);
|
||||
m_titleFrame->setAutoFillBackground(true);
|
||||
|
||||
{
|
||||
QLinearGradient titleGrad(QPointF(0, 0), QPointF(0, 1));
|
||||
titleGrad.setCoordinateMode(QGradient::StretchToDeviceMode);
|
||||
titleGrad.setColorAt(0, QColor(255, 255, 255, 20));
|
||||
titleGrad.setColorAt(1, QColor(0, 0, 0, 30));
|
||||
|
||||
QPalette titleFramePalette = m_titleFrame->palette();
|
||||
titleFramePalette.setBrush(QPalette::Window, titleGrad);
|
||||
titleFramePalette.setBrush(QPalette::Foreground, titleFramePalette.dark());
|
||||
m_titleFrame->setPalette(titleFramePalette);
|
||||
}
|
||||
|
||||
m_titleLabel = new QLabel(title, m_titleFrame);
|
||||
m_titleLabel->setPalette(QApplication::palette()); // To avoid title foreground color bleeding through
|
||||
|
||||
m_collapseButton = new QPushButton( m_titleFrame);
|
||||
m_collapseButton->setFlat(true);
|
||||
m_collapseButton->setIcon(expandUpIcon());
|
||||
|
||||
m_contentFrame = new QFrame(this);
|
||||
m_contentFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
|
||||
m_contentFrame->setAutoFillBackground(true);
|
||||
|
||||
QPalette contentFramePalette = m_contentFrame->palette();
|
||||
contentFramePalette.setBrush(QPalette::Window, QColor(255,250,250,85));
|
||||
//contentFramePalette.setBrush(QPalette::Foreground, contentFramePalette.dark());
|
||||
m_contentFrame->setPalette(contentFramePalette);
|
||||
|
||||
connect(m_collapseButton, SIGNAL(clicked()),this, SLOT(toggleExpanded()) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMinimizePanel::~QMinimizePanel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::setTitle(const QString& title)
|
||||
{
|
||||
m_titleLabel->setText(title);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::setExpanded(bool isExpanded)
|
||||
{
|
||||
m_contentFrame->setVisible(isExpanded);
|
||||
isExpanded ? m_collapseButton->setIcon(expandUpIcon()) : m_collapseButton->setIcon(expandDownIcon());
|
||||
this->QWidget::updateGeometry();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::toggleExpanded()
|
||||
{
|
||||
setExpanded(!m_contentFrame->isVisible());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize QMinimizePanel::minimumSizeHint() const
|
||||
{
|
||||
QSize labelSize = m_titleLabel->sizeHint();
|
||||
QSize titleBarHint = labelSize + QSize(4 + labelSize.height() + 8 - 2 + 1, 8);
|
||||
|
||||
if (m_contentFrame->isVisible())
|
||||
{
|
||||
QSize titleBarMin(0, labelSize.height() + 8 );
|
||||
QSize contentsMin(m_contentFrame->minimumSizeHint());
|
||||
QSize total = contentsMin.expandedTo(titleBarMin);
|
||||
total.rheight() += titleBarMin.height();
|
||||
return total;
|
||||
}
|
||||
else
|
||||
{
|
||||
return titleBarHint;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::resizeEvent(QResizeEvent *resizeEv )
|
||||
{
|
||||
QWidget::updateGeometry();
|
||||
|
||||
int width = resizeEv->size().width();
|
||||
int heigth = resizeEv->size().height();
|
||||
int labelHeight = m_titleLabel->sizeHint().height();
|
||||
int titleHeight = labelHeight + 8;
|
||||
|
||||
int buttonSize = titleHeight - 2;
|
||||
|
||||
m_titleFrame->setGeometry(0,0,width, titleHeight);
|
||||
m_titleLabel->setGeometry( 4, titleHeight - labelHeight - 4, width - buttonSize - 1, labelHeight);
|
||||
m_collapseButton->setGeometry(width - buttonSize - 1, 1, buttonSize, buttonSize);
|
||||
|
||||
m_contentFrame->setGeometry(0, titleHeight-1, width, heigth - titleHeight-1);
|
||||
}
|
||||
|
||||
bool QMinimizePanel::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::LayoutRequest)
|
||||
{
|
||||
this->QWidget::updateGeometry();
|
||||
}
|
||||
|
||||
return this->QWidget::event(event);
|
||||
}
|
74
Fwk/AppFwk/cafUserInterface/QMinimizePanel.h
Normal file
74
Fwk/AppFwk/cafUserInterface/QMinimizePanel.h
Normal file
@ -0,0 +1,74 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// QMinimizePanel
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This class may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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.
|
||||
//
|
||||
// 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 General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library 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.1 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QFrame;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
|
||||
class QMinimizePanel: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QMinimizePanel(QWidget* parent=0);
|
||||
explicit QMinimizePanel(const QString &title, QWidget* parent=0);
|
||||
~QMinimizePanel();
|
||||
|
||||
QFrame * contentFrame() { return m_contentFrame; }
|
||||
void setTitle (const QString& title);
|
||||
|
||||
public slots:
|
||||
void setExpanded(bool isExpanded);
|
||||
void toggleExpanded();
|
||||
public:
|
||||
virtual QSize minimumSizeHint() const override;
|
||||
|
||||
protected:
|
||||
QFrame* m_titleFrame;
|
||||
QLabel* m_titleLabel;
|
||||
QPushButton* m_collapseButton;
|
||||
QFrame* m_contentFrame;
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *) override;
|
||||
virtual bool event(QEvent* event) override; // To catch QEvent::LayoutRequest
|
||||
|
||||
private:
|
||||
void initialize(const QString &title);
|
||||
};
|
||||
|
@ -157,8 +157,8 @@ void PdmUiDefaultObjectEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
|
||||
// Remove all unmentioned group boxes
|
||||
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator itOld;
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator itNew;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator itOld;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator itNew;
|
||||
|
||||
for (itOld = m_groupBoxes.begin(); itOld != m_groupBoxes.end(); ++itOld )
|
||||
{
|
||||
@ -187,7 +187,7 @@ void PdmUiDefaultObjectEditor::cleanupBeforeSettingPdmObject()
|
||||
|
||||
m_newGroupBoxes.clear();
|
||||
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator groupIt;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator groupIt;
|
||||
for (groupIt = m_groupBoxes.begin(); groupIt != m_groupBoxes.end(); ++groupIt)
|
||||
{
|
||||
if (!groupIt->second.isNull()) groupIt->second->deleteLater();
|
||||
@ -214,19 +214,19 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
const std::vector<PdmUiItem*>& groupChildren = group->uiItems();
|
||||
|
||||
QString groupBoxKey = uiItems[i]->uiName();
|
||||
QGroupBox* groupBox = NULL;
|
||||
QMinimizePanel* groupBox = NULL;
|
||||
QGridLayout* groupBoxLayout = NULL;
|
||||
|
||||
// Find or create groupBox
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator it;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator it;
|
||||
it = m_groupBoxes.find(groupBoxKey);
|
||||
|
||||
if (it == m_groupBoxes.end())
|
||||
{
|
||||
groupBox = new QGroupBox( parent );
|
||||
groupBox = new QMinimizePanel( parent );
|
||||
groupBox->setTitle(uiItems[i]->uiName());
|
||||
groupBoxLayout = new QGridLayout();
|
||||
groupBox->setLayout(groupBoxLayout);
|
||||
groupBox->contentFrame()->setLayout(groupBoxLayout);
|
||||
|
||||
m_newGroupBoxes[groupBoxKey] = groupBox;
|
||||
}
|
||||
@ -235,7 +235,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
groupBox = it->second;
|
||||
CAF_ASSERT(groupBox);
|
||||
|
||||
groupBoxLayout = dynamic_cast<QGridLayout*>(groupBox->layout());
|
||||
groupBoxLayout = dynamic_cast<QGridLayout*>(groupBox->contentFrame()->layout());
|
||||
CAF_ASSERT(groupBoxLayout);
|
||||
|
||||
m_newGroupBoxes[groupBoxKey] = groupBox;
|
||||
@ -244,7 +244,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
/// Insert the group box at the correct position of the parent layout
|
||||
|
||||
parentLayout->addWidget(groupBox, currentRowIndex, 0, 1, 2);
|
||||
recursiveSetupFieldsAndGroups(groupChildren, groupBox, groupBoxLayout, uiConfigName);
|
||||
recursiveSetupFieldsAndGroups(groupChildren, groupBox->contentFrame(), groupBoxLayout, uiConfigName);
|
||||
currentRowIndex++;
|
||||
}
|
||||
else
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include "QMinimizePanel.h"
|
||||
|
||||
class QGridLayout;
|
||||
|
||||
@ -81,8 +82,8 @@ private:
|
||||
void recursiveVerifyUniqueNames(const std::vector<PdmUiItem*>& uiItems, const QString& uiConfigName, std::set<QString>* fieldKeywordNames, std::set<QString>* groupNames);
|
||||
|
||||
std::map<PdmFieldHandle*, PdmUiFieldEditorHandle*> m_fieldViews;
|
||||
std::map<QString, QPointer<QGroupBox> > m_groupBoxes;
|
||||
std::map<QString, QPointer<QGroupBox> > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
|
||||
std::map<QString, QPointer<QMinimizePanel> > m_groupBoxes;
|
||||
std::map<QString, QPointer<QMinimizePanel> > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
|
||||
|
||||
QPointer<QWidget> m_mainWidget;
|
||||
QPointer<QGridLayout> m_layout;
|
||||
|
Loading…
Reference in New Issue
Block a user