#include "ToolsWidget.h" ToolsWidget::ToolsWidget(QWidget *parent) : QWidget(parent) { m_parent = parent; } ToolsWidget::~ToolsWidget() { } void ToolsWidget::setColor(QWidget *w,state s) { w->setProperty("state",s); w->style()->unpolish(w); w->style()->polish(w); } void ToolsWidget::setValue(QLabel *w,QString s) { w->setText(s); } void ToolsWidget::setFloat(void) { if(this->parent()) { m_parent = qobject_cast(this->parent()); QPoint pos = mapToGlobal(m_parent->pos()); this->setParent(nullptr); this->resize(this->minimumSize()); this->move(pos.x() + (m_parent->width() - this->width()) * 0.5, pos.y() + (m_parent->height() - this->height()) * 0.5); if(Top()) { this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); } this->show(); } else { if(m_parent) { this->setParent(m_parent); this->setGeometry(m_parent->geometry()); } this->move(0,0); this->hide(); update(); } } void ToolsWidget::resizeEvent(QResizeEvent *event) { update(); } void ToolsWidget::closeEvent(QCloseEvent *event) { setFloat(); event->ignore(); }