mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-21 17:30:15 +00:00
Port away from KGlobalSettings::singleClick() and use the mouse kcm module instead of implementing the single/double click settings on our one.
REVIEW: 122311
This commit is contained in:
parent
fdb5c0d33e
commit
5100c20c0d
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include "kitemlistcontroller.h"
|
#include "kitemlistcontroller.h"
|
||||||
|
|
||||||
#include <KGlobalSettings>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "kitemlistview.h"
|
#include "kitemlistview.h"
|
||||||
|
@ -773,7 +772,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con
|
||||||
} else if (shiftOrControlPressed) {
|
} else if (shiftOrControlPressed) {
|
||||||
// The mouse click should only update the selection, not trigger the item
|
// The mouse click should only update the selection, not trigger the item
|
||||||
emitItemActivated = false;
|
emitItemActivated = false;
|
||||||
} else if (!(KGlobalSettings::singleClick() || m_singleClickActivationEnforced)) {
|
} else if (!(m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced)) {
|
||||||
emitItemActivated = false;
|
emitItemActivated = false;
|
||||||
}
|
}
|
||||||
if (emitItemActivated) {
|
if (emitItemActivated) {
|
||||||
|
@ -803,7 +802,7 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool emitItemActivated = !(KGlobalSettings::singleClick() || m_singleClickActivationEnforced) &&
|
bool emitItemActivated = !(m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) &&
|
||||||
(event->button() & Qt::LeftButton) &&
|
(event->button() & Qt::LeftButton) &&
|
||||||
index >= 0 && index < m_model->count();
|
index >= 0 && index < m_model->count();
|
||||||
if (emitItemActivated) {
|
if (emitItemActivated) {
|
||||||
|
|
|
@ -129,7 +129,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* If set to true, the signals itemActivated() and itemsActivated() are emitted
|
* If set to true, the signals itemActivated() and itemsActivated() are emitted
|
||||||
* after a single-click of the left mouse button. If set to false (the default),
|
* after a single-click of the left mouse button. If set to false (the default),
|
||||||
* the setting from KGlobalSettings::singleClick() is used.
|
* the setting from style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) is used.
|
||||||
*/
|
*/
|
||||||
void setSingleClickActivationEnforced(bool singleClick);
|
void setSingleClickActivationEnforced(bool singleClick);
|
||||||
bool singleClickActivationEnforced() const;
|
bool singleClickActivationEnforced() const;
|
||||||
|
|
|
@ -22,12 +22,9 @@
|
||||||
#include "dolphin_generalsettings.h"
|
#include "dolphin_generalsettings.h"
|
||||||
|
|
||||||
#include <KDialog>
|
#include <KDialog>
|
||||||
#include <KGlobalSettings>
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QGroupBox>
|
|
||||||
#include <QRadioButton>
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
NavigationSettingsPage::NavigationSettingsPage(QWidget* parent) :
|
NavigationSettingsPage::NavigationSettingsPage(QWidget* parent) :
|
||||||
|
@ -44,19 +41,6 @@ NavigationSettingsPage::NavigationSettingsPage(QWidget* parent) :
|
||||||
vBoxLayout->setSpacing(spacing);
|
vBoxLayout->setSpacing(spacing);
|
||||||
vBoxLayout->setAlignment(Qt::AlignTop);
|
vBoxLayout->setAlignment(Qt::AlignTop);
|
||||||
|
|
||||||
// create 'Mouse' group
|
|
||||||
QGroupBox* mouseBox = new QGroupBox(i18nc("@title:group", "Mouse"), vBox);
|
|
||||||
vBoxLayout->addWidget(mouseBox);
|
|
||||||
mouseBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
|
||||||
m_singleClick = new QRadioButton(i18nc("@option:check Mouse Settings",
|
|
||||||
"Single-click to open files and folders"), mouseBox);
|
|
||||||
m_doubleClick = new QRadioButton(i18nc("@option:check Mouse Settings",
|
|
||||||
"Double-click to open files and folders"), mouseBox);
|
|
||||||
|
|
||||||
QVBoxLayout* mouseBoxLayout = new QVBoxLayout(mouseBox);
|
|
||||||
mouseBoxLayout->addWidget(m_singleClick);
|
|
||||||
mouseBoxLayout->addWidget(m_doubleClick);
|
|
||||||
|
|
||||||
m_openArchivesAsFolder = new QCheckBox(i18nc("@option:check", "Open archives as folder"), vBox);
|
m_openArchivesAsFolder = new QCheckBox(i18nc("@option:check", "Open archives as folder"), vBox);
|
||||||
vBoxLayout->addWidget(m_openArchivesAsFolder);
|
vBoxLayout->addWidget(m_openArchivesAsFolder);
|
||||||
|
|
||||||
|
@ -72,8 +56,6 @@ NavigationSettingsPage::NavigationSettingsPage(QWidget* parent) :
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
connect(m_singleClick, &QRadioButton::toggled, this, &NavigationSettingsPage::changed);
|
|
||||||
connect(m_doubleClick, &QRadioButton::toggled, this, &NavigationSettingsPage::changed);
|
|
||||||
connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
|
connect(m_openArchivesAsFolder, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
|
||||||
connect(m_autoExpandFolders, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
|
connect(m_autoExpandFolders, &QCheckBox::toggled, this, &NavigationSettingsPage::changed);
|
||||||
}
|
}
|
||||||
|
@ -84,12 +66,6 @@ NavigationSettingsPage::~NavigationSettingsPage()
|
||||||
|
|
||||||
void NavigationSettingsPage::applySettings()
|
void NavigationSettingsPage::applySettings()
|
||||||
{
|
{
|
||||||
KConfig config("kcminputrc");
|
|
||||||
KConfigGroup group = config.group("KDE");
|
|
||||||
group.writeEntry("SingleClick", m_singleClick->isChecked(), KConfig::Persistent|KConfig::Global);
|
|
||||||
config.sync();
|
|
||||||
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
|
|
||||||
|
|
||||||
GeneralSettings* settings = GeneralSettings::self();
|
GeneralSettings* settings = GeneralSettings::self();
|
||||||
settings->setBrowseThroughArchives(m_openArchivesAsFolder->isChecked());
|
settings->setBrowseThroughArchives(m_openArchivesAsFolder->isChecked());
|
||||||
settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
|
settings->setAutoExpandFolders(m_autoExpandFolders->isChecked());
|
||||||
|
@ -103,18 +79,10 @@ void NavigationSettingsPage::restoreDefaults()
|
||||||
settings->useDefaults(true);
|
settings->useDefaults(true);
|
||||||
loadSettings();
|
loadSettings();
|
||||||
settings->useDefaults(false);
|
settings->useDefaults(false);
|
||||||
|
|
||||||
// The mouse settings stored in KGlobalSettings must be reset to
|
|
||||||
// the default values (= single click) manually.
|
|
||||||
m_singleClick->setChecked(true);
|
|
||||||
m_doubleClick->setChecked(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationSettingsPage::loadSettings()
|
void NavigationSettingsPage::loadSettings()
|
||||||
{
|
{
|
||||||
const bool singleClick = KGlobalSettings::singleClick();
|
|
||||||
m_singleClick->setChecked(singleClick);
|
|
||||||
m_doubleClick->setChecked(!singleClick);
|
|
||||||
m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives());
|
m_openArchivesAsFolder->setChecked(GeneralSettings::browseThroughArchives());
|
||||||
m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders());
|
m_autoExpandFolders->setChecked(GeneralSettings::autoExpandFolders());
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include <settings/settingspagebase.h>
|
#include <settings/settingspagebase.h>
|
||||||
|
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
class QRadioButton;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Page for the 'Navigation' settings of the Dolphin settings dialog.
|
* @brief Page for the 'Navigation' settings of the Dolphin settings dialog.
|
||||||
|
@ -45,8 +44,6 @@ private:
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRadioButton* m_singleClick;
|
|
||||||
QRadioButton* m_doubleClick;
|
|
||||||
QCheckBox* m_openArchivesAsFolder;
|
QCheckBox* m_openArchivesAsFolder;
|
||||||
QCheckBox* m_autoExpandFolders;
|
QCheckBox* m_autoExpandFolders;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,12 +25,51 @@
|
||||||
#include "kitemviews/private/kitemlistviewlayouter.h"
|
#include "kitemviews/private/kitemlistviewlayouter.h"
|
||||||
#include "testdir.h"
|
#include "testdir.h"
|
||||||
|
|
||||||
#include <KConfigGroup>
|
|
||||||
#include <KGlobalSettings>
|
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QSignalSpy>
|
#include <QSignalSpy>
|
||||||
|
#include <QProxyStyle>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class KItemListControllerTestStyle is a proxy style for testing the
|
||||||
|
* KItemListController with different style hint options, e.g. single/double
|
||||||
|
* click activation.
|
||||||
|
*/
|
||||||
|
class KItemListControllerTestStyle : public QProxyStyle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KItemListControllerTestStyle(QStyle* style) :
|
||||||
|
QProxyStyle(style),
|
||||||
|
m_activateItemOnSingleClick((bool)style->styleHint(SH_ItemView_ActivateItemOnSingleClick))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setActivateItemOnSingleClick(bool activateItemOnSingleClick)
|
||||||
|
{
|
||||||
|
m_activateItemOnSingleClick = activateItemOnSingleClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool activateItemOnSingleClick() const
|
||||||
|
{
|
||||||
|
return m_activateItemOnSingleClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
int styleHint(StyleHint hint,
|
||||||
|
const QStyleOption* option = nullptr,
|
||||||
|
const QWidget* widget = nullptr,
|
||||||
|
QStyleHintReturn* returnData = nullptr) const Q_DECL_OVERRIDE
|
||||||
|
{
|
||||||
|
switch (hint) {
|
||||||
|
case QStyle::SH_ItemView_ActivateItemOnSingleClick:
|
||||||
|
return (int)activateItemOnSingleClick();
|
||||||
|
default:
|
||||||
|
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_activateItemOnSingleClick;
|
||||||
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(KFileItemListView::ItemLayout);
|
Q_DECLARE_METATYPE(KFileItemListView::ItemLayout);
|
||||||
Q_DECLARE_METATYPE(Qt::Orientation);
|
Q_DECLARE_METATYPE(Qt::Orientation);
|
||||||
|
@ -66,6 +105,7 @@ private:
|
||||||
KFileItemModel* m_model;
|
KFileItemModel* m_model;
|
||||||
TestDir* m_testDir;
|
TestDir* m_testDir;
|
||||||
KItemListContainer* m_container;
|
KItemListContainer* m_container;
|
||||||
|
KItemListControllerTestStyle* m_testStyle;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +125,8 @@ void KItemListControllerTest::initTestCase()
|
||||||
m_controller = m_container->controller();
|
m_controller = m_container->controller();
|
||||||
m_controller->setSelectionBehavior(KItemListController::MultiSelection);
|
m_controller->setSelectionBehavior(KItemListController::MultiSelection);
|
||||||
m_selectionManager = m_controller->selectionManager();
|
m_selectionManager = m_controller->selectionManager();
|
||||||
|
m_testStyle = new KItemListControllerTestStyle(m_view->style());
|
||||||
|
m_view->setStyle(m_testStyle);
|
||||||
|
|
||||||
QStringList files;
|
QStringList files;
|
||||||
files
|
files
|
||||||
|
@ -529,10 +571,7 @@ void KItemListControllerTest::testMouseClickActivation()
|
||||||
const QPointF pos = m_view->itemContextRect(0).center();
|
const QPointF pos = m_view->itemContextRect(0).center();
|
||||||
|
|
||||||
// Save the "single click" setting.
|
// Save the "single click" setting.
|
||||||
const bool restoreKGlobalSettingsSingleClick = KGlobalSettings::singleClick();
|
const bool restoreSettingsSingleClick = m_testStyle->activateItemOnSingleClick();
|
||||||
|
|
||||||
KConfig config("kcminputrc");
|
|
||||||
KConfigGroup group = config.group("KDE");
|
|
||||||
|
|
||||||
QGraphicsSceneMouseEvent mousePressEvent(QEvent::GraphicsSceneMousePress);
|
QGraphicsSceneMouseEvent mousePressEvent(QEvent::GraphicsSceneMousePress);
|
||||||
mousePressEvent.setPos(pos);
|
mousePressEvent.setPos(pos);
|
||||||
|
@ -547,43 +586,14 @@ void KItemListControllerTest::testMouseClickActivation()
|
||||||
QSignalSpy spyItemActivated(m_controller, SIGNAL(itemActivated(int)));
|
QSignalSpy spyItemActivated(m_controller, SIGNAL(itemActivated(int)));
|
||||||
|
|
||||||
// Default setting: single click activation.
|
// Default setting: single click activation.
|
||||||
group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global);
|
m_testStyle->setActivateItemOnSingleClick(true);
|
||||||
config.sync();
|
|
||||||
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
|
|
||||||
|
|
||||||
int iterations = 0;
|
|
||||||
const int maxIterations = 20;
|
|
||||||
while (!KGlobalSettings::singleClick() && iterations < maxIterations) {
|
|
||||||
QTest::qWait(50);
|
|
||||||
++iterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!KGlobalSettings::singleClick()) {
|
|
||||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
|
||||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_view->event(&mousePressEvent);
|
m_view->event(&mousePressEvent);
|
||||||
m_view->event(&mouseReleaseEvent);
|
m_view->event(&mouseReleaseEvent);
|
||||||
QCOMPARE(spyItemActivated.count(), 1);
|
QCOMPARE(spyItemActivated.count(), 1);
|
||||||
spyItemActivated.clear();
|
spyItemActivated.clear();
|
||||||
|
|
||||||
// Set the global setting to "double click activation".
|
// Set the global setting to "double click activation".
|
||||||
group.writeEntry("SingleClick", false, KConfig::Persistent|KConfig::Global);
|
m_testStyle->setActivateItemOnSingleClick(false);
|
||||||
config.sync();
|
|
||||||
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
|
|
||||||
|
|
||||||
iterations = 0;
|
|
||||||
while (KGlobalSettings::singleClick() && iterations < maxIterations) {
|
|
||||||
QTest::qWait(50);
|
|
||||||
++iterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KGlobalSettings::singleClick()) {
|
|
||||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
|
||||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_view->event(&mousePressEvent);
|
m_view->event(&mousePressEvent);
|
||||||
m_view->event(&mouseReleaseEvent);
|
m_view->event(&mouseReleaseEvent);
|
||||||
QCOMPARE(spyItemActivated.count(), 0);
|
QCOMPARE(spyItemActivated.count(), 0);
|
||||||
|
@ -604,21 +614,7 @@ void KItemListControllerTest::testMouseClickActivation()
|
||||||
spyItemActivated.clear();
|
spyItemActivated.clear();
|
||||||
|
|
||||||
// Set the global setting back to "single click activation".
|
// Set the global setting back to "single click activation".
|
||||||
group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global);
|
m_testStyle->setActivateItemOnSingleClick(true);
|
||||||
config.sync();
|
|
||||||
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
|
|
||||||
|
|
||||||
iterations = 0;
|
|
||||||
while (!KGlobalSettings::singleClick() && iterations < maxIterations) {
|
|
||||||
QTest::qWait(50);
|
|
||||||
++iterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!KGlobalSettings::singleClick()) {
|
|
||||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
|
||||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_view->event(&mousePressEvent);
|
m_view->event(&mousePressEvent);
|
||||||
m_view->event(&mouseReleaseEvent);
|
m_view->event(&mouseReleaseEvent);
|
||||||
QCOMPARE(spyItemActivated.count(), 1);
|
QCOMPARE(spyItemActivated.count(), 1);
|
||||||
|
@ -633,20 +629,7 @@ void KItemListControllerTest::testMouseClickActivation()
|
||||||
|
|
||||||
// Restore previous settings.
|
// Restore previous settings.
|
||||||
m_controller->setSingleClickActivationEnforced(true);
|
m_controller->setSingleClickActivationEnforced(true);
|
||||||
group.writeEntry("SingleClick", restoreKGlobalSettingsSingleClick, KConfig::Persistent|KConfig::Global);
|
m_testStyle->setActivateItemOnSingleClick(restoreSettingsSingleClick);
|
||||||
config.sync();
|
|
||||||
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE);
|
|
||||||
|
|
||||||
iterations = 0;
|
|
||||||
while (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick && iterations < maxIterations) {
|
|
||||||
QTest::qWait(50);
|
|
||||||
++iterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick) {
|
|
||||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
|
||||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KItemListControllerTest::adjustGeometryForColumnCount(int count)
|
void KItemListControllerTest::adjustGeometryForColumnCount(int count)
|
||||||
|
|
Loading…
Reference in a new issue