[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [sflphone-kde] src: [ #50490 ] Add video aspect ratio configuration options
From:       Emmanuel Lepage Vallee <emmanuel.lepage () savoirfairelinux ! com>
Date:       2014-06-30 21:02:23
Message-ID: E1X1iiV-0004Hk-5U () scm ! kde ! org
[Download RAW message or body]

Git commit df2c40a8d3ad58a76890958441f7383dd0df4962 by Emmanuel Lepage Vallee.
Committed on 30/06/2014 at 21:02.
Pushed by lepagevalleeemmanuel into branch 'master'.

[ #50490 ] Add video aspect ratio configuration options

M  +13   -0    src/actioncollection.cpp
M  +2    -0    src/actioncollection.h
M  +10   -1    src/klib/sflphone-client-kde.kcfg
M  +1    -0    src/widgets/videodock.cpp
M  +23   -3    src/widgets/videoglframe.cpp
M  +3    -0    src/widgets/videoglframe.h
M  +11   -0    src/widgets/videoscene.cpp
M  +1    -0    src/widgets/videoscene.h
M  +1    -0    src/widgets/videotoolbar.cpp
M  +21   -2    src/widgets/videowidget3.cpp
M  +2    -0    src/widgets/videowidget3.h

http://commits.kde.org/sflphone-kde/df2c40a8d3ad58a76890958441f7383dd0df4962

diff --git a/src/actioncollection.cpp b/src/actioncollection.cpp
index 41d9fe1..3e86e1c 100644
--- a/src/actioncollection.cpp
+++ b/src/actioncollection.cpp
@@ -104,26 +104,34 @@ action_editToolBar(nullptr), action_addContact(nullptr), \
action_screen(nullptr)  action_video_flip_vertical   = new ExtendedAction(this);
    action_video_mute            = new ExtendedAction(this);
    action_video_preview         = new ExtendedAction(this);
+   action_video_scale           = new ExtendedAction(this);
    action_video_rotate_left     ->setText ( i18n( "Rotate left"  ) );
    action_video_rotate_right    ->setText ( i18n( "Rotate right" ) );
    action_video_flip_horizontal ->setText ( i18n( "Flip"         ) );
    action_video_flip_vertical   ->setText ( i18n( "Flip"         ) );
    action_video_mute            ->setText ( i18n( "Mute"         ) );
    action_video_preview         ->setText ( i18n( "Preview"      ) );
+   action_video_scale           ->setText ( i18n( "Keep aspect ratio"      ));
    action_video_rotate_left     ->setAltIcon(KIcon("object-rotate-left"    ));
    action_video_rotate_right    ->setAltIcon(KIcon("object-rotate-right"   ));
    action_video_flip_horizontal ->setAltIcon(KIcon("object-flip-horizontal"));
    action_video_flip_vertical   ->setAltIcon(KIcon("object-flip-vertical"  ));
    action_video_mute            ->setAltIcon(KIcon("camera-web"            ));
    action_video_preview         ->setAltIcon(KIcon("view-preview"          ));
+   action_video_scale           ->setAltIcon(KIcon("transform-scale"       ));
    action_video_rotate_left     ->setIcon(KIcon("object-rotate-left"    ));
    action_video_rotate_right    ->setIcon(KIcon("object-rotate-right"   ));
    action_video_flip_horizontal ->setIcon(KIcon("object-flip-horizontal"));
    action_video_flip_vertical   ->setIcon(KIcon("object-flip-vertical"  ));
    action_video_mute            ->setIcon(KIcon("camera-web"            ));
    action_video_preview         ->setIcon(KIcon("view-preview"          ));
+   action_video_scale           ->setIcon(KIcon("transform-scale"          ));
    action_video_preview         ->setCheckable(true);
+   action_video_scale           ->setCheckable(true);
    action_video_mute            ->setCheckable(true);
+
+   action_video_scale           \
->setChecked(ConfigurationSkeleton::keepVideoAspectRatio()); +   action_video_preview \
->setChecked(ConfigurationSkeleton::displayVideoPreview());  #endif
 }
 
@@ -642,4 +650,9 @@ ExtendedAction* ActionCollection::videoPreviewAction        ()
 {
    return action_video_preview;
 }
+
+ExtendedAction* ActionCollection::videoScaleAction        ()
+{
+   return action_video_scale;
+}
 #endif
diff --git a/src/actioncollection.h b/src/actioncollection.h
index 42f72a2..21bf8c7 100644
--- a/src/actioncollection.h
+++ b/src/actioncollection.h
@@ -70,6 +70,7 @@ public:
    ExtendedAction* videoFlipVerticalAction   ();
    ExtendedAction* videoMuteAction           ();
    ExtendedAction* videoPreviewAction        ();
+   ExtendedAction* videoScaleAction          ();
    #endif
 
 private:
@@ -94,6 +95,7 @@ private:
    ExtendedAction* action_video_flip_vertical  ;
    ExtendedAction* action_video_mute           ;
    ExtendedAction* action_video_preview        ;
+   ExtendedAction* action_video_scale          ;
    #endif
 
    //Other actions
diff --git a/src/klib/sflphone-client-kde.kcfg b/src/klib/sflphone-client-kde.kcfg
index fec1a9a..3c755af 100644
--- a/src/klib/sflphone-client-kde.kcfg
+++ b/src/klib/sflphone-client-kde.kcfg
@@ -112,7 +112,16 @@
         <label>Defines if the individual contact history list is visible</label>
         <default>false</default>
    </entry>
-    
+
+   <!-- Video Settings -->
+   <entry name="keepVideoAspectRatio" type="Bool">
+        <label>Enforce video aspect ratio or allow stretching</label>
+        <default>true</default>
+   </entry>
+   <entry name="displayVideoPreview" type="Bool">
+        <label>Enforce video aspect ratio or allow stretching</label>
+        <default>false</default>
+   </entry>
 
     <!-- Audio Settings -->
 
diff --git a/src/widgets/videodock.cpp b/src/widgets/videodock.cpp
index 4447624..4524215 100644
--- a/src/widgets/videodock.cpp
+++ b/src/widgets/videodock.cpp
@@ -118,6 +118,7 @@ VideoDock::VideoDock(QWidget* parent) : \
QDockWidget(parent),m_pVideoSettings(nul  \
connect(ActionCollection::instance()->videoRotateRightAction(),SIGNAL(triggered(bool)),m_pVideoWidet,SLOT(slotRotateRight()));
  connect(ActionCollection::instance()->videoPreviewAction()    \
,SIGNAL(triggered(bool)),m_pVideoWidet,SLOT(slotShowPreview(bool)));  \
connect(ActionCollection::instance()->videoMuteAction()       \
,SIGNAL(triggered(bool)),m_pVideoWidet,SLOT(slotMuteOutgoindVideo(bool))); +   \
connect(ActionCollection::instance()->videoScaleAction()      \
,SIGNAL(triggered(bool)),m_pVideoWidet,SLOT(slotKeepAspectRatio(bool)));  }
 
 ///Set current renderer
diff --git a/src/widgets/videoglframe.cpp b/src/widgets/videoglframe.cpp
index 24a5606..5c5db40 100644
--- a/src/widgets/videoglframe.cpp
+++ b/src/widgets/videoglframe.cpp
@@ -166,11 +166,21 @@ void ThreadedPainter2::draw(QPainter* p)
       glRotatef(rot_y, 0.0f, 1.0f, 0.0f);
       glRotatef(rot_z, 0.0f, 0.0f, 1.0f);
 
-
+      //Handle the ratio
+      float xRatio(1),yRatio(1);
+      if (m_pFrm->keepAspectRatio()) {
+         float rendererRatio = ((float)res.width())/((float)res.height());
+         float windowRatio = \
((float)p->device()->width())/((float)p->device()->height()); +
+         if (windowRatio > 1)
+            xRatio = (1.0f/windowRatio) * rendererRatio;
+         else
+            yRatio = 1.0f/windowRatio * rendererRatio;
+      }
 
       // draw background
       glPushMatrix();
-      glScalef(1.7f, 1.7f, 1.7f);
+      glScalef(xRatio*1.7f, yRatio*1.7f, 1.7f);
       glTranslatef(tra_x, tra_y, tra_z);
       glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
       glCallList(tile_list);
@@ -190,7 +200,7 @@ void ThreadedPainter2::draw(QPainter* p)
  VideoGLFrame::VideoGLFrame(QGLWidget *parent)
      : QObject(parent),m_pParent(parent),
      m_pPainter(new ThreadedPainter2(this,parent)),
-     m_pRenderer(nullptr)
+     m_pRenderer(nullptr),m_KeepAspect(true)
  {
    connect(m_pPainter,SIGNAL(changed()),this,SLOT(slotEmitChanged()));
 
@@ -351,5 +361,15 @@ float VideoGLFrame::scale() const
    return m_pPainter->scale;
 }
 
+void VideoGLFrame::setKeepAspectRatio(bool keep)
+{
+   m_KeepAspect = keep;
+}
+
+bool VideoGLFrame::keepAspectRatio() const
+{
+   return m_KeepAspect;
+}
+
 #include "videoglframe.moc"
 #include "moc_videoglframe.cpp"
diff --git a/src/widgets/videoglframe.h b/src/widgets/videoglframe.h
index 8e85d4a..21de8b3 100644
--- a/src/widgets/videoglframe.h
+++ b/src/widgets/videoglframe.h
@@ -57,6 +57,7 @@ public:
    void setTranslationX(float tra);
    void setScale(float scale);
    void setAnchor(const QPointF& point);
+   void setKeepAspectRatio(bool keep);
 
    //Getter
    QPointF anchor() const;
@@ -64,6 +65,7 @@ public:
    float rotY() const;
    float rotX() const;
    float scale() const;
+   bool keepAspectRatio() const;
    VideoRenderer* renderer() const {
       return m_pRenderer;
    }
@@ -73,6 +75,7 @@ private:
    ThreadedPainter2* m_pPainter;
    QGLWidget* m_pParent;
    VideoRenderer* m_pRenderer;
+   bool m_KeepAspect;
 
 public Q_SLOTS:
    void setRenderer(VideoRenderer* renderer = nullptr);
diff --git a/src/widgets/videoscene.cpp b/src/widgets/videoscene.cpp
index e102ef5..90d4de4 100644
--- a/src/widgets/videoscene.cpp
+++ b/src/widgets/videoscene.cpp
@@ -26,6 +26,7 @@
 #include "videotoolbar.h"
 #include <lib/video/videorenderer.h>
 #include <lib/video/videomodel.h>
+#include "klib/kcfg_settings.h"
 
 #ifndef GL_MULTISAMPLE
 #define GL_MULTISAMPLE  0x809D
@@ -94,3 +95,13 @@ void VideoScene::slotRotateRight()
          frm->setRotZ(frm->rotZ()+90);
    }
 }
+
+void VideoScene::slotKeepAspectRatio(bool keep)
+{
+   ConfigurationSkeleton::setKeepVideoAspectRatio(keep);
+   foreach(VideoGLFrame* frm, m_lFrames) {
+      if (VideoModel::instance()->previewRenderer() != frm->renderer())
+         frm->setKeepAspectRatio(keep);
+   }
+}
+
diff --git a/src/widgets/videoscene.h b/src/widgets/videoscene.h
index 24988b3..0f4dc63 100644
--- a/src/widgets/videoscene.h
+++ b/src/widgets/videoscene.h
@@ -53,6 +53,7 @@ public Q_SLOTS:
    void frameChanged      ();
    void slotRotateLeft();
    void slotRotateRight();
+   void slotKeepAspectRatio(bool keep);
 };
 
 #endif
diff --git a/src/widgets/videotoolbar.cpp b/src/widgets/videotoolbar.cpp
index 4deb59d..b5fdda0 100644
--- a/src/widgets/videotoolbar.cpp
+++ b/src/widgets/videotoolbar.cpp
@@ -33,6 +33,7 @@ VideoToolbar::VideoToolbar(QWidget* parent) : QToolBar(parent)
    addAction(ActionCollection::instance()->videoRotateRightAction    ());
    addAction(ActionCollection::instance()->videoFlipHorizontalAction ());
    addAction(ActionCollection::instance()->videoFlipVerticalAction   ());
+   addAction(ActionCollection::instance()->videoScaleAction          ());
    addAction(ActionCollection::instance()->videoMuteAction           ());
    addAction(ActionCollection::instance()->videoPreviewAction        ());
 }
diff --git a/src/widgets/videowidget3.cpp b/src/widgets/videowidget3.cpp
index 09293e0..b55654f 100644
--- a/src/widgets/videowidget3.cpp
+++ b/src/widgets/videowidget3.cpp
@@ -39,6 +39,7 @@
 #include "actioncollection.h"
 #include "extendedaction.h"
 #include <lib/video/videodevicemodel.h>
+#include "klib/kcfg_settings.h"
 
 
 #ifndef GL_MULTISAMPLE
@@ -48,6 +49,7 @@
 
 VideoWidget3::VideoWidget3(QWidget *parent) : QGraphicsView(parent)
 {
+   connect(VideoModel::instance(),SIGNAL(previewStateChanged(bool)),this,SLOT(slotPreviewEnabled(bool)));
  QSizePolicy sp = sizePolicy();
    sp.setVerticalPolicy  ( QSizePolicy::Preferred );
    sp.setHorizontalPolicy( QSizePolicy::Preferred );
@@ -65,6 +67,10 @@ VideoWidget3::VideoWidget3(QWidget *parent) : \
QGraphicsView(parent)  m_pScene = new VideoScene();
    setScene(m_pScene);
 
+   if (VideoModel::instance()->isPreviewing()) {
+      slotShowPreview(true);
+   }
+
 //    m_pScene->setToolbar(tb);
    m_pScene->setSceneRect(0,0,width(),height());
    setAcceptDrops(true);
@@ -107,6 +113,7 @@ void VideoWidget3::addRenderer(VideoRenderer* renderer)
    }
    if (renderer) {
       VideoGLFrame* frm = new VideoGLFrame(m_pWdg);
+      frm->setKeepAspectRatio(ConfigurationSkeleton::keepVideoAspectRatio());
       frm->setRenderer(renderer);
       connect(frm,SIGNAL(changed()),m_pScene,SLOT(frameChanged()));
       m_pScene->addFrame(frm);
@@ -139,8 +146,8 @@ void VideoWidget3::slotRotateRight()
 
 void VideoWidget3::slotShowPreview(bool show)
 {
+   ConfigurationSkeleton::setDisplayVideoPreview(show);
    if (VideoModel::instance()->isPreviewing() && show) {
-      qDebug() << "show";
       addRenderer(VideoModel::instance()->previewRenderer());
       VideoGLFrame* frm = m_hFrames[VideoModel::instance()->previewRenderer()];
       if (frm) {
@@ -151,7 +158,6 @@ void VideoWidget3::slotShowPreview(bool show)
       }
    }
    else {
-      qDebug() << "hide";
       removeRenderer(VideoModel::instance()->previewRenderer());
    }
 }
@@ -167,3 +173,16 @@ void VideoWidget3::slotMuteOutgoindVideo(bool mute)
    }
 }
 
+void VideoWidget3::slotKeepAspectRatio(bool keep)
+{
+   m_pScene->slotKeepAspectRatio(keep);
+}
+
+
+void VideoWidget3::slotPreviewEnabled(bool show)
+{
+   if (show && ActionCollection::instance()->videoPreviewAction()->isChecked()) {
+      slotShowPreview(true);
+   }
+}
+
diff --git a/src/widgets/videowidget3.h b/src/widgets/videowidget3.h
index e5fb4a4..a15f452 100644
--- a/src/widgets/videowidget3.h
+++ b/src/widgets/videowidget3.h
@@ -63,6 +63,8 @@ public Q_SLOTS:
    void slotRotateRight();
    void slotShowPreview(bool show);
    void slotMuteOutgoindVideo(bool mute);
+   void slotKeepAspectRatio(bool mute);
+   void slotPreviewEnabled(bool show);
 
 Q_SIGNALS:
    void changed();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic