]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
Select / unselect clips in timeline with shortcuts (using +, -, and ALT / SHIFT to...
[kdenlive] / src / mainwindow.cpp
index b04f722c2c16d3c5749c264efc41a7c623d9ce0c..91bb142572a8e9582ee6726723ede0560e71fe12 100644 (file)
@@ -82,6 +82,7 @@
 #include <knewstuff2/engine.h>
 #include <knewstuff2/ui/knewstuffaction.h>
 #include <KToolBar>
+#include <KColorScheme>
 
 #include <QTextStream>
 #include <QTimer>
@@ -89,6 +90,7 @@
 #include <QKeyEvent>
 #include <QInputDialog>
 #include <QDesktopWidget>
+#include <QBitmap>
 
 #include <stdlib.h>
 
@@ -260,17 +262,44 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent
     action->setCheckable(true);
     themegroup->addAction(action);
     if (KdenliveSettings::colortheme().isEmpty()) action->setChecked(true);
-    KGlobal::dirs()->addResourceDir("themes", KStandardDirs::installPath("data") + QString("kdenlive/themes"));
+
+
+    const QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*.colors", KStandardDirs::NoDuplicates);
+
+    for (int i = 0; i < schemeFiles.size(); ++i) {
+        // get the file name
+        const QString filename = schemeFiles.at(i);
+        const QFileInfo info(filename);
+
+        // add the entry
+        KSharedConfigPtr config = KSharedConfig::openConfig(filename);
+        QIcon icon = createSchemePreviewIcon(config);
+        KConfigGroup group(config, "General");
+        const QString name = group.readEntry("Name", info.baseName());
+        action = new QAction(name, this);
+        action->setData(filename);
+        action->setIcon(icon);
+        action->setCheckable(true);
+        themegroup->addAction(action);
+        if (KdenliveSettings::colortheme() == filename) action->setChecked(true);
+    }
+
+
+
+
+
+
+    /*KGlobal::dirs()->addResourceDir("themes", KStandardDirs::installPath("data") + QString("kdenlive/themes"));
     QStringList themes = KGlobal::dirs()->findAllResources("themes", QString(), KStandardDirs::Recursive | KStandardDirs::NoDuplicates);
     for (QStringList::const_iterator it = themes.constBegin(); it != themes.constEnd(); ++it)
     {
-       QFileInfo fi(*it);
+    QFileInfo fi(*it);
         action = new QAction(fi.fileName(), this);
         action->setData(*it);
-       action->setCheckable(true);
-       themegroup->addAction(action);
-       if (KdenliveSettings::colortheme() == *it) action->setChecked(true);
-    }
+    action->setCheckable(true);
+    themegroup->addAction(action);
+    if (KdenliveSettings::colortheme() == *it) action->setChecked(true);
+    }*/
     themesMenu->addActions(themegroup->actions());
     connect(themesMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotChangePalette(QAction*)));
 
@@ -908,12 +937,12 @@ void MainWindow::setupActions()
     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
 
     KAction *markIn = collection->addAction("mark_in");
-    markIn->setText(i18n("Set In Point"));
+    markIn->setText(i18n("Set Zone In"));
     markIn->setShortcut(Qt::Key_I);
     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
 
     KAction *markOut = collection->addAction("mark_out");
-    markOut->setText(i18n("Set Out Point"));
+    markOut->setText(i18n("Set Zone Out"));
     markOut->setShortcut(Qt::Key_O);
     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
 
@@ -952,6 +981,16 @@ void MainWindow::setupActions()
     collection->addAction("seek_clip_end", clipEnd);
     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
 
+    KAction* zoneStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Zone Start"), this);
+    zoneStart->setShortcut(Qt::SHIFT + Qt::Key_I);
+    collection->addAction("seek_zone_start", zoneStart);
+    connect(zoneStart, SIGNAL(triggered(bool)), this, SLOT(slotZoneStart()));
+
+    KAction* zoneEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Zone End"), this);
+    zoneEnd->setShortcut(Qt::SHIFT + Qt::Key_O);
+    collection->addAction("seek_zone_end", zoneEnd);
+    connect(zoneEnd, SIGNAL(triggered(bool)), this, SLOT(slotZoneEnd()));
+
     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
     collection->addAction("seek_start", projectStart);
@@ -1005,6 +1044,36 @@ void MainWindow::setupActions()
     ungroupClip->setData("ungroup_clip");
     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
 
+    KAction* selectTimelineClip = new KAction(KIcon("edit-select"), i18n("Select Clip"), this);
+    selectTimelineClip->setShortcut(Qt::Key_Plus);
+    collection->addAction("select_timeline_clip", selectTimelineClip);
+    connect(selectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineClip()));
+
+    KAction* deselectTimelineClip = new KAction(KIcon("edit-select"), i18n("Deselect Clip"), this);
+    deselectTimelineClip->setShortcut(Qt::Key_Minus);
+    collection->addAction("deselect_timeline_clip", deselectTimelineClip);
+    connect(deselectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineClip()));
+
+    KAction* selectAddTimelineClip = new KAction(KIcon("edit-select"), i18n("Add Clip To Selection"), this);
+    selectAddTimelineClip->setShortcut(Qt::ALT + Qt::Key_Plus);
+    collection->addAction("select_add_timeline_clip", selectAddTimelineClip);
+    connect(selectAddTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineClip()));
+
+    KAction* selectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Select Transition"), this);
+    selectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Plus);
+    collection->addAction("select_timeline_transition", selectTimelineTransition);
+    connect(selectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineTransition()));
+
+    KAction* deselectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Deselect Transition"), this);
+    deselectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Minus);
+    collection->addAction("deselect_timeline_transition", deselectTimelineTransition);
+    connect(deselectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineTransition()));
+
+    KAction* selectAddTimelineTransition = new KAction(KIcon("edit-select"), i18n("Add Transition To Selection"), this);
+    selectAddTimelineTransition->setShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
+    collection->addAction("select_add_timeline_transition", selectAddTimelineTransition);
+    connect(selectAddTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineTransition()));
+
     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
     collection->addAction("cut_timeline_clip", cutTimelineClip);
@@ -1651,13 +1720,9 @@ void MainWindow::slotDetectAudioDriver()
 void MainWindow::slotEditProjectSettings()
 {
     QPoint p = m_activeDocument->getTracksCount();
-    ProjectSettings *w = new ProjectSettings(m_activeDocument->clipManager(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
+    ProjectSettings *w = new ProjectSettings(m_projectList, p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
 
     if (w->exec() == QDialog::Accepted) {
-        if (w->deleteUnused()) {
-            // we are going to trash the unused clips
-            m_projectList->trashUnusedClips();
-        }
         QString profile = w->selectedProfile();
         m_activeDocument->setProjectFolder(w->selectedFolder());
         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path(KUrl::AddTrailingSlash));
@@ -2211,6 +2276,48 @@ void MainWindow::slotCutTimelineClip()
     }
 }
 
+void MainWindow::slotSelectTimelineClip()
+{
+    if (m_activeTimeline) {
+        m_activeTimeline->projectView()->selectClip(true);
+    }
+}
+
+void MainWindow::slotSelectTimelineTransition()
+{
+    if (m_activeTimeline) {
+        m_activeTimeline->projectView()->selectTransition(true);
+    }
+}
+
+void MainWindow::slotDeselectTimelineClip()
+{
+    if (m_activeTimeline) {
+        m_activeTimeline->projectView()->selectClip(false, true);
+    }
+}
+
+void MainWindow::slotDeselectTimelineTransition()
+{
+    if (m_activeTimeline) {
+        m_activeTimeline->projectView()->selectTransition(false, true);
+    }
+}
+
+void MainWindow::slotSelectAddTimelineClip()
+{
+    if (m_activeTimeline) {
+        m_activeTimeline->projectView()->selectClip(true, true);
+    }
+}
+
+void MainWindow::slotSelectAddTimelineTransition()
+{
+    if (m_activeTimeline) {
+        m_activeTimeline->projectView()->selectTransition(true, true);
+    }
+}
+
 void MainWindow::slotGroupClips()
 {
     if (m_activeTimeline) {
@@ -2443,6 +2550,18 @@ void MainWindow::slotClipEnd()
     }
 }
 
+void MainWindow::slotZoneStart()
+{
+    if (m_projectMonitor->isActive()) m_projectMonitor->slotZoneStart();
+    else m_clipMonitor->slotZoneStart();
+}
+
+void MainWindow::slotZoneEnd()
+{
+    if (m_projectMonitor->isActive()) m_projectMonitor->slotZoneEnd();
+    else m_clipMonitor->slotZoneEnd();
+}
+
 void MainWindow::slotChangeTool(QAction * action)
 {
     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
@@ -2622,14 +2741,16 @@ void MainWindow::slotSetInPoint()
 {
     if (m_clipMonitor->isActive()) {
         m_clipMonitor->slotSetZoneStart();
-    } else m_activeTimeline->projectView()->setInPoint();
+    } else m_projectMonitor->slotSetZoneStart();
+    //else m_activeTimeline->projectView()->setInPoint();
 }
 
 void MainWindow::slotSetOutPoint()
 {
     if (m_clipMonitor->isActive()) {
         m_clipMonitor->slotSetZoneEnd();
-    } else m_activeTimeline->projectView()->setOutPoint();
+    } else m_projectMonitor->slotSetZoneEnd();
+    // else m_activeTimeline->projectView()->setOutPoint();
 }
 
 void MainWindow::slotGetNewLumaStuff()
@@ -2938,74 +3059,64 @@ void MainWindow::slotChangePalette(QAction *action, const QString &themename)
     QPalette plt;
     if (theme.isEmpty())
         plt = QApplication::desktop()->palette();
-    else
-    {
-       KConfig confFile(theme, KConfig::SimpleConfig);
-        plt = kapp->palette();
-        int h, s, v;
-        const QColor fg(confFile.entryMap().value("TextRegularColor"));
-        const QColor bg(confFile.entryMap().value("BaseColor"));
-
-        bg.getHsv(&h, &s, &v);
-        v += (v < 128) ? +50 : -50;
-        v &= 255; //ensures 0 <= v < 256
-        const QColor highlight = QColor::fromHsv(h, s, v);
-
-        fg.getHsv(&h, &s, &v);
-        v += (v < 128) ? +150 : -150;
-        v &= 255; //ensures 0 <= v < 256
-        const QColor alternate = QColor::fromHsv(h, s, v);
-
-        plt.setColor(QPalette::Active,   QPalette::Base,            bg);
-       plt.setColor(QPalette::Active,   QPalette::AlternateBase,   alternate);
-        plt.setColor(QPalette::Active,   QPalette::Background,      bg.dark(115));
-        plt.setColor(QPalette::Active,   QPalette::Foreground,      confFile.entryMap().value("Foreground"));
-        plt.setColor(QPalette::Active,   QPalette::Highlight,       highlight);
-        plt.setColor(QPalette::Active,   QPalette::HighlightedText, confFile.entryMap().value("TextSelectedColor"));
-        plt.setColor(QPalette::Active,   QPalette::Dark,            Qt::darkGray);
-        plt.setColor(QPalette::Active,   QPalette::Button,          bg);
-        plt.setColor(QPalette::Active,   QPalette::ButtonText,      fg);
-        plt.setColor(QPalette::Active,   QPalette::Text,            fg);
-        plt.setColor(QPalette::Active,   QPalette::Link,            confFile.entryMap().value("TextSpecialRegularColor"));
-        plt.setColor(QPalette::Active,   QPalette::LinkVisited,     confFile.entryMap().value("TextSpecialSelectedColor"));
-       plt.setColor(QPalette::Active,   QPalette::Window,      confFile.entryMap().value("Window"));
-
-        plt.setColor(QPalette::Inactive, QPalette::Base,            bg);
-       plt.setColor(QPalette::Inactive,   QPalette::AlternateBase, alternate);
-       plt.setColor(QPalette::Inactive, QPalette::Background,      bg.dark(115));
-        plt.setColor(QPalette::Inactive, QPalette::Foreground,      fg);
-        plt.setColor(QPalette::Inactive, QPalette::Highlight,       highlight);
-        plt.setColor(QPalette::Inactive, QPalette::HighlightedText, confFile.entryMap().value("TextSelectedColor"));
-        plt.setColor(QPalette::Inactive, QPalette::Dark,            Qt::darkGray);
-        plt.setColor(QPalette::Inactive, QPalette::Button,          bg);
-        plt.setColor(QPalette::Inactive, QPalette::ButtonText,      fg);
-        plt.setColor(QPalette::Inactive, QPalette::Text,            fg);
-        plt.setColor(QPalette::Inactive, QPalette::Link,            confFile.entryMap().value("TextSpecialRegularColor"));
-        plt.setColor(QPalette::Inactive, QPalette::LinkVisited,     confFile.entryMap().value("TextSpecialSelectedColor"));
-       plt.setColor(QPalette::Inactive,   QPalette::Window,   confFile.entryMap().value("Window"));
-
-        plt.setColor(QPalette::Disabled, QPalette::Base,            bg);
-       plt.setColor(QPalette::Disabled,   QPalette::AlternateBase, alternate);
-        plt.setColor(QPalette::Disabled, QPalette::Background,      bg.dark(115));
-        plt.setColor(QPalette::Disabled, QPalette::Foreground,      fg);
-        plt.setColor(QPalette::Disabled, QPalette::Highlight,       highlight);
-        plt.setColor(QPalette::Disabled, QPalette::HighlightedText, confFile.entryMap().value("TextSelectedColor"));
-        plt.setColor(QPalette::Disabled, QPalette::Dark,            Qt::darkGray);
-        plt.setColor(QPalette::Disabled, QPalette::Button,          bg);
-        plt.setColor(QPalette::Disabled, QPalette::ButtonText,      fg);
-        plt.setColor(QPalette::Disabled, QPalette::Text,            fg);
-        plt.setColor(QPalette::Disabled, QPalette::Link,            confFile.entryMap().value("TextSpecialRegularColor"));
-        plt.setColor(QPalette::Disabled, QPalette::LinkVisited,     confFile.entryMap().value("TextSpecialSelectedColor"));
-
-        /*
-        cg.setColor(QColorGroup::Light,           ThemeEngine::instance()->textRegColor());
-        cg.setColor(QColorGroup::Midlight,        ThemeEngine::instance()->textRegColor());
-        cg.setColor(QColorGroup::Mid,             ThemeEngine::instance()->textRegColor());
-        cg.setColor(QColorGroup::Shadow,          ThemeEngine::instance()->textRegColor());
-        */
+    else {
+        KSharedConfigPtr config = KSharedConfig::openConfig(theme);
+        plt = KGlobalSettings::createApplicationPalette(config);
     }
 
     kapp->setPalette(plt);
+    const QObjectList children = statusBar()->children();
+
+    foreach(QObject *child, children) {
+        if (child->isWidgetType())
+            ((QWidget*)child)->setPalette(plt);
+        const QObjectList subchildren = child->children();
+        foreach(QObject *subchild, subchildren) {
+            if (subchild->isWidgetType())
+                ((QWidget*)subchild)->setPalette(plt);
+        }
+    }
+}
+
+
+QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
+{
+    // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
+    const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
+    const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
+    const QSize bitsSize(24, 2);
+    const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
+    const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
+
+    QPixmap pixmap(23, 16);
+    pixmap.fill(Qt::black); // ### use some color other than black for borders?
+
+    KConfigGroup group(config, "WM");
+    QPainter p(&pixmap);
+    KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
+    p.fillRect(1,  1, 7, 7, windowScheme.background());
+    p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
+
+    KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
+    p.fillRect(8,  1, 7, 7, buttonScheme.background());
+    p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
+
+    p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
+    p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
+
+    KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
+    p.fillRect(1,  8, 7, 7, viewScheme.background());
+    p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
+
+    KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
+    p.fillRect(8,  8, 7, 7, selectionScheme.background());
+    p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
+
+    p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
+    p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
+
+    p.end();
+    return pixmap;
 }