mirror of
https://github.com/vicr123/the-libs.git
synced 2025-01-22 18:32:10 -05:00
Add tConditionalWidget
This commit is contained in:
parent
852e2c9c20
commit
258527f315
4 changed files with 158 additions and 1 deletions
|
@ -64,6 +64,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
|
|
||||||
SOURCES += tvariantanimation.cpp \
|
SOURCES += tvariantanimation.cpp \
|
||||||
taboutdialog.cpp \
|
taboutdialog.cpp \
|
||||||
|
tconditionalwidget.cpp \
|
||||||
tcsdtools.cpp \
|
tcsdtools.cpp \
|
||||||
tcsdtools/csdbuttonbox.cpp \
|
tcsdtools/csdbuttonbox.cpp \
|
||||||
tcsdtools/csdsizegrip.cpp \
|
tcsdtools/csdsizegrip.cpp \
|
||||||
|
@ -91,6 +92,7 @@ SOURCES += tvariantanimation.cpp \
|
||||||
|
|
||||||
HEADERS += tvariantanimation.h\
|
HEADERS += tvariantanimation.h\
|
||||||
taboutdialog.h \
|
taboutdialog.h \
|
||||||
|
tconditionalwidget.h \
|
||||||
tcsdtools.h \
|
tcsdtools.h \
|
||||||
tcsdtools/csdbuttonbox.h \
|
tcsdtools/csdbuttonbox.h \
|
||||||
tcsdtools/csdsizegrip.h \
|
tcsdtools/csdsizegrip.h \
|
||||||
|
|
108
lib/tconditionalwidget.cpp
Normal file
108
lib/tconditionalwidget.cpp
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
/****************************************
|
||||||
|
*
|
||||||
|
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
|
||||||
|
* Copyright (C) 2020 Victor Tran
|
||||||
|
*
|
||||||
|
* 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 "tconditionalwidget.h"
|
||||||
|
|
||||||
|
#include <tvariantanimation.h>
|
||||||
|
|
||||||
|
struct tConditionalWidgetPrivate {
|
||||||
|
bool isExpanded = false;
|
||||||
|
bool fullyExpanded = false;
|
||||||
|
|
||||||
|
tVariantAnimation* heightAnim;
|
||||||
|
};
|
||||||
|
|
||||||
|
tConditionalWidget::tConditionalWidget(QWidget* parent) : QWidget(parent) {
|
||||||
|
d = new tConditionalWidgetPrivate();
|
||||||
|
|
||||||
|
d->heightAnim = new tVariantAnimation(this);
|
||||||
|
d->heightAnim->setEasingCurve(QEasingCurve::OutCubic);
|
||||||
|
d->heightAnim->setDuration(250);
|
||||||
|
connect(d->heightAnim, &tVariantAnimation::valueChanged, this, [ = ](QVariant value) {
|
||||||
|
this->setFixedHeight(value.toInt());
|
||||||
|
});
|
||||||
|
this->setFixedHeight(0);
|
||||||
|
// connect(d->heightAnim, &tVariantAnimation::finished, this, &tConditionalWidget::updateGeometry);
|
||||||
|
}
|
||||||
|
|
||||||
|
tConditionalWidget::~tConditionalWidget() {
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tConditionalWidget::expand() {
|
||||||
|
if (d->isExpanded) return;
|
||||||
|
|
||||||
|
if (!this->isVisible()) {
|
||||||
|
d->isExpanded = true;
|
||||||
|
d->fullyExpanded = true;
|
||||||
|
this->setFixedHeight(QWIDGETSIZE_MAX);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->heightAnim->stop();
|
||||||
|
d->heightAnim->setStartValue(this->height());
|
||||||
|
d->heightAnim->setEndValue(QWidget::sizeHint().height());
|
||||||
|
|
||||||
|
QMetaObject::Connection* c = new QMetaObject::Connection();
|
||||||
|
*c = connect(d->heightAnim, &tVariantAnimation::stateChanged, this, [ = ](tVariantAnimation::State newState, tVariantAnimation::State oldState) {
|
||||||
|
if (newState == tVariantAnimation::Running) return;
|
||||||
|
disconnect(*c);
|
||||||
|
delete c;
|
||||||
|
d->fullyExpanded = true;
|
||||||
|
this->setFixedHeight(QWIDGETSIZE_MAX);
|
||||||
|
});
|
||||||
|
d->heightAnim->start();
|
||||||
|
|
||||||
|
d->isExpanded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tConditionalWidget::collapse() {
|
||||||
|
if (!d->fullyExpanded) return;
|
||||||
|
|
||||||
|
if (!this->isVisible()) {
|
||||||
|
d->isExpanded = false;
|
||||||
|
d->fullyExpanded = false;
|
||||||
|
this->setFixedHeight(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->heightAnim->stop();
|
||||||
|
d->heightAnim->setStartValue(this->height());
|
||||||
|
d->heightAnim->setEndValue(0);
|
||||||
|
|
||||||
|
QMetaObject::Connection* c = new QMetaObject::Connection();
|
||||||
|
*c = connect(d->heightAnim, &tVariantAnimation::stateChanged, this, [ = ](tVariantAnimation::State newState, tVariantAnimation::State oldState) {
|
||||||
|
if (newState == tVariantAnimation::Running) return;
|
||||||
|
disconnect(*c);
|
||||||
|
delete c;
|
||||||
|
d->isExpanded = false;
|
||||||
|
this->setFixedHeight(0);
|
||||||
|
});
|
||||||
|
d->heightAnim->start();
|
||||||
|
d->fullyExpanded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tConditionalWidget::setExpanded(bool expanded) {
|
||||||
|
if (expanded) {
|
||||||
|
this->expand();
|
||||||
|
} else {
|
||||||
|
this->collapse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
44
lib/tconditionalwidget.h
Normal file
44
lib/tconditionalwidget.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/****************************************
|
||||||
|
*
|
||||||
|
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
|
||||||
|
* Copyright (C) 2020 Victor Tran
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* *************************************/
|
||||||
|
#ifndef TCONDITIONALWIDGET_H
|
||||||
|
#define TCONDITIONALWIDGET_H
|
||||||
|
|
||||||
|
#include <the-libs_global.h>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
struct tConditionalWidgetPrivate;
|
||||||
|
class THELIBSSHARED_EXPORT tConditionalWidget : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit tConditionalWidget(QWidget* parent = nullptr);
|
||||||
|
~tConditionalWidget();
|
||||||
|
|
||||||
|
void expand();
|
||||||
|
void collapse();
|
||||||
|
|
||||||
|
void setExpanded(bool expanded);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
private:
|
||||||
|
tConditionalWidgetPrivate* d;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TCONDITIONALWIDGET_H
|
|
@ -67,7 +67,10 @@ bool tSettings::contains(QString key) {
|
||||||
|
|
||||||
void tSettings::setValue(QString key, QVariant value) {
|
void tSettings::setValue(QString key, QVariant value) {
|
||||||
d->allSettings.at(0)->setValue(key, value);
|
d->allSettings.at(0)->setValue(key, value);
|
||||||
emit settingChanged(key, value);
|
|
||||||
|
for (tSettings* settingsObjects : d->availableSettingsObjects) {
|
||||||
|
emit settingsObjects->settingChanged(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant tSettings::value(QString key) {
|
QVariant tSettings::value(QString key) {
|
||||||
|
|
Loading…
Reference in a new issue