00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef TRANSLATIONWIDGETAUTORESIZER_H
00026 #define TRANSLATIONWIDGETAUTORESIZER_H
00027
00028 #include <QtGui/qtextedit.h>
00029 class TranslationWidgetAutoResizer : public QObject
00030 {
00031 Q_OBJECT
00032
00033 public:
00034 TranslationWidgetAutoResizer(QWidget *parent) :QObject(parent),
00035 textEdit(qobject_cast<QTextEdit* >((parent))),
00036 edit(qobject_cast<QFrame* >((parent))) {
00037
00038 connect(parent, SIGNAL(textChanged()), this,
00039 SLOT(textEditChanged()));
00040 connect(parent, SIGNAL(cursorPositionChanged()),
00041 this, SLOT(textEditChanged()));
00042 }
00043
00044 public Q_SLOTS:
00045 inline void textEditChanged();
00046
00047 private:
00048 QTextEdit *textEdit;
00049 QFrame *edit;
00050 };
00051
00052 void TranslationWidgetAutoResizer::textEditChanged() {
00053 QTextDocument *doc = textEdit->document();
00054
00055 QSize s = doc->size().toSize();
00056
00057 const QRect fr = edit->frameRect();
00058 const QRect cr = edit->contentsRect();
00059
00060 edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
00061 1));
00062
00063 edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height()) -
00064 1));
00065 }
00066
00067 #endif // TRANSLATIONWIDGETAUTORESIZER_H