46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
|
#include "./syncthinginfoaction.h"
|
||
|
|
||
|
#include <QAction>
|
||
|
#include <QHBoxLayout>
|
||
|
#include <QLabel>
|
||
|
|
||
|
SyncthingInfoWidget::SyncthingInfoWidget(const SyncthingInfoAction *action, QWidget *parent)
|
||
|
: QWidget(parent)
|
||
|
, m_textLabel(new QLabel(parent))
|
||
|
, m_iconLabel(new QLabel(parent))
|
||
|
{
|
||
|
auto *const layout = new QHBoxLayout(parent);
|
||
|
layout->setMargin(4);
|
||
|
layout->setSpacing(5);
|
||
|
m_iconLabel->setFixedWidth(16);
|
||
|
m_iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
|
||
|
layout->addWidget(m_iconLabel);
|
||
|
layout->addWidget(m_textLabel);
|
||
|
setLayout(layout);
|
||
|
updateFromAction(action);
|
||
|
connect(action, &QAction::changed, this, &SyncthingInfoWidget::updateFromSender);
|
||
|
}
|
||
|
|
||
|
void SyncthingInfoWidget::updateFromSender()
|
||
|
{
|
||
|
updateFromAction(qobject_cast<const SyncthingInfoAction *>(QObject::sender()));
|
||
|
}
|
||
|
|
||
|
void SyncthingInfoWidget::updateFromAction(const SyncthingInfoAction *action)
|
||
|
{
|
||
|
auto text(action->text());
|
||
|
m_textLabel->setText(text.startsWith(QChar('&')) ? text.mid(1) : std::move(text));
|
||
|
m_iconLabel->setPixmap(action->icon().pixmap(16));
|
||
|
setVisible(action->isVisible());
|
||
|
}
|
||
|
|
||
|
SyncthingInfoAction::SyncthingInfoAction(QObject *parent)
|
||
|
: QWidgetAction(parent)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
QWidget *SyncthingInfoAction::createWidget(QWidget *parent)
|
||
|
{
|
||
|
return new SyncthingInfoWidget(this, parent);
|
||
|
}
|