]> git.sesse.net Git - kdenlive/blob - src/monitoreditwidget.cpp
Fix bugs when default profile does not match current/last profile.
[kdenlive] / src / monitoreditwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2011 by Till Theato (root@ttill.de)                     *
3  *   This file is part of Kdenlive (www.kdenlive.org).                     *
4  *                                                                         *
5  *   Kdenlive is free software: you can redistribute it and/or modify      *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation, either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   Kdenlive is distributed in the hope that it will be useful,           *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with Kdenlive.  If not, see <http://www.gnu.org/licenses/>.     *
17  ***************************************************************************/
18
19
20 #include "monitoreditwidget.h"
21 #include "renderer.h"
22 #include "monitorscene.h"
23 #include "kdenlivesettings.h"
24
25 #include <QGraphicsView>
26 #include <QVBoxLayout>
27 #include <QAction>
28 #include <QToolButton>
29
30 #include <KIcon>
31
32 MonitorEditWidget::MonitorEditWidget(Render* renderer, QWidget* parent) :
33         QWidget(parent)
34 {
35     m_ui.setupUi(this);
36
37     m_scene = new MonitorScene(renderer);
38     m_view = new QGraphicsView(m_scene, m_ui.frameVideo);
39     m_view->setRenderHints(QFlags<QPainter::RenderHint>());
40     m_view->scale(((double) renderer->renderWidth()) / renderer->frameRenderWidth(), 1.0);
41     m_view->setMouseTracking(true);
42     m_scene->setUp();
43
44     ((QVBoxLayout*)m_ui.frameVideo->layout())->addWidget(m_view);
45
46     m_customControlsLayout = new QVBoxLayout(m_ui.frameCustomControls);
47     m_customControlsLayout->setContentsMargins(0, 4, 0, 4);
48     m_customControlsLayout->setSpacing(0);
49
50     m_visibilityAction = new QAction(KIcon("video-display"), i18n("Show/Hide edit mode"), this);
51     m_visibilityAction->setCheckable(true);
52     m_visibilityAction->setVisible(false);
53
54     m_ui.buttonDirectUpdate->setIcon(KIcon("transform-scale"));
55     m_ui.buttonDirectUpdate->setToolTip(i18n("Update parameters while monitor scene changes"));
56     m_ui.buttonDirectUpdate->setChecked(KdenliveSettings::monitorscene_directupdate());
57
58     m_ui.buttonZoomFit->setIcon(KIcon("zoom-fit-best"));
59     m_ui.buttonZoomFit->setToolTip(i18n("Fit zoom to monitor size"));
60     m_ui.buttonZoomOriginal->setIcon(KIcon("zoom-original"));
61     m_ui.buttonZoomOriginal->setToolTip(i18n("Original size"));
62
63     connect(m_ui.sliderZoom, SIGNAL(valueChanged(int)), m_scene, SLOT(slotZoom(int)));
64     connect(m_scene, SIGNAL(zoomChanged(int)), m_ui.sliderZoom, SLOT(setValue(int)));
65     connect(m_ui.buttonZoomFit,      SIGNAL(clicked()), m_scene, SLOT(slotZoomFit()));
66     connect(m_ui.buttonZoomOriginal, SIGNAL(clicked()), m_scene, SLOT(slotZoomOriginal()));
67     m_scene->slotZoomFit();
68
69     connect(m_visibilityAction, SIGNAL(triggered(bool)), this, SIGNAL(showEdit(bool)));
70     connect(m_ui.buttonDirectUpdate, SIGNAL(toggled(bool)), this, SLOT(slotSetDirectUpdate(bool)));
71 }
72
73 MonitorEditWidget::~MonitorEditWidget()
74 {
75     delete m_view;
76     delete m_scene;
77     delete m_visibilityAction;
78 }
79
80 void MonitorEditWidget::resetProfile(Render* renderer)
81 {
82     m_view->scale(((double) renderer->renderWidth()) / renderer->frameRenderWidth(), 1.0);
83     m_scene->resetProfile();
84 }
85
86 MonitorScene* MonitorEditWidget::getScene()
87 {
88     return m_scene;
89 }
90
91 QAction* MonitorEditWidget::getVisibilityAction()
92 {
93     return m_visibilityAction;
94 }
95
96 void MonitorEditWidget::showVisibilityButton(bool show)
97 {
98     m_visibilityAction->setVisible(show);
99 }
100
101 void MonitorEditWidget::addCustomControl(QWidget* widget)
102 {
103     m_customControlsLayout->addWidget(widget);
104 }
105
106 void MonitorEditWidget::addCustomButton(const QIcon& icon, const QString& text, const QObject* receiver, const char* member, bool checkable, bool checked)
107 {
108     QToolButton *button = new QToolButton(m_ui.frameCustomControls);
109     button->setIcon(icon);
110     button->setToolTip(text);
111     button->setCheckable(checkable);
112     button->setChecked(checked);
113     button->setAutoRaise(true);
114     if (checkable)
115         connect(button, SIGNAL(toggled(bool)), receiver, member);
116     else
117         connect(button, SIGNAL(clicked()), receiver, member);
118     m_customControlsLayout->addWidget(button);
119 }
120
121 void MonitorEditWidget::removeCustomControls()
122 {
123     QLayoutItem *child;
124     while ((child = m_customControlsLayout->takeAt(0)) != 0)
125         delete child;
126 }
127
128 void MonitorEditWidget::slotSetDirectUpdate(bool directUpdate)
129 {
130     KdenliveSettings::setMonitorscene_directupdate(directUpdate);
131 }
132
133 #include "monitoreditwidget.moc"