gui/DictManagerWidget.cpp \
gui/DictTypeSelectDialog.cpp \
backbone/History.cpp \
- gui/HistoryListDialog.cpp
+ gui/HistoryListDialog.cpp \
+ gui/WordListItem.cpp
HEADERS += gui/MainWindow.h \
gui/SearchBarWidget.h \
gui/TranslationWidgetAutoResizer.h \
../includes/History.h \
gui/HistoryListDialog.h \
- ../includes/GUIInterface.h
+ ../includes/GUIInterface.h \
+ gui/WordListItem.h
FORMS += gui/MainWindow.ui
setExactSearch(false);
setWindowTitle("mDictionary");
+
+ showMaximized();
}
MainWindow::~MainWindow() {
--- /dev/null
+/*******************************************************************************
+
+ 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.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "WordListItem.h"
+#include <QDebug>
+
+WordListItem::WordListItem(QString text, QWidget *parent) :
+ QWidget(parent)
+{
+ label = new QLabel(text);
+ button = new QToolButton;
+
+ layout = new QHBoxLayout;
+ setLayout(layout);
+
+ initializeUI();
+
+}
+
+
+
+void WordListItem::initializeUI() {
+
+
+ layout->addWidget(label);
+
+ #ifdef Q_WS_MAEMO_5
+ setMaximumHeight(75);
+ setMinimumHeight(75);
+ #else
+ setMaximumHeight(50);
+ setMinimumHeight(50);
+ #endif
+ _selected = false;
+
+
+ layout->addWidget(button,0, Qt::AlignRight);
+}
+
+void WordListItem::unselect() {
+ if(_selected) {
+ _selected = false;
+ update();
+ }
+}
+
+
+QString WordListItem::text() {
+ return label->text();
+}
+
+void WordListItem::mousePressEvent(QMouseEvent *e) {
+ if(e->button() == Qt::LeftButton) {
+ _selected = true;
+ update();
+ emit selected(label->text());
+ }
+}
+
+void WordListItem::mouseReleaseEvent(QMouseEvent *e) {
+ if(e->button() == Qt::LeftButton) {
+ if(e->y() != -1000)
+ emit clicked(label->text());
+ }
+}
+
+void WordListItem::paintEvent(QPaintEvent *e) {
+ QPainter p(this);
+
+ if(_selected) {
+ p.fillRect(e->rect(), palette().highlight());
+ }
+ else {
+ p.fillRect(e->rect(), palette().background());
+ }
+
+ //p.drawRect(e->rect());
+
+ QWidget::paintEvent(e);
+}
--- /dev/null
+/*******************************************************************************
+
+ 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.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef WORDLISTITEM_H
+#define WORDLISTITEM_H
+
+#include <QWidget>
+#include <QtGui>
+
+class WordListItem : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit WordListItem(QString text, QWidget *parent = 0);
+ void unselect();
+ QString text();
+
+Q_SIGNALS:
+ void clicked(QString text);
+ void selected(QString text);
+
+protected:
+ void mousePressEvent(QMouseEvent *);
+ void mouseReleaseEvent(QMouseEvent *);
+ void paintEvent(QPaintEvent *);
+
+private:
+ QLabel* label;
+ QIcon* icon;
+ QToolButton* button;
+ QHBoxLayout* layout;
+ bool _selected;
+
+ void initializeUI();
+};
+
+#endif // WORDLISTITEM_H
#include "../../includes/translation.h"
#include <QMultiHash>
+
#ifdef Q_WS_MAEMO_5
#include <QMaemo5InformationBox>
#endif
WordListWidget::WordListWidget(QWidget *parent):
- QListView(parent) {
+ QScrollArea(parent) {
- wordListModel = new QStringListModel();
- connect(this, SIGNAL(clicked(QModelIndex)),
- this, SLOT(itemClicked(QModelIndex)));
+ QWidget* w = new QWidget;
+ layout = new QVBoxLayout(w);
+ setWidget(w);
+ setWidgetResizable(true);
+ setMinimumWidth(300);
- setModel(wordListModel);
}
void WordListWidget::addWord(QString word) {
- int wordsCount = wordListModel->rowCount();
-
- wordListModel->insertRow(wordsCount);
+ WordListItem* w = new WordListItem(word);
+ layout->addWidget(w);
+ items.append(w);
- QModelIndex newWordIndex = wordListModel->index(wordsCount);
-
- wordListModel->setData(newWordIndex, word);
+ connect(w, SIGNAL(clicked(QString)),
+ this, SLOT(itemClicked(QString)));
+ connect(w, SIGNAL(selected(QString)),
+ this, SLOT(itemSelected(QString)));
}
void WordListWidget::clear() {
- int wordsCount = wordListModel->rowCount();
-
+ int wordsCount = items.count();
for(int i = 0; i < wordsCount; i++) {
- wordListModel->removeRow(0);
+ delete items.at(i);
}
+ items.clear();
}
void WordListWidget::showSearchResults(
addWord(i.key());
}
- wordListModel->sort(0, Qt::AscendingOrder);
-
- scrollTo(model()->index(0,0));
+}
+void WordListWidget::itemClicked(QString key) {
+ emit showTranslation(searchResult[key]);
}
-void WordListWidget::itemClicked(QModelIndex index) {
- emit showTranslation(searchResult[index.model()->data(index).toString()]);
+void WordListWidget::itemSelected(QString key) {
+ for(int i = 0; i < items.count(); i++) {
+ if(items.at(i)->text() != key)
+ items.at(i)->unselect();
+ }
}
void WordListWidget::lockList() {
#include <QStringListModel>
#include "../backbone/backbone.h"
#include "SearchBarWidget.h"
+#include "WordListItem.h"
//! Displays list of words found in dictionaries
/*!
It allow user to select word to see it's translation or to mark it as "star"
*/
-class WordListWidget : public QListView {
+class WordListWidget : public QScrollArea {
Q_OBJECT
public:
explicit WordListWidget(QWidget *parent = 0);
private Q_SLOTS:
- void itemClicked(QModelIndex index);
+ void itemClicked(QString key);
+ void itemSelected(QString key);
private:
//Backbone *backbone;
//words are keeping as QStringListModel which allow to sort them
- QStringListModel *wordListModel;
+ //QStringListModel *wordListModel;
void addWord(QString word);
//clears all list of words
void clear();
QHash<QString, QList<Translation*> > searchResult;
+ QList<WordListItem*> items;
+
+ QVBoxLayout* layout;
//QString _exactMatchString;
};