From f8cedebe2666681c596f9e35bd29445e98681158 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Fri, 28 Dec 2012 18:00:08 +0100 Subject: [PATCH] Fix View menu not updated when closing a dock: http://kdenlive.org/mantis/view.php?id=2907 --- src/kdenliveui.rc | 1 - src/mainwindow.cpp | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/kdenliveui.rc b/src/kdenliveui.rc index c5bb3d88..87aeff61 100644 --- a/src/kdenliveui.rc +++ b/src/kdenliveui.rc @@ -172,7 +172,6 @@ - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e3ece7e5..a3084394 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -142,6 +142,11 @@ EffectsList MainWindow::transitions; QMap MainWindow::m_lumacache; +static bool sortByNames(const QPair &a, const QPair &b) +{ + return a.first < b.first; +} + MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & clipsToLoad, QWidget *parent) : KXmlGuiWindow(parent), m_activeDocument(NULL), @@ -582,33 +587,41 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & actionCollection()->addAssociatedWidget(m_clipMonitor->container()); actionCollection()->addAssociatedWidget(m_projectMonitor->container()); - QMap viewActions; + QList > viewActions; + QPair pair; KAction *showTimeline = new KAction(i18n("Timeline"), this); showTimeline->setCheckable(true); showTimeline->setChecked(true); connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool))); - viewActions.insert(showTimeline->text(), showTimeline); + + KMenu *viewMenu = static_cast(factory()->container("dockwindows", this)); + pair.first = showTimeline->text(); + pair.second = showTimeline; + viewActions.append(pair); QList docks = findChildren(); for (int i = 0; i < docks.count(); i++) { QDockWidget* dock = docks.at(i); + QAction * a = dock->toggleViewAction(); + if (!a) continue; KAction* dockInformations = new KAction(this); - dockInformations->setText(dock->windowTitle()); + dockInformations->setText(a->text()); dockInformations->setCheckable(true); dockInformations->setChecked(!dock->isHidden()); - connect(dockInformations,SIGNAL(toggled(bool)), dock, SLOT(setVisible(bool))); - viewActions.insert(dockInformations->text(), dockInformations); - } - - - KMenu *viewMenu = static_cast(factory()->container("dockwindows", this)); - //const QList viewActions = createPopupMenu()->actions(); - QMap::const_iterator i = viewActions.constBegin(); - while (i != viewActions.constEnd()) { - viewMenu->addAction(guiActions->addAction(i.key(), i.value())); - ++i; + // HACK: since QActions cannot be used in KActionCategory to allow shortcut, we create a duplicate KAction of the dock QAction and link them + connect(a,SIGNAL(toggled(bool)), dockInformations, SLOT(setChecked(bool))); + connect(dockInformations,SIGNAL(triggered(bool)), a, SLOT(trigger())); + pair.first = dockInformations->text(); + pair.second = dockInformations; + viewActions.append(pair); } + // Sort dock view action by name + qSort(viewActions.begin(), viewActions.end(), sortByNames); + // Populate view menu + for (int i = 0; i < viewActions.count(); i++) + viewMenu->addAction(guiActions->addAction(viewActions.at(i).first, viewActions.at(i).second)); + // Populate encoding profiles KConfig conf("encodingprofiles.rc", KConfig::FullConfig, "appdata"); if (KdenliveSettings::proxyparams().isEmpty() || KdenliveSettings::proxyextension().isEmpty()) { -- 2.39.2