Skip to content

Commit

Permalink
[Object Creator] Redo spell window layout (CleverRaven#68105)
Browse files Browse the repository at this point in the history
* Initial step of the collapsing widget

* Move some more properties to their new container

* Changing the size of the collapsing widget

* Have the parent widget adjust size as well

* Remove excess code

* Finalize basic layout

* Assign percent of space to columns

* Put the widgets in a scroll area

* Adjust height settings

* Change height on fake spell listbox

* Add checks to min and max damage

* remove excess code

* Give learn spells box proper size

* Remove excess code

* Remove comments, set font default
  • Loading branch information
snipercup authored Sep 12, 2023
1 parent 6b73a89 commit 631d3c4
Show file tree
Hide file tree
Showing 4 changed files with 710 additions and 901 deletions.
57 changes: 57 additions & 0 deletions object_creator/collapsing_widget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "collapsing_widget.h"
#include <QtWidgets/qlabel.h>
#include <QtWidgets/qtoolbutton.h>

creator::collapsing_widget::collapsing_widget(QWidget *parent, const QString &text, QLayout& contentLayout)
: QWidget(parent)
{
//Create a vertcal layout
QVBoxLayout *layout = new QVBoxLayout(this);

//Add a button and a label to a horizontal layout and add it to the vertical layout
QHBoxLayout *hlayout = new QHBoxLayout();
layout->addLayout(hlayout);
QToolButton *button = new QToolButton();
button->setCheckable(true);
button->setArrowType(Qt::ArrowType::DownArrow);
//make sure the button starts checked
button->setChecked(true);
hlayout->addWidget(button);
QLabel *label = new QLabel();
label->setText(text);
hlayout->addWidget(label);

//Add the content layout to a new scrollarea and add it to the vertical layout
QScrollArea *scrollArea = new QScrollArea();
scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
scrollArea->setWidgetResizable(true);
scrollArea->setLayout(&contentLayout);

contentLayout.setContentsMargins(0, 0, 0, 0);
contentLayout.setSpacing(0);
scrollArea->setMaximumHeight(scrollArea->layout()->sizeHint().height());
scrollArea->setMinimumHeight(scrollArea->layout()->sizeHint().height());
layout->addWidget(scrollArea);

//When the button is pressed, toggle the content
connect(button, &QToolButton::toggled, [=](){
button->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
scrollArea != nullptr && checked ? showContent(scrollArea) : hideContent(scrollArea);
});
}

void creator::collapsing_widget::hideContent(QScrollArea* scrollArea) {
scrollArea->setMaximumHeight(0);
scrollArea->setMinimumHeight(0);
this->adjustSize();
this->parentWidget()->adjustSize();
checked = true;
}

void creator::collapsing_widget::showContent(QScrollArea* scrollArea) {
scrollArea->setMaximumHeight(scrollArea->layout()->sizeHint().height());
scrollArea->setMinimumHeight(scrollArea->layout()->sizeHint().height());
this->adjustSize();
this->parentWidget()->adjustSize();
checked = false;
}
23 changes: 23 additions & 0 deletions object_creator/collapsing_widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef CATA_OBJECT_CREATOR_COLLAPSING_WIDGET_H
#define CATA_OBJECT_CREATOR_COLLAPSING_WIDGET_H

#include <QtWidgets/qscrollarea.h>
#include <QtCore/qstring.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qwidget.h>


namespace creator
{
class collapsing_widget : public QWidget {
public:
collapsing_widget(QWidget *parent, const QString &text, QLayout& contentLayout);
void hideContent(QScrollArea* scrollArea);
void showContent(QScrollArea* scrollArea);

private:
bool checked = false;
};
}

#endif
51 changes: 22 additions & 29 deletions object_creator/fake_spell_listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
#include "format.h"
#include "json.h"

#include <QtWidgets/qboxlayout.h>


creator::fake_spell_listbox::fake_spell_listbox( QWidget *parent )
: QListWidget( parent )
{
const int default_text_box_height = 20;
const int default_text_box_width = 100;
const QSize default_text_box_size( default_text_box_width, default_text_box_height );

int row = 0;
int col = 0;
int max_row = 0;

QListWidget::resize( QSize( default_text_box_width * 2, default_text_box_height * 4 ) );
//Make a horizontal layout and add two vertical layouts to it
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
QVBoxLayout *vlayout1 = new QVBoxLayout();
vlayout1->setContentsMargins(0, 0, 0, 0);
vlayout1->setSpacing(0);
QVBoxLayout *vlayout2 = new QVBoxLayout();
vlayout2->setContentsMargins(0, 0, 0, 0);
vlayout2->setSpacing(0);
layout->addLayout(vlayout1);
layout->addLayout(vlayout2);

id_label.setParent( this );
id_label.resize( default_text_box_size );
id_label.show();
row++;

add_spell_button.setParent( this );
vlayout1->addWidget(&id_label);
add_spell_button.setText( QString( "Add fake_spell" ) );
add_spell_button.resize( default_text_box_size );
add_spell_button.move( QPoint( default_text_box_width * col, default_text_box_height * row++ ) );
add_spell_button.show();
QObject::connect( &add_spell_button, &QPushButton::clicked,
[&]() {
const int index = windows.size();
Expand All @@ -47,12 +47,9 @@ creator::fake_spell_listbox::fake_spell_listbox( QWidget *parent )
} );
} );
QObject::connect( &add_spell_button, &QPushButton::clicked, this, &fake_spell_listbox::modified );
vlayout1->addWidget(&add_spell_button);

del_spell_button.setParent( this );
del_spell_button.setText( QString( "Remove fake_spell" ) );
del_spell_button.resize( default_text_box_size );
del_spell_button.move( QPoint( default_text_box_width * col, default_text_box_height * row++ ) );
del_spell_button.show();
QObject::connect( &del_spell_button, &QPushButton::clicked,
[&]() {
const int index = fake_spell_list_box.currentIndex();
Expand All @@ -63,17 +60,11 @@ creator::fake_spell_listbox::fake_spell_listbox( QWidget *parent )
fake_spell_list_box.removeItem( index );
} );
QObject::connect( &del_spell_button, &QPushButton::clicked, this, &fake_spell_listbox::modified );
vlayout1->addWidget(&del_spell_button);

// =========================================================================================
// second column of boxes
max_row = std::max( row, max_row );
row = 0;
col = 1;

fake_spell_list_box.setParent( this );
fake_spell_list_box.resize( QSize( default_text_box_width, default_text_box_height * 4 ) );
fake_spell_list_box.move( QPoint( default_text_box_width * col, default_text_box_height * row ) );
fake_spell_list_box.show();
// =========================================================================================
// second column
QObject::connect( &fake_spell_list_box, qOverload<int>( &QComboBox::currentIndexChanged ),
[&]() {
for( fake_spell_window *win : windows ) {
Expand All @@ -94,7 +85,9 @@ creator::fake_spell_listbox::fake_spell_listbox( QWidget *parent )
fake_spell_list_box.setCurrentText( windows.at( fake_spell_list_box.currentIndex() )
->get_fake_spell().id.c_str() );
} );
row += 4;

vlayout2->addWidget(&fake_spell_list_box);
this->adjustSize();
}

void creator::fake_spell_listbox::set_spells( const std::vector<fake_spell> &spells )
Expand Down
Loading

0 comments on commit 631d3c4

Please sign in to comment.