freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master 5e3fbc2: [ftinspect] Use bottom left as the vie


From: Werner LEMBERG
Subject: [freetype2-demos] master 5e3fbc2: [ftinspect] Use bottom left as the viewport anchor for resizing.
Date: Thu, 19 May 2016 13:20:48 +0000 (UTC)

branch: master
commit 5e3fbc2570c7898e67e69ea3eca8cc906955d8a1
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    [ftinspect] Use bottom left as the viewport anchor for resizing.
    
    We store the last bottom left corner point of the viewport rectangle
    and adjust the verticalScrollBar value by the delta relative to the
    current bottom left corner position.
    
    * src/ftinspect.h (QGraphicsViewx): New class, derived from
    `QGraphicsView'.
    (MainGUI): Updated.
    
    * src/ftinspect.cpp (MainGUI::createLayout): Updated.
    (QGraphicsViewx::QGraphicsViewx, QGraphicsViewx::scrollContentsBy,
    QGraphicsView::resizeEvent): New methods.
---
 ChangeLog         |   18 +++++++++++++++++-
 src/ftinspect.cpp |   39 ++++++++++++++++++++++++++++++++++++++-
 src/ftinspect.h   |   23 ++++++++++++++++++++++-
 3 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e0527c1..c5cf5b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,20 @@
-2016-05-15  Werner Lemberg  <address@hidden>
+2016-05-19  Werner Lemberg  <address@hidden>
+
+       [ftinspect] Use bottom left as the viewport anchor for resizing.
+
+       We store the last bottom left corner point of the viewport rectangle
+       and adjust the verticalScrollBar value by the delta relative to the
+       current bottom left corner position.
+
+       * src/ftinspect.h (QGraphicsViewx): New class, derived from
+       `QGraphicsView'.
+       (MainGUI): Updated.
+
+       * src/ftinspect.cpp (MainGUI::createLayout): Updated.
+       (QGraphicsViewx::QGraphicsViewx, QGraphicsViewx::scrollContentsBy,
+       QGraphicsView::resizeEvent): New methods.
+
+2016-05-18  Werner Lemberg  <address@hidden>
 
        [ftinspect] Re-implement file watching.
 
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index 619df37..c8a4f7e 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -2049,7 +2049,7 @@ MainGUI::createLayout()
   currentGlyphPointNumbersItem = NULL;
   drawGlyph();
 
-  glyphView = new QGraphicsView;
+  glyphView = new QGraphicsViewx;
   glyphView->setRenderHint(QPainter::Antialiasing, true);
   glyphView->setDragMode(QGraphicsView::ScrollHandDrag);
   glyphView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
@@ -2417,6 +2417,43 @@ MainGUI::writeSettings()
 }
 
 
+QGraphicsViewx::QGraphicsViewx()
+: lastBottomLeftPointInitialized(false)
+{
+  // empty
+}
+
+
+void
+QGraphicsViewx::scrollContentsBy(int dx,
+                                 int dy)
+{
+  QGraphicsView::scrollContentsBy(dx, dy);
+  lastBottomLeftPoint = viewport()->rect().bottomLeft();
+}
+
+
+void
+QGraphicsViewx::resizeEvent(QResizeEvent* event)
+{
+  QGraphicsView::resizeEvent(event);
+
+  // XXX I don't know how to properly initialize this value,
+  //     thus the hack with the boolean
+  if (!lastBottomLeftPointInitialized)
+  {
+    lastBottomLeftPoint = viewport()->rect().bottomLeft();
+    lastBottomLeftPointInitialized = true;
+  }
+
+  QPointF currentBottomLeftPoint = viewport()->rect().bottomLeft();
+  int verticalPosition = verticalScrollBar()->value();
+  verticalScrollBar()->setValue(verticalPosition
+                                - (currentBottomLeftPoint.y()
+                                   - lastBottomLeftPoint.y()));
+}
+
+
 void
 QComboBoxx::setItemEnabled(int index,
                            bool enable)
diff --git a/src/ftinspect.h b/src/ftinspect.h
index edbd9ff..789f8b3 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -46,6 +46,7 @@
 #include <QPainterPath>
 #include <QPen>
 #include <QPushButton>
+#include <QScrollBar>
 #include <QSettings>
 #include <QSignalMapper>
 #include <QSizePolicy>
@@ -264,6 +265,26 @@ private:
 };
 
 
+// we want to anchor the view at the bottom left corner
+// while the windows gets resized
+class QGraphicsViewx
+: public QGraphicsView
+{
+  Q_OBJECT
+
+public:
+  QGraphicsViewx();
+
+protected:
+  void resizeEvent(QResizeEvent*);
+  void scrollContentsBy(int, int);
+
+private:
+  QPointF lastBottomLeftPoint;
+  bool lastBottomLeftPointInitialized;
+};
+
+
 // we want to grey out items in a combo box;
 // since Qt doesn't provide a function for this we derive a class
 class QComboBoxx
@@ -387,7 +408,7 @@ private:
   QFileSystemWatcher *fontWatcher;
 
   QGraphicsScene *glyphScene;
-  QGraphicsView *glyphView;
+  QGraphicsViewx *glyphView;
 
   QGridLayout *fontLayout;
   QGridLayout *infoRightLayout;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]