1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #include "viewextensionsfactory.h"
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"
31 #include "dolphin_generalsettings.h"
33 #include <kfilepreviewgenerator.h>
34 #include <QAbstractItemView>
36 ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView
* view
,
37 DolphinController
* controller
) :
39 m_controller(controller
),
41 m_previewGenerator(0),
42 m_selectionManager(0),
46 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
48 // initialize tooltips
49 if (settings
->showToolTips()) {
50 DolphinSortFilterProxyModel
* proxyModel
= static_cast<DolphinSortFilterProxyModel
*>(view
->model());
51 m_toolTipManager
= new ToolTipManager(view
, proxyModel
);
53 connect(controller
, SIGNAL(hideToolTip()),
54 m_toolTipManager
, SLOT(hideTip()));
57 // initialize preview generator
58 m_previewGenerator
= new KFilePreviewGenerator(view
);
59 m_previewGenerator
->setPreviewShown(controller
->dolphinView()->showPreview());
60 connect(controller
, SIGNAL(zoomLevelChanged(int)),
61 this, SLOT(slotZoomLevelChanged()));
62 connect(controller
, SIGNAL(cancelPreviews()),
63 this, SLOT(cancelPreviews()));
64 connect(controller
->dolphinView(), SIGNAL(showPreviewChanged()),
65 this, SLOT(slotShowPreviewChanged()));
67 // initialize selection manager
68 if (settings
->showSelectionToggle()) {
69 m_selectionManager
= new SelectionManager(view
);
70 connect(m_selectionManager
, SIGNAL(selectionChanged()),
71 this, SLOT(requestActivation()));
72 connect(controller
, SIGNAL(urlChanged(const KUrl
&)),
73 m_selectionManager
, SLOT(reset()));
76 // initialize auto scroller
77 m_autoScroller
= new DolphinViewAutoScroller(view
);
79 // initialize file item delegate
80 m_fileItemDelegate
= new DolphinFileItemDelegate(view
);
81 m_fileItemDelegate
->setShowToolTipWhenElided(false);
82 view
->setItemDelegate(m_fileItemDelegate
);
84 view
->viewport()->installEventFilter(this);
87 ViewExtensionsFactory::~ViewExtensionsFactory()
91 void ViewExtensionsFactory::handleCurrentIndexChange(const QModelIndex
& current
, const QModelIndex
& previous
)
93 m_autoScroller
->handleCurrentIndexChange(current
, previous
);
96 DolphinFileItemDelegate
* ViewExtensionsFactory::fileItemDelegate() const
98 return m_fileItemDelegate
;
101 bool ViewExtensionsFactory::eventFilter(QObject
* watched
, QEvent
* event
)
104 if ((event
->type() == QEvent::Wheel
) && (m_selectionManager
!= 0)) {
105 m_selectionManager
->reset();
110 void ViewExtensionsFactory::slotZoomLevelChanged()
112 m_previewGenerator
->updateIcons();
113 if (m_selectionManager
!= 0) {
114 m_selectionManager
->reset();
118 void ViewExtensionsFactory::cancelPreviews()
120 m_previewGenerator
->cancelPreviews();
123 void ViewExtensionsFactory::slotShowPreviewChanged()
125 const bool show
= m_controller
->dolphinView()->showPreview();
126 m_previewGenerator
->setPreviewShown(show
);
129 void ViewExtensionsFactory::requestActivation()
131 m_controller
->requestActivation();
134 #include "viewextensionsfactory.moc"