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

List:       kde-commits
Subject:    [calligra/moji] /: Button to chanage writing direction.thanks to
From:       Mojtaba Shahi Senobari <mojtaba.shahi3000 () gmail ! com>
Date:       2011-12-15 19:36:12
Message-ID: 20111215193612.A0E3DA60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 52624f5b6eceead561212c41191a38095e14ffe1 by Mojtaba Shahi Senobari.
Committed on 12/12/2011 at 14:13.
Pushed by mojtabashahi into branch 'moji'.

Button to chanage writing direction.thanks to boemann and ingwa for helping me in my \
first commit. patch approved by boemann.

M  +1    -3    libs/kotext/KoTextEditor.cpp
M  +21   -0    plugins/textshape/TextTool.cpp
M  +6    -1    plugins/textshape/TextTool.h
M  +14   -71   plugins/textshape/dialogs/SimpleParagraphWidget.cpp
M  +1    -1    plugins/textshape/dialogs/SimpleParagraphWidget.h
M  +1    -1    plugins/textshape/dialogs/SimpleParagraphWidget.ui

http://commits.kde.org/calligra/52624f5b6eceead561212c41191a38095e14ffe1

diff --git a/libs/kotext/KoTextEditor.cpp b/libs/kotext/KoTextEditor.cpp
index 48e85d3..f5b7358 100644
--- a/libs/kotext/KoTextEditor.cpp
+++ b/libs/kotext/KoTextEditor.cpp
@@ -1796,9 +1796,7 @@ void KoTextEditor::mergeBlockFormat(const QTextBlockFormat \
&modifier)  if (isEditProtected()) {
         return;
     }
-
-    Q_UNUSED(modifier)
-    //TODO
+    d->caret.mergeBlockFormat(modifier);
 }
 
 void KoTextEditor::mergeCharFormat(const QTextCharFormat &modifier)
diff --git a/plugins/textshape/TextTool.cpp b/plugins/textshape/TextTool.cpp
index 4c13188..b620319 100644
--- a/plugins/textshape/TextTool.cpp
+++ b/plugins/textshape/TextTool.cpp
@@ -4,6 +4,7 @@
  * Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in>
  * Copyright (C) 2008 Pierre Stirnweiss <pierre.stirnweiss_calligra@gadz.org>
  * Copyright (C) 2009 KO GmbH <cbo@kogmbh.com>
+ * Copyright (C) 2011 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -250,6 +251,14 @@ void TextTool::createActions()
     alignmentGroup->addAction(m_actionAlignBlock);
     connect(m_actionAlignBlock, SIGNAL(triggered(bool)), this, SLOT(alignBlock()));
 
+    m_actionChangeDirection = new KAction(KIcon("format-text-direction-ltr"), \
i18n("Change text direction"), this); +    addAction("change_text_direction", \
m_actionChangeDirection); +    m_actionChangeDirection->setToolTip(i18n("Change \
writing direction")); +    m_actionChangeDirection->setShortcut(Qt::CTRL + Qt::SHIFT \
+ Qt::Key_D); +    m_actionChangeDirection->setCheckable(true);
+    connect(m_actionChangeDirection, SIGNAL(triggered()), this, \
SLOT(textDirectionChanged())); +
+
     m_actionFormatSuper = new KAction(KIcon("format-text-superscript"), \
i18n("Superscript"), this);  addAction("format_super", m_actionFormatSuper);
     m_actionFormatSuper->setCheckable(true);
@@ -2350,4 +2359,16 @@ void TextTool::debugTextStyles()
 #endif
 }
 
+void TextTool::textDirectionChanged()
+{
+    QTextBlockFormat blockFormat;
+    if (m_actionChangeDirection->isChecked()) {
+        blockFormat.setProperty(KoParagraphStyle::TextProgressionDirection, \
KoText::RightLeftTopBottom); +    }
+    else {
+        blockFormat.setProperty(KoParagraphStyle::TextProgressionDirection, \
KoText::LeftRightTopBottom); +     }
+    m_textEditor.data()->mergeBlockFormat(blockFormat);
+}
+
 #include <TextTool.moc>
diff --git a/plugins/textshape/TextTool.h b/plugins/textshape/TextTool.h
index 9006316..3dafaa4 100644
--- a/plugins/textshape/TextTool.h
+++ b/plugins/textshape/TextTool.h
@@ -2,6 +2,7 @@
  * Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
  * Copyright (C) 2009 KO GmbH <cbo@kogmbh.com>
+ * Copyright (C) 2011 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -285,6 +286,9 @@ private slots:
 
     void testSlot(bool);
 
+    /// change block text direction
+    void textDirectionChanged();
+
 private:
     void repaintCaret();
     void repaintSelection();
@@ -338,6 +342,8 @@ private:
     KAction *m_growWidthAction;
     KAction *m_growHeightAction;
     KAction *m_shrinkToFitAction;
+    KAction *m_actionChangeDirection;
+
     FontSizeAction *m_actionFormatFontSize;
     KFontAction *m_actionFormatFontFamily;
     KoColorPopupAction *m_actionFormatTextColor;
@@ -358,7 +364,6 @@ private:
     int m_changeTipCursorPos;
     QPoint m_changeTipPos;
     bool m_delayedEnsureVisible;
-
     TextToolSelection *m_toolSelection;
 };
 
diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp \
b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp index f7e61ca..a5302b5 100644
--- a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp
+++ b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp
@@ -1,6 +1,7 @@
 /* This file is part of the KDE project
  * Copyright (C) 2007, 2008, 2010 Thomas Zander <zander@kde.org>
  * Copyright (C) 2009-2010 Casper Boemann <cbo@boemann.dk>
+ * Copyright (C) 2011 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -34,7 +35,6 @@
 #include <KoStyleManager.h>
 #include <KoListLevelProperties.h>
 #include <KoShapePaintingContext.h>
-
 #include <KDebug>
 
 #include <QTextLayout>
@@ -60,6 +60,8 @@ SimpleParagraphWidget::SimpleParagraphWidget(TextTool *tool, \
QWidget *parent)  
     widget.decreaseIndent->setDefaultAction(tool->action("format_decreaseindent"));
     widget.increaseIndent->setDefaultAction(tool->action("format_increaseindent"));
+    widget.changeTextDirection->setDefaultAction(tool->action("change_text_direction"));
 +    connect(widget.changeTextDirection, SIGNAL(clicked()), this, \
                SIGNAL(doneWithFocus()));
     connect(widget.alignCenter, SIGNAL(clicked(bool)), this, \
                SIGNAL(doneWithFocus()));
     connect(widget.alignBlock, SIGNAL(clicked(bool)), this, \
                SIGNAL(doneWithFocus()));
     connect(widget.alignLeft, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
@@ -77,11 +79,9 @@ SimpleParagraphWidget::SimpleParagraphWidget(TextTool *tool, \
QWidget *parent)  
     fillListButtons();
     widget.bulletListButton->addSeparator();
-    //widget.bulletListButton->addAction(new QAction("fgfd",0));
 
     connect(widget.bulletListButton, SIGNAL(itemTriggered(int)), this, \
                SLOT(listStyleChanged(int)));
     connect(widget.numberedListButton, SIGNAL(itemTriggered(int)), this, \
                SLOT(listStyleChanged(int)));
-    connect(widget.reversedText, SIGNAL(clicked()), this, \
SLOT(directionChangeRequested()));  
     m_stylePopup = new StylesWidget(this, true, Qt::Popup);
     m_stylePopup->setFrameShape(QFrame::StyledPanel);
@@ -100,68 +100,6 @@ SimpleParagraphWidget::~SimpleParagraphWidget()
     delete m_thumbnailer;
 }
 
-void SimpleParagraphWidget::directionChangeRequested()
-{
-    KoTextEditor *editor = m_tool->textEditor();
-    QTextBlockFormat format;
-    KoText::Direction dir = \
                static_cast<KoText::Direction>(m_currentBlock.blockFormat()
-            .intProperty(KoParagraphStyle::TextProgressionDirection));
-    switch (dir) {
-    case KoText::PerhapsLeftRightTopBottom:
-    case KoText::LeftRightTopBottom:
-        format.setProperty(KoParagraphStyle::TextProgressionDirection, \
                KoText::RightLeftTopBottom);
-        updateDirection(RTL);
-        break;
-    case KoText::InheritDirection:
-    case KoText::AutoDirection:
-        updateDirection(LTR);
-        format.setProperty(KoParagraphStyle::TextProgressionDirection, \
                KoText::LeftRightTopBottom);
-        break;
-    case KoText::PerhapsRightLeftTopBottom:
-    case KoText::RightLeftTopBottom: {
-        updateDirection(Auto);
-        // clearProperty won't have any effect on merge below.
-        int start = qMin(editor->position(), editor->anchor());
-        int end = qMax(editor->position(), editor->anchor());
-        Q_ASSERT(start >= 0);
-        editor->setPosition(start);
-        while (editor->position() <= end) {
-            QTextBlockFormat bf = editor->blockFormat();
-            bf.clearProperty(KoParagraphStyle::TextProgressionDirection);
-            editor->setBlockFormat(bf);
-            if (!editor->movePosition(QTextCursor::NextBlock))
-                break;
-        }
-        emit doneWithFocus();
-        return;
-    }
-    case KoText::TopBottomRightLeft: ;// Unhandled.
-        break;
-    };
-    editor->mergeBlockFormat(format);
-    emit doneWithFocus();
-}
-
-void SimpleParagraphWidget::updateDirection(DirectionButtonState state)
-{
-    if (m_directionButtonState == state) return;
-    m_directionButtonState = state;
-    QString buttonText;
-    switch (state) {
-    case LTR:
-        buttonText = i18nc("Short for LeftToRight", "LTR");
-        break;
-    case RTL:
-        buttonText = i18nc("Short for RightToLeft", "RTL");
-        break;
-    default:
-    case Auto:
-        buttonText = i18nc("Automatic direction detection", "Auto");
-        break;
-    }
-    widget.reversedText->setText(buttonText);
-}
-
 void SimpleParagraphWidget::fillListButtons()
 {
     KoZoomHandler zoomHandler;
@@ -230,17 +168,22 @@ void SimpleParagraphWidget::setCurrentBlock(const QTextBlock \
&block)  };
     Finally finally(this);
 
-    widget.reversedText->setVisible(m_tool->isBidiDocument());
     QTextLayout *layout = block.layout();
     if (layout) {
-        switch (layout->textOption().textDirection()) {
-        case Qt::LeftToRight: updateDirection(LTR); break;
-        case Qt::RightToLeft: updateDirection(RTL); break;
-        default:
+        switch(layout->textOption().textDirection())
+        {
+        case Qt::LeftToRight:
+             widget.changeTextDirection->setChecked(false);
+             break;
+        case Qt::RightToLeft:
+            widget.changeTextDirection->setChecked(true);
             break;
-        }
+        default:
+              break;
+            }
     }
 
+
     QTextBlockFormat format;
 
     int id = format.intProperty(KoParagraphStyle::StyleId);
diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.h \
b/plugins/textshape/dialogs/SimpleParagraphWidget.h index a6fbaff..041f3d6 100644
--- a/plugins/textshape/dialogs/SimpleParagraphWidget.h
+++ b/plugins/textshape/dialogs/SimpleParagraphWidget.h
@@ -1,6 +1,7 @@
 /* This file is part of the KDE project
  * Copyright (C) 2007 Thomas Zander <zander@kde.org>
  * Copyright (C) 2010 Casper Boemann <cbo@boemann.dk>
+ * Copyright (C) 2011 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -50,7 +51,6 @@ signals:
     void paragraphStyleSelected(KoParagraphStyle *);
 
 private slots:
-    void directionChangeRequested();
     void listStyleChanged(int id);
 
 private:
diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.ui \
b/plugins/textshape/dialogs/SimpleParagraphWidget.ui index bb5f4e7..2f0fae3 100644
--- a/plugins/textshape/dialogs/SimpleParagraphWidget.ui
+++ b/plugins/textshape/dialogs/SimpleParagraphWidget.ui
@@ -60,7 +60,7 @@
       </widget>
      </item>
      <item row="2" column="8">
-      <widget class="QToolButton" name="reversedText"/>
+      <widget class="QToolButton" name="changeTextDirection"/>
      </item>
      <item row="2" column="9">
       <widget class="QuickTableButton" name="quickTable">


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

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