valentina/src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp

109 lines
2.8 KiB
C++
Raw Normal View History

/************************************************************************
**
** @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"
#include <QFileInfo>
#include <QAbstractItemDelegate>
#include "vshortcutpropertyeditor.h"
2014-09-14 11:16:59 +02:00
#include "../vproperty_p.h"
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))
{
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)
{
VShortcutEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
2014-09-10 19:57:08 +02:00
}
tmpWidget->setLocale(parent->locale());
return tmpWidget;
}
bool VShortcutProperty::setEditorData(QWidget* editor)
{
VShortcutEditWidget* tmpWidget = qobject_cast<VShortcutEditWidget*>(editor);
2014-09-10 19:57:08 +02:00
if (tmpWidget)
{
tmpWidget->setShortcut(d_ptr->VariantValue.toString(), false);
2014-09-10 19:57:08 +02:00
}
else
return false;
return true;
}
2014-09-14 11:16:59 +02:00
QVariant VShortcutProperty::getEditorData(const QWidget *editor) const
{
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)
{
return tmpWidget->getShortcutAsString();
2014-09-10 19:57:08 +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());
}