Browse Source

Add short sha1 and view representation

Alexey Edelev 8 years ago
parent
commit
4c5699ced0
5 changed files with 58 additions and 6 deletions
  1. 5 0
      gitcommit.cpp
  2. 2 0
      gitcommit.h
  3. 6 0
      gitoid.cpp
  4. 1 0
      gitoid.h
  5. 44 6
      qml/MainView.qml

+ 5 - 0
gitcommit.cpp

@@ -60,6 +60,11 @@ QString GitCommit::sha1() const
     return oid().toString();
 }
 
+QString GitCommit::shortSha1() const
+{
+    return oid().toShorten();
+}
+
 void GitCommit::setAuthor(QString author)
 {
     Q_UNUSED(author)

+ 2 - 0
gitcommit.h

@@ -16,6 +16,7 @@ class GitCommit : public GitBase<git_commit>
     Q_PROPERTY(QDateTime time READ time WRITE setTime NOTIFY commitChanged)
     Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY commitChanged)
     Q_PROPERTY(QString sha1 READ sha1 NOTIFY commitChanged)
+    Q_PROPERTY(QString shortSha1 READ shortSha1 NOTIFY commitChanged)
 
 public:
     GitCommit(git_commit* raw, GitRepository* parent);
@@ -28,6 +29,7 @@ public:
     QString message() const;
     QString email() const;
     QString sha1() const;
+    QString shortSha1() const;
 
 public slots:
     void setAuthor(QString author);

+ 6 - 0
gitoid.cpp

@@ -20,6 +20,12 @@ QString GitOid::toString() const
     return m_string;
 }
 
+QString GitOid::toShorten() const
+{
+    return m_string.mid(0,9);
+}
+
+
 bool GitOid::operator ==(const GitOid& other) const
 {
     return git_oid_equal(&m_oid, &(other.m_oid)) == 0

+ 1 - 0
gitoid.h

@@ -27,6 +27,7 @@ public:
     }
 
     QString toString() const;
+    QString toShorten() const;
 
     bool isValid() const;
 

+ 44 - 6
qml/MainView.qml

@@ -28,18 +28,56 @@ Item {
 
 
     ListView {
-        height: 200
-        width: 100
+        anchors.top: parent.top
+        anchors.bottom: parent.bottom
+        width: 200
         anchors.right: parent.right
         model: _handler.modelByHead("master")
         delegate: Rectangle {
+            id: idRect
+            width: parent.width
+            height: 80
             color: "#cccccc"
-            width: 200
-            height: 100
+            states: [
+                State {
+                    name:"full"
+                    PropertyChanges {
+                        target: sha1Lable
+                        text: model.sha1
+                    }
+                    PropertyChanges {
+                        target: idRect
+                        color: "#dddddd"
+                    }
+                },
+                State {
+                    name:"short"
+                    PropertyChanges {
+                        target: sha1Lable
+                        text: model.shortSha1
+                    }
+                    PropertyChanges {
+                        target: idRect
+                        color: "#cccccc"
+                    }
+                }]
+
+            state: "short"
+
             Text {
-                anchors.centerIn: parent
+                id: sha1Lable
                 maximumLineCount: 8
-                text: model.sha1
+                text: model.shortSha1
+            }
+            MouseArea {
+                hoverEnabled: true
+                anchors.fill: parent
+                onEntered: {
+                    parent.state = "full"
+                }
+                onExited: {
+                    parent.state = "short"
+                }
             }
         }
     }