From 4f417d527e8cf39d2c7653d80f1aade9155827de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 19 Apr 2015 17:58:53 +0200 Subject: [PATCH] GH-894 link server status widgets to help.mojang.com --- application/widgets/ServerStatus.cpp | 56 +++++++++++++++++++++++++++- application/widgets/ServerStatus.h | 3 ++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/application/widgets/ServerStatus.cpp b/application/widgets/ServerStatus.cpp index 0c11b9bf..f0a7f97a 100644 --- a/application/widgets/ServerStatus.cpp +++ b/application/widgets/ServerStatus.cpp @@ -11,6 +11,49 @@ #include #include #include +#include + +class ClickableLabel : public QLabel +{ + Q_OBJECT +public: + ClickableLabel(QWidget *parent) : QLabel(parent) + { + setCursor(Qt::PointingHandCursor); + } + + ~ClickableLabel(){}; + +signals: + void clicked(); + +protected: + void mousePressEvent(QMouseEvent *event) + { + emit clicked(); + } +}; + +class ClickableIconLabel : public IconLabel +{ + Q_OBJECT +public: + ClickableIconLabel(QWidget *parent, QIcon icon, QSize size) : IconLabel(parent, icon, size) + { + setCursor(Qt::PointingHandCursor); + } + + ~ClickableIconLabel(){}; + +signals: + void clicked(); + +protected: + void mousePressEvent(QMouseEvent *event) + { + emit clicked(); + } +}; ServerStatus::ServerStatus(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { @@ -67,19 +110,26 @@ void ServerStatus::addLine() void ServerStatus::addStatus(QString key, QString name) { { - auto label = new IconLabel(this, badIcon, QSize(16, 16)); + auto label = new ClickableIconLabel(this, badIcon, QSize(16, 16)); label->setToolTip(key); serverLabels[key] = label; layout->addWidget(label); + connect(label,SIGNAL(clicked()),SLOT(clicked())); } { - auto label = new QLabel(this); + auto label = new ClickableLabel(this); label->setText(name); label->setToolTip(key); layout->addWidget(label); + connect(label,SIGNAL(clicked()),SLOT(clicked())); } } +void ServerStatus::clicked() +{ + QDesktopServices::openUrl(QUrl("https://help.mojang.com/")); +} + void ServerStatus::setStatus(QString key, int value) { if (!serverLabels.contains(key)) @@ -127,3 +177,5 @@ void ServerStatus::StatusReloading(bool is_reloading) { m_statusRefresh->setChecked(is_reloading); } + +#include "ServerStatus.moc" diff --git a/application/widgets/ServerStatus.h b/application/widgets/ServerStatus.h index fdd43677..f0b6e223 100644 --- a/application/widgets/ServerStatus.h +++ b/application/widgets/ServerStatus.h @@ -22,6 +22,9 @@ public slots: void StatusChanged(const QMap statuses); void StatusReloading(bool is_reloading); +private slots: + void clicked(); + private: /* methods */ void addLine(); void addStatus(QString key, QString name);