]> cloud.milkyroute.net Git - dolphin.git/blob - src/viewextensionsfactory.cpp
- fixed issue that the horizontal progress bar and the space info bar get hidden...
[dolphin.git] / src / viewextensionsfactory.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
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 #include "viewextensionsfactory.h"
21
22 #include "dolphincontroller.h"
23 #include "dolphinfileitemdelegate.h"
24 #include "dolphinsortfilterproxymodel.h"
25 #include "dolphinview.h"
26 #include "dolphinviewautoscroller.h"
27 #include "selectionmanager.h"
28 #include "settings/dolphinsettings.h"
29 #include "tooltips/tooltipmanager.h"
30
31 #include "dolphin_generalsettings.h"
32
33 #include <kdirlister.h>
34 #include <kdirmodel.h>
35 #include <kfilepreviewgenerator.h>
36 #include <QAbstractItemView>
37
38 ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
39 DolphinController* controller) :
40 QObject(view),
41 m_view(view),
42 m_controller(controller),
43 m_toolTipManager(0),
44 m_previewGenerator(0),
45 m_selectionManager(0),
46 m_autoScroller(0),
47 m_fileItemDelegate(0)
48 {
49 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
50
51 // initialize tooltips
52 if (settings->showToolTips()) {
53 DolphinSortFilterProxyModel* proxyModel = static_cast<DolphinSortFilterProxyModel*>(view->model());
54 m_toolTipManager = new ToolTipManager(view, proxyModel);
55
56 connect(controller, SIGNAL(hideToolTip()),
57 m_toolTipManager, SLOT(hideTip()));
58 }
59
60 // initialize preview generator
61 m_previewGenerator = new KFilePreviewGenerator(view);
62 m_previewGenerator->setPreviewShown(controller->dolphinView()->showPreview());
63 connect(controller, SIGNAL(zoomLevelChanged(int)),
64 this, SLOT(slotZoomLevelChanged()));
65 connect(controller, SIGNAL(cancelPreviews()),
66 this, SLOT(cancelPreviews()));
67 connect(controller->dolphinView(), SIGNAL(showPreviewChanged()),
68 this, SLOT(slotShowPreviewChanged()));
69
70 // initialize selection manager
71 if (settings->showSelectionToggle()) {
72 m_selectionManager = new SelectionManager(view);
73 connect(m_selectionManager, SIGNAL(selectionChanged()),
74 this, SLOT(requestActivation()));
75 connect(controller, SIGNAL(urlChanged(const KUrl&)),
76 m_selectionManager, SLOT(reset()));
77 }
78
79 // initialize auto scroller
80 m_autoScroller = new DolphinViewAutoScroller(view);
81
82 // initialize file item delegate
83 m_fileItemDelegate = new DolphinFileItemDelegate(view);
84 m_fileItemDelegate->setShowToolTipWhenElided(false);
85 view->setItemDelegate(m_fileItemDelegate);
86
87 // react on view property changes
88 const DolphinView* dolphinView = controller->dolphinView();
89 connect(dolphinView, SIGNAL(showHiddenFilesChanged()),
90 this, SLOT(slotShowHiddenFilesChanged()));
91 connect(dolphinView, SIGNAL(sortingChanged(DolphinView::Sorting)),
92 this, SLOT(slotSortingChanged(DolphinView::Sorting)));
93 connect(dolphinView, SIGNAL(sortOrderChanged(Qt::SortOrder)),
94 this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
95 connect(dolphinView, SIGNAL(sortFoldersFirstChanged(bool)),
96 this, SLOT(slotSortFoldersFirstChanged(bool)));
97
98 connect(controller, SIGNAL(nameFilterChanged(const QString&)),
99 this, SLOT(slotNameFilterChanged(const QString&)));
100
101 view->viewport()->installEventFilter(this);
102 }
103
104 ViewExtensionsFactory::~ViewExtensionsFactory()
105 {
106 }
107
108 void ViewExtensionsFactory::handleCurrentIndexChange(const QModelIndex& current, const QModelIndex& previous)
109 {
110 m_autoScroller->handleCurrentIndexChange(current, previous);
111 }
112
113 DolphinFileItemDelegate* ViewExtensionsFactory::fileItemDelegate() const
114 {
115 return m_fileItemDelegate;
116 }
117
118 bool ViewExtensionsFactory::eventFilter(QObject* watched, QEvent* event)
119 {
120 Q_UNUSED(watched);
121 if ((event->type() == QEvent::Wheel) && (m_selectionManager != 0)) {
122 m_selectionManager->reset();
123 }
124 return false;
125 }
126
127 void ViewExtensionsFactory::slotZoomLevelChanged()
128 {
129 m_previewGenerator->updateIcons();
130 if (m_selectionManager != 0) {
131 m_selectionManager->reset();
132 }
133 }
134
135 void ViewExtensionsFactory::cancelPreviews()
136 {
137 m_previewGenerator->cancelPreviews();
138 }
139
140 void ViewExtensionsFactory::slotShowPreviewChanged()
141 {
142 const bool show = m_controller->dolphinView()->showPreview();
143 m_previewGenerator->setPreviewShown(show);
144 }
145
146 void ViewExtensionsFactory::slotShowHiddenFilesChanged()
147 {
148 KDirModel* dirModel = static_cast<KDirModel*>(proxyModel()->sourceModel());
149 KDirLister* dirLister = dirModel->dirLister();
150
151 dirLister->stop();
152
153 const bool show = m_controller->dolphinView()->showHiddenFiles();
154 dirLister->setShowingDotFiles(show);
155
156 const KUrl url = dirLister->url();
157 if (url.isValid()) {
158 dirLister->openUrl(url, KDirLister::NoFlags);
159 }
160 }
161
162 void ViewExtensionsFactory::slotSortingChanged(DolphinView::Sorting sorting)
163 {
164 proxyModel()->setSorting(sorting);
165 }
166
167 void ViewExtensionsFactory::slotSortOrderChanged(Qt::SortOrder order)
168 {
169 proxyModel()->setSortOrder(order);
170 }
171
172 void ViewExtensionsFactory::slotSortFoldersFirstChanged(bool foldersFirst)
173 {
174 proxyModel()->setSortFoldersFirst(foldersFirst);
175 }
176
177 void ViewExtensionsFactory::slotNameFilterChanged(const QString& nameFilter)
178 {
179 proxyModel()->setFilterRegExp(nameFilter);
180 }
181
182 void ViewExtensionsFactory::requestActivation()
183 {
184 m_controller->requestActivation();
185 }
186
187 DolphinSortFilterProxyModel* ViewExtensionsFactory::proxyModel() const
188 {
189 return static_cast<DolphinSortFilterProxyModel*>(m_view->model());
190 }
191
192 #include "viewextensionsfactory.moc"
193