#include "clickablelabel.h"
#include <QApplication>
#include <QFrame>
#include <QPushButton>
#include <QLayout>
class Harness : public QWidget
{
Q_OBJECT
public:
Harness();
private slots:
void enableDisableChange();
private:
ClickableLabel* clickableLabel;
ClickableLabel* invisibleLabel;
QPushButton* enableDisableButton;
};
Harness::Harness()
: QWidget(0)
{
auto visibleLabelDescription = new QLabel("Visible ->");
auto invisibleLabelDescription = new QLabel("Invisible ->");
clickableLabel = new ClickableLabel("Clickable");
invisibleLabel = new ClickableLabel();
invisibleLabel->setMinimumSize(64, 12);
auto clickedButton = new QPushButton("Clicked");
clickedButton->setFocusPolicy(Qt::NoFocus);
auto pressedButton = new QPushButton("Pressed");
pressedButton->setFocusPolicy(Qt::NoFocus);
auto releasedButton = new QPushButton("Released");
releasedButton->setFocusPolicy(Qt::NoFocus);
auto lineFrame = new QFrame;
lineFrame->setFrameShape(QFrame::HLine);
lineFrame->setFrameShadow(QFrame::Sunken);
lineFrame->setLineWidth(1);
lineFrame->setMidLineWidth(0);
enableDisableButton = new QPushButton("Disable");
auto testLabelLayout = new QGridLayout;
testLabelLayout->addWidget(visibleLabelDescription, 0, 0);
testLabelLayout->addWidget(invisibleLabelDescription, 1, 0);
testLabelLayout->addWidget(clickableLabel, 0, 1);
testLabelLayout->addWidget(invisibleLabel, 1, 1);
testLabelLayout->addWidget(clickedButton, 0, 2);
testLabelLayout->addWidget(pressedButton, 1, 2);
testLabelLayout->addWidget(releasedButton, 2, 2);
auto topLayout = new QVBoxLayout;
topLayout->addLayout(testLabelLayout);
topLayout->addWidget(lineFrame);
topLayout->addWidget(enableDisableButton, 0, Qt::AlignCenter);
setLayout(topLayout);
connect(clickableLabel, &ClickableLabel::clicked, clickedButton, &QPushButton::animateClick);
connect(clickableLabel, &ClickableLabel::pressed, pressedButton, &QPushButton::animateClick);
connect(clickableLabel, &ClickableLabel::released, releasedButton, &QPushButton::animateClick);
connect(invisibleLabel, &ClickableLabel::clicked, clickedButton, &QPushButton::animateClick);
connect(invisibleLabel, &ClickableLabel::pressed, pressedButton, &QPushButton::animateClick);
connect(invisibleLabel, &ClickableLabel::released, releasedButton, &QPushButton::animateClick);
connect(enableDisableButton, &QPushButton::clicked, this, &Harness::enableDisableChange);
}
void Harness::enableDisableChange()
{
if (enableDisableButton->text() == "Enable") {
clickableLabel->setEnabled(true);
invisibleLabel->setEnabled(true);
enableDisableButton->setText("Disable");
} else {
clickableLabel->setEnabled(false);
invisibleLabel->setEnabled(false);
enableDisableButton->setText("Enable");
}
}
int main(int argc, char** argv)
{
QApplication app(argc, argv);
Harness harness;
harness.show();
return app.exec();
}
#include "main.moc