]> git.sesse.net Git - kdenlive/blobdiff - src/guide.cpp
some other fixes and improvements for guides
[kdenlive] / src / guide.cpp
index 37be746d7ee46be7afc043f1587398bade961d61..0e55e9017ecd30375622b7b51746d79552d24243 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
-
-#include <QPen>
-#include <QBrush>
-#include <QScrollBar>
-
-#include <KDebug>
-
 #include "guide.h"
 #include "customtrackview.h"
 #include "customtrackscene.h"
 #include "kdenlivesettings.h"
 
-Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, double height)
-        : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_fps(fps) {
+#include <KDebug>
+
+#include <QPen>
+#include <QBrush>
+
+Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, double height) :
+        QGraphicsLineItem(),
+        m_position(pos),
+        m_label(label),
+        m_fps(fps),
+        m_view(view)
+{
     setFlags(QGraphicsItem::ItemIsMovable);
     setToolTip(label);
     setLine(0, 0, 0, height);
     setPos(m_position.frames(m_fps), 0);
-    setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 1));
+    setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
     setZValue(999);
     setAcceptsHoverEvents(true);
     const QFontMetrics metric = m_view->fontMetrics();
@@ -43,19 +46,23 @@ Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, doub
     prepareGeometryChange();
 }
 
-QString Guide::label() const {
+QString Guide::label() const
+{
     return m_label;
 }
 
-GenTime Guide::position() const {
+GenTime Guide::position() const
+{
     return m_position;
 }
 
-CommentedTime Guide::info() const {
+CommentedTime Guide::info() const
+{
     return CommentedTime(m_position, m_label);
 }
 
-void Guide::updateGuide(const GenTime newPos, const QString &comment) {
+void Guide::updateGuide(const GenTime newPos, const QString &comment)
+{
     m_position = newPos;
     setPos(m_position.frames(m_fps), 0);
     if (!comment.isEmpty()) {
@@ -68,22 +75,26 @@ void Guide::updateGuide(const GenTime newPos, const QString &comment) {
 }
 
 //virtual
-int Guide::type() const {
+int Guide::type() const
+{
     return GUIDEITEM;
 }
 
 //virtual
-void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
+void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *)
+{
     setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2));
 }
 
 //virtual
-void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
+void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
+{
     setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
 }
 
 //virtual
-QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) {
+QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value)
+{
     if (change == ItemPositionChange && scene()) {
         // value is the new position.
         QPointF newPos = value.toPointF();
@@ -95,7 +106,8 @@ QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) {
 }
 
 // virtual
-QRectF Guide::boundingRect() const {
+QRectF Guide::boundingRect() const
+{
     if (KdenliveSettings::showmarkers()) {
         QRectF rect = QGraphicsLineItem::boundingRect();
         rect.setLeft(line().x1());
@@ -105,7 +117,21 @@ QRectF Guide::boundingRect() const {
 }
 
 // virtual
-void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) {
+QPainterPath Guide::shape() const
+{
+    QPainterPath path;
+    path.addRect(line().x1() - pen().widthF() / 2, line().y1(), pen().widthF(), line().y2() - line().y1());
+    if (KdenliveSettings::showmarkers()) {
+        const QFontMetrics metric = m_view->fontMetrics();
+        int height = metric.height();
+        path.addRoundedRect(line().x1(), line().y1() + 10, m_width / static_cast <CustomTrackScene*>(scene())->scale(), height, 3, 3);
+    }
+    return path;
+}
+
+// virtual
+void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*w*/)
+{
     painter->setMatrixEnabled(false);
     QLineF guideline = painter->matrix().map(line());
     painter->setPen(pen());