]> git.sesse.net Git - kdenlive/blob - src/geometrywidget.cpp
Fix small memleaks, and add option to show previous keyframe on monitor scene
[kdenlive] / src / geometrywidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "geometrywidget.h"
22 #include "monitor.h"
23 #include "renderer.h"
24 #include "keyframehelper.h"
25 #include "timecodedisplay.h"
26 #include "monitorscene.h"
27 #include "monitoreditwidget.h"
28 #include "onmonitoritems/onmonitorrectitem.h"
29 #include "kdenlivesettings.h"
30 #include "dragvalue.h"
31
32 #include <QtCore>
33 #include <QGraphicsView>
34 #include <QVBoxLayout>
35 #include <QGridLayout>
36 #include <QMenu>
37
38
39
40 GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos, bool isEffect, QWidget* parent):
41     QWidget(parent),
42     m_monitor(monitor),
43     m_timePos(new TimecodeDisplay(timecode)),
44     m_clipPos(clipPos),
45     m_inPoint(0),
46     m_outPoint(1),
47     m_isEffect(isEffect),
48     m_rect(NULL),
49     m_previous(NULL),
50     m_geometry(NULL),
51     m_showScene(true)
52 {
53     m_ui.setupUi(this);
54     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
55     MonitorEditWidget *edit = monitor->getEffectEdit();
56     edit->removeCustomControls();
57     edit->addCustomButton(KIcon("transform-crop"), i18n("Show previous keyframe"), this, SLOT(slotShowPreviousKeyFrame(bool)), true, KdenliveSettings::onmonitoreffects_geometryshowprevious());
58     edit->showVisibilityButton(true);
59     m_scene = edit->getScene();
60
61
62     /*
63         Setup of timeline and keyframe controls
64     */
65
66     ((QGridLayout *)(m_ui.widgetTimeWrapper->layout()))->addWidget(m_timePos, 1, 6);
67
68     QVBoxLayout *layout = new QVBoxLayout(m_ui.frameTimeline);
69     m_timeline = new KeyframeHelper(m_ui.frameTimeline);
70     layout->addWidget(m_timeline);
71     layout->setContentsMargins(0, 0, 0, 0);
72
73     m_ui.buttonPrevious->setIcon(KIcon("media-skip-backward"));
74     m_ui.buttonPrevious->setToolTip(i18n("Go to previous keyframe"));
75     m_ui.buttonNext->setIcon(KIcon("media-skip-forward"));
76     m_ui.buttonNext->setToolTip(i18n("Go to next keyframe"));
77     m_ui.buttonAddDelete->setIcon(KIcon("document-new"));
78     m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
79
80     m_ui.buttonSync->setIcon(KIcon("insert-link"));
81     m_ui.buttonSync->setToolTip(i18n("Synchronize with timeline cursor"));
82     m_ui.buttonSync->setChecked(KdenliveSettings::transitionfollowcursor());
83
84     connect(m_timeline, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int)));
85     connect(m_timeline, SIGNAL(keyframeMoved(int)),   this, SLOT(slotKeyframeMoved(int)));
86     connect(m_timeline, SIGNAL(addKeyframe(int)),     this, SLOT(slotAddKeyframe(int)));
87     connect(m_timeline, SIGNAL(removeKeyframe(int)),  this, SLOT(slotDeleteKeyframe(int)));
88     connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotPositionChanged()));
89     connect(m_ui.buttonPrevious,  SIGNAL(clicked()), this, SLOT(slotPreviousKeyframe()));
90     connect(m_ui.buttonNext,      SIGNAL(clicked()), this, SLOT(slotNextKeyframe()));
91     connect(m_ui.buttonAddDelete, SIGNAL(clicked()), this, SLOT(slotAddDeleteKeyframe()));
92     connect(m_ui.buttonSync,      SIGNAL(toggled(bool)), this, SLOT(slotSetSynchronize(bool)));
93
94     m_spinX = new DragValue(i18n("X"), 0, 0, -1, QString(), false, this);
95     m_spinX->setRange(-10000, 10000);
96     m_ui.horizontalLayout->addWidget(m_spinX);
97     
98     m_spinY = new DragValue(i18n("Y"), 0, 0, -1, QString(), false, this);
99     m_spinY->setRange(-10000, 10000);
100     m_ui.horizontalLayout->addWidget(m_spinY);
101     
102     m_spinWidth = new DragValue(i18n("W"), m_monitor->render->frameRenderWidth(), 0, -1, QString(), false, this);
103     m_spinWidth->setRange(1, 10000);
104     m_ui.horizontalLayout->addWidget(m_spinWidth);
105     
106     m_spinHeight = new DragValue(i18n("H"), m_monitor->render->renderHeight(), 0, -1, QString(), false, this);
107     m_spinHeight->setRange(1, 10000);
108     m_ui.horizontalLayout->addWidget(m_spinHeight);
109     m_ui.horizontalLayout->addStretch(10);
110     
111     m_spinSize = new DragValue(i18n("Size"), 100, 2, -1, i18n("%"), false, this);
112     m_spinSize->setRange(1, 10000);
113     m_ui.horizontalLayout2->addWidget(m_spinSize);
114     
115     m_opacity = new DragValue(i18n("Opacity"), 100, 0, -1, i18n("%"), true, this);
116     m_ui.horizontalLayout2->addWidget(m_opacity);
117     
118     /*
119         Setup of geometry controls
120     */
121
122     connect(m_spinX,            SIGNAL(valueChanged(int)), this, SLOT(slotSetX(int)));
123     connect(m_spinY,            SIGNAL(valueChanged(int)), this, SLOT(slotSetY(int)));
124     connect(m_spinWidth,        SIGNAL(valueChanged(int)), this, SLOT(slotSetWidth(int)));
125     connect(m_spinHeight,       SIGNAL(valueChanged(int)), this, SLOT(slotSetHeight(int)));
126
127     connect(m_spinSize,         SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
128
129     connect(m_opacity, SIGNAL(valueChanged(int)), this, SLOT(slotSetOpacity(int)));
130     
131     QMenu *menu = new QMenu(this);
132     QAction *adjustSize = new QAction(i18n("Adjust to original size"), this);
133     connect(adjustSize, SIGNAL(triggered()), this, SLOT(slotAdjustToFrameSize()));
134     menu->addAction(adjustSize);
135     QAction *fitToWidth = new QAction(i18n("Fit to width"), this);
136     connect(fitToWidth, SIGNAL(triggered()), this, SLOT(slotFitToWidth()));
137     menu->addAction(fitToWidth);
138     QAction *fitToHeight = new QAction(i18n("Fit to height"), this);
139     connect(fitToHeight, SIGNAL(triggered()), this, SLOT(slotFitToHeight()));
140     menu->addAction(fitToHeight);
141     menu->addSeparator();
142
143     QAction *alignleft = new QAction(KIcon("kdenlive-align-left"), i18n("Align left"), this);
144     connect(alignleft, SIGNAL(triggered()), this, SLOT(slotMoveLeft()));
145     menu->addAction(alignleft);
146     QAction *alignhcenter = new QAction(KIcon("kdenlive-align-hor"), i18n("Center horizontally"), this);
147     connect(alignhcenter, SIGNAL(triggered()), this, SLOT(slotCenterH()));
148     menu->addAction(alignhcenter);
149     QAction *alignright = new QAction(KIcon("kdenlive-align-right"), i18n("Align right"), this);
150     connect(alignright, SIGNAL(triggered()), this, SLOT(slotMoveRight()));
151     menu->addAction(alignright);
152     QAction *aligntop = new QAction(KIcon("kdenlive-align-top"), i18n("Align top"), this);
153     connect(aligntop, SIGNAL(triggered()), this, SLOT(slotMoveTop()));
154     menu->addAction(aligntop);    
155     QAction *alignvcenter = new QAction(KIcon("kdenlive-align-vert"), i18n("Center vertically"), this);
156     connect(alignvcenter, SIGNAL(triggered()), this, SLOT(slotCenterV()));
157     menu->addAction(alignvcenter);
158     QAction *alignbottom = new QAction(KIcon("kdenlive-align-bottom"), i18n("Align bottom"), this);
159     connect(alignbottom, SIGNAL(triggered()), this, SLOT(slotMoveBottom()));
160     menu->addAction(alignbottom);
161     m_ui.buttonOptions->setMenu(menu);
162
163     /*connect(m_ui.buttonMoveLeft,   SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
164     connect(m_ui.buttonCenterH,    SIGNAL(clicked()), this, SLOT(slotCenterH()));
165     connect(m_ui.buttonMoveRight,  SIGNAL(clicked()), this, SLOT(slotMoveRight()));
166     connect(m_ui.buttonMoveTop,    SIGNAL(clicked()), this, SLOT(slotMoveTop()));
167     connect(m_ui.buttonCenterV,    SIGNAL(clicked()), this, SLOT(slotCenterV()));
168     connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));*/
169
170
171     /*
172         Setup of configuration controls
173     */
174
175     connect(edit, SIGNAL(showEdit(bool)), this, SLOT(slotShowScene(bool)));
176
177     connect(m_scene, SIGNAL(addKeyframe()),    this, SLOT(slotAddKeyframe()));
178     connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
179     connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
180 }
181
182 GeometryWidget::~GeometryWidget()
183 {
184     m_scene->setEnabled(true);
185     delete m_timePos;
186     delete m_timeline;
187     delete m_spinX;
188     delete m_spinY;
189     delete m_spinWidth;
190     delete m_spinHeight;
191     delete m_opacity;
192     m_scene->removeItem(m_rect);
193     if (m_rect) delete m_rect;
194     if (m_previous) delete m_previous;
195     delete m_geometry;
196     if (m_monitor) {
197         m_monitor->getEffectEdit()->showVisibilityButton(false);
198         m_monitor->slotEffectScene(false);
199     }
200 }
201
202 void GeometryWidget::slotShowPreviousKeyFrame(bool show)
203 {
204     KdenliveSettings::setOnmonitoreffects_geometryshowprevious(show);
205     slotPositionChanged(-1, false);
206 }
207
208 void GeometryWidget::updateTimecodeFormat()
209 {
210     m_timePos->slotUpdateTimeCodeFormat();
211 }
212
213 QString GeometryWidget::getValue() const
214 {
215     return m_geometry->serialise();
216 }
217
218 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
219 {
220     m_inPoint = minframe;
221     m_outPoint = maxframe;
222
223     if (m_geometry)
224         m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
225     else
226         m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
227
228     if (elem.attribute("fixed") == "1" || maxframe < minframe) {
229         // Keyframes are disabled
230         m_ui.widgetTimeWrapper->setHidden(true);
231     } else {
232         m_ui.widgetTimeWrapper->setHidden(false);
233         m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint - 1);
234         m_timeline->update();
235         m_timePos->setRange(0, m_outPoint - m_inPoint - 1);
236     }
237
238     // no opacity
239     if (elem.attribute("opacity") == "false") {
240         m_opacity->setHidden(true);
241         m_ui.horizontalLayout2->addStretch(2);
242     }
243
244     Mlt::GeometryItem item;
245
246     m_geometry->fetch(&item, 0);
247     delete m_rect;
248     m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar());
249     m_rect->setPos(item.x(), item.y());
250     m_rect->setZValue(0);
251     m_scene->addItem(m_rect);
252     connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry()));
253
254     slotPositionChanged(0, false);
255     slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
256 }
257
258 void GeometryWidget::slotSyncPosition(int relTimelinePos)
259 {
260     // do only sync if this effect is keyframable
261     if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
262         relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
263         if (relTimelinePos != m_timePos->getValue())
264             slotPositionChanged(relTimelinePos, false);
265     }
266 }
267
268
269 void GeometryWidget::slotPositionChanged(int pos, bool seek)
270 {
271     if (pos == -1)
272         pos = m_timePos->getValue();
273     else
274         m_timePos->setValue(pos);
275
276     m_timeline->blockSignals(true);
277     m_timeline->setValue(pos);
278     m_timeline->blockSignals(false);
279
280     Mlt::GeometryItem item;
281     Mlt::GeometryItem previousItem;
282     if (m_geometry->fetch(&item, pos) || item.key() == false) {
283         // no keyframe
284         m_rect->setEnabled(false);
285         m_scene->setEnabled(false);
286         m_ui.widgetGeometry->setEnabled(false);
287         m_ui.buttonAddDelete->setIcon(KIcon("document-new"));
288         m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
289     } else {
290         // keyframe
291         m_rect->setEnabled(true);
292         m_scene->setEnabled(true);
293         m_ui.widgetGeometry->setEnabled(true);
294         m_ui.buttonAddDelete->setIcon(KIcon("edit-delete"));
295         m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
296     }
297     
298     if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
299         if (m_previous) {
300             m_scene->removeItem(m_previous);
301         }
302     }
303     else {
304         if (m_previous == NULL) {
305             m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
306             m_previous->setBrush(QColor(200, 200, 0, 20));
307             m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
308             
309             m_previous->setPos(previousItem.x(), previousItem.y());
310             m_previous->setZValue(-1);
311             m_previous->setEnabled(false);
312         }
313         else {
314             m_previous->setPos(previousItem.x(), previousItem.y());
315             m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
316         }
317         m_scene->addItem(m_previous);
318     }
319
320     m_rect->setPos(item.x(), item.y());
321     m_rect->setRect(0, 0, item.w(), item.h());
322
323     m_opacity->blockSignals(true);
324     m_opacity->setValue(item.mix());
325     m_opacity->blockSignals(false);
326
327     slotUpdateProperties();
328
329     if (seek && KdenliveSettings::transitionfollowcursor())
330         emit seekToPos(m_clipPos + pos);
331 }
332
333 void GeometryWidget::slotKeyframeMoved(int pos)
334 {
335     slotPositionChanged(pos);
336     slotUpdateGeometry();
337     QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
338 }
339
340 void GeometryWidget::slotAddKeyframe(int pos)
341 {
342     Mlt::GeometryItem item;
343     if (pos == -1)
344         pos = m_timePos->getValue();
345     item.frame(pos);
346     QRectF r = m_rect->rect().normalized();
347     QPointF rectpos = m_rect->pos();
348     item.x(rectpos.x());
349     item.y(rectpos.y());
350     item.w(r.width());
351     item.h(r.height());
352     item.mix(m_opacity->value());
353     m_geometry->insert(item);
354
355     m_timeline->update();
356     slotPositionChanged(pos, false);
357     emit parameterChanged();
358 }
359
360 void GeometryWidget::slotDeleteKeyframe(int pos)
361 {
362     Mlt::GeometryItem item;
363     if (pos == -1)
364         pos = m_timePos->getValue();
365     // check there is more than one keyframe, do not allow to delete last one
366     if (m_geometry->next_key(&item, pos + 1)) {
367         if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
368             return;
369     }
370     m_geometry->remove(pos);
371
372     m_timeline->update();
373     slotPositionChanged(pos, false);
374     emit parameterChanged();
375 }
376
377 void GeometryWidget::slotPreviousKeyframe()
378 {
379     Mlt::GeometryItem item;
380     // Go to start if no keyframe is found
381     int currentPos = m_timePos->getValue();
382     int pos = 0;
383     if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
384         pos = item.frame();
385
386     slotPositionChanged(pos);
387 }
388
389 void GeometryWidget::slotNextKeyframe()
390 {
391     Mlt::GeometryItem item;
392     // Go to end if no keyframe is found
393     int pos = m_timeline->frameLength;
394     if (!m_geometry->next_key(&item, m_timeline->value() + 1))
395         pos = item.frame();
396
397     slotPositionChanged(pos);
398 }
399
400 void GeometryWidget::slotAddDeleteKeyframe()
401 {
402     Mlt::GeometryItem item;
403     if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
404         slotAddKeyframe();
405     else
406         slotDeleteKeyframe();
407 }
408
409
410 void GeometryWidget::slotCheckMonitorPosition(int renderPos)
411 {
412     if (m_showScene) {
413         /*
414             We do only get the position in timeline if this geometry belongs to a transition,
415             therefore we need two ways here.
416         */
417         if (m_isEffect) {
418             emit checkMonitorPosition(renderPos);
419         } else {
420             if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint) {
421                 if (!m_scene->views().at(0)->isVisible())
422                     m_monitor->slotEffectScene(true);
423             } else {
424                 m_monitor->slotEffectScene(false);
425             }
426         }
427     }
428 }
429
430
431 void GeometryWidget::slotUpdateGeometry()
432 {
433     Mlt::GeometryItem item;
434     int pos = m_timePos->getValue();
435
436     // get keyframe and make sure it is the correct one
437     if (m_geometry->next_key(&item, pos) || item.frame() != pos)
438         return;
439
440     QRectF rectSize = m_rect->rect().normalized();
441     QPointF rectPos = m_rect->pos();
442     item.x(rectPos.x());
443     item.y(rectPos.y());
444     item.w(rectSize.width());
445     item.h(rectSize.height());
446     m_geometry->insert(item);
447     emit parameterChanged();
448 }
449
450 void GeometryWidget::slotUpdateProperties()
451 {
452     QRectF rectSize = m_rect->rect().normalized();
453     QPointF rectPos = m_rect->pos();
454     double size;
455     if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
456         size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
457     else
458         size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
459
460     m_spinX->blockSignals(true);
461     m_spinY->blockSignals(true);
462     m_spinWidth->blockSignals(true);
463     m_spinHeight->blockSignals(true);
464     m_spinSize->blockSignals(true);
465
466     m_spinX->setValue(rectPos.x());
467     m_spinY->setValue(rectPos.y());
468     m_spinWidth->setValue(rectSize.width());
469     m_spinHeight->setValue(rectSize.height());
470     m_spinSize->setValue(size);
471
472     m_spinX->blockSignals(false);
473     m_spinY->blockSignals(false);
474     m_spinWidth->blockSignals(false);
475     m_spinHeight->blockSignals(false);
476     m_spinSize->blockSignals(false);
477 }
478
479
480 void GeometryWidget::slotSetX(int value)
481 {
482     m_rect->setPos(value, m_spinY->value());
483     slotUpdateGeometry();
484 }
485
486 void GeometryWidget::slotSetY(int value)
487 {
488     m_rect->setPos(m_spinX->value(), value);
489     slotUpdateGeometry();
490 }
491
492 void GeometryWidget::slotSetWidth(int value)
493 {
494     m_rect->setRect(0, 0, value, m_spinHeight->value());
495     slotUpdateGeometry();
496 }
497
498 void GeometryWidget::slotSetHeight(int value)
499 {
500     m_rect->setRect(0, 0, m_spinWidth->value(), value);
501     slotUpdateGeometry();
502 }
503
504
505 void GeometryWidget::slotResize(double value)
506 {
507     m_rect->setRect(0, 0,
508                     (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
509                     (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
510     slotUpdateGeometry();
511 }
512
513
514 void GeometryWidget::slotSetOpacity(int value)
515 {
516     int pos = m_timePos->getValue();
517     Mlt::GeometryItem item;
518     if (m_geometry->fetch(&item, pos) || item.key() == false)
519         return;
520     item.mix(value);
521     m_geometry->insert(item);
522     emit parameterChanged();
523 }
524
525
526 void GeometryWidget::slotMoveLeft()
527 {
528     m_rect->setPos(0, m_rect->pos().y());
529     slotUpdateGeometry();
530 }
531
532 void GeometryWidget::slotCenterH()
533 {
534     m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
535     slotUpdateGeometry();
536 }
537
538 void GeometryWidget::slotMoveRight()
539 {
540     m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
541     slotUpdateGeometry();
542 }
543
544 void GeometryWidget::slotMoveTop()
545 {
546     m_rect->setPos(m_rect->pos().x(), 0);
547     slotUpdateGeometry();
548 }
549
550 void GeometryWidget::slotCenterV()
551 {
552     m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
553     slotUpdateGeometry();
554 }
555
556 void GeometryWidget::slotMoveBottom()
557 {
558     m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
559     slotUpdateGeometry();
560 }
561
562
563 void GeometryWidget::slotSetSynchronize(bool sync)
564 {
565     KdenliveSettings::setTransitionfollowcursor(sync);
566     if (sync)
567         emit seekToPos(m_clipPos + m_timePos->getValue());
568 }
569
570 void GeometryWidget::slotShowScene(bool show)
571 {
572     m_showScene = show;
573     if (!m_showScene)
574         m_monitor->slotEffectScene(false);
575     else
576         slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
577 }
578
579 void GeometryWidget::setFrameSize(QPoint size)
580 {
581     m_frameSize = size;
582 }
583
584 void GeometryWidget::slotAdjustToFrameSize()
585 {
586     if (m_frameSize == QPoint()) m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
587     m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
588     m_spinHeight->setValue(m_frameSize.y());
589 }
590
591 void GeometryWidget::slotFitToWidth()
592 {
593     if (m_frameSize == QPoint()) m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
594     double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
595     m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
596     m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
597 }
598
599 void GeometryWidget::slotFitToHeight()
600 {
601     if (m_frameSize == QPoint()) m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
602     double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
603     m_spinHeight->setValue(m_monitor->render->renderHeight());
604     m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
605 }
606
607 #include "geometrywidget.moc"