+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*!
+ author: Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
import Qt 4.7
Rectangle {
- width: 100
- height: 62
+ SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
+
+ function setEnableRemove(Boolean) { removeButton.enabled = Boolean }
+ function setEnableSettings(Boolean) { settingsButton.enabled = Boolean }
+ function changeDictionaryState(nr, state) {
+ dictList.currentIndex = nr
+ dictModel.setModelProperty(dictList.currentIndex, state, "isSelected")
+ rectangle1.setEnableRemove(true)
+ rectangle1.setEnableSettings(true)
+ }
+
+ function setFocus() {
+ dictList.setFocus()
+ }
+
+ signal addButtonClicked;
+ signal removeButtonClicked;
+ signal settingsButtonClicked;
+ signal saveButtonClicked;
+ signal itemActivated(int nr);
+
+ id: rectangle1
+ color: myPalette.base
+ anchors.fill: parent
+
+ ElementsListView{
+ id: dictList
+ width: rectangle1.width
+// height: rectangle1.height
+ anchors.top: parent.top
+ anchors.bottom: buttonsBox.top
+ anchors.bottomMargin: buttonsBox.height + buttonsBox.anchors.topMargin
+ highlightResizeSpeed: 1000
+
+ Keys.onPressed: {
+ if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
+ itemActivated(currentIndex)
+ }
+ if ((event.key == Qt.Key_Delete) && currentIndex >= 0){
+ removeButtonClicked()
+ }
+ if (event.key == Qt.Key_S && event.modifiers == Qt.ControlModifier){
+ saveButtonClicked()
+ }
+ if (event.key == Qt.Key_T && event.modifiers == Qt.ControlModifier){
+ addButtonClicked()
+ }
+ if ((event.key == Qt.Key_Space) && currentIndex >= 0){
+ dictModel.setModelProperty(dictList.currentIndex, "isSelected")
+ }
+ }
+
+ onCurrentIndexChanged: {
+ dictModel.itemSelected(dictList.currentIndex)
+ }
+
+ delegate: Component{
+ id: dictListDelegate
+ Item {
+ width: rectangle1.width
+ height: {
+ if (nameText.height + 4 > logo.height)
+ return nameText.height + 4;
+ else
+ return logo.height;
+ }
+ MouseArea{
+ anchors.fill: parent
+ onClicked: {
+ dictList.currentIndex = number
+ rectangle1.setEnableRemove(true)
+ rectangle1.setEnableSettings(true)
+ }
+ onDoubleClicked: {
+ rectangle1.itemActivated(dictList.currentIndex)
+ }
+ }
+ Row {
+ anchors.fill: parent
+ Checkbox{
+ id: check
+ width: nameText.height
+ selected: isSelected
+ onChanged: rectangle1.changeDictionaryState(number, selected)
+ }
+
+
+ Image {
+ id: logo
+ source: iconPath
+ height: {
+ var aspectRatio = sourceSize.height / sourceSize.width
+ return logo.width * aspectRatio
+ }
+ anchors.leftMargin: 5
+ anchors.verticalCenter: parent.verticalCenter
+ width: nameText.height + 4
+ smooth: true
+ }
+ Text {
+ id: nameText
+ text: name
+ anchors.leftMargin: 5
+ anchors.verticalCenter: parent.verticalCenter
+ }
+ }
+ }
+
+ }
+ model: dictModel
+ }
+
+ //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: 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: 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: 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: saveButtonClicked()
+ }
+
+ }
+
}