Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp	(revision 70645)
@@ -45,4 +45,6 @@
     , m_iSelectedBookmarkIndex(-1)
     , m_bFiltered(false)
+    , m_iFilteredLineCount(-1)
+    , m_iUnfilteredLineCount(-1)
     , m_bShowLineNumbers(true)
     , m_bWrapLines(false)
@@ -142,5 +144,5 @@
 }
 
-void UIVMLogPage::setTextEdit(const QString &strText)
+void UIVMLogPage::setTextEditText(const QString &strText)
 {
     if (!m_pTextEdit)
@@ -155,5 +157,5 @@
 }
 
-void UIVMLogPage::setTextEditAsHtml(const QString &strText)
+void UIVMLogPage::setTextEditTextAsHtml(const QString &strText)
 {
     if (!m_pTextEdit)
@@ -245,4 +247,5 @@
     if (m_pTextEdit)
         m_pTextEdit->setFocus();
+
     QWidget::showEvent(pEvent);
 }
@@ -311,2 +314,33 @@
     update();
 }
+
+void UIVMLogPage::setFilterParameters(const QSet<QString> &filterTermSet, int filterOperationType,
+                                      int iFilteredLineCount, int iUnfilteredLineCount)
+{
+    m_filterTermSet = filterTermSet;
+    m_filterOperationType = filterOperationType;
+    m_iFilteredLineCount = iFilteredLineCount;
+    m_iUnfilteredLineCount = iUnfilteredLineCount;
+}
+
+int  UIVMLogPage::filteredLineCount() const
+{
+    return m_iFilteredLineCount;
+}
+
+int  UIVMLogPage::unfilteredLineCount() const
+{
+    return m_iUnfilteredLineCount;
+}
+
+bool UIVMLogPage::shouldFilterBeApplied(const QSet<QString> &filterTermSet, int filterOperationType) const
+{
+    /* If filter terms set is different reapply the filter. */
+    if(filterTermSet != m_filterTermSet)
+        return true;
+
+    /* If filter operation type set is different reapply the filter. */
+    if(filterOperationType != m_filterOperationType)
+        return true;
+    return false;
+}
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.h	(revision 70645)
@@ -38,4 +38,6 @@
 typedef QPair<int, QString> LogBookmark;
 
+/** UIVMLogPage defines data and functionalities of the each tab page of a UIVMLogViewerWidget.
+    It stores the original log file content , a list of bookmarks, etc */
 class UIVMLogPage  : public QIWithRetranslateUI<QWidget>
 {
@@ -71,6 +73,6 @@
         show currently might be different than
         m_strLog. For example during filtering. */
-    void setTextEdit(const QString &strText);
-    void setTextEditAsHtml(const QString &strText);
+    void setTextEditText(const QString &strText);
+    void setTextEditTextAsHtml(const QString &strText);
 
     /** Marks the plain text edit When we dont have a log content. */
@@ -95,4 +97,15 @@
     void setShowLineNumbers(bool bShowLineNumbers);
     void setWrapLines(bool bWrapLines);
+
+    /** setFilterParameters is called at the end of filtering operation to store the parameter etc.
+        these parameters are used to decide whether we have to reapply the filter, and if not to
+        update filter panel with correct line counts etc.*/
+    void setFilterParameters(const QSet<QString> &filterTermSet, int filterOperationType,
+                             int iFilteredLineCount, int iUnfilteredLineCount);
+    int  filteredLineCount() const;
+    int  unfilteredLineCount() const;
+    /** Compares filter parameters with previous filter operation's parameters to decide if the
+        filter should be applied again. */
+    bool shouldFilterBeApplied(const QSet<QString> &filterTermSet, int filterOperationType) const;
 
 protected:
@@ -127,9 +140,23 @@
     /** Keeps the index of the selected bookmark. Used especially when moving from one tab to another. */
     int                  m_iSelectedBookmarkIndex;
-    /** Keeps the scrolled line number. Used when switching between tabs. */
-    int                  m_iScrolledLineNumber;
+
+    /** @name Filtering related state variables
+     * @{ */
     /** Designates whether currently displayed text is log text or a filtered version of it. That is
         if m_bFiltered is false than (m_strLog == m_pTextEdit->text()). */
-    bool m_bFiltered;
+        bool           m_bFiltered;
+        /** The set of filter terms used in the last filtering.
+            Used when deciding whether we have to reapply the filter or not. see shouldFilterBeApplied function. */
+        QSet<QString>  m_filterTermSet;
+        /** The type of the boolean last filtering operation. Used in deciding whether we have to reapply the
+            filter. see shouldFilterBeApplied function. This is int cast of enum FilterOperatorButton
+            of UIVMLogViewerFilterPanel. */
+        int            m_filterOperationType;
+        /** These counts are saveds and restored during filtering operation. If filter is not reapplied these counts
+            are shown in the filter panel. */
+        int            m_iFilteredLineCount;
+        int            m_iUnfilteredLineCount;
+    /** @} */
+
     bool m_bShowLineNumbers;
     bool m_bWrapLines;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.cpp	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.cpp	(revision 70645)
@@ -40,4 +40,5 @@
 # include "UIIconPool.h"
 # include "UISpecialControls.h"
+# include "UIVMLogPage.h"
 # include "UIVMLogViewerFilterPanel.h"
 # include "UIVMLogViewerWidget.h"
@@ -204,4 +205,19 @@
     if (!pCurrentTextEdit)
         return;
+
+    UIVMLogPage *logPage = viewer()->currentLogPage();
+    if(!logPage)
+        return;
+    /* Check if we have to reapply the filter. If not
+       restore line counts etc. and return */
+    if(!logPage->shouldFilterBeApplied(m_filterTermSet, (int)m_eFilterOperatorButton))
+    {
+        m_iFilteredLineCount = logPage->filteredLineCount();
+        m_iUnfilteredLineCount = logPage->unfilteredLineCount();
+        emit sigFilterApplied(!logPage->isFiltered() /* isOriginalLog */);
+        return;
+    }
+
+
     const QString* originalLogString = logString();
     m_iUnfilteredLineCount = 0;
@@ -214,9 +230,12 @@
     QStringList stringLines = originalLogString->split("\n");
     m_iUnfilteredLineCount = stringLines.size();
-    if (m_filterTermList.empty())
+
+    if (m_filterTermSet.empty())
     {
         document->setPlainText(*originalLogString);
         emit sigFilterApplied(true /* isOriginalLog */);
         m_iFilteredLineCount = document->lineCount();
+        logPage->setFilterParameters(m_filterTermSet, (int)m_eFilterOperatorButton,
+                                     m_iFilteredLineCount, m_iUnfilteredLineCount);
         return;
     }
@@ -246,4 +265,6 @@
 
     emit sigFilterApplied(false /* isOriginalLog */);
+    logPage->setFilterParameters(m_filterTermSet, (int)m_eFilterOperatorButton,
+                                 m_iFilteredLineCount, m_iUnfilteredLineCount);
 }
 
@@ -253,7 +274,10 @@
     /* Number of the filter terms contained with the @p string: */
     int hitCount = 0;
-    for (int i = 0; i < m_filterTermList.size(); ++i)
-    {
-        const QRegExp rxFilterExp(m_filterTermList.at(i), Qt::CaseInsensitive);
+
+    for(QSet<QString>::const_iterator iterator = m_filterTermSet.begin();
+        iterator != m_filterTermSet.end(); ++iterator)
+    {
+        const QString& filterTerm = *iterator;
+        const QRegExp rxFilterExp(filterTerm, Qt::CaseInsensitive);
         /* Disregard empty and invalid filter terms: */
         if (rxFilterExp.isEmpty() || !rxFilterExp.isValid())
@@ -273,5 +297,5 @@
     }
     /* All the terms are found within the @p string. To catch AND case: */
-    if (hitCount == m_filterTermList.size())
+    if (hitCount == m_filterTermSet.size())
         return true;
     return false;
@@ -287,7 +311,7 @@
 
     /* Continue only if the term is new. */
-    if (m_filterTermList.contains(m_pFilterComboBox->currentText()))
-        return;
-    m_filterTermList.push_back(m_pFilterComboBox->currentText());
+    if (m_filterTermSet.contains(m_pFilterComboBox->currentText()))
+        return;
+    m_filterTermSet.insert(m_pFilterComboBox->currentText());
 
     /* Add the new filter term to line edit: */
@@ -302,7 +326,7 @@
 void UIVMLogViewerFilterPanel::sltClearFilterTerms()
 {
-    if (m_filterTermList.empty())
-        return;
-    m_filterTermList.clear();
+    if (m_filterTermSet.empty())
+        return;
+    m_filterTermSet.clear();
     applyFilter();
     if (m_pFilterTermsLineEdit)
@@ -320,12 +344,5 @@
 void UIVMLogViewerFilterPanel::sltRemoveFilterTerm(const QString &termString)
 {
-    QStringList newList;
-    for (QStringList::iterator iterator = m_filterTermList.begin();
-        iterator != m_filterTermList.end(); ++iterator)
-    {
-        if ((*iterator) != termString)
-            newList.push_back(*iterator);
-    }
-    m_filterTermList = newList;
+    m_filterTermSet.remove(termString);
     applyFilter();
 }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.h	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.h	(revision 70645)
@@ -19,4 +19,6 @@
 #define ___UIVMLogViewerFilterPanel_h___
 
+/* Qt includes: */
+# include <QSet>
 
 /* GUI includes: */
@@ -84,5 +86,5 @@
 
     enum FilterOperatorButton{
-        AndButton = 0,
+        AndButton = 0,/* Don't change this value */
         OrButton,
         ButtonEnd
@@ -101,5 +103,5 @@
     QFrame              *m_pRadioButtonContainer;
     QIToolButton        *m_pAddFilterTermButton;
-    QStringList          m_filterTermList;
+    QSet<QString>        m_filterTermSet;
     FilterOperatorButton m_eFilterOperatorButton;
     UIVMFilterLineEdit  *m_pFilterTermsLineEdit;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPanel.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPanel.h	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPanel.h	(revision 70645)
@@ -42,7 +42,4 @@
     UIVMLogViewerPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer);
 
-
-public slots:
-
 protected:
 
@@ -70,9 +67,6 @@
     /* Return the unmodified log. */
     const QString* logString() const;
-private slots:
-
 
 private:
-
 
     /** Holds the reference to VM Log-Viewer this panel belongs to. */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp	(revision 70645)
@@ -74,9 +74,4 @@
     m_matchLocationVector.clear();
     m_iMatchCount = -1;
-    if (m_pHighlightAllCheckBox)
-    {
-        if (m_pHighlightAllCheckBox->checkState() == Qt::Checked)
-            m_pHighlightAllCheckBox->setCheckState(Qt::Unchecked);
-    }
     configureInfoLabels();
 }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp	(revision 70645)
@@ -162,4 +162,6 @@
     //setStyleSheet("background-color: rgba(240, 240, 240, 75%) ");
     prepare();
+
+
 }
 
@@ -186,9 +188,12 @@
     setWordWrapMode(QTextOption::NoWrap);
     setWordWrapMode(QTextOption::NoWrap);
+
     setReadOnly(true);
+
     /* Set colors to have a selection with bluebackground and white foreground: */
     QPalette mPalette = palette();
     mPalette.setColor(QPalette::Highlight, QColor(48, 140, 198, 255));
     mPalette.setColor(QPalette::HighlightedText, QColor(255, 255, 255, 255));
+    mPalette.setColor(QPalette::Text, QColor(0, 0, 0, 255));
     setPalette(mPalette);
 
@@ -311,7 +316,9 @@
 {
     QPlainTextEdit::resizeEvent(pEvent);
-
-    QRect cr = contentsRect();
-    m_pLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
+    if(m_pLineNumberArea)
+    {
+        QRect cr = contentsRect();
+        m_pLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
+    }
 }
 
@@ -319,5 +326,7 @@
 {
     setMouseCursorLine(lineNumberForPos(pEvent->pos()));
-    m_pLineNumberArea->repaint();
+    if(m_pLineNumberArea)
+        m_pLineNumberArea->repaint();
+    QPlainTextEdit::mouseMoveEvent(pEvent);
 }
 
@@ -326,5 +335,5 @@
     QPlainTextEdit::leaveEvent(pEvent);
     /* Force a redraw as mouse leaves this to remove the mouse
-       cursor track rectangle (the red rectangle we draw on the line number area. */
+       cursor track rectangle (the red rectangle we draw on the line number area). */
     update();
 }
@@ -371,7 +380,7 @@
         return;
 
+    moveCursor(QTextCursor::End);
     int halfPageLineCount = 0.5 * visibleLineCount() ;
     QTextCursor cursor(pDocument->findBlockByLineNumber(qMax(lineNumber - halfPageLineCount, 0)));
-    moveCursor(QTextCursor::End);
     setTextCursor(cursor);
 }
@@ -403,4 +412,5 @@
 }
 
+
 QPair<int, QString> UIVMLogViewerTextEdit::bookmarkForPos(const QPoint &position)
 {
@@ -461,4 +471,24 @@
 }
 
+int  UIVMLogViewerTextEdit::currentVerticalScrollBarValue() const
+{
+    if(!verticalScrollBar())
+        return -1;
+    return verticalScrollBar()->value();
+}
+void UIVMLogViewerTextEdit::setCurrentVerticalScrollBarValue(int value)
+{
+    if(!verticalScrollBar())
+        return;
+
+    setCenterOnScroll(true);
+
+    verticalScrollBar()->setValue(value);
+    verticalScrollBar()->setSliderPosition(value);
+    printf("value %d\n", value);
+    viewport()->update();
+    update();
+}
+
 
 #include "UIVMLogViewerTextEdit.moc"
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.h	(revision 70645)
@@ -53,4 +53,9 @@
     void setWrapLines(bool bWrapLines);
 
+    /** currentVerticalScrollBarValue is used by UIVMLogPage to store and restore scrolled
+        plain text position as we switch from a tab to another */
+    int  currentVerticalScrollBarValue() const;
+    void setCurrentVerticalScrollBarValue(int value);
+
 protected:
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp	(revision 70644)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp	(revision 70645)
@@ -263,11 +263,7 @@
     Q_UNUSED(tabIndex);
 
-    // if (m_iCurrentTabIndex == tabIndex)
-    //     return;
-
     resetHighlighthing();
     if (m_pSearchPanel)
         m_pSearchPanel->reset();
-    // m_iCurrentTabIndex = tabIndex;
 
     /* We keep a separate QVector<LogBookmark> for each log page: */
@@ -850,9 +846,9 @@
     /* Set text edit since we want to display this text: */
     if (!noLogsToShow)
-        pLogPage->setTextEdit(strLogContent);
+        pLogPage->setTextEditText(strLogContent);
     /* In case there are some errors append the error text as html: */
     else
     {
-        pLogPage->setTextEditAsHtml(strLogContent);
+        pLogPage->setTextEditTextAsHtml(strLogContent);
         pLogPage->markForError();
     }
