|
From: Tapio V. <aa...@us...> - 2011-01-12 13:35:01
|
Module: editor
Branch: master
Commit: e7c137cfa5f5d74ce51a4d2487aae778691eb6fa
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jan 11 22:08:41 2011 +0200
Use qobject_cast<> with widgets.
---
CMakeLists.txt | 2 +-
notegraphwidget.cc | 12 ++++++------
notelabel.cc | 2 +-
notelabel.hh | 2 ++
4 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5c77c4..af65e1a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,7 @@ find_package(Qt4 REQUIRED) # find and setup Qt4 for this project
include(${QT_USE_FILE})
# Headers that need MOC need to be defined separately
-file(GLOB MOC_HEADER_FILES "editorapp.hh" "notegraphwidget.hh")
+file(GLOB MOC_HEADER_FILES "editorapp.hh" "notelabel.hh" "notegraphwidget.hh")
file(GLOB SOURCE_FILES "*.cc")
file(GLOB HEADER_FILES "*.hh")
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 3e05b09..04492f7 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -48,7 +48,7 @@ void NoteGraphWidget::clear()
// Clear NoteLabels
const QObjectList &childlist = children();
for (QObjectList::const_iterator it = childlist.begin(); it != childlist.end(); ++it) {
- NoteLabel *child = dynamic_cast<NoteLabel*>(*it);
+ NoteLabel *child = qobject_cast<NoteLabel*>(*it);
if (child) child->close();
}
m_notes.clear();
@@ -165,7 +165,7 @@ void NoteGraphWidget::rebuildNoteList()
m_notes.clear();
const QObjectList &childlist = children();
for (QObjectList::const_iterator it = childlist.begin(); it != childlist.end(); ++it) {
- NoteLabel *child = dynamic_cast<NoteLabel*>(*it);
+ NoteLabel *child = qobject_cast<NoteLabel*>(*it);
if (child) m_notes.push_back(child);
}
m_notes.sort(cmpNoteLabelPtr);
@@ -173,7 +173,7 @@ void NoteGraphWidget::rebuildNoteList()
void NoteGraphWidget::mousePressEvent(QMouseEvent *event)
{
- NoteLabel *child = static_cast<NoteLabel*>(childAt(event->pos()));
+ NoteLabel *child = qobject_cast<NoteLabel*>(childAt(event->pos()));
if (!child) {
// Left click empty area = pan
if (event->button() == Qt::LeftButton)
@@ -241,7 +241,7 @@ void NoteGraphWidget::mouseReleaseEvent(QMouseEvent *event)
void NoteGraphWidget::wheelEvent(QWheelEvent *event)
{
- NoteLabel *child = static_cast<NoteLabel*>(childAt(event->pos()));
+ NoteLabel *child = qobject_cast<NoteLabel*>(childAt(event->pos()));
if (!child)
return;
@@ -256,7 +256,7 @@ void NoteGraphWidget::wheelEvent(QWheelEvent *event)
void NoteGraphWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
- NoteLabel *child = static_cast<NoteLabel*>(childAt(event->pos()));
+ NoteLabel *child = qobject_cast<NoteLabel*>(childAt(event->pos()));
if (!child)
return;
@@ -280,7 +280,7 @@ void NoteGraphWidget::mouseMoveEvent(QMouseEvent *event)
setCursor(QCursor(Qt::ClosedHandCursor));
QScrollArea *scrollArea = NULL;
if (parentWidget() && parentWidget()->parent())
- scrollArea = dynamic_cast<QScrollArea*>(parentWidget()->parent()->parent());
+ scrollArea = qobject_cast<QScrollArea*>(parentWidget()->parent()->parent());
if (scrollArea) {
QPoint diff = event->pos() - m_panHotSpot;
QScrollBar *scrollHor = scrollArea->horizontalScrollBar();
diff --git a/notelabel.cc b/notelabel.cc
index 6eb46d8..359751f 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -91,7 +91,7 @@ void NoteLabel::mouseMoveEvent(QMouseEvent *event)
{
QToolTip::showText(event->globalPos(), toolTip(), this);
- NoteGraphWidget* ngw = dynamic_cast<NoteGraphWidget*>(parent());
+ NoteGraphWidget* ngw = qobject_cast<NoteGraphWidget*>(parent());
if (m_resizing != 0) {
// Resizing
if (m_resizing < 0)
diff --git a/notelabel.hh b/notelabel.hh
index 44c7eac..b36e0d0 100644
--- a/notelabel.hh
+++ b/notelabel.hh
@@ -5,6 +5,8 @@
class NoteLabel: public QLabel
{
+ Q_OBJECT
+
public:
static const int resize_margin;
static const int min_width;
|