mainwindow.cpp 165 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/***************************************************************************
 *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
20
#include "mainwindow.h"
21
#include "assets/assetpanel.hpp"
22
#include "bin/clipcreator.hpp"
23
#include "bin/generators/generators.h"
Nicolas Carion's avatar
Nicolas Carion committed
24
#include "bin/projectclip.h"
25 26
#include "bin/projectfolder.h"
#include "bin/projectitemmodel.h"
Nicolas Carion's avatar
Nicolas Carion committed
27
#include "core.h"
28
#include "dialogs/clipcreationdialog.h"
Nicolas Carion's avatar
Nicolas Carion committed
29 30 31
#include "dialogs/kdenlivesettingsdialog.h"
#include "dialogs/renderwidget.h"
#include "dialogs/wizard.h"
32
#include "doc/docundostack.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
33
#include "doc/kdenlivedoc.h"
34
#include "effects/effectlist/view/effectlistwidget.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
35 36
#include "effectslist/effectbasket.h"
#include "hidetitlebars.h"
37 38
#include "jobs/jobmanager.h"
#include "jobs/scenesplitjob.hpp"
39
#include "jobs/speedjob.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
40
#include "jobs/stabilizejob.hpp"
41
#include "jobs/transcodeclipjob.h"
Nicolas Carion's avatar
Nicolas Carion committed
42 43 44
#include "kdenlivesettings.h"
#include "layoutmanagement.h"
#include "library/librarywidget.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
45
#include "audiomixer/mixermanager.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
46 47 48 49 50 51
#include "mainwindowadaptor.h"
#include "mltconnection.h"
#include "mltcontroller/clipcontroller.h"
#include "monitor/monitor.h"
#include "monitor/monitormanager.h"
#include "monitor/scopes/audiographspectrum.h"
Nicolas Carion's avatar
linting  
Nicolas Carion committed
52
#include "profiles/profilemodel.hpp"
Vincent Pinon's avatar
Vincent Pinon committed
53
#include "project/cliptranscode.h"
Vincent Pinon's avatar
Vincent Pinon committed
54
#include "project/dialogs/archivewidget.h"
Nicolas Carion's avatar
Nicolas Carion committed
55 56
#include "project/dialogs/projectsettings.h"
#include "project/projectcommands.h"
Till Theato's avatar
Till Theato committed
57
#include "project/projectmanager.h"
Nicolas Carion's avatar
Nicolas Carion committed
58
#include "scopes/scopemanager.h"
Nicolas Carion's avatar
linting  
Nicolas Carion committed
59
#include "timeline2/view/timelinecontroller.h"
60
#include "timeline2/view/timelinetabs.hpp"
61
#include "timeline2/view/timelinewidget.h"
Nicolas Carion's avatar
Nicolas Carion committed
62 63 64 65 66
#include "titler/titlewidget.h"
#include "transitions/transitionlist/view/transitionlistwidget.hpp"
#include "transitions/transitionsrepository.hpp"
#include "utils/resourcewidget.h"
#include "utils/thememanager.h"
67

68
#include "profiles/profilerepository.hpp"
69 70
#include "widgets/progressbutton.h"
#include <config-kdenlive.h>
71

72
#include "project/dialogs/temporarydata.h"
73

74 75 76
#ifdef USE_JOGSHUTTLE
#include "jogshuttle/jogmanager.h"
#endif
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
77

78
#include <KActionCategory>
Nicolas Carion's avatar
Nicolas Carion committed
79
#include <KActionCollection>
80
#include <KActionMenu>
Nicolas Carion's avatar
Nicolas Carion committed
81 82
#include <KColorScheme>
#include <KColorSchemeManager>
83
#include <KConfigDialog>
Nicolas Carion's avatar
Nicolas Carion committed
84 85
#include <KDualAction>
#include <KEditToolBar>
86
#include <KIconTheme>
Nicolas Carion's avatar
Nicolas Carion committed
87 88
#include <KMessageBox>
#include <KNotifyConfigWidget>
89
#include <KRecentDirs>
Nicolas Carion's avatar
Nicolas Carion committed
90 91 92 93 94
#include <KShortcutsDialog>
#include <KStandardAction>
#include <KToolBar>
#include <KXMLGUIFactory>
#include <klocalizedstring.h>
95 96
#include <kns3/downloaddialog.h>
#include <kns3/knewstuffaction.h>
Nicolas Carion's avatar
Nicolas Carion committed
97
#include <ktogglefullscreenaction.h>
98

Laurent Montel's avatar
Laurent Montel committed
99
#include "kdenlive_debug.h"
Nicolas Carion's avatar
Nicolas Carion committed
100 101 102 103
#include <QAction>
#include <QFileDialog>
#include <QMenu>
#include <QMenuBar>
104
#include <QStatusBar>
Nicolas Carion's avatar
Nicolas Carion committed
105
#include <QStyleFactory>
106
#include <QUndoGroup>
Vincent Pinon's avatar
Vincent Pinon committed
107 108 109
#include <KConfigGroup>
#include <QDialogButtonBox>
#include <QPushButton>
110
#include <QScreen>
Nicolas Carion's avatar
Nicolas Carion committed
111 112
#include <QStandardPaths>
#include <QVBoxLayout>
113

114
static const char version[] = KDENLIVE_VERSION;
Nicolas Carion's avatar
Nicolas Carion committed
115
namespace Mlt {
116
class Producer;
Laurent Montel's avatar
Laurent Montel committed
117
}
118

Laurent Montel's avatar
Laurent Montel committed
119 120
QMap<QString, QImage> MainWindow::m_lumacache;
QMap<QString, QStringList> MainWindow::m_lumaFiles;
121

122
/*static bool sortByNames(const QPair<QString, QAction *> &a, const QPair<QString, QAction*> &b)
123 124
{
    return a.first < b.first;
125
}*/
126

Yuri Chornoivan's avatar
Yuri Chornoivan committed
127
// determine the default KDE style as defined BY THE USER
128
// (as opposed to whatever style KDE considers default)
Laurent Montel's avatar
Laurent Montel committed
129
static QString defaultStyle(const char *fallback = nullptr)
130 131 132 133 134 135
{
    KSharedConfigPtr kdeGlobals = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals);
    KConfigGroup cg(kdeGlobals, "KDE");
    return cg.readEntry("widgetStyle", fallback);
}

Nicolas Carion's avatar
Nicolas Carion committed
136
MainWindow::MainWindow(QWidget *parent)
137
    : KXmlGuiWindow(parent)
Nicolas Carion's avatar
Nicolas Carion committed
138

139
{
140 141
}

142
void MainWindow::init()
143
{
144
    QString desktopStyle = QApplication::style()->objectName();
145 146 147 148 149
    // Load themes
    auto themeManager = new ThemeManager(actionCollection());
    actionCollection()->addAction(QStringLiteral("themes_menu"), themeManager);
    connect(themeManager, &ThemeManager::themeChanged, this, &MainWindow::slotThemeChanged);

150 151 152 153
    if (!KdenliveSettings::widgetstyle().isEmpty() && QString::compare(desktopStyle, KdenliveSettings::widgetstyle(), Qt::CaseInsensitive) != 0) {
        // User wants a custom widget style, init
        doChangeStyle();
    }
Nicolas Carion's avatar
Nicolas Carion committed
154

155
    // Widget themes for non KDE users
Laurent Montel's avatar
Laurent Montel committed
156
    KActionMenu *stylesAction = new KActionMenu(i18n("Style"), this);
Nicolas Carion's avatar
Nicolas Carion committed
157
    auto *stylesGroup = new QActionGroup(stylesAction);
158

159 160
    // GTK theme does not work well with Kdenlive, and does not support color theming, so avoid it
    QStringList availableStyles = QStyleFactory::keys();
161 162
    if (KdenliveSettings::widgetstyle().isEmpty()) {
        // First run
163
        QStringList incompatibleStyles = {QStringLiteral("GTK+"), QStringLiteral("windowsvista"), QStringLiteral("Windows")};
164

165
        if (incompatibleStyles.contains(desktopStyle, Qt::CaseInsensitive)) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
166
            if (availableStyles.contains(QStringLiteral("breeze"), Qt::CaseInsensitive)) {
167 168
                // Auto switch to Breeze theme
                KdenliveSettings::setWidgetstyle(QStringLiteral("Breeze"));
169
		QApplication::setStyle(QStyleFactory::create(QStringLiteral("Breeze")));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
170
            } else if (availableStyles.contains(QStringLiteral("fusion"), Qt::CaseInsensitive)) {
171
                KdenliveSettings::setWidgetstyle(QStringLiteral("Fusion"));
172
		QApplication::setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
173
            }
174 175
        } else {
            KdenliveSettings::setWidgetstyle(QStringLiteral("Default"));
176 177 178
        }
    }

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
179 180
    // Add default style action
    QAction *defaultStyle = new QAction(i18n("Default"), stylesGroup);
181
    defaultStyle->setData(QStringLiteral("Default"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
182 183
    defaultStyle->setCheckable(true);
    stylesAction->addAction(defaultStyle);
184
    if (KdenliveSettings::widgetstyle() == QLatin1String("Default") || KdenliveSettings::widgetstyle().isEmpty()) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
185 186 187
        defaultStyle->setChecked(true);
    }

Nicolas Carion's avatar
Nicolas Carion committed
188
    for (const QString &style : availableStyles) {
Nicolas Carion's avatar
Nicolas Carion committed
189
        auto *a = new QAction(style, stylesGroup);
190 191
        a->setCheckable(true);
        a->setData(style);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
192 193 194
        if (KdenliveSettings::widgetstyle() == style) {
            a->setChecked(true);
        }
195 196 197
        stylesAction->addAction(a);
    }
    connect(stylesGroup, &QActionGroup::triggered, this, &MainWindow::slotChangeStyle);
Nicolas Carion's avatar
Nicolas Carion committed
198
    // QIcon::setThemeSearchPaths(QStringList() <<QStringLiteral(":/icons/"));
199 200

    new RenderingAdaptor(this);
201
    QString defaultProfile = KdenliveSettings::default_profile();
202
    pCore->setCurrentProfile(defaultProfile.isEmpty() ? ProjectManager::getDefaultProjectFormat() : defaultProfile);
203
    m_commandStack = new QUndoGroup();
204 205

    // If using a custom profile, make sure the file exists or fallback to default
206 207
    QString currentProfilePath = pCore->getCurrentProfile()->path();
    if (currentProfilePath.startsWith(QLatin1Char('/')) && !QFile::exists(currentProfilePath)) {
208
        KMessageBox::sorry(this, i18n("Cannot find your default profile, switching to ATSC 1080p 25"));
209
        pCore->setCurrentProfile(QStringLiteral("atsc_1080p_25"));
Laurent Montel's avatar
Laurent Montel committed
210
        KdenliveSettings::setDefault_profile(QStringLiteral("atsc_1080p_25"));
211
    }
212

213
    m_gpuAllowed = EffectsRepository::get()->hasInternalEffect(QStringLiteral("glsl.manager"));
214

215
    m_shortcutRemoveFocus = new QShortcut(QKeySequence(QStringLiteral("Esc")), this);
Laurent Montel's avatar
Laurent Montel committed
216
    connect(m_shortcutRemoveFocus, &QShortcut::activated, this, &MainWindow::slotRemoveFocus);
Simon Eugster's avatar
Simon Eugster committed
217

218
    /// Add Widgets
219
    setDockOptions(dockOptions() | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks);
220
    setDockOptions(dockOptions() | QMainWindow::GroupedDragging);
Nicolas Carion's avatar
Nicolas Carion committed
221
    setTabPosition(Qt::AllDockWidgetAreas, (QTabWidget::TabPosition)KdenliveSettings::tabposition());
222
    m_timelineToolBar = toolBar(QStringLiteral("timelineToolBar"));
223
    m_timelineToolBarContainer = new TimelineContainer(this);
Nicolas Carion's avatar
Nicolas Carion committed
224
    auto *ctnLay = new QVBoxLayout;
225 226
    ctnLay->setSpacing(0);
    ctnLay->setContentsMargins(0, 0, 0, 0);
227 228
    m_timelineToolBarContainer->setLayout(ctnLay);
    ctnLay->addWidget(m_timelineToolBar);
229 230 231 232
    KSharedConfigPtr config = KSharedConfig::openConfig();
    KConfigGroup mainConfig(config, QStringLiteral("MainWindow"));
    KConfigGroup tbGroup(&mainConfig, QStringLiteral("Toolbar timelineToolBar"));
    m_timelineToolBar->applySettings(tbGroup);
233 234 235 236 237
    QFrame *fr = new QFrame(this);
    fr->setFrameShape(QFrame::HLine);
    fr->setMaximumHeight(1);
    fr->setLineWidth(1);
    ctnLay->addWidget(fr);
238
    setupActions();
239

Laurent Montel's avatar
Laurent Montel committed
240
    QDockWidget *libraryDock = addDock(i18n("Library"), QStringLiteral("library"), pCore->library());
Simon Eugster's avatar
Simon Eugster committed
241

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
242
    m_clipMonitor = new Monitor(Kdenlive::ClipMonitor, pCore->monitorManager(), this);
243
    pCore->bin()->setMonitor(m_clipMonitor);
244 245
    connect(m_clipMonitor, &Monitor::addMarker, this, &MainWindow::slotAddMarkerGuideQuickly);
    connect(m_clipMonitor, &Monitor::deleteMarker, this, &MainWindow::slotDeleteClipMarker);
246 247
    connect(m_clipMonitor, &Monitor::seekToPreviousSnap, this, &MainWindow::slotSnapRewind);
    connect(m_clipMonitor, &Monitor::seekToNextSnap, this, &MainWindow::slotSnapForward);
248

249
    connect(pCore->bin(), &Bin::findInTimeline, this, &MainWindow::slotClipInTimeline, Qt::DirectConnection);
250 251
    connect(pCore->bin(), &Bin::setupTargets, this, [&] (bool hasVideo, QList <int> audioStreams) {
            getCurrentTimeline()->controller()->setTargetTracks(hasVideo, audioStreams);
252 253
        }
    );
254

Nicolas Carion's avatar
Nicolas Carion committed
255
    // TODO deprecated, replace with Bin methods if necessary
256
    /*connect(m_projectList, SIGNAL(loadingIsOver()), this, SLOT(slotElapsedTime()));
257
    connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
Laurent Montel's avatar
Laurent Montel committed
258
    connect(m_projectList, SIGNAL(updateProfile(QString)), this, SLOT(slotUpdateProjectProfile(QString)));
259
    connect(m_projectList, SIGNAL(refreshClip(QString,bool)), pCore->monitorManager(), SLOT(slotRefreshCurrentMonitor(QString)));
260
    connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));*/
261

Laurent Montel's avatar
Laurent Montel committed
262
    connect(m_clipMonitor, &Monitor::passKeyPress, this, &MainWindow::triggerKey);
263

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
264
    m_projectMonitor = new Monitor(Kdenlive::ProjectMonitor, pCore->monitorManager(), this);
Laurent Montel's avatar
Laurent Montel committed
265
    connect(m_projectMonitor, &Monitor::passKeyPress, this, &MainWindow::triggerKey);
266
    connect(m_projectMonitor, &Monitor::addMarker, this, &MainWindow::slotAddMarkerGuideQuickly);
267
    connect(m_projectMonitor, &Monitor::deleteMarker, this, &MainWindow::slotDeleteGuide);
268 269
    connect(m_projectMonitor, &Monitor::seekToPreviousSnap, this, &MainWindow::slotSnapRewind);
    connect(m_projectMonitor, &Monitor::seekToNextSnap, this, &MainWindow::slotSnapForward);
270
    connect(m_loopClip, &QAction::triggered, m_projectMonitor, &Monitor::slotLoopClip);
271

272
    pCore->monitorManager()->initMonitors(m_clipMonitor, m_projectMonitor);
273
    connect(m_clipMonitor, &Monitor::addMasterEffect, pCore->bin(), &Bin::slotAddEffect);
274

275 276
    m_timelineTabs = new TimelineTabs(this);
    ctnLay->addWidget(m_timelineTabs);
277
    setCentralWidget(m_timelineToolBarContainer);
278

279 280 281 282 283 284 285
    // Screen grab widget
    QWidget *grabWidget = new QWidget(this);
    QVBoxLayout *grabLayout = new QVBoxLayout;
    grabWidget->setLayout(grabLayout);
    QToolBar *recToolbar = new QToolBar(grabWidget);
    grabLayout->addWidget(recToolbar);
    grabLayout->addStretch(10);
286
    // Check number of monitors for FFmpeg screen capture
Vincent Pinon's avatar
Vincent Pinon committed
287
    int screens = QApplication::screens().count();
288 289 290 291 292 293 294 295 296 297
    if (screens > 1) {
        QComboBox *screenCombo = new QComboBox(recToolbar);
        for (int ix = 0; ix < screens; ix++) {
            screenCombo->addItem(i18n("Monitor %1", ix));
        }
        connect(screenCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), m_clipMonitor, &Monitor::slotSetScreen);
        recToolbar->addWidget(screenCombo);
        // Update screen grab monitor choice in case we changed from fullscreen
        screenCombo->setEnabled(KdenliveSettings::grab_capture_type() == 0);
    }
298 299 300 301 302 303 304 305 306
    QAction *recAction = m_clipMonitor->recAction();
    addAction(QStringLiteral("screengrab_record"), recAction);
    recToolbar->addAction(recAction);
    QAction *recConfig = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure Recording"), this);
    recToolbar->addAction(recConfig);
    connect(recConfig, &QAction::triggered, [&]() {
        pCore->showConfigDialog(4, 0);
    });
    QDockWidget *screenGrabDock = addDock(i18n("Screen Grab"), QStringLiteral("screengrab"), grabWidget);
307

308 309
    // Audio spectrum scope
    m_audioSpectrum = new AudioGraphSpectrum(pCore->monitorManager());
Laurent Montel's avatar
Laurent Montel committed
310
    QDockWidget *spectrumDock = addDock(i18n("Audio Spectrum"), QStringLiteral("audiospectrum"), m_audioSpectrum);
311
    // Close library and audiospectrum on first run
312
    screenGrabDock->close();
313 314 315
    libraryDock->close();
    spectrumDock->close();

316
    m_projectBinDock = addDock(i18n("Project Bin"), QStringLiteral("project_bin"), pCore->bin());
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
317

318
    m_assetPanel = new AssetPanel(this);
319
    m_effectStackDock = addDock(i18n("Properties"), QStringLiteral("effect_stack"), m_assetPanel);
320 321
    connect(m_assetPanel, &AssetPanel::doSplitEffect, m_projectMonitor, &Monitor::slotSwitchCompare);
    connect(m_assetPanel, &AssetPanel::doSplitBinEffect, m_clipMonitor, &Monitor::slotSwitchCompare);
322 323 324 325
    connect(m_assetPanel, &AssetPanel::switchCurrentComposition, [&](int cid, const QString &compositionId) {
        getMainTimeline()->controller()->getModel()->switchComposition(cid, compositionId);
    });

326
    connect(m_timelineTabs, &TimelineTabs::showTransitionModel, m_assetPanel, &AssetPanel::showTransition);
327 328 329
    connect(m_timelineTabs, &TimelineTabs::showTransitionModel, [&] () {
        m_effectStackDock->raise();
    });
330
    connect(m_timelineTabs, &TimelineTabs::showItemEffectStack, m_assetPanel, &AssetPanel::showEffectStack);
331 332 333 334
    connect(m_timelineTabs, &TimelineTabs::showItemEffectStack, [&] () {
        m_effectStackDock->raise();
    });

335
    connect(m_timelineTabs, &TimelineTabs::updateZoom, this, &MainWindow::updateZoomSlider);
336
    connect(pCore->bin(), &Bin::requestShowEffectStack, m_assetPanel, &AssetPanel::showEffectStack);
337
    connect(pCore->bin(), &Bin::requestShowEffectStack, [&] () {
338 339
        // Don't raise effect stack on clip bin in case it is docked with bin or clip monitor
        // m_effectStackDock->raise();
340
    });
341
    connect(this, &MainWindow::clearAssetPanel, m_assetPanel, &AssetPanel::clearAssetPanel);
342
    connect(this, &MainWindow::assetPanelWarning, m_assetPanel, &AssetPanel::assetPanelWarning);
343 344 345
    connect(m_assetPanel, &AssetPanel::seekToPos, [this](int pos) {
        ObjectId oId = m_assetPanel->effectStackOwner();
        switch (oId.first) {
Nicolas Carion's avatar
Nicolas Carion committed
346 347 348
        case ObjectType::TimelineTrack:
        case ObjectType::TimelineClip:
        case ObjectType::TimelineComposition:
349
        case ObjectType::Master:
350
            m_projectMonitor->requestSeek(pos);
Nicolas Carion's avatar
Nicolas Carion committed
351 352 353 354 355 356 357
            break;
        case ObjectType::BinClip:
            m_clipMonitor->requestSeek(pos);
            break;
        default:
            qDebug() << "ERROR unhandled object type";
            break;
358 359
        }
    });
360

361 362
    m_effectList2 = new EffectListWidget(this);
    connect(m_effectList2, &EffectListWidget::activateAsset, pCore->projectManager(), &ProjectManager::activateAsset);
363
    connect(m_assetPanel, &AssetPanel::reloadEffect, m_effectList2, &EffectListWidget::reloadCustomEffect);
364
    m_effectListDock = addDock(i18n("Effects"), QStringLiteral("effect_list"), m_effectList2);
Simon Eugster's avatar
Simon Eugster committed
365

366
    m_transitionList2 = new TransitionListWidget(this);
367
    m_transitionListDock = addDock(i18n("Compositions"), QStringLiteral("transition_list"), m_transitionList2);
368

Simon Eugster's avatar
Simon Eugster committed
369
    // Add monitors here to keep them at the right of the window
370 371
    m_clipMonitorDock = addDock(i18n("Clip Monitor"), QStringLiteral("clip_monitor"), m_clipMonitor);
    m_projectMonitorDock = addDock(i18n("Project Monitor"), QStringLiteral("project_monitor"), m_projectMonitor);
Simon Eugster's avatar
Simon Eugster committed
372

373
    m_undoView = new QUndoView();
374
    m_undoView->setCleanIcon(QIcon::fromTheme(QStringLiteral("edit-clear")));
375 376
    m_undoView->setEmptyLabel(i18n("Clean"));
    m_undoView->setGroup(m_commandStack);
377
    m_undoViewDock = addDock(i18n("Undo History"), QStringLiteral("undo_history"), m_undoView);
378

379
    // Color and icon theme stuff
Laurent Montel's avatar
Laurent Montel committed
380
    connect(m_commandStack, &QUndoGroup::cleanChanged, m_saveAction, &QAction::setDisabled);
381
    addAction(QStringLiteral("styles_menu"), stylesAction);
Simon Eugster's avatar
Simon Eugster committed
382

383 384 385 386 387
    QAction *iconAction = new QAction(i18n("Force Breeze Icon Theme"), this);
    iconAction->setCheckable(true);
    iconAction->setChecked(KdenliveSettings::force_breeze());
    addAction(QStringLiteral("force_icon_theme"), iconAction);
    connect(iconAction, &QAction::triggered, this, &MainWindow::forceIconSet);
388

389
    QDockWidget *mixerDock = addDock(i18n("Audio Mixer"), QStringLiteral("mixer"), pCore->mixer());
390
    QAction *showMixer = new QAction(QIcon::fromTheme(QStringLiteral("view-media-equalizer")), i18n("Audio Mixer"), this);
391 392 393 394 395 396 397
    showMixer->setCheckable(true);
    addAction(QStringLiteral("audiomixer_button"), showMixer);
    connect(mixerDock, &QDockWidget::visibilityChanged, [&, showMixer](bool visible) {
        pCore->mixer()->connectMixer(visible);
        showMixer->setChecked(visible);
    });
    connect(showMixer, &QAction::triggered, [&, mixerDock]() {
398
        if (mixerDock->isVisible() && !mixerDock->visibleRegion().isEmpty()) {
399 400 401
            mixerDock->close();
        } else {
            mixerDock->show();
402
            mixerDock->raise();
403 404 405
        }
    });

Simon Eugster's avatar
Simon Eugster committed
406 407 408
    // Close non-general docks for the initial layout
    // only show important ones
    m_undoViewDock->close();
409
    mixerDock->close();
Simon Eugster's avatar
Simon Eugster committed
410

411
    /// Tabify Widgets
412
    tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
413
    tabifyDockWidget(m_transitionListDock, m_effectListDock);
414
    tabifyDockWidget(m_effectStackDock, pCore->bin()->clipPropertiesDock());
415
    bool firstRun = readOptions();
Simon Eugster's avatar
Simon Eugster committed
416

417
    // Build effects menu
418
    m_effectsMenu = new QMenu(i18n("Add Effect"), this);
419
    m_effectActions = new KActionCategory(i18n("Effects"), actionCollection());
420
    m_effectList2->reloadEffectMenu(m_effectsMenu, m_effectActions);
421

422 423 424
    m_transitionsMenu = new QMenu(i18n("Add Transition"), this);
    m_transitionActions = new KActionCategory(i18n("Transitions"), actionCollection());

Nicolas Carion's avatar
Nicolas Carion committed
425
    auto *scmanager = new ScopeManager(this);
426

Till Theato's avatar
Till Theato committed
427
    new LayoutManagement(this);
428
    new HideTitleBars(this);
429 430
    m_extraFactory = new KXMLGUIClient(this);
    buildDynamicActions();
431

432
    // Create Effect Basket (dropdown list of favorites)
433 434
    m_effectBasket = new EffectBasket(this);
    connect(m_effectBasket, &EffectBasket::activateAsset, pCore->projectManager(), &ProjectManager::activateAsset);
435
    connect(m_effectList2, &EffectListWidget::reloadFavorites, m_effectBasket, &EffectBasket::slotReloadBasket);
Nicolas Carion's avatar
Nicolas Carion committed
436
    auto *widgetlist = new QWidgetAction(this);
437
    widgetlist->setDefaultWidget(m_effectBasket);
Nicolas Carion's avatar
Nicolas Carion committed
438
    // widgetlist->setText(i18n("Favorite Effects"));
439
    widgetlist->setToolTip(i18n("Favorite Effects"));
440
    widgetlist->setIcon(QIcon::fromTheme(QStringLiteral("favorite")));
Nicolas Carion's avatar
Nicolas Carion committed
441
    auto *menu = new QMenu(this);
442 443
    menu->addAction(widgetlist);

Nicolas Carion's avatar
Nicolas Carion committed
444
    auto *basketButton = new QToolButton(this);
445
    basketButton->setMenu(menu);
446
    basketButton->setToolButtonStyle(toolBar()->toolButtonStyle());
447 448
    basketButton->setDefaultAction(widgetlist);
    basketButton->setPopupMode(QToolButton::InstantPopup);
Nicolas Carion's avatar
Nicolas Carion committed
449
    // basketButton->setText(i18n("Favorite Effects"));
450
    basketButton->setToolTip(i18n("Favorite Effects"));
451
    basketButton->setIcon(QIcon::fromTheme(QStringLiteral("favorite")));
452

Nicolas Carion's avatar
Nicolas Carion committed
453
    auto *toolButtonAction = new QWidgetAction(this);
454
    toolButtonAction->setText(i18n("Favorite Effects"));
455
    toolButtonAction->setIcon(QIcon::fromTheme(QStringLiteral("favorite")));
456
    toolButtonAction->setDefaultWidget(basketButton);
457
    addAction(QStringLiteral("favorite_effects"), toolButtonAction);
Laurent Montel's avatar
Laurent Montel committed
458
    connect(toolButtonAction, &QAction::triggered, basketButton, &QToolButton::showMenu);
459
    connect(m_effectBasket, &EffectBasket::activateAsset, menu, &QMenu::close);
460

461 462
    // Render button
    ProgressButton *timelineRender = new ProgressButton(i18n("Render"), 100, this);
Nicolas Carion's avatar
Nicolas Carion committed
463
    auto *tlrMenu = new QMenu(this);
464 465
    timelineRender->setMenu(tlrMenu);
    connect(this, &MainWindow::setRenderProgress, timelineRender, &ProgressButton::setProgress);
Nicolas Carion's avatar
Nicolas Carion committed
466
    auto *renderButtonAction = new QWidgetAction(this);
467
    renderButtonAction->setText(i18n("Render Button"));
468
    renderButtonAction->setIcon(QIcon::fromTheme(QStringLiteral("media-record")));
469 470 471
    renderButtonAction->setDefaultWidget(timelineRender);
    addAction(QStringLiteral("project_render_button"), renderButtonAction);

472
    // Timeline preview button
473
    ProgressButton *timelinePreview = new ProgressButton(i18n("Rendering preview"), 1000, this);
Nicolas Carion's avatar
Nicolas Carion committed
474
    auto *tlMenu = new QMenu(this);
475
    timelinePreview->setMenu(tlMenu);
476
    connect(this, &MainWindow::setPreviewProgress, timelinePreview, &ProgressButton::setProgress);
Nicolas Carion's avatar
Nicolas Carion committed
477
    auto *previewButtonAction = new QWidgetAction(this);
478
    previewButtonAction->setText(i18n("Timeline Preview"));
479
    previewButtonAction->setIcon(QIcon::fromTheme(QStringLiteral("preview-render-on")));
480
    previewButtonAction->setDefaultWidget(timelinePreview);
481
    addAction(QStringLiteral("timeline_preview_button"), previewButtonAction);
482

483
    setupGUI(KXmlGuiWindow::ToolBar | KXmlGuiWindow::StatusBar | KXmlGuiWindow::Save | KXmlGuiWindow::Create);
484
    if (firstRun) {
485
        if (QScreen *current = QApplication::primaryScreen()) {
486 487 488 489 490 491 492
            if (current->availableSize().height() < 1000) {
                resize(current->availableSize());
            } else {
                resize(current->availableSize() / 1.5);
            }
        }
    }
493 494 495
    updateActionsToolTip();
    m_timelineToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
    m_timelineToolBar->setProperty("otherToolbar", true);
496 497
    timelinePreview->setToolButtonStyle(m_timelineToolBar->toolButtonStyle());
    connect(m_timelineToolBar, &QToolBar::toolButtonStyleChanged, timelinePreview, &ProgressButton::setToolButtonStyle);
498

499
    timelineRender->setToolButtonStyle(toolBar()->toolButtonStyle());
500 501
    /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
    guiFactory()->addClient(sp);*/
502

503
    loadGenerators();
504
    loadDockActions();
505
    loadClipActions();
506 507 508 509 510 511 512 513 514 515 516
    QMenu *openGLMenu = static_cast<QMenu *>(factory()->container(QStringLiteral("qt_opengl"), this));
#if defined(Q_OS_WIN)
    connect(openGLMenu, &QMenu::triggered, [&](QAction *ac) {
        KdenliveSettings::setOpengl_backend(ac->data().toInt());
        if (KMessageBox::questionYesNo(this, i18n("Kdenlive needs to be restarted to change this setting. Do you want to proceed?")) != KMessageBox::Yes) {
            return;
        }
        slotRestart(false);
    });
#else
    if (openGLMenu) {
517
        openGLMenu->menuAction()->setVisible(false);;
518 519
    }
#endif
520
    // Connect monitor overlay info menu.
Laurent Montel's avatar
Laurent Montel committed
521
    QMenu *monitorOverlay = static_cast<QMenu *>(factory()->container(QStringLiteral("monitor_config_overlay"), this));
Laurent Montel's avatar
Laurent Montel committed
522
    connect(monitorOverlay, &QMenu::triggered, this, &MainWindow::slotSwitchMonitorOverlay);
523

Nicolas Carion's avatar
Nicolas Carion committed
524 525 526 527
    m_projectMonitor->setupMenu(static_cast<QMenu *>(factory()->container(QStringLiteral("monitor_go"), this)), monitorOverlay, m_playZone, m_loopZone, nullptr,
                                m_loopClip);
    m_clipMonitor->setupMenu(static_cast<QMenu *>(factory()->container(QStringLiteral("monitor_go"), this)), monitorOverlay, m_playZone, m_loopZone,
                             static_cast<QMenu *>(factory()->container(QStringLiteral("marker_menu"), this)));
528

Laurent Montel's avatar
Laurent Montel committed
529
    QMenu *clipInTimeline = static_cast<QMenu *>(factory()->container(QStringLiteral("clip_in_timeline"), this));
530
    clipInTimeline->setIcon(QIcon::fromTheme(QStringLiteral("go-jump")));
531
    pCore->bin()->setupGeneratorMenu();
Marco Gittler's avatar
Marco Gittler committed
532

Laurent Montel's avatar
Laurent Montel committed
533
    connect(pCore->monitorManager(), &MonitorManager::updateOverlayInfos, this, &MainWindow::slotUpdateMonitorOverlays);
534

535
    // Setup and fill effects and transitions menus.
Laurent Montel's avatar
Laurent Montel committed
536
    QMenu *m = static_cast<QMenu *>(factory()->container(QStringLiteral("video_effects_menu"), this));
537 538
    connect(m, &QMenu::triggered, this, &MainWindow::slotAddEffect);
    connect(m_effectsMenu, &QMenu::triggered, this, &MainWindow::slotAddEffect);
Laurent Montel's avatar
Laurent Montel committed
539
    connect(m_transitionsMenu, &QMenu::triggered, this, &MainWindow::slotAddTransition);
540

541 542
    m_timelineContextMenu = new QMenu(this);

543 544
    m_timelineContextMenu->addAction(actionCollection()->action(QStringLiteral("insert_space")));
    m_timelineContextMenu->addAction(actionCollection()->action(QStringLiteral("delete_space")));
545
    m_timelineContextMenu->addAction(actionCollection()->action(QStringLiteral("delete_space_all_tracks")));
546 547
    m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));

548
    // QMenu *markersMenu = static_cast<QMenu *>(factory()->container(QStringLiteral("marker_menu"), this));
549 550 551 552 553

    /*m_timelineClipActions->addMenu(markersMenu);
    m_timelineClipActions->addSeparator();
    m_timelineClipActions->addMenu(m_transitionsMenu);
    m_timelineClipActions->addMenu(m_effectsMenu);*/
Marco Gittler's avatar
Marco Gittler committed
554

555
    slotConnectMonitors();
556

557
    m_timelineToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
558
    // TODO: let user select timeline toolbar toolbutton style
Nicolas Carion's avatar
Nicolas Carion committed
559
    // connect(toolBar(), &QToolBar::iconSizeChanged, m_timelineToolBar, &QToolBar::setToolButtonStyle);
560 561
    m_timelineToolBar->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(m_timelineToolBar, &QWidget::customContextMenuRequested, this, &MainWindow::showTimelineToolbarMenu);
562 563

    QAction *prevRender = actionCollection()->action(QStringLiteral("prerender_timeline_zone"));
564 565
    QAction *stopPrevRender = actionCollection()->action(QStringLiteral("stop_prerender_timeline"));
    tlMenu->addAction(stopPrevRender);
566 567
    tlMenu->addAction(actionCollection()->action(QStringLiteral("set_render_timeline_zone")));
    tlMenu->addAction(actionCollection()->action(QStringLiteral("unset_render_timeline_zone")));
568
    tlMenu->addAction(actionCollection()->action(QStringLiteral("clear_render_timeline_zone")));
569 570

    // Automatic timeline preview action
571
    QAction *autoRender = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), i18n("Automatic Preview"), this);
572 573 574 575
    autoRender->setCheckable(true);
    autoRender->setChecked(KdenliveSettings::autopreview());
    connect(autoRender, &QAction::triggered, this, &MainWindow::slotToggleAutoPreview);
    tlMenu->addAction(autoRender);
576
    tlMenu->addSeparator();
577
    tlMenu->addAction(actionCollection()->action(QStringLiteral("disable_preview")));
578
    tlMenu->addAction(actionCollection()->action(QStringLiteral("manage_cache")));
579
    timelinePreview->defineDefaultAction(prevRender, stopPrevRender);
580
    timelinePreview->setAutoRaise(true);
581

582 583
    QAction *showRender = actionCollection()->action(QStringLiteral("project_render"));
    tlrMenu->addAction(showRender);
584
    tlrMenu->addAction(actionCollection()->action(QStringLiteral("stop_project_render")));
585
    timelineRender->defineDefaultAction(showRender, showRender);
586 587
    timelineRender->setAutoRaise(true);

588
    // Populate encoding profiles
589
    KConfig conf(QStringLiteral("encodingprofiles.rc"), KConfig::CascadeConfig, QStandardPaths::AppDataLocation);
590
    /*KConfig conf(QStringLiteral("encodingprofiles.rc"), KConfig::CascadeConfig, QStandardPaths::AppDataLocation);
591
    if (KdenliveSettings::proxyparams().isEmpty() || KdenliveSettings::proxyextension().isEmpty()) {
592
        KConfigGroup group(&conf, "proxy");
Nicolas Carion's avatar
Nicolas Carion committed
593
        QMap<QString, QString> values = group.entryMap();
594 595 596
        QMapIterator<QString, QString> i(values);
        if (i.hasNext()) {
            i.next();
597 598 599
            QString proxystring = i.value();
            KdenliveSettings::setProxyparams(proxystring.section(QLatin1Char(';'), 0, 0));
            KdenliveSettings::setProxyextension(proxystring.section(QLatin1Char(';'), 1, 1));
600
        }
601
    }*/
602
    if (KdenliveSettings::v4l_parameters().isEmpty() || KdenliveSettings::v4l_extension().isEmpty()) {
603
        KConfigGroup group(&conf, "video4linux");
Nicolas Carion's avatar
Nicolas Carion committed
604
        QMap<QString, QString> values = group.entryMap();
605 606 607
        QMapIterator<QString, QString> i(values);
        if (i.hasNext()) {
            i.next();
608 609 610
            QString v4lstring = i.value();
            KdenliveSettings::setV4l_parameters(v4lstring.section(QLatin1Char(';'), 0, 0));
            KdenliveSettings::setV4l_extension(v4lstring.section(QLatin1Char(';'), 1, 1));
611 612
        }
    }
613 614
    if (KdenliveSettings::grab_parameters().isEmpty() || KdenliveSettings::grab_extension().isEmpty()) {
        KConfigGroup group(&conf, "screengrab");
Nicolas Carion's avatar
Nicolas Carion committed
615
        QMap<QString, QString> values = group.entryMap();
616 617 618
        QMapIterator<QString, QString> i(values);
        if (i.hasNext()) {
            i.next();
619 620 621
            QString grabstring = i.value();
            KdenliveSettings::setGrab_parameters(grabstring.section(QLatin1Char(';'), 0, 0));
            KdenliveSettings::setGrab_extension(grabstring.section(QLatin1Char(';'), 1, 1));
622 623
        }
    }
624
    if (KdenliveSettings::decklink_parameters().isEmpty() || KdenliveSettings::decklink_extension().isEmpty()) {
625
        KConfigGroup group(&conf, "decklink");
Nicolas Carion's avatar
Nicolas Carion committed
626
        QMap<QString, QString> values = group.entryMap();
627 628 629
        QMapIterator<QString, QString> i(values);
        if (i.hasNext()) {
            i.next();
630 631 632
            QString decklinkstring = i.value();
            KdenliveSettings::setDecklink_parameters(decklinkstring.section(QLatin1Char(';'), 0, 0));
            KdenliveSettings::setDecklink_extension(decklinkstring.section(QLatin1Char(';'), 1, 1));
633 634
        }
    }
Vincent Pinon's avatar
Vincent Pinon committed
635 636 637
    if (!QDir(KdenliveSettings::currenttmpfolder()).isReadable())
        KdenliveSettings::setCurrenttmpfolder(QStandardPaths::writableLocation(QStandardPaths::TempLocation));

Laurent Montel's avatar
Laurent Montel committed
638
    QTimer::singleShot(0, this, &MainWindow::GUISetupDone);
639

640 641 642
#ifdef USE_JOGSHUTTLE
    new JogManager(this);
#endif
643
    scmanager->slotCheckActiveScopes();
Nicolas Carion's avatar
format  
Nicolas Carion committed
644
    // m_messageLabel->setMessage(QStringLiteral("This is a beta version. Always backup your data"), MltError);
645
}
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
646

647
void MainWindow::slotThemeChanged(const QString &name)
648
{
649
    KSharedConfigPtr config = KSharedConfig::openConfig(name);
650
    QPalette plt = KColorScheme::createApplicationPalette(config);
651
    // qApp->setPalette(plt);
652
    // Required for qml palette change
653
    QGuiApplication::setPalette(plt);