From kde-commits Sat Jun 30 18:37:04 2012 From: Sven Langkamp Date: Sat, 30 Jun 2012 18:37:04 +0000 To: kde-commits Subject: [calligra/krita_locking_langkamp] krita/ui: added a check for node editablity, show a notification i Message-Id: <20120630183704.8FC50A60C6 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=134108165923062 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 pa= int 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 #include #include +#include = #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 =3D currentNode(); + if (!node) { + return false; + } + if (!node->isEditable()) { + KisCanvas2 * kiscanvas =3D static_cast(canvas()); + KisFloatingMessage *floatingMessage =3D new KisFloatingMessage(i18= n("Layer is locked."), + kisca= nvas->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 deactiva= te 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_fr= eehand.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() !=3D PAINT) return; = + if (!nodeEditable()) { + return; + } + setMode(KisTool::PAINT_MODE); = KisCanvas2 *canvas2 =3D dynamic_cast(canvas()); diff --git a/krita/ui/widgets/kis_floating_message.cpp b/krita/ui/widgets/k= is_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 *pa= rent) +KisFloatingMessage::KisFloatingMessage(const QString &message, QWidget *pa= rent, bool showOverParent) : QWidget(parent) , m_message(message) + , m_showOverParent(showOverParent) { KIcon icon("krita"); m_icon =3D icon.pixmap(256, 256).toImage(); @@ -152,6 +153,16 @@ void KisFloatingMessage::showMessage() m_timer.start(4500); } = +void KisFloatingMessage::setShowOverParent(bool show) +{ + m_showOverParent =3D show; +} + +void KisFloatingMessage::setIcon(const QIcon& icon) +{ + m_icon =3D icon.pixmap(256, 256).toImage(); +} + const int MARGIN =3D 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 =3D rect.size(); - const QRect screen =3D QApplication::desktop()->screenGeometry(parentW= idget()); + QRect screen =3D QApplication::desktop()->screenGeometry(parentWidget(= )); + if (parentWidget() && m_showOverParent) { + screen =3D 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, b= ool showOverParent =3D 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