Seamly2D
Code documentation
vshortcutproperty.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vshortcutproperty.cpp
4  ** @author hedgeware <internal(at)hedgeware.net>
5  ** @date
6  **
7  ** @brief
8  ** @copyright
9  ** All rights reserved. This program and the accompanying materials
10  ** are made available under the terms of the GNU Lesser General Public License
11  ** (LGPL) version 2.1 which accompanies this distribution, and is available at
12  ** http://www.gnu.org/licenses/lgpl-2.1.html
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  ** Lesser General Public License for more details.
18  **
19  *************************************************************************/
20 
21 #include "vshortcutproperty.h"
22 
23 #include <QAbstractItemDelegate>
24 #include <QKeySequence>
25 #include <QLocale>
26 #include <QWidget>
27 
28 #include "../vproperty_p.h"
30 
32  : VProperty(name, QVariant::String)
33 {
34 
35 }
36 
38 {
39  //
40 }
41 
42 QVariant VPE::VShortcutProperty::data (int column, int role) const
43 {
44  if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
45  {
46  return d_ptr->VariantValue;
47  }
48  else
49  return VProperty::data(column, role);
50 }
51 
52 
53 QWidget* VPE::VShortcutProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
54  const QAbstractItemDelegate* delegate)
55 {
56  Q_UNUSED(options)
57 
58  VShortcutEditWidget* tmpWidget = new VShortcutEditWidget(parent);
59  if (delegate)
60  {
61  VShortcutEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
62  }
63  tmpWidget->setLocale(parent->locale());
64  return tmpWidget;
65 }
66 
67 
69 {
70  VShortcutEditWidget* tmpWidget = qobject_cast<VShortcutEditWidget*>(editor);
71  if (tmpWidget)
72  {
73  tmpWidget->setShortcut(d_ptr->VariantValue.toString(), false);
74  }
75  else
76  return false;
77 
78  return true;
79 }
80 
81 
82 QVariant VPE::VShortcutProperty::getEditorData(const QWidget *editor) const
83 {
84  const VShortcutEditWidget* tmpWidget = qobject_cast<const VShortcutEditWidget*>(editor);
85  if (tmpWidget)
86  {
87  return tmpWidget->getShortcutAsString();
88  }
89 
90  return QVariant();
91 }
92 
93 
95 {
96  return "shortcut";
97 }
98 
99 VPE::VProperty* VPE::VShortcutProperty::clone(bool include_children, VProperty* container) const
100 {
101  return VProperty::clone(include_children, container ? container : new VShortcutProperty(getName()));
102 }
103 
104 void VPE::VShortcutProperty::setValue(const QVariant &value)
105 {
106  VProperty::setValue(QKeySequence::fromString(value.toString()).toString());
107 }
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const
Clones this property.
Definition: vproperty.cpp:372
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const
Get the data how it should be displayed.
Definition: vproperty.cpp:68
virtual void setValue(const QVariant &value)
Sets the value of the property.
Definition: vproperty.cpp:171
void setShortcut(const QString &shortcut, bool emit_signal)
Sets the shortcut.
QString getShortcutAsString() const
Returns the currently set shortcut.
This property can be used to handle key shortcuts.
virtual void setValue(const QVariant &value) Q_DECL_OVERRIDE
Sets the value of the property.
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Get the data how it should be displayed.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
virtual QVariant getEditorData(const QWidget *editor) const Q_DECL_OVERRIDE
Gets the data from the widget.
virtual ~VShortcutProperty() Q_DECL_OVERRIDE
The destructor.
VShortcutProperty(const QString &name)
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &options, const QAbstractItemDelegate *delegate) Q_DECL_OVERRIDE
Returns an editor widget, or NULL if it doesn't supply one.
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const Q_DECL_OVERRIDE
Clones this property.
virtual bool setEditorData(QWidget *editor) Q_DECL_OVERRIDE
Sets the property's data to the editor (returns false, if the standard delegate should do that)