]> git.sesse.net Git - kdenlive/blob - src/monitoreditwidget.cpp
Moving choosecolorwidget and colorpickerwidget in the widget folder.
[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 "onmonitoritems/onmonitorrectitem.h"
26 #include "onmonitoritems/onmonitorpathitem.h"
27
28 #include <QGraphicsView>
29 #include <QVBoxLayout>
30 #include <QAction>
31 #include <QToolButton>
32 #include <QMouseEvent>
33 #include <QGraphicsView>
34
35 #include <KIcon>
36
37
38 MonitorEditWidget::MonitorEditWidget(Render* renderer, QWidget* parent) :
39         QWidget(parent)
40 {
41     setAutoFillBackground(true);
42     setAttribute(Qt::WA_PaintOnScreen, false);
43     setAttribute(Qt::WA_OpaquePaintEvent, false);
44     setContentsMargins(0, 0, 0, 0);
45     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
46     m_ui.setupUi(this);
47     m_scene = new MonitorScene(renderer);
48     m_view = new QGraphicsView(m_scene, m_ui.frameVideo);
49     m_view->setFrameShape(QFrame::NoFrame);
50     //m_view->setRenderHints(QFlags<QPainter::RenderHint>());
51     m_view->scale(((double) renderer->renderWidth()) / renderer->frameRenderWidth(), 1.0);
52     m_view->setMouseTracking(true);
53     m_scene->setUp();
54
55     ((QVBoxLayout*)m_ui.frameVideo->layout())->addWidget(m_view);
56
57     m_customControlsLayout = new QVBoxLayout(m_ui.frameCustomControls);
58     m_customControlsLayout->setContentsMargins(0, 4, 0, 4);
59     m_customControlsLayout->setSpacing(0);
60
61     m_visibilityAction = new QAction(KIcon("video-display"), i18n("Show/Hide edit mode"), this);
62     m_visibilityAction->setCheckable(true);
63     m_visibilityAction->setChecked(KdenliveSettings::showOnMonitorScene());
64     m_visibilityAction->setVisible(false);
65
66     m_ui.buttonDirectUpdate->setIcon(KIcon("transform-scale"));
67     m_ui.buttonDirectUpdate->setToolTip(i18n("Update parameters while monitor scene changes"));
68     m_ui.buttonDirectUpdate->setChecked(KdenliveSettings::monitorscene_directupdate());
69
70     m_ui.buttonZoomFit->setIcon(KIcon("zoom-fit-best"));
71     m_ui.buttonZoomFit->setToolTip(i18n("Fit zoom to monitor size"));
72     m_ui.buttonZoomOriginal->setIcon(KIcon("zoom-original"));
73     m_ui.buttonZoomOriginal->setToolTip(i18n("Original size"));
74
75     connect(m_ui.sliderZoom, SIGNAL(valueChanged(int)), m_scene, SLOT(slotZoom(int)));
76     connect(m_scene, SIGNAL(zoomChanged(int)), this, SLOT(slotZoom(int)));
77     connect(m_ui.buttonZoomFit,      SIGNAL(clicked()), m_scene, SLOT(slotZoomFit()));
78     connect(m_ui.buttonZoomOriginal, SIGNAL(clicked()), m_scene, SLOT(slotZoomOriginal()));
79     m_scene->slotZoomFit();
80
81     connect(m_visibilityAction, SIGNAL(triggered(bool)), this, SIGNAL(showEdit(bool)));
82     connect(m_ui.buttonDirectUpdate, SIGNAL(toggled(bool)), this, SLOT(slotSetDirectUpdate(bool)));
83 }
84
85 MonitorEditWidget::~MonitorEditWidget()
86 {
87     KdenliveSettings::setShowOnMonitorScene(m_visibilityAction->isChecked());
88     delete m_view;
89     delete m_scene;
90     delete m_visibilityAction;
91 }
92
93 void MonitorEditWidget::slotZoom(int value)
94 {
95     m_ui.sliderZoom->blockSignals(true);
96     m_ui.sliderZoom->setValue(value);
97     m_ui.sliderZoom->blockSignals(false);
98 }
99
100 void MonitorEditWidget::resetProfile(Render* renderer)
101 {
102     m_view->scale(((double) renderer->renderWidth()) / renderer->frameRenderWidth(), 1.0);
103     m_scene->resetProfile();
104 }
105
106 MonitorScene* MonitorEditWidget::getScene() const
107 {
108     return m_scene;
109 }
110
111 QAction* MonitorEditWidget::getVisibilityAction()
112 {
113     return m_visibilityAction;
114 }
115
116 void MonitorEditWidget::showVisibilityButton(bool show)
117 {
118     m_visibilityAction->setVisible(show);
119 }
120
121 void MonitorEditWidget::addCustomControl(QWidget* widget)
122 {
123     m_customControlsLayout->addWidget(widget);
124 }
125
126 void MonitorEditWidget::addCustomButton(const QIcon& icon, const QString& text, const QObject* receiver, const char* member, bool checkable, bool checked)
127 {
128     QToolButton *button = new QToolButton(m_ui.frameCustomControls);
129     button->setIcon(icon);
130     button->setToolTip(text);
131     button->setCheckable(checkable);
132     button->setChecked(checked);
133     button->setAutoRaise(true);
134     if (checkable)
135         connect(button, SIGNAL(toggled(bool)), receiver, member);
136     else
137         connect(button, SIGNAL(clicked()), receiver, member);
138     m_customControlsLayout->addWidget(button);
139 }
140
141 void MonitorEditWidget::removeCustomControls()
142 {
143     QLayoutItem *child;
144     while ((child = m_customControlsLayout->takeAt(0)) != 0) {
145         if (child->widget()) delete child->widget();
146         delete child;
147     }
148 }
149
150 void MonitorEditWidget::slotSetDirectUpdate(bool directUpdate)
151 {
152     KdenliveSettings::setMonitorscene_directupdate(directUpdate);
153 }
154
155 #include "monitoreditwidget.moc"