1 /***************************************************************************
2 * Copyright (C) 2011 by Till Theato (root@ttill.de) *
3 * This file is part of Kdenlive (www.kdenlive.org). *
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. *
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. *
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 ***************************************************************************/
20 #include "monitoreditwidget.h"
22 #include "monitorscene.h"
23 #include "kdenlivesettings.h"
25 #include <QGraphicsView>
26 #include <QVBoxLayout>
28 #include <QToolButton>
32 MonitorEditWidget::MonitorEditWidget(Render* renderer, QWidget* parent) :
35 setAutoFillBackground(true);
36 setAttribute(Qt::WA_PaintOnScreen, false);
37 setAttribute(Qt::WA_OpaquePaintEvent, false);
38 setContentsMargins(0, 0, 0, 0);
39 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
41 m_scene = new MonitorScene(renderer);
42 m_view = new QGraphicsView(m_scene, m_ui.frameVideo);
43 m_view->setFrameShape(QFrame::NoFrame);
44 m_view->setRenderHints(QFlags<QPainter::RenderHint>());
45 m_view->scale(((double) renderer->renderWidth()) / renderer->frameRenderWidth(), 1.0);
46 m_view->setMouseTracking(true);
49 ((QVBoxLayout*)m_ui.frameVideo->layout())->addWidget(m_view);
51 m_customControlsLayout = new QVBoxLayout(m_ui.frameCustomControls);
52 m_customControlsLayout->setContentsMargins(0, 4, 0, 4);
53 m_customControlsLayout->setSpacing(0);
55 m_visibilityAction = new QAction(KIcon("video-display"), i18n("Show/Hide edit mode"), this);
56 m_visibilityAction->setCheckable(true);
57 m_visibilityAction->setChecked(KdenliveSettings::showOnMonitorScene());
58 m_visibilityAction->setVisible(false);
60 m_ui.buttonDirectUpdate->setIcon(KIcon("transform-scale"));
61 m_ui.buttonDirectUpdate->setToolTip(i18n("Update parameters while monitor scene changes"));
62 m_ui.buttonDirectUpdate->setChecked(KdenliveSettings::monitorscene_directupdate());
64 m_ui.buttonZoomFit->setIcon(KIcon("zoom-fit-best"));
65 m_ui.buttonZoomFit->setToolTip(i18n("Fit zoom to monitor size"));
66 m_ui.buttonZoomOriginal->setIcon(KIcon("zoom-original"));
67 m_ui.buttonZoomOriginal->setToolTip(i18n("Original size"));
69 connect(m_ui.sliderZoom, SIGNAL(valueChanged(int)), m_scene, SLOT(slotZoom(int)));
70 connect(m_scene, SIGNAL(zoomChanged(int)), this, SLOT(slotZoom(int)));
71 connect(m_ui.buttonZoomFit, SIGNAL(clicked()), m_scene, SLOT(slotZoomFit()));
72 connect(m_ui.buttonZoomOriginal, SIGNAL(clicked()), m_scene, SLOT(slotZoomOriginal()));
73 m_scene->slotZoomFit();
75 connect(m_visibilityAction, SIGNAL(triggered(bool)), this, SIGNAL(showEdit(bool)));
76 connect(m_ui.buttonDirectUpdate, SIGNAL(toggled(bool)), this, SLOT(slotSetDirectUpdate(bool)));
79 MonitorEditWidget::~MonitorEditWidget()
81 KdenliveSettings::setShowOnMonitorScene(m_visibilityAction->isChecked());
84 delete m_visibilityAction;
87 void MonitorEditWidget::slotZoom(int value)
89 m_ui.sliderZoom->blockSignals(true);
90 m_ui.sliderZoom->setValue(value);
91 m_ui.sliderZoom->blockSignals(false);
94 void MonitorEditWidget::resetProfile(Render* renderer)
96 m_view->scale(((double) renderer->renderWidth()) / renderer->frameRenderWidth(), 1.0);
97 m_scene->resetProfile();
100 MonitorScene* MonitorEditWidget::getScene()
105 QAction* MonitorEditWidget::getVisibilityAction()
107 return m_visibilityAction;
110 void MonitorEditWidget::showVisibilityButton(bool show)
112 m_visibilityAction->setVisible(show);
115 void MonitorEditWidget::addCustomControl(QWidget* widget)
117 m_customControlsLayout->addWidget(widget);
120 void MonitorEditWidget::addCustomButton(const QIcon& icon, const QString& text, const QObject* receiver, const char* member, bool checkable, bool checked)
122 QToolButton *button = new QToolButton(m_ui.frameCustomControls);
123 button->setIcon(icon);
124 button->setToolTip(text);
125 button->setCheckable(checkable);
126 button->setChecked(checked);
127 button->setAutoRaise(true);
129 connect(button, SIGNAL(toggled(bool)), receiver, member);
131 connect(button, SIGNAL(clicked()), receiver, member);
132 m_customControlsLayout->addWidget(button);
135 void MonitorEditWidget::removeCustomControls()
138 while ((child = m_customControlsLayout->takeAt(0)) != 0) {
139 if (child->widget()) delete child->widget();
144 void MonitorEditWidget::slotSetDirectUpdate(bool directUpdate)
146 KdenliveSettings::setMonitorscene_directupdate(directUpdate);
149 #include "monitoreditwidget.moc"