1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file GUI/coregui/Views/AccordionWidget/ContentPane.cpp
//! @brief Implements ContentPane class
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************** //
// This file is part of qAccordion. An Accordion widget for Qt
// Copyright (C) 2015 Christian Rapp <0x2a at posteo dot org>
//
// This program 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 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "GUI/coregui/Views/AccordionWidget/ContentPane.h"
namespace clickcon = ClickableFrame_constants;
ContentPane::ContentPane(QString header, QWidget* parent) : QWidget(parent)
{
this->content = nullptr;
this->initDefaults(std::move(header));
}
ContentPane::ContentPane(QString header, QFrame* content, QWidget* parent)
: QWidget(parent), content(content)
{
this->initDefaults(std::move(header));
}
bool ContentPane::getActive()
{
return this->active;
}
QFrame* ContentPane::getContentFrame()
{
return this->content;
}
void ContentPane::setContentFrame(QFrame* content)
{
this->container->layout()->removeWidget(this->content);
if (this->content != nullptr)
delete (this->content);
this->content = content;
dynamic_cast<QVBoxLayout*>(this->container->layout())->insertWidget(0, this->content);
}
int ContentPane::getMaximumHeight()
{
return this->container->maximumHeight();
}
void ContentPane::setMaximumHeight(int maxHeight)
{
this->containerAnimationMaxHeight = maxHeight;
if (this->getActive())
this->container->setMaximumHeight(this->containerAnimationMaxHeight);
this->openAnimation->setEndValue(this->containerAnimationMaxHeight);
this->closeAnimation->setStartValue(this->containerAnimationMaxHeight);
}
void ContentPane::setHeader(QString header)
{
this->header->setHeader(std::move(header));
}
QString ContentPane::getHeader()
{
return this->header->getHeader();
}
void ContentPane::setHeaderTooltip(QString tooltip)
{
this->header->setToolTip(tooltip);
}
QString ContentPane::getHeaderTooltip()
{
return this->header->toolTip();
}
void ContentPane::setHeaderStylesheet(QString stylesheet)
{
this->header->setNormalStylesheet(std::move(stylesheet));
}
QString ContentPane::getHeaderStylesheet()
{
return this->header->getNormalStylesheet();
}
void ContentPane::setHeaderHoverStylesheet(QString stylesheet)
{
this->header->setHoverStylesheet(std::move(stylesheet));
}
QString ContentPane::getHeaderHoverStylesheet()
{
return this->header->getHoverStylesheet();
}
void ContentPane::setHeaderFrameStyle(int style)
{
this->header->setFrameStyle(style);
}
int ContentPane::getHeaderFrameStyle()
{
return this->header->frameStyle();
}
void ContentPane::setContainerFrameStyle(int style)
{
this->container->setFrameStyle(style);
}
int ContentPane::getContainerFrameStyle()
{
return this->container->frameStyle();
}
void ContentPane::openContentPane()
{
if (this->getActive())
return;
this->openAnimation->start();
this->header->setCaretPixmap(clickcon::CARRET_ICON_OPENED);
this->active = true;
}
void ContentPane::closeContentPane()
{
if (!this->getActive())
return;
this->closeAnimation->start();
this->header->setCaretPixmap(clickcon::CARRET_ICON_CLOSED);
this->active = false;
}
void ContentPane::initDefaults(QString header)
{
this->active = false;
this->headerFrameStyle = QFrame::Shape::StyledPanel | QFrame::Shadow::Raised;
this->contentPaneFrameStyle = QFrame::Shape::StyledPanel | QFrame::Shadow::Plain;
this->containerAnimationMaxHeight = 150;
// TODO: Why do I need to set the vertial policy to Maximum? from the api
// documentation Minimum would make more sens :/
this->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Maximum);
this->setLayout(new QVBoxLayout());
this->layout()->setSpacing(0);
this->layout()->setContentsMargins(QMargins());
this->initHeaderFrame(std::move(header));
this->initContainerContentFrame();
this->initAnimations();
}
void ContentPane::initHeaderFrame(QString header)
{
this->header = new ClickableFrame(std::move(header));
this->header->setFrameStyle(this->headerFrameStyle);
this->layout()->addWidget(this->header);
QObject::connect(this->header, &ClickableFrame::singleClick, this, &ContentPane::headerClicked);
}
void ContentPane::initContainerContentFrame()
{
this->container = new QFrame();
this->container->setLayout(new QVBoxLayout());
this->container->setFrameStyle(this->contentPaneFrameStyle);
this->container->setMaximumHeight(0);
this->container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
this->layout()->addWidget(this->container);
if (this->content == nullptr) {
this->content = new QFrame();
}
this->container->layout()->addWidget(this->content);
this->container->layout()->setSpacing(0);
this->container->layout()->setContentsMargins(QMargins());
}
void ContentPane::initAnimations()
{
this->openAnimation = std::unique_ptr<QPropertyAnimation>(new QPropertyAnimation());
this->closeAnimation = std::unique_ptr<QPropertyAnimation>(new QPropertyAnimation());
// TODO: Currently these animations only animate maximumHeight. This leads to
// different behaviour depending on whether the Accordion Widget is placed
// inside a QScollWidget or not. Maybe we also need to animate minimumHeight
// as well to get the same effect.
this->openAnimation->setTargetObject(this->container);
this->openAnimation->setPropertyName("maximumHeight");
this->closeAnimation->setTargetObject(this->container);
this->closeAnimation->setPropertyName("maximumHeight");
this->openAnimation->setDuration(100);
this->closeAnimation->setDuration(100);
this->openAnimation->setStartValue(0);
this->closeAnimation->setStartValue(this->containerAnimationMaxHeight);
this->openAnimation->setEndValue(this->containerAnimationMaxHeight);
this->closeAnimation->setEndValue(0);
this->openAnimation->setEasingCurve(QEasingCurve(QEasingCurve::Type::Linear));
this->closeAnimation->setEasingCurve(QEasingCurve(QEasingCurve::Type::Linear));
}
void ContentPane::headerClicked()
{
emit this->clicked();
}
void ContentPane::paintEvent(ATTR_UNUSED QPaintEvent* event)
{
QStyleOption o;
o.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
}
|