mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 07:28:12 +08:00
[UI][ADD] Model selectable item button
This commit is contained in:
parent
d818ccd469
commit
ffa0ac065a
@ -1 +1,83 @@
|
|||||||
#pragma once
|
#include <qlabel.h>
|
||||||
|
|
||||||
|
#include "modelselectable.h"
|
||||||
|
#include "sceneviewer.h"
|
||||||
|
|
||||||
|
ModelSelectable::ModelSelectable(Model* model, QWidget* parent) :
|
||||||
|
QWidget(parent), _model(model)
|
||||||
|
{
|
||||||
|
// Set size
|
||||||
|
setFixedHeight(150);
|
||||||
|
setSizeIncrement(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
|
||||||
|
// Create stretch layout to hold the main button
|
||||||
|
_stretchLayout = new QHBoxLayout(this);
|
||||||
|
_stretchLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
_stretchLayout->setSpacing(0);
|
||||||
|
setLayout(_stretchLayout);
|
||||||
|
|
||||||
|
// Create main button widget
|
||||||
|
_mainBtn = new PushButton(nullptr, this);
|
||||||
|
_mainBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
_mainBtn->setMargin(0, 0, 0, 0);
|
||||||
|
_mainBtn->setRadius(10);
|
||||||
|
_mainBtn->setBackgroundColor(QColor(58, 143, 183, 15));
|
||||||
|
_stretchLayout->addWidget(_mainBtn);
|
||||||
|
_mainBtn->show();
|
||||||
|
|
||||||
|
// Create widget to hold the button content
|
||||||
|
_mainBtnChild = new QWidget(_mainBtn);
|
||||||
|
_mainBtnChild->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
//_mainBtnChild->setObjectName("mainBtnChild");
|
||||||
|
//_mainBtnChild->setStyleSheet("QWidget#mainBtnChild{border: 3px solid " + _borderColor.name(QColor::HexArgb) + ";"
|
||||||
|
// "border-radius:" + QString::number(_cornerRadius) + "px;}");
|
||||||
|
_mainBtn->setChildWidget(_mainBtnChild);
|
||||||
|
_mainBtnChild->show();
|
||||||
|
|
||||||
|
// Create layout to hold the button content
|
||||||
|
_mainLayout = new QHBoxLayout(_mainBtnChild);
|
||||||
|
_mainLayout->setContentsMargins(16, 12, 16, 12);
|
||||||
|
_mainLayout->setSpacing(12);
|
||||||
|
_mainBtnChild->setLayout(_mainLayout);
|
||||||
|
|
||||||
|
// Create model thumbnail widget
|
||||||
|
_thumbnailContainer = new RoundedCornerWidget(_mainBtnChild);
|
||||||
|
_thumbnailContainer->setCornerRadius(_cornerRadius);
|
||||||
|
_thumbnailContainer->setBorderColor(QColor(255, 255, 255, 0));
|
||||||
|
_thumbnailContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
_mainLayout->addWidget(_thumbnailContainer);
|
||||||
|
_thumbnailContainer->show();
|
||||||
|
|
||||||
|
_thumbnailWidget = new ModelThumbnailWidget(_model, _mainBtnChild);
|
||||||
|
_thumbnailWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
|
_thumbnailContainerLayout = new QHBoxLayout(_thumbnailContainer->mainWidget());
|
||||||
|
_thumbnailContainerLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
_thumbnailContainerLayout->setSpacing(0);
|
||||||
|
_thumbnailContainer->mainWidget()->setLayout(_thumbnailContainerLayout);
|
||||||
|
_thumbnailContainerLayout->addWidget(_thumbnailWidget);
|
||||||
|
_thumbnailWidget->show();
|
||||||
|
|
||||||
|
// Create delete button
|
||||||
|
_deleteButton = new PushButton(nullptr, _mainBtnChild);
|
||||||
|
_deleteButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
|
_deleteIcon = new QLabel(_deleteButton);
|
||||||
|
_deleteIcon->setFont(QFont("Font Awesome 6 Free Regular", 12));
|
||||||
|
_deleteIcon->setText("\uf2ed");
|
||||||
|
_deleteIcon->setAlignment(Qt::AlignCenter);
|
||||||
|
_deleteButton->setChildWidget(_deleteIcon);
|
||||||
|
_deleteButton->setColorScheme(QColor(171, 59, 58));
|
||||||
|
_deleteButton->setIndicatorColor(QColor(171, 59, 58, 0));
|
||||||
|
_deleteIcon->show();
|
||||||
|
_mainLayout->addWidget(_deleteButton);
|
||||||
|
_deleteButton->show();
|
||||||
|
|
||||||
|
// Connect
|
||||||
|
connect(_mainBtn, &PushButton::onClick, this, &ModelSelectable::onSelected);
|
||||||
|
connect(_deleteButton, &PushButton::onClick, this, &ModelSelectable::onRemoved);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelSelectable::~ModelSelectable()
|
||||||
|
{
|
||||||
|
delete _model;
|
||||||
|
}
|
||||||
@ -1,6 +1,46 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "model.h"
|
|
||||||
|
|
||||||
#include <qwidget.h>
|
#include <qwidget.h>
|
||||||
|
#include <qlayout.h>
|
||||||
|
#include <qlabel.h>
|
||||||
|
|
||||||
|
#include "model.h"
|
||||||
|
#include "pushbutton.h"
|
||||||
|
#include "roundedcornerwidget.h"
|
||||||
|
#include "modelthumbnailwidget.h"
|
||||||
|
#include "lineeditwidget.h"
|
||||||
|
|
||||||
|
class ModelSelectable : public QWidget {
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ModelSelectable(Model* model, QWidget* parent = 0);
|
||||||
|
~ModelSelectable();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Data
|
||||||
|
Model* _model;
|
||||||
|
|
||||||
|
// UI control variables
|
||||||
|
const QColor _borderColor = QColor(58, 143, 183);
|
||||||
|
const int _cornerRadius = 10;
|
||||||
|
|
||||||
|
// UI elements
|
||||||
|
QHBoxLayout* _stretchLayout = nullptr;
|
||||||
|
PushButton* _mainBtn = nullptr;
|
||||||
|
|
||||||
|
QWidget* _mainBtnChild = nullptr;
|
||||||
|
QHBoxLayout* _mainLayout = nullptr;
|
||||||
|
|
||||||
|
RoundedCornerWidget* _thumbnailContainer = nullptr;
|
||||||
|
QHBoxLayout* _thumbnailContainerLayout = nullptr;
|
||||||
|
ModelThumbnailWidget* _thumbnailWidget = nullptr;
|
||||||
|
|
||||||
|
PushButton* _deleteButton = nullptr;
|
||||||
|
QLabel* _deleteIcon = nullptr;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void onSelected();
|
||||||
|
void onRemoved();
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user