2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vshortcutproperty.cpp
|
|
|
|
** @author hedgeware <internal(at)hedgeware.net>
|
|
|
|
** @date
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** All rights reserved. This program and the accompanying materials
|
|
|
|
** are made available under the terms of the GNU Lesser General Public License
|
|
|
|
** (LGPL) version 2.1 which accompanies this distribution, and is available at
|
|
|
|
** http://www.gnu.org/licenses/lgpl-2.1.html
|
|
|
|
**
|
|
|
|
** This library 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
|
|
|
|
** Lesser General Public License for more details.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vshortcutproperty.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2014-09-10 17:27:45 +02:00
|
|
|
#include <QAbstractItemDelegate>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QKeySequence>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QWidget>
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vproperty_p.h"
|
2014-09-10 17:27:45 +02:00
|
|
|
#include "vshortcutpropertyeditor.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
class QStyleOptionViewItem;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
using namespace VPE;
|
|
|
|
|
|
|
|
VShortcutProperty::VShortcutProperty(const QString& name)
|
|
|
|
: VProperty(name, QVariant::String)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
VShortcutProperty::~VShortcutProperty()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant VShortcutProperty::data (int column, int role) const
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return d_ptr->VariantValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return VProperty::data(column, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* VShortcutProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
|
|
|
|
const QAbstractItemDelegate* delegate)
|
|
|
|
{
|
|
|
|
Q_UNUSED(options);
|
|
|
|
|
|
|
|
VShortcutEditWidget* tmpWidget = new VShortcutEditWidget(parent);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (delegate)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
VShortcutEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2015-02-11 11:33:13 +01:00
|
|
|
tmpWidget->setLocale(parent->locale());
|
2014-09-10 17:27:45 +02:00
|
|
|
return tmpWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool VShortcutProperty::setEditorData(QWidget* editor)
|
|
|
|
{
|
|
|
|
VShortcutEditWidget* tmpWidget = qobject_cast<VShortcutEditWidget*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpWidget)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
tmpWidget->setShortcut(d_ptr->VariantValue.toString(), false);
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-14 11:16:59 +02:00
|
|
|
QVariant VShortcutProperty::getEditorData(const QWidget *editor) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-14 11:16:59 +02:00
|
|
|
const VShortcutEditWidget* tmpWidget = qobject_cast<const VShortcutEditWidget*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpWidget)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return tmpWidget->getShortcutAsString();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString VShortcutProperty::type() const
|
|
|
|
{
|
|
|
|
return "shortcut";
|
|
|
|
}
|
|
|
|
|
|
|
|
VProperty* VShortcutProperty::clone(bool include_children, VProperty* container) const
|
|
|
|
{
|
|
|
|
return VProperty::clone(include_children, container ? container : new VShortcutProperty(getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void VShortcutProperty::setValue(const QVariant &value)
|
|
|
|
{
|
|
|
|
VProperty::setValue(QKeySequence::fromString(value.toString()).toString());
|
|
|
|
}
|