ensured parenting of qwidgets

This commit is contained in:
itsmattkc
2019-01-30 17:36:54 +11:00
parent 54180e5e0d
commit 6f3a826da7
32 changed files with 350 additions and 357 deletions
+33 -34
View File
@@ -15,62 +15,61 @@
#include "debug.h"
CollapsibleWidget::CollapsibleWidget(QWidget* parent) : QWidget(parent) {
selected = false;
selected = false;
layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
title_bar = new CollapsibleWidgetHeader();
title_bar = new CollapsibleWidgetHeader(this);
title_bar->setFocusPolicy(Qt::ClickFocus);
title_bar->setAutoFillBackground(true);
title_bar_layout = new QHBoxLayout();
title_bar_layout = new QHBoxLayout(title_bar);
title_bar_layout->setMargin(5);
title_bar->setLayout(title_bar_layout);
enabled_check = new CheckboxEx();
enabled_check = new CheckboxEx(title_bar);
enabled_check->setChecked(true);
header = new QLabel();
collapse_button = new QPushButton();
collapse_button->setIconSize(collapse_button->iconSize()*0.5);
collapse_button->setStyleSheet("QPushButton { border: none; }");
setText(tr("<untitled>"));
title_bar_layout->addWidget(collapse_button);
title_bar_layout->addWidget(enabled_check);
title_bar_layout->addWidget(header);
title_bar_layout->addStretch();
layout->addWidget(title_bar);
header = new QLabel(title_bar);
collapse_button = new QPushButton(title_bar);
collapse_button->setIconSize(collapse_button->iconSize()*0.5);
collapse_button->setStyleSheet("QPushButton { border: none; }");
setText(tr("<untitled>"));
title_bar_layout->addWidget(collapse_button);
title_bar_layout->addWidget(enabled_check);
title_bar_layout->addWidget(header);
title_bar_layout->addStretch();
layout->addWidget(title_bar);
connect(title_bar, SIGNAL(select(bool, bool)), this, SLOT(header_click(bool, bool)));
set_button_icon(true);
set_button_icon(true);
contents = nullptr;
}
void CollapsibleWidget::header_click(bool s, bool deselect) {
selected = s;
title_bar->selected = s;
if (s) {
selected = s;
title_bar->selected = s;
if (s) {
QPalette p = title_bar->palette();
p.setColor(QPalette::Background, QColor(255, 255, 255, 64));
p.setColor(QPalette::Background, QColor(255, 255, 255, 64));
title_bar->setPalette(p);
} else {
title_bar->setPalette(palette());
}
if (deselect) emit deselect_others(this);
if (deselect) emit deselect_others(this);
}
bool CollapsibleWidget::is_focused() {
if (hasFocus()) return true;
return title_bar->hasFocus();
if (hasFocus()) return true;
return title_bar->hasFocus();
}
bool CollapsibleWidget::is_expanded() {
return contents->isVisible();
return contents->isVisible();
}
void CollapsibleWidget::set_button_icon(bool open) {
collapse_button->setIcon(open ? QIcon(":/icons/tri-down.png") : QIcon(":/icons/tri-right.png"));
collapse_button->setIcon(open ? QIcon(":/icons/tri-down.png") : QIcon(":/icons/tri-right.png"));
}
void CollapsibleWidget::setContents(QWidget* c) {
@@ -93,7 +92,7 @@ void CollapsibleWidget::on_enabled_change(bool b) {
void CollapsibleWidget::on_visible_change() {
contents->setVisible(!contents->isVisible());
set_button_icon(contents->isVisible());
set_button_icon(contents->isVisible());
emit visibleChanged();
}
@@ -102,14 +101,14 @@ CollapsibleWidgetHeader::CollapsibleWidgetHeader(QWidget* parent) : QWidget(pare
}
void CollapsibleWidgetHeader::mousePressEvent(QMouseEvent* event) {
if (selected) {
if ((event->modifiers() & Qt::ShiftModifier)) {
selected = false;
emit select(selected, false);
}
} else {
selected = true;
emit select(selected, !(event->modifiers() & Qt::ShiftModifier));
if (selected) {
if ((event->modifiers() & Qt::ShiftModifier)) {
selected = false;
emit select(selected, false);
}
} else {
selected = true;
emit select(selected, !(event->modifiers() & Qt::ShiftModifier));
}
}
+4 -5
View File
@@ -7,13 +7,12 @@
#include <QFileDialog>
EmbeddedFileChooser::EmbeddedFileChooser(QWidget* parent) : QWidget(parent) {
QHBoxLayout* layout = new QHBoxLayout();
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
setLayout(layout);
file_label = new QLabel();
file_label = new QLabel(this);
update_label();
layout->addWidget(file_label);
QPushButton* browse_button = new QPushButton("...");
QPushButton* browse_button = new QPushButton("...", this);
browse_button->setFixedWidth(25);
layout->addWidget(browse_button);
connect(browse_button, SIGNAL(clicked(bool)), this, SLOT(browse()));
@@ -35,7 +34,7 @@ void EmbeddedFileChooser::setFilename(const QString &s) {
}
void EmbeddedFileChooser::update_label() {
QString l = "<html>" + tr("File:") + " ";
QString l = "<html>" + tr("File:") + " ";
if (filename.isEmpty()) {
l += "(none)";
} else {
+6 -14
View File
@@ -6,7 +6,7 @@
#include <QDesktopWidget>
KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget(parent) {
key_controls = new QHBoxLayout();
key_controls = new QHBoxLayout(this);
key_controls->setSpacing(0);
key_controls->setMargin(0);
@@ -14,9 +14,7 @@ KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget
key_controls->addStretch();
}
setLayout(key_controls);
left_key_nav = new QPushButton();
left_key_nav = new QPushButton(this);
left_key_nav->setIcon(QIcon(":/icons/tri-left.png"));
left_key_nav->setIconSize(left_key_nav->iconSize()*0.5);
left_key_nav->setVisible(false);
@@ -24,7 +22,7 @@ KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget
connect(left_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(goto_previous_key()));
connect(left_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
key_addremove = new QPushButton();
key_addremove = new QPushButton(this);
key_addremove->setIcon(QIcon(":/icons/diamond.png"));
key_addremove->setIconSize(key_addremove->iconSize()*0.5);
key_addremove->setVisible(false);
@@ -32,7 +30,7 @@ KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget
connect(key_addremove, SIGNAL(clicked(bool)), this, SIGNAL(toggle_key()));
connect(key_addremove, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
right_key_nav = new QPushButton();
right_key_nav = new QPushButton(this);
right_key_nav->setIcon(QIcon(":/icons/tri-right.png"));
right_key_nav->setIconSize(right_key_nav->iconSize()*0.5);
right_key_nav->setVisible(false);
@@ -40,7 +38,7 @@ KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget
connect(right_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(goto_next_key()));
connect(right_key_nav, SIGNAL(clicked(bool)), this, SIGNAL(clicked()));
keyframe_enable = new QPushButton(QIcon(":/icons/clock.png"), "");
keyframe_enable = new QPushButton(QIcon(":/icons/clock.png"), "", this);
keyframe_enable->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
keyframe_enable->setIconSize(keyframe_enable->iconSize()*0.75);
keyframe_enable->setCheckable(true);
@@ -51,13 +49,7 @@ KeyframeNavigator::KeyframeNavigator(QWidget *parent, bool addLeftPad) : QWidget
key_controls->addWidget(keyframe_enable);
}
KeyframeNavigator::~KeyframeNavigator() {
delete keyframe_enable;
delete right_key_nav;
delete key_addremove;
delete left_key_nav;
delete key_controls;
}
KeyframeNavigator::~KeyframeNavigator() {}
void KeyframeNavigator::enable_keyframes(bool b) {
keyframe_enable->setChecked(b);