[Kstars-devel] [kstars] kstars/widgets: Fixed last commit: added the KSHelpLabel class.
Akarsh Simha
akarshsimha at gmail.com
Mon Jul 2 14:26:43 UTC 2012
Git commit f782a6d871015bbdc41c5b874f97b9c4009b65d1 by Akarsh Simha, on behalf of Victor Carbune.
Committed on 01/12/2010 at 14:34.
Pushed by asimha into branch 'master'.
Fixed last commit: added the KSHelpLabel class.
CCMAIL: kstars-devel at kde.org, kharvd at gmail.com
svn path=/branches/kstars/code-in/kstars/; revision=1202587
A +34 -0 kstars/widgets/kshelplabel.cpp [License: UNKNOWN] *
A +57 -0 kstars/widgets/kshelplabel.h [License: UNKNOWN] *
The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.
http://commits.kde.org/kstars/f782a6d871015bbdc41c5b874f97b9c4009b65d1
diff --git a/kstars/widgets/kshelplabel.cpp b/kstars/widgets/kshelplabel.cpp
new file mode 100644
index 0000000..a094742
--- /dev/null
+++ b/kstars/widgets/kshelplabel.cpp
@@ -0,0 +1,34 @@
+#include "kshelplabel.h"
+#include <ktoolinvocation.h>
+#include <QtGui/QMessageBox>
+
+KSHelpLabel::KSHelpLabel(const QString& text, const QString& anchor,
+ QWidget *parent) : QLabel(parent), m_anchor(anchor)
+{
+ setText(text);
+ updateText();
+ connect(this, SIGNAL(linkActivated(QString)), SLOT(slotShowDefinition(QString)));
+}
+
+KSHelpLabel::KSHelpLabel(QWidget *parent) : QLabel(parent)
+{
+ connect(this, SIGNAL(linkActivated(QString)), SLOT(slotShowDefinition(QString)));
+}
+
+void KSHelpLabel::setAnchor(const QString& anchor) {
+ m_anchor = anchor;
+ updateText();
+}
+
+void KSHelpLabel::updateText() {
+ QLabel::setText("<a href=\"ai-" + m_anchor + "\">" + text() + "</a>");
+}
+
+void KSHelpLabel::slotShowDefinition(const QString & term) {
+ KToolInvocation::invokeHelp(term);
+}
+
+void KSHelpLabel::setText(const QString& txt) {
+ m_cleanText = txt;
+ QLabel::setText("<a href=\"ai-" + m_anchor + "\">" + m_cleanText + "</a>");
+}
\ No newline at end of file
diff --git a/kstars/widgets/kshelplabel.h b/kstars/widgets/kshelplabel.h
new file mode 100644
index 0000000..ad772de
--- /dev/null
+++ b/kstars/widgets/kshelplabel.h
@@ -0,0 +1,57 @@
+#ifndef KSHELPLABEL_H
+#define KSHELPLABEL_H
+
+#include <QtGui/qlabel.h>
+
+/** Label for displaying links to AstroInfo project
+ * @author Valery Kharitonov
+ */
+class KSHelpLabel : public QLabel
+{
+ Q_OBJECT
+ Q_PROPERTY(QString anchor READ anchor WRITE setAnchor)
+ Q_PROPERTY(QString text READ text WRITE setText)
+
+public:
+ /**
+ * Constructor. Creates clear label
+ */
+ KSHelpLabel(QWidget *parent = 0);
+
+ /**
+ * Constructor. Creates label with a text and help anchor.
+ * @param text Text of the label
+ * @param anchor Name of the section in the AstroInfo project (without 'ai-')
+ */
+ KSHelpLabel(const QString& text, const QString& anchor,
+ QWidget *parent = 0);
+
+ QString text() { return m_cleanText; }
+ void setText(const QString& text);
+
+ void setAnchor(const QString& anchor);
+ QString anchor() { return m_anchor; }
+
+private slots:
+ /** Open AstroInfo definition of the terms
+ * @param term jargon term */
+ void slotShowDefinition(const QString & term);
+
+private:
+ /**
+ * Updates text with the new anchor
+ */
+ void updateText();
+
+ /**
+ * Anchor in AstroInfo project
+ */
+ QString m_anchor;
+
+ /**
+ * String without markup
+ */
+ QString m_cleanText;
+};
+
+#endif // KSHELPLABEL_H
More information about the Kstars-devel
mailing list