Added a focus reticle. It indicates CAF status only for now.
authorMohammed Sameer <msameer@foolab.org>
Fri, 14 Dec 2012 17:10:52 +0000 (19:10 +0200)
committerMohammed Sameer <msameer@foolab.org>
Fri, 14 Dec 2012 17:10:52 +0000 (19:10 +0200)
qml/CameraPage.qml
src/focusrectangle.cpp [new file with mode: 0644]
src/focusrectangle.h [new file with mode: 0644]
src/main.cpp
src/src.pro

index 25f9b82..ca91e23 100644 (file)
@@ -39,6 +39,7 @@ Page {
         property bool zoomVisible: true
         property bool modesVisible: true
         property bool standbyVisible: true
+        property bool focusReticleVisible: true
 
         anchors.fill: parent
 
@@ -52,6 +53,12 @@ Page {
                 }
         }
 
+        FocusReticle {
+                visible: controlsVisible && focusReticleVisible
+                id: focusReticle
+                autoFocusStatus: cam.autoFocus.cafStatus
+        }
+
         Rectangle {
                 // TODO: fade out transition
                 // TODO: there is a toolbar visible on the first startup
diff --git a/src/focusrectangle.cpp b/src/focusrectangle.cpp
new file mode 100644 (file)
index 0000000..aeda534
--- /dev/null
@@ -0,0 +1,117 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "focusrectangle.h"
+#include <QPainter>
+#include <QDebug>
+
+#define OUTER_WIDTH  4
+#define INNER_WIDTH  2
+#define OUTER_LENGTH 50
+#define INNER_LENGTH 49
+
+FocusRectangle::FocusRectangle(QDeclarativeItem *parent) :
+  QDeclarativeItem(parent),
+  m_color(Qt::white) {
+
+  setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+FocusRectangle::~FocusRectangle() {
+
+}
+
+QColor FocusRectangle::color() const {
+  return m_color;
+}
+
+void FocusRectangle::setColor(const QColor& color) {
+  if (color != m_color) {
+    m_color = color;
+    emit colorChanged();
+
+    update();
+  }
+}
+
+void FocusRectangle::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
+                          QWidget* widget) {
+
+  QDeclarativeItem::paint(painter, option, widget);
+
+  painter->save();
+
+  painter->setPen(QPen(QBrush(Qt::black), OUTER_WIDTH));
+  painter->drawPath(m_outer);
+
+  painter->setPen(QPen(QBrush(m_color), INNER_WIDTH));
+  painter->drawPath(m_inner);
+
+  painter->restore();
+}
+
+void FocusRectangle::geometryChanged( const QRectF& newGeometry, const QRectF& oldGeometry) {
+  QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
+
+  qreal w = width();
+  qreal h = height();
+
+  // Outer:
+  // top left:
+  m_outer = QPainterPath(QPointF(0, OUTER_LENGTH));
+  m_outer.lineTo(0, 0);
+  m_outer.lineTo(OUTER_LENGTH, 0);
+
+  // top right:
+  m_outer.moveTo(w - OUTER_LENGTH, 0);
+  m_outer.lineTo(w, 0);
+  m_outer.lineTo(w, OUTER_LENGTH);
+
+  // bottom right:
+  m_outer.moveTo(w, h - OUTER_LENGTH);
+  m_outer.lineTo(w, h);
+  m_outer.lineTo(w - OUTER_LENGTH, h);
+
+  // bottom left:
+  m_outer.moveTo(OUTER_LENGTH, h);
+  m_outer.lineTo(0, h);
+  m_outer.lineTo(0, h - OUTER_LENGTH);
+
+  // Inner:
+  // top left:
+  m_inner = QPainterPath(QPointF(0, INNER_LENGTH));
+  m_inner.lineTo(0, 0);
+  m_inner.lineTo(INNER_LENGTH, 0);
+
+  // top right:
+  m_inner.moveTo(w - INNER_LENGTH, 0);
+  m_inner.lineTo(w, 0);
+  m_inner.lineTo(w, INNER_LENGTH);
+
+  // bottom right:
+  m_inner.moveTo(w, h - INNER_LENGTH);
+  m_inner.lineTo(w, h);
+  m_inner.lineTo(w - INNER_LENGTH, h);
+
+  // bottom left:
+  m_inner.moveTo(INNER_LENGTH, h);
+  m_inner.lineTo(0, h);
+  m_inner.lineTo(0, h - INNER_LENGTH);
+}
diff --git a/src/focusrectangle.h b/src/focusrectangle.h
new file mode 100644 (file)
index 0000000..6d6e296
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef FOCUS_RECTANGLE_H
+#define FOCUS_RECTANGLE_H
+
+#include <QDeclarativeItem>
+
+class FocusRectangle : public QDeclarativeItem {
+  Q_OBJECT
+
+  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged);
+
+public:
+  FocusRectangle(QDeclarativeItem *parent = 0);
+  ~FocusRectangle();
+
+  QColor color() const;
+  void setColor(const QColor& color);
+
+  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+
+protected:
+  void geometryChanged( const QRectF& newGeometry, const QRectF& oldGeometry);
+
+signals:
+  void colorChanged();
+
+private:
+  QColor m_color;
+
+  QPainterPath m_inner;
+  QPainterPath m_outer;
+};
+
+#endif /* FOCUS_RECTANGLE_H */
index fda85f2..1fde073 100644 (file)
@@ -39,6 +39,7 @@
 #include "geocode.h"
 #include "mountprotector.h"
 #include "trackerstore.h"
+#include "focusrectangle.h"
 
 static void initQuill() {
   // TODO: All these are hardcoded.
@@ -80,6 +81,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   qmlRegisterType<Geocode>("CameraPlus", 1, 0, "ReverseGeocode");
   qmlRegisterType<MountProtector>("CameraPlus", 1, 0, "MountProtector");
   qmlRegisterType<TrackerStore>("CameraPlus", 1, 0, "TrackerStore");
+  qmlRegisterType<FocusRectangle>("CameraPlus", 1, 0, "FocusRectangle");
 
   QUrl sourceUrl = QUrl::fromLocalFile(QDir::currentPath() + "/main.qml");
   view.setSource(sourceUrl);
index f3a9cc9..d1057e1 100644 (file)
@@ -16,8 +16,8 @@ LIBS +=  -L../imports/ -limports -L../lib/ -lqtcamera
 
 SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp fsmonitor.cpp \
            cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp \
-           trackerstore.cpp
+           trackerstore.cpp focusrectangle.cpp
 
 HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \
            cameraresources.h compass.h orientation.h geocode.h mountprotector.h \
-           trackerstore.h
+           trackerstore.h focusrectangle.h