setRoleNames(roles);
setDictionaries(dictionaries);
+
+ connect(this, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(itemChanged()));
}
int DictManagerModel::rowCount(const QModelIndex &parent) const
}
return name;
}
- if (role == NumberRole)
+ if (role == NumberRole){
return index.row();
- if (role == IconPathRole)
+ }
+ if (role == IconPathRole){
return dictionary->iconPath();
- if (role == IsSelectedRole)
+ }
+ if (role == IsSelectedRole){
return _dictionaries[dictionary];
+ }
return QVariant();
}
bool DictManagerModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
- if (index.row() < 0 || index.row() > _dictList.count())
+ int res = setDataPriv(index.row(), value, role);
+ if (res == 0)
return false;
+ if (res > 0)
+ return true;
+ return true;
+}
- CommonDictInterface* dictionary = _dictList[index.row()];
+int DictManagerModel::setDataPriv(int index, const QVariant &value, int role)
+{
+ if (index < 0 || index > _dictList.count())
+ return 0;
+
+ CommonDictInterface* dictionary = _dictList[index];
if (role == NameRole)
- return true;
+ return 1;
if (role == NumberRole)
- return true;
+ return 1;
if (role == IconPathRole)
- return true;
+ return 1;
if (role == IsSelectedRole)
{
if (value.type() == QVariant::Bool)
{
_dictionaries[dictionary] = value.toBool();
- emit dataChanged(index, index);
- return true;
+// if (index == _dictList.count())
+// emit dataChanged(this->index(index-1), this->index(index));
+ emit dataChanged(this->index(0), this->index(_dictList.count() - 1));
+ return 2;
}
else
{
- return false;
+ return 0;
}
}
- return false;
+ return 0;
+}
+
+void DictManagerModel::setModelProperty(int index, const QVariant value, QString role)
+{
+ if (role.contains("isSelected"))
+ {
+ setDataPriv(index, value, IsSelectedRole);
+ }
+
}
Qt::ItemFlags DictManagerModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags fl = QAbstractItemModel::flags(index);
+ qDebug("lol1");
return (fl | Qt::ItemIsEditable);
}
_dictList << dictionary;
endInsertRows();
}
+
+QHash<CommonDictInterface*, bool> DictManagerModel::dictionaries()
+{
+ return _dictionaries;
+}
+
+QList<CommonDictInterface*> DictManagerModel::dictList()
+{
+ return _dictList;
+}
Qt::ItemFlags flags(const QModelIndex &index) const;
void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
+ QHash<CommonDictInterface*, bool> dictionaries();
+ QList<CommonDictInterface*> dictList();
void clear();
+public Q_SLOTS:
+ void setModelProperty(int index, const QVariant value, QString role);
+
+Q_SIGNALS:
+ void itemChanged();
+
private:
QHash<CommonDictInterface*, bool> _dictionaries;
QList<CommonDictInterface*> _dictList;
+ int setDataPriv(int index, const QVariant &value, int role);
void addDictionary(CommonDictInterface* dictionary, bool isActive);
};
#endif
#ifndef Q_WS_MAEMO_5
- //pozmieniać connecty
+ connect(rootObject, SIGNAL(addButtonClicked()),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(addButtonClicked()),
+ this, SLOT(addNewDictButtonClicked()));
+
+ connect(rootObject, SIGNAL(removeButtonClicked()),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(removeButtonClicked()),
+ this, SLOT(removeButtonClicked()));
+
+ connect(rootObject, SIGNAL(settingsButtonClicked()),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(settingsButtonClicked()),
+ this, SLOT(settingsButtonClicked()));
+
+ //z modelu sygnał, oraz z okienka zmian ustawień w pluginie, gdy są zmiany
+// oryginalnie:
+// connect(dictList, SIGNAL(itemChanged(QListWidgetItem*)),
+// this, SLOT(changed()));
+ connect(model, SIGNAL(itemChanged()),
+ this, SLOT(changed()));
+ //pozmieniać connecty, to jest na dwuklik mysza na liście, sprawdzić, zrobic alternatywne sloty
+ connect(rootObject, SIGNAL(itemActivated(int)),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(itemActivated(int)),
+ settingsButton, SIGNAL(clicked()));
+
// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
// this, SLOT(saveChanges()));
// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
// setMinimumHeight(sizeHint().height());
// setMaximumHeight(sizeHint().height()*2);
//connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
+ connect(rootObject, SIGNAL(saveButtonClicked()), this, SLOT(save()));
#endif
}
QHash<CommonDictInterface*, bool> dicts = guiInterface->getDictionaries();
if (model == 0){
- qDebug("ok");
model = new DictManagerModel(dicts, this);
} else {
- qDebug("lol");
model->clear();
model->setDictionaries(dicts);
}
style: Text.Sunken; color: "white"; styleColor: "black"; smooth: true
}
-// Rectangle {
-// id: shade
-// anchors.centerIn: parent;
-// radius: parent.height*.4;
-// color: "black";
-// opacity: 0
-// width: parent.width;
-// height: parent.height;
-// }
-
Image {
id: image1
width: (35*parent.height)/107 +1
Rectangle {
SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
-// signal selectedRow(int nr)
+
+ function setEnableRemove(Boolean) { removeButton.enabled = Boolean }
+ function setEnableSettings(Boolean) { settingsButton.enabled = Boolean }
+
+ signal addButtonClicked;
+ signal removeButtonClicked;
+ signal settingsButtonClicked;
+ signal saveButtonClicked;
+ signal itemActivated(int nr);
id: rectangle1
color: myPalette.base
width: rectangle1.width
// height: rectangle1.height
anchors.top: parent.top
+ anchors.bottom: buttonsBox.top
+ anchors.bottomMargin: buttonsBox.height + buttonsBox.anchors.topMargin
highlightResizeSpeed: 1000
delegate: Component{
id: dictListDelegate
Item {
width: rectangle1.width
height: {
- if (nameText.height + 10 > logo.height)
- return nameText.height + 10;
+ if (nameText.height + 4 > logo.height)
+ return nameText.height + 4;
else
return logo.height;
}
anchors.fill: parent
onClicked: {
dictList.currentIndex = number
+ rectangle1.setEnableRemove(true)
+ rectangle1.setEnableSettings(true)
}
onDoubleClicked: {
- selectedRow(number)
+ rectangle1.itemActivated(dictList.currentIndex)
}
}
Row {
- //image zaznacz/odznacz
anchors.fill: parent
Image {
id: checkbox
-// source: "qrc:/button/checkbox.png"
height: {
var aspectRatio = sourceSize.height / sourceSize.width
- return logo.width * aspectRatio
+ return checkbox.width * aspectRatio
}
anchors.verticalCenter: parent.verticalCenter
- width: nameText.height + 10
+ width: nameText.height
+ smooth: true
states: [
State {
name: "checked";
PropertyChanges { target: checkbox; source: "qrc:/button/checkbox.png" }
}
]
+ MouseArea{
+ anchors.fill: parent
+ onClicked: {
+ dictList.currentIndex = number
+ dictModel.setModelProperty(dictList.currentIndex, !isSelected, "isSelected")
+ rectangle1.setEnableRemove(true)
+ rectangle1.setEnableSettings(true)
+ }
+ }
}
Image {
var aspectRatio = sourceSize.height / sourceSize.width
return logo.width * aspectRatio
}
+ anchors.left: checkbox.right
+ anchors.leftMargin: 5
anchors.verticalCenter: parent.verticalCenter
- width: nameText.height + 10
+ width: nameText.height + 4
+ smooth: true
}
Text {
id: nameText
model: dictModel
}
- //buttonki
+ //buttons
+
+ Item {
+ id: buttonsBox
+ width: parent.width
+ height: 30
+ anchors.bottom: parent.bottom
+ anchors.top: dictList.bottom
+ anchors.topMargin: 8
+
+ Button {
+ id: addButton
+ width: (parent.width - 4) / 4
+ height: buttonsBox.height
+ anchors.left: buttonsBox.left
+ anchors.leftMargin: 4
+ anchors.verticalCenter: parent.verticalCenter
+ textInButton: qsTr("Add")
+ onClicked: rectangle1.addButtonClicked
+ }
+
+ Button {
+ id: removeButton
+ width: (parent.width - 4) / 4
+ height: buttonsBox.height
+ anchors.left: addButton.right
+ anchors.leftMargin: 4
+ anchors.verticalCenter: parent.verticalCenter
+ textInButton: qsTr("Remove")
+ enabled: false
+ onClicked: rectangle1.removeButtonClicked
+ }
+
+ Button {
+ id: settingsButton
+ width: (parent.width - 4) / 4
+ height: buttonsBox.height
+ anchors.left: removeButton.right
+ anchors.leftMargin: 4
+ anchors.verticalCenter: parent.verticalCenter
+ textInButton: qsTr("Settings")
+ enabled: false
+ onClicked: rectangle1.settingsButtonClicked
+ }
+
+ Button {
+ id: saveButton
+ width: (parent.width - 4) / 4
+ height: buttonsBox.height
+ anchors.left: settingsButton.right
+ anchors.leftMargin: 4
+ anchors.right: buttonsBox.right
+ anchors.rightMargin: 4
+ anchors.verticalCenter: parent.verticalCenter
+ textInButton: qsTr("Save")
+ onClicked: rectangle1.saveButtonClicked
+ }
+
+ }
}