[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bcalligra/kotext-annotations-skakoczky=5D_/=3A_=09mo?=
From:       Steven Kakoczky <steven.kakoczky () gmail ! com>
Date:       2011-06-16 0:51:25
Message-ID: 20110616005125.D0A5FA60A4 () git ! kde ! org
[Download RAW message or body]

Git commit 39a9be5c2a270a2d34dea4f8a16e7877d8fbb0ce by Steven Kakoczky.
Committed on 16/06/2011 at 02:48.
Pushed by kakoczky into branch 'kotext-annotations-skakoczky'.

modified:   libs/widgets/CMakeLists.txt
	new file:   libs/widgets/KoAnnotation.cpp
	new file:   libs/widgets/KoAnnotation.h
	modified:   libs/widgets/KoAnnotationSideBar.cpp
	modified:   libs/widgets/KoAnnotationSideBar.h
	modified:   libs/widgets/KoBalloon.cpp
	modified:   libs/widgets/KoBalloon.h
	modified:   words/part/KWView.cpp

M  +4    -0    libs/widgets/CMakeLists.txt     
A  +6    -0    libs/widgets/KoAnnotation.cpp         [License: UNKNOWN]  *
A  +22   -0    libs/widgets/KoAnnotation.h         [License: UNKNOWN]  *
M  +37   -4    libs/widgets/KoAnnotationSideBar.cpp     
M  +8    -2    libs/widgets/KoAnnotationSideBar.h     
M  +4    -4    libs/widgets/KoBalloon.cpp     
M  +6    -1    libs/widgets/KoBalloon.h     
M  +1    -1    words/part/KWView.cpp     

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/calligra/39a9be5c2a270a2d34dea4f8a16e7877d8fbb0ce

diff --git a/libs/widgets/CMakeLists.txt b/libs/widgets/CMakeLists.txt
index b2496b4..b9b687e 100644
--- a/libs/widgets/CMakeLists.txt
+++ b/libs/widgets/CMakeLists.txt
@@ -47,6 +47,8 @@ set(kowidgets_LIB_SRCS
     KoLineStyleModel.cpp
     KoDockWidgetTitleBar.cpp
     KoDockWidgetTitleBarButton.cpp
+    KoAnnotationSideBar.cpp
+    KoBalloon.cpp
 )
 
 kde4_add_ui_files( kowidgets_LIB_SRCS
@@ -105,6 +107,8 @@ install( FILES
     KoDockWidgetTitleBar.h
     KoDockWidgetTitleBar.h
     KoDockWidgetTitleBarButton.h
+    KoAnnotationSideBar.h
+    KoBalloon.h
 
     DESTINATION
     ${INCLUDE_INSTALL_DIR}
diff --git a/libs/widgets/KoAnnotation.cpp b/libs/widgets/KoAnnotation.cpp
new file mode 100644
index 0000000..825dd09
--- /dev/null
+++ b/libs/widgets/KoAnnotation.cpp
@@ -0,0 +1,6 @@
+#include "KoAnnotation.h"
+
+KoAnnotation::KoAnnotation(QString author, QDateTime date, QTextBlock content, QObject *parent = 0) :
+    QObject(parent), m_author(author), m_date(date), m_content(content)
+{
+}
diff --git a/libs/widgets/KoAnnotation.h b/libs/widgets/KoAnnotation.h
new file mode 100644
index 0000000..d7c1c8f
--- /dev/null
+++ b/libs/widgets/KoAnnotation.h
@@ -0,0 +1,22 @@
+#ifndef KOANNOTATION_H
+#define KOANNOTATION_H
+
+#include <QObject>
+
+class KoAnnotation : public QObject
+{
+    Q_OBJECT
+public:
+    explicit KoAnnotation(QString author, QDateTime date, QTextBlock content, QObject *parent = 0);
+    QString author(){return m_author;}
+    QDateTime date(){return m_date;}
+    QTextBlock content(){return m_content;}
+
+private:
+    QString m_author;
+    QDateTime m_date;
+    QTextBlock m_content;
+
+};
+
+#endif // KOANNOTATION_H
diff --git a/libs/widgets/KoAnnotationSideBar.cpp b/libs/widgets/KoAnnotationSideBar.cpp
index d86e297..c3c194e 100644
--- a/libs/widgets/KoAnnotationSideBar.cpp
+++ b/libs/widgets/KoAnnotationSideBar.cpp
@@ -3,11 +3,44 @@
 KoAnnotationSideBar::KoAnnotationSideBar(QWidget *parent) :
     QWidget(parent)
 {
-    annotations = new QList<KoBalloon>();
+    annotations = new QList<KoBalloon*>();
 }
 
-void KoAnnotationSideBar::addAnnotation(QString content)
+void KoAnnotationSideBar::addAnnotation(QString content, int position)
 {
-    // TODO: insert in order of KoBalloon y values
-    annotations.append(new KoBalloon(content, this));
+    KoBalloon *curr;
+    int i;
+    for(i = 0; i < annotations->size(); ++i)
+    {
+        curr = annotations->at(i);
+        if(curr->y() < position)
+        {
+            annotations->insert(i, new KoBalloon(content, position, this));
+            break;
+        }
+    }
+}
+
+void KoAnnotationSideBar::paintEvent(QPaintEvent *event)
+{
+    int i;
+    KoBalloon *curr;
+    QPainter painter(this);
+    painter.setBackgroundMode(Qt::OpaqueMode);
+    painter.setBackground(QBrush(Qt::gray));
+
+    setPositions();
+
+    for(i = 0; i < annotations->size(); ++i)
+    {
+        curr = annotations->at(i);
+        curr->paintEvent(event);
+        QPoint anchorConnection((curr->pos()).x() - 30, curr->y());// 30 pixels to the left of current \
balloon +        painter.drawLine(anchorConnection, curr->pos());
+    }
+}
+
+void KoAnnotationSideBar::setPositions()
+{
+    //TODO: algorithm to statically place note balloons
 }
diff --git a/libs/widgets/KoAnnotationSideBar.h b/libs/widgets/KoAnnotationSideBar.h
index 39326a4..1aca2e9 100644
--- a/libs/widgets/KoAnnotationSideBar.h
+++ b/libs/widgets/KoAnnotationSideBar.h
@@ -11,10 +11,16 @@ public:
     explicit KoAnnotationSideBar(QWidget *parent = 0);
 
     // add a new annotation to the list
-    void addAnnotation(QString content);
+    void addAnnotation(QString content, int position);
+    // overridden paint event
+    void paintEvent(QPaintEvent *event);
 
 private:
-    QList<KoBalloon*> annotations;
+    // set the positions of the balloons relative to eachother and the boundries
+    void setPositions();
+
+private:
+    QList<KoBalloon*> *annotations;
 
 };
 
diff --git a/libs/widgets/KoBalloon.cpp b/libs/widgets/KoBalloon.cpp
index c1a853e..1fca86c 100644
--- a/libs/widgets/KoBalloon.cpp
+++ b/libs/widgets/KoBalloon.cpp
@@ -1,16 +1,16 @@
 #include "KoBalloon.h"
 
-KoBalloon::KoBalloon(QString content, QWidget *parent) :
+KoBalloon::KoBalloon(QString content, int position, QWidget *parent) :
     QWidget(parent)
 {
     m_content = content;
+    m_y = position;
 }
 
 void KoBalloon::paintEvent(QPaintEvent *event)
 {
     QPainter painter(this);
-    painter.setPen(Qt::blue);
+    QBrush brush(Qt::green);
     painter.setBackgroundMode(Qt::OpaqueMode);
-    painter.setBrush(Qt::SolidPattern);
-    painter.drawRect(this->x, this->y, this->width, this->height);
+    painter.setBackground(brush);
 }
diff --git a/libs/widgets/KoBalloon.h b/libs/widgets/KoBalloon.h
index 046f8b3..b4e9d95 100644
--- a/libs/widgets/KoBalloon.h
+++ b/libs/widgets/KoBalloon.h
@@ -2,15 +2,20 @@
 #define KOBALLOON_H
 
 #include <QWidget>
+#include <QPainter>
 
 class KoBalloon : public QWidget
 {
     Q_OBJECT
 public:
-    explicit KoBalloon(QString content, QWidget *parent = 0);
+    explicit KoBalloon(QString content, int position, QWidget *parent = 0);
+
+    int y() {return m_y;}
+    virtual void paintEvent(QPaintEvent *event);
 
 private:
     QString m_content;
+    int m_y;
 
 };
 
diff --git a/words/part/KWView.cpp b/words/part/KWView.cpp
index cfc8e2a..007749e 100644
--- a/words/part/KWView.cpp
+++ b/words/part/KWView.cpp
@@ -156,7 +156,7 @@ KWView::KWView(const QString &viewMode, KWDocument *document, QWidget *parent)
     }
     // temp comments section
     KoAnnotationSideBar *commentbar = new KoAnnotationSideBar(this);
-    commentbar->addAnnotation(QString("This is a test"));
+    commentbar->addAnnotation(QString("This is a test"), 0);
     commentbar->setVisible(true);
 
     layout->addWidget(commentbar);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic