Fix alignment of annotations/line numbers with source.
authorCyp <[email protected]>
Tue, 19 Jan 2010 13:56:53 +0000 (19 14:56 +0100)
committerMarco Costalba <[email protected]>
Wed, 20 Jan 2010 17:21:15 +0000 (20 18:21 +0100)
Sets the size hint of the QListWidgetItems to the correct values to align with the source.
Cleared the uniformItemSizes flag, since the items have slightly different heights, especially when using source highlighting.

Signed-off-by: Marco Costalba <[email protected]>
src/filecontent.cpp
src/fileview.ui

index 23c2e95..1827bb9 100644 (file)
@@ -13,6 +13,7 @@
 #include <QApplication>
 #include <QClipboard>
 #include <QTemporaryFile>
+#include <QAbstractTextDocumentLayout>
 #include "domain.h"
 #include "myprocess.h"
 #include "mainimpl.h"
@@ -111,6 +112,8 @@ void FileContent::on_listScrollBar_valueChanged(int value) {
 
 int FileContent::itemAnnId(QListWidgetItem* item) {
 
+       if (item == NULL)
+               return 0;
        QString id(item->text());
        if (!id.contains('.'))
                return 0;
@@ -556,7 +559,7 @@ void FileContent::setAnnList() {
 
        QStringList sl;
        QVector<int> curIdLines;
-       for (int i = 0; i <= linesNum; i++) { // QTextEdit adds a blank line after content
+       for (int i = 0; i < linesNum; i++) {
 
                if (isAnnotationAppended) {
                        if (it != endIt)
@@ -572,10 +575,26 @@ void FileContent::setAnnList() {
                tmp.append(QString(" %1 ").arg(i + 1, linesNumDigits));
                sl.append(tmp);
        }
+       sl.append(QString());  // QTextEdit adds a blank line after content
        listWidgetAnn->setUpdatesEnabled(false);
        listWidgetAnn->clear();
        listWidgetAnn->addItems(sl);
 
+       QAbstractTextDocumentLayout *layout = document()->documentLayout();
+       if (layout != NULL) {
+               int previousBottom = 0;
+               QTextBlock block = document()->begin();
+               for (int i = 0; i < linesNum; i++) {
+                       int bottom = layout->blockBoundingRect(block).bottom();
+                       QListWidgetItem* item = listWidgetAnn->item(i);
+                       item->setSizeHint(QSize(0, bottom - previousBottom));
+                       item->setTextAlignment(Qt::AlignVCenter);  // Move down a pixel or so.
+
+                       previousBottom = bottom;
+                       block = block.next();
+               }
+       }
+
        QBrush fore(Qt::darkRed);
        QBrush back(Qt::lightGray);
        QFont f(listWidgetAnn->font());
@@ -610,5 +629,5 @@ void FileContent::resizeEvent(QResizeEvent* e) {
 
        QTextEdit::resizeEvent(e);
        int width = listWidgetAnn->geometry().width();
-       adjustAnnListSize(width); // update list height
+       adjustAnnListSize(width); // update list width
 }
index 97fa000..ab078bc 100644 (file)
              <property name="horizontalScrollMode" >
               <enum>QAbstractItemView::ScrollPerPixel</enum>
              </property>
-             <property name="uniformItemSizes" >
-              <bool>true</bool>
-             </property>
             </widget>
            </item>
            <item>