]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Prevent unwanted item animations (#2)
authorPeter Penz <peter.penz19@gmail.com>
Wed, 7 Dec 2011 22:46:35 +0000 (23:46 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 7 Dec 2011 22:49:58 +0000 (23:49 +0100)
Use a cleaner approach to prevent item animations when showing
a hidden tab the first time. For Dolphin > 2.0 the tab-code should
be refactored from DolphinMainWindow and encapsulated into an
own module (but well, this is on my TODO-list since KDE SC 4.4...)

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h

index 203d3249a7c4732663c4dc145adefc5c9b96c982..3f527d9a5c2b178a535738f6bbb90d63cb6f8106 100644 (file)
@@ -156,6 +156,8 @@ DolphinMainWindow::DolphinMainWindow() :
     setObjectName("Dolphin#");
 
     m_viewTab.append(ViewTab());
     setObjectName("Dolphin#");
 
     m_viewTab.append(ViewTab());
+    ViewTab& viewTab = m_viewTab[m_tabIndex];
+    viewTab.wasActive = true; // The first opened tab is automatically active
 
     KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
     undoManager->setUiInterface(new UndoUiInterface());
 
     KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
     undoManager->setUiInterface(new UndoUiInterface());
@@ -177,8 +179,8 @@ DolphinMainWindow::DolphinMainWindow() :
 
     setAcceptDrops(true);
 
 
     setAcceptDrops(true);
 
-    m_viewTab[m_tabIndex].splitter = new QSplitter(this);
-    m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
+    viewTab.splitter = new QSplitter(this);
+    viewTab.splitter->setChildrenCollapsible(false);
 
     setupActions();
 
 
     setupActions();
 
@@ -188,9 +190,9 @@ DolphinMainWindow::DolphinMainWindow() :
     connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
     connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
 
     connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
     connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
 
-    m_viewTab[m_tabIndex].primaryView = createViewContainer(homeUrl, m_viewTab[m_tabIndex].splitter);
+    viewTab.primaryView = createViewContainer(homeUrl, viewTab.splitter);
 
 
-    m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
+    m_activeViewContainer = viewTab.primaryView;
     connectViewSignals(m_activeViewContainer);
     DolphinView* view = m_activeViewContainer->view();
     m_activeViewContainer->show();
     connectViewSignals(m_activeViewContainer);
     DolphinView* view = m_activeViewContainer->view();
     m_activeViewContainer->show();
@@ -227,7 +229,7 @@ DolphinMainWindow::DolphinMainWindow() :
     m_centralWidgetLayout->setSpacing(0);
     m_centralWidgetLayout->setMargin(0);
     m_centralWidgetLayout->addWidget(m_tabBar);
     m_centralWidgetLayout->setSpacing(0);
     m_centralWidgetLayout->setMargin(0);
     m_centralWidgetLayout->addWidget(m_tabBar);
-    m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
+    m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
 
     setCentralWidget(centralWidget);
     setupDockWidgets();
 
     setCentralWidget(centralWidget);
     setupDockWidgets();
@@ -504,13 +506,13 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
     viewTab.primaryView->setActive(false);
     connectViewSignals(viewTab.primaryView);
 
     viewTab.primaryView->setActive(false);
     connectViewSignals(viewTab.primaryView);
 
-    const int newTabIndex = m_viewTab.count();
     m_viewTab.append(viewTab);
 
     actionCollection()->action("close_tab")->setEnabled(true);
 
     // provide a split view, if the startup settings are set this way
     if (GeneralSettings::splitView()) {
     m_viewTab.append(viewTab);
 
     actionCollection()->action("close_tab")->setEnabled(true);
 
     // provide a split view, if the startup settings are set this way
     if (GeneralSettings::splitView()) {
+        const int newTabIndex = m_viewTab.count() - 1;
         createSecondaryView(newTabIndex);
         viewTab.secondaryView->setActive(true);
         viewTab.isPrimaryViewActive = false;
         createSecondaryView(newTabIndex);
         viewTab.secondaryView->setActive(true);
         viewTab.isPrimaryViewActive = false;
@@ -521,14 +523,6 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
         // in background, assure that the previous focused widget gets the focus back.
         focusWidget->setFocus();
     }
         // in background, assure that the previous focused widget gets the focus back.
         focusWidget->setFocus();
     }
-
-    // TODO: Temporary switching to the new tab is a workaround/hack to prevent that
-    // the KItemListView from the DolphinView is initialized with a too small size.
-    // The small size results in an unwanted animation of the items when showing the
-    // tab the first time, as the KItemListView size will be adjusted on-the-fly.
-    const int currentTabIndex = m_tabIndex;
-    m_tabBar->setCurrentIndex(newTabIndex);
-    m_tabBar->setCurrentIndex(currentTabIndex);
 }
 
 void DolphinMainWindow::activateNextTab()
 }
 
 void DolphinMainWindow::activateNextTab()
@@ -1156,6 +1150,18 @@ void DolphinMainWindow::setActiveTab(int index)
     }
     viewTab.splitter->show();
 
     }
     viewTab.splitter->show();
 
+    if (!viewTab.wasActive) {
+        viewTab.wasActive = true;
+
+        // If the tab has not been activated yet the size of the KItemListView is
+        // undefined and results in an unwanted animation. To prevent this a
+        // reloading of the directory gets triggered.
+        viewTab.primaryView->view()->reload();
+        if (viewTab.secondaryView) {
+            viewTab.secondaryView->view()->reload();
+        }
+    }
+
     setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
                                                          viewTab.secondaryView);
 }
     setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
                                                          viewTab.secondaryView);
 }
index fd9e1032993b05cfcddd252de35a7db59a1ee880..998b6fc254d3d39264f5d5ec79870b6ab4811b7e 100644 (file)
@@ -565,8 +565,9 @@ private:
     // Members for the tab-handling:
     struct ViewTab
     {
     // Members for the tab-handling:
     struct ViewTab
     {
-        ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
+        ViewTab() : isPrimaryViewActive(true), wasActive(false), primaryView(0), secondaryView(0), splitter(0) {}
         bool isPrimaryViewActive;
         bool isPrimaryViewActive;
+        bool wasActive;
         DolphinViewContainer* primaryView;
         DolphinViewContainer* secondaryView;
         QSplitter* splitter;
         DolphinViewContainer* primaryView;
         DolphinViewContainer* secondaryView;
         QSplitter* splitter;