Compare commits

...

2 Commits

3 changed files with 29 additions and 4 deletions

View File

@ -70,6 +70,9 @@
<QtUic Include="MainWindow.ui"> <QtUic Include="MainWindow.ui">
<Filter>Form Files</Filter> <Filter>Form Files</Filter>
</QtUic> </QtUic>
<QtUic Include="EditorWidget.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\Editor\EditorWidgetItem.cpp"> <ClCompile Include="src\Editor\EditorWidgetItem.cpp">

View File

@ -3,14 +3,22 @@
ElementPoolWidget::ElementPoolWidget(QWidget* parent) ElementPoolWidget::ElementPoolWidget(QWidget* parent)
: QWidget(parent) : QWidget(parent)
{ {
iconWidth = 150, iconHeight = 100; parentSize = QSize(270, 210);
elementManager = nullptr;
iconWidth = 80, iconHeight = 60;
pictureList = new QListWidget(this); pictureList = new QListWidget(this);
pictureList->setIconSize(QSize(iconWidth, iconHeight)); pictureList->setIconSize(QSize(iconWidth, iconHeight));
pictureList->setResizeMode(QListView::Adjust); pictureList->setResizeMode(QListView::Adjust);
pictureList->setViewMode(QListView::IconMode); pictureList->setViewMode(QListView::IconMode);
pictureList->setMovement(QListView::Static); pictureList->setMovement(QListView::Static);
pictureList->setSpacing(10); pictureList->setSpacing(5);
pictureList->setFixedSize(600, 800); pictureList->setStyleSheet("QListWidget::Item:hover{background-color:rgba(47,46,46,0);border-radius:5px; }"
"QListWidget::item:selected{background-color:rgba(47,46,46,0);color:rgb(61,61,61);border:1px solid #000;border-radius:2px; }"
"QScrollBar:vertical{width:6px}");
pictureList->setFocusPolicy(Qt::NoFocus);
pictureList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
//pictureList->setFixedSize(600, 800);
setVisible(true); setVisible(true);
@ -37,13 +45,19 @@ void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) {
//p->show(); //p->show();
QListWidgetItem* pItem = new QListWidgetItem( QListWidgetItem* pItem = new QListWidgetItem(
itemPixmap.scaled(QSize(iconWidth-20, iconHeight-20)), itemPixmap.scaled(QSize(iconWidth-15, iconHeight-15)),
elements[index]->name); elements[index]->name);
pItem->setSizeHint(QSize(iconWidth, iconHeight)); pItem->setSizeHint(QSize(iconWidth, iconHeight));
pictureList->insertItem(index, pItem); pictureList->insertItem(index, pItem);
} }
} }
void ElementPoolWidget::setParentSize(QSize pSize) {
parentSize = pSize;
iconWidth = (parentSize.width() - 30) / 3;
iconHeight = (parentSize.width() - 30) / 4;
}
ElementPoolWidget::~ElementPoolWidget() { ElementPoolWidget::~ElementPoolWidget() {
} }
@ -59,3 +73,8 @@ void ElementPoolWidget::setElementManager(ElementManager* element)
this->elementManager = element; this->elementManager = element;
this->setElementList(this->elementManager->elements); this->setElementList(this->elementManager->elements);
} }
void ElementPoolWidget::refresh() {
this->setElementList(this->elementManager->elements);
// update();
}

View File

@ -12,12 +12,14 @@ private:
std::vector<GraphicElement*> elements; std::vector<GraphicElement*> elements;
QListWidget* pictureList; QListWidget* pictureList;
int iconWidth, iconHeight; int iconWidth, iconHeight;
QSize parentSize;
ElementManager* elementManager; ElementManager* elementManager;
public: public:
ElementPoolWidget(QWidget* parent = nullptr); ElementPoolWidget(QWidget* parent = nullptr);
void setElementList(std::vector<GraphicElement*> elementList); void setElementList(std::vector<GraphicElement*> elementList);
void setElementManager(ElementManager* element); void setElementManager(ElementManager* element);
void setParentSize(QSize pSize);
~ElementPoolWidget(); ~ElementPoolWidget();
signals: signals:
@ -25,5 +27,6 @@ signals:
public slots: public slots:
int pictureItemClicked(QListWidgetItem* item); int pictureItemClicked(QListWidgetItem* item);
void refresh();
}; };