iconmanager.cpp
ratingpainter.cpp
renamedialog.cpp
+ selectiontoggle.cpp
+ selectionmanager.cpp
viewproperties.cpp
)
<label context="@label">Browse through archives</label>
<default>false</default>
</entry>
+ <entry name="ShowSelectionToggle" type="Bool">
+ <label context="@label">Show selection toggle</label>
+ <default>true</default>
+ </entry>
<entry name="ViewPropsTimestamp" type="DateTime" >
<label context="@label">Timestamp since when the view properties are valid</label>
</entry>
#include "dolphinsortfilterproxymodel.h"
#include "dolphinsettings.h"
#include "dolphin_columnmodesettings.h"
+#include "dolphin_generalsettings.h"
#include "draganddrophelper.h"
+#include "selectionmanager.h"
#include <kcolorscheme.h>
#include <kdirlister.h>
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
setModel(m_proxyModel);
+ const bool useSelManager = KGlobalSettings::singleClick() &&
+ DolphinSettings::instance().generalSettings()->showSelectionToggle();
+ if (useSelManager) {
+ SelectionManager* selManager = new SelectionManager(this);
+ connect(selManager, SIGNAL(selectionChanged()),
+ this, SLOT(requestActivation()));
+ }
new KMimeTypeResolver(this, m_dolphinModel);
m_iconManager = new IconManager(this, m_proxyModel);
m_iconManager->setShowPreview(m_view->m_controller->dolphinView()->showPreview());
void DolphinColumnWidget::mousePressEvent(QMouseEvent* event)
{
- m_view->m_controller->requestActivation();
- if (!m_active) {
- m_view->requestActivation(this);
- m_view->m_controller->triggerUrlChangeRequest(m_url);
- }
-
+ requestActivation();
QListView::mousePressEvent(event);
}
m_view->m_controller->emitItemEntered(item);
}
+void DolphinColumnWidget::requestActivation()
+{
+ m_view->m_controller->requestActivation();
+ if (!m_active) {
+ m_view->requestActivation(this);
+ m_view->m_controller->triggerUrlChangeRequest(m_url);
+ selectionModel()->clear();
+ }
+}
+
void DolphinColumnWidget::activate()
{
setFocus(Qt::OtherFocusReason);
void slotEntered(const QModelIndex& index);
+ void requestActivation();
+
private:
/** Used by DolphinColumnWidget::setActive(). */
void activate();
#include "dolphinsettings.h"
#include "dolphinsortfilterproxymodel.h"
#include "draganddrophelper.h"
+#include "selectionmanager.h"
#include "viewproperties.h"
#include "dolphin_detailsmodesettings.h"
+#include "dolphin_generalsettings.h"
#include <kdirmodel.h>
#include <klocale.h>
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
+ if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
+ SelectionManager* selManager = new SelectionManager(this);
+ connect(selManager, SIGNAL(selectionChanged()),
+ this, SLOT(requestActivation()));
+ }
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
m_autoResize = false;
}
+void DolphinDetailsView::requestActivation()
+{
+ m_controller->requestActivation();
+}
+
bool DolphinDetailsView::isZoomInPossible() const
{
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
*/
void disableAutoResizing();
+ void requestActivation();
+
private:
bool isZoomInPossible() const;
bool isZoomOutPossible() const;
#include "dolphincontroller.h"
#include "dolphinsettings.h"
#include "dolphin_iconsmodesettings.h"
+#include "dolphin_generalsettings.h"
#include "draganddrophelper.h"
+#include "selectionmanager.h"
#include <kcategorizedsortfilterproxymodel.h>
#include <kdialog.h>
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
+ if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
+ SelectionManager* selManager = new SelectionManager(this);
+ connect(selManager, SIGNAL(selectionChanged()),
+ this, SLOT(requestActivation()));
+ }
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
}
}
+void DolphinIconsView::requestActivation()
+{
+ m_controller->requestActivation();
+}
+
bool DolphinIconsView::isZoomInPossible() const
{
IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
void slotAdditionalInfoChanged();
void zoomIn();
void zoomOut();
+ void requestActivation();
private:
bool isZoomInPossible() const;
m_globalProps(0),
m_maxPreviewSize(0),
m_spinBox(0),
- m_useFileThumbnails(0)
+ m_useFileThumbnails(0),
+ m_showSelectionToggle(0)
{
const int spacing = KDialog::spacingHint();
const int margin = KDialog::marginHint();
previewBoxLayout->addWidget(vBox);
previewBoxLayout->addWidget(m_useFileThumbnails);
+ m_showSelectionToggle = new QCheckBox(i18nc("option:check", "Show selection toggle"), this);
+
// Add a dummy widget with no restriction regarding
// a vertical resizing. This assures that the dialog layout
// is not stretched vertically.
m_useFileThumbnails->isChecked(),
KConfigBase::Normal | KConfigBase::Global);
globalConfig.sync();
+
+ settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
}
void GeneralViewSettingsPage::restoreDefaults()
const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", true);
m_useFileThumbnails->setChecked(useFileThumbnails);
+
+ m_showSelectionToggle->setChecked(settings->showSelectionToggle());
}
#include "generalviewsettingspage.moc"
QSlider* m_maxPreviewSize;
QSpinBox* m_spinBox;
QCheckBox* m_useFileThumbnails;
+ QCheckBox* m_showSelectionToggle;
};
#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "selectionmanager.h"
+
+#include "dolphinmodel.h"
+#include "selectiontoggle.h"
+#include <kdirmodel.h>
+#include <kiconeffect.h>
+
+#include <QAbstractButton>
+#include <QAbstractItemView>
+#include <QAbstractProxyModel>
+#include <QModelIndex>
+#include <QPainter>
+#include <QPaintEvent>
+#include <QRect>
+
+SelectionManager::SelectionManager(QAbstractItemView* parent) :
+ QObject(parent),
+ m_view(parent),
+ m_button(0),
+ m_item()
+{
+ connect(parent, SIGNAL(entered(const QModelIndex&)),
+ this, SLOT(slotEntered(const QModelIndex&)));
+ connect(parent, SIGNAL(viewportEntered()),
+ this, SLOT(slotViewportEntered()));
+ m_button = new SelectionToggle(m_view->viewport());
+ m_button->setCheckable(true);
+ m_button->hide();
+ connect(m_button, SIGNAL(clicked(bool)),
+ this, SLOT(setItemSelected(bool)));
+ connect(m_view->selectionModel(), SIGNAL(selectionChanged()),
+ this, SLOT(slotSelectionChanged()));
+}
+
+SelectionManager::~SelectionManager()
+{
+}
+
+void SelectionManager::slotEntered(const QModelIndex& index)
+{
+ m_button->hide();
+ if (index.isValid() && (index.column() == DolphinModel::Name)) {
+ m_item = itemForIndex(index);
+
+ const QRect rect = m_view->visualRect(index);
+ const int gap = 2;
+ const int x = rect.right() - m_button->width() - gap;
+ int y = rect.top();
+ if (rect.height() <= m_button->height() * 2) {
+ // center the button vertically
+ y += (rect.height() - m_button->height()) / 2;
+ } else {
+ y += gap;
+ }
+
+ m_button->move(QPoint(x, y));
+
+ QItemSelectionModel* selModel = m_view->selectionModel();
+ m_button->setChecked(selModel->isSelected(index));
+ m_button->show();
+ } else {
+ m_item = KFileItem();
+ }
+}
+
+void SelectionManager::slotViewportEntered()
+{
+ m_button->hide();
+ m_item = KFileItem();
+}
+
+void SelectionManager::slotSelectionChanged()
+{
+ const QModelIndex index = indexForItem(m_item);
+ if (index.isValid()) {
+ QItemSelectionModel* selModel = m_view->selectionModel();
+ m_button->setChecked(selModel->isSelected(index));
+ }
+}
+
+void SelectionManager::setItemSelected(bool selected)
+{
+ emit selectionChanged();
+ Q_ASSERT(!m_item.isNull());
+
+ const QModelIndex index = indexForItem(m_item);
+ if (index.isValid()) {
+ QItemSelectionModel* selModel = m_view->selectionModel();
+ if (selected) {
+ selModel->select(index, QItemSelectionModel::Select);
+ } else {
+ selModel->select(index, QItemSelectionModel::Deselect);
+ }
+ }
+}
+
+KFileItem SelectionManager::itemForIndex(const QModelIndex& index) const
+{
+ QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_view->model());
+ KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+ const QModelIndex dirIndex = proxyModel->mapToSource(index);
+ return dirModel->itemForIndex(dirIndex);
+}
+
+const QModelIndex SelectionManager::indexForItem(const KFileItem& item) const
+{
+ QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(m_view->model());
+ KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+ const QModelIndex dirIndex = dirModel->indexForItem(item);
+ return proxyModel->mapFromSource(dirIndex);
+}
+
+#include "selectionmanager.moc"
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef SELECTIONMANAGER_H
+#define SELECTIONMANAGER_H
+
+#include <kfileitem.h>
+
+#include <QObject>
+
+class DolphinSortFilterProxyModel;
+class QAbstractItemView;
+class QModelIndex;
+class QAbstractButton;
+
+/**
+ * @brief Allows to select and deselect items for the single-click mode.
+ *
+ * Whenever an item is hovered by the mouse, a toggle button is shown
+ * which allows to select/deselect the current item.
+ */
+class SelectionManager : public QObject
+{
+ Q_OBJECT
+
+public:
+ SelectionManager(QAbstractItemView* parent);
+ virtual ~SelectionManager();
+
+signals:
+ /** Is emitted if the selection has been changed by the toggle button. */
+ void selectionChanged();
+
+private slots:
+ void slotEntered(const QModelIndex& index);
+ void slotViewportEntered();
+ void slotSelectionChanged();
+ void setItemSelected(bool selected);
+
+private:
+ KFileItem itemForIndex(const QModelIndex& index) const;
+ const QModelIndex indexForItem(const KFileItem& item) const;
+
+private:
+ QAbstractItemView* m_view;
+ QAbstractButton* m_button;
+ KFileItem m_item;
+};
+
+#endif
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "selectiontoggle.h"
+
+#include <kicon.h>
+#include <kiconloader.h>
+#include <kiconeffect.h>
+
+#include <QPainter>
+#include <QPaintEvent>
+#include <QRect>
+#include <QTimer>
+
+#include <kdebug.h>
+
+SelectionToggle::SelectionToggle(QWidget* parent) :
+ QAbstractButton(parent),
+ m_showIcon(false),
+ m_isHovered(false),
+ m_icon(),
+ m_timer(0)
+{
+ parent->installEventFilter(this);
+ resize(sizeHint());
+ m_icon = KIconLoader::global()->loadIcon("dialog-ok",
+ KIconLoader::NoGroup,
+ KIconLoader::SizeSmall);
+ m_timer = new QTimer(this);
+ connect(m_timer, SIGNAL(timeout()),
+ this, SLOT(showIcon()));
+}
+
+SelectionToggle::~SelectionToggle()
+{
+}
+
+QSize SelectionToggle::sizeHint() const
+{
+ return QSize(16, 16);
+}
+
+void SelectionToggle::setVisible(bool visible)
+{
+ QAbstractButton::setVisible(visible);
+ if (visible) {
+ m_timer->start(1000);
+ } else {
+ m_timer->stop();
+ m_showIcon = false;
+ }
+}
+
+bool SelectionToggle::eventFilter(QObject* obj, QEvent* event)
+{
+ if ((obj == parent()) && (event->type() == QEvent::Leave)) {
+ hide();
+ }
+ return QAbstractButton::eventFilter(obj, event);
+}
+
+void SelectionToggle::enterEvent(QEvent* event)
+{
+ QAbstractButton::enterEvent(event);
+ m_isHovered = true;
+ m_showIcon = true;
+ update();
+}
+
+void SelectionToggle::leaveEvent(QEvent* event)
+{
+ QAbstractButton::leaveEvent(event);
+ m_isHovered = false;
+ update();
+}
+
+void SelectionToggle::paintEvent(QPaintEvent* event)
+{
+ QPainter painter(this);
+ painter.setClipRect(event->rect());
+
+ if (m_isHovered) {
+ KIconEffect iconEffect;
+ QPixmap activeIcon = iconEffect.apply(m_icon, KIconLoader::Desktop, KIconLoader::ActiveState);
+ painter.drawPixmap(0, 0, activeIcon);
+ } else if (m_showIcon) {
+ painter.drawPixmap(0, 0, m_icon);
+ }
+}
+
+void SelectionToggle::showIcon()
+{
+ m_showIcon = true;
+ update();
+}
+
+#include "selectiontoggle.moc"
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef SELECTIONTOGGLE_H
+#define SELECTIONTOGGLE_H
+
+#include <QAbstractButton>
+#include <QPixmap>
+#include <QTimer>
+
+/**
+ * @brief Toggle button for changing the selection of an hovered item.
+ * @see SelectionManager
+ */
+class SelectionToggle : public QAbstractButton
+{
+ Q_OBJECT
+
+public:
+ explicit SelectionToggle(QWidget* parent);
+ virtual ~SelectionToggle();
+ virtual QSize sizeHint() const;
+
+public slots:
+ virtual void setVisible(bool visible);
+
+protected:
+ virtual bool eventFilter(QObject* obj, QEvent* event);
+ virtual void enterEvent(QEvent* event);
+ virtual void leaveEvent(QEvent* event);
+ virtual void paintEvent(QPaintEvent* event);
+
+private slots:
+ void showIcon();
+
+private:
+ bool m_showIcon;
+ bool m_isHovered;
+ QPixmap m_icon;
+ QTimer* m_timer;
+};
+
+#endif