Changed word list widget to use qtreeview
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 17 Aug 2010 11:21:44 +0000 (13:21 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 17 Aug 2010 11:21:44 +0000 (13:21 +0200)
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/SearchBarWidget.h
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/TranslationWidget.h
trunk/src/base/gui/WordListWidget.cpp
trunk/src/base/gui/WordListWidget.h

index 5d1a9e3..e67ce7c 100644 (file)
@@ -32,6 +32,10 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     GUIInterface(parent),
     ui(new Ui::MainWindow) {
 
+    #ifdef Q_WS_MAEMO_5
+        setAttribute(Qt::WA_Maemo5StackedWindow);
+    #endif
+
     this->backbone = backbone;
 
     initializeUI();
@@ -58,10 +62,9 @@ MainWindow::~MainWindow() {
 void MainWindow::initializeUI() {
     ui->setupUi(this);
 
+    //showFullScreen();
     //sets attribute to maemo's stacked window
-    #ifdef Q_WS_MAEMO_5
-        setAttribute(Qt::WA_Maemo5StackedWindow);
-    #endif
+
 
 
     searchBarWidget = new SearchBarWidget;
index ee9fca7..4731d6e 100644 (file)
@@ -110,14 +110,14 @@ void SearchBarWidget::initializeUI() {
 
 
     searchPushButton = new QPushButton(tr("Search"));
-    searchPushButton->setMinimumWidth(150);
+    searchPushButton->setMinimumWidth(125);
     #ifndef Q_WS_MAEMO_5
         searchPushButton->setMinimumHeight(
                 searchPushButton->sizeHint().height()*2);
     #endif
 
     searchWordLineEdit = new QLineEdit();
-    searchWordLineEdit->setMinimumWidth(300);
+    searchWordLineEdit->setMinimumWidth(250);
 
     #ifndef Q_WS_MAEMO_5
         searchWordLineEdit->setMinimumHeight(
@@ -185,6 +185,18 @@ void SearchBarWidget::initializeUI() {
                 clearSearchWordToolButton->sizeHint().height()*2);
     #endif
 
+    fullScreenToolButton = new QToolButton();
+    #ifdef Q_WS_MAEMO_5
+        fullScreenToolButton->setIcon(
+                generateIcon(QIcon::fromTheme("general_fullsize")));
+    #else
+        fullScreenToolButton->setIcon(
+                generateIcon(QIcon::fromTheme("view-fullscreen")));
+        fullScreenToolButton->setMinimumSize(
+                fullScreenToolButton->sizeHint().height()*2,
+                fullScreenToolButton->sizeHint().height()*2);
+    #endif
+
 
     searchingProgressBar = new QProgressBar();
     //progress bar have minimum and maximum values set to 0, which will effect
@@ -207,6 +219,7 @@ void SearchBarWidget::initializeUI() {
     horizontalLayout->addWidget(historyPrevToolButton);
     horizontalLayout->addWidget(historyShowToolButton);
     horizontalLayout->addWidget(historyNextToolButton);
+    horizontalLayout->addWidget(fullScreenToolButton);
 
     //adding clear toolButton to textEdit with right alignment
     lineEditLayout->addWidget(clearSearchWordToolButton, 0,
index 2bf1ee0..1172d7b 100644 (file)
@@ -117,6 +117,7 @@ private:
     QToolButton* historyPrevToolButton;
     QToolButton* historyNextToolButton;
     QToolButton* historyShowToolButton;
+    QToolButton* fullScreenToolButton;
     QHBoxLayout* horizontalLayout;
     QProgressBar* searchingProgressBar;
 
index 22c55c0..7befd4c 100644 (file)
@@ -44,6 +44,7 @@ void TranslationWidget::show() {
 }
 
 void TranslationWidget::show(QStringList translations) {
+
     show();
 
     textEdit->clear();
@@ -102,5 +103,31 @@ void TranslationWidget::initializeUI() {
     connect(zoomInToolButton, SIGNAL(clicked()),
             this, SIGNAL(updateSize()));
 
+   /* #ifdef Q_WS_MAEMO_5
+        fullScreenButton = new QToolButton(this);
+        fullScreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
+        fullScreenButton->setMinimumSize(fullScreenButton->sizeHint());
+        int x = QApplication::desktop()->screenGeometry(this).width()  -
+                fullScreenButton->sizeHint().width();
+        int y = QApplication::desktop()->screenGeometry(this).height() -
+                fullScreenButton->sizeHint().height();
+        fullScreenButton->move(QPoint(x,y));
+        fullScreenButton->show();
+        fullScreenButton->setWindowOpacity(0.5);
+
+
+        backButton = new QToolButton(this);
+        backButton->setIcon(QIcon::fromTheme("general_overlay_back"));
+        backButton->setMinimumSize(fullScreenButton->sizeHint());
+        x = QApplication::desktop()->screenGeometry(this).width()  -
+                backButton->sizeHint().width();
+        y = 0;
+        backButton->move(QPoint(x,y));
+        backButton->show();
+        backButton->setWindowOpacity(0.5);
+
+        connect(backButton, SIGNAL(clicked()),
+                this, SLOT(hide()));
+    #endif*/
 }
 
index 0b8f058..957f243 100644 (file)
@@ -55,6 +55,10 @@ private:
     QTextEdit *textEdit;
     QToolButton* zoomInToolButton;
     QToolButton* zoomOutToolButton;
+    #ifdef Q_WS_MAEMO_5
+        QToolButton* fullScreenButton;
+        QToolButton* backButton;
+    #endif
     QVBoxLayout *verticalLayout;
     QHBoxLayout* horizontalLayout;
     TranslationWidgetAutoResizer* resizer;
index d03b9a1..360d423 100644 (file)
 #endif
 
 WordListWidget::WordListWidget(QWidget *parent):
-    QListWidget(parent) {
+    QTreeView(parent) {
 
-    connect(this, SIGNAL(itemPressed(QListWidgetItem*)),
-            this, SLOT(wordPressed(QListWidgetItem*)));
+    model = new QStandardItemModel(this);
+    setModel(model);
+    setHeaderHidden(true);
+    setRootIsDecorated(false);
 
-
-    connect(this, SIGNAL(itemClicked(QListWidgetItem*)),
-            this, SLOT(wordClicked(QListWidgetItem*)));
+    #ifdef Q_WS_MAEMO_5
+        checkBoxWidth = 70;
+    #else
+        checkBoxWidth = 25;
+    #endif
 
 
     setStyle(new WordListProxyStyle);
 
-    setLayoutDirection(Qt::RightToLeft);
-
 }
 
-void WordListWidget::addWord(QString word) {
-    QListWidgetItem* item = new QListWidgetItem(word, this);
-    item->setCheckState(Qt::Unchecked);
-    item->setTextAlignment(Qt::AlignRight);
+void WordListWidget::addWord(QString word, int row) {
+    QStandardItem* item = new QStandardItem(word);
+    item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+    QStandardItem* itemCheckBox = new QStandardItem();
+    itemCheckBox->setFlags(itemCheckBox->flags() ^ Qt::ItemIsEditable |
+                           Qt::ItemIsUserCheckable);
+    itemCheckBox->setCheckState(Qt::Checked);
+
+    model->setItem(row,0, item);
+    model->setItem(row,1, itemCheckBox);
 }
 
 
 void WordListWidget::showSearchResults(
         QHash<QString, QList<Translation *> > result) {
-    clear();
+    model->clear();
     searchResult.clear();
 
+    model->setColumnCount(2);
+    model->setRowCount(result.count());
+
     searchResult = result;
+    int row=0;
     QHash<QString, QList<Translation*> >::iterator i;
     for(i = result.begin(); i != result.end(); i++) {
-           addWord(i.key());
+           addWord(i.key(), row++);
     }
+
+    qDebug()<<width();
+    setColumnWidth(0, width()-checkBoxWidth - 20);
+    setColumnWidth(1, checkBoxWidth);
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+}
+
+void WordListWidget::wordClicked(QModelIndex index) {
+    emit showTranslation(
+            searchResult[index.data().toString()]);
 }
 
-void WordListWidget::wordClicked(QListWidgetItem *item) {
-    if(itemState == item->checkState()) {
-        emit showTranslation(
-                searchResult[item->data(Qt::DisplayRole).toString()]);
+void WordListWidget::wordChecked(QModelIndex index) {
+    Qt::CheckState state =
+            Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
+
+     QModelIndex item = selectedIndexes().at(0);
+
+    if(state == Qt::Checked) {
+        qDebug()<<"Added  "<<item.data().toString();
+        emit addBookmark(searchResult[item.data().toString()]);
     }
     else {
-        if(item->checkState() == Qt::Checked) {
-            emit addBookmark(
-                    searchResult[item->data(Qt::DisplayRole).toString()]);
-        }
-        else {
-            emit removeBookmark(
-                    searchResult[item->data(Qt::DisplayRole).toString()]);
-        }
+        qDebug()<<"Removed  "<<item.data().toString();
+        emit removeBookmark(searchResult[item.data().toString()]);
     }
 }
 
-void WordListWidget::wordPressed(QListWidgetItem *item) {
-    itemState = item->checkState();
+
+void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
+    QTreeView::mouseReleaseEvent(event);
+
+
+    QModelIndex index = indexAt(event->pos());
+    int c = index.column();
+    if(c==0)
+        wordClicked(index);
+    else
+        wordChecked(index);
 }
 
+void WordListWidget::resizeEvent(QResizeEvent *event) {
+    setColumnWidth(0, width()-checkBoxWidth - 20);
+    setColumnWidth(1, checkBoxWidth);
+    QTreeView::resizeEvent(event);
+}
 
 void WordListWidget::lockList() {
     setEnabled(false);
index f368653..51e7c73 100644 (file)
 /*!
     It allow user to select word to see it's translation or to mark it as "star"
   */
-class WordListWidget : public QListWidget {
+class WordListWidget : public QTreeView {
     Q_OBJECT
 public:
     explicit WordListWidget(QWidget *parent = 0);
 
+
 Q_SIGNALS:
     //! Request to show translation which is described by passed translations
     //! objects
@@ -63,12 +64,18 @@ public Q_SLOTS:
     //! Unlocks words list
     void unlockList();
 
+protected:
+    void mouseReleaseEvent(QMouseEvent *event);
+    void resizeEvent(QResizeEvent *event);
+
 private Q_SLOTS:
-    void wordClicked(QListWidgetItem* item);
-    void wordPressed(QListWidgetItem* item);
+    void wordClicked(QModelIndex index);
+    void wordChecked(QModelIndex index);
 
 private:
-    void addWord(QString word);
+    void addWord(QString word, int row);
+    QStandardItemModel* model;
+    int checkBoxWidth;
 
     Qt::CheckState itemState;
     QHash<QString, QList<Translation*> > searchResult;