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

List:       kde-commits
Subject:    [ktouch/next] src: resource editor: implement editing of special key properties
From:       Sebastian Gottfried <sebastiangottfried () web ! de>
Date:       2012-07-31 18:53:27
Message-ID: 20120731185327.F22BDA60C9 () git ! kde ! org
[Download RAW message or body]

Git commit 031078f0a23c3473bb6b1dd2191e542d682a4bcc by Sebastian Gottfried.
Committed on 31/07/2012 at 20:37.
Pushed by gottfried into branch 'next'.

resource editor: implement editing of special key properties

M  +123  -0    src/editor/keyboardlayoutcommands.cpp
M  +47   -0    src/editor/keyboardlayoutcommands.h
M  +82   -3    src/editor/keyboardlayoutpropertieswidget.cpp
M  +7    -0    src/editor/keyboardlayoutpropertieswidget.h
M  +22   -2    src/ui/keyboardlayoutpropertieswidget.ui

http://commits.kde.org/ktouch/031078f0a23c3473bb6b1dd2191e542d682a4bcc

diff --git a/src/editor/keyboardlayoutcommands.cpp \
b/src/editor/keyboardlayoutcommands.cpp index e5e1712..83a2412 100644
--- a/src/editor/keyboardlayoutcommands.cpp
+++ b/src/editor/keyboardlayoutcommands.cpp
@@ -265,3 +265,126 @@ bool SetKeyHasHapticMarkerCommand::mergeWith(const \
                QUndoCommand* other)
     m_newHasHapticMarker = setKeyHasHapticMarkerCommand->m_newHasHapticMarker;
     return true;
 }
+
+SetSpecialKeyTypeCommand::SetSpecialKeyTypeCommand(KeyboardLayout* layout, int \
keyIndex, SpecialKey::Type newType, QUndoCommand* parent) : +    \
QUndoCommand(parent), +    m_layout(layout),
+    m_keyIndex(keyIndex),
+    m_newType(newType)
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    m_oldType = key->type();
+}
+
+void SetSpecialKeyTypeCommand::undo()
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    key->setType(m_oldType);
+}
+
+void SetSpecialKeyTypeCommand::redo()
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    key->setType(m_newType);
+}
+
+int SetSpecialKeyTypeCommand::id() const
+{
+    return 0xf1ce4bee;
+}
+
+bool SetSpecialKeyTypeCommand::mergeWith(const QUndoCommand* other)
+{
+    const SetSpecialKeyTypeCommand* setSpecialKeyTypeCommand = static_cast<const \
SetSpecialKeyTypeCommand*>(other); +
+    if (m_layout != setSpecialKeyTypeCommand->m_layout)
+        return false;
+
+    if (m_keyIndex != setSpecialKeyTypeCommand->m_keyIndex)
+        return false;
+
+    m_newType = setSpecialKeyTypeCommand->m_newType;
+    return true;
+}
+
+SetSpecialKeyLabelCommand::SetSpecialKeyLabelCommand(KeyboardLayout* layout, int \
keyIndex, const QString& newLabel, QUndoCommand* parent) : +    QUndoCommand(parent),
+    m_layout(layout),
+    m_keyIndex(keyIndex),
+    m_newLabel(newLabel)
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    m_oldLabel = key->label();
+}
+
+void SetSpecialKeyLabelCommand::undo()
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    key->setLabel(m_oldLabel);
+}
+
+void SetSpecialKeyLabelCommand::redo()
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    key->setLabel(m_newLabel);
+}
+
+int SetSpecialKeyLabelCommand::id() const
+{
+    return 0x6a1ddec9;
+}
+
+bool SetSpecialKeyLabelCommand::mergeWith(const QUndoCommand* other)
+{
+    const SetSpecialKeyLabelCommand* setSpecialKeyLabelCommand = static_cast<const \
SetSpecialKeyLabelCommand*>(other); +
+    if (m_layout != setSpecialKeyLabelCommand->m_layout)
+        return false;
+
+    if (m_keyIndex != setSpecialKeyLabelCommand->m_keyIndex)
+        return false;
+
+    m_newLabel = setSpecialKeyLabelCommand->m_newLabel;
+    return true;
+}
+
+SetSpecialKeyModifierIdCommand::SetSpecialKeyModifierIdCommand(KeyboardLayout* \
layout, int keyIndex, const QString& newModifiewId, QUndoCommand* parent) : +    \
QUndoCommand(parent), +    m_layout(layout),
+    m_keyIndex(keyIndex),
+    m_newModifierId(newModifiewId)
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    m_oldModifierId = key->modifierId();
+}
+
+void SetSpecialKeyModifierIdCommand::undo()
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    key->setModifierId(m_oldModifierId);
+}
+
+void SetSpecialKeyModifierIdCommand::redo()
+{
+    SpecialKey* key = qobject_cast<SpecialKey*>(m_layout->key(m_keyIndex));
+    key->setModifierId(m_newModifierId);
+}
+
+int SetSpecialKeyModifierIdCommand::id() const
+{
+    return 0xafabebaf;
+}
+
+bool SetSpecialKeyModifierIdCommand::mergeWith(const QUndoCommand* other)
+{
+    const SetSpecialKeyModifierIdCommand* setSpecialKeyModifierIdCommand = \
static_cast<const SetSpecialKeyModifierIdCommand*>(other); +
+    if (m_layout != setSpecialKeyModifierIdCommand->m_layout)
+        return false;
+
+    if (m_keyIndex != setSpecialKeyModifierIdCommand->m_keyIndex)
+        return false;
+
+    m_newModifierId = setSpecialKeyModifierIdCommand->m_newModifierId;
+    return true;
+}
diff --git a/src/editor/keyboardlayoutcommands.h \
b/src/editor/keyboardlayoutcommands.h index db83db1..5c64dfc 100644
--- a/src/editor/keyboardlayoutcommands.h
+++ b/src/editor/keyboardlayoutcommands.h
@@ -21,6 +21,8 @@
 #include <QUndoStack>
 #include <QRect>
 
+#include "core/specialkey.h"
+
 class KeyboardLayout;
 
 class SetKeyboardLayoutTitleCommand : public QUndoCommand
@@ -110,4 +112,49 @@ private:
     bool m_newHasHapticMarker;
 };
 
+class SetSpecialKeyTypeCommand : public QUndoCommand
+{
+public:
+    explicit SetSpecialKeyTypeCommand(KeyboardLayout* layout, int keyIndex, \
SpecialKey::Type newType, QUndoCommand* parent = 0); +    void undo();
+    void redo();
+    int id() const;
+    bool mergeWith(const QUndoCommand* other);
+private:
+    KeyboardLayout* m_layout;
+    int m_keyIndex;
+    SpecialKey::Type m_oldType;
+    SpecialKey::Type m_newType;
+};
+
+class SetSpecialKeyLabelCommand : public QUndoCommand
+{
+public:
+    explicit SetSpecialKeyLabelCommand(KeyboardLayout* layout, int keyIndex, const \
QString& newLabel, QUndoCommand* parent = 0); +    void undo();
+    void redo();
+    int id() const;
+    bool mergeWith(const QUndoCommand* other);
+private:
+    KeyboardLayout* m_layout;
+    int m_keyIndex;
+    QString m_oldLabel;
+    QString m_newLabel;
+};
+
+class SetSpecialKeyModifierIdCommand : public QUndoCommand
+{
+public:
+    explicit SetSpecialKeyModifierIdCommand(KeyboardLayout* layout, int keyIndex, \
const QString& newModifiewId, QUndoCommand* parent = 0); +    void undo();
+    void redo();
+    int id() const;
+    bool mergeWith(const QUndoCommand* other);
+private:
+    KeyboardLayout* m_layout;
+    int m_keyIndex;
+    QString m_oldModifierId;
+    QString m_newModifierId;
+};
+
 #endif // KEYBOARDLAYOUTCOMMANDS_H
diff --git a/src/editor/keyboardlayoutpropertieswidget.cpp \
b/src/editor/keyboardlayoutpropertieswidget.cpp index fd0f638..ac25d09 100644
--- a/src/editor/keyboardlayoutpropertieswidget.cpp
+++ b/src/editor/keyboardlayoutpropertieswidget.cpp
@@ -49,6 +49,9 @@ KeyboardLayoutPropertiesWidget::KeyboardLayoutPropertiesWidget(QWidget* \
                parent)
     connect(m_keyHeightSpinBox, SIGNAL(valueChanged(int)), \
                SLOT(onKeyHeightChanged(int)));
     connect(m_keyFingerComboBox, SIGNAL(currentIndexChanged(int)), \
                SLOT(onFingerIndexChanged(int)));
     connect(m_keyHapticMarkerCheckBox, SIGNAL(clicked(bool)), \
SLOT(setKeyHasHapticMarker(bool))); +    connect(m_specialKeyTypeComboBox, \
SIGNAL(currentIndexChanged(int)), SLOT(onSpecialKeyTypeChanged(int))); +    \
connect(m_specialKeyLabelLineEdit, SIGNAL(textEdited(QString)), \
SLOT(setSpecialKeyLabel(QString))); +    connect(m_specialKeyModifierIdLineEdit, \
SIGNAL(textEdited(QString)), SLOT(setSpecialKeyModifierId(QString)));  }
 
 void KeyboardLayoutPropertiesWidget::setKeyboardLayout(KeyboardLayout* layout)
@@ -109,9 +112,18 @@ void KeyboardLayoutPropertiesWidget::setSelectedKey(int index)
             connect(key, SIGNAL(fingerIndexChanged()), \
                SLOT(updateKeyFingerIndex()));
             connect(key, SIGNAL(hasHapticMarkerChanged()), \
SLOT(updateKeyHasHapticMarker()));  }
-        else if (qobject_cast<SpecialKey*>(m_selectedKey))
+        else if (SpecialKey* specialKey = qobject_cast<SpecialKey*>(m_selectedKey))
         {
             m_subStackedWidget->setCurrentWidget(m_specialKeyPropertiesSubWidget);
+
+            m_specialKeyTypeComboBox->setCurrentIndex(specialKey->type());
+            m_specialKeyLabelLineEdit->setText(specialKey->label());
+            m_specialKeyLabelLineEdit->setEnabled(specialKey->type() == \
SpecialKey::Other); +            \
m_specialKeyModifierIdLineEdit->setText(specialKey->modifierId()); +
+            connect(specialKey, SIGNAL(typeChanged()), \
SLOT(updateSpecialKeyType())); +            connect(specialKey, \
SIGNAL(labelChanged()), SLOT(updateSpecialKeyLabel())); +            \
connect(specialKey, SIGNAL(modifierIdChanged()), SLOT(updateSpecialKeyModifierId())); \
}  }
 }
@@ -128,8 +140,8 @@ void KeyboardLayoutPropertiesWidget::setReadOnly(bool readOnly)
     m_keyTopSpinBox->setReadOnly(readOnly);
     m_keyWidthSpinBox->setReadOnly(readOnly);
     m_keyHeightSpinBox->setReadOnly(readOnly);
-    m_specialKeyTypeComboBox->setEnabled(readOnly);
-    m_specialKeyLabelLineEdit->setReadOnly(!readOnly);
+    m_specialKeyTypeComboBox->setEnabled(!readOnly);
+    m_specialKeyLabelLineEdit->setReadOnly(readOnly);
     m_specialKeyModifierIdLineEdit->setReadOnly(readOnly);
 }
 
@@ -174,6 +186,24 @@ void KeyboardLayoutPropertiesWidget::setKeyHasHapticMarker(bool \
hasHapticMarker)  m_undoStack->push(command);
 }
 
+void KeyboardLayoutPropertiesWidget::setSpecialKeyType(int type)
+{
+    QUndoCommand* command = new SetSpecialKeyTypeCommand(m_keyboardLayout, \
m_selectedKeyIndex, static_cast<SpecialKey::Type>(type)); +    \
m_undoStack->push(command); +}
+
+void KeyboardLayoutPropertiesWidget::setSpecialKeyLabel(const QString& label)
+{
+    QUndoCommand* command = new SetSpecialKeyLabelCommand(m_keyboardLayout, \
m_selectedKeyIndex, label); +    m_undoStack->push(command);
+}
+
+void KeyboardLayoutPropertiesWidget::setSpecialKeyModifierId(const QString& id)
+{
+    QUndoCommand* command = new SetSpecialKeyModifierIdCommand(m_keyboardLayout, \
m_selectedKeyIndex, id); +    m_undoStack->push(command);
+}
+
 void KeyboardLayoutPropertiesWidget::updateKeyboardLayoutTitle()
 {
     const QString title = m_keyboardLayout->title();
@@ -308,6 +338,43 @@ void KeyboardLayoutPropertiesWidget::updateKeyHasHapticMarker()
     m_keyHapticMarkerCheckBox->setChecked(key->hasHapticMarker());
 }
 
+void KeyboardLayoutPropertiesWidget::updateSpecialKeyType()
+{
+    SpecialKey* const specialKey = qobject_cast<SpecialKey*>(m_selectedKey);
+
+    Q_ASSERT(specialKey);
+
+    m_specialKeyTypeComboBox->setCurrentIndex(specialKey->type());
+}
+
+void KeyboardLayoutPropertiesWidget::updateSpecialKeyLabel()
+{
+    SpecialKey* const specialKey = qobject_cast<SpecialKey*>(m_selectedKey);
+
+    Q_ASSERT(specialKey);
+
+    const QString label = specialKey->label();
+
+    if (label != m_specialKeyLabelLineEdit->text())
+    {
+        m_specialKeyLabelLineEdit->setText(label);
+    }
+}
+
+void KeyboardLayoutPropertiesWidget::updateSpecialKeyModifierId()
+{
+    SpecialKey* const specialKey = qobject_cast<SpecialKey*>(m_selectedKey);
+
+    Q_ASSERT(specialKey);
+
+    const QString modifierId = specialKey->modifierId();
+
+    if (modifierId != m_specialKeyModifierIdLineEdit->text())
+    {
+        m_specialKeyModifierIdLineEdit->setText(modifierId);
+    }
+}
+
 void KeyboardLayoutPropertiesWidget::onKeyboardLayoutWidthChanged(int width)
 {
     if (width != m_keyboardLayout->width())
@@ -387,3 +454,15 @@ void KeyboardLayoutPropertiesWidget::onFingerIndexChanged(int \
fingerIndex)  setKeyFingerIndex(fingerIndex);
     }
 }
+
+void KeyboardLayoutPropertiesWidget::onSpecialKeyTypeChanged(int type)
+{
+    SpecialKey* const specialKey = qobject_cast<SpecialKey*>(m_selectedKey);
+
+    Q_ASSERT(specialKey);
+
+    if (type != specialKey->type())
+    {
+        setSpecialKeyType(type);
+    }
+}
diff --git a/src/editor/keyboardlayoutpropertieswidget.h \
b/src/editor/keyboardlayoutpropertieswidget.h index 4b81d57..1bb3409 100644
--- a/src/editor/keyboardlayoutpropertieswidget.h
+++ b/src/editor/keyboardlayoutpropertieswidget.h
@@ -42,6 +42,9 @@ private slots:
     void setKeyGeometry(const QRect& rect);
     void setKeyFingerIndex(int fingerIndex);
     void setKeyHasHapticMarker(bool hasHapticMarker);
+    void setSpecialKeyType(int type);
+    void setSpecialKeyLabel(const QString& label);
+    void setSpecialKeyModifierId(const QString& id);
     void updateKeyboardLayoutTitle();
     void updateKeyboardLayoutName();
     void updateKeyboardLayoutWidth();
@@ -53,6 +56,9 @@ private slots:
     void resetKeyGeometry(AbstractKey* key);
     void updateKeyFingerIndex();
     void updateKeyHasHapticMarker();
+    void updateSpecialKeyType();
+    void updateSpecialKeyLabel();
+    void updateSpecialKeyModifierId();
     void onKeyboardLayoutWidthChanged(int width);
     void onKeyboardLayoutHeightChanged(int height);
     void onKeyLeftChanged(int left);
@@ -60,6 +66,7 @@ private slots:
     void onKeyWidthChanged(int width);
     void onKeyHeightChanged(int height);
     void onFingerIndexChanged(int fingerIndex);
+    void onSpecialKeyTypeChanged(int type);
 private:
     KeyboardLayout* m_keyboardLayout;
     int m_selectedKeyIndex;
diff --git a/src/ui/keyboardlayoutpropertieswidget.ui \
b/src/ui/keyboardlayoutpropertieswidget.ui index a016312..39b8941 100644
--- a/src/ui/keyboardlayoutpropertieswidget.ui
+++ b/src/ui/keyboardlayoutpropertieswidget.ui
@@ -489,12 +489,12 @@
                 </property>
                 <item>
                  <property name="text">
-                  <string>Other</string>
+                  <string>Tab</string>
                  </property>
                 </item>
                 <item>
                  <property name="text">
-                  <string>Tab</string>
+                  <string>Capslock</string>
                  </property>
                 </item>
                 <item>
@@ -502,6 +502,26 @@
                   <string>Shift</string>
                  </property>
                 </item>
+                <item>
+                 <property name="text">
+                  <string>Backspace</string>
+                 </property>
+                </item>
+                <item>
+                 <property name="text">
+                  <string>Return</string>
+                 </property>
+                </item>
+                <item>
+                 <property name="text">
+                  <string>Space</string>
+                 </property>
+                </item>
+                <item>
+                 <property name="text">
+                  <string>Other</string>
+                 </property>
+                </item>
                </widget>
               </item>
               <item row="1" column="0">


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

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