forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Object Creator] Redo spell window layout (CleverRaven#68105)
* 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
Showing
4 changed files
with
710 additions
and
901 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.