1#include "FileWidget.h"
2
3#include <QPushButton>
4#include <QLabel>
5#include <QHBoxLayout>
6
7FileWidget::FileWidget(const QIcon &icon, const QString &text, QWidget *parent)
8 : QFrame(parent)
9 , mIcon(icon)
10 , mButton(new QPushButton(mIcon, ""))
11 , mText(new QLabel(text))
12{
13 const auto itemLayout = new QHBoxLayout(this);
14 itemLayout->setContentsMargins(QMargins());
15 mButton->setStyleSheet("max-width: 15px; min-width: 15px; max-height: 15px; min-height: 15px;");
16
17 itemLayout->addWidget(mButton);
18 itemLayout->addWidget(mText);
19
20 if (!icon.isNull())
21 connect(mButton, &QPushButton::clicked, this, [this]() { emit clicked(); });
22}
23
24FileWidget::FileWidget(const QString &icon, const QString &text, QWidget *parent)
25 : FileWidget(QIcon(icon), text, parent)
26{
27}
28
29QString FileWidget::text() const
30{
31 return mText->text();
32}
33
34void FileWidget::setText(const QString &text)
35{
36 mText->setText(text);
37}
38
39QSize FileWidget::sizeHint() const
40{
41 auto size = QFrame::sizeHint();
42 size.setWidth(size.width() + layout()->spacing());
43
44 return size;
45}
46
47void FileWidget::setTextColor(const QColor &color)
48{
49 mColor = color;
50 mText->setStyleSheet(QString("color: %1").arg(mColor.name()));
51}
52