2006-11-21 06:02:05 +00:00
|
|
|
/***************************************************************************
|
2007-02-14 21:54:24 +00:00
|
|
|
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
|
2006-11-21 06:02:05 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
2006-12-08 21:24:08 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
2006-11-21 06:02:05 +00:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "dolphiniconsview.h"
|
2007-02-14 21:54:24 +00:00
|
|
|
|
|
|
|
#include "dolphincontroller.h"
|
2007-02-27 20:46:21 +00:00
|
|
|
#include "dolphinsettings.h"
|
2007-04-10 08:46:21 +00:00
|
|
|
#include "dolphinitemcategorizer.h"
|
2007-02-27 20:46:21 +00:00
|
|
|
|
|
|
|
#include "dolphin_iconsmodesettings.h"
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-02 21:51:36 +00:00
|
|
|
#include <kdirmodel.h>
|
|
|
|
#include <kfileitem.h>
|
2007-02-28 22:32:42 +00:00
|
|
|
#include <kfileitemdelegate.h>
|
2006-12-02 21:51:36 +00:00
|
|
|
|
2007-05-09 22:23:52 +00:00
|
|
|
#include <QtGui/QAbstractProxyModel>
|
|
|
|
#include <QtCore/QPoint>
|
2007-01-06 21:11:04 +00:00
|
|
|
|
2007-02-14 21:54:24 +00:00
|
|
|
DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
|
2007-04-14 21:37:29 +00:00
|
|
|
KListView(parent),
|
|
|
|
m_controller(controller)
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2007-02-28 19:17:26 +00:00
|
|
|
Q_ASSERT(controller != 0);
|
2007-02-28 06:32:56 +00:00
|
|
|
setViewMode(QListView::IconMode);
|
2006-12-08 23:41:08 +00:00
|
|
|
setResizeMode(QListView::Adjust);
|
2007-02-14 21:54:24 +00:00
|
|
|
|
2007-05-12 10:22:01 +00:00
|
|
|
setMouseTracking(true);
|
2007-03-02 19:38:11 +00:00
|
|
|
viewport()->setAttribute(Qt::WA_Hover);
|
|
|
|
|
2007-05-01 09:12:24 +00:00
|
|
|
if (KGlobalSettings::singleClick()) {
|
|
|
|
connect(this, SIGNAL(clicked(const QModelIndex&)),
|
|
|
|
controller, SLOT(triggerItem(const QModelIndex&)));
|
|
|
|
} else {
|
|
|
|
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
|
|
|
|
controller, SLOT(triggerItem(const QModelIndex&)));
|
|
|
|
}
|
2007-03-10 18:42:19 +00:00
|
|
|
connect(this, SIGNAL(activated(const QModelIndex&)),
|
|
|
|
controller, SLOT(triggerItem(const QModelIndex&)));
|
2007-05-12 10:22:01 +00:00
|
|
|
connect(this, SIGNAL(entered(const QModelIndex&)),
|
|
|
|
controller, SLOT(emitItemEntered(const QModelIndex&)));
|
|
|
|
connect(this, SIGNAL(viewportEntered()),
|
|
|
|
controller, SLOT(emitViewportEntered()));
|
2007-02-28 19:17:26 +00:00
|
|
|
connect(controller, SIGNAL(showPreviewChanged(bool)),
|
2007-05-10 20:29:10 +00:00
|
|
|
this, SLOT(slotShowPreviewChanged(bool)));
|
|
|
|
connect(controller, SIGNAL(showAdditionalInfoChanged(bool)),
|
|
|
|
this, SLOT(slotShowAdditionalInfoChanged(bool)));
|
2007-03-01 19:36:37 +00:00
|
|
|
connect(controller, SIGNAL(zoomIn()),
|
|
|
|
this, SLOT(zoomIn()));
|
|
|
|
connect(controller, SIGNAL(zoomOut()),
|
|
|
|
this, SLOT(zoomOut()));
|
2007-02-27 20:46:21 +00:00
|
|
|
|
|
|
|
// apply the icons mode settings to the widget
|
|
|
|
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
|
2007-02-28 19:17:26 +00:00
|
|
|
Q_ASSERT(settings != 0);
|
2007-02-27 20:46:21 +00:00
|
|
|
|
2007-04-10 08:46:21 +00:00
|
|
|
m_viewOptions = KListView::viewOptions();
|
2007-04-14 21:37:29 +00:00
|
|
|
m_viewOptions.showDecorationSelected = true;
|
2007-03-13 19:46:49 +00:00
|
|
|
|
|
|
|
QFont font(settings->fontFamily(), settings->fontSize());
|
|
|
|
font.setItalic(settings->italicFont());
|
|
|
|
font.setBold(settings->boldFont());
|
|
|
|
m_viewOptions.font = font;
|
2007-05-10 20:29:10 +00:00
|
|
|
if (settings->numberOfTextlines() > 1) {
|
|
|
|
m_viewOptions.features = QStyleOptionViewItemV2::WrapText;
|
|
|
|
}
|
2007-03-01 19:36:37 +00:00
|
|
|
|
2007-05-10 20:29:10 +00:00
|
|
|
updateGridSize(controller->showPreview(), controller->showAdditionalInfo());
|
2007-02-28 06:32:56 +00:00
|
|
|
|
|
|
|
if (settings->arrangement() == QListView::TopToBottom) {
|
2007-02-28 17:14:26 +00:00
|
|
|
setFlow(QListView::LeftToRight);
|
2007-02-28 06:32:56 +00:00
|
|
|
m_viewOptions.decorationPosition = QStyleOptionViewItem::Top;
|
2007-04-09 19:12:54 +00:00
|
|
|
} else {
|
2007-02-28 17:14:26 +00:00
|
|
|
setFlow(QListView::TopToBottom);
|
2007-02-28 06:32:56 +00:00
|
|
|
m_viewOptions.decorationPosition = QStyleOptionViewItem::Left;
|
|
|
|
}
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DolphinIconsView::~DolphinIconsView()
|
2007-04-14 21:37:29 +00:00
|
|
|
{
|
|
|
|
}
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2006-12-08 23:41:08 +00:00
|
|
|
QStyleOptionViewItem DolphinIconsView::viewOptions() const
|
|
|
|
{
|
2007-02-27 20:46:21 +00:00
|
|
|
return m_viewOptions;
|
2006-12-08 23:41:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-04 05:48:57 +00:00
|
|
|
void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
|
2006-12-02 21:51:36 +00:00
|
|
|
{
|
2007-04-10 08:46:21 +00:00
|
|
|
KListView::contextMenuEvent(event);
|
2007-02-16 17:03:02 +00:00
|
|
|
m_controller->triggerContextMenuRequest(event->pos());
|
2006-12-02 21:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
|
2006-11-25 23:23:08 +00:00
|
|
|
{
|
2007-04-10 08:46:21 +00:00
|
|
|
KListView::mouseReleaseEvent(event);
|
2007-02-14 21:54:24 +00:00
|
|
|
m_controller->triggerActivation();
|
2006-11-25 23:23:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-06 21:11:04 +00:00
|
|
|
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasUrls()) {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinIconsView::dropEvent(QDropEvent* event)
|
|
|
|
{
|
|
|
|
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
2007-03-11 11:13:07 +00:00
|
|
|
if (!urls.isEmpty()) {
|
|
|
|
m_controller->indicateDroppedUrls(urls,
|
|
|
|
indexAt(event->pos()),
|
|
|
|
event->source());
|
2007-01-06 21:11:04 +00:00
|
|
|
event->acceptProposedAction();
|
2007-02-16 17:03:02 +00:00
|
|
|
}
|
2007-04-10 08:46:21 +00:00
|
|
|
KListView::dropEvent(event);
|
2007-01-06 21:11:04 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 20:29:10 +00:00
|
|
|
void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
|
2007-02-28 19:17:26 +00:00
|
|
|
{
|
2007-05-10 20:29:10 +00:00
|
|
|
updateGridSize(showPreview, m_controller->showAdditionalInfo());
|
|
|
|
}
|
2007-03-01 19:36:37 +00:00
|
|
|
|
2007-05-10 20:29:10 +00:00
|
|
|
void DolphinIconsView::slotShowAdditionalInfoChanged(bool showAdditionalInfo)
|
|
|
|
{
|
|
|
|
updateGridSize(m_controller->showPreview(), showAdditionalInfo);
|
2007-03-01 19:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinIconsView::zoomIn()
|
|
|
|
{
|
|
|
|
if (isZoomInPossible()) {
|
|
|
|
IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
|
|
|
|
|
2007-03-14 20:56:16 +00:00
|
|
|
const int oldIconSize = settings->iconSize();
|
|
|
|
int newIconSize = oldIconSize;
|
|
|
|
|
2007-03-01 19:36:37 +00:00
|
|
|
const bool showPreview = m_controller->showPreview();
|
|
|
|
if (showPreview) {
|
|
|
|
const int previewSize = increasedIconSize(settings->previewSize());
|
|
|
|
settings->setPreviewSize(previewSize);
|
2007-04-09 19:12:54 +00:00
|
|
|
} else {
|
2007-03-14 20:56:16 +00:00
|
|
|
newIconSize = increasedIconSize(oldIconSize);
|
|
|
|
settings->setIconSize(newIconSize);
|
|
|
|
if (settings->previewSize() < newIconSize) {
|
2007-03-01 19:44:04 +00:00
|
|
|
// assure that the preview size is always >= the icon size
|
2007-03-14 20:56:16 +00:00
|
|
|
settings->setPreviewSize(newIconSize);
|
2007-03-01 19:44:04 +00:00
|
|
|
}
|
2007-03-01 19:36:37 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 20:56:16 +00:00
|
|
|
// increase also the grid size
|
|
|
|
const int diff = newIconSize - oldIconSize;
|
|
|
|
settings->setGridWidth(settings->gridWidth() + diff);
|
|
|
|
settings->setGridHeight(settings->gridHeight() + diff);
|
|
|
|
|
2007-05-10 20:29:10 +00:00
|
|
|
updateGridSize(showPreview, m_controller->showAdditionalInfo());
|
2007-03-01 19:36:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinIconsView::zoomOut()
|
|
|
|
{
|
|
|
|
if (isZoomOutPossible()) {
|
|
|
|
IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
|
|
|
|
|
2007-03-14 20:56:16 +00:00
|
|
|
const int oldIconSize = settings->iconSize();
|
|
|
|
int newIconSize = oldIconSize;
|
|
|
|
|
2007-03-01 19:36:37 +00:00
|
|
|
const bool showPreview = m_controller->showPreview();
|
|
|
|
if (showPreview) {
|
|
|
|
const int previewSize = decreasedIconSize(settings->previewSize());
|
|
|
|
settings->setPreviewSize(previewSize);
|
2007-03-01 19:44:04 +00:00
|
|
|
if (settings->iconSize() > previewSize) {
|
|
|
|
// assure that the icon size is always <= the preview size
|
2007-03-14 20:56:16 +00:00
|
|
|
newIconSize = previewSize;
|
|
|
|
settings->setIconSize(newIconSize);
|
2007-03-01 19:44:04 +00:00
|
|
|
}
|
2007-04-09 19:12:54 +00:00
|
|
|
} else {
|
2007-03-14 20:56:16 +00:00
|
|
|
newIconSize = decreasedIconSize(settings->iconSize());
|
|
|
|
settings->setIconSize(newIconSize);
|
2007-03-01 19:36:37 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 20:56:16 +00:00
|
|
|
// decrease also the grid size
|
|
|
|
const int diff = oldIconSize - newIconSize;
|
|
|
|
settings->setGridWidth(settings->gridWidth() - diff);
|
|
|
|
settings->setGridHeight(settings->gridHeight() - diff);
|
|
|
|
|
2007-05-10 20:29:10 +00:00
|
|
|
updateGridSize(showPreview, m_controller->showAdditionalInfo());
|
2007-03-01 19:36:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DolphinIconsView::isZoomInPossible() const
|
|
|
|
{
|
|
|
|
IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
|
|
|
|
const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize();
|
|
|
|
return size < K3Icon::SizeEnormous;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DolphinIconsView::isZoomOutPossible() const
|
|
|
|
{
|
|
|
|
IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
|
|
|
|
const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize();
|
|
|
|
return size > K3Icon::SizeSmall;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DolphinIconsView::increasedIconSize(int size) const
|
|
|
|
{
|
|
|
|
// TODO: get rid of K3Icon sizes
|
|
|
|
int incSize = 0;
|
|
|
|
switch (size) {
|
2007-04-09 19:12:54 +00:00
|
|
|
case K3Icon::SizeSmall: incSize = K3Icon::SizeSmallMedium; break;
|
|
|
|
case K3Icon::SizeSmallMedium: incSize = K3Icon::SizeMedium; break;
|
|
|
|
case K3Icon::SizeMedium: incSize = K3Icon::SizeLarge; break;
|
|
|
|
case K3Icon::SizeLarge: incSize = K3Icon::SizeHuge; break;
|
|
|
|
case K3Icon::SizeHuge: incSize = K3Icon::SizeEnormous; break;
|
|
|
|
default: Q_ASSERT(false); break;
|
2007-03-01 19:36:37 +00:00
|
|
|
}
|
|
|
|
return incSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DolphinIconsView::decreasedIconSize(int size) const
|
|
|
|
{
|
|
|
|
// TODO: get rid of K3Icon sizes
|
|
|
|
int decSize = 0;
|
|
|
|
switch (size) {
|
2007-04-09 19:12:54 +00:00
|
|
|
case K3Icon::SizeSmallMedium: decSize = K3Icon::SizeSmall; break;
|
|
|
|
case K3Icon::SizeMedium: decSize = K3Icon::SizeSmallMedium; break;
|
|
|
|
case K3Icon::SizeLarge: decSize = K3Icon::SizeMedium; break;
|
|
|
|
case K3Icon::SizeHuge: decSize = K3Icon::SizeLarge; break;
|
|
|
|
case K3Icon::SizeEnormous: decSize = K3Icon::SizeHuge; break;
|
|
|
|
default: Q_ASSERT(false); break;
|
2007-03-01 19:36:37 +00:00
|
|
|
}
|
|
|
|
return decSize;
|
2007-02-28 19:17:26 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 20:29:10 +00:00
|
|
|
void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
|
|
|
|
{
|
|
|
|
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
|
|
|
|
Q_ASSERT(settings != 0);
|
|
|
|
|
|
|
|
int gridWidth = settings->gridWidth();
|
|
|
|
int gridHeight = settings->gridHeight();
|
|
|
|
int size = settings->iconSize();
|
|
|
|
|
|
|
|
if (showPreview) {
|
|
|
|
const int previewSize = settings->previewSize();
|
|
|
|
const int diff = previewSize - size;
|
|
|
|
Q_ASSERT(diff >= 0);
|
|
|
|
gridWidth += diff;
|
|
|
|
gridHeight += diff;
|
|
|
|
|
|
|
|
size = previewSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showAdditionalInfo) {
|
|
|
|
gridHeight += m_viewOptions.font.pointSize() * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_viewOptions.decorationSize = QSize(size, size);
|
|
|
|
setGridSize(QSize(gridWidth, gridHeight));
|
|
|
|
|
|
|
|
m_controller->setZoomInPossible(isZoomInPossible());
|
|
|
|
m_controller->setZoomOutPossible(isZoomOutPossible());
|
|
|
|
}
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
#include "dolphiniconsview.moc"
|