[Kstars-devel] [kstars/code-in] kstars/widgets: Fixed last commit: added the KSHelpLabel class.
Victor Carbune
victor.carbune at gmail.com
Mon Jul 18 02:42:10 CEST 2011
Git commit fe699bcac95a370101c7a0758631df58ab355378 by Victor Carbune.
Committed on 01/12/2010 at 14:34.
Pushed by nalvarez into branch 'code-in'.
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 +57 -0 kstars/widgets/kshelplabel.h [License: UNKNOWN] *
A +34 -0 kstars/widgets/kshelplabel.cpp [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/fe699bcac95a370101c7a0758631df58ab355378
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