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

List:       kde-commits
Subject:    [calligra/krita_locking_langkamp] krita/ui: added a check for node editablity, show a notification i
From:       Sven Langkamp <sven.langkamp () gmail ! com>
Date:       2012-06-30 18:37:04
Message-ID: 20120630183704.8FC50A60C6 () git ! kde ! org
[Download RAW message or body]

Git commit c10816ae1b836211b088a86a1d3cebb614a8729c by Sven Langkamp.
Committed on 30/06/2012 at 19:49.
Pushed by langkamp into branch 'krita_locking_langkamp'.

added a check for node editablity, show a notification if users tries to paint anyway

M  +18   -0    krita/ui/tool/kis_tool.cc
M  +3    -0    krita/ui/tool/kis_tool.h
M  +4    -0    krita/ui/tool/kis_tool_freehand.cc
M  +17   -2    krita/ui/widgets/kis_floating_message.cpp
M  +6    -1    krita/ui/widgets/kis_floating_message.h

http://commits.kde.org/calligra/c10816ae1b836211b088a86a1d3cebb614a8729c

diff --git a/krita/ui/tool/kis_tool.cc b/krita/ui/tool/kis_tool.cc
index f65437d..ce821d5 100644
--- a/krita/ui/tool/kis_tool.cc
+++ b/krita/ui/tool/kis_tool.cc
@@ -59,6 +59,7 @@
 #include <kis_pattern.h>
 #include <kis_transaction.h>
 #include <kis_selection.h>
+#include <kis_floating_message.h>
 
 #include "kis_canvas_resource_provider.h"
 #include "canvas/kis_canvas2.h"
@@ -690,5 +691,22 @@ void KisTool::setCurrentNodeLocked(bool locked)
     }
 }
 
+bool KisTool::nodeEditable()
+{
+    KisNodeSP node = currentNode();
+    if (!node) {
+        return false;
+    }
+    if (!node->isEditable()) {
+        KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
+        KisFloatingMessage *floatingMessage = new KisFloatingMessage(i18n("Layer is locked."),
+                                                                     kiscanvas->canvasWidget());
+        floatingMessage->setShowOverParent(true);
+        floatingMessage->setIcon(KIcon("object-locked"));
+        floatingMessage->showMessage();
+    }
+    return node->isEditable();
+}
+
 #include "kis_tool.moc"
 
diff --git a/krita/ui/tool/kis_tool.h b/krita/ui/tool/kis_tool.h
index fee096b..c86bf26 100644
--- a/krita/ui/tool/kis_tool.h
+++ b/krita/ui/tool/kis_tool.h
@@ -197,6 +197,9 @@ protected:
     /// Sets the systemLocked for the current node, this will not deactivate the tool buttons
     void setCurrentNodeLocked(bool locked);
 
+    /// Checks checks if the current node is editable
+    bool nodeEditable();
+
 protected:
     enum ToolMode {
         HOVER_MODE,
diff --git a/krita/ui/tool/kis_tool_freehand.cc b/krita/ui/tool/kis_tool_freehand.cc
index 675f3d7..6167b18 100644
--- a/krita/ui/tool/kis_tool_freehand.cc
+++ b/krita/ui/tool/kis_tool_freehand.cc
@@ -216,6 +216,10 @@ void KisToolFreehand::mousePressEvent(KoPointerEvent *e)
         if (nodePaintAbility() != PAINT)
             return;
 
+        if (!nodeEditable()) {
+            return;
+        }
+
         setMode(KisTool::PAINT_MODE);
 
         KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2 *>(canvas());
diff --git a/krita/ui/widgets/kis_floating_message.cpp b/krita/ui/widgets/kis_floating_message.cpp
index c72b10c..bff3b67 100644
--- a/krita/ui/widgets/kis_floating_message.cpp
+++ b/krita/ui/widgets/kis_floating_message.cpp
@@ -123,9 +123,10 @@ namespace ShadowEngine
 
 #define OSD_WINDOW_OPACITY 0.74
 
-KisFloatingMessage::KisFloatingMessage(const QString &message, QWidget *parent)
+KisFloatingMessage::KisFloatingMessage(const QString &message, QWidget *parent, bool showOverParent)
     : QWidget(parent)
     , m_message(message)
+    , m_showOverParent(showOverParent)
 {
     KIcon icon("krita");
     m_icon = icon.pixmap(256, 256).toImage();
@@ -152,6 +153,16 @@ void KisFloatingMessage::showMessage()
     m_timer.start(4500);
 }
 
+void KisFloatingMessage::setShowOverParent(bool show)
+{
+    m_showOverParent = show;
+}
+
+void KisFloatingMessage::setIcon(const QIcon& icon)
+{
+    m_icon = icon.pixmap(256, 256).toImage();
+}
+
 const int MARGIN = 20;
 
 QRect KisFloatingMessage::determineMetrics( const int M )
@@ -190,7 +201,11 @@ QRect KisFloatingMessage::determineMetrics( const int M )
     rect.adjust( -M, -M, M, M );
 
     const QSize newSize = rect.size();
-    const QRect screen = QApplication::desktop()->screenGeometry(parentWidget());
+    QRect screen = QApplication::desktop()->screenGeometry(parentWidget());
+    if (parentWidget() && m_showOverParent) {
+        screen = parentWidget()->geometry();
+        screen.setTopLeft(parentWidget()->mapToGlobal(QPoint(0, 0)));
+    }
     QPoint newPos(MARGIN, MARGIN);
 
     // move to the right
diff --git a/krita/ui/widgets/kis_floating_message.h b/krita/ui/widgets/kis_floating_message.h
index 19040c2..79da217 100644
--- a/krita/ui/widgets/kis_floating_message.h
+++ b/krita/ui/widgets/kis_floating_message.h
@@ -43,9 +43,13 @@ class KisFloatingMessage : public QWidget
 
 public:
 
-    explicit KisFloatingMessage(const QString &message, QWidget *parent);
+    explicit KisFloatingMessage(const QString &message, QWidget *parent, bool showOverParent = false);
     void showMessage();
 
+    /// Show message above parent widget instead of screen
+    void setShowOverParent(bool show);
+
+    void setIcon(const QIcon& icon);
 protected:
 
     void paintEvent(QPaintEvent *e);
@@ -65,6 +69,7 @@ private:
     QTimer m_timer;
     int m_m;
     QTimeLine m_fadeTimeLine;
+    bool m_showOverParent;
 };
 
 #endif // KIS_FLOATING_MESSAGE_H
[prev in list] [next in list] [prev in thread] [next in thread] 

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