gui/DictTypeSelectDialog.cpp \
backbone/History.cpp \
gui/HistoryListDialog.cpp \
- gui/WordListItem.cpp
+ gui/WordListProxyStyle.cpp
HEADERS += gui/MainWindow.h \
gui/SearchBarWidget.h \
../includes/History.h \
gui/HistoryListDialog.h \
../includes/GUIInterface.h \
- gui/WordListItem.h
+ gui/WordListProxyStyle.h
FORMS += gui/MainWindow.ui
icon64.path = $$DATADIR/icons/hicolor/64x64/hildon
}
-unix {
+!maemo5 {
desktop.path = $$DATADIR/applications
icon64.path = $$DATADIR/icons
}
desktop.files += ../../../data/other/$${TARGET}.desktop
icon64.files += ../../../data/icons/64x64/$${TARGET}.png
}
+
+RESOURCES += \
+ gui/gui.qrc
searchBarWidget = new SearchBarWidget;
+
wordListWidget = new WordListWidget;
//translationWidget is antoher stacked window, so we don't add it to layout
+++ /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
--- /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 "WordListProxyStyle.h"
+
+
+WordListProxyStyle::WordListProxyStyle() :
+ QProxyStyle()
+{
+ starPixmapOn = QPixmap(":/icons/staron.png");
+ starPixmapOff = QPixmap(":/icons/staroff.png");
+}
+
+
+void WordListProxyStyle::drawPrimitive(PrimitiveElement element,
+ const QStyleOption *option,
+ QPainter *painter,
+ const QWidget *widget) const {
+ if(element == PE_IndicatorCheckBox) {
+ if(option->state & QStyle::State_On)
+ painter->drawPixmap(option->rect, starPixmapOn);
+ else
+ painter->drawPixmap(option->rect, starPixmapOff);
+ }
+ else {
+ QProxyStyle::drawPrimitive(element, option, painter, widget);
+ }
+}
+
+
--- /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 WORDLISTPROXYSTYLE_H
+#define WORDLISTPROXYSTYLE_H
+
+#include <QProxyStyle>
+#include <QtGui>
+
+class WordListProxyStyle : public QProxyStyle
+{
+public:
+ WordListProxyStyle();
+ void drawPrimitive(PrimitiveElement element,
+ const QStyleOption *option,
+ QPainter *painter,
+ const QWidget *widget) const;
+
+private:
+ QPixmap starPixmapOn;
+ QPixmap starPixmapOff;
+};
+
+#endif // WORDLISTPROXYSTYLE_H
#include <QDebug>
#include "../../includes/translation.h"
#include <QMultiHash>
+#include "WordListProxyStyle.h"
#ifdef Q_WS_MAEMO_5
#endif
WordListWidget::WordListWidget(QWidget *parent):
- QScrollArea(parent) {
+ QListWidget(parent) {
+ connect(this, SIGNAL(itemPressed(QListWidgetItem*)),
+ this, SLOT(wordPressed(QListWidgetItem*)));
- QWidget* w = new QWidget;
- layout = new QVBoxLayout(w);
- setWidget(w);
- setWidgetResizable(true);
- setMinimumWidth(300);
+ connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
+ this, SLOT(wordClicked(QListWidgetItem*)));
-}
-void WordListWidget::addWord(QString word) {
- WordListItem* w = new WordListItem(word);
- layout->addWidget(w);
- items.append(w);
+ setStyle(new WordListProxyStyle);
- connect(w, SIGNAL(clicked(QString)),
- this, SLOT(itemClicked(QString)));
+ setLayoutDirection(Qt::RightToLeft);
- connect(w, SIGNAL(selected(QString)),
- this, SLOT(itemSelected(QString)));
}
-void WordListWidget::clear() {
- int wordsCount = items.count();
- for(int i = 0; i < wordsCount; i++) {
- delete items.at(i);
- }
- items.clear();
+void WordListWidget::addWord(QString word) {
+ QListWidgetItem* item = new QListWidgetItem(word, this);
+ item->setCheckState(Qt::Unchecked);
+ item->setTextAlignment(Qt::AlignRight);
}
+
void WordListWidget::showSearchResults(
- QHash<QString, QList<Translation *> > result) {
+ QHash<QString, QList<Translation *> > result) {
clear();
searchResult.clear();
for(i = result.begin(); i != result.end(); i++) {
addWord(i.key());
}
-
}
-void WordListWidget::itemClicked(QString key) {
- emit showTranslation(searchResult[key]);
+void WordListWidget::wordClicked(QListWidgetItem *item) {
+ if(itemState == item->checkState()) {
+ emit showTranslation(
+ searchResult[item->data(Qt::DisplayRole).toString()]);
+ }
+ else {
+ qDebug()<<"edited";
+ }
}
-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::wordPressed(QListWidgetItem *item) {
+ itemState = item->checkState();
}
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 QScrollArea {
+class WordListWidget : public QListWidget {
Q_OBJECT
public:
explicit WordListWidget(QWidget *parent = 0);
//! Unlocks words list
void unlockList();
-
private Q_SLOTS:
- void itemClicked(QString key);
- void itemSelected(QString key);
+ void wordClicked(QListWidgetItem* item);
+ void wordPressed(QListWidgetItem* item);
private:
- //Backbone *backbone;
- //words are keeping as QStringListModel which allow to sort them
- //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;
+ Qt::CheckState itemState;
+ QHash<QString, QList<Translation*> > searchResult;
};
#endif // WORDLISTWIDGET_H
--- /dev/null
+<RCC>
+ <qresource prefix="/icons">
+ <file>staroff.png</file>
+ <file>staron.png</file>
+ </qresource>
+</RCC>