correct action input field

This commit is contained in:
Marco Martin 2013-08-26 14:58:59 +02:00
parent 01f041b3ef
commit 35748e1f1e
3 changed files with 74 additions and 13 deletions

View File

@ -37,10 +37,11 @@
CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent)
: QStandardItemModel(parent)
: QStandardItemModel(parent),
m_containment(cotainment)
{
QHash<int, QByteArray> roleNames;
roleNames[NameRole] = "name";
roleNames[ActionRole] = "action";
roleNames[PluginRole] = "plugin";
setRoleNames(roleNames);
@ -52,7 +53,7 @@ CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containme
i.next();
QStandardItem *item = new QStandardItem();
item->setData(i.key(), NameRole);
item->setData(i.key(), ActionRole);
item->setData(i.value()->pluginInfo().pluginName(), PluginRole);
appendRow(item);
}
@ -62,12 +63,39 @@ CurrentContainmentActionsModel::~CurrentContainmentActionsModel()
{
}
void CurrentContainmentActionsModel::append(const QString &action, const QString &plugin)
QString CurrentContainmentActionsModel::mouseEventString(int mouseButton, int modifiers)
{
QMouseEvent *mouse = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(), (Qt::MouseButton)mouseButton, (Qt::MouseButton)mouseButton, (Qt::KeyboardModifiers) modifiers);
QString string = Plasma::ContainmentActions::eventToString(mouse);
delete mouse;
return string;
}
QString CurrentContainmentActionsModel::wheelEventString(const QPointF &delta, int mouseButtons, int modifiers)
{
QWheelEvent *wheel = new QWheelEvent(QPointF(), QPointF(), delta.toPoint(), QPoint(), 0, Qt::Vertical, (Qt::MouseButtons)mouseButtons, (Qt::KeyboardModifiers) modifiers);
QString string = Plasma::ContainmentActions::eventToString(wheel);
delete wheel;
return string;
}
bool CurrentContainmentActionsModel::append(const QString &action, const QString &plugin)
{
if (!match(index(0,0), ActionRole, action).isEmpty()) {
return false;
}
QStandardItem *item = new QStandardItem();
item->setData(action, NameRole);
item->setData(action, ActionRole);
item->setData(plugin, PluginRole);
appendRow(item);
return true;
}
void CurrentContainmentActionsModel::update(int row, const QString &action, const QString &plugin)
@ -75,7 +103,7 @@ void CurrentContainmentActionsModel::update(int row, const QString &action, cons
QModelIndex idx = index(row, 0);
if (idx.isValid()) {
setData(idx, action, NameRole);
setData(idx, action, ActionRole);
setData(idx, plugin, PluginRole);
}
}

View File

@ -35,17 +35,22 @@ class CurrentContainmentActionsModel : public QStandardItemModel
public:
enum Roles {
NameRole = Qt::UserRole+1,
ActionRole = Qt::UserRole+1,
PluginRole
};
CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0);
~CurrentContainmentActionsModel();
Q_INVOKABLE void append(const QString &action, const QString &plugin);
Q_INVOKABLE QString mouseEventString(int mouseButtons, int modifiers);
Q_INVOKABLE QString wheelEventString(const QPointF &delta, int mouseButtons, int modifiers);
Q_INVOKABLE bool append(const QString &action, const QString &plugin);
Q_INVOKABLE void update(int row, const QString &action, const QString &plugin);
Q_INVOKABLE void remove(int row);
Q_INVOKABLE void save();
private:
Plasma::Containment *m_containment;
};
//TODO: is it possible to move this in the shell?

View File

@ -20,6 +20,7 @@ import QtQuick 2.0
import QtQuick.Controls 1.0 as QtControls
import QtQuick.Layouts 1.0
import org.kde.qtextracomponents 2.0
Item {
id: root
@ -37,9 +38,9 @@ Item {
Repeater {
model: configDialog.currentContainmentActionsModel
delegate: RowLayout {
width: root.width * 0.8
width: root.width
QtControls.Button {
text: "Middle Button"
text: model.action
}
QtControls.ComboBox {
Layout.fillWidth: true
@ -64,9 +65,36 @@ Item {
}
}
QtControls.Button {
text: "Add Action"
id: mouseInputButton
text: i18n("Add Action")
checkable: true
onCheckedChanged: {
if (checked) {
text = i18n("Input Here");
mouseInputArea.enabled = true;
}
}
MouseArea {
id: mouseInputArea
anchors.fill: parent
acceptedButtons: Qt.AllButtons
enabled: false
onClicked: {
configDialog.currentContainmentActionsModel.append("RightButton;NoModifier", "org.kde.contextmenu");
if (configDialog.currentContainmentActionsModel.append(configDialog.currentContainmentActionsModel.mouseEventString(mouse.button, mouse.modifiers), "org.kde.contextmenu")) {
mouseInputButton.text = i18n("Add Action");
mouseInputButton.checked = false;
enabled = false;
}
}
onWheel: {
if (configDialog.currentContainmentActionsModel.append(configDialog.currentContainmentActionsModel.wheelEventString(wheel.pixelDelta, wheel.buttons, wheel.modifiers), "org.kde.contextmenu")) {
mouseInputButton.text = i18n("Add Action");
mouseInputButton.checked = false;
enabled = false;
}
}
}
}
}