#ifndef MTMULTISVGWIDGET_H
#define MTMULTISVGWIDGET_H
#include <QWidget>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QLabel>
#include "flowlayout.h"
class MTMultiSvgWidget : public QWidget
{
Q_OBJECT
protected:
void init() {
msw_flayout = new FlowLayout(this);
msw_flayout->setContentsMargins(0, 0, 0, 0);
msw_flayout->setSpacing(6);
};
public:
MTMultiSvgWidget(QWidget * parent = 0):
QWidget(parent) { init(); };
void addWidget(QWidget * w) { msw_flayout->addWidget(w); };
void addWidget(QWidget * w, QString title, bool link = false) {
QWidget * widget = new QWidget;
QVBoxLayout * vlayout = new QVBoxLayout(widget);
QLabel * label = new QLabel(widget);
if (!link) {
label->setText(title);
} else {
label->setText(QString("<a href=\"%1\">%2</a>").arg(msw_flayout->count()).arg(substituteHtmlTags(title)));
QObject::connect(label, SIGNAL(linkActivated(QString)), this, SLOT(emitTitleClicked(QString)));
}
label->setAlignment(Qt::AlignCenter);
vlayout->addWidget(label);
vlayout->addWidget(w);
msw_flayout->addWidget(widget);
};
QSize layoutSizeHint() { return msw_flayout->sizeHint(); };
int layoutHeightForWidth(int w) { return msw_flayout->heightForWidth(w); };
public slots:
void clear() {
for (int i = 0; i < msw_flayout->count();) {
delete msw_flayout->takeAt(i)->widget();
}
};
private slots:
void emitTitleClicked(QString text) { emit titleClicked(text); };
signals:
void titleClicked(QString);
private:
QString substituteHtmlTags(QString str) {
str.replace(QString("<"), QString("<"));
str.replace(QString(">"), QString(">"));
str.replace(QString("&"), QString("&"));
return str;
};
FlowLayout * msw_flayout;
};
#endif