Fixed welcome screen layout
[mdictionary] / trunk / src / base / gui / WordListWidget.cpp
index fed3397..60cf791 100644 (file)
@@ -1,3 +1,4 @@
+
 /*******************************************************************************
 
     This file is part of mDictionary.
@@ -39,16 +40,15 @@ WordListWidget::WordListWidget(QWidget *parent):
     setModel(model);
     setHeaderHidden(true);
     setRootIsDecorated(false);
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+    setStyle(new WordListProxyStyle);
 
     #ifdef Q_WS_MAEMO_5
         checkBoxWidth = 70;
     #else
         checkBoxWidth = 25;
     #endif
-
-
-    setStyle(new WordListProxyStyle);
-
 }
 
 void WordListWidget::addWord(QString word, int row) {
@@ -92,9 +92,8 @@ void WordListWidget::showSearchResults(
            addWord(i.key(), row++);
     }
 
-    setColumnWidth(0, width()-checkBoxWidth - 20);
-    setColumnWidth(1, checkBoxWidth);
-    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    resizeColumns();
+    model->sort(0);
 }
 
 void WordListWidget::wordClicked(QModelIndex index) {
@@ -106,14 +105,16 @@ void WordListWidget::wordChecked(QModelIndex index) {
     Qt::CheckState state =
             Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
 
-     QModelIndex item = selectedIndexes().at(0);
+    if(selectedIndexes().count()==0) return;
+    QModelIndex item = selectedIndexes().at(0);
+    if(!item.isValid()) return;
+
+    repaint();
 
     if(state == Qt::Checked) {
-        qDebug()<<"Added  "<<item.data().toString();
         emit addBookmark(searchResult[item.data().toString()]);
     }
     else {
-        qDebug()<<"Removed  "<<item.data().toString();
         emit removeBookmark(searchResult[item.data().toString()]);
     }
 }
@@ -125,6 +126,11 @@ void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
 
     QModelIndex index = indexAt(event->pos());
     if(!index.isValid()) return;
+    if(selectedIndexes().count() == 0) return;
+
+    if(selectedIndexes().at(0) != index && selectedIndexes().at(1) != index)
+        return;
+
     int c = index.column();
     if(c==0)
         wordClicked(index);
@@ -133,11 +139,15 @@ void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
 }
 
 void WordListWidget::resizeEvent(QResizeEvent *event) {
-    setColumnWidth(0, width()-checkBoxWidth - 20);
-    setColumnWidth(1, checkBoxWidth);
+    resizeColumns();
     QTreeView::resizeEvent(event);
 }
 
+void WordListWidget::resizeColumns() {
+    setColumnWidth(0, viewport()->width() -checkBoxWidth - 20);
+    setColumnWidth(1, checkBoxWidth);
+}
+
 void WordListWidget::lockList() {
     setEnabled(false);
 }