File indexing completed on 2024-07-07 07:09:17

0001 /*
0002     SPDX-FileCopyrightText: 2010 Valery Kharitonov <kharvd@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kshelplabel.h"
0008 #include "Options.h"
0009 #include <KHelpClient>
0010 #include <QMessageBox>
0011 #include <QDesktopServices>
0012 
0013 KSHelpLabel::KSHelpLabel(const QString &text, const QString &anchor, QWidget *parent) : QLabel(parent), m_anchor(anchor)
0014 {
0015     setText(text);
0016     updateText();
0017     connect(this, SIGNAL(linkActivated(QString)), SLOT(slotShowDefinition(QString)));
0018 }
0019 
0020 KSHelpLabel::KSHelpLabel(QWidget *parent) : QLabel(parent)
0021 {
0022     connect(this, SIGNAL(linkActivated(QString)), SLOT(slotShowDefinition(QString)));
0023 }
0024 
0025 void KSHelpLabel::setAnchor(const QString &anchor)
0026 {
0027     m_anchor = anchor;
0028     updateText();
0029 }
0030 
0031 void KSHelpLabel::updateText()
0032 {
0033     //TODO This function probably needs to be removed since the theme setting stakes care already of link colors
0034     /*
0035     QString linkcolor =
0036         (Options::darkAppColors() ?
0037              "red" :
0038              "blue"); // In night colors mode, use red links because blue links are black through a red filter.
0039     QLabel::setText("<a href=\"ai-" + m_anchor + "\" style=\"color: " + linkcolor + "\" >" + text() + "</a>");
0040     */
0041     QLabel::setText("<a href=\"ai-" + m_anchor + "\">" + text() + "</a>");
0042 }
0043 
0044 void KSHelpLabel::slotShowDefinition(const QString &term)
0045 {
0046 #ifdef Q_OS_OSX // This is because KHelpClient doesn't seem to be working right on MacOS
0047     QDesktopServices::openUrl(QUrl("https://docs.kde.org/trunk5/en/kstars/kstars/index.html"));
0048 #else
0049     KHelpClient::invokeHelp(term);
0050 #endif
0051 }
0052 
0053 void KSHelpLabel::setText(const QString &txt)
0054 {
0055     m_cleanText = txt;
0056     updateText();
0057 }