Fixed scrolling in translation widget
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 10 Aug 2010 09:42:52 +0000 (11:42 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Tue, 10 Aug 2010 09:42:52 +0000 (11:42 +0200)
trunk/src/base/base.pro
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/MainWindow.h
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/TranslationWidgetAutoResizer.h [new file with mode: 0644]
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.cpp

index 26389d1..08d6172 100644 (file)
@@ -39,7 +39,8 @@ HEADERS  += gui/MainWindow.h \
     gui/MenuWidget.h \
     gui/MenuTabWidget.h \
     gui/DictManagerWidget.h \
-    gui/DictTypeSelectDialog.h
+    gui/DictTypeSelectDialog.h \
+    gui/TranslationWidgetAutoResizer.h
 
 FORMS    += gui/MainWindow.ui
 
index 69d575a..b764849 100644 (file)
@@ -77,7 +77,8 @@ void DictManagerWidget::refreshDictsList() {
 
     dictListWidget->clear();
     dictsHash.clear();
-
+    removeDictButton->setEnabled(false);
+    settingsButton->setEnabled(false);
 
     QHash<CommonDictInterface*, bool> dicts = backbone->getDictionaries();
 
@@ -107,8 +108,6 @@ void DictManagerWidget::refreshDictsList() {
 void DictManagerWidget::showEvent(QShowEvent *e) {
 
     refreshDictsList();
-    removeDictButton->setEnabled(false);
-    settingsButton->setEnabled(false);
     QWidget::showEvent(e);
 }
 
@@ -144,7 +143,7 @@ void DictManagerWidget::addNewDictButtonClicked() {
     }
 }
 
-void DictManagerWidget::itemSelected(QListWidgetItem *item) {
+void DictManagerWidget::itemSelected(QListWidgetItem *) {
     removeDictButton->setEnabled(true);
     settingsButton->setEnabled(true);
 }
index 7e673d8..4427411 100644 (file)
@@ -40,6 +40,8 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
     searchBarWidget = new SearchBarWidget(backbone);
     wordListWidget = new WordListWidget(backbone);
     translationWidget = new TranslationWidget(backbone, this);
+
+    searchBarWidget->setFocus();
     menuWidget = new MenuWidget(this);
 
 
@@ -50,9 +52,13 @@ MainWindow::MainWindow(Backbone *backbone, QWidget *parent):
 
     ui->menuBar->addAction(menuWidget);
 
+
     connect(this, SIGNAL(searchWordList(QStringList)),
             searchBarWidget, SLOT(searchWordList(QStringList)));
 
+    connect(searchBarWidget, SIGNAL(enableMenu(bool)),
+            this, SLOT(enableMenu(bool)));
+
     connect(wordListWidget, SIGNAL(showTranslation(QList<Translation*>)),
             translationWidget, SLOT(show(QList<Translation*>)));
 
@@ -90,3 +96,8 @@ void MainWindow::closeOk() {
 void MainWindow::search(QStringList words) {
     emit searchWordList(words);
 }
+
+void MainWindow::enableMenu(bool enabled) {
+    ui->menuBar->setVisible(enabled);
+    qDebug()<<enabled;
+}
index eb9b999..57091f9 100644 (file)
@@ -60,6 +60,8 @@ protected:
     */
     void closeEvent(QCloseEvent *);
 
+private Q_SLOTS:
+    void enableMenu(bool);
 
 private:
     Backbone* backbone;
index 168b968..3165837 100644 (file)
@@ -41,6 +41,9 @@ SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
     connect(searchPushButton, SIGNAL(clicked()),
             this, SLOT(searchPushButtonClicked()));
 
+    connect(searchWordLineEdit, SIGNAL(returnPressed()),
+            this, SLOT(searchPushButtonClicked()));
+
     connect(historyNextToolButton, SIGNAL(clicked()),
             this, SLOT(historyNextToolButtonClicked()));
 
@@ -64,6 +67,7 @@ SearchBarWidget::SearchBarWidget(Backbone* backbone, QWidget *parent) :
     connect(backbone, SIGNAL(ready()),
             this, SLOT(searchFinished()));
 
+    searchWordLineEdit->setFocus();
 }
 
 SearchBarWidget::~SearchBarWidget() {
@@ -76,12 +80,13 @@ void SearchBarWidget::initializeUI() {
     verticalLayout = new QVBoxLayout();
 
 
+
     searchPushButton = new QPushButton(tr("Search"));
-    searchPushButton->setMinimumWidth(200);
+    searchPushButton->setMinimumWidth(150);
 
 
     searchWordLineEdit = new QLineEdit();
-    searchWordLineEdit->setMinimumWidth(350);
+    searchWordLineEdit->setMinimumWidth(300);
     //create layout for lineEdit to have clear button on it
     QHBoxLayout* lineEditLayout = new QHBoxLayout;
     searchWordLineEdit->setLayout(lineEditLayout);
@@ -97,23 +102,23 @@ void SearchBarWidget::initializeUI() {
 
     historyNextToolButton = new QToolButton();
     historyNextToolButton->setIcon(QIcon::fromTheme("general_forward"));
-    historyNextToolButton->setMaximumSize(
+   /* historyNextToolButton->setMaximumSize(
             historyNextToolButton->sizeHint().width()/2,
-            historyNextToolButton->sizeHint().height()/2);
+            historyNextToolButton->sizeHint().height()/2);*/
 
 
     historyPrevToolButton = new QToolButton();
     historyPrevToolButton->setIcon(QIcon::fromTheme("general_back"));
-    historyPrevToolButton->setMaximumSize(
+    /*historyPrevToolButton->setMaximumSize(
             historyPrevToolButton->sizeHint().width()/2,
-            historyPrevToolButton->sizeHint().height()/2);
+            historyPrevToolButton->sizeHint().height()/2);*/
 
 
     historyShowToolButton = new QToolButton();
     historyShowToolButton->setIcon(QIcon::fromTheme("general_back"));
-    historyShowToolButton->setMaximumSize(
+    /*historyShowToolButton->setMaximumSize(
             historyShowToolButton->sizeHint().width()/2,
-            historyShowToolButton->sizeHint().height()/2);
+            historyShowToolButton->sizeHint().height()/2);*/
 
     QPixmap p = historyShowToolButton->icon().pixmap(256);
     QMatrix m;
@@ -151,6 +156,8 @@ void SearchBarWidget::initializeUI() {
                               Qt::AlignRight | Qt::AlignVCenter);
 
     verticalLayout->addLayout(horizontalLayout);
+
+
 }
 
 
@@ -159,6 +166,7 @@ void SearchBarWidget::searchPushButtonClicked() {
         searchingProgressBar->hide();
         searchPushButton->setText(tr("Search"));
         setEnabled(true);
+        emit enableMenu(true);
         _isSearching = false;
         emit stopSearching();
     }
@@ -166,6 +174,7 @@ void SearchBarWidget::searchPushButtonClicked() {
         searchingProgressBar->show();
         searchPushButton->setText(tr("Stop"));
         setEnabled(false);
+        emit enableMenu(false);
         _isSearching = true;
         QStringList searchWord;
         searchWord << searchWordLineEdit->text();
@@ -178,6 +187,7 @@ void SearchBarWidget::searchWordList(QStringList words) {
         searchingProgressBar->show();
         searchPushButton->setText(tr("Stop"));
         setEnabled(false);
+        emit enableMenu(false);
         _isSearching = true;
         emit searchForTranslations(words);
     }
@@ -195,13 +205,12 @@ void SearchBarWidget::searchFinished() {
         searchingProgressBar->hide();
         searchPushButton->setText(tr("Search"));
         setEnabled(true);
+        emit enableMenu(true);
         _isSearching = false;
 }
 
 void SearchBarWidget::historyNextToolButtonClicked() {
 
-    CommonDictInterface*p = backbone->getPlugins()[0];
-    p->dictDialog()->addNewDictionary(this);
 }
 
 void SearchBarWidget::historyPrevToolButtonClicked() {
index 0c7ca2d..09fade5 100644 (file)
@@ -52,6 +52,8 @@ Q_SIGNALS:
     //! Request to stop all active searchings
     void stopSearching();
 
+    void enableMenu(bool);
+
 public Q_SLOTS:
     //! Enable or disable search word line edit and history buttons
     /*!
index 37fe4d3..25ef2d8 100644 (file)
 //Created by Mateusz Półrola
 
 #include "TranslationWidget.h"
+#include "TranslationWidgetAutoResizer.h"
 #include <QDebug>
 
 TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
-    QWidget(parent) {
+    QScrollArea(parent) {
 
     this->backbone = backbone;
 
@@ -37,15 +38,15 @@ TranslationWidget::TranslationWidget(Backbone *backbone, QWidget *parent):
 
     initializeUI();
 
-    connect(textEdit, SIGNAL(customContextMenuRequested(QPoint)),
-            this, SLOT(showContextMenu(QPoint)));
+   /* connect(textEdit, SIGNAL(customContextMenuRequested(QPoint)),
+            this, SLOT(showContextMenu(QPoint)));*/
 
     setWindowTitle(tr("Translation"));
 }
 
 
 void TranslationWidget::show() {
-    QWidget::show();
+    QScrollArea::show();
 }
 
 void TranslationWidget::show(QList<Translation*> translations) {
@@ -62,24 +63,30 @@ void TranslationWidget::show(QList<Translation*> translations) {
 
     textEdit->setPlainText(trans);
 
-    textEdit->repaint(this->rect());
+    textEdit->update(this->rect());
 
 }
 
 void TranslationWidget::initializeUI() {
-    contextMenu = new QMenu;
+    /*contextMenu = new QMenu;
 
     contextMenu->addAction(tr("Copy"), this, SLOT(copy()));
     contextMenu->addAction(tr("Paste"), this, SLOT(paste()));
-    contextMenu->addAction(tr("Select all"), this, SLOT(selectAll()));
+    contextMenu->addAction(tr("Select all"), this, SLOT(selectAll()));*/
 
     textEdit = new QTextEdit;
     textEdit->setReadOnly(true);
-    textEdit->setContextMenuPolicy(Qt::CustomContextMenu);
 
-    verticalLayout = new QVBoxLayout;
-    setLayout(verticalLayout);
+    new TranslationWidgetAutoResizer(textEdit);
+
+    QWidget*w = new QWidget;
+    verticalLayout = new QVBoxLayout(w);
     verticalLayout->addWidget(textEdit);
+
+    this->setWidget(w);
+    this->setWidgetResizable(true);
+
+
 }
 
 void TranslationWidget::showContextMenu(QPoint pos) {
index 5ad03fc..7755e3c 100644 (file)
@@ -33,7 +33,7 @@
 /*!
     Display many translation of word, formatted as html.
 */
-class TranslationWidget : public QWidget {
+class TranslationWidget : public QScrollArea {
     Q_OBJECT
 public:
     explicit TranslationWidget(Backbone* backbone, QWidget *parent = 0);
diff --git a/trunk/src/base/gui/TranslationWidgetAutoResizer.h b/trunk/src/base/gui/TranslationWidgetAutoResizer.h
new file mode 100644 (file)
index 0000000..c8768d2
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************
+
+    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 TRANSLATIONWIDGETAUTORESIZER_H
+#define TRANSLATIONWIDGETAUTORESIZER_H
+
+#include <QtGui/qtextedit.h>
+class TranslationWidgetAutoResizer : public QObject
+{
+    Q_OBJECT
+
+public:
+    TranslationWidgetAutoResizer(QWidget *parent) :QObject(parent),
+    textEdit(qobject_cast<QTextEdit* >((parent))),
+    edit(qobject_cast<QFrame* >((parent))) {
+
+     connect(parent, SIGNAL(textChanged()), this,
+             SLOT(textEditChanged()));
+     connect(parent, SIGNAL(cursorPositionChanged()),
+             this, SLOT(textEditChanged()));
+     }
+
+private Q_SLOTS:
+    inline void textEditChanged();
+
+private:
+    QTextEdit *textEdit;
+    QFrame *edit;
+};
+
+void TranslationWidgetAutoResizer::textEditChanged() {
+    QTextDocument *doc = textEdit->document();
+
+    QSize s = doc->size().toSize();
+
+    const QRect fr = edit->frameRect();
+    const QRect cr = edit->contentsRect();
+
+    edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
+                                1));
+}
+
+#endif // TRANSLATIONWIDGETAUTORESIZER_H
index c8d882e..be49470 100644 (file)
@@ -75,7 +75,7 @@ XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
     connect(saveButton, SIGNAL(clicked()),
             this, SLOT(accept()));
 
-    _dicitonaryFilePath = QString();
+    _dicitonaryFilePath = plugin->settings()->value("path");
 }
 
 void XdxfSettingsDialog::selectFile() {